Set maxNodeModuleJsDepth for inferred projects

This commit is contained in:
zhengbli 2016-10-12 18:05:01 -07:00
parent 31a55e6452
commit 536d703d9e
2 changed files with 29 additions and 0 deletions

View File

@ -2387,4 +2387,26 @@ namespace ts.projectSystem {
assert.isTrue(errorResult.length === 0);
});
});
describe("maxNodeModuleJsDepth for inferred projects", () => {
it("should be set by default", () => {
const file1: FileOrFolder = {
path: "/a/b/file1.js",
content: `var t = require("test"); t.`
};
const moduleFile: FileOrFolder = {
path: "/a/b/node_modules/test/index.js",
content: `var v = 10; module.exports = v;`
};
const host = createServerHost([file1, moduleFile]);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
const project = projectService.inferredProjects[0];
const sourceFile = project.getSourceFile(<Path>file1.path);
assert.isTrue("test" in sourceFile.resolvedModules);
assert.equal((<ResolvedModule>sourceFile.resolvedModules["test"]).resolvedFileName, moduleFile.path);
});
});
}

View File

@ -126,6 +126,13 @@ namespace ts.server {
this.compilerOptions.allowNonTsExtensions = true;
}
if (this.projectKind === ProjectKind.Inferred) {
// Add default compiler options for inferred projects here
if (this.compilerOptions.maxNodeModuleJsDepth === undefined) {
this.compilerOptions.maxNodeModuleJsDepth = 2;
}
}
if (languageServiceEnabled) {
this.enableLanguageService();
}