From 21dccdb435b324cf127b877a08e34341450165cd Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Tue, 25 Jul 2023 12:22:14 +0200 Subject: [PATCH 1/2] fix(types): Use file extensions on type imports so they work with `moduleResolution: 'node16'` --- packages/vite/scripts/postPatchTypes.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/vite/scripts/postPatchTypes.ts b/packages/vite/scripts/postPatchTypes.ts index 51599384059d67..81f46551d62a51 100644 --- a/packages/vite/scripts/postPatchTypes.ts +++ b/packages/vite/scripts/postPatchTypes.ts @@ -7,10 +7,12 @@ import { rewriteImports, walkDir } from './util' const dir = dirname(fileURLToPath(import.meta.url)) const nodeDts = resolve(dir, '../dist/node/index.d.ts') -// rewrite `types/*` import to relative import +// rewrite `types/*` import to relative import with file extension rewriteImports(nodeDts, (importPath) => { if (importPath.startsWith('types/')) { - return '../../' + importPath + return '../../' + importPath.endsWith('.js') + ? importPath + : importPath + '.js' } }) From 929790ac6555bb8d9a4775b0b06a9d30cf2bb490 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Tue, 25 Jul 2023 12:50:04 +0200 Subject: [PATCH 2/2] fix: use parenthesis --- packages/vite/scripts/postPatchTypes.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/vite/scripts/postPatchTypes.ts b/packages/vite/scripts/postPatchTypes.ts index 81f46551d62a51..8d170922fcfa36 100644 --- a/packages/vite/scripts/postPatchTypes.ts +++ b/packages/vite/scripts/postPatchTypes.ts @@ -10,9 +10,9 @@ const nodeDts = resolve(dir, '../dist/node/index.d.ts') // rewrite `types/*` import to relative import with file extension rewriteImports(nodeDts, (importPath) => { if (importPath.startsWith('types/')) { - return '../../' + importPath.endsWith('.js') - ? importPath - : importPath + '.js' + return ( + '../../' + (importPath.endsWith('.js') ? importPath : importPath + '.js') + ) } })