From f51b93e571ac8fa52d0bc1df4e7fb263097242e5 Mon Sep 17 00:00:00 2001 From: Glenn <33450392+glenn2223@users.noreply.github.com> Date: Thu, 15 Dec 2022 11:13:14 +0000 Subject: [PATCH 1/3] Applied fix The `id` passed to `async load(id)` has certain edge cases when drives letters can de different cases or file**names** can have different cases. By normalising the `emittedFiles` we will always find the `code` we need and, as such, will not throw --- packages/typescript/src/index.ts | 4 ++-- packages/typescript/src/outputFile.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/typescript/src/index.ts b/packages/typescript/src/index.ts index 1cb79dbda..9dab51acf 100644 --- a/packages/typescript/src/index.ts +++ b/packages/typescript/src/index.ts @@ -69,7 +69,7 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi if (parsedOptions.options.composite || parsedOptions.options.incremental) { tsCache.cacheCode(fileName, data); } - emittedFiles.set(fileName, data); + emittedFiles.set(fileName.toLowerCase(), data); }, status(diagnostic) { watchProgramHelper.handleStatus(diagnostic); @@ -143,7 +143,7 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi parsedOptions.fileNames.push(fileName); } - const output = findTypescriptOutput(ts, parsedOptions, id, emittedFiles, tsCache); + const output = findTypescriptOutput(ts, parsedOptions, fileName, emittedFiles, tsCache); return output.code != null ? (output as SourceDescription) : null; }, diff --git a/packages/typescript/src/outputFile.ts b/packages/typescript/src/outputFile.ts index e2ff67220..05346b955 100644 --- a/packages/typescript/src/outputFile.ts +++ b/packages/typescript/src/outputFile.ts @@ -41,8 +41,8 @@ export function getEmittedFile( ): string | undefined { let code: string | undefined; if (fileName) { - if (emittedFiles.has(fileName)) { - code = emittedFiles.get(fileName); + if (emittedFiles.has(fileName.toLowerCase())) { + code = emittedFiles.get(fileName.toLowerCase()); } else { code = tsCache.getCached(fileName); } From a7d7658ecf59d4a719896ef1aa89d3c08196f482 Mon Sep 17 00:00:00 2001 From: Glenn <33450392+glenn2223@users.noreply.github.com> Date: Thu, 15 Dec 2022 12:13:27 +0000 Subject: [PATCH 2/3] Added case test It's such an edge case and I don't know the reason/case in order to force it --- .../typescript/test/fixtures/caseTest/Main.ts | 3 +++ .../test/fixtures/caseTest/tsconfig.json | 1 + packages/typescript/test/test.js | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 packages/typescript/test/fixtures/caseTest/Main.ts create mode 100644 packages/typescript/test/fixtures/caseTest/tsconfig.json diff --git a/packages/typescript/test/fixtures/caseTest/Main.ts b/packages/typescript/test/fixtures/caseTest/Main.ts new file mode 100644 index 000000000..ccf559ebb --- /dev/null +++ b/packages/typescript/test/fixtures/caseTest/Main.ts @@ -0,0 +1,3 @@ +const answer = 42; +// eslint-disable-next-line no-console +console.log(`the answer is ${answer}`); diff --git a/packages/typescript/test/fixtures/caseTest/tsconfig.json b/packages/typescript/test/fixtures/caseTest/tsconfig.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/packages/typescript/test/fixtures/caseTest/tsconfig.json @@ -0,0 +1 @@ +{} diff --git a/packages/typescript/test/test.js b/packages/typescript/test/test.js index ecf5b0597..f6810d55b 100644 --- a/packages/typescript/test/test.js +++ b/packages/typescript/test/test.js @@ -1346,3 +1346,27 @@ test.serial('noForceEmit option defers to tsconfig.json for noEmit', async (t) = const originalCode = fs.readFileSync(path.join(__dirname, input), 'utf8'); t.is(output[0].code, originalCode); }); + +test.serial('incorrect file case still compiles', async (t) => { + const warnings = []; + const bundle = await rollup({ + input: 'fixtures/caseTest/Main.ts', + plugins: [typescript({ tsconfig: 'fixtures/caseTest/tsconfig.json', target: 'es5' })], + onwarn(warning) { + warnings.push(warning); + } + }); + // generate a single output bundle, in which case, declaration files were not correctly emitted + const output = await getCode( + bundle, + { format: 'es', file: 'fixtures/caseTest/dist/Main.js' }, + true + ); + + t.deepEqual( + output.map((out) => out.fileName), + // no `main.d.ts`, main.js is passed through + ['Main.js'] + ); + t.is(warnings.length, 0); +}); From b9cd33cd6978f0e4c13b799623698570d15e49fa Mon Sep 17 00:00:00 2001 From: Glenn <33450392+glenn2223@users.noreply.github.com> Date: Mon, 19 Dec 2022 12:12:28 +0000 Subject: [PATCH 3/3] Switch back to `id` Accidentally left in a code tweak from earlier tests - reverted --- packages/typescript/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typescript/src/index.ts b/packages/typescript/src/index.ts index 9dab51acf..d1c234ded 100644 --- a/packages/typescript/src/index.ts +++ b/packages/typescript/src/index.ts @@ -143,7 +143,7 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi parsedOptions.fileNames.push(fileName); } - const output = findTypescriptOutput(ts, parsedOptions, fileName, emittedFiles, tsCache); + const output = findTypescriptOutput(ts, parsedOptions, id, emittedFiles, tsCache); return output.code != null ? (output as SourceDescription) : null; },