Skip to content

Commit

Permalink
fix(rollup): handle aliases when checking for externals (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
s3xysteak authored Jun 4, 2024
1 parent 7926335 commit 27b89f5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/builder/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ const getChunkFilename = (
};

export function getRollupOptions(ctx: BuildContext): RollupOptions {
const _aliases = resolveAliases(ctx);
return (<RollupOptions>{
input: Object.fromEntries(
ctx.options.entries
Expand Down Expand Up @@ -361,6 +362,7 @@ export function getRollupOptions(ctx: BuildContext): RollupOptions {
].filter(Boolean),

external(id) {
id = resolveAlias(id, _aliases);
const pkg = getpkg(id);
const isExplicitExternal =
arrayIncludes(ctx.options.externals, pkg) ||
Expand Down Expand Up @@ -402,7 +404,7 @@ export function getRollupOptions(ctx: BuildContext): RollupOptions {
ctx.options.rollup.alias &&
alias({
...ctx.options.rollup.alias,
entries: resolveAliases(ctx),
entries: _aliases,
}),

ctx.options.rollup.resolve &&
Expand Down Expand Up @@ -470,6 +472,16 @@ function resolveAliases(ctx: BuildContext) {
return aliases;
}

// TODO: use pathe utils to handle nested aliases
function resolveAlias(id: string, aliases: Record<string, string>): string {
for (const [find, replacement] of Object.entries(aliases)) {
if (id.startsWith(find)) {
return id.replace(find, replacement);
}
}
return id;
}

export function _watch(rollupOptions: RollupOptions) {
const watcher = rollupWatch(rollupOptions);

Expand Down

0 comments on commit 27b89f5

Please sign in to comment.