Skip to content

Commit 2d3257e

Browse files
authored
fix: External map references (#457)
* fix: replace placeholders in assetFileNames So that external source map references point to the right file. Gotta pass a real file to postcss or it does some funny things. Fixes #455
1 parent 66f7059 commit 2d3257e

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

packages/rollup/rollup.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ const emptyMappings = {
1616
mappings : "",
1717
};
1818

19-
function extensionless(file) {
20-
return path.join(path.dirname(file), path.basename(file, path.extname(file)));
21-
}
19+
const makeFile = (details) => {
20+
const { entry } = details;
21+
const name = path.basename(entry, path.extname(entry));
22+
23+
return Object.assign(details, {
24+
base : path.join(path.dirname(entry), name),
25+
name,
26+
});
27+
};
2228

2329
module.exports = function(opts) {
2430
const options = Object.assign(Object.create(null), {
@@ -161,12 +167,10 @@ module.exports = function(opts) {
161167

162168
// First pass is used to calculate JS usage of CSS dependencies
163169
Object.keys(bundles).forEach((entry) => {
164-
const file = {
170+
const file = makeFile({
165171
entry,
166-
167-
base : extensionless(entry),
168-
css : [],
169-
};
172+
css : [],
173+
});
170174

171175
// Get CSS files being used by each entry point
172176
const css = Object.keys(bundles[entry].modules).filter(filter);
@@ -221,22 +225,24 @@ module.exports = function(opts) {
221225

222226
// Common chunk only emitted if necessary
223227
if(common.size) {
224-
files.push({
228+
files.push(makeFile({
225229
entry : options.common,
226-
base : extensionless(options.common),
227230
css : [ ...common.keys() ],
228-
});
231+
}));
229232
}
230233
}
231234

232235
await Promise.all(
233236
files
234237
.filter(({ css }) => css.length)
235-
.map(async ({ base, css }) => {
238+
.map(async (details) => {
239+
const { base, name, css } = details;
236240
const id = this.emitAsset(`${base}.css`);
237241

238242
const result = await processor.output({
239-
to,
243+
to : to.replace(/\[(name|extname)\]/g, (match, field) =>
244+
(field === "name" ? name : ".css")
245+
),
240246
files : css,
241247
});
242248

packages/rollup/test/__snapshots__/rollup.test.js.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ Object {
163163
}
164164
`;
165165
166+
exports[`/rollup.js should generate external source maps 2`] = `
167+
"/* packages/rollup/test/specimens/simple.css */
168+
.fooga {
169+
color: red;
170+
}
171+
172+
/*# sourceMappingURL=simple.css.map */"
173+
`;
174+
166175
exports[`/rollup.js should handle assetFileNames being undefined 1`] = `
167176
"/* packages/rollup/test/specimens/simple.css */
168177
.fooga {

packages/rollup/test/rollup.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ describe("/rollup.js", () => {
240240
expect(JSON.parse(read("./rollup/external-source-maps/assets/simple.css.map"))).toMatchSnapshot({
241241
file : expect.any(String),
242242
});
243+
244+
expect(read("./rollup/external-source-maps/assets/simple.css")).toMatchSnapshot();
243245
});
244246

245247
it("should warn & not export individual keys when they are not valid identifiers", async () => {

0 commit comments

Comments
 (0)