diff --git a/src/testRunner/unittests/tsbuild/resolveJsonModule.ts b/src/testRunner/unittests/tsbuild/resolveJsonModule.ts index 4d36bab67ba..3d1d8c3549d 100644 --- a/src/testRunner/unittests/tsbuild/resolveJsonModule.ts +++ b/src/testRunner/unittests/tsbuild/resolveJsonModule.ts @@ -1,7 +1,6 @@ namespace ts { describe("unittests:: tsbuild:: with resolveJsonModule option on project resolveJsonModuleAndComposite", () => { let projFs: vfs.FileSystem; - const allExpectedOutputs = ["/src/dist/src/index.js", "/src/dist/src/index.d.ts", "/src/dist/src/hello.json"]; before(() => { projFs = loadProjectFromDisk("tests/projects/resolveJsonModuleAndComposite"); }); @@ -10,108 +9,64 @@ namespace ts { projFs = undefined!; // Release the contents }); - function verifyProjectWithResolveJsonModule(configFile: string, ...expectedDiagnosticMessages: fakes.ExpectedDiagnostic[]) { - const fs = projFs.shadow(); - verifyProjectWithResolveJsonModuleWithFs(fs, configFile, allExpectedOutputs, ...expectedDiagnosticMessages); - } - - function verifyProjectWithResolveJsonModuleWithFs(fs: vfs.FileSystem, configFile: string, allExpectedOutputs: readonly string[], ...expectedDiagnosticMessages: fakes.ExpectedDiagnostic[]) { - const host = fakes.SolutionBuilderHost.create(fs); - const builder = createSolutionBuilder(host, [configFile], { dry: false, force: false, verbose: false }); - builder.build(); - host.assertDiagnosticMessages(...expectedDiagnosticMessages); - if (!expectedDiagnosticMessages.length) { - // Check for outputs. Not an exhaustive list - verifyOutputsPresent(fs, allExpectedOutputs); - } - } - - it("with resolveJsonModule and include only", () => { - verifyProjectWithResolveJsonModule( - "/src/tsconfig_withInclude.json", - { - message: [ - Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, - "/src/src/hello.json", - "/src/tsconfig_withInclude.json" - ], - location: expectedLocationIndexOf(projFs, "/src/src/index.ts", `"./hello.json"`) - } - ); + verifyTsc({ + scenario: "resolveJsonModule", + subScenario: "include only", + fs: () => projFs, + commandLineArgs: ["--b", "/src/tsconfig_withInclude.json"], }); - it("with resolveJsonModule and include of *.json along with other include", () => { - verifyProjectWithResolveJsonModule("/src/tsconfig_withIncludeOfJson.json"); + verifyTsc({ + scenario: "resolveJsonModule", + subScenario: "include of json along with other include", + fs: () => projFs, + commandLineArgs: ["--b", "/src/tsconfig_withIncludeOfJson.json"], }); - it("with resolveJsonModule and include of *.json along with other include and file name matches ts file", () => { - const fs = projFs.shadow(); - fs.rimrafSync("/src/src/hello.json"); - fs.writeFileSync("/src/src/index.json", JSON.stringify({ hello: "world" })); - fs.writeFileSync("/src/src/index.ts", `import hello from "./index.json" + verifyTsc({ + scenario: "resolveJsonModule", + subScenario: "include of json along with other include and file name matches ts file", + fs: () => projFs, + commandLineArgs: ["--b", "/src/tsconfig_withIncludeOfJson.json"], + modifyFs: fs => { + fs.rimrafSync("/src/src/hello.json"); + fs.writeFileSync("/src/src/index.json", JSON.stringify({ hello: "world" })); + fs.writeFileSync("/src/src/index.ts", `import hello from "./index.json" export default hello.hello`); - const allExpectedOutputs = ["/src/dist/src/index.js", "/src/dist/src/index.d.ts", "/src/dist/src/index.json"]; - verifyProjectWithResolveJsonModuleWithFs( - fs, - "/src/tsconfig_withIncludeOfJson.json", - allExpectedOutputs, - errorDiagnostic([Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files, "/src/dist/src/index.d.ts"]) - ); + }, }); - it("with resolveJsonModule and files containing json file", () => { - verifyProjectWithResolveJsonModule("/src/tsconfig_withFiles.json"); + verifyTsc({ + scenario: "resolveJsonModule", + subScenario: "files containing json file", + fs: () => projFs, + commandLineArgs: ["--b", "/src/tsconfig_withFiles.json"], }); - it("with resolveJsonModule and include and files", () => { - verifyProjectWithResolveJsonModule("/src/tsconfig_withIncludeAndFiles.json"); + verifyTsc({ + scenario: "resolveJsonModule", + subScenario: "include and files", + fs: () => projFs, + commandLineArgs: ["--b", "/src/tsconfig_withIncludeAndFiles.json"], }); - it("with resolveJsonModule and sourceMap", () => { - const { fs, tick } = getFsWithTime(projFs); - const configFile = "src/tsconfig_withFiles.json"; - replaceText(fs, configFile, `"composite": true,`, `"composite": true, "sourceMap": true,`); - const host = fakes.SolutionBuilderHost.create(fs); - let builder = createSolutionBuilder(host, [configFile], { verbose: true }); - builder.build(); - host.assertDiagnosticMessages( - getExpectedDiagnosticForProjectsInBuild(configFile), - [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, configFile, "src/dist/src/index.js"], - [Diagnostics.Building_project_0, `/${configFile}`] - ); - verifyOutputsPresent(fs, [...allExpectedOutputs, "/src/dist/src/index.js.map"]); - host.clearDiagnostics(); - builder = createSolutionBuilder(host, [configFile], { verbose: true }); - tick(); - builder.build(); - host.assertDiagnosticMessages( - getExpectedDiagnosticForProjectsInBuild(configFile), - [Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, configFile, "src/src/index.ts", "src/dist/src/index.js"] - ); + verifyTscIncrementalEdits({ + scenario: "resolveJsonModule", + subScenario: "sourcemap", + fs: () => projFs, + commandLineArgs: ["--b", "src/tsconfig_withFiles.json", "--verbose"], + modifyFs: fs => replaceText(fs, "src/tsconfig_withFiles.json", `"composite": true,`, `"composite": true, "sourceMap": true,`), + incrementalScenarios: [noChangeRun] }); - it("with resolveJsonModule and without outDir", () => { - const { fs, tick } = getFsWithTime(projFs); - const configFile = "src/tsconfig_withFiles.json"; - replaceText(fs, configFile, `"outDir": "dist",`, ""); - const host = fakes.SolutionBuilderHost.create(fs); - let builder = createSolutionBuilder(host, [configFile], { verbose: true }); - builder.build(); - host.assertDiagnosticMessages( - getExpectedDiagnosticForProjectsInBuild(configFile), - [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, configFile, "src/src/index.js"], - [Diagnostics.Building_project_0, `/${configFile}`] - ); - verifyOutputsPresent(fs, ["/src/src/index.js", "/src/src/index.d.ts"]); - host.clearDiagnostics(); - builder = createSolutionBuilder(host, [configFile], { verbose: true }); - tick(); - builder.build(); - host.assertDiagnosticMessages( - getExpectedDiagnosticForProjectsInBuild(configFile), - [Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, configFile, "src/src/index.ts", "src/src/index.js"] - ); + verifyTscIncrementalEdits({ + scenario: "resolveJsonModule", + subScenario: "without outDir", + fs: () => projFs, + commandLineArgs: ["--b", "src/tsconfig_withFiles.json", "--verbose"], + modifyFs: fs => replaceText(fs, "src/tsconfig_withFiles.json", `"outDir": "dist",`, ""), + incrementalScenarios: [noChangeRun] }); }); @@ -125,32 +80,12 @@ export default hello.hello`); projFs = undefined!; // Release the contents }); - it("when importing json module from project reference", () => { - const expectedOutput = "/src/main/index.js"; - const { fs, tick } = getFsWithTime(projFs); - const configFile = "src/tsconfig.json"; - const stringsConfigFile = "src/strings/tsconfig.json"; - const mainConfigFile = "src/main/tsconfig.json"; - const host = fakes.SolutionBuilderHost.create(fs); - let builder = createSolutionBuilder(host, [configFile], { verbose: true }); - builder.build(); - host.assertDiagnosticMessages( - getExpectedDiagnosticForProjectsInBuild(stringsConfigFile, mainConfigFile, configFile), - [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, stringsConfigFile, "src/strings/tsconfig.tsbuildinfo"], - [Diagnostics.Building_project_0, `/${stringsConfigFile}`], - [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, mainConfigFile, "src/main/index.js"], - [Diagnostics.Building_project_0, `/${mainConfigFile}`], - ); - verifyOutputsPresent(fs, [expectedOutput]); - host.clearDiagnostics(); - builder = createSolutionBuilder(host, [configFile], { verbose: true }); - tick(); - builder.build(); - host.assertDiagnosticMessages( - getExpectedDiagnosticForProjectsInBuild(stringsConfigFile, mainConfigFile, configFile), - [Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, stringsConfigFile, "src/strings/foo.json", "src/strings/tsconfig.tsbuildinfo"], - [Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, mainConfigFile, "src/main/index.ts", "src/main/index.js"], - ); + verifyTscIncrementalEdits({ + scenario: "resolveJsonModule", + subScenario: "importing json module from project reference", + fs: () => projFs, + commandLineArgs: ["--b", "src/tsconfig.json", "--verbose"], + incrementalScenarios: [noChangeRun] }); }); } diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/files-containing-json-file.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/files-containing-json-file.js new file mode 100644 index 00000000000..1d953745219 --- /dev/null +++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/files-containing-json-file.js @@ -0,0 +1,73 @@ +//// [/lib/initial-buildOutput.txt] +/lib/tsc --b /src/tsconfig_withFiles.json +exitCode:: ExitStatus.Success + + +//// [/src/dist/src/hello.d.ts] +export declare const hello: string; + + +//// [/src/dist/src/hello.json] +{ + "hello": "world" +} + + +//// [/src/dist/src/index.d.ts] +declare const _default: string; +export default _default; + + +//// [/src/dist/src/index.js] +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +exports.__esModule = true; +var hello_json_1 = __importDefault(require("./hello.json")); +exports["default"] = hello_json_1["default"].hello; + + +//// [/src/dist/tsconfig_withFiles.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };" + }, + "../src/hello.json": { + "version": "6651571919-{\n \"hello\": \"world\"\n}", + "signature": "-4341462827-export declare const hello: string;\r\n" + }, + "../src/index.ts": { + "version": "-27703454282-import hello from \"./hello.json\"\n\nexport default hello.hello", + "signature": "-1680156224-declare const _default: string;\r\nexport default _default;\r\n" + } + }, + "options": { + "composite": true, + "moduleResolution": 2, + "module": 1, + "resolveJsonModule": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "outDir": "./", + "skipDefaultLibCheck": true, + "configFilePath": "../tsconfig_withFiles.json" + }, + "referencedMap": { + "../src/index.ts": [ + "../src/hello.json" + ] + }, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "../src/hello.json", + "../src/index.ts" + ] + }, + "version": "FakeTSVersion" +} + diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/importing-json-module-from-project-reference.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/importing-json-module-from-project-reference.js new file mode 100644 index 00000000000..12542f55749 --- /dev/null +++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/importing-json-module-from-project-reference.js @@ -0,0 +1,108 @@ +//// [/lib/initial-buildOutput.txt] +/lib/tsc --b src/tsconfig.json --verbose +12:01:00 AM - Projects in this build: + * src/strings/tsconfig.json + * src/main/tsconfig.json + * src/tsconfig.json + +12:01:00 AM - Project 'src/strings/tsconfig.json' is out of date because output file 'src/strings/tsconfig.tsbuildinfo' does not exist + +12:01:00 AM - Building project '/src/strings/tsconfig.json'... + +12:01:00 AM - Project 'src/main/tsconfig.json' is out of date because output file 'src/main/index.js' does not exist + +12:01:00 AM - Building project '/src/main/tsconfig.json'... + +exitCode:: ExitStatus.Success + + +//// [/src/main/index.d.ts] +export {}; + + +//// [/src/main/index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var foo_json_1 = require("../strings/foo.json"); +console.log(foo_json_1.foo); + + +//// [/src/main/tsconfig.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };" + }, + "../strings/foo.json": { + "version": "-1457151099-export declare const foo: string;\r\n", + "signature": "-1457151099-export declare const foo: string;\r\n" + }, + "./index.ts": { + "version": "-4651661680-import { foo } from '../strings/foo.json';\n\nconsole.log(foo);", + "signature": "-4882119183-export {};\r\n" + } + }, + "options": { + "target": 1, + "module": 1, + "rootDir": "..", + "composite": true, + "resolveJsonModule": true, + "strict": true, + "esModuleInterop": true, + "configFilePath": "./tsconfig.json" + }, + "referencedMap": { + "./index.ts": [ + "../strings/foo.d.ts" + ] + }, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "../strings/foo.json", + "./index.ts" + ] + }, + "version": "FakeTSVersion" +} + +//// [/src/strings/foo.d.ts] +export declare const foo: string; + + +//// [/src/strings/tsconfig.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };" + }, + "./foo.json": { + "version": "4395333385-{\n \"foo\": \"bar baz\"\n}", + "signature": "-1457151099-export declare const foo: string;\r\n" + } + }, + "options": { + "target": 1, + "module": 1, + "rootDir": "..", + "composite": true, + "resolveJsonModule": true, + "strict": true, + "esModuleInterop": true, + "configFilePath": "./tsconfig.json" + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "./foo.json" + ] + }, + "version": "FakeTSVersion" +} + diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-and-files.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-and-files.js new file mode 100644 index 00000000000..b4404190e27 --- /dev/null +++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-and-files.js @@ -0,0 +1,73 @@ +//// [/lib/initial-buildOutput.txt] +/lib/tsc --b /src/tsconfig_withIncludeAndFiles.json +exitCode:: ExitStatus.Success + + +//// [/src/dist/src/hello.d.ts] +export declare const hello: string; + + +//// [/src/dist/src/hello.json] +{ + "hello": "world" +} + + +//// [/src/dist/src/index.d.ts] +declare const _default: string; +export default _default; + + +//// [/src/dist/src/index.js] +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +exports.__esModule = true; +var hello_json_1 = __importDefault(require("./hello.json")); +exports["default"] = hello_json_1["default"].hello; + + +//// [/src/dist/tsconfig_withIncludeAndFiles.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };" + }, + "../src/hello.json": { + "version": "6651571919-{\n \"hello\": \"world\"\n}", + "signature": "-4341462827-export declare const hello: string;\r\n" + }, + "../src/index.ts": { + "version": "-27703454282-import hello from \"./hello.json\"\n\nexport default hello.hello", + "signature": "-1680156224-declare const _default: string;\r\nexport default _default;\r\n" + } + }, + "options": { + "composite": true, + "moduleResolution": 2, + "module": 1, + "resolveJsonModule": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "outDir": "./", + "skipDefaultLibCheck": true, + "configFilePath": "../tsconfig_withIncludeAndFiles.json" + }, + "referencedMap": { + "../src/index.ts": [ + "../src/hello.json" + ] + }, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "../src/hello.json", + "../src/index.ts" + ] + }, + "version": "FakeTSVersion" +} + diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include-and-file-name-matches-ts-file.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include-and-file-name-matches-ts-file.js new file mode 100644 index 00000000000..0b516b4944f --- /dev/null +++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include-and-file-name-matches-ts-file.js @@ -0,0 +1,15 @@ +//// [/lib/initial-buildOutput.txt] +/lib/tsc --b /src/tsconfig_withIncludeOfJson.json +error TS5056: Cannot write file '/src/dist/src/index.d.ts' because it would be overwritten by multiple input files. +exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped + + +//// [/src/src/hello.json] unlink +//// [/src/src/index.json] +{"hello":"world"} + +//// [/src/src/index.ts] +import hello from "./index.json" + +export default hello.hello + diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include.js new file mode 100644 index 00000000000..5bedb91c4be --- /dev/null +++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-of-json-along-with-other-include.js @@ -0,0 +1,73 @@ +//// [/lib/initial-buildOutput.txt] +/lib/tsc --b /src/tsconfig_withIncludeOfJson.json +exitCode:: ExitStatus.Success + + +//// [/src/dist/src/hello.d.ts] +export declare const hello: string; + + +//// [/src/dist/src/hello.json] +{ + "hello": "world" +} + + +//// [/src/dist/src/index.d.ts] +declare const _default: string; +export default _default; + + +//// [/src/dist/src/index.js] +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +exports.__esModule = true; +var hello_json_1 = __importDefault(require("./hello.json")); +exports["default"] = hello_json_1["default"].hello; + + +//// [/src/dist/tsconfig_withIncludeOfJson.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };" + }, + "../src/hello.json": { + "version": "6651571919-{\n \"hello\": \"world\"\n}", + "signature": "-4341462827-export declare const hello: string;\r\n" + }, + "../src/index.ts": { + "version": "-27703454282-import hello from \"./hello.json\"\n\nexport default hello.hello", + "signature": "-1680156224-declare const _default: string;\r\nexport default _default;\r\n" + } + }, + "options": { + "composite": true, + "moduleResolution": 2, + "module": 1, + "resolveJsonModule": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "outDir": "./", + "skipDefaultLibCheck": true, + "configFilePath": "../tsconfig_withIncludeOfJson.json" + }, + "referencedMap": { + "../src/index.ts": [ + "../src/hello.json" + ] + }, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "../src/hello.json", + "../src/index.ts" + ] + }, + "version": "FakeTSVersion" +} + diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-only.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-only.js new file mode 100644 index 00000000000..a809be90609 --- /dev/null +++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/include-only.js @@ -0,0 +1,6 @@ +//// [/lib/initial-buildOutput.txt] +/lib/tsc --b /src/tsconfig_withInclude.json +src/src/index.ts(1,19): error TS6307: File '/src/src/hello.json' is not listed within the file list of project '/src/tsconfig_withInclude.json'. Projects must list all files or use an 'include' pattern. +exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped + + diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/sourcemap.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/sourcemap.js new file mode 100644 index 00000000000..92ff87ebcad --- /dev/null +++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/sourcemap.js @@ -0,0 +1,101 @@ +//// [/lib/initial-buildOutput.txt] +/lib/tsc --b src/tsconfig_withFiles.json --verbose +12:01:00 AM - Projects in this build: + * src/tsconfig_withFiles.json + +12:01:00 AM - Project 'src/tsconfig_withFiles.json' is out of date because output file 'src/dist/src/index.js' does not exist + +12:01:00 AM - Building project '/src/tsconfig_withFiles.json'... + +exitCode:: ExitStatus.Success + + +//// [/src/dist/src/hello.d.ts] +export declare const hello: string; + + +//// [/src/dist/src/hello.json] +{ + "hello": "world" +} + + +//// [/src/dist/src/index.d.ts] +declare const _default: string; +export default _default; + + +//// [/src/dist/src/index.js] +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +exports.__esModule = true; +var hello_json_1 = __importDefault(require("./hello.json")); +exports["default"] = hello_json_1["default"].hello; +//# sourceMappingURL=index.js.map + +//// [/src/dist/src/index.js.map] +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,4DAAgC;AAEhC,qBAAe,uBAAK,CAAC,KAAK,CAAA"} + +//// [/src/dist/tsconfig_withFiles.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };" + }, + "../src/hello.json": { + "version": "6651571919-{\n \"hello\": \"world\"\n}", + "signature": "-4341462827-export declare const hello: string;\r\n" + }, + "../src/index.ts": { + "version": "-27703454282-import hello from \"./hello.json\"\n\nexport default hello.hello", + "signature": "-1680156224-declare const _default: string;\r\nexport default _default;\r\n" + } + }, + "options": { + "composite": true, + "sourceMap": true, + "moduleResolution": 2, + "module": 1, + "resolveJsonModule": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "outDir": "./", + "skipDefaultLibCheck": true, + "configFilePath": "../tsconfig_withFiles.json" + }, + "referencedMap": { + "../src/index.ts": [ + "../src/hello.json" + ] + }, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "../src/hello.json", + "../src/index.ts" + ] + }, + "version": "FakeTSVersion" +} + +//// [/src/tsconfig_withFiles.json] +{ + "compilerOptions": { + "composite": true, "sourceMap": true, + "moduleResolution": "node", + "module": "commonjs", + "resolveJsonModule": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "outDir": "dist", + "skipDefaultLibCheck": true + }, + "files": [ + "src/index.ts", "src/hello.json" + ] +} + diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/without-outDir.js b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/without-outDir.js new file mode 100644 index 00000000000..b8756d8bf4b --- /dev/null +++ b/tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/without-outDir.js @@ -0,0 +1,90 @@ +//// [/lib/initial-buildOutput.txt] +/lib/tsc --b src/tsconfig_withFiles.json --verbose +12:01:00 AM - Projects in this build: + * src/tsconfig_withFiles.json + +12:01:00 AM - Project 'src/tsconfig_withFiles.json' is out of date because output file 'src/src/index.js' does not exist + +12:01:00 AM - Building project '/src/tsconfig_withFiles.json'... + +exitCode:: ExitStatus.Success + + +//// [/src/src/hello.d.ts] +export declare const hello: string; + + +//// [/src/src/index.d.ts] +declare const _default: string; +export default _default; + + +//// [/src/src/index.js] +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +exports.__esModule = true; +var hello_json_1 = __importDefault(require("./hello.json")); +exports["default"] = hello_json_1["default"].hello; + + +//// [/src/tsconfig_withFiles.json] +{ + "compilerOptions": { + "composite": true, + "moduleResolution": "node", + "module": "commonjs", + "resolveJsonModule": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + + "skipDefaultLibCheck": true + }, + "files": [ + "src/index.ts", "src/hello.json" + ] +} + +//// [/src/tsconfig_withFiles.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../lib/lib.d.ts": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };" + }, + "./src/hello.json": { + "version": "6651571919-{\n \"hello\": \"world\"\n}", + "signature": "-4341462827-export declare const hello: string;\r\n" + }, + "./src/index.ts": { + "version": "-27703454282-import hello from \"./hello.json\"\n\nexport default hello.hello", + "signature": "-1680156224-declare const _default: string;\r\nexport default _default;\r\n" + } + }, + "options": { + "composite": true, + "moduleResolution": 2, + "module": 1, + "resolveJsonModule": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "skipDefaultLibCheck": true, + "configFilePath": "./tsconfig_withFiles.json" + }, + "referencedMap": { + "./src/index.ts": [ + "./src/hello.json" + ] + }, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../lib/lib.d.ts", + "./src/hello.json", + "./src/index.ts" + ] + }, + "version": "FakeTSVersion" +} + diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/no-change-run/importing-json-module-from-project-reference.js b/tests/baselines/reference/tsbuild/resolveJsonModule/no-change-run/importing-json-module-from-project-reference.js new file mode 100644 index 00000000000..512a0f0e4a9 --- /dev/null +++ b/tests/baselines/reference/tsbuild/resolveJsonModule/no-change-run/importing-json-module-from-project-reference.js @@ -0,0 +1,14 @@ +//// [/lib/no-change-runOutput.txt] +/lib/tsc --b src/tsconfig.json --verbose +12:04:00 AM - Projects in this build: + * src/strings/tsconfig.json + * src/main/tsconfig.json + * src/tsconfig.json + +12:04:00 AM - Project 'src/strings/tsconfig.json' is up to date because newest input 'src/strings/foo.json' is older than oldest output 'src/strings/tsconfig.tsbuildinfo' + +12:04:00 AM - Project 'src/main/tsconfig.json' is up to date because newest input 'src/main/index.ts' is older than oldest output 'src/main/index.js' + +exitCode:: ExitStatus.Success + + diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/no-change-run/sourcemap.js b/tests/baselines/reference/tsbuild/resolveJsonModule/no-change-run/sourcemap.js new file mode 100644 index 00000000000..a5638600708 --- /dev/null +++ b/tests/baselines/reference/tsbuild/resolveJsonModule/no-change-run/sourcemap.js @@ -0,0 +1,10 @@ +//// [/lib/no-change-runOutput.txt] +/lib/tsc --b src/tsconfig_withFiles.json --verbose +12:04:00 AM - Projects in this build: + * src/tsconfig_withFiles.json + +12:04:00 AM - Project 'src/tsconfig_withFiles.json' is up to date because newest input 'src/src/index.ts' is older than oldest output 'src/dist/src/index.js' + +exitCode:: ExitStatus.Success + + diff --git a/tests/baselines/reference/tsbuild/resolveJsonModule/no-change-run/without-outDir.js b/tests/baselines/reference/tsbuild/resolveJsonModule/no-change-run/without-outDir.js new file mode 100644 index 00000000000..a6329e50745 --- /dev/null +++ b/tests/baselines/reference/tsbuild/resolveJsonModule/no-change-run/without-outDir.js @@ -0,0 +1,10 @@ +//// [/lib/no-change-runOutput.txt] +/lib/tsc --b src/tsconfig_withFiles.json --verbose +12:04:00 AM - Projects in this build: + * src/tsconfig_withFiles.json + +12:04:00 AM - Project 'src/tsconfig_withFiles.json' is up to date because newest input 'src/src/index.ts' is older than oldest output 'src/src/index.js' + +exitCode:: ExitStatus.Success + +