@embroider/core 3.4.19 → 3.4.20-unstable.0552afa
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 +19 -9
- package/src/app-files.d.ts +3 -5
- package/src/app-files.js +25 -8
- package/src/app-files.js.map +1 -1
- package/src/index.d.ts +3 -3
- package/src/index.js +3 -3
- package/src/index.js.map +1 -1
- package/src/measure-concat.js +1 -2
- package/src/measure-concat.js.map +1 -1
- package/src/module-request.d.ts +45 -0
- package/src/module-request.js +91 -0
- package/src/module-request.js.map +1 -0
- package/src/module-resolver-options.d.ts +42 -0
- package/src/module-resolver-options.js +164 -0
- package/src/module-resolver-options.js.map +1 -0
- package/src/module-resolver.d.ts +17 -60
- package/src/module-resolver.js +432 -307
- package/src/module-resolver.js.map +1 -1
- package/src/node-resolve.d.ts +29 -0
- package/src/node-resolve.js +114 -0
- package/src/node-resolve.js.map +1 -0
- package/src/options.d.ts +0 -7
- package/src/options.js +0 -1
- package/src/options.js.map +1 -1
- package/src/resolver-loader.js +8 -1
- package/src/resolver-loader.js.map +1 -1
- package/src/virtual-content.d.ts +6 -4
- package/src/virtual-content.js +67 -99
- package/src/virtual-content.js.map +1 -1
- package/src/virtual-entrypoint.d.ts +19 -0
- package/src/virtual-entrypoint.js +289 -0
- package/src/virtual-entrypoint.js.map +1 -0
- package/src/virtual-route-entrypoint.d.ts +15 -0
- package/src/virtual-route-entrypoint.js +94 -0
- package/src/virtual-route-entrypoint.js.map +1 -0
- package/src/virtual-test-support-styles.d.ts +4 -0
- package/src/virtual-test-support-styles.js +64 -0
- package/src/virtual-test-support-styles.js.map +1 -0
- package/src/virtual-test-support.d.ts +4 -0
- package/src/virtual-test-support.js +68 -0
- package/src/virtual-test-support.js.map +1 -0
- package/src/virtual-vendor-styles.d.ts +4 -0
- package/src/virtual-vendor-styles.js +82 -0
- package/src/virtual-vendor-styles.js.map +1 -0
- package/src/virtual-vendor.d.ts +4 -0
- package/src/virtual-vendor.js +57 -0
- package/src/virtual-vendor.js.map +1 -0
- package/types/virtual/index.d.ts +9 -0
- package/types/virtual/index.js +3 -0
- package/src/asset.d.ts +0 -32
- package/src/asset.js +0 -3
- package/src/asset.js.map +0 -1
- package/src/ember-html.d.ts +0 -43
- package/src/ember-html.js +0 -110
- package/src/ember-html.js.map +0 -1
- package/src/portable-babel-config.d.ts +0 -11
- package/src/portable-babel-config.js +0 -132
- package/src/portable-babel-config.js.map +0 -1
- package/src/portable-babel-launcher.d.ts +0 -6
- package/src/portable-babel-launcher.js +0 -75
- package/src/portable-babel-launcher.js.map +0 -1
- package/src/to-broccoli-plugin.d.ts +0 -8
- package/src/to-broccoli-plugin.js +0 -30
- package/src/to-broccoli-plugin.js.map +0 -1
package/src/module-resolver.js
CHANGED
@@ -15,64 +15,52 @@ 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
|
18
|
+
const reverse_exports_1 = require("@embroider/reverse-exports");
|
19
|
+
const resolve_exports_1 = require("resolve.exports");
|
19
20
|
const virtual_content_1 = require("./virtual-content");
|
20
21
|
const typescript_memoize_1 = require("typescript-memoize");
|
21
22
|
const describe_exports_1 = require("./describe-exports");
|
22
23
|
const fs_1 = require("fs");
|
24
|
+
const node_resolve_1 = require("./node-resolve");
|
25
|
+
const virtual_route_entrypoint_1 = require("./virtual-route-entrypoint");
|
23
26
|
const semver_1 = require("semver");
|
24
27
|
const debug = (0, debug_1.default)('embroider:resolver');
|
28
|
+
// Using a formatter makes this work lazy so nothing happens when we aren't
|
29
|
+
// logging. It is unfortunate that formatters are a globally mutable config and
|
30
|
+
// you can only use single character names, but oh well.
|
31
|
+
debug_1.default.formatters.p = (s) => {
|
32
|
+
let cwd = process.cwd();
|
33
|
+
if (s.startsWith(cwd)) {
|
34
|
+
return s.slice(cwd.length + 1);
|
35
|
+
}
|
36
|
+
return s;
|
37
|
+
};
|
25
38
|
function logTransition(reason, before, after = before) {
|
26
|
-
if (after.
|
27
|
-
debug(`
|
39
|
+
if (after.resolvedTo) {
|
40
|
+
debug(`[%s:resolvedTo] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
28
41
|
}
|
29
42
|
else if (before.specifier !== after.specifier) {
|
30
43
|
if (before.fromFile !== after.fromFile) {
|
31
|
-
debug(`aliased and rehomed
|
44
|
+
debug(`[%s:aliased and rehomed] %s to %s\n because %s\n from %p\n to %p`, before.debugType, before.specifier, after.specifier, reason, before.fromFile, after.fromFile);
|
32
45
|
}
|
33
46
|
else {
|
34
|
-
debug(`aliased
|
47
|
+
debug(`[%s:aliased] %s to %s\n because %s`, before.debugType, before.specifier, after.specifier, reason);
|
35
48
|
}
|
36
49
|
}
|
37
50
|
else if (before.fromFile !== after.fromFile) {
|
38
|
-
debug(`rehomed
|
51
|
+
debug(`[%s:rehomed] %s, because %s\n from %p\n to %p`, before.debugType, before.specifier, reason, before.fromFile, after.fromFile);
|
39
52
|
}
|
40
53
|
else {
|
41
|
-
debug(`
|
54
|
+
debug(`[%s:unchanged] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
|
42
55
|
}
|
43
56
|
return after;
|
44
57
|
}
|
45
|
-
const compatPattern =
|
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
|
-
}
|
58
|
+
const compatPattern = /@embroider\/virtual\/(?<type>[^\/]+)\/(?<rest>.*)/;
|
71
59
|
class Resolver {
|
72
60
|
constructor(options) {
|
73
61
|
this.options = options;
|
74
62
|
}
|
75
|
-
beforeResolve(request) {
|
63
|
+
async beforeResolve(request) {
|
76
64
|
if (request.specifier === '@embroider/macros') {
|
77
65
|
// the macros package is always handled directly within babel (not
|
78
66
|
// necessarily as a real resolvable package), so we should not mess with it.
|
@@ -81,9 +69,15 @@ class Resolver {
|
|
81
69
|
return logTransition('early exit', request);
|
82
70
|
}
|
83
71
|
request = this.handleFastbootSwitch(request);
|
84
|
-
request = this.handleGlobalsCompat(request);
|
72
|
+
request = await this.handleGlobalsCompat(request);
|
85
73
|
request = this.handleImplicitModules(request);
|
74
|
+
request = this.handleImplicitTestScripts(request);
|
75
|
+
request = this.handleVendorStyles(request);
|
76
|
+
request = this.handleTestSupportStyles(request);
|
77
|
+
request = this.handleEntrypoint(request);
|
78
|
+
request = this.handleRouteEntrypoint(request);
|
86
79
|
request = this.handleRenaming(request);
|
80
|
+
request = this.handleVendor(request);
|
87
81
|
// we expect the specifier to be app relative at this point - must be after handleRenaming
|
88
82
|
request = this.generateFastbootSwitch(request);
|
89
83
|
request = this.preHandleExternal(request);
|
@@ -97,95 +91,53 @@ class Resolver {
|
|
97
91
|
// that calls your build system's normal module resolver, this does both pre-
|
98
92
|
// and post-resolution adjustments as needed to implement our compatibility
|
99
93
|
// rules.
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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);
|
94
|
+
async resolve(request) {
|
95
|
+
request = await this.beforeResolve(request);
|
96
|
+
let resolution;
|
97
|
+
if (request.resolvedTo) {
|
98
|
+
if (typeof request.resolvedTo === 'function') {
|
99
|
+
resolution = await request.resolvedTo();
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
resolution = request.resolvedTo;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
else {
|
106
|
+
resolution = await request.defaultResolve();
|
107
|
+
}
|
128
108
|
switch (resolution.type) {
|
129
109
|
case 'found':
|
110
|
+
case 'ignored':
|
130
111
|
return resolution;
|
131
112
|
case 'not_found':
|
132
113
|
break;
|
133
114
|
default:
|
134
115
|
throw (0, assert_never_1.default)(resolution);
|
135
116
|
}
|
136
|
-
|
117
|
+
request = request.clone();
|
118
|
+
let nextRequest = await this.fallbackResolve(request);
|
137
119
|
if (nextRequest === request) {
|
138
120
|
// no additional fallback is available.
|
139
121
|
return resolution;
|
140
122
|
}
|
123
|
+
if (nextRequest.resolvedTo) {
|
124
|
+
if (typeof nextRequest.resolvedTo === 'function') {
|
125
|
+
return await nextRequest.resolvedTo();
|
126
|
+
}
|
127
|
+
else {
|
128
|
+
return nextRequest.resolvedTo;
|
129
|
+
}
|
130
|
+
}
|
141
131
|
if (nextRequest.fromFile === request.fromFile && nextRequest.specifier === request.specifier) {
|
142
132
|
throw new Error('Bug Discovered! New request is not === original request but has the same fromFile and specifier. This will likely create a loop.');
|
143
133
|
}
|
144
|
-
|
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);
|
134
|
+
return this.resolve(nextRequest);
|
151
135
|
}
|
152
136
|
// Use standard NodeJS resolving, with our required compatibility rules on
|
153
137
|
// top. This is a convenience method for calling resolveSync with the
|
154
138
|
// defaultResolve already configured to be "do the normal node thing".
|
155
|
-
nodeResolve(specifier, fromFile) {
|
156
|
-
|
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
|
-
}
|
139
|
+
async nodeResolve(specifier, fromFile) {
|
140
|
+
return (0, node_resolve_1.nodeResolve)(this, specifier, fromFile);
|
189
141
|
}
|
190
142
|
get packageCache() {
|
191
143
|
return shared_internals_2.RewrittenPackageCache.shared('embroider', this.options.appRoot);
|
@@ -202,6 +154,9 @@ class Resolver {
|
|
202
154
|
return owningPackage;
|
203
155
|
}
|
204
156
|
generateFastbootSwitch(request) {
|
157
|
+
if (request.resolvedTo) {
|
158
|
+
return request;
|
159
|
+
}
|
205
160
|
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
206
161
|
if (!pkg) {
|
207
162
|
return request;
|
@@ -219,7 +174,9 @@ class Resolver {
|
|
219
174
|
let fastbootFile = engineConfig.fastbootFiles[candidate];
|
220
175
|
if (fastbootFile) {
|
221
176
|
if (fastbootFile.shadowedFilename) {
|
222
|
-
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)((0, path_1.resolve)(pkg.root, fastbootFile.shadowedFilename), 'utf8'), {
|
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
|
+
});
|
223
180
|
let switchFile = (0, virtual_content_1.fastbootSwitch)(candidate, (0, path_1.resolve)(pkg.root, 'package.json'), names);
|
224
181
|
if (switchFile === request.fromFile) {
|
225
182
|
return logTransition('internal lookup from fastbootSwitch', request);
|
@@ -238,6 +195,9 @@ class Resolver {
|
|
238
195
|
}
|
239
196
|
handleFastbootSwitch(request) {
|
240
197
|
var _a;
|
198
|
+
if (request.resolvedTo) {
|
199
|
+
return request;
|
200
|
+
}
|
241
201
|
let match = (0, virtual_content_1.decodeFastbootSwitch)(request.fromFile);
|
242
202
|
if (!match) {
|
243
203
|
return request;
|
@@ -276,12 +236,15 @@ class Resolver {
|
|
276
236
|
}
|
277
237
|
let entry = (_a = this.getEntryFromMergeMap(rel, pkg.root)) === null || _a === void 0 ? void 0 : _a.entry;
|
278
238
|
if ((entry === null || entry === void 0 ? void 0 : entry.type) === 'both') {
|
279
|
-
return logTransition('matched addon entry', request, request.alias(entry[section].
|
239
|
+
return logTransition('matched addon entry', request, request.alias(entry[section].specifier).rehome(entry[section].fromFile));
|
280
240
|
}
|
281
241
|
}
|
282
242
|
return logTransition('failed to match in fastboot switch', request);
|
283
243
|
}
|
284
244
|
handleImplicitModules(request) {
|
245
|
+
if (request.resolvedTo) {
|
246
|
+
return request;
|
247
|
+
}
|
285
248
|
let im = (0, virtual_content_1.decodeImplicitModules)(request.specifier);
|
286
249
|
if (!im) {
|
287
250
|
return request;
|
@@ -299,7 +262,97 @@ class Resolver {
|
|
299
262
|
return logTransition(`own implicit modules`, request, request.virtualize((0, path_1.resolve)(pkg.root, `-embroider-${im.type}.js`)));
|
300
263
|
}
|
301
264
|
}
|
302
|
-
|
265
|
+
handleEntrypoint(request) {
|
266
|
+
var _a;
|
267
|
+
if (request.resolvedTo) {
|
268
|
+
return request;
|
269
|
+
}
|
270
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
271
|
+
const candidates = [
|
272
|
+
'@embroider/virtual/compat-modules',
|
273
|
+
'/@embroider/virtual/compat-modules',
|
274
|
+
'./@embroider/virtual/compat-modules',
|
275
|
+
];
|
276
|
+
if (!candidates.some(c => request.specifier.startsWith(c + '/') || request.specifier === c)) {
|
277
|
+
return request;
|
278
|
+
}
|
279
|
+
const result = /\.?\/?@embroider\/virtual\/compat-modules(?:\/(?<packageName>.*))?/.exec(request.specifier);
|
280
|
+
if (!result) {
|
281
|
+
// TODO make a better error
|
282
|
+
throw new Error('entrypoint does not match pattern' + request.specifier);
|
283
|
+
}
|
284
|
+
const { packageName } = result.groups;
|
285
|
+
const requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
286
|
+
if (!(requestingPkg === null || requestingPkg === void 0 ? void 0 : requestingPkg.isV2Ember())) {
|
287
|
+
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
|
288
|
+
}
|
289
|
+
let pkg;
|
290
|
+
if (packageName) {
|
291
|
+
pkg = this.packageCache.resolve(packageName, requestingPkg);
|
292
|
+
}
|
293
|
+
else {
|
294
|
+
pkg = requestingPkg;
|
295
|
+
}
|
296
|
+
let matched = (0, resolve_exports_1.exports)(pkg.packageJSON, '-embroider-entrypoint.js', {
|
297
|
+
browser: true,
|
298
|
+
conditions: ['default', 'imports'],
|
299
|
+
});
|
300
|
+
return logTransition('entrypoint', request, request.virtualize((0, path_1.resolve)(pkg.root, (_a = matched === null || matched === void 0 ? void 0 : matched[0]) !== null && _a !== void 0 ? _a : '-embroider-entrypoint.js')));
|
301
|
+
}
|
302
|
+
handleRouteEntrypoint(request) {
|
303
|
+
if (request.resolvedTo) {
|
304
|
+
return request;
|
305
|
+
}
|
306
|
+
let routeName = (0, virtual_route_entrypoint_1.decodePublicRouteEntrypoint)(request.specifier);
|
307
|
+
if (!routeName) {
|
308
|
+
return request;
|
309
|
+
}
|
310
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
311
|
+
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
|
312
|
+
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
|
313
|
+
}
|
314
|
+
let matched = (0, resolve_exports_1.exports)(pkg.packageJSON, '-embroider-route-entrypoint.js', {
|
315
|
+
browser: true,
|
316
|
+
conditions: ['default', 'imports'],
|
317
|
+
});
|
318
|
+
return logTransition('route entrypoint', request, request.virtualize((0, virtual_route_entrypoint_1.encodeRouteEntrypoint)(pkg.root, matched === null || matched === void 0 ? void 0 : matched[0], routeName)));
|
319
|
+
}
|
320
|
+
handleImplicitTestScripts(request) {
|
321
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
322
|
+
const candidates = [
|
323
|
+
'@embroider/virtual/test-support.js',
|
324
|
+
'/@embroider/virtual/test-support.js',
|
325
|
+
'./@embroider/virtual/test-support.js',
|
326
|
+
];
|
327
|
+
if (!candidates.includes(request.specifier)) {
|
328
|
+
return request;
|
329
|
+
}
|
330
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
331
|
+
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
332
|
+
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.`);
|
333
|
+
}
|
334
|
+
return logTransition('test-support', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support.js')));
|
335
|
+
}
|
336
|
+
handleTestSupportStyles(request) {
|
337
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
338
|
+
const candidates = [
|
339
|
+
'@embroider/virtual/test-support.css',
|
340
|
+
'/@embroider/virtual/test-support.css',
|
341
|
+
'./@embroider/virtual/test-support.css',
|
342
|
+
];
|
343
|
+
if (!candidates.includes(request.specifier)) {
|
344
|
+
return request;
|
345
|
+
}
|
346
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
347
|
+
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
348
|
+
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.`);
|
349
|
+
}
|
350
|
+
return logTransition('test-support-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support-styles.css')));
|
351
|
+
}
|
352
|
+
async handleGlobalsCompat(request) {
|
353
|
+
if (request.resolvedTo) {
|
354
|
+
return request;
|
355
|
+
}
|
303
356
|
let match = compatPattern.exec(request.specifier);
|
304
357
|
if (!match) {
|
305
358
|
return request;
|
@@ -320,62 +373,92 @@ class Resolver {
|
|
320
373
|
case 'ambiguous':
|
321
374
|
return this.resolveHelperOrComponent(rest, engine, request);
|
322
375
|
default:
|
323
|
-
throw new Error(`bug: unexepected
|
376
|
+
throw new Error(`bug: unexepected @embroider/virtual specifier: ${request.specifier}`);
|
377
|
+
}
|
378
|
+
}
|
379
|
+
handleVendorStyles(request) {
|
380
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
381
|
+
const candidates = [
|
382
|
+
'@embroider/virtual/vendor.css',
|
383
|
+
'/@embroider/virtual/vendor.css',
|
384
|
+
'./@embroider/virtual/vendor.css',
|
385
|
+
];
|
386
|
+
if (!candidates.includes(request.specifier)) {
|
387
|
+
return request;
|
324
388
|
}
|
389
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
390
|
+
if (!pkg || !this.options.engines.some(e => e.root === (pkg === null || pkg === void 0 ? void 0 : pkg.root))) {
|
391
|
+
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.`);
|
392
|
+
}
|
393
|
+
return logTransition('vendor-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor-styles.css')));
|
325
394
|
}
|
326
395
|
resolveHelper(path, inEngine, request) {
|
327
396
|
let target = this.parseGlobalPath(path, inEngine);
|
328
397
|
return logTransition('resolveHelper', request, request.alias(`${target.packageName}/helpers/${target.memberName}`).rehome((0, path_1.resolve)(inEngine.root, 'package.json')));
|
329
398
|
}
|
330
|
-
resolveComponent(path, inEngine, request) {
|
399
|
+
async resolveComponent(path, inEngine, request) {
|
331
400
|
let target = this.parseGlobalPath(path, inEngine);
|
332
401
|
let hbsModule = null;
|
333
402
|
let jsModule = null;
|
334
403
|
// first, the various places our template might be.
|
335
404
|
for (let candidate of this.componentTemplateCandidates(target.packageName)) {
|
336
|
-
let
|
337
|
-
|
338
|
-
|
405
|
+
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;
|
406
|
+
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from).withMeta({
|
407
|
+
runtimeFallback: false,
|
408
|
+
}));
|
409
|
+
if (resolution.type === 'found') {
|
410
|
+
hbsModule = resolution;
|
339
411
|
break;
|
340
412
|
}
|
341
413
|
}
|
342
414
|
// then the various places our javascript might be.
|
343
415
|
for (let candidate of this.componentJSCandidates(target.packageName)) {
|
344
|
-
let
|
416
|
+
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;
|
417
|
+
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from).withMeta({
|
418
|
+
runtimeFallback: false,
|
419
|
+
}));
|
420
|
+
if (resolution.type === 'ignored') {
|
421
|
+
return logTransition(`resolving to ignored component`, request, request.resolveTo(resolution));
|
422
|
+
}
|
345
423
|
// .hbs is a resolvable extension for us, so we need to exclude it here.
|
346
424
|
// It matches as a priority lower than .js, so finding an .hbs means
|
347
425
|
// there's definitely not a .js.
|
348
|
-
if (resolution.type === '
|
349
|
-
jsModule = resolution
|
426
|
+
if (resolution.type === 'found' && !resolution.filename.endsWith('.hbs')) {
|
427
|
+
jsModule = resolution;
|
350
428
|
break;
|
351
429
|
}
|
352
430
|
}
|
353
431
|
if (hbsModule) {
|
354
432
|
if (!this.emberVersionSupportsSeparateTemplates) {
|
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}.`);
|
433
|
+
throw new Error(`Components with separately resolved templates were removed at Ember 6.0. Migrate to either co-located js/ts + hbs files or to gjs/gts. https://deprecations.emberjs.com/id/component-template-resolving/. Bad template was: ${hbsModule.filename}.`);
|
356
434
|
}
|
357
|
-
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule, jsModule)));
|
435
|
+
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule.filename, jsModule === null || jsModule === void 0 ? void 0 : jsModule.filename)));
|
358
436
|
}
|
359
437
|
else if (jsModule) {
|
360
|
-
return logTransition(`resolveComponent found only JS`, request, request.
|
438
|
+
return logTransition(`resolving to resolveComponent found only JS`, request, request.resolveTo(jsModule));
|
361
439
|
}
|
362
440
|
else {
|
363
441
|
return logTransition(`resolveComponent failed`, request);
|
364
442
|
}
|
365
443
|
}
|
366
|
-
resolveHelperOrComponent(path, inEngine, request) {
|
444
|
+
async resolveHelperOrComponent(path, inEngine, request) {
|
367
445
|
// resolveHelper just rewrites our request to one that should target the
|
368
446
|
// component, so here to resolve the ambiguity we need to actually resolve
|
369
447
|
// that candidate to see if it works.
|
370
448
|
let helperCandidate = this.resolveHelper(path, inEngine, request);
|
371
|
-
let helperMatch = this.
|
372
|
-
|
373
|
-
|
449
|
+
let helperMatch = await this.resolve(request.alias(helperCandidate.specifier).rehome(helperCandidate.fromFile).withMeta({
|
450
|
+
runtimeFallback: false,
|
451
|
+
}));
|
452
|
+
// for the case of 'ignored' that means that esbuild found this helper in an external
|
453
|
+
// package so it should be considered found in this case and we should not look for a
|
454
|
+
// component with this name
|
455
|
+
if (helperMatch.type === 'found' || helperMatch.type === 'ignored') {
|
456
|
+
return logTransition('resolve to ambiguous case matched a helper', request, request.resolveTo(helperMatch));
|
374
457
|
}
|
375
458
|
// unlike resolveHelper, resolveComponent already does pre-resolution in
|
376
459
|
// order to deal with its own internal ambiguity around JS vs HBS vs
|
377
460
|
// colocation.≥
|
378
|
-
let componentMatch = this.resolveComponent(path, inEngine, request);
|
461
|
+
let componentMatch = await this.resolveComponent(path, inEngine, request);
|
379
462
|
if (componentMatch !== request) {
|
380
463
|
return logTransition('ambiguous case matched a cmoponent', request, componentMatch);
|
381
464
|
}
|
@@ -400,6 +483,7 @@ class Resolver {
|
|
400
483
|
}
|
401
484
|
*componentJSCandidates(inPackageName) {
|
402
485
|
yield { prefix: '/components/', suffix: '' };
|
486
|
+
yield { prefix: '/components/', suffix: '/index' };
|
403
487
|
yield { prefix: '/components/', suffix: '/component' };
|
404
488
|
let pods = this.podPrefix(inPackageName);
|
405
489
|
if (pods) {
|
@@ -418,10 +502,10 @@ class Resolver {
|
|
418
502
|
parseGlobalPath(path, inEngine) {
|
419
503
|
let parts = path.split('@');
|
420
504
|
if (parts.length > 1 && parts[0].length > 0) {
|
421
|
-
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, '
|
505
|
+
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'package.json') };
|
422
506
|
}
|
423
507
|
else {
|
424
|
-
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, '
|
508
|
+
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'package.json') };
|
425
509
|
}
|
426
510
|
}
|
427
511
|
engineConfig(packageName) {
|
@@ -447,14 +531,18 @@ class Resolver {
|
|
447
531
|
if (!inAddonName.startsWith('./')) {
|
448
532
|
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`);
|
449
533
|
}
|
534
|
+
let specifier = (0, reverse_exports_1.externalName)(addon.packageJSON, inAddonName);
|
535
|
+
if (!specifier) {
|
536
|
+
throw new Error(`${addon.name}'s package.json app-js refers to ${inAddonName}, but that module is not accessible from outside the package`);
|
537
|
+
}
|
450
538
|
let prevEntry = engineModules.get(inEngineName);
|
451
539
|
switch (prevEntry === null || prevEntry === void 0 ? void 0 : prevEntry.type) {
|
452
540
|
case undefined:
|
453
541
|
engineModules.set(inEngineName, {
|
454
542
|
type: 'app-only',
|
455
543
|
'app-js': {
|
456
|
-
|
457
|
-
|
544
|
+
specifier,
|
545
|
+
fromFile: addonConfig.canResolveFromFile,
|
458
546
|
fromPackageName: addon.name,
|
459
547
|
},
|
460
548
|
});
|
@@ -467,8 +555,8 @@ class Resolver {
|
|
467
555
|
engineModules.set(inEngineName, {
|
468
556
|
type: 'both',
|
469
557
|
'app-js': {
|
470
|
-
|
471
|
-
|
558
|
+
specifier,
|
559
|
+
fromFile: addonConfig.canResolveFromFile,
|
472
560
|
fromPackageName: addon.name,
|
473
561
|
},
|
474
562
|
'fastboot-js': prevEntry['fastboot-js'],
|
@@ -486,14 +574,18 @@ class Resolver {
|
|
486
574
|
if (!inAddonName.startsWith('./')) {
|
487
575
|
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`);
|
488
576
|
}
|
577
|
+
let specifier = (0, reverse_exports_1.externalName)(addon.packageJSON, inAddonName);
|
578
|
+
if (!specifier) {
|
579
|
+
throw new Error(`${addon.name}'s package.json fastboot-js refers to ${inAddonName}, but that module is not accessible from outside the package`);
|
580
|
+
}
|
489
581
|
let prevEntry = engineModules.get(inEngineName);
|
490
582
|
switch (prevEntry === null || prevEntry === void 0 ? void 0 : prevEntry.type) {
|
491
583
|
case undefined:
|
492
584
|
engineModules.set(inEngineName, {
|
493
585
|
type: 'fastboot-only',
|
494
586
|
'fastboot-js': {
|
495
|
-
|
496
|
-
|
587
|
+
specifier,
|
588
|
+
fromFile: addonConfig.canResolveFromFile,
|
497
589
|
fromPackageName: addon.name,
|
498
590
|
},
|
499
591
|
});
|
@@ -506,8 +598,8 @@ class Resolver {
|
|
506
598
|
engineModules.set(inEngineName, {
|
507
599
|
type: 'both',
|
508
600
|
'fastboot-js': {
|
509
|
-
|
510
|
-
|
601
|
+
specifier,
|
602
|
+
fromFile: addonConfig.canResolveFromFile,
|
511
603
|
fromPackageName: addon.name,
|
512
604
|
},
|
513
605
|
'app-js': prevEntry['app-js'],
|
@@ -538,7 +630,7 @@ class Resolver {
|
|
538
630
|
});
|
539
631
|
}
|
540
632
|
handleRewrittenPackages(request) {
|
541
|
-
if (request.
|
633
|
+
if (request.resolvedTo) {
|
542
634
|
return request;
|
543
635
|
}
|
544
636
|
let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
@@ -557,10 +649,6 @@ class Resolver {
|
|
557
649
|
targetPkg = this.packageCache.resolve(packageName, requestingPkg);
|
558
650
|
}
|
559
651
|
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)
|
564
652
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
565
653
|
throw err;
|
566
654
|
}
|
@@ -576,14 +664,26 @@ class Resolver {
|
|
576
664
|
return logTransition('request targets a moved package', request, this.resolveWithinMovedPackage(request, targetPkg));
|
577
665
|
}
|
578
666
|
else if (originalRequestingPkg !== requestingPkg) {
|
579
|
-
|
580
|
-
|
581
|
-
|
667
|
+
if (targetPkg) {
|
668
|
+
// in this case, the requesting package is moved but its destination is
|
669
|
+
// not, so we need to rehome the request back to the original location.
|
670
|
+
return logTransition('outbound request from moved package', request, request
|
671
|
+
// setting meta here because if this fails, we want the fallback
|
672
|
+
// logic to revert our rehome and continue from the *moved* package.
|
673
|
+
.withMeta({ originalFromFile: request.fromFile })
|
674
|
+
.rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
|
675
|
+
}
|
676
|
+
else {
|
677
|
+
// requesting package was moved and we failed to find its target. We
|
678
|
+
// can't let that accidentally succeed in the defaultResolve because we
|
679
|
+
// could escape the moved package system.
|
680
|
+
return logTransition('missing outbound request from moved package', request, request.notFound());
|
681
|
+
}
|
582
682
|
}
|
583
683
|
return request;
|
584
684
|
}
|
585
685
|
handleRenaming(request) {
|
586
|
-
if (request.
|
686
|
+
if (request.resolvedTo) {
|
587
687
|
return request;
|
588
688
|
}
|
589
689
|
let packageName = (0, shared_internals_1.packageName)(request.specifier);
|
@@ -591,14 +691,11 @@ class Resolver {
|
|
591
691
|
return request;
|
592
692
|
}
|
593
693
|
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
594
|
-
if (!pkg || !pkg.isV2Ember()) {
|
595
|
-
return request;
|
596
|
-
}
|
597
694
|
// real deps take precedence over renaming rules. That is, a package like
|
598
695
|
// ember-source might provide backburner via module renaming, but if you
|
599
696
|
// have an explicit dependency on backburner you should still get that real
|
600
697
|
// copy.
|
601
|
-
if (!pkg.hasDependency(packageName)) {
|
698
|
+
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.hasDependency(packageName))) {
|
602
699
|
for (let [candidate, replacement] of Object.entries(this.options.renameModules)) {
|
603
700
|
if (candidate === request.specifier) {
|
604
701
|
return logTransition(`renameModules`, request, request.alias(replacement));
|
@@ -616,30 +713,79 @@ class Resolver {
|
|
616
713
|
return logTransition(`renamePackages`, request, request.alias(request.specifier.replace(packageName, this.options.renamePackages[packageName])));
|
617
714
|
}
|
618
715
|
}
|
619
|
-
if (pkg
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
//
|
624
|
-
|
716
|
+
if (!pkg || !pkg.isV2Ember()) {
|
717
|
+
return request;
|
718
|
+
}
|
719
|
+
if (pkg.name === packageName) {
|
720
|
+
// we found a self-import
|
721
|
+
if (pkg.meta['auto-upgraded']) {
|
722
|
+
// auto-upgraded packages always get automatically adjusted. They never
|
723
|
+
// supported fancy package.json exports features so this direct mapping
|
724
|
+
// to the root is always right.
|
725
|
+
// "my-app/foo" -> "./foo" from app's package.json
|
726
|
+
// "my-addon/foo" -> "my-addon/foo" from a package that's guaranteed to be able to resolve my-addon
|
727
|
+
let owningEngine = this.owningEngine(pkg);
|
728
|
+
let addonConfig = owningEngine.activeAddons.find(a => a.root === pkg.root);
|
729
|
+
if (addonConfig) {
|
730
|
+
// auto-upgraded addons get special support for self-resolving here.
|
731
|
+
return logTransition(`v1 addon self-import`, request, request.rehome(addonConfig.canResolveFromFile));
|
732
|
+
}
|
733
|
+
else {
|
734
|
+
// auto-upgraded apps will necessarily have packageJSON.exports
|
735
|
+
// because we insert them, so for that support we can fall through to
|
736
|
+
// that support below.
|
737
|
+
}
|
738
|
+
}
|
739
|
+
// v2 packages are supposed to use package.json `exports` to enable
|
740
|
+
// self-imports, but not all build tools actually follow the spec. This
|
741
|
+
// is a workaround for badly behaved packagers.
|
742
|
+
//
|
743
|
+
// Known upstream bugs this works around:
|
744
|
+
// - https://github.com/vitejs/vite/issues/9731
|
745
|
+
if (pkg.packageJSON.exports) {
|
746
|
+
let found = (0, resolve_exports_1.exports)(pkg.packageJSON, request.specifier, {
|
747
|
+
browser: true,
|
748
|
+
conditions: ['default', 'imports'],
|
749
|
+
});
|
750
|
+
if (found === null || found === void 0 ? void 0 : found[0]) {
|
751
|
+
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')));
|
752
|
+
}
|
753
|
+
}
|
625
754
|
}
|
626
755
|
return request;
|
627
756
|
}
|
757
|
+
handleVendor(request) {
|
758
|
+
//TODO move the extra forwardslash handling out into the vite plugin
|
759
|
+
const candidates = [
|
760
|
+
'@embroider/virtual/vendor.js',
|
761
|
+
'/@embroider/virtual/vendor.js',
|
762
|
+
'./@embroider/virtual/vendor.js',
|
763
|
+
];
|
764
|
+
if (!candidates.includes(request.specifier)) {
|
765
|
+
return request;
|
766
|
+
}
|
767
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
768
|
+
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
|
769
|
+
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.`);
|
770
|
+
}
|
771
|
+
return logTransition('vendor', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor.js')));
|
772
|
+
}
|
628
773
|
resolveWithinMovedPackage(request, pkg) {
|
629
774
|
let levels = ['..'];
|
630
775
|
if (pkg.name.startsWith('@')) {
|
631
776
|
levels.push('..');
|
632
777
|
}
|
778
|
+
let originalFromFile = request.fromFile;
|
633
779
|
let newRequest = request.rehome((0, path_1.resolve)(pkg.root, ...levels, 'moved-package-target.js'));
|
634
780
|
if (newRequest === request) {
|
635
781
|
return request;
|
636
782
|
}
|
637
|
-
|
638
|
-
|
639
|
-
});
|
783
|
+
// setting meta because if this fails, we want the fallback to pick up back
|
784
|
+
// in the original requesting package.
|
785
|
+
return newRequest.withMeta({ originalFromFile });
|
640
786
|
}
|
641
787
|
preHandleExternal(request) {
|
642
|
-
if (request.
|
788
|
+
if (request.resolvedTo) {
|
643
789
|
return request;
|
644
790
|
}
|
645
791
|
let { specifier, fromFile } = request;
|
@@ -649,11 +795,6 @@ class Resolver {
|
|
649
795
|
}
|
650
796
|
let packageName = (0, shared_internals_1.packageName)(specifier);
|
651
797
|
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.
|
657
798
|
let absoluteSpecifier = (0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier);
|
658
799
|
if (!absoluteSpecifier.startsWith(pkg.root)) {
|
659
800
|
// this relative path escape its package. So it's not really using
|
@@ -662,36 +803,23 @@ class Resolver {
|
|
662
803
|
// references to runtime utilities, like we do in @embroider/macros.
|
663
804
|
return logTransition('beforeResolve: relative path escapes its package', request);
|
664
805
|
}
|
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
|
-
}
|
670
806
|
// if the requesting file is in an addon's app-js, the relative request
|
671
807
|
// should really be understood as a request for a module in the containing
|
672
|
-
// engine
|
808
|
+
// engine.
|
673
809
|
let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
|
674
810
|
if (logicalLocation) {
|
675
|
-
return logTransition('beforeResolve: relative import in app-js', request, request.
|
811
|
+
return logTransition('beforeResolve: relative import in app-js', request, request.alias(path_1.posix.join(logicalLocation.owningEngine.packageName, (0, path_1.dirname)(logicalLocation.inAppName), request.specifier)));
|
676
812
|
}
|
677
813
|
return request;
|
678
814
|
}
|
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
|
-
}
|
687
815
|
if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
|
688
816
|
// addons (whether auto-upgraded or not) may use the app's
|
689
817
|
// emberVirtualPeerDeps, like "@glimmer/component" etc.
|
690
|
-
|
691
|
-
|
818
|
+
let addon = this.locateActiveAddon(packageName);
|
819
|
+
if (!addon) {
|
820
|
+
throw new Error(`${pkg.name} is trying to import the emberVirtualPeerDep "${packageName}", but it seems to be missing`);
|
692
821
|
}
|
693
|
-
|
694
|
-
return logTransition(`emberVirtualPeerDeps in v2 addon`, request, request.rehome(newHome));
|
822
|
+
return logTransition(`emberVirtualPeerDeps`, request, request.rehome(addon.canResolveFromFile));
|
695
823
|
}
|
696
824
|
// if this file is part of an addon's app-js, it's really the logical
|
697
825
|
// package to which it belongs (normally the app) that affects some policy
|
@@ -700,10 +828,10 @@ class Resolver {
|
|
700
828
|
if (logicalPackage.meta['auto-upgraded'] && !logicalPackage.hasDependency('ember-auto-import')) {
|
701
829
|
try {
|
702
830
|
let dep = this.packageCache.resolve(packageName, logicalPackage);
|
703
|
-
if (!dep.
|
831
|
+
if (!dep.isEmberAddon()) {
|
704
832
|
// classic ember addons can only import non-ember dependencies if they
|
705
833
|
// have ember-auto-import.
|
706
|
-
return
|
834
|
+
return logTransition('v1 package without auto-import', request, request.notFound());
|
707
835
|
}
|
708
836
|
}
|
709
837
|
catch (err) {
|
@@ -713,49 +841,33 @@ class Resolver {
|
|
713
841
|
}
|
714
842
|
}
|
715
843
|
// assertions on what native v2 addons can import
|
716
|
-
if (!pkg.
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
throw new Error(`${pkg.name} is trying to import from ${packageName} but that is not one of its explicit dependencies`);
|
721
|
-
}
|
844
|
+
if (!pkg.needsLooseResolving() &&
|
845
|
+
!appImportInAppTree(pkg, logicalPackage, packageName) &&
|
846
|
+
!reliablyResolvable(pkg, packageName)) {
|
847
|
+
throw new Error(`${pkg.name} is trying to import from ${packageName} but that is not one of its explicit dependencies`);
|
722
848
|
}
|
723
849
|
return request;
|
724
850
|
}
|
725
|
-
|
726
|
-
if (this.options.
|
727
|
-
|
728
|
-
return
|
729
|
-
|
730
|
-
|
731
|
-
|
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));
|
851
|
+
locateActiveAddon(packageName) {
|
852
|
+
if (packageName === this.options.modulePrefix) {
|
853
|
+
// the app itself is something that addon's can classically resolve if they know it's name.
|
854
|
+
return {
|
855
|
+
root: this.options.appRoot,
|
856
|
+
canResolveFromFile: (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json'),
|
857
|
+
};
|
752
858
|
}
|
753
|
-
|
754
|
-
|
859
|
+
for (let engine of this.options.engines) {
|
860
|
+
for (let addon of engine.activeAddons) {
|
861
|
+
if (addon.name === packageName) {
|
862
|
+
return addon;
|
863
|
+
}
|
864
|
+
}
|
755
865
|
}
|
756
866
|
}
|
757
|
-
fallbackResolve(request) {
|
758
|
-
|
867
|
+
async fallbackResolve(request) {
|
868
|
+
if (request.resolvedTo) {
|
869
|
+
throw new Error('Build tool bug detected! Fallback resolve should never see an already-resolved request.');
|
870
|
+
}
|
759
871
|
if (request.specifier === '@embroider/macros') {
|
760
872
|
// the macros package is always handled directly within babel (not
|
761
873
|
// necessarily as a real resolvable package), so we should not mess with it.
|
@@ -763,108 +875,124 @@ class Resolver {
|
|
763
875
|
// why we need to know about it.
|
764
876
|
return logTransition('fallback early exit', request);
|
765
877
|
}
|
766
|
-
|
767
|
-
if (compatPattern.test(specifier)) {
|
878
|
+
if (compatPattern.test(request.specifier)) {
|
768
879
|
// Some kinds of compat requests get rewritten into other things
|
769
|
-
// deterministically. For example, "
|
880
|
+
// deterministically. For example, "@embroider/virtual/helpers/whatever"
|
770
881
|
// means only "the-current-engine/helpers/whatever", and if that doesn't
|
771
882
|
// actually exist it's that path that will show up as a missing import.
|
772
883
|
//
|
773
884
|
// But others have an ambiguous meaning. For example,
|
774
|
-
//
|
885
|
+
// @embroider/virtual/components/whatever can mean several different
|
775
886
|
// things. If we're unable to find any of them, the actual
|
776
|
-
// "
|
887
|
+
// "@embroider/virtual" request will fall through all the way to here.
|
777
888
|
//
|
778
889
|
// In that case, we don't want to externalize that failure. We know it's
|
779
890
|
// not a classic runtime thing. It's better to let it be a build error
|
780
891
|
// here.
|
781
892
|
return request;
|
782
893
|
}
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
}
|
787
|
-
fromFile = (0, path_1.resolve)((_b = request.meta) === null || _b === void 0 ? void 0 : _b.resolvedWithinPackage, 'package.json');
|
788
|
-
}
|
789
|
-
let pkg = this.packageCache.ownerOfFile(fromFile);
|
790
|
-
if (!pkg) {
|
791
|
-
return logTransition('no identifiable owningPackage', request);
|
894
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
895
|
+
if (pkg) {
|
896
|
+
({ pkg, request } = this.restoreRehomedRequest(pkg, request));
|
792
897
|
}
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
898
|
+
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
|
899
|
+
// this request is coming from a file that appears to be owned by no ember
|
900
|
+
// package. We offer one fallback behavior for such files. They're allowed
|
901
|
+
// to resolve from the app's namespace.
|
902
|
+
//
|
903
|
+
// This makes it possible for integrations like vite to leave references
|
904
|
+
// to the app in their pre-bundled dependencies, which will end up in an
|
905
|
+
// arbitrary cache that is not inside any particular package.
|
906
|
+
let description = pkg ? 'non-ember package' : 'unowned module';
|
907
|
+
let packageName = (0, shared_internals_1.packageName)(request.specifier);
|
908
|
+
if (packageName === this.options.modulePrefix) {
|
909
|
+
return logTransition(`fallbackResolver: ${description} resolved app namespace`, request, request.rehome(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root));
|
801
910
|
}
|
802
|
-
|
803
|
-
pkg = movedPkg;
|
804
|
-
}
|
805
|
-
if (!pkg.isV2Ember()) {
|
806
|
-
return logTransition('fallbackResolve: not in an ember package', request);
|
911
|
+
return logTransition(`fallbackResolver: ${description}`, request);
|
807
912
|
}
|
808
|
-
let packageName = (0, shared_internals_1.packageName)(specifier);
|
913
|
+
let packageName = (0, shared_internals_1.packageName)(request.specifier);
|
809
914
|
if (!packageName) {
|
810
915
|
// this is a relative import
|
811
|
-
|
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
|
-
}
|
916
|
+
return this.relativeFallbackResolve(pkg, request);
|
827
917
|
}
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
return logTransition(`activeAddons`, request, rehomed);
|
918
|
+
if (pkg.needsLooseResolving()) {
|
919
|
+
let activeAddon = this.maybeFallbackToActiveAddon(request, packageName);
|
920
|
+
if (activeAddon) {
|
921
|
+
return activeAddon;
|
833
922
|
}
|
834
923
|
}
|
835
|
-
let logicalLocation = this.reverseSearchAppTree(pkg, fromFile);
|
924
|
+
let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
|
836
925
|
if (logicalLocation) {
|
837
926
|
// the requesting file is in an addon's appTree. We didn't succeed in
|
838
927
|
// resolving this (non-relative) request from inside the actual addon, so
|
839
928
|
// next try to resolve it from the corresponding logical location in the
|
840
929
|
// app.
|
841
|
-
return logTransition('fallbackResolve: retry from logical home of app-js file', request,
|
930
|
+
return logTransition('fallbackResolve: retry from logical home of app-js file', request,
|
931
|
+
// it might look more precise to rehome into logicalLocation.inAppName
|
932
|
+
// rather than package.json. But that logical location may not actually
|
933
|
+
// exist, and some systems (including node's require.resolve) will be
|
934
|
+
// mad about trying to resolve from notional paths that don't really
|
935
|
+
// exist.
|
936
|
+
request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
|
842
937
|
}
|
843
938
|
let targetingEngine = this.engineConfig(packageName);
|
844
939
|
if (targetingEngine) {
|
845
|
-
let appJSMatch = this.searchAppTree(request, targetingEngine, specifier.replace(packageName, '.'));
|
940
|
+
let appJSMatch = await this.searchAppTree(request, targetingEngine, request.specifier.replace(packageName, '.'));
|
846
941
|
if (appJSMatch) {
|
847
942
|
return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
|
848
943
|
}
|
849
944
|
}
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
945
|
+
// this is falling through with the original specifier which was
|
946
|
+
// non-resolvable, which will presumably cause a static build error in stage3.
|
947
|
+
return logTransition('fallbackResolve final exit', request);
|
948
|
+
}
|
949
|
+
restoreRehomedRequest(pkg, request) {
|
950
|
+
var _a;
|
951
|
+
// meta.originalFromFile gets set when we want to try to rehome a request
|
952
|
+
// but then come back to the original location here in the fallback when the
|
953
|
+
// rehomed request fails
|
954
|
+
let movedPkg = this.packageCache.maybeMoved(pkg);
|
955
|
+
if (movedPkg !== pkg) {
|
956
|
+
let originalFromFile = (_a = request.meta) === null || _a === void 0 ? void 0 : _a.originalFromFile;
|
957
|
+
if (typeof originalFromFile !== 'string') {
|
958
|
+
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
959
|
+
}
|
960
|
+
request = request.rehome(originalFromFile);
|
961
|
+
pkg = movedPkg;
|
962
|
+
}
|
963
|
+
return { pkg, request };
|
964
|
+
}
|
965
|
+
async relativeFallbackResolve(pkg, request) {
|
966
|
+
let withinEngine = this.engineConfig(pkg.name);
|
967
|
+
if (withinEngine) {
|
968
|
+
// it's a relative import inside an engine (which also means app), which
|
969
|
+
// means we may need to satisfy the request via app tree merging.
|
970
|
+
let logicalName = engineRelativeName(pkg, (0, path_1.resolve)((0, path_1.dirname)(request.fromFile), request.specifier));
|
971
|
+
if (!logicalName) {
|
972
|
+
return logTransition('fallbackResolve: relative failure because this file is not externally accessible', request);
|
973
|
+
}
|
974
|
+
let appJSMatch = await this.searchAppTree(request, withinEngine, logicalName);
|
975
|
+
if (appJSMatch) {
|
976
|
+
return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
|
977
|
+
}
|
978
|
+
else {
|
979
|
+
return logTransition('fallbackResolve: relative appJs search failure', request);
|
980
|
+
}
|
856
981
|
}
|
857
982
|
else {
|
858
|
-
//
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
983
|
+
// nothing else to do for relative imports
|
984
|
+
return logTransition('fallbackResolve: relative failure', request);
|
985
|
+
}
|
986
|
+
}
|
987
|
+
maybeFallbackToActiveAddon(request, requestedPackageName) {
|
988
|
+
// auto-upgraded packages can fall back to the set of known active addons
|
989
|
+
let addon = this.locateActiveAddon(requestedPackageName);
|
990
|
+
if (addon) {
|
991
|
+
const rehomed = request.rehome(addon.canResolveFromFile);
|
992
|
+
if (rehomed !== request) {
|
993
|
+
return logTransition(`activeAddons`, request, rehomed);
|
863
994
|
}
|
864
995
|
}
|
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);
|
868
996
|
}
|
869
997
|
getEntryFromMergeMap(inEngineSpecifier, root) {
|
870
998
|
var _a;
|
@@ -886,25 +1014,23 @@ class Resolver {
|
|
886
1014
|
}
|
887
1015
|
}
|
888
1016
|
}
|
889
|
-
searchAppTree(request, engine, inEngineSpecifier) {
|
1017
|
+
async searchAppTree(request, engine, inEngineSpecifier) {
|
890
1018
|
let matched = this.getEntryFromMergeMap(inEngineSpecifier, engine.root);
|
891
1019
|
switch (matched === null || matched === void 0 ? void 0 : matched.entry.type) {
|
892
1020
|
case undefined:
|
893
1021
|
return undefined;
|
894
1022
|
case 'app-only':
|
895
|
-
return request
|
896
|
-
.alias(matched.entry['app-js'].localPath)
|
897
|
-
.rehome((0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
|
1023
|
+
return request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile);
|
898
1024
|
case 'fastboot-only':
|
899
|
-
return request
|
900
|
-
.alias(matched.entry['fastboot-js'].localPath)
|
901
|
-
.rehome((0, path_1.resolve)(matched.entry['fastboot-js'].packageRoot, 'package.json'));
|
1025
|
+
return request.alias(matched.entry['fastboot-js'].specifier).rehome(matched.entry['fastboot-js'].fromFile);
|
902
1026
|
case 'both':
|
903
|
-
let foundAppJS = this.
|
904
|
-
|
1027
|
+
let foundAppJS = await this.resolve(request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile).withMeta({
|
1028
|
+
runtimeFallback: false,
|
1029
|
+
}));
|
1030
|
+
if (foundAppJS.type !== 'found') {
|
905
1031
|
throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`);
|
906
1032
|
}
|
907
|
-
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), {});
|
1033
|
+
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), { configFile: false });
|
908
1034
|
return request.virtualize((0, virtual_content_1.fastbootSwitch)(matched.matched, (0, path_1.resolve)(engine.root, 'package.json'), names));
|
909
1035
|
}
|
910
1036
|
}
|
@@ -939,14 +1065,10 @@ class Resolver {
|
|
939
1065
|
if (engineConfig) {
|
940
1066
|
// we're directly inside an engine, so we're potentially resolvable as a
|
941
1067
|
// global component
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
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);
|
1068
|
+
let inAppName = engineRelativeName(owningPackage, filename);
|
1069
|
+
if (inAppName) {
|
1070
|
+
return this.tryReverseComponent(engineConfig.packageName, inAppName);
|
1071
|
+
}
|
950
1072
|
}
|
951
1073
|
let engineInfo = this.reverseSearchAppTree(owningPackage, filename);
|
952
1074
|
if (engineInfo) {
|
@@ -973,9 +1095,6 @@ __decorate([
|
|
973
1095
|
__decorate([
|
974
1096
|
(0, typescript_memoize_1.Memoize)()
|
975
1097
|
], Resolver.prototype, "emberVersionSupportsSeparateTemplates", null);
|
976
|
-
function isExplicitlyExternal(specifier, fromPkg) {
|
977
|
-
return Boolean(fromPkg.isV2Addon() && fromPkg.meta['externals'] && fromPkg.meta['externals'].includes(specifier));
|
978
|
-
}
|
979
1098
|
// we don't want to allow things that resolve only by accident that are likely
|
980
1099
|
// to break in other setups. For example: import your dependencies'
|
981
1100
|
// dependencies, or importing your own name from within a monorepo (which will
|
@@ -997,4 +1116,10 @@ function reliablyResolvable(pkg, packageName) {
|
|
997
1116
|
function appImportInAppTree(inPackage, inLogicalPackage, importedPackageName) {
|
998
1117
|
return inPackage !== inLogicalPackage && importedPackageName === inLogicalPackage.name;
|
999
1118
|
}
|
1119
|
+
function engineRelativeName(pkg, filename) {
|
1120
|
+
let outsideName = (0, reverse_exports_1.externalName)(pkg.packageJSON, (0, shared_internals_2.explicitRelative)(pkg.root, filename));
|
1121
|
+
if (outsideName) {
|
1122
|
+
return '.' + outsideName.slice(pkg.name.length);
|
1123
|
+
}
|
1124
|
+
}
|
1000
1125
|
//# sourceMappingURL=module-resolver.js.map
|