Skip to content

Commit 33fbc2c

Browse files
committed
fix(test): rewrite vitest self-references in globals.d.ts for type-aware linting (#1177)
The bundled globals.d.ts declares types like `typeof import('vitest')['test']`, but `vitest` is not resolvable from the @voidzero-dev/vite-plus-test package context in pnpm's strict node_modules layout. TypeScript silently treats the unresolved import as `any`, but oxlint's type-aware linting treats it as an `error` type, causing `no-unsafe-call` errors. Fix by rewriting `import('vitest')` to `import('@voidzero-dev/vite-plus-test')` during the bundleVitest() copy step, making it a self-reference that resolves correctly via Node.js package self-referencing. Also adds the vite-plus-vitest-global-type-minimal-repro project to ecosystem-ci.
1 parent c086408 commit 33fbc2c

File tree

12 files changed

+68
-2
lines changed

12 files changed

+68
-2
lines changed

.github/workflows/e2e-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ jobs:
294294
command: |
295295
vp fmt
296296
vp run validate
297+
- name: vite-plus-vitest-global-type-minimal-repro
298+
node-version: 24
299+
command: |
300+
vp test
301+
vp check --fix
297302
exclude:
298303
# frm-stack uses Docker (testcontainers) which doesn't work the same way on Windows
299304
- os: windows-latest

ecosystem-ci/repo.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,11 @@
102102
"repository": "https://github.com/why-reproductions-are-required/bun-vite-template.git",
103103
"branch": "master",
104104
"hash": "d84099b4a153c7e0f35e510725b2ceb24c6e09ad"
105+
},
106+
"vite-plus-vitest-global-type-minimal-repro": {
107+
"repository": "https://github.com/why-reproductions-are-required/vite-plus-vitest-global-type-minimal-repro.git",
108+
"branch": "main",
109+
"hash": "419653665e4f0688ad3cac68a34673fdd0632b55",
110+
"forceFreshMigration": true
105111
}
106112
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "check-vitest-globals-typecheck",
3+
"version": "0.0.0",
4+
"private": true
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
> vp check
2+
pass: All 6 files are correctly formatted (<variable>ms, <variable> threads)
3+
pass: Found no warnings, lint errors, or type errors in 3 files (<variable>ms, <variable> threads)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { fn } from "./index.ts";
2+
3+
test("fn", () => {
4+
expect(fn()).toBe("Hello, world!");
5+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function fn() {
2+
return "Hello, world!";
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"env": {
3+
"VITE_DISABLE_AUTO_INSTALL": "1"
4+
},
5+
"commands": ["vp check"]
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "nodenext",
5+
"moduleResolution": "nodenext",
6+
"types": ["vite-plus/test/globals"],
7+
"strict": true,
8+
"noEmit": true,
9+
"allowImportingTsExtensions": true,
10+
"skipLibCheck": true
11+
},
12+
"include": ["src"]
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default {
2+
test: {
3+
globals: true,
4+
},
5+
lint: {
6+
options: {
7+
typeAware: true,
8+
typeCheck: true,
9+
},
10+
rules: {
11+
"typescript/no-unsafe-call": "error",
12+
},
13+
},
14+
};

packages/cli/src/migration/migrator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ export function rewriteStandaloneProject(
720720
overrides: {
721721
...pkg.pnpm?.overrides,
722722
...VITE_PLUS_OVERRIDE_PACKAGES,
723+
...(isForceOverrideMode() ? { [VITE_PLUS_NAME]: VITE_PLUS_VERSION } : {}),
723724
},
724725
};
725726
// remove packages from `resolutions` field if they exist
@@ -734,7 +735,7 @@ export function rewriteStandaloneProject(
734735
extractedStagedConfig = rewritePackageJson(pkg, packageManager, false, skipStagedMigration);
735736

736737
// ensure vite-plus is in devDependencies
737-
if (!pkg.devDependencies?.[VITE_PLUS_NAME]) {
738+
if (!pkg.devDependencies?.[VITE_PLUS_NAME] || isForceOverrideMode()) {
738739
pkg.devDependencies = {
739740
...pkg.devDependencies,
740741
[VITE_PLUS_NAME]: VITE_PLUS_VERSION,

0 commit comments

Comments
 (0)