From d60cf8c005a8368acc7d386eac90292649f563e1 Mon Sep 17 00:00:00 2001 From: Ian Yong Date: Tue, 29 Aug 2023 23:19:08 +0800 Subject: [PATCH] fix(typescript): fix .js.map files being treated as declarations --- packages/typescript/src/index.ts | 8 ++++---- packages/typescript/src/outputFile.ts | 7 +++++++ 2 files changed, 11 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'); }