Skip to content

Commit

Permalink
Use correct file names when writing sourcemaps for multiple outputs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Mar 13, 2020
1 parent 99a9c41 commit a6c450e
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/Chunk.ts
Expand Up @@ -509,6 +509,7 @@ export default class Chunk {
) {
timeStart('render format', 3);

const chunkId = this.id!;
const format = options.format as string;
const finalise = finalisers[format];
if (options.dynamicImportFunction && format !== 'es') {
Expand Down Expand Up @@ -602,12 +603,12 @@ export default class Chunk {

let file: string;
if (options.file) file = resolve(options.sourcemapFile || options.file);
else if (options.dir) file = resolve(options.dir, this.id!);
else file = resolve(this.id!);
else if (options.dir) file = resolve(options.dir, chunkId);
else file = resolve(chunkId);

const decodedMap = magicString.generateDecodedMap({});
map = collapseSourcemaps(
this,
this.graph,
file,
decodedMap,
this.usedModules,
Expand Down
5 changes: 2 additions & 3 deletions src/utils/collapseSourcemaps.ts
@@ -1,5 +1,4 @@
import { DecodedSourceMap, SourceMap } from 'magic-string';
import Chunk from '../Chunk';
import Graph from '../Graph';
import Module from '../Module';
import {
Expand Down Expand Up @@ -200,14 +199,14 @@ function getCollapsedSourcemap(
}

export function collapseSourcemaps(
bundle: Chunk,
graph: Graph,
file: string,
map: DecodedSourceMap,
modules: Module[],
bundleSourcemapChain: DecodedSourceMapOrMissing[],
excludeContent: boolean | undefined
) {
const linkMap = getLinkMap(bundle.graph);
const linkMap = getLinkMap(graph);
const moduleSources = modules
.filter(module => !module.excludeFromSourcemap)
.map(module =>
Expand Down
4 changes: 4 additions & 0 deletions test/cli/samples/config-multiple-source-maps/_config.js
@@ -0,0 +1,4 @@
module.exports = {
description: 'correctly generates sourcemaps for multiple outputs',
command: 'rollup -c'
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/cli/samples/config-multiple-source-maps/main.js
@@ -0,0 +1 @@
assert.equal( ANSWER, 42 );
17 changes: 17 additions & 0 deletions test/cli/samples/config-multiple-source-maps/rollup.config.js
@@ -0,0 +1,17 @@
export default {
input: 'main.js',
output: [
{
format: 'cjs',
dir: '_actual',
entryFileNames: '[name]-[format].js',
sourcemap: true,
},
{
format: 'es',
dir: '_actual',
entryFileNames: '[name]-[format].js',
sourcemap: true
}
]
};

0 comments on commit a6c450e

Please sign in to comment.