diff --git a/packages/compat/package.json b/packages/compat/package.json index 2514869865..89019c8722 100644 --- a/packages/compat/package.json +++ b/packages/compat/package.json @@ -48,6 +48,7 @@ "broccoli-plugin": "^4.0.7", "broccoli-source": "^3.0.1", "chalk": "^4.1.1", + "content-tag": "^2.0.1", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "fast-sourcemap-concat": "^1.4.0", diff --git a/packages/compat/src/audit.ts b/packages/compat/src/audit.ts index 499313fce9..8eec7b5269 100644 --- a/packages/compat/src/audit.ts +++ b/packages/compat/src/audit.ts @@ -11,6 +11,7 @@ import type { ExportAll, InternalImport, NamespaceMarker } from './audit/babel-v import { auditJS, CodeFrameStorage, isNamespaceMarker } from './audit/babel-visitor'; import { AuditBuildOptions, AuditOptions } from './audit/options'; import { buildApp, BuildError, isBuildError } from './audit/build'; +import { Preprocessor } from 'content-tag'; const { JSDOM } = jsdom; @@ -238,6 +239,11 @@ export class Audit { return cache.maybeMoved(cache.get(this.originAppRoot)).root; } + @Memoize() + private get preprocessor() { + return new Preprocessor(); + } + private get meta() { return this.pkg['ember-addon'] as AppMeta; } @@ -276,8 +282,12 @@ export class Audit { return this.visitHTML; } else if (filename.endsWith('.hbs')) { return this.visitHBS; + } else if (filename.endsWith('.gjs') || filename.endsWith('.gts')) { + return this.visitGJS; } else if (filename.endsWith('.json')) { return this.visitJSON; + } else if (filename.endsWith('.css')) { + return this.visitCSS; } else { return this.visitJS; } @@ -511,6 +521,22 @@ export class Audit { return this.visitJS(filename, js); } + private async visitGJS( + filename: string, + content: Buffer | string + ): Promise { + let rawSource = content.toString('utf8'); + + const result = this.preprocessor.process(rawSource, { filename }); + + return this.visitJS(filename, result); + } + + // TODO I don't know exactly how to just ignore CSS or if that's what we want here + private async visitCSS(): Promise { + return []; + } + private async visitJSON( filename: string, content: Buffer | string diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1e36604ce9..8c444b04e4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -235,6 +235,9 @@ importers: chalk: specifier: ^4.1.1 version: 4.1.2 + content-tag: + specifier: ^2.0.1 + version: 2.0.1 debug: specifier: ^4.3.2 version: 4.3.4(supports-color@9.4.0)