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