From 9f1ed709d05286df519061cc34199c3e455cb200 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 3 Feb 2014 19:05:22 -0500 Subject: [PATCH] Revert "Switched from browserify to pure-cjs bundler." This reverts commit bff9731b66093239dc0408fb1d83df423925b6f9. --- grunt/tasks/browserify.js | 55 ++++++++++++++++++++++++++++----------- package.json | 2 +- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/grunt/tasks/browserify.js b/grunt/tasks/browserify.js index 9a0eea744b..e36c545e17 100644 --- a/grunt/tasks/browserify.js +++ b/grunt/tasks/browserify.js @@ -1,6 +1,6 @@ 'use strict'; -var cjs = require('pure-cjs'); +var browserify = require('browserify'); var grunt = require('grunt'); module.exports = function() { @@ -18,26 +18,51 @@ module.exports = function() { config.after = [config.after]; } - // Extract options + // create the bundle we'll work with + var entries = grunt.file.expand(config.entries); + var bundle = browserify(entries); + + // Make sure the things that need to be exposed are. + var requires = config.requires || {}; + if (requires instanceof Array) { + grunt.file.expand({ + nonull: true, // Keep IDs that don't expand to anything. + cwd: "src" + }, requires).forEach(function(name) { + bundle.require("./build/modules/" + name, { + expose: name.replace(/\.js$/i, "") + }); + }); + } else if (typeof requires === "object") { + Object.keys(requires).forEach(function(name) { + bundle.require(requires[name], { expose: name }); + }); + } + + // Extract other options var options = { - input: config.entries[0], - output: config.outfile, - map: config.debug, // sourcemaps - exports: config.standalone, // global - transform: config.transforms, - dryRun: true // we will write to disk ourselves + debug: config.debug, // sourcemaps + standalone: config.standalone // global }; + // TODO: make sure this works, test with this too + config.transforms.forEach(function(transform) { + bundle.transform({}, transform); + }); + // Actually bundle it up var _this = this; - cjs.transform(options).then(function(result) { - grunt.file.write(config.outfile, config.after.reduce(function(src, fn) { - return fn.call(_this, src); - }, result.code)); + bundle.bundle(options, function(err, src) { + if (err) { + grunt.log.error(err); + done(); + } - done(); - }, function(err) { - grunt.log.error(err); + config.after.forEach(function(fn) { + src = fn.call(_this, src); + }); + + grunt.file.write(config.outfile, src); done(); }); }; diff --git a/package.json b/package.json index 21d9b71b8c..1d89f67fa7 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ }, "devDependencies": { "benchmark": "~1.0.0", + "browserify": "~3.20.0", "coverify": "~1.0.4", "envify": "~1.0.1", "es5-shim": "~2.3.0", @@ -59,7 +60,6 @@ "phantomjs": "~1.9", "platform": "~1.0.0", "populist": "~0.1.6", - "pure-cjs": "~1.8.0", "recast": "~0.5.6", "sauce-tunnel": "~1.1.0", "semver": "~2.2.1",