@embroider/compat 2.1.1 → 2.1.2-unstable.16dc72c

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 (55) hide show
  1. package/package.json +12 -8
  2. package/src/addon-dependency-rules/ember-data.js +1 -0
  3. package/src/addon-dependency-rules/ember-data.js.map +1 -1
  4. package/src/audit/babel-visitor.d.ts +1 -0
  5. package/src/audit/babel-visitor.js +2 -2
  6. package/src/audit/babel-visitor.js.map +1 -1
  7. package/src/audit/build.js +48 -46
  8. package/src/audit/build.js.map +1 -1
  9. package/src/audit/options.d.ts +3 -2
  10. package/src/audit/options.js.map +1 -1
  11. package/src/audit-cli.js +0 -0
  12. package/src/audit.d.ts +25 -1
  13. package/src/audit.js +63 -41
  14. package/src/audit.js.map +1 -1
  15. package/src/babel-plugin-adjust-imports.d.ts +16 -0
  16. package/src/babel-plugin-adjust-imports.js +198 -0
  17. package/src/babel-plugin-adjust-imports.js.map +1 -0
  18. package/src/compat-adapters/active-model-adapter.d.ts +1 -1
  19. package/src/compat-adapters/ember-asset-loader.d.ts +1 -1
  20. package/src/compat-adapters/ember-cli-addon-docs.d.ts +1 -1
  21. package/src/compat-adapters/ember-data.d.ts +1 -0
  22. package/src/compat-adapters/ember-data.js +4 -0
  23. package/src/compat-adapters/ember-data.js.map +1 -1
  24. package/src/compat-adapters/ember-decorators.d.ts +1 -1
  25. package/src/compat-adapters/ember-get-config.d.ts +1 -1
  26. package/src/compat-adapters/ember-macro-helpers.d.ts +1 -1
  27. package/src/compat-adapters/ember-percy.d.ts +1 -1
  28. package/src/compat-adapters/ember-source.d.ts +1 -1
  29. package/src/compat-adapters/ember-svg-jar.d.ts +1 -1
  30. package/src/compat-adapters/ember-test-selectors.d.ts +1 -1
  31. package/src/compat-app.js +41 -77
  32. package/src/compat-app.js.map +1 -1
  33. package/src/dependency-rules.d.ts +14 -11
  34. package/src/dependency-rules.js +21 -37
  35. package/src/dependency-rules.js.map +1 -1
  36. package/src/modules-compat.js.map +1 -1
  37. package/src/resolver-transform.d.ts +13 -6
  38. package/src/resolver-transform.js +717 -320
  39. package/src/resolver-transform.js.map +1 -1
  40. package/src/rewrite-addon-tree.d.ts +1 -1
  41. package/src/v1-addon.js +1 -0
  42. package/src/v1-addon.js.map +1 -1
  43. package/src/v1-app.js +14 -10
  44. package/src/v1-app.js.map +1 -1
  45. package/src/v1-instance-cache.js +7 -7
  46. package/src/v1-instance-cache.js.map +1 -1
  47. package/src/audit/capture.d.ts +0 -8
  48. package/src/audit/capture.js +0 -45
  49. package/src/audit/capture.js.map +0 -1
  50. package/src/resolver.d.ts +0 -128
  51. package/src/resolver.js +0 -677
  52. package/src/resolver.js.map +0 -1
  53. package/src/template-compiler-broccoli-plugin.d.ts +0 -10
  54. package/src/template-compiler-broccoli-plugin.js +0 -28
  55. package/src/template-compiler-broccoli-plugin.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/compat",
3
- "version": "2.1.1",
3
+ "version": "2.1.2-unstable.16dc72c",
4
4
  "private": false,
5
5
  "description": "Backward compatibility layer for the Embroider build system.",
6
6
  "repository": {
@@ -28,10 +28,11 @@
28
28
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
29
29
  "@babel/preset-env": "^7.14.5",
30
30
  "@babel/traverse": "^7.14.5",
31
- "@embroider/macros": "1.10.0",
31
+ "@embroider/macros": "1.10.1-unstable.16dc72c",
32
32
  "@types/babel__code-frame": "^7.0.2",
33
33
  "@types/yargs": "^17.0.3",
34
34
  "assert-never": "^1.1.0",
35
+ "babel-import-util": "^1.1.0",
35
36
  "babel-plugin-ember-template-compilation": "^2.0.0",
36
37
  "babel-plugin-syntax-dynamic-import": "^6.18.0",
37
38
  "babylon": "^6.18.0",
@@ -61,12 +62,14 @@
61
62
  "yargs": "^17.0.1"
62
63
  },
63
64
  "devDependencies": {
64
- "@embroider/sample-transforms": "0.0.0",
65
- "@embroider/test-support": "0.36.0",
65
+ "@embroider/sample-transforms": "workspace:*",
66
+ "@embroider/test-support": "workspace:*",
66
67
  "@glimmer/syntax": "^0.84.2",
68
+ "@glint/template": "^1.0.0",
67
69
  "@types/babel__core": "^7.1.14",
68
70
  "@types/babel__generator": "^7.6.2",
69
71
  "@types/babel__template": "^7.4.0",
72
+ "@types/babel__traverse": "^7.18.5",
70
73
  "@types/babylon": "^6.16.5",
71
74
  "@types/debug": "^4.1.5",
72
75
  "@types/fs-extra": "^9.0.11",
@@ -76,13 +79,14 @@
76
79
  "@types/node": "^15.12.2",
77
80
  "@types/resolve": "^1.20.0",
78
81
  "@types/semver": "^7.3.6",
79
- "code-equality-assertions": "^0.7.0",
82
+ "broccoli-node-api": "^1.7.0",
83
+ "code-equality-assertions": "^0.9.0",
80
84
  "ember-engines": "^0.8.19",
81
- "scenario-tester": "^2.0.1",
82
- "typescript": "*"
85
+ "scenario-tester": "^2.1.2",
86
+ "typescript": "^4.9.0"
83
87
  },
84
88
  "peerDependencies": {
85
- "@embroider/core": "^2.0.0"
89
+ "@embroider/core": "2.1.2-unstable.16dc72c"
86
90
  },
