Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct file names when writing sourcemaps for multiple outputs using the "dir" option #3440

Merged
merged 1 commit into from Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}
]
};