Skip to content

Commit

Permalink
prevent infinite loops
Browse files Browse the repository at this point in the history
  • Loading branch information
tjenkinson committed Feb 11, 2021
1 parent 23465bf commit bab212a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/node-resolve/src/index.js
Expand Up @@ -54,6 +54,7 @@ export function nodeResolve(opts = {}) {
const rootDir = options.rootDir || process.cwd();
let { dedupe } = options;
let rollupOptions;
let inNestedResolve = false;

if (typeof dedupe !== 'function') {
dedupe = (importee) =>
Expand Down Expand Up @@ -270,10 +271,17 @@ export function nodeResolve(opts = {}) {
}

const resolved = await doResolveId(this, importee, importer, opts);
if (resolved) {
const resolvedResolved = await this.resolve(resolved.id, importer, { skipSelf: true });
if (resolvedResolved && resolvedResolved.external) {
return false;
if (resolved && !inNestedResolve) {
// if a plugin invoked by `this.resolve` also does `this.resolve`
// we need to break the loop
inNestedResolve = true;
try {
const resolvedResolved = await this.resolve(resolved.id, importer, { skipSelf: true });
if (resolvedResolved && resolvedResolved.external) {
return false;
}
} finally {
inNestedResolve = false;
}
}

Expand Down

0 comments on commit bab212a

Please sign in to comment.