Skip to content

Commit

Permalink
Simplify cache process. Fixes #42 (#43)
Browse files Browse the repository at this point in the history
* Try using a plain JS object to solve cache object memory leak

* Use object properties to enable multiple rollup tasks.
  • Loading branch information
halfnibble authored and MikeKovarik committed Mar 21, 2019
1 parent 5958ad6 commit 3eae3d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ try {
}

// map object storing rollup cache objects for each input file
var rollupCache = new Map
var rollupCache = {}

function parseBundles(arg) {
if (typeof arg == 'string')
Expand Down Expand Up @@ -65,7 +65,7 @@ class GulpRollup extends Transform {
// caching is enabled by default because of the nature of gulp and the watching/recompilatin
// but can be disabled by setting 'cache' to false
if (inputOptions.cache !== false)
inputOptions.cache = rollupCache.get(inputOptions.input)
inputOptions.cache = rollupCache[inputOptions.input] || null

// enable sourcemap is gulp-sourcemaps plugin is enabled
var createSourceMap = file.sourceMap !== undefined
Expand Down Expand Up @@ -162,15 +162,15 @@ class GulpRollup extends Transform {
.then(bundle => {
// cache rollup object if caching is enabled
if (inputOptions.cache !== false)
rollupCache.set(inputOptions.input, bundle)
rollupCache[inputOptions.input] = bundle
// generate ouput according to (each of) given outputOptions
return Promise.all(bundleList.map((outputOptions, i) => createBundle(bundle, outputOptions, i)))
})
// pass file to gulp and end stream
.then(() => cb(null, file))
.catch(err => {
if (inputOptions.cache !== false)
rollupCache.delete(inputOptions.input)
rollupCache[inputOptions.input] = null
process.nextTick(() => {
this.emit('error', new PluginError(PLUGIN_NAME, err))
cb(null, file)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-better-rollup",
"version": "4.0.0",
"version": "4.0.1",
"description": "Better Gulp plugin for Rollup ES6 module bundler",
"author": "Mike Kovarik",
"license": "MIT",
Expand Down

0 comments on commit 3eae3d1

Please sign in to comment.