mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
Allow "typings" in a package.json to be missing its extension (but also allow it to have an extension)
This commit is contained in:
parent
bb6c6fd003
commit
92eb8df68c
@ -720,8 +720,9 @@ namespace ts {
|
||||
const typesFile = tryReadTypesSection(packageJsonPath, candidate, state);
|
||||
if (typesFile) {
|
||||
const onlyRecordFailures = !directoryProbablyExists(getDirectoryPath(typesFile), state.host);
|
||||
// The package.json "typings" property must specify the file with extension, so just try that exact filename.
|
||||
const result = tryFile(typesFile, failedLookupLocation, onlyRecordFailures, state);
|
||||
// A package.json "typings" may specify an exact filename, or may choose to omit an extension.
|
||||
const result = tryFile(typesFile, failedLookupLocation, onlyRecordFailures, state) ||
|
||||
tryAddingExtensions(typesFile, extensions, failedLookupLocation, onlyRecordFailures, state);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
36
tests/baselines/reference/typingsLookup4.js
Normal file
36
tests/baselines/reference/typingsLookup4.js
Normal file
@ -0,0 +1,36 @@
|
||||
//// [tests/cases/conformance/typings/typingsLookup4.ts] ////
|
||||
|
||||
//// [package.json]
|
||||
{ "typings": "jquery.d.ts" }
|
||||
|
||||
//// [jquery.d.ts]
|
||||
export const j: number;
|
||||
|
||||
//// [package.json]
|
||||
{ "typings": "kquery" }
|
||||
|
||||
//// [kquery.d.ts]
|
||||
export const k: number;
|
||||
|
||||
//// [package.json]
|
||||
{ "typings": "lquery" }
|
||||
|
||||
//// [lquery.ts]
|
||||
export const l = 2;
|
||||
|
||||
//// [a.ts]
|
||||
import { j } from "jquery";
|
||||
import { k } from "kquery";
|
||||
import { l } from "lquery";
|
||||
j + k + l;
|
||||
|
||||
|
||||
//// [lquery.js]
|
||||
"use strict";
|
||||
exports.l = 2;
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
var jquery_1 = require("jquery");
|
||||
var kquery_1 = require("kquery");
|
||||
var lquery_1 = require("lquery");
|
||||
jquery_1.j + kquery_1.k + lquery_1.l;
|
||||
27
tests/baselines/reference/typingsLookup4.symbols
Normal file
27
tests/baselines/reference/typingsLookup4.symbols
Normal file
@ -0,0 +1,27 @@
|
||||
=== /a.ts ===
|
||||
import { j } from "jquery";
|
||||
>j : Symbol(j, Decl(a.ts, 0, 8))
|
||||
|
||||
import { k } from "kquery";
|
||||
>k : Symbol(k, Decl(a.ts, 1, 8))
|
||||
|
||||
import { l } from "lquery";
|
||||
>l : Symbol(l, Decl(a.ts, 2, 8))
|
||||
|
||||
j + k + l;
|
||||
>j : Symbol(j, Decl(a.ts, 0, 8))
|
||||
>k : Symbol(k, Decl(a.ts, 1, 8))
|
||||
>l : Symbol(l, Decl(a.ts, 2, 8))
|
||||
|
||||
=== /node_modules/@types/jquery/jquery.d.ts ===
|
||||
export const j: number;
|
||||
>j : Symbol(j, Decl(jquery.d.ts, 0, 12))
|
||||
|
||||
=== /node_modules/@types/kquery/kquery.d.ts ===
|
||||
export const k: number;
|
||||
>k : Symbol(k, Decl(kquery.d.ts, 0, 12))
|
||||
|
||||
=== /node_modules/@types/lquery/lquery.ts ===
|
||||
export const l = 2;
|
||||
>l : Symbol(l, Decl(lquery.ts, 0, 12))
|
||||
|
||||
93
tests/baselines/reference/typingsLookup4.trace.json
Normal file
93
tests/baselines/reference/typingsLookup4.trace.json
Normal file
@ -0,0 +1,93 @@
|
||||
[
|
||||
"======== Resolving module 'jquery' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module 'jquery' from 'node_modules' folder.",
|
||||
"File '/node_modules/jquery.ts' does not exist.",
|
||||
"File '/node_modules/jquery.tsx' does not exist.",
|
||||
"File '/node_modules/jquery.d.ts' does not exist.",
|
||||
"File '/node_modules/jquery/package.json' does not exist.",
|
||||
"File '/node_modules/jquery/index.ts' does not exist.",
|
||||
"File '/node_modules/jquery/index.tsx' does not exist.",
|
||||
"File '/node_modules/jquery/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/jquery.ts' does not exist.",
|
||||
"File '/node_modules/@types/jquery.tsx' does not exist.",
|
||||
"File '/node_modules/@types/jquery.d.ts' does not exist.",
|
||||
"Found 'package.json' at '/node_modules/@types/jquery/package.json'.",
|
||||
"'package.json' has 'typings' field 'jquery.d.ts' that references '/node_modules/@types/jquery/jquery.d.ts'.",
|
||||
"File '/node_modules/@types/jquery/jquery.d.ts' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/node_modules/@types/jquery/jquery.d.ts', result '/node_modules/@types/jquery/jquery.d.ts'",
|
||||
"======== Module name 'jquery' was successfully resolved to '/node_modules/@types/jquery/jquery.d.ts'. ========",
|
||||
"======== Resolving module 'kquery' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module 'kquery' from 'node_modules' folder.",
|
||||
"File '/node_modules/kquery.ts' does not exist.",
|
||||
"File '/node_modules/kquery.tsx' does not exist.",
|
||||
"File '/node_modules/kquery.d.ts' does not exist.",
|
||||
"File '/node_modules/kquery/package.json' does not exist.",
|
||||
"File '/node_modules/kquery/index.ts' does not exist.",
|
||||
"File '/node_modules/kquery/index.tsx' does not exist.",
|
||||
"File '/node_modules/kquery/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/kquery.ts' does not exist.",
|
||||
"File '/node_modules/@types/kquery.tsx' does not exist.",
|
||||
"File '/node_modules/@types/kquery.d.ts' does not exist.",
|
||||
"Found 'package.json' at '/node_modules/@types/kquery/package.json'.",
|
||||
"'package.json' has 'typings' field 'kquery' that references '/node_modules/@types/kquery/kquery'.",
|
||||
"File '/node_modules/@types/kquery/kquery' does not exist.",
|
||||
"File '/node_modules/@types/kquery/kquery.ts' does not exist.",
|
||||
"File '/node_modules/@types/kquery/kquery.tsx' does not exist.",
|
||||
"File '/node_modules/@types/kquery/kquery.d.ts' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/node_modules/@types/kquery/kquery.d.ts', result '/node_modules/@types/kquery/kquery.d.ts'",
|
||||
"======== Module name 'kquery' was successfully resolved to '/node_modules/@types/kquery/kquery.d.ts'. ========",
|
||||
"======== Resolving module 'lquery' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module 'lquery' from 'node_modules' folder.",
|
||||
"File '/node_modules/lquery.ts' does not exist.",
|
||||
"File '/node_modules/lquery.tsx' does not exist.",
|
||||
"File '/node_modules/lquery.d.ts' does not exist.",
|
||||
"File '/node_modules/lquery/package.json' does not exist.",
|
||||
"File '/node_modules/lquery/index.ts' does not exist.",
|
||||
"File '/node_modules/lquery/index.tsx' does not exist.",
|
||||
"File '/node_modules/lquery/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/lquery.ts' does not exist.",
|
||||
"File '/node_modules/@types/lquery.tsx' does not exist.",
|
||||
"File '/node_modules/@types/lquery.d.ts' does not exist.",
|
||||
"Found 'package.json' at '/node_modules/@types/lquery/package.json'.",
|
||||
"'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.",
|
||||
"File '/node_modules/@types/lquery/lquery' does not exist.",
|
||||
"File '/node_modules/@types/lquery/lquery.ts' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/node_modules/@types/lquery/lquery.ts', result '/node_modules/@types/lquery/lquery.ts'",
|
||||
"======== Module name 'lquery' was successfully resolved to '/node_modules/@types/lquery/lquery.ts'. ========",
|
||||
"======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
|
||||
"Resolving with primary search path '/node_modules/@types'",
|
||||
"Found 'package.json' at '/node_modules/@types/jquery/package.json'.",
|
||||
"'package.json' has 'typings' field 'jquery.d.ts' that references '/node_modules/@types/jquery/jquery.d.ts'.",
|
||||
"File '/node_modules/@types/jquery/jquery.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/jquery.d.ts', primary: true. ========",
|
||||
"======== Resolving type reference directive 'kquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
|
||||
"Resolving with primary search path '/node_modules/@types'",
|
||||
"Found 'package.json' at '/node_modules/@types/kquery/package.json'.",
|
||||
"'package.json' has 'typings' field 'kquery' that references '/node_modules/@types/kquery/kquery'.",
|
||||
"File '/node_modules/@types/kquery/kquery' does not exist.",
|
||||
"File '/node_modules/@types/kquery/kquery.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'kquery' was successfully resolved to '/node_modules/@types/kquery/kquery.d.ts', primary: true. ========",
|
||||
"======== Resolving type reference directive 'lquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
|
||||
"Resolving with primary search path '/node_modules/@types'",
|
||||
"Found 'package.json' at '/node_modules/@types/lquery/package.json'.",
|
||||
"'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.",
|
||||
"File '/node_modules/@types/lquery/lquery' does not exist.",
|
||||
"File '/node_modules/@types/lquery/lquery.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/lquery/index.d.ts' does not exist.",
|
||||
"Looking up in 'node_modules' folder, initial location '/'",
|
||||
"File '/node_modules/lquery.ts' does not exist.",
|
||||
"File '/node_modules/lquery.d.ts' does not exist.",
|
||||
"File '/node_modules/lquery/package.json' does not exist.",
|
||||
"File '/node_modules/lquery/index.ts' does not exist.",
|
||||
"File '/node_modules/lquery/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/lquery.ts' does not exist.",
|
||||
"File '/node_modules/@types/lquery.d.ts' does not exist.",
|
||||
"Found 'package.json' at '/node_modules/@types/lquery/package.json'.",
|
||||
"'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.",
|
||||
"File '/node_modules/@types/lquery/lquery' does not exist.",
|
||||
"File '/node_modules/@types/lquery/lquery.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'lquery' was successfully resolved to '/node_modules/@types/lquery/lquery.ts', primary: false. ========"
|
||||
]
|
||||
30
tests/baselines/reference/typingsLookup4.types
Normal file
30
tests/baselines/reference/typingsLookup4.types
Normal file
@ -0,0 +1,30 @@
|
||||
=== /a.ts ===
|
||||
import { j } from "jquery";
|
||||
>j : number
|
||||
|
||||
import { k } from "kquery";
|
||||
>k : number
|
||||
|
||||
import { l } from "lquery";
|
||||
>l : number
|
||||
|
||||
j + k + l;
|
||||
>j + k + l : number
|
||||
>j + k : number
|
||||
>j : number
|
||||
>k : number
|
||||
>l : number
|
||||
|
||||
=== /node_modules/@types/jquery/jquery.d.ts ===
|
||||
export const j: number;
|
||||
>j : number
|
||||
|
||||
=== /node_modules/@types/kquery/kquery.d.ts ===
|
||||
export const k: number;
|
||||
>k : number
|
||||
|
||||
=== /node_modules/@types/lquery/lquery.ts ===
|
||||
export const l = 2;
|
||||
>l : number
|
||||
>2 : number
|
||||
|
||||
31
tests/cases/conformance/typings/typingsLookup4.ts
Normal file
31
tests/cases/conformance/typings/typingsLookup4.ts
Normal file
@ -0,0 +1,31 @@
|
||||
// @traceResolution: true
|
||||
// @noImplicitReferences: true
|
||||
// @currentDirectory: /
|
||||
// A file extension is optional in typings entries.
|
||||
|
||||
// @filename: /tsconfig.json
|
||||
{}
|
||||
|
||||
// @filename: /node_modules/@types/jquery/package.json
|
||||
{ "typings": "jquery.d.ts" }
|
||||
|
||||
// @filename: /node_modules/@types/jquery/jquery.d.ts
|
||||
export const j: number;
|
||||
|
||||
// @filename: /node_modules/@types/kquery/package.json
|
||||
{ "typings": "kquery" }
|
||||
|
||||
// @filename: /node_modules/@types/kquery/kquery.d.ts
|
||||
export const k: number;
|
||||
|
||||
// @filename: /node_modules/@types/lquery/package.json
|
||||
{ "typings": "lquery" }
|
||||
|
||||
// @filename: /node_modules/@types/lquery/lquery.ts
|
||||
export const l = 2;
|
||||
|
||||
// @filename: /a.ts
|
||||
import { j } from "jquery";
|
||||
import { k } from "kquery";
|
||||
import { l } from "lquery";
|
||||
j + k + l;
|
||||
Loading…
x
Reference in New Issue
Block a user