Skip to content
Open
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
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"build-types": "pnpm build-types-roll && pnpm build-types-check",
"build-types-roll": "rolldown --config rolldown.dts.config.ts",
"build-types-check": "tsc --project tsconfig.check.json",
"typecheck": "tsc && tsc -p src/node && tsc -p src/module-runner && tsc -p src/shared && tsc -p src/node/__tests_dts__",
"typecheck": "tsc && tsc -p src/node && tsc -p src/module-runner && tsc -p src/shared && tsc -p src/node/__tests_dts__ && tsc -p src/module-runner/__tests_dts__",
"lint": "eslint --cache --ext .ts src/**",
"format": "prettier --write --cache --parser typescript \"src/**/*.ts\"",
"generate-target": "tsx scripts/generateTarget.ts",
Expand Down
20 changes: 20 additions & 0 deletions packages/vite/src/module-runner/__tests_dts__/importMeta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Type test to verify ModuleRunnerImportMeta is structurally compatible
* with ImportMeta (including @types/node augmentations).
*
* This replaces `extends ImportMeta` in the interface declaration with a
* test-only assignability check that won't cause TS2717 "subsequent property
* declarations must have the same type" errors in consumer projects using
* skipLibCheck: false with augmented ImportMeta.
*/

import type { ExpectExtends, ExpectTrue } from '@type-challenges/utils'
import type { ModuleRunnerImportMeta } from '../types'

export type cases = [
// Ensure ModuleRunnerImportMeta is assignable to ImportMeta
// (which includes @types/node augmentations: dirname, filename, url, resolve, main)
ExpectTrue<ExpectExtends<ImportMeta, ModuleRunnerImportMeta>>,
]

export {}
9 changes: 9 additions & 0 deletions packages/vite/src/module-runner/__tests_dts__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"isolatedDeclarations": false,
"declaration": false
},
"include": ["../", "../../types"],
"exclude": ["../**/__tests__"]
}
4 changes: 2 additions & 2 deletions packages/vite/src/module-runner/createImportMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export function createDefaultImportMeta(
resolve(_id: string, _parent?: string) {
throw new Error('[module runner] "import.meta.resolve" is not supported.')
},
main: false,
// should be replaced during transformation
glob() {
throw new Error(
`[module runner] "import.meta.glob" is statically replaced during ` +
`file transformation. Make sure to reference it by the full name.`,
)
},
// @types/node adds `main` to `import.meta`, but we don't add that for the defaultImportMeta
} satisfies Omit<ModuleRunnerImportMeta, 'main'> as any
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion packages/vite/src/module-runner/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ import type { InterceptorOptions } from './sourcemap/interceptor'

export type { DefineImportMetadata, SSRImportMetadata }

export interface ModuleRunnerImportMeta extends ImportMeta {
export interface ModuleRunnerImportMeta {
url: string
env: ImportMetaEnv
hot?: ViteHotContext
dirname: string
filename: string
glob: (...args: any[]) => any
resolve(specifier: string, parent?: string): string
main: boolean
[key: string]: any
}

Expand Down