diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ac599ae58cb99..724c3b48cc670 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3630,7 +3630,7 @@ namespace ts { if (ext === Extension.Ts || ext === Extension.Js || ext === Extension.Tsx || ext === Extension.Jsx) { const scope = currentSourceFile.packageJsonScope; const targetExt = ext === Extension.Ts ? Extension.Mts : ext === Extension.Js ? Extension.Mjs : undefined; - if (scope && !scope.packageJsonContent.type) { + if (scope && !scope.contents.packageJsonContent.type) { if (targetExt) { diagnosticDetails = chainDiagnosticMessages( /*details*/ undefined, diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 9e3b15f09580c..3e46edbec46c1 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -13,7 +13,7 @@ namespace ts { function withPackageId(packageInfo: PackageJsonInfo | undefined, r: PathAndExtension | undefined): Resolved | undefined { let packageId: PackageId | undefined; if (r && packageInfo) { - const packageJsonContent = packageInfo.packageJsonContent as PackageJson; + const packageJsonContent = packageInfo.contents.packageJsonContent as PackageJson; if (typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string") { packageId = { name: packageJsonContent.name, @@ -1679,8 +1679,8 @@ namespace ts { function loadNodeModuleFromDirectory(extensions: Extensions, candidate: string, onlyRecordFailures: boolean, state: ModuleResolutionState, considerPackageJson = true) { const packageInfo = considerPackageJson ? getPackageJsonInfo(candidate, onlyRecordFailures, state) : undefined; - const packageJsonContent = packageInfo && packageInfo.packageJsonContent; - const versionPaths = packageInfo && packageInfo.versionPaths; + const packageJsonContent = packageInfo && packageInfo.contents.packageJsonContent; + const versionPaths = packageInfo && packageInfo.contents.versionPaths; return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths)); } @@ -1692,10 +1692,10 @@ namespace ts { cache: ModuleResolutionCache | undefined, resolveJs?: boolean, ): string[] | false { - if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) { + if (!resolveJs && packageJsonInfo.contents.resolvedEntrypoints !== undefined) { // Cached value excludes resolutions to JS files - those could be // cached separately, but they're used rarely. - return packageJsonInfo.resolvedEntrypoints; + return packageJsonInfo.contents.resolvedEntrypoints; } let entrypoints: string[] | undefined; @@ -1709,16 +1709,16 @@ namespace ts { packageJsonInfo.packageDirectory, /*onlyRecordFailures*/ false, requireState, - packageJsonInfo.packageJsonContent, - packageJsonInfo.versionPaths); + packageJsonInfo.contents.packageJsonContent, + packageJsonInfo.contents.versionPaths); entrypoints = append(entrypoints, requireResolution?.path); - if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) { + if (features & NodeResolutionFeatures.Exports && packageJsonInfo.contents.packageJsonContent.exports) { for (const conditions of [["node", "import", "types"], ["node", "require", "types"]]) { const exportState = { ...requireState, failedLookupLocations: [], conditions }; const exportResolutions = loadEntrypointsFromExportMap( packageJsonInfo, - packageJsonInfo.packageJsonContent.exports, + packageJsonInfo.contents.packageJsonContent.exports, exportState, extensions); if (exportResolutions) { @@ -1729,7 +1729,7 @@ namespace ts { } } - return packageJsonInfo.resolvedEntrypoints = entrypoints || false; + return packageJsonInfo.contents.resolvedEntrypoints = entrypoints || false; } function loadEntrypointsFromExportMap( @@ -1808,6 +1808,10 @@ namespace ts { /*@internal*/ export interface PackageJsonInfo { packageDirectory: string; + contents: PackageJsonInfoContents; + } + /*@internal*/ + export interface PackageJsonInfoContents { packageJsonContent: PackageJsonPathFields; versionPaths: VersionPaths | undefined; /** false: resolved to nothing. undefined: not yet resolved */ @@ -1818,7 +1822,7 @@ namespace ts { * A function for locating the package.json scope for a given path */ /*@internal*/ - export function getPackageScopeForPath(fileName: Path, state: ModuleResolutionState): PackageJsonInfo | undefined { + export function getPackageScopeForPath(fileName: string, state: ModuleResolutionState): PackageJsonInfo | undefined { const parts = getPathComponents(fileName); parts.pop(); while (parts.length > 0) { @@ -1845,7 +1849,9 @@ namespace ts { if (typeof existing !== "boolean") { if (traceEnabled) trace(host, Diagnostics.File_0_exists_according_to_earlier_cached_lookups, packageJsonPath); state.affectingLocations.push(packageJsonPath); - return existing; + return existing.packageDirectory === packageDirectory ? + existing : + { packageDirectory, contents: existing.contents }; } else { if (existing && traceEnabled) trace(host, Diagnostics.File_0_does_not_exist_according_to_earlier_cached_lookups, packageJsonPath); @@ -1860,7 +1866,7 @@ namespace ts { trace(host, Diagnostics.Found_package_json_at_0, packageJsonPath); } const versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state); - const result = { packageDirectory, packageJsonContent, versionPaths, resolvedEntrypoints: undefined }; + const result: PackageJsonInfo = { packageDirectory, contents: { packageJsonContent, versionPaths, resolvedEntrypoints: undefined } }; state.packageJsonInfoCache?.setPackageJsonInfo(packageJsonPath, result); state.affectingLocations.push(packageJsonPath); return result; @@ -1994,17 +2000,16 @@ namespace ts { } function loadModuleFromSelfNameReference(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult { - const useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - const directoryPath = toPath(combinePaths(directory, "dummy"), state.host.getCurrentDirectory?.(), createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + const directoryPath = getNormalizedAbsolutePath(combinePaths(directory, "dummy"), state.host.getCurrentDirectory?.()); const scope = getPackageScopeForPath(directoryPath, state); - if (!scope || !scope.packageJsonContent.exports) { + if (!scope || !scope.contents.packageJsonContent.exports) { return undefined; } - if (typeof scope.packageJsonContent.name !== "string") { + if (typeof scope.contents.packageJsonContent.name !== "string") { return undefined; } const parts = getPathComponents(moduleName); // unrooted paths should have `""` as their 0th entry - const nameParts = getPathComponents(scope.packageJsonContent.name); + const nameParts = getPathComponents(scope.contents.packageJsonContent.name); if (!every(nameParts, (p, i) => parts[i] === p)) { return undefined; } @@ -2013,31 +2018,31 @@ namespace ts { } function loadModuleFromExports(scope: PackageJsonInfo, extensions: Extensions, subpath: string, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult { - if (!scope.packageJsonContent.exports) { + if (!scope.contents.packageJsonContent.exports) { return undefined; } if (subpath === ".") { let mainExport; - if (typeof scope.packageJsonContent.exports === "string" || Array.isArray(scope.packageJsonContent.exports) || (typeof scope.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.packageJsonContent.exports as MapLike))) { - mainExport = scope.packageJsonContent.exports; + if (typeof scope.contents.packageJsonContent.exports === "string" || Array.isArray(scope.contents.packageJsonContent.exports) || (typeof scope.contents.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.contents.packageJsonContent.exports as MapLike))) { + mainExport = scope.contents.packageJsonContent.exports; } - else if (hasProperty(scope.packageJsonContent.exports as MapLike, ".")) { - mainExport = (scope.packageJsonContent.exports as MapLike)["."]; + else if (hasProperty(scope.contents.packageJsonContent.exports as MapLike, ".")) { + mainExport = (scope.contents.packageJsonContent.exports as MapLike)["."]; } if (mainExport) { const loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, subpath, scope, /*isImports*/ false); return loadModuleFromTargetImportOrExport(mainExport, "", /*pattern*/ false); } } - else if (allKeysStartWithDot(scope.packageJsonContent.exports as MapLike)) { - if (typeof scope.packageJsonContent.exports !== "object") { + else if (allKeysStartWithDot(scope.contents.packageJsonContent.exports as MapLike)) { + if (typeof scope.contents.packageJsonContent.exports !== "object") { if (state.traceEnabled) { trace(state.host, Diagnostics.Export_specifier_0_does_not_exist_in_package_json_scope_at_path_1, subpath, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - const result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.packageJsonContent.exports, scope, /*isImports*/ false); + const result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.contents.packageJsonContent.exports, scope, /*isImports*/ false); if (result) { return result; } @@ -2056,8 +2061,7 @@ namespace ts { } return toSearchResult(/*value*/ undefined); } - const useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - const directoryPath = toPath(combinePaths(directory, "dummy"), state.host.getCurrentDirectory?.(), createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + const directoryPath = getNormalizedAbsolutePath(combinePaths(directory, "dummy"), state.host.getCurrentDirectory?.()); const scope = getPackageScopeForPath(directoryPath, state); if (!scope) { if (state.traceEnabled) { @@ -2065,14 +2069,14 @@ namespace ts { } return toSearchResult(/*value*/ undefined); } - if (!scope.packageJsonContent.imports) { + if (!scope.contents.packageJsonContent.imports) { if (state.traceEnabled) { trace(state.host, Diagnostics.package_json_scope_0_has_no_imports_defined, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - const result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.packageJsonContent.imports, scope, /*isImports*/ true); + const result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.contents.packageJsonContent.imports, scope, /*isImports*/ true); if (result) { return result; } @@ -2426,8 +2430,8 @@ namespace ts { candidate, !nodeModulesDirectoryExists, state, - packageInfo.packageJsonContent, - packageInfo.versionPaths + packageInfo.contents.packageJsonContent, + packageInfo.contents.versionPaths ); return withPackageId(packageInfo, fromDirectory); } @@ -2436,7 +2440,7 @@ namespace ts { const { packageName, rest } = parsePackageName(moduleName); const loader: ResolutionKindSpecificLoader = (extensions, candidate, onlyRecordFailures, state) => { // package exports are higher priority than file/directory lookups (and, if there's exports present, blocks them) - if (packageInfo && packageInfo.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { + if (packageInfo && packageInfo.contents.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { return loadModuleFromExports(packageInfo, extensions, combinePaths(".", rest), state, cache, redirectedReference)?.value; } let pathAndExtension = @@ -2446,13 +2450,13 @@ namespace ts { candidate, onlyRecordFailures, state, - packageInfo && packageInfo.packageJsonContent, - packageInfo && packageInfo.versionPaths + packageInfo && packageInfo.contents.packageJsonContent, + packageInfo && packageInfo.contents.versionPaths ); if ( !pathAndExtension && packageInfo // eslint-disable-next-line no-null/no-null - && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) + && (packageInfo.contents.packageJsonContent.exports === undefined || packageInfo.contents.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode ) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume @@ -2467,12 +2471,12 @@ namespace ts { // Don't use a "types" or "main" from here because we're not loading the root, but a subdirectory -- just here for the packageId and path mappings. packageInfo = getPackageJsonInfo(packageDirectory, !nodeModulesDirectoryExists, state); - if (packageInfo && packageInfo.versionPaths) { + if (packageInfo && packageInfo.contents.versionPaths) { if (state.traceEnabled) { - trace(state.host, Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.versionPaths.version, version, rest); + trace(state.host, Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.contents.versionPaths.version, version, rest); } const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists(packageDirectory, state.host); - const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); + const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.contents.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); if (fromPaths) { return fromPaths.value; } diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index e38dd46598587..32640fcb81579 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -807,7 +807,7 @@ namespace ts.moduleSpecifiers { let maybeBlockedByTypesVersions = false; const cachedPackageJson = host.getPackageJsonInfoCache?.()?.getPackageJsonInfo(packageJsonPath); if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) { - const packageJsonContent = cachedPackageJson?.packageJsonContent || JSON.parse(host.readFile!(packageJsonPath)!); + const packageJsonContent = cachedPackageJson?.contents.packageJsonContent || JSON.parse(host.readFile!(packageJsonPath)!); const importMode = overrideMode || importingSourceFile.impliedNodeFormat; if (getEmitModuleResolutionKind(options) === ModuleResolutionKind.Node16 || getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeNext) { const conditions = ["node", importMode === ModuleKind.ESNext ? "import" : "require", "types"]; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 6b064be8640ca..412f307eae4bf 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -849,7 +849,7 @@ namespace ts { /*@internal*/ export function getImpliedNodeFormatForFileWorker( - fileName: Path, + fileName: string, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions, @@ -870,7 +870,7 @@ namespace ts { state.failedLookupLocations = packageJsonLocations; state.affectingLocations = packageJsonLocations; const packageJsonScope = getPackageScopeForPath(fileName, state); - const impliedNodeFormat = packageJsonScope?.packageJsonContent.type === "module" ? ModuleKind.ESNext : ModuleKind.CommonJS; + const impliedNodeFormat = packageJsonScope?.contents.packageJsonContent.type === "module" ? ModuleKind.ESNext : ModuleKind.CommonJS; return { impliedNodeFormat, packageJsonLocations, packageJsonScope }; } } @@ -2834,7 +2834,7 @@ namespace ts { // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront. - const result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache?.getPackageJsonInfoCache(), host, options); + const result = getImpliedNodeFormatForFileWorker(getNormalizedAbsolutePath(fileName, currentDirectory), moduleResolutionCache?.getPackageJsonInfoCache(), host, options); const languageVersion = getEmitScriptTarget(options); const setExternalModuleIndicator = getSetExternalModuleIndicator(options); return typeof result === "object" ? diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 23e9da91c6243..d1851cd02cd08 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -262,7 +262,7 @@ namespace ts { if (file.packageJsonScope) { (result ??= []).push(chainDiagnosticMessages( /*details*/ undefined, - file.packageJsonScope.packageJsonContent.type ? + file.packageJsonScope.contents.packageJsonContent.type ? Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module : Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(last(file.packageJsonLocations!), fileNameConvertor) diff --git a/src/server/session.ts b/src/server/session.ts index 5eff52c6ad8e0..4bdadd04a15fa 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1378,7 +1378,7 @@ namespace ts.server { const packageDirectory = fileName.substring(0, nodeModulesPathParts.packageRootIndex); const packageJsonCache = project.getModuleResolutionCache()?.getPackageJsonInfoCache(); const compilerOptions = project.getCompilationSettings(); - const packageJson = getPackageScopeForPath(project.toPath(packageDirectory + "/package.json"), getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions)); + const packageJson = getPackageScopeForPath(getNormalizedAbsolutePath(packageDirectory + "/package.json", project.getCurrentDirectory()), getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions)); if (!packageJson) return undefined; // Use fake options instead of actual compiler options to avoid following export map if the project uses node16 or nodenext - // Mapping from an export map entry across packages is out of scope for now. Returned entrypoints will only be what can be diff --git a/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts b/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts index 584b32c33535c..d00ea144ea9d4 100644 --- a/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts +++ b/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts @@ -326,5 +326,36 @@ a;b; }, { currentDirectory: "/Users/name/projects/web" }), changes: emptyArray, }); + + + verifyTscWatch({ + scenario: "forceConsistentCasingInFileNames", + subScenario: "package json is looked up for file", + commandLineArgs: ["-w", "--explainFiles"], + sys: () => createWatchedSystem({ + "/Users/name/projects/lib-boilerplate/package.json": JSON.stringify({ + name: "lib-boilerplate", + version: "0.0.2", + type: "module", + exports: "./src/index.ts", + }), + "/Users/name/projects/lib-boilerplate/src/index.ts": Utils.dedent` + export function thing(): void {} + `, + "/Users/name/projects/lib-boilerplate/test/basic.spec.ts": Utils.dedent` + import { thing } from 'lib-boilerplate' + `, + "/Users/name/projects/lib-boilerplate/tsconfig.json": JSON.stringify({ + compilerOptions: { + module: "node16", + target: "es2021", + forceConsistentCasingInFileNames: true, + traceResolution: true, + } + }), + "/a/lib/lib.es2021.full.d.ts": libFile.content, + }, { currentDirectory: "/Users/name/projects/lib-boilerplate" }), + changes: emptyArray, + }); }); } diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNext.trace.json b/tests/baselines/reference/reactJsxReactResolvedNodeNext.trace.json index 5b9a25f308130..a8678e499c969 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNext.trace.json +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNext.trace.json @@ -25,15 +25,15 @@ "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index.d.ts' that references 'tests/cases/compiler/node_modules/@types/react/index.d.ts'.", "File 'tests/cases/compiler/node_modules/@types/react/index.d.ts' exist - use it as a name resolution result.", - "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/index.d.ts@0.0.1'. ========", + "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/ndex.d.ts@0.0.1'. ========", "File 'tests/cases/compiler/node_modules/@types/react/package.json' exists according to earlier cached lookups.", "======== Resolving module './' from 'tests/cases/compiler/node_modules/@types/react/jsx-runtime.d.ts'. ========", "Resolution for module './' was found in cache from location 'tests/cases/compiler/node_modules/@types/react'.", - "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/index.d.ts@0.0.1'. ========", + "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/ndex.d.ts@0.0.1'. ========", "File 'tests/cases/compiler/node_modules/@types/react/package.json' exists according to earlier cached lookups.", "======== Resolving module './' from 'tests/cases/compiler/node_modules/@types/react/jsx-dev-runtime.d.ts'. ========", "Resolution for module './' was found in cache from location 'tests/cases/compiler/node_modules/@types/react'.", - "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/index.d.ts@0.0.1'. ========", + "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/ndex.d.ts@0.0.1'. ========", "File 'package.json' does not exist.", "File '/package.json' does not exist according to earlier cached lookups.", "File 'package.json' does not exist according to earlier cached lookups.", diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.trace.json b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.trace.json index 590cc918f3d5b..99dcbbddc5a08 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.trace.json +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.trace.json @@ -19,15 +19,15 @@ "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index.d.ts' that references 'tests/cases/compiler/node_modules/@types/react/index.d.ts'.", "File 'tests/cases/compiler/node_modules/@types/react/index.d.ts' exist - use it as a name resolution result.", - "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/index.d.ts@0.0.1'. ========", + "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/ndex.d.ts@0.0.1'. ========", "File 'tests/cases/compiler/node_modules/@types/react/package.json' exists according to earlier cached lookups.", "======== Resolving module './' from 'tests/cases/compiler/node_modules/@types/react/jsx-runtime.d.ts'. ========", "Resolution for module './' was found in cache from location 'tests/cases/compiler/node_modules/@types/react'.", - "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/index.d.ts@0.0.1'. ========", + "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/ndex.d.ts@0.0.1'. ========", "File 'tests/cases/compiler/node_modules/@types/react/package.json' exists according to earlier cached lookups.", "======== Resolving module './' from 'tests/cases/compiler/node_modules/@types/react/jsx-dev-runtime.d.ts'. ========", "Resolution for module './' was found in cache from location 'tests/cases/compiler/node_modules/@types/react'.", - "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/index.d.ts@0.0.1'. ========", + "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/ndex.d.ts@0.0.1'. ========", "File 'package.json' does not exist.", "File '/package.json' does not exist.", "File 'package.json' does not exist according to earlier cached lookups.", diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/package-json-is-looked-up-for-file.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/package-json-is-looked-up-for-file.js new file mode 100644 index 0000000000000..b164c2ee08bbf --- /dev/null +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/package-json-is-looked-up-for-file.js @@ -0,0 +1,116 @@ +Input:: +//// [/Users/name/projects/lib-boilerplate/package.json] +{"name":"lib-boilerplate","version":"0.0.2","type":"module","exports":"./src/index.ts"} + +//// [/Users/name/projects/lib-boilerplate/src/index.ts] +export function thing(): void {} + + +//// [/Users/name/projects/lib-boilerplate/test/basic.spec.ts] +import { thing } from 'lib-boilerplate' + + +//// [/Users/name/projects/lib-boilerplate/tsconfig.json] +{"compilerOptions":{"module":"node16","target":"es2021","forceConsistentCasingInFileNames":true,"traceResolution":true}} + +//// [/a/lib/lib.es2021.full.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + + +/a/lib/tsc.js -w --explainFiles +Output:: +>> Screen clear +[12:00:29 AM] Starting compilation in watch mode... + +File '/Users/name/projects/lib-boilerplate/src/package.json' does not exist. +Found 'package.json' at '/Users/name/projects/lib-boilerplate/package.json'. +'package.json' does not have a 'typesVersions' field. +File '/Users/name/projects/lib-boilerplate/test/package.json' does not exist. +File '/Users/name/projects/lib-boilerplate/package.json' exists according to earlier cached lookups. +======== Resolving module 'lib-boilerplate' from '/Users/name/projects/lib-boilerplate/test/basic.spec.ts'. ======== +Module resolution kind is not specified, using 'Node16'. +File '/Users/name/projects/lib-boilerplate/test/package.json' does not exist according to earlier cached lookups. +File '/Users/name/projects/lib-boilerplate/package.json' exists according to earlier cached lookups. +File '/Users/name/projects/lib-boilerplate/src/index.ts' exist - use it as a name resolution result. +Resolving real path for '/Users/name/projects/lib-boilerplate/src/index.ts', result '/Users/name/projects/lib-boilerplate/src/index.ts'. +======== Module name 'lib-boilerplate' was successfully resolved to '/Users/name/projects/lib-boilerplate/src/index.ts' with Package ID 'lib-boilerplate/src/index.ts@0.0.2'. ======== +File '/a/lib/package.json' does not exist. +File '/a/package.json' does not exist. +File '/package.json' does not exist. +../../../../a/lib/lib.es2021.full.d.ts + Default library for target 'es2021' +src/index.ts + Matched by default include pattern '**/*' + Imported via 'lib-boilerplate' from file 'test/basic.spec.ts' with packageId 'lib-boilerplate/src/index.ts@0.0.2' + File is ECMAScript module because 'package.json' has field "type" with value "module" +test/basic.spec.ts + Matched by default include pattern '**/*' + File is ECMAScript module because 'package.json' has field "type" with value "module" +[12:00:34 AM] Found 0 errors. Watching for file changes. + + + +Program root files: ["/Users/name/projects/lib-boilerplate/src/index.ts","/Users/name/projects/lib-boilerplate/test/basic.spec.ts"] +Program options: {"module":100,"target":8,"forceConsistentCasingInFileNames":true,"traceResolution":true,"watch":true,"explainFiles":true,"configFilePath":"/Users/name/projects/lib-boilerplate/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.es2021.full.d.ts +/Users/name/projects/lib-boilerplate/src/index.ts +/Users/name/projects/lib-boilerplate/test/basic.spec.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.es2021.full.d.ts +/Users/name/projects/lib-boilerplate/src/index.ts +/Users/name/projects/lib-boilerplate/test/basic.spec.ts + +Shape signatures in builder refreshed for:: +/a/lib/lib.es2021.full.d.ts (used version) +/users/name/projects/lib-boilerplate/src/index.ts (used version) +/users/name/projects/lib-boilerplate/test/basic.spec.ts (used version) + +PolledWatches:: +/users/name/projects/lib-boilerplate/src/package.json: + {"pollingInterval":2000} +/users/name/projects/lib-boilerplate/test/package.json: + {"pollingInterval":2000} +/users/name/projects/lib-boilerplate/node_modules/@types: + {"pollingInterval":500} + +FsWatches:: +/users/name/projects/lib-boilerplate/tsconfig.json: + {} +/users/name/projects/lib-boilerplate/src/index.ts: + {} +/users/name/projects/lib-boilerplate/test/basic.spec.ts: + {} +/a/lib/lib.es2021.full.d.ts: + {} +/users/name/projects/lib-boilerplate/package.json: + {} + +FsWatchesRecursive:: +/users/name/projects/lib-boilerplate/test: + {} +/users/name/projects/lib-boilerplate: + {} + +exitCode:: ExitStatus.undefined + +//// [/Users/name/projects/lib-boilerplate/src/index.js] +export function thing() { } + + +//// [/Users/name/projects/lib-boilerplate/test/basic.spec.js] +export {}; + + diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js index e21d33487a58d..8b72ee0569589 100644 --- a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js @@ -30,11 +30,11 @@ Output:: >> Screen clear [12:00:23 AM] Starting compilation in watch mode... -Found 'package.json' at '/users/name/projects/web/package.json'. +Found 'package.json' at '/Users/name/projects/web/package.json'. 'package.json' does not have a 'typesVersions' field. ======== Resolving module '@this/package' from '/Users/name/projects/web/index.ts'. ======== Module resolution kind is not specified, using 'NodeNext'. -File '/users/name/projects/web/package.json' exists according to earlier cached lookups. +File '/Users/name/projects/web/package.json' exists according to earlier cached lookups. File '/Users/name/projects/web/index.ts' exist - use it as a name resolution result. Resolving real path for '/Users/name/projects/web/index.ts', result '/Users/name/projects/web/index.ts'. ======== Module name '@this/package' was successfully resolved to '/Users/name/projects/web/index.ts'. ======== diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js index 1d6bfe1933f70..489113e3d6b32 100644 --- a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js @@ -33,19 +33,19 @@ Output:: >> Screen clear [12:00:35 AM] Starting compilation in watch mode... -File '/users/name/projects/web/src/package.json' does not exist. -File '/users/name/projects/web/package.json' does not exist. -File '/users/name/projects/package.json' does not exist. -File '/users/name/package.json' does not exist. -File '/users/package.json' does not exist. +File '/Users/name/projects/web/src/package.json' does not exist. +File '/Users/name/projects/web/package.json' does not exist. +File '/Users/name/projects/package.json' does not exist. +File '/Users/name/package.json' does not exist. +File '/Users/package.json' does not exist. File '/package.json' does not exist. ======== Resolving module 'yargs' from '/Users/name/projects/web/src/bin.ts'. ======== Explicitly specified module resolution kind: 'NodeNext'. -File '/users/name/projects/web/src/package.json' does not exist according to earlier cached lookups. -File '/users/name/projects/web/package.json' does not exist according to earlier cached lookups. -File '/users/name/projects/package.json' does not exist according to earlier cached lookups. -File '/users/name/package.json' does not exist according to earlier cached lookups. -File '/users/package.json' does not exist according to earlier cached lookups. +File '/Users/name/projects/web/src/package.json' does not exist according to earlier cached lookups. +File '/Users/name/projects/web/package.json' does not exist according to earlier cached lookups. +File '/Users/name/projects/package.json' does not exist according to earlier cached lookups. +File '/Users/name/package.json' does not exist according to earlier cached lookups. +File '/Users/package.json' does not exist according to earlier cached lookups. File '/package.json' does not exist according to earlier cached lookups. Loading module 'yargs' from 'node_modules' folder, target file type 'TypeScript'. Directory '/Users/name/projects/web/src/node_modules' does not exist, skipping all lookups in it. @@ -57,7 +57,7 @@ Found 'package.json' at '/Users/name/projects/web/node_modules/@types/yargs/pack File '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' exist - use it as a name resolution result. Resolving real path for '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts', result '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts'. ======== Module name 'yargs' was successfully resolved to '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' with Package ID 'yargs/index.d.ts@17.0.12'. ======== -File '/users/name/projects/web/node_modules/@types/yargs/package.json' exists according to earlier cached lookups. +File '/Users/name/projects/web/node_modules/@types/yargs/package.json' exists according to earlier cached lookups. ======== Resolving type reference directive 'yargs', containing file '/Users/name/projects/web/__inferred type names__.ts', root directory '/Users/name/projects/web/node_modules/@types'. ======== Resolving with primary search path '/Users/name/projects/web/node_modules/@types'. File '/Users/name/projects/web/node_modules/@types/yargs/package.json' exists according to earlier cached lookups. diff --git a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json index a487a795006e0..64f195b78e58f 100644 --- a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json +++ b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json @@ -22,7 +22,7 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' exist - use it as a name resolution result.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json' exists according to earlier cached lookups.", - "======== Module name '../other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' with Package ID 'ext/ther.d.ts@1.0.0'. ========", + "======== Module name '../other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' with Package ID 'ext/other.d.ts@1.0.0'. ========", "======== Resolving module 'ext' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext' from 'node_modules' folder, target file type 'TypeScript'.", @@ -41,7 +41,7 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/s3.1/index.d.ts@1.0.0'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/ts3.1/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", @@ -53,5 +53,5 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts'.", - "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/s3.1/other.d.ts@1.0.0'. ========" + "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/ts3.1/other.d.ts@1.0.0'. ========" ] \ No newline at end of file