Skip to content

Commit 0176d45

Browse files
fix(types): remove extends ImportMeta from ModuleRunnerImportMeta (#21710)
1 parent 71687e8 commit 0176d45

5 files changed

Lines changed: 36 additions & 4 deletions

File tree

packages/vite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"build-types": "pnpm build-types-roll && pnpm build-types-check",
6666
"build-types-roll": "rolldown --config rolldown.dts.config.ts",
6767
"build-types-check": "tsc --project tsconfig.check.json",
68-
"typecheck": "tsc && tsc -p src/node && tsc -p src/module-runner && tsc -p src/shared && tsc -p src/node/__tests_dts__",
68+
"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__",
6969
"lint": "eslint --cache --ext .ts src/**",
7070
"format": "prettier --write --cache --parser typescript \"src/**/*.ts\"",
7171
"generate-target": "tsx scripts/generateTarget.ts",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Type test to verify ModuleRunnerImportMeta is structurally compatible
3+
* with ImportMeta (including @types/node augmentations).
4+
*
5+
* This replaces `extends ImportMeta` in the interface declaration with a
6+
* test-only assignability check that won't cause TS2717 "subsequent property
7+
* declarations must have the same type" errors in consumer projects using
8+
* skipLibCheck: false with augmented ImportMeta.
9+
*/
10+
11+
import type { ExpectExtends, ExpectTrue } from '@type-challenges/utils'
12+
import type { ModuleRunnerImportMeta } from '../types'
13+
14+
export type cases = [
15+
// Ensure ModuleRunnerImportMeta is assignable to ImportMeta
16+
// (which includes @types/node augmentations: dirname, filename, url, resolve, main)
17+
ExpectTrue<ExpectExtends<Omit<ImportMeta, 'main'>, ModuleRunnerImportMeta>>,
18+
]
19+
20+
export {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"isolatedDeclarations": false,
5+
"declaration": false
6+
},
7+
"include": ["../", "../../types"],
8+
"exclude": ["../**/__tests__"]
9+
}

packages/vite/src/module-runner/createImportMeta.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ export function createDefaultImportMeta(
3232
`file transformation. Make sure to reference it by the full name.`,
3333
)
3434
},
35-
// @types/node adds `main` to `import.meta`, but we don't add that for the defaultImportMeta
36-
} satisfies Omit<ModuleRunnerImportMeta, 'main'> as any
35+
}
3736
}
3837

3938
/**

packages/vite/src/module-runner/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ import type { InterceptorOptions } from './sourcemap/interceptor'
2424

2525
export type { DefineImportMetadata, SSRImportMetadata }
2626

27-
export interface ModuleRunnerImportMeta extends ImportMeta {
27+
export interface ModuleRunnerImportMeta {
2828
url: string
2929
env: ImportMetaEnv
3030
hot?: ViteHotContext
31+
dirname: string
32+
filename: string
33+
glob: (...args: any[]) => any
34+
resolve(specifier: string, parent?: string): string
3135
[key: string]: any
3236
}
3337

0 commit comments

Comments
 (0)