Directory not found error when adding source file to node_modules folder with in memory file system
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 238
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
Doing this...
```ts
import { Project, ts } from "ts-morph";
// setup
const project = new Project({ useInMemoryFileSystem: true });
project.createSourceFile("/node_modules/@types/node/path.d.ts", `
declare module 'path' {
namespace path {
interface ParsedPath {}
interface FormatInputPathObject {}
interface PlatformPath {
normalize(p: string): string;
join(...paths: string[]): string;
// other...
}
}
const path: path.PlatformPath;
export = path;
}`);
const sourceFile = project.createSourceFile("file.ts", `
import path from "path";
`);
for (const importDeclaration of sourceFile.getImportDeclarations()) {
const moduleSpecifierSymbol = importDeclaration.getModuleSpecifier().getSymbolOrThrow();
for (const symbol of moduleSpecifierSymbol.getExports()) {
console.log(symbol.getName());
}
}
```
Leads to:
```
Error: Directory not found: /node_modules/@types
at InMemoryFileSystemHost.readDirSync (V:\test\node_modules\@ts-morph\common\dist\ts-morph-common.js:1830:19)
at TransactionalFileSystem.readDirSync (V:\test\node_modules\@ts-morph\common\dist\ts-morph-common.js:1583:58)
at TransactionalFileSystem.getDirectories (V:\test\node_modules\@ts-morph\common\dist\ts-morph-common.js:1615:21)
at Object.getDirectories (V:\test\node_modules\@ts-morph\common\dist\ts-morph-common.js:2054:59)
at Object.getAutomaticTypeDirectiveNames (V:\test\node_modules\typescript\lib\typescript.js:29701:52)
at Object.createProgram (V:\test\node_modules\typescript\lib\typescript.js:100141:56)
at Program._getOrCreateCompilerObject (V:\test\node_modules\ts-morph\dist\ts-morph.js:16710:57)
at Program.get compilerObject [as compilerObject] (V:\test\node_modules\ts-morph\dist\ts-morph.js:16701:21)
at TypeChecker._getCompilerObject (V:\test\node_modules\ts-morph\dist\ts-morph.js:16719:45)
at TypeChecker.get compilerObject [as compilerObject] (V:\test\node_modules\ts-morph\dist\ts-morph.js:16599:21)
```
Contributor guide
Assessment
This issue has not been assessed yet.