Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow "typings" in a package.json to be missing its extension #10480

Merged
1 commit merged into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
36 changes: 36 additions & 0 deletions tests/baselines/reference/typingsLookup4.js
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions tests/baselines/reference/typingsLookup4.symbols
Original file line number Diff line number Diff line change
@@ -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 changes: 93 additions & 0 deletions tests/baselines/reference/typingsLookup4.trace.json
Original file line number Diff line number Diff line change
@@ -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 changes: 30 additions & 0 deletions tests/baselines/reference/typingsLookup4.types
Original file line number Diff line number Diff line change
@@ -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 changes: 31 additions & 0 deletions tests/cases/conformance/typings/typingsLookup4.ts
Original file line number Diff line number Diff line change
@@ -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;