Skip to content

Commit

Permalink
fix: Rollup rebuilds in watch mode (#449)
Browse files Browse the repository at this point in the history
New API: `Processor.dependents()`, to get all files that depend on a specific file.

BREAKING CHANGE:  `Processor.remove()` no longer removes the specified files AND their dependencies.
  • Loading branch information
tivac authored Jul 12, 2018
1 parent 9e495dc commit d2eefec
Show file tree
Hide file tree
Showing 23 changed files with 702 additions and 428 deletions.
29 changes: 7 additions & 22 deletions package-lock.json

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

8 changes: 7 additions & 1 deletion packages/browserify/browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,13 @@ module.exports = function(browserify, opts) {
// Watchify fires update events when files change, this tells the processor
// to remove the changed files from its cache so they will be re-processed
browserify.on("update", (files) => {
processor.remove(files);
files.forEach((file) => {
processor.dependents(file).forEach((dep) =>
processor.remove(dep)
);

processor.remove(file);
});
});

return browserify.on("bundle", (current) => {
Expand Down
1 change: 0 additions & 1 deletion packages/browserify/package-lock.json

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

38 changes: 19 additions & 19 deletions packages/browserify/test/__snapshots__/issue-58.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@

exports[`/browserify.js /issues /58 should update when CSS dependencies change 1`] = `
"(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\\"function\\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\\"Cannot find module '\\"+i+\\"'\\");throw a.code=\\"MODULE_NOT_FOUND\\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\\"function\\"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
require('./packages/browserify/test/specimens/issues/58/issue.css');
},{\\"./packages/browserify/test/specimens/issues/58/issue.css\\":2}],2:[function(require,module,exports){
require('./packages/browserify/test/output/issues/58/issue.css');
},{\\"./packages/browserify/test/output/issues/58/issue.css\\":2}],2:[function(require,module,exports){
module.exports = {
\\"issue1\\": \\"mc2652cf16_other1 mc46e4a65d_issue1\\",
\\"issue2\\": \\"mc2652cf16_other1 mc46e4a65d_issue1 mc2652cf16_other3 mc46e4a65d_issue2\\"
\\"issue1\\": \\"mce821a830_other1 mc2a3f7922_issue1\\",
\\"issue2\\": \\"mce821a830_other1 mc2a3f7922_issue1 mce821a830_other3 mc2a3f7922_issue2\\"
};
},{\\"./packages/browserify/test/specimens/issues/58/other.css\\":3}],3:[function(require,module,exports){
},{\\"./packages/browserify/test/output/issues/58/other.css\\":3}],3:[function(require,module,exports){
module.exports = {
\\"other1\\": \\"mc2652cf16_other1\\",
\\"other2\\": \\"mc2652cf16_other2\\",
\\"other3\\": \\"mc2652cf16_other3\\"
\\"other1\\": \\"mce821a830_other1\\",
\\"other2\\": \\"mce821a830_other2\\",
\\"other3\\": \\"mce821a830_other3\\"
};
},{}]},{},[1]);
"
`;

exports[`/browserify.js /issues /58 should update when CSS dependencies change 2`] = `
"(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\\"function\\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\\"Cannot find module '\\"+i+\\"'\\");throw a.code=\\"MODULE_NOT_FOUND\\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\\"function\\"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
require('./packages/browserify/test/specimens/issues/58/issue.css');
},{\\"./packages/browserify/test/specimens/issues/58/issue.css\\":2}],2:[function(require,module,exports){
require('./packages/browserify/test/output/issues/58/issue.css');
},{\\"./packages/browserify/test/output/issues/58/issue.css\\":2}],2:[function(require,module,exports){
module.exports = {
\\"issue1\\": \\"mc2652cf16_other1 mc46e4a65d_issue1\\",
\\"issue2\\": \\"mc2652cf16_other1 mc46e4a65d_issue1 mc2652cf16_other2 mc2652cf16_other3 mc46e4a65d_issue2\\"
\\"issue1\\": \\"mce821a830_other1 mc2a3f7922_issue1\\",
\\"issue2\\": \\"mce821a830_other1 mc2a3f7922_issue1 mce821a830_other2 mce821a830_other3 mc2a3f7922_issue2\\"
};
},{}]},{},[1]);
"
`;

exports[`/browserify.js /issues /58 should update when CSS dependencies change 3`] = `
"/* packages/browserify/test/specimens/issues/58/other.css */
.mc2652cf16_other1 { color: green; }
.mc2652cf16_other2 { color: yellow; }
.mc2652cf16_other3 { background: white; }
/* packages/browserify/test/specimens/issues/58/issue.css */
.mc46e4a65d_issue1 {
"/* packages/browserify/test/output/issues/58/other.css */
.mce821a830_other1 { color: green; }
.mce821a830_other2 { color: yellow; }
.mce821a830_other3 { background: white; }
/* packages/browserify/test/output/issues/58/issue.css */
.mc2a3f7922_issue1 {
color: teal;
}
.mc46e4a65d_issue2 {
.mc2a3f7922_issue2 {
color: aqua;
}"
`;
55 changes: 28 additions & 27 deletions packages/browserify/test/issue-58.test.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
"use strict";

var fs = require("fs"),

from = require("from2-string"),
shell = require("shelljs"),
browserify = require("browserify"),
watchify = require("watchify"),
dedent = require("dedent"),
const from = require("from2-string");
const shell = require("shelljs");
const browserify = require("browserify");
const watchify = require("watchify");
const dedent = require("dedent");

read = require("test-utils/read.js")(__dirname),

bundle = require("./lib/bundle.js"),
plugin = require("../browserify.js");
const read = require("test-utils/read.js")(__dirname);
const write = require("test-utils/write.js")(__dirname);

function write(txt) {
fs.writeFileSync(
"./packages/browserify/test/specimens/issues/58/other.css",
dedent(txt),
"utf8"
);
}
const bundle = require("./lib/bundle.js");
const plugin = require("../browserify.js");

describe("/browserify.js", () => {
describe("/issues", () => {
describe("/58", () => {
afterAll(() => {
shell.rm("-rf", "./packages/browserify/test/output/issues");
shell.rm("./packages/browserify/test/specimens/issues/58/other.css");
});
afterAll(() => shell.rm("-rf", "./packages/browserify/test/output/issues"));

it("should update when CSS dependencies change", (done) => {
var build = browserify();

write(`
write("./issues/58/issue.css", dedent(`
.issue1 {
composes: other1 from "./other.css";
color: teal;
}
.issue2 {
composes: issue1;
composes: other3 from "./other.css";
color: aqua;
}
`));

write("./issues/58/other.css", dedent(`
.other1 { color: red; }
.other2 { color: navy; }
.other3 { color: blue; }
`);
`));

build.add(
from("require('./packages/browserify/test/specimens/issues/58/issue.css');")
from("require('./packages/browserify/test/output/issues/58/issue.css');")
);

build.plugin(watchify);
Expand All @@ -60,11 +61,11 @@ describe("/browserify.js", () => {
bundle(build).then((out) => {
expect(out).toMatchSnapshot();

write(`
write("./issues/58/other.css", dedent(`
.other1 { color: green; }
.other2 { color: yellow; }
.other3 { composes: other2; background: white; }
`);
`));
});
});
});
Expand Down
1 change: 0 additions & 1 deletion packages/cli/package-lock.json

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

5 changes: 0 additions & 5 deletions packages/core/package-lock.json

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

1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"lodash.get": "^4.4.2",
"lodash.invert": "^4.3.0",
"lodash.mapvalues": "^4.6.0",
"lodash.uniq": "^4.5.0",
"p-each-series": "^1.0.0",
"postcss": "^6.0.11",
"postcss-selector-parser": "^3.0.0",
Expand Down
Loading

0 comments on commit d2eefec

Please sign in to comment.