Skip to content

Instantly share code, notes, and snippets.

@tivac

tivac/README.md Secret

Created September 12, 2019 06:14
Show Gist options
  • Save tivac/ca2ff933d6dac4e06e8264800b0a1f98 to your computer and use it in GitHub Desktop.
Save tivac/ca2ff933d6dac4e06e8264800b0a1f98 to your computer and use it in GitHub Desktop.
Rollup this.addWatchFile bug in v1.21.0+

Setup

  1. clone/download this gist
  2. npm install

Repro

  1. npm start
  2. Note date value in ./out.js
  3. Change ./depdep.txt, date value in ./out.js doesn't change due to bug
  4. Swap order of ./dep.txt and ./first.js imports in ./index.js
  5. Change ./depdep.txt again, now the date value in ./out.js properly changes
export default "b";
// Since b.js comes first, and invalidate uses "return" inside a for...of loop instead of "continue",
// the search stops as soon as it checks b.js instead of continuining on and invalidating dep.txt
// If you swap the order of these imports changes to depdep.txt will properly invalidate/rebuild of dep.txt
import first from "./first.js";
import dep from "./dep.txt";
console.log(first, dep);
{
"name": "rollup-addwatchfile-issue",
"version": "1.0.0",
"description": "Example of a rollup .addWatchFile bug in v1.21.0+",
"main": "index.js",
"scripts": {
"start": "rollup --config --watch"
},
"author": "Pat Cavit <github@patcavit.com>",
"license": "MIT",
"devDependencies": {
"rollup": "^1.21.2"
}
}
"use strict";
module.exports = {
input : "./index.js",
output : {
format : "esm",
file : "./out.js",
},
watch : {
clearScreen : false,
},
plugins : [
{
name : "plugin",
transform(code, id) {
if(!id.includes("dep.txt")) {
return;
}
this.addWatchFile("./depdep.txt");
return `export default ${JSON.stringify((new Date().toString()))};`;
}
}
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment