From e2ab0e7acfbb11d0864656db51ac223adbb70e69 Mon Sep 17 00:00:00 2001 From: Andrea Date: Thu, 3 Sep 2026 17:37:49 -0400 Subject: [PATCH] fix(typescript-vfs): resolve lib dir via getDefaultLibFilePath so re-export wrappers work createDefaultMapFromNodeModules located lib.*.d.ts via path.dirname(require.resolve("typescript")), the resolved entry file's directory. For the official @typescript/typescript6 TS 7 side-by-side wrapper (whose entry re-exports @typescript/old) that directory has no lib files, so the default map was built without the stdlib and the VFS later threw. Derive the lib dir from the compiler's getDefaultLibFilePath, which follows the re-export. --- packages/typescript-vfs/src/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) mode change 100755 => 100644 packages/typescript-vfs/src/index.ts diff --git a/packages/typescript-vfs/src/index.ts b/packages/typescript-vfs/src/index.ts old mode 100755 new mode 100644 index 9dfeec90f1b7..05460db79817 --- a/packages/typescript-vfs/src/index.ts +++ b/packages/typescript-vfs/src/index.ts @@ -290,14 +290,18 @@ export const createDefaultMapFromNodeModules = ( const path = requirePath() const fs = requireFS() + // Resolve the lib dir from the compiler, which follows re-export wrappers (e.g. @typescript/typescript6) + // to the real stdlib; require.resolve would point at the wrapper's own lib/, which has no lib.*.d.ts. + const ts = _ts ?? (require("typescript") as typeof import("typescript")) + const libDir = tsLibDirectory || path.dirname(ts.getDefaultLibFilePath(_compilerOptions)) + const getLib = (name: string) => { - const lib = tsLibDirectory || path.dirname(require.resolve("typescript")) - return fs.readFileSync(path.join(lib, name), "utf8") + return fs.readFileSync(path.join(libDir, name), "utf8") } const isDtsFile = (file: string) => /\.d\.([^\.]+\.)?[cm]?ts$/i.test(file) - const libFiles = fs.readdirSync(tsLibDirectory || path.dirname(require.resolve("typescript"))) + const libFiles = fs.readdirSync(libDir) const knownLibFiles = libFiles.filter(f => f.startsWith("lib.") && isDtsFile(f)) const fsMap = new Map()