Skip to content

Commit 5353098

Browse files
authored
Merge pull request #626 from preactjs/JoviDeCroock/prefresh-issue-625
fix(vite): resolve ESM types correctly under NodeNext and Deno
2 parents 96fe0fe + 4bbe51f commit 5353098

5 files changed

Lines changed: 38 additions & 8 deletions

File tree

.changeset/clean-types-resolve.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@prefresh/vite': patch
3+
---
4+
5+
Fix type resolution under `moduleResolution: NodeNext` and Deno
6+
7+
The `import` condition now resolves to a real ESM entry (`src/index.mjs`) with matching ESM type declarations (`index.d.mts` using `export default`), while `require` keeps the CommonJS declarations (`index.d.ts` using `export =`). Previously the ESM entry was typed with a CJS-style `export =` declaration, which TypeScript 6 / Deno 2.8.3+ reject as a hard error.
8+
9+
Also inline the `FilterPattern` type instead of importing it from `@rollup/pluginutils`, whose types do not resolve under NodeNext.

packages/vite/index.d.mts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { PluginOption } from 'vite';
2+
3+
type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null;
4+
5+
interface Options {
6+
parserPlugins?: readonly string[];
7+
include?: FilterPattern;
8+
exclude?: FilterPattern;
9+
}
10+
11+
declare const prefreshPlugin: (options?: Options) => Promise<PluginOption>;
12+
13+
export default prefreshPlugin;

packages/vite/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { FilterPattern } from '@rollup/pluginutils';
21
import { PluginOption } from 'vite';
32

3+
type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null;
4+
45
interface Options {
56
parserPlugins?: readonly string[];
67
include?: FilterPattern;

packages/vite/package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@
66
"types": "index.d.ts",
77
"exports": {
88
".": {
9-
"types": "./index.d.ts",
10-
"require": "./src/index.js",
11-
"import": "./src/index.js"
9+
"import": {
10+
"types": "./index.d.mts",
11+
"default": "./src/index.mjs"
12+
},
13+
"require": {
14+
"types": "./index.d.ts",
15+
"default": "./src/index.js"
16+
}
1217
},
1318
"./package.json": "./package.json"
1419
},
1520
"modes": {
1621
"default": "src/index.js"
1722
},
1823
"files": [
19-
"dist",
20-
"runtime",
21-
"utils",
22-
"index.d.ts"
24+
"src",
25+
"index.d.ts",
26+
"index.d.mts"
2327
],
2428
"scripts": {
2529
"lint": "eslint src",

packages/vite/src/index.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import prefreshPlugin from './index.js';
2+
3+
export default prefreshPlugin;

0 commit comments

Comments
 (0)