Skip to content

Commit

Permalink
fix: don't attempt to change declarationMap sources when no output
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
agilgur5 committed Jun 1, 2022
1 parent 4310873 commit 3a9c951
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,12 @@ const typescript: PluginImpl<RPT2Options> = (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 =>
Expand Down

0 comments on commit 3a9c951

Please sign in to comment.