Skip to content
Permalink
Browse files
fix: adding new files w/ rollup shouldn't error (#422)
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 67e17075e4c3d8b7ccba6eeee11359ad981207c3
@@ -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

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -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

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -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;
@@ -54,8 +54,6 @@ module.exports = function(opts) {
// avoid cache staleness issues
if(runs) {
removed = processor.remove(id);
} else {
removed = [];
}

return Promise.all(
@@ -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 {
@@ -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();
}));
});
});
});

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

0 comments on commit 67e1707

Please sign in to comment.