Skip to content

Commit

Permalink
Fix glob resolver package issue with deep entry points (#8169)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcins committed Jun 13, 2022
1 parent d2d0d33 commit b837522
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 36 additions & 12 deletions packages/resolvers/glob/src/GlobResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export default (new Resolver({
throw errorToThrowableDiagnostic(error, dependency);
}

let invalidateOnFileCreate = [];
let invalidateOnFileChange = new Set();

// if the specifier does not start with /, ~, or . then it's not a path but package-ish - we resolve
// the package first, and then append the rest of the path
if (!/^[/~.]/.test(specifier)) {
Expand Down Expand Up @@ -91,25 +94,43 @@ export default (new Resolver({
logger,
});

const result = await resolver.resolve({
filename: pkg,
let ctx = {
invalidateOnFileCreate,
invalidateOnFileChange,
specifierType: dependency.specifierType,
parent: dependency.resolveFrom,
env: dependency.env,
sourcePath: dependency.sourcePath,
loc: dependency.loc,
});
};

if (!result || !result.filePath) {
let result;
try {
result = await resolver.resolveModule({
filename: pkg,
parent: dependency.resolveFrom,
env: dependency.env,
sourcePath: dependency.sourcePath,
ctx,
});
} catch (err) {
if (err instanceof ThrowableDiagnostic) {
// Return instead of throwing so we can provide invalidations.
return {
diagnostics: err.diagnostics,
invalidateOnFileCreate,
invalidateOnFileChange: [...invalidateOnFileChange],
};
} else {
throw err;
}
}

if (!result || !result.moduleDir) {
throw errorToThrowableDiagnostic(
`Unable to resolve ${pkg} from ${sourceFile} when evaluating specifier ${specifier}`,
`Unable to resolve ${pkg} from ${sourceFile} when resolving specifier ${specifier}`,
dependency,
);
} else if (result.diagnostics) {
throw new ThrowableDiagnostic({diagnostic: result.diagnostics});
}

specifier = path.resolve(path.dirname(result.filePath), rest);
specifier = path.resolve(result.moduleDir, rest);
} else {
specifier = path.resolve(path.dirname(sourceFile), specifier);
}
Expand Down Expand Up @@ -151,6 +172,8 @@ export default (new Resolver({
}
}

invalidateOnFileCreate.push({glob: normalized});

return {
filePath: path.join(
dir,
Expand All @@ -159,7 +182,8 @@ export default (new Resolver({
sourceAssetType,
),
code,
invalidateOnFileCreate: [{glob: normalized}],
invalidateOnFileCreate,
invalidateOnFileChange: [...invalidateOnFileChange],
pipeline: null,
priority: 'sync',
};
Expand Down

0 comments on commit b837522

Please sign in to comment.