Skip to content

Commit 2480e8d

Browse files
committed
do secondary lookup only if module has non-relative name
1 parent de71002 commit 2480e8d

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

Jakefile.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ if (process.env.path !== undefined) {
3737
}
3838

3939
function filesFromConfig(configPath) {
40-
console.log(configPath);
4140
var configText = fs.readFileSync(configPath).toString();
4241
var config = ts.parseConfigFileTextToJson(configPath, configText, /*stripComments*/ true);
4342
if (config.error) {

src/harness/unittests/typingsInstaller.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,45 @@ namespace ts.projectSystem {
4646

4747
import typingsName = server.typingsInstaller.typingsName;
4848

49+
describe("local module", () => {
50+
it("should not be picked up", () => {
51+
const f1 = {
52+
path: "/a/app.js",
53+
content: "const c = require('./config');"
54+
};
55+
const f2 = {
56+
path: "/a/config.js",
57+
content: "export let x = 1"
58+
};
59+
const typesCache = "/cache"
60+
const typesConfig = {
61+
path: typesCache + "/node_modules/@types/config/index.d.ts",
62+
content: "export let y: number;"
63+
};
64+
const config = {
65+
path: "/a/jsconfig.json",
66+
content: JSON.stringify({
67+
compilerOptions: { moduleResolution: "commonjs" },
68+
typeAcquisition: { enable: true }
69+
})
70+
};
71+
const host = createServerHost([f1, f2, config, typesConfig]);
72+
const installer = new (class extends Installer {
73+
constructor() {
74+
super(host, { typesRegistry: createTypesRegistry("config"), globalTypingsCacheLocation: typesCache });
75+
}
76+
installWorker(_requestId: number, _args: string[], _cwd: string, _cb: server.typingsInstaller.RequestCompletedAction) {
77+
assert(false, "should not be called")
78+
}
79+
})();
80+
const service = createProjectService(host, { typingsInstaller: installer });
81+
service.openClientFile(f1.path);
82+
service.checkNumberOfProjects({ configuredProjects: 1 });
83+
checkProjectActualFiles(service.configuredProjects[0], [f1.path, f2.path]);
84+
installer.installAll(0);
85+
});
86+
});
87+
4988
describe("typingsInstaller", () => {
5089
it("configured projects (typings installed) 1", () => {
5190
const file1 = {

src/server/lsHost.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace ts.server {
2828
: undefined;
2929
const primaryResult = resolveModuleName(moduleName, containingFile, compilerOptions, host);
3030
// return result immediately only if it is .ts, .tsx or .d.ts
31-
if (!(primaryResult.resolvedModule && extensionIsTypeScript(primaryResult.resolvedModule.extension)) && globalCache !== undefined) {
31+
if (moduleHasNonRelativeName(moduleName) && !(primaryResult.resolvedModule && extensionIsTypeScript(primaryResult.resolvedModule.extension)) && globalCache !== undefined) {
3232
// otherwise try to load typings from @types
3333

3434
// create different collection of failed lookup locations for second pass

0 commit comments

Comments
 (0)