From 29d637930983a52076d458c8ca7b2963e60484f8 Mon Sep 17 00:00:00 2001 From: Joey Baker Date: Fri, 11 Sep 2015 10:02:13 -0700 Subject: [PATCH 1/3] Install rebundler as a dev dep --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0e57907..f5536ff 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "devDependencies": { "browserify": "^11.0.1", "proxyquire": "^1.6.0", + "rebundler": "^0.2.0", "tape": "^4.0.1" }, "scripts": { From 6ff4ef83a4efd6d4ec1fbf0cb05532b93e6b0841 Mon Sep 17 00:00:00 2001 From: Joey Baker Date: Fri, 11 Sep 2015 10:02:51 -0700 Subject: [PATCH 2/3] internal: add failing test for re-bundling #32 --- tests/cache.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/cache.js diff --git a/tests/cache.js b/tests/cache.js new file mode 100644 index 0000000..45c3c59 --- /dev/null +++ b/tests/cache.js @@ -0,0 +1,49 @@ +var tape = require('tape'); + +var browserify = require('browserify'); +var proxyquire = require('proxyquire'); +var fs = require('fs'); +var path = require('path'); +var rebundler = require('rebundler'); + +var casesDir = path.join(__dirname, 'cases'); +var simpleCaseDir = path.join(casesDir, 'simple'); +var cssOutFilename = 'out.css'; + +tape('multiple builds', function (t) { + var fakeFs = { + writeFile: function (filename, content, cb) { + var expected = fs.readFileSync(path.join(simpleCaseDir, 'expected.css'), 'utf8'); + + t.equal(filename, cssOutFilename, 'correct output filename'); + t.equal(content, expected, 'output matches expected'); + cb(); + } + }; + + var cssModulesify = proxyquire('../', { + fs: fakeFs + }); + + var getBundler = rebundler(function (cache, packageCache) { + return browserify(path.join(simpleCaseDir, 'main.js'), { + cache: cache + , packageCache: packageCache + , fullPaths: true + }) + .plugin(cssModulesify, { + rootDir: path.join(simpleCaseDir) + , output: cssOutFilename + }); + }); + + getBundler().bundle(function (err) { + t.error(err, 'initial bundle without a cache does not error'); + + getBundler().bundle(function (err2) { + t.error(err2, 'second pass bundle with a cache does not error'); + + t.end(); + }); + }); +}); From 194a6c6de3a8b7483f25f8b8ce565586cc55a2f4 Mon Sep 17 00:00:00 2001 From: Joey Baker Date: Fri, 11 Sep 2015 10:07:00 -0700 Subject: [PATCH 3/3] fix #32: ensure caches are persisted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the caches were re-initialized on every plugin initialization. This caused an incompatibility with other tools like rebundler or persistify. This change keeps the original intent of creating caches when the plugin is initialized, but ensures the process keeps the caches instead of the plugin instance itself. It’s not really possible to have a cache conflict since they’re keyed by file. --- index.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 9b6195d..0d21473 100644 --- a/index.js +++ b/index.js @@ -37,6 +37,22 @@ function normalizeManifestPaths (tokensByFile, rootDir) { } var cssExt = /\.css$/; + +// caches +// +// persist these for as long as the process is running. #32 + +// keep track of css files visited +var filenames = []; + +// keep track of all tokens so we can avoid duplicates +var tokensByFile = {}; + +// keep track of all source files for later builds: when +// using watchify, not all files will be caught on subsequent +// bundles +var sourceByFile = {}; + module.exports = function (browserify, options) { options = options || {}; @@ -91,17 +107,6 @@ module.exports = function (browserify, options) { return plugin; }); - // keep track of css files visited - var filenames = []; - - // keep track of all tokens so we can avoid duplicates - var tokensByFile = {}; - - // keep track of all source files for later builds: when - // using watchify, not all files will be caught on subsequent - // bundles - var sourceByFile = {}; - function transform (filename) { // only handle .css files if (!cssExt.test(filename)) {