@embroider/core 3.4.9 → 3.4.10-unstable.14b84ff
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +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/asset.d.ts +2 -6
- package/src/asset.js.map +1 -1
- package/src/describe-exports.js.map +1 -1
- package/src/ember-html.d.ts +3 -6
- package/src/ember-html.js +7 -18
- package/src/ember-html.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 +2 -2
- package/src/index.js.map +1 -1
- package/src/messages.js.map +1 -1
- package/src/module-resolver.d.ts +30 -15
- package/src/module-resolver.js +329 -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 +114 -42
- package/src/virtual-content.js.map +1 -1
- package/src/virtual-entrypoint.d.ts +19 -0
- package/src/virtual-entrypoint.js +316 -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-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/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,19 @@ 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.handleRouteEntrypoint(request);
|
85
90
|
request = this.handleRenaming(request);
|
91
|
+
request = this.handleVendor(request);
|
86
92
|
// we expect the specifier to be app relative at this point - must be after handleRenaming
|
87
93
|
request = this.generateFastbootSwitch(request);
|
88
94
|
request = this.preHandleExternal(request);
|
@@ -96,95 +102,45 @@ class Resolver {
|
|
96
102
|
// that calls your build system's normal module resolver, this does both pre-
|
97
103
|
// and post-resolution adjustments as needed to implement our compatibility
|
98
104
|
// 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);
|
105
|
+
async resolve(request) {
|
106
|
+
request = await this.beforeResolve(request);
|
107
|
+
if (request.resolvedTo) {
|
108
|
+
return request.resolvedTo;
|
109
|
+
}
|
110
|
+
let resolution = await request.defaultResolve();
|
127
111
|
switch (resolution.type) {
|
128
112
|
case 'found':
|
113
|
+
case 'ignored':
|
129
114
|
return resolution;
|
130
115
|
case 'not_found':
|
131
116
|
break;
|
132
117
|
default:
|
133
118
|
throw (0, assert_never_1.default)(resolution);
|
134
119
|
}
|
135
|
-
let nextRequest = this.fallbackResolve(request);
|
120
|
+
let nextRequest = await this.fallbackResolve(request);
|
136
121
|
if (nextRequest === request) {
|
137
122
|
// no additional fallback is available.
|
138
123
|
return resolution;
|
139
124
|
}
|
125
|
+
if (nextRequest.resolvedTo) {
|
126
|
+
return nextRequest.resolvedTo;
|
127
|
+
}
|
140
128
|
if (nextRequest.fromFile === request.fromFile && nextRequest.specifier === request.specifier) {
|
141
129
|
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
130
|
}
|
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
|
131
|
+
if (nextRequest.isVirtual || nextRequest.isNotFound) {
|
132
|
+
// virtual and NotFound requests are terminal, there is no more
|
133
|
+
// beforeResolve or fallbackResolve around them. The defaultResolve is
|
134
|
+
// expected to know how to implement them.
|
135
|
+
return nextRequest.defaultResolve();
|
148
136
|
}
|
149
|
-
return
|
137
|
+
return this.resolve(nextRequest);
|
150
138
|
}
|
151
139
|
// Use standard NodeJS resolving, with our required compatibility rules on
|
152
140
|
// top. This is a convenience method for calling resolveSync with the
|
153
141
|
// 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
|
-
}
|
142
|
+
async nodeResolve(specifier, fromFile) {
|
143
|
+
return (0, node_resolve_1.nodeResolve)(this, specifier, fromFile);
|
188
144
|
}
|
189
145
|
get packageCache() {
|
190
146
|
return shared_internals_2.RewrittenPackageCache.shared('embroider', this.options.appRoot);
|
@@ -201,6 +157,9 @@ class Resolver {
|
|
201
157
|
return owningPackage;
|
202
158
|
}
|
203
159
|
generateFastbootSwitch(request) {
|
160
|
+
if (isTerminal(request)) {
|
161
|
+
return request;
|
162
|
+
}
|
204
163
|
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
205
164
|
if (!pkg) {
|
206
165
|
return request;
|
@@ -218,7 +177,9 @@ class Resolver {
|
|
218
177
|
let fastbootFile = engineConfig.fastbootFiles[candidate];
|
219
178
|
if (fastbootFile) {
|
220
179
|
if (fastbootFile.shadowedFilename) {
|
221
|
-
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)((0, path_1.resolve)(pkg.root, fastbootFile.shadowedFilename), 'utf8'), {
|
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
183
|
let switchFile = (0, virtual_content_1.fastbootSwitch)(candidate, (0, path_1.resolve)(pkg.root, 'package.json'), names);
|
223
184
|
if (switchFile === request.fromFile) {
|
224
185
|
return logTransition('internal lookup from fastbootSwitch', request);
|
@@ -237,6 +198,9 @@ class Resolver {
|
|
237
198
|
}
|
238
199
|
handleFastbootSwitch(request) {
|
239
200
|
var _a;
|
201
|
+
if (isTerminal(request)) {
|
202
|
+
return request;
|
203
|
+
}
|
240
204
|
let match = (0, virtual_content_1.decodeFastbootSwitch)(request.fromFile);
|
241
205
|
if (!match) {
|
242
206
|
return request;
|
@@ -275,12 +239,15 @@ class Resolver {
|
|
275
239
|
}
|
276
240
|
let entry = (_a = this.getEntryFromMergeMap(rel, pkg.root)) === null || _a === void 0 ? void 0 : _a.entry;
|
277
241
|
if ((entry === null || entry === void 0 ? void 0 : entry.type) === 'both') {
|
278
|
-
return logTransition('matched addon entry', request, request.alias(entry[section].
|
242
|
+
return logTransition('matched addon entry', request, request.alias(entry[section].specifier).rehome(entry[section].fromFile));
|
279
243
|
}
|
280
244
|
}
|
281
245
|
return logTransition('failed to match in fastboot switch', request);
|
282
246
|
}
|
283
247
|
handleImplicitModules(request) {
|
248
|
+
if (isTerminal(request)) {
|
249
|
+
return request;
|
250
|
+
}
|
284
251
|
let im = (0, virtual_content_1.decodeImplicitModules)(request.specifier);
|
285
252
|
if (!im) {
|
286
253
|
return request;
|
@@ -298,7 +265,87 @@ class Resolver {
|
|
298
265
|
return logTransition(`own implicit modules`, request, request.virtualize((0, path_1.resolve)(pkg.root, `-embroider-${im.type}.js`)));
|
299
266
|
}
|
300
267
|
}
|
301
|
-
|
268
|
+
handleEntrypoint(request) {
|
269
|
+
if (isTerminal(request)) {
|
270
|
+
return request;
|
271
|
+
}
|
272
|
+
// TODO: also handle targeting from the outside (for engines) like:
|
273
|
+
// request.specifier === 'my-package-name/-embroider-entrypoint.js'
|
274
|
+
// just like implicit-modules does.
|
275
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
276
|
+
const candidates = ['@embroider/core/entrypoint', '/@embroider/core/entrypoint', './@embroider/core/entrypoint'];
|
277
|
+
if (!candidates.some(c => request.specifier.startsWith(c + '/') || request.specifier === c)) {
|
278
|
+
return request;
|
279
|
+
}
|
280
|
+
const result = /\.?\/?@embroider\/core\/entrypoint(?:\/(?<packageName>.*))?/.exec(request.specifier);
|
281
|
+
if (!result) {
|
282
|
+
// TODO make a better error
|
283
|
+
throw new Error('entrypoint does not match pattern' + request.specifier);
|
284
|
+
}
|
285
|
+
const { packageName } = result.groups;
|
286
|
+
const requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
287
|
+
if (!(requestingPkg === null || requestingPkg === void 0 ? void 0 : requestingPkg.isV2Ember())) {
|
288
|
+
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
|
289
|
+
}
|
290
|
+
let pkg;
|
291
|
+
if (packageName) {
|
292
|
+
pkg = this.packageCache.resolve(packageName, requestingPkg);
|
293
|
+
}
|
294
|
+
else {
|
295
|
+
pkg = requestingPkg;
|
296
|
+
}
|
297
|
+
return logTransition('entrypoint', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-entrypoint.js')));
|
298
|
+
}
|
299
|
+
handleRouteEntrypoint(request) {
|
300
|
+
if (isTerminal(request)) {
|
301
|
+
return request;
|
302
|
+
}
|
303
|
+
let routeName = (0, virtual_route_entrypoint_1.decodePublicRouteEntrypoint)(request.specifier);
|
304
|
+
if (!routeName) {
|
305
|
+
return request;
|
306
|
+
}
|
307
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
308
|
+
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
|
309
|
+
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
|
310
|
+
}
|
311
|
+
return logTransition('route entrypoint', request, request.virtualize((0, virtual_route_entrypoint_1.encodeRouteEntrypoint)(pkg.root, routeName)));
|
312
|
+
}
|
313
|
+
handleImplicitTestScripts(request) {
|
314
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
315
|
+
const candidates = [
|
316
|
+
'@embroider/core/test-support.js',
|
317
|
+
'/@embroider/core/test-support.js',
|
318
|
+
'./@embroider/core/test-support.js',
|
319
|
+
];
|
320
|
+
if (!candidates.includes(request.specifier)) {
|
321
|
+
return request;
|
322
|
+
}
|
323
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
324
|
+
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
325
|
+
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.`);
|
326
|
+
}
|
327
|
+
return logTransition('test-support', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support.js')));
|
328
|
+
}
|
329
|
+
handleTestSupportStyles(request) {
|
330
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
331
|
+
const candidates = [
|
332
|
+
'@embroider/core/test-support.css',
|
333
|
+
'/@embroider/core/test-support.css',
|
334
|
+
'./@embroider/core/test-support.css',
|
335
|
+
];
|
336
|
+
if (!candidates.includes(request.specifier)) {
|
337
|
+
return request;
|
338
|
+
}
|
339
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
340
|
+
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
341
|
+
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.`);
|
342
|
+
}
|
343
|
+
return logTransition('test-support-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support-styles.css')));
|
344
|
+
}
|
345
|
+
async handleGlobalsCompat(request) {
|
346
|
+
if (isTerminal(request)) {
|
347
|
+
return request;
|
348
|
+
}
|
302
349
|
let match = compatPattern.exec(request.specifier);
|
303
350
|
if (!match) {
|
304
351
|
return request;
|
@@ -322,56 +369,76 @@ class Resolver {
|
|
322
369
|
throw new Error(`bug: unexepected #embroider_compat specifier: ${request.specifier}`);
|
323
370
|
}
|
324
371
|
}
|
372
|
+
handleVendorStyles(request) {
|
373
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
374
|
+
const candidates = ['@embroider/core/vendor.css', '/@embroider/core/vendor.css', './@embroider/core/vendor.css'];
|
375
|
+
if (!candidates.includes(request.specifier)) {
|
376
|
+
return request;
|
377
|
+
}
|
378
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
379
|
+
if (!pkg || !this.options.engines.some(e => e.root === (pkg === null || pkg === void 0 ? void 0 : pkg.root))) {
|
380
|
+
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.`);
|
381
|
+
}
|
382
|
+
return logTransition('vendor-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor-styles.css')));
|
383
|
+
}
|
325
384
|
resolveHelper(path, inEngine, request) {
|
326
385
|
let target = this.parseGlobalPath(path, inEngine);
|
327
386
|
return logTransition('resolveHelper', request, request.alias(`${target.packageName}/helpers/${target.memberName}`).rehome((0, path_1.resolve)(inEngine.root, 'package.json')));
|
328
387
|
}
|
329
|
-
resolveComponent(path, inEngine, request) {
|
388
|
+
async resolveComponent(path, inEngine, request) {
|
330
389
|
let target = this.parseGlobalPath(path, inEngine);
|
331
390
|
let hbsModule = null;
|
332
391
|
let jsModule = null;
|
333
392
|
// first, the various places our template might be.
|
334
393
|
for (let candidate of this.componentTemplateCandidates(target.packageName)) {
|
335
|
-
let
|
336
|
-
|
337
|
-
|
394
|
+
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;
|
395
|
+
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from).withMeta({
|
396
|
+
runtimeFallback: false,
|
397
|
+
}));
|
398
|
+
if (resolution.type === 'found') {
|
399
|
+
hbsModule = resolution;
|
338
400
|
break;
|
339
401
|
}
|
340
402
|
}
|
341
403
|
// then the various places our javascript might be.
|
342
404
|
for (let candidate of this.componentJSCandidates(target.packageName)) {
|
343
|
-
let
|
405
|
+
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;
|
406
|
+
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from).withMeta({
|
407
|
+
runtimeFallback: false,
|
408
|
+
}));
|
344
409
|
// .hbs is a resolvable extension for us, so we need to exclude it here.
|
345
410
|
// It matches as a priority lower than .js, so finding an .hbs means
|
346
411
|
// there's definitely not a .js.
|
347
|
-
if (resolution.type === '
|
348
|
-
jsModule = resolution
|
412
|
+
if (resolution.type === 'found' && !resolution.filename.endsWith('.hbs')) {
|
413
|
+
jsModule = resolution;
|
349
414
|
break;
|
350
415
|
}
|
351
416
|
}
|
352
417
|
if (hbsModule) {
|
353
|
-
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule, jsModule)));
|
418
|
+
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
419
|
}
|
355
420
|
else if (jsModule) {
|
356
|
-
return logTransition(`resolveComponent found only JS`, request, request.
|
421
|
+
return logTransition(`resolving to resolveComponent found only JS`, request, request.resolveTo(jsModule));
|
357
422
|
}
|
358
423
|
else {
|
359
424
|
return logTransition(`resolveComponent failed`, request);
|
360
425
|
}
|
361
426
|
}
|
362
|
-
resolveHelperOrComponent(path, inEngine, request) {
|
427
|
+
async resolveHelperOrComponent(path, inEngine, request) {
|
363
428
|
// resolveHelper just rewrites our request to one that should target the
|
364
429
|
// component, so here to resolve the ambiguity we need to actually resolve
|
365
430
|
// that candidate to see if it works.
|
366
431
|
let helperCandidate = this.resolveHelper(path, inEngine, request);
|
367
|
-
let helperMatch = this.
|
368
|
-
|
369
|
-
|
432
|
+
let helperMatch = await this.resolve(request.alias(helperCandidate.specifier).rehome(helperCandidate.fromFile).withMeta({
|
433
|
+
runtimeFallback: false,
|
434
|
+
}));
|
435
|
+
if (helperMatch.type === 'found') {
|
436
|
+
return logTransition('resolve to ambiguous case matched a helper', request, request.resolveTo(helperMatch));
|
370
437
|
}
|
371
438
|
// unlike resolveHelper, resolveComponent already does pre-resolution in
|
372
439
|
// order to deal with its own internal ambiguity around JS vs HBS vs
|
373
440
|
// colocation.≥
|
374
|
-
let componentMatch = this.resolveComponent(path, inEngine, request);
|
441
|
+
let componentMatch = await this.resolveComponent(path, inEngine, request);
|
375
442
|
if (componentMatch !== request) {
|
376
443
|
return logTransition('ambiguous case matched a cmoponent', request, componentMatch);
|
377
444
|
}
|
@@ -396,6 +463,7 @@ class Resolver {
|
|
396
463
|
}
|
397
464
|
*componentJSCandidates(inPackageName) {
|
398
465
|
yield { prefix: '/components/', suffix: '' };
|
466
|
+
yield { prefix: '/components/', suffix: '/index' };
|
399
467
|
yield { prefix: '/components/', suffix: '/component' };
|
400
468
|
let pods = this.podPrefix(inPackageName);
|
401
469
|
if (pods) {
|
@@ -414,10 +482,10 @@ class Resolver {
|
|
414
482
|
parseGlobalPath(path, inEngine) {
|
415
483
|
let parts = path.split('@');
|
416
484
|
if (parts.length > 1 && parts[0].length > 0) {
|
417
|
-
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, '
|
485
|
+
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'package.json') };
|
418
486
|
}
|
419
487
|
else {
|
420
|
-
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, '
|
488
|
+
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'package.json') };
|
421
489
|
}
|
422
490
|
}
|
423
491
|
engineConfig(packageName) {
|
@@ -449,8 +517,8 @@ class Resolver {
|
|
449
517
|
engineModules.set(inEngineName, {
|
450
518
|
type: 'app-only',
|
451
519
|
'app-js': {
|
452
|
-
|
453
|
-
|
520
|
+
specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
|
521
|
+
fromFile: addonConfig.canResolveFromFile,
|
454
522
|
fromPackageName: addon.name,
|
455
523
|
},
|
456
524
|
});
|
@@ -463,8 +531,8 @@ class Resolver {
|
|
463
531
|
engineModules.set(inEngineName, {
|
464
532
|
type: 'both',
|
465
533
|
'app-js': {
|
466
|
-
|
467
|
-
|
534
|
+
specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
|
535
|
+
fromFile: addonConfig.canResolveFromFile,
|
468
536
|
fromPackageName: addon.name,
|
469
537
|
},
|
470
538
|
'fastboot-js': prevEntry['fastboot-js'],
|
@@ -488,8 +556,8 @@ class Resolver {
|
|
488
556
|
engineModules.set(inEngineName, {
|
489
557
|
type: 'fastboot-only',
|
490
558
|
'fastboot-js': {
|
491
|
-
|
492
|
-
|
559
|
+
specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
|
560
|
+
fromFile: addonConfig.canResolveFromFile,
|
493
561
|
fromPackageName: addon.name,
|
494
562
|
},
|
495
563
|
});
|
@@ -502,8 +570,8 @@ class Resolver {
|
|
502
570
|
engineModules.set(inEngineName, {
|
503
571
|
type: 'both',
|
504
572
|
'fastboot-js': {
|
505
|
-
|
506
|
-
|
573
|
+
specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
|
574
|
+
fromFile: addonConfig.canResolveFromFile,
|
507
575
|
fromPackageName: addon.name,
|
508
576
|
},
|
509
577
|
'app-js': prevEntry['app-js'],
|
@@ -525,7 +593,7 @@ class Resolver {
|
|
525
593
|
return owningEngine;
|
526
594
|
}
|
527
595
|
handleRewrittenPackages(request) {
|
528
|
-
if (request
|
596
|
+
if (isTerminal(request)) {
|
529
597
|
return request;
|
530
598
|
}
|
531
599
|
let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
@@ -544,10 +612,6 @@ class Resolver {
|
|
544
612
|
targetPkg = this.packageCache.resolve(packageName, requestingPkg);
|
545
613
|
}
|
546
614
|
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
615
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
552
616
|
throw err;
|
553
617
|
}
|
@@ -563,14 +627,26 @@ class Resolver {
|
|
563
627
|
return logTransition('request targets a moved package', request, this.resolveWithinMovedPackage(request, targetPkg));
|
564
628
|
}
|
565
629
|
else if (originalRequestingPkg !== requestingPkg) {
|
566
|
-
|
567
|
-
|
568
|
-
|
630
|
+
if (targetPkg) {
|
631
|
+
// in this case, the requesting package is moved but its destination is
|
632
|
+
// not, so we need to rehome the request back to the original location.
|
633
|
+
return logTransition('outbound request from moved package', request, request
|
634
|
+
// setting meta here because if this fails, we want the fallback
|
635
|
+
// logic to revert our rehome and continue from the *moved* package.
|
636
|
+
.withMeta({ originalFromFile: request.fromFile })
|
637
|
+
.rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
|
638
|
+
}
|
639
|
+
else {
|
640
|
+
// requesting package was moved and we failed to find its target. We
|
641
|
+
// can't let that accidentally succeed in the defaultResolve because we
|
642
|
+
// could escape the moved package system.
|
643
|
+
return logTransition('missing outbound request from moved package', request, request.notFound());
|
644
|
+
}
|
569
645
|
}
|
570
646
|
return request;
|
571
647
|
}
|
572
648
|
handleRenaming(request) {
|
573
|
-
if (request
|
649
|
+
if (isTerminal(request)) {
|
574
650
|
return request;
|
575
651
|
}
|
576
652
|
let packageName = (0, shared_internals_1.packageName)(request.specifier);
|
@@ -603,30 +679,65 @@ class Resolver {
|
|
603
679
|
return logTransition(`renamePackages`, request, request.alias(request.specifier.replace(packageName, this.options.renamePackages[packageName])));
|
604
680
|
}
|
605
681
|
}
|
606
|
-
if (pkg.
|
607
|
-
// we found a self-import
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
682
|
+
if (pkg.name === packageName) {
|
683
|
+
// we found a self-import
|
684
|
+
if (pkg.meta['auto-upgraded']) {
|
685
|
+
// auto-upgraded packages always get automatically adjusted. They never
|
686
|
+
// supported fancy package.json exports features so this direct mapping
|
687
|
+
// to the root is always right.
|
688
|
+
// "my-package/foo" -> "./foo"
|
689
|
+
// "my-package" -> "./" (this can't be just "." because node's require.resolve doesn't reliable support that)
|
690
|
+
let selfImportPath = request.specifier === pkg.name ? './' : request.specifier.replace(pkg.name, '.');
|
691
|
+
return logTransition(`v1 self-import`, request, request.alias(selfImportPath).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
|
692
|
+
}
|
693
|
+
else {
|
694
|
+
// v2 packages are supposed to use package.json `exports` to enable
|
695
|
+
// self-imports, but not all build tools actually follow the spec. This
|
696
|
+
// is a workaround for badly behaved packagers.
|
697
|
+
//
|
698
|
+
// Known upstream bugs this works around:
|
699
|
+
// - https://github.com/vitejs/vite/issues/9731
|
700
|
+
if (pkg.packageJSON.exports) {
|
701
|
+
let found = (0, resolve_exports_1.exports)(pkg.packageJSON, request.specifier, {
|
702
|
+
browser: true,
|
703
|
+
conditions: ['default', 'imports'],
|
704
|
+
});
|
705
|
+
if (found === null || found === void 0 ? void 0 : found[0]) {
|
706
|
+
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')));
|
707
|
+
}
|
708
|
+
}
|
709
|
+
}
|
612
710
|
}
|
613
711
|
return request;
|
614
712
|
}
|
713
|
+
handleVendor(request) {
|
714
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
715
|
+
const candidates = ['@embroider/core/vendor.js', '/@embroider/core/vendor.js', './@embroider/core/vendor.js'];
|
716
|
+
if (!candidates.includes(request.specifier)) {
|
717
|
+
return request;
|
718
|
+
}
|
719
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
720
|
+
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
721
|
+
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.`);
|
722
|
+
}
|
723
|
+
return logTransition('vendor', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor.js')));
|
724
|
+
}
|
615
725
|
resolveWithinMovedPackage(request, pkg) {
|
616
726
|
let levels = ['..'];
|
617
727
|
if (pkg.name.startsWith('@')) {
|
618
728
|
levels.push('..');
|
619
729
|
}
|
730
|
+
let originalFromFile = request.fromFile;
|
620
731
|
let newRequest = request.rehome((0, path_1.resolve)(pkg.root, ...levels, 'moved-package-target.js'));
|
621
732
|
if (newRequest === request) {
|
622
733
|
return request;
|
623
734
|
}
|
624
|
-
|
625
|
-
|
626
|
-
});
|
735
|
+
// setting meta because if this fails, we want the fallback to pick up back
|
736
|
+
// in the original requesting package.
|
737
|
+
return newRequest.withMeta({ originalFromFile });
|
627
738
|
}
|
628
739
|
preHandleExternal(request) {
|
629
|
-
if (request
|
740
|
+
if (isTerminal(request)) {
|
630
741
|
return request;
|
631
742
|
}
|
632
743
|
let { specifier, fromFile } = request;
|
@@ -659,7 +770,15 @@ class Resolver {
|
|
659
770
|
// engine
|
660
771
|
let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
|
661
772
|
if (logicalLocation) {
|
662
|
-
return logTransition('beforeResolve: relative import in app-js', request, request
|
773
|
+
return logTransition('beforeResolve: relative import in app-js', request, request
|
774
|
+
.alias('./' + path_1.posix.join((0, path_1.dirname)(logicalLocation.inAppName), request.specifier))
|
775
|
+
// it's important that we're rehoming this to the root of the engine
|
776
|
+
// (which we know really exists), and not to a subdir like
|
777
|
+
// logicalLocation.inAppName (which might not physically exist),
|
778
|
+
// because some environments (including node's require.resolve) will
|
779
|
+
// refuse to do resolution from a notional path that doesn't
|
780
|
+
// physically exist.
|
781
|
+
.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
|
663
782
|
}
|
664
783
|
return request;
|
665
784
|
}
|
@@ -674,11 +793,11 @@ class Resolver {
|
|
674
793
|
if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
|
675
794
|
// addons (whether auto-upgraded or not) may use the app's
|
676
795
|
// emberVirtualPeerDeps, like "@glimmer/component" etc.
|
677
|
-
|
678
|
-
|
796
|
+
let addon = this.locateActiveAddon(packageName);
|
797
|
+
if (!addon) {
|
798
|
+
throw new Error(`${pkg.name} is trying to import the emberVirtualPeerDep "${packageName}", but it seems to be missing`);
|
679
799
|
}
|
680
|
-
|
681
|
-
return logTransition(`emberVirtualPeerDeps in v2 addon`, request, request.rehome(newHome));
|
800
|
+
return logTransition(`emberVirtualPeerDeps`, request, request.rehome(addon.canResolveFromFile));
|
682
801
|
}
|
683
802
|
// if this file is part of an addon's app-js, it's really the logical
|
684
803
|
// package to which it belongs (normally the app) that affects some policy
|
@@ -709,6 +828,22 @@ class Resolver {
|
|
709
828
|
}
|
710
829
|
return request;
|
711
830
|
}
|
831
|
+
locateActiveAddon(packageName) {
|
832
|
+
if (packageName === this.options.modulePrefix) {
|
833
|
+
// the app itself is something that addon's can classically resolve if they know it's name.
|
834
|
+
return {
|
835
|
+
root: this.options.appRoot,
|
836
|
+
canResolveFromFile: (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json'),
|
837
|
+
};
|
838
|
+
}
|
839
|
+
for (let engine of this.options.engines) {
|
840
|
+
for (let addon of engine.activeAddons) {
|
841
|
+
if (addon.name === packageName) {
|
842
|
+
return addon;
|
843
|
+
}
|
844
|
+
}
|
845
|
+
}
|
846
|
+
}
|
712
847
|
external(label, request, specifier) {
|
713
848
|
if (this.options.amdCompatibility === 'cjs') {
|
714
849
|
let filename = (0, virtual_content_1.virtualExternalCJSModule)(specifier);
|
@@ -741,8 +876,11 @@ class Resolver {
|
|
741
876
|
throw new Error(`Embroider's amdCompatibility option is disabled, but something tried to use it to access "${request.specifier}"`);
|
742
877
|
}
|
743
878
|
}
|
744
|
-
fallbackResolve(request) {
|
879
|
+
async fallbackResolve(request) {
|
745
880
|
var _a, _b, _c;
|
881
|
+
if (request.isVirtual) {
|
882
|
+
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');
|
883
|
+
}
|
746
884
|
if (request.specifier === '@embroider/macros') {
|
747
885
|
// the macros package is always handled directly within babel (not
|
748
886
|
// necessarily as a real resolvable package), so we should not mess with it.
|
@@ -750,8 +888,7 @@ class Resolver {
|
|
750
888
|
// why we need to know about it.
|
751
889
|
return logTransition('fallback early exit', request);
|
752
890
|
}
|
753
|
-
|
754
|
-
if (compatPattern.test(specifier)) {
|
891
|
+
if (compatPattern.test(request.specifier)) {
|
755
892
|
// Some kinds of compat requests get rewritten into other things
|
756
893
|
// deterministically. For example, "#embroider_compat/helpers/whatever"
|
757
894
|
// means only "the-current-engine/helpers/whatever", and if that doesn't
|
@@ -767,39 +904,33 @@ class Resolver {
|
|
767
904
|
// here.
|
768
905
|
return request;
|
769
906
|
}
|
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);
|
907
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
777
908
|
if (!pkg) {
|
778
909
|
return logTransition('no identifiable owningPackage', request);
|
779
910
|
}
|
780
|
-
//
|
781
|
-
// to
|
782
|
-
//
|
783
|
-
// isV2Ember()
|
911
|
+
// meta.originalFromFile gets set when we want to try to rehome a request
|
912
|
+
// but then come back to the original location here in the fallback when the
|
913
|
+
// rehomed request fails
|
784
914
|
let movedPkg = this.packageCache.maybeMoved(pkg);
|
785
915
|
if (movedPkg !== pkg) {
|
786
|
-
|
916
|
+
let originalFromFile = (_a = request.meta) === null || _a === void 0 ? void 0 : _a.originalFromFile;
|
917
|
+
if (typeof originalFromFile !== 'string') {
|
787
918
|
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
788
919
|
}
|
789
|
-
|
920
|
+
request = request.rehome(originalFromFile);
|
790
921
|
pkg = movedPkg;
|
791
922
|
}
|
792
923
|
if (!pkg.isV2Ember()) {
|
793
924
|
return logTransition('fallbackResolve: not in an ember package', request);
|
794
925
|
}
|
795
|
-
let packageName = (0, shared_internals_1.packageName)(specifier);
|
926
|
+
let packageName = (0, shared_internals_1.packageName)(request.specifier);
|
796
927
|
if (!packageName) {
|
797
928
|
// this is a relative import
|
798
929
|
let withinEngine = this.engineConfig(pkg.name);
|
799
930
|
if (withinEngine) {
|
800
931
|
// it's a relative import inside an engine (which also means app), which
|
801
932
|
// 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)));
|
933
|
+
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
934
|
if (appJSMatch) {
|
804
935
|
return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
|
805
936
|
}
|
@@ -813,40 +944,49 @@ class Resolver {
|
|
813
944
|
}
|
814
945
|
}
|
815
946
|
// auto-upgraded packages can fall back to the set of known active addons
|
816
|
-
if (pkg.meta['auto-upgraded']
|
817
|
-
|
818
|
-
if (
|
819
|
-
|
947
|
+
if (pkg.meta['auto-upgraded']) {
|
948
|
+
let addon = this.locateActiveAddon(packageName);
|
949
|
+
if (addon) {
|
950
|
+
const rehomed = request.rehome(addon.canResolveFromFile);
|
951
|
+
if (rehomed !== request) {
|
952
|
+
return logTransition(`activeAddons`, request, rehomed);
|
953
|
+
}
|
820
954
|
}
|
821
955
|
}
|
822
|
-
let logicalLocation = this.reverseSearchAppTree(pkg, fromFile);
|
956
|
+
let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
|
823
957
|
if (logicalLocation) {
|
824
958
|
// the requesting file is in an addon's appTree. We didn't succeed in
|
825
959
|
// resolving this (non-relative) request from inside the actual addon, so
|
826
960
|
// next try to resolve it from the corresponding logical location in the
|
827
961
|
// app.
|
828
|
-
return logTransition('fallbackResolve: retry from logical home of app-js file', request,
|
962
|
+
return logTransition('fallbackResolve: retry from logical home of app-js file', request,
|
963
|
+
// it might look more precise to rehome into logicalLocation.inAppName
|
964
|
+
// rather than package.json. But that logical location may not actually
|
965
|
+
// exist, and some systems (including node's require.resolve) will be
|
966
|
+
// mad about trying to resolve from notional paths that don't really
|
967
|
+
// exist.
|
968
|
+
request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
|
829
969
|
}
|
830
970
|
let targetingEngine = this.engineConfig(packageName);
|
831
971
|
if (targetingEngine) {
|
832
|
-
let appJSMatch = this.searchAppTree(request, targetingEngine, specifier.replace(packageName, '.'));
|
972
|
+
let appJSMatch = await this.searchAppTree(request, targetingEngine, request.specifier.replace(packageName, '.'));
|
833
973
|
if (appJSMatch) {
|
834
974
|
return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
|
835
975
|
}
|
836
976
|
}
|
837
|
-
if (pkg.meta['auto-upgraded']) {
|
977
|
+
if (pkg.meta['auto-upgraded'] && ((_c = (_b = request.meta) === null || _b === void 0 ? void 0 : _b.runtimeFallback) !== null && _c !== void 0 ? _c : true)) {
|
838
978
|
// auto-upgraded packages can fall back to attempting to find dependencies at
|
839
979
|
// runtime. Native v2 packages can only get this behavior in the
|
840
980
|
// isExplicitlyExternal case above because they need to explicitly ask for
|
841
981
|
// externals.
|
842
|
-
return this.external('v1 catch-all fallback', request, specifier);
|
982
|
+
return this.external('v1 catch-all fallback', request, request.specifier);
|
843
983
|
}
|
844
984
|
else {
|
845
985
|
// native v2 packages don't automatically externalize *everything* the way
|
846
986
|
// auto-upgraded packages do, but they still externalize known and approved
|
847
987
|
// ember virtual packages (like @ember/component)
|
848
988
|
if (shared_internals_1.emberVirtualPackages.has(packageName)) {
|
849
|
-
return this.external('emberVirtualPackages', request, specifier);
|
989
|
+
return this.external('emberVirtualPackages', request, request.specifier);
|
850
990
|
}
|
851
991
|
}
|
852
992
|
// this is falling through with the original specifier which was
|
@@ -873,25 +1013,23 @@ class Resolver {
|
|
873
1013
|
}
|
874
1014
|
}
|
875
1015
|
}
|
876
|
-
searchAppTree(request, engine, inEngineSpecifier) {
|
1016
|
+
async searchAppTree(request, engine, inEngineSpecifier) {
|
877
1017
|
let matched = this.getEntryFromMergeMap(inEngineSpecifier, engine.root);
|
878
1018
|
switch (matched === null || matched === void 0 ? void 0 : matched.entry.type) {
|
879
1019
|
case undefined:
|
880
1020
|
return undefined;
|
881
1021
|
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'));
|
1022
|
+
return request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile);
|
885
1023
|
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'));
|
1024
|
+
return request.alias(matched.entry['fastboot-js'].specifier).rehome(matched.entry['fastboot-js'].fromFile);
|
889
1025
|
case 'both':
|
890
|
-
let foundAppJS = this.
|
891
|
-
|
1026
|
+
let foundAppJS = await this.resolve(request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile).withMeta({
|
1027
|
+
runtimeFallback: false,
|
1028
|
+
}));
|
1029
|
+
if (foundAppJS.type !== 'found') {
|
892
1030
|
throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`);
|
893
1031
|
}
|
894
|
-
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), {});
|
1032
|
+
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), { configFile: false });
|
895
1033
|
return request.virtualize((0, virtual_content_1.fastbootSwitch)(matched.matched, (0, path_1.resolve)(engine.root, 'package.json'), names));
|
896
1034
|
}
|
897
1035
|
}
|