From 3a9c95136d8315fd8d37276887c7230e194ae0a2 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Tue, 31 May 2022 17:57:11 -0400 Subject: [PATCH] fix: don't attempt to change declarationMap sources when no output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - when using rpt2 as a configPlugin, there is no Rollup `output`, so it will be `undefined` - when `declarationMap: true` in `tsconfig`, this block of code is called as a workaround due to the placeholder dir we must use for output -- but, in this case, it errors out, since the `declarationDir` is `undefined` - `path.relative` needs a `string` as a arg, not `undefined` - so skip this transformation entirely when there's no `output`, as it doesn't need to be done in that case anyway - this transformation code happens to have been written by me 2 years ago too, so I had fixed one bug with that but created a different bug 😅 (fortunately one that only I have stumbled upon) --- src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 686374a3..37fb5183 100644 --- a/src/index.ts +++ b/src/index.ts @@ -337,12 +337,12 @@ const typescript: PluginImpl = (options) => // don't mutate the entry because generateBundle gets called multiple times let entryText = entry.text - const declarationDir = (_output.file ? dirname(_output.file) : _output.dir) as string; const cachePlaceholder = `${pluginOptions.cacheRoot}/placeholder` - // modify declaration map sources to correct relative path - if (extension === ".d.ts.map") + // modify declaration map sources to correct relative path (only if outputting) + if (extension === ".d.ts.map" && (_output?.file || _output?.dir)) { + const declarationDir = (_output.file ? dirname(_output.file) : _output.dir) as string; const parsedText = JSON.parse(entryText) as SourceMap; // invert back to absolute, then make relative to declarationDir parsedText.sources = parsedText.sources.map(source =>