Skip to content

Commit

Permalink
Merge pull request #1670 from embroider-build/fix-looping
Browse files Browse the repository at this point in the history
Fix looping for unchanged files
  • Loading branch information
mansona authored Nov 16, 2023
2 parents 04bf3a7 + f53a466 commit 2d59287
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -834,7 +841,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,
});
}
Expand Down Expand Up @@ -1065,11 +1078,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);
Expand Down

0 comments on commit 2d59287

Please sign in to comment.