Skip to content

Commit 510b662

Browse files
authored
feat: Use rollup@0.65.0's watchChange event (#511)
1 parent fd9d4f0 commit 510b662

File tree

6 files changed

+29
-55
lines changed

6 files changed

+29
-55
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"lerna": "^3.1.4",
3636
"pegjs": "0.10.0",
3737
"read-dir-deep": "1.0.4",
38-
"rollup": "0.64.1",
38+
"rollup": "^0.65.0",
3939
"rollup-plugin-svelte": "4.2.1",
4040
"shelljs": "0.8.2",
4141
"svelte": "^2.13.0",

packages/rollup/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ Rollup support for [`modular-css`](https://github.com/tivac/modular-css).
1010

1111
`$ npm i modular-css-rollup`
1212

13-
## Usage
13+
## ⚠️Rollup Version support⚠️
14+
15+
Due to API changes, certain major versions of this plugin will require a specific minimum rollup version.
1416

15-
⚠️ As of `modular-css-rollup@11` this plugin will only work with `rollup@0.60.0` or higher due to plugin API changes ⚠️
17+
- `modular-css-rollup@11` requires `rollup@0.60.0`
18+
- `modular-css-rollup@15` requires `rollup@0.65.0`
19+
20+
## Usage
1621

1722
### API
1823

packages/rollup/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@
2222
"mkdirp": "^0.5.1",
2323
"modular-css-core": "file:../core",
2424
"rollup-pluginutils": "^2.0.1"
25+
},
26+
"peerDependencies": {
27+
"rollup":"^0.65.0"
2528
}
2629
}

packages/rollup/rollup.js

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint max-statements: [ 1, 20 ] */
22
"use strict";
33

4-
const fs = require("fs");
54
const path = require("path");
65

76
const { keyword } = require("esutils");
@@ -48,11 +47,6 @@ module.exports = function(opts) {
4847

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

51-
let runs = 0;
52-
53-
// Track which files were changed for which run to avoid excessive re-processing
54-
const updated = new Map();
55-
5650
return {
5751
name : "modular-css-rollup",
5852

@@ -67,50 +61,21 @@ module.exports = function(opts) {
6761
}
6862
},
6963

70-
async transform(code, id) {
71-
if(!filter(id)) {
72-
return null;
64+
watchChange(file) {
65+
if(!processor.files[file]) {
66+
return;
7367
}
7468

75-
// Is this file being processed on a watch update?
76-
if(runs++ && (id in processor.files)) {
77-
const files = [];
78-
79-
// Watching will call transform w/ the same entry file, even if it
80-
// was one of its dependencies that changed. We need to fork the logic
81-
// here to handle that case.
82-
if(processor.files[id].text === code) {
83-
// figure out exactly which dependency changed
84-
processor.dependencies(id).forEach((dep) => {
85-
if(fs.readFileSync(dep, "utf8") === processor.files[dep].text) {
86-
return;
87-
}
88-
89-
files.push(dep, ...processor.dependents(dep));
90-
});
91-
} else {
92-
// Entry file changed, remove all its dependents and
93-
// then re-process them
94-
files.push(id, ...processor.dependents(id));
95-
}
96-
97-
files.forEach((file) => {
98-
// Don't do the remove/re-add dance for any files that
99-
// were already processed in this run
100-
if(updated.has(file) && updated.get(file) === runs) {
101-
return;
102-
}
103-
104-
updated.set(file, runs);
69+
processor.dependents(file).forEach((dep) =>
70+
processor.remove(dep)
71+
);
10572

106-
processor.remove(file);
107-
});
73+
processor.remove(file);
74+
},
10875

109-
// Can't filter this using updated, it's already been updated
110-
// by the remove loop up above but the processing still needs to happen
111-
await Promise.all([ ...files ].map((dep) =>
112-
processor.file(dep)
113-
));
76+
async transform(code, id) {
77+
if(!filter(id)) {
78+
return null;
11479
}
11580

11681
const { details, exports } = await processor.string(id, code);

packages/rollup/test/__snapshots__/rollup.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ exports[`/rollup.js should respect the CSS dependency tree 2`] = `
161161
exports[`/rollup.js should warn & not export individual keys when they are not valid identifiers 1`] = `
162162
Object {
163163
"code": "PLUGIN_WARNING",
164+
"hook": "transform",
164165
"id": Any<String>,
165166
"message": "Invalid JS identifier \\"fooga-wooga\\", unable to export",
166167
"plugin": "modular-css-rollup",

0 commit comments

Comments
 (0)