Skip to content
Permalink
Browse files

fix: metadata output breaks when common.css is output (#556)

* 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 committed Jan 28, 2019
1 parent ef5cfaa commit bf50079d97eefef35753c1031b8e4106e378354a
@@ -342,6 +342,10 @@ module.exports = (opts) => {
const meta = {};

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

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

meta[entry] = {
@@ -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 {
@@ -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");
@@ -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 : [

0 comments on commit bf50079

Please sign in to comment.
You can’t perform that action at this time.