Skip to content

Commit

Permalink
Merge branch 'master' into allow-outfile-in-new-directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwanders committed Jan 10, 2018
2 parents a0a81e9 + c668b99 commit 5c85031
Show file tree
Hide file tree
Showing 257 changed files with 6,969 additions and 655 deletions.
18 changes: 16 additions & 2 deletions .travis.yml
@@ -1,6 +1,20 @@
language: node_js
node_js:
- "0.8"
- "9"
- "8"
- "6"
- "4"
- "iojs"
- "0.12"
- "0.10"
- "0.8"
- "0.6"
before_install:
- npm install -g npm@~1.4.6
- 'nvm install-latest-npm'
install:
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
sudo: false
matrix:
fast_finish: true
allow_failures:
- node_js: "0.6"
2 changes: 1 addition & 1 deletion LICENSE
Expand Up @@ -29,7 +29,7 @@ buffer_ieee754.js has this license in it:

----

Copyright (c) 2008-2014, Fair Oaks Labs, Inc.
Copyright (c) 2008-2015, Fair Oaks Labs, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
Binary file added assets/browserify.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion bin/advanced.txt
Expand Up @@ -51,6 +51,24 @@ Advanced Options:
to just "__filename,__dirname". This is handy if you want to run bundles in
node.

--no-browser-field, --no-bf

Turn off package.json browser field resolution. This is also handy if you
need to run a bundle in node.

--transform-key

Instead of the default package.json#browserify#transform field to list
all transforms to apply when running browserify, a custom field, like, e.g.
package.json#browserify#production or package.json#browserify#staging
can be used, by for example running:
* `browserify index.js --transform-key=production > bundle.js`
* `browserify index.js --transform-key=staging > bundle.js`

--node

Alias for --bare and --no-browser-field.

--full-paths

Turn off converting module ids into numerical indexes. This is useful for
Expand All @@ -61,6 +79,10 @@ Advanced Options:
Instead of standard bundle output, print the dependency array generated by
module-deps.

--no-dedupe

Turn off deduping.

--list

Print each file in the dependency graph. Useful for makefiles.
Expand All @@ -70,7 +92,7 @@ Advanced Options:
Consider files with specified EXTENSION as modules, this option can used
multiple times.

--global-transform=MODULE, --g MODULE
--global-transform=MODULE, -g MODULE

Use a transform module on all files after any ordinary transforms have run.

Expand Down
71 changes: 48 additions & 23 deletions bin/args.js
Expand Up @@ -13,12 +13,14 @@ module.exports = function (args, opts) {
var argv = subarg(args, {
'boolean': [
'deps', 'pack', 'ig', 'dg', 'im', 'd', 'list', 'builtins',
'commondir', 'bare', 'full-paths', 'bundle-external'
'commondir', 'bare', 'full-paths', 'bundle-external', 'bf',
'node'
],
string: [ 's', 'r', 'u', 'x', 't', 'i', 'o', 'e', 'c', 'it' ],
alias: {
ig: [ 'insert-globals', 'fast' ],
dg: [ 'detect-globals', 'detectGlobals', 'dg' ],
bf: [ 'browser-field', 'browserField' ],
im: 'ignore-missing',
it: 'ignore-transform',
igv: 'insert-global-vars',
Expand All @@ -43,7 +45,10 @@ module.exports = function (args, opts) {
d: false,
builtins: true,
commondir: true,
'bundle-external': true
'bundle-external': true,
bf: true,
dedupe: true,
node: false
}
});

Expand All @@ -57,30 +62,52 @@ module.exports = function (args, opts) {
s.resume();
return rs;
}
return path.resolve(process.cwd(), entry);
return entry;
});

if (argv.node) {
argv.bare = true;
argv.browserField = false;
}
if (argv.bare) {
argv.builtins = false;
argv.commondir = false;
argv.detectGlobals = false;
if (argv.igv === undefined) {
argv.igv = '__filename,__dirname';
}
}


if (argv.igv) {
var insertGlobalVars = {};
var wantedGlobalVars = argv.igv.split(',');
Object.keys(insertGlobals.vars).forEach(function (x) {
if (wantedGlobalVars.indexOf(x) === -1) {
insertGlobalVars[x] = undefined;
}
});
}

