Skip to content

Commit 1128b4d

Browse files
authoredOct 28, 2022
fix: remove picomatch type import (fixes #10656) (#10678)
1 parent b823fd6 commit 1128b4d

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed
 

‎packages/vite/scripts/postPatchTypes.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { dirname, resolve } from 'node:path'
22
import { fileURLToPath } from 'node:url'
3+
import fs from 'node:fs'
34
import colors from 'picocolors'
4-
import { rewriteImports } from './util'
5+
import { rewriteImports, walkDir } from './util'
56

67
const dir = dirname(fileURLToPath(import.meta.url))
78
const nodeDts = resolve(dir, '../dist/node/index.d.ts')
@@ -14,3 +15,18 @@ rewriteImports(nodeDts, (importPath) => {
1415
})
1516

1617
console.log(colors.green(colors.bold(`patched types/* imports`)))
18+
19+
// remove picomatch type import because only the internal property uses it
20+
const picomatchImport = "import type { Matcher as Matcher_2 } from 'picomatch';"
21+
22+
walkDir(nodeDts, (file) => {
23+
const content = fs.readFileSync(file, 'utf-8')
24+
if (!content.includes(picomatchImport)) {
25+
throw new Error(`Should find picomatch type import in ${file}`)
26+
}
27+
28+
const replacedContent = content.replace(picomatchImport, '')
29+
fs.writeFileSync(file, replacedContent, 'utf-8')
30+
})
31+
32+
console.log(colors.green(colors.bold(`removed picomatch type import`)))

‎packages/vite/scripts/util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function slash(p: string): string {
2121
return p.replace(/\\/g, '/')
2222
}
2323

24-
function walkDir(dir: string, handleFile: (file: string) => void): void {
24+
export function walkDir(dir: string, handleFile: (file: string) => void): void {
2525
if (statSync(dir).isDirectory()) {
2626
const files = readdirSync(dir)
2727
for (const file of files) {

‎packages/vite/tsconfig.check.json

+17-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"compilerOptions": {
33
"noEmit": true,
44
"moduleResolution": "classic",
5+
"noResolve": true,
6+
"typeRoots": [],
57
// Only add entries to `paths` when you are adding/updating dependencies (not devDependencies)
68
// See CONTRIBUTING.md "Ensure type support" for more details
79
"paths": {
@@ -14,9 +16,22 @@
1416
// indirect: postcss depends on it
1517
"source-map-js": ["./node_modules/source-map-js/source-map.d.ts"]
1618
},
17-
"typeRoots": [],
1819
"strict": true,
1920
"exactOptionalPropertyTypes": true
2021
},
21-
"include": ["dist/**/*.d.ts"]
22+
"include": [
23+
"../../node_modules/@types/node/**/*",
24+
// dependencies
25+
"./node_modules/rollup/**/*",
26+
"./node_modules/esbuild/**/*",
27+
"./node_modules/postcss/**/*",
28+
"./node_modules/source-map-js/**/*",
29+
// dist
30+
"dist/**/*",
31+
"types/customEvent.d.ts",
32+
"types/hmrPayload.d.ts",
33+
"types/importGlob.d.ts",
34+
"types/importMeta.d.ts",
35+
"types/hot.d.ts"
36+
]
2237
}

0 commit comments

Comments
 (0)
Please sign in to comment.