From 4c618dff4921c813c82aec62cf2c4d22ada22a24 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 16 Nov 2023 15:02:01 +0000 Subject: [PATCH 1/2] make sure that we don't return a new request when unmoved --- packages/core/src/module-resolver.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/core/src/module-resolver.ts b/packages/core/src/module-resolver.ts index ad4cb021f..457444eb3 100644 --- a/packages/core/src/module-resolver.ts +++ b/packages/core/src/module-resolver.ts @@ -834,7 +834,13 @@ export class Resolver { if (pkg.name.startsWith('@')) { levels.push('..'); } - return request.rehome(resolve(pkg.root, ...levels, 'moved-package-target.js')).withMeta({ + let newRequest = request.rehome(resolve(pkg.root, ...levels, 'moved-package-target.js')); + + if (newRequest === request) { + return request; + } + + return newRequest.withMeta({ resolvedWithinPackage: pkg.root, }); } @@ -1065,11 +1071,14 @@ export class Resolver { // auto-upgraded packages can fall back to the set of known active addons if (pkg.meta['auto-upgraded'] && this.options.activeAddons[packageName]) { - return logTransition( - `activeAddons`, + const rehomed = this.resolveWithinMovedPackage( request, - this.resolveWithinMovedPackage(request, this.packageCache.get(this.options.activeAddons[packageName])) + this.packageCache.get(this.options.activeAddons[packageName]) ); + + if (rehomed !== request) { + return logTransition(`activeAddons`, request, rehomed); + } } let logicalLocation = this.reverseSearchAppTree(pkg, fromFile); From f53a46649893aaccf9378cef1311308e24cf384b Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 16 Nov 2023 15:02:33 +0000 Subject: [PATCH 2/2] add a guard to let us know if a packager loop is likely --- packages/core/src/module-resolver.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core/src/module-resolver.ts b/packages/core/src/module-resolver.ts index 457444eb3..386feafd3 100644 --- a/packages/core/src/module-resolver.ts +++ b/packages/core/src/module-resolver.ts @@ -242,6 +242,13 @@ export class Resolver { // no additional fallback is available. return resolution; } + + if (nextRequest.fromFile === request.fromFile && nextRequest.specifier === request.specifier) { + throw new Error( + 'Bug Discovered! New request is not === original request but has the same fromFile and specifier. This will likely create a loop.' + ); + } + if (nextRequest.isVirtual) { // virtual requests are terminal, there is no more beforeResolve or // fallbackResolve around them. The defaultResolve is expected to know how