@embroider/core 3.4.3-unstable.efd9117 → 3.4.3

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,47 +15,58 @@ 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 reverse_exports_1 = __importDefault(require("@embroider/reverse-exports"));
18
+ const resolve_1 = __importDefault(require("resolve"));
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");
24
23
  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
- };
35
24
  function logTransition(reason, before, after = before) {
36
25
  if (after.isVirtual) {
37
- debug(`[%s:virtualized] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
26
+ debug(`virtualized %s in %s because %s`, before.specifier, before.fromFile, reason);
38
27
  }
39
28
  else if (before.specifier !== after.specifier) {
40
29
  if (before.fromFile !== after.fromFile) {
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);
30
+ debug(`aliased and rehomed: %s to %s, from %s to %s because %s`, before.specifier, after.specifier, before.fromFile, after.fromFile, reason);
42
31
  }
43
32
  else {
44
- debug(`[%s:aliased] %s to %s\n because %s`, before.debugType, before.specifier, after.specifier, reason);
33
+ debug(`aliased: %s to %s in %s because`, before.specifier, after.specifier, before.fromFile, reason);
45
34
  }
46
35
  }
47
36
  else if (before.fromFile !== after.fromFile) {
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);
37
+ debug(`rehomed: %s from %s to %s because`, before.specifier, before.fromFile, after.fromFile, reason);
52
38
  }
53
39
  else {
54
- debug(`[%s:unchanged] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile);
40
+ debug(`unchanged: %s in %s because %s`, before.specifier, before.fromFile, reason);
55
41
  }
56
42
  return after;
57
43
  }
58
44
  const compatPattern = /#embroider_compat\/(?<type>[^\/]+)\/(?<rest>.*)/;
45
+ class NodeModuleRequest {
46
+ constructor(specifier, fromFile, isVirtual, meta) {
47
+ this.specifier = specifier;
48
+ this.fromFile = fromFile;
49
+ this.isVirtual = isVirtual;
50
+ this.meta = meta;
51
+ }
52
+ alias(specifier) {
53
+ return new NodeModuleRequest(specifier, this.fromFile, false, this.meta);
54
+ }
55
+ rehome(fromFile) {
56
+ if (this.fromFile === fromFile) {
57
+ return this;
58
+ }
59
+ else {
60
+ return new NodeModuleRequest(this.specifier, fromFile, false, this.meta);
61
+ }
62
+ }
63
+ virtualize(filename) {
64
+ return new NodeModuleRequest(filename, this.fromFile, true, this.meta);
65
+ }
66
+ withMeta(meta) {
67
+ return new NodeModuleRequest(this.specifier, this.fromFile, this.isVirtual, meta);
68
+ }
69
+ }
59
70
  class Resolver {
60
71
  constructor(options) {
61
72
  this.options = options;
@@ -68,9 +79,6 @@ class Resolver {
68
79
  // why we need to know about it.
69
80
  return logTransition('early exit', request);
70
81
  }
71
- if (request.specifier === 'require') {
72
- return this.external('early require', request, request.specifier);
73
- }
74
82
  request = this.handleFastbootSwitch(request);
75
83
  request = this.handleGlobalsCompat(request);
76
84
  request = this.handleImplicitModules(request);
@@ -132,10 +140,10 @@ class Resolver {
132
140
  if (nextRequest.fromFile === request.fromFile && nextRequest.specifier === request.specifier) {
133
141
  throw new Error('Bug Discovered! New request is not === original request but has the same fromFile and specifier. This will likely create a loop.');
134
142
  }
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.
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.
139
147
  return yield defaultResolve(nextRequest);
140
148
  }
141
149
  return yield* this.internalResolve(nextRequest, defaultResolve);
@@ -144,7 +152,39 @@ class Resolver {
144
152
  // top. This is a convenience method for calling resolveSync with the
145
153
  // defaultResolve already configured to be "do the normal node thing".
146
154
  nodeResolve(specifier, fromFile) {
147
- return (0, node_resolve_1.nodeResolve)(this, 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
+ }
148
188
  }
149
189
  get packageCache() {
150
190
  return shared_internals_2.RewrittenPackageCache.shared('embroider', this.options.appRoot);
@@ -235,7 +275,7 @@ class Resolver {
235
275
  }
236
276
  let entry = (_a = this.getEntryFromMergeMap(rel, pkg.root)) === null || _a === void 0 ? void 0 : _a.entry;
237
277
  if ((entry === null || entry === void 0 ? void 0 : entry.type) === 'both') {
238
- return logTransition('matched addon entry', request, request.alias(entry[section].specifier).rehome(entry[section].fromFile));
278
+ return logTransition('matched addon entry', request, request.alias(entry[section].localPath).rehome((0, path_1.resolve)(entry[section].packageRoot, 'package.json')));
239
279
  }
240
280
  }
241
281
  return logTransition('failed to match in fastboot switch', request);
@@ -374,10 +414,10 @@ class Resolver {
374
414
  parseGlobalPath(path, inEngine) {
375
415
  let parts = path.split('@');
376
416
  if (parts.length > 1 && parts[0].length > 0) {
377
- return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'package.json') };
417
+ return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') };
378
418
  }
379
419
  else {
380
- return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'package.json') };
420
+ return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') };
381
421
  }
382
422
  }
