From 2480e8d492ecd90849b189f98e57eb63ad1918c3 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 8 Feb 2017 20:35:01 -0800 Subject: [PATCH] do secondary lookup only if module has non-relative name --- Jakefile.js | 1 - src/harness/unittests/typingsInstaller.ts | 39 +++++++++++++++++++++++ src/server/lsHost.ts | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index f422a99572..4fd3be57e4 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -37,7 +37,6 @@ if (process.env.path !== undefined) { } function filesFromConfig(configPath) { - console.log(configPath); var configText = fs.readFileSync(configPath).toString(); var config = ts.parseConfigFileTextToJson(configPath, configText, /*stripComments*/ true); if (config.error) { diff --git a/src/harness/unittests/typingsInstaller.ts b/src/harness/unittests/typingsInstaller.ts index 2b79141c3e..29076df80f 100644 --- a/src/harness/unittests/typingsInstaller.ts +++ b/src/harness/unittests/typingsInstaller.ts @@ -46,6 +46,45 @@ namespace ts.projectSystem { import typingsName = server.typingsInstaller.typingsName; + describe("local module", () => { + it("should not be picked up", () => { + const f1 = { + path: "/a/app.js", + content: "const c = require('./config');" + }; + const f2 = { + path: "/a/config.js", + content: "export let x = 1" + }; + const typesCache = "/cache" + const typesConfig = { + path: typesCache + "/node_modules/@types/config/index.d.ts", + content: "export let y: number;" + }; + const config = { + path: "/a/jsconfig.json", + content: JSON.stringify({ + compilerOptions: { moduleResolution: "commonjs" }, + typeAcquisition: { enable: true } + }) + }; + const host = createServerHost([f1, f2, config, typesConfig]); + const installer = new (class extends Installer { + constructor() { + super(host, { typesRegistry: createTypesRegistry("config"), globalTypingsCacheLocation: typesCache }); + } + installWorker(_requestId: number, _args: string[], _cwd: string, _cb: server.typingsInstaller.RequestCompletedAction) { + assert(false, "should not be called") + } + })(); + const service = createProjectService(host, { typingsInstaller: installer }); + service.openClientFile(f1.path); + service.checkNumberOfProjects({ configuredProjects: 1 }); + checkProjectActualFiles(service.configuredProjects[0], [f1.path, f2.path]); + installer.installAll(0); + }); + }); + describe("typingsInstaller", () => { it("configured projects (typings installed) 1", () => { const file1 = { diff --git a/src/server/lsHost.ts b/src/server/lsHost.ts index 9d8c9c08cb..eee80d82e7 100644 --- a/src/server/lsHost.ts +++ b/src/server/lsHost.ts @@ -28,7 +28,7 @@ namespace ts.server { : undefined; const primaryResult = resolveModuleName(moduleName, containingFile, compilerOptions, host); // return result immediately only if it is .ts, .tsx or .d.ts - if (!(primaryResult.resolvedModule && extensionIsTypeScript(primaryResult.resolvedModule.extension)) && globalCache !== undefined) { + if (moduleHasNonRelativeName(moduleName) && !(primaryResult.resolvedModule && extensionIsTypeScript(primaryResult.resolvedModule.extension)) && globalCache !== undefined) { // otherwise try to load typings from @types // create different collection of failed lookup locations for second pass