Skip to content

Commit

Permalink
add gjs and css parsing to audits
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Feb 29, 2024
1 parent ec1ebad commit 393203f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions packages/compat/src/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -511,6 +521,22 @@ export class Audit {
return this.visitJS(filename, js);
}

private async visitGJS(
filename: string,
content: Buffer | string
): Promise<ParsedInternalModule['parsed'] | Finding[]> {
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<ParsedInternalModule['parsed'] | Finding[]> {
return [];
}

private async visitJSON(
filename: string,
content: Buffer | string
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 393203f

Please sign in to comment.