383
423
  engineConfig(packageName) {
@@ -409,8 +449,8 @@ class Resolver {
409
449
  engineModules.set(inEngineName, {
410
450
  type: 'app-only',
411
451
  'app-js': {
412
- specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
413
- fromFile: addonConfig.canResolveFromFile,
452
+ localPath: inAddonName,
453
+ packageRoot: addon.root,
414
454
  fromPackageName: addon.name,
415
455
  },
416
456
  });
@@ -423,8 +463,8 @@ class Resolver {
423
463
  engineModules.set(inEngineName, {
424
464
  type: 'both',
425
465
  'app-js': {
426
- specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
427
- fromFile: addonConfig.canResolveFromFile,
466
+ localPath: inAddonName,
467
+ packageRoot: addon.root,
428
468
  fromPackageName: addon.name,
429
469
  },
430
470
  'fastboot-js': prevEntry['fastboot-js'],
@@ -448,8 +488,8 @@ class Resolver {
448
488
  engineModules.set(inEngineName, {
449
489
  type: 'fastboot-only',
450
490
  'fastboot-js': {
451
- specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
452
- fromFile: addonConfig.canResolveFromFile,
491
+ localPath: inAddonName,
492
+ packageRoot: addon.root,
453
493
  fromPackageName: addon.name,
454
494
  },
455
495
  });
@@ -462,8 +502,8 @@ class Resolver {
462
502
  engineModules.set(inEngineName, {
463
503
  type: 'both',
464
504
  'fastboot-js': {
465
- specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
466
- fromFile: addonConfig.canResolveFromFile,
505
+ localPath: inAddonName,
506
+ packageRoot: addon.root,
467
507
  fromPackageName: addon.name,
468
508
  },
469
509
  'app-js': prevEntry['app-js'],
@@ -485,7 +525,7 @@ class Resolver {
485
525
  return owningEngine;
486
526
  }
487
527
  handleRewrittenPackages(request) {
488
- if (request.isVirtual || request.isNotFound) {
528
+ if (request.isVirtual) {
489
529
  return request;
490
530
  }
491
531
  let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
@@ -504,6 +544,10 @@ class Resolver {
504
544
  targetPkg = this.packageCache.resolve(packageName, requestingPkg);
505
545
  }
506
546
  catch (err) {
547
+ // this is not the place to report resolution failures. If the thing
548
+ // doesn't resolve, we're just not interested in redirecting it for
549
+ // backward-compat, that's all. The rest of the system will take care of
550
+ // reporting a failure to resolve (or handling it a different way)
507
551
  if (err.code !== 'MODULE_NOT_FOUND') {
508
552
  throw err;
509
553
  }
@@ -519,26 +563,14 @@ class Resolver {
519
563
  return logTransition('request targets a moved package', request, this.resolveWithinMovedPackage(request, targetPkg));
520
564
  }
521
565
  else if (originalRequestingPkg !== requestingPkg) {
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
- }
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')));
537
569
  }
538
570
  return request;
539
571
  }
540
572
  handleRenaming(request) {
541
- if (request.isVirtual || request.isNotFound) {
573
+ if (request.isVirtual) {
542
574
  return request;
543
575
  }
544
576
  let packageName = (0, shared_internals_1.packageName)(request.specifier);
@@ -576,10 +608,7 @@ class Resolver {
576
608
  // packages get this help, v2 packages are natively supposed to make their
577
609
  // own modules resolvable, and we want to push them all to do that
578
610
  // correctly.
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')));
611
+ return logTransition(`v1 self-import`, request, request.alias(request.specifier.replace(pkg.name, '.')).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
583
612
  }
584
613
  return request;
585
614
  }
@@ -588,17 +617,16 @@ class Resolver {
588
617
  if (pkg.name.startsWith('@')) {
589
618
  levels.push('..');
590
619
  }
591
- let originalFromFile = request.fromFile;
592
620
  let newRequest = request.rehome((0, path_1.resolve)(pkg.root, ...levels, 'moved-package-target.js'));
593
621
  if (newRequest === request) {
594
622
  return request;
595
623
  }
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 });
624
+ return newRequest.withMeta({
625
+ resolvedWithinPackage: pkg.root,
626
+ });
599
627
  }
600
628
  preHandleExternal(request) {
601
- if (request.isVirtual || request.isNotFound) {
629
+ if (request.isVirtual) {
602
630
  return request;
603
631
  }
604
632
  let { specifier, fromFile } = request;
@@ -631,15 +659,7 @@ class Resolver {
631
659
  // engine
632
660
  let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
633
661
  if (logicalLocation) {
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')));
662
+ return logTransition('beforeResolve: relative import in app-js', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
643
663
  }
644
664
  return request;
645
665
  }
@@ -654,11 +674,11 @@ class Resolver {
654
674
  if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
655
675
  // addons (whether auto-upgraded or not) may use the app's
656
676
  // emberVirtualPeerDeps, like "@glimmer/component" etc.
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`);
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`);
660
679
  }
661
- return logTransition(`emberVirtualPeerDeps`, request, request.rehome(addon.canResolveFromFile));
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));
662
682
  }
663
683
  // if this file is part of an addon's app-js, it's really the logical
664
684
  // package to which it belongs (normally the app) that affects some policy
@@ -689,22 +709,6 @@ class Resolver {
689
709
  }
690
710
  return request;
691
711
  }
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
- }
708
712
  external(label, request, specifier) {
709
713
  if (this.options.amdCompatibility === 'cjs') {
710
714
  let filename = (0, virtual_content_1.virtualExternalCJSModule)(specifier);
@@ -738,7 +742,7 @@ class Resolver {
738
742
  }
739
743
  }
740
744
  fallbackResolve(request) {
741
- var _a;
745
+ var _a, _b, _c;
742
746
  if (request.specifier === '@embroider/macros') {
743
747
  // the macros package is always handled directly within babel (not
744
748
  // necessarily as a real resolvable package), so we should not mess with it.
@@ -746,7 +750,8 @@ class Resolver {
746
750
  // why we need to know about it.
747
751
  return logTransition('fallback early exit', request);
748
752
  }
749
- if (compatPattern.test(request.specifier)) {
753
+ let { specifier, fromFile } = request;
754
+ if (compatPattern.test(specifier)) {
750
755
  // Some kinds of compat requests get rewritten into other things
751
756
  // deterministically. For example, "#embroider_compat/helpers/whatever"
752
757
  // means only "the-current-engine/helpers/whatever", and if that doesn't
@@ -762,33 +767,39 @@ class Resolver {
762
767
  // here.
763
768
  return request;
764
769
  }
765
- let pkg = this.packageCache.ownerOfFile(request.fromFile);
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);
766
777
  if (!pkg) {
767
778
  return logTransition('no identifiable owningPackage', request);
768
779
  }
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
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()
772
784
  let movedPkg = this.packageCache.maybeMoved(pkg);
773
785
  if (movedPkg !== pkg) {
774
- let originalFromFile = (_a = request.meta) === null || _a === void 0 ? void 0 : _a.originalFromFile;
775
- if (typeof originalFromFile !== 'string') {
786
+ if (!((_c = request.meta) === null || _c === void 0 ? void 0 : _c.wasMovedTo)) {
776
787
  throw new Error(`bug: embroider resolver's meta is not propagating`);
777
788
  }
778
- request = request.rehome(originalFromFile);
789
+ fromFile = request.meta.wasMovedTo;
779
790
  pkg = movedPkg;
780
791
  }
781
792
  if (!pkg.isV2Ember()) {
782
793
  return logTransition('fallbackResolve: not in an ember package', request);
783
794
  }
784
- let packageName = (0, shared_internals_1.packageName)(request.specifier);
795
+ let packageName = (0, shared_internals_1.packageName)(specifier);
785
796
  if (!packageName) {
786
797
  // this is a relative import
787
798
  let withinEngine = this.engineConfig(pkg.name);
788
799
  if (withinEngine) {
789
800
  // it's a relative import inside an engine (which also means app), which
790
801
  // means we may need to satisfy the request via app tree merging.
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)));
802
+ let appJSMatch = this.searchAppTree(request, withinEngine, (0, shared_internals_2.explicitRelative)(pkg.root, (0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier)));
792
803
  if (appJSMatch) {
793
804
  return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
794
805
  }
@@ -802,32 +813,23 @@ class Resolver {
802
813
  }
803
814
  }
804
815
  // auto-upgraded packages can fall back to the set of known active addons
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
- }
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);
812
820
  }
813
821
  }
814
- let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
822
+ let logicalLocation = this.reverseSearchAppTree(pkg, fromFile);
815
823
  if (logicalLocation) {
816
824
  // the requesting file is in an addon's appTree. We didn't succeed in
817
825
  // resolving this (non-relative) request from inside the actual addon, so
818
826
  // next try to resolve it from the corresponding logical location in the
819
827
  // app.
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')));
828
+ return logTransition('fallbackResolve: retry from logical home of app-js file', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
827
829
  }
828
830
  let targetingEngine = this.engineConfig(packageName);
829
831
  if (targetingEngine) {
830
- let appJSMatch = this.searchAppTree(request, targetingEngine, request.specifier.replace(packageName, '.'));
832
+ let appJSMatch = this.searchAppTree(request, targetingEngine, specifier.replace(packageName, '.'));
831
833
  if (appJSMatch) {
832
834
  return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
833
835
  }
@@ -837,14 +839,14 @@ class Resolver {
837
839
  // runtime. Native v2 packages can only get this behavior in the
838
840
  // isExplicitlyExternal case above because they need to explicitly ask for
839
841
  // externals.
840
- return this.external('v1 catch-all fallback', request, request.specifier);
842
+ return this.external('v1 catch-all fallback', request, specifier);
841
843
  }
842
844
  else {
843
845
  // native v2 packages don't automatically externalize *everything* the way
844
846
  // auto-upgraded packages do, but they still externalize known and approved
845
847
  // ember virtual packages (like @ember/component)
846
848
  if (shared_internals_1.emberVirtualPackages.has(packageName)) {
847
- return this.external('emberVirtualPackages', request, request.specifier);
849
+ return this.external('emberVirtualPackages', request, specifier);
848
850
  }
849
851
  }
850
852
  // this is falling through with the original specifier which was
@@ -877,11 +879,15 @@ class Resolver {
877
879
  case undefined:
878
880
  return undefined;
879
881
  case 'app-only':
880
- return request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile);
882
+ return request
883
+ .alias(matched.entry['app-js'].localPath)
884
+ .rehome((0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
881
885
  case 'fastboot-only':
882
- return request.alias(matched.entry['fastboot-js'].specifier).rehome(matched.entry['fastboot-js'].fromFile);
886
+ return request
887
+ .alias(matched.entry['fastboot-js'].localPath)
888
+ .rehome((0, path_1.resolve)(matched.entry['fastboot-js'].packageRoot, 'package.json'));
883
889
  case 'both':
884
- let foundAppJS = this.nodeResolve(matched.entry['app-js'].specifier, matched.entry['app-js'].fromFile);
890
+ let foundAppJS = this.nodeResolve(matched.entry['app-js'].localPath, (0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
885
891
  if (foundAppJS.type !== 'real') {
886
892
  throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`);
887
893
  }