@embroider/compat 3.8.0 → 3.8.1-unstable.f779011

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 (97) hide show
  1. package/babel.js +1 -0
  2. package/package.json +15 -17
  3. package/src/audit/babel-visitor.js +7 -1
  4. package/src/audit/babel-visitor.js.map +1 -1
  5. package/src/audit/build.js.map +1 -1
  6. package/src/audit/options.d.ts +2 -1
  7. package/src/audit/options.js.map +1 -1
  8. package/src/audit.d.ts +7 -57
  9. package/src/audit.js +101 -301
  10. package/src/audit.js.map +1 -1
  11. package/src/babel-plugin-adjust-imports.js +19 -18
  12. package/src/babel-plugin-adjust-imports.js.map +1 -1
  13. package/src/babel.d.ts +17 -0
  14. package/src/babel.js +146 -0
  15. package/src/babel.js.map +1 -0
  16. package/src/compat-adapters/@ember-data/store.d.ts +1 -5
  17. package/src/compat-adapters/@ember-data/store.js +3 -15
  18. package/src/compat-adapters/@ember-data/store.js.map +1 -1
  19. package/src/compat-adapters/active-model-adapter.d.ts +1 -1
  20. package/src/compat-adapters/ember-asset-loader.d.ts +1 -1
  21. package/src/compat-adapters/ember-cli-addon-docs.d.ts +1 -1
  22. package/src/compat-adapters/ember-cli-fastboot.js +0 -1
  23. package/src/compat-adapters/ember-cli-fastboot.js.map +1 -1
  24. package/src/compat-adapters/ember-cli-mirage.js +0 -1
  25. package/src/compat-adapters/ember-cli-mirage.js.map +1 -1
  26. package/src/compat-adapters/ember-decorators.d.ts +1 -1
  27. package/src/compat-adapters/ember-fetch.d.ts +5 -0
  28. package/src/compat-adapters/{ember-macro-helpers.js → ember-fetch.js} +5 -4
  29. package/src/compat-adapters/ember-fetch.js.map +1 -0
  30. package/src/compat-adapters/ember-percy.d.ts +1 -1
  31. package/src/compat-adapters/ember-resolver.d.ts +4 -0
  32. package/src/compat-adapters/ember-resolver.js +21 -0
  33. package/src/compat-adapters/ember-resolver.js.map +1 -0
  34. package/src/compat-adapters/ember-scroll-modifiers.d.ts +1 -1
  35. package/src/compat-adapters/ember-source.d.ts +3 -6
  36. package/src/compat-adapters/ember-source.js +26 -41
  37. package/src/compat-adapters/ember-source.js.map +1 -1
  38. package/src/compat-adapters/ember-test-selectors.d.ts +1 -1
  39. package/src/compat-addons.js +1 -1
  40. package/src/compat-addons.js.map +1 -1
  41. package/src/compat-app-builder.d.ts +9 -64
  42. package/src/compat-app-builder.js +110 -1272
  43. package/src/compat-app-builder.js.map +1 -1
  44. package/src/compat-app.d.ts +4 -22
  45. package/src/compat-app.js +77 -218
  46. package/src/compat-app.js.map +1 -1
  47. package/src/content-for-config.d.ts +11 -0
  48. package/src/content-for-config.js +66 -0
  49. package/src/content-for-config.js.map +1 -0
  50. package/src/default-pipeline.d.ts +3 -5
  51. package/src/default-pipeline.js +11 -49
  52. package/src/default-pipeline.js.map +1 -1
  53. package/src/dependency-rules.d.ts +1 -0
  54. package/src/dependency-rules.js +19 -11
  55. package/src/dependency-rules.js.map +1 -1
  56. package/src/detect-babel-plugins.d.ts +1 -0
  57. package/src/detect-babel-plugins.js +14 -0
  58. package/src/detect-babel-plugins.js.map +1 -1
  59. package/src/http-audit.d.ts +13 -0
  60. package/src/http-audit.js +60 -0
  61. package/src/http-audit.js.map +1 -0
  62. package/src/index.d.ts +2 -2
  63. package/src/index.js +2 -4
  64. package/src/index.js.map +1 -1
  65. package/src/module-visitor.d.ts +52 -0
  66. package/src/module-visitor.js +285 -0
  67. package/src/module-visitor.js.map +1 -0
  68. package/src/options.d.ts +3 -3
  69. package/src/options.js +3 -2
  70. package/src/options.js.map +1 -1
  71. package/src/resolver-transform.js +56 -15
  72. package/src/resolver-transform.js.map +1 -1
  73. package/src/standalone-addon-build.js +6 -15
  74. package/src/standalone-addon-build.js.map +1 -1
  75. package/src/v1-config.d.ts +0 -8
  76. package/src/v1-config.js +1 -51
  77. package/src/v1-config.js.map +1 -1
  78. package/src/audit-cli.d.ts +0 -2
  79. package/src/audit-cli.js +0 -150
  80. package/src/audit-cli.js.map +0 -1
  81. package/src/compat-adapters/@ember-data/debug.d.ts +0 -6
  82. package/src/compat-adapters/@ember-data/debug.js +0 -22
  83. package/src/compat-adapters/@ember-data/debug.js.map +0 -1
  84. package/src/compat-adapters/ember-macro-helpers.d.ts +0 -4
  85. package/src/compat-adapters/ember-macro-helpers.js.map +0 -1
  86. package/src/rename-require-plugin.d.ts +0 -1
  87. package/src/rename-require-plugin.js +0 -15
  88. package/src/rename-require-plugin.js.map +0 -1
  89. package/src/sync-dir.d.ts +0 -8
  90. package/src/sync-dir.js +0 -68
  91. package/src/sync-dir.js.map +0 -1
  92. package/src/template-tag-codemod.d.ts +0 -13
  93. package/src/template-tag-codemod.js +0 -302
  94. package/src/template-tag-codemod.js.map +0 -1
  95. package/src/v1-appboot.d.ts +0 -14
  96. package/src/v1-appboot.js +0 -47
  97. package/src/v1-appboot.js.map +0 -1
package/babel.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./src/babel');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/compat",
3
- "version": "3.8.0",
3
+ "version": "3.8.1-unstable.f779011",
4
4
  "private": false,
5
5
  "description": "Backward compatibility layer for the Embroider build system.",
6
6
  "repository": {
@@ -12,13 +12,11 @@
12
12
  "author": "Edward Faulkner",
13
13
  "main": "src/index.js",
14
14
  "files": [
15
+ "babel.js",
15
16
  "src/**/*.js",
16
17
  "src/**/*.d.ts",
17
18
  "src/**/*.js.map"
18
19
  ],
19
- "bin": {
20
- "embroider-compat-audit": "./src/audit-cli.js"
21
- },
22
20
  "dependencies": {
23
21
  "@babel/code-frame": "^7.14.5",
24
22
  "@babel/core": "^7.14.5",
@@ -30,10 +28,10 @@
30
28
  "@babel/runtime": "^7.18.6",
31
29
  "@babel/traverse": "^7.14.5",
32
30
  "@types/babel__code-frame": "^7.0.2",
33
- "@types/yargs": "^17.0.3",
34
31
  "assert-never": "^1.1.0",
35
32
  "babel-import-util": "^2.0.0",
36
- "babel-plugin-ember-template-compilation": "^2.1.1",
33
+ "babel-plugin-debug-macros": "^1.0.2",
34
+ "babel-plugin-ember-template-compilation": "^2.3.0",
37
35
  "babel-plugin-syntax-dynamic-import": "^6.18.0",
38
36
  "babylon": "^6.18.0",
39
37
  "bind-decorator": "^1.0.11",
@@ -47,7 +45,7 @@
47
45
  "broccoli-source": "^3.0.1",
48
46
  "chalk": "^4.1.1",
49
47
  "debug": "^4.3.2",
50
- "escape-string-regexp": "^4.0.0",
48
+ "ember-source": "6.1.0-beta.1",
51
49
  "fast-sourcemap-concat": "^2.1.1",
52
50
  "fs-extra": "^9.1.0",
53
51
  "fs-tree-diff": "^2.0.1",
@@ -55,14 +53,14 @@
55
53
  "lodash": "^4.17.21",
56
54
  "pkg-up": "^3.1.0",
57
55
  "resolve": "^1.20.0",
56
+ "resolve.exports": "^2.0.2",
58
57
  "resolve-package-path": "^4.0.1",
59
58
  "semver": "^7.3.5",
60
59
  "symlink-or-copy": "^1.3.1",
61
60
  "tree-sync": "^2.1.0",
62
61
  "typescript-memoize": "^1.0.1",
63
62
  "walk-sync": "^3.0.0",
64
- "yargs": "^17.0.1",
65
- "@embroider/macros": "1.16.10"
63
+ "@embroider/macros": "1.16.11-unstable.f779011"
66
64
  },
67
65
  "devDependencies": {
68
66
  "@glimmer/syntax": "^0.84.3",
@@ -77,20 +75,20 @@
77
75
  "@types/js-string-escape": "^1.0.0",
78
76
  "@types/jsdom": "^16.2.11",
79
77
  "@types/lodash": "^4.14.170",
80
- "@types/node": "^15.12.2",
78
+ "@types/node": "^22.9.3",
81
79
  "@types/resolve": "^1.20.0",
82
80
  "@types/semver": "^7.3.6",
83
81
  "broccoli-node-api": "^1.7.0",
84
- "code-equality-assertions": "^0.9.0",
82
+ "code-equality-assertions": "^1.0.1",
85
83
  "ember-engines": "^0.8.19",
86
- "scenario-tester": "^2.1.2",
87
- "typescript": "^5.1.6",
88
- "@embroider/core": "^3.5.0",
89
- "@embroider/test-support": "0.36.0",
90
- "@embroider/sample-transforms": "0.0.0"
84
+ "scenario-tester": "^4.0.0",
85
+ "typescript": "^5.4.5",
86
+ "@embroider/core": "^3.5.1-unstable.f779011",
87
+ "@embroider/sample-transforms": "0.0.0",
88
+ "@embroider/test-support": "0.36.0"
91
89
  },
92
90
  "peerDependencies": {
93
- "@embroider/core": "^3.5.0"
91
+ "@embroider/core": "^3.5.1-unstable.f779011"
94
92
  },
95
93
  "engines": {
96
94
  "node": "12.* || 14.* || >= 16"
@@ -15,8 +15,10 @@ exports.VisitorState = VisitorState;
15
15
  function isNamespaceMarker(value) {
16
16
  return typeof value !== 'string';
17
17
  }
18
- // babelConfig must include { ast: true }
19
18
  function auditJS(rawSource, filename, babelConfig, frames) {
19
+ if (!babelConfig.ast) {
20
+ throw new Error(`module auditing requires a babel config with ast: true`);
21
+ }
20
22
  let imports = [];
21
23
  let exports = new Set();
22
24
  let problems = [];
@@ -46,6 +48,7 @@ function auditJS(rawSource, filename, babelConfig, frames) {
46
48
  }
47
49
  },
48
50
  CallExpression(path) {
51
+ var _a;
49
52
  let callee = path.get('callee');
50
53
  if (callee.referencesImport('@embroider/macros', 'importSync') || core_1.types.isImport(callee.node)) {
51
54
  let arg = path.node.arguments[0];
@@ -56,6 +59,9 @@ function auditJS(rawSource, filename, babelConfig, frames) {
56
59
  specifiers: [],
57
60
  });
58
61
  }
62
+ else if ((_a = arg.leadingComments) === null || _a === void 0 ? void 0 : _a.find(c => /@vite-ignore/.test(c.value))) {
63
+ // this is vite internals that we should ignore too
64
+ }
59
65
  else {
60
66
  problems.push({
61
67
  message: `audit tool is unable to understand this usage of ${core_1.types.isImport(callee.node) ? 'import' : 'importSync'}`,
@@ -1 +1 @@
1
- {"version":3,"file":"babel-visitor.js","sourceRoot":"","sources":["babel-visitor.ts"],"names":[],"mappings":";;;;;;AAuBA,8CAEC;AAOD,0BAkIC;AAjKD,+DAAuC;AAEvC,sCAAwD;AAExD,kDAAqD;AAErD,MAAa,YAAY;CAAG;AAA5B,oCAA4B;AA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C;AAED,SAAS,2BAA2B,CAAC,IAAc;IACjD,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACzB,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,wBAAwB;YAC3B,OAAO,MAAM,CAAC,WAAW,KAAK,IAAI,CAAC,IAAI,CAAC;QAC1C,KAAK,qBAAqB,CAAC;QAC3B,KAAK,eAAe,CAAC;QACrB,KAAK,cAAc,CAAC;QACpB,KAAK,aAAa;YAChB,OAAO,0BAA0B,CAAC,IAAI,CAAC,UAAW,CAAC,CAAC;QACtD,KAAK,oBAAoB;YACvB,OAAO,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,IAAI,0BAA0B,CAAC,IAAI,CAAC,UAAW,CAAC,CAAC;QACjF,KAAK,gBAAgB;YACnB,OAAO,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,IAAI,IAAI,0BAA0B,CAAC,IAAI,CAAC,UAAW,CAAC,CAAC;QACpF,KAAK,mBAAmB;YACtB,OAAO,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,0BAA0B,CAAC,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;IACjB,CAAC;AACH,CAAC","sourcesContent":["import type { NodePath, Node } from '@babel/traverse';\nimport traverse from '@babel/traverse';\nimport type { TransformOptions } from '@babel/core';\nimport { transformSync, types as t } from '@babel/core';\nimport type { SourceLocation } from '@babel/code-frame';\nimport { codeFrameColumns } 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.node)) {\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 ${\n t.isImport(callee.node) ? 'import' : 'importSync'\n }`,\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
+ {"version":3,"file":"babel-visitor.js","sourceRoot":"","sources":["babel-visitor.ts"],"names":[],"mappings":";;;;;;AAuBA,8CAEC;AAMD,0BAwIC;AAtKD,+DAAuC;AAEvC,sCAAwD;AAExD,kDAAqD;AAErD,MAAa,YAAY;CAAG;AAA5B,oCAA4B;AAgB5B,SAAgB,iBAAiB,CAAC,KAA+B;IAC/D,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAMD,SAAgB,OAAO,CAAC,SAAiB,EAAE,QAAgB,EAAE,WAA6B,EAAE,MAAwB;IAClH,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IAED,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,0DAA0D;IAE1D,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAA,oBAAa,EAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,WAAW,CAAC,CAAE,CAAC;IAClG,IAAI,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAEhD,IAAA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AAI,0BAA0B,CAAC,IAAI,CAAC,UAAW,CAAC,CAAC;QACpF,KAAK,mBAAmB;YACtB,OAAO,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,0BAA0B,CAAC,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;IACjB,CAAC;AACH,CAAC","sourcesContent":["import type { NodePath, Node } from '@babel/traverse';\nimport traverse from '@babel/traverse';\nimport type { TransformOptions } from '@babel/core';\nimport { transformSync, types as t } from '@babel/core';\nimport type { SourceLocation } from '@babel/code-frame';\nimport { codeFrameColumns } 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\nexport function auditJS(rawSource: string, filename: string, babelConfig: TransformOptions, frames: CodeFrameStorage) {\n if (!babelConfig.ast) {\n throw new Error(`module auditing requires a babel config with ast: true`);\n }\n\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.node)) {\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 if (arg.leadingComments?.find(c => /@vite-ignore/.test(c.value))) {\n // this is vite internals that we should ignore too\n } else {\n problems.push({\n message: `audit tool is unable to understand this usage of ${\n t.isImport(callee.node) ? 'import' : 'importSync'\n }`,\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 +1 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["build.ts"],"names":[],"mappings":";;;;;;AAIA,4BAaC;AASD,oCAEC;AA5BD,kDAA0B;AAE1B,iDAAsC;AAE/B,KAAK,UAAU,QAAQ,CAAC,OAA0B;IACvD,IAAI,MAAM,GAAG,MAAM,OAAO,CAAC,6CAA6C,EAAE;QACxE,GAAG,EAAE,OAA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C,CAAC;QACxB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;QAC7B,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,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 type { 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"]}
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["build.ts"],"names":[],"mappings":";;;;;;AAIA,4BAaC;AASD,oCAEC;AA5BD,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,CAAC;QAC1B,MAAM,IAAI,UAAU,CAClB,GAAG,eAAK,CAAC,MAAM,CAAC,uBAAuB,CAAC,qDAAqD,MAAM,CAAC,MAAM,EAAE,CAC7G,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAa,UAAW,SAAQ,KAAK;IAEnC,YAAY,WAAmB;QAC7B,KAAK,CAAC,WAAW,CAAC,CAAC;QAFrB,iBAAY,GAAG,IAAI,CAAC;IAGpB,CAAC;CACF;AALD,gCAKC;AAED,SAAgB,YAAY,CAAC,GAAQ;IACnC,OAAO,GAAG,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AAE,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 type { 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"]}
@@ -1,5 +1,6 @@
1
1
  export interface AuditOptions {
2
- debug?: boolean;
2
+ entrypoints: string[];
3
+ rootURL: string;
3
4
  }
4
5
  export interface AuditBuildOptions extends AuditOptions {
5
6
  'reuse-build'?: boolean;
@@ -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 entrypoints: string[];\n rootURL: string;\n}\n\nexport interface AuditBuildOptions extends AuditOptions {\n 'reuse-build'?: boolean;\n app: string;\n}\n"]}
package/src/audit.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { ExportAll, InternalImport, NamespaceMarker } from './audit/babel-visitor';
2
1
  import { AuditBuildOptions, AuditOptions } from './audit/options';
3
2
  import { BuildError, isBuildError } from './audit/build';
3
+ import { type Module } from './module-visitor';
4
4
  export interface AuditMessage {
5
5
  message: string;
6
6
  detail: string;
@@ -25,85 +25,35 @@ export interface Finding {
25
25
  detail: string;
26
26
  codeFrame?: string;
27
27
  }
28
- export interface Module {
29
- appRelativePath: string;
30
- consumedFrom: (string | RootMarker)[];
31
- imports: Import[];
32
- exports: string[];
33
- resolutions: {
34
- [source: string]: string | null;
35
- };
36
- content: string;
37
- }
38
- interface ResolutionFailure {
39
- isResolutionFailure: true;
40
- }
41
- interface InternalModule {
42
- consumedFrom: (string | RootMarker)[];
43
- parsed?: {
44
- imports: InternalImport[];
45
- exports: Set<string | ExportAll>;
46
- isCJS: boolean;
47
- isAMD: boolean;
48
- dependencies: string[];
49
- transpiledContent: string | Buffer;
50
- };
51
- resolved?: Map<string, string | ResolutionFailure>;
52
- linked?: {
53
- exports: Set<string>;
54
- };
55
- }
56
- export interface Import {
57
- source: string;
58
- specifiers: {
59
- name: string | NamespaceMarker;
60
- local: string | null;
61
- }[];
62
- }
63
28
  export declare class AuditResults {
64
29
  modules: {
65
30
  [file: string]: Module;
66
31
  };
67
32
  findings: Finding[];
68
- static create(baseDir: string, findings: Finding[], modules: Map<string, InternalModule>): AuditResults;
33
+ static create(baseDir: string, findings: Finding[], modules: Record<string, Module>): AuditResults;
69
34
  humanReadable(): string;
70
35
  get perfect(): boolean;
71
36
  }
72
37
  export declare class Audit {
73
38
  private originAppRoot;
74
39
  private options;
75
- private modules;
76
40
  private virtualModules;
77
- private moduleQueue;
78
41
  private findings;
79
42
  private frames;
80
43
  static run(options: AuditBuildOptions): Promise<AuditResults>;
81
- constructor(originAppRoot: string, options?: AuditOptions);
82
- private get pkg();
44
+ constructor(originAppRoot: string, options: AuditOptions);
83
45
  private get movedAppRoot();
84
- private get meta();
85
46
  private get babelConfig();
86
47
  private get resolverParams();
87
48
  private resolver;
88
- private debug;
89
- private visitorFor;
90
- private drainQueue;
91
49
  run(): Promise<AuditResults>;
50
+ private resolveId;
51
+ private load;
92
52
  private handleResolverError;
93
- private linkModules;
94
- private linkModule;
95
53
  private inspectModules;
96
54
  private inspectImports;
97
55
  private moduleProvidesName;
98
- private visitHTML;
99
- private visitJS;
100
- private visitHBS;
101
- private visitJSON;
102
- private resolveDeps;
56
+ private handleJSON;
103
57
  private pushFinding;
104
- private scheduleVisit;
105
- }
106
- export interface RootMarker {
107
- isRoot: true;
108
58
  }
109
- export declare function isRootMarker(value: string | RootMarker | undefined): value is RootMarker;
59
+ export { Module };