@embroider/core 3.4.3 → 3.4.4-unstable.2edb355

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);
@@ -332,28 +292,30 @@ class Resolver {
332
292
  let jsModule = null;
333
293
  // first, the various places our template might be.
334
294
  for (let candidate of this.componentTemplateCandidates(target.packageName)) {
295
+ let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}.hbs`;
335
296
  let resolution = this.nodeResolve(`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`, target.from);
336
297
  if (resolution.type === 'real') {
337
- hbsModule = resolution.filename;
298
+ hbsModule = { requested: candidateSpecifier, found: resolution.filename };
338
299
  break;
339
300
  }
340
301
  }
341
302
  // then the various places our javascript might be.
342
303
  for (let candidate of this.componentJSCandidates(target.packageName)) {
343
- let resolution = this.nodeResolve(`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`, target.from);
304
+ let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`;
305
+ let resolution = this.nodeResolve(candidateSpecifier, target.from);
344
306
  // .hbs is a resolvable extension for us, so we need to exclude it here.
345
307
  // It matches as a priority lower than .js, so finding an .hbs means
346
308
  // there's definitely not a .js.
347
309
  if (resolution.type === 'real' && !resolution.filename.endsWith('.hbs')) {
348
- jsModule = resolution.filename;
310
+ jsModule = { requested: candidateSpecifier, found: resolution.filename };
349
311
  break;
350
312
  }
351
313
  }
352
314
  if (hbsModule) {
353
- return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule, jsModule)));
315
+ return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule.found, jsModule === null || jsModule === void 0 ? void 0 : jsModule.found)));
354
316
  }
355
317
  else if (jsModule) {
356
- return logTransition(`resolveComponent found only JS`, request, request.alias(jsModule).rehome(target.from));
318
+ return logTransition(`resolveComponent found only JS`, request, request.alias(jsModule.requested).rehome(target.from));
357
319
  }
358
320
  else {
359
321
  return logTransition(`resolveComponent failed`, request);
@@ -414,10 +376,10 @@ class Resolver {
414
376
  parseGlobalPath(path, inEngine) {
415
377
  let parts = path.split('@');
416
378
  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') };
379
+ return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'package.json') };
418
380
  }
419
381
  else {
420
- return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') };
382
+ return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'package.json') };
421
383
  }
422
384
  }
