@embroider/core 3.4.10 → 3.4.11-unstable.0653f6d
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 +15 -12
- package/src/app-files.d.ts +3 -4
- package/src/app-files.js +10 -3
- package/src/app-files.js.map +1 -1
- package/src/describe-exports.js.map +1 -1
- package/src/html-entrypoint.js.map +1 -1
- package/src/html-placeholder.js.map +1 -1
- package/src/index.d.ts +1 -2
- package/src/index.js.map +1 -1
- package/src/messages.js.map +1 -1
- package/src/module-resolver.d.ts +31 -15
- package/src/module-resolver.js +346 -191
- package/src/module-resolver.js.map +1 -1
- package/src/node-resolve.d.ts +33 -0
- package/src/node-resolve.js +131 -0
- package/src/node-resolve.js.map +1 -0
- package/src/options.js.map +1 -1
- package/src/packager.js.map +1 -1
- package/src/portable-babel-config.js.map +1 -1
- package/src/portable-babel-launcher.js.map +1 -1
- package/src/portable.js.map +1 -1
- package/src/resolver-loader.js.map +1 -1
- package/src/to-broccoli-plugin.js.map +1 -1
- package/src/virtual-content.d.ts +6 -2
- package/src/virtual-content.js +119 -42
- package/src/virtual-content.js.map +1 -1
- package/src/virtual-entrypoint.d.ts +19 -0
- package/src/virtual-entrypoint.js +303 -0
- package/src/virtual-entrypoint.js.map +1 -0
- package/src/virtual-route-entrypoint.d.ts +15 -0
- package/src/virtual-route-entrypoint.js +102 -0
- package/src/virtual-route-entrypoint.js.map +1 -0
- package/src/virtual-test-entrypoint.d.ts +10 -0
- package/src/virtual-test-entrypoint.js +67 -0
- package/src/virtual-test-entrypoint.js.map +1 -0
- package/src/virtual-test-support-styles.d.ts +4 -0
- package/src/virtual-test-support-styles.js +65 -0
- package/src/virtual-test-support-styles.js.map +1 -0
- package/src/virtual-test-support.d.ts +4 -0
- package/src/virtual-test-support.js +69 -0
- package/src/virtual-test-support.js.map +1 -0
- package/src/virtual-vendor-styles.d.ts +4 -0
- package/src/virtual-vendor-styles.js +83 -0
- package/src/virtual-vendor-styles.js.map +1 -0
- package/src/virtual-vendor.d.ts +4 -0
- package/src/virtual-vendor.js +73 -0
- package/src/virtual-vendor.js.map +1 -0
- package/src/wait-for-trees.js.map +1 -1
- package/LICENSE +0 -21
- package/src/asset.d.ts +0 -33
- package/src/asset.js +0 -3
- package/src/asset.js.map +0 -1
- package/src/ember-html.d.ts +0 -43
- package/src/ember-html.js +0 -110
- package/src/ember-html.js.map +0 -1
package/src/module-resolver.js
CHANGED
@@ -15,63 +15,60 @@ 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
|
18
|
+
const reverse_exports_1 = __importDefault(require("@embroider/reverse-exports"));
|
19
|
+
const resolve_exports_1 = require("resolve.exports");
|
19
20
|
const virtual_content_1 = require("./virtual-content");
|
20
21
|
const typescript_memoize_1 = require("typescript-memoize");
|
21
22
|
const describe_exports_1 = require("./describe-exports");
|
22
23
|
const fs_1 = require("fs");
|
24
|
+
const node_resolve_1 = require("./node-resolve");
|
25
|
+
const virtual_route_entrypoint_1 = require("./virtual-route-entrypoint");
|
23
26
|
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
|
+
};
|
24
37
|
function logTransition(reason, before, after = before) {
|
25
38
|
if (after.isVirtual) {
|
26
|
-
debug(`
|
39
|
+
debug(`[%s:virtualized] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
40
|
+
}
|
41
|
+
else if (after.resolvedTo) {
|
42
|
+
debug(`[%s:resolvedTo] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
27
43
|
}
|
28
44
|
else if (before.specifier !== after.specifier) {
|
29
45
|
if (before.fromFile !== after.fromFile) {
|
30
|
-
debug(`aliased and rehomed
|
46
|
+
debug(`[%s:aliased and rehomed] %s to %s\n because %s\n from %p\n to %p`, before.debugType, before.specifier, after.specifier, reason, before.fromFile, after.fromFile);
|
31
47
|
}
|
32
48
|
else {
|
33
|
-
debug(`aliased
|
49
|
+
debug(`[%s:aliased] %s to %s\n because %s`, before.debugType, before.specifier, after.specifier, reason);
|
34
50
|
}
|
35
51
|
}
|
36
52
|
else if (before.fromFile !== after.fromFile) {
|
37
|
-
debug(`rehomed
|
53
|
+
debug(`[%s:rehomed] %s, because %s\n from %p\n to %p`, before.debugType, before.specifier, reason, before.fromFile, after.fromFile);
|
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
57
|
}
|
39
58
|
else {
|
40
|
-
debug(`
|
59
|
+
debug(`[%s:unchanged] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
41
60
|
}
|
42
61
|
return after;
|
43
62
|
}
|
44
|
-
|
45
|
-
|
46
|
-
constructor(specifier, fromFile, isVirtual, meta) {
|
47
|
-
this.specifier = specifier;
|
48
|
-
this.fromFile = fromFile;
|
49
|
-
this.isVirtual = isVirtual;
|
50
|
-
this.meta = meta;
|
51
|
-
}
|
52
|
-
alias(specifier) {
|
53
|
-
return new NodeModuleRequest(specifier, this.fromFile, false, this.meta);
|
54
|
-
}
|
55
|
-
rehome(fromFile) {
|
56
|
-
if (this.fromFile === fromFile) {
|
57
|
-
return this;
|
58
|
-
}
|
59
|
-
else {
|
60
|
-
return new NodeModuleRequest(this.specifier, fromFile, false, this.meta);
|
61
|
-
}
|
62
|
-
}
|
63
|
-
virtualize(filename) {
|
64
|
-
return new NodeModuleRequest(filename, this.fromFile, true, this.meta);
|
65
|
-
}
|
66
|
-
withMeta(meta) {
|
67
|
-
return new NodeModuleRequest(this.specifier, this.fromFile, this.isVirtual, meta);
|
68
|
-
}
|
63
|
+
function isTerminal(request) {
|
64
|
+
return request.isVirtual || request.isNotFound || Boolean(request.resolvedTo);
|
69
65
|
}
|
66
|
+
const compatPattern = /#embroider_compat\/(?<type>[^\/]+)\/(?<rest>.*)/;
|
70
67
|
class Resolver {
|
71
68
|
constructor(options) {
|
72
69
|
this.options = options;
|
73
70
|
}
|
74
|
-
beforeResolve(request) {
|
71
|
+
async beforeResolve(request) {
|
75
72
|
if (request.specifier === '@embroider/macros') {
|
76
73
|
// the macros package is always handled directly within babel (not
|
77
74
|
// necessarily as a real resolvable package), so we should not mess with it.
|
@@ -79,10 +76,20 @@ class Resolver {
|
|
79
76
|
// why we need to know about it.
|
80
77
|
return logTransition('early exit', request);
|
81
78
|
}
|
79
|
+
if (request.specifier === 'require') {
|
80
|
+
return this.external('early require', request, request.specifier);
|
81
|
+
}
|
82
82
|
request = this.handleFastbootSwitch(request);
|
83
|
-
request = this.handleGlobalsCompat(request);
|
83
|
+
request = await this.handleGlobalsCompat(request);
|
84
84
|
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.handleTestEntrypoint(request);
|
90
|
+
request = this.handleRouteEntrypoint(request);
|
85
91
|
request = this.handleRenaming(request);
|
92
|
+
request = this.handleVendor(request);
|
86
93
|
// we expect the specifier to be app relative at this point - must be after handleRenaming
|
87
94
|
request = this.generateFastbootSwitch(request);
|
88
95
|
request = this.preHandleExternal(request);
|
@@ -96,95 +103,45 @@ class Resolver {
|
|
96
103
|
// that calls your build system's normal module resolver, this does both pre-
|
97
104
|
// and post-resolution adjustments as needed to implement our compatibility
|
98
105
|
// rules.
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
let
|
105
|
-
let out = gen.next();
|
106
|
-
while (!out.done) {
|
107
|
-
out = gen.next(await out.value);
|
108
|
-
}
|
109
|
-
return out.value;
|
110
|
-
}
|
111
|
-
// synchronous alternative to resolve() above. Because our own internals are
|
112
|
-
// all synchronous, you can use this if your defaultResolve function is
|
113
|
-
// synchronous.
|
114
|
-
resolveSync(request, defaultResolve) {
|
115
|
-
let gen = this.internalResolve(request, defaultResolve);
|
116
|
-
let out = gen.next();
|
117
|
-
while (!out.done) {
|
118
|
-
out = gen.next(out.value);
|
119
|
-
}
|
120
|
-
return out.value;
|
121
|
-
}
|
122
|
-
// Our core implementation is a generator so it can power both resolve() and
|
123
|
-
// resolveSync()
|
124
|
-
*internalResolve(request, defaultResolve) {
|
125
|
-
request = this.beforeResolve(request);
|
126
|
-
let resolution = yield defaultResolve(request);
|
106
|
+
async resolve(request) {
|
107
|
+
request = await this.beforeResolve(request);
|
108
|
+
if (request.resolvedTo) {
|
109
|
+
return request.resolvedTo;
|
110
|
+
}
|
111
|
+
let resolution = await request.defaultResolve();
|
127
112
|
switch (resolution.type) {
|
128
113
|
case 'found':
|
114
|
+
case 'ignored':
|
129
115
|
return resolution;
|
130
116
|
case 'not_found':
|
131
117
|
break;
|
132
118
|
default:
|
133
119
|
throw (0, assert_never_1.default)(resolution);
|
134
120
|
}
|
135
|
-
let nextRequest = this.fallbackResolve(request);
|
121
|
+
let nextRequest = await this.fallbackResolve(request);
|
136
122
|
if (nextRequest === request) {
|
137
123
|
// no additional fallback is available.
|
138
124
|
return resolution;
|
139
125
|
}
|
126
|
+
if (nextRequest.resolvedTo) {
|
127
|
+
return nextRequest.resolvedTo;
|
128
|
+
}
|
140
129
|
if (nextRequest.fromFile === request.fromFile && nextRequest.specifier === request.specifier) {
|
141
130
|
throw new Error('Bug Discovered! New request is not === original request but has the same fromFile and specifier. This will likely create a loop.');
|
142
131
|
}
|
143
|
-
if (nextRequest.isVirtual) {
|
144
|
-
// virtual requests are terminal, there is no more
|
145
|
-
// fallbackResolve around them. The defaultResolve is
|
146
|
-
// to implement them.
|
147
|
-
return
|
132
|
+
if (nextRequest.isVirtual || nextRequest.isNotFound) {
|
133
|
+
// virtual and NotFound requests are terminal, there is no more
|
134
|
+
// beforeResolve or fallbackResolve around them. The defaultResolve is
|
135
|
+
// expected to know how to implement them.
|
136
|
+
return nextRequest.defaultResolve();
|
148
137
|
}
|
149
|
-
return
|
138
|
+
return this.resolve(nextRequest);
|
150
139
|
}
|
151
140
|
// Use standard NodeJS resolving, with our required compatibility rules on
|
152
141
|
// top. This is a convenience method for calling resolveSync with the
|
153
142
|
// defaultResolve already configured to be "do the normal node thing".
|
154
|
-
nodeResolve(specifier, fromFile) {
|
155
|
-
|
156
|
-
if (request.isVirtual) {
|
157
|
-
return {
|
158
|
-
type: 'found',
|
159
|
-
result: {
|
160
|
-
type: 'virtual',
|
161
|
-
content: (0, virtual_content_1.virtualContent)(request.specifier, this),
|
162
|
-
filename: request.specifier,
|
163
|
-
},
|
164
|
-
};
|
165
|
-
}
|
166
|
-
try {
|
167
|
-
let filename = resolve_1.default.sync(request.specifier, {
|
168
|
-
basedir: (0, path_1.dirname)(request.fromFile),
|
169
|
-
extensions: this.options.resolvableExtensions,
|
170
|
-
});
|
171
|
-
return { type: 'found', result: { type: 'real', filename } };
|
172
|
-
}
|
173
|
-
catch (err) {
|
174
|
-
if (err.code !== 'MODULE_NOT_FOUND') {
|
175
|
-
throw err;
|
176
|
-
}
|
177
|
-
return { type: 'not_found', err };
|
178
|
-
}
|
179
|
-
});
|
180
|
-
switch (resolution.type) {
|
181
|
-
case 'not_found':
|
182
|
-
return resolution;
|
183
|
-
case 'found':
|
184
|
-
return resolution.result;
|
185
|
-
default:
|
186
|
-
throw (0, assert_never_1.default)(resolution);
|
187
|
-
}
|
143
|
+
async nodeResolve(specifier, fromFile) {
|
144
|
+
return (0, node_resolve_1.nodeResolve)(this, specifier, fromFile);
|
188
145
|
}
|
189
146
|
get packageCache() {
|
190
147
|
return shared_internals_2.RewrittenPackageCache.shared('embroider', this.options.appRoot);
|
@@ -201,6 +158,9 @@ class Resolver {
|
|
201
158
|
return owningPackage;
|
202
159
|
}
|
203
160
|
generateFastbootSwitch(request) {
|
161
|
+
if (isTerminal(request)) {
|
162
|
+
return request;
|
163
|
+
}
|
204
164
|
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
205
165
|
if (!pkg) {
|
206
166
|
return request;
|
@@ -218,7 +178,9 @@ class Resolver {
|
|
218
178
|
let fastbootFile = engineConfig.fastbootFiles[candidate];
|
219
179
|
if (fastbootFile) {
|
220
180
|
if (fastbootFile.shadowedFilename) {
|
221
|
-
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)((0, path_1.resolve)(pkg.root, fastbootFile.shadowedFilename), 'utf8'), {
|
181
|
+
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)((0, path_1.resolve)(pkg.root, fastbootFile.shadowedFilename), 'utf8'), {
|
182
|
+
configFile: false,
|
183
|
+
});
|
222
184
|
let switchFile = (0, virtual_content_1.fastbootSwitch)(candidate, (0, path_1.resolve)(pkg.root, 'package.json'), names);
|
223
185
|
if (switchFile === request.fromFile) {
|
224
186
|
return logTransition('internal lookup from fastbootSwitch', request);
|
@@ -237,6 +199,9 @@ class Resolver {
|
|
237
199
|
}
|
238
200
|
handleFastbootSwitch(request) {
|
239
201
|
var _a;
|
202
|
+
if (isTerminal(request)) {
|
203
|
+
return request;
|
204
|
+
}
|
240
205
|
let match = (0, virtual_content_1.decodeFastbootSwitch)(request.fromFile);
|
241
206
|
if (!match) {
|
242
207
|
return request;
|
@@ -275,12 +240,15 @@ class Resolver {
|
|
275
240
|
}
|
276
241
|
let entry = (_a = this.getEntryFromMergeMap(rel, pkg.root)) === null || _a === void 0 ? void 0 : _a.entry;
|
277
242
|
if ((entry === null || entry === void 0 ? void 0 : entry.type) === 'both') {
|
278
|
-
return logTransition('matched addon entry', request, request.alias(entry[section].
|
243
|
+
return logTransition('matched addon entry', request, request.alias(entry[section].specifier).rehome(entry[section].fromFile));
|
279
244
|
}
|
280
245
|
}
|
281
246
|
return logTransition('failed to match in fastboot switch', request);
|
282
247
|
}
|
283
248
|
handleImplicitModules(request) {
|
249
|
+
if (isTerminal(request)) {
|
250
|
+
return request;
|
251
|
+
}
|
284
252
|
let im = (0, virtual_content_1.decodeImplicitModules)(request.specifier);
|
285
253
|
if (!im) {
|
286
254
|
return request;
|
@@ -298,7 +266,103 @@ class Resolver {
|
|
298
266
|
return logTransition(`own implicit modules`, request, request.virtualize((0, path_1.resolve)(pkg.root, `-embroider-${im.type}.js`)));
|
299
267
|
}
|
300
268
|
}
|
301
|
-
|
269
|
+
handleEntrypoint(request) {
|
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
|
+
return logTransition('entrypoint', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-entrypoint.js')));
|
296
|
+
}
|
297
|
+
handleTestEntrypoint(request) {
|
298
|
+
if (isTerminal(request)) {
|
299
|
+
return request;
|
300
|
+
}
|
301
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
302
|
+
const candidates = [
|
303
|
+
'@embroider/core/test-entrypoint',
|
304
|
+
'/@embroider/core/test-entrypoint',
|
305
|
+
'./@embroider/core/test-entrypoint',
|
306
|
+
];
|
307
|
+
if (!candidates.some(c => request.specifier === c)) {
|
308
|
+
return request;
|
309
|
+
}
|
310
|
+
const pkg = this.packageCache.ownerOfFile(request.fromFile);
|
311
|
+
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember()) || !pkg.isV2App()) {
|
312
|
+
throw new Error(`bug: found test entrypoint import from somewhere other than the top-level app engine: ${request.fromFile}`);
|
313
|
+
}
|
314
|
+
return logTransition('test-entrypoint', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-entrypoint.js')));
|
315
|
+
}
|
316
|
+
handleRouteEntrypoint(request) {
|
317
|
+
if (isTerminal(request)) {
|
318
|
+
return request;
|
319
|
+
}
|
320
|
+
let routeName = (0, virtual_route_entrypoint_1.decodePublicRouteEntrypoint)(request.specifier);
|
321
|
+
if (!routeName) {
|
322
|
+
return request;
|
323
|
+
}
|
324
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
325
|
+
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
|
326
|
+
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
|
327
|
+
}
|
328
|
+
return logTransition('route entrypoint', request, request.virtualize((0, virtual_route_entrypoint_1.encodeRouteEntrypoint)(pkg.root, routeName)));
|
329
|
+
}
|
330
|
+
handleImplicitTestScripts(request) {
|
331
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
332
|
+
const candidates = [
|
333
|
+
'@embroider/core/test-support.js',
|
334
|
+
'/@embroider/core/test-support.js',
|
335
|
+
'./@embroider/core/test-support.js',
|
336
|
+
];
|
337
|
+
if (!candidates.includes(request.specifier)) {
|
338
|
+
return request;
|
339
|
+
}
|
340
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
341
|
+
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
342
|
+
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.`);
|
343
|
+
}
|
344
|
+
return logTransition('test-support', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support.js')));
|
345
|
+
}
|
346
|
+
handleTestSupportStyles(request) {
|
347
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
348
|
+
const candidates = [
|
349
|
+
'@embroider/core/test-support.css',
|
350
|
+
'/@embroider/core/test-support.css',
|
351
|
+
'./@embroider/core/test-support.css',
|
352
|
+
];
|
353
|
+
if (!candidates.includes(request.specifier)) {
|
354
|
+
return request;
|
355
|
+
}
|
356
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
357
|
+
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
358
|
+
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.`);
|
359
|
+
}
|
360
|
+
return logTransition('test-support-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support-styles.css')));
|
361
|
+
}
|
362
|
+
async handleGlobalsCompat(request) {
|
363
|
+
if (isTerminal(request)) {
|
364
|
+
return request;
|
365
|
+
}
|
302
366
|
let match = compatPattern.exec(request.specifier);
|
303
367
|
if (!match) {
|
304
368
|
return request;
|
@@ -322,56 +386,76 @@ class Resolver {
|
|
322
386
|
throw new Error(`bug: unexepected #embroider_compat specifier: ${request.specifier}`);
|
323
387
|
}
|
324
388
|
}
|
389
|
+
handleVendorStyles(request) {
|
390
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
391
|
+
const candidates = ['@embroider/core/vendor.css', '/@embroider/core/vendor.css', './@embroider/core/vendor.css'];
|
392
|
+
if (!candidates.includes(request.specifier)) {
|
393
|
+
return request;
|
394
|
+
}
|
395
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
396
|
+
if (!pkg || !this.options.engines.some(e => e.root === (pkg === null || pkg === void 0 ? void 0 : pkg.root))) {
|
397
|
+
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.`);
|
398
|
+
}
|
399
|
+
return logTransition('vendor-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor-styles.css')));
|
400
|
+
}
|
325
401
|
resolveHelper(path, inEngine, request) {
|
326
402
|
let target = this.parseGlobalPath(path, inEngine);
|
327
403
|
return logTransition('resolveHelper', request, request.alias(`${target.packageName}/helpers/${target.memberName}`).rehome((0, path_1.resolve)(inEngine.root, 'package.json')));
|
328
404
|
}
|
329
|
-
resolveComponent(path, inEngine, request) {
|
405
|
+
async resolveComponent(path, inEngine, request) {
|
330
406
|
let target = this.parseGlobalPath(path, inEngine);
|
331
407
|
let hbsModule = null;
|
332
408
|
let jsModule = null;
|
333
409
|
// first, the various places our template might be.
|
334
410
|
for (let candidate of this.componentTemplateCandidates(target.packageName)) {
|
335
|
-
let
|
336
|
-
|
337
|
-
|
411
|
+
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;
|
412
|
+
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from).withMeta({
|
413
|
+
runtimeFallback: false,
|
414
|
+
}));
|
415
|
+
if (resolution.type === 'found') {
|
416
|
+
hbsModule = resolution;
|
338
417
|
break;
|
339
418
|
}
|
340
419
|
}
|
341
420
|
// then the various places our javascript might be.
|
342
421
|
for (let candidate of this.componentJSCandidates(target.packageName)) {
|
343
|
-
let
|
422
|
+
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;
|
423
|
+
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from).withMeta({
|
424
|
+
runtimeFallback: false,
|
425
|
+
}));
|
344
426
|
// .hbs is a resolvable extension for us, so we need to exclude it here.
|
345
427
|
// It matches as a priority lower than .js, so finding an .hbs means
|
346
428
|
// there's definitely not a .js.
|
347
|
-
if (resolution.type === '
|
348
|
-
jsModule = resolution
|
429
|
+
if (resolution.type === 'found' && !resolution.filename.endsWith('.hbs')) {
|
430
|
+
jsModule = resolution;
|
349
431
|
break;
|
350
432
|
}
|
351
433
|
}
|
352
434
|
if (hbsModule) {
|
353
|
-
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule, jsModule)));
|
435
|
+
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule.filename, jsModule === null || jsModule === void 0 ? void 0 : jsModule.filename)));
|
354
436
|
}
|
355
437
|
else if (jsModule) {
|
356
|
-
return logTransition(`resolveComponent found only JS`, request, request.
|
438
|
+
return logTransition(`resolving to resolveComponent found only JS`, request, request.resolveTo(jsModule));
|
357
439
|
}
|
358
440
|
else {
|
359
441
|
return logTransition(`resolveComponent failed`, request);
|
360
442
|
}
|
361
443
|
}
|
362
|
-
resolveHelperOrComponent(path, inEngine, request) {
|
444
|
+
async resolveHelperOrComponent(path, inEngine, request) {
|
363
445
|
// resolveHelper just rewrites our request to one that should target the
|
364
446
|
// component, so here to resolve the ambiguity we need to actually resolve
|
365
447
|
// that candidate to see if it works.
|
366
448
|
let helperCandidate = this.resolveHelper(path, inEngine, request);
|
367
|
-
let helperMatch = this.
|
368
|
-
|
369
|
-
|
449
|
+
let helperMatch = await this.resolve(request.alias(helperCandidate.specifier).rehome(helperCandidate.fromFile).withMeta({
|
450
|
+
runtimeFallback: false,
|
451
|
+
}));
|
452
|
+
if (helperMatch.type === 'found') {
|
453
|
+
return logTransition('resolve to ambiguous case matched a helper', request, request.resolveTo(helperMatch));
|
370
454
|
}
|
371
455
|
// unlike resolveHelper, resolveComponent already does pre-resolution in
|
372
456
|
// order to deal with its own internal ambiguity around JS vs HBS vs
|
373
457
|
// colocation.≥
|
374
|
-
let componentMatch = this.resolveComponent(path, inEngine, request);
|
458
|
+
let componentMatch = await this.resolveComponent(path, inEngine, request);
|
375
459
|
if (componentMatch !== request) {
|
376
460
|
return logTransition('ambiguous case matched a cmoponent', request, componentMatch);
|
377
461
|
}
|
@@ -396,6 +480,7 @@ class Resolver {
|
|
396
480
|
}
|
397
481
|
*componentJSCandidates(inPackageName) {
|
398
482
|
yield { prefix: '/components/', suffix: '' };
|
483
|
+
yield { prefix: '/components/', suffix: '/index' };
|
399
484
|
yield { prefix: '/components/', suffix: '/component' };
|
400
485
|
let pods = this.podPrefix(inPackageName);
|
401
486
|
if (pods) {
|
@@ -414,10 +499,10 @@ class Resolver {
|
|
414
499
|
parseGlobalPath(path, inEngine) {
|
415
500
|
let parts = path.split('@');
|
416
501
|
if (parts.length > 1 && parts[0].length > 0) {
|
417
|
-
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, '
|
502
|
+
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'package.json') };
|
418
503
|
}
|
419
504
|
else {
|
420
|
-
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, '
|
505
|
+
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'package.json') };
|
421
506
|
}
|
422
507
|
}
|
423
508
|
engineConfig(packageName) {
|
@@ -449,8 +534,8 @@ class Resolver {
|
|
449
534
|
engineModules.set(inEngineName, {
|
450
535
|
type: 'app-only',
|
451
536
|
'app-js': {
|
452
|
-
|
453
|
-
|
537
|
+
specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
|
538
|
+
fromFile: addonConfig.canResolveFromFile,
|
454
539
|
fromPackageName: addon.name,
|
455
540
|
},
|
456
541
|
});
|
@@ -463,8 +548,8 @@ class Resolver {
|
|
463
548
|
engineModules.set(inEngineName, {
|
464
549
|
type: 'both',
|
465
550
|
'app-js': {
|
466
|
-
|
467
|
-
|
551
|
+
specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
|
552
|
+
fromFile: addonConfig.canResolveFromFile,
|
468
553
|
fromPackageName: addon.name,
|
469
554
|
},
|
470
555
|
'fastboot-js': prevEntry['fastboot-js'],
|
@@ -488,8 +573,8 @@ class Resolver {
|
|
488
573
|
engineModules.set(inEngineName, {
|
489
574
|
type: 'fastboot-only',
|
490
575
|
'fastboot-js': {
|
491
|
-
|
492
|
-
|
576
|
+
specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
|
577
|
+
fromFile: addonConfig.canResolveFromFile,
|
493
578
|
fromPackageName: addon.name,
|
494
579
|
},
|
495
580
|
});
|
@@ -502,8 +587,8 @@ class Resolver {
|
|
502
587
|
engineModules.set(inEngineName, {
|
503
588
|
type: 'both',
|
504
589
|
'fastboot-js': {
|
505
|
-
|
506
|
-
|
590
|
+
specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
|
591
|
+
fromFile: addonConfig.canResolveFromFile,
|
507
592
|
fromPackageName: addon.name,
|
508
593
|
},
|
509
594
|
'app-js': prevEntry['app-js'],
|
@@ -525,7 +610,7 @@ class Resolver {
|
|
525
610
|
return owningEngine;
|
526
611
|
}
|
527
612
|
handleRewrittenPackages(request) {
|
528
|
-
if (request
|
613
|
+
if (isTerminal(request)) {
|
529
614
|
return request;
|
530
615
|
}
|
531
616
|
let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
@@ -544,10 +629,6 @@ class Resolver {
|
|
544
629
|
targetPkg = this.packageCache.resolve(packageName, requestingPkg);
|
545
630
|
}
|
546
631
|
catch (err) {
|
547
|
-
// this is not the place to report resolution failures. If the thing
|
548
|
-
// doesn't resolve, we're just not interested in redirecting it for
|
549
|
-
// backward-compat, that's all. The rest of the system will take care of
|
550
|
-
// reporting a failure to resolve (or handling it a different way)
|
551
632
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
552
633
|
throw err;
|
553
634
|
}
|
@@ -563,14 +644,26 @@ class Resolver {
|
|
563
644
|
return logTransition('request targets a moved package', request, this.resolveWithinMovedPackage(request, targetPkg));
|
564
645
|
}
|
565
646
|
else if (originalRequestingPkg !== requestingPkg) {
|
566
|
-
|
567
|
-
|
568
|
-
|
647
|
+
if (targetPkg) {
|
648
|
+
// in this case, the requesting package is moved but its destination is
|
649
|
+
// not, so we need to rehome the request back to the original location.
|
650
|
+
return logTransition('outbound request from moved package', request, request
|
651
|
+
// setting meta here because if this fails, we want the fallback
|
652
|
+
// logic to revert our rehome and continue from the *moved* package.
|
653
|
+
.withMeta({ originalFromFile: request.fromFile })
|
654
|
+
.rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
|
655
|
+
}
|
656
|
+
else {
|
657
|
+
// requesting package was moved and we failed to find its target. We
|
658
|
+
// can't let that accidentally succeed in the defaultResolve because we
|
659
|
+
// could escape the moved package system.
|
660
|
+
return logTransition('missing outbound request from moved package', request, request.notFound());
|
661
|
+
}
|
569
662
|
}
|
570
663
|
return request;
|
571
664
|
}
|
572
665
|
handleRenaming(request) {
|
573
|
-
if (request
|
666
|
+
if (isTerminal(request)) {
|
574
667
|
return request;
|
575
668
|
}
|
576
669
|
let packageName = (0, shared_internals_1.packageName)(request.specifier);
|
@@ -603,30 +696,65 @@ class Resolver {
|
|
603
696
|
return logTransition(`renamePackages`, request, request.alias(request.specifier.replace(packageName, this.options.renamePackages[packageName])));
|
604
697
|
}
|
605
698
|
}
|
606
|
-
if (pkg.
|
607
|
-
// we found a self-import
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
699
|
+
if (pkg.name === packageName) {
|
700
|
+
// we found a self-import
|
701
|
+
if (pkg.meta['auto-upgraded']) {
|
702
|
+
// auto-upgraded packages always get automatically adjusted. They never
|
703
|
+
// supported fancy package.json exports features so this direct mapping
|
704
|
+
// to the root is always right.
|
705
|
+
// "my-package/foo" -> "./foo"
|
706
|
+
// "my-package" -> "./" (this can't be just "." because node's require.resolve doesn't reliable support that)
|
707
|
+
let selfImportPath = request.specifier === pkg.name ? './' : request.specifier.replace(pkg.name, '.');
|
708
|
+
return logTransition(`v1 self-import`, request, request.alias(selfImportPath).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
|
709
|
+
}
|
710
|
+
else {
|
711
|
+
// v2 packages are supposed to use package.json `exports` to enable
|
712
|
+
// self-imports, but not all build tools actually follow the spec. This
|
713
|
+
// is a workaround for badly behaved packagers.
|
714
|
+
//
|
715
|
+
// Known upstream bugs this works around:
|
716
|
+
// - https://github.com/vitejs/vite/issues/9731
|
717
|
+
if (pkg.packageJSON.exports) {
|
718
|
+
let found = (0, resolve_exports_1.exports)(pkg.packageJSON, request.specifier, {
|
719
|
+
browser: true,
|
720
|
+
conditions: ['default', 'imports'],
|
721
|
+
});
|
722
|
+
if (found === null || found === void 0 ? void 0 : found[0]) {
|
723
|
+
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')));
|
724
|
+
}
|
725
|
+
}
|
726
|
+
}
|
612
727
|
}
|
613
728
|
return request;
|
614
729
|
}
|
730
|
+
handleVendor(request) {
|
731
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
732
|
+
const candidates = ['@embroider/core/vendor.js', '/@embroider/core/vendor.js', './@embroider/core/vendor.js'];
|
733
|
+
if (!candidates.includes(request.specifier)) {
|
734
|
+
return request;
|
735
|
+
}
|
736
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
737
|
+
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
738
|
+
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.`);
|
739
|
+
}
|
740
|
+
return logTransition('vendor', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor.js')));
|
741
|
+
}
|
615
742
|
resolveWithinMovedPackage(request, pkg) {
|
616
743
|
let levels = ['..'];
|
617
744
|
if (pkg.name.startsWith('@')) {
|
618
745
|
levels.push('..');
|
619
746
|
}
|
747
|
+
let originalFromFile = request.fromFile;
|
620
748
|
let newRequest = request.rehome((0, path_1.resolve)(pkg.root, ...levels, 'moved-package-target.js'));
|
621
749
|
if (newRequest === request) {
|
622
750
|
return request;
|
623
751
|
}
|
624
|
-
|
625
|
-
|
626
|
-
});
|
752
|
+
// setting meta because if this fails, we want the fallback to pick up back
|
753
|
+
// in the original requesting package.
|
754
|
+
return newRequest.withMeta({ originalFromFile });
|
627
755
|
}
|
628
756
|
preHandleExternal(request) {
|
629
|
-
if (request
|
757
|
+
if (isTerminal(request)) {
|
630
758
|
return request;
|
631
759
|
}
|
632
760
|
let { specifier, fromFile } = request;
|
@@ -659,7 +787,15 @@ class Resolver {
|
|
659
787
|
// engine
|
660
788
|
let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
|
661
789
|
if (logicalLocation) {
|
662
|
-
return logTransition('beforeResolve: relative import in app-js', request, request
|
790
|
+
return logTransition('beforeResolve: relative import in app-js', request, request
|
791
|
+
.alias('./' + path_1.posix.join((0, path_1.dirname)(logicalLocation.inAppName), request.specifier))
|
792
|
+
// it's important that we're rehoming this to the root of the engine
|
793
|
+
// (which we know really exists), and not to a subdir like
|
794
|
+
// logicalLocation.inAppName (which might not physically exist),
|
795
|
+
// because some environments (including node's require.resolve) will
|
796
|
+
// refuse to do resolution from a notional path that doesn't
|
797
|
+
// physically exist.
|
798
|
+
.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
|
663
799
|
}
|
664
800
|
return request;
|
665
801
|
}
|
@@ -674,11 +810,11 @@ class Resolver {
|
|
674
810
|
if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
|
675
811
|
// addons (whether auto-upgraded or not) may use the app's
|
676
812
|
// emberVirtualPeerDeps, like "@glimmer/component" etc.
|
677
|
-
|
678
|
-
|
813
|
+
let addon = this.locateActiveAddon(packageName);
|
814
|
+
if (!addon) {
|
815
|
+
throw new Error(`${pkg.name} is trying to import the emberVirtualPeerDep "${packageName}", but it seems to be missing`);
|
679
816
|
}
|
680
|
-
|
681
|
-
return logTransition(`emberVirtualPeerDeps in v2 addon`, request, request.rehome(newHome));
|
817
|
+
return logTransition(`emberVirtualPeerDeps`, request, request.rehome(addon.canResolveFromFile));
|
682
818
|
}
|
683
819
|
// if this file is part of an addon's app-js, it's really the logical
|
684
820
|
// package to which it belongs (normally the app) that affects some policy
|
@@ -709,6 +845,22 @@ class Resolver {
|
|
709
845
|
}
|
710
846
|
return request;
|
711
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
|
+
}
|
861
|
+
}
|
862
|
+
}
|
863
|
+
}
|
712
864
|
external(label, request, specifier) {
|
713
865
|
if (this.options.amdCompatibility === 'cjs') {
|
714
866
|
let filename = (0, virtual_content_1.virtualExternalCJSModule)(specifier);
|
@@ -741,8 +893,11 @@ class Resolver {
|
|
741
893
|
throw new Error(`Embroider's amdCompatibility option is disabled, but something tried to use it to access "${request.specifier}"`);
|
742
894
|
}
|
743
895
|
}
|
744
|
-
fallbackResolve(request) {
|
896
|
+
async fallbackResolve(request) {
|
745
897
|
var _a, _b, _c;
|
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
|
+
}
|
746
901
|
if (request.specifier === '@embroider/macros') {
|
747
902
|
// the macros package is always handled directly within babel (not
|
748
903
|
// necessarily as a real resolvable package), so we should not mess with it.
|
@@ -750,8 +905,7 @@ class Resolver {
|
|
750
905
|
// why we need to know about it.
|
751
906
|
return logTransition('fallback early exit', request);
|
752
907
|
}
|
753
|
-
|
754
|
-
if (compatPattern.test(specifier)) {
|
908
|
+
if (compatPattern.test(request.specifier)) {
|
755
909
|
// Some kinds of compat requests get rewritten into other things
|
756
910
|
// deterministically. For example, "#embroider_compat/helpers/whatever"
|
757
911
|
// means only "the-current-engine/helpers/whatever", and if that doesn't
|
@@ -767,39 +921,33 @@ class Resolver {
|
|
767
921
|
// here.
|
768
922
|
return request;
|
769
923
|
}
|
770
|
-
|
771
|
-
if (!((_a = request.meta) === null || _a === void 0 ? void 0 : _a.resolvedWithinPackage)) {
|
772
|
-
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
773
|
-
}
|
774
|
-
fromFile = (0, path_1.resolve)((_b = request.meta) === null || _b === void 0 ? void 0 : _b.resolvedWithinPackage, 'package.json');
|
775
|
-
}
|
776
|
-
let pkg = this.packageCache.ownerOfFile(fromFile);
|
924
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
777
925
|
if (!pkg) {
|
778
926
|
return logTransition('no identifiable owningPackage', request);
|
779
927
|
}
|
780
|
-
//
|
781
|
-
// to
|
782
|
-
//
|
783
|
-
// isV2Ember()
|
928
|
+
// meta.originalFromFile gets set when we want to try to rehome a request
|
929
|
+
// but then come back to the original location here in the fallback when the
|
930
|
+
// rehomed request fails
|
784
931
|
let movedPkg = this.packageCache.maybeMoved(pkg);
|
785
932
|
if (movedPkg !== pkg) {
|
786
|
-
|
933
|
+
let originalFromFile = (_a = request.meta) === null || _a === void 0 ? void 0 : _a.originalFromFile;
|
934
|
+
if (typeof originalFromFile !== 'string') {
|
787
935
|
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
788
936
|
}
|
789
|
-
|
937
|
+
request = request.rehome(originalFromFile);
|
790
938
|
pkg = movedPkg;
|
791
939
|
}
|
792
940
|
if (!pkg.isV2Ember()) {
|
793
941
|
return logTransition('fallbackResolve: not in an ember package', request);
|
794
942
|
}
|
795
|
-
let packageName = (0, shared_internals_1.packageName)(specifier);
|
943
|
+
let packageName = (0, shared_internals_1.packageName)(request.specifier);
|
796
944
|
if (!packageName) {
|
797
945
|
// this is a relative import
|
798
946
|
let withinEngine = this.engineConfig(pkg.name);
|
799
947
|
if (withinEngine) {
|
800
948
|
// it's a relative import inside an engine (which also means app), which
|
801
949
|
// means we may need to satisfy the request via app tree merging.
|
802
|
-
let appJSMatch = this.searchAppTree(request, withinEngine, (0, shared_internals_2.explicitRelative)(pkg.root, (0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier)));
|
950
|
+
let appJSMatch = await this.searchAppTree(request, withinEngine, (0, shared_internals_2.explicitRelative)(pkg.root, (0, path_1.resolve)((0, path_1.dirname)(request.fromFile), request.specifier)));
|
803
951
|
if (appJSMatch) {
|
804
952
|
return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
|
805
953
|
}
|
@@ -813,40 +961,49 @@ class Resolver {
|
|
813
961
|
}
|
814
962
|
}
|
815
963
|
// auto-upgraded packages can fall back to the set of known active addons
|
816
|
-
if (pkg.meta['auto-upgraded']
|
817
|
-
|
818
|
-
if (
|
819
|
-
|
964
|
+
if (pkg.meta['auto-upgraded']) {
|
965
|
+
let addon = this.locateActiveAddon(packageName);
|
966
|
+
if (addon) {
|
967
|
+
const rehomed = request.rehome(addon.canResolveFromFile);
|
968
|
+
if (rehomed !== request) {
|
969
|
+
return logTransition(`activeAddons`, request, rehomed);
|
970
|
+
}
|
820
971
|
}
|
821
972
|
}
|
822
|
-
let logicalLocation = this.reverseSearchAppTree(pkg, fromFile);
|
973
|
+
let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
|
823
974
|
if (logicalLocation) {
|
824
975
|
// the requesting file is in an addon's appTree. We didn't succeed in
|
825
976
|
// resolving this (non-relative) request from inside the actual addon, so
|
826
977
|
// next try to resolve it from the corresponding logical location in the
|
827
978
|
// app.
|
828
|
-
return logTransition('fallbackResolve: retry from logical home of app-js file', request,
|
979
|
+
return logTransition('fallbackResolve: retry from logical home of app-js file', request,
|
980
|
+
// it might look more precise to rehome into logicalLocation.inAppName
|
981
|
+
// rather than package.json. But that logical location may not actually
|
982
|
+
// exist, and some systems (including node's require.resolve) will be
|
983
|
+
// mad about trying to resolve from notional paths that don't really
|
984
|
+
// exist.
|
985
|
+
request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
|
829
986
|
}
|
830
987
|
let targetingEngine = this.engineConfig(packageName);
|
831
988
|
if (targetingEngine) {
|
832
|
-
let appJSMatch = this.searchAppTree(request, targetingEngine, specifier.replace(packageName, '.'));
|
989
|
+
let appJSMatch = await this.searchAppTree(request, targetingEngine, request.specifier.replace(packageName, '.'));
|
833
990
|
if (appJSMatch) {
|
834
991
|
return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
|
835
992
|
}
|
836
993
|
}
|
837
|
-
if (pkg.meta['auto-upgraded']) {
|
994
|
+
if (pkg.meta['auto-upgraded'] && ((_c = (_b = request.meta) === null || _b === void 0 ? void 0 : _b.runtimeFallback) !== null && _c !== void 0 ? _c : true)) {
|
838
995
|
// auto-upgraded packages can fall back to attempting to find dependencies at
|
839
996
|
// runtime. Native v2 packages can only get this behavior in the
|
840
997
|
// isExplicitlyExternal case above because they need to explicitly ask for
|
841
998
|
// externals.
|
842
|
-
return this.external('v1 catch-all fallback', request, specifier);
|
999
|
+
return this.external('v1 catch-all fallback', request, request.specifier);
|
843
1000
|
}
|
844
1001
|
else {
|
845
1002
|
// native v2 packages don't automatically externalize *everything* the way
|
846
1003
|
// auto-upgraded packages do, but they still externalize known and approved
|
847
1004
|
// ember virtual packages (like @ember/component)
|
848
1005
|
if (shared_internals_1.emberVirtualPackages.has(packageName)) {
|
849
|
-
return this.external('emberVirtualPackages', request, specifier);
|
1006
|
+
return this.external('emberVirtualPackages', request, request.specifier);
|
850
1007
|
}
|
851
1008
|
}
|
852
1009
|
// this is falling through with the original specifier which was
|
@@ -873,25 +1030,23 @@ class Resolver {
|
|
873
1030
|
}
|
874
1031
|
}
|
875
1032
|
}
|
876
|
-
searchAppTree(request, engine, inEngineSpecifier) {
|
1033
|
+
async searchAppTree(request, engine, inEngineSpecifier) {
|
877
1034
|
let matched = this.getEntryFromMergeMap(inEngineSpecifier, engine.root);
|
878
1035
|
switch (matched === null || matched === void 0 ? void 0 : matched.entry.type) {
|
879
1036
|
case undefined:
|
880
1037
|
return undefined;
|
881
1038
|
case 'app-only':
|
882
|
-
return request
|
883
|
-
.alias(matched.entry['app-js'].localPath)
|
884
|
-
.rehome((0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
|
1039
|
+
return request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile);
|
885
1040
|
case 'fastboot-only':
|
886
|
-
return request
|
887
|
-
.alias(matched.entry['fastboot-js'].localPath)
|
888
|
-
.rehome((0, path_1.resolve)(matched.entry['fastboot-js'].packageRoot, 'package.json'));
|
1041
|
+
return request.alias(matched.entry['fastboot-js'].specifier).rehome(matched.entry['fastboot-js'].fromFile);
|
889
1042
|
case 'both':
|
890
|
-
let foundAppJS = this.
|
891
|
-
|
1043
|
+
let foundAppJS = await this.resolve(request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile).withMeta({
|
1044
|
+
runtimeFallback: false,
|
1045
|
+
}));
|
1046
|
+
if (foundAppJS.type !== 'found') {
|
892
1047
|
throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`);
|
893
1048
|
}
|
894
|
-
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), {});
|
1049
|
+
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), { configFile: false });
|
895
1050
|
return request.virtualize((0, virtual_content_1.fastbootSwitch)(matched.matched, (0, path_1.resolve)(engine.root, 'package.json'), names));
|
896
1051
|
}
|
897
1052
|
}
|