@embroider/compat 3.8.1-unstable.f779011 → 3.8.1

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/package.json +15 -13
  2. package/src/audit/babel-visitor.js +1 -7
  3. package/src/audit/babel-visitor.js.map +1 -1
  4. package/src/audit/build.js.map +1 -1
  5. package/src/audit/options.d.ts +1 -2
  6. package/src/audit/options.js.map +1 -1
  7. package/src/audit-cli.d.ts +2 -0
  8. package/src/audit-cli.js +150 -0
  9. package/src/audit-cli.js.map +1 -0
  10. package/src/audit.d.ts +57 -7
  11. package/src/audit.js +301 -101
  12. package/src/audit.js.map +1 -1
  13. package/src/babel-plugin-adjust-imports.js +18 -19
  14. package/src/babel-plugin-adjust-imports.js.map +1 -1
  15. package/src/compat-adapters/@ember-data/debug.d.ts +6 -0
  16. package/src/compat-adapters/@ember-data/debug.js +22 -0
  17. package/src/compat-adapters/@ember-data/debug.js.map +1 -0
  18. package/src/compat-adapters/@ember-data/store.d.ts +5 -1
  19. package/src/compat-adapters/@ember-data/store.js +15 -3
  20. package/src/compat-adapters/@ember-data/store.js.map +1 -1
  21. package/src/compat-adapters/active-model-adapter.d.ts +1 -1
  22. package/src/compat-adapters/ember-asset-loader.d.ts +1 -1
  23. package/src/compat-adapters/ember-cli-addon-docs.d.ts +1 -1
  24. package/src/compat-adapters/ember-cli-fastboot.js +1 -0
  25. package/src/compat-adapters/ember-cli-fastboot.js.map +1 -1
  26. package/src/compat-adapters/ember-cli-mirage.js +1 -0
  27. package/src/compat-adapters/ember-cli-mirage.js.map +1 -1
  28. package/src/compat-adapters/ember-decorators.d.ts +1 -1
  29. package/src/compat-adapters/ember-macro-helpers.d.ts +4 -0
  30. package/src/compat-adapters/{ember-fetch.js → ember-macro-helpers.js} +4 -5
  31. package/src/compat-adapters/ember-macro-helpers.js.map +1 -0
  32. package/src/compat-adapters/ember-percy.d.ts +1 -1
  33. package/src/compat-adapters/ember-scroll-modifiers.d.ts +1 -1
  34. package/src/compat-adapters/ember-source.d.ts +6 -3
  35. package/src/compat-adapters/ember-source.js +41 -26
  36. package/src/compat-adapters/ember-source.js.map +1 -1
  37. package/src/compat-adapters/ember-test-selectors.d.ts +1 -1
  38. package/src/compat-addons.js +1 -1
  39. package/src/compat-addons.js.map +1 -1
  40. package/src/compat-app-builder.d.ts +64 -9
  41. package/src/compat-app-builder.js +1272 -110
  42. package/src/compat-app-builder.js.map +1 -1
  43. package/src/compat-app.d.ts +22 -4
  44. package/src/compat-app.js +218 -77
  45. package/src/compat-app.js.map +1 -1
  46. package/src/default-pipeline.d.ts +5 -3
  47. package/src/default-pipeline.js +49 -11
  48. package/src/default-pipeline.js.map +1 -1
  49. package/src/dependency-rules.d.ts +0 -1
  50. package/src/dependency-rules.js +11 -19
  51. package/src/dependency-rules.js.map +1 -1
  52. package/src/detect-babel-plugins.d.ts +0 -1
  53. package/src/detect-babel-plugins.js +0 -14
  54. package/src/detect-babel-plugins.js.map +1 -1
  55. package/src/index.d.ts +2 -2
  56. package/src/index.js +4 -2
  57. package/src/index.js.map +1 -1
  58. package/src/options.d.ts +40 -3
  59. package/src/options.js +11 -3
  60. package/src/options.js.map +1 -1
  61. package/src/rename-require-plugin.d.ts +1 -0
  62. package/src/rename-require-plugin.js +15 -0
  63. package/src/rename-require-plugin.js.map +1 -0
  64. package/src/resolver-transform.js +15 -56
  65. package/src/resolver-transform.js.map +1 -1
  66. package/src/standalone-addon-build.js +15 -6
  67. package/src/standalone-addon-build.js.map +1 -1
  68. package/src/sync-dir.d.ts +8 -0
  69. package/src/sync-dir.js +68 -0
  70. package/src/sync-dir.js.map +1 -0
  71. package/src/template-tag-codemod.d.ts +13 -0
  72. package/src/template-tag-codemod.js +302 -0
  73. package/src/template-tag-codemod.js.map +1 -0
  74. package/src/v1-appboot.d.ts +14 -0
  75. package/src/v1-appboot.js +47 -0
  76. package/src/v1-appboot.js.map +1 -0
  77. package/src/v1-config.d.ts +8 -0
  78. package/src/v1-config.js +51 -1
  79. package/src/v1-config.js.map +1 -1
  80. package/babel.js +0 -1
  81. package/src/babel.d.ts +0 -17
  82. package/src/babel.js +0 -146
  83. package/src/babel.js.map +0 -1
  84. package/src/compat-adapters/ember-fetch.d.ts +0 -5
  85. package/src/compat-adapters/ember-fetch.js.map +0 -1
  86. package/src/compat-adapters/ember-resolver.d.ts +0 -4
  87. package/src/compat-adapters/ember-resolver.js +0 -21
  88. package/src/compat-adapters/ember-resolver.js.map +0 -1
  89. package/src/content-for-config.d.ts +0 -11
  90. package/src/content-for-config.js +0 -66
  91. package/src/content-for-config.js.map +0 -1
  92. package/src/http-audit.d.ts +0 -13
  93. package/src/http-audit.js +0 -60
  94. package/src/http-audit.js.map +0 -1
  95. package/src/module-visitor.d.ts +0 -52
  96. package/src/module-visitor.js +0 -285
  97. package/src/module-visitor.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/compat",
