@embroider/compat 3.4.9 → 3.5.1-unstable.14b84ff
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.
- package/package.json +13 -13
- package/src/audit/babel-visitor.js +5 -3
- package/src/audit/babel-visitor.js.map +1 -1
- package/src/audit/build.js.map +1 -1
- package/src/audit-cli.js.map +1 -1
- package/src/audit.d.ts +6 -54
- package/src/audit.js +86 -275
- package/src/audit.js.map +1 -1
- package/src/babel-plugin-adjust-imports.d.ts +2 -1
- package/src/babel-plugin-adjust-imports.js +1 -1
- package/src/babel-plugin-adjust-imports.js.map +1 -1
- package/src/build-compat-addon.js.map +1 -1
- package/src/compat-adapters/@ember/test-waiters.js.map +1 -1
- package/src/compat-adapters/@ember-data/store.d.ts +1 -5
- package/src/compat-adapters/@ember-data/store.js +3 -15
- package/src/compat-adapters/@ember-data/store.js.map +1 -1
- package/src/compat-adapters/ember-asset-loader.js.map +1 -1
- package/src/compat-adapters/ember-cli-babel.js.map +1 -1
- package/src/compat-adapters/ember-cli-fastboot.js.map +1 -1
- package/src/compat-adapters/ember-cli-mirage.js.map +1 -1
- package/src/compat-adapters/ember-composable-helpers.js.map +1 -1
- package/src/compat-adapters/ember-data.js.map +1 -1
- package/src/compat-adapters/ember-engines.js.map +1 -1
- package/src/compat-adapters/ember-fetch.d.ts +5 -0
- package/src/compat-adapters/ember-fetch.js +19 -0
- package/src/compat-adapters/ember-fetch.js.map +1 -0
- package/src/compat-adapters/ember-macro-helpers.js.map +1 -1
- package/src/compat-adapters/ember-scroll-modifiers.js.map +1 -1
- package/src/compat-adapters/ember-source.js +20 -2
- package/src/compat-adapters/ember-source.js.map +1 -1
- package/src/compat-adapters/ember-svg-jar.js.map +1 -1
- package/src/compat-addons.js.map +1 -1
- package/src/compat-app-builder.d.ts +7 -17
- package/src/compat-app-builder.js +94 -559
- package/src/compat-app-builder.js.map +1 -1
- package/src/compat-app.d.ts +2 -3
- package/src/compat-app.js +60 -20
- package/src/compat-app.js.map +1 -1
- package/src/compat-utils.js.map +1 -1
- package/src/content-for-config.d.ts +11 -0
- package/src/content-for-config.js +66 -0
- package/src/content-for-config.js.map +1 -0
- package/src/dasherize-component-name.js.map +1 -1
- package/src/default-pipeline.d.ts +2 -2
- package/src/default-pipeline.js +22 -1
- package/src/default-pipeline.js.map +1 -1
- package/src/dependency-rules.js.map +1 -1
- package/src/detect-babel-plugins.js.map +1 -1
- package/src/detect-compact-reexports.js.map +1 -1
- package/src/dummy-package.js.map +1 -1
- package/src/empty-package-tree.js.map +1 -1
- package/src/get-real-addon.js.map +1 -1
- package/src/hbs-to-js-broccoli-plugin.js.map +1 -1
- package/src/http-audit.d.ts +13 -0
- package/src/http-audit.js +46 -0
- package/src/http-audit.js.map +1 -0
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -1
- package/src/index.js.map +1 -1
- package/src/merges.js.map +1 -1
- package/src/module-visitor.d.ts +53 -0
- package/src/module-visitor.js +286 -0
- package/src/module-visitor.js.map +1 -0
- package/src/options.d.ts +1 -0
- package/src/options.js +1 -0
- package/src/options.js.map +1 -1
- package/src/prepare-htmlbars-ast-plugins.js.map +1 -1
- package/src/rename-require-plugin.js.map +1 -1
- package/src/resolver-transform.js +3 -0
- package/src/resolver-transform.js.map +1 -1
- package/src/rewrite-addon-tree.js.map +1 -1
- package/src/smoosh-package-json.js.map +1 -1
- package/src/snitch.js.map +1 -1
- package/src/standalone-addon-build.js.map +1 -1
- package/src/sync-dir.js.map +1 -1
- package/src/synthesize-template-only-components.js.map +1 -1
- package/src/v1-addon.js.map +1 -1
- package/src/v1-appboot.js.map +1 -1
- package/src/v1-config.js.map +1 -1
- package/src/v1-instance-cache.js.map +1 -1
- package/LICENSE +0 -21
- package/src/compat-adapters/@ember-data/debug.d.ts +0 -6
- package/src/compat-adapters/@ember-data/debug.js +0 -22
- package/src/compat-adapters/@ember-data/debug.js.map +0 -1
package/src/audit.js
CHANGED
|
@@ -9,72 +9,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.Audit = exports.AuditResults = exports.isBuildError = exports.BuildError = void 0;
|
|
13
13
|
const fs_extra_1 = require("fs-extra");
|
|
14
14
|
const path_1 = require("path");
|
|
15
15
|
const core_1 = require("@embroider/core");
|
|
16
16
|
const typescript_memoize_1 = require("typescript-memoize");
|
|
17
17
|
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
-
const jsdom_1 = __importDefault(require("jsdom"));
|
|
19
18
|
const groupBy_1 = __importDefault(require("lodash/groupBy"));
|
|
20
|
-
const fromPairs_1 = __importDefault(require("lodash/fromPairs"));
|
|
21
19
|
const babel_visitor_1 = require("./audit/babel-visitor");
|
|
22
20
|
const build_1 = require("./audit/build");
|
|
23
21
|
Object.defineProperty(exports, "BuildError", { enumerable: true, get: function () { return build_1.BuildError; } });
|
|
24
22
|
Object.defineProperty(exports, "isBuildError", { enumerable: true, get: function () { return build_1.isBuildError; } });
|
|
25
|
-
const
|
|
26
|
-
function isResolutionFailure(result) {
|
|
27
|
-
return typeof result === 'object' && 'isResolutionFailure' in result;
|
|
28
|
-
}
|
|
29
|
-
function isResolved(module) {
|
|
30
|
-
return Boolean((module === null || module === void 0 ? void 0 : module.parsed) && module.resolved);
|
|
31
|
-
}
|
|
32
|
-
function isLinked(module) {
|
|
33
|
-
return Boolean((module === null || module === void 0 ? void 0 : module.parsed) && module.resolved && module.linked);
|
|
34
|
-
}
|
|
23
|
+
const module_visitor_1 = require("./module-visitor");
|
|
35
24
|
class AuditResults {
|
|
36
25
|
constructor() {
|
|
37
26
|
this.modules = {};
|
|
38
27
|
this.findings = [];
|
|
39
28
|
}
|
|
40
29
|
static create(baseDir, findings, modules) {
|
|
41
|
-
var _a, _b, _c, _d;
|
|
42
30
|
let results = new this();
|
|
43
|
-
|
|
44
|
-
let publicModule = {
|
|
45
|
-
appRelativePath: (0, core_1.explicitRelative)(baseDir, filename),
|
|
46
|
-
consumedFrom: module.consumedFrom.map(entry => {
|
|
47
|
-
if (isRootMarker(entry)) {
|
|
48
|
-
return entry;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
return (0, core_1.explicitRelative)(baseDir, entry);
|
|
52
|
-
}
|
|
53
|
-
}),
|
|
54
|
-
resolutions: module.resolved
|
|
55
|
-
? (0, fromPairs_1.default)([...module.resolved].map(([source, target]) => [
|
|
56
|
-
source,
|
|
57
|
-
isResolutionFailure(target) ? null : (0, core_1.explicitRelative)(baseDir, target),
|
|
58
|
-
]))
|
|
59
|
-
: {},
|
|
60
|
-
imports: ((_a = module.parsed) === null || _a === void 0 ? void 0 : _a.imports)
|
|
61
|
-
? module.parsed.imports.map(i => ({
|
|
62
|
-
source: i.source,
|
|
63
|
-
specifiers: i.specifiers.map(s => ({
|
|
64
|
-
name: s.name,
|
|
65
|
-
local: s.local,
|
|
66
|
-
})),
|
|
67
|
-
}))
|
|
68
|
-
: [],
|
|
69
|
-
exports: ((_b = module.linked) === null || _b === void 0 ? void 0 : _b.exports) ? [...module.linked.exports] : [],
|
|
70
|
-
content: ((_c = module.parsed) === null || _c === void 0 ? void 0 : _c.transpiledContent)
|
|
71
|
-
? (_d = module.parsed) === null || _d === void 0 ? void 0 : _d.transpiledContent.toString()
|
|
72
|
-
: 'module failed to transpile',
|
|
73
|
-
};
|
|
74
|
-
results.modules[(0, core_1.explicitRelative)(baseDir, filename)] = publicModule;
|
|
75
|
-
}
|
|
31
|
+
results.modules = modules;
|
|
76
32
|
for (let finding of findings) {
|
|
77
|
-
|
|
33
|
+
const filename = finding.filename.startsWith('./')
|
|
34
|
+
? finding.filename
|
|
35
|
+
: (0, core_1.explicitRelative)(baseDir, finding.filename);
|
|
36
|
+
let relFinding = Object.assign({}, finding, { filename });
|
|
78
37
|
results.findings.push(relFinding);
|
|
79
38
|
}
|
|
80
39
|
return results;
|
|
@@ -94,7 +53,7 @@ class AuditResults {
|
|
|
94
53
|
}
|
|
95
54
|
output.push(indent(chalk_1.default.blueBright(`file was included because:`), 1));
|
|
96
55
|
let pointer = filename;
|
|
97
|
-
while (!isRootMarker(pointer)) {
|
|
56
|
+
while (!(0, module_visitor_1.isRootMarker)(pointer)) {
|
|
98
57
|
// the zero here means we only display the first path we found. I think
|
|
99
58
|
// that's a fine tradeoff to keep the output smaller.
|
|
100
59
|
let nextPointer = (_a = this.modules[pointer]) === null || _a === void 0 ? void 0 : _a.consumedFrom[0];
|
|
@@ -102,7 +61,7 @@ class AuditResults {
|
|
|
102
61
|
output.push(indent(chalk_1.default.red(`couldn't figure out why this was included. Please file a bug against @embroider/compat.`), 2));
|
|
103
62
|
break;
|
|
104
63
|
}
|
|
105
|
-
if (isRootMarker(nextPointer)) {
|
|
64
|
+
if ((0, module_visitor_1.isRootMarker)(nextPointer)) {
|
|
106
65
|
output.push(indent('packageJSON.ember-addon.assets', 2));
|
|
107
66
|
}
|
|
108
67
|
else {
|
|
@@ -144,12 +103,52 @@ class Audit {
|
|
|
144
103
|
constructor(originAppRoot, options = {}) {
|
|
145
104
|
this.originAppRoot = originAppRoot;
|
|
146
105
|
this.options = options;
|
|
147
|
-
this.modules = new Map();
|
|
148
106
|
this.virtualModules = new Map();
|
|
149
|
-
this.moduleQueue = new Set();
|
|
150
107
|
this.findings = [];
|
|
151
108
|
this.frames = new babel_visitor_1.CodeFrameStorage();
|
|
152
109
|
this.resolver = new core_1.Resolver(this.resolverParams);
|
|
110
|
+
this.resolveId = async (specifier, fromFile) => {
|
|
111
|
+
if (['@embroider/macros'].includes(specifier)) {
|
|
112
|
+
// the audit process deliberately removes the @embroider/macros babel
|
|
113
|
+
// plugins, so the imports are still present and should be left alone.
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
if (fromFile.endsWith('.html') && specifier.startsWith(this.meta['root-url'])) {
|
|
117
|
+
// root-relative URLs in HTML are actually relative to the appDir
|
|
118
|
+
specifier = (0, core_1.explicitRelative)((0, path_1.dirname)(fromFile), (0, path_1.resolve)(this.movedAppRoot, specifier.replace(this.meta['root-url'], '')));
|
|
119
|
+
}
|
|
120
|
+
let resolution = await this.resolver.nodeResolve(specifier, fromFile);
|
|
121
|
+
switch (resolution.type) {
|
|
122
|
+
case 'virtual':
|
|
123
|
+
this.virtualModules.set(resolution.filename, resolution.content);
|
|
124
|
+
return resolution.filename;
|
|
125
|
+
case 'not_found':
|
|
126
|
+
return undefined;
|
|
127
|
+
case 'real':
|
|
128
|
+
return resolution.filename;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
this.load = async (id) => {
|
|
132
|
+
let content;
|
|
133
|
+
if (this.virtualModules.has(id)) {
|
|
134
|
+
content = this.virtualModules.get(id);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
content = (0, fs_extra_1.readFileSync)(id);
|
|
138
|
+
}
|
|
139
|
+
if (id.endsWith('.html')) {
|
|
140
|
+
return { content, type: 'html' };
|
|
141
|
+
}
|
|
142
|
+
else if (id.endsWith('.hbs')) {
|
|
143
|
+
return { content: (0, core_1.hbsToJS)(content.toString('utf8')), type: 'javascript' };
|
|
144
|
+
}
|
|
145
|
+
else if (id.endsWith('.json')) {
|
|
146
|
+
return this.handleJSON(id, content);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return { content, type: 'javascript' };
|
|
150
|
+
}
|
|
151
|
+
};
|
|
153
152
|
}
|
|
154
153
|
get pkg() {
|
|
155
154
|
return (0, fs_extra_1.readJSONSync)((0, path_1.join)(this.movedAppRoot, 'package.json'));
|
|
@@ -177,64 +176,22 @@ class Audit {
|
|
|
177
176
|
console.log(message, ...args);
|
|
178
177
|
}
|
|
179
178
|
}
|
|
180
|
-
visitorFor(filename) {
|
|
181
|
-
if (filename.endsWith('.html')) {
|
|
182
|
-
return this.visitHTML;
|
|
183
|
-
}
|
|
184
|
-
else if (filename.endsWith('.hbs')) {
|
|
185
|
-
return this.visitHBS;
|
|
186
|
-
}
|
|
187
|
-
else if (filename.endsWith('.json')) {
|
|
188
|
-
return this.visitJSON;
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
return this.visitJS;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
async drainQueue() {
|
|
195
|
-
while (this.moduleQueue.size > 0) {
|
|
196
|
-
let filename = this.moduleQueue.values().next().value;
|
|
197
|
-
this.moduleQueue.delete(filename);
|
|
198
|
-
this.debug('visit', filename);
|
|
199
|
-
let visitor = this.visitorFor(filename);
|
|
200
|
-
let content;
|
|
201
|
-
if (this.virtualModules.has(filename)) {
|
|
202
|
-
content = this.virtualModules.get(filename);
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
content = (0, fs_extra_1.readFileSync)(filename);
|
|
206
|
-
}
|
|
207
|
-
// cast is safe because the only way to get into the queue is to go
|
|
208
|
-
// through scheduleVisit, and scheduleVisit creates the entry in
|
|
209
|
-
// this.modules.
|
|
210
|
-
let module = this.modules.get(filename);
|
|
211
|
-
let visitResult = await visitor.call(this, filename, content);
|
|
212
|
-
if (Array.isArray(visitResult)) {
|
|
213
|
-
// the visitor was unable to figure out the ParseFields and returned
|
|
214
|
-
// some number of Findings to us to explain why.
|
|
215
|
-
for (let finding of visitResult) {
|
|
216
|
-
this.pushFinding(finding);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
module.parsed = visitResult;
|
|
221
|
-
module.resolved = await this.resolveDeps(visitResult.dependencies, filename);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
179
|
async run() {
|
|
226
180
|
globalThis.embroider_audit = this.handleResolverError.bind(this);
|
|
227
181
|
try {
|
|
228
182
|
this.debug(`meta`, this.meta);
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
183
|
+
let entrypoints = this.meta.assets.filter(a => a.endsWith('html')).map(a => (0, path_1.resolve)(this.movedAppRoot, a));
|
|
184
|
+
let modules = await (0, module_visitor_1.visitModules)({
|
|
185
|
+
base: this.originAppRoot,
|
|
186
|
+
entrypoints,
|
|
187
|
+
resolveId: this.resolveId,
|
|
188
|
+
load: this.load,
|
|
189
|
+
findings: this.findings,
|
|
190
|
+
frames: this.frames,
|
|
191
|
+
babelConfig: this.babelConfig,
|
|
192
|
+
});
|
|
193
|
+
this.inspectModules(modules);
|
|
194
|
+
return AuditResults.create(this.originAppRoot, this.findings, modules);
|
|
238
195
|
}
|
|
239
196
|
finally {
|
|
240
197
|
delete globalThis.embroider_audit;
|
|
@@ -248,54 +205,22 @@ class Audit {
|
|
|
248
205
|
codeFrame: this.frames.render(this.frames.forSource(msg.source)(msg)),
|
|
249
206
|
});
|
|
250
207
|
}
|
|
251
|
-
|
|
252
|
-
for (let module of
|
|
253
|
-
if (
|
|
254
|
-
this.
|
|
208
|
+
inspectModules(modules) {
|
|
209
|
+
for (let [filename, module] of Object.entries(modules)) {
|
|
210
|
+
if (module.type === 'complete') {
|
|
211
|
+
this.inspectImports(filename, module, modules);
|
|
255
212
|
}
|
|
256
213
|
}
|
|
257
214
|
}
|
|
258
|
-
|
|
259
|
-
let
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
else {
|
|
265
|
-
let moduleName = module.resolved.get(exp.all);
|
|
266
|
-
if (!isResolutionFailure(moduleName)) {
|
|
267
|
-
let target = this.modules.get(moduleName);
|
|
268
|
-
if (!isLinked(target) && isResolved(target)) {
|
|
269
|
-
this.linkModule(target);
|
|
270
|
-
}
|
|
271
|
-
if (isLinked(target)) {
|
|
272
|
-
for (let innerExp of target.linked.exports) {
|
|
273
|
-
exports.add(innerExp);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
// our module doesn't successfully enter linked state because it
|
|
278
|
-
// depends on stuff that also couldn't
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
module.linked = {
|
|
285
|
-
exports,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
inspectModules() {
|
|
289
|
-
for (let [filename, module] of this.modules) {
|
|
290
|
-
if (isLinked(module)) {
|
|
291
|
-
this.inspectImports(filename, module);
|
|
215
|
+
inspectImports(filename, module, modules) {
|
|
216
|
+
for (let imp of module.imports) {
|
|
217
|
+
// our Audit should always ignore any imports of @embroider/macros because we already ignored them
|
|
218
|
+
// in resolveId above
|
|
219
|
+
if (imp.source === '@embroider/macros') {
|
|
220
|
+
continue;
|
|
292
221
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
inspectImports(filename, module) {
|
|
296
|
-
for (let imp of module.parsed.imports) {
|
|
297
|
-
let resolved = module.resolved.get(imp.source);
|
|
298
|
-
if (isResolutionFailure(resolved)) {
|
|
222
|
+
let resolved = module.resolutions[imp.source];
|
|
223
|
+
if (!resolved) {
|
|
299
224
|
this.findings.push({
|
|
300
225
|
filename,
|
|
301
226
|
message: 'unable to resolve dependency',
|
|
@@ -304,9 +229,9 @@ class Audit {
|
|
|
304
229
|
});
|
|
305
230
|
}
|
|
306
231
|
else if (resolved) {
|
|
307
|
-
let target =
|
|
232
|
+
let target = modules[resolved];
|
|
308
233
|
for (let specifier of imp.specifiers) {
|
|
309
|
-
if (
|
|
234
|
+
if (target.type === 'complete' && !this.moduleProvidesName(target, specifier.name)) {
|
|
310
235
|
if (specifier.name === 'default') {
|
|
311
236
|
let backtick = '`';
|
|
312
237
|
this.findings.push({
|
|
@@ -333,137 +258,27 @@ class Audit {
|
|
|
333
258
|
// any module can provide a namespace.
|
|
334
259
|
// CJS and AMD are too dynamic to be sure exactly what names are available,
|
|
335
260
|
// so they always get a pass
|
|
336
|
-
return (0, babel_visitor_1.isNamespaceMarker)(name) || target.
|
|
337
|
-
}
|
|
338
|
-
async visitHTML(filename, content) {
|
|
339
|
-
let dom = new JSDOM(content);
|
|
340
|
-
let scripts = dom.window.document.querySelectorAll('script[type="module"]');
|
|
341
|
-
let dependencies = [];
|
|
342
|
-
for (let script of scripts) {
|
|
343
|
-
let src = script.src;
|
|
344
|
-
if (!src) {
|
|
345
|
-
continue;
|
|
346
|
-
}
|
|
347
|
-
if (new URL(src, 'http://example.com:4321').origin !== 'http://example.com:4321') {
|
|
348
|
-
// src was absolute, we don't handle it
|
|
349
|
-
continue;
|
|
350
|
-
}
|
|
351
|
-
if (src.startsWith(this.meta['root-url'])) {
|
|
352
|
-
// root-relative URLs are actually relative to the appDir
|
|
353
|
-
src = (0, core_1.explicitRelative)((0, path_1.dirname)(filename), (0, path_1.resolve)(this.movedAppRoot, src.replace(this.meta['root-url'], '')));
|
|
354
|
-
}
|
|
355
|
-
dependencies.push(src);
|
|
356
|
-
}
|
|
357
|
-
return {
|
|
358
|
-
imports: [],
|
|
359
|
-
exports: new Set(),
|
|
360
|
-
isCJS: false,
|
|
361
|
-
isAMD: false,
|
|
362
|
-
dependencies,
|
|
363
|
-
transpiledContent: content,
|
|
364
|
-
};
|
|
261
|
+
return (0, babel_visitor_1.isNamespaceMarker)(name) || target.isCJS || target.isAMD || target.exports.includes(name);
|
|
365
262
|
}
|
|
366
|
-
|
|
367
|
-
let rawSource = content.toString('utf8');
|
|
368
|
-
try {
|
|
369
|
-
let result = (0, babel_visitor_1.auditJS)(rawSource, filename, this.babelConfig, this.frames);
|
|
370
|
-
for (let problem of result.problems) {
|
|
371
|
-
this.pushFinding({
|
|
372
|
-
filename,
|
|
373
|
-
message: problem.message,
|
|
374
|
-
detail: problem.detail,
|
|
375
|
-
codeFrame: this.frames.render(problem.codeFrameIndex),
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
return {
|
|
379
|
-
exports: result.exports,
|
|
380
|
-
imports: result.imports,
|
|
381
|
-
isCJS: result.isCJS,
|
|
382
|
-
isAMD: result.isAMD,
|
|
383
|
-
dependencies: result.imports.map(i => i.source),
|
|
384
|
-
transpiledContent: result.transpiledContent,
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
catch (err) {
|
|
388
|
-
if (['BABEL_PARSE_ERROR', 'BABEL_TRANSFORM_ERROR'].includes(err.code)) {
|
|
389
|
-
return [
|
|
390
|
-
{
|
|
391
|
-
filename,
|
|
392
|
-
message: `failed to parse`,
|
|
393
|
-
detail: err.toString().replace(filename, (0, core_1.explicitRelative)(this.originAppRoot, filename)),
|
|
394
|
-
},
|
|
395
|
-
];
|
|
396
|
-
}
|
|
397
|
-
else {
|
|
398
|
-
throw err;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
async visitHBS(filename, content) {
|
|
403
|
-
let rawSource = content.toString('utf8');
|
|
404
|
-
let js = (0, core_1.hbsToJS)(rawSource);
|
|
405
|
-
return this.visitJS(filename, js);
|
|
406
|
-
}
|
|
407
|
-
async visitJSON(filename, content) {
|
|
263
|
+
handleJSON(filename, content) {
|
|
408
264
|
let js;
|
|
409
265
|
try {
|
|
410
266
|
let structure = JSON.parse(content.toString('utf8'));
|
|
411
267
|
js = `export default ${JSON.stringify(structure)}`;
|
|
412
268
|
}
|
|
413
269
|
catch (err) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
];
|
|
270
|
+
this.findings.push({
|
|
271
|
+
filename,
|
|
272
|
+
message: `failed to parse JSON`,
|
|
273
|
+
detail: err.toString().replace(filename, (0, core_1.explicitRelative)(this.originAppRoot, filename)),
|
|
274
|
+
});
|
|
275
|
+
return;
|
|
421
276
|
}
|
|
422
|
-
return
|
|
423
|
-
}
|
|
424
|
-
async resolveDeps(deps, fromFile) {
|
|
425
|
-
let resolved = new Map();
|
|
426
|
-
for (let dep of deps) {
|
|
427
|
-
let resolution = await this.resolver.nodeResolve(dep, fromFile);
|
|
428
|
-
switch (resolution.type) {
|
|
429
|
-
case 'virtual':
|
|
430
|
-
this.virtualModules.set(resolution.filename, resolution.content);
|
|
431
|
-
resolved.set(dep, resolution.filename);
|
|
432
|
-
this.scheduleVisit(resolution.filename, fromFile);
|
|
433
|
-
break;
|
|
434
|
-
case 'not_found':
|
|
435
|
-
if (['@embroider/macros', '@ember/template-factory'].includes(dep)) {
|
|
436
|
-
// the audit process deliberately removes the @embroider/macros babel
|
|
437
|
-
// plugins, so the imports are still present and should be left alone.
|
|
438
|
-
continue;
|
|
439
|
-
}
|
|
440
|
-
resolved.set(dep, { isResolutionFailure: true });
|
|
441
|
-
break;
|
|
442
|
-
case 'real':
|
|
443
|
-
resolved.set(dep, resolution.filename);
|
|
444
|
-
this.scheduleVisit(resolution.filename, fromFile);
|
|
445
|
-
break;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
return resolved;
|
|
277
|
+
return { content: js, type: 'javascript' };
|
|
449
278
|
}
|
|
450
279
|
pushFinding(finding) {
|
|
451
280
|
this.findings.push(finding);
|
|
452
281
|
}
|
|
453
|
-
scheduleVisit(filename, parent) {
|
|
454
|
-
let record = this.modules.get(filename);
|
|
455
|
-
if (!record) {
|
|
456
|
-
this.debug(`discovered`, filename);
|
|
457
|
-
record = {
|
|
458
|
-
consumedFrom: [parent],
|
|
459
|
-
};
|
|
460
|
-
this.modules.set(filename, record);
|
|
461
|
-
this.moduleQueue.add(filename);
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
record.consumedFrom.push(parent);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
282
|
}
|
|
468
283
|
exports.Audit = Audit;
|
|
469
284
|
__decorate([
|
|
@@ -489,8 +304,4 @@ function indent(str, level) {
|
|
|
489
304
|
.map(line => spaces + line)
|
|
490
305
|
.join('\n');
|
|
491
306
|
}
|
|
492
|
-
function isRootMarker(value) {
|
|
493
|
-
return Boolean(value && typeof value !== 'string' && value.isRoot);
|
|
494
|
-
}
|
|
495
|
-
exports.isRootMarker = isRootMarker;
|
|
496
307
|
//# sourceMappingURL=audit.js.map
|
package/src/audit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.js","sourceRoot":"","sources":["audit.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAsD;AACtD,+BAA6D;AAE7D,0CAAwH;AACxH,2DAA6C;AAC7C,kDAA0B;AAC1B,kDAA0B;AAC1B,6DAAqC;AACrC,iEAAyC;AAEzC,yDAAqF;AAErF,yCAAmE;AAiBzB,2FAjBvB,kBAAU,OAiBuB;AAAE,6FAjBvB,oBAAY,OAiBuB;AAflE,MAAM,EAAE,KAAK,EAAE,GAAG,eAAK,CAAC;AAqCxB,SAAS,mBAAmB,CAAC,MAA8C;IACzE,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,qBAAqB,IAAI,MAAM,CAAC;AACvE,CAAC;AA6BD,SAAS,UAAU,CAAC,MAAkC;IACpD,OAAO,OAAO,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;AACpD,CAAC;AAMD,SAAS,QAAQ,CAAC,MAAkC;IAClD,OAAO,OAAO,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;AACrE,CAAC;AAUD,MAAa,YAAY;IAAzB;QACE,YAAO,GAA+B,EAAE,CAAC;QACzC,aAAQ,GAAc,EAAE,CAAC;IA+F3B,CAAC;IA7FC,MAAM,CAAC,MAAM,CAAC,OAAe,EAAE,QAAmB,EAAE,OAAoC;;QACtF,IAAI,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;QACzB,KAAK,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE;YACtC,IAAI,YAAY,GAAW;gBACzB,eAAe,EAAE,IAAA,uBAAgB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AAI,CAAC,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC;SAC1B,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAMD,SAAgB,YAAY,CAAC,KAAsC;IACjE,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AACrE,CAAC;AAFD,oCAEC","sourcesContent":["import { readFileSync, readJSONSync } from 'fs-extra';\nimport { dirname, join, resolve as resolvePath } from 'path';\nimport type { AppMeta, ResolverOptions } from '@embroider/core';\nimport { explicitRelative, hbsToJS, locateEmbroiderWorkingDir, Resolver, RewrittenPackageCache } from '@embroider/core';\nimport { Memoize } from 'typescript-memoize';\nimport chalk from 'chalk';\nimport jsdom from 'jsdom';\nimport groupBy from 'lodash/groupBy';\nimport fromPairs from 'lodash/fromPairs';\nimport type { ExportAll, InternalImport, NamespaceMarker } from './audit/babel-visitor';\nimport { auditJS, CodeFrameStorage, isNamespaceMarker } from './audit/babel-visitor';\nimport { AuditBuildOptions, AuditOptions } from './audit/options';\nimport { buildApp, BuildError, isBuildError } from './audit/build';\n\nconst { JSDOM } = jsdom;\n\nexport interface AuditMessage {\n message: string;\n detail: string;\n loc: Loc;\n source: string;\n filename: string;\n}\n\nexport interface Loc {\n start: { line: number; column: number };\n end: { line: number; column: number };\n}\n\nexport { AuditOptions, AuditBuildOptions, BuildError, isBuildError };\n\nexport interface Finding {\n message: string;\n filename: string;\n detail: string;\n codeFrame?: string;\n}\n\nexport interface Module {\n appRelativePath: string;\n consumedFrom: (string | RootMarker)[];\n imports: Import[];\n exports: string[];\n resolutions: { [source: string]: string | null };\n content: string;\n}\n\ninterface ResolutionFailure {\n isResolutionFailure: true;\n}\n\nfunction isResolutionFailure(result: string | ResolutionFailure | undefined): result is ResolutionFailure {\n return typeof result === 'object' && 'isResolutionFailure' in result;\n}\n\ninterface InternalModule {\n consumedFrom: (string | RootMarker)[];\n\n parsed?: {\n imports: InternalImport[];\n exports: Set<string | ExportAll>;\n isCJS: boolean;\n isAMD: boolean;\n dependencies: string[];\n transpiledContent: string | Buffer;\n };\n\n resolved?: Map<string, string | ResolutionFailure>;\n\n linked?: {\n exports: Set<string>;\n };\n}\n\ntype ParsedInternalModule = Omit<InternalModule, 'parsed'> & {\n parsed: NonNullable<InternalModule['parsed']>;\n};\n\ntype ResolvedInternalModule = Omit<ParsedInternalModule, 'resolved'> & {\n resolved: NonNullable<ParsedInternalModule['resolved']>;\n};\n\nfunction isResolved(module: InternalModule | undefined): module is ResolvedInternalModule {\n return Boolean(module?.parsed && module.resolved);\n}\n\ntype LinkedInternalModule = Omit<ResolvedInternalModule, 'linked'> & {\n linked: NonNullable<ResolvedInternalModule['linked']>;\n};\n\nfunction isLinked(module: InternalModule | undefined): module is LinkedInternalModule {\n return Boolean(module?.parsed && module.resolved && module.linked);\n}\n\nexport interface Import {\n source: string;\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 }[];\n}\n\nexport class AuditResults {\n modules: { [file: string]: Module } = {};\n findings: Finding[] = [];\n\n static create(baseDir: string, findings: Finding[], modules: Map<string, InternalModule>) {\n let results = new this();\n for (let [filename, module] of modules) {\n let publicModule: Module = {\n appRelativePath: explicitRelative(baseDir, filename),\n consumedFrom: module.consumedFrom.map(entry => {\n if (isRootMarker(entry)) {\n return entry;\n } else {\n return explicitRelative(baseDir, entry);\n }\n }),\n resolutions: module.resolved\n ? fromPairs(\n [...module.resolved].map(([source, target]) => [\n source,\n isResolutionFailure(target) ? null : explicitRelative(baseDir, target),\n ])\n )\n : {},\n imports: module.parsed?.imports\n ? module.parsed.imports.map(i => ({\n source: i.source,\n specifiers: i.specifiers.map(s => ({\n name: s.name,\n local: s.local,\n })),\n }))\n : [],\n exports: module.linked?.exports ? [...module.linked.exports] : [],\n content: module.parsed?.transpiledContent\n ? module.parsed?.transpiledContent.toString()\n : 'module failed to transpile',\n };\n results.modules[explicitRelative(baseDir, filename)] = publicModule;\n }\n for (let finding of findings) {\n let relFinding = Object.assign({}, finding, { filename: explicitRelative(baseDir, finding.filename) });\n results.findings.push(relFinding);\n }\n return results;\n }\n\n humanReadable(): string {\n let output = [] as string[];\n let findingsByFile = groupBy(this.findings, f => f.filename);\n output.push(`=== Audit Results ===`);\n for (let [filename, findings] of Object.entries(findingsByFile)) {\n output.push(`${chalk.yellow(filename)}`);\n for (let finding of findings) {\n output.push(indent(chalk.red(finding.message) + ': ' + finding.detail, 1));\n if (finding.codeFrame) {\n output.push(indent(finding.codeFrame, 2));\n }\n }\n output.push(indent(chalk.blueBright(`file was included because:`), 1));\n let pointer: string | RootMarker = filename;\n while (!isRootMarker(pointer)) {\n // the zero here means we only display the first path we found. I think\n // that's a fine tradeoff to keep the output smaller.\n let nextPointer: string | RootMarker | undefined = this.modules[pointer]?.consumedFrom[0];\n if (!nextPointer) {\n output.push(\n indent(\n chalk.red(`couldn't figure out why this was included. Please file a bug against @embroider/compat.`),\n 2\n )\n );\n break;\n }\n if (isRootMarker(nextPointer)) {\n output.push(indent('packageJSON.ember-addon.assets', 2));\n } else {\n output.push(indent(nextPointer, 2));\n }\n pointer = nextPointer;\n }\n }\n let summaryColor;\n if (this.perfect) {\n summaryColor = chalk.green;\n } else {\n summaryColor = chalk.yellow;\n }\n output.push(summaryColor(`${this.findings.length} issues found`));\n output.push(`=== End Audit Results ===`);\n output.push(''); // always end with a newline because `yarn run` can overwrite our last line otherwise\n return output.join('\\n');\n }\n\n get perfect() {\n return this.findings.length === 0;\n }\n}\n\nexport class Audit {\n private modules: Map<string, InternalModule> = new Map();\n private virtualModules: Map<string, string> = new Map();\n private moduleQueue = new Set<string>();\n private findings = [] as Finding[];\n\n private frames = new CodeFrameStorage();\n\n static async run(options: AuditBuildOptions): Promise<AuditResults> {\n if (!options['reuse-build']) {\n await buildApp(options);\n }\n\n let audit = new this(options.app, options);\n if (options['reuse-build']) {\n if (!audit.meta.babel.isParallelSafe) {\n throw new BuildError(\n `You can't use the ${chalk.red(\n '--reuse-build'\n )} option because some of your babel or HBS plugins are non-serializable`\n );\n }\n }\n return audit.run();\n }\n\n constructor(private originAppRoot: string, private options: AuditOptions = {}) {}\n\n @Memoize()\n private get pkg() {\n return readJSONSync(join(this.movedAppRoot, 'package.json'));\n }\n\n @Memoize()\n private get movedAppRoot() {\n let cache = RewrittenPackageCache.shared('embroider', this.originAppRoot);\n return cache.maybeMoved(cache.get(this.originAppRoot)).root;\n }\n\n private get meta() {\n return this.pkg['ember-addon'] as AppMeta;\n }\n\n @Memoize()\n private get babelConfig() {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n let config = require(join(this.movedAppRoot, this.meta.babel.filename));\n config = Object.assign({}, config);\n config.plugins = config.plugins.filter((p: any) => !isMacrosPlugin(p));\n\n config.ast = true;\n return config;\n }\n\n private get resolverParams(): ResolverOptions {\n return readJSONSync(join(locateEmbroiderWorkingDir(this.originAppRoot), 'resolver.json'));\n }\n\n private resolver = new Resolver(this.resolverParams);\n\n private debug(message: string, ...args: any[]) {\n if (this.options.debug) {\n console.log(message, ...args);\n }\n }\n\n private visitorFor(\n filename: string\n ): (\n this: Audit,\n filename: string,\n content: Buffer | string\n ) => Promise<NonNullable<InternalModule['parsed']> | Finding[]> {\n if (filename.endsWith('.html')) {\n return this.visitHTML;\n } else if (filename.endsWith('.hbs')) {\n return this.visitHBS;\n } else if (filename.endsWith('.json')) {\n return this.visitJSON;\n } else {\n return this.visitJS;\n }\n }\n\n private async drainQueue() {\n while (this.moduleQueue.size > 0) {\n let filename = this.moduleQueue.values().next().value as string;\n this.moduleQueue.delete(filename);\n this.debug('visit', filename);\n let visitor = this.visitorFor(filename);\n let content: string | Buffer;\n if (this.virtualModules.has(filename)) {\n content = this.virtualModules.get(filename)!;\n } else {\n content = readFileSync(filename);\n }\n // cast is safe because the only way to get into the queue is to go\n // through scheduleVisit, and scheduleVisit creates the entry in\n // this.modules.\n let module: InternalModule = this.modules.get(filename)!;\n let visitResult = await visitor.call(this, filename, content);\n if (Array.isArray(visitResult)) {\n // the visitor was unable to figure out the ParseFields and returned\n // some number of Findings to us to explain why.\n for (let finding of visitResult) {\n this.pushFinding(finding);\n }\n } else {\n module.parsed = visitResult;\n module.resolved = await this.resolveDeps(visitResult.dependencies, filename);\n }\n }\n }\n\n async run(): Promise<AuditResults> {\n (globalThis as any).embroider_audit = this.handleResolverError.bind(this);\n\n try {\n this.debug(`meta`, this.meta);\n for (let asset of this.meta.assets) {\n if (asset.endsWith('.html')) {\n this.scheduleVisit(resolvePath(this.movedAppRoot, asset), { isRoot: true });\n }\n }\n await this.drainQueue();\n this.linkModules();\n this.inspectModules();\n\n return AuditResults.create(this.originAppRoot, this.findings, this.modules);\n } finally {\n delete (globalThis as any).embroider_audit;\n }\n }\n\n private handleResolverError(msg: AuditMessage) {\n this.pushFinding({\n message: msg.message,\n filename: msg.filename,\n detail: msg.detail,\n codeFrame: this.frames.render(this.frames.forSource(msg.source)(msg)),\n });\n }\n\n private linkModules() {\n for (let module of this.modules.values()) {\n if (isResolved(module)) {\n this.linkModule(module);\n }\n }\n }\n\n private linkModule(module: ResolvedInternalModule) {\n let exports = new Set<string>();\n for (let exp of module.parsed.exports) {\n if (typeof exp === 'string') {\n exports.add(exp);\n } else {\n let moduleName = module.resolved.get(exp.all)!;\n if (!isResolutionFailure(moduleName)) {\n let target = this.modules.get(moduleName)!;\n if (!isLinked(target) && isResolved(target)) {\n this.linkModule(target);\n }\n if (isLinked(target)) {\n for (let innerExp of target.linked.exports) {\n exports.add(innerExp);\n }\n } else {\n // our module doesn't successfully enter linked state because it\n // depends on stuff that also couldn't\n return;\n }\n }\n }\n }\n module.linked = {\n exports,\n };\n }\n\n private inspectModules() {\n for (let [filename, module] of this.modules) {\n if (isLinked(module)) {\n this.inspectImports(filename, module);\n }\n }\n }\n\n private inspectImports(filename: string, module: LinkedInternalModule) {\n for (let imp of module.parsed.imports) {\n let resolved = module.resolved.get(imp.source);\n if (isResolutionFailure(resolved)) {\n this.findings.push({\n filename,\n message: 'unable to resolve dependency',\n detail: imp.source,\n codeFrame: this.frames.render(imp.codeFrameIndex),\n });\n } else if (resolved) {\n let target = this.modules.get(resolved)!;\n for (let specifier of imp.specifiers) {\n if (isLinked(target) && !this.moduleProvidesName(target, specifier.name)) {\n if (specifier.name === 'default') {\n let backtick = '`';\n this.findings.push({\n filename,\n message: 'importing a non-existent default export',\n detail: `\"${imp.source}\" has no default export. Did you mean ${backtick}import * as ${specifier.local} from \"${imp.source}\"${backtick}?`,\n codeFrame: this.frames.render(specifier.codeFrameIndex),\n });\n } else {\n this.findings.push({\n filename,\n message: 'importing a non-existent named export',\n detail: `\"${imp.source}\" has no export named \"${specifier.name}\".`,\n codeFrame: this.frames.render(specifier.codeFrameIndex),\n });\n }\n }\n }\n }\n }\n }\n\n private moduleProvidesName(target: LinkedInternalModule, name: string | NamespaceMarker) {\n // any module can provide a namespace.\n // CJS and AMD are too dynamic to be sure exactly what names are available,\n // so they always get a pass\n return isNamespaceMarker(name) || target.parsed.isCJS || target.parsed.isAMD || target.linked.exports.has(name);\n }\n\n private async visitHTML(filename: string, content: Buffer | string): Promise<ParsedInternalModule['parsed']> {\n let dom = new JSDOM(content);\n let scripts = dom.window.document.querySelectorAll('script[type=\"module\"]') as NodeListOf<HTMLScriptElement>;\n let dependencies = [] as string[];\n for (let script of scripts) {\n let src = script.src;\n if (!src) {\n continue;\n }\n if (new URL(src, 'http://example.com:4321').origin !== 'http://example.com:4321') {\n // src was absolute, we don't handle it\n continue;\n }\n if (src.startsWith(this.meta['root-url'])) {\n // root-relative URLs are actually relative to the appDir\n src = explicitRelative(\n dirname(filename),\n resolvePath(this.movedAppRoot, src.replace(this.meta['root-url'], ''))\n );\n }\n dependencies.push(src);\n }\n\n return {\n imports: [],\n exports: new Set(),\n isCJS: false,\n isAMD: false,\n dependencies,\n transpiledContent: content,\n };\n }\n\n private async visitJS(\n filename: string,\n content: Buffer | string\n ): Promise<ParsedInternalModule['parsed'] | Finding[]> {\n let rawSource = content.toString('utf8');\n try {\n let result = auditJS(rawSource, filename, this.babelConfig, this.frames);\n\n for (let problem of result.problems) {\n this.pushFinding({\n filename,\n message: problem.message,\n detail: problem.detail,\n codeFrame: this.frames.render(problem.codeFrameIndex),\n });\n }\n return {\n exports: result.exports,\n imports: result.imports,\n isCJS: result.isCJS,\n isAMD: result.isAMD,\n dependencies: result.imports.map(i => i.source),\n transpiledContent: result.transpiledContent,\n };\n } catch (err) {\n if (['BABEL_PARSE_ERROR', 'BABEL_TRANSFORM_ERROR'].includes(err.code)) {\n return [\n {\n filename,\n message: `failed to parse`,\n detail: err.toString().replace(filename, explicitRelative(this.originAppRoot, filename)),\n },\n ];\n } else {\n throw err;\n }\n }\n }\n\n private async visitHBS(\n filename: string,\n content: Buffer | string\n ): Promise<ParsedInternalModule['parsed'] | Finding[]> {\n let rawSource = content.toString('utf8');\n let js = hbsToJS(rawSource);\n return this.visitJS(filename, js);\n }\n\n private async visitJSON(\n filename: string,\n content: Buffer | string\n ): Promise<ParsedInternalModule['parsed'] | Finding[]> {\n let js;\n try {\n let structure = JSON.parse(content.toString('utf8'));\n js = `export default ${JSON.stringify(structure)}`;\n } catch (err) {\n return [\n {\n filename,\n message: `failed to parse JSON`,\n detail: err.toString().replace(filename, explicitRelative(this.originAppRoot, filename)),\n },\n ];\n }\n return this.visitJS(filename, js);\n }\n\n private async resolveDeps(deps: string[], fromFile: string): Promise<InternalModule['resolved']> {\n let resolved = new Map() as NonNullable<InternalModule['resolved']>;\n for (let dep of deps) {\n let resolution = await this.resolver.nodeResolve(dep, fromFile);\n switch (resolution.type) {\n case 'virtual':\n this.virtualModules.set(resolution.filename, resolution.content);\n resolved.set(dep, resolution.filename);\n this.scheduleVisit(resolution.filename, fromFile);\n break;\n case 'not_found':\n if (['@embroider/macros', '@ember/template-factory'].includes(dep)) {\n // the audit process deliberately removes the @embroider/macros babel\n // plugins, so the imports are still present and should be left alone.\n continue;\n }\n resolved.set(dep, { isResolutionFailure: true as true });\n break;\n case 'real':\n resolved.set(dep, resolution.filename);\n this.scheduleVisit(resolution.filename, fromFile);\n break;\n }\n }\n return resolved;\n }\n\n private pushFinding(finding: Finding) {\n this.findings.push(finding);\n }\n\n private scheduleVisit(filename: string, parent: string | RootMarker) {\n let record = this.modules.get(filename);\n if (!record) {\n this.debug(`discovered`, filename);\n record = {\n consumedFrom: [parent],\n };\n this.modules.set(filename, record);\n this.moduleQueue.add(filename);\n } else {\n record.consumedFrom.push(parent);\n }\n }\n}\n\nfunction isMacrosPlugin(p: any) {\n return Array.isArray(p) && p[1] && p[1].embroiderMacrosConfigMarker;\n}\n\nfunction indent(str: string, level: number) {\n const spacesPerLevel = 2;\n let spaces = '';\n for (let i = 0; i < level * spacesPerLevel; i++) {\n spaces += ' ';\n }\n\n return str\n .split('\\n')\n .map(line => spaces + line)\n .join('\\n');\n}\n\nexport interface RootMarker {\n isRoot: true;\n}\n\nexport function isRootMarker(value: string | RootMarker | undefined): value is RootMarker {\n return Boolean(value && typeof value !== 'string' && value.isRoot);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["audit.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAsD;AACtD,+BAA6D;AAE7D,0CAAwH;AACxH,2DAA6C;AAC7C,kDAA0B;AAC1B,6DAAqC;AAErC,yDAA4E;AAE5E,yCAAmE;AAuBzB,2FAvBvB,kBAAU,OAuBuB;AAAE,6FAvBvB,oBAAY,OAuBuB;AAtBlE,qDAO0B;AAwB1B,MAAa,YAAY;IAAzB;QACE,YAAO,GAA+B,EAAE,CAAC;QACzC,aAAQ,GAAc,EAAE,CAAC;IAkE3B,CAAC;IAhEC,MAAM,CAAC,MAAM,CAAC,OAAe,EAAE,QAAmB,EAAE,OAA+B;QACjF,IAAI,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;QACzB,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;QAC1B,KAAK,IAAI,OA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O,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,2BAA2B,CAAC;AACtE,CAAC;AAED,SAAS,MAAM,CAAC,GAAW,EAAE,KAAa;IACxC,MAAM,cAAc,GAAG,CAAC,CAAC;IACzB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,cAAc,EAAE,CAAC,EAAE,EAAE,CAAC;QAChD,MAAM,IAAI,GAAG,CAAC;IAChB,CAAC;IAED,OAAO,GAAG;SACP,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC;SAC1B,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC","sourcesContent":["import { readFileSync, readJSONSync } from 'fs-extra';\nimport { join, resolve as resolvePath, dirname } from 'path';\nimport type { AppMeta, ResolverOptions } from '@embroider/core';\nimport { explicitRelative, hbsToJS, locateEmbroiderWorkingDir, Resolver, RewrittenPackageCache } from '@embroider/core';\nimport { Memoize } from 'typescript-memoize';\nimport chalk from 'chalk';\nimport groupBy from 'lodash/groupBy';\nimport type { NamespaceMarker } from './audit/babel-visitor';\nimport { CodeFrameStorage, isNamespaceMarker } from './audit/babel-visitor';\nimport { AuditBuildOptions, AuditOptions } from './audit/options';\nimport { buildApp, BuildError, isBuildError } from './audit/build';\nimport {\n type ContentType,\n type Module,\n visitModules,\n type RootMarker,\n isRootMarker,\n type CompleteModule,\n} from './module-visitor';\n\nexport interface AuditMessage {\n message: string;\n detail: string;\n loc: Loc;\n source: string;\n filename: string;\n}\n\nexport interface Loc {\n start: { line: number; column: number };\n end: { line: number; column: number };\n}\n\nexport { AuditOptions, AuditBuildOptions, BuildError, isBuildError };\n\nexport interface Finding {\n message: string;\n filename: string;\n detail: string;\n codeFrame?: string;\n}\n\nexport class AuditResults {\n modules: { [file: string]: Module } = {};\n findings: Finding[] = [];\n\n static create(baseDir: string, findings: Finding[], modules: Record<string, Module>) {\n let results = new this();\n results.modules = modules;\n for (let finding of findings) {\n const filename = finding.filename.startsWith('./')\n ? finding.filename\n : explicitRelative(baseDir, finding.filename);\n\n let relFinding = Object.assign({}, finding, { filename });\n results.findings.push(relFinding);\n }\n return results;\n }\n\n humanReadable(): string {\n let output = [] as string[];\n let findingsByFile = groupBy(this.findings, f => f.filename);\n output.push(`=== Audit Results ===`);\n for (let [filename, findings] of Object.entries(findingsByFile)) {\n output.push(`${chalk.yellow(filename)}`);\n for (let finding of findings) {\n output.push(indent(chalk.red(finding.message) + ': ' + finding.detail, 1));\n if (finding.codeFrame) {\n output.push(indent(finding.codeFrame, 2));\n }\n }\n output.push(indent(chalk.blueBright(`file was included because:`), 1));\n let pointer: string | RootMarker = filename;\n while (!isRootMarker(pointer)) {\n // the zero here means we only display the first path we found. I think\n // that's a fine tradeoff to keep the output smaller.\n let nextPointer: string | RootMarker | undefined = this.modules[pointer]?.consumedFrom[0];\n if (!nextPointer) {\n output.push(\n indent(\n chalk.red(`couldn't figure out why this was included. Please file a bug against @embroider/compat.`),\n 2\n )\n );\n break;\n }\n if (isRootMarker(nextPointer)) {\n output.push(indent('packageJSON.ember-addon.assets', 2));\n } else {\n output.push(indent(nextPointer, 2));\n }\n pointer = nextPointer;\n }\n }\n let summaryColor;\n if (this.perfect) {\n summaryColor = chalk.green;\n } else {\n summaryColor = chalk.yellow;\n }\n output.push(summaryColor(`${this.findings.length} issues found`));\n output.push(`=== End Audit Results ===`);\n output.push(''); // always end with a newline because `yarn run` can overwrite our last line otherwise\n return output.join('\\n');\n }\n\n get perfect() {\n return this.findings.length === 0;\n }\n}\n\nexport class Audit {\n private virtualModules: Map<string, string> = new Map();\n private findings = [] as Finding[];\n\n private frames = new CodeFrameStorage();\n\n static async run(options: AuditBuildOptions): Promise<AuditResults> {\n if (!options['reuse-build']) {\n await buildApp(options);\n }\n\n let audit = new this(options.app, options);\n if (options['reuse-build']) {\n if (!audit.meta.babel.isParallelSafe) {\n throw new BuildError(\n `You can't use the ${chalk.red(\n '--reuse-build'\n )} option because some of your babel or HBS plugins are non-serializable`\n );\n }\n }\n return audit.run();\n }\n\n constructor(private originAppRoot: string, private options: AuditOptions = {}) {}\n\n @Memoize()\n private get pkg() {\n return readJSONSync(join(this.movedAppRoot, 'package.json'));\n }\n\n @Memoize()\n private get movedAppRoot() {\n let cache = RewrittenPackageCache.shared('embroider', this.originAppRoot);\n return cache.maybeMoved(cache.get(this.originAppRoot)).root;\n }\n\n private get meta() {\n return this.pkg['ember-addon'] as AppMeta;\n }\n\n @Memoize()\n private get babelConfig() {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n let config = require(join(this.movedAppRoot, this.meta.babel.filename));\n config = Object.assign({}, config);\n config.plugins = config.plugins.filter((p: any) => !isMacrosPlugin(p));\n\n config.ast = true;\n return config;\n }\n\n private get resolverParams(): ResolverOptions {\n return readJSONSync(join(locateEmbroiderWorkingDir(this.originAppRoot), 'resolver.json'));\n }\n\n private resolver = new Resolver(this.resolverParams);\n\n private debug(message: string, ...args: any[]) {\n if (this.options.debug) {\n console.log(message, ...args);\n }\n }\n\n async run(): Promise<AuditResults> {\n (globalThis as any).embroider_audit = this.handleResolverError.bind(this);\n\n try {\n this.debug(`meta`, this.meta);\n let entrypoints = this.meta.assets.filter(a => a.endsWith('html')).map(a => resolvePath(this.movedAppRoot, a));\n\n let modules = await visitModules({\n base: this.originAppRoot,\n entrypoints,\n resolveId: this.resolveId,\n load: this.load,\n findings: this.findings,\n frames: this.frames,\n babelConfig: this.babelConfig,\n });\n\n this.inspectModules(modules);\n\n return AuditResults.create(this.originAppRoot, this.findings, modules);\n } finally {\n delete (globalThis as any).embroider_audit;\n }\n }\n\n private resolveId = async (specifier: string, fromFile: string): Promise<string | undefined> => {\n if (['@embroider/macros'].includes(specifier)) {\n // the audit process deliberately removes the @embroider/macros babel\n // plugins, so the imports are still present and should be left alone.\n return undefined;\n }\n\n if (fromFile.endsWith('.html') && specifier.startsWith(this.meta['root-url'])) {\n // root-relative URLs in HTML are actually relative to the appDir\n specifier = explicitRelative(\n dirname(fromFile),\n resolvePath(this.movedAppRoot, specifier.replace(this.meta['root-url'], ''))\n );\n }\n\n let resolution = await this.resolver.nodeResolve(specifier, fromFile);\n switch (resolution.type) {\n case 'virtual':\n this.virtualModules.set(resolution.filename, resolution.content);\n return resolution.filename;\n case 'not_found':\n return undefined;\n case 'real':\n return resolution.filename;\n }\n };\n\n private load = async (id: string): Promise<{ content: string | Buffer; type: ContentType } | undefined> => {\n let content: string | Buffer;\n if (this.virtualModules.has(id)) {\n content = this.virtualModules.get(id)!;\n } else {\n content = readFileSync(id);\n }\n\n if (id.endsWith('.html')) {\n return { content, type: 'html' };\n } else if (id.endsWith('.hbs')) {\n return { content: hbsToJS(content.toString('utf8')), type: 'javascript' };\n } else if (id.endsWith('.json')) {\n return this.handleJSON(id, content);\n } else {\n return { content, type: 'javascript' };\n }\n };\n\n private handleResolverError(msg: AuditMessage) {\n this.pushFinding({\n message: msg.message,\n filename: msg.filename,\n detail: msg.detail,\n codeFrame: this.frames.render(this.frames.forSource(msg.source)(msg)),\n });\n }\n\n private inspectModules(modules: Record<string, Module>) {\n for (let [filename, module] of Object.entries(modules)) {\n if (module.type === 'complete') {\n this.inspectImports(filename, module, modules);\n }\n }\n }\n\n private inspectImports(filename: string, module: CompleteModule, modules: Record<string, Module>) {\n for (let imp of module.imports) {\n // our Audit should always ignore any imports of @embroider/macros because we already ignored them\n // in resolveId above\n if (imp.source === '@embroider/macros') {\n continue;\n }\n let resolved = module.resolutions[imp.source];\n if (!resolved) {\n this.findings.push({\n filename,\n message: 'unable to resolve dependency',\n detail: imp.source,\n codeFrame: this.frames.render(imp.codeFrameIndex),\n });\n } else if (resolved) {\n let target = modules[resolved]!;\n for (let specifier of imp.specifiers) {\n if (target.type === 'complete' && !this.moduleProvidesName(target, specifier.name)) {\n if (specifier.name === 'default') {\n let backtick = '`';\n this.findings.push({\n filename,\n message: 'importing a non-existent default export',\n detail: `\"${imp.source}\" has no default export. Did you mean ${backtick}import * as ${specifier.local} from \"${imp.source}\"${backtick}?`,\n codeFrame: this.frames.render(specifier.codeFrameIndex),\n });\n } else {\n this.findings.push({\n filename,\n message: 'importing a non-existent named export',\n detail: `\"${imp.source}\" has no export named \"${specifier.name}\".`,\n codeFrame: this.frames.render(specifier.codeFrameIndex),\n });\n }\n }\n }\n }\n }\n }\n\n private moduleProvidesName(target: CompleteModule, name: string | NamespaceMarker) {\n // any module can provide a namespace.\n // CJS and AMD are too dynamic to be sure exactly what names are available,\n // so they always get a pass\n return isNamespaceMarker(name) || target.isCJS || target.isAMD || target.exports.includes(name);\n }\n\n private handleJSON(filename: string, content: Buffer | string): { content: string; type: ContentType } | undefined {\n let js;\n try {\n let structure = JSON.parse(content.toString('utf8'));\n js = `export default ${JSON.stringify(structure)}`;\n } catch (err) {\n this.findings.push({\n filename,\n message: `failed to parse JSON`,\n detail: err.toString().replace(filename, explicitRelative(this.originAppRoot, filename)),\n });\n return;\n }\n return { content: js, type: 'javascript' };\n }\n\n private pushFinding(finding: Finding) {\n this.findings.push(finding);\n }\n}\n\nfunction isMacrosPlugin(p: any) {\n return Array.isArray(p) && p[1] && p[1].embroiderMacrosConfigMarker;\n}\n\nfunction indent(str: string, level: number) {\n const spacesPerLevel = 2;\n let spaces = '';\n for (let i = 0; i < level * spacesPerLevel; i++) {\n spaces += ' ';\n }\n\n return str\n .split('\\n')\n .map(line => spaces + line)\n .join('\\n');\n}\n\nexport { Module };\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NodePath } from '@babel/traverse';
|
|
2
2
|
import type * as Babel from '@babel/core';
|
|
3
|
+
import type { types as t } from '@babel/core';
|
|
3
4
|
export type Options = {
|
|
4
5
|
appRoot: string;
|
|
5
6
|
};
|
|
@@ -9,7 +10,7 @@ interface State {
|
|
|
9
10
|
export default function main(babel: typeof Babel): {
|
|
10
11
|
visitor: {
|
|
11
12
|
Program: {
|
|
12
|
-
enter(path: NodePath<
|
|
13
|
+
enter(path: NodePath<t.Program>, state: State): void;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
};
|
|
@@ -38,7 +38,7 @@ main.baseDir = function () {
|
|
|
38
38
|
return (0, path_1.join)(__dirname, '..');
|
|
39
39
|
};
|
|
40
40
|
function addExtraImports(t, path, config) {
|
|
41
|
-
let filename = path.hub.file.opts.filename;
|
|
41
|
+
let filename = (0, core_1.cleanUrl)(path.hub.file.opts.filename);
|
|
42
42
|
let entry = config.extraImports[filename];
|
|
43
43
|
let adder = new babel_import_util_1.ImportUtil(t, path);
|
|
44
44
|
if (entry) {
|