Compare commits
4 commits
main
...
type_roots
Author | SHA1 | Date | |
---|---|---|---|
|
ad9d32813e | ||
|
e1bd44d95c | ||
|
b866bf1763 | ||
|
119cc5dd1a |
|
@ -59,8 +59,7 @@ namespace ts {
|
|||
|
||||
interface ModuleResolutionState {
|
||||
host: ModuleResolutionHost;
|
||||
// We only use this subset of the compiler options.
|
||||
compilerOptions: { rootDirs?: string[], baseUrl?: string, paths?: MapLike<string[]> };
|
||||
compilerOptions: CompilerOptions;
|
||||
traceEnabled: boolean;
|
||||
}
|
||||
|
||||
|
@ -125,7 +124,9 @@ namespace ts {
|
|||
currentDirectory = host.getCurrentDirectory();
|
||||
}
|
||||
|
||||
return currentDirectory !== undefined && getDefaultTypeRoots(currentDirectory, host);
|
||||
if (currentDirectory !== undefined) {
|
||||
return getDefaultTypeRoots(currentDirectory, host);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,18 +141,12 @@ namespace ts {
|
|||
|
||||
let typeRoots: string[];
|
||||
|
||||
while (true) {
|
||||
const atTypes = combinePaths(currentDirectory, nodeModulesAtTypes);
|
||||
forEachAncestorDirectory(currentDirectory, directory => {
|
||||
const atTypes = combinePaths(directory, nodeModulesAtTypes);
|
||||
if (host.directoryExists(atTypes)) {
|
||||
(typeRoots || (typeRoots = [])).push(atTypes);
|
||||
}
|
||||
|
||||
const parent = getDirectoryPath(currentDirectory);
|
||||
if (parent === currentDirectory) {
|
||||
break;
|
||||
}
|
||||
currentDirectory = parent;
|
||||
}
|
||||
});
|
||||
|
||||
return typeRoots;
|
||||
}
|
||||
|
@ -197,23 +192,15 @@ namespace ts {
|
|||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", "));
|
||||
}
|
||||
for (const typeRoot of typeRoots) {
|
||||
const candidate = combinePaths(typeRoot, typeReferenceDirectiveName);
|
||||
const candidateDirectory = getDirectoryPath(candidate);
|
||||
|
||||
const resolved = resolvedTypeScriptOnly(
|
||||
loadNodeModuleFromDirectory(Extensions.DtsOnly, candidate, failedLookupLocations,
|
||||
!directoryProbablyExists(candidateDirectory, host), moduleResolutionState));
|
||||
|
||||
if (resolved) {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolved, true);
|
||||
}
|
||||
return {
|
||||
resolvedTypeReferenceDirective: { primary: true, resolvedFileName: resolved },
|
||||
failedLookupLocations
|
||||
};
|
||||
const resolved = resolvedTypeScriptOnly(fooTypeRoots(typeRoots, typeReferenceDirectiveName, failedLookupLocations, moduleResolutionState));
|
||||
if (resolved) {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolved, true);
|
||||
}
|
||||
return {
|
||||
resolvedTypeReferenceDirective: { primary: true, resolvedFileName: resolved },
|
||||
failedLookupLocations
|
||||
};
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -230,7 +217,7 @@ namespace ts {
|
|||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Looking_up_in_node_modules_folder_initial_location_0, initialLocationForSecondaryLookup);
|
||||
}
|
||||
resolvedFile = resolvedTypeScriptOnly(loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState, /*checkOneLevel*/ false));
|
||||
resolvedFile = resolvedTypeScriptOnly(loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState));
|
||||
if (traceEnabled) {
|
||||
if (resolvedFile) {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFile, false);
|
||||
|
@ -251,6 +238,24 @@ namespace ts {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a module from typeRoots. Used by node/classic resolvers.
|
||||
* This should be done in *addition* to climbing ancestor directories and looking for node_modules/@types.
|
||||
* It should be done after looking for TypeScript but before JavaScript.
|
||||
* This should only be done for global imports.
|
||||
*/
|
||||
function loadModuleFromTypeRoots(moduleName: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
//don't want to include the default node_modules/@types type roots since that's already been looked for in the node_modules/@types search.
|
||||
const roots = state.compilerOptions.typeRoots; //getEffectiveTypeRoots(state.compilerOptions, state.host);
|
||||
return fooTypeRoots(roots, moduleName, failedLookupLocations, state);
|
||||
}
|
||||
|
||||
//name: searchInTypeRoots
|
||||
function fooTypeRoots(typeRoots: string[] | undefined, moduleName: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
return forEach(typeRoots, root =>
|
||||
loadNodeModuleFromDirectoryHelper(Extensions.DtsOnly, combinePaths(root, moduleName), failedLookupLocations, state));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a set of options, returns the set of type directive names
|
||||
* that should be included for this program automatically.
|
||||
|
@ -297,7 +302,8 @@ namespace ts {
|
|||
|
||||
let moduleResolution = compilerOptions.moduleResolution;
|
||||
if (moduleResolution === undefined) {
|
||||
moduleResolution = getEmitModuleKind(compilerOptions) === ModuleKind.CommonJS ? ModuleResolutionKind.NodeJs : ModuleResolutionKind.Classic;
|
||||
//todo: ugly cast, just use CompilerOptions...
|
||||
moduleResolution = getEmitModuleKind(compilerOptions as CompilerOptions) === ModuleKind.CommonJS ? ModuleResolutionKind.NodeJs : ModuleResolutionKind.Classic;
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Module_resolution_kind_is_not_specified_using_0, ModuleResolutionKind[moduleResolution]);
|
||||
}
|
||||
|
@ -541,8 +547,9 @@ namespace ts {
|
|||
|
||||
const failedLookupLocations: string[] = [];
|
||||
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
|
||||
const nonRelative = moduleHasNonRelativeName(moduleName);
|
||||
|
||||
const result = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript);
|
||||
const result = tryResolve(Extensions.TypeScript) || tryTypeRoots() || tryResolve(Extensions.JavaScript); //Should we try typeroots first? last?
|
||||
if (result) {
|
||||
const { resolved, isExternalLibraryImport } = result;
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved && resolvedWithRealpath(resolved, host, traceEnabled), isExternalLibraryImport, failedLookupLocations);
|
||||
|
@ -555,11 +562,11 @@ namespace ts {
|
|||
return { resolved, isExternalLibraryImport: false };
|
||||
}
|
||||
|
||||
if (moduleHasNonRelativeName(moduleName)) {
|
||||
if (nonRelative) {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Loading_module_0_from_node_modules_folder, moduleName);
|
||||
}
|
||||
const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state, /*checkOneLevel*/ false);
|
||||
const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state);
|
||||
return resolved && { resolved, isExternalLibraryImport: true };
|
||||
}
|
||||
else {
|
||||
|
@ -568,6 +575,14 @@ namespace ts {
|
|||
return resolved && { resolved, isExternalLibraryImport: false };
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: this may duplicate effort from tryResolve!
|
||||
function tryTypeRoots(): { resolved: Resolved, isExternalLibraryImport: boolean } | undefined {
|
||||
if (nonRelative) {
|
||||
const resolved = loadModuleFromTypeRoots(moduleName, failedLookupLocations, state); //loadModuleFromAnyTypeLocation(moduleName, containingDirectory, failedLookupLocations, state);
|
||||
return resolved && { resolved, isExternalLibraryImport: true };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resolvedWithRealpath(resolved: Resolved, host: ModuleResolutionHost, traceEnabled: boolean): Resolved {
|
||||
|
@ -662,9 +677,18 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModulesFolder(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
const nodeModulesFolder = combinePaths(directory, "node_modules");
|
||||
const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host);
|
||||
const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName));
|
||||
|
||||
return loadModuleFromFile(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state) ||
|
||||
loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state);
|
||||
}
|
||||
|
||||
function loadNodeModuleFromDirectory(extensions: Extensions, candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
const packageJsonPath = pathToPackageJson(candidate);
|
||||
const directoryExists = !onlyRecordFailures && directoryProbablyExists(candidate, state.host);
|
||||
const directoryExists = !onlyRecordFailures && directoryProbablyExists(candidate, state.host); //We do the check a second time??? silly!
|
||||
|
||||
if (directoryExists && state.host.fileExists(packageJsonPath)) {
|
||||
if (state.traceEnabled) {
|
||||
|
@ -700,49 +724,38 @@ namespace ts {
|
|||
|
||||
return loadModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocation, !directoryExists, state);
|
||||
}
|
||||
//NEATER
|
||||
function loadNodeModuleFromDirectoryHelper(extensions: Extensions, directory: string, failedLookupLocations: string[], state: ModuleResolutionState) {
|
||||
//const onlyRecordFailures = !directoryProbablyExists(directory, state.host);
|
||||
return loadNodeModuleFromDirectory(extensions, directory, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
}
|
||||
|
||||
function pathToPackageJson(directory: string): string {
|
||||
return combinePaths(directory, "package.json");
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModulesFolder(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
const nodeModulesFolder = combinePaths(directory, "node_modules");
|
||||
const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host);
|
||||
const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName));
|
||||
|
||||
return loadModuleFromFile(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state) ||
|
||||
loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state);
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModules(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState, checkOneLevel: boolean): Resolved | undefined {
|
||||
return loadModuleFromNodeModulesWorker(extensions, moduleName, directory, failedLookupLocations, state, checkOneLevel, /*typesOnly*/ false);
|
||||
}
|
||||
//check uses
|
||||
function loadModuleFromNodeModulesAtTypes(moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
return loadModuleFromNodeModulesWorker(Extensions.TypeScript, moduleName, directory, failedLookupLocations, state, /*checkOneLevel*/ false, /*typesOnly*/ true);
|
||||
//should this be Extensions.DtsOnly??? That would match loadModulesFromTypeRoots
|
||||
return loadModuleFromNodeModules(Extensions.TypeScript, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ true);
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModulesWorker(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState, checkOneLevel: boolean, typesOnly: boolean): Resolved | undefined {
|
||||
//Dont' do @types lookup here, use loadModuleFromTypeRoots instead!
|
||||
//"checkOneLevel" is never used!!!
|
||||
function loadModuleFromNodeModules(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState, typesOnly = false): Resolved | undefined {
|
||||
directory = normalizeSlashes(directory);
|
||||
while (true) {
|
||||
//forEachAncestorDirectory helper
|
||||
return forEachAncestorDirectory(directory, directory => {
|
||||
if (getBaseFileName(directory) !== "node_modules") {
|
||||
const resolved = tryInDirectory();
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
}
|
||||
return loadModuleFromSingleNodeModules(extensions, moduleName, directory, failedLookupLocations, state, typesOnly);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const parentPath = getDirectoryPath(directory);
|
||||
if (parentPath === directory || checkOneLevel) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
directory = parentPath;
|
||||
}
|
||||
|
||||
function tryInDirectory(): Resolved | undefined {
|
||||
const packageResult = typesOnly ? undefined : loadModuleFromNodeModulesFolder(extensions, moduleName, directory, failedLookupLocations, state);
|
||||
return packageResult || loadModuleFromNodeModulesFolder(extensions, combinePaths("@types", moduleName), directory, failedLookupLocations, state);
|
||||
}
|
||||
/** Load a package from a single node_modules directory. Tries both regular and @types lookup. */
|
||||
function loadModuleFromSingleNodeModules(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState, typesOnly = false): Resolved | undefined {
|
||||
const packageResult = typesOnly ? undefined : loadModuleFromNodeModulesFolder(extensions, moduleName, directory, failedLookupLocations, state);
|
||||
return packageResult || loadModuleFromNodeModulesFolder(extensions, combinePaths("@types", moduleName), directory, failedLookupLocations, state);
|
||||
}
|
||||
|
||||
export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
|
||||
|
@ -750,6 +763,7 @@ namespace ts {
|
|||
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
|
||||
const failedLookupLocations: string[] = [];
|
||||
const containingDirectory = getDirectoryPath(containingFile);
|
||||
const nonRelative = moduleHasNonRelativeName(moduleName);
|
||||
|
||||
const resolved = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript);
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ false, failedLookupLocations);
|
||||
|
@ -760,14 +774,14 @@ namespace ts {
|
|||
return resolvedUsingSettings;
|
||||
}
|
||||
|
||||
if (moduleHasNonRelativeName(moduleName)) {
|
||||
if (nonRelative) {
|
||||
const resolved = loadModuleFromAncestorDirectories(extensions, moduleName, containingDirectory, failedLookupLocations, state);
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
}
|
||||
if (extensions === Extensions.TypeScript) {
|
||||
// If we didn't find the file normally, look it up in @types.
|
||||
return loadModuleFromNodeModulesAtTypes(moduleName, containingDirectory, failedLookupLocations, state);
|
||||
// If we didn't find the file normally, look it up in @types and in type roots.
|
||||
return loadModuleFromNodeModulesAtTypes(moduleName, containingDirectory, failedLookupLocations, state) || loadModuleFromTypeRoots(moduleName, failedLookupLocations, state);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -779,18 +793,10 @@ namespace ts {
|
|||
|
||||
/** Climb up parent directories looking for a module. */
|
||||
function loadModuleFromAncestorDirectories(extensions: Extensions, moduleName: string, containingDirectory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
while (true) {
|
||||
const searchName = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
const referencedSourceFile = loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
if (referencedSourceFile) {
|
||||
return referencedSourceFile;
|
||||
}
|
||||
const parentPath = getDirectoryPath(containingDirectory);
|
||||
if (parentPath === containingDirectory) {
|
||||
return undefined;
|
||||
}
|
||||
containingDirectory = parentPath;
|
||||
}
|
||||
return forEachAncestorDirectory(containingDirectory, directory => {
|
||||
const searchName = normalizePath(combinePaths(directory, moduleName));
|
||||
return loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -805,8 +811,26 @@ namespace ts {
|
|||
}
|
||||
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
|
||||
const failedLookupLocations: string[] = [];
|
||||
const resolved = loadModuleFromNodeModules(Extensions.TypeScript, moduleName, globalCache, failedLookupLocations, state, /*checkOneLevel*/ true) ||
|
||||
loadModuleFromNodeModules(Extensions.JavaScript, moduleName, globalCache, failedLookupLocations, state, /*checkOneLevel*/ true);
|
||||
//TODO: this could be DtsOnly but that would change baselines...
|
||||
//also, it used to look for js, but that's silly if we're installing @types!
|
||||
const resolved = loadModuleFromSingleNodeModules(Extensions.TypeScript, moduleName, globalCache, failedLookupLocations, state);
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ true, failedLookupLocations);
|
||||
}
|
||||
|
||||
/** Calls `callback` on `directory` and every ancestor directory it has, returning the first defined result. */
|
||||
function forEachAncestorDirectory<T>(directory: string, callback: (directory: string) => T | undefined): T | undefined {
|
||||
while (true) {
|
||||
const result = callback(directory);
|
||||
if (result !== undefined) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const parentPath = getDirectoryPath(directory);
|
||||
if (parentPath === directory) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
directory = parentPath;
|
||||
}
|
||||
}
|
||||
}
|
11
tests/baselines/reference/typeRoots_classic.js
Normal file
11
tests/baselines/reference/typeRoots_classic.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
//// [tests/cases/conformance/moduleResolution/typeRoots_classic.ts] ////
|
||||
|
||||
//// [index.d.ts]
|
||||
export function foo(): void;
|
||||
|
||||
//// [a.ts]
|
||||
import { foo } from "foo";
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
8
tests/baselines/reference/typeRoots_classic.symbols
Normal file
8
tests/baselines/reference/typeRoots_classic.symbols
Normal file
|
@ -0,0 +1,8 @@
|
|||
=== /a.ts ===
|
||||
import { foo } from "foo";
|
||||
>foo : Symbol(foo, Decl(a.ts, 0, 8))
|
||||
|
||||
=== /types/foo/index.d.ts ===
|
||||
export function foo(): void;
|
||||
>foo : Symbol(foo, Decl(index.d.ts, 0, 0))
|
||||
|
22
tests/baselines/reference/typeRoots_classic.trace.json
Normal file
22
tests/baselines/reference/typeRoots_classic.trace.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
[
|
||||
"======== Resolving module 'foo' from '/a.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"File '/foo.ts' does not exist.",
|
||||
"File '/foo.tsx' does not exist.",
|
||||
"File '/foo.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/foo.ts' does not exist.",
|
||||
"File '/node_modules/@types/foo.tsx' does not exist.",
|
||||
"File '/node_modules/@types/foo.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/foo/package.json' does not exist.",
|
||||
"File '/node_modules/@types/foo/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/foo/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/foo/index.d.ts' does not exist.",
|
||||
"File '/types/foo/package.json' does not exist.",
|
||||
"File '/types/foo/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name 'foo' was successfully resolved to '/types/foo/index.d.ts'. ========",
|
||||
"======== Resolving type reference directive 'foo', containing file '/__inferred type names__.ts', root directory '/types'. ========",
|
||||
"Resolving with primary search path '/types'",
|
||||
"File '/types/foo/package.json' does not exist.",
|
||||
"File '/types/foo/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'foo' was successfully resolved to '/types/foo/index.d.ts', primary: true. ========"
|
||||
]
|
8
tests/baselines/reference/typeRoots_classic.types
Normal file
8
tests/baselines/reference/typeRoots_classic.types
Normal file
|
@ -0,0 +1,8 @@
|
|||
=== /a.ts ===
|
||||
import { foo } from "foo";
|
||||
>foo : () => void
|
||||
|
||||
=== /types/foo/index.d.ts ===
|
||||
export function foo(): void;
|
||||
>foo : () => void
|
||||
|
11
tests/baselines/reference/typeRoots_node.js
Normal file
11
tests/baselines/reference/typeRoots_node.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
//// [tests/cases/conformance/moduleResolution/typeRoots_node.ts] ////
|
||||
|
||||
//// [index.d.ts]
|
||||
export function foo(): void;
|
||||
|
||||
//// [a.ts]
|
||||
import { foo } from "foo";
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
8
tests/baselines/reference/typeRoots_node.symbols
Normal file
8
tests/baselines/reference/typeRoots_node.symbols
Normal file
|
@ -0,0 +1,8 @@
|
|||
=== /a.ts ===
|
||||
import { foo } from "foo";
|
||||
>foo : Symbol(foo, Decl(a.ts, 0, 8))
|
||||
|
||||
=== /types/foo/index.d.ts ===
|
||||
export function foo(): void;
|
||||
>foo : Symbol(foo, Decl(index.d.ts, 0, 0))
|
||||
|
28
tests/baselines/reference/typeRoots_node.trace.json
Normal file
28
tests/baselines/reference/typeRoots_node.trace.json
Normal file
|
@ -0,0 +1,28 @@
|
|||
[
|
||||
"======== Resolving module 'foo' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module 'foo' from 'node_modules' folder.",
|
||||
"File '/node_modules/foo.ts' does not exist.",
|
||||
"File '/node_modules/foo.tsx' does not exist.",
|
||||
"File '/node_modules/foo.d.ts' does not exist.",
|
||||
"File '/node_modules/foo/package.json' does not exist.",
|
||||
"File '/node_modules/foo/index.ts' does not exist.",
|
||||
"File '/node_modules/foo/index.tsx' does not exist.",
|
||||
"File '/node_modules/foo/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/foo.ts' does not exist.",
|
||||
"File '/node_modules/@types/foo.tsx' does not exist.",
|
||||
"File '/node_modules/@types/foo.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/foo/package.json' does not exist.",
|
||||
"File '/node_modules/@types/foo/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/foo/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/foo/index.d.ts' does not exist.",
|
||||
"File '/types/foo/package.json' does not exist.",
|
||||
"File '/types/foo/index.d.ts' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/types/foo/index.d.ts', result '/types/foo/index.d.ts'",
|
||||
"======== Module name 'foo' was successfully resolved to '/types/foo/index.d.ts'. ========",
|
||||
"======== Resolving type reference directive 'foo', containing file '/__inferred type names__.ts', root directory '/types'. ========",
|
||||
"Resolving with primary search path '/types'",
|
||||
"File '/types/foo/package.json' does not exist.",
|
||||
"File '/types/foo/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'foo' was successfully resolved to '/types/foo/index.d.ts', primary: true. ========"
|
||||
]
|
8
tests/baselines/reference/typeRoots_node.types
Normal file
8
tests/baselines/reference/typeRoots_node.types
Normal file
|
@ -0,0 +1,8 @@
|
|||
=== /a.ts ===
|
||||
import { foo } from "foo";
|
||||
>foo : () => void
|
||||
|
||||
=== /types/foo/index.d.ts ===
|
||||
export function foo(): void;
|
||||
>foo : () => void
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
// Identical to typeRoots_node except for following line
|
||||
// @moduleResolution: classic
|
||||
// @traceResolution: true
|
||||
// @noImplicitReferences: true
|
||||
// @currentDirectory: /
|
||||
|
||||
// @filename: /tsconfig.json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"typeRoots": ["types"]
|
||||
}
|
||||
}
|
||||
|
||||
// @filename: /types/foo/index.d.ts
|
||||
export function foo(): void;
|
||||
|
||||
// @filename: /a.ts
|
||||
import { foo } from "foo";
|
16
tests/cases/conformance/moduleResolution/typeRoots_node.ts
Normal file
16
tests/cases/conformance/moduleResolution/typeRoots_node.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
// @traceResolution: true
|
||||
// @noImplicitReferences: true
|
||||
// @currentDirectory: /
|
||||
|
||||
// @filename: /tsconfig.json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"typeRoots": ["./types"]
|
||||
}
|
||||
}
|
||||
|
||||
// @filename: /types/foo/index.d.ts
|
||||
export function foo(): void;
|
||||
|
||||
// @filename: /a.ts
|
||||
import { foo } from "foo";
|
Loading…
Reference in a new issue