Store information in buildInfo to repopulate mode mismatch based on status of package.json (#59286)

This commit is contained in:
Sheetal Nandi 2024-07-16 10:12:14 -07:00 коммит произвёл GitHub
Родитель bd54a6bb2b
Коммит 6369240da6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
11 изменённых файлов: 404 добавлений и 65 удалений

Просмотреть файл

@ -21,6 +21,7 @@ import {
concatenate,
convertToOptionsWithAbsolutePaths,
createGetCanonicalFileName,
createModeMismatchDetails,
createModuleNotFoundChain,
createProgram,
CustomTransformers,
@ -70,7 +71,6 @@ import {
ReadBuildProgramHost,
ReadonlyCollection,
RepopulateDiagnosticChainInfo,
RepopulateModuleNotFoundDiagnosticChain,
returnFalse,
returnUndefined,
sameMap,
@ -111,8 +111,8 @@ export interface ReusableDiagnosticRelatedInformation {
}
/** @internal */
export interface ReusableRepopulateModuleNotFoundChain {
info: RepopulateModuleNotFoundDiagnosticChain;
export interface ReusableRepopulateInfoChain {
info: RepopulateDiagnosticChainInfo;
next?: ReusableDiagnosticMessageChain[];
}
@ -122,7 +122,7 @@ export type SerializedDiagnosticMessageChain = Omit<DiagnosticMessageChain, "nex
};
/** @internal */
export type ReusableDiagnosticMessageChain = SerializedDiagnosticMessageChain | ReusableRepopulateModuleNotFoundChain;
export type ReusableDiagnosticMessageChain = SerializedDiagnosticMessageChain | ReusableRepopulateInfoChain;
/**
* Signature (Hash of d.ts emitted), is string if it was emitted using same d.ts.map option as what compilerOptions indicate, otherwise tuple of string
@ -538,7 +538,13 @@ function convertOrRepopulateDiagnosticMessageChain<T extends DiagnosticMessageCh
repopulateInfo: (chain: T) => RepopulateDiagnosticChainInfo | undefined,
): DiagnosticMessageChain {
const info = repopulateInfo(chain);
if (info) {
if (info === true) {
return {
...createModeMismatchDetails(sourceFile!),
next: convertOrRepopulateDiagnosticMessageChainArray(chain.next as T[], sourceFile, newProgram, repopulateInfo),
};
}
else if (info) {
return {
...createModuleNotFoundChain(sourceFile!, newProgram, info.moduleReference, info.mode, info.packageName || info.moduleReference),
next: convertOrRepopulateDiagnosticMessageChainArray(chain.next as T[], sourceFile, newProgram, repopulateInfo),
@ -600,7 +606,7 @@ function convertToDiagnosticRelatedInformation(
file: sourceFile,
messageText: isString(diagnostic.messageText) ?
diagnostic.messageText :
convertOrRepopulateDiagnosticMessageChain(diagnostic.messageText, sourceFile, newProgram, chain => (chain as ReusableRepopulateModuleNotFoundChain).info),
convertOrRepopulateDiagnosticMessageChain(diagnostic.messageText, sourceFile, newProgram, chain => (chain as ReusableRepopulateInfoChain).info),
};
}

Просмотреть файл

@ -79,7 +79,6 @@ import {
classOrConstructorParameterIsDecorated,
ClassStaticBlockDeclaration,
clear,
combinePaths,
compareDiagnostics,
comparePaths,
compareValues,
@ -116,6 +115,7 @@ import {
createFlowNode,
createGetSymbolWalker,
createModeAwareCacheKey,
createModeMismatchDetails,
createModuleNotFoundChain,
createMultiMap,
createNameResolver,
@ -4627,40 +4627,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
let diagnosticDetails;
const ext = tryGetExtensionFromPath(currentSourceFile.fileName);
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.contents.packageJsonContent.type) {
if (targetExt) {
diagnosticDetails = chainDiagnosticMessages(
/*details*/ undefined,
Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1,
targetExt,
combinePaths(scope.packageDirectory, "package.json"),
);
}
else {
diagnosticDetails = chainDiagnosticMessages(
/*details*/ undefined,
Diagnostics.To_convert_this_file_to_an_ECMAScript_module_add_the_field_type_Colon_module_to_0,
combinePaths(scope.packageDirectory, "package.json"),
);
}
}
else {
if (targetExt) {
diagnosticDetails = chainDiagnosticMessages(
/*details*/ undefined,
Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_create_a_local_package_json_file_with_type_Colon_module,
targetExt,
);
}
else {
diagnosticDetails = chainDiagnosticMessages(
/*details*/ undefined,
Diagnostics.To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module,
);
}
}
diagnosticDetails = createModeMismatchDetails(currentSourceFile);
}
diagnostics.add(createDiagnosticForNodeFromMessageChain(
getSourceFileOfNode(errorNode),

Просмотреть файл

@ -2382,17 +2382,11 @@ export interface PackageJsonInfoContents {
*
* @internal
*/
export function getPackageScopeForPath(fileName: string, state: ModuleResolutionState): PackageJsonInfo | undefined {
const parts = getPathComponents(fileName);
parts.pop();
while (parts.length > 0) {
const pkg = getPackageJsonInfo(getPathFromPathComponents(parts), /*onlyRecordFailures*/ false, state);
if (pkg) {
return pkg;
}
parts.pop();
}
return undefined;
export function getPackageScopeForPath(directory: string, state: ModuleResolutionState): PackageJsonInfo | undefined {
return forEachAncestorDirectory(
directory,
dir => getPackageJsonInfo(dir, /*onlyRecordFailures*/ false, state),
);
}
function getVersionPathsOfPackageJsonInfo(packageJsonInfo: PackageJsonInfo, state: ModuleResolutionState): VersionPaths | undefined {
@ -2568,7 +2562,7 @@ function noKeyStartsWithDot(obj: MapLike<unknown>) {
}
function loadModuleFromSelfNameReference(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult<Resolved> {
const directoryPath = getNormalizedAbsolutePath(combinePaths(directory, "dummy"), state.host.getCurrentDirectory?.());
const directoryPath = getNormalizedAbsolutePath(directory, state.host.getCurrentDirectory?.());
const scope = getPackageScopeForPath(directoryPath, state);
if (!scope || !scope.contents.packageJsonContent.exports) {
return undefined;
@ -2649,7 +2643,7 @@ function loadModuleFromImports(extensions: Extensions, moduleName: string, direc
}
return toSearchResult(/*value*/ undefined);
}
const directoryPath = getNormalizedAbsolutePath(combinePaths(directory, "dummy"), state.host.getCurrentDirectory?.());
const directoryPath = getNormalizedAbsolutePath(directory, state.host.getCurrentDirectory?.());
const scope = getPackageScopeForPath(directoryPath, state);
if (!scope) {
if (state.traceEnabled) {

Просмотреть файл

@ -737,7 +737,7 @@ function getAllModulePathsWorker(info: Info, importedFileName: string, host: Mod
// This should populate all the relevant symlinks in the symlink cache, and most, if not all, of these resolutions
// should get (re)used.
const state = getTemporaryModuleResolutionState(cache.getPackageJsonInfoCache(), host, {});
const packageJson = getPackageScopeForPath(info.importingSourceFileName, state);
const packageJson = getPackageScopeForPath(getDirectoryPath(info.importingSourceFileName), state);
if (packageJson) {
const toResolve = getAllRuntimeDependencies(packageJson.contents.packageJsonContent);
for (const depName of (toResolve || emptyArray)) {

Просмотреть файл

@ -1363,7 +1363,7 @@ export function getImpliedNodeFormatForFileWorker(
const packageJsonLocations: string[] = [];
state.failedLookupLocations = packageJsonLocations;
state.affectingLocations = packageJsonLocations;
const packageJsonScope = getPackageScopeForPath(fileName, state);
const packageJsonScope = getPackageScopeForPath(getDirectoryPath(fileName), state);
const impliedNodeFormat = packageJsonScope?.contents.packageJsonContent.type === "module" ? ModuleKind.ESNext : ModuleKind.CommonJS;
return { impliedNodeFormat, packageJsonLocations, packageJsonScope };
}

Просмотреть файл

@ -7042,7 +7042,10 @@ export interface RepopulateModuleNotFoundDiagnosticChain {
}
/** @internal */
export type RepopulateDiagnosticChainInfo = RepopulateModuleNotFoundDiagnosticChain;
export type RepopulateModeMismatchDiagnosticChain = true;
/** @internal */
export type RepopulateDiagnosticChainInfo = RepopulateModuleNotFoundDiagnosticChain | RepopulateModeMismatchDiagnosticChain;
/**
* A linked list of formatted diagnostic messages to be used as part of a multiline message.

Просмотреть файл

@ -844,6 +844,38 @@ export function createModuleNotFoundChain(sourceFile: SourceFile, host: TypeChec
return result;
}
/** @internal */
export function createModeMismatchDetails(currentSourceFile: SourceFile) {
const ext = tryGetExtensionFromPath(currentSourceFile.fileName);
const scope = currentSourceFile.packageJsonScope;
const targetExt = ext === Extension.Ts ? Extension.Mts : ext === Extension.Js ? Extension.Mjs : undefined;
const result = scope && !scope.contents.packageJsonContent.type ?
targetExt ?
chainDiagnosticMessages(
/*details*/ undefined,
Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1,
targetExt,
combinePaths(scope.packageDirectory, "package.json"),
) :
chainDiagnosticMessages(
/*details*/ undefined,
Diagnostics.To_convert_this_file_to_an_ECMAScript_module_add_the_field_type_Colon_module_to_0,
combinePaths(scope.packageDirectory, "package.json"),
) :
targetExt ?
chainDiagnosticMessages(
/*details*/ undefined,
Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_create_a_local_package_json_file_with_type_Colon_module,
targetExt,
) :
chainDiagnosticMessages(
/*details*/ undefined,
Diagnostics.To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module,
);
result.repopulateInfo = () => true;
return result;
}
function packageIdIsEqual(a: PackageId | undefined, b: PackageId | undefined): boolean {
return a === b || !!a && !!b && a.name === b.name && a.subModuleName === b.subModuleName && a.version === b.version && a.peerDependencies === b.peerDependencies;
}

Просмотреть файл

@ -1712,7 +1712,7 @@ export class Session<TMessage = string> implements EventSender {
const packageDirectory = fileName.substring(0, nodeModulesPathParts.packageRootIndex);
const packageJsonCache = project.getModuleResolutionCache()?.getPackageJsonInfoCache();
const compilerOptions = project.getCompilationSettings();
const packageJson = getPackageScopeForPath(getNormalizedAbsolutePath(packageDirectory + "/package.json", project.getCurrentDirectory()), getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions));
const packageJson = getPackageScopeForPath(getNormalizedAbsolutePath(packageDirectory, 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

Просмотреть файл

@ -1,3 +1,7 @@
import {
ModuleKind,
ScriptTarget,
} from "../../_namespaces/ts.js";
import { dedent } from "../../_namespaces/Utils.js";
import { jsonToReadableText } from "../helpers.js";
import {
@ -6,11 +10,17 @@ import {
getFsContentsForAlternateResultDts,
getFsContentsForAlternateResultPackageJson,
} from "../helpers/alternateResult.js";
import { libContent } from "../helpers/contents.js";
import {
compilerOptionsToConfigJson,
libContent,
} from "../helpers/contents.js";
import { verifyTsc } from "../helpers/tsc.js";
import { verifyTscWatch } from "../helpers/tscWatch.js";
import { loadProjectFromFiles } from "../helpers/vfs.js";
import { createWatchedSystem } from "../helpers/virtualFileSystemWithWatch.js";
import {
createWatchedSystem,
libFile,
} from "../helpers/virtualFileSystemWithWatch.js";
describe("unittests:: tsc:: moduleResolution::", () => {
verifyTsc({
@ -271,4 +281,40 @@ describe("unittests:: tsc:: moduleResolution::", () => {
},
],
});
verifyTsc({
scenario: "moduleResolution",
subScenario: "package json scope",
fs: () =>
loadProjectFromFiles({
"/src/projects/project/src/tsconfig.json": jsonToReadableText({
compilerOptions: compilerOptionsToConfigJson({
target: ScriptTarget.ES2016,
composite: true,
module: ModuleKind.Node16,
traceResolution: true,
}),
files: [
"main.ts",
"fileA.ts",
"fileB.mts",
],
}),
"/src/projects/project/src/main.ts": "export const x = 10;",
"/src/projects/project/src/fileA.ts": dedent`
import { foo } from "./fileB.mjs";
foo();
`,
"/src/projects/project/src/fileB.mts": "export function foo() {}",
"/src/projects/project/package.json": jsonToReadableText({ name: "app", version: "1.0.0" }),
"/lib/lib.es2016.full.d.ts": libFile.content,
}, { cwd: "/src/projects/project" }),
commandLineArgs: ["-p", "src", "--explainFiles", "--extendedDiagnostics"],
edits: [
{
caption: "Delete package.json",
edit: fs => fs.unlinkSync(`/src/projects/project/package.json`),
},
],
});
});

Просмотреть файл

@ -69,7 +69,7 @@ exports.default = (0, jsx_runtime_1.jsx)("div", {});
//// [/tsconfig.tsbuildinfo]
{"fileNames":["./lib/lib.d.ts","./node_modules/solid-js/jsx-runtime.d.ts","./src/main.tsx"],"fileIdsList":[[2]],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"-3511680495-export namespace JSX {\n type IntrinsicElements = { div: {}; };\n}\n","impliedFormat":99},{"version":"-359851309-export default <div/>;","signature":"2119670487-declare const _default: any;\nexport default _default;\n","impliedFormat":1}],"root":[1,3],"options":{"composite":true,"jsx":4,"jsxImportSource":"solid-js","module":100},"referencedMap":[[3,1]],"semanticDiagnosticsPerFile":[[3,[{"start":15,"length":6,"code":1479,"category":1,"messageText":{"messageText":"The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import(\"solid-js/jsx-runtime\")' call instead.","category":1,"code":1479,"next":[{"messageText":"To convert this file to an ECMAScript module, create a local package.json file with `{ \"type\": \"module\" }`.","category":3,"code":1483}]}}]]],"latestChangedDtsFile":"./src/main.d.ts","version":"FakeTSVersion"}
{"fileNames":["./lib/lib.d.ts","./node_modules/solid-js/jsx-runtime.d.ts","./src/main.tsx"],"fileIdsList":[[2]],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"-3511680495-export namespace JSX {\n type IntrinsicElements = { div: {}; };\n}\n","impliedFormat":99},{"version":"-359851309-export default <div/>;","signature":"2119670487-declare const _default: any;\nexport default _default;\n","impliedFormat":1}],"root":[1,3],"options":{"composite":true,"jsx":4,"jsxImportSource":"solid-js","module":100},"referencedMap":[[3,1]],"semanticDiagnosticsPerFile":[[3,[{"start":15,"length":6,"code":1479,"category":1,"messageText":{"messageText":"The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import(\"solid-js/jsx-runtime\")' call instead.","category":1,"code":1479,"next":[{"info":true}]}}]]],"latestChangedDtsFile":"./src/main.d.ts","version":"FakeTSVersion"}
//// [/tsconfig.tsbuildinfo.readable.baseline.txt]
{
@ -151,9 +151,7 @@ exports.default = (0, jsx_runtime_1.jsx)("div", {});
"code": 1479,
"next": [
{
"messageText": "To convert this file to an ECMAScript module, create a local package.json file with `{ \"type\": \"module\" }`.",
"category": 3,
"code": 1483
"info": true
}
]
}
@ -163,6 +161,6 @@ exports.default = (0, jsx_runtime_1.jsx)("div", {});
],
"latestChangedDtsFile": "./src/main.d.ts",
"version": "FakeTSVersion",
"size": 1628
"size": 1487
}

Просмотреть файл

@ -0,0 +1,293 @@
currentDirectory:: /src/projects/project useCaseSensitiveFileNames: false
Input::
//// [/lib/lib.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
interface ReadonlyArray<T> {}
declare const console: { log(msg: any): void; };
//// [/lib/lib.es2016.full.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
//// [/src/projects/project/package.json]
{
"name": "app",
"version": "1.0.0"
}
//// [/src/projects/project/src/fileA.ts]
import { foo } from "./fileB.mjs";
foo();
//// [/src/projects/project/src/fileB.mts]
export function foo() {}
//// [/src/projects/project/src/main.ts]
export const x = 10;
//// [/src/projects/project/src/tsconfig.json]
{
"compilerOptions": {
"target": "es2016",
"composite": true,
"module": "node16",
"traceResolution": true
},
"files": [
"main.ts",
"fileA.ts",
"fileB.mts"
]
}
Output::
/lib/tsc -p src --explainFiles --extendedDiagnostics
File '/src/projects/project/src/package.json' does not exist.
Found 'package.json' at '/src/projects/project/package.json'.
File '/src/projects/project/src/package.json' does not exist according to earlier cached lookups.
File '/src/projects/project/package.json' exists according to earlier cached lookups.
======== Resolving module './fileB.mjs' from '/src/projects/project/src/fileA.ts'. ========
Module resolution kind is not specified, using 'Node16'.
Resolving in CJS mode with conditions 'require', 'types', 'node'.
Loading module as file / folder, candidate module location '/src/projects/project/src/fileB.mjs', target file types: TypeScript, JavaScript, Declaration.
File name '/src/projects/project/src/fileB.mjs' has a '.mjs' extension - stripping it.
File '/src/projects/project/src/fileB.mts' exists - use it as a name resolution result.
======== Module name './fileB.mjs' was successfully resolved to '/src/projects/project/src/fileB.mts'. ========
File '/lib/package.json' does not exist.
File '/package.json' does not exist.
src/fileA.ts:1:21 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./fileB.mjs")' call instead.
To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '/src/projects/project/package.json'.
1 import { foo } from "./fileB.mjs";
   ~~~~~~~~~~~~~
../../../lib/lib.es2016.full.d.ts
Default library for target 'es2016'
src/main.ts
Part of 'files' list in tsconfig.json
File is CommonJS module because 'package.json' does not have field "type"
src/fileB.mts
Imported via "./fileB.mjs" from file 'src/fileA.ts'
Part of 'files' list in tsconfig.json
src/fileA.ts
Part of 'files' list in tsconfig.json
File is CommonJS module because 'package.json' does not have field "type"
Found 1 error in src/fileA.ts:1
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
//// [/src/projects/project/src/fileA.d.ts]
export {};
//// [/src/projects/project/src/fileA.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fileB_mjs_1 = require("./fileB.mjs");
(0, fileB_mjs_1.foo)();
//// [/src/projects/project/src/fileB.d.mts]
export declare function foo(): void;
//// [/src/projects/project/src/fileB.mjs]
export function foo() { }
//// [/src/projects/project/src/main.d.ts]
export declare const x = 10;
//// [/src/projects/project/src/main.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.x = void 0;
exports.x = 10;
//// [/src/projects/project/src/tsconfig.tsbuildinfo]
{"fileNames":["../../../../lib/lib.es2016.full.d.ts","./main.ts","./fileb.mts","./filea.ts"],"fileIdsList":[[3]],"fileInfos":[{"version":"-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }","affectsGlobalScope":true,"impliedFormat":1},{"version":"-10726455937-export const x = 10;","signature":"-6821242887-export declare const x = 10;\n","impliedFormat":1},{"version":"3524703962-export function foo() {}","signature":"-5677608893-export declare function foo(): void;\n","impliedFormat":99},{"version":"-5325347830-import { foo } from \"./fileB.mjs\";\nfoo();\n","signature":"-3531856636-export {};\n","impliedFormat":1}],"root":[[2,4]],"options":{"composite":true,"module":100,"target":3},"referencedMap":[[4,1]],"semanticDiagnosticsPerFile":[[4,[{"start":20,"length":13,"code":1479,"category":1,"messageText":{"messageText":"The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import(\"./fileB.mjs\")' call instead.","category":1,"code":1479,"next":[{"info":true}]}}]]],"latestChangedDtsFile":"./fileA.d.ts","version":"FakeTSVersion"}
//// [/src/projects/project/src/tsconfig.tsbuildinfo.readable.baseline.txt]
{
"fileNames": [
"../../../../lib/lib.es2016.full.d.ts",
"./main.ts",
"./fileb.mts",
"./filea.ts"
],
"fileIdsList": [
[
"./fileb.mts"
]
],
"fileInfos": {
"../../../../lib/lib.es2016.full.d.ts": {
"original": {
"version": "-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }",
"affectsGlobalScope": true,
"impliedFormat": 1
},
"version": "-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }",
"signature": "-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }",
"affectsGlobalScope": true,
"impliedFormat": "commonjs"
},
"./main.ts": {
"original": {
"version": "-10726455937-export const x = 10;",
"signature": "-6821242887-export declare const x = 10;\n",
"impliedFormat": 1
},
"version": "-10726455937-export const x = 10;",
"signature": "-6821242887-export declare const x = 10;\n",
"impliedFormat": "commonjs"
},
"./fileb.mts": {
"original": {
"version": "3524703962-export function foo() {}",
"signature": "-5677608893-export declare function foo(): void;\n",
"impliedFormat": 99
},
"version": "3524703962-export function foo() {}",
"signature": "-5677608893-export declare function foo(): void;\n",
"impliedFormat": "esnext"
},
"./filea.ts": {
"original": {
"version": "-5325347830-import { foo } from \"./fileB.mjs\";\nfoo();\n",
"signature": "-3531856636-export {};\n",
"impliedFormat": 1
},
"version": "-5325347830-import { foo } from \"./fileB.mjs\";\nfoo();\n",
"signature": "-3531856636-export {};\n",
"impliedFormat": "commonjs"
}
},
"root": [
[
[
2,
4
],
[
"./main.ts",
"./fileb.mts",
"./filea.ts"
]
]
],
"options": {
"composite": true,
"module": 100,
"target": 3
},
"referencedMap": {
"./filea.ts": [
"./fileb.mts"
]
},
"semanticDiagnosticsPerFile": [
[
"./filea.ts",
[
{
"start": 20,
"length": 13,
"code": 1479,
"category": 1,
"messageText": {
"messageText": "The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import(\"./fileB.mjs\")' call instead.",
"category": 1,
"code": 1479,
"next": [
{
"info": true
}
]
}
}
]
]
],
"latestChangedDtsFile": "./fileA.d.ts",
"version": "FakeTSVersion",
"size": 1495
}
Change:: Delete package.json
Input::
//// [/src/projects/project/package.json] unlink
Output::
/lib/tsc -p src --explainFiles --extendedDiagnostics
File '/src/projects/project/src/package.json' does not exist.
File '/src/projects/project/package.json' does not exist.
File '/src/projects/package.json' does not exist.
File '/src/package.json' does not exist.
File '/package.json' does not exist.
File '/src/projects/project/src/package.json' does not exist according to earlier cached lookups.
File '/src/projects/project/package.json' does not exist according to earlier cached lookups.
File '/src/projects/package.json' does not exist according to earlier cached lookups.
File '/src/package.json' does not exist according to earlier cached lookups.
File '/package.json' does not exist according to earlier cached lookups.
======== Resolving module './fileB.mjs' from '/src/projects/project/src/fileA.ts'. ========
Module resolution kind is not specified, using 'Node16'.
Resolving in CJS mode with conditions 'require', 'types', 'node'.
Loading module as file / folder, candidate module location '/src/projects/project/src/fileB.mjs', target file types: TypeScript, JavaScript, Declaration.
File name '/src/projects/project/src/fileB.mjs' has a '.mjs' extension - stripping it.
File '/src/projects/project/src/fileB.mts' exists - use it as a name resolution result.
======== Module name './fileB.mjs' was successfully resolved to '/src/projects/project/src/fileB.mts'. ========
File '/lib/package.json' does not exist.
File '/package.json' does not exist according to earlier cached lookups.
src/fileA.ts:1:21 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./fileB.mjs")' call instead.
To convert this file to an ECMAScript module, change its file extension to '.mts' or create a local package.json file with `{ "type": "module" }`.
1 import { foo } from "./fileB.mjs";
   ~~~~~~~~~~~~~
../../../lib/lib.es2016.full.d.ts
Default library for target 'es2016'
src/main.ts
Part of 'files' list in tsconfig.json
File is CommonJS module because 'package.json' was not found
src/fileB.mts
Imported via "./fileB.mjs" from file 'src/fileA.ts'
Part of 'files' list in tsconfig.json
src/fileA.ts
Part of 'files' list in tsconfig.json
File is CommonJS module because 'package.json' was not found
Found 1 error in src/fileA.ts:1
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated