Skip to content

Commit

Permalink
guard against infinte loops at rehome implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
void-mAlex committed Apr 12, 2023
1 parent 1aa035a commit 340ef7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 6 additions & 7 deletions packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ class NodeModuleRequest implements ModuleRequest {
return new NodeModuleRequest(specifier, this.fromFile) as this;
}
rehome(fromFile: string): this {
return new NodeModuleRequest(this.specifier, fromFile) as this;
if (this.fromFile === fromFile) {
return this;
} else {
return new NodeModuleRequest(this.specifier, fromFile) as this;
}
}
virtualize(filename: string) {
return new NodeModuleRequest(filename, this.fromFile, true) as this;
Expand Down Expand Up @@ -710,12 +714,7 @@ export class Resolver {
// this is the easy case -- a package that uses exports can safely resolve
// its own name, so it's enough to let it resolve the (self-targeting)
// specifier from its own package root.
const resolvedPkgJson = resolve(pkg.root, 'package.json');
if (request.fromFile === resolvedPkgJson) {
return request;
} else {
return request.rehome(resolvedPkgJson);
}
return request.rehome(resolve(pkg.root, 'package.json'));
} else {
// otherwise we need to just assume that internal naming is simple
return request.alias(request.specifier.replace(pkg.name, '.')).rehome(resolve(pkg.root, 'package.json'));
Expand Down
10 changes: 7 additions & 3 deletions packages/webpack/src/webpack-resolver-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,13 @@ class WebpackModuleRequest implements ModuleRequest {
return new WebpackModuleRequest(this.babelLoaderPrefix, this.state) as this;
}
rehome(newFromFile: string) {
this.state.contextInfo.issuer = newFromFile;
this.state.context = dirname(newFromFile);
return new WebpackModuleRequest(this.babelLoaderPrefix, this.state) as this;
if (this.fromFile === newFromFile) {
return this;
} else {
this.state.contextInfo.issuer = newFromFile;
this.state.context = dirname(newFromFile);
return new WebpackModuleRequest(this.babelLoaderPrefix, this.state) as this;
}
}
virtualize(filename: string) {
let next = this.alias(`${this.babelLoaderPrefix}${virtualLoaderName}?${filename}!`);
Expand Down

0 comments on commit 340ef7d

Please sign in to comment.