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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jan 28, 2019
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
4 changes: 4 additions & 0 deletions packages/rollup/rollup.js
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
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
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