Last active
May 26, 2016 17:57
-
-
Save ngryman/52ca69f809d4c38f4cdb4db710de3592 to your computer and use it in GitHub Desktop.
Browserify incremental memory cache bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const browserify = require('browserify') | |
const concat = require('concat-stream') | |
const delay = require('delay') | |
const fs = require('fs') | |
const incremental = require('browserify-incremental') | |
const forceMode = '--force' === process.argv[2] | |
let bundler, builds = 0 | |
function bundle() { | |
if (forceMode || !bundler) { | |
bundler = browserify(Object.assign({ | |
entries: 'bundle.js' | |
}, incremental.args)) | |
incremental(bundler) | |
} | |
return new Promise(resolve => { | |
console.time('Bundle') | |
bundler.bundle() | |
.pipe(concat( | |
d => { | |
console.timeEnd('Bundle') | |
if (d.toString().match(/alert\("yay"\)/g).length !== ++builds) { | |
console.error('Not updated') | |
} | |
resolve() | |
} | |
)) | |
}) | |
} | |
function createMainEntry() { | |
return new Promise(resolve => { | |
fs.writeFile('bundle.js', 'alert("yay")\n', resolve) | |
}) | |
} | |
function updateMainEntry() { | |
return new Promise(resolve => { | |
fs.appendFile('bundle.js', 'alert("yay")\n', resolve) | |
}) | |
} | |
function deleteMainEntry() { | |
return new Promise(resolve => { | |
fs.unlink('bundle.js', resolve) | |
}) | |
} | |
Promise.resolve() | |
.then(createMainEntry) | |
.then(bundle) | |
.then(updateMainEntry) | |
.then(delay(2000)) | |
.then(bundle) | |
.then(deleteMainEntry) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"browserify": "^13.0.1", | |
"browserify-incremental": "^3.1.1", | |
"delay": "^1.3.1", | |
"stream-assert": "^2.0.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment