Skip to content

Commit ccd6815

Browse files
authored
fix: don't attempt to change declarationMap sources when no output (#334)
- 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)
1 parent 4310873 commit ccd6815

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,12 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
337337

338338
// don't mutate the entry because generateBundle gets called multiple times
339339
let entryText = entry.text
340-
const declarationDir = (_output.file ? dirname(_output.file) : _output.dir) as string;
341340
const cachePlaceholder = `${pluginOptions.cacheRoot}/placeholder`
342341

343-
// modify declaration map sources to correct relative path
344-
if (extension === ".d.ts.map")
342+
// modify declaration map sources to correct relative path (only if outputting)
343+
if (extension === ".d.ts.map" && (_output?.file || _output?.dir))
345344
{
345+
const declarationDir = (_output.file ? dirname(_output.file) : _output.dir) as string;
346346
const parsedText = JSON.parse(entryText) as SourceMap;
347347
// invert back to absolute, then make relative to declarationDir
348348
parsedText.sources = parsedText.sources.map(source =>

0 commit comments

Comments
 (0)