Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove picomatch type import (fixes #10656) #10678

Merged
merged 2 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/vite/scripts/postPatchTypes.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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"
]
}