Skip to content

Commit

Permalink
fix: metadata output breaks when common.css is output (#556)
Browse files Browse the repository at this point in the history
* fix: bundle entries don't always exist

Specifically in the case where the plugin is outputting a "common.css" file that includes all the CSS that rollup itself didn't walk.

* test: test/snapshot for common metadata case
  • Loading branch information
tivac authored Jan 28, 2019
1 parent ef5cfaa commit bf50079
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/rollup/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ module.exports = (opts) => {
const meta = {};

out.forEach((value, entry) => {
if(!bundle[entry]) {
return;
}

const { assets, dynamicAssets } = bundle[entry];

meta[entry] = {
Expand Down
51 changes: 51 additions & 0 deletions packages/rollup/test/__snapshots__/splitting.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,57 @@ Array [
]
`;

exports[`/rollup.js code splitting should output metadata successfully when unreferenced CSS is output to common 1`] = `
Array [
Object {
"file": "a.css",
"text": "/* packages/rollup/test/specimens/metadata/a.css */
.mc541d3f5c_a { color: aqua; }
",
},
Object {
"file": "b.css",
"text": "/* packages/rollup/test/specimens/metadata/b.css */
.mc04101138_b { color: blue; }
",
},
Object {
"file": "chunk.css",
"text": "/* packages/rollup/test/specimens/metadata/d.css */
.mc7de0d66b_d { color: darkkhaki; }
",
},
Object {
"file": "common.css",
"text": "/* fake.css */
.mc2c838439_fake { color: red; }",
},
Object {
"file": "metadata.json",
"text": "{
\\"chunk2.js\\": {
\\"assets\\": [],
\\"dynamicAssets\\": [
\\"assets/chunk.css\\"
]
},
\\"a.js\\": {
\\"assets\\": [
\\"assets/a.css\\"
],
\\"dynamicAssets\\": []
},
\\"b.js\\": {
\\"assets\\": [
\\"assets/b.css\\"
],
\\"dynamicAssets\\": []
}
}",
},
]
`;

exports[`/rollup.js code splitting should support circular JS dependencies 1`] = `
Array [
Object {
Expand Down
36 changes: 36 additions & 0 deletions packages/rollup/test/splitting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const { rollup } = require("rollup");

const shell = require("shelljs");

const Processor = require("@modular-css/processor");

const dir = require("@modular-css/test-utils/read-dir.js")(__dirname);
const prefix = require("@modular-css/test-utils/prefix.js")(__dirname);
const namer = require("@modular-css/test-utils/namer.js");
Expand Down Expand Up @@ -85,6 +87,40 @@ describe("/rollup.js", () => {
expect(dir("./css-metadata/assets")).toMatchSnapshot();
});

it("should output metadata successfully when unreferenced CSS is output to common", async () => {
const processor = new Processor();

await processor.string("./fake.css", ".fake { color: red; }");

const bundle = await rollup({
input : [
require.resolve("./specimens/metadata/a.js"),
require.resolve("./specimens/metadata/b.js"),
],

plugins : [
plugin({
namer,
map,
processor,
meta : true,
}),
],
});

await bundle.write({
format,
sourcemap,

assetFileNames,
chunkFileNames,

dir : prefix(`./output/css-metadata-common`),
});

expect(dir("./css-metadata-common/assets")).toMatchSnapshot();
});

it("should support outputting metadata about CSS dependencies to a named file ", async () => {
const bundle = await rollup({
input : [
Expand Down

0 comments on commit bf50079

Please sign in to comment.