Permalink
Browse files

Add fullPaths option.

Completely preserves the original module ids, instead of
converting them to numerical indices. Useful for analysing
a bundle after it's created, making the browser-unpack
module a viable standard approach for picking apart
bundle contents.
  • Loading branch information...
1 parent be339cd commit d9fb285d3cd81dbe14cc2ead0dada58b1900d49e @hughsk hughsk committed with Feb 22, 2014
Showing with 61 additions and 3 deletions.
  1. +5 −0 bin/advanced.txt
  2. +2 −1 bin/args.js
  3. +5 −1 index.js
  4. +2 −1 package.json
  5. +8 −0 readme.markdown
  6. +39 −0 test/full_paths.js
View
@@ -46,6 +46,11 @@ Advanced Options:
to just "__filename,__dirname". This is handy if you want to run bundles in
node.
+ --full-paths
+
+ Turn off converting module ids into numerical indexes. This is useful for
+ preserving the original paths that a bundle was generated with.
+
--deps
Instead of standard bundle output, print the dependency array generated by
View
@@ -11,7 +11,7 @@ module.exports = function (args) {
var argv = subarg(args, {
'boolean': [
'deps','pack','ig','dg', 'im', 'd','list',
- 'builtins','commondir', 'bare'
+ 'builtins','commondir', 'bare', 'full-paths'
],
string: [ 's' ],
alias: {
@@ -62,6 +62,7 @@ module.exports = function (args) {
noParse: [].concat(argv.noparse).filter(Boolean),
extensions: [].concat(argv.extension).filter(Boolean),
entries: entries,
+ fullPaths: argv['full-paths'],
builtins: argv.builtins === false ? false : undefined,
commondir: argv.commondir === false ? false : undefined
});
View
@@ -76,7 +76,8 @@ function Browserify (opts) {
var sep = /^win/i.test(process.platform) ? ';' : ':';
self._paths = opts.paths || (process.env.NODE_PATH || '').split(sep);
-
+ self._fullPaths = !!opts.fullPaths;
+
self._browserPack = opts.pack || function (params) {
params.raw = true;
params.sourceMapPrefix = '//#';
@@ -555,6 +556,9 @@ Browserify.prototype.pack = function (opts) {
else if (self._expose[row.id]) {
return row.id;
}
+ else if (self._fullPaths) {
+ return row.id;
+ }
else if (row.index === undefined) {
return row.id;
}
View
@@ -73,7 +73,8 @@
"dnode": "~1.0.3",
"seq": "0.3.3",
"coffee-script": "~1.5.0",
- "coffeeify": "~0.6.0"
+ "coffeeify": "~0.6.0",
+ "browser-unpack": "0.0.0"
},
"author": {
"name": "James Halliday",
View
@@ -145,6 +145,11 @@ Advanced Options:
to just "__filename,__dirname". This is handy if you want to run bundles in
node.
+ --full-paths
+
+ Turn off converting module ids into numerical indexes. This is useful for
+ preserving the original paths that a bundle was generated with.
+
--deps
Instead of standard bundle output, print the dependency array generated by
@@ -347,6 +352,9 @@ filenames that start with `.`.
`false` to turn this off, otherwise it uses the
[commondir](https://npmjs.or/package/commondir) module.
+`opts.fullPaths` disables converting module ids into numerical indexes. This is
+useful for preserving the original paths that a bundle was generated with.
+
`opts.builtins` sets the list of builtins to use, which by default is set in
`lib/builtins.js` in this distribution.
View
@@ -0,0 +1,39 @@
+var unpack = require('browser-unpack');
+var browserify = require('../');
+var test = require('tap').test;
+
+var deps = [
+ __dirname + '/entry/main.js',
+ __dirname + '/entry/one.js',
+ __dirname + '/entry/two.js'
+];
+
+test('fullPaths enabled', function (t) {
+ t.plan(3);
+
+ var b = browserify({
+ entries: [ deps[0] ],
+ fullPaths: true
+ });
+
+ b.bundle(function (err, src) {
+ unpack(src).forEach(function(dep) {
+ t.notEqual(deps.indexOf(dep.id), -1, 'full path name for dep.id');
+ });
+ });
+});
+
+test('fullPaths disabled', function (t) {
+ t.plan(3);
+
+ var b = browserify({
+ entries: [ deps[0] ],
+ fullPaths: false
+ });
+
+ b.bundle(function (err, src) {
+ unpack(src).forEach(function(dep) {
+ t.equal(deps.indexOf(dep.id), -1, 'full path name no longer available');
+ });
+ });
+});

0 comments on commit d9fb285

Please sign in to comment.