From 902fb3d3408c2ad5ac944d3d6fa5ea24ee0ee384 Mon Sep 17 00:00:00 2001 From: Ian Yong Date: Mon, 25 Sep 2023 22:41:09 +0800 Subject: [PATCH 1/3] fix(typescript): fix sourcemap sourcecontent referencing non-existent files (#1571) * test(typescript): add test case for incorrect `sourceContent` * fix(typescript): fix .js.map files being treated as declarations --- packages/typescript/src/index.ts | 8 ++++---- packages/typescript/src/outputFile.ts | 7 +++++++ packages/typescript/test/test.js | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/typescript/src/index.ts b/packages/typescript/src/index.ts index 293e341d9..bea3e736d 100644 --- a/packages/typescript/src/index.ts +++ b/packages/typescript/src/index.ts @@ -17,7 +17,7 @@ import findTypescriptOutput, { normalizePath, emitFile, isDeclarationOutputFile, - isMapOutputFile + isTypeScriptMapOutputFile } from './outputFile'; import { preflight } from './preflight'; import createWatchProgram, { WatchProgramHelper } from './watchProgram'; @@ -156,11 +156,11 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi }, async generateBundle(outputOptions) { - const declarationAndMapFiles = [...emittedFiles.keys()].filter( - (fileName) => isDeclarationOutputFile(fileName) || isMapOutputFile(fileName) + const declarationAndTypeScriptMapFiles = [...emittedFiles.keys()].filter( + (fileName) => isDeclarationOutputFile(fileName) || isTypeScriptMapOutputFile(fileName) ); - declarationAndMapFiles.forEach((id) => { + declarationAndTypeScriptMapFiles.forEach((id) => { const code = getEmittedFile(id, emittedFiles, tsCache); if (!code || !parsedOptions.options.declaration) { return; diff --git a/packages/typescript/src/outputFile.ts b/packages/typescript/src/outputFile.ts index 4dc0de04d..d7b080ab1 100644 --- a/packages/typescript/src/outputFile.ts +++ b/packages/typescript/src/outputFile.ts @@ -24,6 +24,13 @@ export function isCodeOutputFile(name: string): boolean { * Checks if the given OutputFile represents some source map */ export function isMapOutputFile(name: string): boolean { + return name.endsWith('.map'); +} + +/** + * Checks if the given OutputFile represents some TypeScript source map + */ +export function isTypeScriptMapOutputFile(name: string): boolean { return name.endsWith('ts.map'); } diff --git a/packages/typescript/test/test.js b/packages/typescript/test/test.js index 27cb33a10..e746680c1 100644 --- a/packages/typescript/test/test.js +++ b/packages/typescript/test/test.js @@ -612,6 +612,24 @@ test.serial('should not emit null sourceContent', async (t) => { t.false(sourcemap.sourcesContent.includes(undefined)); }); +test.serial('should not emit sourceContent that references a non-existent file', async (t) => { + const bundle = await rollup({ + input: 'fixtures/basic/main.ts', + output: { + sourcemap: true + }, + plugins: [ + typescript({ + tsconfig: 'fixtures/basic/tsconfig.json' + }) + ], + onwarn + }); + const output = await getCode(bundle, { format: 'es', sourcemap: true }, true); + const sourcemap = output[0].map; + t.false(sourcemap.sourcesContent.includes('//# sourceMappingURL=main.js.map')); +}); + test.serial('should not fail if source maps are off', async (t) => { await t.notThrowsAsync( rollup({ From 2e9d5d35651dd5d3f57a209cc107f713a0a71a6c Mon Sep 17 00:00:00 2001 From: chika3742 Date: Sat, 9 Sep 2023 16:23:39 +0900 Subject: [PATCH 2/3] fix(dsv): type of processRow --- packages/dsv/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dsv/types/index.d.ts b/packages/dsv/types/index.d.ts index f923829cd..e1031295a 100644 --- a/packages/dsv/types/index.d.ts +++ b/packages/dsv/types/index.d.ts @@ -20,7 +20,7 @@ interface RollupDsvOptions { * The function can either manipulate the passed row, or return an entirely new row object. * @default undefined */ - processRow?: null | ((row: DSVRowString, id: string) => DSVRowString | undefined); + processRow?: null | ((row: DSVRowString, id: string) => object | void); } /** From 4d50f834901eb37d0f645a0956b5f3ceb694905e Mon Sep 17 00:00:00 2001 From: chika3742 Date: Sat, 9 Sep 2023 16:42:26 +0900 Subject: [PATCH 3/3] test(dsv): update test for processRow types --- packages/dsv/test/types.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/dsv/test/types.ts b/packages/dsv/test/types.ts index f48fb7319..54528eef5 100644 --- a/packages/dsv/test/types.ts +++ b/packages/dsv/test/types.ts @@ -13,7 +13,17 @@ const config: RollupOptions = { include: 'node_modules/**', exclude: ['node_modules/foo/**', 'node_modules/bar/**'], processRow(row) { - return row; + return { + foo: +row.foo, + bar: new Date(row.bar), + baz: row.baz === 'true', + ...row + }; + } + }), + dsv({ + processRow() { + // void } }) ]