Skip to content

fix(pluginContainer): align resolveid without importer behavior with rollup #20081

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ export interface ResolvedConfig
configFileDependencies: string[]
inlineConfig: InlineConfig
root: string
/** @internal */
fallbackImporter: string
base: string
/** @internal */
decodedBase: string
Expand Down Expand Up @@ -1459,6 +1461,7 @@ export async function resolveConfig(
),
inlineConfig,
root: resolvedRoot,
fallbackImporter: normalizePath(path.resolve(resolvedRoot, 'index.html')),
base,
decodedBase: decodeBase(base),
rawBase: resolvedBase,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class DevEnvironment extends BaseEnvironment {
this._pendingRequests = new Map()

this.moduleGraph = new EnvironmentModuleGraph(name, (url: string) =>
this.pluginContainer!.resolveId(url, undefined),
this.pluginContainer!.resolveId(url, config.fallbackImporter),
)

this._crawlEndFinder = setupOnCrawlEnd()
Expand Down
6 changes: 1 addition & 5 deletions packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ SOFTWARE.
*/

import fs from 'node:fs'
import { join } from 'node:path'
import { performance } from 'node:perf_hooks'
import { parseAst as rollupParseAst } from 'rollup/parseAst'
import type {
Expand Down Expand Up @@ -338,10 +337,7 @@ class EnvironmentPluginContainer {

async resolveId(
rawId: string,
importer: string | undefined = join(
this.environment.config.root,
'index.html',
),
importer: string | undefined,
options?: {
attributes?: Record<string, string>
custom?: CustomPluginOptions
Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/server/transformRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ async function doTransform(

const resolved = module
? undefined
: ((await pluginContainer.resolveId(url, undefined)) ?? undefined)
: ((await pluginContainer.resolveId(
url,
environment.config.fallbackImporter,
)) ?? undefined)

// resolve
const id = module?.id ?? resolved?.id ?? url
Expand Down
Loading