@embroider/core 3.4.10-unstable.e01da0a → 3.4.10
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/LICENSE +21 -0
- package/package.json +12 -15
- package/src/app-files.d.ts +4 -3
- package/src/app-files.js +3 -10
- package/src/app-files.js.map +1 -1
- package/src/asset.d.ts +6 -2
- package/src/asset.js.map +1 -1
- package/src/describe-exports.js.map +1 -1
- package/src/ember-html.d.ts +8 -3
- package/src/ember-html.js +19 -7
- 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 +15 -31
- package/src/module-resolver.js +191 -346
- package/src/module-resolver.js.map +1 -1
- 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 +2 -6
- package/src/virtual-content.js +42 -119
- package/src/virtual-content.js.map +1 -1
- package/src/wait-for-trees.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 -303
- package/src/virtual-entrypoint.js.map +0 -1
- package/src/virtual-route-entrypoint.d.ts +0 -15
- package/src/virtual-route-entrypoint.js +0 -102
- 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 -67
- 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 -65
- 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 -69
- 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 -83
- package/src/virtual-vendor-styles.js.map +0 -1
- package/src/virtual-vendor.d.ts +0 -4
- package/src/virtual-vendor.js +0 -73
- 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
|
-
function isTerminal(request) {
|
64
|
-
return request.isVirtual || request.isNotFound || Boolean(request.resolvedTo);
|
65
|
-
}
|
66
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
|
+
}
|
69
|
+
}
|
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;
|
@@ -386,76 +322,56 @@ class Resolver {
|
|
386
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
|
-
}));
|
343
|
+
let resolution = this.nodeResolve(`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`, target.from);
|
426
344
|
// .hbs is a resolvable extension for us, so we need to exclude it here.
|
427
345
|
// It matches as a priority lower than .js, so finding an .hbs means
|
428
346
|
// there's definitely not a .js.
|
429
|
-
if (resolution.type === '
|
430
|
-
jsModule = resolution;
|
347
|
+
if (resolution.type === 'real' && !resolution.filename.endsWith('.hbs')) {
|
348
|
+
jsModule = resolution.filename;
|
431
349
|
break;
|
432
350
|
}
|
433
351
|
}
|
434
352
|
if (hbsModule) {
|
435
|
-
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)));
|
436
354
|
}
|
437
355
|
else if (jsModule) {
|
438
|
-
return logTransition(`
|
356
|
+
return logTransition(`resolveComponent found only JS`, request, request.alias(jsModule).rehome(target.from));
|
439
357
|
}
|
440
358
|
else {
|
441
359
|
return logTransition(`resolveComponent failed`, request);
|
442
360
|
}
|
443
361
|
}
|
444
|
-
|
362
|
+
resolveHelperOrComponent(path, inEngine, request) {
|
445
363
|
// resolveHelper just rewrites our request to one that should target the
|
446
364
|
// component, so here to resolve the ambiguity we need to actually resolve
|
447
365
|
// that candidate to see if it works.
|
448
366
|
let helperCandidate = this.resolveHelper(path, inEngine, request);
|
449
|
-
let helperMatch =
|
450
|
-
|
451
|
-
|
452
|
-
if (helperMatch.type === 'found') {
|
453
|
-
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);
|
454
370
|
}
|
455
371
|
// unlike resolveHelper, resolveComponent already does pre-resolution in
|
456
372
|
// order to deal with its own internal ambiguity around JS vs HBS vs
|
457
373
|
// colocation.≥
|
458
|
-
let componentMatch =
|
374
|
+
let componentMatch = this.resolveComponent(path, inEngine, request);
|
459
375
|
if (componentMatch !== request) {
|
460
376
|
return logTransition('ambiguous case matched a cmoponent', request, componentMatch);
|
461
377
|
}
|
@@ -480,7 +396,6 @@ class Resolver {
|
|
480
396
|
}
|
481
397
|
*componentJSCandidates(inPackageName) {
|
482
398
|
yield { prefix: '/components/', suffix: '' };
|
483
|
-
yield { prefix: '/components/', suffix: '/index' };
|
484
399
|
yield { prefix: '/components/', suffix: '/component' };
|
485
400
|
let pods = this.podPrefix(inPackageName);
|
486
401
|
if (pods) {
|
@@ -499,10 +414,10 @@ class Resolver {
|
|
499
414
|
parseGlobalPath(path, inEngine) {
|
500
415
|
let parts = path.split('@');
|
501
416
|
if (parts.length > 1 && parts[0].length > 0) {
|
502
|
-
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') };
|
503
418
|
}
|
504
419
|
else {
|
505
|
-
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') };
|
506
421
|
}
|
507
422
|
}
|
508
423
|
engineConfig(packageName) {
|
@@ -534,8 +449,8 @@ class Resolver {
|
|
534
449
|
engineModules.set(inEngineName, {
|
535
450
|
type: 'app-only',
|
536
451
|
'app-js': {
|
537
|
-
|
538
|
-
|
452
|
+
localPath: inAddonName,
|
453
|
+
packageRoot: addon.root,
|
539
454
|
fromPackageName: addon.name,
|
540
455
|
},
|
541
456
|
});
|
@@ -548,8 +463,8 @@ class Resolver {
|
|
548
463
|
engineModules.set(inEngineName, {
|
549
464
|
type: 'both',
|
550
465
|
'app-js': {
|
551
|
-
|
552
|
-
|
466
|
+
localPath: inAddonName,
|
467
|
+
packageRoot: addon.root,
|
553
468
|
fromPackageName: addon.name,
|
554
469
|
},
|
555
470
|
'fastboot-js': prevEntry['fastboot-js'],
|
@@ -573,8 +488,8 @@ class Resolver {
|
|
573
488
|
engineModules.set(inEngineName, {
|
574
489
|
type: 'fastboot-only',
|
575
490
|
'fastboot-js': {
|
576
|
-
|
577
|
-
|
491
|
+
localPath: inAddonName,
|
492
|
+
packageRoot: addon.root,
|
578
493
|
fromPackageName: addon.name,
|
579
494
|
},
|
580
495
|
});
|
@@ -587,8 +502,8 @@ class Resolver {
|
|
587
502
|
engineModules.set(inEngineName, {
|
588
503
|
type: 'both',
|
589
504
|
'fastboot-js': {
|
590
|
-
|
591
|
-
|
505
|
+
localPath: inAddonName,
|
506
|
+
packageRoot: addon.root,
|
592
507
|
fromPackageName: addon.name,
|
593
508
|
},
|
594
509
|
'app-js': prevEntry['app-js'],
|
@@ -610,7 +525,7 @@ class Resolver {
|
|
610
525
|
return owningEngine;
|
611
526
|
}
|
612
527
|
handleRewrittenPackages(request) {
|
613
|
-
if (
|
528
|
+
if (request.isVirtual) {
|
614
529
|
return request;
|
615
530
|
}
|
616
531
|
let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
@@ -629,6 +544,10 @@ class Resolver {
|
|
629
544
|
targetPkg = this.packageCache.resolve(packageName, requestingPkg);
|
630
545
|
}
|
631
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)
|
632
551
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
633
552
|
throw err;
|
634
553
|
}
|
@@ -644,26 +563,14 @@ class Resolver {
|
|
644
563
|
return logTransition('request targets a moved package', request, this.resolveWithinMovedPackage(request, targetPkg));
|
645
564
|
}
|
646
565
|
else if (originalRequestingPkg !== requestingPkg) {
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
return logTransition('outbound request from moved package', request, request
|
651
|
-
// setting meta here because if this fails, we want the fallback
|
652
|
-
// logic to revert our rehome and continue from the *moved* package.
|
653
|
-
.withMeta({ originalFromFile: request.fromFile })
|
654
|
-
.rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
|
655
|
-
}
|
656
|
-
else {
|
657
|
-
// requesting package was moved and we failed to find its target. We
|
658
|
-
// can't let that accidentally succeed in the defaultResolve because we
|
659
|
-
// could escape the moved package system.
|
660
|
-
return logTransition('missing outbound request from moved package', request, request.notFound());
|
661
|
-
}
|
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')));
|
662
569
|
}
|
663
570
|
return request;
|
664
571
|
}
|
665
572
|
handleRenaming(request) {
|
666
|
-
if (
|
573
|
+
if (request.isVirtual) {
|
667
574
|
return request;
|
668
575
|
}
|
669
576
|
let packageName = (0, shared_internals_1.packageName)(request.specifier);
|
@@ -696,65 +603,30 @@ class Resolver {
|
|
696
603
|
return logTransition(`renamePackages`, request, request.alias(request.specifier.replace(packageName, this.options.renamePackages[packageName])));
|
697
604
|
}
|
698
605
|
}
|
699
|
-
if (pkg.name === packageName) {
|
700
|
-
// we found a self-import
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
// "my-package/foo" -> "./foo"
|
706
|
-
// "my-package" -> "./" (this can't be just "." because node's require.resolve doesn't reliable support that)
|
707
|
-
let selfImportPath = request.specifier === pkg.name ? './' : request.specifier.replace(pkg.name, '.');
|
708
|
-
return logTransition(`v1 self-import`, request, request.alias(selfImportPath).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
|
709
|
-
}
|
710
|
-
else {
|
711
|
-
// v2 packages are supposed to use package.json `exports` to enable
|
712
|
-
// self-imports, but not all build tools actually follow the spec. This
|
713
|
-
// is a workaround for badly behaved packagers.
|
714
|
-
//
|
715
|
-
// Known upstream bugs this works around:
|
716
|
-
// - https://github.com/vitejs/vite/issues/9731
|
717
|
-
if (pkg.packageJSON.exports) {
|
718
|
-
let found = (0, resolve_exports_1.exports)(pkg.packageJSON, request.specifier, {
|
719
|
-
browser: true,
|
720
|
-
conditions: ['default', 'imports'],
|
721
|
-
});
|
722
|
-
if (found === null || found === void 0 ? void 0 : found[0]) {
|
723
|
-
return logTransition(`v2 self-import with package.json exports`, request, request.alias(found === null || found === void 0 ? void 0 : found[0]).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
|
724
|
-
}
|
725
|
-
}
|
726
|
-
}
|
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')));
|
727
612
|
}
|
728
613
|
return request;
|
729
614
|
}
|
730
|
-
handleVendor(request) {
|
731
|
-
//TODO move the extra forwardslash handling out into the vite plugin
|
732
|
-
const candidates = ['@embroider/core/vendor.js', '/@embroider/core/vendor.js', './@embroider/core/vendor.js'];
|
733
|
-
if (!candidates.includes(request.specifier)) {
|
734
|
-
return request;
|
735
|
-
}
|
736
|
-
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
737
|
-
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
738
|
-
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/core/vendor.js. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
739
|
-
}
|
740
|
-
return logTransition('vendor', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor.js')));
|
741
|
-
}
|
742
615
|
resolveWithinMovedPackage(request, pkg) {
|
743
616
|
let levels = ['..'];
|
744
617
|
if (pkg.name.startsWith('@')) {
|
745
618
|
levels.push('..');
|
746
619
|
}
|
747
|
-
let originalFromFile = request.fromFile;
|
748
620
|
let newRequest = request.rehome((0, path_1.resolve)(pkg.root, ...levels, 'moved-package-target.js'));
|
749
621
|
if (newRequest === request) {
|
750
622
|
return request;
|
751
623
|
}
|
752
|
-
|
753
|
-
|
754
|
-
|
624
|
+
return newRequest.withMeta({
|
625
|
+
resolvedWithinPackage: pkg.root,
|
626
|
+
});
|
755
627
|
}
|
756
628
|
preHandleExternal(request) {
|
757
|
-
if (
|
629
|
+
if (request.isVirtual) {
|
758
630
|
return request;
|
759
631
|
}
|
760
632
|
let { specifier, fromFile } = request;
|
@@ -787,15 +659,7 @@ class Resolver {
|
|
787
659
|
// engine
|
788
660
|
let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
|
789
661
|
if (logicalLocation) {
|
790
|
-
return logTransition('beforeResolve: relative import in app-js', request, request
|
791
|
-
.alias('./' + path_1.posix.join((0, path_1.dirname)(logicalLocation.inAppName), request.specifier))
|
792
|
-
// it's important that we're rehoming this to the root of the engine
|
793
|
-
// (which we know really exists), and not to a subdir like
|
794
|
-
// logicalLocation.inAppName (which might not physically exist),
|
795
|
-
// because some environments (including node's require.resolve) will
|
796
|
-
// refuse to do resolution from a notional path that doesn't
|
797
|
-
// physically exist.
|
798
|
-
.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
|
662
|
+
return logTransition('beforeResolve: relative import in app-js', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
|
799
663
|
}
|
800
664
|
return request;
|
801
665
|
}
|
@@ -810,11 +674,11 @@ class Resolver {
|
|
810
674
|
if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
|
811
675
|
// addons (whether auto-upgraded or not) may use the app's
|
812
676
|
// emberVirtualPeerDeps, like "@glimmer/component" etc.
|
813
|
-
|
814
|
-
|
815
|
-
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`);
|
816
679
|
}
|
817
|
-
|
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));
|
818
682
|
}
|
819
683
|
// if this file is part of an addon's app-js, it's really the logical
|
820
684
|
// package to which it belongs (normally the app) that affects some policy
|
@@ -845,22 +709,6 @@ class Resolver {
|
|
845
709
|
}
|
846
710
|
return request;
|
847
711
|
}
|
848
|
-
locateActiveAddon(packageName) {
|
849
|
-
if (packageName === this.options.modulePrefix) {
|
850
|
-
// the app itself is something that addon's can classically resolve if they know it's name.
|
851
|
-
return {
|
852
|
-
root: this.options.appRoot,
|
853
|
-
canResolveFromFile: (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json'),
|
854
|
-
};
|
855
|
-
}
|
856
|
-
for (let engine of this.options.engines) {
|
857
|
-
for (let addon of engine.activeAddons) {
|
858
|
-
if (addon.name === packageName) {
|
859
|
-
return addon;
|
860
|
-
}
|
861
|
-
}
|
862
|
-
}
|
863
|
-
}
|
864
712
|
external(label, request, specifier) {
|
865
713
|
if (this.options.amdCompatibility === 'cjs') {
|
866
714
|
let filename = (0, virtual_content_1.virtualExternalCJSModule)(specifier);
|
@@ -893,11 +741,8 @@ class Resolver {
|
|
893
741
|
throw new Error(`Embroider's amdCompatibility option is disabled, but something tried to use it to access "${request.specifier}"`);
|
894
742
|
}
|
895
743
|
}
|
896
|
-
|
744
|
+
fallbackResolve(request) {
|
897
745
|
var _a, _b, _c;
|
898
|
-
if (request.isVirtual) {
|
899
|
-
throw new Error('Build tool bug detected! Fallback resolve should never see a virtual request. It is expected that the defaultResolve for your bundler has already resolved this request');
|
900
|
-
}
|
901
746
|
if (request.specifier === '@embroider/macros') {
|
902
747
|
// the macros package is always handled directly within babel (not
|
903
748
|
// necessarily as a real resolvable package), so we should not mess with it.
|
@@ -905,7 +750,8 @@ class Resolver {
|
|
905
750
|
// why we need to know about it.
|
906
751
|
return logTransition('fallback early exit', request);
|
907
752
|
}
|
908
|
-
|
753
|
+
let { specifier, fromFile } = request;
|
754
|
+
if (compatPattern.test(specifier)) {
|
909
755
|
// Some kinds of compat requests get rewritten into other things
|
910
756
|
// deterministically. For example, "#embroider_compat/helpers/whatever"
|
911
757
|
// means only "the-current-engine/helpers/whatever", and if that doesn't
|
@@ -921,33 +767,39 @@ class Resolver {
|
|
921
767
|
// here.
|
922
768
|
return request;
|
923
769
|
}
|
924
|
-
|
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);
|
925
777
|
if (!pkg) {
|
926
778
|
return logTransition('no identifiable owningPackage', request);
|
927
779
|
}
|
928
|
-
//
|
929
|
-
//
|
930
|
-
//
|
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()
|
931
784
|
let movedPkg = this.packageCache.maybeMoved(pkg);
|
932
785
|
if (movedPkg !== pkg) {
|
933
|
-
|
934
|
-
if (typeof originalFromFile !== 'string') {
|
786
|
+
if (!((_c = request.meta) === null || _c === void 0 ? void 0 : _c.wasMovedTo)) {
|
935
787
|
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
936
788
|
}
|
937
|
-
|
789
|
+
fromFile = request.meta.wasMovedTo;
|
938
790
|
pkg = movedPkg;
|
939
791
|
}
|
940
792
|
if (!pkg.isV2Ember()) {
|
941
793
|
return logTransition('fallbackResolve: not in an ember package', request);
|
942
794
|
}
|
943
|
-
let packageName = (0, shared_internals_1.packageName)(
|
795
|
+
let packageName = (0, shared_internals_1.packageName)(specifier);
|
944
796
|
if (!packageName) {
|
945
797
|
// this is a relative import
|
946
798
|
let withinEngine = this.engineConfig(pkg.name);
|
947
799
|
if (withinEngine) {
|
948
800
|
// it's a relative import inside an engine (which also means app), which
|
949
801
|
// means we may need to satisfy the request via app tree merging.
|
950
|
-
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)));
|
951
803
|
if (appJSMatch) {
|
952
804
|
return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
|
953
805
|
}
|
@@ -961,49 +813,40 @@ class Resolver {
|
|
961
813
|
}
|
962
814
|
}
|
963
815
|
// auto-upgraded packages can fall back to the set of known active addons
|
964
|
-
if (pkg.meta['auto-upgraded']) {
|
965
|
-
|
966
|
-
if (
|
967
|
-
|
968
|
-
if (rehomed !== request) {
|
969
|
-
return logTransition(`activeAddons`, request, rehomed);
|
970
|
-
}
|
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);
|
971
820
|
}
|
972
821
|
}
|
973
|
-
let logicalLocation = this.reverseSearchAppTree(pkg,
|
822
|
+
let logicalLocation = this.reverseSearchAppTree(pkg, fromFile);
|
974
823
|
if (logicalLocation) {
|
975
824
|
// the requesting file is in an addon's appTree. We didn't succeed in
|
976
825
|
// resolving this (non-relative) request from inside the actual addon, so
|
977
826
|
// next try to resolve it from the corresponding logical location in the
|
978
827
|
// app.
|
979
|
-
return logTransition('fallbackResolve: retry from logical home of app-js file', request,
|
980
|
-
// it might look more precise to rehome into logicalLocation.inAppName
|
981
|
-
// rather than package.json. But that logical location may not actually
|
982
|
-
// exist, and some systems (including node's require.resolve) will be
|
983
|
-
// mad about trying to resolve from notional paths that don't really
|
984
|
-
// exist.
|
985
|
-
request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
|
828
|
+
return logTransition('fallbackResolve: retry from logical home of app-js file', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
|
986
829
|
}
|
987
830
|
let targetingEngine = this.engineConfig(packageName);
|
988
831
|
if (targetingEngine) {
|
989
|
-
let appJSMatch =
|
832
|
+
let appJSMatch = this.searchAppTree(request, targetingEngine, specifier.replace(packageName, '.'));
|
990
833
|
if (appJSMatch) {
|
991
834
|
return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
|
992
835
|
}
|
993
836
|
}
|
994
|
-
if (pkg.meta['auto-upgraded']
|
837
|
+
if (pkg.meta['auto-upgraded']) {
|
995
838
|
// auto-upgraded packages can fall back to attempting to find dependencies at
|
996
839
|
// runtime. Native v2 packages can only get this behavior in the
|
997
840
|
// isExplicitlyExternal case above because they need to explicitly ask for
|
998
841
|
// externals.
|
999
|
-
return this.external('v1 catch-all fallback', request,
|
842
|
+
return this.external('v1 catch-all fallback', request, specifier);
|
1000
843
|
}
|
1001
844
|
else {
|
1002
845
|
// native v2 packages don't automatically externalize *everything* the way
|
1003
846
|
// auto-upgraded packages do, but they still externalize known and approved
|
1004
847
|
// ember virtual packages (like @ember/component)
|
1005
848
|
if (shared_internals_1.emberVirtualPackages.has(packageName)) {
|
1006
|
-
return this.external('emberVirtualPackages', request,
|
849
|
+
return this.external('emberVirtualPackages', request, specifier);
|
1007
850
|
}
|
1008
851
|
}
|
1009
852
|
// this is falling through with the original specifier which was
|
@@ -1030,23 +873,25 @@ class Resolver {
|
|
1030
873
|
}
|
1031
874
|
}
|
1032
875
|
}
|
1033
|
-
|
876
|
+
searchAppTree(request, engine, inEngineSpecifier) {
|
1034
877
|
let matched = this.getEntryFromMergeMap(inEngineSpecifier, engine.root);
|
1035
878
|
switch (matched === null || matched === void 0 ? void 0 : matched.entry.type) {
|
1036
879
|
case undefined:
|
1037
880
|
return undefined;
|
1038
881
|
case 'app-only':
|
1039
|
-
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'));
|
1040
885
|
case 'fastboot-only':
|
1041
|
-
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'));
|
1042
889
|
case 'both':
|
1043
|
-
let foundAppJS =
|
1044
|
-
|
1045
|
-
}));
|
1046
|
-
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') {
|
1047
892
|
throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`);
|
1048
893
|
}
|
1049
|
-
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'), {});
|
1050
895
|
return request.virtualize((0, virtual_content_1.fastbootSwitch)(matched.matched, (0, path_1.resolve)(engine.root, 'package.json'), names));
|
1051
896
|
}
|
1052
897
|
}
|