423
385
  engineConfig(packageName) {
@@ -449,8 +411,8 @@ class Resolver {
449
411
  engineModules.set(inEngineName, {
450
412
  type: 'app-only',
451
413
  'app-js': {
452
- localPath: inAddonName,
453
- packageRoot: addon.root,
414
+ specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
415
+ fromFile: addonConfig.canResolveFromFile,
454
416
  fromPackageName: addon.name,
455
417
  },
456
418
  });
@@ -463,8 +425,8 @@ class Resolver {
463
425
  engineModules.set(inEngineName, {
464
426
  type: 'both',
465
427
  'app-js': {
466
- localPath: inAddonName,
467
- packageRoot: addon.root,
428
+ specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
429
+ fromFile: addonConfig.canResolveFromFile,
468
430
  fromPackageName: addon.name,
469
431
  },
470
432
  'fastboot-js': prevEntry['fastboot-js'],
@@ -488,8 +450,8 @@ class Resolver {
488
450
  engineModules.set(inEngineName, {
489
451
  type: 'fastboot-only',
490
452
  'fastboot-js': {
491
- localPath: inAddonName,
492
- packageRoot: addon.root,
453
+ specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
454
+ fromFile: addonConfig.canResolveFromFile,
493
455
  fromPackageName: addon.name,
494
456
  },
495
457
  });
@@ -502,8 +464,8 @@ class Resolver {
502
464
  engineModules.set(inEngineName, {
503
465
  type: 'both',
504
466
  'fastboot-js': {
505
- localPath: inAddonName,
506
- packageRoot: addon.root,
467
+ specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName),
468
+ fromFile: addonConfig.canResolveFromFile,
507
469
  fromPackageName: addon.name,
508
470
  },
509
471
  'app-js': prevEntry['app-js'],
@@ -525,7 +487,7 @@ class Resolver {
525
487
  return owningEngine;
526
488
  }
527
489
  handleRewrittenPackages(request) {
528
- if (request.isVirtual) {
490
+ if (request.isVirtual || request.isNotFound) {
529
491
  return request;
530
492
  }
531
493
  let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
@@ -544,10 +506,6 @@ class Resolver {
544
506
  targetPkg = this.packageCache.resolve(packageName, requestingPkg);
545
507
  }
546
508
  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
509
  if (err.code !== 'MODULE_NOT_FOUND') {
552
510
  throw err;
553
511
  }
@@ -563,14 +521,26 @@ class Resolver {
563
521
  return logTransition('request targets a moved package', request, this.resolveWithinMovedPackage(request, targetPkg));
564
522
  }
565
523
  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')));
524
+ if (targetPkg) {
525
+ // in this case, the requesting package is moved but its destination is
526
+ // not, so we need to rehome the request back to the original location.
527
+ return logTransition('outbound request from moved package', request, request
528
+ // setting meta here because if this fails, we want the fallback
529
+ // logic to revert our rehome and continue from the *moved* package.
530
+ .withMeta({ originalFromFile: request.fromFile })
531
+ .rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
532
+ }
533
+ else {
534
+ // requesting package was moved and we failed to find its target. We
535
+ // can't let that accidentally succeed in the defaultResolve because we
536
+ // could escape the moved package system.
537
+ return logTransition('missing outbound request from moved package', request, request.notFound());
538
+ }
569
539
  }
570
540
  return request;
571
541
  }
572
542
  handleRenaming(request) {
573
- if (request.isVirtual) {
543
+ if (request.isVirtual || request.isNotFound) {
574
544
  return request;
575
545
  }
576
546
  let packageName = (0, shared_internals_1.packageName)(request.specifier);
@@ -608,7 +578,10 @@ class Resolver {
608
578
  // packages get this help, v2 packages are natively supposed to make their
609
579
  // own modules resolvable, and we want to push them all to do that
610
580
  // correctly.
611
- return logTransition(`v1 self-import`, request, request.alias(request.specifier.replace(pkg.name, '.')).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
581
+ // "my-package/foo" -> "./foo"
582
+ // "my-package" -> "./" (this can't be just "." because node's require.resolve doesn't reliable support that)
583
+ let selfImportPath = request.specifier === pkg.name ? './' : request.specifier.replace(pkg.name, '.');
584
+ return logTransition(`v1 self-import`, request, request.alias(selfImportPath).rehome((0, path_1.resolve)(pkg.root, 'package.json')));
612
585
  }
613
586
  return request;
614
587
  }
@@ -617,16 +590,17 @@ class Resolver {
617
590
  if (pkg.name.startsWith('@')) {
618
591
  levels.push('..');
619
592
  }
593
+ let originalFromFile = request.fromFile;
620
594
  let newRequest = request.rehome((0, path_1.resolve)(pkg.root, ...levels, 'moved-package-target.js'));
621
595
  if (newRequest === request) {
622
596
  return request;
623
597
  }
624
- return newRequest.withMeta({
625
- resolvedWithinPackage: pkg.root,
626
- });
598
+ // setting meta because if this fails, we want the fallback to pick up back
599
+ // in the original requesting package.
600
+ return newRequest.withMeta({ originalFromFile });
627
601
  }
628
602
  preHandleExternal(request) {
629
- if (request.isVirtual) {
603
+ if (request.isVirtual || request.isNotFound) {
630
604
  return request;
631
605
  }
632
606
  let { specifier, fromFile } = request;
@@ -659,7 +633,15 @@ class Resolver {
659
633
  // engine
660
634
  let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
661
635
  if (logicalLocation) {
662
- return logTransition('beforeResolve: relative import in app-js', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName)));
636
+ return logTransition('beforeResolve: relative import in app-js', request, request
637
+ .alias('./' + path_1.posix.join((0, path_1.dirname)(logicalLocation.inAppName), request.specifier))
638
+ // it's important that we're rehoming this to the root of the engine
639
+ // (which we know really exists), and not to a subdir like
640
+ // logicalLocation.inAppName (which might not physically exist),
641
+ // because some environments (including node's require.resolve) will
642
+ // refuse to do resolution from a notional path that doesn't
643
+ // physically exist.
644
+ .rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
663
645
  }
664
646
  return request;
665
647
  }
@@ -674,11 +656,11 @@ class Resolver {
674
656
  if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
675
657
  // addons (whether auto-upgraded or not) may use the app's
676
658
  // 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`);
659
+ let addon = this.locateActiveAddon(packageName);
660
+ if (!addon) {
661
+ throw new Error(`${pkg.name} is trying to import the emberVirtualPeerDep "${packageName}", but it seems to be missing`);
679
662
  }
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));
663
+ return logTransition(`emberVirtualPeerDeps`, request, request.rehome(addon.canResolveFromFile));
682
664
  }
683
665
  // if this file is part of an addon's app-js, it's really the logical
684
666
  // package to which it belongs (normally the app) that affects some policy
@@ -709,6 +691,22 @@ class Resolver {
709
691
  }
710
692
  return request;
711
693
  }
694
+ locateActiveAddon(packageName) {
695
+ if (packageName === this.options.modulePrefix) {
696
+ // the app itself is something that addon's can classically resolve if they know it's name.
697
+ return {
698
+ root: this.options.appRoot,
699
+ canResolveFromFile: (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json'),
700
+ };
701
+ }
702
+ for (let engine of this.options.engines) {
703
+ for (let addon of engine.activeAddons) {
704
+ if (addon.name === packageName) {
705
+ return addon;
706
+ }
707
+ }
708
+ }
709
+ }
712
710
  external(label, request, specifier) {
713
711
  if (this.options.amdCompatibility === 'cjs') {
714
712
  let filename = (0, virtual_content_1.virtualExternalCJSModule)(specifier);
@@ -742,7 +740,7 @@ class Resolver {
742
740
  }
743
741
  }
744
742
  fallbackResolve(request) {
745
- var _a, _b, _c;
743
+ var _a;
746
744
  if (request.specifier === '@embroider/macros') {
747
745
  // the macros package is always handled directly within babel (not
748
746
  // necessarily as a real resolvable package), so we should not mess with it.
@@ -750,8 +748,7 @@ class Resolver {
750
748
  // why we need to know about it.
751
749
  return logTransition('fallback early exit', request);
752
750
  }
753
- let { specifier, fromFile } = request;
754
- if (compatPattern.test(specifier)) {
751
+ if (compatPattern.test(request.specifier)) {
755
752
  // Some kinds of compat requests get rewritten into other things
756
753
  // deterministically. For example, "#embroider_compat/helpers/whatever"
757
754
  // means only "the-current-engine/helpers/whatever", and if that doesn't
@@ -767,39 +764,33 @@ class Resolver {
767
764
  // here.
768
765
  return request;
769
766
  }
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);
767
+ let pkg = this.packageCache.ownerOfFile(request.fromFile);
777
768
  if (!pkg) {
778
769
  return logTransition('no identifiable owningPackage', request);
779
770
  }
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()
771
+ // meta.originalFromFile gets set when we want to try to rehome a request
772
+ // but then come back to the original location here in the fallback when the
773
+ // rehomed request fails
784
774
  let movedPkg = this.packageCache.maybeMoved(pkg);
785
775
  if (movedPkg !== pkg) {
786
- if (!((_c = request.meta) === null || _c === void 0 ? void 0 : _c.wasMovedTo)) {
776
+ let originalFromFile = (_a = request.meta) === null || _a === void 0 ? void 0 : _a.originalFromFile;
777
+ if (typeof originalFromFile !== 'string') {
787
778
  throw new Error(`bug: embroider resolver's meta is not propagating`);
788
779
  }
789
- fromFile = request.meta.wasMovedTo;
780
+ request = request.rehome(originalFromFile);
790
781
  pkg = movedPkg;
791
782
  }
792
783
  if (!pkg.isV2Ember()) {
793
784
  return logTransition('fallbackResolve: not in an ember package', request);
794
785
  }
795
- let packageName = (0, shared_internals_1.packageName)(specifier);
786
+ let packageName = (0, shared_internals_1.packageName)(request.specifier);
796
787
  if (!packageName) {
797
788
  // this is a relative import
798
789
  let withinEngine = this.engineConfig(pkg.name);
799
790
  if (withinEngine) {
800
791
  // it's a relative import inside an engine (which also means app), which
801
792
  // 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)));
793
+ 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
794
  if (appJSMatch) {
804
795
  return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
805
796
  }
@@ -813,23 +804,32 @@ class Resolver {
813
804
  }
814
805
  }
815
806
  // 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);
807
+ if (pkg.meta['auto-upgraded']) {
808
+ let addon = this.locateActiveAddon(packageName);
809
+ if (addon) {
810
+ const rehomed = request.rehome(addon.canResolveFromFile);
811
+ if (rehomed !== request) {
812
+ return logTransition(`activeAddons`, request, rehomed);
813
+ }
820
814
  }
821
815
  }
822
- let logicalLocation = this.reverseSearchAppTree(pkg, fromFile);
816
+ let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile);
823
817
  if (logicalLocation) {
824
818
  // the requesting file is in an addon's appTree. We didn't succeed in
825
819
  // resolving this (non-relative) request from inside the actual addon, so
826
820
  // next try to resolve it from the corresponding logical location in the
827
821
  // 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)));
822
+ return logTransition('fallbackResolve: retry from logical home of app-js file', request,
823
+ // it might look more precise to rehome into logicalLocation.inAppName
824
+ // rather than package.json. But that logical location may not actually
825
+ // exist, and some systems (including node's require.resolve) will be
826
+ // mad about trying to resolve from notional paths that don't really
827
+ // exist.
828
+ request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json')));
829
829
  }
830
830
  let targetingEngine = this.engineConfig(packageName);
831
831
  if (targetingEngine) {
832
- let appJSMatch = this.searchAppTree(request, targetingEngine, specifier.replace(packageName, '.'));
832
+ let appJSMatch = this.searchAppTree(request, targetingEngine, request.specifier.replace(packageName, '.'));
833
833
  if (appJSMatch) {
834
834
  return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
835
835
  }
@@ -839,14 +839,14 @@ class Resolver {
839
839
  // runtime. Native v2 packages can only get this behavior in the
840
840
  // isExplicitlyExternal case above because they need to explicitly ask for
841
841
  // externals.
842
- return this.external('v1 catch-all fallback', request, specifier);
842
+ return this.external('v1 catch-all fallback', request, request.specifier);
843
843
  }
844
844
  else {
845
845
  // native v2 packages don't automatically externalize *everything* the way
846
846
  // auto-upgraded packages do, but they still externalize known and approved
847
847
  // ember virtual packages (like @ember/component)
848
848
  if (shared_internals_1.emberVirtualPackages.has(packageName)) {
849
- return this.external('emberVirtualPackages', request, specifier);
849
+ return this.external('emberVirtualPackages', request, request.specifier);
850
850
  }
851
851
  }
852
852
  // this is falling through with the original specifier which was
@@ -879,15 +879,11 @@ class Resolver {
879
879
  case undefined:
880
880
  return undefined;
881
881
  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'));
882
+ return request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile);
885
883
  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'));
884
+ return request.alias(matched.entry['fastboot-js'].specifier).rehome(matched.entry['fastboot-js'].fromFile);
889
885
  case 'both':
890
- let foundAppJS = this.nodeResolve(matched.entry['app-js'].localPath, (0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json'));
886
+ let foundAppJS = this.nodeResolve(matched.entry['app-js'].specifier, matched.entry['app-js'].fromFile);
891
887
  if (foundAppJS.type !== 'real') {
892
888
  throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`);
893
889
  }