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

fix: External map references #457

Merged
merged 2 commits into from
Jul 19, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions packages/rollup/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ const emptyMappings = {
mappings : "",
};

function extensionless(file) {
return path.join(path.dirname(file), path.basename(file, path.extname(file)));
}
const makeFile = (details) => {
const { entry } = details;
const name = path.basename(entry, path.extname(entry));

return Object.assign(details, {
base : path.join(path.dirname(entry), name),
name,
});
};

module.exports = function(opts) {
const options = Object.assign(Object.create(null), {
Expand Down Expand Up @@ -161,12 +167,10 @@ module.exports = function(opts) {

// First pass is used to calculate JS usage of CSS dependencies
Object.keys(bundles).forEach((entry) => {
const file = {
const file = makeFile({
entry,

base : extensionless(entry),
css : [],
};
css : [],
});

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

// Common chunk only emitted if necessary
if(common.size) {
files.push({
files.push(makeFile({
entry : options.common,
base : extensionless(options.common),
css : [ ...common.keys() ],
});
}));
}
}

await Promise.all(
files
.filter(({ css }) => css.length)
.map(async ({ base, css }) => {
.map(async (details) => {
const { base, name, css } = details;
const id = this.emitAsset(`${base}.css`);

const result = await processor.output({
to,
to : to.replace(/\[(name|extname)\]/g, (match, field) =>
(field === "name" ? name : ".css")
),
files : css,
});

Expand Down
9 changes: 9 additions & 0 deletions packages/rollup/test/__snapshots__/rollup.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ Object {
}
`;

exports[`/rollup.js should generate external source maps 2`] = `
"/* packages/rollup/test/specimens/simple.css */
.fooga {
color: red;
}

/*# sourceMappingURL=simple.css.map */"
`;

exports[`/rollup.js should handle assetFileNames being undefined 1`] = `
"/* packages/rollup/test/specimens/simple.css */
.fooga {
Expand Down
2 changes: 2 additions & 0 deletions packages/rollup/test/rollup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ describe("/rollup.js", () => {
expect(JSON.parse(read("./rollup/external-source-maps/assets/simple.css.map"))).toMatchSnapshot({
file : expect.any(String),
});

expect(read("./rollup/external-source-maps/assets/simple.css")).toMatchSnapshot();
});

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