@embroider/core 3.4.20-unstable.3e8dbe3 → 3.4.20-unstable.4070ba7
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 +5 -5
- package/src/index.d.ts +3 -3
- package/src/index.js +3 -3
- package/src/index.js.map +1 -1
- package/src/module-request.d.ts +43 -0
- package/src/module-request.js +91 -0
- package/src/module-request.js.map +1 -0
- package/src/module-resolver-options.d.ts +0 -2
- package/src/module-resolver-options.js +0 -3
- package/src/module-resolver-options.js.map +1 -1
- package/src/module-resolver.d.ts +1 -29
- package/src/module-resolver.js +59 -166
- package/src/module-resolver.js.map +1 -1
- package/src/node-resolve.d.ts +13 -16
- package/src/node-resolve.js +38 -57
- package/src/node-resolve.js.map +1 -1
- package/src/options.d.ts +0 -3
- package/src/options.js.map +1 -1
- package/src/virtual-content.d.ts +24 -3
- package/src/virtual-content.js +10 -120
- package/src/virtual-content.js.map +1 -1
- package/src/virtual-entrypoint.d.ts +4 -0
- package/src/virtual-entrypoint.js +38 -0
- package/src/virtual-entrypoint.js.map +1 -1
- package/src/virtual-route-entrypoint.d.ts +2 -1
- package/src/virtual-route-entrypoint.js +12 -13
- package/src/virtual-route-entrypoint.js.map +1 -1
- package/src/virtual-vendor.js +2 -17
- package/src/virtual-vendor.js.map +1 -1
- package/src/to-broccoli-plugin.d.ts +0 -8
- package/src/to-broccoli-plugin.js +0 -30
- package/src/to-broccoli-plugin.js.map +0 -1
package/src/module-resolver.js
CHANGED
@@ -24,6 +24,7 @@ const fs_1 = require("fs");
|
|
24
24
|
const node_resolve_1 = require("./node-resolve");
|
25
25
|
const virtual_route_entrypoint_1 = require("./virtual-route-entrypoint");
|
26
26
|
const semver_1 = require("semver");
|
27
|
+
const virtual_entrypoint_1 = require("./virtual-entrypoint");
|
27
28
|
const debug = (0, debug_1.default)('embroider:resolver');
|
28
29
|
// Using a formatter makes this work lazy so nothing happens when we aren't
|
29
30
|
// logging. It is unfortunate that formatters are a globally mutable config and
|
@@ -36,10 +37,7 @@ debug_1.default.formatters.p = (s) => {
|
|
36
37
|
return s;
|
37
38
|
};
|
38
39
|
function logTransition(reason, before, after = before) {
|
39
|
-
if (after.
|
40
|
-
debug(`[%s:virtualized] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
41
|
-
}
|
42
|
-
else if (after.resolvedTo) {
|
40
|
+
if (after.resolvedTo) {
|
43
41
|
debug(`[%s:resolvedTo] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
44
42
|
}
|
45
43
|
else if (before.specifier !== after.specifier) {
|
@@ -53,17 +51,11 @@ function logTransition(reason, before, after = before) {
|
|
53
51
|
else if (before.fromFile !== after.fromFile) {
|
54
52
|
debug(`[%s:rehomed] %s, because %s\n from %p\n to %p`, before.debugType, before.specifier, reason, before.fromFile, after.fromFile);
|
55
53
|
}
|
56
|
-
else if (after.isNotFound) {
|
57
|
-
debug(`[%s:not-found] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
58
|
-
}
|
59
54
|
else {
|
60
55
|
debug(`[%s:unchanged] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
61
56
|
}
|
62
57
|
return after;
|
63
58
|
}
|
64
|
-
function isTerminal(request) {
|
65
|
-
return request.isVirtual || request.isNotFound || Boolean(request.resolvedTo);
|
66
|
-
}
|
67
59
|
const compatPattern = /@embroider\/virtual\/(?<type>[^\/]+)\/(?<rest>.*)/;
|
68
60
|
class Resolver {
|
69
61
|
constructor(options) {
|
@@ -77,9 +69,6 @@ class Resolver {
|
|
77
69
|
// why we need to know about it.
|
78
70
|
return logTransition('early exit', request);
|
79
71
|
}
|
80
|
-
if (request.specifier === 'require') {
|
81
|
-
return this.external('early require', request, request.specifier);
|
82
|
-
}
|
83
72
|
request = this.handleFastbootSwitch(request);
|
84
73
|
request = await this.handleGlobalsCompat(request);
|
85
74
|
request = this.handleImplicitModules(request);
|
@@ -105,36 +94,43 @@ class Resolver {
|
|
105
94
|
// rules.
|
106
95
|
async resolve(request) {
|
107
96
|
request = await this.beforeResolve(request);
|
97
|
+
let resolution;
|
108
98
|
if (request.resolvedTo) {
|
109
|
-
|
99
|
+
if (typeof request.resolvedTo === 'function') {
|
100
|
+
resolution = await request.resolvedTo();
|
101
|
+
}
|
102
|
+
else {
|
103
|
+
resolution = request.resolvedTo;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
else {
|
107
|
+
resolution = await request.defaultResolve();
|
110
108
|
}
|
111
|
-
let resolution = await request.defaultResolve();
|
112
109
|
switch (resolution.type) {
|
113
110
|
case 'found':
|
114
|
-
case 'ignored':
|
115
111
|
return resolution;
|
116
112
|
case 'not_found':
|
117
113
|
break;
|
118
114
|
default:
|
119
115
|
throw (0, assert_never_1.default)(resolution);
|
120
116
|
}
|
117
|
+
request = request.clone();
|
121
118
|
let nextRequest = await this.fallbackResolve(request);
|
122
119
|
if (nextRequest === request) {
|
123
120
|
// no additional fallback is available.
|
124
121
|
return resolution;
|
125
122
|
}
|
126
123
|
if (nextRequest.resolvedTo) {
|
127
|
-
|
124
|
+
if (typeof nextRequest.resolvedTo === 'function') {
|
125
|
+
return await nextRequest.resolvedTo();
|
126
|
+
}
|
127
|
+
else {
|
128
|
+
return nextRequest.resolvedTo;
|
129
|
+
}
|
128
130
|
}
|
129
131
|
if (nextRequest.fromFile === request.fromFile && nextRequest.specifier === request.specifier) {
|
130
132
|
throw new Error('Bug Discovered! New request is not === original request but has the same fromFile and specifier. This will likely create a loop.');
|
131
133
|
}
|
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();
|
137
|
-
}
|
138
134
|
return this.resolve(nextRequest);
|
139
135
|
}
|
140
136
|
// Use standard NodeJS resolving, with our required compatibility rules on
|
@@ -158,7 +154,7 @@ class Resolver {
|
|
158
154
|
return owningPackage;
|
159
155
|
}
|
160
156
|
generateFastbootSwitch(request) {
|
161
|
-
if (
|
157
|
+
if (request.resolvedTo) {
|
162
158
|
return request;
|
163
159
|
}
|
164
160
|
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
@@ -186,7 +182,7 @@ class Resolver {
|
|
186
182
|
return logTransition('internal lookup from fastbootSwitch', request);
|
187
183
|
}
|
188
184
|
else {
|
189
|
-
return logTransition('shadowed app fastboot', request, request.virtualize(switchFile));
|
185
|
+
return logTransition('shadowed app fastboot', request, request.virtualize({ type: 'fastboot-switch', specifier: switchFile }));
|
190
186
|
}
|
191
187
|
}
|
192
188
|
else {
|
@@ -199,7 +195,7 @@ class Resolver {
|
|
199
195
|
}
|
200
196
|
handleFastbootSwitch(request) {
|
201
197
|
var _a;
|
202
|
-
if (
|
198
|
+
if (request.resolvedTo) {
|
203
199
|
return request;
|
204
200
|
}
|
205
201
|
let match = (0, virtual_content_1.decodeFastbootSwitch)(request.fromFile);
|
@@ -246,7 +242,7 @@ class Resolver {
|
|
246
242
|
return logTransition('failed to match in fastboot switch', request);
|
247
243
|
}
|
248
244
|
handleImplicitModules(request) {
|
249
|
-
if (
|
245
|
+
if (request.resolvedTo) {
|
250
246
|
return request;
|
251
247
|
}
|
252
248
|
let im = (0, virtual_content_1.decodeImplicitModules)(request.specifier);
|
@@ -260,51 +256,26 @@ class Resolver {
|
|
260
256
|
let packageName = (0, shared_internals_1.packageName)(im.fromFile);
|
261
257
|
if (packageName) {
|
262
258
|
let dep = this.packageCache.resolve(packageName, pkg);
|
263
|
-
return logTransition(`dep's implicit modules`, request, request.virtualize((0, path_1.resolve)(dep.root, `-embroider-${im.type}.js`)));
|
259
|
+
return logTransition(`dep's implicit modules`, request, request.virtualize({ type: im.type, specifier: (0, path_1.resolve)(dep.root, `-embroider-${im.type}.js`) }));
|
264
260
|
}
|
265
261
|
else {
|
266
|
-
return logTransition(`own implicit modules`, request, request.virtualize((0, path_1.resolve)(pkg.root, `-embroider-${im.type}.js`)));
|
262
|
+
return logTransition(`own implicit modules`, request, request.virtualize({ type: im.type, specifier: (0, path_1.resolve)(pkg.root, `-embroider-${im.type}.js`) }));
|
267
263
|
}
|
268
264
|
}
|
269
265
|
handleEntrypoint(request) {
|
270
|
-
|
271
|
-
if (isTerminal(request)) {
|
272
|
-
return request;
|
273
|
-
}
|
274
|
-
//TODO move the extra forwardslash handling out into the vite plugin
|
275
|
-
const candidates = [
|
276
|
-
'@embroider/virtual/compat-modules',
|
277
|
-
'/@embroider/virtual/compat-modules',
|
278
|
-
'./@embroider/virtual/compat-modules',
|
279
|
-
];
|
280
|
-
if (!candidates.some(c => request.specifier.startsWith(c + '/') || request.specifier === c)) {
|
266
|
+
if (request.resolvedTo) {
|
281
267
|
return request;
|
282
268
|
}
|
283
|
-
|
284
|
-
if (
|
285
|
-
|
286
|
-
throw new Error('entrypoint does not match pattern' + request.specifier);
|
287
|
-
}
|
288
|
-
const { packageName } = result.groups;
|
289
|
-
const requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
290
|
-
if (!(requestingPkg === null || requestingPkg === void 0 ? void 0 : requestingPkg.isV2Ember())) {
|
291
|
-
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
|
292
|
-
}
|
293
|
-
let pkg;
|
294
|
-
if (packageName) {
|
295
|
-
pkg = this.packageCache.resolve(packageName, requestingPkg);
|
269
|
+
let virtualResponse = (0, virtual_entrypoint_1.virtualEntrypoint)(request, this.packageCache);
|
270
|
+
if (virtualResponse) {
|
271
|
+
return logTransition('entrypoint', request, request.virtualize(virtualResponse));
|
296
272
|
}
|
297
273
|
else {
|
298
|
-
|
274
|
+
return request;
|
299
275
|
}
|
300
|
-
let matched = (0, resolve_exports_1.exports)(pkg.packageJSON, '-embroider-entrypoint.js', {
|
301
|
-
browser: true,
|
302
|
-
conditions: ['default', 'imports'],
|
303
|
-
});
|
304
|
-
return logTransition('entrypoint', request, request.virtualize((0, path_1.resolve)(pkg.root, (_a = matched === null || matched === void 0 ? void 0 : matched[0]) !== null && _a !== void 0 ? _a : '-embroider-entrypoint.js')));
|
305
276
|
}
|
306
277
|
handleRouteEntrypoint(request) {
|
307
|
-
if (
|
278
|
+
if (request.resolvedTo) {
|
308
279
|
return request;
|
309
280
|
}
|
310
281
|
let routeName = (0, virtual_route_entrypoint_1.decodePublicRouteEntrypoint)(request.specifier);
|
@@ -315,11 +286,7 @@ class Resolver {
|
|
315
286
|
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
|
316
287
|
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
|
317
288
|
}
|
318
|
-
|
319
|
-
browser: true,
|
320
|
-
conditions: ['default', 'imports'],
|
321
|
-
});
|
322
|
-
return logTransition('route entrypoint', request, request.virtualize((0, virtual_route_entrypoint_1.encodeRouteEntrypoint)(pkg.root, matched === null || matched === void 0 ? void 0 : matched[0], routeName)));
|
289
|
+
return logTransition('route entrypoint', request, request.virtualize({ type: 'route-entrypoint', specifier: (0, virtual_route_entrypoint_1.encodeRouteEntrypoint)(pkg, routeName) }));
|
323
290
|
}
|
324
291
|
handleImplicitTestScripts(request) {
|
325
292
|
//TODO move the extra forwardslash handling out into the vite plugin
|
@@ -335,7 +302,7 @@ class Resolver {
|
|
335
302
|
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
336
303
|
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/virtual/test-support.js. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
337
304
|
}
|
338
|
-
return logTransition('test-support', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support.js')));
|
305
|
+
return logTransition('test-support', request, request.virtualize({ type: 'test-support-js', specifier: (0, path_1.resolve)(pkg.root, '-embroider-test-support.js') }));
|
339
306
|
}
|
340
307
|
handleTestSupportStyles(request) {
|
341
308
|
//TODO move the extra forwardslash handling out into the vite plugin
|
@@ -351,10 +318,13 @@ class Resolver {
|
|
351
318
|
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
352
319
|
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/virtual/test-support.css. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
353
320
|
}
|
354
|
-
return logTransition('test-support-styles', request, request.virtualize(
|
321
|
+
return logTransition('test-support-styles', request, request.virtualize({
|
322
|
+
type: 'test-support-css',
|
323
|
+
specifier: (0, path_1.resolve)(pkg.root, '-embroider-test-support-styles.css'),
|
324
|
+
}));
|
355
325
|
}
|
356
326
|
async handleGlobalsCompat(request) {
|
357
|
-
if (
|
327
|
+
if (request.resolvedTo) {
|
358
328
|
return request;
|
359
329
|
}
|
360
330
|
let match = compatPattern.exec(request.specifier);
|
@@ -394,7 +364,7 @@ class Resolver {
|
|
394
364
|
if (!pkg || !this.options.engines.some(e => e.root === (pkg === null || pkg === void 0 ? void 0 : pkg.root))) {
|
395
365
|
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/virtual/vendor.css. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
396
366
|
}
|
397
|
-
return logTransition('vendor-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor-styles.css')));
|
367
|
+
return logTransition('vendor-styles', request, request.virtualize({ type: 'vendor-css', specifier: (0, path_1.resolve)(pkg.root, '-embroider-vendor-styles.css') }));
|
398
368
|
}
|
399
369
|
resolveHelper(path, inEngine, request) {
|
400
370
|
let target = this.parseGlobalPath(path, inEngine);
|
@@ -407,9 +377,7 @@ class Resolver {
|
|
407
377
|
// first, the various places our template might be.
|
408
378
|
for (let candidate of this.componentTemplateCandidates(target.packageName)) {
|
409
379
|
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;
|
410
|
-
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from)
|
411
|
-
runtimeFallback: false,
|
412
|
-
}));
|
380
|
+
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from));
|
413
381
|
if (resolution.type === 'found') {
|
414
382
|
hbsModule = resolution;
|
415
383
|
break;
|
@@ -418,12 +386,7 @@ class Resolver {
|
|
418
386
|
// then the various places our javascript might be.
|
419
387
|
for (let candidate of this.componentJSCandidates(target.packageName)) {
|
420
388
|
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;
|
421
|
-
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from)
|
422
|
-
runtimeFallback: false,
|
423
|
-
}));
|
424
|
-
if (resolution.type === 'ignored') {
|
425
|
-
return logTransition(`resolving to ignored component`, request, request.resolveTo(resolution));
|
426
|
-
}
|
389
|
+
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from));
|
427
390
|
// .hbs is a resolvable extension for us, so we need to exclude it here.
|
428
391
|
// It matches as a priority lower than .js, so finding an .hbs means
|
429
392
|
// there's definitely not a .js.
|
@@ -436,7 +399,10 @@ class Resolver {
|
|
436
399
|
if (!this.emberVersionSupportsSeparateTemplates) {
|
437
400
|
throw new Error(`Components with separately resolved templates were removed at Ember 6.0. Migrate to either co-located js/ts + hbs files or to gjs/gts. https://deprecations.emberjs.com/id/component-template-resolving/. Bad template was: ${hbsModule.filename}.`);
|
438
401
|
}
|
439
|
-
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize(
|
402
|
+
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize({
|
403
|
+
type: 'component-pair',
|
404
|
+
specifier: (0, virtual_content_1.virtualPairComponent)(this.options.appRoot, hbsModule.filename, jsModule === null || jsModule === void 0 ? void 0 : jsModule.filename),
|
405
|
+
}));
|
440
406
|
}
|
441
407
|
else if (jsModule) {
|
442
408
|
return logTransition(`resolving to resolveComponent found only JS`, request, request.resolveTo(jsModule));
|
@@ -450,13 +416,8 @@ class Resolver {
|
|
450
416
|
// component, so here to resolve the ambiguity we need to actually resolve
|
451
417
|
// that candidate to see if it works.
|
452
418
|
let helperCandidate = this.resolveHelper(path, inEngine, request);
|
453
|
-
let helperMatch = await this.resolve(request.alias(helperCandidate.specifier).rehome(helperCandidate.fromFile)
|
454
|
-
|
455
|
-
}));
|
456
|
-
// for the case of 'ignored' that means that esbuild found this helper in an external
|
457
|
-
// package so it should be considered found in this case and we should not look for a
|
458
|
-
// component with this name
|
459
|
-
if (helperMatch.type === 'found' || helperMatch.type === 'ignored') {
|
419
|
+
let helperMatch = await this.resolve(request.alias(helperCandidate.specifier).rehome(helperCandidate.fromFile));
|
420
|
+
if (helperMatch.type === 'found') {
|
460
421
|
return logTransition('resolve to ambiguous case matched a helper', request, request.resolveTo(helperMatch));
|
461
422
|
}
|
462
423
|
// unlike resolveHelper, resolveComponent already does pre-resolution in
|
@@ -634,7 +595,7 @@ class Resolver {
|
|
634
595
|
});
|
635
596
|
}
|
636
597
|
handleRewrittenPackages(request) {
|
637
|
-
if (
|
598
|
+
if (request.resolvedTo) {
|
638
599
|
return request;
|
639
600
|
}
|
640
601
|
let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
@@ -687,7 +648,7 @@ class Resolver {
|
|
687
648
|
return request;
|
688
649
|
}
|
689
650
|
handleRenaming(request) {
|
690
|
-
if (
|
651
|
+
if (request.resolvedTo) {
|
691
652
|
return request;
|
692
653
|
}
|
693
654
|
let packageName = (0, shared_internals_1.packageName)(request.specifier);
|
@@ -772,7 +733,7 @@ class Resolver {
|
|
772
733
|
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
773
734
|
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/virtual/vendor.js. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
774
735
|
}
|
775
|
-
return logTransition('vendor', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor.js')));
|
736
|
+
return logTransition('vendor', request, request.virtualize({ type: 'vendor-js', specifier: (0, path_1.resolve)(pkg.root, '-embroider-vendor.js') }));
|
776
737
|
}
|
777
738
|
resolveWithinMovedPackage(request, pkg) {
|
778
739
|
let levels = ['..'];
|
@@ -789,7 +750,7 @@ class Resolver {
|
|
789
750
|
return newRequest.withMeta({ originalFromFile });
|
790
751
|
}
|
791
752
|
preHandleExternal(request) {
|
792
|
-
if (
|
753
|
+
if (request.resolvedTo) {
|
793
754
|
return request;
|
794
755
|
}
|
795
756
|
let { specifier, fromFile } = request;
|
@@ -799,11 +760,6 @@ class Resolver {
|
|
799
760
|
}
|
800
761
|
let packageName = (0, shared_internals_1.packageName)(specifier);
|
801
762
|
if (!packageName) {
|
802
|
-
// This is a relative import. We don't automatically externalize those
|
803
|
-
// because it's rare, and by keeping them static we give better errors. But
|
804
|
-
// we do allow them to be explicitly externalized by the package author (or
|
805
|
-
// a compat adapter). In the metadata, they would be listed in
|
806
|
-
// package-relative form, so we need to convert this specifier to that.
|
807
763
|
let absoluteSpecifier = (0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier);
|
808
764
|
if (!absoluteSpecifier.startsWith(pkg.root)) {
|
809
765
|
// this relative path escape its package. So it's not really using
|
@@ -812,11 +768,6 @@ class Resolver {
|
|
812
768
|
// references to runtime utilities, like we do in @embroider/macros.
|
813
769
|
return logTransition('beforeResolve: relative path escapes its package', request);
|
814
770
|
}
|
815
|
-
let packageRelativeSpecifier = (0, shared_internals_2.explicitRelative)(pkg.root, absoluteSpecifier);
|
816
|
-
if (isExplicitlyExternal(packageRelativeSpecifier, pkg)) {
|
817
|
-
let publicSpecifier = absoluteSpecifier.replace(pkg.root, pkg.name);
|
818
|
-
return this.external('beforeResolve', request, publicSpecifier);
|
819
|
-
}
|
820
771
|
// if the requesting file is in an addon's app-js, the relative request
|
821
772
|
// should really be understood as a request for a module in the containing
|
822
773
|
// engine.
|
@@ -826,14 +777,6 @@ class Resolver {
|
|
826
777
|
}
|
827
778
|
return request;
|
828
779
|
}
|
829
|
-
// absolute package imports can also be explicitly external based on their
|
830
|
-
// full specifier name
|
831
|
-
if (isExplicitlyExternal(specifier, pkg)) {
|
832
|
-
return this.external('beforeResolve', request, specifier);
|
833
|
-
}
|
834
|
-
if (shared_internals_1.emberVirtualPackages.has(packageName) && !pkg.hasDependency(packageName)) {
|
835
|
-
return this.external('beforeResolve emberVirtualPackages', request, specifier);
|
836
|
-
}
|
837
780
|
if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
|
838
781
|
// addons (whether auto-upgraded or not) may use the app's
|
839
782
|
// emberVirtualPeerDeps, like "@glimmer/component" etc.
|
@@ -853,7 +796,7 @@ class Resolver {
|
|
853
796
|
if (!dep.isEmberAddon()) {
|
854
797
|
// classic ember addons can only import non-ember dependencies if they
|
855
798
|
// have ember-auto-import.
|
856
|
-
return
|
799
|
+
return logTransition('v1 package without auto-import', request, request.notFound());
|
857
800
|
}
|
858
801
|
}
|
859
802
|
catch (err) {
|
@@ -886,42 +829,9 @@ class Resolver {
|
|
886
829
|
}
|
887
830
|
}
|
888
831
|
}
|
889
|
-
external(label, request, specifier) {
|
890
|
-
if (this.options.amdCompatibility === 'cjs') {
|
891
|
-
let filename = (0, virtual_content_1.virtualExternalCJSModule)(specifier);
|
892
|
-
return logTransition(label, request, request.virtualize(filename));
|
893
|
-
}
|
894
|
-
else if (this.options.amdCompatibility) {
|
895
|
-
let entry = this.options.amdCompatibility.es.find(entry => entry[0] === specifier || entry[0] + '/index' === specifier);
|
896
|
-
if (!entry && request.specifier === 'require') {
|
897
|
-
entry = ['require', ['default', 'has']];
|
898
|
-
}
|
899
|
-
if (!entry) {
|
900
|
-
throw new Error(`[${request.debugType}] A module tried to resolve "${request.specifier}" and didn't find it (${label}).
|
901
|
-
|
902
|
-
- Maybe a dependency declaration is missing?
|
903
|
-
- Remember that v1 addons can only import non-Ember-addon NPM dependencies if they include ember-auto-import in their dependencies.
|
904
|
-
- If this dependency is available in the AMD loader (because someone manually called "define()" for it), you can configure a shim like:
|
905
|
-
|
906
|
-
amdCompatibility: {
|
907
|
-
es: [
|
908
|
-
["${request.specifier}", ["default", "yourNamedExportsGoHere"]],
|
909
|
-
]
|
910
|
-
}
|
911
|
-
|
912
|
-
`);
|
913
|
-
}
|
914
|
-
let filename = (0, virtual_content_1.virtualExternalESModule)(specifier, entry[1]);
|
915
|
-
return logTransition(label, request, request.virtualize(filename));
|
916
|
-
}
|
917
|
-
else {
|
918
|
-
throw new Error(`Embroider's amdCompatibility option is disabled, but something tried to use it to access "${request.specifier}"`);
|
919
|
-
}
|
920
|
-
}
|
921
832
|
async fallbackResolve(request) {
|
922
|
-
|
923
|
-
|
924
|
-
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');
|
833
|
+
if (request.resolvedTo) {
|
834
|
+
throw new Error('Build tool bug detected! Fallback resolve should never see an already-resolved request.');
|
925
835
|
}
|
926
836
|
if (request.specifier === '@embroider/macros') {
|
927
837
|
// the macros package is always handled directly within babel (not
|
@@ -997,21 +907,6 @@ class Resolver {
|
|
997
907
|
return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
|
998
908
|
}
|
999
909
|
}
|
1000
|
-
if (pkg.needsLooseResolving() && ((_b = (_a = request.meta) === null || _a === void 0 ? void 0 : _a.runtimeFallback) !== null && _b !== void 0 ? _b : true)) {
|
1001
|
-
// auto-upgraded packages can fall back to attempting to find dependencies at
|
1002
|
-
// runtime. Native v2 packages can only get this behavior in the
|
1003
|
-
// isExplicitlyExternal case above because they need to explicitly ask for
|
1004
|
-
// externals.
|
1005
|
-
return this.external('v1 catch-all fallback', request, request.specifier);
|
1006
|
-
}
|
1007
|
-
else {
|
1008
|
-
// native v2 packages don't automatically externalize *everything* the way
|
1009
|
-
// auto-upgraded packages do, but they still externalize known and approved
|
1010
|
-
// ember virtual packages (like @ember/component)
|
1011
|
-
if (shared_internals_1.emberVirtualPackages.has(packageName)) {
|
1012
|
-
return this.external('emberVirtualPackages', request, request.specifier);
|
1013
|
-
}
|
1014
|
-
}
|
1015
910
|
// this is falling through with the original specifier which was
|
1016
911
|
// non-resolvable, which will presumably cause a static build error in stage3.
|
1017
912
|
return logTransition('fallbackResolve final exit', request);
|
@@ -1094,14 +989,15 @@ class Resolver {
|
|
1094
989
|
case 'fastboot-only':
|
1095
990
|
return request.alias(matched.entry['fastboot-js'].specifier).rehome(matched.entry['fastboot-js'].fromFile);
|
1096
991
|
case 'both':
|
1097
|
-
let foundAppJS = await this.resolve(request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile)
|
1098
|
-
runtimeFallback: false,
|
1099
|
-
}));
|
992
|
+
let foundAppJS = await this.resolve(request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile));
|
1100
993
|
if (foundAppJS.type !== 'found') {
|
1101
994
|
throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`);
|
1102
995
|
}
|
1103
996
|
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), { configFile: false });
|
1104
|
-
return request.virtualize(
|
997
|
+
return request.virtualize({
|
998
|
+
type: 'fastboot-switch',
|
999
|
+
specifier: (0, virtual_content_1.fastbootSwitch)(matched.matched, (0, path_1.resolve)(engine.root, 'package.json'), names),
|
1000
|
+
});
|
1105
1001
|
}
|
1106
1002
|
}
|
1107
1003
|
// check whether the given file with the given owningPackage is an addon's
|
@@ -1165,9 +1061,6 @@ __decorate([
|
|
1165
1061
|
__decorate([
|
1166
1062
|
(0, typescript_memoize_1.Memoize)()
|
1167
1063
|
], Resolver.prototype, "emberVersionSupportsSeparateTemplates", null);
|
1168
|
-
function isExplicitlyExternal(specifier, fromPkg) {
|
1169
|
-
return Boolean(fromPkg.isV2Addon() && fromPkg.meta['externals'] && fromPkg.meta['externals'].includes(specifier));
|
1170
|
-
}
|
1171
1064
|
// we don't want to allow things that resolve only by accident that are likely
|
1172
1065
|
// to break in other setups. For example: import your dependencies'
|
1173
1066
|
// dependencies, or importing your own name from within a monorepo (which will
|