Skip to content

Commit

Permalink
fix: adding new files w/ rollup shouldn't error (#422)
Browse files Browse the repository at this point in the history
Fixes #421

BREAKING CHANGE: Processor.remove now always returns an array. If
nothing was removed the array will be empty.
  • Loading branch information
tivac committed May 2, 2018
1 parent dd9f6d0 commit 67e1707
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 35 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Expand Up @@ -20,14 +20,14 @@ cache:
directories:
- "$HOME/.npm"

# Set up latest npm & cipm for installs
# Set up npm 5 for installs (npm 6 seems busted atm)
before_install:
- npm config set loglevel warn
- npm install --global npm@latest cipm
- npm install --global npm@5

install:
- cipm
- lerna exec -- cipm
- npm ci
- lerna exec -- npm ci

script:
- npm test -- --coverage --verbose --ci
Expand Down
3 changes: 2 additions & 1 deletion 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 packages/aliases/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 packages/browserify/package-lock.json

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

16 changes: 8 additions & 8 deletions packages/cli/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 packages/core/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 packages/core/processor.js
Expand Up @@ -169,7 +169,7 @@ Processor.prototype = {
.filter((file) => this._graph.hasNode(file));

if(!files.length) {
return;
return [];
}

// Remove everything that depends on files to be removed as well
Expand Down
2 changes: 1 addition & 1 deletion packages/glob/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 packages/namer/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 packages/paths/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 packages/postcss/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 packages/rollup/package-lock.json

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

4 changes: 1 addition & 3 deletions packages/rollup/rollup.js
Expand Up @@ -44,7 +44,7 @@ module.exports = function(opts) {
},

transform : function(code, id) {
let removed;
let removed = [];

if(!filter(id) || id.slice(slice) !== options.ext) {
return null;
Expand All @@ -54,8 +54,6 @@ module.exports = function(opts) {
// avoid cache staleness issues
if(runs) {
removed = processor.remove(id);
} else {
removed = [];
}

return Promise.all(
Expand Down
9 changes: 9 additions & 0 deletions packages/rollup/test/__snapshots__/rollup.test.js.snap
Expand Up @@ -101,6 +101,15 @@ console.log(css);
}
`;

exports[`/rollup.js watch should correctly add new css files in watch mode when files change 1`] = `""`;

exports[`/rollup.js watch should correctly add new css files in watch mode when files change 2`] = `
"/* packages/rollup/test/output/one.css */
.mc19ef5610_one {
color: red;
}"
`;

exports[`/rollup.js watch should correctly update files within the dependency graph in watch mode when files change 1`] = `
"/* packages/rollup/test/output/one.css */
.mc19ef5610_one {
Expand Down
57 changes: 57 additions & 0 deletions packages/rollup/test/rollup.test.js
Expand Up @@ -422,5 +422,62 @@ describe("/rollup.js", () => {
return done();
}));
});

it("should correctly add new css files in watch mode when files change", (done) => {
// Create v1 of the files
fs.writeFileSync(
"./packages/rollup/test/output/one.css",
dedent(`
.one {
color: red;
}
`)
);

fs.writeFileSync(
"./packages/rollup/test/output/watch.js",
dedent(`
console.log("hello");
`)
);

// Start watching (re-requiring rollup because it needs root obj reference)
watcher = watch({
input : require.resolve("./output/watch.js"),
output : {
file : "./packages/rollup/test/output/watch-output.js",
format : "es"
},
plugins : [
plugin({
css : "./packages/rollup/test/output/watch-output.css",
map : false
})
]
});

// Create v2 of the file after a bit
setTimeout(() => fs.writeFileSync(
"./packages/rollup/test/output/watch.js",
dedent(`
import css from "./one.css";
console.log(css);
`)
), 200);

watcher.on("event", watching((builds) => {
if(builds === 1) {
expect(read("watch-output.css")).toMatchSnapshot();

// continue watching
return;
}

expect(read("watch-output.css")).toMatchSnapshot();

return done();
}));
});
});
});
2 changes: 1 addition & 1 deletion packages/svelte/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 packages/test-utils/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 packages/webpack/package-lock.json

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

14 changes: 7 additions & 7 deletions packages/www/package-lock.json

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

0 comments on commit 67e1707

Please sign in to comment.