var ignoreTransform = argv['ignore-transform'] || argv.it;
var b = browserify(xtend({
noParse: Array.isArray(argv.noParse) ? argv.noParse : [argv.noParse],
extensions: [].concat(argv.extension).filter(Boolean),
extensions: [].concat(argv.extension).filter(Boolean).map(function (extension) {
if (extension.charAt(0) != '.') {
return '.' + extension;
} else {
return extension
}
}),
ignoreTransform: [].concat(ignoreTransform).filter(Boolean),
entries: entries,
fullPaths: argv['full-paths'],
builtins: argv.builtins === false ? false : undefined,
commondir: argv.commondir === false ? false : undefined,
bundleExternal: argv['bundle-external'],
basedir: argv.basedir,

browserField: argv.browserField,
transformKey: argv['transform-key'] ? ['browserify', argv['transform-key']] : undefined,
dedupe: argv['dedupe'],

detectGlobals: argv.detectGlobals,
insertGlobals: argv['insert-globals'] || argv.ig,
insertGlobalVars: insertGlobalVars,
Expand Down Expand Up @@ -134,16 +161,16 @@ module.exports = function (args, opts) {

[].concat(argv.require).filter(Boolean)
.forEach(function (r) {
var xs = r.split(':');
var xs = splitOnColon(r);
b.require(xs[0], { expose: xs.length === 1 ? xs[0] : xs[1] })
})
;

// resolve any external files and add them to the bundle as externals
[].concat(argv.external).filter(Boolean)
.forEach(function (x) {
if (/:/.test(x)) {
var xs = x.split(':');
var xs = splitOnColon(x);
if (xs.length === 2) {
add(xs[0], { expose: xs[1] });
}
else if (/\*/.test(x)) {
Expand Down Expand Up @@ -225,20 +252,18 @@ module.exports = function (args, opts) {
return b;
}

var insertGlobalVars;
if (argv.igv) {
insertGlobalVars = argv.igv.split(',').reduce(function (vars, x) {
vars[x] = insertGlobals.vars[x];
return vars;
}, {});
}

return b;
};

function copy (obj) {
return Object.keys(obj).reduce(function (acc, key) {
acc[key] = obj[key];
return acc;
}, {});
function splitOnColon (f) {
var pos = f.lastIndexOf(':');
if (pos == -1) {
return [f]; // No colon
} else {
if ((/[a-zA-Z]:[\\/]/.test(f)) && (pos == 1)){
return [f]; // Windows path and colon is part of drive name
} else {
return [f.substr(0, pos), f.substr(pos + 1)];
}
}
}
26 changes: 16 additions & 10 deletions bin/cmd.js
Expand Up @@ -22,7 +22,7 @@ if (b.argv._[0] === 'help' || b.argv.h || b.argv.help
.on('close', function () { process.exit(1) })
;
}
if (b.argv.v || b.argv.version) {
if (b.argv.version) {
return console.log(require('../package.json').version);
}

Expand Down Expand Up @@ -56,25 +56,25 @@ if (b.argv.list) {

var bundle = b.bundle();
bundle.on('error', errorExit);
bundle.on('end', successExit);

var tmpfile;
var outfile = b.argv.o || b.argv.outfile;
if (outfile) {
mkdirp.sync(path.dirname(outfile));
bundle.pipe(fs.createWriteStream(outfile));

// we'll output to a temp file within same filesystem, then atomically overwrite outfile once successful
tmpfile = outfile + ".tmp-browserify-" + Math.random().toFixed(20).slice(2)
bundle.pipe(fs.createWriteStream(tmpfile));
}
else {
bundle.pipe(process.stdout);
}

function packageFilter (info) {
if (info && typeof info.browserify === 'string' && !info.browser) {
info.browser = info.browserify;
delete info.browserify;
}
return info || {};
}

function errorExit(err) {
if (tmpfile) fs.unlink(tmpfile, function (err) {
if (err) /* no-op, we're already exiting unhappily… */;
});
if (err.stack) {
console.error(err.stack);
}
Expand All @@ -83,3 +83,9 @@ function errorExit(err) {
}
process.exit(1);
}

function successExit() {
if (tmpfile && outfile) fs.rename(tmpfile, outfile, function (err) {
if (err) errorExit(err);
});
}

0 comments on commit 5c85031

Please sign in to comment.