@embroider/core 3.4.20-unstable.aaeb674 → 3.4.20-unstable.b470496

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.
Files changed (42) hide show
  1. package/package.json +5 -5
  2. package/src/index.d.ts +3 -3
  3. package/src/index.js +3 -3
  4. package/src/index.js.map +1 -1
  5. package/src/module-request.d.ts +43 -0
  6. package/src/module-request.js +91 -0
  7. package/src/module-request.js.map +1 -0
  8. package/src/module-resolver-options.d.ts +0 -2
  9. package/src/module-resolver-options.js +0 -3
  10. package/src/module-resolver-options.js.map +1 -1
  11. package/src/module-resolver.d.ts +1 -29
  12. package/src/module-resolver.js +125 -198
  13. package/src/module-resolver.js.map +1 -1
  14. package/src/node-resolve.d.ts +13 -16
  15. package/src/node-resolve.js +38 -57
  16. package/src/node-resolve.js.map +1 -1
  17. package/src/options.d.ts +0 -3
  18. package/src/options.js.map +1 -1
  19. package/src/virtual-content.d.ts +24 -12
  20. package/src/virtual-content.js +35 -218
  21. package/src/virtual-content.js.map +1 -1
  22. package/src/virtual-entrypoint.d.ts +4 -2
  23. package/src/virtual-entrypoint.js +2 -18
  24. package/src/virtual-entrypoint.js.map +1 -1
  25. package/src/virtual-route-entrypoint.d.ts +4 -9
  26. package/src/virtual-route-entrypoint.js +5 -44
  27. package/src/virtual-route-entrypoint.js.map +1 -1
  28. package/src/virtual-test-support-styles.d.ts +5 -2
  29. package/src/virtual-test-support-styles.js +2 -5
  30. package/src/virtual-test-support-styles.js.map +1 -1
  31. package/src/virtual-test-support.d.ts +5 -2
  32. package/src/virtual-test-support.js +2 -5
  33. package/src/virtual-test-support.js.map +1 -1
  34. package/src/virtual-vendor-styles.d.ts +5 -1
  35. package/src/virtual-vendor-styles.js +2 -1
  36. package/src/virtual-vendor-styles.js.map +1 -1
  37. package/src/virtual-vendor.d.ts +5 -2
  38. package/src/virtual-vendor.js +6 -25
  39. package/src/virtual-vendor.js.map +1 -1
  40. package/src/to-broccoli-plugin.d.ts +0 -8
  41. package/src/to-broccoli-plugin.js +0 -30
  42. package/src/to-broccoli-plugin.js.map +0 -1
@@ -17,12 +17,10 @@ const debug_1 = __importDefault(require("debug"));
17
17
  const assert_never_1 = __importDefault(require("assert-never"));
18
18
  const reverse_exports_1 = require("@embroider/reverse-exports");
19
19
  const resolve_exports_1 = require("resolve.exports");
20
- 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
23
  const node_resolve_1 = require("./node-resolve");
25
- const virtual_route_entrypoint_1 = require("./virtual-route-entrypoint");
26
24
  const semver_1 = require("semver");
27
25
  const debug = (0, debug_1.default)('embroider:resolver');
28
26
  // Using a formatter makes this work lazy so nothing happens when we aren't
@@ -36,10 +34,7 @@ debug_1.default.formatters.p = (s) => {
36
34
  return s;
37
35
  };
