@embroider/core 3.4.3 → 3.4.4-unstable.7619120

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.
@@ -15,58 +15,47 @@ 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 resolve_1 = __importDefault(require("resolve"));
18
+ const reverse_exports_1 = __importDefault(require("@embroider/reverse-exports"));
19
19
  const virtual_content_1 = require("./virtual-content");
20
20
  const typescript_memoize_1 = require("typescript-memoize");
21
21
  const describe_exports_1 = require("./describe-exports");
22
22
  const fs_1 = require("fs");
23
+ const node_resolve_1 = require("./node-resolve");
23
24
  const debug = (0, debug_1.default)('embroider:resolver');
25
+ // Using a formatter makes this work lazy so nothing happens when we aren't
26
+ // logging. It is unfortunate that formatters are a globally mutable config and
27
+ // you can only use single character names, but oh well.
28
+ debug_1.default.formatters.p = (s) => {
29
+ let cwd = process.cwd();
30
+ if (s.startsWith(cwd)) {
31
+ return s.slice(cwd.length + 1);
32
+ }
33
+ return s;
34
+ };
24
35
  function logTransition(reason, before, after = before) {
25
36
  if (after.isVirtual) {
26
- debug(`virtualized %s in %s because %s`, before.specifier, before.fromFile, reason);
37
+ debug(`[%s:virtualized] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
27
38
  }
28
39
  else if (before.specifier !== after.specifier) {
29
40
  if (before.fromFile !== after.fromFile) {
30
- debug(`aliased and rehomed: %s to %s, from %s to %s because %s`, before.specifier, after.specifier, before.fromFile, after.fromFile, reason);
41
+ 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);
31
42
  }
32
43
  else {
33
- debug(`aliased: %s to %s in %s because`, before.specifier, after.specifier, before.fromFile, reason);
44
+ debug(`[%s:aliased] %s to %s\n because %s`, before.debugType, before.specifier, after.specifier, reason);
34
45
  }
35
46
  }
36
47
  else if (before.fromFile !== after.fromFile) {
37
- debug(`rehomed: %s from %s to %s because`, before.specifier, before.fromFile, after.fromFile, reason);
48
+ debug(`[%s:rehomed] %s, because %s\n from %p\n to %p`, before.debugType, before.specifier, reason, before.fromFile, after.fromFile);
49
+ }
50
+ else if (after.isNotFound) {
51
+ debug(`[%s:not-found] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
38
52
  }
39
53
  else {
40
- debug(`unchanged: %s in %s because %s`, before.specifier, before.fromFile, reason);
54
+ debug(`[%s:unchanged] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
41
55
  }
42
56
  return after;
43
57
  }
44
58
  const compatPattern = /#embroider_compat\/(?<type>[^\/]+)\/(?<rest>.*)/;
45
- class NodeModuleRequest {
46
- constructor(specifier, fromFile, isVirtual, meta) {
47
- this.specifier = specifier;
48
- this.fromFile = fromFile;
49
- this.isVirtual = isVirtual;
50
- this.meta = meta;
51
- }
52
- alias(specifier) {
53
- return new NodeModuleRequest(specifier, this.fromFile, false, this.meta);
54
- }
55
- rehome(fromFile) {
56
- if (this.fromFile === fromFile) {
57
- return this;
58
- }
59
- else {
60
- return new NodeModuleRequest(this.specifier, fromFile, false, this.meta);
61
- }
62
- }
63
- virtualize(filename) {
64
- return new NodeModuleRequest(filename, this.fromFile, true, this.meta);
65
- }
66
- withMeta(meta) {
67
- return new NodeModuleRequest(this.specifier, this.fromFile, this.isVirtual, meta);
68
- }
69
- }
70
59
  class Resolver {
71
60
  constructor(options) {
72
61
  this.options = options;
@@ -79,6 +68,9 @@ class Resolver {
79
68
  // why we need to know about it.
80
69
  return logTransition('early exit', request);
81
70
  }
71
+ if (request.specifier === 'require') {
72
+ return this.external('early require', request, request.specifier);
73
+ }
82
74
  request = this.handleFastbootSwitch(request);
83
75
  request = this.handleGlobalsCompat(request);
84
76
  request = this.handleImplicitModules(request);
@@ -140,10 +132,10 @@ class Resolver {
140
132
  if (nextRequest.fromFile === request.fromFile && nextRequest.specifier === request.specifier) {
141
133
  throw new Error('Bug Discovered! New request is not === original request but has the same fromFile and specifier. This will likely create a loop.');
142
134
  }
143
- if (nextRequest.isVirtual) {
144
- // virtual requests are terminal, there is no more beforeResolve or
145
- // fallbackResolve around them. The defaultResolve is expected to know how
146
- // to implement them.
135
+ if (nextRequest.isVirtual || nextRequest.isNotFound) {
136
+ // virtual and NotFound requests are terminal, there is no more
137
+ // beforeResolve or fallbackResolve around them. The defaultResolve is
138
+ // expected to know how to implement them.
147
139
  return yield defaultResolve(nextRequest);
148
140
  }
149
141
  return yield* this.internalResolve(nextRequest, defaultResolve);
@@ -152,39 +144,7 @@ class Resolver {
152
144
  // top. This is a convenience method for calling resolveSync with the
153
145
  // defaultResolve already configured to be "do the normal node thing".
154
146
  nodeResolve(specifier, fromFile) {
155
- let resolution = this.resolveSync(new NodeModuleRequest(specifier, fromFile, false, undefined), request => {
156
- if (request.isVirtual) {
157
- return {
158
- type: 'found',
159
- result: {
160
- type: 'virtual',
161
- content: (0, virtual_content_1.virtualContent)(request.specifier, this),
162
- filename: request.specifier,
163
- },
164
- };
165
- }
166
- try {
167
- let filename = resolve_1.default.sync(request.specifier, {
168
- basedir: (0, path_1.dirname)(request.fromFile),
169
- extensions: this.options.resolvableExtensions,
170
- });
171
- return { type: 'found', result: { type: 'real', filename } };
172
- }
173
- catch (err) {
174
- if (err.code !== 'MODULE_NOT_FOUND') {
175
- throw err;
176
- }
177
- return { type: 'not_found', err };
178
- }
179
- });
180
- switch (resolution.type) {
181
- case 'not_found':
182
- return resolution;
183
- case 'found':
184
- return resolution.result;
185
- default:
186
- throw (0, assert_never_1.default)(resolution);
187
- }
147
+ return (0, node_resolve_1.nodeResolve)(this, specifier, fromFile);
188
148
  }
189
149
  get packageCache() {
190
150
  return shared_internals_2.RewrittenPackageCache.shared('embroider', this.options.appRoot);
@@ -275,7 +235,7 @@ class Resolver {
275
235
  }
276
236
  let entry = (_a = this.getEntryFromMergeMap(rel, pkg.root)) === null || _a === void 0 ? void 0 : _a.entry;
277
237
  if ((entry === null || entry === void 0 ? void 0 : entry.type) === 'both') {
278
- return logTransition('matched addon entry', request, request.alias(entry[section].localPath).rehome((0, path_1.resolve)(entry[section].packageRoot, 'package.json')));
238
+ return logTransition('matched addon entry', request, request.alias(entry[section].specifier).rehome(entry[section].fromFile));
279
239
  }
280
240
  }
281
241
  return logTransition('failed to match in fastboot switch', request);
@@ -414,10 +374,10 @@ class Resolver {
414
374
  parseGlobalPath(path, inEngine) {
415
375
  let parts = path.split('@');
416
376
  if (parts.length > 1 && parts[0].length > 0) {
417
- return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') };
377
+ return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'package.json') };
418
378
  }
419
379
  else {
420
- return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') };
380
+ return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'package.json') };
421
381
  }
422
382
  }
423
383
  engineConfig(packageName) {
@@ -449,8 +409,8 @@ class Resolver {
449
409
  engineModules.set(inEngineName, {
450
410
  type: 'app-only',
451
411
  'app-js': {
452
- localPath: inAddonName,
453
- packageRoot: addon.root,
412
+ specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
413
+ fromFile: addonConfig.canResolveFromFile,
454
414
  fromPackageName: addon.name,
455
415
  },
456
416
  });
@@ -463,8 +423,8 @@ class Resolver {
463
423
  engineModules.set(inEngineName, {
464
424
  type: 'both',
465
425
  'app-js': {
466
- localPath: inAddonName,
467
- packageRoot: addon.root,
426
+ specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
427
+ fromFile: addonConfig.canResolveFromFile,
468
428
  fromPackageName: addon.name,
469
429
  },
470
430
  'fastboot-js': prevEntry['fastboot-js'],
@@ -488,8 +448,8 @@ class Resolver {
488
448
  engineModules.set(inEngineName, {
489
449
  type: 'fastboot-only',
490
450
  'fastboot-js': {
491
- localPath: inAddonName,
492
- packageRoot: addon.root,
451
+ specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
452
+ fromFile: addonConfig.canResolveFromFile,
493
453
  fromPackageName: addon.name,
494
454
  },
495
455
  });
@@ -502,8 +462,8 @@ class Resolver {
502
462
  engineModules.set(inEngineName, {
503
463
  type: 'both',
504
464
  'fastboot-js': {
505
- localPath: inAddonName,
506
- packageRoot: addon.root,
465
+ specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
466
+ fromFile: addonConfig.canResolveFromFile,
507
467
  fromPackageName: addon.name,
508
468
  },
509
469
  'app-js': prevEntry['app-js'],
@@ -525,7 +485,7 @@ class Resolver {
525
485
  return owningEngine;
526
486
  }
527
487
  handleRewrittenPackages(request) {
528
- if (request.isVirtual) {
488
+ if (request.isVirtual || request.isNotFound) {
529
489
  return request;
530
490
  }
531
491
  let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
@@ -544,10 +504,6 @@ class Resolver {
544
504
  targetPkg = this.packageCache.resolve(packageName, requestingPkg);
545
505
  }
546
506
  catch (err) {
547
- // this is not the place to report resolution failures. If the thing
548
- // doesn't resolve, we're just not interested in redirecting it for
549
- // backward-compat, that's all. The rest of the system will take care of
550
- // reporting a failure to resolve (or handling it a different way)
551
507
  if (err.code !== 'MODULE_NOT_FOUND') {
552
508
  throw err;
553
509
  }
@@ -563,14 +519,26 @@ class Resolver {
563
519
  return logTransition('request targets a moved package', request, this.resolveWithinMovedPackage(request, targetPkg));
564
520
  }
565
521
  else if (originalRequestingPkg !== requestingPkg) {
566
- // in this case, the requesting package is moved but its destination is
567
- // not, so we need to rehome the request back to the original location.
568
- return logTransition('outbound request from moved package', request, request.withMeta({ wasMovedTo: request.fromFile }).rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
522
+ if (targetPkg) {
523
+ // in this case, the requesting package is moved but its destination is
524
+ // not, so we need to rehome the request back to the original location.
525
+ return logTransition('outbound request from moved package', request, request
526
+ // setting meta here because if this fails, we want the fallback
527
+ // logic to revert our rehome and continue from the *moved* package.
528
+ .withMeta({ originalFromFile: request.fromFile })
529
+ .rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
530
+ }
531
+ else {
532
+ // requesting package was moved and we failed to find its target. We
533
+ // can't let that accidentally succeed in the defaultResolve because we
534
+ // could escape the moved package system.
535
+ return logTransition('missing outbound request from moved package', request, request.notFound());
536
+ }
569
537
  }
570
538
  return request;
571
539
  }
572
540
  handleRenaming(request) {
573
- if (request.isVirtual) {
541
+ if (request.isVirtual || request.isNotFound) {
574
542
  return request;
575
543
  }
576
544
  let packageName = (0, shared_internals_1.packageName)(request.specifier);
@@ -608,7 +576,10 @@ class Resolver {
608
576
  // packages get this help, v2 packages are natively supposed to make their
609
577
  // own modules resolvable, and we want to push them all to do that
610
578
  // correctly.
611
- return logTransition(`v1 self-import`, request, request.alias(request.specifier.replace(pkg.name, '.')).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
579
+ // "my-package/foo" -> "./foo"
580
+ // "my-package" -> "./" (this can't be just "." because node's require.resolve doesn't reliable support that)
581
+ let selfImportPath = request.specifier === pkg.name ? './' : request.specifier.replace(pkg.name, '.');
582
+ return logTransition(`v1 self-import`, request, request.alias(selfImportPath).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
612
583
  }
613
584
  return request;
614
585
  }
@@ -617,16 +588,17 @@ class Resolver {
617
588
  if (pkg.name.startsWith('@')) {
618
589
  levels.push('..');
619
590
  }
591
+ let originalFromFile = request.fromFile;
620
592
  let newRequest = request.rehome((0, path_1.resolve)(pkg.root, ...levels, 'moved-package-target.js'));
621
593
  if (newRequest === request) {
622
594
  return request;
623
595
  }
624
- return newRequest.withMeta({
625
- resolvedWithinPackage: pkg.root,
626
- });
596
+ // setting meta because if this fails, we want the fallback to pick up back
597
+ // in the original requesting package.
598
+ return newRequest.withMeta({ originalFromFile });
627
599
  }
628
600
  preHandleExternal(request) {
629
- if (request.isVirtual) {
601
+ if (request.isVirtual || request.isNotFound) {
630
602
  return request;
631
603
  }
632
604
  let { specifier, fromFile } = request;
@@ -659,7 +631,15 @@ class Resolver {
659
631
  // engine
660
632
  let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
661
633
  if (logicalLocation) {
662
- return logTransition('beforeResolve: relative import in app-js', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
634
+ return logTransition('beforeResolve: relative import in app-js', request, request
635
+ .alias('./' + path_1.posix.join((0, path_1.dirname)(logicalLocation.inAppName), request.specifier))
636
+ // it's important that we're rehoming this to the root of the engine
637
+ // (which we know really exists), and not to a subdir like
638
+ // logicalLocation.inAppName (which might not physically exist),
639
+ // because some environments (including node's require.resolve) will
640
+ // refuse to do resolution from a notional path that doesn't
641
+ // physically exist.
642
+ .rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
663
643
  }
664
644
  return request;
665
645
  }
@@ -674,11 +654,11 @@ class Resolver {
674
654
  if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
675
655
  // addons (whether auto-upgraded or not) may use the app's
676
656
  // emberVirtualPeerDeps, like "@glimmer/component" etc.
677
- if (!this.options.activeAddons[packageName]) {
678
- throw new Error(`${pkg.name} is trying to import the app's ${packageName} package, but it seems to be missing`);
657
+ let addon = this.locateActiveAddon(packageName);
658
+ if (!addon) {
659
+ throw new Error(`${pkg.name} is trying to import the emberVirtualPeerDep "${packageName}", but it seems to be missing`);
679
660
  }
680
- let newHome = (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json');
681
- return logTransition(`emberVirtualPeerDeps in v2 addon`, request, request.rehome(newHome));
661
+ return logTransition(`emberVirtualPeerDeps`, request, request.rehome(addon.canResolveFromFile));
682
662
  }
683
663
  // if this file is part of an addon's app-js, it's really the logical
684
664
  // package to which it belongs (normally the app) that affects some policy
@@ -709,6 +689,22 @@ class Resolver {
709
689
  }
710
690
  return request;
711
691
  }
692
+ locateActiveAddon(packageName) {
693
+ if (packageName === this.options.modulePrefix) {
694
+ // the app itself is something that addon's can classically resolve if they know it's name.
695
+ return {
696
+ root: this.options.appRoot,
697
+ canResolveFromFile: (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json'),
698
+ };
699
+ }
700
+ for (let engine of this.options.engines) {
701
+ for (let addon of engine.activeAddons) {
702
+ if (addon.name === packageName) {
703
+ return addon;
704
+ }
705
+ }
706
+ }
707
+ }
712
708
  external(label, request, specifier) {
713
709
  if (this.options.amdCompatibility === 'cjs') {
714
710
  let filename = (0, virtual_content_1.virtualExternalCJSModule)(specifier);
@@ -742,7 +738,7 @@ class Resolver {
742
738
  }
743
739
  }
744
740
  fallbackResolve(request) {
745
- var _a, _b, _c;
741
+ var _a;
746
742
  if (request.specifier === '@embroider/macros') {
747
743
  // the macros package is always handled directly within babel (not
748
744
  // necessarily as a real resolvable package), so we should not mess with it.
@@ -750,8 +746,7 @@ class Resolver {
750
746
  // why we need to know about it.
751
747
  return logTransition('fallback early exit', request);
752
748
  }
753
- let { specifier, fromFile } = request;
754
- if (compatPattern.test(specifier)) {
749
+ if (compatPattern.test(request.specifier)) {
755
750
  // Some kinds of compat requests get rewritten into other things
756
751
  // deterministically. For example, "#embroider_compat/helpers/whatever"
757
752
  // means only "the-current-engine/helpers/whatever", and if that doesn't
@@ -767,39 +762,33 @@ class Resolver {
767
762
  // here.
768
763
  return request;
769
764
  }
770
- if (fromFile.endsWith('moved-package-target.js')) {
771
- if (!((_a = request.meta) === null || _a === void 0 ? void 0 : _a.resolvedWithinPackage)) {
772
- throw new Error(`bug: embroider resolver's meta is not propagating`);
773
- }
774
- fromFile = (0, path_1.resolve)((_b = request.meta) === null || _b === void 0 ? void 0 : _b.resolvedWithinPackage, 'package.json');
775
- }
776
- let pkg = this.packageCache.ownerOfFile(fromFile);
765
+ let pkg = this.packageCache.ownerOfFile(request.fromFile);
777
766
  if (!pkg) {
778
767
  return logTransition('no identifiable owningPackage', request);
779
768
  }
780
- // if we rehomed this request to its un-rewritten location in order to try
781
- // to do the defaultResolve from there, now we refer back to the rewritten
782
- // location because that's what we want to use when asking things like
783
- // isV2Ember()
769
+ // meta.originalFromFile gets set when we want to try to rehome a request
770
+ // but then come back to the original location here in the fallback when the
771
+ // rehomed request fails
784
772
  let movedPkg = this.packageCache.maybeMoved(pkg);
785
773
  if (movedPkg !== pkg) {
786
- if (!((_c = request.meta) === null || _c === void 0 ? void 0 : _c.wasMovedTo)) {
774
+ let originalFromFile = (_a = request.meta) === null || _a === void 0 ? void 0 : _a.originalFromFile;
775
+ if (typeof originalFromFile !== 'string') {
787
776
  throw new Error(`bug: embroider resolver's meta is not propagating`);
788
777
  }
789
- fromFile = request.meta.wasMovedTo;
778
+ request = request.rehome(originalFromFile);
790
779
  pkg = movedPkg;
791
780
  }
792
781
  if (!pkg.isV2Ember()) {
793
782
  return logTransition('fallbackResolve: not in an ember package', request);
794
783
  }
795
- let packageName = (0, shared_internals_1.packageName)(specifier);
784
+ let packageName = (0, shared_internals_1.packageName)(request.specifier);
796
785
  if (!packageName) {
797
786
  // this is a relative import
798
787
  let withinEngine = this.engineConfig(pkg.name);
799
788
  if (withinEngine) {
800
789
  // it's a relative import inside an engine (which also means app), which
801
790
  // means we may need to satisfy the request via app tree merging.
802
- let appJSMatch = this.searchAppTree(request, withinEngine, (0, shared_internals_2.explicitRelative)(pkg.root, (0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier)));
791
+ let appJSMatch = this.searchAppTree(request, withinEngine, (0, shared_internals_2.explicitRelative)(pkg.root, (0, path_1.resolve)((0, path_1.dirname)(request.fromFile), request.specifier)));
803
792
  if (appJSMatch) {
804
793
  return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
805
794
  }
@@ -813,23 +802,32 @@ class Resolver {
813
802
  }
814
803
  }
815
804
  // auto-upgraded packages can fall back to the set of known active addons
816
- if (pkg.meta['auto-upgraded'] && this.options.activeAddons[packageName]) {
817
- const rehomed = this.resolveWithinMovedPackage(request, this.packageCache.get(this.options.activeAddons[packageName]));
818
- if (rehomed !== request) {
819
- return logTransition(`activeAddons`, request, rehomed);
805
+ if (pkg.meta['auto-upgraded']) {
806
+ let addon = this.locateActiveAddon(packageName);
807
+ if (addon) {
808
+ const rehomed = request.rehome(addon.canResolveFromFile);
809
+ if (rehomed !== request) {
810
+ return logTransition(`activeAddons`, request, rehomed);
811
+ }
820
812
  }
821
813
  }
822
- let logicalLocation = this.reverseSearchAppTree(pkg, fromFile);
814
+ let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
823
815
  if (logicalLocation) {
824
816
  // the requesting file is in an addon's appTree. We didn't succeed in
825
817
  // resolving this (non-relative) request from inside the actual addon, so
826
818
  // next try to resolve it from the corresponding logical location in the
827
819
  // app.
828
- return logTransition('fallbackResolve: retry from logical home of app-js file', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
820
+ return logTransition('fallbackResolve: retry from logical home of app-js file', request,
821
+ // it might look more precise to rehome into logicalLocation.inAppName
822
+ // rather than package.json. But that logical location may not actually
823
+ // exist, and some systems (including node's require.resolve) will be
824
+ // mad about trying to resolve from notional paths that don't really
825
+ // exist.
826
+ request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
829
827
  }
830
828
  let targetingEngine = this.engineConfig(packageName);
831
829
  if (targetingEngine) {
832
- let appJSMatch = this.searchAppTree(request, targetingEngine, specifier.replace(packageName, '.'));
830
+ let appJSMatch = this.searchAppTree(request, targetingEngine, request.specifier.replace(packageName, '.'));
833
831
  if (appJSMatch) {
834
832
  return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
835
833
  }
@@ -839,14 +837,14 @@ class Resolver {
839
837
  // runtime. Native v2 packages can only get this behavior in the
840
838
  // isExplicitlyExternal case above because they need to explicitly ask for
841
839
  // externals.
842
- return this.external('v1 catch-all fallback', request, specifier);
840
+ return this.external('v1 catch-all fallback', request, request.specifier);
843
841
  }
844
842
  else {
845
843
  // native v2 packages don't automatically externalize *everything* the way
846
844
  // auto-upgraded packages do, but they still externalize known and approved
847
845
  // ember virtual packages (like @ember/component)
848
846
  if (shared_internals_1.emberVirtualPackages.has(packageName)) {
849
- return this.external('emberVirtualPackages', request, specifier);
847
+ return this.external('emberVirtualPackages', request, request.specifier);
850
848
  }
851
849
  }
852
850
  // this is falling through with the original specifier which was
@@ -879,15 +877,11 @@ class Resolver {
879
877
  case undefined:
880
878
  return undefined;
881
879
  case 'app-only':
882
- return request
883
- .alias(matched.entry['app-js'].localPath)
884
- .rehome((0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
880
+ return request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile);
885
881
  case 'fastboot-only':
886
- return request
887
- .alias(matched.entry['fastboot-js'].localPath)
888
- .rehome((0, path_1.resolve)(matched.entry['fastboot-js'].packageRoot, 'package.json'));
882
+ return request.alias(matched.entry['fastboot-js'].specifier).rehome(matched.entry['fastboot-js'].fromFile);
889
883
  case 'both':
890
- let foundAppJS = this.nodeResolve(matched.entry['app-js'].localPath, (0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
884
+ let foundAppJS = this.nodeResolve(matched.entry['app-js'].specifier, matched.entry['app-js'].fromFile);
891
885
  if (foundAppJS.type !== 'real') {
892
886
  throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`);
893
887
  }