Skip to content

Commit 486bfbd

Browse files
committed
fix: vite resolver using rolldown resolveId kind instead of plugin-commonjs custom.node-resolve.isRequire
1 parent bfc679e commit 486bfbd

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

packages/vite/src/node/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export interface Plugin<T = any> extends RolldownPlugin<T> {
160160
// */
161161
scan?: boolean
162162
isEntry: boolean
163+
kind?: 'import' | 'dynamic-import' | 'require-call'
163164
},
164165
) => Promise<ResolveIdResult> | ResolveIdResult
165166
>

packages/vite/src/node/plugins/resolve.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
178178

179179
// this is passed by @rollup/plugin-commonjs
180180
const isRequire: boolean =
181-
resolveOpts?.custom?.['node-resolve']?.isRequire ?? false
181+
resolveOpts?.custom?.['node-resolve']?.isRequire ||
182+
/* rolldown */ resolveOpts.kind === 'require-call' ||
183+
false
182184

183185
// end user can configure different conditions for ssr and client.
184186
// falls back to client conditions if no ssr conditions supplied
@@ -453,7 +455,7 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
453455
return `module.exports = {}`
454456
} else {
455457
id = id.slice(browserExternalId.length + 1)
456-
// The rolldown using esbuild interop helper, so here copy the proxy module from https://github.com/vitejs/vite/blob/main/packages/vite/src/node/optimizer/esbuildDepPlugin.ts#L259
458+
// The rolldown using esbuild interop helper, so here copy the proxy module from https://github.com/vitejs/vite/blob/main/packages/vite/src/node/optimizer/esbuildDepPlugin.ts#L259-------
457459
return `\
458460
module.exports = Object.create(new Proxy({}, {
459461
get(_, key) {

packages/vite/src/node/server/pluginContainer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,12 @@ class PluginContainer {
307307
*/
308308
scan?: boolean
309309
isEntry?: boolean
310+
kind?: 'import' | 'dynamic-import' | 'require-call'
310311
},
311312
): Promise<PartialResolvedId | null> {
312313
const skip = options?.skip
313314
const ssr = options?.ssr
315+
const kind = options?.kind
314316
const scan = !!options?.scan
315317
const ctx = new ResolveIdContext(this, !!ssr, skip, scan)
316318

@@ -334,6 +336,7 @@ class PluginContainer {
334336
isEntry: !!options?.isEntry,
335337
ssr,
336338
scan,
339+
kind,
337340
}),
338341
)
339342
if (!result) continue

0 commit comments

Comments
 (0)