From c02209be833049c969dbbfc4e41056197af884f2 Mon Sep 17 00:00:00 2001 From: Aeriit Date: Tue, 27 Jul 2021 17:01:42 -0400 Subject: [PATCH] Handle JSON string source maps returned from rollup plugins --- .changeset/healthy-shrimps-hope.md | 5 +++++ packages/wmr/src/lib/rollup-plugin-container.js | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .changeset/healthy-shrimps-hope.md diff --git a/.changeset/healthy-shrimps-hope.md b/.changeset/healthy-shrimps-hope.md new file mode 100644 index 000000000..c96f7b3d0 --- /dev/null +++ b/.changeset/healthy-shrimps-hope.md @@ -0,0 +1,5 @@ +--- +'wmr': patch +--- + +Handle JSON string source maps returned from rollup plugins diff --git a/packages/wmr/src/lib/rollup-plugin-container.js b/packages/wmr/src/lib/rollup-plugin-container.js index dcf1e8df8..8cfe92372 100644 --- a/packages/wmr/src/lib/rollup-plugin-container.js +++ b/packages/wmr/src/lib/rollup-plugin-container.js @@ -290,6 +290,18 @@ export function createPluginContainer(plugins, opts = {}) { logTransform(`${kl.dim(formatPath(id))} [${plugin.name}]`); if (typeof result === 'object') { + if (typeof result.map === 'string') { + try { + result.map = JSON.parse(result.map); + } catch { + if (hasDebugFlag()) { + logTransform(kl.yellow(`Invalid source map JSON returned by plugin `) + kl.magenta(plugin.name)); + } + + result.map = undefined; + } + } + if (result.map) { // Normalize source map sources URLs for the browser result.map.sources = result.map.sources.map(s => {