@embroider/core 3.4.15-unstable.e9544fc → 3.4.15
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 -8
- package/src/app-files.d.ts +4 -3
- package/src/app-files.js +5 -24
- package/src/app-files.js.map +1 -1
- package/src/asset.d.ts +32 -0
- package/src/asset.js +3 -0
- package/src/asset.js.map +1 -0
- package/src/ember-html.d.ts +43 -0
- package/src/ember-html.js +110 -0
- package/src/ember-html.js.map +1 -0
- package/src/index.d.ts +2 -1
- package/src/index.js.map +1 -1
- package/src/module-resolver.d.ts +15 -31
- package/src/module-resolver.js +203 -369
- package/src/module-resolver.js.map +1 -1
- package/src/virtual-content.d.ts +2 -6
- package/src/virtual-content.js +42 -119
- package/src/virtual-content.js.map +1 -1
- package/src/node-resolve.d.ts +0 -33
- package/src/node-resolve.js +0 -131
- package/src/node-resolve.js.map +0 -1
- package/src/virtual-entrypoint.d.ts +0 -19
- package/src/virtual-entrypoint.js +0 -289
- package/src/virtual-entrypoint.js.map +0 -1
- package/src/virtual-route-entrypoint.d.ts +0 -15
- package/src/virtual-route-entrypoint.js +0 -101
- package/src/virtual-route-entrypoint.js.map +0 -1
- package/src/virtual-test-entrypoint.d.ts +0 -10
- package/src/virtual-test-entrypoint.js +0 -66
- package/src/virtual-test-entrypoint.js.map +0 -1
- package/src/virtual-test-support-styles.d.ts +0 -4
- package/src/virtual-test-support-styles.js +0 -64
- package/src/virtual-test-support-styles.js.map +0 -1
- package/src/virtual-test-support.d.ts +0 -4
- package/src/virtual-test-support.js +0 -68
- package/src/virtual-test-support.js.map +0 -1
- package/src/virtual-vendor-styles.d.ts +0 -4
- package/src/virtual-vendor-styles.js +0 -82
- package/src/virtual-vendor-styles.js.map +0 -1
- package/src/virtual-vendor.d.ts +0 -4
- package/src/virtual-vendor.js +0 -72
- package/src/virtual-vendor.js.map +0 -1
package/src/module-resolver.js
CHANGED
@@ -15,60 +15,63 @@ const path_1 = require("path");
|
|
15
15
|
const shared_internals_2 = require("@embroider/shared-internals");
|
16
16
|
const debug_1 = __importDefault(require("debug"));
|
17
17
|
const assert_never_1 = __importDefault(require("assert-never"));
|
18
|
-
const
|
19
|
-
const resolve_exports_1 = require("resolve.exports");
|
18
|
+
const resolve_1 = __importDefault(require("resolve"));
|
20
19
|
const virtual_content_1 = require("./virtual-content");
|
21
20
|
const typescript_memoize_1 = require("typescript-memoize");
|
22
21
|
const describe_exports_1 = require("./describe-exports");
|
23
22
|
const fs_1 = require("fs");
|
24
|
-
const node_resolve_1 = require("./node-resolve");
|
25
|
-
const virtual_route_entrypoint_1 = require("./virtual-route-entrypoint");
|
26
23
|
const debug = (0, debug_1.default)('embroider:resolver');
|
27
|
-
// Using a formatter makes this work lazy so nothing happens when we aren't
|
28
|
-
// logging. It is unfortunate that formatters are a globally mutable config and
|
29
|
-
// you can only use single character names, but oh well.
|
30
|
-
debug_1.default.formatters.p = (s) => {
|
31
|
-
let cwd = process.cwd();
|
32
|
-
if (s.startsWith(cwd)) {
|
33
|
-
return s.slice(cwd.length + 1);
|
34
|
-
}
|
35
|
-
return s;
|
36
|
-
};
|
37
24
|
function logTransition(reason, before, after = before) {
|
38
25
|
if (after.isVirtual) {
|
39
|
-
debug(`
|
40
|
-
}
|
41
|
-
else if (after.resolvedTo) {
|
42
|
-
debug(`[%s:resolvedTo] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
26
|
+
debug(`virtualized %s in %s because %s`, before.specifier, before.fromFile, reason);
|
43
27
|
}
|
44
28
|
else if (before.specifier !== after.specifier) {
|
45
29
|
if (before.fromFile !== after.fromFile) {
|
46
|
-
debug(`
|
30
|
+
debug(`aliased and rehomed: %s to %s, from %s to %s because %s`, before.specifier, after.specifier, before.fromFile, after.fromFile, reason);
|
47
31
|
}
|
48
32
|
else {
|
49
|
-
debug(`
|
33
|
+
debug(`aliased: %s to %s in %s because`, before.specifier, after.specifier, before.fromFile, reason);
|
50
34
|
}
|
51
35
|
}
|
52
36
|
else if (before.fromFile !== after.fromFile) {
|
53
|
-
debug(`
|
54
|
-
}
|
55
|
-
else if (after.isNotFound) {
|
56
|
-
debug(`[%s:not-found] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
37
|
+
debug(`rehomed: %s from %s to %s because`, before.specifier, before.fromFile, after.fromFile, reason);
|
57
38
|
}
|
58
39
|
else {
|
59
|
-
debug(`
|
40
|
+
debug(`unchanged: %s in %s because %s`, before.specifier, before.fromFile, reason);
|
60
41
|
}
|
61
42
|
return after;
|
62
43
|
}
|
63
|
-
|
64
|
-
|
44
|
+
const compatPattern = /#embroider_compat\/(?<type>[^\/]+)\/(?<rest>.*)/;
|
45
|
+
class NodeModuleRequest {
|
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
|
+
}
|
65
69
|
}
|
66
|
-
const compatPattern = /@embroider\/virtual\/(?<type>[^\/]+)\/(?<rest>.*)/;
|
67
70
|
class Resolver {
|
68
71
|
constructor(options) {
|
69
72
|
this.options = options;
|
70
73
|
}
|
71
|
-
|
74
|
+
beforeResolve(request) {
|
72
75
|
if (request.specifier === '@embroider/macros') {
|
73
76
|
// the macros package is always handled directly within babel (not
|
74
77
|
// necessarily as a real resolvable package), so we should not mess with it.
|
@@ -76,20 +79,10 @@ class Resolver {
|
|
76
79
|
// why we need to know about it.
|
77
80
|
return logTransition('early exit', request);
|
78
81
|
}
|
79
|
-
if (request.specifier === 'require') {
|
80
|
-
return this.external('early require', request, request.specifier);
|
81
|
-
}
|
82
82
|
request = this.handleFastbootSwitch(request);
|
83
|
-
request =
|
83
|
+
request = 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);
|
91
85
|
request = this.handleRenaming(request);
|
92
|
-
request = this.handleVendor(request);
|
93
86
|
// we expect the specifier to be app relative at this point - must be after handleRenaming
|
94
87
|
request = this.generateFastbootSwitch(request);
|
95
88
|
request = this.preHandleExternal(request);
|
@@ -103,45 +96,95 @@ class Resolver {
|
|
103
96
|
// that calls your build system's normal module resolver, this does both pre-
|
104
97
|
// and post-resolution adjustments as needed to implement our compatibility
|
105
98
|
// rules.
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
let
|
99
|
+
//
|
100
|
+
// Depending on the plugin architecture you're working in, it may be easier to
|
101
|
+
// call beforeResolve and fallbackResolve directly, in which case matching the
|
102
|
+
// details of the recursion to what this method does are your responsibility.
|
103
|
+
async resolve(request, defaultResolve) {
|
104
|
+
let gen = this.internalResolve(request, defaultResolve);
|
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);
|
112
127
|
switch (resolution.type) {
|
113
128
|
case 'found':
|
114
|
-
case 'ignored':
|
115
129
|
return resolution;
|
116
130
|
case 'not_found':
|
117
131
|
break;
|
118
132
|
default:
|
119
133
|
throw (0, assert_never_1.default)(resolution);
|
120
134
|
}
|
121
|
-
let nextRequest =
|
135
|
+
let nextRequest = this.fallbackResolve(request);
|
122
136
|
if (nextRequest === request) {
|
123
137
|
// no additional fallback is available.
|
124
138
|
return resolution;
|
125
139
|
}
|
126
|
-
if (nextRequest.resolvedTo) {
|
127
|
-
return nextRequest.resolvedTo;
|
128
|
-
}
|
129
140
|
if (nextRequest.fromFile === request.fromFile && nextRequest.specifier === request.specifier) {
|
130
141
|
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
142
|
}
|
132
|
-
if (nextRequest.isVirtual
|
133
|
-
// virtual
|
134
|
-
//
|
135
|
-
//
|
136
|
-
return
|
143
|
+
if (nextRequest.isVirtual) {
|
144
|
+
// virtual requests are terminal, there is no more beforeResolve or
|
145
|
+
// fallbackResolve around them. The defaultResolve is expected to know how
|
146
|
+
// to implement them.
|
147
|
+
return yield defaultResolve(nextRequest);
|
137
148
|
}
|
138
|
-
return this.
|
149
|
+
return yield* this.internalResolve(nextRequest, defaultResolve);
|
139
150
|
}
|
140
151
|
// Use standard NodeJS resolving, with our required compatibility rules on
|
141
152
|
// top. This is a convenience method for calling resolveSync with the
|
142
153
|
// defaultResolve already configured to be "do the normal node thing".
|
143
|
-
|
144
|
-
|
154
|
+
nodeResolve(specifier, fromFile) {
|
155
|
+
let resolution = this.resolveSync(new NodeModuleRequest(specifier, fromFile, false, undefined), request => {
|
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
|
+
}
|
145
188
|
}
|
146
189
|
get packageCache() {
|
147
190
|
return shared_internals_2.RewrittenPackageCache.shared('embroider', this.options.appRoot);
|
@@ -158,9 +201,6 @@ class Resolver {
|
|
158
201
|
return owningPackage;
|
159
202
|
}
|
160
203
|
generateFastbootSwitch(request) {
|
161
|
-
if (isTerminal(request)) {
|
162
|
-
return request;
|
163
|
-
}
|
164
204
|
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
165
205
|
if (!pkg) {
|
166
206
|
return request;
|
@@ -178,9 +218,7 @@ class Resolver {
|
|
178
218
|
let fastbootFile = engineConfig.fastbootFiles[candidate];
|
179
219
|
if (fastbootFile) {
|
180
220
|
if (fastbootFile.shadowedFilename) {
|
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
|
-
});
|
221
|
+
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)((0, path_1.resolve)(pkg.root, fastbootFile.shadowedFilename), 'utf8'), {});
|
184
222
|
let switchFile = (0, virtual_content_1.fastbootSwitch)(candidate, (0, path_1.resolve)(pkg.root, 'package.json'), names);
|
185
223
|
if (switchFile === request.fromFile) {
|
186
224
|
return logTransition('internal lookup from fastbootSwitch', request);
|
@@ -199,9 +237,6 @@ class Resolver {
|
|
199
237
|
}
|
200
238
|
handleFastbootSwitch(request) {
|
201
239
|
var _a;
|
202
|
-
if (isTerminal(request)) {
|
203
|
-
return request;
|
204
|
-
}
|
205
240
|
let match = (0, virtual_content_1.decodeFastbootSwitch)(request.fromFile);
|
206
241
|
if (!match) {
|
207
242
|
return request;
|
@@ -240,15 +275,12 @@ class Resolver {
|
|
240
275
|
}
|
241
276
|
let entry = (_a = this.getEntryFromMergeMap(rel, pkg.root)) === null || _a === void 0 ? void 0 : _a.entry;
|
242
277
|
if ((entry === null || entry === void 0 ? void 0 : entry.type) === 'both') {
|
243
|
-
return logTransition('matched addon entry', request, request.alias(entry[section].
|
278
|
+
return logTransition('matched addon entry', request, request.alias(entry[section].localPath).rehome((0, path_1.resolve)(entry[section].packageRoot, 'package.json')));
|
244
279
|
}
|
245
280
|
}
|
246
281
|
return logTransition('failed to match in fastboot switch', request);
|
247
282
|
}
|
248
283
|
handleImplicitModules(request) {
|
249
|
-
if (isTerminal(request)) {
|
250
|
-
return request;
|
251
|
-
}
|
252
284
|
let im = (0, virtual_content_1.decodeImplicitModules)(request.specifier);
|
253
285
|
if (!im) {
|
254
286
|
return request;
|
@@ -266,103 +298,7 @@ class Resolver {
|
|
266
298
|
return logTransition(`own implicit modules`, request, request.virtualize((0, path_1.resolve)(pkg.root, `-embroider-${im.type}.js`)));
|
267
299
|
}
|
268
300
|
}
|
269
|
-
|
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
|
-
}
|
301
|
+
handleGlobalsCompat(request) {
|
366
302
|
let match = compatPattern.exec(request.specifier);
|
367
303
|
if (!match) {
|
368
304
|
return request;
|
@@ -383,85 +319,59 @@ class Resolver {
|
|
383
319
|
case 'ambiguous':
|
384
320
|
return this.resolveHelperOrComponent(rest, engine, request);
|
385
321
|
default:
|
386
|
-
throw new Error(`bug: unexepected
|
322
|
+
throw new Error(`bug: unexepected #embroider_compat specifier: ${request.specifier}`);
|
387
323
|
}
|
388
324
|
}
|
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
|
-
}
|
401
325
|
resolveHelper(path, inEngine, request) {
|
402
326
|
let target = this.parseGlobalPath(path, inEngine);
|
403
327
|
return logTransition('resolveHelper', request, request.alias(`${target.packageName}/helpers/${target.memberName}`).rehome((0, path_1.resolve)(inEngine.root, 'package.json')));
|
404
328
|
}
|
405
|
-
|
329
|
+
resolveComponent(path, inEngine, request) {
|
406
330
|
let target = this.parseGlobalPath(path, inEngine);
|
407
331
|
let hbsModule = null;
|
408
332
|
let jsModule = null;
|
409
333
|
// first, the various places our template might be.
|
410
334
|
for (let candidate of this.componentTemplateCandidates(target.packageName)) {
|
411
|
-
let
|
412
|
-
|
413
|
-
|
414
|
-
}));
|
415
|
-
if (resolution.type === 'found') {
|
416
|
-
hbsModule = resolution;
|
335
|
+
let resolution = this.nodeResolve(`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`, target.from);
|
336
|
+
if (resolution.type === 'real') {
|
337
|
+
hbsModule = resolution.filename;
|
417
338
|
break;
|
418
339
|
}
|
419
340
|
}
|
420
341
|
// then the various places our javascript might be.
|
421
342
|
for (let candidate of this.componentJSCandidates(target.packageName)) {
|
422
|
-
let
|
423
|
-
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from).withMeta({
|
424
|
-
runtimeFallback: false,
|
425
|
-
}));
|
426
|
-
if (resolution.type === 'ignored') {
|
427
|
-
return logTransition(`resolving to ignored component`, request, request.resolveTo(resolution));
|
428
|
-
}
|
343
|
+
let resolution = this.nodeResolve(`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`, target.from);
|
429
344
|
// .hbs is a resolvable extension for us, so we need to exclude it here.
|
430
345
|
// It matches as a priority lower than .js, so finding an .hbs means
|
431
346
|
// there's definitely not a .js.
|
432
|
-
if (resolution.type === '
|
433
|
-
jsModule = resolution;
|
347
|
+
if (resolution.type === 'real' && !resolution.filename.endsWith('.hbs')) {
|
348
|
+
jsModule = resolution.filename;
|
434
349
|
break;
|
435
350
|
}
|
436
351
|
}
|
437
352
|
if (hbsModule) {
|
438
|
-
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule
|
353
|
+
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule, jsModule)));
|
439
354
|
}
|
440
355
|
else if (jsModule) {
|
441
|
-
return logTransition(`
|
356
|
+
return logTransition(`resolveComponent found only JS`, request, request.alias(jsModule).rehome(target.from));
|
442
357
|
}
|
443
358
|
else {
|
444
359
|
return logTransition(`resolveComponent failed`, request);
|
445
360
|
}
|
446
361
|
}
|
447
|
-
|
362
|
+
resolveHelperOrComponent(path, inEngine, request) {
|
448
363
|
// resolveHelper just rewrites our request to one that should target the
|
449
364
|
// component, so here to resolve the ambiguity we need to actually resolve
|
450
365
|
// that candidate to see if it works.
|
451
366
|
let helperCandidate = this.resolveHelper(path, inEngine, request);
|
452
|
-
let helperMatch =
|
453
|
-
|
454
|
-
|
455
|
-
// for the case of 'ignored' that means that esbuild found this helper in an external
|
456
|
-
// package so it should be considered found in this case and we should not look for a
|
457
|
-
// component with this name
|
458
|
-
if (helperMatch.type === 'found' || helperMatch.type === 'ignored') {
|
459
|
-
return logTransition('resolve to ambiguous case matched a helper', request, request.resolveTo(helperMatch));
|
367
|
+
let helperMatch = this.nodeResolve(helperCandidate.specifier, helperCandidate.fromFile);
|
368
|
+
if (helperMatch.type === 'real') {
|
369
|
+
return logTransition('ambiguous case matched a helper', request, helperCandidate);
|
460
370
|
}
|
461
371
|
// unlike resolveHelper, resolveComponent already does pre-resolution in
|
462
372
|
// order to deal with its own internal ambiguity around JS vs HBS vs
|
463
373
|
// colocation.≥
|
464
|
-
let componentMatch =
|
374
|
+
let componentMatch = this.resolveComponent(path, inEngine, request);
|
465
375
|
if (componentMatch !== request) {
|
466
376
|
return logTransition('ambiguous case matched a cmoponent', request, componentMatch);
|
467
377
|
}
|
@@ -486,7 +396,6 @@ class Resolver {
|
|
486
396
|
}
|
487
397
|
*componentJSCandidates(inPackageName) {
|
488
398
|
yield { prefix: '/components/', suffix: '' };
|
489
|
-
yield { prefix: '/components/', suffix: '/index' };
|
490
399
|
yield { prefix: '/components/', suffix: '/component' };
|
491
400
|
let pods = this.podPrefix(inPackageName);
|
492
401
|
if (pods) {
|
@@ -505,10 +414,10 @@ class Resolver {
|
|
505
414
|
parseGlobalPath(path, inEngine) {
|
506
415
|
let parts = path.split('@');
|
507
416
|
if (parts.length > 1 && parts[0].length > 0) {
|
508
|
-
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, '
|
417
|
+
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') };
|
509
418
|
}
|
510
419
|
else {
|
511
|
-
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, '
|
420
|
+
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') };
|
512
421
|
}
|
513
422
|
}
|
514
423
|
engineConfig(packageName) {
|
@@ -540,8 +449,8 @@ class Resolver {
|
|
540
449
|
engineModules.set(inEngineName, {
|
541
450
|
type: 'app-only',
|
542
451
|
'app-js': {
|
543
|
-
|
544
|
-
|
452
|
+
localPath: inAddonName,
|
453
|
+
packageRoot: addon.root,
|
545
454
|
fromPackageName: addon.name,
|
546
455
|
},
|
547
456
|
});
|
@@ -554,8 +463,8 @@ class Resolver {
|
|
554
463
|
engineModules.set(inEngineName, {
|
555
464
|
type: 'both',
|
556
465
|
'app-js': {
|
557
|
-
|
558
|
-
|
466
|
+
localPath: inAddonName,
|
467
|
+
packageRoot: addon.root,
|
559
468
|
fromPackageName: addon.name,
|
560
469
|
},
|
561
470
|
'fastboot-js': prevEntry['fastboot-js'],
|
@@ -579,8 +488,8 @@ class Resolver {
|
|
579
488
|
engineModules.set(inEngineName, {
|
580
489
|
type: 'fastboot-only',
|
581
490
|
'fastboot-js': {
|
582
|
-
|
583
|
-
|
491
|
+
localPath: inAddonName,
|
492
|
+
packageRoot: addon.root,
|
584
493
|
fromPackageName: addon.name,
|
585
494
|
},
|
586
495
|
});
|
@@ -593,8 +502,8 @@ class Resolver {
|
|
593
502
|
engineModules.set(inEngineName, {
|
594
503
|
type: 'both',
|
595
504
|
'fastboot-js': {
|
596
|
-
|
597
|
-
|
505
|
+
localPath: inAddonName,
|
506
|
+
packageRoot: addon.root,
|
598
507
|
fromPackageName: addon.name,
|
599
508
|
},
|
600
509
|
'app-js': prevEntry['app-js'],
|
@@ -616,7 +525,7 @@ class Resolver {
|
|
616
525
|
return owningEngine;
|
617
526
|
}
|
618
527
|
handleRewrittenPackages(request) {
|
619
|
-
if (
|
528
|
+
if (request.isVirtual) {
|
620
529
|
return request;
|
621
530
|
}
|
622
531
|
let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
@@ -635,6 +544,10 @@ class Resolver {
|
|
635
544
|
targetPkg = this.packageCache.resolve(packageName, requestingPkg);
|
636
545
|
}
|
637
546
|
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)
|
638
551
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
639
552
|
throw err;
|
640
553
|
}
|
@@ -650,26 +563,14 @@ class Resolver {
|
|
650
563
|
return logTransition('request targets a moved package', request, this.resolveWithinMovedPackage(request, targetPkg));
|
651
564
|
}
|
652
565
|
else if (originalRequestingPkg !== requestingPkg) {
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
return logTransition('outbound request from moved package', request, request
|
657
|
-
// setting meta here because if this fails, we want the fallback
|
658
|
-
// logic to revert our rehome and continue from the *moved* package.
|
659
|
-
.withMeta({ originalFromFile: request.fromFile })
|
660
|
-
.rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
|
661
|
-
}
|
662
|
-
else {
|
663
|
-
// requesting package was moved and we failed to find its target. We
|
664
|
-
// can't let that accidentally succeed in the defaultResolve because we
|
665
|
-
// could escape the moved package system.
|
666
|
-
return logTransition('missing outbound request from moved package', request, request.notFound());
|
667
|
-
}
|
566
|
+
// in this case, the requesting package is moved but its destination is
|
567
|
+
// not, so we need to rehome the request back to the original location.
|
568
|
+
return logTransition('outbound request from moved package', request, request.withMeta({ wasMovedTo: request.fromFile }).rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
|
668
569
|
}
|
669
570
|
return request;
|
670
571
|
}
|
671
572
|
handleRenaming(request) {
|
672
|
-
if (
|
573
|
+
if (request.isVirtual) {
|
673
574
|
return request;
|
674
575
|
}
|
675
576
|
let packageName = (0, shared_internals_1.packageName)(request.specifier);
|
@@ -702,72 +603,30 @@ class Resolver {
|
|
702
603
|
return logTransition(`renamePackages`, request, request.alias(request.specifier.replace(packageName, this.options.renamePackages[packageName])));
|
703
604
|
}
|
704
605
|
}
|
705
|
-
if (pkg.name === packageName) {
|
706
|
-
// we found a self-import
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
// "my-app/foo" -> "./foo" from app's package.json
|
712
|
-
// "my-addon/foo" -> "my-addon/foo" from a package that's guaranteed to be able to resolve my-addon
|
713
|
-
let owningEngine = this.owningEngine(pkg);
|
714
|
-
let addonConfig = owningEngine.activeAddons.find(a => a.root === pkg.root);
|
715
|
-
if (addonConfig) {
|
716
|
-
return logTransition(`v1 addon self-import`, request, request.rehome(addonConfig.canResolveFromFile));
|
717
|
-
}
|
718
|
-
else {
|
719
|
-
let selfImportPath = request.specifier === pkg.name ? './' : request.specifier.replace(pkg.name, '.');
|
720
|
-
return logTransition(`v1 app self-import`, request, request.alias(selfImportPath).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
|
721
|
-
}
|
722
|
-
}
|
723
|
-
else {
|
724
|
-
// v2 packages are supposed to use package.json `exports` to enable
|
725
|
-
// self-imports, but not all build tools actually follow the spec. This
|
726
|
-
// is a workaround for badly behaved packagers.
|
727
|
-
//
|
728
|
-
// Known upstream bugs this works around:
|
729
|
-
// - https://github.com/vitejs/vite/issues/9731
|
730
|
-
if (pkg.packageJSON.exports) {
|
731
|
-
let found = (0, resolve_exports_1.exports)(pkg.packageJSON, request.specifier, {
|
732
|
-
browser: true,
|
733
|
-
conditions: ['default', 'imports'],
|
734
|
-
});
|
735
|
-
if (found === null || found === void 0 ? void 0 : found[0]) {
|
736
|
-
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')));
|
737
|
-
}
|
738
|
-
}
|
739
|
-
}
|
606
|
+
if (pkg.meta['auto-upgraded'] && pkg.name === packageName) {
|
607
|
+
// we found a self-import, resolve it for them. Only auto-upgraded
|
608
|
+
// packages get this help, v2 packages are natively supposed to make their
|
609
|
+
// own modules resolvable, and we want to push them all to do that
|
610
|
+
// correctly.
|
611
|
+
return logTransition(`v1 self-import`, request, request.alias(request.specifier.replace(pkg.name, '.')).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
|
740
612
|
}
|
741
613
|
return request;
|
742
614
|
}
|
743
|
-
handleVendor(request) {
|
744
|
-
//TODO move the extra forwardslash handling out into the vite plugin
|
745
|
-
const candidates = ['@embroider/core/vendor.js', '/@embroider/core/vendor.js', './@embroider/core/vendor.js'];
|
746
|
-
if (!candidates.includes(request.specifier)) {
|
747
|
-
return request;
|
748
|
-
}
|
749
|
-
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
750
|
-
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
751
|
-
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.`);
|
752
|
-
}
|
753
|
-
return logTransition('vendor', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor.js')));
|
754
|
-
}
|
755
615
|
resolveWithinMovedPackage(request, pkg) {
|
756
616
|
let levels = ['..'];
|
757
617
|
if (pkg.name.startsWith('@')) {
|
758
618
|
levels.push('..');
|
759
619
|
}
|
760
|
-
let originalFromFile = request.fromFile;
|
761
620
|
let newRequest = request.rehome((0, path_1.resolve)(pkg.root, ...levels, 'moved-package-target.js'));
|
762
621
|
if (newRequest === request) {
|
763
622
|
return request;
|
764
623
|
}
|
765
|
-
|
766
|
-
|
767
|
-
|
624
|
+
return newRequest.withMeta({
|
625
|
+
resolvedWithinPackage: pkg.root,
|
626
|
+
});
|
768
627
|
}
|
769
628
|
preHandleExternal(request) {
|
770
|
-
if (
|
629
|
+
if (request.isVirtual) {
|
771
630
|
return request;
|
772
631
|
}
|
773
632
|
let { specifier, fromFile } = request;
|
@@ -800,15 +659,7 @@ class Resolver {
|
|
800
659
|
// engine
|
801
660
|
let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
|
802
661
|
if (logicalLocation) {
|
803
|
-
return logTransition('beforeResolve: relative import in app-js', request, request
|
804
|
-
.alias('./' + path_1.posix.join((0, path_1.dirname)(logicalLocation.inAppName), request.specifier))
|
805
|
-
// it's important that we're rehoming this to the root of the engine
|
806
|
-
// (which we know really exists), and not to a subdir like
|
807
|
-
// logicalLocation.inAppName (which might not physically exist),
|
808
|
-
// because some environments (including node's require.resolve) will
|
809
|
-
// refuse to do resolution from a notional path that doesn't
|
810
|
-
// physically exist.
|
811
|
-
.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
|
662
|
+
return logTransition('beforeResolve: relative import in app-js', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
|
812
663
|
}
|
813
664
|
return request;
|
814
665
|
}
|
@@ -823,11 +674,11 @@ class Resolver {
|
|
823
674
|
if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
|
824
675
|
// addons (whether auto-upgraded or not) may use the app's
|
825
676
|
// emberVirtualPeerDeps, like "@glimmer/component" etc.
|
826
|
-
|
827
|
-
|
828
|
-
throw new Error(`${pkg.name} is trying to import the emberVirtualPeerDep "${packageName}", but it seems to be missing`);
|
677
|
+
if (!this.options.activeAddons[packageName]) {
|
678
|
+
throw new Error(`${pkg.name} is trying to import the app's ${packageName} package, but it seems to be missing`);
|
829
679
|
}
|
830
|
-
|
680
|
+
let newHome = (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json');
|
681
|
+
return logTransition(`emberVirtualPeerDeps in v2 addon`, request, request.rehome(newHome));
|
831
682
|
}
|
832
683
|
// if this file is part of an addon's app-js, it's really the logical
|
833
684
|
// package to which it belongs (normally the app) that affects some policy
|
@@ -836,7 +687,7 @@ class Resolver {
|
|
836
687
|
if (logicalPackage.meta['auto-upgraded'] && !logicalPackage.hasDependency('ember-auto-import')) {
|
837
688
|
try {
|
838
689
|
let dep = this.packageCache.resolve(packageName, logicalPackage);
|
839
|
-
if (!dep.
|
690
|
+
if (!dep.isEmberPackage()) {
|
840
691
|
// classic ember addons can only import non-ember dependencies if they
|
841
692
|
// have ember-auto-import.
|
842
693
|
return this.external('v1 package without auto-import', request, specifier);
|
@@ -849,28 +700,14 @@ class Resolver {
|
|
849
700
|
}
|
850
701
|
}
|
851
702
|
// assertions on what native v2 addons can import
|
852
|
-
if (!pkg.
|
853
|
-
!
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
return request;
|
858
|
-
}
|
859
|
-
locateActiveAddon(packageName) {
|
860
|
-
if (packageName === this.options.modulePrefix) {
|
861
|
-
// the app itself is something that addon's can classically resolve if they know it's name.
|
862
|
-
return {
|
863
|
-
root: this.options.appRoot,
|
864
|
-
canResolveFromFile: (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json'),
|
865
|
-
};
|
866
|
-
}
|
867
|
-
for (let engine of this.options.engines) {
|
868
|
-
for (let addon of engine.activeAddons) {
|
869
|
-
if (addon.name === packageName) {
|
870
|
-
return addon;
|
871
|
-
}
|
703
|
+
if (!pkg.meta['auto-upgraded']) {
|
704
|
+
if (!pkg.meta['auto-upgraded'] &&
|
705
|
+
!appImportInAppTree(pkg, logicalPackage, packageName) &&
|
706
|
+
!reliablyResolvable(pkg, packageName)) {
|
707
|
+
throw new Error(`${pkg.name} is trying to import from ${packageName} but that is not one of its explicit dependencies`);
|
872
708
|
}
|
873
709
|
}
|
710
|
+
return request;
|
874
711
|
}
|
875
712
|
external(label, request, specifier) {
|
876
713
|
if (this.options.amdCompatibility === 'cjs') {
|
@@ -883,7 +720,7 @@ class Resolver {
|
|
883
720
|
entry = ['require', ['default', 'has']];
|
884
721
|
}
|
885
722
|
if (!entry) {
|
886
|
-
throw new Error(`
|
723
|
+
throw new Error(`A module tried to resolve "${request.specifier}" and didn't find it (${label}).
|
887
724
|
|
888
725
|
- Maybe a dependency declaration is missing?
|
889
726
|
- Remember that v1 addons can only import non-Ember-addon NPM dependencies if they include ember-auto-import in their dependencies.
|
@@ -904,11 +741,8 @@ class Resolver {
|
|
904
741
|
throw new Error(`Embroider's amdCompatibility option is disabled, but something tried to use it to access "${request.specifier}"`);
|
905
742
|
}
|
906
743
|
}
|
907
|
-
|
744
|
+
fallbackResolve(request) {
|
908
745
|
var _a, _b, _c;
|
909
|
-
if (request.isVirtual) {
|
910
|
-
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');
|
911
|
-
}
|
912
746
|
if (request.specifier === '@embroider/macros') {
|
913
747
|
// the macros package is always handled directly within babel (not
|
914
748
|
// necessarily as a real resolvable package), so we should not mess with it.
|
@@ -916,49 +750,56 @@ class Resolver {
|
|
916
750
|
// why we need to know about it.
|
917
751
|
return logTransition('fallback early exit', request);
|
918
752
|
}
|
919
|
-
|
753
|
+
let { specifier, fromFile } = request;
|
754
|
+
if (compatPattern.test(specifier)) {
|
920
755
|
// Some kinds of compat requests get rewritten into other things
|
921
|
-
// deterministically. For example, "
|
756
|
+
// deterministically. For example, "#embroider_compat/helpers/whatever"
|
922
757
|
// means only "the-current-engine/helpers/whatever", and if that doesn't
|
923
758
|
// actually exist it's that path that will show up as a missing import.
|
924
759
|
//
|
925
760
|
// But others have an ambiguous meaning. For example,
|
926
|
-
//
|
761
|
+
// #embroider_compat/components/whatever can mean several different
|
927
762
|
// things. If we're unable to find any of them, the actual
|
928
|
-
// "
|
763
|
+
// "#embroider_compat" request will fall through all the way to here.
|
929
764
|
//
|
930
765
|
// In that case, we don't want to externalize that failure. We know it's
|
931
766
|
// not a classic runtime thing. It's better to let it be a build error
|
932
767
|
// here.
|
933
768
|
return request;
|
934
769
|
}
|
935
|
-
|
770
|
+
if (fromFile.endsWith('moved-package-target.js')) {
|
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);
|
936
777
|
if (!pkg) {
|
937
778
|
return logTransition('no identifiable owningPackage', request);
|
938
779
|
}
|
939
|
-
//
|
940
|
-
//
|
941
|
-
//
|
780
|
+
// if we rehomed this request to its un-rewritten location in order to try
|
781
|
+
// to do the defaultResolve from there, now we refer back to the rewritten
|
782
|
+
// location because that's what we want to use when asking things like
|
783
|
+
// isV2Ember()
|
942
784
|
let movedPkg = this.packageCache.maybeMoved(pkg);
|
943
785
|
if (movedPkg !== pkg) {
|
944
|
-
|
945
|
-
if (typeof originalFromFile !== 'string') {
|
786
|
+
if (!((_c = request.meta) === null || _c === void 0 ? void 0 : _c.wasMovedTo)) {
|
946
787
|
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
947
788
|
}
|
948
|
-
|
789
|
+
fromFile = request.meta.wasMovedTo;
|
949
790
|
pkg = movedPkg;
|
950
791
|
}
|
951
792
|
if (!pkg.isV2Ember()) {
|
952
793
|
return logTransition('fallbackResolve: not in an ember package', request);
|
953
794
|
}
|
954
|
-
let packageName = (0, shared_internals_1.packageName)(
|
795
|
+
let packageName = (0, shared_internals_1.packageName)(specifier);
|
955
796
|
if (!packageName) {
|
956
797
|
// this is a relative import
|
957
798
|
let withinEngine = this.engineConfig(pkg.name);
|
958
799
|
if (withinEngine) {
|
959
800
|
// it's a relative import inside an engine (which also means app), which
|
960
801
|
// means we may need to satisfy the request via app tree merging.
|
961
|
-
let appJSMatch =
|
802
|
+
let appJSMatch = this.searchAppTree(request, withinEngine, (0, shared_internals_2.explicitRelative)(pkg.root, (0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier)));
|
962
803
|
if (appJSMatch) {
|
963
804
|
return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
|
964
805
|
}
|
@@ -972,49 +813,40 @@ class Resolver {
|
|
972
813
|
}
|
973
814
|
}
|
974
815
|
// auto-upgraded packages can fall back to the set of known active addons
|
975
|
-
if (pkg.
|
976
|
-
|
977
|
-
if (
|
978
|
-
|
979
|
-
if (rehomed !== request) {
|
980
|
-
return logTransition(`activeAddons`, request, rehomed);
|
981
|
-
}
|
816
|
+
if (pkg.meta['auto-upgraded'] && this.options.activeAddons[packageName]) {
|
817
|
+
const rehomed = this.resolveWithinMovedPackage(request, this.packageCache.get(this.options.activeAddons[packageName]));
|
818
|
+
if (rehomed !== request) {
|
819
|
+
return logTransition(`activeAddons`, request, rehomed);
|
982
820
|
}
|
983
821
|
}
|
984
|
-
let logicalLocation = this.reverseSearchAppTree(pkg,
|
822
|
+
let logicalLocation = this.reverseSearchAppTree(pkg, fromFile);
|
985
823
|
if (logicalLocation) {
|
986
824
|
// the requesting file is in an addon's appTree. We didn't succeed in
|
987
825
|
// resolving this (non-relative) request from inside the actual addon, so
|
988
826
|
// next try to resolve it from the corresponding logical location in the
|
989
827
|
// app.
|
990
|
-
return logTransition('fallbackResolve: retry from logical home of app-js file', request,
|
991
|
-
// it might look more precise to rehome into logicalLocation.inAppName
|
992
|
-
// rather than package.json. But that logical location may not actually
|
993
|
-
// exist, and some systems (including node's require.resolve) will be
|
994
|
-
// mad about trying to resolve from notional paths that don't really
|
995
|
-
// exist.
|
996
|
-
request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
|
828
|
+
return logTransition('fallbackResolve: retry from logical home of app-js file', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
|
997
829
|
}
|
998
830
|
let targetingEngine = this.engineConfig(packageName);
|
999
831
|
if (targetingEngine) {
|
1000
|
-
let appJSMatch =
|
832
|
+
let appJSMatch = this.searchAppTree(request, targetingEngine, specifier.replace(packageName, '.'));
|
1001
833
|
if (appJSMatch) {
|
1002
834
|
return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
|
1003
835
|
}
|
1004
836
|
}
|
1005
|
-
if (pkg.
|
837
|
+
if (pkg.meta['auto-upgraded']) {
|
1006
838
|
// auto-upgraded packages can fall back to attempting to find dependencies at
|
1007
839
|
// runtime. Native v2 packages can only get this behavior in the
|
1008
840
|
// isExplicitlyExternal case above because they need to explicitly ask for
|
1009
841
|
// externals.
|
1010
|
-
return this.external('v1 catch-all fallback', request,
|
842
|
+
return this.external('v1 catch-all fallback', request, specifier);
|
1011
843
|
}
|
1012
844
|
else {
|
1013
845
|
// native v2 packages don't automatically externalize *everything* the way
|
1014
846
|
// auto-upgraded packages do, but they still externalize known and approved
|
1015
847
|
// ember virtual packages (like @ember/component)
|
1016
848
|
if (shared_internals_1.emberVirtualPackages.has(packageName)) {
|
1017
|
-
return this.external('emberVirtualPackages', request,
|
849
|
+
return this.external('emberVirtualPackages', request, specifier);
|
1018
850
|
}
|
1019
851
|
}
|
1020
852
|
// this is falling through with the original specifier which was
|
@@ -1041,23 +873,25 @@ class Resolver {
|
|
1041
873
|
}
|
1042
874
|
}
|
1043
875
|
}
|
1044
|
-
|
876
|
+
searchAppTree(request, engine, inEngineSpecifier) {
|
1045
877
|
let matched = this.getEntryFromMergeMap(inEngineSpecifier, engine.root);
|
1046
878
|
switch (matched === null || matched === void 0 ? void 0 : matched.entry.type) {
|
1047
879
|
case undefined:
|
1048
880
|
return undefined;
|
1049
881
|
case 'app-only':
|
1050
|
-
return request
|
882
|
+
return request
|
883
|
+
.alias(matched.entry['app-js'].localPath)
|
884
|
+
.rehome((0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
|
1051
885
|
case 'fastboot-only':
|
1052
|
-
return request
|
886
|
+
return request
|
887
|
+
.alias(matched.entry['fastboot-js'].localPath)
|
888
|
+
.rehome((0, path_1.resolve)(matched.entry['fastboot-js'].packageRoot, 'package.json'));
|
1053
889
|
case 'both':
|
1054
|
-
let foundAppJS =
|
1055
|
-
|
1056
|
-
}));
|
1057
|
-
if (foundAppJS.type !== 'found') {
|
890
|
+
let foundAppJS = this.nodeResolve(matched.entry['app-js'].localPath, (0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
|
891
|
+
if (foundAppJS.type !== 'real') {
|
1058
892
|
throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`);
|
1059
893
|
}
|
1060
|
-
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), {
|
894
|
+
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), {});
|
1061
895
|
return request.virtualize((0, virtual_content_1.fastbootSwitch)(matched.matched, (0, path_1.resolve)(engine.root, 'package.json'), names));
|
1062
896
|
}
|
1063
897
|
}
|