Skip to content

Commit

Permalink
fix: remove picomatch type import (fixes #10656) (#10678)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Oct 28, 2022
1 parent b823fd6 commit 1128b4d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
18 changes: 17 additions & 1 deletion packages/vite/scripts/postPatchTypes.ts
@@ -1,7 +1,8 @@
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import fs from 'node:fs'
import colors from 'picocolors'
import { rewriteImports } from './util'
import { rewriteImports, walkDir } from './util'

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

console.log(colors.green(colors.bold(`patched types/* imports`)))

// remove picomatch type import because only the internal property uses it
const picomatchImport = "import type { Matcher as Matcher_2 } from 'picomatch';"

walkDir(nodeDts, (file) => {
const content = fs.readFileSync(file, 'utf-8')
if (!content.includes(picomatchImport)) {
throw new Error(`Should find picomatch type import in ${file}`)
}

const replacedContent = content.replace(picomatchImport, '')
fs.writeFileSync(file, replacedContent, 'utf-8')
})

console.log(colors.green(colors.bold(`removed picomatch type import`)))
2 changes: 1 addition & 1 deletion packages/vite/scripts/util.ts
Expand Up @@ -21,7 +21,7 @@ export function slash(p: string): string {
return p.replace(/\\/g, '/')
}

function walkDir(dir: string, handleFile: (file: string) => void): void {
export function walkDir(dir: string, handleFile: (file: string) => void): void {
if (statSync(dir).isDirectory()) {
const files = readdirSync(dir)
for (const file of files) {
Expand Down
19 changes: 17 additions & 2 deletions packages/vite/tsconfig.check.json
Expand Up @@ -2,6 +2,8 @@
"compilerOptions": {
"noEmit": true,
"moduleResolution": "classic",
"noResolve": true,
"typeRoots": [],
// Only add entries to `paths` when you are adding/updating dependencies (not devDependencies)
// See CONTRIBUTING.md "Ensure type support" for more details
"paths": {
Expand All @@ -14,9 +16,22 @@
// indirect: postcss depends on it
"source-map-js": ["./node_modules/source-map-js/source-map.d.ts"]
},
"typeRoots": [],
"strict": true,
"exactOptionalPropertyTypes": true
},
"include": ["dist/**/*.d.ts"]
"include": [
"../../node_modules/@types/node/**/*",
// dependencies
"./node_modules/rollup/**/*",
"./node_modules/esbuild/**/*",
"./node_modules/postcss/**/*",
"./node_modules/source-map-js/**/*",
// dist
"dist/**/*",
"types/customEvent.d.ts",
"types/hmrPayload.d.ts",
"types/importGlob.d.ts",
"types/importMeta.d.ts",
"types/hot.d.ts"
]
}

0 comments on commit 1128b4d

Please sign in to comment.