38
36
  function logTransition(reason, before, after = before) {
39
- if (after.isVirtual) {
40
- debug(`[%s:virtualized] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
41
- }
42
- else if (after.resolvedTo) {
37
+ if (after.resolvedTo) {
43
38
  debug(`[%s:resolvedTo] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
44
39
  }
45
40
  else if (before.specifier !== after.specifier) {
@@ -53,17 +48,11 @@ function logTransition(reason, before, after = before) {
53
48
  else if (before.fromFile !== after.fromFile) {
54
49
  debug(`[%s:rehomed] %s, because %s\n from %p\n to %p`, before.debugType, before.specifier, reason, before.fromFile, after.fromFile);
55
50
  }
56
- else if (after.isNotFound) {
57
- debug(`[%s:not-found] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
58
- }
59
51
  else {
60
52
  debug(`[%s:unchanged] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
61
53
  }
62
54
  return after;
63
55
  }
64
- function isTerminal(request) {
65
- return request.isVirtual || request.isNotFound || Boolean(request.resolvedTo);
66
- }
67
56
  const compatPattern = /@embroider\/virtual\/(?<type>[^\/]+)\/(?<rest>.*)/;
68
57
  class Resolver {
69
58
  constructor(options) {
@@ -77,9 +66,6 @@ class Resolver {
77
66
  // why we need to know about it.
78
67
  return logTransition('early exit', request);
79
68
  }
80
- if (request.specifier === 'require') {
81
- return this.external('early require', request, request.specifier);
82
- }
83
69
  request = this.handleFastbootSwitch(request);
84
70
  request = await this.handleGlobalsCompat(request);
85
71
  request = this.handleImplicitModules(request);
@@ -105,36 +91,43 @@ class Resolver {
105
91
  // rules.
106
92
  async resolve(request) {
107
93
  request = await this.beforeResolve(request);
94
+ let resolution;
108
95
  if (request.resolvedTo) {
109
- return request.resolvedTo;
96
+ if (typeof request.resolvedTo === 'function') {
97
+ resolution = await request.resolvedTo();
98
+ }
99
+ else {
100
+ resolution = request.resolvedTo;
101
+ }
102
+ }
103
+ else {
104
+ resolution = await request.defaultResolve();
110
105
  }
111
- let resolution = await request.defaultResolve();
112
106
  switch (resolution.type) {
113
107
  case 'found':
114
- case 'ignored':
115
108
  return resolution;
116
109
  case 'not_found':
117
110
  break;
118
111
  default:
119
112
  throw (0, assert_never_1.default)(resolution);
120
113
  }
114
+ request = request.clone();
121
115
  let nextRequest = await this.fallbackResolve(request);
122
116
  if (nextRequest === request) {
123
117
  // no additional fallback is available.
124
118
  return resolution;
125
119
  }
126
120
  if (nextRequest.resolvedTo) {
127
- return nextRequest.resolvedTo;
121
+ if (typeof nextRequest.resolvedTo === 'function') {
122
+ return await nextRequest.resolvedTo();
123
+ }
124
+ else {
125
+ return nextRequest.resolvedTo;
126
+ }
128
127
  }
129
128
  if (nextRequest.fromFile === request.fromFile && nextRequest.specifier === request.specifier) {
130
129
  throw new Error('Bug Discovered! New request is not === original request but has the same fromFile and specifier. This will likely create a loop.');
131
130
  }
132
- if (nextRequest.isVirtual || nextRequest.isNotFound) {
133
- // virtual and NotFound requests are terminal, there is no more
134
- // beforeResolve or fallbackResolve around them. The defaultResolve is
135
- // expected to know how to implement them.
136
- return nextRequest.defaultResolve();
137
- }
138
131
  return this.resolve(nextRequest);
139
132
  }
140
133
  // Use standard NodeJS resolving, with our required compatibility rules on
@@ -158,7 +151,7 @@ class Resolver {
158
151
  return owningPackage;
159
152
  }
160
153
  generateFastbootSwitch(request) {
161
- if (isTerminal(request)) {
154
+ if (request.resolvedTo) {
162
155
  return request;
163
156
  }
164
157
  let pkg = this.packageCache.ownerOfFile(request.fromFile);
@@ -181,8 +174,8 @@ class Resolver {
181
174
  let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)((0, path_1.resolve)(pkg.root, fastbootFile.shadowedFilename), 'utf8'), {
182
175
  configFile: false,
183
176
  });
184
- let switchFile = (0, virtual_content_1.fastbootSwitch)(candidate, (0, path_1.resolve)(pkg.root, 'package.json'), names);
185
- if (switchFile === request.fromFile) {
177
+ let switchFile = fastbootSwitch(candidate, (0, path_1.resolve)(pkg.root, 'package.json'), names);
178
+ if (switchFile.specifier === request.fromFile) {
186
179
  return logTransition('internal lookup from fastbootSwitch', request);
187
180
  }
188
181
  else {
@@ -199,10 +192,10 @@ class Resolver {
199
192
  }
200
193
  handleFastbootSwitch(request) {
201
194
  var _a;
202
- if (isTerminal(request)) {
195
+ if (request.resolvedTo) {
203
196
  return request;
204
197
  }
205
- let match = (0, virtual_content_1.decodeFastbootSwitch)(request.fromFile);
198
+ let match = decodeFastbootSwitch(request.fromFile);
206
199
  if (!match) {
207
200
  return request;
208
201
  }
@@ -246,71 +239,77 @@ class Resolver {
246
239
  return logTransition('failed to match in fastboot switch', request);
247
240
  }
248
241
  handleImplicitModules(request) {
249
- if (isTerminal(request)) {
250
- return request;
251
- }
252
- let im = (0, virtual_content_1.decodeImplicitModules)(request.specifier);
253
- if (!im) {
242
+ if (request.resolvedTo) {
254
243
  return request;
255
244
  }
256
- let pkg = this.packageCache.ownerOfFile(request.fromFile);
257
- if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
258
- throw new Error(`bug: found implicit modules import in non-ember package at ${request.fromFile}`);
259
- }
260
- let packageName = (0, shared_internals_1.packageName)(im.fromFile);
261
- if (packageName) {
262
- let dep = this.packageCache.resolve(packageName, pkg);
263
- return logTransition(`dep's implicit modules`, request, request.virtualize((0, path_1.resolve)(dep.root, `-embroider-${im.type}.js`)));
264
- }
265
- else {
266
- return logTransition(`own implicit modules`, request, request.virtualize((0, path_1.resolve)(pkg.root, `-embroider-${im.type}.js`)));
245
+ for (let variant of ['', 'test-']) {
246
+ let suffix = `-embroider-implicit-${variant}modules.js`;
247
+ if (!request.specifier.endsWith(suffix)) {
248
+ continue;
249
+ }
250
+ let filename = request.specifier.slice(0, -1 * suffix.length);
251
+ if (!filename.endsWith('/') && filename.endsWith('\\')) {
252
+ continue;
253
+ }
254
+ filename = filename.slice(0, -1);
255
+ let pkg = this.packageCache.ownerOfFile(request.fromFile);
256
+ if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
257
+ throw new Error(`bug: found implicit modules import in non-ember package at ${request.fromFile}`);
258
+ }
259
+ let type = `implicit-${variant}modules`;
260
+ let packageName = (0, shared_internals_1.packageName)(filename);
261
+ if (packageName) {
262
+ let dep = this.packageCache.resolve(packageName, pkg);
263
+ return logTransition(`dep's implicit modules`, request, request.virtualize({ type, specifier: (0, path_1.resolve)(dep.root, `-embroider-${type}.js`), fromFile: dep.root }));
264
+ }
265
+ else {
266
+ return logTransition(`own implicit modules`, request, request.virtualize({ type, specifier: (0, path_1.resolve)(pkg.root, `-embroider-${type}.js`), fromFile: pkg.root }));
267
+ }
267
268
  }
269
+ return request;
268
270
  }
269
271
  handleEntrypoint(request) {
270
272
  var _a;
271
- if (isTerminal(request)) {
273
+ if (request.resolvedTo) {
272
274
  return request;
273
275
  }
274
- //TODO move the extra forwardslash handling out into the vite plugin
275
- const candidates = [
276
- '@embroider/virtual/compat-modules',
277
- '/@embroider/virtual/compat-modules',
278
- './@embroider/virtual/compat-modules',
279
- ];
280
- if (!candidates.some(c => request.specifier.startsWith(c + '/') || request.specifier === c)) {
276
+ const compatModulesSpecifier = '@embroider/virtual/compat-modules';
277
+ let isCompatModules = request.specifier === compatModulesSpecifier || request.specifier.startsWith(compatModulesSpecifier + '/');
278
+ if (!isCompatModules) {
281
279
  return request;
282
280
  }
283
- const result = /\.?\/?@embroider\/virtual\/compat-modules(?:\/(?<packageName>.*))?/.exec(request.specifier);
284
- if (!result) {
285
- // TODO make a better error
286
- throw new Error('entrypoint does not match pattern' + request.specifier);
287
- }
288
- const { packageName } = result.groups;
289
281
  const requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
290
282
  if (!(requestingPkg === null || requestingPkg === void 0 ? void 0 : requestingPkg.isV2Ember())) {
291
283
  throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
292
284
  }
293
285
  let pkg;
294
- if (packageName) {
295
- pkg = this.packageCache.resolve(packageName, requestingPkg);
286
+ if (request.specifier === compatModulesSpecifier) {
287
+ pkg = requestingPkg;
296
288
  }
297
289
  else {
298
- pkg = requestingPkg;
290
+ let packageName = request.specifier.slice(compatModulesSpecifier.length + 1);
291
+ pkg = this.packageCache.resolve(packageName, requestingPkg);
299
292
  }
300
293
  let matched = (0, resolve_exports_1.exports)(pkg.packageJSON, '-embroider-entrypoint.js', {
301
294
  browser: true,
302
295
  conditions: ['default', 'imports'],
303
296
  });
304
- 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')));
297
+ let specifier = (0, path_1.resolve)(pkg.root, (_a = matched === null || matched === void 0 ? void 0 : matched[0]) !== null && _a !== void 0 ? _a : '-embroider-entrypoint.js');
298
+ return logTransition('entrypoint', request, request.virtualize({
299
+ type: 'entrypoint',
300
+ specifier,
301
+ fromDir: (0, path_1.dirname)(specifier),
302
+ }));
305
303
  }
306
304
  handleRouteEntrypoint(request) {
307
- if (isTerminal(request)) {
305
+ if (request.resolvedTo) {
308
306
  return request;
309
307
  }
310
- let routeName = (0, virtual_route_entrypoint_1.decodePublicRouteEntrypoint)(request.specifier);
311
- if (!routeName) {
308
+ const publicPrefix = '@embroider/core/route/';
309
+ if (!request.specifier.startsWith(publicPrefix)) {
312
310
  return request;
313
311
  }
312
+ let routeName = request.specifier.slice(publicPrefix.length);
314
313
  let pkg = this.packageCache.ownerOfFile(request.fromFile);
315
314
  if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
316
315
  throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
@@ -319,42 +318,35 @@ class Resolver {
319
318
  browser: true,
320
319
  conditions: ['default', 'imports'],
321
320
  });
322
- 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)));
321
+ let target = matched ? `${matched}:route=${routeName}` : `-embroider-route-entrypoint.js:route=${routeName}`;
322
+ let specifier = (0, path_1.resolve)(pkg.root, target);
323
+ return logTransition('route entrypoint', request, request.virtualize({ type: 'route-entrypoint', specifier, route: routeName, fromDir: (0, path_1.dirname)(specifier) }));
323
324
  }
324
325
  handleImplicitTestScripts(request) {
325
- //TODO move the extra forwardslash handling out into the vite plugin
326
- const candidates = [
327
- '@embroider/virtual/test-support.js',
328
- '/@embroider/virtual/test-support.js',
329
- './@embroider/virtual/test-support.js',
330
- ];
331
- if (!candidates.includes(request.specifier)) {
326
+ if (request.specifier !== '@embroider/virtual/test-support.js') {
332
327
  return request;
333
328
  }
334
329
  let pkg = this.packageCache.ownerOfFile(request.fromFile);
335
330
  if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
336
331
  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.`);
337
332
  }
338
- return logTransition('test-support', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support.js')));
333
+ return logTransition('test-support', request, request.virtualize({ type: 'test-support-js', specifier: (0, path_1.resolve)(pkg.root, '-embroider-test-support.js') }));
339
334
  }
340
335
  handleTestSupportStyles(request) {
341
- //TODO move the extra forwardslash handling out into the vite plugin
342
- const candidates = [
343
- '@embroider/virtual/test-support.css',
344
- '/@embroider/virtual/test-support.css',
345
- './@embroider/virtual/test-support.css',
346
- ];
347
- if (!candidates.includes(request.specifier)) {
336
+ if (request.specifier !== '@embroider/virtual/test-support.css') {
348
337
  return request;
349
338
  }
350
339
  let pkg = this.packageCache.ownerOfFile(request.fromFile);
351
340
  if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
352
341
  throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/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.`);
353
342
  }
354
- return logTransition('test-support-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support-styles.css')));
343
+ return logTransition('test-support-styles', request, request.virtualize({
344
+ type: 'test-support-css',
345
+ specifier: (0, path_1.resolve)(pkg.root, '-embroider-test-support-styles.css'),
346
+ }));
355
347
  }
356
348
  async handleGlobalsCompat(request) {
357
- if (isTerminal(request)) {
349
+ if (request.resolvedTo) {
358
350
  return request;
359
351
  }
360
352
  let match = compatPattern.exec(request.specifier);
@@ -381,35 +373,28 @@ class Resolver {
381
373
  }
382
374
  }
383
375
  handleVendorStyles(request) {
384
- //TODO move the extra forwardslash handling out into the vite plugin
385
- const candidates = [
386
- '@embroider/virtual/vendor.css',
387
- '/@embroider/virtual/vendor.css',
388
- './@embroider/virtual/vendor.css',
389
- ];
390
- if (!candidates.includes(request.specifier)) {
376
+ if (request.specifier !== '@embroider/virtual/vendor.css') {
391
377
  return request;
392
378
  }
393
379
  let pkg = this.packageCache.ownerOfFile(request.fromFile);
394
380
  if (!pkg || !this.options.engines.some(e => e.root === (pkg === null || pkg === void 0 ? void 0 : pkg.root))) {
395
381
  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.`);
396
382
  }
397
- return logTransition('vendor-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor-styles.css')));
383
+ return logTransition('vendor-styles', request, request.virtualize({ type: 'vendor-css', specifier: (0, path_1.resolve)(pkg.root, '-embroider-vendor-styles.css') }));
398
384
  }
399
385
  resolveHelper(path, inEngine, request) {
400
386
  let target = this.parseGlobalPath(path, inEngine);
401
387
  return logTransition('resolveHelper', request, request.alias(`${target.packageName}/helpers/${target.memberName}`).rehome((0, path_1.resolve)(inEngine.root, 'package.json')));
402
388
  }
403
389
  async resolveComponent(path, inEngine, request) {
390
+ var _a, _b;
404
391
  let target = this.parseGlobalPath(path, inEngine);
405
392
  let hbsModule = null;
406
393
  let jsModule = null;
407
394
  // first, the various places our template might be.
408
395
  for (let candidate of this.componentTemplateCandidates(target.packageName)) {
409
396
  let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;
410
- let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from).withMeta({
411
- runtimeFallback: false,
412
- }));
397
+ let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from));
413
398
  if (resolution.type === 'found') {
414
399
  hbsModule = resolution;
415
400
  break;
@@ -418,12 +403,7 @@ class Resolver {
418
403
  // then the various places our javascript might be.
419
404
  for (let candidate of this.componentJSCandidates(target.packageName)) {
420
405
  let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;
421
- let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from).withMeta({
422
- runtimeFallback: false,
423
- }));
424
- if (resolution.type === 'ignored') {
425
- return logTransition(`resolving to ignored component`, request, request.resolveTo(resolution));
426
- }
406
+ let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from));
427
407
  // .hbs is a resolvable extension for us, so we need to exclude it here.
428
408
  // It matches as a priority lower than .js, so finding an .hbs means
429
409
  // there's definitely not a .js.
@@ -434,9 +414,15 @@ class Resolver {
434
414
  }
435
415
  if (hbsModule) {
436
416
  if (!this.emberVersionSupportsSeparateTemplates) {
437
- 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}.`);
417
+ 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}.`);
438
418
  }
439
- 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)));
419
+ return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize({
420
+ type: 'component-pair',
421
+ hbsModule: hbsModule.filename,
422
+ jsModule: (_a = jsModule === null || jsModule === void 0 ? void 0 : jsModule.filename) !== null && _a !== void 0 ? _a : null,
423
+ debugName: (0, path_1.basename)(hbsModule.filename).replace(/\.(js|hbs)$/, ''),
424
+ specifier: `${this.options.appRoot}/embroider-pair-component/${encodeURIComponent(hbsModule.filename)}/__vpc__/${encodeURIComponent((_b = jsModule === null || jsModule === void 0 ? void 0 : jsModule.filename) !== null && _b !== void 0 ? _b : '')}`,
425
+ }));
440
426
  }
441
427
  else if (jsModule) {
442
428
  return logTransition(`resolving to resolveComponent found only JS`, request, request.resolveTo(jsModule));
@@ -450,13 +436,8 @@ class Resolver {
450
436
  // component, so here to resolve the ambiguity we need to actually resolve
451
437
  // that candidate to see if it works.
452
438
  let helperCandidate = this.resolveHelper(path, inEngine, request);
453
- let helperMatch = await this.resolve(request.alias(helperCandidate.specifier).rehome(helperCandidate.fromFile).withMeta({
454
- runtimeFallback: false,
455
- }));
456
- // for the case of 'ignored' that means that esbuild found this helper in an external
457
- // package so it should be considered found in this case and we should not look for a
458
- // component with this name
459
- if (helperMatch.type === 'found' || helperMatch.type === 'ignored') {
439
+ let helperMatch = await this.resolve(request.alias(helperCandidate.specifier).rehome(helperCandidate.fromFile));
440
+ if (helperMatch.type === 'found') {
460
441
  return logTransition('resolve to ambiguous case matched a helper', request, request.resolveTo(helperMatch));
461
442
  }
462
443
  // unlike resolveHelper, resolveComponent already does pre-resolution in
@@ -634,7 +615,7 @@ class Resolver {
634
615
  });
635
616
  }
636
617
  handleRewrittenPackages(request) {
637
- if (isTerminal(request)) {
618
+ if (request.resolvedTo) {
638
619
  return request;
639
620
  }
640
621
  let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
@@ -687,7 +668,7 @@ class Resolver {
687
668
  return request;
688
669
  }
689
670
  handleRenaming(request) {
690
- if (isTerminal(request)) {
671
+ if (request.resolvedTo) {
691
672
  return request;
692
673
  }
693
674
  let packageName = (0, shared_internals_1.packageName)(request.specifier);
@@ -759,20 +740,14 @@ class Resolver {
759
740
  return request;
760
741
  }
761
742
  handleVendor(request) {
762
- //TODO move the extra forwardslash handling out into the vite plugin
763
- const candidates = [
764
- '@embroider/virtual/vendor.js',
765
- '/@embroider/virtual/vendor.js',
766
- './@embroider/virtual/vendor.js',
767
- ];
768
- if (!candidates.includes(request.specifier)) {
743
+ if (request.specifier !== '@embroider/virtual/vendor.js') {
769
744
  return request;
770
745
  }
771
746
  let pkg = this.packageCache.ownerOfFile(request.fromFile);
772
747
  if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) {
773
748
  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.`);
774
749
  }
775
- return logTransition('vendor', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor.js')));
750
+ return logTransition('vendor', request, request.virtualize({ type: 'vendor-js', specifier: (0, path_1.resolve)(pkg.root, '-embroider-vendor.js') }));
776
751
  }
777
752
  resolveWithinMovedPackage(request, pkg) {
778
753
  let levels = ['..'];
@@ -789,7 +764,7 @@ class Resolver {
789
764
  return newRequest.withMeta({ originalFromFile });
790
765
  }
791
766
  preHandleExternal(request) {
792
- if (isTerminal(request)) {
767
+ if (request.resolvedTo) {
793
768
  return request;
794
769
  }
795
770
  let { specifier, fromFile } = request;
@@ -799,11 +774,6 @@ class Resolver {
799
774
  }
800
775
  let packageName = (0, shared_internals_1.packageName)(specifier);
801
776
  if (!packageName) {
802
- // This is a relative import. We don't automatically externalize those
803
- // because it's rare, and by keeping them static we give better errors. But
804
- // we do allow them to be explicitly externalized by the package author (or
805
- // a compat adapter). In the metadata, they would be listed in
806
- // package-relative form, so we need to convert this specifier to that.
807
777
  let absoluteSpecifier = (0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier);
808
778
  if (!absoluteSpecifier.startsWith(pkg.root)) {
809
779
  // this relative path escape its package. So it's not really using
@@ -812,11 +782,6 @@ class Resolver {
812
782
  // references to runtime utilities, like we do in @embroider/macros.
813
783
  return logTransition('beforeResolve: relative path escapes its package', request);
814
784
  }
815
- let packageRelativeSpecifier = (0, shared_internals_2.explicitRelative)(pkg.root, absoluteSpecifier);
816
- if (isExplicitlyExternal(packageRelativeSpecifier, pkg)) {
817
- let publicSpecifier = absoluteSpecifier.replace(pkg.root, pkg.name);
818
- return this.external('beforeResolve', request, publicSpecifier);
819
- }
820
785
  // if the requesting file is in an addon's app-js, the relative request
821
786
  // should really be understood as a request for a module in the containing
822
787
  // engine.
@@ -826,14 +791,6 @@ class Resolver {
826
791
  }
827
792
  return request;
828
793
  }
829
- // absolute package imports can also be explicitly external based on their
830
- // full specifier name
831
- if (isExplicitlyExternal(specifier, pkg)) {
832
- return this.external('beforeResolve', request, specifier);
833
- }
834
- if (shared_internals_1.emberVirtualPackages.has(packageName) && !pkg.hasDependency(packageName)) {
835
- return this.external('beforeResolve emberVirtualPackages', request, specifier);
836
- }
837
794
  if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
838
795
  // addons (whether auto-upgraded or not) may use the app's
839
796
  // emberVirtualPeerDeps, like "@glimmer/component" etc.
@@ -853,7 +810,7 @@ class Resolver {
853
810
  if (!dep.isEmberAddon()) {
854
811
  // classic ember addons can only import non-ember dependencies if they
855
812
  // have ember-auto-import.
856
- return this.external('v1 package without auto-import', request, specifier);
813
+ return logTransition('v1 package without auto-import', request, request.notFound());
857
814
  }
858
815
  }
859
816
  catch (err) {
@@ -886,42 +843,9 @@ class Resolver {
886
843
  }
887
844
  }
888
845
  }
889
- external(label, request, specifier) {
890
- if (this.options.amdCompatibility === 'cjs') {
891
- let filename = (0, virtual_content_1.virtualExternalCJSModule)(specifier);
892
- return logTransition(label, request, request.virtualize(filename));
893
- }
894
- else if (this.options.amdCompatibility) {
895
- let entry = this.options.amdCompatibility.es.find(entry => entry[0] === specifier || entry[0] + '/index' === specifier);
896
- if (!entry && request.specifier === 'require') {
897
- entry = ['require', ['default', 'has']];
898
- }
899
- if (!entry) {
900
- throw new Error(`[${request.debugType}] A module tried to resolve "${request.specifier}" and didn't find it (${label}).
901
-
902
- - Maybe a dependency declaration is missing?
903
- - Remember that v1 addons can only import non-Ember-addon NPM dependencies if they include ember-auto-import in their dependencies.
904
- - If this dependency is available in the AMD loader (because someone manually called "define()" for it), you can configure a shim like:
905
-
906
- amdCompatibility: {
907
- es: [
908
- ["${request.specifier}", ["default", "yourNamedExportsGoHere"]],
909
- ]
910
- }
911
-
912
- `);
913
- }
914
- let filename = (0, virtual_content_1.virtualExternalESModule)(specifier, entry[1]);
915
- return logTransition(label, request, request.virtualize(filename));
916
- }
917
- else {
918
- throw new Error(`Embroider's amdCompatibility option is disabled, but something tried to use it to access "${request.specifier}"`);
919
- }
920
- }
921
846
  async fallbackResolve(request) {
922
- var _a, _b;
923
- if (request.isVirtual) {
924
- throw new Error('Build tool bug detected! Fallback resolve should never see a virtual request. It is expected that the defaultResolve for your bundler has already resolved this request');
847
+ if (request.resolvedTo) {
848
+ throw new Error('Build tool bug detected! Fallback resolve should never see an already-resolved request.');
925
849
  }
926
850
  if (request.specifier === '@embroider/macros') {
927
851
  // the macros package is always handled directly within babel (not
@@ -997,21 +921,6 @@ class Resolver {
997
921
  return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
998
922
  }
999
923
  }
1000
- if (pkg.needsLooseResolving() && ((_b = (_a = request.meta) === null || _a === void 0 ? void 0 : _a.runtimeFallback) !== null && _b !== void 0 ? _b : true)) {
1001
- // auto-upgraded packages can fall back to attempting to find dependencies at
1002
- // runtime. Native v2 packages can only get this behavior in the
1003
- // isExplicitlyExternal case above because they need to explicitly ask for
1004
- // externals.
1005
- return this.external('v1 catch-all fallback', request, request.specifier);
1006
- }
1007
- else {
1008
- // native v2 packages don't automatically externalize *everything* the way
1009
- // auto-upgraded packages do, but they still externalize known and approved
1010
- // ember virtual packages (like @ember/component)
1011
- if (shared_internals_1.emberVirtualPackages.has(packageName)) {
1012
- return this.external('emberVirtualPackages', request, request.specifier);
1013
- }
1014
- }
1015
924
  // this is falling through with the original specifier which was
1016
925
  // non-resolvable, which will presumably cause a static build error in stage3.
1017
926
  return logTransition('fallbackResolve final exit', request);
@@ -1094,14 +1003,12 @@ class Resolver {
1094
1003
  case 'fastboot-only':
1095
1004
  return request.alias(matched.entry['fastboot-js'].specifier).rehome(matched.entry['fastboot-js'].fromFile);
1096
1005
  case 'both':
1097
- let foundAppJS = await this.resolve(request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile).withMeta({
1098
- runtimeFallback: false,
1099
- }));
1006
+ let foundAppJS = await this.resolve(request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile));
1100
1007
  if (foundAppJS.type !== 'found') {
1101
1008
  throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`);
1102
1009
  }
1103
1010
  let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), { configFile: false });
1104
- return request.virtualize((0, virtual_content_1.fastbootSwitch)(matched.matched, (0, path_1.resolve)(engine.root, 'package.json'), names));
1011
+ return request.virtualize(fastbootSwitch(matched.matched, (0, path_1.resolve)(engine.root, 'package.json'), names));
1105
1012
  }
1106
1013
  }
1107
1014
  // check whether the given file with the given owningPackage is an addon's
@@ -1165,9 +1072,6 @@ __decorate([
1165
1072
  __decorate([
1166
1073
  (0, typescript_memoize_1.Memoize)()
1167
1074
  ], Resolver.prototype, "emberVersionSupportsSeparateTemplates", null);
1168
- function isExplicitlyExternal(specifier, fromPkg) {
1169
- return Boolean(fromPkg.isV2Addon() && fromPkg.meta['externals'] && fromPkg.meta['externals'].includes(specifier));
1170
- }
1171
1075
  // we don't want to allow things that resolve only by accident that are likely
1172
1076
  // to break in other setups. For example: import your dependencies'
1173
1077
  // dependencies, or importing your own name from within a monorepo (which will
@@ -1195,4 +1099,27 @@ function engineRelativeName(pkg, filename) {
1195
1099
  return '.' + outsideName.slice(pkg.name.length);
1196
1100
  }
1197
1101
  }
1102
+ const fastbootSwitchSuffix = '/embroider_fastboot_switch';
1103
+ function fastbootSwitch(specifier, fromFile, names) {
1104
+ let filename = `${(0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier)}${fastbootSwitchSuffix}`;
1105
+ let virtualSpecifier;
1106
+ if (names.size > 0) {
1107
+ virtualSpecifier = `${filename}?names=${[...names].join(',')}`;
1108
+ }
1109
+ else {
1110
+ virtualSpecifier = filename;
1111
+ }
1112
+ return {
1113
+ type: 'fastboot-switch',
1114
+ specifier: virtualSpecifier,
1115
+ names,
1116
+ hasDefaultExport: 'x',
1117
+ };
1118
+ }
1119
+ function decodeFastbootSwitch(filename) {
1120
+ let index = filename.indexOf(fastbootSwitchSuffix);
1121
+ if (index >= 0) {
1122
+ return { filename: filename.slice(0, index) };
1123
+ }
1124
+ }
1198
1125
  //# sourceMappingURL=module-resolver.js.map