Permalink
Browse files

new --debug mode using //@ sourceURL=...

  • Loading branch information...
1 parent 87d0bee commit 04e2c4ee9598f6532bd87bf6bce4b995b544ec07 @substack substack committed Jan 17, 2012
Showing with 31 additions and 10 deletions.
  1. +11 −1 bin/cli.js
  2. +1 −1 index.js
  3. +14 −7 lib/wrap.js
  4. +1 −1 wrappers/body.js
  5. +4 −0 wrappers/body_debug.js
View
@@ -38,6 +38,11 @@ var argv = require('optimist')
+ 'or use a file for caching.\n',
default : true,
})
+ .option('debug', {
+ alias : 'd',
+ desc : 'Switch on debugging mode with //@ sourceURL=...s.',
+ type : 'boolean'
+ })
.option('plugin', {
alias : 'p',
desc : 'Use a plugin. Use a colon separator to specify additional '
@@ -73,7 +78,12 @@ var argv = require('optimist')
.argv
;
-var bundle = browserify({ watch : argv.watch, cache : argv.cache });
+var bundle = browserify({
+ watch : argv.watch,
+ cache : argv.cache,
+ debug : argv.debug
+});
+
if (argv.noprelude || argv.prelude === false) {
bundle.files = [];
bundle.prepends = [];
View
@@ -46,7 +46,7 @@ var exports = module.exports = function (entryFile, opts) {
}
var watches = {};
- var w = wrap({ cache : opts.cache })
+ var w = wrap({ cache : opts.cache, debug : opts.debug })
.register('.coffee', function (body) {
return coffee.compile(body)
})
View
@@ -45,6 +45,7 @@ function Wrap (opts) {
this.prepends = [ wrappers.prelude, wrappers.process ];
this.appends = []
this.entries = {};
+ this.debug = opts.debug;
this.require([ 'path' ]);
}
@@ -157,6 +158,7 @@ Wrap.prototype.addEntry = function (file, opts) {
});
this.entries[file] = this.appends.length;
+
this.append(wrappers.entry
.replace(/\$__filename/g, function () {
return JSON.stringify(opts.target || file.slice(dir.length))
@@ -218,13 +220,18 @@ Wrap.prototype.bundle = function () {
};
Wrap.prototype.wrap = function (target, body) {
- return wrappers.body
- .replace(/\$__filename/g, function () {
- return JSON.stringify(target);
- })
- .replace(/\$body/, function () {
- return body.toString();
- });
+ var self = this;
+ return (self.debug ? wrappers.body_debug : wrappers.body)
+ .replace(/\$__filename/g, function () {
+ return JSON.stringify(target);
+ })
+ .replace(/\$body/, function () {
+ return self.debug
+ ? JSON.stringify('//@ sourceURL=' + target + '\n' + body)
+ : body
+ ;
+ })
+ ;
};
Wrap.prototype.include = function (file, target, body, root) {
View
@@ -1,3 +1,3 @@
require.define($__filename, function (require, module, exports, __dirname, __filename) {
- $body
+$body
});
View
@@ -0,0 +1,4 @@
+require.define($__filename, Function(
+ [ 'require', 'module', 'exports', '__dirname', '__filename' ],
+ $body
+));

0 comments on commit 04e2c4e

Please sign in to comment.