87
91
  "engines": {
88
92
  "node": "12.* || 14.* || >= 16"
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  let rules = [
4
4
  {
5
5
  package: '@ember-data/store',
6
+ semverRange: '<=4.11.0',
6
7
  addonModules: {
7
8
  '-private.js': {
8
9
  dependsOnModules: ['@ember-data/record-data/-private'],
@@ -1 +1 @@
1
- {"version":3,"file":"ember-data.js","sourceRoot":"","sources":["ember-data.ts"],"names":[],"mappings":";;AAEA,IAAI,KAAK,GAAmB;IAC1B;QACE,OAAO,EAAE,mBAAmB;QAC5B,YAAY,EAAE;YACZ,aAAa,EAAE;gBACb,gBAAgB,EAAE,CAAC,kCAAkC,CAAC;aACvD;YACD,+BAA+B,EAAE;gBAC/B,gBAAgB,EAAE,CAAC,kCAAkC,CAAC;aACvD;YACD,yCAAyC,EAAE;gBACzC,gBAAgB,EAAE,CAAC,4BAA4B,CAAC;aACjD;SACF;KACF;CACF,CAAC;AAEF,kBAAe,KAAK,CAAC","sourcesContent":["import { PackageRules } from '..';\n\nlet rules: PackageRules[] = [\n {\n package: '@ember-data/store',\n addonModules: {\n '-private.js': {\n dependsOnModules: ['@ember-data/record-data/-private'],\n },\n '-private/system/core-store.js': {\n dependsOnModules: ['@ember-data/record-data/-private'],\n },\n '-private/system/model/internal-model.js': {\n dependsOnModules: ['@ember-data/model/-private'],\n },\n },\n },\n];\n\nexport default rules;\n"]}
1
+ {"version":3,"file":"ember-data.js","sourceRoot":"","sources":["ember-data.ts"],"names":[],"mappings":";;AAEA,IAAI,KAAK,GAAmB;IAC1B;QACE,OAAO,EAAE,mBAAmB;QAC5B,WAAW,EAAE,UAAU;QACvB,YAAY,EAAE;YACZ,aAAa,EAAE;gBACb,gBAAgB,EAAE,CAAC,kCAAkC,CAAC;aACvD;YACD,+BAA+B,EAAE;gBAC/B,gBAAgB,EAAE,CAAC,kCAAkC,CAAC;aACvD;YACD,yCAAyC,EAAE;gBACzC,gBAAgB,EAAE,CAAC,4BAA4B,CAAC;aACjD;SACF;KACF;CACF,CAAC;AAEF,kBAAe,KAAK,CAAC","sourcesContent":["import { PackageRules } from '..';\n\nlet rules: PackageRules[] = [\n {\n package: '@ember-data/store',\n semverRange: '<=4.11.0',\n addonModules: {\n '-private.js': {\n dependsOnModules: ['@ember-data/record-data/-private'],\n },\n '-private/system/core-store.js': {\n dependsOnModules: ['@ember-data/record-data/-private'],\n },\n '-private/system/model/internal-model.js': {\n dependsOnModules: ['@ember-data/model/-private'],\n },\n },\n },\n];\n\nexport default rules;\n"]}
@@ -28,6 +28,7 @@ export declare function auditJS(rawSource: string, filename: string, babelConfig
28
28
  detail: string;
29
29
  codeFrameIndex: number | undefined;
30
30
  }[];
31
+ transpiledContent: string;
31
32
  };
32
33
  export declare class CodeFrameStorage {
33
34
  private codeFrames;
@@ -27,7 +27,7 @@ function auditJS(rawSource, filename, babelConfig, frames) {
27
27
  let sawExports = false;
28
28
  let sawDefine = false;
29
29
  /* eslint-enable @typescript-eslint/no-inferrable-types */
30
- let ast = (0, core_1.transformSync)(rawSource, Object.assign({ filename: filename }, babelConfig)).ast;
30
+ let { ast, code } = (0, core_1.transformSync)(rawSource, Object.assign({ filename: filename }, babelConfig));
31
31
  let saveCodeFrame = frames.forSource(rawSource);
32
32
  (0, traverse_1.default)(ast, {
33
33
  Identifier(path) {
@@ -141,7 +141,7 @@ function auditJS(rawSource, filename, babelConfig, frames) {
141
141
  });
142
142
  let isCJS = imports.length === 0 && exports.size === 0 && (sawModule || sawExports);
143
143
  let isAMD = imports.length === 0 && exports.size === 0 && sawDefine;
144
- return { imports, exports, isCJS, isAMD, problems };
144
+ return { imports, exports, isCJS, isAMD, problems, transpiledContent: code };
145
145
  }
146
146
  exports.auditJS = auditJS;
147
147
  class CodeFrameStorage {
@@ -1 +1 @@
1
- {"version":3,"file":"babel-visitor.js","sourceRoot":"","sources":["babel-visitor.ts"],"names":[],"mappings":";;;;;;AAAA,+DAA2D;AAC3D,sCAA0E;AAC1E,kDAAqE;AAErE,MAAa,YAAY;CAAG;AAA5B,oCAA4B;AAgB5B,SAAgB,iBAAiB,CAAC,KAA+B;IAC/D,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAFD,8CAEC;AAMD,yCAAyC;AACzC,SAAgB,OAAO,CAAC,SAAiB,EAAE,QAAgB,EAAE,WAA6B,EAAE,MAAwB;IAClH,IAAI,OAAO,GAAG,EAAsB,CAAC;IACrC,IAAI,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC5C,IAAI,QAAQ,GAAG,EAA+E,CAAC;IAE/F,2DAA2D;IAC3D,4EAA4E;IAC5E,uEAAuE;IACvE,gBAAgB;IAChB,IAAI,SAAS,GAAY,KAAK,CAAC;IAC/B,IAAI,UAAU,GAAY,KAAK,CAAC;IAChC,IAAI,SAAS,GAAY,KAAK,CAAC;IAC/B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C;QAC3B,KAAK,kBAAkB;YACrB,OAAO,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,IAAI,0BAA0B,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAChF;YACE,OAAO,KAAK,CAAC;KAChB;AACH,CAAC","sourcesContent":["import traverse, { NodePath, Node } from '@babel/traverse';\nimport { TransformOptions, transformSync, types as t } from '@babel/core';\nimport { codeFrameColumns, SourceLocation } from '@babel/code-frame';\n\nexport class VisitorState {}\n\nexport interface InternalImport {\n source: string;\n codeFrameIndex: number | undefined;\n specifiers: {\n name: string | NamespaceMarker;\n local: string | null; // can be null when re-exporting, because in that case we import `name` from `source` but don't create any local binding for it\n codeFrameIndex: number | undefined;\n }[];\n}\n\nexport interface NamespaceMarker {\n isNamespace: true;\n}\n\nexport function isNamespaceMarker(value: string | NamespaceMarker): value is NamespaceMarker {\n return typeof value !== 'string';\n}\n\nexport interface ExportAll {\n all: string;\n}\n\n// babelConfig must include { ast: true }\nexport function auditJS(rawSource: string, filename: string, babelConfig: TransformOptions, frames: CodeFrameStorage) {\n let imports = [] as InternalImport[];\n let exports = new Set<string | ExportAll>();\n let problems = [] as { message: string; detail: string; codeFrameIndex: number | undefined }[];\n\n /* eslint-disable @typescript-eslint/no-inferrable-types */\n // These are not really inferrable. Without explicit declarations, TS thinks\n // they're always false because it doesn't know the handler methods run\n // synchronously\n let sawModule: boolean = false;\n let sawExports: boolean = false;\n let sawDefine: boolean = false;\n /* eslint-enable @typescript-eslint/no-inferrable-types */\n\n let ast = transformSync(rawSource, Object.assign({ filename: filename }, babelConfig))!.ast!;\n let saveCodeFrame = frames.forSource(rawSource);\n\n traverse(ast, {\n Identifier(path: NodePath<t.Identifier>) {\n if (path.node.name === 'module' && isFreeVariable(path)) {\n sawModule = true;\n } else if (path.node.name === 'exports' && isFreeVariable(path)) {\n sawExports = true;\n } else if (path.node.name === 'define' && isFreeVariable(path)) {\n sawDefine = true;\n }\n if (inExportDeclarationContext(path)) {\n exports.add(path.node.name);\n }\n },\n CallExpression(path: NodePath<t.CallExpression>) {\n let callee = path.get('callee');\n if (callee.referencesImport('@embroider/macros', 'importSync') || t.isImport(callee)) {\n let arg = path.node.arguments[0];\n if (arg.type === 'StringLiteral') {\n imports.push({\n source: arg.value,\n codeFrameIndex: saveCodeFrame(arg),\n specifiers: [],\n });\n } else {\n problems.push({\n message: `audit tool is unable to understand this usage of ${t.isImport(callee) ? 'import' : 'importSync'}`,\n detail: arg.type,\n codeFrameIndex: saveCodeFrame(arg),\n });\n }\n }\n },\n ImportDeclaration(path: NodePath<t.ImportDeclaration>) {\n imports.push({\n source: path.node.source.value,\n codeFrameIndex: saveCodeFrame(path.node.source),\n specifiers: [],\n });\n },\n ImportDefaultSpecifier(path: NodePath<t.ImportDefaultSpecifier>) {\n imports[imports.length - 1].specifiers.push({\n name: 'default',\n local: path.node.local.name,\n codeFrameIndex: saveCodeFrame(path.node),\n });\n },\n ImportNamespaceSpecifier(path: NodePath<t.ImportNamespaceSpecifier>) {\n imports[imports.length - 1].specifiers.push({\n name: { isNamespace: true },\n local: path.node.local.name,\n codeFrameIndex: saveCodeFrame(path.node),\n });\n },\n ImportSpecifier(path: NodePath<t.ImportSpecifier>) {\n imports[imports.length - 1].specifiers.push({\n name: name(path.node.imported),\n local: path.node.local.name,\n codeFrameIndex: saveCodeFrame(path.node),\n });\n },\n ExportDefaultDeclaration(_path: NodePath<t.ExportDefaultDeclaration>) {\n exports.add('default');\n },\n ExportSpecifier(path: NodePath<t.ExportSpecifier>) {\n exports.add(name(path.node.exported));\n if (path.parent.type === 'ExportNamedDeclaration' && path.parent.source) {\n imports[imports.length - 1].specifiers.push({\n name: name(path.node.local),\n local: null, // re-exports don't create local bindings\n codeFrameIndex: saveCodeFrame(path.node),\n });\n }\n },\n ExportNamespaceSpecifier(path: NodePath<t.ExportNamespaceSpecifier>) {\n exports.add(name(path.node.exported));\n if (path.parent.type === 'ExportNamedDeclaration' && path.parent.source) {\n imports[imports.length - 1].specifiers.push({\n name: { isNamespace: true },\n local: null, // re-exports don't create local bindings\n codeFrameIndex: saveCodeFrame(path.node),\n });\n }\n },\n ExportAllDeclaration(path: NodePath<t.ExportAllDeclaration>) {\n exports.add({ all: path.node.source.value });\n imports.push({\n source: path.node.source.value,\n codeFrameIndex: saveCodeFrame(path.node.source),\n specifiers: [\n {\n name: { isNamespace: true },\n local: null,\n codeFrameIndex: saveCodeFrame(path.node),\n },\n ],\n });\n },\n ExportNamedDeclaration(path: NodePath<t.ExportNamedDeclaration>) {\n if (path.node.source) {\n imports.push({\n source: path.node.source.value,\n codeFrameIndex: saveCodeFrame(path.node.source),\n specifiers: [],\n });\n }\n },\n });\n\n let isCJS = imports.length === 0 && exports.size === 0 && (sawModule || sawExports);\n let isAMD = imports.length === 0 && exports.size === 0 && sawDefine;\n return { imports, exports, isCJS, isAMD, problems };\n}\n\nexport class CodeFrameStorage {\n private codeFrames = [] as { rawSourceIndex: number; loc: SourceLocation }[];\n private rawSources = [] as string[];\n\n forSource(rawSource: string): (node: { loc?: SourceLocation | null }) => number | undefined {\n let rawSourceIndex: number | undefined;\n return (node: { loc?: SourceLocation | null | undefined }) => {\n let loc = node.loc;\n if (!loc) {\n return;\n }\n if (rawSourceIndex == null) {\n rawSourceIndex = this.rawSources.length;\n this.rawSources.push(rawSource);\n }\n let codeFrameIndex = this.codeFrames.length;\n this.codeFrames.push({\n rawSourceIndex,\n loc,\n });\n return codeFrameIndex;\n };\n }\n\n render(codeFrameIndex: number | undefined): string | undefined {\n if (codeFrameIndex != null) {\n let { loc, rawSourceIndex } = this.codeFrames[codeFrameIndex];\n return codeFrameColumns(this.rawSources[rawSourceIndex], loc, { highlightCode: true });\n }\n }\n}\n\nfunction name(node: t.StringLiteral | t.Identifier): string {\n if (t.isStringLiteral(node)) {\n return node.value;\n } else {\n return node.name;\n }\n}\n\nfunction isFreeVariable(path: NodePath<t.Identifier>) {\n return !path.scope.hasBinding(path.node.name);\n}\n\nconst contextCache: WeakMap<Node, boolean> = new WeakMap();\n\nfunction inExportDeclarationContext(path: NodePath): boolean {\n if (contextCache.has(path.node)) {\n return contextCache.get(path.node)!;\n } else {\n let answer = _inExportDeclarationContext(path);\n contextCache.set(path.node, answer);\n return answer;\n }\n}\n\nfunction _inExportDeclarationContext(path: NodePath): boolean {\n let parent = path.parent;\n switch (parent.type) {\n case 'ExportNamedDeclaration':\n return parent.declaration === path.node;\n case 'VariableDeclaration':\n case 'ObjectPattern':\n case 'ArrayPattern':\n case 'RestElement':\n return inExportDeclarationContext(path.parentPath);\n case 'VariableDeclarator':\n return parent.id === path.node && inExportDeclarationContext(path.parentPath);\n case 'ObjectProperty':\n return parent.value === path.node && inExportDeclarationContext(path.parentPath);\n case 'AssignmentPattern':\n return parent.left === path.node && inExportDeclarationContext(path.parentPath);\n case 'FunctionDeclaration':\n case 'ClassDeclaration':\n return parent.id === path.node && inExportDeclarationContext(path.parentPath);\n default:\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"babel-visitor.js","sourceRoot":"","sources":["babel-visitor.ts"],"names":[],"mappings":";;;;;;AAAA,+DAA2D;AAC3D,sCAA0E;AAC1E,kDAAqE;AAErE,MAAa,YAAY;CAAG;AAA5B,oCAA4B;AAgB5B,SAAgB,iBAAiB,CAAC,KAA+B;IAC/D,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAFD,8CAEC;AAMD,yCAAyC;AACzC,SAAgB,OAAO,CAAC,SAAiB,EAAE,QAAgB,EAAE,WAA6B,EAAE,MAAwB;IAClH,IAAI,OAAO,GAAG,EAAsB,CAAC;IACrC,IAAI,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC5C,IAAI,QAAQ,GAAG,EAA+E,CAAC;IAE/F,2DAA2D;IAC3D,4EAA4E;IAC5E,uEAAuE;IACvE,gBAAgB;IAChB,IAAI,SAAS,GAAY,KAAK,CAAC;IAC/B,IAAI,UAAU,GAAY,KAAK,CAAC;IAChC,IAAI,SAAS,GAAY,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IAAI,CAAC,UAAW,CAAC,CAAC;QACnF,KAAK,qBAAqB,CAAC;QAC3B,KAAK,kBAAkB;YACrB,OAAO,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,IAAI,0BAA0B,CAAC,IAAI,CAAC,UAAW,CAAC,CAAC;QACjF;YACE,OAAO,KAAK,CAAC;KAChB;AACH,CAAC","sourcesContent":["import traverse, { NodePath, Node } from '@babel/traverse';\nimport { TransformOptions, transformSync, types as t } from '@babel/core';\nimport { codeFrameColumns, SourceLocation } from '@babel/code-frame';\n\nexport class VisitorState {}\n\nexport interface InternalImport {\n source: string;\n codeFrameIndex: number | undefined;\n specifiers: {\n name: string | NamespaceMarker;\n local: string | null; // can be null when re-exporting, because in that case we import `name` from `source` but don't create any local binding for it\n codeFrameIndex: number | undefined;\n }[];\n}\n\nexport interface NamespaceMarker {\n isNamespace: true;\n}\n\nexport function isNamespaceMarker(value: string | NamespaceMarker): value is NamespaceMarker {\n return typeof value !== 'string';\n}\n\nexport interface ExportAll {\n all: string;\n}\n\n// babelConfig must include { ast: true }\nexport function auditJS(rawSource: string, filename: string, babelConfig: TransformOptions, frames: CodeFrameStorage) {\n let imports = [] as InternalImport[];\n let exports = new Set<string | ExportAll>();\n let problems = [] as { message: string; detail: string; codeFrameIndex: number | undefined }[];\n\n /* eslint-disable @typescript-eslint/no-inferrable-types */\n // These are not really inferrable. Without explicit declarations, TS thinks\n // they're always false because it doesn't know the handler methods run\n // synchronously\n let sawModule: boolean = false;\n let sawExports: boolean = false;\n let sawDefine: boolean = false;\n /* eslint-enable @typescript-eslint/no-inferrable-types */\n\n let { ast, code } = transformSync(rawSource, Object.assign({ filename: filename }, babelConfig))!;\n let saveCodeFrame = frames.forSource(rawSource);\n\n traverse(ast!, {\n Identifier(path: NodePath<t.Identifier>) {\n if (path.node.name === 'module' && isFreeVariable(path)) {\n sawModule = true;\n } else if (path.node.name === 'exports' && isFreeVariable(path)) {\n sawExports = true;\n } else if (path.node.name === 'define' && isFreeVariable(path)) {\n sawDefine = true;\n }\n if (inExportDeclarationContext(path)) {\n exports.add(path.node.name);\n }\n },\n CallExpression(path: NodePath<t.CallExpression>) {\n let callee = path.get('callee');\n if (callee.referencesImport('@embroider/macros', 'importSync') || t.isImport(callee)) {\n let arg = path.node.arguments[0];\n if (arg.type === 'StringLiteral') {\n imports.push({\n source: arg.value,\n codeFrameIndex: saveCodeFrame(arg),\n specifiers: [],\n });\n } else {\n problems.push({\n message: `audit tool is unable to understand this usage of ${t.isImport(callee) ? 'import' : 'importSync'}`,\n detail: arg.type,\n codeFrameIndex: saveCodeFrame(arg),\n });\n }\n }\n },\n ImportDeclaration(path: NodePath<t.ImportDeclaration>) {\n imports.push({\n source: path.node.source.value,\n codeFrameIndex: saveCodeFrame(path.node.source),\n specifiers: [],\n });\n },\n ImportDefaultSpecifier(path: NodePath<t.ImportDefaultSpecifier>) {\n imports[imports.length - 1].specifiers.push({\n name: 'default',\n local: path.node.local.name,\n codeFrameIndex: saveCodeFrame(path.node),\n });\n },\n ImportNamespaceSpecifier(path: NodePath<t.ImportNamespaceSpecifier>) {\n imports[imports.length - 1].specifiers.push({\n name: { isNamespace: true },\n local: path.node.local.name,\n codeFrameIndex: saveCodeFrame(path.node),\n });\n },\n ImportSpecifier(path: NodePath<t.ImportSpecifier>) {\n imports[imports.length - 1].specifiers.push({\n name: name(path.node.imported),\n local: path.node.local.name,\n codeFrameIndex: saveCodeFrame(path.node),\n });\n },\n ExportDefaultDeclaration(_path: NodePath<t.ExportDefaultDeclaration>) {\n exports.add('default');\n },\n ExportSpecifier(path: NodePath<t.ExportSpecifier>) {\n exports.add(name(path.node.exported));\n if (path.parent.type === 'ExportNamedDeclaration' && path.parent.source) {\n imports[imports.length - 1].specifiers.push({\n name: name(path.node.local),\n local: null, // re-exports don't create local bindings\n codeFrameIndex: saveCodeFrame(path.node),\n });\n }\n },\n ExportNamespaceSpecifier(path: NodePath<t.ExportNamespaceSpecifier>) {\n exports.add(name(path.node.exported));\n if (path.parent.type === 'ExportNamedDeclaration' && path.parent.source) {\n imports[imports.length - 1].specifiers.push({\n name: { isNamespace: true },\n local: null, // re-exports don't create local bindings\n codeFrameIndex: saveCodeFrame(path.node),\n });\n }\n },\n ExportAllDeclaration(path: NodePath<t.ExportAllDeclaration>) {\n exports.add({ all: path.node.source.value });\n imports.push({\n source: path.node.source.value,\n codeFrameIndex: saveCodeFrame(path.node.source),\n specifiers: [\n {\n name: { isNamespace: true },\n local: null,\n codeFrameIndex: saveCodeFrame(path.node),\n },\n ],\n });\n },\n ExportNamedDeclaration(path: NodePath<t.ExportNamedDeclaration>) {\n if (path.node.source) {\n imports.push({\n source: path.node.source.value,\n codeFrameIndex: saveCodeFrame(path.node.source),\n specifiers: [],\n });\n }\n },\n });\n\n let isCJS = imports.length === 0 && exports.size === 0 && (sawModule || sawExports);\n let isAMD = imports.length === 0 && exports.size === 0 && sawDefine;\n return { imports, exports, isCJS, isAMD, problems, transpiledContent: code! };\n}\n\nexport class CodeFrameStorage {\n private codeFrames = [] as { rawSourceIndex: number; loc: SourceLocation }[];\n private rawSources = [] as string[];\n\n forSource(rawSource: string): (node: { loc?: SourceLocation | null }) => number | undefined {\n let rawSourceIndex: number | undefined;\n return (node: { loc?: SourceLocation | null | undefined }) => {\n let loc = node.loc;\n if (!loc) {\n return;\n }\n if (rawSourceIndex == null) {\n rawSourceIndex = this.rawSources.length;\n this.rawSources.push(rawSource);\n }\n let codeFrameIndex = this.codeFrames.length;\n this.codeFrames.push({\n rawSourceIndex,\n loc,\n });\n return codeFrameIndex;\n };\n }\n\n render(codeFrameIndex: number | undefined): string | undefined {\n if (codeFrameIndex != null) {\n let { loc, rawSourceIndex } = this.codeFrames[codeFrameIndex];\n return codeFrameColumns(this.rawSources[rawSourceIndex], loc, { highlightCode: true });\n }\n }\n}\n\nfunction name(node: t.StringLiteral | t.Identifier): string {\n if (t.isStringLiteral(node)) {\n return node.value;\n } else {\n return node.name;\n }\n}\n\nfunction isFreeVariable(path: NodePath<t.Identifier>) {\n return !path.scope.hasBinding(path.node.name);\n}\n\nconst contextCache: WeakMap<Node, boolean> = new WeakMap();\n\nfunction inExportDeclarationContext(path: NodePath): boolean {\n if (contextCache.has(path.node)) {\n return contextCache.get(path.node)!;\n } else {\n let answer = _inExportDeclarationContext(path);\n contextCache.set(path.node, answer);\n return answer;\n }\n}\n\nfunction _inExportDeclarationContext(path: NodePath): boolean {\n let parent = path.parent;\n switch (parent.type) {\n case 'ExportNamedDeclaration':\n return parent.declaration === path.node;\n case 'VariableDeclaration':\n case 'ObjectPattern':\n case 'ArrayPattern':\n case 'RestElement':\n return inExportDeclarationContext(path.parentPath!);\n case 'VariableDeclarator':\n return parent.id === path.node && inExportDeclarationContext(path.parentPath!);\n case 'ObjectProperty':\n return parent.value === path.node && inExportDeclarationContext(path.parentPath!);\n case 'AssignmentPattern':\n return parent.left === path.node && inExportDeclarationContext(path.parentPath!);\n case 'FunctionDeclaration':\n case 'ClassDeclaration':\n return parent.id === path.node && inExportDeclarationContext(path.parentPath!);\n default:\n return false;\n }\n}\n"]}
@@ -1,57 +1,20 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
22
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
4
  };
24
5
  Object.defineProperty(exports, "__esModule", { value: true });
25
6
  exports.isBuildError = exports.BuildError = exports.buildApp = void 0;
26
7
  const chalk_1 = __importDefault(require("chalk"));
27
- const resolve_1 = __importDefault(require("resolve"));
28
- const capture_1 = require("./capture");
8
+ const child_process_1 = require("child_process");
29
9
  async function buildApp(options) {
30
- let { default: cli } = await Promise.resolve().then(() => __importStar(require(resolve_1.default.sync('ember-cli', { basedir: options.app }))));
31
- process.env.STAGE2_ONLY = 'true';
32
- let capture = new capture_1.CaptureStream();
33
- let orig = { cwd: process.cwd(), log: console.log, error: console.error, warn: console.warn };
34
- process.chdir(options.app);
35
- // this is icky, but too many things in the build don't respect the
36
- // `outputStream`, etc, options we pass below.
37
- console.log = console.warn = console.error = capture.log;
38
- try {
39
- let result = await cli({
40
- cliArgs: ['build'],
41
- outputStream: capture,
42
- errorStream: capture,
43
- });
44
- let exitCode = typeof result === 'object' ? result.exitCode : result;
45
- // an undefined exit code means success, because of course it does.
46
- if (exitCode != null && exitCode !== 0) {
47
- throw new BuildError(`${chalk_1.default.yellow('Unable to begin audit')} because the build failed. Build output follows:\n${capture.output}`);
48
- }
49
- }
50
- finally {
51
- process.chdir(orig.cwd);
52
- console.log = orig.log;
53
- console.warn = orig.warn;
54
- console.error = orig.error;
10
+ let result = await execute(`node node_modules/ember-cli/bin/ember build`, {
11
+ pwd: options.app,
12
+ env: {
13
+ STAGE2_ONLY: 'true',
14
+ },
15
+ });
16
+ if (result.exitCode !== 0) {
17
+ throw new BuildError(`${chalk_1.default.yellow('Unable to begin audit')} because the build failed. Build output follows:\n${result.output}`);
55
18
  }
56
19
  }
57
20
  exports.buildApp = buildApp;
@@ -66,4 +29,43 @@ function isBuildError(err) {
66
29
  return err === null || err === void 0 ? void 0 : err.isBuildError;
67
30
  }
68
31
  exports.isBuildError = isBuildError;
32
+ async function execute(shellCommand, opts) {
33
+ let env;
34
+ if (opts === null || opts === void 0 ? void 0 : opts.env) {
35
+ env = { ...process.env, ...opts.env };
36
+ }
37
+ let child = (0, child_process_1.spawn)(shellCommand, {
38
+ stdio: ['inherit', 'pipe', 'pipe'],
39
+ cwd: opts === null || opts === void 0 ? void 0 : opts.pwd,
40
+ shell: true,
41
+ env,
42
+ });
43
+ let stderrBuffer = [];
44
+ let stdoutBuffer = [];
45
+ let combinedBuffer = [];
46
+ child.stderr.on('data', data => {
47
+ stderrBuffer.push(data);
48
+ combinedBuffer.push(data);
49
+ });
50
+ child.stdout.on('data', data => {
51
+ stdoutBuffer.push(data);
52
+ combinedBuffer.push(data);
53
+ });
54
+ return new Promise(resolve => {
55
+ child.on('close', (exitCode) => {
56
+ resolve({
57
+ exitCode,
58
+ get stdout() {
59
+ return stdoutBuffer.join('');
60
+ },
61
+ get stderr() {
62
+ return stderrBuffer.join('');
63
+ },
64
+ get output() {
65
+ return combinedBuffer.join('');
66
+ },
67
+ });
68
+ });
69
+ });
70
+ }
69
71
  //# sourceMappingURL=build.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["build.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,sDAAoC;AAEpC,uCAA0C;AAEnC,KAAK,UAAU,QAAQ,CAAC,OAA0B;IACvD,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,wDAAa,iBAAa,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,GAAC,CAAC;IAC/F,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,MAAM,CAAC;IACjC,IAAI,OAAO,GAAG,IAAI,uBAAa,EAAE,CAAC;IAClC,IAAI,IAAI,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI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D,oCAEC","sourcesContent":["import chalk from 'chalk';\nimport resolveModule from 'resolve';\nimport { AuditBuildOptions } from '../audit';\nimport { CaptureStream } from './capture';\n\nexport async function buildApp(options: AuditBuildOptions): Promise<void> {\n let { default: cli } = await import(resolveModule.sync('ember-cli', { basedir: options.app }));\n process.env.STAGE2_ONLY = 'true';\n let capture = new CaptureStream();\n let orig = { cwd: process.cwd(), log: console.log, error: console.error, warn: console.warn };\n process.chdir(options.app);\n // this is icky, but too many things in the build don't respect the\n // `outputStream`, etc, options we pass below.\n console.log = console.warn = console.error = capture.log;\n try {\n let result = await cli({\n cliArgs: ['build'],\n outputStream: capture,\n errorStream: capture,\n });\n let exitCode = typeof result === 'object' ? result.exitCode : result;\n // an undefined exit code means success, because of course it does.\n if (exitCode != null && exitCode !== 0) {\n throw new BuildError(\n `${chalk.yellow('Unable to begin audit')} because the build failed. Build output follows:\\n${capture.output}`\n );\n }\n } finally {\n process.chdir(orig.cwd);\n console.log = orig.log;\n console.warn = orig.warn;\n console.error = orig.error;\n }\n}\n\nexport class BuildError extends Error {\n isBuildError = true;\n constructor(buildOutput: string) {\n super(buildOutput);\n }\n}\n\nexport function isBuildError(err: any): err is BuildError {\n return err?.isBuildError;\n}\n"]}
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["build.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,iDAAsC;AAE/B,KAAK,UAAU,QAAQ,CAAC,OAA0B;IACvD,IAAI,MAAM,GAAG,MAAM,OAAO,CAAC,6CAA6C,EAAE;QACxE,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,GAAG,EAAE;YACH,WAAW,EAAE,MAAM;SACpB;KACF,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,EAAE;QACzB,MAAM,IAAI,UAAU,CAClB,GAAG,eAAK,CAAC,MAAM,CAAC,uBAAuB,CAAC,qDAAqD,MAAM,CAAC,MAAM,EAAE,CAC7G,CAAC;KACH;AAC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B,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,QAAgB,EAAE,EAAE;YACrC,OAAO,CAAC;gBACN,QAAQ;gBACR,IAAI,MAAM;oBACR,OAAO,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC/B,CAAC;gBACD,IAAI,MAAM;oBACR,OAAO,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC/B,CAAC;gBACD,IAAI,MAAM;oBACR,OAAO,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACjC,CAAC;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import chalk from 'chalk';\nimport { AuditBuildOptions } from '../audit';\nimport { spawn } from 'child_process';\n\nexport async function buildApp(options: AuditBuildOptions): Promise<void> {\n let result = await execute(`node node_modules/ember-cli/bin/ember build`, {\n pwd: options.app,\n env: {\n STAGE2_ONLY: 'true',\n },\n });\n\n if (result.exitCode !== 0) {\n throw new BuildError(\n `${chalk.yellow('Unable to begin audit')} because the build failed. Build output follows:\\n${result.output}`\n );\n }\n}\n\nexport class BuildError extends Error {\n isBuildError = true;\n constructor(buildOutput: string) {\n super(buildOutput);\n }\n}\n\nexport function isBuildError(err: any): err is BuildError {\n return err?.isBuildError;\n}\n\nasync function execute(\n shellCommand: string,\n opts?: { env?: Record<string, string>; pwd?: string }\n): Promise<{\n exitCode: number;\n stderr: string;\n stdout: string;\n output: string;\n}> {\n let env: Record<string, string | undefined> | undefined;\n if (opts?.env) {\n env = { ...process.env, ...opts.env };\n }\n let child = spawn(shellCommand, {\n stdio: ['inherit', 'pipe', 'pipe'],\n cwd: opts?.pwd,\n shell: true,\n env,\n });\n let stderrBuffer: string[] = [];\n let stdoutBuffer: string[] = [];\n let combinedBuffer: string[] = [];\n child.stderr.on('data', data => {\n stderrBuffer.push(data);\n combinedBuffer.push(data);\n });\n child.stdout.on('data', data => {\n stdoutBuffer.push(data);\n combinedBuffer.push(data);\n });\n return new Promise(resolve => {\n child.on('close', (exitCode: number) => {\n resolve({\n exitCode,\n get stdout() {\n return stdoutBuffer.join('');\n },\n get stderr() {\n return stderrBuffer.join('');\n },\n get output() {\n return combinedBuffer.join('');\n },\n });\n });\n });\n}\n"]}
@@ -2,6 +2,7 @@ export interface AuditOptions {
2
2
  debug?: boolean;
3
3
  }
4
4
  export interface AuditBuildOptions extends AuditOptions {
5
- 'reuse-build': boolean;
6
- app: string;
5
+ 'reuse-build'?: boolean;
6
+ app?: string;
7
+ outputDir?: string;
7
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":"","sourcesContent":["export interface AuditOptions {\n debug?: boolean;\n}\n\nexport interface AuditBuildOptions extends AuditOptions {\n 'reuse-build': boolean;\n app: string;\n}\n"]}
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":"","sourcesContent":["export interface AuditOptions {\n debug?: boolean;\n}\n\nexport interface AuditBuildOptions extends AuditOptions {\n 'reuse-build'?: boolean;\n app?: string;\n outputDir?: string;\n}\n"]}
package/src/audit-cli.js CHANGED
File without changes
package/src/audit.d.ts CHANGED
@@ -1,6 +1,24 @@
1
+ /// <reference types="node" />
1
2
  import { ExportAll, InternalImport, NamespaceMarker } from './audit/babel-visitor';
2
3
  import { AuditBuildOptions, AuditOptions } from './audit/options';
3
4
  import { BuildError, isBuildError } from './audit/build';
5
+ export interface AuditMessage {
6
+ message: string;
7
+ detail: string;
8
+ loc: Loc;
9
+ source: string;
10
+ filename: string;
11
+ }
12
+ export interface Loc {
13
+ start: {
14
+ line: number;
15
+ column: number;
16
+ };
17
+ end: {
18
+ line: number;
19
+ column: number;
20
+ };
21
+ }
4
22
  export { AuditOptions, AuditBuildOptions, BuildError, isBuildError };
5
23
  export interface Finding {
6
24
  message: string;
@@ -9,12 +27,14 @@ export interface Finding {
9
27
  codeFrame?: string;
10
28
  }
11
29
  export interface Module {
30
+ appRelativePath: string;
12
31
  consumedFrom: (string | RootMarker)[];
13
32
  imports: Import[];
14
33
  exports: string[];
15
34
  resolutions: {
16
35
  [source: string]: string | null;
17
36
  };
37
+ content: string;
18
38
  }
19
39
  interface ResolutionFailure {
20
40
  isResolutionFailure: true;
@@ -27,6 +47,7 @@ interface InternalModule {
27
47
  isCJS: boolean;
28
48
  isAMD: boolean;
29
49
  dependencies: string[];
50
+ transpiledContent: string | Buffer;
30
51
  };
31
52
  resolved?: Map<string, string | ResolutionFailure>;
32
53
  linked?: {
@@ -53,6 +74,7 @@ export declare class Audit {
53
74
  private appDir;
54
75
  private options;
55
76
  private modules;
77
+ private virtualModules;
56
78
  private moduleQueue;
57
79
  private findings;
58
80
  private frames;
@@ -62,6 +84,8 @@ export declare class Audit {
62
84
  private get pkg();
63
85
  private get meta();
64
86
  private get babelConfig();
87
+ private get resolverParams();
88
+ private resolver;
65
89
  private debug;
66
90
  private visitorFor;
67
91
  private drainQueue;
@@ -76,7 +100,7 @@ export declare class Audit {
76
100
  private visitJS;
77
101
  private visitHBS;
78
102
  private visitJSON;
79
- private resolve;
103
+ private resolveDeps;
80
104
  private pushFinding;
81
105
  private scheduleVisit;
82
106
  }
package/src/audit.js CHANGED
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.isRootMarker = 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
- const resolve_1 = __importDefault(require("resolve"));
16
15
  const core_1 = require("@embroider/core");
17
16
  const typescript_memoize_1 = require("typescript-memoize");
18
17
  const chalk_1 = __importDefault(require("chalk"));
@@ -39,10 +38,11 @@ class AuditResults {
39
38
  this.findings = [];
40
39
  }
41
40
  static create(baseDir, findings, modules) {
42
- var _a, _b;
41
+ var _a, _b, _c, _d;
43
42
  let results = new this();
44
43
  for (let [filename, module] of modules) {
45
44
  let publicModule = {
45
+ appRelativePath: (0, core_1.explicitRelative)(baseDir, filename),
46
46
  consumedFrom: module.consumedFrom.map(entry => {
47
47
  if (isRootMarker(entry)) {
48
48
  return entry;
@@ -67,6 +67,9 @@ class AuditResults {
67
67
  }))
68
68
  : [],
69
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',
70
73
  };
71
74
  results.modules[(0, core_1.explicitRelative)(baseDir, filename)] = publicModule;
72
75
  }
@@ -126,19 +129,17 @@ class AuditResults {
126
129
  }
127
130
  exports.AuditResults = AuditResults;
128
131
  class Audit {
129
- constructor(appDir, options = {}) {
130
- this.appDir = appDir;
131
- this.options = options;
132
- this.modules = new Map();
133
- this.moduleQueue = new Set();
134
- this.findings = [];
135
- this.frames = new babel_visitor_1.CodeFrameStorage();
136
- }
137
132
  static async run(options) {
138
- if (!options['reuse-build']) {
139
- await (0, build_1.buildApp)(options);
133
+ let dir;
134
+ if (options.outputDir) {
135
+ dir = options.outputDir;
136
+ }
137
+ else {
138
+ if (!options['reuse-build']) {
139
+ await (0, build_1.buildApp)(options);
140
+ }
141
+ dir = await this.findStage2Output(options);
140
142
  }
141
- let dir = await this.findStage2Output(options);
142
143
  let audit = new this(dir, options);
143
144
  if (options['reuse-build']) {
144
145
  if (!audit.meta.babel.isParallelSafe) {
@@ -149,6 +150,9 @@ class Audit {
149
150
  }
150
151
  static async findStage2Output(options) {
151
152
  try {
153
+ if (!options.app) {
154
+ throw new Error(`AuditBuildOptions needs "app" directory`);
155
+ }
152
156
  return (0, fs_extra_1.readFileSync)((0, path_1.join)(options.app, 'dist/.stage2-output'), 'utf8');
153
157
  }
154
158
  catch (err) {
@@ -158,6 +162,16 @@ class Audit {
158
162
  throw err;
159
163
  }
160
164
  }
165
+ constructor(appDir, options = {}) {
166
+ this.appDir = appDir;
167
+ this.options = options;
168
+ this.modules = new Map();
169
+ this.virtualModules = new Map();
170
+ this.moduleQueue = new Set();
171
+ this.findings = [];
172
+ this.frames = new babel_visitor_1.CodeFrameStorage();
173
+ this.resolver = new core_1.Resolver(this.resolverParams);
174
+ }
161
175
  get pkg() {
162
176
  return (0, fs_extra_1.readJSONSync)((0, path_1.join)(this.appDir, 'package.json'));
163
177
  }
@@ -172,6 +186,9 @@ class Audit {
172
186
  config.ast = true;
173
187
  return config;
174
188
  }
189
+ get resolverParams() {
190
+ return (0, fs_extra_1.readJSONSync)((0, path_1.join)(this.appDir, '.embroider', 'resolver.json'));
191
+ }
175
192
  debug(message, ...args) {
176
193
  if (this.options.debug) {
177
194
  console.log(message, ...args);
@@ -197,7 +214,13 @@ class Audit {
197
214
  this.moduleQueue.delete(filename);
198
215
  this.debug('visit', filename);
199
216
  let visitor = this.visitorFor(filename);
200
- let content = (0, fs_extra_1.readFileSync)(filename);
217
+ let content;
218
+ if (this.virtualModules.has(filename)) {
219
+ content = this.virtualModules.get(filename);
220
+ }
221
+ else {
222
+ content = (0, fs_extra_1.readFileSync)(filename);
223
+ }
201
224
  // cast is safe because the only way to get into the queue is to go
202
225
  // through scheduleVisit, and scheduleVisit creates the entry in
203
226
  // this.modules.
@@ -212,17 +235,7 @@ class Audit {
212
235
  }
213
236
  else {
214
237
  module.parsed = visitResult;
215
- let resolved = new Map();
216
- for (let dep of visitResult.dependencies) {
217
- let depFilename = await this.resolve(dep, filename);
218
- if (depFilename) {
219
- resolved.set(dep, depFilename);
220
- if (!isResolutionFailure(depFilename)) {
221
- this.scheduleVisit(depFilename, filename);
222
- }
223
- }
224
- }
225
- module.resolved = resolved;
238
+ module.resolved = await this.resolveDeps(visitResult.dependencies, filename);
226
239
  }
227
240
  }
228
241
  }
@@ -364,6 +377,7 @@ class Audit {
364
377
  isCJS: false,
365
378
  isAMD: false,
366
379
  dependencies,
380
+ transpiledContent: content,
367
381
  };
368
382
  }
369
383
  async visitJS(filename, content) {
@@ -384,6 +398,7 @@ class Audit {
384
398
  isCJS: result.isCJS,
385
399
  isAMD: result.isAMD,
386
400
  dependencies: result.imports.map(i => i.source),
401
+ transpiledContent: result.transpiledContent,
387
402
  };
388
403
  }
389
404
  catch (err) {
@@ -423,24 +438,31 @@ class Audit {
423
438
  }
424
439
  return this.visitJS(filename, js);
425
440
  }
426
- async resolve(specifier, fromPath) {
427
- if (['@embroider/macros', '@ember/template-factory'].includes(specifier)) {
428
- return;
429
- }
430
- try {
431
- return resolve_1.default.sync(specifier, {
432
- basedir: (0, path_1.dirname)(fromPath),
433
- extensions: this.meta['resolvable-extensions'],
434
- });
435
- }
436
- catch (err) {
437
- if (err.code === 'MODULE_NOT_FOUND') {
438
- return { isResolutionFailure: true };
439
- }
440
- else {
441
- throw err;
441
+ async resolveDeps(deps, fromFile) {
442
+ let resolved = new Map();
443
+ for (let dep of deps) {
444
+ let resolution = await this.resolver.nodeResolve(dep, fromFile);
445
+ switch (resolution.type) {
446
+ case 'virtual':
447
+ this.virtualModules.set(resolution.filename, resolution.content);
448
+ resolved.set(dep, resolution.filename);
449
+ this.scheduleVisit(resolution.filename, fromFile);
450
+ break;
451
+ case 'not_found':
452
+ if (['@embroider/macros', '@ember/template-factory'].includes(dep)) {
453
+ // the audit process deliberately removes the @embroider/macros babel
454
+ // plugins, so the imports are still present and should be left alone.
455
+ continue;
456
+ }
457
+ resolved.set(dep, { isResolutionFailure: true });
458
+ break;
459
+ case 'real':
460
+ resolved.set(dep, resolution.filename);
461
+ this.scheduleVisit(resolution.filename, fromFile);
462
+ break;
442
463
  }
443
464
  }
465
+ return resolved;
444
466
  }
445
467
  pushFinding(finding) {
446
468
  this.findings.push(finding);