Skip to content

Commit

Permalink
fix(externals): check explicit inline rules on resolved id (#2288)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Mar 21, 2024
1 parent a072a76 commit 882f0a9
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/rollup/plugins/externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ export function externals(opts: NodeExternalsOptions): Plugin {
.map((p) => normalizeMatcher(p))
.sort((a, b) => b.score - a.score);

// Utility to check explicit inlines
const isExplicitInline = (id: string, importer: string) => {
const inlineMatch = inlineMatchers.find((m) => m(id, importer));
const externalMatch = externalMatchers.find((m) => m(id, importer));
if (
inlineMatch &&
(!externalMatch ||
(externalMatch && inlineMatch.score > externalMatch.score))
) {
return true;
}
};

return {
name: "node-externals",
async resolveId(originalId, importer, options) {
Expand All @@ -83,13 +96,7 @@ export function externals(opts: NodeExternalsOptions): Plugin {
const id = normalize(originalId);

// Check for explicit inlines and externals
const inlineMatch = inlineMatchers.find((m) => m(id, importer));
const externalMatch = externalMatchers.find((m) => m(id, importer));
if (
inlineMatch &&
(!externalMatch ||
(externalMatch && inlineMatch.score > externalMatch.score))
) {
if (isExplicitInline(id, importer)) {
return null;
}

Expand All @@ -98,6 +105,11 @@ export function externals(opts: NodeExternalsOptions): Plugin {
id,
};

// Check for explicit inlines and externals
if (isExplicitInline(resolved.id, importer)) {
return null;
}

// Try resolving with mlly as fallback
if (
!isAbsolute(resolved.id) ||
Expand Down

0 comments on commit 882f0a9

Please sign in to comment.