@embroider/core 3.4.20-unstable.e6197c7 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -19
- package/src/app-files.d.ts +5 -3
- package/src/app-files.js +8 -25
- package/src/app-files.js.map +1 -1
- package/src/asset.d.ts +32 -0
- package/src/asset.js +3 -0
- package/src/asset.js.map +1 -0
- package/src/ember-html.d.ts +43 -0
- package/src/ember-html.js +110 -0
- package/src/ember-html.js.map +1 -0
- package/src/index.d.ts +4 -4
- package/src/index.js +3 -3
- package/src/index.js.map +1 -1
- package/src/measure-concat.js +2 -1
- package/src/measure-concat.js.map +1 -1
- package/src/module-resolver.d.ts +60 -17
- package/src/module-resolver.js +311 -402
- package/src/module-resolver.js.map +1 -1
- package/src/options.d.ts +60 -1
- package/src/options.js +1 -3
- package/src/options.js.map +1 -1
- package/src/portable-babel-config.d.ts +11 -0
- package/src/portable-babel-config.js +132 -0
- package/src/portable-babel-config.js.map +1 -0
- package/src/portable-babel-launcher.d.ts +6 -0
- package/src/portable-babel-launcher.js +75 -0
- package/src/portable-babel-launcher.js.map +1 -0
- package/src/resolver-loader.js +1 -8
- package/src/resolver-loader.js.map +1 -1
- package/src/to-broccoli-plugin.d.ts +8 -0
- package/src/to-broccoli-plugin.js +30 -0
- package/src/to-broccoli-plugin.js.map +1 -0
- package/src/virtual-content.d.ts +4 -29
- package/src/virtual-content.js +112 -74
- package/src/virtual-content.js.map +1 -1
- package/src/module-request.d.ts +0 -43
- package/src/module-request.js +0 -91
- package/src/module-request.js.map +0 -1
- package/src/module-resolver-options.d.ts +0 -42
- package/src/module-resolver-options.js +0 -164
- package/src/module-resolver-options.js.map +0 -1
- package/src/node-resolve.d.ts +0 -30
- package/src/node-resolve.js +0 -112
- package/src/node-resolve.js.map +0 -1
- package/src/virtual-entrypoint.d.ts +0 -23
- package/src/virtual-entrypoint.js +0 -327
- package/src/virtual-entrypoint.js.map +0 -1
- package/src/virtual-route-entrypoint.d.ts +0 -16
- package/src/virtual-route-entrypoint.js +0 -100
- 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 -64
- package/src/virtual-test-support-styles.js.map +0 -1
- package/src/virtual-test-support.d.ts +0 -4
- package/src/virtual-test-support.js +0 -68
- package/src/virtual-test-support.js.map +0 -1
- package/src/virtual-vendor-styles.d.ts +0 -4
- package/src/virtual-vendor-styles.js +0 -82
- package/src/virtual-vendor-styles.js.map +0 -1
- package/src/virtual-vendor.d.ts +0 -4
- package/src/virtual-vendor.js +0 -57
- package/src/virtual-vendor.js.map +0 -1
- package/types/virtual/index.d.ts +0 -9
- package/types/virtual/index.js +0 -3
package/src/module-resolver.js
CHANGED
@@ -15,53 +15,64 @@ 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 semver_1 = require("semver");
|
27
|
-
const virtual_entrypoint_1 = require("./virtual-entrypoint");
|
28
24
|
const debug = (0, debug_1.default)('embroider:resolver');
|
29
|
-
// Using a formatter makes this work lazy so nothing happens when we aren't
|
30
|
-
// logging. It is unfortunate that formatters are a globally mutable config and
|
31
|
-
// you can only use single character names, but oh well.
|
32
|
-
debug_1.default.formatters.p = (s) => {
|
33
|
-
let cwd = process.cwd();
|
34
|
-
if (s.startsWith(cwd)) {
|
35
|
-
return s.slice(cwd.length + 1);
|
36
|
-
}
|
37
|
-
return s;
|
38
|
-
};
|
39
25
|
function logTransition(reason, before, after = before) {
|
40
|
-
if (after.
|
41
|
-
debug(`
|
26
|
+
if (after.isVirtual) {
|
27
|
+
debug(`virtualized %s in %s because %s`, before.specifier, before.fromFile, reason);
|
42
28
|
}
|
43
29
|
else if (before.specifier !== after.specifier) {
|
44
30
|
if (before.fromFile !== after.fromFile) {
|
45
|
-
debug(`
|
31
|
+
debug(`aliased and rehomed: %s to %s, from %s to %s because %s`, before.specifier, after.specifier, before.fromFile, after.fromFile, reason);
|
46
32
|
}
|
47
33
|
else {
|
48
|
-
debug(`
|
34
|
+
debug(`aliased: %s to %s in %s because`, before.specifier, after.specifier, before.fromFile, reason);
|
49
35
|
}
|
50
36
|
}
|
51
37
|
else if (before.fromFile !== after.fromFile) {
|
52
|
-
debug(`
|
38
|
+
debug(`rehomed: %s from %s to %s because`, before.specifier, before.fromFile, after.fromFile, reason);
|
53
39
|
}
|
54
40
|
else {
|
55
|
-
debug(`
|
41
|
+
debug(`unchanged: %s in %s because %s`, before.specifier, before.fromFile, reason);
|
56
42
|
}
|
57
43
|
return after;
|
58
44
|
}
|
59
|
-
const compatPattern =
|
45
|
+
const compatPattern = /#embroider_compat\/(?<type>[^\/]+)\/(?<rest>.*)/;
|
46
|
+
class NodeModuleRequest {
|
47
|
+
constructor(specifier, fromFile, isVirtual, meta) {
|
48
|
+
this.specifier = specifier;
|
49
|
+
this.fromFile = fromFile;
|
50
|
+
this.isVirtual = isVirtual;
|
51
|
+
this.meta = meta;
|
52
|
+
}
|
53
|
+
alias(specifier) {
|
54
|
+
return new NodeModuleRequest(specifier, this.fromFile, false, this.meta);
|
55
|
+
}
|
56
|
+
rehome(fromFile) {
|
57
|
+
if (this.fromFile === fromFile) {
|
58
|
+
return this;
|
59
|
+
}
|
60
|
+
else {
|
61
|
+
return new NodeModuleRequest(this.specifier, fromFile, false, this.meta);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
virtualize(filename) {
|
65
|
+
return new NodeModuleRequest(filename, this.fromFile, true, this.meta);
|
66
|
+
}
|
67
|
+
withMeta(meta) {
|
68
|
+
return new NodeModuleRequest(this.specifier, this.fromFile, this.isVirtual, meta);
|
69
|
+
}
|
70
|
+
}
|
60
71
|
class Resolver {
|
61
72
|
constructor(options) {
|
62
73
|
this.options = options;
|
63
74
|
}
|
64
|
-
|
75
|
+
beforeResolve(request) {
|
65
76
|
if (request.specifier === '@embroider/macros') {
|
66
77
|
// the macros package is always handled directly within babel (not
|
67
78
|
// necessarily as a real resolvable package), so we should not mess with it.
|
@@ -70,15 +81,9 @@ class Resolver {
|
|
70
81
|
return logTransition('early exit', request);
|
71
82
|
}
|
72
83
|
request = this.handleFastbootSwitch(request);
|
73
|
-
request =
|
84
|
+
request = this.handleGlobalsCompat(request);
|
74
85
|
request = this.handleImplicitModules(request);
|
75
|
-
request = this.handleImplicitTestScripts(request);
|
76
|
-
request = this.handleVendorStyles(request);
|
77
|
-
request = this.handleTestSupportStyles(request);
|
78
|
-
request = this.handleEntrypoint(request);
|
79
|
-
request = this.handleRouteEntrypoint(request);
|
80
86
|
request = this.handleRenaming(request);
|
81
|
-
request = this.handleVendor(request);
|
82
87
|
// we expect the specifier to be app relative at this point - must be after handleRenaming
|
83
88
|
request = this.generateFastbootSwitch(request);
|
84
89
|
request = this.preHandleExternal(request);
|
@@ -92,20 +97,34 @@ class Resolver {
|
|
92
97
|
// that calls your build system's normal module resolver, this does both pre-
|
93
98
|
// and post-resolution adjustments as needed to implement our compatibility
|
94
99
|
// rules.
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
100
|
+
//
|
101
|
+
// Depending on the plugin architecture you're working in, it may be easier to
|
102
|
+
// call beforeResolve and fallbackResolve directly, in which case matching the
|
103
|
+
// details of the recursion to what this method does are your responsibility.
|
104
|
+
async resolve(request, defaultResolve) {
|
105
|
+
let gen = this.internalResolve(request, defaultResolve);
|
106
|
+
let out = gen.next();
|
107
|
+
while (!out.done) {
|
108
|
+
out = gen.next(await out.value);
|
109
|
+
}
|
110
|
+
return out.value;
|
111
|
+
}
|
112
|
+
// synchronous alternative to resolve() above. Because our own internals are
|
113
|
+
// all synchronous, you can use this if your defaultResolve function is
|
114
|
+
// synchronous.
|
115
|
+
resolveSync(request, defaultResolve) {
|
116
|
+
let gen = this.internalResolve(request, defaultResolve);
|
117
|
+
let out = gen.next();
|
118
|
+
while (!out.done) {
|
119
|
+
out = gen.next(out.value);
|
120
|
+
}
|
121
|
+
return out.value;
|
122
|
+
}
|
123
|
+
// Our core implementation is a generator so it can power both resolve() and
|
124
|
+
// resolveSync()
|
125
|
+
*internalResolve(request, defaultResolve) {
|
126
|
+
request = this.beforeResolve(request);
|
127
|
+
let resolution = yield defaultResolve(request);
|
109
128
|
switch (resolution.type) {
|
110
129
|
case 'found':
|
111
130
|
return resolution;
|
@@ -114,30 +133,59 @@ class Resolver {
|
|
114
133
|
default:
|
115
134
|
throw (0, assert_never_1.default)(resolution);
|
116
135
|
}
|
117
|
-
|
118
|
-
let nextRequest = await this.fallbackResolve(request);
|
136
|
+
let nextRequest = this.fallbackResolve(request);
|
119
137
|
if (nextRequest === request) {
|
120
138
|
// no additional fallback is available.
|
121
139
|
return resolution;
|
122
140
|
}
|
123
|
-
if (nextRequest.resolvedTo) {
|
124
|
-
if (typeof nextRequest.resolvedTo === 'function') {
|
125
|
-
return await nextRequest.resolvedTo();
|
126
|
-
}
|
127
|
-
else {
|
128
|
-
return nextRequest.resolvedTo;
|
129
|
-
}
|
130
|
-
}
|
131
141
|
if (nextRequest.fromFile === request.fromFile && nextRequest.specifier === request.specifier) {
|
132
142
|
throw new Error('Bug Discovered! New request is not === original request but has the same fromFile and specifier. This will likely create a loop.');
|
133
143
|
}
|
134
|
-
|
144
|
+
if (nextRequest.isVirtual) {
|
145
|
+
// virtual requests are terminal, there is no more beforeResolve or
|
146
|
+
// fallbackResolve around them. The defaultResolve is expected to know how
|
147
|
+
// to implement them.
|
148
|
+
return yield defaultResolve(nextRequest);
|
149
|
+
}
|
150
|
+
return yield* this.internalResolve(nextRequest, defaultResolve);
|
135
151
|
}
|
136
152
|
// Use standard NodeJS resolving, with our required compatibility rules on
|
137
153
|
// top. This is a convenience method for calling resolveSync with the
|
138
154
|
// defaultResolve already configured to be "do the normal node thing".
|
139
|
-
|
140
|
-
|
155
|
+
nodeResolve(specifier, fromFile) {
|
156
|
+
let resolution = this.resolveSync(new NodeModuleRequest(specifier, fromFile, false, undefined), request => {
|
157
|
+
if (request.isVirtual) {
|
158
|
+
return {
|
159
|
+
type: 'found',
|
160
|
+
result: {
|
161
|
+
type: 'virtual',
|
162
|
+
content: (0, virtual_content_1.virtualContent)(request.specifier, this),
|
163
|
+
filename: request.specifier,
|
164
|
+
},
|
165
|
+
};
|
166
|
+
}
|
167
|
+
try {
|
168
|
+
let filename = resolve_1.default.sync(request.specifier, {
|
169
|
+
basedir: (0, path_1.dirname)(request.fromFile),
|
170
|
+
extensions: this.options.resolvableExtensions,
|
171
|
+
});
|
172
|
+
return { type: 'found', result: { type: 'real', filename } };
|
173
|
+
}
|
174
|
+
catch (err) {
|
175
|
+
if (err.code !== 'MODULE_NOT_FOUND') {
|
176
|
+
throw err;
|
177
|
+
}
|
178
|
+
return { type: 'not_found', err };
|
179
|
+
}
|
180
|
+
});
|
181
|
+
switch (resolution.type) {
|
182
|
+
case 'not_found':
|
183
|
+
return resolution;
|
184
|
+
case 'found':
|
185
|
+
return resolution.result;
|
186
|
+
default:
|
187
|
+
throw (0, assert_never_1.default)(resolution);
|
188
|
+
}
|
141
189
|
}
|
142
190
|
get packageCache() {
|
143
191
|
return shared_internals_2.RewrittenPackageCache.shared('embroider', this.options.appRoot);
|
@@ -154,9 +202,6 @@ class Resolver {
|
|
154
202
|
return owningPackage;
|
155
203
|
}
|
156
204
|
generateFastbootSwitch(request) {
|
157
|
-
if (request.resolvedTo) {
|
158
|
-
return request;
|
159
|
-
}
|
160
205
|
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
161
206
|
if (!pkg) {
|
162
207
|
return request;
|
@@ -174,15 +219,13 @@ class Resolver {
|
|
174
219
|
let fastbootFile = engineConfig.fastbootFiles[candidate];
|
175
220
|
if (fastbootFile) {
|
176
221
|
if (fastbootFile.shadowedFilename) {
|
177
|
-
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)((0, path_1.resolve)(pkg.root, fastbootFile.shadowedFilename), 'utf8'), {
|
178
|
-
configFile: false,
|
179
|
-
});
|
222
|
+
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)((0, path_1.resolve)(pkg.root, fastbootFile.shadowedFilename), 'utf8'), {});
|
180
223
|
let switchFile = (0, virtual_content_1.fastbootSwitch)(candidate, (0, path_1.resolve)(pkg.root, 'package.json'), names);
|
181
224
|
if (switchFile === request.fromFile) {
|
182
225
|
return logTransition('internal lookup from fastbootSwitch', request);
|
183
226
|
}
|
184
227
|
else {
|
185
|
-
return logTransition('shadowed app fastboot', request, request.virtualize(
|
228
|
+
return logTransition('shadowed app fastboot', request, request.virtualize(switchFile));
|
186
229
|
}
|
187
230
|
}
|
188
231
|
else {
|
@@ -195,9 +238,6 @@ class Resolver {
|
|
195
238
|
}
|
196
239
|
handleFastbootSwitch(request) {
|
197
240
|
var _a;
|
198
|
-
if (request.resolvedTo) {
|
199
|
-
return request;
|
200
|
-
}
|
201
241
|
let match = (0, virtual_content_1.decodeFastbootSwitch)(request.fromFile);
|
202
242
|
if (!match) {
|
203
243
|
return request;
|
@@ -236,15 +276,12 @@ class Resolver {
|
|
236
276
|
}
|
237
277
|
let entry = (_a = this.getEntryFromMergeMap(rel, pkg.root)) === null || _a === void 0 ? void 0 : _a.entry;
|
238
278
|
if ((entry === null || entry === void 0 ? void 0 : entry.type) === 'both') {
|
239
|
-
return logTransition('matched addon entry', request, request.alias(entry[section].
|
279
|
+
return logTransition('matched addon entry', request, request.alias(entry[section].localPath).rehome((0, path_1.resolve)(entry[section].packageRoot, 'package.json')));
|
240
280
|
}
|
241
281
|
}
|
242
282
|
return logTransition('failed to match in fastboot switch', request);
|
243
283
|
}
|
244
284
|
handleImplicitModules(request) {
|
245
|
-
if (request.resolvedTo) {
|
246
|
-
return request;
|
247
|
-
}
|
248
285
|
let im = (0, virtual_content_1.decodeImplicitModules)(request.specifier);
|
249
286
|
if (!im) {
|
250
287
|
return request;
|
@@ -256,77 +293,13 @@ class Resolver {
|
|
256
293
|
let packageName = (0, shared_internals_1.packageName)(im.fromFile);
|
257
294
|
if (packageName) {
|
258
295
|
let dep = this.packageCache.resolve(packageName, pkg);
|
259
|
-
return logTransition(`dep's implicit modules`, request, request.virtualize(
|
296
|
+
return logTransition(`dep's implicit modules`, request, request.virtualize((0, path_1.resolve)(dep.root, `-embroider-${im.type}.js`)));
|
260
297
|
}
|
261
298
|
else {
|
262
|
-
return logTransition(`own implicit modules`, request, request.virtualize(
|
263
|
-
}
|
264
|
-
}
|
265
|
-
handleEntrypoint(request) {
|
266
|
-
if (request.resolvedTo) {
|
267
|
-
return request;
|
268
|
-
}
|
269
|
-
let virtualResponse = (0, virtual_entrypoint_1.virtualEntrypoint)(request, this.packageCache);
|
270
|
-
if (virtualResponse) {
|
271
|
-
return logTransition('entrypoint', request, request.virtualize(virtualResponse));
|
272
|
-
}
|
273
|
-
else {
|
274
|
-
return request;
|
275
|
-
}
|
276
|
-
}
|
277
|
-
handleRouteEntrypoint(request) {
|
278
|
-
if (request.resolvedTo) {
|
279
|
-
return request;
|
280
|
-
}
|
281
|
-
let routeName = (0, virtual_route_entrypoint_1.decodePublicRouteEntrypoint)(request.specifier);
|
282
|
-
if (!routeName) {
|
283
|
-
return request;
|
284
|
-
}
|
285
|
-
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
286
|
-
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
|
287
|
-
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
|
288
|
-
}
|
289
|
-
return logTransition('route entrypoint', request, request.virtualize({ type: 'route-entrypoint', specifier: (0, virtual_route_entrypoint_1.encodeRouteEntrypoint)(pkg, routeName) }));
|
290
|
-
}
|
291
|
-
handleImplicitTestScripts(request) {
|
292
|
-
//TODO move the extra forwardslash handling out into the vite plugin
|
293
|
-
const candidates = [
|
294
|
-
'@embroider/virtual/test-support.js',
|
295
|
-
'/@embroider/virtual/test-support.js',
|
296
|
-
'./@embroider/virtual/test-support.js',
|
297
|
-
];
|
298
|
-
if (!candidates.includes(request.specifier)) {
|
299
|
-
return request;
|
299
|
+
return logTransition(`own implicit modules`, request, request.virtualize((0, path_1.resolve)(pkg.root, `-embroider-${im.type}.js`)));
|
300
300
|
}
|
301
|
-
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
302
|
-
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
303
|
-
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/virtual/test-support.js. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
304
|
-
}
|
305
|
-
return logTransition('test-support', request, request.virtualize({ type: 'test-support-js', specifier: (0, path_1.resolve)(pkg.root, '-embroider-test-support.js') }));
|
306
301
|
}
|
307
|
-
|
308
|
-
//TODO move the extra forwardslash handling out into the vite plugin
|
309
|
-
const candidates = [
|
310
|
-
'@embroider/virtual/test-support.css',
|
311
|
-
'/@embroider/virtual/test-support.css',
|
312
|
-
'./@embroider/virtual/test-support.css',
|
313
|
-
];
|
314
|
-
if (!candidates.includes(request.specifier)) {
|
315
|
-
return request;
|
316
|
-
}
|
317
|
-
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
318
|
-
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
319
|
-
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/virtual/test-support.css. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
320
|
-
}
|
321
|
-
return logTransition('test-support-styles', request, request.virtualize({
|
322
|
-
type: 'test-support-css',
|
323
|
-
specifier: (0, path_1.resolve)(pkg.root, '-embroider-test-support-styles.css'),
|
324
|
-
}));
|
325
|
-
}
|
326
|
-
async handleGlobalsCompat(request) {
|
327
|
-
if (request.resolvedTo) {
|
328
|
-
return request;
|
329
|
-
}
|
302
|
+
handleGlobalsCompat(request) {
|
330
303
|
let match = compatPattern.exec(request.specifier);
|
331
304
|
if (!match) {
|
332
305
|
return request;
|
@@ -347,83 +320,62 @@ class Resolver {
|
|
347
320
|
case 'ambiguous':
|
348
321
|
return this.resolveHelperOrComponent(rest, engine, request);
|
349
322
|
default:
|
350
|
-
throw new Error(`bug: unexepected
|
323
|
+
throw new Error(`bug: unexepected #embroider_compat specifier: ${request.specifier}`);
|
351
324
|
}
|
352
325
|
}
|
353
|
-
handleVendorStyles(request) {
|
354
|
-
//TODO move the extra forwardslash handling out into the vite plugin
|
355
|
-
const candidates = [
|
356
|
-
'@embroider/virtual/vendor.css',
|
357
|
-
'/@embroider/virtual/vendor.css',
|
358
|
-
'./@embroider/virtual/vendor.css',
|
359
|
-
];
|
360
|
-
if (!candidates.includes(request.specifier)) {
|
361
|
-
return request;
|
362
|
-
}
|
363
|
-
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
364
|
-
if (!pkg || !this.options.engines.some(e => e.root === (pkg === null || pkg === void 0 ? void 0 : pkg.root))) {
|
365
|
-
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app or Engine. The top-level Ember app is the only one that has support for @embroider/virtual/vendor.css. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
366
|
-
}
|
367
|
-
return logTransition('vendor-styles', request, request.virtualize({ type: 'vendor-css', specifier: (0, path_1.resolve)(pkg.root, '-embroider-vendor-styles.css') }));
|
368
|
-
}
|
369
326
|
resolveHelper(path, inEngine, request) {
|
370
327
|
let target = this.parseGlobalPath(path, inEngine);
|
371
328
|
return logTransition('resolveHelper', request, request.alias(`${target.packageName}/helpers/${target.memberName}`).rehome((0, path_1.resolve)(inEngine.root, 'package.json')));
|
372
329
|
}
|
373
|
-
|
330
|
+
resolveComponent(path, inEngine, request) {
|
374
331
|
let target = this.parseGlobalPath(path, inEngine);
|
375
332
|
let hbsModule = null;
|
376
333
|
let jsModule = null;
|
377
334
|
// first, the various places our template might be.
|
378
335
|
for (let candidate of this.componentTemplateCandidates(target.packageName)) {
|
379
|
-
let
|
380
|
-
|
381
|
-
|
382
|
-
hbsModule = resolution;
|
336
|
+
let resolution = this.nodeResolve(`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`, target.from);
|
337
|
+
if (resolution.type === 'real') {
|
338
|
+
hbsModule = resolution.filename;
|
383
339
|
break;
|
384
340
|
}
|
385
341
|
}
|
386
342
|
// then the various places our javascript might be.
|
387
343
|
for (let candidate of this.componentJSCandidates(target.packageName)) {
|
388
|
-
let
|
389
|
-
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from));
|
344
|
+
let resolution = this.nodeResolve(`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`, target.from);
|
390
345
|
// .hbs is a resolvable extension for us, so we need to exclude it here.
|
391
346
|
// It matches as a priority lower than .js, so finding an .hbs means
|
392
347
|
// there's definitely not a .js.
|
393
|
-
if (resolution.type === '
|
394
|
-
jsModule = resolution;
|
348
|
+
if (resolution.type === 'real' && !resolution.filename.endsWith('.hbs')) {
|
349
|
+
jsModule = resolution.filename;
|
395
350
|
break;
|
396
351
|
}
|
397
352
|
}
|
398
353
|
if (hbsModule) {
|
399
354
|
if (!this.emberVersionSupportsSeparateTemplates) {
|
400
|
-
throw new Error(`Components with separately resolved templates were removed at Ember 6.0. Migrate to either co-located js/ts + hbs files or to gjs/gts. https://deprecations.emberjs.com/id/component-template-resolving/. Bad template was: ${hbsModule
|
355
|
+
throw new Error(`Components with separately resolved templates were removed at Ember 6.0. Migrate to either co-located js/ts + hbs files or to gjs/gts. https://deprecations.emberjs.com/id/component-template-resolving/. Bad template was: ${hbsModule}.`);
|
401
356
|
}
|
402
|
-
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize(
|
403
|
-
type: 'component-pair',
|
404
|
-
specifier: (0, virtual_content_1.virtualPairComponent)(this.options.appRoot, hbsModule.filename, jsModule === null || jsModule === void 0 ? void 0 : jsModule.filename),
|
405
|
-
}));
|
357
|
+
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule, jsModule)));
|
406
358
|
}
|
407
359
|
else if (jsModule) {
|
408
|
-
return logTransition(`
|
360
|
+
return logTransition(`resolveComponent found only JS`, request, request.alias(jsModule).rehome(target.from));
|
409
361
|
}
|
410
362
|
else {
|
411
363
|
return logTransition(`resolveComponent failed`, request);
|
412
364
|
}
|
413
365
|
}
|
414
|
-
|
366
|
+
resolveHelperOrComponent(path, inEngine, request) {
|
415
367
|
// resolveHelper just rewrites our request to one that should target the
|
416
368
|
// component, so here to resolve the ambiguity we need to actually resolve
|
417
369
|
// that candidate to see if it works.
|
418
370
|
let helperCandidate = this.resolveHelper(path, inEngine, request);
|
419
|
-
let helperMatch =
|
420
|
-
if (helperMatch.type === '
|
421
|
-
return logTransition('
|
371
|
+
let helperMatch = this.nodeResolve(helperCandidate.specifier, helperCandidate.fromFile);
|
372
|
+
if (helperMatch.type === 'real') {
|
373
|
+
return logTransition('ambiguous case matched a helper', request, helperCandidate);
|
422
374
|
}
|
423
375
|
// unlike resolveHelper, resolveComponent already does pre-resolution in
|
424
376
|
// order to deal with its own internal ambiguity around JS vs HBS vs
|
425
377
|
// colocation.≥
|
426
|
-
let componentMatch =
|
378
|
+
let componentMatch = this.resolveComponent(path, inEngine, request);
|
427
379
|
if (componentMatch !== request) {
|
428
380
|
return logTransition('ambiguous case matched a cmoponent', request, componentMatch);
|
429
381
|
}
|
@@ -448,7 +400,6 @@ class Resolver {
|
|
448
400
|
}
|
449
401
|
*componentJSCandidates(inPackageName) {
|
450
402
|
yield { prefix: '/components/', suffix: '' };
|
451
|
-
yield { prefix: '/components/', suffix: '/index' };
|
452
403
|
yield { prefix: '/components/', suffix: '/component' };
|
453
404
|
let pods = this.podPrefix(inPackageName);
|
454
405
|
if (pods) {
|
@@ -467,10 +418,10 @@ class Resolver {
|
|
467
418
|
parseGlobalPath(path, inEngine) {
|
468
419
|
let parts = path.split('@');
|
469
420
|
if (parts.length > 1 && parts[0].length > 0) {
|
470
|
-
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, '
|
421
|
+
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') };
|
471
422
|
}
|
472
423
|
else {
|
473
|
-
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, '
|
424
|
+
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') };
|
474
425
|
}
|
475
426
|
}
|
476
427
|
engineConfig(packageName) {
|
@@ -496,18 +447,14 @@ class Resolver {
|
|
496
447
|
if (!inAddonName.startsWith('./')) {
|
497
448
|
throw new Error(`addon ${addon.name} declares app-js in its package.json with the illegal name "${inAddonName}". It must start with "./" to make it clear that it's relative to the addon`);
|
498
449
|
}
|
499
|
-
let specifier = (0, reverse_exports_1.externalName)(addon.packageJSON, inAddonName);
|
500
|
-
if (!specifier) {
|
501
|
-
throw new Error(`${addon.name}'s package.json app-js refers to ${inAddonName}, but that module is not accessible from outside the package`);
|
502
|
-
}
|
503
450
|
let prevEntry = engineModules.get(inEngineName);
|
504
451
|
switch (prevEntry === null || prevEntry === void 0 ? void 0 : prevEntry.type) {
|
505
452
|
case undefined:
|
506
453
|
engineModules.set(inEngineName, {
|
507
454
|
type: 'app-only',
|
508
455
|
'app-js': {
|
509
|
-
|
510
|
-
|
456
|
+
localPath: inAddonName,
|
457
|
+
packageRoot: addon.root,
|
511
458
|
fromPackageName: addon.name,
|
512
459
|
},
|
513
460
|
});
|
@@ -520,8 +467,8 @@ class Resolver {
|
|
520
467
|
engineModules.set(inEngineName, {
|
521
468
|
type: 'both',
|
522
469
|
'app-js': {
|
523
|
-
|
524
|
-
|
470
|
+
localPath: inAddonName,
|
471
|
+
packageRoot: addon.root,
|
525
472
|
fromPackageName: addon.name,
|
526
473
|
},
|
527
474
|
'fastboot-js': prevEntry['fastboot-js'],
|
@@ -539,18 +486,14 @@ class Resolver {
|
|
539
486
|
if (!inAddonName.startsWith('./')) {
|
540
487
|
throw new Error(`addon ${addon.name} declares fastboot-js in its package.json with the illegal name "${inAddonName}". It must start with "./" to make it clear that it's relative to the addon`);
|
541
488
|
}
|
542
|
-
let specifier = (0, reverse_exports_1.externalName)(addon.packageJSON, inAddonName);
|
543
|
-
if (!specifier) {
|
544
|
-
throw new Error(`${addon.name}'s package.json fastboot-js refers to ${inAddonName}, but that module is not accessible from outside the package`);
|
545
|
-
}
|
546
489
|
let prevEntry = engineModules.get(inEngineName);
|
547
490
|
switch (prevEntry === null || prevEntry === void 0 ? void 0 : prevEntry.type) {
|
548
491
|
case undefined:
|
549
492
|
engineModules.set(inEngineName, {
|
550
493
|
type: 'fastboot-only',
|
551
494
|
'fastboot-js': {
|
552
|
-
|
553
|
-
|
495
|
+
localPath: inAddonName,
|
496
|
+
packageRoot: addon.root,
|
554
497
|
fromPackageName: addon.name,
|
555
498
|
},
|
556
499
|
});
|
@@ -563,8 +506,8 @@ class Resolver {
|
|
563
506
|
engineModules.set(inEngineName, {
|
564
507
|
type: 'both',
|
565
508
|
'fastboot-js': {
|
566
|
-
|
567
|
-
|
509
|
+
localPath: inAddonName,
|
510
|
+
packageRoot: addon.root,
|
568
511
|
fromPackageName: addon.name,
|
569
512
|
},
|
570
513
|
'app-js': prevEntry['app-js'],
|
@@ -595,7 +538,7 @@ class Resolver {
|
|
595
538
|
});
|
596
539
|
}
|
597
540
|
handleRewrittenPackages(request) {
|
598
|
-
if (request.
|
541
|
+
if (request.isVirtual) {
|
599
542
|
return request;
|
600
543
|
}
|
601
544
|
let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
@@ -614,6 +557,10 @@ class Resolver {
|
|
614
557
|
targetPkg = this.packageCache.resolve(packageName, requestingPkg);
|
615
558
|
}
|
616
559
|
catch (err) {
|
560
|
+
// this is not the place to report resolution failures. If the thing
|
561
|
+
// doesn't resolve, we're just not interested in redirecting it for
|
562
|
+
// backward-compat, that's all. The rest of the system will take care of
|
563
|
+
// reporting a failure to resolve (or handling it a different way)
|
617
564
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
618
565
|
throw err;
|
619
566
|
}
|
@@ -629,26 +576,14 @@ class Resolver {
|
|
629
576
|
return logTransition('request targets a moved package', request, this.resolveWithinMovedPackage(request, targetPkg));
|
630
577
|
}
|
631
578
|
else if (originalRequestingPkg !== requestingPkg) {
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
return logTransition('outbound request from moved package', request, request
|
636
|
-
// setting meta here because if this fails, we want the fallback
|
637
|
-
// logic to revert our rehome and continue from the *moved* package.
|
638
|
-
.withMeta({ originalFromFile: request.fromFile })
|
639
|
-
.rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
|
640
|
-
}
|
641
|
-
else {
|
642
|
-
// requesting package was moved and we failed to find its target. We
|
643
|
-
// can't let that accidentally succeed in the defaultResolve because we
|
644
|
-
// could escape the moved package system.
|
645
|
-
return logTransition('missing outbound request from moved package', request, request.notFound());
|
646
|
-
}
|
579
|
+
// in this case, the requesting package is moved but its destination is
|
580
|
+
// not, so we need to rehome the request back to the original location.
|
581
|
+
return logTransition('outbound request from moved package', request, request.withMeta({ wasMovedTo: request.fromFile }).rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
|
647
582
|
}
|
648
583
|
return request;
|
649
584
|
}
|
650
585
|
handleRenaming(request) {
|
651
|
-
if (request.
|
586
|
+
if (request.isVirtual) {
|
652
587
|
return request;
|
653
588
|
}
|
654
589
|
let packageName = (0, shared_internals_1.packageName)(request.specifier);
|
@@ -656,11 +591,14 @@ class Resolver {
|
|
656
591
|
return request;
|
657
592
|
}
|
658
593
|
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
594
|
+
if (!pkg || !pkg.isV2Ember()) {
|
595
|
+
return request;
|
596
|
+
}
|
659
597
|
// real deps take precedence over renaming rules. That is, a package like
|
660
598
|
// ember-source might provide backburner via module renaming, but if you
|
661
599
|
// have an explicit dependency on backburner you should still get that real
|
662
600
|
// copy.
|
663
|
-
if (!
|
601
|
+
if (!pkg.hasDependency(packageName)) {
|
664
602
|
for (let [candidate, replacement] of Object.entries(this.options.renameModules)) {
|
665
603
|
if (candidate === request.specifier) {
|
666
604
|
return logTransition(`renameModules`, request, request.alias(replacement));
|
@@ -678,79 +616,30 @@ class Resolver {
|
|
678
616
|
return logTransition(`renamePackages`, request, request.alias(request.specifier.replace(packageName, this.options.renamePackages[packageName])));
|
679
617
|
}
|
680
618
|
}
|
681
|
-
if (
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
//
|
686
|
-
|
687
|
-
// auto-upgraded packages always get automatically adjusted. They never
|
688
|
-
// supported fancy package.json exports features so this direct mapping
|
689
|
-
// to the root is always right.
|
690
|
-
// "my-app/foo" -> "./foo" from app's package.json
|
691
|
-
// "my-addon/foo" -> "my-addon/foo" from a package that's guaranteed to be able to resolve my-addon
|
692
|
-
let owningEngine = this.owningEngine(pkg);
|
693
|
-
let addonConfig = owningEngine.activeAddons.find(a => a.root === pkg.root);
|
694
|
-
if (addonConfig) {
|
695
|
-
// auto-upgraded addons get special support for self-resolving here.
|
696
|
-
return logTransition(`v1 addon self-import`, request, request.rehome(addonConfig.canResolveFromFile));
|
697
|
-
}
|
698
|
-
else {
|
699
|
-
// auto-upgraded apps will necessarily have packageJSON.exports
|
700
|
-
// because we insert them, so for that support we can fall through to
|
701
|
-
// that support below.
|
702
|
-
}
|
703
|
-
}
|
704
|
-
// v2 packages are supposed to use package.json `exports` to enable
|
705
|
-
// self-imports, but not all build tools actually follow the spec. This
|
706
|
-
// is a workaround for badly behaved packagers.
|
707
|
-
//
|
708
|
-
// Known upstream bugs this works around:
|
709
|
-
// - https://github.com/vitejs/vite/issues/9731
|
710
|
-
if (pkg.packageJSON.exports) {
|
711
|
-
let found = (0, resolve_exports_1.exports)(pkg.packageJSON, request.specifier, {
|
712
|
-
browser: true,
|
713
|
-
conditions: ['default', 'imports'],
|
714
|
-
});
|
715
|
-
if (found === null || found === void 0 ? void 0 : found[0]) {
|
716
|
-
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')));
|
717
|
-
}
|
718
|
-
}
|
619
|
+
if (pkg.meta['auto-upgraded'] && pkg.name === packageName) {
|
620
|
+
// we found a self-import, resolve it for them. Only auto-upgraded
|
621
|
+
// packages get this help, v2 packages are natively supposed to make their
|
622
|
+
// own modules resolvable, and we want to push them all to do that
|
623
|
+
// correctly.
|
624
|
+
return logTransition(`v1 self-import`, request, request.alias(request.specifier.replace(pkg.name, '.')).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
|
719
625
|
}
|
720
626
|
return request;
|
721
627
|
}
|
722
|
-
handleVendor(request) {
|
723
|
-
//TODO move the extra forwardslash handling out into the vite plugin
|
724
|
-
const candidates = [
|
725
|
-
'@embroider/virtual/vendor.js',
|
726
|
-
'/@embroider/virtual/vendor.js',
|
727
|
-
'./@embroider/virtual/vendor.js',
|
728
|
-
];
|
729
|
-
if (!candidates.includes(request.specifier)) {
|
730
|
-
return request;
|
731
|
-
}
|
732
|
-
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
733
|
-
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
734
|
-
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/virtual/vendor.js. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`);
|
735
|
-
}
|
736
|
-
return logTransition('vendor', request, request.virtualize({ type: 'vendor-js', specifier: (0, path_1.resolve)(pkg.root, '-embroider-vendor.js') }));
|
737
|
-
}
|
738
628
|
resolveWithinMovedPackage(request, pkg) {
|
739
629
|
let levels = ['..'];
|
740
630
|
if (pkg.name.startsWith('@')) {
|
741
631
|
levels.push('..');
|
742
632
|
}
|
743
|
-
let originalFromFile = request.fromFile;
|
744
633
|
let newRequest = request.rehome((0, path_1.resolve)(pkg.root, ...levels, 'moved-package-target.js'));
|
745
634
|
if (newRequest === request) {
|
746
635
|
return request;
|
747
636
|
}
|
748
|
-
|
749
|
-
|
750
|
-
|
637
|
+
return newRequest.withMeta({
|
638
|
+
resolvedWithinPackage: pkg.root,
|
639
|
+
});
|
751
640
|
}
|
752
641
|
preHandleExternal(request) {
|
753
|
-
if (request.
|
642
|
+
if (request.isVirtual) {
|
754
643
|
return request;
|
755
644
|
}
|
756
645
|
let { specifier, fromFile } = request;
|
@@ -760,6 +649,11 @@ class Resolver {
|
|
760
649
|
}
|
761
650
|
let packageName = (0, shared_internals_1.packageName)(specifier);
|
762
651
|
if (!packageName) {
|
652
|
+
// This is a relative import. We don't automatically externalize those
|
653
|
+
// because it's rare, and by keeping them static we give better errors. But
|
654
|
+
// we do allow them to be explicitly externalized by the package author (or
|
655
|
+
// a compat adapter). In the metadata, they would be listed in
|
656
|
+
// package-relative form, so we need to convert this specifier to that.
|
763
657
|
let absoluteSpecifier = (0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier);
|
764
658
|
if (!absoluteSpecifier.startsWith(pkg.root)) {
|
765
659
|
// this relative path escape its package. So it's not really using
|
@@ -768,23 +662,36 @@ class Resolver {
|
|
768
662
|
// references to runtime utilities, like we do in @embroider/macros.
|
769
663
|
return logTransition('beforeResolve: relative path escapes its package', request);
|
770
664
|
}
|
665
|
+
let packageRelativeSpecifier = (0, shared_internals_2.explicitRelative)(pkg.root, absoluteSpecifier);
|
666
|
+
if (isExplicitlyExternal(packageRelativeSpecifier, pkg)) {
|
667
|
+
let publicSpecifier = absoluteSpecifier.replace(pkg.root, pkg.name);
|
668
|
+
return this.external('beforeResolve', request, publicSpecifier);
|
669
|
+
}
|
771
670
|
// if the requesting file is in an addon's app-js, the relative request
|
772
671
|
// should really be understood as a request for a module in the containing
|
773
|
-
// engine
|
672
|
+
// engine
|
774
673
|
let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
|
775
674
|
if (logicalLocation) {
|
776
|
-
return logTransition('beforeResolve: relative import in app-js', request, request.
|
675
|
+
return logTransition('beforeResolve: relative import in app-js', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
|
777
676
|
}
|
778
677
|
return request;
|
779
678
|
}
|
679
|
+
// absolute package imports can also be explicitly external based on their
|
680
|
+
// full specifier name
|
681
|
+
if (isExplicitlyExternal(specifier, pkg)) {
|
682
|
+
return this.external('beforeResolve', request, specifier);
|
683
|
+
}
|
684
|
+
if (shared_internals_1.emberVirtualPackages.has(packageName) && !pkg.hasDependency(packageName)) {
|
685
|
+
return this.external('beforeResolve emberVirtualPackages', request, specifier);
|
686
|
+
}
|
780
687
|
if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
|
781
688
|
// addons (whether auto-upgraded or not) may use the app's
|
782
689
|
// emberVirtualPeerDeps, like "@glimmer/component" etc.
|
783
|
-
|
784
|
-
|
785
|
-
throw new Error(`${pkg.name} is trying to import the emberVirtualPeerDep "${packageName}", but it seems to be missing`);
|
690
|
+
if (!this.options.activeAddons[packageName]) {
|
691
|
+
throw new Error(`${pkg.name} is trying to import the app's ${packageName} package, but it seems to be missing`);
|
786
692
|
}
|
787
|
-
|
693
|
+
let newHome = (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json');
|
694
|
+
return logTransition(`emberVirtualPeerDeps in v2 addon`, request, request.rehome(newHome));
|
788
695
|
}
|
789
696
|
// if this file is part of an addon's app-js, it's really the logical
|
790
697
|
// package to which it belongs (normally the app) that affects some policy
|
@@ -793,10 +700,10 @@ class Resolver {
|
|
793
700
|
if (logicalPackage.meta['auto-upgraded'] && !logicalPackage.hasDependency('ember-auto-import')) {
|
794
701
|
try {
|
795
702
|
let dep = this.packageCache.resolve(packageName, logicalPackage);
|
796
|
-
if (!dep.
|
703
|
+
if (!dep.isEmberPackage()) {
|
797
704
|
// classic ember addons can only import non-ember dependencies if they
|
798
705
|
// have ember-auto-import.
|
799
|
-
return
|
706
|
+
return this.external('v1 package without auto-import', request, specifier);
|
800
707
|
}
|
801
708
|
}
|
802
709
|
catch (err) {
|
@@ -806,33 +713,49 @@ class Resolver {
|
|
806
713
|
}
|
807
714
|
}
|
808
715
|
// assertions on what native v2 addons can import
|
809
|
-
if (!pkg.
|
810
|
-
!
|
811
|
-
|
812
|
-
|
716
|
+
if (!pkg.meta['auto-upgraded']) {
|
717
|
+
if (!pkg.meta['auto-upgraded'] &&
|
718
|
+
!appImportInAppTree(pkg, logicalPackage, packageName) &&
|
719
|
+
!reliablyResolvable(pkg, packageName)) {
|
720
|
+
throw new Error(`${pkg.name} is trying to import from ${packageName} but that is not one of its explicit dependencies`);
|
721
|
+
}
|
813
722
|
}
|
814
723
|
return request;
|
815
724
|
}
|
816
|
-
|
817
|
-
if (
|
818
|
-
|
819
|
-
return
|
820
|
-
|
821
|
-
|
822
|
-
|
725
|
+
external(label, request, specifier) {
|
726
|
+
if (this.options.amdCompatibility === 'cjs') {
|
727
|
+
let filename = (0, virtual_content_1.virtualExternalCJSModule)(specifier);
|
728
|
+
return logTransition(label, request, request.virtualize(filename));
|
729
|
+
}
|
730
|
+
else if (this.options.amdCompatibility) {
|
731
|
+
let entry = this.options.amdCompatibility.es.find(entry => entry[0] === specifier || entry[0] + '/index' === specifier);
|
732
|
+
if (!entry && request.specifier === 'require') {
|
733
|
+
entry = ['require', ['default', 'has']];
|
734
|
+
}
|
735
|
+
if (!entry) {
|
736
|
+
throw new Error(`A module tried to resolve "${request.specifier}" and didn't find it (${label}).
|
737
|
+
|
738
|
+
- Maybe a dependency declaration is missing?
|
739
|
+
- Remember that v1 addons can only import non-Ember-addon NPM dependencies if they include ember-auto-import in their dependencies.
|
740
|
+
- If this dependency is available in the AMD loader (because someone manually called "define()" for it), you can configure a shim like:
|
741
|
+
|
742
|
+
amdCompatibility: {
|
743
|
+
es: [
|
744
|
+
["${request.specifier}", ["default", "yourNamedExportsGoHere"]],
|
745
|
+
]
|
746
|
+
}
|
747
|
+
|
748
|
+
`);
|
749
|
+
}
|
750
|
+
let filename = (0, virtual_content_1.virtualExternalESModule)(specifier, entry[1]);
|
751
|
+
return logTransition(label, request, request.virtualize(filename));
|
823
752
|
}
|
824
|
-
|
825
|
-
|
826
|
-
if (addon.name === packageName) {
|
827
|
-
return addon;
|
828
|
-
}
|
829
|
-
}
|
753
|
+
else {
|
754
|
+
throw new Error(`Embroider's amdCompatibility option is disabled, but something tried to use it to access "${request.specifier}"`);
|
830
755
|
}
|
831
756
|
}
|
832
|
-
|
833
|
-
|
834
|
-
throw new Error('Build tool bug detected! Fallback resolve should never see an already-resolved request.');
|
835
|
-
}
|
757
|
+
fallbackResolve(request) {
|
758
|
+
var _a, _b, _c;
|
836
759
|
if (request.specifier === '@embroider/macros') {
|
837
760
|
// the macros package is always handled directly within babel (not
|
838
761
|
// necessarily as a real resolvable package), so we should not mess with it.
|
@@ -840,124 +763,108 @@ class Resolver {
|
|
840
763
|
// why we need to know about it.
|
841
764
|
return logTransition('fallback early exit', request);
|
842
765
|
}
|
843
|
-
|
766
|
+
let { specifier, fromFile } = request;
|
767
|
+
if (compatPattern.test(specifier)) {
|
844
768
|
// Some kinds of compat requests get rewritten into other things
|
845
|
-
// deterministically. For example, "
|
769
|
+
// deterministically. For example, "#embroider_compat/helpers/whatever"
|
846
770
|
// means only "the-current-engine/helpers/whatever", and if that doesn't
|
847
771
|
// actually exist it's that path that will show up as a missing import.
|
848
772
|
//
|
849
773
|
// But others have an ambiguous meaning. For example,
|
850
|
-
//
|
774
|
+
// #embroider_compat/components/whatever can mean several different
|
851
775
|
// things. If we're unable to find any of them, the actual
|
852
|
-
// "
|
776
|
+
// "#embroider_compat" request will fall through all the way to here.
|
853
777
|
//
|
854
778
|
// In that case, we don't want to externalize that failure. We know it's
|
855
779
|
// not a classic runtime thing. It's better to let it be a build error
|
856
780
|
// here.
|
857
781
|
return request;
|
858
782
|
}
|
859
|
-
|
860
|
-
|
861
|
-
|
783
|
+
if (fromFile.endsWith('moved-package-target.js')) {
|
784
|
+
if (!((_a = request.meta) === null || _a === void 0 ? void 0 : _a.resolvedWithinPackage)) {
|
785
|
+
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
786
|
+
}
|
787
|
+
fromFile = (0, path_1.resolve)((_b = request.meta) === null || _b === void 0 ? void 0 : _b.resolvedWithinPackage, 'package.json');
|
862
788
|
}
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
if (
|
874
|
-
|
789
|
+
let pkg = this.packageCache.ownerOfFile(fromFile);
|
790
|
+
if (!pkg) {
|
791
|
+
return logTransition('no identifiable owningPackage', request);
|
792
|
+
}
|
793
|
+
// if we rehomed this request to its un-rewritten location in order to try
|
794
|
+
// to do the defaultResolve from there, now we refer back to the rewritten
|
795
|
+
// location because that's what we want to use when asking things like
|
796
|
+
// isV2Ember()
|
797
|
+
let movedPkg = this.packageCache.maybeMoved(pkg);
|
798
|
+
if (movedPkg !== pkg) {
|
799
|
+
if (!((_c = request.meta) === null || _c === void 0 ? void 0 : _c.wasMovedTo)) {
|
800
|
+
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
875
801
|
}
|
876
|
-
|
802
|
+
fromFile = request.meta.wasMovedTo;
|
803
|
+
pkg = movedPkg;
|
877
804
|
}
|
878
|
-
|
805
|
+
if (!pkg.isV2Ember()) {
|
806
|
+
return logTransition('fallbackResolve: not in an ember package', request);
|
807
|
+
}
|
808
|
+
let packageName = (0, shared_internals_1.packageName)(specifier);
|
879
809
|
if (!packageName) {
|
880
810
|
// this is a relative import
|
881
|
-
|
811
|
+
let withinEngine = this.engineConfig(pkg.name);
|
812
|
+
if (withinEngine) {
|
813
|
+
// it's a relative import inside an engine (which also means app), which
|
814
|
+
// means we may need to satisfy the request via app tree merging.
|
815
|
+
let appJSMatch = this.searchAppTree(request, withinEngine, (0, shared_internals_2.explicitRelative)(pkg.root, (0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier)));
|
816
|
+
if (appJSMatch) {
|
817
|
+
return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
|
818
|
+
}
|
819
|
+
else {
|
820
|
+
return logTransition('fallbackResolve: relative appJs search failure', request);
|
821
|
+
}
|
822
|
+
}
|
823
|
+
else {
|
824
|
+
// nothing else to do for relative imports
|
825
|
+
return logTransition('fallbackResolve: relative failure', request);
|
826
|
+
}
|
882
827
|
}
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
828
|
+
// auto-upgraded packages can fall back to the set of known active addons
|
829
|
+
if (pkg.meta['auto-upgraded'] && this.options.activeAddons[packageName]) {
|
830
|
+
const rehomed = this.resolveWithinMovedPackage(request, this.packageCache.get(this.options.activeAddons[packageName]));
|
831
|
+
if (rehomed !== request) {
|
832
|
+
return logTransition(`activeAddons`, request, rehomed);
|
887
833
|
}
|
888
834
|
}
|
889
|
-
let logicalLocation = this.reverseSearchAppTree(pkg,
|
835
|
+
let logicalLocation = this.reverseSearchAppTree(pkg, fromFile);
|
890
836
|
if (logicalLocation) {
|
891
837
|
// the requesting file is in an addon's appTree. We didn't succeed in
|
892
838
|
// resolving this (non-relative) request from inside the actual addon, so
|
893
839
|
// next try to resolve it from the corresponding logical location in the
|
894
840
|
// app.
|
895
|
-
return logTransition('fallbackResolve: retry from logical home of app-js file', request,
|
896
|
-
// it might look more precise to rehome into logicalLocation.inAppName
|
897
|
-
// rather than package.json. But that logical location may not actually
|
898
|
-
// exist, and some systems (including node's require.resolve) will be
|
899
|
-
// mad about trying to resolve from notional paths that don't really
|
900
|
-
// exist.
|
901
|
-
request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
|
841
|
+
return logTransition('fallbackResolve: retry from logical home of app-js file', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
|
902
842
|
}
|
903
843
|
let targetingEngine = this.engineConfig(packageName);
|
904
844
|
if (targetingEngine) {
|
905
|
-
let appJSMatch =
|
845
|
+
let appJSMatch = this.searchAppTree(request, targetingEngine, specifier.replace(packageName, '.'));
|
906
846
|
if (appJSMatch) {
|
907
847
|
return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
|
908
848
|
}
|
909
849
|
}
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
// meta.originalFromFile gets set when we want to try to rehome a request
|
917
|
-
// but then come back to the original location here in the fallback when the
|
918
|
-
// rehomed request fails
|
919
|
-
let movedPkg = this.packageCache.maybeMoved(pkg);
|
920
|
-
if (movedPkg !== pkg) {
|
921
|
-
let originalFromFile = (_a = request.meta) === null || _a === void 0 ? void 0 : _a.originalFromFile;
|
922
|
-
if (typeof originalFromFile !== 'string') {
|
923
|
-
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
924
|
-
}
|
925
|
-
request = request.rehome(originalFromFile);
|
926
|
-
pkg = movedPkg;
|
927
|
-
}
|
928
|
-
return { pkg, request };
|
929
|
-
}
|
930
|
-
async relativeFallbackResolve(pkg, request) {
|
931
|
-
let withinEngine = this.engineConfig(pkg.name);
|
932
|
-
if (withinEngine) {
|
933
|
-
// it's a relative import inside an engine (which also means app), which
|
934
|
-
// means we may need to satisfy the request via app tree merging.
|
935
|
-
let logicalName = engineRelativeName(pkg, (0, path_1.resolve)((0, path_1.dirname)(request.fromFile), request.specifier));
|
936
|
-
if (!logicalName) {
|
937
|
-
return logTransition('fallbackResolve: relative failure because this file is not externally accessible', request);
|
938
|
-
}
|
939
|
-
let appJSMatch = await this.searchAppTree(request, withinEngine, logicalName);
|
940
|
-
if (appJSMatch) {
|
941
|
-
return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
|
942
|
-
}
|
943
|
-
else {
|
944
|
-
return logTransition('fallbackResolve: relative appJs search failure', request);
|
945
|
-
}
|
850
|
+
if (pkg.meta['auto-upgraded']) {
|
851
|
+
// auto-upgraded packages can fall back to attempting to find dependencies at
|
852
|
+
// runtime. Native v2 packages can only get this behavior in the
|
853
|
+
// isExplicitlyExternal case above because they need to explicitly ask for
|
854
|
+
// externals.
|
855
|
+
return this.external('v1 catch-all fallback', request, specifier);
|
946
856
|
}
|
947
857
|
else {
|
948
|
-
//
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
// auto-upgraded packages can fall back to the set of known active addons
|
954
|
-
let addon = this.locateActiveAddon(requestedPackageName);
|
955
|
-
if (addon) {
|
956
|
-
const rehomed = request.rehome(addon.canResolveFromFile);
|
957
|
-
if (rehomed !== request) {
|
958
|
-
return logTransition(`activeAddons`, request, rehomed);
|
858
|
+
// native v2 packages don't automatically externalize *everything* the way
|
859
|
+
// auto-upgraded packages do, but they still externalize known and approved
|
860
|
+
// ember virtual packages (like @ember/component)
|
861
|
+
if (shared_internals_1.emberVirtualPackages.has(packageName)) {
|
862
|
+
return this.external('emberVirtualPackages', request, specifier);
|
959
863
|
}
|
960
864
|
}
|
865
|
+
// this is falling through with the original specifier which was
|
866
|
+
// non-resolvable, which will presumably cause a static build error in stage3.
|
867
|
+
return logTransition('fallbackResolve final exit', request);
|
961
868
|
}
|
962
869
|
getEntryFromMergeMap(inEngineSpecifier, root) {
|
963
870
|
var _a;
|
@@ -979,25 +886,26 @@ class Resolver {
|
|
979
886
|
}
|
980
887
|
}
|
981
888
|
}
|
982
|
-
|
889
|
+
searchAppTree(request, engine, inEngineSpecifier) {
|
983
890
|
let matched = this.getEntryFromMergeMap(inEngineSpecifier, engine.root);
|
984
891
|
switch (matched === null || matched === void 0 ? void 0 : matched.entry.type) {
|
985
892
|
case undefined:
|
986
893
|
return undefined;
|
987
894
|
case 'app-only':
|
988
|
-
return request
|
895
|
+
return request
|
896
|
+
.alias(matched.entry['app-js'].localPath)
|
897
|
+
.rehome((0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
|
989
898
|
case 'fastboot-only':
|
990
|
-
return request
|
899
|
+
return request
|
900
|
+
.alias(matched.entry['fastboot-js'].localPath)
|
901
|
+
.rehome((0, path_1.resolve)(matched.entry['fastboot-js'].packageRoot, 'package.json'));
|
991
902
|
case 'both':
|
992
|
-
let foundAppJS =
|
993
|
-
if (foundAppJS.type !== '
|
903
|
+
let foundAppJS = this.nodeResolve(matched.entry['app-js'].localPath, (0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
|
904
|
+
if (foundAppJS.type !== 'real') {
|
994
905
|
throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`);
|
995
906
|
}
|
996
|
-
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), {
|
997
|
-
return request.virtualize(
|
998
|
-
type: 'fastboot-switch',
|
999
|
-
specifier: (0, virtual_content_1.fastbootSwitch)(matched.matched, (0, path_1.resolve)(engine.root, 'package.json'), names),
|
1000
|
-
});
|
907
|
+
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), {});
|
908
|
+
return request.virtualize((0, virtual_content_1.fastbootSwitch)(matched.matched, (0, path_1.resolve)(engine.root, 'package.json'), names));
|
1001
909
|
}
|
1002
910
|
}
|
1003
911
|
// check whether the given file with the given owningPackage is an addon's
|
@@ -1031,10 +939,14 @@ class Resolver {
|
|
1031
939
|
if (engineConfig) {
|
1032
940
|
// we're directly inside an engine, so we're potentially resolvable as a
|
1033
941
|
// global component
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
942
|
+
// this kind of mapping is not true in general for all packages, but it
|
943
|
+
// *is* true for all classical engines (which includes apps) since they
|
944
|
+
// don't support package.json `exports`. As for a future v2 engine or app:
|
945
|
+
// this whole method is only relevant for implementing packageRules, which
|
946
|
+
// should only be for classic stuff. v2 packages should do the right
|
947
|
+
// things from the beginning and not need packageRules about themselves.
|
948
|
+
let inAppName = (0, shared_internals_2.explicitRelative)(engineConfig.root, filename);
|
949
|
+
return this.tryReverseComponent(engineConfig.packageName, inAppName);
|
1038
950
|
}
|
1039
951
|
let engineInfo = this.reverseSearchAppTree(owningPackage, filename);
|
1040
952
|
if (engineInfo) {
|
@@ -1061,6 +973,9 @@ __decorate([
|
|
1061
973
|
__decorate([
|
1062
974
|
(0, typescript_memoize_1.Memoize)()
|
1063
975
|
], Resolver.prototype, "emberVersionSupportsSeparateTemplates", null);
|
976
|
+
function isExplicitlyExternal(specifier, fromPkg) {
|
977
|
+
return Boolean(fromPkg.isV2Addon() && fromPkg.meta['externals'] && fromPkg.meta['externals'].includes(specifier));
|
978
|
+
}
|
1064
979
|
// we don't want to allow things that resolve only by accident that are likely
|
1065
980
|
// to break in other setups. For example: import your dependencies'
|
1066
981
|
// dependencies, or importing your own name from within a monorepo (which will
|
@@ -1082,10 +997,4 @@ function reliablyResolvable(pkg, packageName) {
|
|
1082
997
|
function appImportInAppTree(inPackage, inLogicalPackage, importedPackageName) {
|
1083
998
|
return inPackage !== inLogicalPackage && importedPackageName === inLogicalPackage.name;
|
1084
999
|
}
|
1085
|
-
function engineRelativeName(pkg, filename) {
|
1086
|
-
let outsideName = (0, reverse_exports_1.externalName)(pkg.packageJSON, (0, shared_internals_2.explicitRelative)(pkg.root, filename));
|
1087
|
-
if (outsideName) {
|
1088
|
-
return '.' + outsideName.slice(pkg.name.length);
|
1089
|
-
}
|
1090
|
-
}
|
1091
1000
|
//# sourceMappingURL=module-resolver.js.map
|