From b9f60b91f0537fb501ff4f9e80edc5fc33c179ea Mon Sep 17 00:00:00 2001 From: craigphicks <13205732+craigphicks@users.noreply.github.com> Date: Wed, 4 May 2022 11:13:16 -0700 Subject: [PATCH 1/6] testing package.json and impliedNodeFormat --- src/compiler/tsbuildPublic.ts | 2 + src/testRunner/tsconfig.json | 1 + .../publicApiImpliedNodeFormat.ts | 161 ++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts diff --git a/src/compiler/tsbuildPublic.ts b/src/compiler/tsbuildPublic.ts index 5b17f2f4d902d..d38dca3793169 100644 --- a/src/compiler/tsbuildPublic.ts +++ b/src/compiler/tsbuildPublic.ts @@ -148,6 +148,7 @@ namespace ts { /*@internal*/ buildNextInvalidatedProject(): void; /*@internal*/ getAllParsedConfigs(): readonly ParsedCommandLine[]; /*@internal*/ close(): void; + /*@internal*/ getModuleResolutionCache(): ModuleResolutionCache | undefined; } /** @@ -1992,6 +1993,7 @@ namespace ts { config => isParsedCommandLine(config) ? config : undefined )), close: () => stopWatching(state), + getModuleResolutionCache: ()=> state.moduleResolutionCache, }; } diff --git a/src/testRunner/tsconfig.json b/src/testRunner/tsconfig.json index 401c5aeb68a8d..200149a3d08f2 100644 --- a/src/testRunner/tsconfig.json +++ b/src/testRunner/tsconfig.json @@ -147,6 +147,7 @@ "unittests/tsbuildWatch/noEmitOnError.ts", "unittests/tsbuildWatch/programUpdates.ts", "unittests/tsbuildWatch/publicApi.ts", + "unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts", "unittests/tsbuildWatch/reexport.ts", "unittests/tsbuildWatch/watchEnvironment.ts", "unittests/tsc/composite.ts", diff --git a/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts b/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts new file mode 100644 index 0000000000000..e84362bfda7f7 --- /dev/null +++ b/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts @@ -0,0 +1,161 @@ +namespace ts.tscWatch { + it("unittests:: tsbuildWatch:: watchMode:: Public API with custom transformers / impliedNodeFormat", () => { + const solution: File = { + path: `${projectRoot}/tsconfig.json`, + content: JSON.stringify({ + references: [ + { path: "./shared/tsconfig.json" }, + { path: "./webpack/tsconfig.json" } + ], + files: [] + }) + }; + const sharedConfig: File = { + path: `${projectRoot}/shared/tsconfig.json`, + content: JSON.stringify({ + module:"Node12", + compilerOptions: { composite: true }, + }) + }; + const sharedPackageJson: File = { + path: `${projectRoot}/shared/package.json`, + content: JSON.stringify({ + name:"shared", + version:"1.0.0", + type:"commonjs", + }) + }; + const sharedIndex: File = { + path: `${projectRoot}/shared/index.ts`, + content: `export function f1() { } +export class c { } +export enum e { } +// leading +export function f2() { } // trailing` + }; + const webpackConfig: File = { + path: `${projectRoot}/webpack/tsconfig.json`, + content: JSON.stringify({ + compilerOptions: { composite: true, }, + references: [{ path: "../shared/tsconfig.json" }] + }) + }; + const webpackIndex: File = { + path: `${projectRoot}/webpack/index.ts`, + content: `export function f2() { } +export class c2 { } +export enum e2 { } +// leading +export function f22() { } // trailing` + }; + const commandLineArgs = ["--b", "--w", /*"--verbose"*/]; + const { sys, baseline, oldSnap, cb, getPrograms } = createBaseline(createWatchedSystem([libFile, solution, sharedConfig, sharedPackageJson, sharedIndex, webpackConfig, webpackIndex], { currentDirectory: projectRoot })); + + const writeToConsole = true; + if (writeToConsole){ + const origSysWrite = sys.write.bind(sys); + sys.write = (message: string)=>{ + console.log(message); + origSysWrite(message); + }; + } + type ImpliedNodeFormat = ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + const impliedNodeFormatToString = (f: ImpliedNodeFormat)=>(f===undefined)? "undefined" : ModuleKind[f]; + const lastImpliedNodeFormats = new Map(); + function printLastImpliedNodeFormats(){ + lastImpliedNodeFormats.forEach((x,fileName)=>{ + sys.write(`fileName:${fileName},impliedNodeFormat:${impliedNodeFormatToString(x.impliedNodeFormat)}`+sys.newLine); + }); + } + + function printModuleResolutionCache(buildr: SolutionBuilder){ + const x = { moduleResolutionCache: buildr.getModuleResolutionCache() }; + sys.write(JSON.stringify(x,undefined,2)); + } + + const buildHost = createSolutionBuilderWithWatchHostForBaseline(sys, cb); + buildHost.getCustomTransformers = getCustomTransformers; + const builder = createSolutionBuilderWithWatch(buildHost, [solution.path], { verbose: true }); + + builder.build(); + runWatchBaseline({ + scenario: "publicApi", + subScenario: "with custom transformers", + commandLineArgs, + sys, + baseline, + oldSnap, + getPrograms, + changes: [ + { + caption: "change to shared", + change: sys => sys.prependFile(sharedIndex.path, "export function fooBar() {}"), + timeouts: sys => { + sys.checkTimeoutQueueLengthAndRun(1); // Shared + sys.checkTimeoutQueueLengthAndRun(1); // webpack + sys.checkTimeoutQueueLengthAndRun(1); // solution + sys.checkTimeoutQueueLength(0); + printLastImpliedNodeFormats(); + printModuleResolutionCache(builder); + if (lastImpliedNodeFormats.get("/user/username/projects/myproject/shared/index.ts")?.impliedNodeFormat!==ModuleKind.CommonJS) { + throw new Error(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.CommonJS`); + } + } + }, + // { + // caption: "add package.json to shared", + // change: sys => sys.writeFile(sharedPackageJson.path, sharedPackageJson.content), + // timeouts: sys => { + // sys.checkTimeoutQueueLengthAndRun(1); // Shared + // sys.checkTimeoutQueueLengthAndRun(1); // webpack + // sys.checkTimeoutQueueLengthAndRun(1); // solution + // sys.checkTimeoutQueueLength(0); + // printLastImpliedNodeFormats(); + // } + // } + ], + watchOrSolution: builder + }); + + function getCustomTransformers(project: string): CustomTransformers { + const before: TransformerFactory = context => { + return file => { + // const gotImpliedNodeFormat = getImpliedNodeFormatForFile( + // importingSourceFileName, buildHost.getPackageJsonInfoCache?.(), getModuleResolutionHost(host), compilerOptions);; + + lastImpliedNodeFormats.set(file.fileName,{ impliedNodeFormat : file.impliedNodeFormat }); + return visitEachChild(file, visit, context); + }; + function visit(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + return visitFunction(node as FunctionDeclaration); + default: + return visitEachChild(node, visit, context); + } + } + function visitFunction(node: FunctionDeclaration) { + addSyntheticLeadingComment(node, SyntaxKind.MultiLineCommentTrivia, `@before${project}`, /*hasTrailingNewLine*/ true); + return node; + } + }; + + const after: TransformerFactory = context => { + return file => visitEachChild(file, visit, context); + function visit(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.VariableStatement: + return visitVariableStatement(node as VariableStatement); + default: + return visitEachChild(node, visit, context); + } + } + function visitVariableStatement(node: VariableStatement) { + addSyntheticLeadingComment(node, SyntaxKind.SingleLineCommentTrivia, `@after${project}`); + return node; + } + }; + return { before: [before], after: [after] }; + } + }); +} From edd89ef85e027dd647eec77479120cd3be5f841f Mon Sep 17 00:00:00 2001 From: craigphicks <13205732+craigphicks@users.noreply.github.com> Date: Wed, 4 May 2022 14:04:26 -0700 Subject: [PATCH 2/6] shared/tsconfig.options.json now correct --- .../publicApiImpliedNodeFormat.ts | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts b/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts index e84362bfda7f7..829e3cac4c2b1 100644 --- a/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts +++ b/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts @@ -1,5 +1,22 @@ namespace ts.tscWatch { - it("unittests:: tsbuildWatch:: watchMode:: Public API with custom transformers / impliedNodeFormat", () => { +// export const libFile: File = { +// path: "/a/lib/lib.d.ts", +// content: `/// +// 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; }` +// }; + + + + it("unittests:: tsbuildWatch:: watchMode:: Public API with custom transformers / PublicAPI-impliedNodeFormat", () => { const solution: File = { path: `${projectRoot}/tsconfig.json`, content: JSON.stringify({ @@ -10,11 +27,24 @@ namespace ts.tscWatch { files: [] }) }; + const sharedConfigOptions: File = { + path: `${projectRoot}/shared/tsconfig.options.json`, + content: JSON.stringify({ + compilerOptions: { + module:"Node12", + lib: ["es2020"], + moduleResolution: "node", + target: "es2020", + }, + }) + }; const sharedConfig: File = { path: `${projectRoot}/shared/tsconfig.json`, content: JSON.stringify({ - module:"Node12", - compilerOptions: { composite: true }, + extends:"./tsconfig.options.json", + compilerOptions: { + composite: true + }, }) }; const sharedPackageJson: File = { @@ -49,7 +79,7 @@ export enum e2 { } export function f22() { } // trailing` }; const commandLineArgs = ["--b", "--w", /*"--verbose"*/]; - const { sys, baseline, oldSnap, cb, getPrograms } = createBaseline(createWatchedSystem([libFile, solution, sharedConfig, sharedPackageJson, sharedIndex, webpackConfig, webpackIndex], { currentDirectory: projectRoot })); + const { sys, baseline, oldSnap, cb, getPrograms } = createBaseline(createWatchedSystem([libFile, { ...libFile, path: "/a/lib/lib.es2020.d.ts" }, solution, sharedConfig, sharedConfigOptions, sharedPackageJson, sharedIndex, webpackConfig, webpackIndex], { currentDirectory: projectRoot })); const writeToConsole = true; if (writeToConsole){ @@ -98,7 +128,8 @@ export function f22() { } // trailing` printLastImpliedNodeFormats(); printModuleResolutionCache(builder); if (lastImpliedNodeFormats.get("/user/username/projects/myproject/shared/index.ts")?.impliedNodeFormat!==ModuleKind.CommonJS) { - throw new Error(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.CommonJS`); +// throw new Error(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.CommonJS`); + sys.write(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.CommonJS`); } } }, @@ -122,7 +153,7 @@ export function f22() { } // trailing` return file => { // const gotImpliedNodeFormat = getImpliedNodeFormatForFile( // importingSourceFileName, buildHost.getPackageJsonInfoCache?.(), getModuleResolutionHost(host), compilerOptions);; - + sys.write(`project=${project}, file.impliedNodeFormat=${impliedNodeFormatToString(file.impliedNodeFormat)}`); lastImpliedNodeFormats.set(file.fileName,{ impliedNodeFormat : file.impliedNodeFormat }); return visitEachChild(file, visit, context); }; From 9d779680890042d411c4204da9a22b500fc8af9b Mon Sep 17 00:00:00 2001 From: craigphicks <13205732+craigphicks@users.noreply.github.com> Date: Wed, 4 May 2022 17:28:01 -0700 Subject: [PATCH 3/6] On branch cph-packageJsonWatch Changes to be committed: modified: src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts new file: tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js * tests the impliedNodeFormat is correctly set for custom transformer, in a simple case with compilerOptions:nodeResolution set to Node12 --- .../publicApiImpliedNodeFormat.ts | 44 +- ...ers,-test-that-impliedNodeFormat-is-set.js | 416 ++++++++++++++++++ 2 files changed, 424 insertions(+), 36 deletions(-) create mode 100644 tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js diff --git a/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts b/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts index 829e3cac4c2b1..699e680eacdd4 100644 --- a/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts +++ b/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts @@ -1,21 +1,4 @@ namespace ts.tscWatch { -// export const libFile: File = { -// path: "/a/lib/lib.d.ts", -// content: `/// -// 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; }` -// }; - - - it("unittests:: tsbuildWatch:: watchMode:: Public API with custom transformers / PublicAPI-impliedNodeFormat", () => { const solution: File = { path: `${projectRoot}/tsconfig.json`, @@ -31,9 +14,9 @@ namespace ts.tscWatch { path: `${projectRoot}/shared/tsconfig.options.json`, content: JSON.stringify({ compilerOptions: { - module:"Node12", + //module:"Node12", == NOT NEEDED lib: ["es2020"], - moduleResolution: "node", + moduleResolution: "Node12", // absolutely needed target: "es2020", }, }) @@ -81,7 +64,7 @@ export function f22() { } // trailing` const commandLineArgs = ["--b", "--w", /*"--verbose"*/]; const { sys, baseline, oldSnap, cb, getPrograms } = createBaseline(createWatchedSystem([libFile, { ...libFile, path: "/a/lib/lib.es2020.d.ts" }, solution, sharedConfig, sharedConfigOptions, sharedPackageJson, sharedIndex, webpackConfig, webpackIndex], { currentDirectory: projectRoot })); - const writeToConsole = true; + const writeToConsole = false; // MUST BE false WHEN NOT TESTING SINGULARLY if (writeToConsole){ const origSysWrite = sys.write.bind(sys); sys.write = (message: string)=>{ @@ -110,7 +93,7 @@ export function f22() { } // trailing` builder.build(); runWatchBaseline({ scenario: "publicApi", - subScenario: "with custom transformers", + subScenario: "with custom transformers, test that impliedNodeFormat is set", commandLineArgs, sys, baseline, @@ -128,22 +111,13 @@ export function f22() { } // trailing` printLastImpliedNodeFormats(); printModuleResolutionCache(builder); if (lastImpliedNodeFormats.get("/user/username/projects/myproject/shared/index.ts")?.impliedNodeFormat!==ModuleKind.CommonJS) { -// throw new Error(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.CommonJS`); - sys.write(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.CommonJS`); + throw new Error(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.CommonJS`); + } + else { + sys.write(`impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.CommonJS`); } } }, - // { - // caption: "add package.json to shared", - // change: sys => sys.writeFile(sharedPackageJson.path, sharedPackageJson.content), - // timeouts: sys => { - // sys.checkTimeoutQueueLengthAndRun(1); // Shared - // sys.checkTimeoutQueueLengthAndRun(1); // webpack - // sys.checkTimeoutQueueLengthAndRun(1); // solution - // sys.checkTimeoutQueueLength(0); - // printLastImpliedNodeFormats(); - // } - // } ], watchOrSolution: builder }); @@ -151,8 +125,6 @@ export function f22() { } // trailing` function getCustomTransformers(project: string): CustomTransformers { const before: TransformerFactory = context => { return file => { - // const gotImpliedNodeFormat = getImpliedNodeFormatForFile( - // importingSourceFileName, buildHost.getPackageJsonInfoCache?.(), getModuleResolutionHost(host), compilerOptions);; sys.write(`project=${project}, file.impliedNodeFormat=${impliedNodeFormatToString(file.impliedNodeFormat)}`); lastImpliedNodeFormats.set(file.fileName,{ impliedNodeFormat : file.impliedNodeFormat }); return visitEachChild(file, visit, context); diff --git a/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js b/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js new file mode 100644 index 0000000000000..898aacb5b0bfd --- /dev/null +++ b/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js @@ -0,0 +1,416 @@ +Input:: +//// [/a/lib/lib.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/lib.es2020.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; } + +//// [/user/username/projects/myproject/tsconfig.json] +{"references":[{"path":"./shared/tsconfig.json"},{"path":"./webpack/tsconfig.json"}],"files":[]} + +//// [/user/username/projects/myproject/shared/tsconfig.json] +{"extends":"./tsconfig.options.json","compilerOptions":{"composite":true}} + +//// [/user/username/projects/myproject/shared/tsconfig.options.json] +{"compilerOptions":{"lib":["es2020"],"moduleResolution":"Node12","target":"es2020"}} + +//// [/user/username/projects/myproject/shared/package.json] +{"name":"shared","version":"1.0.0","type":"commonjs"} + +//// [/user/username/projects/myproject/shared/index.ts] +export function f1() { } +export class c { } +export enum e { } +// leading +export function f2() { } // trailing + +//// [/user/username/projects/myproject/webpack/tsconfig.json] +{"compilerOptions":{"composite":true},"references":[{"path":"../shared/tsconfig.json"}]} + +//// [/user/username/projects/myproject/webpack/index.ts] +export function f2() { } +export class c2 { } +export enum e2 { } +// leading +export function f22() { } // trailing + + +/a/lib/tsc.js --b --w +Output:: +[12:00:37 AM] Projects in this build: + * shared/tsconfig.json + * webpack/tsconfig.json + * tsconfig.json + +[12:00:38 AM] Project 'shared/tsconfig.json' is out of date because output file 'shared/index.js' does not exist + +[12:00:39 AM] Building project '/user/username/projects/myproject/shared/tsconfig.json'... + +project=/user/username/projects/myproject/shared/tsconfig.json, file.impliedNodeFormat=CommonJS[12:00:48 AM] Project 'webpack/tsconfig.json' is out of date because output file 'webpack/index.js' does not exist + +[12:00:49 AM] Building project '/user/username/projects/myproject/webpack/tsconfig.json'... + +project=/user/username/projects/myproject/webpack/tsconfig.json, file.impliedNodeFormat=undefined[12:00:58 AM] Found 0 errors. Watching for file changes. + + + +Program root files: ["/user/username/projects/myproject/shared/index.ts"] +Program options: {"lib":["lib.es2020.d.ts"],"moduleResolution":3,"target":7,"composite":true,"configFilePath":"/user/username/projects/myproject/shared/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.es2020.d.ts +/user/username/projects/myproject/shared/index.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.es2020.d.ts +/user/username/projects/myproject/shared/index.ts + +Shape signatures in builder refreshed for:: +/a/lib/lib.es2020.d.ts (used version) +/user/username/projects/myproject/shared/index.ts (used version) + +Program root files: ["/user/username/projects/myproject/webpack/index.ts"] +Program options: {"composite":true,"configFilePath":"/user/username/projects/myproject/webpack/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/webpack/index.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.d.ts +/user/username/projects/myproject/webpack/index.ts + +Shape signatures in builder refreshed for:: +/a/lib/lib.d.ts (used version) +/user/username/projects/myproject/webpack/index.ts (used version) + +WatchedFiles:: +/user/username/projects/myproject/shared/tsconfig.json: + {"fileName":"/user/username/projects/myproject/shared/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/shared/tsconfig.options.json: + {"fileName":"/user/username/projects/myproject/shared/tsconfig.options.json","pollingInterval":250} +/user/username/projects/myproject/shared/index.ts: + {"fileName":"/user/username/projects/myproject/shared/index.ts","pollingInterval":250} +/user/username/projects/myproject/shared/package.json: + {"fileName":"/user/username/projects/myproject/shared/package.json","pollingInterval":250} +/user/username/projects/myproject/webpack/tsconfig.json: + {"fileName":"/user/username/projects/myproject/webpack/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/webpack/index.ts: + {"fileName":"/user/username/projects/myproject/webpack/index.ts","pollingInterval":250} +/user/username/projects/myproject/webpack/package.json: + {"fileName":"/user/username/projects/myproject/webpack/package.json","pollingInterval":250} +/user/username/projects/myproject/tsconfig.json: + {"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/user/username/projects/myproject/shared: + {"directoryName":"/user/username/projects/myproject/shared","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} +/user/username/projects/myproject/webpack: + {"directoryName":"/user/username/projects/myproject/webpack","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/myproject/shared/index.js] +/*@before/user/username/projects/myproject/shared/tsconfig.json*/ +export function f1() { } +export class c { +} +//@after/user/username/projects/myproject/shared/tsconfig.json +export var e; +(function (e) { +})(e || (e = {})); +// leading +/*@before/user/username/projects/myproject/shared/tsconfig.json*/ +export function f2() { } // trailing + + +//// [/user/username/projects/myproject/shared/index.d.ts] +export declare function f1(): void; +export declare class c { +} +export declare enum e { +} +export declare function f2(): void; + + +//// [/user/username/projects/myproject/shared/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../../a/lib/lib.es2020.d.ts","./index.ts"],"fileInfos":[{"version":"-7698705165-/// \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; }","affectsGlobalScope":true,"impliedFormat":1},{"version":"8649344783-export function f1() { }\nexport class c { }\nexport enum e { }\n// leading\nexport function f2() { } // trailing","impliedFormat":1}],"options":{"composite":true,"target":7},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2]},"version":"FakeTSVersion"} + +//// [/user/username/projects/myproject/shared/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../../a/lib/lib.es2020.d.ts", + "./index.ts" + ], + "fileInfos": { + "../../../../../a/lib/lib.es2020.d.ts": { + "version": "-7698705165-/// \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; }", + "signature": "-7698705165-/// \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; }", + "affectsGlobalScope": true, + "impliedFormat": 1 + }, + "./index.ts": { + "version": "8649344783-export function f1() { }\nexport class c { }\nexport enum e { }\n// leading\nexport function f2() { } // trailing", + "signature": "8649344783-export function f1() { }\nexport class c { }\nexport enum e { }\n// leading\nexport function f2() { } // trailing", + "impliedFormat": 1 + } + }, + "options": { + "composite": true, + "target": 7 + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../../a/lib/lib.es2020.d.ts", + "./index.ts" + ] + }, + "version": "FakeTSVersion", + "size": 811 +} + +//// [/user/username/projects/myproject/webpack/index.js] +"use strict"; +exports.__esModule = true; +exports.f22 = exports.e2 = exports.c2 = exports.f2 = void 0; +/*@before/user/username/projects/myproject/webpack/tsconfig.json*/ +function f2() { } +exports.f2 = f2; +//@after/user/username/projects/myproject/webpack/tsconfig.json +var c2 = /** @class */ (function () { + function c2() { + } + return c2; +}()); +exports.c2 = c2; +//@after/user/username/projects/myproject/webpack/tsconfig.json +var e2; +(function (e2) { +})(e2 = exports.e2 || (exports.e2 = {})); +// leading +/*@before/user/username/projects/myproject/webpack/tsconfig.json*/ +function f22() { } // trailing +exports.f22 = f22; + + +//// [/user/username/projects/myproject/webpack/index.d.ts] +export declare function f2(): void; +export declare class c2 { +} +export declare enum e2 { +} +export declare function f22(): void; + + +//// [/user/username/projects/myproject/webpack/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../../a/lib/lib.d.ts","./index.ts"],"fileInfos":[{"version":"-7698705165-/// \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; }","affectsGlobalScope":true},"20140662566-export function f2() { }\nexport class c2 { }\nexport enum e2 { }\n// leading\nexport function f22() { } // trailing"],"options":{"composite":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2]},"version":"FakeTSVersion"} + +//// [/user/username/projects/myproject/webpack/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../../a/lib/lib.d.ts", + "./index.ts" + ], + "fileInfos": { + "../../../../../a/lib/lib.d.ts": { + "version": "-7698705165-/// \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; }", + "signature": "-7698705165-/// \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; }", + "affectsGlobalScope": true + }, + "./index.ts": { + "version": "20140662566-export function f2() { }\nexport class c2 { }\nexport enum e2 { }\n// leading\nexport function f22() { } // trailing", + "signature": "20140662566-export function f2() { }\nexport class c2 { }\nexport enum e2 { }\n// leading\nexport function f22() { } // trailing" + } + }, + "options": { + "composite": true + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../../a/lib/lib.d.ts", + "./index.ts" + ] + }, + "version": "FakeTSVersion", + "size": 749 +} + + +Change:: change to shared + +Input:: +//// [/user/username/projects/myproject/shared/index.ts] +export function fooBar() {}export function f1() { } +export class c { } +export enum e { } +// leading +export function f2() { } // trailing + + +Output:: +>> Screen clear +[12:01:01 AM] File change detected. Starting incremental compilation... + +[12:01:02 AM] Project 'shared/tsconfig.json' is out of date because oldest output 'shared/index.js' is older than newest input 'shared/index.ts' + +[12:01:03 AM] Building project '/user/username/projects/myproject/shared/tsconfig.json'... + +project=/user/username/projects/myproject/shared/tsconfig.json, file.impliedNodeFormat=CommonJS[12:01:16 AM] Project 'webpack/tsconfig.json' is out of date because oldest output 'webpack/index.js' is older than newest input 'shared/tsconfig.json' + +[12:01:17 AM] Building project '/user/username/projects/myproject/webpack/tsconfig.json'... + +[12:01:19 AM] Updating unchanged output timestamps of project '/user/username/projects/myproject/webpack/tsconfig.json'... + +[12:01:20 AM] Found 0 errors. Watching for file changes. + +fileName:/user/username/projects/myproject/shared/index.ts,impliedNodeFormat:CommonJS +fileName:/user/username/projects/myproject/webpack/index.ts,impliedNodeFormat:undefined +{ + "moduleResolutionCache": {} +}impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.CommonJS + +Program root files: ["/user/username/projects/myproject/shared/index.ts"] +Program options: {"lib":["lib.es2020.d.ts"],"moduleResolution":3,"target":7,"composite":true,"configFilePath":"/user/username/projects/myproject/shared/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.es2020.d.ts +/user/username/projects/myproject/shared/index.ts + +Semantic diagnostics in builder refreshed for:: +/user/username/projects/myproject/shared/index.ts + +Shape signatures in builder refreshed for:: +/user/username/projects/myproject/shared/index.ts (computed .d.ts) + +Program root files: ["/user/username/projects/myproject/webpack/index.ts"] +Program options: {"composite":true,"configFilePath":"/user/username/projects/myproject/webpack/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/webpack/index.ts + +Semantic diagnostics in builder refreshed for:: + +No shapes updated in the builder:: + +WatchedFiles:: +/user/username/projects/myproject/shared/tsconfig.json: + {"fileName":"/user/username/projects/myproject/shared/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/shared/tsconfig.options.json: + {"fileName":"/user/username/projects/myproject/shared/tsconfig.options.json","pollingInterval":250} +/user/username/projects/myproject/shared/index.ts: + {"fileName":"/user/username/projects/myproject/shared/index.ts","pollingInterval":250} +/user/username/projects/myproject/shared/package.json: + {"fileName":"/user/username/projects/myproject/shared/package.json","pollingInterval":250} +/user/username/projects/myproject/webpack/tsconfig.json: + {"fileName":"/user/username/projects/myproject/webpack/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/webpack/index.ts: + {"fileName":"/user/username/projects/myproject/webpack/index.ts","pollingInterval":250} +/user/username/projects/myproject/webpack/package.json: + {"fileName":"/user/username/projects/myproject/webpack/package.json","pollingInterval":250} +/user/username/projects/myproject/tsconfig.json: + {"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/user/username/projects/myproject/shared: + {"directoryName":"/user/username/projects/myproject/shared","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} +/user/username/projects/myproject/webpack: + {"directoryName":"/user/username/projects/myproject/webpack","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/myproject/shared/index.js] +/*@before/user/username/projects/myproject/shared/tsconfig.json*/ +export function fooBar() { } +/*@before/user/username/projects/myproject/shared/tsconfig.json*/ +export function f1() { } +export class c { +} +//@after/user/username/projects/myproject/shared/tsconfig.json +export var e; +(function (e) { +})(e || (e = {})); +// leading +/*@before/user/username/projects/myproject/shared/tsconfig.json*/ +export function f2() { } // trailing + + +//// [/user/username/projects/myproject/shared/index.d.ts] +export declare function fooBar(): void; +export declare function f1(): void; +export declare class c { +} +export declare enum e { +} +export declare function f2(): void; + + +//// [/user/username/projects/myproject/shared/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../../a/lib/lib.es2020.d.ts","./index.ts"],"fileInfos":[{"version":"-7698705165-/// \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; }","affectsGlobalScope":true,"impliedFormat":1},{"version":"14127205977-export function fooBar() {}export function f1() { }\nexport class c { }\nexport enum e { }\n// leading\nexport function f2() { } // trailing","signature":"1966424426-export declare function fooBar(): void;\nexport declare function f1(): void;\nexport declare class c {\n}\nexport declare enum e {\n}\nexport declare function f2(): void;\n","impliedFormat":1}],"options":{"composite":true,"target":7},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2]},"version":"FakeTSVersion"} + +//// [/user/username/projects/myproject/shared/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../../a/lib/lib.es2020.d.ts", + "./index.ts" + ], + "fileInfos": { + "../../../../../a/lib/lib.es2020.d.ts": { + "version": "-7698705165-/// \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; }", + "signature": "-7698705165-/// \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; }", + "affectsGlobalScope": true, + "impliedFormat": 1 + }, + "./index.ts": { + "version": "14127205977-export function fooBar() {}export function f1() { }\nexport class c { }\nexport enum e { }\n// leading\nexport function f2() { } // trailing", + "signature": "1966424426-export declare function fooBar(): void;\nexport declare function f1(): void;\nexport declare class c {\n}\nexport declare enum e {\n}\nexport declare function f2(): void;\n", + "impliedFormat": 1 + } + }, + "options": { + "composite": true, + "target": 7 + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../../a/lib/lib.es2020.d.ts", + "./index.ts" + ] + }, + "version": "FakeTSVersion", + "size": 1037 +} + +//// [/user/username/projects/myproject/webpack/index.js] file changed its modified time +//// [/user/username/projects/myproject/webpack/index.d.ts] file changed its modified time +//// [/user/username/projects/myproject/webpack/tsconfig.tsbuildinfo] file changed its modified time From 0eac38e5ce55742bbe374bb0a239dc9d3370f8fc Mon Sep 17 00:00:00 2001 From: craigphicks <13205732+craigphicks@users.noreply.github.com> Date: Wed, 4 May 2022 19:20:55 -0700 Subject: [PATCH 4/6] On branch cph-packageJsonWatch Changes to be committed: modified: src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts modified: tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js * add test to change package.json type from coomonjs tp module => impliedNodeFormat correctly changes * add test to change package.json data only => project rebuild (not really desired, but it doesn't affect correctness) --- .../publicApiImpliedNodeFormat.ts | 36 +++ ...ers,-test-that-impliedNodeFormat-is-set.js | 211 ++++++++++++++++++ 2 files changed, 247 insertions(+) diff --git a/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts b/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts index 699e680eacdd4..d2e1e0c7f4d2c 100644 --- a/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts +++ b/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts @@ -118,6 +118,42 @@ export function f22() { } // trailing` } } }, + { + caption: "change package.json type to module", + change: sys => sys.writeFile(sharedPackageJson.path, sharedPackageJson.content.replace("commonjs","module")), + timeouts: sys => { + sys.checkTimeoutQueueLengthAndRun(1); // Shared + sys.checkTimeoutQueueLengthAndRun(1); // webpack + sys.checkTimeoutQueueLengthAndRun(1); // solution + sys.checkTimeoutQueueLength(0); + printLastImpliedNodeFormats(); + printModuleResolutionCache(builder); + if (lastImpliedNodeFormats.get("/user/username/projects/myproject/shared/index.ts")?.impliedNodeFormat!==ModuleKind.ESNext) { + throw new Error(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.ESNext`); + } + else { + sys.write(`impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.ESNext`); + } + } + }, + { + caption: "date change package.json", + change: sys => sys.writeFile(sharedPackageJson.path, sharedPackageJson.content.replace("commonjs","module")), + timeouts: sys => { + sys.checkTimeoutQueueLengthAndRun(1); // Shared + sys.checkTimeoutQueueLengthAndRun(1); // webpack + sys.checkTimeoutQueueLengthAndRun(1); // solution + sys.checkTimeoutQueueLength(0); + printLastImpliedNodeFormats(); + printModuleResolutionCache(builder); + if (lastImpliedNodeFormats.get("/user/username/projects/myproject/shared/index.ts")?.impliedNodeFormat!==ModuleKind.ESNext) { + throw new Error(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.ESNext`); + } + else { + sys.write(`impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.ESNext`); + } + } + } ], watchOrSolution: builder }); diff --git a/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js b/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js index 898aacb5b0bfd..3077e7dcc7521 100644 --- a/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js +++ b/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js @@ -414,3 +414,214 @@ export declare function f2(): void; //// [/user/username/projects/myproject/webpack/index.js] file changed its modified time //// [/user/username/projects/myproject/webpack/index.d.ts] file changed its modified time //// [/user/username/projects/myproject/webpack/tsconfig.tsbuildinfo] file changed its modified time + +Change:: change package.json type to module + +Input:: +//// [/user/username/projects/myproject/shared/package.json] +{"name":"shared","version":"1.0.0","type":"module"} + + +Output:: +>> Screen clear +[12:01:24 AM] File change detected. Starting incremental compilation... + +[12:01:25 AM] Project 'shared/tsconfig.json' is out of date because oldest output 'shared/index.js' is older than newest input 'shared/package.json' + +[12:01:26 AM] Building project '/user/username/projects/myproject/shared/tsconfig.json'... + +project=/user/username/projects/myproject/shared/tsconfig.json, file.impliedNodeFormat=ESNext[12:01:39 AM] Project 'webpack/tsconfig.json' is out of date because oldest output 'webpack/index.js' is older than newest input 'shared/package.json' + +[12:01:40 AM] Building project '/user/username/projects/myproject/webpack/tsconfig.json'... + +[12:01:42 AM] Updating unchanged output timestamps of project '/user/username/projects/myproject/webpack/tsconfig.json'... + +[12:01:43 AM] Found 0 errors. Watching for file changes. + +fileName:/user/username/projects/myproject/shared/index.ts,impliedNodeFormat:ESNext +fileName:/user/username/projects/myproject/webpack/index.ts,impliedNodeFormat:undefined +{ + "moduleResolutionCache": {} +}impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.ESNext + +Program root files: ["/user/username/projects/myproject/shared/index.ts"] +Program options: {"lib":["lib.es2020.d.ts"],"moduleResolution":3,"target":7,"composite":true,"configFilePath":"/user/username/projects/myproject/shared/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.es2020.d.ts +/user/username/projects/myproject/shared/index.ts + +Semantic diagnostics in builder refreshed for:: +/user/username/projects/myproject/shared/index.ts + +Shape signatures in builder refreshed for:: +/user/username/projects/myproject/shared/index.ts (computed .d.ts) + +Program root files: ["/user/username/projects/myproject/webpack/index.ts"] +Program options: {"composite":true,"configFilePath":"/user/username/projects/myproject/webpack/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/webpack/index.ts + +Semantic diagnostics in builder refreshed for:: + +No shapes updated in the builder:: + +WatchedFiles:: +/user/username/projects/myproject/shared/tsconfig.json: + {"fileName":"/user/username/projects/myproject/shared/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/shared/tsconfig.options.json: + {"fileName":"/user/username/projects/myproject/shared/tsconfig.options.json","pollingInterval":250} +/user/username/projects/myproject/shared/index.ts: + {"fileName":"/user/username/projects/myproject/shared/index.ts","pollingInterval":250} +/user/username/projects/myproject/shared/package.json: + {"fileName":"/user/username/projects/myproject/shared/package.json","pollingInterval":250} +/user/username/projects/myproject/webpack/tsconfig.json: + {"fileName":"/user/username/projects/myproject/webpack/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/webpack/index.ts: + {"fileName":"/user/username/projects/myproject/webpack/index.ts","pollingInterval":250} +/user/username/projects/myproject/webpack/package.json: + {"fileName":"/user/username/projects/myproject/webpack/package.json","pollingInterval":250} +/user/username/projects/myproject/tsconfig.json: + {"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/user/username/projects/myproject/shared: + {"directoryName":"/user/username/projects/myproject/shared","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} +/user/username/projects/myproject/webpack: + {"directoryName":"/user/username/projects/myproject/webpack","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/myproject/shared/index.js] file written with same contents +//// [/user/username/projects/myproject/shared/index.d.ts] file written with same contents +//// [/user/username/projects/myproject/shared/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../../a/lib/lib.es2020.d.ts","./index.ts"],"fileInfos":[{"version":"-7698705165-/// \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; }","affectsGlobalScope":true,"impliedFormat":1},{"version":"14127205977-export function fooBar() {}export function f1() { }\nexport class c { }\nexport enum e { }\n// leading\nexport function f2() { } // trailing","signature":"1966424426-export declare function fooBar(): void;\nexport declare function f1(): void;\nexport declare class c {\n}\nexport declare enum e {\n}\nexport declare function f2(): void;\n","impliedFormat":99}],"options":{"composite":true,"target":7},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2]},"version":"FakeTSVersion"} + +//// [/user/username/projects/myproject/shared/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../../a/lib/lib.es2020.d.ts", + "./index.ts" + ], + "fileInfos": { + "../../../../../a/lib/lib.es2020.d.ts": { + "version": "-7698705165-/// \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; }", + "signature": "-7698705165-/// \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; }", + "affectsGlobalScope": true, + "impliedFormat": 1 + }, + "./index.ts": { + "version": "14127205977-export function fooBar() {}export function f1() { }\nexport class c { }\nexport enum e { }\n// leading\nexport function f2() { } // trailing", + "signature": "1966424426-export declare function fooBar(): void;\nexport declare function f1(): void;\nexport declare class c {\n}\nexport declare enum e {\n}\nexport declare function f2(): void;\n", + "impliedFormat": 99 + } + }, + "options": { + "composite": true, + "target": 7 + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../../a/lib/lib.es2020.d.ts", + "./index.ts" + ] + }, + "version": "FakeTSVersion", + "size": 1038 +} + +//// [/user/username/projects/myproject/webpack/index.js] file changed its modified time +//// [/user/username/projects/myproject/webpack/index.d.ts] file changed its modified time +//// [/user/username/projects/myproject/webpack/tsconfig.tsbuildinfo] file changed its modified time + +Change:: date change package.json + +Input:: +//// [/user/username/projects/myproject/shared/package.json] file written with same contents + +Output:: +>> Screen clear +[12:01:47 AM] File change detected. Starting incremental compilation... + +[12:01:48 AM] Project 'shared/tsconfig.json' is out of date because oldest output 'shared/index.js' is older than newest input 'shared/package.json' + +[12:01:49 AM] Building project '/user/username/projects/myproject/shared/tsconfig.json'... + +[12:01:51 AM] Updating unchanged output timestamps of project '/user/username/projects/myproject/shared/tsconfig.json'... + +[12:01:52 AM] Project 'webpack/tsconfig.json' is out of date because oldest output 'webpack/index.js' is older than newest input 'shared/package.json' + +[12:01:53 AM] Building project '/user/username/projects/myproject/webpack/tsconfig.json'... + +[12:01:55 AM] Updating unchanged output timestamps of project '/user/username/projects/myproject/webpack/tsconfig.json'... + +[12:01:56 AM] Found 0 errors. Watching for file changes. + +fileName:/user/username/projects/myproject/shared/index.ts,impliedNodeFormat:ESNext +fileName:/user/username/projects/myproject/webpack/index.ts,impliedNodeFormat:undefined +{ + "moduleResolutionCache": {} +}impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.ESNext + +Program root files: ["/user/username/projects/myproject/shared/index.ts"] +Program options: {"lib":["lib.es2020.d.ts"],"moduleResolution":3,"target":7,"composite":true,"configFilePath":"/user/username/projects/myproject/shared/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.es2020.d.ts +/user/username/projects/myproject/shared/index.ts + +Semantic diagnostics in builder refreshed for:: + +No shapes updated in the builder:: + +Program root files: ["/user/username/projects/myproject/webpack/index.ts"] +Program options: {"composite":true,"configFilePath":"/user/username/projects/myproject/webpack/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/webpack/index.ts + +Semantic diagnostics in builder refreshed for:: + +No shapes updated in the builder:: + +WatchedFiles:: +/user/username/projects/myproject/shared/tsconfig.json: + {"fileName":"/user/username/projects/myproject/shared/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/shared/tsconfig.options.json: + {"fileName":"/user/username/projects/myproject/shared/tsconfig.options.json","pollingInterval":250} +/user/username/projects/myproject/shared/index.ts: + {"fileName":"/user/username/projects/myproject/shared/index.ts","pollingInterval":250} +/user/username/projects/myproject/shared/package.json: + {"fileName":"/user/username/projects/myproject/shared/package.json","pollingInterval":250} +/user/username/projects/myproject/webpack/tsconfig.json: + {"fileName":"/user/username/projects/myproject/webpack/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/webpack/index.ts: + {"fileName":"/user/username/projects/myproject/webpack/index.ts","pollingInterval":250} +/user/username/projects/myproject/webpack/package.json: + {"fileName":"/user/username/projects/myproject/webpack/package.json","pollingInterval":250} +/user/username/projects/myproject/tsconfig.json: + {"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/user/username/projects/myproject/shared: + {"directoryName":"/user/username/projects/myproject/shared","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} +/user/username/projects/myproject/webpack: + {"directoryName":"/user/username/projects/myproject/webpack","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/myproject/shared/index.js] file changed its modified time +//// [/user/username/projects/myproject/shared/index.d.ts] file changed its modified time +//// [/user/username/projects/myproject/shared/tsconfig.tsbuildinfo] file changed its modified time +//// [/user/username/projects/myproject/webpack/index.js] file changed its modified time +//// [/user/username/projects/myproject/webpack/index.d.ts] file changed its modified time +//// [/user/username/projects/myproject/webpack/tsconfig.tsbuildinfo] file changed its modified time From 7fe3b7cffb6ccc1d79a9a413c8d8f26af0396299 Mon Sep 17 00:00:00 2001 From: craigphicks <13205732+craigphicks@users.noreply.github.com> Date: Thu, 5 May 2022 17:03:49 -0700 Subject: [PATCH 5/6] On branch cph-packageJsonWatch Changes to be committed: modified: src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts modified: tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js * adding tests for other combinations of module and moduleResolution | module | moduleResolution | uses package.json:type | |-- |-- |-- | | unset | "node12" | true | | "node12" | unset | true | | "node12" | "node" | false | --- .../publicApiImpliedNodeFormat.ts | 74 ++++- ...ers,-test-that-impliedNodeFormat-is-set.js | 269 +++++++++++++++++- 2 files changed, 324 insertions(+), 19 deletions(-) diff --git a/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts b/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts index d2e1e0c7f4d2c..53f1809f0f4ed 100644 --- a/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts +++ b/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts @@ -80,15 +80,23 @@ export function f22() { } // trailing` sys.write(`fileName:${fileName},impliedNodeFormat:${impliedNodeFormatToString(x.impliedNodeFormat)}`+sys.newLine); }); } - - function printModuleResolutionCache(buildr: SolutionBuilder){ - const x = { moduleResolutionCache: buildr.getModuleResolutionCache() }; - sys.write(JSON.stringify(x,undefined,2)); - } - + // function printModuleResolutionCache(buildr: SolutionBuilder){ + // const x = { moduleResolutionCache: buildr.getModuleResolutionCache() }; + // sys.write(JSON.stringify(x,undefined,2)); + // } const buildHost = createSolutionBuilderWithWatchHostForBaseline(sys, cb); buildHost.getCustomTransformers = getCustomTransformers; const builder = createSolutionBuilderWithWatch(buildHost, [solution.path], { verbose: true }); + const compilerOptions: { + lib: ["es2020"], + target: "es2020" + moduleResolution?: "Node12" | "NodeNext", // absolutely needed + module?: "Node12" | "NodeNext" + }={ + lib: ["es2020"], + moduleResolution: "Node12", + target: "es2020", + }; builder.build(); runWatchBaseline({ @@ -109,7 +117,6 @@ export function f22() { } // trailing` sys.checkTimeoutQueueLengthAndRun(1); // solution sys.checkTimeoutQueueLength(0); printLastImpliedNodeFormats(); - printModuleResolutionCache(builder); if (lastImpliedNodeFormats.get("/user/username/projects/myproject/shared/index.ts")?.impliedNodeFormat!==ModuleKind.CommonJS) { throw new Error(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.CommonJS`); } @@ -127,7 +134,6 @@ export function f22() { } // trailing` sys.checkTimeoutQueueLengthAndRun(1); // solution sys.checkTimeoutQueueLength(0); printLastImpliedNodeFormats(); - printModuleResolutionCache(builder); if (lastImpliedNodeFormats.get("/user/username/projects/myproject/shared/index.ts")?.impliedNodeFormat!==ModuleKind.ESNext) { throw new Error(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.ESNext`); } @@ -138,14 +144,38 @@ export function f22() { } // trailing` }, { caption: "date change package.json", - change: sys => sys.writeFile(sharedPackageJson.path, sharedPackageJson.content.replace("commonjs","module")), + change: sys => { + sys.writeFile(sharedPackageJson.path, sharedPackageJson.content.replace("commonjs","module")); + }, + timeouts: sys => { + sys.checkTimeoutQueueLengthAndRun(1); // Shared + sys.checkTimeoutQueueLengthAndRun(1); // webpack + sys.checkTimeoutQueueLengthAndRun(1); // solution + sys.checkTimeoutQueueLength(0); + printLastImpliedNodeFormats(); + if (lastImpliedNodeFormats.get("/user/username/projects/myproject/shared/index.ts")?.impliedNodeFormat!==ModuleKind.ESNext) { + throw new Error(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.ESNext`); + } + else { + sys.write(`impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.ESNext`); + } + } + }, + { + caption: "tsconfig compilerOptions -> module:node12, moduleResolution omitted", + change: sys => { + const co: Partial= { ...compilerOptions }; + delete co.moduleResolution; + co.module = "Node12"; + const tsconfig = { compilerOptions:co }; + sys.writeFile(sharedConfigOptions.path, JSON.stringify(tsconfig)); + }, timeouts: sys => { sys.checkTimeoutQueueLengthAndRun(1); // Shared sys.checkTimeoutQueueLengthAndRun(1); // webpack sys.checkTimeoutQueueLengthAndRun(1); // solution sys.checkTimeoutQueueLength(0); printLastImpliedNodeFormats(); - printModuleResolutionCache(builder); if (lastImpliedNodeFormats.get("/user/username/projects/myproject/shared/index.ts")?.impliedNodeFormat!==ModuleKind.ESNext) { throw new Error(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts to be ModuleKind.ESNext`); } @@ -153,6 +183,30 @@ export function f22() { } // trailing` sys.write(`impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.ESNext`); } } + }, + { + caption: "tsconfig compilerOptions -> module:node12, moduleResolution: node", + change: sys => { + const co: Partial= { ...compilerOptions }; + delete co.moduleResolution; + co.module = "Node12"; + (co.moduleResolution as any) = "Node"; + const tsconfig = { compilerOptions:co }; + sys.writeFile(sharedConfigOptions.path, JSON.stringify(tsconfig)); + }, + timeouts: sys => { + sys.checkTimeoutQueueLengthAndRun(1); // Shared + sys.checkTimeoutQueueLengthAndRun(1); // webpack + sys.checkTimeoutQueueLengthAndRun(1); // solution + sys.checkTimeoutQueueLength(0); + printLastImpliedNodeFormats(); + if (lastImpliedNodeFormats.get("/user/username/projects/myproject/shared/index.ts")?.impliedNodeFormat!==undefined) { + throw new Error(`Expecting impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is not undefined`); + } + else { + sys.write(`impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is undefined, as expected`); + } + } } ], watchOrSolution: builder diff --git a/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js b/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js index 3077e7dcc7521..e9c94605e4f01 100644 --- a/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js +++ b/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js @@ -291,9 +291,7 @@ project=/user/username/projects/myproject/shared/tsconfig.json, file.impliedNode fileName:/user/username/projects/myproject/shared/index.ts,impliedNodeFormat:CommonJS fileName:/user/username/projects/myproject/webpack/index.ts,impliedNodeFormat:undefined -{ - "moduleResolutionCache": {} -}impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.CommonJS +impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.CommonJS Program root files: ["/user/username/projects/myproject/shared/index.ts"] Program options: {"lib":["lib.es2020.d.ts"],"moduleResolution":3,"target":7,"composite":true,"configFilePath":"/user/username/projects/myproject/shared/tsconfig.json"} @@ -440,9 +438,7 @@ project=/user/username/projects/myproject/shared/tsconfig.json, file.impliedNode fileName:/user/username/projects/myproject/shared/index.ts,impliedNodeFormat:ESNext fileName:/user/username/projects/myproject/webpack/index.ts,impliedNodeFormat:undefined -{ - "moduleResolutionCache": {} -}impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.ESNext +impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.ESNext Program root files: ["/user/username/projects/myproject/shared/index.ts"] Program options: {"lib":["lib.es2020.d.ts"],"moduleResolution":3,"target":7,"composite":true,"configFilePath":"/user/username/projects/myproject/shared/tsconfig.json"} @@ -565,9 +561,7 @@ Output:: fileName:/user/username/projects/myproject/shared/index.ts,impliedNodeFormat:ESNext fileName:/user/username/projects/myproject/webpack/index.ts,impliedNodeFormat:undefined -{ - "moduleResolutionCache": {} -}impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.ESNext +impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.ESNext Program root files: ["/user/username/projects/myproject/shared/index.ts"] Program options: {"lib":["lib.es2020.d.ts"],"moduleResolution":3,"target":7,"composite":true,"configFilePath":"/user/username/projects/myproject/shared/tsconfig.json"} @@ -625,3 +619,260 @@ exitCode:: ExitStatus.undefined //// [/user/username/projects/myproject/webpack/index.js] file changed its modified time //// [/user/username/projects/myproject/webpack/index.d.ts] file changed its modified time //// [/user/username/projects/myproject/webpack/tsconfig.tsbuildinfo] file changed its modified time + +Change:: tsconfig compilerOptions -> module:node12, moduleResolution omitted + +Input:: +//// [/user/username/projects/myproject/shared/tsconfig.options.json] +{"compilerOptions":{"lib":["es2020"],"target":"es2020","module":"Node12"}} + + +Output:: +>> Screen clear +[12:02:00 AM] File change detected. Starting incremental compilation... + +[12:02:01 AM] Project 'shared/tsconfig.json' is out of date because oldest output 'shared/index.js' is older than newest input 'shared/tsconfig.options.json' + +[12:02:02 AM] Building project '/user/username/projects/myproject/shared/tsconfig.json'... + +project=/user/username/projects/myproject/shared/tsconfig.json, file.impliedNodeFormat=ESNext[12:02:15 AM] Project 'webpack/tsconfig.json' is up to date with .d.ts files from its dependencies + +[12:02:17 AM] Updating output timestamps of project '/user/username/projects/myproject/webpack/tsconfig.json'... + +[12:02:18 AM] Found 0 errors. Watching for file changes. + +fileName:/user/username/projects/myproject/shared/index.ts,impliedNodeFormat:ESNext +fileName:/user/username/projects/myproject/webpack/index.ts,impliedNodeFormat:undefined +impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is correctly ModuleKind.ESNext + +Program root files: ["/user/username/projects/myproject/shared/index.ts"] +Program options: {"lib":["lib.es2020.d.ts"],"target":7,"module":100,"composite":true,"configFilePath":"/user/username/projects/myproject/shared/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.es2020.d.ts +/user/username/projects/myproject/shared/index.ts + +Semantic diagnostics in builder refreshed for:: + +No shapes updated in the builder:: + +WatchedFiles:: +/user/username/projects/myproject/shared/tsconfig.json: + {"fileName":"/user/username/projects/myproject/shared/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/shared/tsconfig.options.json: + {"fileName":"/user/username/projects/myproject/shared/tsconfig.options.json","pollingInterval":250} +/user/username/projects/myproject/shared/index.ts: + {"fileName":"/user/username/projects/myproject/shared/index.ts","pollingInterval":250} +/user/username/projects/myproject/shared/package.json: + {"fileName":"/user/username/projects/myproject/shared/package.json","pollingInterval":250} +/user/username/projects/myproject/webpack/tsconfig.json: + {"fileName":"/user/username/projects/myproject/webpack/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/webpack/index.ts: + {"fileName":"/user/username/projects/myproject/webpack/index.ts","pollingInterval":250} +/user/username/projects/myproject/webpack/package.json: + {"fileName":"/user/username/projects/myproject/webpack/package.json","pollingInterval":250} +/user/username/projects/myproject/tsconfig.json: + {"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/user/username/projects/myproject/shared: + {"directoryName":"/user/username/projects/myproject/shared","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} +/user/username/projects/myproject/webpack: + {"directoryName":"/user/username/projects/myproject/webpack","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/myproject/shared/index.js] +/*@before/user/username/projects/myproject/shared/tsconfig.json*/ +export function fooBar() { } +/*@before/user/username/projects/myproject/shared/tsconfig.json*/ +export function f1() { } +export class c { +} +//@after/user/username/projects/myproject/shared/tsconfig.json +export var e; +(function (e) { +})(e = e || (e = {})); +// leading +/*@before/user/username/projects/myproject/shared/tsconfig.json*/ +export function f2() { } // trailing + + +//// [/user/username/projects/myproject/shared/index.d.ts] file written with same contents +//// [/user/username/projects/myproject/shared/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../../a/lib/lib.es2020.d.ts","./index.ts"],"fileInfos":[{"version":"-7698705165-/// \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; }","affectsGlobalScope":true,"impliedFormat":1},{"version":"14127205977-export function fooBar() {}export function f1() { }\nexport class c { }\nexport enum e { }\n// leading\nexport function f2() { } // trailing","signature":"1966424426-export declare function fooBar(): void;\nexport declare function f1(): void;\nexport declare class c {\n}\nexport declare enum e {\n}\nexport declare function f2(): void;\n","impliedFormat":99}],"options":{"composite":true,"module":100,"target":7},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2]},"version":"FakeTSVersion"} + +//// [/user/username/projects/myproject/shared/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../../a/lib/lib.es2020.d.ts", + "./index.ts" + ], + "fileInfos": { + "../../../../../a/lib/lib.es2020.d.ts": { + "version": "-7698705165-/// \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; }", + "signature": "-7698705165-/// \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; }", + "affectsGlobalScope": true, + "impliedFormat": 1 + }, + "./index.ts": { + "version": "14127205977-export function fooBar() {}export function f1() { }\nexport class c { }\nexport enum e { }\n// leading\nexport function f2() { } // trailing", + "signature": "1966424426-export declare function fooBar(): void;\nexport declare function f1(): void;\nexport declare class c {\n}\nexport declare enum e {\n}\nexport declare function f2(): void;\n", + "impliedFormat": 99 + } + }, + "options": { + "composite": true, + "module": 100, + "target": 7 + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../../a/lib/lib.es2020.d.ts", + "./index.ts" + ] + }, + "version": "FakeTSVersion", + "size": 1051 +} + +//// [/user/username/projects/myproject/webpack/index.js] file changed its modified time +//// [/user/username/projects/myproject/webpack/index.d.ts] file changed its modified time +//// [/user/username/projects/myproject/webpack/tsconfig.tsbuildinfo] file changed its modified time + +Change:: tsconfig compilerOptions -> module:node12, moduleResolution: node + +Input:: +//// [/user/username/projects/myproject/shared/tsconfig.options.json] +{"compilerOptions":{"lib":["es2020"],"target":"es2020","module":"Node12","moduleResolution":"Node"}} + + +Output:: +>> Screen clear +[12:02:22 AM] File change detected. Starting incremental compilation... + +[12:02:23 AM] Project 'shared/tsconfig.json' is out of date because oldest output 'shared/index.js' is older than newest input 'shared/tsconfig.options.json' + +[12:02:24 AM] Building project '/user/username/projects/myproject/shared/tsconfig.json'... + +project=/user/username/projects/myproject/shared/tsconfig.json, file.impliedNodeFormat=undefined[12:02:37 AM] Project 'webpack/tsconfig.json' is up to date with .d.ts files from its dependencies + +[12:02:39 AM] Updating output timestamps of project '/user/username/projects/myproject/webpack/tsconfig.json'... + +[12:02:40 AM] Found 0 errors. Watching for file changes. + +fileName:/user/username/projects/myproject/shared/index.ts,impliedNodeFormat:undefined +fileName:/user/username/projects/myproject/webpack/index.ts,impliedNodeFormat:undefined +impliedNodeFormat for /user/username/projects/myproject/shared/index.ts is undefined, as expected + +Program root files: ["/user/username/projects/myproject/shared/index.ts"] +Program options: {"lib":["lib.es2020.d.ts"],"target":7,"module":100,"moduleResolution":2,"composite":true,"configFilePath":"/user/username/projects/myproject/shared/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.es2020.d.ts +/user/username/projects/myproject/shared/index.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.es2020.d.ts +/user/username/projects/myproject/shared/index.ts + +Shape signatures in builder refreshed for:: +/a/lib/lib.es2020.d.ts (used version) +/user/username/projects/myproject/shared/index.ts (computed .d.ts) + +WatchedFiles:: +/user/username/projects/myproject/shared/tsconfig.json: + {"fileName":"/user/username/projects/myproject/shared/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/shared/tsconfig.options.json: + {"fileName":"/user/username/projects/myproject/shared/tsconfig.options.json","pollingInterval":250} +/user/username/projects/myproject/shared/index.ts: + {"fileName":"/user/username/projects/myproject/shared/index.ts","pollingInterval":250} +/user/username/projects/myproject/shared/package.json: + {"fileName":"/user/username/projects/myproject/shared/package.json","pollingInterval":250} +/user/username/projects/myproject/webpack/tsconfig.json: + {"fileName":"/user/username/projects/myproject/webpack/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/webpack/index.ts: + {"fileName":"/user/username/projects/myproject/webpack/index.ts","pollingInterval":250} +/user/username/projects/myproject/webpack/package.json: + {"fileName":"/user/username/projects/myproject/webpack/package.json","pollingInterval":250} +/user/username/projects/myproject/tsconfig.json: + {"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/user/username/projects/myproject/shared: + {"directoryName":"/user/username/projects/myproject/shared","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} +/user/username/projects/myproject/webpack: + {"directoryName":"/user/username/projects/myproject/webpack","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/myproject/shared/index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.f2 = exports.e = exports.c = exports.f1 = exports.fooBar = void 0; +/*@before/user/username/projects/myproject/shared/tsconfig.json*/ +function fooBar() { } +exports.fooBar = fooBar; +/*@before/user/username/projects/myproject/shared/tsconfig.json*/ +function f1() { } +exports.f1 = f1; +class c { +} +exports.c = c; +//@after/user/username/projects/myproject/shared/tsconfig.json +var e; +(function (e) { +})(e = exports.e || (exports.e = {})); +// leading +/*@before/user/username/projects/myproject/shared/tsconfig.json*/ +function f2() { } // trailing +exports.f2 = f2; + + +//// [/user/username/projects/myproject/shared/index.d.ts] file written with same contents +//// [/user/username/projects/myproject/shared/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../../a/lib/lib.es2020.d.ts","./index.ts"],"fileInfos":[{"version":"-7698705165-/// \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; }","affectsGlobalScope":true},{"version":"14127205977-export function fooBar() {}export function f1() { }\nexport class c { }\nexport enum e { }\n// leading\nexport function f2() { } // trailing","signature":"1966424426-export declare function fooBar(): void;\nexport declare function f1(): void;\nexport declare class c {\n}\nexport declare enum e {\n}\nexport declare function f2(): void;\n"}],"options":{"composite":true,"module":100,"target":7},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2]},"version":"FakeTSVersion"} + +//// [/user/username/projects/myproject/shared/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../../a/lib/lib.es2020.d.ts", + "./index.ts" + ], + "fileInfos": { + "../../../../../a/lib/lib.es2020.d.ts": { + "version": "-7698705165-/// \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; }", + "signature": "-7698705165-/// \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; }", + "affectsGlobalScope": true + }, + "./index.ts": { + "version": "14127205977-export function fooBar() {}export function f1() { }\nexport class c { }\nexport enum e { }\n// leading\nexport function f2() { } // trailing", + "signature": "1966424426-export declare function fooBar(): void;\nexport declare function f1(): void;\nexport declare class c {\n}\nexport declare enum e {\n}\nexport declare function f2(): void;\n" + } + }, + "options": { + "composite": true, + "module": 100, + "target": 7 + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../../a/lib/lib.es2020.d.ts", + "./index.ts" + ] + }, + "version": "FakeTSVersion", + "size": 1014 +} + +//// [/user/username/projects/myproject/webpack/index.js] file changed its modified time +//// [/user/username/projects/myproject/webpack/index.d.ts] file changed its modified time +//// [/user/username/projects/myproject/webpack/tsconfig.tsbuildinfo] file changed its modified time From 28136ed12fc71a84230ff9e4c8bb3bfc3b8d1916 Mon Sep 17 00:00:00 2001 From: craigphicks <13205732+craigphicks@users.noreply.github.com> Date: Fri, 13 May 2022 12:12:39 -0700 Subject: [PATCH 6/6] On branch cph-packageJsonWatch Changes to be committed: modified: src/compiler/tsbuildPublic.ts The public accessor for getModuleResolutionCache is removed modified: src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts Baseline description simplified, resulting in more legible naming of the baseline renamed: tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js -> tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers-impliedNodeFormat.js --- src/compiler/tsbuildPublic.ts | 2 -- .../unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts | 8 ++------ ...t.js => with-custom-transformers-impliedNodeFormat.js} | 0 3 files changed, 2 insertions(+), 8 deletions(-) rename tests/baselines/reference/tsbuildWatch/publicApi/{with-custom-transformers,-test-that-impliedNodeFormat-is-set.js => with-custom-transformers-impliedNodeFormat.js} (100%) diff --git a/src/compiler/tsbuildPublic.ts b/src/compiler/tsbuildPublic.ts index d38dca3793169..5b17f2f4d902d 100644 --- a/src/compiler/tsbuildPublic.ts +++ b/src/compiler/tsbuildPublic.ts @@ -148,7 +148,6 @@ namespace ts { /*@internal*/ buildNextInvalidatedProject(): void; /*@internal*/ getAllParsedConfigs(): readonly ParsedCommandLine[]; /*@internal*/ close(): void; - /*@internal*/ getModuleResolutionCache(): ModuleResolutionCache | undefined; } /** @@ -1993,7 +1992,6 @@ namespace ts { config => isParsedCommandLine(config) ? config : undefined )), close: () => stopWatching(state), - getModuleResolutionCache: ()=> state.moduleResolutionCache, }; } diff --git a/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts b/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts index 53f1809f0f4ed..d653c77ad6139 100644 --- a/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts +++ b/src/testRunner/unittests/tsbuildWatch/publicApiImpliedNodeFormat.ts @@ -1,5 +1,5 @@ namespace ts.tscWatch { - it("unittests:: tsbuildWatch:: watchMode:: Public API with custom transformers / PublicAPI-impliedNodeFormat", () => { + it("unittests:: tsbuildWatch:: watchMode:: Public API with custom transformers impliedNodeFormat", () => { const solution: File = { path: `${projectRoot}/tsconfig.json`, content: JSON.stringify({ @@ -80,10 +80,6 @@ export function f22() { } // trailing` sys.write(`fileName:${fileName},impliedNodeFormat:${impliedNodeFormatToString(x.impliedNodeFormat)}`+sys.newLine); }); } - // function printModuleResolutionCache(buildr: SolutionBuilder){ - // const x = { moduleResolutionCache: buildr.getModuleResolutionCache() }; - // sys.write(JSON.stringify(x,undefined,2)); - // } const buildHost = createSolutionBuilderWithWatchHostForBaseline(sys, cb); buildHost.getCustomTransformers = getCustomTransformers; const builder = createSolutionBuilderWithWatch(buildHost, [solution.path], { verbose: true }); @@ -101,7 +97,7 @@ export function f22() { } // trailing` builder.build(); runWatchBaseline({ scenario: "publicApi", - subScenario: "with custom transformers, test that impliedNodeFormat is set", + subScenario: "with custom transformers impliedNodeFormat", commandLineArgs, sys, baseline, diff --git a/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js b/tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers-impliedNodeFormat.js similarity index 100% rename from tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers,-test-that-impliedNodeFormat-is-set.js rename to tests/baselines/reference/tsbuildWatch/publicApi/with-custom-transformers-impliedNodeFormat.js