Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix glob resolver package issue with deep entry points #8169

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

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
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