@embroider/compat 3.4.8 → 3.4.9-unstable.4c21dd5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/package.json +13 -13
  2. package/src/audit.d.ts +6 -54
  3. package/src/audit.js +86 -275
  4. package/src/audit.js.map +1 -1
  5. package/src/babel-plugin-adjust-imports.js +1 -1
  6. package/src/babel-plugin-adjust-imports.js.map +1 -1
  7. package/src/compat-adapters/@ember-data/store.d.ts +1 -5
  8. package/src/compat-adapters/@ember-data/store.js +3 -15
  9. package/src/compat-adapters/@ember-data/store.js.map +1 -1
  10. package/src/compat-adapters/ember-fetch.d.ts +5 -0
  11. package/src/compat-adapters/ember-fetch.js +19 -0
  12. package/src/compat-adapters/ember-fetch.js.map +1 -0
  13. package/src/compat-app-builder.d.ts +5 -5
  14. package/src/compat-app-builder.js +98 -183
  15. package/src/compat-app-builder.js.map +1 -1
  16. package/src/compat-app.d.ts +2 -0
  17. package/src/compat-app.js +32 -6
  18. package/src/compat-app.js.map +1 -1
  19. package/src/content-for-config.d.ts +11 -0
  20. package/src/content-for-config.js +66 -0
  21. package/src/content-for-config.js.map +1 -0
  22. package/src/default-pipeline.d.ts +2 -2
  23. package/src/default-pipeline.js +22 -1
  24. package/src/default-pipeline.js.map +1 -1
  25. package/src/index.d.ts +1 -1
  26. package/src/index.js +2 -1
  27. package/src/index.js.map +1 -1
  28. package/src/module-visitor.d.ts +53 -0
  29. package/src/module-visitor.js +286 -0
  30. package/src/module-visitor.js.map +1 -0
  31. package/src/options.d.ts +1 -0
  32. package/src/options.js +1 -0
  33. package/src/options.js.map +1 -1
  34. package/src/resolver-transform.js +3 -0
  35. package/src/resolver-transform.js.map +1 -1
  36. package/LICENSE +0 -21
  37. package/src/compat-adapters/@ember-data/debug.d.ts +0 -6
  38. package/src/compat-adapters/@ember-data/debug.js +0 -22
  39. package/src/compat-adapters/@ember-data/debug.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/compat",
3
- "version": "3.4.8",
3
+ "version": "3.4.9-unstable.4c21dd5",
4
4
  "private": false,
5
5
  "description": "Backward compatibility layer for the Embroider build system.",
6
6
  "repository": {
@@ -19,6 +19,9 @@
19
19
  "bin": {
20
20
  "embroider-compat-audit": "./src/audit-cli.js"
21
21
  },
22
+ "scripts": {
23
+ "test": "jest"
24
+ },
22
25
  "dependencies": {
23
26
  "@babel/code-frame": "^7.14.5",
24
27
  "@babel/core": "^7.14.5",
@@ -27,6 +30,7 @@
27
30
  "@babel/preset-env": "^7.14.5",
28
31
  "@babel/runtime": "^7.18.6",
29
32
  "@babel/traverse": "^7.14.5",
33
+ "@embroider/macros": "1.16.1-unstable.4c21dd5",
30
34
  "@types/babel__code-frame": "^7.0.2",
31
35
  "@types/yargs": "^17.0.3",
32
36
  "assert-never": "^1.1.0",
@@ -59,10 +63,12 @@
59
63
  "tree-sync": "^2.1.0",
60
64
  "typescript-memoize": "^1.0.1",
61
65
  "walk-sync": "^3.0.0",
62
- "yargs": "^17.0.1",
63
- "@embroider/macros": "1.16.0"
66
+ "yargs": "^17.0.1"
64
67
  },
65
68
  "devDependencies": {
69
+ "@embroider/core": "3.4.9-unstable.4c21dd5",
70
+ "@embroider/sample-transforms": "workspace:*",
71
+ "@embroider/test-support": "workspace:*",
66
72
  "@glimmer/syntax": "^0.84.3",
67
73
  "@glint/template": "^1.0.0",
68
74
  "@types/babel__core": "^7.1.14",
@@ -81,19 +87,13 @@
81
87
  "broccoli-node-api": "^1.7.0",
82
88
  "code-equality-assertions": "^0.9.0",
83
89
  "ember-engines": "^0.8.19",
84
- "scenario-tester": "^2.1.2",
85
- "typescript": "^5.1.6",
86
- "@embroider/core": "^3.4.8",
87
- "@embroider/sample-transforms": "0.0.0",
88
- "@embroider/test-support": "0.36.0"
90
+ "scenario-tester": "^3.0.1",
91
+ "typescript": "^5.1.6"
89
92
  },
90
93
  "peerDependencies": {
91
- "@embroider/core": "^3.4.8"
94
+ "@embroider/core": "3.4.9-unstable.4c21dd5"
92
95
  },
93
96
  "engines": {
94
97
  "node": "12.* || 14.* || >= 16"
95
- },
96
- "scripts": {
97
- "test": "jest"
98
98
  }
99
- }
99
+ }
package/src/audit.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- /// <reference types="node" />
2
- import type { ExportAll, InternalImport, NamespaceMarker } from './audit/babel-visitor';
3
1
  import { AuditBuildOptions, AuditOptions } from './audit/options';
