Skip to content

Commit 92eb8df

Browse files
author
Andy Hanson
committed
Allow "typings" in a package.json to be missing its extension (but also allow it to have an extension)
1 parent bb6c6fd commit 92eb8df

File tree

6 files changed

+220
-2
lines changed

6 files changed

+220
-2
lines changed

src/compiler/program.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,9 @@ namespace ts {
720720
const typesFile = tryReadTypesSection(packageJsonPath, candidate, state);
721721
if (typesFile) {
722722
const onlyRecordFailures = !directoryProbablyExists(getDirectoryPath(typesFile), state.host);
723-
// The package.json "typings" property must specify the file with extension, so just try that exact filename.
724-
const result = tryFile(typesFile, failedLookupLocation, onlyRecordFailures, state);
723+
// A package.json "typings" may specify an exact filename, or may choose to omit an extension.
724+
const result = tryFile(typesFile, failedLookupLocation, onlyRecordFailures, state) ||
725+
tryAddingExtensions(typesFile, extensions, failedLookupLocation, onlyRecordFailures, state);
725726
if (result) {
726727
return result;
727728
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//// [tests/cases/conformance/typings/typingsLookup4.ts] ////
2+
3+
//// [package.json]
4+
{ "typings": "jquery.d.ts" }
5+
6+
//// [jquery.d.ts]
7+
export const j: number;
8+
9+
//// [package.json]
10+
{ "typings": "kquery" }
11+
12+
//// [kquery.d.ts]
13+
export const k: number;
14+
15+
//// [package.json]
16+
{ "typings": "lquery" }
17+
18+
//// [lquery.ts]
19+
export const l = 2;
20+
21+
//// [a.ts]
22+
import { j } from "jquery";
23+
import { k } from "kquery";
24+
import { l } from "lquery";
25+
j + k + l;
26+
27+
28+
//// [lquery.js]
29+
"use strict";
30+
exports.l = 2;
31+
//// [a.js]
32+
"use strict";
33+
var jquery_1 = require("jquery");
34+
var kquery_1 = require("kquery");
35+
var lquery_1 = require("lquery");
36+
jquery_1.j + kquery_1.k + lquery_1.l;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== /a.ts ===
2+
import { j } from "jquery";
3+
>j : Symbol(j, Decl(a.ts, 0, 8))
4+
5+
import { k } from "kquery";
6+
>k : Symbol(k, Decl(a.ts, 1, 8))
7+
8+
import { l } from "lquery";
9+
>l : Symbol(l, Decl(a.ts, 2, 8))
10+
11+
j + k + l;
12+
>j : Symbol(j, Decl(a.ts, 0, 8))
13+
>k : Symbol(k, Decl(a.ts, 1, 8))
14+
>l : Symbol(l, Decl(a.ts, 2, 8))
15+
16+
=== /node_modules/@types/jquery/jquery.d.ts ===
17+
export const j: number;
18+
>j : Symbol(j, Decl(jquery.d.ts, 0, 12))
19+
20+
=== /node_modules/@types/kquery/kquery.d.ts ===
21+
export const k: number;
22+
>k : Symbol(k, Decl(kquery.d.ts, 0, 12))
23+
24+
=== /node_modules/@types/lquery/lquery.ts ===
25+
export const l = 2;
26+
>l : Symbol(l, Decl(lquery.ts, 0, 12))
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
[
2+
"======== Resolving module 'jquery' from '/a.ts'. ========",
3+
"Module resolution kind is not specified, using 'NodeJs'.",
4+
"Loading module 'jquery' from 'node_modules' folder.",
5+
"File '/node_modules/jquery.ts' does not exist.",
6+
"File '/node_modules/jquery.tsx' does not exist.",
7+
"File '/node_modules/jquery.d.ts' does not exist.",
8+
"File '/node_modules/jquery/package.json' does not exist.",
9+
"File '/node_modules/jquery/index.ts' does not exist.",
10+
"File '/node_modules/jquery/index.tsx' does not exist.",
11+
"File '/node_modules/jquery/index.d.ts' does not exist.",
12+
"File '/node_modules/@types/jquery.ts' does not exist.",
13+
"File '/node_modules/@types/jquery.tsx' does not exist.",
14+
"File '/node_modules/@types/jquery.d.ts' does not exist.",
15+
"Found 'package.json' at '/node_modules/@types/jquery/package.json'.",
16+
"'package.json' has 'typings' field 'jquery.d.ts' that references '/node_modules/@types/jquery/jquery.d.ts'.",
17+
"File '/node_modules/@types/jquery/jquery.d.ts' exist - use it as a name resolution result.",
18+
"Resolving real path for '/node_modules/@types/jquery/jquery.d.ts', result '/node_modules/@types/jquery/jquery.d.ts'",
19+
"======== Module name 'jquery' was successfully resolved to '/node_modules/@types/jquery/jquery.d.ts'. ========",
20+
"======== Resolving module 'kquery' from '/a.ts'. ========",
21+
"Module resolution kind is not specified, using 'NodeJs'.",
22+
"Loading module 'kquery' from 'node_modules' folder.",
23+
"File '/node_modules/kquery.ts' does not exist.",
24+
"File '/node_modules/kquery.tsx' does not exist.",
25+
"File '/node_modules/kquery.d.ts' does not exist.",
26+
"File '/node_modules/kquery/package.json' does not exist.",
27+
"File '/node_modules/kquery/index.ts' does not exist.",
28+
"File '/node_modules/kquery/index.tsx' does not exist.",
29+
"File '/node_modules/kquery/index.d.ts' does not exist.",
30+
"File '/node_modules/@types/kquery.ts' does not exist.",
31+
"File '/node_modules/@types/kquery.tsx' does not exist.",
32+
"File '/node_modules/@types/kquery.d.ts' does not exist.",
33+
"Found 'package.json' at '/node_modules/@types/kquery/package.json'.",
34+
"'package.json' has 'typings' field 'kquery' that references '/node_modules/@types/kquery/kquery'.",
35+
"File '/node_modules/@types/kquery/kquery' does not exist.",
36+
"File '/node_modules/@types/kquery/kquery.ts' does not exist.",
37+
"File '/node_modules/@types/kquery/kquery.tsx' does not exist.",
38+
"File '/node_modules/@types/kquery/kquery.d.ts' exist - use it as a name resolution result.",
39+
"Resolving real path for '/node_modules/@types/kquery/kquery.d.ts', result '/node_modules/@types/kquery/kquery.d.ts'",
40+
"======== Module name 'kquery' was successfully resolved to '/node_modules/@types/kquery/kquery.d.ts'. ========",
41+
"======== Resolving module 'lquery' from '/a.ts'. ========",
42+
"Module resolution kind is not specified, using 'NodeJs'.",
43+
"Loading module 'lquery' from 'node_modules' folder.",
44+
"File '/node_modules/lquery.ts' does not exist.",
45+
"File '/node_modules/lquery.tsx' does not exist.",
46+
"File '/node_modules/lquery.d.ts' does not exist.",
47+
"File '/node_modules/lquery/package.json' does not exist.",
48+
"File '/node_modules/lquery/index.ts' does not exist.",
49+
"File '/node_modules/lquery/index.tsx' does not exist.",
50+
"File '/node_modules/lquery/index.d.ts' does not exist.",
51+
"File '/node_modules/@types/lquery.ts' does not exist.",
52+
"File '/node_modules/@types/lquery.tsx' does not exist.",
53+
"File '/node_modules/@types/lquery.d.ts' does not exist.",
54+
"Found 'package.json' at '/node_modules/@types/lquery/package.json'.",
55+
"'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.",
56+
"File '/node_modules/@types/lquery/lquery' does not exist.",
57+
"File '/node_modules/@types/lquery/lquery.ts' exist - use it as a name resolution result.",
58+
"Resolving real path for '/node_modules/@types/lquery/lquery.ts', result '/node_modules/@types/lquery/lquery.ts'",
59+
"======== Module name 'lquery' was successfully resolved to '/node_modules/@types/lquery/lquery.ts'. ========",
60+
"======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
61+
"Resolving with primary search path '/node_modules/@types'",
62+
"Found 'package.json' at '/node_modules/@types/jquery/package.json'.",
63+
"'package.json' has 'typings' field 'jquery.d.ts' that references '/node_modules/@types/jquery/jquery.d.ts'.",
64+
"File '/node_modules/@types/jquery/jquery.d.ts' exist - use it as a name resolution result.",
65+
"======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/jquery.d.ts', primary: true. ========",
66+
"======== Resolving type reference directive 'kquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
67+
"Resolving with primary search path '/node_modules/@types'",
68+
"Found 'package.json' at '/node_modules/@types/kquery/package.json'.",
69+
"'package.json' has 'typings' field 'kquery' that references '/node_modules/@types/kquery/kquery'.",
70+
"File '/node_modules/@types/kquery/kquery' does not exist.",
71+
"File '/node_modules/@types/kquery/kquery.d.ts' exist - use it as a name resolution result.",
72+
"======== Type reference directive 'kquery' was successfully resolved to '/node_modules/@types/kquery/kquery.d.ts', primary: true. ========",
73+
"======== Resolving type reference directive 'lquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
74+
"Resolving with primary search path '/node_modules/@types'",
75+
"Found 'package.json' at '/node_modules/@types/lquery/package.json'.",
76+
"'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.",
77+
"File '/node_modules/@types/lquery/lquery' does not exist.",
78+
"File '/node_modules/@types/lquery/lquery.d.ts' does not exist.",
79+
"File '/node_modules/@types/lquery/index.d.ts' does not exist.",
80+
"Looking up in 'node_modules' folder, initial location '/'",
81+
"File '/node_modules/lquery.ts' does not exist.",
82+
"File '/node_modules/lquery.d.ts' does not exist.",
83+
"File '/node_modules/lquery/package.json' does not exist.",
84+
"File '/node_modules/lquery/index.ts' does not exist.",
85+
"File '/node_modules/lquery/index.d.ts' does not exist.",
86+
"File '/node_modules/@types/lquery.ts' does not exist.",
87+
"File '/node_modules/@types/lquery.d.ts' does not exist.",
88+
"Found 'package.json' at '/node_modules/@types/lquery/package.json'.",
89+
"'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.",
90+
"File '/node_modules/@types/lquery/lquery' does not exist.",
91+
"File '/node_modules/@types/lquery/lquery.ts' exist - use it as a name resolution result.",
92+
"======== Type reference directive 'lquery' was successfully resolved to '/node_modules/@types/lquery/lquery.ts', primary: false. ========"
93+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
=== /a.ts ===
2+
import { j } from "jquery";
3+
>j : number
4+
5+
import { k } from "kquery";
6+
>k : number
7+
8+
import { l } from "lquery";
9+
>l : number
10+
11+
j + k + l;
12+
>j + k + l : number
13+
>j + k : number
14+
>j : number
15+
>k : number
16+
>l : number
17+
18+
=== /node_modules/@types/jquery/jquery.d.ts ===
19+
export const j: number;
20+
>j : number
21+
22+
=== /node_modules/@types/kquery/kquery.d.ts ===
23+
export const k: number;
24+
>k : number
25+
26+
=== /node_modules/@types/lquery/lquery.ts ===
27+
export const l = 2;
28+
>l : number
29+
>2 : number
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// @traceResolution: true
2+
// @noImplicitReferences: true
3+
// @currentDirectory: /
4+
// A file extension is optional in typings entries.
5+
6+
// @filename: /tsconfig.json
7+
{}
8+
9+
// @filename: /node_modules/@types/jquery/package.json
10+
{ "typings": "jquery.d.ts" }
11+
12+
// @filename: /node_modules/@types/jquery/jquery.d.ts
13+
export const j: number;
14+
15+
// @filename: /node_modules/@types/kquery/package.json
16+
{ "typings": "kquery" }
17+
18+
// @filename: /node_modules/@types/kquery/kquery.d.ts
19+
export const k: number;
20+
21+
// @filename: /node_modules/@types/lquery/package.json
22+
{ "typings": "lquery" }
23+
24+
// @filename: /node_modules/@types/lquery/lquery.ts
25+
export const l = 2;
26+
27+
// @filename: /a.ts
28+
import { j } from "jquery";
29+
import { k } from "kquery";
30+
import { l } from "lquery";
31+
j + k + l;

0 commit comments

Comments
 (0)