Skip to content

Commit 536d703

Browse files
committed
Set maxNodeModuleJsDepth for inferred projects
1 parent 31a55e6 commit 536d703

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,4 +2387,26 @@ namespace ts.projectSystem {
23872387
assert.isTrue(errorResult.length === 0);
23882388
});
23892389
});
2390+
2391+
describe("maxNodeModuleJsDepth for inferred projects", () => {
2392+
it("should be set by default", () => {
2393+
const file1: FileOrFolder = {
2394+
path: "/a/b/file1.js",
2395+
content: `var t = require("test"); t.`
2396+
};
2397+
const moduleFile: FileOrFolder = {
2398+
path: "/a/b/node_modules/test/index.js",
2399+
content: `var v = 10; module.exports = v;`
2400+
};
2401+
2402+
const host = createServerHost([file1, moduleFile]);
2403+
const projectService = createProjectService(host);
2404+
projectService.openClientFile(file1.path);
2405+
2406+
const project = projectService.inferredProjects[0];
2407+
const sourceFile = project.getSourceFile(<Path>file1.path);
2408+
assert.isTrue("test" in sourceFile.resolvedModules);
2409+
assert.equal((<ResolvedModule>sourceFile.resolvedModules["test"]).resolvedFileName, moduleFile.path);
2410+
});
2411+
});
23902412
}

src/server/project.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ namespace ts.server {
126126
this.compilerOptions.allowNonTsExtensions = true;
127127
}
128128

129+
if (this.projectKind === ProjectKind.Inferred) {
130+
// Add default compiler options for inferred projects here
131+
if (this.compilerOptions.maxNodeModuleJsDepth === undefined) {
132+
this.compilerOptions.maxNodeModuleJsDepth = 2;
133+
}
134+
}
135+
129136
if (languageServiceEnabled) {
130137
this.enableLanguageService();
131138
}

0 commit comments

Comments
 (0)