From f1c24c712188a0c248b6a145129472449e52fda2 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 3 Nov 2024 11:25:46 +0100 Subject: [PATCH 1/2] fix(rollup): pass options to `resolve` --- src/rollup/plugins/handlers-meta.ts | 8 ++++++-- src/rollup/plugins/raw.ts | 5 ++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/rollup/plugins/handlers-meta.ts b/src/rollup/plugins/handlers-meta.ts index 2b69cf423b..2014a8265e 100644 --- a/src/rollup/plugins/handlers-meta.ts +++ b/src/rollup/plugins/handlers-meta.ts @@ -18,12 +18,16 @@ const esbuildLoaders = { export function handlersMeta(nitro: Nitro) { return { name: "nitro:handlers-meta", - async resolveId(id) { + async resolveId(id, importer, options) { if (id.startsWith("\0")) { return; } if (id.endsWith(`?meta`)) { - const resolved = await this.resolve(id.replace(`?meta`, ``)); + const resolved = await this.resolve( + id.replace(`?meta`, ``), + importer, + options + ); if (!resolved) { return; } diff --git a/src/rollup/plugins/raw.ts b/src/rollup/plugins/raw.ts index 98345da3ee..8c6b98f87e 100644 --- a/src/rollup/plugins/raw.ts +++ b/src/rollup/plugins/raw.ts @@ -20,7 +20,7 @@ export function raw(opts: RawOptions = {}): Plugin { return { name: "raw", - async resolveId(id, importer) { + async resolveId(id, importer, options) { if (id === HELPER_ID) { return id; } @@ -34,8 +34,7 @@ export function raw(opts: RawOptions = {}): Plugin { id = id.slice(4); } - const resolvedId = (await this.resolve(id, importer, { skipSelf: true })) - ?.id; + const resolvedId = (await this.resolve(id, importer, options))?.id; if (!resolvedId || resolvedId.startsWith("\0")) { return resolvedId; From a723e3facd654344640b088bc5c63f33481f77c2 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 3 Nov 2024 11:28:29 +0100 Subject: [PATCH 2/2] refactor: make name more clear --- src/rollup/config.ts | 4 ++-- src/rollup/plugins/externals-legacy.ts | 8 ++++++-- src/rollup/plugins/handlers-meta.ts | 4 ++-- src/rollup/plugins/raw.ts | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/rollup/config.ts b/src/rollup/config.ts index 3af2024b1e..0bae6616e6 100644 --- a/src/rollup/config.ts +++ b/src/rollup/config.ts @@ -407,14 +407,14 @@ export const plugins = [ if (nitro.options.noExternals) { rollupConfig.plugins.push({ name: "no-externals", - async resolveId(id, from, options) { + async resolveId(id, from, resolveOpts) { if ( nitro.options.node && (id.startsWith("node:") || builtinModules.includes(id)) ) { return { id, external: true }; } - const resolved = await this.resolve(id, from, options); + const resolved = await this.resolve(id, from, resolveOpts); if (!resolved) { const _resolved = await resolvePath(id, { url: nitro.options.nodeModulesDirs, diff --git a/src/rollup/plugins/externals-legacy.ts b/src/rollup/plugins/externals-legacy.ts index be0dd201e0..5eb553a9d5 100644 --- a/src/rollup/plugins/externals-legacy.ts +++ b/src/rollup/plugins/externals-legacy.ts @@ -52,7 +52,7 @@ export function externals(opts: NodeExternalsOptions): Plugin { return { name: "node-externals", - async resolveId(originalId, importer, options) { + async resolveId(originalId, importer, resolveOpts) { // Skip internals if ( !originalId || @@ -86,7 +86,11 @@ export function externals(opts: NodeExternalsOptions): Plugin { } // Resolve id using rollup resolver - const resolved = (await this.resolve(originalId, importer, options)) || { + const resolved = (await this.resolve( + originalId, + importer, + resolveOpts + )) || { id, }; diff --git a/src/rollup/plugins/handlers-meta.ts b/src/rollup/plugins/handlers-meta.ts index 2014a8265e..f2f3ddb8c1 100644 --- a/src/rollup/plugins/handlers-meta.ts +++ b/src/rollup/plugins/handlers-meta.ts @@ -18,7 +18,7 @@ const esbuildLoaders = { export function handlersMeta(nitro: Nitro) { return { name: "nitro:handlers-meta", - async resolveId(id, importer, options) { + async resolveId(id, importer, resolveOpts) { if (id.startsWith("\0")) { return; } @@ -26,7 +26,7 @@ export function handlersMeta(nitro: Nitro) { const resolved = await this.resolve( id.replace(`?meta`, ``), importer, - options + resolveOpts ); if (!resolved) { return; diff --git a/src/rollup/plugins/raw.ts b/src/rollup/plugins/raw.ts index 8c6b98f87e..d9ee2589c4 100644 --- a/src/rollup/plugins/raw.ts +++ b/src/rollup/plugins/raw.ts @@ -20,7 +20,7 @@ export function raw(opts: RawOptions = {}): Plugin { return { name: "raw", - async resolveId(id, importer, options) { + async resolveId(id, importer, resolveOpts) { if (id === HELPER_ID) { return id; } @@ -34,7 +34,7 @@ export function raw(opts: RawOptions = {}): Plugin { id = id.slice(4); } - const resolvedId = (await this.resolve(id, importer, options))?.id; + const resolvedId = (await this.resolve(id, importer, resolveOpts))?.id; if (!resolvedId || resolvedId.startsWith("\0")) { return resolvedId;