Skip to content

Instantly share code, notes, and snippets.

@ngryman
Last active May 26, 2016 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngryman/52ca69f809d4c38f4cdb4db710de3592 to your computer and use it in GitHub Desktop.
Save ngryman/52ca69f809d4c38f4cdb4db710de3592 to your computer and use it in GitHub Desktop.
Browserify incremental memory cache bug
'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)
{
"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