3
- "version": "3.8.1-unstable.f779011",
3
+ "version": "3.8.1",
4
4
  "private": false,
5
5
  "description": "Backward compatibility layer for the Embroider build system.",
6
6
  "repository": {
@@ -12,11 +12,13 @@
12
12
  "author": "Edward Faulkner",
13
13
  "main": "src/index.js",
14
14
  "files": [
15
- "babel.js",
16
15
  "src/**/*.js",
17
16
  "src/**/*.d.ts",
18
17
  "src/**/*.js.map"
19
18
  ],
19
+ "bin": {
20
+ "embroider-compat-audit": "./src/audit-cli.js"
21
+ },
20
22
  "dependencies": {
21
23
  "@babel/code-frame": "^7.14.5",
22
24
  "@babel/core": "^7.14.5",
@@ -28,10 +30,10 @@
28
30
  "@babel/runtime": "^7.18.6",
29
31
  "@babel/traverse": "^7.14.5",
30
32
  "@types/babel__code-frame": "^7.0.2",
33
+ "@types/yargs": "^17.0.3",
31
34
  "assert-never": "^1.1.0",
32
35
  "babel-import-util": "^2.0.0",
33
- "babel-plugin-debug-macros": "^1.0.2",
34
- "babel-plugin-ember-template-compilation": "^2.3.0",
36
+ "babel-plugin-ember-template-compilation": "^2.1.1",
35
37
  "babel-plugin-syntax-dynamic-import": "^6.18.0",
36
38
  "babylon": "^6.18.0",
37
39
  "bind-decorator": "^1.0.11",
@@ -45,7 +47,7 @@
45
47
  "broccoli-source": "^3.0.1",
46
48
  "chalk": "^4.1.1",
47
49
  "debug": "^4.3.2",
48
- "ember-source": "6.1.0-beta.1",
50
+ "escape-string-regexp": "^4.0.0",
49
51
  "fast-sourcemap-concat": "^2.1.1",
50
52
  "fs-extra": "^9.1.0",
51
53
  "fs-tree-diff": "^2.0.1",
@@ -53,14 +55,14 @@
53
55
  "lodash": "^4.17.21",
54
56
  "pkg-up": "^3.1.0",
55
57
  "resolve": "^1.20.0",
56
- "resolve.exports": "^2.0.2",
57
58
  "resolve-package-path": "^4.0.1",
58
59
  "semver": "^7.3.5",
59
60
  "symlink-or-copy": "^1.3.1",
60
61
  "tree-sync": "^2.1.0",
61
62
  "typescript-memoize": "^1.0.1",
62
63
  "walk-sync": "^3.0.0",
63
- "@embroider/macros": "1.16.11-unstable.f779011"
64
+ "yargs": "^17.0.1",
65
+ "@embroider/macros": "1.16.10"
64
66
  },
65
67
  "devDependencies": {
66
68
  "@glimmer/syntax": "^0.84.3",
@@ -75,20 +77,20 @@
75
77
  "@types/js-string-escape": "^1.0.0",
76
78
  "@types/jsdom": "^16.2.11",
77
79
  "@types/lodash": "^4.14.170",
78
- "@types/node": "^22.9.3",
80
+ "@types/node": "^15.12.2",
79
81
  "@types/resolve": "^1.20.0",
80
82
  "@types/semver": "^7.3.6",
81
83
  "broccoli-node-api": "^1.7.0",
82
- "code-equality-assertions": "^1.0.1",
84
+ "code-equality-assertions": "^0.9.0",
83
85
  "ember-engines": "^0.8.19",
84
- "scenario-tester": "^4.0.0",
85
- "typescript": "^5.4.5",
86
- "@embroider/core": "^3.5.1-unstable.f779011",
86
+ "scenario-tester": "^2.1.2",
87
+ "typescript": "^5.1.6",
87
88
  "@embroider/sample-transforms": "0.0.0",
89
+ "@embroider/core": "^3.5.0",
88
90
  "@embroider/test-support": "0.36.0"
89
91
  },
90
92
  "peerDependencies": {
91
- "@embroider/core": "^3.5.1-unstable.f779011"
93
+ "@embroider/core": "^3.5.0"
92
94
  },
93
95
  "engines": {
94
96
  "node": "12.* || 14.* || >= 16"
@@ -15,10 +15,8 @@ exports.VisitorState = VisitorState;
15
15
  function isNamespaceMarker(value) {
16
16
  return typeof value !== 'string';
17
17
  }
18
+ // babelConfig must include { ast: true }
18
19
  function auditJS(rawSource, filename, babelConfig, frames) {
19
- if (!babelConfig.ast) {
20
- throw new Error(`module auditing requires a babel config with ast: true`);
21
- }
22
20
  let imports = [];
23
21
  let exports = new Set();
24
22
  let problems = [];
@@ -48,7 +46,6 @@ function auditJS(rawSource, filename, babelConfig, frames) {
48
46
  }
49
47
  },
50
48
  CallExpression(path) {
51
- var _a;
52
49
  let callee = path.get('callee');
53
50
  if (callee.referencesImport('@embroider/macros', 'importSync') || core_1.types.isImport(callee.node)) {
54
51
  let arg = path.node.arguments[0];
@@ -59,9 +56,6 @@ function auditJS(rawSource, filename, babelConfig, frames) {
59
56
  specifiers: [],
60
57
  });
61
58
  }
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
- }
65
59
  else {
66
60
  problems.push({
67
61
  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;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,OAA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I,MAAM,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;QAC/C,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACpC,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC;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\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
+ {"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;AAgB5B,SAAgB,iBAAiB,CAAC,KAA+B;IAC/D,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;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,0DAA0D;IAE1D,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAA,oBAAa,EAAC,SAAS,E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AA0B,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 +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,OAAO,CAAC,GAAG;QAChB,GAAG,EAAE;YACH,WAAW,EAAE,MAAM;SACpB;KACF,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,QAAQ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C,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;QAC9B,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,aAAH,GAAG,uBAAH,GAAG,CAAE,YAAY,CAAC;AAC3B,CAAC;AAED,KAAK,UAAU,OAAO,CACpB,YAAoB,EACpB,IAAqD;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AC/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,6 +1,5 @@
1
1
  export interface AuditOptions {
2
- entrypoints: string[];
3
- rootURL: string;
2
+ debug?: boolean;
4
3
  }
5
4
  export interface AuditBuildOptions extends AuditOptions {
6
5
  'reuse-build'?: boolean;
@@ -1 +1 @@
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"]}
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"]}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_extra_1 = require("fs-extra");
8
+ const path_1 = require("path");
9
+ const yargs_1 = __importDefault(require("yargs/yargs"));
10
+ const audit_1 = require("./audit");
11
+ // slightly wacky because yargs types don't cover this, but you can't access the
12
+ // other documented place to find `hideBin` on node < 12.17
13
+ const { hideBin } = yargs_1.default;
14
+ function runCLI() {
15
+ return (0, yargs_1.default)(hideBin(process.argv))
16
+ .command('$0', 'audit your app for embroider compatibility problems', yargs => {
17
+ return yargs
18
+ .option('debug', {
19
+ alias: 'd',
20
+ type: 'boolean',
21
+ description: 'Add debug logging about the audit itself',
22
+ default: false,
23
+ })
24
+ .option('json', {
25
+ alias: 'j',
26
+ type: 'boolean',
27
+ description: 'Print results in JSON format',
28
+ default: false,
29
+ })
30
+ .option('reuse-build', {
31
+ alias: 'r',
32
+ type: 'boolean',
33
+ description: 'Reuse previous build',
34
+ default: false,
35
+ })
36
+ .option('load', {
37
+ alias: 'l',
38
+ type: 'string',
39
+ description: 'Load previous audit results from a JSON file instead of running a new audit',
40
+ })
41
+ .option('save', {
42
+ alias: 's',
43
+ type: 'string',
44
+ description: 'Save audit results as a JSON file.',
45
+ })
46
+ .option('app', {
47
+ type: 'string',
48
+ description: 'Path to your app',
49
+ default: process.cwd(),
50
+ })
51
+ .option('filter', {
52
+ type: 'string',
53
+ description: 'Path to a JS file that describes which findings to silence. Generate the initial file using `--create-filter`.',
54
+ })
55
+ .option('create-filter', {
56
+ type: 'string',
57
+ description: 'Path to a JS file where we will create a filter that will silence all your current findings. Pass it back into future audits via --filter',
58
+ })
59
+ .fail(function (_, err, _yargs) {
60
+ if ((0, audit_1.isBuildError)(err)) {
61
+ process.stderr.write(err.message + '\n');
62
+ }
63
+ else {
64
+ console.error(err);
65
+ }
66
+ process.exit(1);
67
+ });
68
+ }, async (options) => {
69
+ let filter = loadFilter(options);
70
+ let results;
71
+ if (options.load) {
72
+ results = new audit_1.AuditResults();
73
+ Object.assign(results, (0, fs_extra_1.readJSONSync)(options.load));
74
+ }
75
+ else {
76
+ results = await audit_1.Audit.run(options);
77
+ }
78
+ if (options.save) {
79
+ (0, fs_extra_1.writeFileSync)(options.save, JSON.stringify(results, null, 2));
80
+ }
81
+ applyFilter(filter, results);
82
+ if (options.json) {
83
+ process.stdout.write(JSON.stringify(results, null, 2) + '\n');
84
+ }
85
+ else {
86
+ process.stdout.write(results.humanReadable());
87
+ }
88
+ if (options['create-filter']) {
89
+ createFilter(options['create-filter'], results);
90
+ }
91
+ process.exit(results.perfect ? 0 : 1);
92
+ })
93
+ .command('pretty', 'format JSON audit results as pretty human-readable results', yargs => {
94
+ return yargs.option('filter', {
95
+ type: 'string',
96
+ description: 'Path to a JS file that describes which findings to silence. Generate the file using `embroider-compat-audit acknowledge`',
97
+ });
98
+ }, async (options) => {
99
+ let filter = loadFilter(options);
100
+ let results = new audit_1.AuditResults();
101
+ // process.stdin.fd is a documented public API. The Node typings don't
102
+ // seem to know about it.
103
+ Object.assign(results, JSON.parse((0, fs_extra_1.readFileSync)(process.stdin.fd, 'utf8')));
104
+ applyFilter(filter, results);
105
+ process.stdout.write(results.humanReadable());
106
+ process.exit(0);
107
+ })
108
+ .command('acknowledge', 'Pipe your audit JSON to this command to generate a filter file that will silence the current issues. Pass the filter file into your next audit via --filter. Delete findings out of the filter file as you address them.', yargs => yargs, async () => {
109
+ let results = new audit_1.AuditResults();
110
+ // process.stdin.fd is a documented public API. The Node typings don't
111
+ // seem to know about it.
112
+ Object.assign(results, JSON.parse((0, fs_extra_1.readFileSync)(process.stdin.fd, 'utf8')));
113
+ let findings = results.findings.map(f => ({
114
+ filename: f.filename,
115
+ message: f.message,
116
+ detail: f.detail,
117
+ }));
118
+ process.stdout.write(`module.exports = ${JSON.stringify({ findings }, null, 2)};\n`);
119
+ process.exit(0);
120
+ }).argv;
121
+ }
122
+ if (require.main === module) {
123
+ runCLI();
124
+ }
125
+ function loadFilter(options) {
126
+ if (options.filter) {
127
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
128
+ return require((0, path_1.resolve)(options.filter));
129
+ }
130
+ }
131
+ function applyFilter(filter, results) {
132
+ if (filter) {
133
+ results.findings = results.findings.filter(finding => {
134
+ return !filter.findings.find(filtered => {
135
+ return (filtered.message === finding.message &&
136
+ filtered.detail === finding.detail &&
137
+ filtered.filename === finding.filename);
138
+ });
139
+ });
140
+ }
141
+ }
142
+ function createFilter(filename, results) {
143
+ let findings = results.findings.map(f => ({
144
+ filename: f.filename,
145
+ message: f.message,
146
+ detail: f.detail,
147
+ }));
148
+ (0, fs_extra_1.writeFileSync)(filename, `module.exports = ${JSON.stringify({ findings }, null, 2)};\n`);
149
+ }
150
+ //# sourceMappingURL=audit-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-cli.js","sourceRoot":"","sources":["audit-cli.ts"],"names":[],"mappings":";;;;;;AAEA,uCAAqE;AACrE,+BAA+B;AAC/B,wDAAgC;AAEhC,mCAA4D;AAE5D,gFAAgF;A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AAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,QAAgB,EAAE,OAAqB;IAC3D,IAAI,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACxC,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,MAAM,EAAE,CAAC,CAAC,MAAM;KACjB,CAAC,CAAC,CAAC;IACJ,IAAA,wBAAa,EAAC,QAAQ,EAAE,oBAAoB,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;AAC1F,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { readFileSync, readJSONSync, writeFileSync } from 'fs-extra';\nimport { resolve } from 'path';\nimport yargs from 'yargs/yargs';\nimport type { Finding } from './audit';\nimport { Audit, AuditResults, isBuildError } from './audit';\n\n// slightly wacky because yargs types don't cover this, but you can't access the\n// other documented place to find `hideBin` on node < 12.17\nconst { hideBin } = yargs as any as {\n hideBin(argv: readonly string[]): readonly string[];\n};\n\nfunction runCLI() {\n return yargs(hideBin(process.argv))\n .command(\n '$0',\n 'audit your app for embroider compatibility problems',\n yargs => {\n return yargs\n .option('debug', {\n alias: 'd',\n type: 'boolean',\n description: 'Add debug logging about the audit itself',\n default: false,\n })\n .option('json', {\n alias: 'j',\n type: 'boolean',\n description: 'Print results in JSON format',\n default: false,\n })\n .option('reuse-build', {\n alias: 'r',\n type: 'boolean',\n description: 'Reuse previous build',\n default: false,\n })\n .option('load', {\n alias: 'l',\n type: 'string',\n description: 'Load previous audit results from a JSON file instead of running a new audit',\n })\n .option('save', {\n alias: 's',\n type: 'string',\n description: 'Save audit results as a JSON file.',\n })\n .option('app', {\n type: 'string',\n description: 'Path to your app',\n default: process.cwd(),\n })\n .option('filter', {\n type: 'string',\n description:\n 'Path to a JS file that describes which findings to silence. Generate the initial file using `--create-filter`.',\n })\n .option('create-filter', {\n type: 'string',\n description:\n 'Path to a JS file where we will create a filter that will silence all your current findings. Pass it back into future audits via --filter',\n })\n .fail(function (_, err, _yargs) {\n if (isBuildError(err)) {\n process.stderr.write(err.message + '\\n');\n } else {\n console.error(err);\n }\n process.exit(1);\n });\n },\n async options => {\n let filter = loadFilter(options);\n let results: AuditResults;\n if (options.load) {\n results = new AuditResults();\n Object.assign(results, readJSONSync(options.load));\n } else {\n results = await Audit.run(options);\n }\n if (options.save) {\n writeFileSync(options.save, JSON.stringify(results, null, 2));\n }\n applyFilter(filter, results);\n if (options.json) {\n process.stdout.write(JSON.stringify(results, null, 2) + '\\n');\n } else {\n process.stdout.write(results.humanReadable());\n }\n if (options['create-filter']) {\n createFilter(options['create-filter'], results);\n }\n process.exit(results.perfect ? 0 : 1);\n }\n )\n .command(\n 'pretty',\n 'format JSON audit results as pretty human-readable results',\n yargs => {\n return yargs.option('filter', {\n type: 'string',\n description:\n 'Path to a JS file that describes which findings to silence. Generate the file using `embroider-compat-audit acknowledge`',\n });\n },\n async options => {\n let filter = loadFilter(options);\n let results = new AuditResults();\n // process.stdin.fd is a documented public API. The Node typings don't\n // seem to know about it.\n Object.assign(results, JSON.parse(readFileSync((process.stdin as any).fd, 'utf8')));\n applyFilter(filter, results);\n process.stdout.write(results.humanReadable());\n process.exit(0);\n }\n )\n .command(\n 'acknowledge',\n 'Pipe your audit JSON to this command to generate a filter file that will silence the current issues. Pass the filter file into your next audit via --filter. Delete findings out of the filter file as you address them.',\n yargs => yargs,\n async () => {\n let results = new AuditResults();\n // process.stdin.fd is a documented public API. The Node typings don't\n // seem to know about it.\n Object.assign(results, JSON.parse(readFileSync((process.stdin as any).fd, 'utf8')));\n let findings = results.findings.map(f => ({\n filename: f.filename,\n message: f.message,\n detail: f.detail,\n }));\n process.stdout.write(`module.exports = ${JSON.stringify({ findings }, null, 2)};\\n`);\n process.exit(0);\n }\n ).argv;\n}\n\nif (require.main === module) {\n runCLI();\n}\n\ntype Filter = { findings: Omit<Finding, 'codeFrame'>[] };\n\nfunction loadFilter(options: { filter: string | undefined }): Filter | undefined {\n if (options.filter) {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n return require(resolve(options.filter));\n }\n}\n\nfunction applyFilter(filter: Filter | undefined, results: AuditResults) {\n if (filter) {\n results.findings = results.findings.filter(finding => {\n return !filter!.findings.find(filtered => {\n return (\n filtered.message === finding.message &&\n filtered.detail === finding.detail &&\n filtered.filename === finding.filename\n );\n });\n });\n }\n}\n\nfunction createFilter(filename: string, results: AuditResults) {\n let findings = results.findings.map(f => ({\n filename: f.filename,\n message: f.message,\n detail: f.detail,\n }));\n writeFileSync(filename, `module.exports = ${JSON.stringify({ findings }, null, 2)};\\n`);\n}\n"]}
package/src/audit.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import type { ExportAll, InternalImport, NamespaceMarker } from './audit/babel-visitor';
1
2
  import { AuditBuildOptions, AuditOptions } from './audit/options';
2
3
  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,35 +25,85 @@ 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
+ }
28
63
  export declare class AuditResults {
29
64
  modules: {
30
65
  [file: string]: Module;
31
66
  };
32
67
  findings: Finding[];
33
- static create(baseDir: string, findings: Finding[], modules: Record<string, Module>): AuditResults;
68
+ static create(baseDir: string, findings: Finding[], modules: Map<string, InternalModule>): AuditResults;
34
69
  humanReadable(): string;
35
70
  get perfect(): boolean;
36
71
  }
37
72
  export declare class Audit {
38
73
  private originAppRoot;
39
74
  private options;
75
+ private modules;
40
76
  private virtualModules;
77
+ private moduleQueue;
41
78
  private findings;
42
79
  private frames;
43
80
  static run(options: AuditBuildOptions): Promise<AuditResults>;
44
- constructor(originAppRoot: string, options: AuditOptions);
81
+ constructor(originAppRoot: string, options?: AuditOptions);
82
+ private get pkg();
45
83
  private get movedAppRoot();
84
+ private get meta();
46
85
  private get babelConfig();
47
86
  private get resolverParams();
48
87
  private resolver;
88
+ private debug;
89
+ private visitorFor;
90
+ private drainQueue;
49
91
  run(): Promise<AuditResults>;
50
- private resolveId;
51
- private load;
52
92
  private handleResolverError;
93
+ private linkModules;
94
+ private linkModule;
53
95
  private inspectModules;
54
96
  private inspectImports;
55
97
  private moduleProvidesName;
56
- private handleJSON;
98
+ private visitHTML;
99
+ private visitJS;
100
+ private visitHBS;
101
+ private visitJSON;
102
+ private resolveDeps;
57
103
  private pushFinding;
104
+ private scheduleVisit;
105
+ }
106
+ export interface RootMarker {
107
+ isRoot: true;
58
108
  }
59
- export { Module };
109
+ export declare function isRootMarker(value: string | RootMarker | undefined): value is RootMarker;