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 rollup dependency removal #442

Merged
merged 5 commits into from
Jul 5, 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
19 changes: 11 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"lint-staged": "^7.0.4",
"modular-css-core": "file:./packages/core",
"pegjs": "^0.10.0",
"rollup": "^0.61.2",
"rollup": "^0.62.0",
"rollup-plugin-svelte": "^4.1.0",
"shelljs": "^0.8.1",
"svelte": "^2.8.1",
Expand Down
22 changes: 18 additions & 4 deletions packages/rollup/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module.exports = function(opts) {
const filter = utils.createFilter(options.include, options.exclude);

const processor = options.processor || new Processor(options);

let runs = 0;

return {
name : "modular-css-rollup",
Expand All @@ -42,13 +44,20 @@ module.exports = function(opts) {
if(!filter(id)) {
return null;
}

// If the file is being re-processed we need to remove it to
// avoid cache staleness issues
if(id in processor.files) {
processor.dependencies(id)
.concat(id)
.forEach((file) => processor.remove(file));
let files = [ id ];

// First time build should only remove the file and any files that depend on it
// but watchs update need to clear out the file, any files that depend on it,
// AND any files it depends on
if(runs) {
files = processor.dependencies(id).concat(files);
}

files.forEach((file) => processor.remove(file));
}

return processor.string(id, code).then((result) => {
Expand Down Expand Up @@ -80,6 +89,11 @@ module.exports = function(opts) {
});
},

// Track # of runs since remove functionality needs to change
buildEnd() {
runs++;
},

async generateBundle(outputOptions, bundles) {
const usage = new Map();
const common = new Map();
Expand Down
39 changes: 39 additions & 0 deletions packages/rollup/test/__snapshots__/rollup.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,45 @@ console.log(css);
}
`;

exports[`/rollup.js shouldn't over-remove files from an existing processor instance 1`] = `
"var css = {
\\"a\\": \\"c a\\"
};

var css$1 = {
\\"b\\": \\"c b\\"
};

console.log(css, css$1);
"
`;

exports[`/rollup.js shouldn't over-remove files from an existing processor instance 2`] = `
"/* packages/rollup/test/specimens/repeated-references/a.css */
.a {

color: red;
}
/* packages/rollup/test/specimens/repeated-references/b.css */
.b {

color: blue;
}
"
`;

exports[`/rollup.js shouldn't over-remove files from an existing processor instance 3`] = `
"/* packages/rollup/test/specimens/repeated-references/d.css */
.d {
color: darkblue;
}
/* packages/rollup/test/specimens/repeated-references/c.css */
.c {
color: cadetblue;
}
"
`;

exports[`/rollup.js watch should correctly add new css files in watch mode when files change 1`] = `
"/* packages/rollup/test/output/one.css */
.mc19ef5610_one {
Expand Down
32 changes: 31 additions & 1 deletion packages/rollup/test/rollup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ describe("/rollup.js", () => {
expect(read("dependencies/dependencies.js")).toMatchSnapshot();
expect(read("dependencies/assets/dependencies.css")).toMatchSnapshot();
});

it("should accept an existing processor instance", async () => {
const processor = new Processor({
namer,
Expand Down Expand Up @@ -333,6 +333,36 @@ describe("/rollup.js", () => {
expect(read("existing-processor/assets/common.css")).toMatchSnapshot();
});

it("shouldn't over-remove files from an existing processor instance", async () => {
const processor = new Processor({
namer,
map,
});

await processor.file(require.resolve("./specimens/repeated-references/b.css"));

const bundle = await rollup({
input : require.resolve("./specimens/repeated-references/a.js"),
plugins : [
plugin({
processor,
}),
],
});

await bundle.write({
format,
sourcemap,
assetFileNames,

file : `${output}/repeated-references/repeated-references.js`,
});

expect(read("repeated-references/repeated-references.js")).toMatchSnapshot();
expect(read("repeated-references/assets/repeated-references.css")).toMatchSnapshot();
expect(read("repeated-references/assets/common.css")).toMatchSnapshot();
});

describe("errors", () => {
function checkError(err) {
expect(err.toString()).toMatch("error-plugin:");
Expand Down
5 changes: 5 additions & 0 deletions packages/rollup/test/specimens/repeated-references/a.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.a {
composes: c from "./c.css";

color: red;
}
4 changes: 4 additions & 0 deletions packages/rollup/test/specimens/repeated-references/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import css from "./a.css";
import b from "./b.js";

console.log(css, b);
5 changes: 5 additions & 0 deletions packages/rollup/test/specimens/repeated-references/b.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.b {
composes: c from "./c.css";

color: blue;
}
3 changes: 3 additions & 0 deletions packages/rollup/test/specimens/repeated-references/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import css from "./b.css";

export default css;
7 changes: 7 additions & 0 deletions packages/rollup/test/specimens/repeated-references/c.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.c {
color: cadetblue;
}

.other {
composes: d from "./d.css";
}
3 changes: 3 additions & 0 deletions packages/rollup/test/specimens/repeated-references/d.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.d {
color: darkblue;
}