@embroider/core 3.4.16-unstable.ad1534d → 3.4.16
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 +8 -9
- package/src/app-files.d.ts +5 -3
- package/src/app-files.js +8 -25
- package/src/app-files.js.map +1 -1
- package/src/asset.d.ts +32 -0
- package/src/asset.js +3 -0
- package/src/asset.js.map +1 -0
- package/src/ember-html.d.ts +43 -0
- package/src/ember-html.js +110 -0
- package/src/ember-html.js.map +1 -0
- package/src/index.d.ts +2 -2
- package/src/index.js.map +1 -1
- package/src/module-resolver.d.ts +45 -28
- package/src/module-resolver.js +258 -428
- package/src/module-resolver.js.map +1 -1
- package/src/options.d.ts +4 -0
- package/src/options.js +1 -0
- package/src/options.js.map +1 -1
- package/src/portable-babel-config.d.ts +11 -0
- package/src/portable-babel-config.js +132 -0
- package/src/portable-babel-config.js.map +1 -0
- package/src/portable-babel-launcher.d.ts +6 -0
- package/src/portable-babel-launcher.js +75 -0
- package/src/portable-babel-launcher.js.map +1 -0
- package/src/resolver-loader.js +1 -8
- package/src/resolver-loader.js.map +1 -1
- package/src/virtual-content.d.ts +2 -6
- package/src/virtual-content.js +61 -117
- package/src/virtual-content.js.map +1 -1
- package/src/module-resolver-options.d.ts +0 -44
- package/src/module-resolver-options.js +0 -167
- package/src/module-resolver-options.js.map +0 -1
- package/src/node-resolve.d.ts +0 -33
- package/src/node-resolve.js +0 -131
- package/src/node-resolve.js.map +0 -1
- package/src/virtual-entrypoint.d.ts +0 -19
- package/src/virtual-entrypoint.js +0 -289
- package/src/virtual-entrypoint.js.map +0 -1
- package/src/virtual-route-entrypoint.d.ts +0 -15
- package/src/virtual-route-entrypoint.js +0 -101
- package/src/virtual-route-entrypoint.js.map +0 -1
- package/src/virtual-test-support-styles.d.ts +0 -4
- package/src/virtual-test-support-styles.js +0 -64
- package/src/virtual-test-support-styles.js.map +0 -1
- package/src/virtual-test-support.d.ts +0 -4
- package/src/virtual-test-support.js +0 -68
- package/src/virtual-test-support.js.map +0 -1
- package/src/virtual-vendor-styles.d.ts +0 -4
- package/src/virtual-vendor-styles.js +0 -82
- package/src/virtual-vendor-styles.js.map +0 -1
- package/src/virtual-vendor.d.ts +0 -4
- package/src/virtual-vendor.js +0 -72
- package/src/virtual-vendor.js.map +0 -1
package/src/module-resolver.js
CHANGED
@@ -15,60 +15,64 @@ const path_1 = require("path");
|
|
15
15
|
const shared_internals_2 = require("@embroider/shared-internals");
|
16
16
|
const debug_1 = __importDefault(require("debug"));
|
17
17
|
const assert_never_1 = __importDefault(require("assert-never"));
|
18
|
-
const
|
19
|
-
const resolve_exports_1 = require("resolve.exports");
|
18
|
+
const resolve_1 = __importDefault(require("resolve"));
|
20
19
|
const virtual_content_1 = require("./virtual-content");
|
21
20
|
const typescript_memoize_1 = require("typescript-memoize");
|
22
21
|
const describe_exports_1 = require("./describe-exports");
|
23
22
|
const fs_1 = require("fs");
|
24
|
-
const
|
25
|
-
const virtual_route_entrypoint_1 = require("./virtual-route-entrypoint");
|
23
|
+
const semver_1 = require("semver");
|
26
24
|
const debug = (0, debug_1.default)('embroider:resolver');
|
27
|
-
// Using a formatter makes this work lazy so nothing happens when we aren't
|
28
|
-
// logging. It is unfortunate that formatters are a globally mutable config and
|
29
|
-
// you can only use single character names, but oh well.
|
30
|
-
debug_1.default.formatters.p = (s) => {
|
31
|
-
let cwd = process.cwd();
|
32
|
-
if (s.startsWith(cwd)) {
|
33
|
-
return s.slice(cwd.length + 1);
|
34
|
-
}
|
35
|
-
return s;
|
36
|
-
};
|
37
25
|
function logTransition(reason, before, after = before) {
|
38
26
|
if (after.isVirtual) {
|
39
|
-
debug(`
|
40
|
-
}
|
41
|
-
else if (after.resolvedTo) {
|
42
|
-
debug(`[%s:resolvedTo] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
27
|
+
debug(`virtualized %s in %s because %s`, before.specifier, before.fromFile, reason);
|
43
28
|
}
|
44
29
|
else if (before.specifier !== after.specifier) {
|
45
30
|
if (before.fromFile !== after.fromFile) {
|
46
|
-
debug(`
|
31
|
+
debug(`aliased and rehomed: %s to %s, from %s to %s because %s`, before.specifier, after.specifier, before.fromFile, after.fromFile, reason);
|
47
32
|
}
|
48
33
|
else {
|
49
|
-
debug(`
|
34
|
+
debug(`aliased: %s to %s in %s because`, before.specifier, after.specifier, before.fromFile, reason);
|
50
35
|
}
|
51
36
|
}
|
52
37
|
else if (before.fromFile !== after.fromFile) {
|
53
|
-
debug(`
|
54
|
-
}
|
55
|
-
else if (after.isNotFound) {
|
56
|
-
debug(`[%s:not-found] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
38
|
+
debug(`rehomed: %s from %s to %s because`, before.specifier, before.fromFile, after.fromFile, reason);
|
57
39
|
}
|
58
40
|
else {
|
59
|
-
debug(`
|
41
|
+
debug(`unchanged: %s in %s because %s`, before.specifier, before.fromFile, reason);
|
60
42
|
}
|
61
43
|
return after;
|
62
44
|
}
|
63
|
-
|
64
|
-
|
45
|
+
const compatPattern = /#embroider_compat\/(?<type>[^\/]+)\/(?<rest>.*)/;
|
46
|
+
class NodeModuleRequest {
|
47
|
+
constructor(specifier, fromFile, isVirtual, meta) {
|
48
|
+
this.specifier = specifier;
|
49
|
+
this.fromFile = fromFile;
|
50
|
+
this.isVirtual = isVirtual;
|
51
|
+
this.meta = meta;
|
52
|
+
}
|
53
|
+
alias(specifier) {
|
54
|
+
return new NodeModuleRequest(specifier, this.fromFile, false, this.meta);
|
55
|
+
}
|
56
|
+
rehome(fromFile) {
|
57
|
+
if (this.fromFile === fromFile) {
|
58
|
+
return this;
|
59
|
+
}
|
60
|
+
else {
|
61
|
+
return new NodeModuleRequest(this.specifier, fromFile, false, this.meta);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
virtualize(filename) {
|
65
|
+
return new NodeModuleRequest(filename, this.fromFile, true, this.meta);
|
66
|
+
}
|
67
|
+
withMeta(meta) {
|
68
|
+
return new NodeModuleRequest(this.specifier, this.fromFile, this.isVirtual, meta);
|
69
|
+
}
|
65
70
|
}
|
66
|
-
const compatPattern = /@embroider\/virtual\/(?<type>[^\/]+)\/(?<rest>.*)/;
|
67
71
|
class Resolver {
|
68
72
|
constructor(options) {
|
69
73
|
this.options = options;
|
70
74
|
}
|
71
|
-
|
75
|
+
beforeResolve(request) {
|
72
76
|
if (request.specifier === '@embroider/macros') {
|
73
77
|
// the macros package is always handled directly within babel (not
|
74
78
|
// necessarily as a real resolvable package), so we should not mess with it.
|
@@ -76,19 +80,10 @@ class Resolver {
|
|
76
80
|
// why we need to know about it.
|
77
81
|
return logTransition('early exit', request);
|
78
82
|
}
|
79
|
-
if (request.specifier === 'require') {
|
80
|
-
return this.external('early require', request, request.specifier);
|
81
|
-
}
|
82
83
|
request = this.handleFastbootSwitch(request);
|
83
|
-
request =
|
84
|
+
request = this.handleGlobalsCompat(request);
|
84
85
|
request = this.handleImplicitModules(request);
|
85
|
-
request = this.handleImplicitTestScripts(request);
|
86
|
-
request = this.handleVendorStyles(request);
|
87
|
-
request = this.handleTestSupportStyles(request);
|
88
|
-
request = this.handleEntrypoint(request);
|
89
|
-
request = this.handleRouteEntrypoint(request);
|
90
86
|
request = this.handleRenaming(request);
|
91
|
-
request = this.handleVendor(request);
|
92
87
|
// we expect the specifier to be app relative at this point - must be after handleRenaming
|
93
88
|
request = this.generateFastbootSwitch(request);
|
94
89
|
request = this.preHandleExternal(request);
|
@@ -102,45 +97,95 @@ class Resolver {
|
|
102
97
|
// that calls your build system's normal module resolver, this does both pre-
|
103
98
|
// and post-resolution adjustments as needed to implement our compatibility
|
104
99
|
// rules.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
let
|
100
|
+
//
|
101
|
+
// Depending on the plugin architecture you're working in, it may be easier to
|
102
|
+
// call beforeResolve and fallbackResolve directly, in which case matching the
|
103
|
+
// details of the recursion to what this method does are your responsibility.
|
104
|
+
async resolve(request, defaultResolve) {
|
105
|
+
let gen = this.internalResolve(request, defaultResolve);
|
106
|
+
let out = gen.next();
|
107
|
+
while (!out.done) {
|
108
|
+
out = gen.next(await out.value);
|
109
|
+
}
|
110
|
+
return out.value;
|
111
|
+
}
|
112
|
+
// synchronous alternative to resolve() above. Because our own internals are
|
113
|
+
// all synchronous, you can use this if your defaultResolve function is
|
114
|
+
// synchronous.
|
115
|
+
resolveSync(request, defaultResolve) {
|
116
|
+
let gen = this.internalResolve(request, defaultResolve);
|
117
|
+
let out = gen.next();
|
118
|
+
while (!out.done) {
|
119
|
+
out = gen.next(out.value);
|
120
|
+
}
|
121
|
+
return out.value;
|
122
|
+
}
|
123
|
+
// Our core implementation is a generator so it can power both resolve() and
|
124
|
+
// resolveSync()
|
125
|
+
*internalResolve(request, defaultResolve) {
|
126
|
+
request = this.beforeResolve(request);
|
127
|
+
let resolution = yield defaultResolve(request);
|
111
128
|
switch (resolution.type) {
|
112
129
|
case 'found':
|
113
|
-
case 'ignored':
|
114
130
|
return resolution;
|
115
131
|
case 'not_found':
|
116
132
|
break;
|
117
133
|
default:
|
118
134
|
throw (0, assert_never_1.default)(resolution);
|
119
135
|
}
|
120
|
-
let nextRequest =
|
136
|
+
let nextRequest = this.fallbackResolve(request);
|
121
137
|
if (nextRequest === request) {
|
122
138
|
// no additional fallback is available.
|
123
139
|
return resolution;
|
124
140
|
}
|
125
|
-
if (nextRequest.resolvedTo) {
|
126
|
-
return nextRequest.resolvedTo;
|
127
|
-
}
|
128
141
|
if (nextRequest.fromFile === request.fromFile && nextRequest.specifier === request.specifier) {
|
129
142
|
throw new Error('Bug Discovered! New request is not === original request but has the same fromFile and specifier. This will likely create a loop.');
|
130
143
|
}
|
131
|
-
if (nextRequest.isVirtual
|
132
|
-
// virtual
|
133
|
-
//
|
134
|
-
//
|
135
|
-
return
|
144
|
+
if (nextRequest.isVirtual) {
|
145
|
+
// virtual requests are terminal, there is no more beforeResolve or
|
146
|
+
// fallbackResolve around them. The defaultResolve is expected to know how
|
147
|
+
// to implement them.
|
148
|
+
return yield defaultResolve(nextRequest);
|
136
149
|
}
|
137
|
-
return this.
|
150
|
+
return yield* this.internalResolve(nextRequest, defaultResolve);
|
138
151
|
}
|
139
152
|
// Use standard NodeJS resolving, with our required compatibility rules on
|
140
153
|
// top. This is a convenience method for calling resolveSync with the
|
141
154
|
// defaultResolve already configured to be "do the normal node thing".
|
142
|
-
|
143
|
-
|
155
|
+
nodeResolve(specifier, fromFile) {
|
156
|
+
let resolution = this.resolveSync(new NodeModuleRequest(specifier, fromFile, false, undefined), request => {
|
157
|
+
if (request.isVirtual) {
|
158
|
+
return {
|
159
|
+
type: 'found',
|
160
|
+
result: {
|
161
|
+
type: 'virtual',
|
162
|
+
content: (0, virtual_content_1.virtualContent)(request.specifier, this),
|
163
|
+
filename: request.specifier,
|
164
|
+
},
|
165
|
+
};
|
166
|
+
}
|
167
|
+
try {
|
168
|
+
let filename = resolve_1.default.sync(request.specifier, {
|
169
|
+
basedir: (0, path_1.dirname)(request.fromFile),
|
170
|
+
extensions: this.options.resolvableExtensions,
|
171
|
+
});
|
172
|
+
return { type: 'found', result: { type: 'real', filename } };
|
173
|
+
}
|
174
|
+
catch (err) {
|
175
|
+
if (err.code !== 'MODULE_NOT_FOUND') {
|
176
|
+
throw err;
|
177
|
+
}
|
178
|
+
return { type: 'not_found', err };
|
179
|
+
}
|
180
|
+
});
|
181
|
+
switch (resolution.type) {
|
182
|
+
case 'not_found':
|
183
|
+
return resolution;
|
184
|
+
case 'found':
|
185
|
+
return resolution.result;
|
186
|
+
default:
|
187
|
+
throw (0, assert_never_1.default)(resolution);
|
188
|
+
}
|
144
189
|
}
|
145
190
|
get packageCache() {
|
146
191
|
return shared_internals_2.RewrittenPackageCache.shared('embroider', this.options.appRoot);
|
@@ -157,9 +202,6 @@ class Resolver {
|
|
157
202
|
return owningPackage;
|
158
203
|
}
|
159
204
|
generateFastbootSwitch(request) {
|
160
|
-
if (isTerminal(request)) {
|
161
|
-
return request;
|
162
|
-
}
|
163
205
|
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
164
206
|
if (!pkg) {
|
165
207
|
return request;
|
@@ -177,9 +219,7 @@ class Resolver {
|
|
177
219
|
let fastbootFile = engineConfig.fastbootFiles[candidate];
|
178
220
|
if (fastbootFile) {
|
179
221
|
if (fastbootFile.shadowedFilename) {
|
180
|
-
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)((0, path_1.resolve)(pkg.root, fastbootFile.shadowedFilename), 'utf8'), {
|
181
|
-
configFile: false,
|
182
|
-
});
|
222
|
+
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)((0, path_1.resolve)(pkg.root, fastbootFile.shadowedFilename), 'utf8'), {});
|
183
223
|
let switchFile = (0, virtual_content_1.fastbootSwitch)(candidate, (0, path_1.resolve)(pkg.root, 'package.json'), names);
|
184
224
|
if (switchFile === request.fromFile) {
|
185
225
|
return logTransition('internal lookup from fastbootSwitch', request);
|
@@ -198,9 +238,6 @@ class Resolver {
|
|
198
238
|
}
|
199
239
|
handleFastbootSwitch(request) {
|
200
240
|
var _a;
|
201
|
-
if (isTerminal(request)) {
|
202
|
-
return request;
|
203
|
-
}
|
204
241
|
let match = (0, virtual_content_1.decodeFastbootSwitch)(request.fromFile);
|
205
242
|
if (!match) {
|
206
243
|
return request;
|
@@ -239,15 +276,12 @@ class Resolver {
|
|
239
276
|
}
|
240
277
|
let entry = (_a = this.getEntryFromMergeMap(rel, pkg.root)) === null || _a === void 0 ? void 0 : _a.entry;
|
241
278
|
if ((entry === null || entry === void 0 ? void 0 : entry.type) === 'both') {
|
242
|
-
return logTransition('matched addon entry', request, request.alias(entry[section].
|
279
|
+
return logTransition('matched addon entry', request, request.alias(entry[section].localPath).rehome((0, path_1.resolve)(entry[section].packageRoot, 'package.json')));
|
243
280
|
}
|
244
281
|
}
|
245
282
|
return logTransition('failed to match in fastboot switch', request);
|
246
283
|
}
|
247
284
|
handleImplicitModules(request) {
|
248
|
-
if (isTerminal(request)) {
|
249
|
-
return request;
|
250
|
-
}
|
251
285
|
let im = (0, virtual_content_1.decodeImplicitModules)(request.specifier);
|
252
286
|
if (!im) {
|
253
287
|
return request;
|
@@ -265,93 +299,7 @@ class Resolver {
|
|
265
299
|
return logTransition(`own implicit modules`, request, request.virtualize((0, path_1.resolve)(pkg.root, `-embroider-${im.type}.js`)));
|
266
300
|
}
|
267
301
|
}
|
268
|
-
|
269
|
-
var _a;
|
270
|
-
if (isTerminal(request)) {
|
271
|
-
return request;
|
272
|
-
}
|
273
|
-
//TODO move the extra forwardslash handling out into the vite plugin
|
274
|
-
const candidates = ['@embroider/core/entrypoint', '/@embroider/core/entrypoint', './@embroider/core/entrypoint'];
|
275
|
-
if (!candidates.some(c => request.specifier.startsWith(c + '/') || request.specifier === c)) {
|
276
|
-
return request;
|
277
|
-
}
|
278
|
-
const result = /\.?\/?@embroider\/core\/entrypoint(?:\/(?<packageName>.*))?/.exec(request.specifier);
|
279
|
-
if (!result) {
|
280
|
-
// TODO make a better error
|
281
|
-
throw new Error('entrypoint does not match pattern' + request.specifier);
|
282
|
-
}
|
283
|
-
const { packageName } = result.groups;
|
284
|
-
const requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
285
|
-
if (!(requestingPkg === null || requestingPkg === void 0 ? void 0 : requestingPkg.isV2Ember())) {
|
286
|
-
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
|
287
|
-
}
|
288
|
-
let pkg;
|
289
|
-
if (packageName) {
|
290
|
-
pkg = this.packageCache.resolve(packageName, requestingPkg);
|
291
|
-
}
|
292
|
-
else {
|
293
|
-
pkg = requestingPkg;
|
294
|
-
}
|
295
|
-
let matched = (0, resolve_exports_1.exports)(pkg.packageJSON, '-embroider-entrypoint.js', {
|
296
|
-
browser: true,
|
297
|
-
conditions: ['default', 'imports'],
|
298
|
-
});
|
299
|
-
return logTransition('entrypoint', request, request.virtualize((0, path_1.resolve)(pkg.root, (_a = matched === null || matched === void 0 ? void 0 : matched[0]) !== null && _a !== void 0 ? _a : '-embroider-entrypoint.js')));
|
300
|
-
}
|
301
|
-
handleRouteEntrypoint(request) {
|
302
|
-
if (isTerminal(request)) {
|
303
|
-
return request;
|
304
|
-
}
|
305
|
-
let routeName = (0, virtual_route_entrypoint_1.decodePublicRouteEntrypoint)(request.specifier);
|
306
|
-
if (!routeName) {
|
307
|
-
return request;
|
308
|
-
}
|
309
|
-
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
310
|
-
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
|
311
|
-
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
|
312
|
-
}
|
313
|
-
let matched = (0, resolve_exports_1.exports)(pkg.packageJSON, '-embroider-route-entrypoint.js', {
|
314
|
-
browser: true,
|
315
|
-
conditions: ['default', 'imports'],
|
316
|
-
});
|
317
|
-
return logTransition('route entrypoint', request, request.virtualize((0, virtual_route_entrypoint_1.encodeRouteEntrypoint)(pkg.root, matched === null || matched === void 0 ? void 0 : matched[0], routeName)));
|
318
|
-
}
|
319
|
-
handleImplicitTestScripts(request) {
|
320
|
-
//TODO move the extra forwardslash handling out into the vite plugin
|
321
|
-
const candidates = [
|
322
|
-
'@embroider/core/test-support.js',
|
323
|
-
'/@embroider/core/test-support.js',
|
324
|
-
'./@embroider/core/test-support.js',
|
325
|
-
];
|
326
|
-
if (!candidates.includes(request.specifier)) {
|
327
|
-
return request;
|
328
|
-
}
|
329
|
-
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
330
|
-
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
331
|
-
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/core/test-support.js. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
332
|
-
}
|
333
|
-
return logTransition('test-support', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support.js')));
|
334
|
-
}
|
335
|
-
handleTestSupportStyles(request) {
|
336
|
-
//TODO move the extra forwardslash handling out into the vite plugin
|
337
|
-
const candidates = [
|
338
|
-
'@embroider/core/test-support.css',
|
339
|
-
'/@embroider/core/test-support.css',
|
340
|
-
'./@embroider/core/test-support.css',
|
341
|
-
];
|
342
|
-
if (!candidates.includes(request.specifier)) {
|
343
|
-
return request;
|
344
|
-
}
|
345
|
-
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
346
|
-
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
347
|
-
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/core/test-support.css. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
348
|
-
}
|
349
|
-
return logTransition('test-support-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support-styles.css')));
|
350
|
-
}
|
351
|
-
async handleGlobalsCompat(request) {
|
352
|
-
if (isTerminal(request)) {
|
353
|
-
return request;
|
354
|
-
}
|
302
|
+
handleGlobalsCompat(request) {
|
355
303
|
let match = compatPattern.exec(request.specifier);
|
356
304
|
if (!match) {
|
357
305
|
return request;
|
@@ -372,85 +320,62 @@ class Resolver {
|
|
372
320
|
case 'ambiguous':
|
373
321
|
return this.resolveHelperOrComponent(rest, engine, request);
|
374
322
|
default:
|
375
|
-
throw new Error(`bug: unexepected
|
376
|
-
}
|
377
|
-
}
|
378
|
-
handleVendorStyles(request) {
|
379
|
-
//TODO move the extra forwardslash handling out into the vite plugin
|
380
|
-
const candidates = ['@embroider/core/vendor.css', '/@embroider/core/vendor.css', './@embroider/core/vendor.css'];
|
381
|
-
if (!candidates.includes(request.specifier)) {
|
382
|
-
return request;
|
383
|
-
}
|
384
|
-
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
385
|
-
if (!pkg || !this.options.engines.some(e => e.root === (pkg === null || pkg === void 0 ? void 0 : pkg.root))) {
|
386
|
-
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app or Engine. The top-level Ember app is the only one that has support for @embroider/core/vendor.css. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
323
|
+
throw new Error(`bug: unexepected #embroider_compat specifier: ${request.specifier}`);
|
387
324
|
}
|
388
|
-
return logTransition('vendor-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor-styles.css')));
|
389
325
|
}
|
390
326
|
resolveHelper(path, inEngine, request) {
|
391
327
|
let target = this.parseGlobalPath(path, inEngine);
|
392
328
|
return logTransition('resolveHelper', request, request.alias(`${target.packageName}/helpers/${target.memberName}`).rehome((0, path_1.resolve)(inEngine.root, 'package.json')));
|
393
329
|
}
|
394
|
-
|
330
|
+
resolveComponent(path, inEngine, request) {
|
395
331
|
let target = this.parseGlobalPath(path, inEngine);
|
396
332
|
let hbsModule = null;
|
397
333
|
let jsModule = null;
|
398
334
|
// first, the various places our template might be.
|
399
335
|
for (let candidate of this.componentTemplateCandidates(target.packageName)) {
|
400
|
-
let
|
401
|
-
|
402
|
-
|
403
|
-
}));
|
404
|
-
if (resolution.type === 'found') {
|
405
|
-
hbsModule = resolution;
|
336
|
+
let resolution = this.nodeResolve(`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`, target.from);
|
337
|
+
if (resolution.type === 'real') {
|
338
|
+
hbsModule = resolution.filename;
|
406
339
|
break;
|
407
340
|
}
|
408
341
|
}
|
409
342
|
// then the various places our javascript might be.
|
410
343
|
for (let candidate of this.componentJSCandidates(target.packageName)) {
|
411
|
-
let
|
412
|
-
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from).withMeta({
|
413
|
-
runtimeFallback: false,
|
414
|
-
}));
|
415
|
-
if (resolution.type === 'ignored') {
|
416
|
-
return logTransition(`resolving to ignored component`, request, request.resolveTo(resolution));
|
417
|
-
}
|
344
|
+
let resolution = this.nodeResolve(`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`, target.from);
|
418
345
|
// .hbs is a resolvable extension for us, so we need to exclude it here.
|
419
346
|
// It matches as a priority lower than .js, so finding an .hbs means
|
420
347
|
// there's definitely not a .js.
|
421
|
-
if (resolution.type === '
|
422
|
-
jsModule = resolution;
|
348
|
+
if (resolution.type === 'real' && !resolution.filename.endsWith('.hbs')) {
|
349
|
+
jsModule = resolution.filename;
|
423
350
|
break;
|
424
351
|
}
|
425
352
|
}
|
426
353
|
if (hbsModule) {
|
427
|
-
|
354
|
+
if (!this.emberVersionSupportsSeparateTemplates) {
|
355
|
+
throw new Error(`Components with separately resolved templates were removed at Ember 6.0. Migrate to either co-located js/ts + hbs files or to gjs/gts. https://deprecations.emberjs.com/id/component-template-resolving/. Bad template was: ${hbsModule}.`);
|
356
|
+
}
|
357
|
+
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule, jsModule)));
|
428
358
|
}
|
429
359
|
else if (jsModule) {
|
430
|
-
return logTransition(`
|
360
|
+
return logTransition(`resolveComponent found only JS`, request, request.alias(jsModule).rehome(target.from));
|
431
361
|
}
|
432
362
|
else {
|
433
363
|
return logTransition(`resolveComponent failed`, request);
|
434
364
|
}
|
435
365
|
}
|
436
|
-
|
366
|
+
resolveHelperOrComponent(path, inEngine, request) {
|
437
367
|
// resolveHelper just rewrites our request to one that should target the
|
438
368
|
// component, so here to resolve the ambiguity we need to actually resolve
|
439
369
|
// that candidate to see if it works.
|
440
370
|
let helperCandidate = this.resolveHelper(path, inEngine, request);
|
441
|
-
let helperMatch =
|
442
|
-
|
443
|
-
|
444
|
-
// for the case of 'ignored' that means that esbuild found this helper in an external
|
445
|
-
// package so it should be considered found in this case and we should not look for a
|
446
|
-
// component with this name
|
447
|
-
if (helperMatch.type === 'found' || helperMatch.type === 'ignored') {
|
448
|
-
return logTransition('resolve to ambiguous case matched a helper', request, request.resolveTo(helperMatch));
|
371
|
+
let helperMatch = this.nodeResolve(helperCandidate.specifier, helperCandidate.fromFile);
|
372
|
+
if (helperMatch.type === 'real') {
|
373
|
+
return logTransition('ambiguous case matched a helper', request, helperCandidate);
|
449
374
|
}
|
450
375
|
// unlike resolveHelper, resolveComponent already does pre-resolution in
|
451
376
|
// order to deal with its own internal ambiguity around JS vs HBS vs
|
452
377
|
// colocation.≥
|
453
|
-
let componentMatch =
|
378
|
+
let componentMatch = this.resolveComponent(path, inEngine, request);
|
454
379
|
if (componentMatch !== request) {
|
455
380
|
return logTransition('ambiguous case matched a cmoponent', request, componentMatch);
|
456
381
|
}
|
@@ -475,7 +400,6 @@ class Resolver {
|
|
475
400
|
}
|
476
401
|
*componentJSCandidates(inPackageName) {
|
477
402
|
yield { prefix: '/components/', suffix: '' };
|
478
|
-
yield { prefix: '/components/', suffix: '/index' };
|
479
403
|
yield { prefix: '/components/', suffix: '/component' };
|
480
404
|
let pods = this.podPrefix(inPackageName);
|
481
405
|
if (pods) {
|
@@ -494,10 +418,10 @@ class Resolver {
|
|
494
418
|
parseGlobalPath(path, inEngine) {
|
495
419
|
let parts = path.split('@');
|
496
420
|
if (parts.length > 1 && parts[0].length > 0) {
|
497
|
-
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, '
|
421
|
+
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') };
|
498
422
|
}
|
499
423
|
else {
|
500
|
-
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, '
|
424
|
+
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') };
|
501
425
|
}
|
502
426
|
}
|
503
427
|
engineConfig(packageName) {
|
@@ -523,18 +447,14 @@ class Resolver {
|
|
523
447
|
if (!inAddonName.startsWith('./')) {
|
524
448
|
throw new Error(`addon ${addon.name} declares app-js in its package.json with the illegal name "${inAddonName}". It must start with "./" to make it clear that it's relative to the addon`);
|
525
449
|
}
|
526
|
-
let specifier = (0, reverse_exports_1.externalName)(addon.packageJSON, inAddonName);
|
527
|
-
if (!specifier) {
|
528
|
-
throw new Error(`${addon.name}'s package.json app-js refers to ${inAddonName}, but that module is not accessible from outside the package`);
|
529
|
-
}
|
530
450
|
let prevEntry = engineModules.get(inEngineName);
|
531
451
|
switch (prevEntry === null || prevEntry === void 0 ? void 0 : prevEntry.type) {
|
532
452
|
case undefined:
|
533
453
|
engineModules.set(inEngineName, {
|
534
454
|
type: 'app-only',
|
535
455
|
'app-js': {
|
536
|
-
|
537
|
-
|
456
|
+
localPath: inAddonName,
|
457
|
+
packageRoot: addon.root,
|
538
458
|
fromPackageName: addon.name,
|
539
459
|
},
|
540
460
|
});
|
@@ -547,8 +467,8 @@ class Resolver {
|
|
547
467
|
engineModules.set(inEngineName, {
|
548
468
|
type: 'both',
|
549
469
|
'app-js': {
|
550
|
-
|
551
|
-
|
470
|
+
localPath: inAddonName,
|
471
|
+
packageRoot: addon.root,
|
552
472
|
fromPackageName: addon.name,
|
553
473
|
},
|
554
474
|
'fastboot-js': prevEntry['fastboot-js'],
|
@@ -566,18 +486,14 @@ class Resolver {
|
|
566
486
|
if (!inAddonName.startsWith('./')) {
|
567
487
|
throw new Error(`addon ${addon.name} declares fastboot-js in its package.json with the illegal name "${inAddonName}". It must start with "./" to make it clear that it's relative to the addon`);
|
568
488
|
}
|
569
|
-
let specifier = (0, reverse_exports_1.externalName)(addon.packageJSON, inAddonName);
|
570
|
-
if (!specifier) {
|
571
|
-
throw new Error(`${addon.name}'s package.json fastboot-js refers to ${inAddonName}, but that module is not accessible from outside the package`);
|
572
|
-
}
|
573
489
|
let prevEntry = engineModules.get(inEngineName);
|
574
490
|
switch (prevEntry === null || prevEntry === void 0 ? void 0 : prevEntry.type) {
|
575
491
|
case undefined:
|
576
492
|
engineModules.set(inEngineName, {
|
577
493
|
type: 'fastboot-only',
|
578
494
|
'fastboot-js': {
|
579
|
-
|
580
|
-
|
495
|
+
localPath: inAddonName,
|
496
|
+
packageRoot: addon.root,
|
581
497
|
fromPackageName: addon.name,
|
582
498
|
},
|
583
499
|
});
|
@@ -590,8 +506,8 @@ class Resolver {
|
|
590
506
|
engineModules.set(inEngineName, {
|
591
507
|
type: 'both',
|
592
508
|
'fastboot-js': {
|
593
|
-
|
594
|
-
|
509
|
+
localPath: inAddonName,
|
510
|
+
packageRoot: addon.root,
|
595
511
|
fromPackageName: addon.name,
|
596
512
|
},
|
597
513
|
'app-js': prevEntry['app-js'],
|
@@ -612,8 +528,17 @@ class Resolver {
|
|
612
528
|
}
|
613
529
|
return owningEngine;
|
614
530
|
}
|
531
|
+
get emberVersion() {
|
532
|
+
return this.packageCache.get(this.options.engines[0].root).dependencies.find(d => d.name === 'ember-source')
|
533
|
+
.version;
|
534
|
+
}
|
535
|
+
get emberVersionSupportsSeparateTemplates() {
|
536
|
+
return (0, semver_1.satisfies)(this.emberVersion, '< 6.0.0-alpha.0', {
|
537
|
+
includePrerelease: true,
|
538
|
+
});
|
539
|
+
}
|
615
540
|
handleRewrittenPackages(request) {
|
616
|
-
if (
|
541
|
+
if (request.isVirtual) {
|
617
542
|
return request;
|
618
543
|
}
|
619
544
|
let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
@@ -632,6 +557,10 @@ class Resolver {
|
|
632
557
|
targetPkg = this.packageCache.resolve(packageName, requestingPkg);
|
633
558
|
}
|
634
559
|
catch (err) {
|
560
|
+
// this is not the place to report resolution failures. If the thing
|
561
|
+
// doesn't resolve, we're just not interested in redirecting it for
|
562
|
+
// backward-compat, that's all. The rest of the system will take care of
|
563
|
+
// reporting a failure to resolve (or handling it a different way)
|
635
564
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
636
565
|
throw err;
|
637
566
|
}
|
@@ -647,26 +576,14 @@ class Resolver {
|
|
647
576
|
return logTransition('request targets a moved package', request, this.resolveWithinMovedPackage(request, targetPkg));
|
648
577
|
}
|
649
578
|
else if (originalRequestingPkg !== requestingPkg) {
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
return logTransition('outbound request from moved package', request, request
|
654
|
-
// setting meta here because if this fails, we want the fallback
|
655
|
-
// logic to revert our rehome and continue from the *moved* package.
|
656
|
-
.withMeta({ originalFromFile: request.fromFile })
|
657
|
-
.rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
|
658
|
-
}
|
659
|
-
else {
|
660
|
-
// requesting package was moved and we failed to find its target. We
|
661
|
-
// can't let that accidentally succeed in the defaultResolve because we
|
662
|
-
// could escape the moved package system.
|
663
|
-
return logTransition('missing outbound request from moved package', request, request.notFound());
|
664
|
-
}
|
579
|
+
// in this case, the requesting package is moved but its destination is
|
580
|
+
// not, so we need to rehome the request back to the original location.
|
581
|
+
return logTransition('outbound request from moved package', request, request.withMeta({ wasMovedTo: request.fromFile }).rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
|
665
582
|
}
|
666
583
|
return request;
|
667
584
|
}
|
668
585
|
handleRenaming(request) {
|
669
|
-
if (
|
586
|
+
if (request.isVirtual) {
|
670
587
|
return request;
|
671
588
|
}
|
672
589
|
let packageName = (0, shared_internals_1.packageName)(request.specifier);
|
@@ -674,11 +591,14 @@ class Resolver {
|
|
674
591
|
return request;
|
675
592
|
}
|
676
593
|
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
594
|
+
if (!pkg || !pkg.isV2Ember()) {
|
595
|
+
return request;
|
596
|
+
}
|
677
597
|
// real deps take precedence over renaming rules. That is, a package like
|
678
598
|
// ember-source might provide backburner via module renaming, but if you
|
679
599
|
// have an explicit dependency on backburner you should still get that real
|
680
600
|
// copy.
|
681
|
-
if (!
|
601
|
+
if (!pkg.hasDependency(packageName)) {
|
682
602
|
for (let [candidate, replacement] of Object.entries(this.options.renameModules)) {
|
683
603
|
if (candidate === request.specifier) {
|
684
604
|
return logTransition(`renameModules`, request, request.alias(replacement));
|
@@ -696,75 +616,30 @@ class Resolver {
|
|
696
616
|
return logTransition(`renamePackages`, request, request.alias(request.specifier.replace(packageName, this.options.renamePackages[packageName])));
|
697
617
|
}
|
698
618
|
}
|
699
|
-
if (
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
//
|
704
|
-
|
705
|
-
// auto-upgraded packages always get automatically adjusted. They never
|
706
|
-
// supported fancy package.json exports features so this direct mapping
|
707
|
-
// to the root is always right.
|
708
|
-
// "my-app/foo" -> "./foo" from app's package.json
|
709
|
-
// "my-addon/foo" -> "my-addon/foo" from a package that's guaranteed to be able to resolve my-addon
|
710
|
-
let owningEngine = this.owningEngine(pkg);
|
711
|
-
let addonConfig = owningEngine.activeAddons.find(a => a.root === pkg.root);
|
712
|
-
if (addonConfig) {
|
713
|
-
// auto-upgraded addons get special support for self-resolving here.
|
714
|
-
return logTransition(`v1 addon self-import`, request, request.rehome(addonConfig.canResolveFromFile));
|
715
|
-
}
|
716
|
-
else {
|
717
|
-
// auto-upgraded apps will necessarily have packageJSON.exports
|
718
|
-
// because we insert them, so for that support we can fall through to
|
719
|
-
// that support below.
|
720
|
-
}
|
721
|
-
}
|
722
|
-
// v2 packages are supposed to use package.json `exports` to enable
|
723
|
-
// self-imports, but not all build tools actually follow the spec. This
|
724
|
-
// is a workaround for badly behaved packagers.
|
725
|
-
//
|
726
|
-
// Known upstream bugs this works around:
|
727
|
-
// - https://github.com/vitejs/vite/issues/9731
|
728
|
-
if (pkg.packageJSON.exports) {
|
729
|
-
let found = (0, resolve_exports_1.exports)(pkg.packageJSON, request.specifier, {
|
730
|
-
browser: true,
|
731
|
-
conditions: ['default', 'imports'],
|
732
|
-
});
|
733
|
-
if (found === null || found === void 0 ? void 0 : found[0]) {
|
734
|
-
return logTransition(`v2 self-import with package.json exports`, request, request.alias(found === null || found === void 0 ? void 0 : found[0]).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
|
735
|
-
}
|
736
|
-
}
|
619
|
+
if (pkg.meta['auto-upgraded'] && pkg.name === packageName) {
|
620
|
+
// we found a self-import, resolve it for them. Only auto-upgraded
|
621
|
+
// packages get this help, v2 packages are natively supposed to make their
|
622
|
+
// own modules resolvable, and we want to push them all to do that
|
623
|
+
// correctly.
|
624
|
+
return logTransition(`v1 self-import`, request, request.alias(request.specifier.replace(pkg.name, '.')).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
|
737
625
|
}
|
738
626
|
return request;
|
739
627
|
}
|
740
|
-
handleVendor(request) {
|
741
|
-
//TODO move the extra forwardslash handling out into the vite plugin
|
742
|
-
const candidates = ['@embroider/core/vendor.js', '/@embroider/core/vendor.js', './@embroider/core/vendor.js'];
|
743
|
-
if (!candidates.includes(request.specifier)) {
|
744
|
-
return request;
|
745
|
-
}
|
746
|
-
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
747
|
-
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
748
|
-
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/core/vendor.js. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
749
|
-
}
|
750
|
-
return logTransition('vendor', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor.js')));
|
751
|
-
}
|
752
628
|
resolveWithinMovedPackage(request, pkg) {
|
753
629
|
let levels = ['..'];
|
754
630
|
if (pkg.name.startsWith('@')) {
|
755
631
|
levels.push('..');
|
756
632
|
}
|
757
|
-
let originalFromFile = request.fromFile;
|
758
633
|
let newRequest = request.rehome((0, path_1.resolve)(pkg.root, ...levels, 'moved-package-target.js'));
|
759
634
|
if (newRequest === request) {
|
760
635
|
return request;
|
761
636
|
}
|
762
|
-
|
763
|
-
|
764
|
-
|
637
|
+
return newRequest.withMeta({
|
638
|
+
resolvedWithinPackage: pkg.root,
|
639
|
+
});
|
765
640
|
}
|
766
641
|
preHandleExternal(request) {
|
767
|
-
if (
|
642
|
+
if (request.isVirtual) {
|
768
643
|
return request;
|
769
644
|
}
|
770
645
|
let { specifier, fromFile } = request;
|
@@ -794,10 +669,10 @@ class Resolver {
|
|
794
669
|
}
|
795
670
|
// if the requesting file is in an addon's app-js, the relative request
|
796
671
|
// should really be understood as a request for a module in the containing
|
797
|
-
// engine
|
672
|
+
// engine
|
798
673
|
let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
|
799
674
|
if (logicalLocation) {
|
800
|
-
return logTransition('beforeResolve: relative import in app-js', request, request.
|
675
|
+
return logTransition('beforeResolve: relative import in app-js', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
|
801
676
|
}
|
802
677
|
return request;
|
803
678
|
}
|
@@ -812,11 +687,11 @@ class Resolver {
|
|
812
687
|
if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
|
813
688
|
// addons (whether auto-upgraded or not) may use the app's
|
814
689
|
// emberVirtualPeerDeps, like "@glimmer/component" etc.
|
815
|
-
|
816
|
-
|
817
|
-
throw new Error(`${pkg.name} is trying to import the emberVirtualPeerDep "${packageName}", but it seems to be missing`);
|
690
|
+
if (!this.options.activeAddons[packageName]) {
|
691
|
+
throw new Error(`${pkg.name} is trying to import the app's ${packageName} package, but it seems to be missing`);
|
818
692
|
}
|
819
|
-
|
693
|
+
let newHome = (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json');
|
694
|
+
return logTransition(`emberVirtualPeerDeps in v2 addon`, request, request.rehome(newHome));
|
820
695
|
}
|
821
696
|
// if this file is part of an addon's app-js, it's really the logical
|
822
697
|
// package to which it belongs (normally the app) that affects some policy
|
@@ -825,7 +700,7 @@ class Resolver {
|
|
825
700
|
if (logicalPackage.meta['auto-upgraded'] && !logicalPackage.hasDependency('ember-auto-import')) {
|
826
701
|
try {
|
827
702
|
let dep = this.packageCache.resolve(packageName, logicalPackage);
|
828
|
-
if (!dep.
|
703
|
+
if (!dep.isEmberPackage()) {
|
829
704
|
// classic ember addons can only import non-ember dependencies if they
|
830
705
|
// have ember-auto-import.
|
831
706
|
return this.external('v1 package without auto-import', request, specifier);
|
@@ -838,28 +713,14 @@ class Resolver {
|
|
838
713
|
}
|
839
714
|
}
|
840
715
|
// assertions on what native v2 addons can import
|
841
|
-
if (!pkg.
|
842
|
-
!
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
return request;
|
847
|
-
}
|
848
|
-
locateActiveAddon(packageName) {
|
849
|
-
if (packageName === this.options.modulePrefix) {
|
850
|
-
// the app itself is something that addon's can classically resolve if they know it's name.
|
851
|
-
return {
|
852
|
-
root: this.options.appRoot,
|
853
|
-
canResolveFromFile: (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json'),
|
854
|
-
};
|
855
|
-
}
|
856
|
-
for (let engine of this.options.engines) {
|
857
|
-
for (let addon of engine.activeAddons) {
|
858
|
-
if (addon.name === packageName) {
|
859
|
-
return addon;
|
860
|
-
}
|
716
|
+
if (!pkg.meta['auto-upgraded']) {
|
717
|
+
if (!pkg.meta['auto-upgraded'] &&
|
718
|
+
!appImportInAppTree(pkg, logicalPackage, packageName) &&
|
719
|
+
!reliablyResolvable(pkg, packageName)) {
|
720
|
+
throw new Error(`${pkg.name} is trying to import from ${packageName} but that is not one of its explicit dependencies`);
|
861
721
|
}
|
862
722
|
}
|
723
|
+
return request;
|
863
724
|
}
|
864
725
|
external(label, request, specifier) {
|
865
726
|
if (this.options.amdCompatibility === 'cjs') {
|
@@ -872,7 +733,7 @@ class Resolver {
|
|
872
733
|
entry = ['require', ['default', 'has']];
|
873
734
|
}
|
874
735
|
if (!entry) {
|
875
|
-
throw new Error(`
|
736
|
+
throw new Error(`A module tried to resolve "${request.specifier}" and didn't find it (${label}).
|
876
737
|
|
877
738
|
- Maybe a dependency declaration is missing?
|
878
739
|
- Remember that v1 addons can only import non-Ember-addon NPM dependencies if they include ember-auto-import in their dependencies.
|
@@ -893,11 +754,8 @@ class Resolver {
|
|
893
754
|
throw new Error(`Embroider's amdCompatibility option is disabled, but something tried to use it to access "${request.specifier}"`);
|
894
755
|
}
|
895
756
|
}
|
896
|
-
|
897
|
-
var _a, _b;
|
898
|
-
if (request.isVirtual) {
|
899
|
-
throw new Error('Build tool bug detected! Fallback resolve should never see a virtual request. It is expected that the defaultResolve for your bundler has already resolved this request');
|
900
|
-
}
|
757
|
+
fallbackResolve(request) {
|
758
|
+
var _a, _b, _c;
|
901
759
|
if (request.specifier === '@embroider/macros') {
|
902
760
|
// the macros package is always handled directly within babel (not
|
903
761
|
// necessarily as a real resolvable package), so we should not mess with it.
|
@@ -905,140 +763,109 @@ class Resolver {
|
|
905
763
|
// why we need to know about it.
|
906
764
|
return logTransition('fallback early exit', request);
|
907
765
|
}
|
908
|
-
|
766
|
+
let { specifier, fromFile } = request;
|
767
|
+
if (compatPattern.test(specifier)) {
|
909
768
|
// Some kinds of compat requests get rewritten into other things
|
910
|
-
// deterministically. For example, "
|
769
|
+
// deterministically. For example, "#embroider_compat/helpers/whatever"
|
911
770
|
// means only "the-current-engine/helpers/whatever", and if that doesn't
|
912
771
|
// actually exist it's that path that will show up as a missing import.
|
913
772
|
//
|
914
773
|
// But others have an ambiguous meaning. For example,
|
915
|
-
//
|
774
|
+
// #embroider_compat/components/whatever can mean several different
|
916
775
|
// things. If we're unable to find any of them, the actual
|
917
|
-
// "
|
776
|
+
// "#embroider_compat" request will fall through all the way to here.
|
918
777
|
//
|
919
778
|
// In that case, we don't want to externalize that failure. We know it's
|
920
779
|
// not a classic runtime thing. It's better to let it be a build error
|
921
780
|
// here.
|
922
781
|
return request;
|
923
782
|
}
|
924
|
-
|
925
|
-
|
926
|
-
|
783
|
+
if (fromFile.endsWith('moved-package-target.js')) {
|
784
|
+
if (!((_a = request.meta) === null || _a === void 0 ? void 0 : _a.resolvedWithinPackage)) {
|
785
|
+
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
786
|
+
}
|
787
|
+
fromFile = (0, path_1.resolve)((_b = request.meta) === null || _b === void 0 ? void 0 : _b.resolvedWithinPackage, 'package.json');
|
927
788
|
}
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
if (
|
939
|
-
|
789
|
+
let pkg = this.packageCache.ownerOfFile(fromFile);
|
790
|
+
if (!pkg) {
|
791
|
+
return logTransition('no identifiable owningPackage', request);
|
792
|
+
}
|
793
|
+
// if we rehomed this request to its un-rewritten location in order to try
|
794
|
+
// to do the defaultResolve from there, now we refer back to the rewritten
|
795
|
+
// location because that's what we want to use when asking things like
|
796
|
+
// isV2Ember()
|
797
|
+
let movedPkg = this.packageCache.maybeMoved(pkg);
|
798
|
+
if (movedPkg !== pkg) {
|
799
|
+
if (!((_c = request.meta) === null || _c === void 0 ? void 0 : _c.wasMovedTo)) {
|
800
|
+
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
940
801
|
}
|
941
|
-
|
802
|
+
fromFile = request.meta.wasMovedTo;
|
803
|
+
pkg = movedPkg;
|
942
804
|
}
|
943
|
-
|
805
|
+
if (!pkg.isV2Ember()) {
|
806
|
+
return logTransition('fallbackResolve: not in an ember package', request);
|
807
|
+
}
|
808
|
+
let packageName = (0, shared_internals_1.packageName)(specifier);
|
944
809
|
if (!packageName) {
|
945
810
|
// this is a relative import
|
946
|
-
|
811
|
+
let withinEngine = this.engineConfig(pkg.name);
|
812
|
+
if (withinEngine) {
|
813
|
+
// it's a relative import inside an engine (which also means app), which
|
814
|
+
// means we may need to satisfy the request via app tree merging.
|
815
|
+
let appJSMatch = this.searchAppTree(request, withinEngine, (0, shared_internals_2.explicitRelative)(pkg.root, (0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier)));
|
816
|
+
if (appJSMatch) {
|
817
|
+
return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
|
818
|
+
}
|
819
|
+
else {
|
820
|
+
return logTransition('fallbackResolve: relative appJs search failure', request);
|
821
|
+
}
|
822
|
+
}
|
823
|
+
else {
|
824
|
+
// nothing else to do for relative imports
|
825
|
+
return logTransition('fallbackResolve: relative failure', request);
|
826
|
+
}
|
947
827
|
}
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
828
|
+
// auto-upgraded packages can fall back to the set of known active addons
|
829
|
+
if (pkg.meta['auto-upgraded'] && this.options.activeAddons[packageName]) {
|
830
|
+
const rehomed = this.resolveWithinMovedPackage(request, this.packageCache.get(this.options.activeAddons[packageName]));
|
831
|
+
if (rehomed !== request) {
|
832
|
+
return logTransition(`activeAddons`, request, rehomed);
|
952
833
|
}
|
953
834
|
}
|
954
|
-
let logicalLocation = this.reverseSearchAppTree(pkg,
|
835
|
+
let logicalLocation = this.reverseSearchAppTree(pkg, fromFile);
|
955
836
|
if (logicalLocation) {
|
956
837
|
// the requesting file is in an addon's appTree. We didn't succeed in
|
957
838
|
// resolving this (non-relative) request from inside the actual addon, so
|
958
839
|
// next try to resolve it from the corresponding logical location in the
|
959
840
|
// app.
|
960
|
-
return logTransition('fallbackResolve: retry from logical home of app-js file', request,
|
961
|
-
// it might look more precise to rehome into logicalLocation.inAppName
|
962
|
-
// rather than package.json. But that logical location may not actually
|
963
|
-
// exist, and some systems (including node's require.resolve) will be
|
964
|
-
// mad about trying to resolve from notional paths that don't really
|
965
|
-
// exist.
|
966
|
-
request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
|
841
|
+
return logTransition('fallbackResolve: retry from logical home of app-js file', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
|
967
842
|
}
|
968
843
|
let targetingEngine = this.engineConfig(packageName);
|
969
844
|
if (targetingEngine) {
|
970
|
-
let appJSMatch =
|
845
|
+
let appJSMatch = this.searchAppTree(request, targetingEngine, specifier.replace(packageName, '.'));
|
971
846
|
if (appJSMatch) {
|
972
847
|
return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
|
973
848
|
}
|
974
849
|
}
|
975
|
-
if (pkg.
|
850
|
+
if (pkg.meta['auto-upgraded']) {
|
976
851
|
// auto-upgraded packages can fall back to attempting to find dependencies at
|
977
852
|
// runtime. Native v2 packages can only get this behavior in the
|
978
853
|
// isExplicitlyExternal case above because they need to explicitly ask for
|
979
854
|
// externals.
|
980
|
-
return this.external('v1 catch-all fallback', request,
|
855
|
+
return this.external('v1 catch-all fallback', request, specifier);
|
981
856
|
}
|
982
857
|
else {
|
983
858
|
// native v2 packages don't automatically externalize *everything* the way
|
984
859
|
// auto-upgraded packages do, but they still externalize known and approved
|
985
860
|
// ember virtual packages (like @ember/component)
|
986
861
|
if (shared_internals_1.emberVirtualPackages.has(packageName)) {
|
987
|
-
return this.external('emberVirtualPackages', request,
|
862
|
+
return this.external('emberVirtualPackages', request, specifier);
|
988
863
|
}
|
989
864
|
}
|
990
865
|
// this is falling through with the original specifier which was
|
991
866
|
// non-resolvable, which will presumably cause a static build error in stage3.
|
992
867
|
return logTransition('fallbackResolve final exit', request);
|
993
868
|
}
|
994
|
-
restoreRehomedRequest(pkg, request) {
|
995
|
-
var _a;
|
996
|
-
// meta.originalFromFile gets set when we want to try to rehome a request
|
997
|
-
// but then come back to the original location here in the fallback when the
|
998
|
-
// rehomed request fails
|
999
|
-
let movedPkg = this.packageCache.maybeMoved(pkg);
|
1000
|
-
if (movedPkg !== pkg) {
|
1001
|
-
let originalFromFile = (_a = request.meta) === null || _a === void 0 ? void 0 : _a.originalFromFile;
|
1002
|
-
if (typeof originalFromFile !== 'string') {
|
1003
|
-
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
1004
|
-
}
|
1005
|
-
request = request.rehome(originalFromFile);
|
1006
|
-
pkg = movedPkg;
|
1007
|
-
}
|
1008
|
-
return { pkg, request };
|
1009
|
-
}
|
1010
|
-
async relativeFallbackResolve(pkg, request) {
|
1011
|
-
let withinEngine = this.engineConfig(pkg.name);
|
1012
|
-
if (withinEngine) {
|
1013
|
-
// it's a relative import inside an engine (which also means app), which
|
1014
|
-
// means we may need to satisfy the request via app tree merging.
|
1015
|
-
let logicalName = engineRelativeName(pkg, (0, path_1.resolve)((0, path_1.dirname)(request.fromFile), request.specifier));
|
1016
|
-
if (!logicalName) {
|
1017
|
-
return logTransition('fallbackResolve: relative failure because this file is not externally accessible', request);
|
1018
|
-
}
|
1019
|
-
let appJSMatch = await this.searchAppTree(request, withinEngine, logicalName);
|
1020
|
-
if (appJSMatch) {
|
1021
|
-
return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
|
1022
|
-
}
|
1023
|
-
else {
|
1024
|
-
return logTransition('fallbackResolve: relative appJs search failure', request);
|
1025
|
-
}
|
1026
|
-
}
|
1027
|
-
else {
|
1028
|
-
// nothing else to do for relative imports
|
1029
|
-
return logTransition('fallbackResolve: relative failure', request);
|
1030
|
-
}
|
1031
|
-
}
|
1032
|
-
maybeFallbackToActiveAddon(request, requestedPackageName) {
|
1033
|
-
// auto-upgraded packages can fall back to the set of known active addons
|
1034
|
-
let addon = this.locateActiveAddon(requestedPackageName);
|
1035
|
-
if (addon) {
|
1036
|
-
const rehomed = request.rehome(addon.canResolveFromFile);
|
1037
|
-
if (rehomed !== request) {
|
1038
|
-
return logTransition(`activeAddons`, request, rehomed);
|
1039
|
-
}
|
1040
|
-
}
|
1041
|
-
}
|
1042
869
|
getEntryFromMergeMap(inEngineSpecifier, root) {
|
1043
870
|
var _a;
|
1044
871
|
let entry;
|
@@ -1059,23 +886,25 @@ class Resolver {
|
|
1059
886
|
}
|
1060
887
|
}
|
1061
888
|
}
|
1062
|
-
|
889
|
+
searchAppTree(request, engine, inEngineSpecifier) {
|
1063
890
|
let matched = this.getEntryFromMergeMap(inEngineSpecifier, engine.root);
|
1064
891
|
switch (matched === null || matched === void 0 ? void 0 : matched.entry.type) {
|
1065
892
|
case undefined:
|
1066
893
|
return undefined;
|
1067
894
|
case 'app-only':
|
1068
|
-
return request
|
895
|
+
return request
|
896
|
+
.alias(matched.entry['app-js'].localPath)
|
897
|
+
.rehome((0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
|
1069
898
|
case 'fastboot-only':
|
1070
|
-
return request
|
899
|
+
return request
|
900
|
+
.alias(matched.entry['fastboot-js'].localPath)
|
901
|
+
.rehome((0, path_1.resolve)(matched.entry['fastboot-js'].packageRoot, 'package.json'));
|
1071
902
|
case 'both':
|
1072
|
-
let foundAppJS =
|
1073
|
-
|
1074
|
-
}));
|
1075
|
-
if (foundAppJS.type !== 'found') {
|
903
|
+
let foundAppJS = this.nodeResolve(matched.entry['app-js'].localPath, (0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
|
904
|
+
if (foundAppJS.type !== 'real') {
|
1076
905
|
throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`);
|
1077
906
|
}
|
1078
|
-
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), {
|
907
|
+
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), {});
|
1079
908
|
return request.virtualize((0, virtual_content_1.fastbootSwitch)(matched.matched, (0, path_1.resolve)(engine.root, 'package.json'), names));
|
1080
909
|
}
|
1081
910
|
}
|
@@ -1110,10 +939,14 @@ class Resolver {
|
|
1110
939
|
if (engineConfig) {
|
1111
940
|
// we're directly inside an engine, so we're potentially resolvable as a
|
1112
941
|
// global component
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
942
|
+
// this kind of mapping is not true in general for all packages, but it
|
943
|
+
// *is* true for all classical engines (which includes apps) since they
|
944
|
+
// don't support package.json `exports`. As for a future v2 engine or app:
|
945
|
+
// this whole method is only relevant for implementing packageRules, which
|
946
|
+
// should only be for classic stuff. v2 packages should do the right
|
947
|
+
// things from the beginning and not need packageRules about themselves.
|
948
|
+
let inAppName = (0, shared_internals_2.explicitRelative)(engineConfig.root, filename);
|
949
|
+
return this.tryReverseComponent(engineConfig.packageName, inAppName);
|
1117
950
|
}
|
1118
951
|
let engineInfo = this.reverseSearchAppTree(owningPackage, filename);
|
1119
952
|
if (engineInfo) {
|
@@ -1137,6 +970,9 @@ exports.Resolver = Resolver;
|
|
1137
970
|
__decorate([
|
1138
971
|
(0, typescript_memoize_1.Memoize)()
|
1139
972
|
], Resolver.prototype, "mergeMap", null);
|
973
|
+
__decorate([
|
974
|
+
(0, typescript_memoize_1.Memoize)()
|
975
|
+
], Resolver.prototype, "emberVersionSupportsSeparateTemplates", null);
|
1140
976
|
function isExplicitlyExternal(specifier, fromPkg) {
|
1141
977
|
return Boolean(fromPkg.isV2Addon() && fromPkg.meta['externals'] && fromPkg.meta['externals'].includes(specifier));
|
1142
978
|
}
|
@@ -1161,10 +997,4 @@ function reliablyResolvable(pkg, packageName) {
|
|
1161
997
|
function appImportInAppTree(inPackage, inLogicalPackage, importedPackageName) {
|
1162
998
|
return inPackage !== inLogicalPackage && importedPackageName === inLogicalPackage.name;
|
1163
999
|
}
|
1164
|
-
function engineRelativeName(pkg, filename) {
|
1165
|
-
let outsideName = (0, reverse_exports_1.externalName)(pkg.packageJSON, (0, shared_internals_2.explicitRelative)(pkg.root, filename));
|
1166
|
-
if (outsideName) {
|
1167
|
-
return '.' + outsideName.slice(pkg.name.length);
|
1168
|
-
}
|
1169
|
-
}
|
1170
1000
|
//# sourceMappingURL=module-resolver.js.map
|