Skip to content

Commit d2eefec

Browse files
authored
fix: Rollup rebuilds in watch mode (#449)
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.
1 parent 9e495dc commit d2eefec

23 files changed

+702
-428
lines changed

package-lock.json

Lines changed: 7 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/browserify/browserify.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,13 @@ module.exports = function(browserify, opts) {
159159
// Watchify fires update events when files change, this tells the processor
160160
// to remove the changed files from its cache so they will be re-processed
161161
browserify.on("update", (files) => {
162-
processor.remove(files);
162+
files.forEach((file) => {
163+
processor.dependents(file).forEach((dep) =>
164+
processor.remove(dep)
165+
);
166+
167+
processor.remove(file);
168+
});
163169
});
164170

165171
return browserify.on("bundle", (current) => {

packages/browserify/package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/browserify/test/__snapshots__/issue-58.test.js.snap

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,44 @@
22

33
exports[`/browserify.js /issues /58 should update when CSS dependencies change 1`] = `
44
"(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){
5-
require('./packages/browserify/test/specimens/issues/58/issue.css');
6-
},{\\"./packages/browserify/test/specimens/issues/58/issue.css\\":2}],2:[function(require,module,exports){
5+
require('./packages/browserify/test/output/issues/58/issue.css');
6+
},{\\"./packages/browserify/test/output/issues/58/issue.css\\":2}],2:[function(require,module,exports){
77
module.exports = {
8-
\\"issue1\\": \\"mc2652cf16_other1 mc46e4a65d_issue1\\",
9-
\\"issue2\\": \\"mc2652cf16_other1 mc46e4a65d_issue1 mc2652cf16_other3 mc46e4a65d_issue2\\"
8+
\\"issue1\\": \\"mce821a830_other1 mc2a3f7922_issue1\\",
9+
\\"issue2\\": \\"mce821a830_other1 mc2a3f7922_issue1 mce821a830_other3 mc2a3f7922_issue2\\"
1010
};
11-
},{\\"./packages/browserify/test/specimens/issues/58/other.css\\":3}],3:[function(require,module,exports){
11+
},{\\"./packages/browserify/test/output/issues/58/other.css\\":3}],3:[function(require,module,exports){
1212
module.exports = {
13-
\\"other1\\": \\"mc2652cf16_other1\\",
14-
\\"other2\\": \\"mc2652cf16_other2\\",
15-
\\"other3\\": \\"mc2652cf16_other3\\"
13+
\\"other1\\": \\"mce821a830_other1\\",
14+
\\"other2\\": \\"mce821a830_other2\\",
15+
\\"other3\\": \\"mce821a830_other3\\"
1616
};
1717
},{}]},{},[1]);
1818
"
1919
`;
2020

2121
exports[`/browserify.js /issues /58 should update when CSS dependencies change 2`] = `
2222
"(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){
23-
require('./packages/browserify/test/specimens/issues/58/issue.css');
24-
},{\\"./packages/browserify/test/specimens/issues/58/issue.css\\":2}],2:[function(require,module,exports){
23+
require('./packages/browserify/test/output/issues/58/issue.css');
24+
},{\\"./packages/browserify/test/output/issues/58/issue.css\\":2}],2:[function(require,module,exports){
2525
module.exports = {
26-
\\"issue1\\": \\"mc2652cf16_other1 mc46e4a65d_issue1\\",
27-
\\"issue2\\": \\"mc2652cf16_other1 mc46e4a65d_issue1 mc2652cf16_other2 mc2652cf16_other3 mc46e4a65d_issue2\\"
26+
\\"issue1\\": \\"mce821a830_other1 mc2a3f7922_issue1\\",
27+
\\"issue2\\": \\"mce821a830_other1 mc2a3f7922_issue1 mce821a830_other2 mce821a830_other3 mc2a3f7922_issue2\\"
2828
};
2929
},{}]},{},[1]);
3030
"
3131
`;
3232

3333
exports[`/browserify.js /issues /58 should update when CSS dependencies change 3`] = `
34-
"/* packages/browserify/test/specimens/issues/58/other.css */
35-
.mc2652cf16_other1 { color: green; }
36-
.mc2652cf16_other2 { color: yellow; }
37-
.mc2652cf16_other3 { background: white; }
38-
/* packages/browserify/test/specimens/issues/58/issue.css */
39-
.mc46e4a65d_issue1 {
34+
"/* packages/browserify/test/output/issues/58/other.css */
35+
.mce821a830_other1 { color: green; }
36+
.mce821a830_other2 { color: yellow; }
37+
.mce821a830_other3 { background: white; }
38+
/* packages/browserify/test/output/issues/58/issue.css */
39+
.mc2a3f7922_issue1 {
4040
color: teal;
4141
}
42-
.mc46e4a65d_issue2 {
42+
.mc2a3f7922_issue2 {
4343
color: aqua;
4444
}"
4545
`;

packages/browserify/test/issue-58.test.js

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,46 @@
11
"use strict";
22

3-
var fs = require("fs"),
4-
5-
from = require("from2-string"),
6-
shell = require("shelljs"),
7-
browserify = require("browserify"),
8-
watchify = require("watchify"),
9-
dedent = require("dedent"),
3+
const from = require("from2-string");
4+
const shell = require("shelljs");
5+
const browserify = require("browserify");
6+
const watchify = require("watchify");
7+
const dedent = require("dedent");
108

11-
read = require("test-utils/read.js")(__dirname),
12-
13-
bundle = require("./lib/bundle.js"),
14-
plugin = require("../browserify.js");
9+
const read = require("test-utils/read.js")(__dirname);
10+
const write = require("test-utils/write.js")(__dirname);
1511

16-
function write(txt) {
17-
fs.writeFileSync(
18-
"./packages/browserify/test/specimens/issues/58/other.css",
19-
dedent(txt),
20-
"utf8"
21-
);
22-
}
12+
const bundle = require("./lib/bundle.js");
13+
const plugin = require("../browserify.js");
2314

2415
describe("/browserify.js", () => {
2516
describe("/issues", () => {
2617
describe("/58", () => {
27-
afterAll(() => {
28-
shell.rm("-rf", "./packages/browserify/test/output/issues");
29-
shell.rm("./packages/browserify/test/specimens/issues/58/other.css");
30-
});
18+
afterAll(() => shell.rm("-rf", "./packages/browserify/test/output/issues"));
3119

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

35-
write(`
23+
write("./issues/58/issue.css", dedent(`
24+
.issue1 {
25+
composes: other1 from "./other.css";
26+
color: teal;
27+
}
28+
29+
.issue2 {
30+
composes: issue1;
31+
composes: other3 from "./other.css";
32+
color: aqua;
33+
}
34+
`));
35+
36+
write("./issues/58/other.css", dedent(`
3637
.other1 { color: red; }
3738
.other2 { color: navy; }
3839
.other3 { color: blue; }
39-
`);
40+
`));
4041

4142
build.add(
42-
from("require('./packages/browserify/test/specimens/issues/58/issue.css');")
43+
from("require('./packages/browserify/test/output/issues/58/issue.css');")
4344
);
4445

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

63-
write(`
64+
write("./issues/58/other.css", dedent(`
6465
.other1 { color: green; }
6566
.other2 { color: yellow; }
6667
.other3 { composes: other2; background: white; }
67-
`);
68+
`));
6869
});
6970
});
7071
});

packages/cli/package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package-lock.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"lodash.get": "^4.4.2",
2424
"lodash.invert": "^4.3.0",
2525
"lodash.mapvalues": "^4.6.0",
26-
"lodash.uniq": "^4.5.0",
2726
"p-each-series": "^1.0.0",
2827
"postcss": "^6.0.11",
2928
"postcss-selector-parser": "^3.0.0",

0 commit comments

Comments
 (0)