4
2
  import { BuildError, isBuildError } from './audit/build';
3
+ import { type Module } from './module-visitor';
5
4
  export interface AuditMessage {
6
5
  message: string;
7
6
  detail: string;
@@ -26,56 +25,19 @@ export interface Finding {
26
25
  detail: string;
27
26
  codeFrame?: string;
28
27
  }
29
- export interface Module {
30
- appRelativePath: string;
31
- consumedFrom: (string | RootMarker)[];
32
- imports: Import[];
33
- exports: string[];
34
- resolutions: {
35
- [source: string]: string | null;
36
- };
37
- content: string;
38
- }
39
- interface ResolutionFailure {
40
- isResolutionFailure: true;
41
- }
42
- interface InternalModule {
43
- consumedFrom: (string | RootMarker)[];
44
- parsed?: {
45
- imports: InternalImport[];
46
- exports: Set<string | ExportAll>;
47
- isCJS: boolean;
48
- isAMD: boolean;
49
- dependencies: string[];
50
- transpiledContent: string | Buffer;
51
- };
52
- resolved?: Map<string, string | ResolutionFailure>;
53
- linked?: {
54
- exports: Set<string>;
55
- };
56
- }
57
- export interface Import {
58
- source: string;
59
- specifiers: {
60
- name: string | NamespaceMarker;
61
- local: string | null;
62
- }[];
63
- }
64
28
  export declare class AuditResults {
65
29
  modules: {
66
30
  [file: string]: Module;
67
31
  };
68
32
  findings: Finding[];
69
- static create(baseDir: string, findings: Finding[], modules: Map<string, InternalModule>): AuditResults;
33
+ static create(baseDir: string, findings: Finding[], modules: Record<string, Module>): AuditResults;
70
34
  humanReadable(): string;
71
35
  get perfect(): boolean;
72
36
  }
73
37
  export declare class Audit {
74
38
  private originAppRoot;
75
39
  private options;
76
- private modules;
77
40
  private virtualModules;
78
- private moduleQueue;
79
41
  private findings;
80
42
  private frames;
81
43
  static run(options: AuditBuildOptions): Promise<AuditResults>;
@@ -87,24 +49,14 @@ export declare class Audit {
87
49
  private get resolverParams();
88
50
  private resolver;
89
51
  private debug;
90
- private visitorFor;
91
- private drainQueue;
92
52
  run(): Promise<AuditResults>;
53
+ private resolveId;
54
+ private load;
93
55
  private handleResolverError;
94
- private linkModules;
95
- private linkModule;
96
56
  private inspectModules;
97
57
  private inspectImports;
98
58
  private moduleProvidesName;
99
- private visitHTML;
100
- private visitJS;
101
- private visitHBS;
102
- private visitJSON;
103
- private resolveDeps;
59
+ private handleJSON;
104
60
  private pushFinding;
105
- private scheduleVisit;
106
- }
107
- export interface RootMarker {
108
- isRoot: true;
109
61
  }
110
- export declare function isRootMarker(value: string | RootMarker | undefined): value is RootMarker;
62
+ export { Module };
package/src/audit.js CHANGED
@@ -9,72 +9,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.isRootMarker = exports.Audit = exports.AuditResults = exports.isBuildError = exports.BuildError = void 0;
12
+ exports.Audit = exports.AuditResults = exports.isBuildError = exports.BuildError = void 0;
13
13
  const fs_extra_1 = require("fs-extra");
14
14
  const path_1 = require("path");
15
15
  const core_1 = require("@embroider/core");
16
16
  const typescript_memoize_1 = require("typescript-memoize");
17
17
  const chalk_1 = __importDefault(require("chalk"));
18
- const jsdom_1 = __importDefault(require("jsdom"));
19
18
  const groupBy_1 = __importDefault(require("lodash/groupBy"));
20
- const fromPairs_1 = __importDefault(require("lodash/fromPairs"));
21
19
  const babel_visitor_1 = require("./audit/babel-visitor");
22
20
  const build_1 = require("./audit/build");
23
21
  Object.defineProperty(exports, "BuildError", { enumerable: true, get: function () { return build_1.BuildError; } });
24
22
  Object.defineProperty(exports, "isBuildError", { enumerable: true, get: function () { return build_1.isBuildError; } });
25
- const { JSDOM } = jsdom_1.default;
26
- function isResolutionFailure(result) {
27
- return typeof result === 'object' && 'isResolutionFailure' in result;
28
- }
29
- function isResolved(module) {
30
- return Boolean((module === null || module === void 0 ? void 0 : module.parsed) && module.resolved);
31
- }
32
- function isLinked(module) {
33
- return Boolean((module === null || module === void 0 ? void 0 : module.parsed) && module.resolved && module.linked);
34
- }
23
+ const module_visitor_1 = require("./module-visitor");
35
24
  class AuditResults {
36
25
  constructor() {
37
26
  this.modules = {};
38
27
  this.findings = [];
39
28
  }
40
29
  static create(baseDir, findings, modules) {
41
- var _a, _b, _c, _d;
42
30
  let results = new this();
43
- for (let [filename, module] of modules) {
44
- let publicModule = {
45
- appRelativePath: (0, core_1.explicitRelative)(baseDir, filename),
46
- consumedFrom: module.consumedFrom.map(entry => {
47
- if (isRootMarker(entry)) {
48
- return entry;
49
- }
50
- else {
51
- return (0, core_1.explicitRelative)(baseDir, entry);
52
- }
53
- }),
54
- resolutions: module.resolved
55
- ? (0, fromPairs_1.default)([...module.resolved].map(([source, target]) => [
56
- source,
57
- isResolutionFailure(target) ? null : (0, core_1.explicitRelative)(baseDir, target),
58
- ]))
59
- : {},
60
- imports: ((_a = module.parsed) === null || _a === void 0 ? void 0 : _a.imports)
61
- ? module.parsed.imports.map(i => ({
62
- source: i.source,
63
- specifiers: i.specifiers.map(s => ({
64
- name: s.name,
65
- local: s.local,
66
- })),
67
- }))
68
- : [],
69
- exports: ((_b = module.linked) === null || _b === void 0 ? void 0 : _b.exports) ? [...module.linked.exports] : [],
70
- content: ((_c = module.parsed) === null || _c === void 0 ? void 0 : _c.transpiledContent)
71
- ? (_d = module.parsed) === null || _d === void 0 ? void 0 : _d.transpiledContent.toString()
72
- : 'module failed to transpile',
73
- };
74
- results.modules[(0, core_1.explicitRelative)(baseDir, filename)] = publicModule;
75
- }
31
+ results.modules = modules;
76
32
  for (let finding of findings) {
77
- let relFinding = Object.assign({}, finding, { filename: (0, core_1.explicitRelative)(baseDir, finding.filename) });
33
+ const filename = finding.filename.startsWith('./')
34
+ ? finding.filename
35
+ : (0, core_1.explicitRelative)(baseDir, finding.filename);
36
+ let relFinding = Object.assign({}, finding, { filename });
78
37
  results.findings.push(relFinding);
79
38
  }
80
39
  return results;
@@ -94,7 +53,7 @@ class AuditResults {
94
53
  }
95
54
  output.push(indent(chalk_1.default.blueBright(`file was included because:`), 1));
96
55
  let pointer = filename;
97
- while (!isRootMarker(pointer)) {
56
+ while (!(0, module_visitor_1.isRootMarker)(pointer)) {
98
57
  // the zero here means we only display the first path we found. I think
99
58
  // that's a fine tradeoff to keep the output smaller.
100
59
  let nextPointer = (_a = this.modules[pointer]) === null || _a === void 0 ? void 0 : _a.consumedFrom[0];
@@ -102,7 +61,7 @@ class AuditResults {
102
61
  output.push(indent(chalk_1.default.red(`couldn't figure out why this was included. Please file a bug against @embroider/compat.`), 2));
103
62
  break;
104
63
  }
105
- if (isRootMarker(nextPointer)) {
64
+ if ((0, module_visitor_1.isRootMarker)(nextPointer)) {
106
65
  output.push(indent('packageJSON.ember-addon.assets', 2));
107
66
  }
108
67
  else {
@@ -144,12 +103,52 @@ class Audit {
144
103
  constructor(originAppRoot, options = {}) {
145
104
  this.originAppRoot = originAppRoot;
146
105
  this.options = options;
147
- this.modules = new Map();
148
106
  this.virtualModules = new Map();
149
- this.moduleQueue = new Set();
150
107
  this.findings = [];
151
108
  this.frames = new babel_visitor_1.CodeFrameStorage();
152
109
  this.resolver = new core_1.Resolver(this.resolverParams);
110
+ this.resolveId = async (specifier, fromFile) => {
111
+ if (['@embroider/macros'].includes(specifier)) {
112
+ // the audit process deliberately removes the @embroider/macros babel
113
+ // plugins, so the imports are still present and should be left alone.
114
+ return undefined;
115
+ }
116
+ if (fromFile.endsWith('.html') && specifier.startsWith(this.meta['root-url'])) {
117
+ // root-relative URLs in HTML are actually relative to the appDir
118
+ specifier = (0, core_1.explicitRelative)((0, path_1.dirname)(fromFile), (0, path_1.resolve)(this.movedAppRoot, specifier.replace(this.meta['root-url'], '')));
119
+ }
120
+ let resolution = await this.resolver.nodeResolve(specifier, fromFile);
121
+ switch (resolution.type) {
122
+ case 'virtual':
123
+ this.virtualModules.set(resolution.filename, resolution.content);
124
+ return resolution.filename;
125
+ case 'not_found':
126
+ return undefined;
127
+ case 'real':
128
+ return resolution.filename;
129
+ }
130
+ };
131
+ this.load = async (id) => {
132
+ let content;
133
+ if (this.virtualModules.has(id)) {
134
+ content = this.virtualModules.get(id);
135
+ }
136
+ else {
137
+ content = (0, fs_extra_1.readFileSync)(id);
138
+ }
139
+ if (id.endsWith('.html')) {
140
+ return { content, type: 'html' };
141
+ }
142
+ else if (id.endsWith('.hbs')) {
143
+ return { content: (0, core_1.hbsToJS)(content.toString('utf8')), type: 'javascript' };
144
+ }
145
+ else if (id.endsWith('.json')) {
146
+ return this.handleJSON(id, content);
147
+ }
148
+ else {
149
+ return { content, type: 'javascript' };
150
+ }
151
+ };
153
152
  }
154
153
  get pkg() {
155
154
  return (0, fs_extra_1.readJSONSync)((0, path_1.join)(this.movedAppRoot, 'package.json'));
@@ -177,64 +176,22 @@ class Audit {
177
176
  console.log(message, ...args);
178
177
  }
179
178
  }
180
- visitorFor(filename) {
181
- if (filename.endsWith('.html')) {
182
- return this.visitHTML;
183
- }
184
- else if (filename.endsWith('.hbs')) {
185
- return this.visitHBS;
186
- }
187
- else if (filename.endsWith('.json')) {
188
- return this.visitJSON;
189
- }
190
- else {
191
- return this.visitJS;
192
- }
193
- }
194
- async drainQueue() {
195
- while (this.moduleQueue.size > 0) {
196
- let filename = this.moduleQueue.values().next().value;
197
- this.moduleQueue.delete(filename);
198
- this.debug('visit', filename);
199
- let visitor = this.visitorFor(filename);
200
- let content;
201
- if (this.virtualModules.has(filename)) {
202
- content = this.virtualModules.get(filename);
203
- }
204
- else {
205
- content = (0, fs_extra_1.readFileSync)(filename);
206
- }
207
- // cast is safe because the only way to get into the queue is to go
208
- // through scheduleVisit, and scheduleVisit creates the entry in
209
- // this.modules.
210
- let module = this.modules.get(filename);
211
- let visitResult = await visitor.call(this, filename, content);
212
- if (Array.isArray(visitResult)) {
213
- // the visitor was unable to figure out the ParseFields and returned
214
- // some number of Findings to us to explain why.
215
- for (let finding of visitResult) {
216
- this.pushFinding(finding);
217
- }
218
- }
219
- else {
220
- module.parsed = visitResult;
221
- module.resolved = await this.resolveDeps(visitResult.dependencies, filename);
222
- }
223
- }
224
- }
225
179
  async run() {
226
180
  globalThis.embroider_audit = this.handleResolverError.bind(this);
227
181
  try {
228
182
  this.debug(`meta`, this.meta);
229
- for (let asset of this.meta.assets) {
230
- if (asset.endsWith('.html')) {
231
- this.scheduleVisit((0, path_1.resolve)(this.movedAppRoot, asset), { isRoot: true });
232
- }
233
- }
234
- await this.drainQueue();
235
- this.linkModules();
236
- this.inspectModules();
237
- return AuditResults.create(this.originAppRoot, this.findings, this.modules);
183
+ let entrypoints = this.meta.assets.filter(a => a.endsWith('html')).map(a => (0, path_1.resolve)(this.movedAppRoot, a));
184
+ let modules = await (0, module_visitor_1.visitModules)({
185
+ base: this.originAppRoot,
186
+ entrypoints,
187
+ resolveId: this.resolveId,
188
+ load: this.load,
189
+ findings: this.findings,
190
+ frames: this.frames,
191
+ babelConfig: this.babelConfig,
192
+ });
193
+ this.inspectModules(modules);
194
+ return AuditResults.create(this.originAppRoot, this.findings, modules);
238
195
  }
239
196
  finally {
240
197
  delete globalThis.embroider_audit;
@@ -248,54 +205,22 @@ class Audit {
248
205
  codeFrame: this.frames.render(this.frames.forSource(msg.source)(msg)),
249
206
  });
250
207
  }
251
- linkModules() {
252
- for (let module of this.modules.values()) {
253
- if (isResolved(module)) {
254
- this.linkModule(module);
208
+ inspectModules(modules) {
209
+ for (let [filename, module] of Object.entries(modules)) {
210
+ if (module.type === 'complete') {
211
+ this.inspectImports(filename, module, modules);
255
212
  }
256
213
  }
257
214
  }
258
- linkModule(module) {
259
- let exports = new Set();
260
- for (let exp of module.parsed.exports) {
261
- if (typeof exp === 'string') {
262
- exports.add(exp);
263
- }
264
- else {
265
- let moduleName = module.resolved.get(exp.all);
266
- if (!isResolutionFailure(moduleName)) {
267
- let target = this.modules.get(moduleName);
268
- if (!isLinked(target) && isResolved(target)) {
269
- this.linkModule(target);
270
- }
271
- if (isLinked(target)) {
272
- for (let innerExp of target.linked.exports) {
273
- exports.add(innerExp);
274
- }
275
- }
276
- else {
277
- // our module doesn't successfully enter linked state because it
278
- // depends on stuff that also couldn't
279
- return;
280
- }
281
- }
282
- }
283
- }
284
- module.linked = {
285
- exports,
286
- };
287
- }
288
- inspectModules() {
289
- for (let [filename, module] of this.modules) {
290
- if (isLinked(module)) {
291
- this.inspectImports(filename, module);
215
+ inspectImports(filename, module, modules) {
216
+ for (let imp of module.imports) {
217
+ // our Audit should always ignore any imports of @embroider/macros because we already ignored them
218
+ // in resolveId above
219
+ if (imp.source === '@embroider/macros') {
220
+ continue;
292
221
  }
293
- }
294
- }
295
- inspectImports(filename, module) {
296
- for (let imp of module.parsed.imports) {
297
- let resolved = module.resolved.get(imp.source);
298
- if (isResolutionFailure(resolved)) {
222
+ let resolved = module.resolutions[imp.source];
223
+ if (!resolved) {
299
224
  this.findings.push({
300
225
  filename,
301
226
  message: 'unable to resolve dependency',
@@ -304,9 +229,9 @@ class Audit {
304
229
  });
305
230
  }
306
231
  else if (resolved) {
307
- let target = this.modules.get(resolved);
232
+ let target = modules[resolved];
308
233
  for (let specifier of imp.specifiers) {
309
- if (isLinked(target) && !this.moduleProvidesName(target, specifier.name)) {
234
+ if (target.type === 'complete' && !this.moduleProvidesName(target, specifier.name)) {
310
235
  if (specifier.name === 'default') {
311
236
  let backtick = '`';
312
237
  this.findings.push({
@@ -333,137 +258,27 @@ class Audit {
333
258
  // any module can provide a namespace.
334
259
  // CJS and AMD are too dynamic to be sure exactly what names are available,
335
260
  // so they always get a pass
336
- return (0, babel_visitor_1.isNamespaceMarker)(name) || target.parsed.isCJS || target.parsed.isAMD || target.linked.exports.has(name);
337
- }
338
- async visitHTML(filename, content) {
339
- let dom = new JSDOM(content);
340
- let scripts = dom.window.document.querySelectorAll('script[type="module"]');
341
- let dependencies = [];
342
- for (let script of scripts) {
343
- let src = script.src;
344
- if (!src) {
345
- continue;
346
- }
347
- if (new URL(src, 'http://example.com:4321').origin !== 'http://example.com:4321') {
348
- // src was absolute, we don't handle it
349
- continue;
350
- }
351
- if (src.startsWith(this.meta['root-url'])) {
352
- // root-relative URLs are actually relative to the appDir
353
- src = (0, core_1.explicitRelative)((0, path_1.dirname)(filename), (0, path_1.resolve)(this.movedAppRoot, src.replace(this.meta['root-url'], '')));
354
- }
355
- dependencies.push(src);
356
- }
357
- return {
358
- imports: [],
359
- exports: new Set(),
360
- isCJS: false,
361
- isAMD: false,
362
- dependencies,
363
- transpiledContent: content,
364
- };
261
+ return (0, babel_visitor_1.isNamespaceMarker)(name) || target.isCJS || target.isAMD || target.exports.includes(name);
365
262
  }
366
- async visitJS(filename, content) {
367
- let rawSource = content.toString('utf8');
368
- try {
369
- let result = (0, babel_visitor_1.auditJS)(rawSource, filename, this.babelConfig, this.frames);
370
- for (let problem of result.problems) {
371
- this.pushFinding({
372
- filename,
373
- message: problem.message,
374
- detail: problem.detail,
375
- codeFrame: this.frames.render(problem.codeFrameIndex),
376
- });
377
- }
378
- return {
379
- exports: result.exports,
380
- imports: result.imports,
381
- isCJS: result.isCJS,
382
- isAMD: result.isAMD,
383
- dependencies: result.imports.map(i => i.source),
384
- transpiledContent: result.transpiledContent,
385
- };
386
- }
387
- catch (err) {
388
- if (['BABEL_PARSE_ERROR', 'BABEL_TRANSFORM_ERROR'].includes(err.code)) {
389
- return [
390
- {
391
- filename,
392
- message: `failed to parse`,
393
- detail: err.toString().replace(filename, (0, core_1.explicitRelative)(this.originAppRoot, filename)),
394
- },
395
- ];
396
- }
397
- else {
398
- throw err;
399
- }
400
- }
401
- }
402
- async visitHBS(filename, content) {
403
- let rawSource = content.toString('utf8');
404
- let js = (0, core_1.hbsToJS)(rawSource);
405
- return this.visitJS(filename, js);
406
- }
407
- async visitJSON(filename, content) {
263
+ handleJSON(filename, content) {
408
264
  let js;
409
265
  try {
410
266
  let structure = JSON.parse(content.toString('utf8'));
411
267
  js = `export default ${JSON.stringify(structure)}`;
412
268
  }
413
269
  catch (err) {
414
- return [
415
- {
416
- filename,
417
- message: `failed to parse JSON`,
418
- detail: err.toString().replace(filename, (0, core_1.explicitRelative)(this.originAppRoot, filename)),
419
- },
420
- ];
270
+ this.findings.push({
271
+ filename,
272
+ message: `failed to parse JSON`,
273
+ detail: err.toString().replace(filename, (0, core_1.explicitRelative)(this.originAppRoot, filename)),
274
+ });
275
+ return;
421
276
  }
422
- return this.visitJS(filename, js);
423
- }
424
- async resolveDeps(deps, fromFile) {
425
- let resolved = new Map();
426
- for (let dep of deps) {
427
- let resolution = await this.resolver.nodeResolve(dep, fromFile);
428
- switch (resolution.type) {
429
- case 'virtual':
430
- this.virtualModules.set(resolution.filename, resolution.content);
431
- resolved.set(dep, resolution.filename);
432
- this.scheduleVisit(resolution.filename, fromFile);
433
- break;
434
- case 'not_found':
435
- if (['@embroider/macros', '@ember/template-factory'].includes(dep)) {
436
- // the audit process deliberately removes the @embroider/macros babel
437
- // plugins, so the imports are still present and should be left alone.
438
- continue;
439
- }
440
- resolved.set(dep, { isResolutionFailure: true });
441
- break;
442
- case 'real':
443
- resolved.set(dep, resolution.filename);
444
- this.scheduleVisit(resolution.filename, fromFile);
445
- break;
446
- }
447
- }
448
- return resolved;
277
+ return { content: js, type: 'javascript' };
449
278
  }
450
279
  pushFinding(finding) {
451
280
  this.findings.push(finding);
452
281
  }
453
- scheduleVisit(filename, parent) {
454
- let record = this.modules.get(filename);
455
- if (!record) {
456
- this.debug(`discovered`, filename);
457
- record = {
458
- consumedFrom: [parent],
459
- };
460
- this.modules.set(filename, record);
461
- this.moduleQueue.add(filename);
462
- }
463
- else {
464
- record.consumedFrom.push(parent);
465
- }
466
- }
467
282
  }
468
283
  exports.Audit = Audit;
469
284
  __decorate([
@@ -489,8 +304,4 @@ function indent(str, level) {
489
304
  .map(line => spaces + line)
490
305
  .join('\n');
491
306
  }
492
- function isRootMarker(value) {
493
- return Boolean(value && typeof value !== 'string' && value.isRoot);
494
- }
495
- exports.isRootMarker = isRootMarker;
496
307
  //# sourceMappingURL=audit.js.map