diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..d8b83df9c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +package-lock.json diff --git a/.npmrc b/.npmrc new file mode 100644 index 000000000..43c97e719 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml index 74c57bf15..0ad727779 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,23 @@ language: node_js node_js: - - "0.8" - - "0.10" - - "0.12" + - "10" + - "9" + - "8" + - "6" + - "4" - "iojs" + - "0.12" + - "0.10" + - "0.8" + - "0.6" before_install: - - npm install -g npm@~1.4.6 + # Old npm certs are untrusted https://github.com/npm/npm/issues/20191 + - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.8" ]; then export NPM_CONFIG_STRICT_SSL=false; fi' + - '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" diff --git a/LICENSE b/LICENSE index c9016780d..eff138cad 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,24 @@ +This software is released under the MIT license: + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--- + Some pieces from builtins/ taken from node core under this license: ---- @@ -29,7 +50,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 diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..d4dac1bd9 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,27 @@ +environment: + matrix: + - nodejs_version: "10" + - nodejs_version: "9" + - nodejs_version: "8" + - nodejs_version: "6" + - nodejs_version: "4" + - nodejs_version: "0.12" + - nodejs_version: "0.10" + +# Install scripts. (runs after repo cloning) +install: + # Get the latest stable version of Node.js or io.js + - ps: Install-Product node $env:nodejs_version + # install modules + - npm install + +# Post-install test scripts. +test_script: + # Output useful info for debugging. + - node --version + - npm --version + # run tests + - npm test + +# Don't actually build. +build: off diff --git a/assets/browserify.png b/assets/browserify.png new file mode 100644 index 000000000..56a8f741d Binary files /dev/null and b/assets/browserify.png differ diff --git a/assets/logo.png b/assets/logo.png new file mode 100644 index 000000000..98d6bf5f6 Binary files /dev/null and b/assets/logo.png differ diff --git a/bin/advanced.txt b/bin/advanced.txt index 23ed10f31..b23688c34 100644 --- a/bin/advanced.txt +++ b/bin/advanced.txt @@ -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 @@ -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. @@ -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. @@ -78,6 +100,10 @@ Advanced Options: Register MODULE as a plugin. + --preserve-symlinks + + Preserves symlinks when resolving modules. + Passing arguments to transforms and plugins: For -t, -g, and -p, you may use subarg syntax to pass options to the diff --git a/bin/args.js b/bin/args.js index d9fd01ccc..130ace75b 100644 --- a/bin/args.js +++ b/bin/args.js @@ -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', 'preserve-symlinks' ], 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', @@ -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 } }); @@ -57,22 +62,31 @@ module.exports = function (args, opts) { s.resume(); return rs; } - return path.resolve(process.cwd(), entry); + return entry; }); - - 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({ + node: argv.node, + bare: argv.bare, 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'], @@ -80,7 +94,11 @@ module.exports = function (args, opts) { 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'], + preserveSymlinks: argv['preserve-symlinks'], + detectGlobals: argv.detectGlobals, insertGlobals: argv['insert-globals'] || argv.ig, insertGlobalVars: insertGlobalVars, @@ -225,24 +243,9 @@ 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) { diff --git a/bin/cmd.js b/bin/cmd.js index d61bf1ea9..1a63b19ac 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -2,6 +2,8 @@ var fs = require('fs'); var JSONStream = require('JSONStream'); var through = require('through2'); +var mkdirp = require('mkdirp'); +var path = require('path'); var b = require('./args')(process.argv.slice(2)); process.stdout.on('error', process.exit); @@ -20,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); } @@ -54,24 +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) { - bundle.pipe(fs.createWriteStream(outfile)); + mkdirp.sync(path.dirname(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); } @@ -80,3 +83,9 @@ function errorExit(err) { } process.exit(1); } + +function successExit() { + if (tmpfile && outfile) fs.rename(tmpfile, outfile, function (err) { + if (err) errorExit(err); + }); +} diff --git a/changelog.markdown b/changelog.markdown index 4cbbdb7be..ec63d8c91 100644 --- a/changelog.markdown +++ b/changelog.markdown @@ -1,3 +1,393 @@ +# 16.2.3 + +add empty stub for the `inspector` builtin module. + +https://github.com/browserify/browserify/pull/1854 + +change the "browser" field link to the browser-field-spec repo instead of the old gist. + +https://github.com/browserify/browserify/pull/1845 + +# 16.2.2 + +Remove some extraneous files from the published package. + +# 16.2.1 + +Fix relative `--external` paths on Windows. + +https://github.com/browserify/browserify/pull/1704 + +Fix tests to work on Windows, and add Appveyor CI for Windows testing. + +https://github.com/browserify/browserify/pull/1819 + +# 16.2.0 + +update the browser versions of `vm-browserify` and `string_decoder`. + +`string_decoder` updates to the Node 8+ API. +`vm-browserify` replaces an unlicensed dependency by an MIT one. + +https://github.com/browserify/browserify/pull/1829 + +# 16.1.1 + +add empty stub for the `perf_hooks` builtin module. + +https://github.com/browserify/browserify/pull/1815 + +# 16.1.0 + +add `bare` and `node` options to the API, same as the `--bare` and `--node` CLI arguments. + +https://github.com/browserify/browserify/pull/1804 + +# 16.0.0 + +add `--preserve-symlinks` option from Node 6.3 + +https://github.com/browserify/browserify/pull/1742 +https://github.com/browserify/browserify/pull/1801 + +update the browser version of `events` to 2.0.0—this version adds methods like `prependListener` that were introduced in recent node versions, but it is also twice the size of events v1.x (2KB instead of 1KB). + +https://github.com/browserify/browserify/pull/1803 + +Dynamically calculate `__dirname` and `__filename` when `--node` is passed + +https://github.com/browserify/browserify/pull/1725 + +upgrade module-deps, see https://github.com/browserify/module-deps/releases/tag/v6.0.0 + +https://github.com/browserify/browserify/commit/e5e1ec8799f1007a56118ae46646e0048385ed84 + +# 15.2.0 + +create parent directories if they do not exist when `--outfile /x/y/z/bundle.js` is used + +https://github.com/browserify/browserify/pull/995 + +add regression test for object rest spread syntax + +https://github.com/browserify/browserify/pull/1798 + +# 15.1.0 + +restore support for node `< 4.0` until we can decide on a support schedule + +# 15.0.0 + +fixed repository url in package.json. + +https://github.com/browserify/browserify/commit/5ec19eed48a5f46cb48d44be8ffc2f6bfb73fbfb + +update `module-deps` to 5.0.0, which enables requiring modules in backtick-enclosed strings. + +https://github.com/browserify/browserify/pull/1785 + +dropped testing in node 0.10 and 0.12, set supported node versions to `>=4` + +https://github.com/browserify/browserify/pull/1743 +https://github.com/browserify/browserify/pull/1793 + +add support for passing arrays to the `exclude` and `ignore` methods. + +https://github.com/browserify/browserify/pull/1769 + +# 14.5.0 + +update `os-browserify` to 0.3.0, which adds a shim for node.js's `os.homedir` method. + +https://github.com/browserify/browserify/pull/1767 + +update `browserify-zlib` to 0.2.0, which adds support for dictionaries. + +https://github.com/browserify/browserify/pull/1733 + +# 14.4.0 + +update `string_decoder` to 1.0.0, which matches the latest node.js behavior more closely. + +https://github.com/substack/node-browserify/pull/1714 + +# 14.3.0 + +update `https-browserify` to 1.0.0, which matches node.js behavior more closely. + +- throw exception if non-https URL is passed to `https.request` or `https.get` +- support passing string URL as first argument to `https.request` and `https.get` + +https://github.com/substack/node-browserify/pull/1710 + +# 14.2.0 + +adds a --transform-key flag to the command-line tool + +https://github.com/substack/node-browserify/pull/1709 + +# 14.1.0 + +writes to a temp outfile until success + +Previously, browserify would overwrite output files when an error occurs. + +https://github.com/substack/node-browserify/pull/1673 +https://github.com/substack/node-browserify/issues/899 + +# 14.0.0 + +Updates the version of the buffer package, which drops support for IE8-10. + +buffer v5 removes the `Object` implementation and relies on a single, +fast Typed Array (`Uint8Array`) implementation, greatly simplifying the +maintanence of the buffer package. + +If IE8-10 support is critical to your web app, you can continue to rely on +browserify v13, or see the PR for other workarounds. + +https://github.com/substack/node-browserify/pull/1678 + +# 13.3.0 + +updates the version for the assert package + +https://github.com/substack/node-browserify/pull/1611 + +# 13.2.0 + +allow configuring transformKey from module-deps +https://github.com/substack/node-browserify/pull/1670 + +# 13.1.1 + +boost performance by memoizing calls to path.relative() + +https://github.com/substack/node-browserify/pull/1544 + +# 13.1.0 + +exposes `opts.dedupe` and `--no-deupe` to optionally turn off deduping behavior: +[#1581](https://github.com/substack/node-browserify/pull/1581) + +# 13.0.1 + +## Internal + +[#1552](https://github.com/substack/node-browserify/pull/1552), [#1555](https://github.com/substack/node-browserify/pull/1555): Use native `Array.isArray` and drop `isarray` dep. ([@kt3k](https://github.com/kt3k)) + +# 13.0.0 + +This release bumps the [`buffer`](https://www.npmjs.com/package/buffer) dependency +to v4, which has one possible breaking change: + +- The `buffer.toArrayBuffer()` method on `Buffer` instances has been removed. + +(This is probably not a problem for 99.9% of users.) + +This API was added in node v0.11.8 and +[removed before v0.12 was released](https://github.com/nodejs/node-v0.x-archive/issues/7609#issuecomment-42903457). +It was added to browserify's `buffer` implementation but was never removed when v0.12 + was released. `buffer` v4 removes it so we have full parity with node.js. + +Going forward, to get an `ArrayBuffer` from a node.js-style `Buffer`, users should +just use `buffer.buffer`. This works because `Buffer` is a subclass of `Uint8Array` +in both the browser and node.js (since v3). + +On the plus side, this release also includes: + +- Performance improvements to `buffer` that +[increase the speed](https://github.com/feross/buffer/pull/92) of some buffer +methods by as much as 30%! + +# 12.0.2 + +normalizes module paths on windows to consistently use `/` + +https://github.com/substack/node-browserify/pull/1424#issuecomment-170143099 + +# 12.0.1 + +adds the previously failing tests and a small change necessary for transforms to +be applied properly for symlinked packages + +https://github.com/substack/node-browserify/pull/1392 + +# 12.0.0 + +Node support changes: now testing against the latest node (currently 4.2.1). +node 0.8 is no longer supported, and iojs isn't actively tested. + +Stream3 everywhere! Everything has been updated to use streams3. + +Sourcemaps charset now uses an `=` instead of a `:`. This fixes certain issues +with Chinese characters in sourcemaps. See #753. + +module-deps has been updated to fix root transforms on symlinked modules. See +https://github.com/substack/module-deps/pull/99. + +stream-http, the module that provides `http` support, dropped IE8 support. If +you depend on this, see https://github.com/jhiesey/stream-http#ie8-note. + +Removed `builtins` and `commondir` – both unused dependencies. + +# 11.2.0 + +When `bundleExternal` is set to `false`, `process` and `buffer` are now correctly excluded. Also, using `--igv` via the CLI now works. That also means that `--bare` and `--node` actually insert `__filename` and `__dirname`. + +https://github.com/substack/node-browserify/pull/1361 + +# 11.1.0 + +adds a `'.'` to extensions if it wasn't added + +https://github.com/substack/node-browserify/pull/1380 + +# 11.0.1 + +The callback form of bundle() uses the returned output stream instead of the +pipeline so that the `'end'` event will fire on the bundle instance. + +https://github.com/substack/watchify/pull/249#issuecomment-126061169 + +# 11.0.0 + +## streams3 + +The [`readable-stream`](https://npmjs.com/package/readable-stream) dependency was updated to `^2.0.0`. This package is inserted into bundles as `require('stream')`. Bundles will now get the latest streams implementation from io.js/node.js core, instead of an old version from node.js 0.11.x. Go forth and stream ALL THE DATA without fear! + +## shiny new HTTP package + +[John Hiesey](https://github.com/jhiesey) rewrote the [http-browserify](https://npmjs.org/package/http-browserify) package +to create [stream-http](https://npmjs.org/package/stream-http), an implemention of `http` that supports streaming in modern browsers. Before v11.0.0, in most situations when you used `http.get` or `http.request`, the entire request would buffer in memory until the download was complete, and a single `'data'` event was emitted with the entire response as a string. + +`stream-http` uses the [Fetch API](https://fetch.spec.whatwg.org/) and various browser-specific XHR extensions to make binary streaming http requests work in as many browsers as possible. + +The following browsers support true streaming, where only a small amount of the request has to be held in memory at once: + +* Chrome >= 43 (using the `fetch` api) +* Firefox >= 9 (using `moz-chunked-arraybuffer` responseType with XHR) + +The following browsers support pseudo-streaming, where the data is available before the request finishes, but the entire response must be held in memory: + +* Safari >= 5 +* IE >= 10 +* Most other Webkit-based browsers, including the default Android browser + +Older browsers will work, without streaming support. There is no support for IE6 or IE7. + +Compared to `http-browserify`, it is not necessary to set `options.responseType`. The `responseType` property of the XHR object will be set automatically depending on what features are detected in the browser (although see `options.mode` in the [readme](https://github.com/jhiesey/stream-http) to see how you can optimize this choice manually). + +The `response` is a streams3 stream, so all data is passed as `Buffer`s, unlike the variable types provided by the `'data'` event in `http-browserify`. This behavior tries to mimic the node core `http` module as closely as possible. + +* [#1327](https://github.com/substack/node-browserify/pull/1327) + +If you're brave, go ahead and give v11.0.0 a try today! + +# 10.2.6 + +uses the non-sync version of fs.realpath + +# 10.2.5 + +fixes an issue with symlinked files executing multiple times + +https://github.com/substack/node-browserify/issues/1063 +https://github.com/substack/node-browserify/pull/1318 + +# 10.2.4 + +fixes requiring an entry from another entry + +remove unused dep "deep-equal" and unused file "lib/_exclude.js" + +https://github.com/substack/node-browserify/pull/1268 + +# 10.2.3 + +fixes an errant space in the `--no-browser-field` flag alias +that kept it from working + +https://github.com/substack/node-browserify/issues/1286 + +# 10.2.2 + +fix tests for tap@^1.1.0 (and update tap) + +https://github.com/substack/node-browserify/pull/1276 + +# 10.2.1 + +housekeeping - removed unused code + +https://github.com/substack/node-browserify/pull/1273 + +# 10.2.0 + +remove unnecessary "isDedupe" json check. this was a hack-fix for watchify <=2.4. + +https://github.com/substack/node-browserify/pull/1244 + +fixes for the "noParse" path matcher. + +https://github.com/substack/node-browserify/pull/1259 + +add syntax check cache. this speeds up rebuilds (like when using watchify). + +https://github.com/substack/node-browserify/pull/1253 + +update to browser-pack@^5.0.0 - includes several fixes related to source maps. + +https://github.com/substack/node-browserify/pull/1257 + +# 10.1.3 + +Replace jsonstream with JSONStream + +https://github.com/substack/node-browserify/pull/1252 + +# 10.1.2 + +Replace JSONStream with jsonstream +Update deps to avoid jsonstream npm case problems + +https://github.com/substack/node-browserify/pull/1247 +https://github.com/substack/node-browserify/commit/1ca71e23 + +# 10.1.1 + +ensures that entry paths are always full paths + +https://github.com/substack/node-browserify/pull/1248 + +# 10.1.0 + +adds `--no-browser-field` and `opts.browserField = false` behavior to turn off +the package.json browser field. This is useful if you want to make a bundle with +a target of node or some environment with shimmed node primitives. + +A new alias `--node` sets `--no-browser-field` and `--bare`. + +https://github.com/substack/node-browserify/pull/1240 + +# 10.0.0 + +## Possibly Breaking Change +The ‘process’ dependency was updated to ~0.11.0, this module is inserted into bundles as the ‘process’ global/dependency. +Previously, an unhandled error thrown in a ‘process.nextTick’ task would prevent any subsequent tasks from running, forever. +The task queue now recovers from this condition, but may do so on a future browser tick. +As part of this update, ‘process.nextTick’ now accepts variadic arguments, passed to the task, added to io.js in 1.8.1. + +* [#1231](https://github.com/substack/node-browserify/pull/1231) +* [defunctzombie/node-process#38](https://github.com/defunctzombie/node-process/pull/38) +* [iojs/io.js#1077](https://github.com/iojs/io.js/pull/1077) + +## Other changes + +* Escapes JavaScript-unsafe characters from JSON. [#1211](https://github.com/substack/node-browserify/pull/1211) +* Removes ‘-v’ shortcut for ‘--version’ (conflicted with watchify) [#1222](https://github.com/substack/node-browserify/pull/1222) +* Updated ‘defined’, ‘punycode’, ‘module-deps’, and ‘xtend’ dependencies to reduce install size [#1230](https://github.com/substack/node-browserify/pull/1230) + # 9.0.8 makes `.require({ expose: 'name' })` and `require('name')` work at the same time @@ -442,7 +832,7 @@ adds an untracked test At a glance: * extensible internal labeled-stream-splicer pipeline -* bundle() - no longer accepts `opts`, callback gets a buffer +* bundle() - no longer accepts `opts`, callback gets a buffer * b.deps(), b.pack(), opts.pack, opts.deps are gone * can call bundle() multiple times on the same instance * a better --noparse matcher @@ -637,7 +1027,7 @@ renders complete stack traces where before they were getting truncated https://g # 3.44.2 -slims down the dependency payload by 20M https://github.com/substack/node-browserify/pull/736 +slims down the dependency payload by 20M https://github.com/substack/node-browserify/pull/736 # 3.44.1 @@ -653,39 +1043,39 @@ lets b.transform(opts, t) args to be swapped around since opts is more common as # 3.42.0 -passes through the dir parameter in opts.packageFilter from module-deps 1.10.0 https://github.com/substack/node-browserify/pull/731 +passes through the dir parameter in opts.packageFilter from module-deps 1.10.0 https://github.com/substack/node-browserify/pull/731 # 3.41.0 -has an option to disable external files, making it easier to run bundles in node for code coverage https://github.com/substack/node-browserify/pull/672 +has an option to disable external files, making it easier to run bundles in node for code coverage https://github.com/substack/node-browserify/pull/672 # 3.40.4 -makes --list work again https://github.com/substack/node-browserify/pull/727 +makes --list work again https://github.com/substack/node-browserify/pull/727 # 3.40.3 -merges a patch for piping via stdin and --require at the same time https://github.com/substack/node-browserify/pull/728 +merges a patch for piping via stdin and --require at the same time https://github.com/substack/node-browserify/pull/728 # 3.40.2 -upgrades module-deps to fix --list for $NODE_PATH https://github.com/substack/node-browserify/issues/726 +upgrades module-deps to fix --list for $NODE_PATH https://github.com/substack/node-browserify/issues/726 # 3.40.1 -upgrades module-deps to get this packageTransform bugfix https://github.com/substack/module-deps/pull/32 +upgrades module-deps to get this packageTransform bugfix https://github.com/substack/module-deps/pull/32 # 3.40.0 -modifies the behavior of opts.builtins to be more useful and intuitive https://github.com/substack/node-browserify/pull/717 +modifies the behavior of opts.builtins to be more useful and intuitive https://github.com/substack/node-browserify/pull/717 # 3.39.0 -adds a zlib that has parity with node https://github.com/substack/node-browserify/pull/721 +adds a zlib that has parity with node https://github.com/substack/node-browserify/pull/721 # 3.38.0 -upgrades derequire which uses esprima-fb https://github.com/substack/node-browserify/pull/710 +upgrades derequire which uses esprima-fb https://github.com/substack/node-browserify/pull/710 # 3.37.2 @@ -701,7 +1091,7 @@ also reverts that require('process') thing which was mistakenly briefly put in t # 3.37.0 -gives streams2 semantics for bundle() https://github.com/substack/node-browserify/pull/646 +gives streams2 semantics for bundle() https://github.com/substack/node-browserify/pull/646 # 3.36.1 @@ -713,35 +1103,35 @@ adds require('process') and removes the path resolution for process out of inser # 3.35.0 -adds an empty tls stub to the builtins list https://github.com/substack/node-browserify/issues/703 +adds an empty tls stub to the builtins list https://github.com/substack/node-browserify/issues/703 # 3.34.0 -fixes a bug with transforms not being applied in deps() https://github.com/substack/node-browserify/pull/708 +fixes a bug with transforms not being applied in deps() https://github.com/substack/node-browserify/pull/708 # 3.33.1 -fixes a bug with options in --global-transform on the command-line https://github.com/substack/node-browserify/pull/705 +fixes a bug with options in --global-transform on the command-line https://github.com/substack/node-browserify/pull/705 # 3.33.0 -fixes parsing errors while maintaining es6 support by switching to esprima-fb https://github.com/substack/node-browserify/issues/698 +fixes parsing errors while maintaining es6 support by switching to esprima-fb https://github.com/substack/node-browserify/issues/698 # 3.32.1 -should be easier to shinkwrap and install on windows https://github.com/substack/node-browserify/pull/684 +should be easier to shinkwrap and install on windows https://github.com/substack/node-browserify/pull/684 # 3.32.0 -adds --full-path and opts.fullPath to always expand ids to full paths https://github.com/substack/node-browserify/pull/668#issuecomment-36586786 +adds --full-path and opts.fullPath to always expand ids to full paths https://github.com/substack/node-browserify/pull/668#issuecomment-36586786 # 3.31.2 -fixes a bug in the subarg argument parsing for multiple transforms https://github.com/substack/node-browserify/issues/678 +fixes a bug in the subarg argument parsing for multiple transforms https://github.com/substack/node-browserify/issues/678 # 3.31.1 -uses process.cwd() as the default rebase target instead of commondir https://github.com/substack/node-browserify/pull/669#issuecomment-36078282 +uses process.cwd() as the default rebase target instead of commondir https://github.com/substack/node-browserify/pull/669#issuecomment-36078282 # 3.31.0 @@ -749,23 +1139,23 @@ merges https://github.com/substack/node-browserify/pull/669 which should help w # 3.30.4 -fixes parsing the --insert-global-vars argument properly https://github.com/substack/node-browserify/pull/674 +fixes parsing the --insert-global-vars argument properly https://github.com/substack/node-browserify/pull/674 # 3.30.3 -fixes exclude globbing in the arg parser https://github.com/substack/node-browserify/pull/676 +fixes exclude globbing in the arg parser https://github.com/substack/node-browserify/pull/676 # 3.30.2 -included a fix for --no-builtins for non-wrapped modules https://github.com/substack/node-browserify/pull/666 +included a fix for --no-builtins for non-wrapped modules https://github.com/substack/node-browserify/pull/666 # 3.30.1 -upgrades buffer for a utf8 fix https://github.com/substack/node-browserify/pull/656 +upgrades buffer for a utf8 fix https://github.com/substack/node-browserify/pull/656 # 3.30.0 -adds globs for -u, -i, and -x https://github.com/substack/node-browserify/issues/654 +adds globs for -u, -i, and -x https://github.com/substack/node-browserify/issues/654 # 3.29.1 @@ -781,11 +1171,11 @@ now always includes the full package.json content in the 'package' event # 3.28.1 -fixes a bug with stream entry order https://github.com/substack/node-browserify/pull/643 +fixes a bug with stream entry order https://github.com/substack/node-browserify/pull/643 # 3.28.0 -adds plugins for doing super fancy things like factored bundle output https://github.com/substack/node-browserify#plugins +adds plugins for doing super fancy things like factored bundle output https://github.com/substack/node-browserify#plugins # 3.27.1 @@ -793,11 +1183,11 @@ fixes a bug resolving transform modules when browserify is under a symlink # 3.27.0 -adds transform configuration in the package.json browserify.transform field https://github.com/substack/module-deps#packagejson-transformkey +adds transform configuration in the package.json browserify.transform field https://github.com/substack/module-deps#packagejson-transformkey # 3.26.0 -you can pass arguments to transforms https://github.com/substack/node-browserify/blob/master/bin/advanced.txt#L67-L77 +you can pass arguments to transforms https://github.com/substack/node-browserify/blob/master/bin/advanced.txt#L67-L77 # 3.25.2 @@ -809,7 +1199,7 @@ fixes the transform docs # 3.25.0 -adds 'bundle' and 'transform' events https://github.com/substack/node-browserify#bonbundle-function-bundle- +adds 'bundle' and 'transform' events https://github.com/substack/node-browserify#bonbundle-function-bundle- # 3.24.11 @@ -817,15 +1207,15 @@ upgrades derequire to 0.6.0. That should be the last piece needed for full es6 s # 3.24.10 -expands the documentation for the package.json browser and browserify.transform fields https://github.com/substack/node-browserify#packagejson +expands the documentation for the package.json browser and browserify.transform fields https://github.com/substack/node-browserify#packagejson # 3.24.9 -fixes generator syntax and other es6-isms in browserify https://github.com/substack/node-browserify/issues/614 +fixes generator syntax and other es6-isms in browserify https://github.com/substack/node-browserify/issues/614 # 3.24.7 -fixes noParse, which had accidentally been disabled in the insert-module-global changes and also closes https://github.com/substack/node-browserify/issues/504 +fixes noParse, which had accidentally been disabled in the insert-module-global changes and also closes https://github.com/substack/node-browserify/issues/504 # 3.24.6 @@ -833,15 +1223,15 @@ similar to 3.24.5, 3.24.6 fixes some error reporting propagation from the browse # 3.24.3 -fixes how require('buffer').Buffer wasn't the same as implicit Buffer https://github.com/substack/node-browserify/issues/612 +fixes how require('buffer').Buffer wasn't the same as implicit Buffer https://github.com/substack/node-browserify/issues/612 # 3.24.2 -fixes where the output stream didn't emit "close" in standalone mode https://github.com/substack/node-browserify/pull/608 +fixes where the output stream didn't emit "close" in standalone mode https://github.com/substack/node-browserify/pull/608 # 3.24.1 -fixes an issue where --standalone combined with expose caused a syntax error https://github.com/substack/node-browserify/issues/489 +fixes an issue where --standalone combined with expose caused a syntax error https://github.com/substack/node-browserify/issues/489 # 3.24.0 @@ -849,7 +1239,7 @@ removes require() calls from --standalone so you can require() a standalone bund # 3.23.0 -merges this tiny fix returning `this` in noParse() https://github.com/substack/node-browserify/pull/592 +merges this tiny fix returning `this` in noParse() https://github.com/substack/node-browserify/pull/592 # 3.22.0 @@ -865,7 +1255,7 @@ has a fix for the case where stdin is implicitly treated as the input stream ins # 3.20.0 -3.20.0 is out: parity with how $NODE_PATH works in node https://github.com/substack/node-browserify/issues/593 +3.20.0 is out: parity with how $NODE_PATH works in node https://github.com/substack/node-browserify/issues/593 # 3.19.1 @@ -883,7 +1273,7 @@ There are 2 big changes in v3 but most code should be relatively unaffected. [feross](https://github.com/feross) forked the [buffer-browserify](https://npmjs.org/package/buffer-browserify) package -to create +to create [native-buffer-browserify](https://npmjs.org/package/native-buffer-browserify), a `Buffer` implementation that uses `Uint8Array` to get `buf[i]` notation and parity with the node core `Buffer` api without the performance hit of the diff --git a/code-of-conduct.md b/code-of-conduct.md new file mode 100644 index 000000000..4a324853b --- /dev/null +++ b/code-of-conduct.md @@ -0,0 +1,78 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at (any one or all of these): + +* substack@gmail.com + +All complaints will be reviewed and investigated and will result in a response +that is deemed necessary and appropriate to the circumstances. The project team +is obligated to maintain confidentiality with regard to the reporter of an +incident. Further details of specific enforcement policies may be posted +separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/index.js b/index.js index 1216cdc81..54dcf2c6e 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +var path = require('path'); var mdeps = require('module-deps'); var depsSort = require('deps-sort'); var bpack = require('browser-pack'); @@ -9,15 +10,15 @@ var builtins = require('./lib/builtins.js'); var splicer = require('labeled-stream-splicer'); var through = require('through2'); var concat = require('concat-stream'); -var duplexer = require('duplexer2'); var inherits = require('inherits'); var EventEmitter = require('events').EventEmitter; var xtend = require('xtend'); -var copy = require('shallow-copy'); -var isarray = require('isarray'); +var isArray = Array.isArray; var defined = require('defined'); var has = require('has'); +var sanitize = require('htmlescape').sanitize; +var shasum = require('shasum'); var bresolve = require('browser-resolve'); var resolve = require('resolve'); @@ -27,7 +28,10 @@ var readonly = require('read-only-stream'); module.exports = Browserify; inherits(Browserify, EventEmitter); +var fs = require('fs'); var path = require('path'); +var cachedPathRelative = require('cached-path-relative'); + var paths = { empty: path.join(__dirname, 'lib/_empty.js') }; @@ -37,10 +41,27 @@ function Browserify (files, opts) { if (!(this instanceof Browserify)) return new Browserify(files, opts); if (!opts) opts = {}; - if (typeof files === 'string' || isarray(files) || isStream(files)) { + if (typeof files === 'string' || isArray(files) || isStream(files)) { opts = xtend(opts, { entries: [].concat(opts.entries || [], files) }); } else opts = xtend(files, opts); + + if (opts.node) { + opts.bare = true; + opts.browserField = false; + } + if (opts.bare) { + opts.builtins = false; + opts.commondir = false; + if (opts.insertGlobalVars === undefined) { + opts.insertGlobalVars = {} + Object.keys(insertGlobals.vars).forEach(function (name) { + if (name !== '__dirname' && name !== '__filename') { + opts.insertGlobalVars[name] = undefined; + } + }) + } + } self._options = opts; if (opts.noparse) opts.noParse = opts.noparse; @@ -48,7 +69,9 @@ function Browserify (files, opts) { if (opts.basedir !== undefined && typeof opts.basedir !== 'string') { throw new Error('opts.basedir must be either undefined or a string.'); } - + + opts.dedupe = opts.dedupe === false ? false : true; + self._external = []; self._exclude = []; self._ignore = []; @@ -60,10 +83,18 @@ function Browserify (files, opts) { self._transforms = []; self._entryOrder = 0; self._ticked = false; + self._bresolve = opts.browserField === false + ? function (id, opts, cb) { + if (!opts.basedir) opts.basedir = path.dirname(opts.filename) + resolve(id, opts, cb) + } + : bresolve + ; + self._syntaxCache = {}; var ignoreTransform = [].concat(opts.ignoreTransform).filter(Boolean); self._filterTransform = function (tr) { - if (Array.isArray(tr)) { + if (isArray(tr)) { return ignoreTransform.indexOf(tr[0]) === -1; } return ignoreTransform.indexOf(tr) === -1; @@ -91,7 +122,7 @@ function Browserify (files, opts) { Browserify.prototype.require = function (file, opts) { var self = this; - if (isarray(file)) { + if (isArray(file)) { file.forEach(function (x) { if (typeof x === 'object') { self.require(x.file, xtend(opts, x)); @@ -105,13 +136,13 @@ Browserify.prototype.require = function (file, opts) { var basedir = defined(opts.basedir, self._options.basedir, process.cwd()); var expose = opts.expose; if (file === expose && /^[\.]/.test(expose)) { - expose = '/' + path.relative(basedir, expose); + expose = '/' + relativePath(basedir, expose); } if (expose === undefined && this._options.exposeAll) { expose = true; } if (expose === true) { - expose = '/' + path.relative(basedir, file); + expose = '/' + relativePath(basedir, file); } if (isStream(file)) { @@ -148,16 +179,16 @@ Browserify.prototype.require = function (file, opts) { if (typeof file === 'object') { row = xtend(file, opts); } - else if (isExternalModule(file)) { + else if (!opts.entry && isExternalModule(file)) { // external module or builtin row = xtend(opts, { id: expose || file, file: file }); } else { - row = xtend(opts, { file: file }); + row = xtend(opts, { file: path.resolve(basedir, file) }); } if (!row.id) { - row.id = expose || file; + row.id = expose || row.file; } if (expose || !row.entry) { // Make this available to mdeps so that it can assign the value when it @@ -173,6 +204,7 @@ Browserify.prototype.require = function (file, opts) { } if (row.entry) row.order = self._entryOrder ++; + if (opts.transform === false) row.transform = false; self.pipeline.write(row); return self; @@ -181,7 +213,7 @@ Browserify.prototype.require = function (file, opts) { Browserify.prototype.add = function (file, opts) { var self = this; if (!opts) opts = {}; - if (isarray(file)) { + if (isArray(file)) { file.forEach(function (x) { self.add(x, opts) }); return this; } @@ -190,7 +222,7 @@ Browserify.prototype.add = function (file, opts) { Browserify.prototype.external = function (file, opts) { var self = this; - if (isarray(file)) { + if (isArray(file)) { file.forEach(function (f) { if (typeof f === 'object') { self.external(f, xtend(opts, f)); @@ -242,20 +274,34 @@ Browserify.prototype.external = function (file, opts) { if (!opts) opts = {}; var basedir = defined(opts.basedir, process.cwd()); this._external.push(file); - this._external.push('/' + path.relative(basedir, file)); + this._external.push('/' + relativePath(basedir, file)); return this; }; Browserify.prototype.exclude = function (file, opts) { if (!opts) opts = {}; + if (isArray(file)) { + var self = this; + file.forEach(function(file) { + self.exclude(file, opts); + }); + return this; + } var basedir = defined(opts.basedir, process.cwd()); this._exclude.push(file); - this._exclude.push('/' + path.relative(basedir, file)); + this._exclude.push('/' + relativePath(basedir, file)); return this; }; Browserify.prototype.ignore = function (file, opts) { if (!opts) opts = {}; + if (isArray(file)) { + var self = this; + file.forEach(function(file) { + self.ignore(file, opts); + }); + return this; + } var basedir = defined(opts.basedir, process.cwd()); // Handle relative paths @@ -273,7 +319,7 @@ Browserify.prototype.transform = function (tr, opts) { if (typeof opts === 'function' || typeof opts === 'string') { tr = [ opts, tr ]; } - if (isarray(tr)) { + if (isArray(tr)) { opts = tr[1]; tr = tr[0]; } @@ -329,7 +375,7 @@ Browserify.prototype.transform = function (tr, opts) { }; Browserify.prototype.plugin = function (p, opts) { - if (isarray(p)) { + if (isArray(p)) { opts = p[1]; p = p[0]; } @@ -368,7 +414,7 @@ Browserify.prototype._createPipeline = function (opts) { var dopts = { index: !opts.fullPaths && !opts.exposeAll, - dedupe: true, + dedupe: opts.dedupe, expose: this._expose }; this._bpack = bpack(xtend(opts, { raw: true })); @@ -395,10 +441,10 @@ Browserify.prototype._createPipeline = function (opts) { if (self._external.indexOf(row.file) >= 0) return next(); if (isAbsolutePath(row.id)) { - row.id = '/' + path.relative(basedir, row.file); + row.id = '/' + relativePath(basedir, row.file); } Object.keys(row.deps || {}).forEach(function (key) { - row.deps[key] = '/' + path.relative(basedir, row.deps[key]); + row.deps[key] = '/' + relativePath(basedir, row.deps[key]); }); this.push(row); next(); @@ -409,7 +455,7 @@ Browserify.prototype._createPipeline = function (opts) { Browserify.prototype._createDeps = function (opts) { var self = this; - var mopts = copy(opts); + var mopts = xtend(opts); var basedir = defined(opts.basedir, process.cwd()); // Let mdeps populate these values since it will be resolving file paths @@ -419,7 +465,7 @@ Browserify.prototype._createDeps = function (opts) { self._extensions = mopts.extensions; mopts.transform = []; - mopts.transformKey = [ 'browserify', 'transform' ]; + mopts.transformKey = defined(opts.transformKey, [ 'browserify', 'transform' ]); mopts.postFilter = function (id, file, pkg) { if (opts.postFilter && !opts.postFilter(id, file, pkg)) return false; if (self._external.indexOf(file) >= 0) return false; @@ -446,12 +492,12 @@ Browserify.prototype._createDeps = function (opts) { mopts.resolve = function (id, parent, cb) { if (self._ignore.indexOf(id) >= 0) return cb(null, paths.empty, {}); - bresolve(id, parent, function (err, file, pkg) { + self._bresolve(id, parent, function (err, file, pkg) { if (file && self._ignore.indexOf(file) >= 0) { return cb(null, paths.empty, {}); } if (file && self._ignore.length) { - var nm = file.split('/node_modules/')[1]; + var nm = file.replace(/\\/g, '/').split('/node_modules/')[1]; if (nm) { nm = nm.split('/')[0]; if (self._ignore.indexOf(nm) >= 0) { @@ -461,7 +507,7 @@ Browserify.prototype._createDeps = function (opts) { } if (file) { - var ex = '/' + path.relative(basedir, file); + var ex = '/' + relativePath(basedir, file); if (self._external.indexOf(ex) >= 0) { return cb(null, ex); } @@ -472,7 +518,16 @@ Browserify.prototype._createDeps = function (opts) { return cb(null, paths.empty, {}); } } - cb(err, file, pkg); + if (err) cb(err, file, pkg) + else if (file) { + if (opts.preserveSymlinks && parent.id !== self._mdeps.top.id) { + return cb(err, path.resolve(file), pkg, file) + } + + fs.realpath(file, function (err, res) { + cb(err, res, pkg, file); + }); + } else cb(err, null, pkg) }); }; @@ -480,7 +535,7 @@ Browserify.prototype._createDeps = function (opts) { mopts.modules = {}; self._exclude.push.apply(self._exclude, Object.keys(builtins)); } - else if (opts.builtins && isarray(opts.builtins)) { + else if (opts.builtins && isArray(opts.builtins)) { mopts.modules = {}; opts.builtins.forEach(function (key) { mopts.modules[key] = builtins[key]; @@ -489,7 +544,7 @@ Browserify.prototype._createDeps = function (opts) { else if (opts.builtins && typeof opts.builtins === 'object') { mopts.modules = opts.builtins; } - else mopts.modules = copy(builtins); + else mopts.modules = xtend(builtins); Object.keys(builtins).forEach(function (key) { if (!has(mopts.modules, key)) self._exclude.push(key); @@ -506,17 +561,21 @@ Browserify.prototype._createDeps = function (opts) { }); } + var no = [].concat(opts.noParse).filter(Boolean); + var absno = no.filter(function(x) { + return typeof x === 'string'; + }).map(function (x) { + return path.resolve(basedir, x); + }); + function globalTr (file) { if (opts.detectGlobals === false) return through(); if (opts.noParse === true) return through(); - var no = [].concat(opts.noParse).filter(Boolean); if (no.indexOf(file) >= 0) return through(); - if (no.map(function (x){return path.resolve(x)}).indexOf(file)>=0){ - return through(); - } + if (absno.indexOf(file) >= 0) return through(); - var parts = file.split('/node_modules/'); + var parts = file.replace(/\\/g, '/').split('/node_modules/'); for (var i = 0; i < no.length; i++) { if (typeof no[i] === 'function' && no[i](file)) { return through(); @@ -528,20 +587,33 @@ Browserify.prototype._createDeps = function (opts) { return through(); } } + + if (opts.commondir === false && opts.builtins === false) { + opts.insertGlobalVars = xtend({ + __dirname: function(file, basedir) { + var dir = path.dirname(path.relative(basedir, file)); + return 'require("path").join(__dirname,' + dir.split(path.sep).map(JSON.stringify).join(',') + ')'; + }, + __filename: function(file, basedir) { + var filename = path.relative(basedir, file); + return 'require("path").join(__dirname,' + filename.split(path.sep).map(JSON.stringify).join(',') + ')'; + } + }, opts.insertGlobalVars); + } var vars = xtend({ process: function () { return "require('_process')" }, }, opts.insertGlobalVars); if (opts.bundleExternal === false) { - delete vars.process; - delete vars.buffer; + vars.process = undefined; + vars.buffer = undefined; } - + return insertGlobals(file, xtend(opts, { debug: opts.debug, always: opts.insertGlobals, - basedir: opts.commondir === false + basedir: opts.commondir === false && isArray(opts.builtins) ? '/' : opts.basedir || process.cwd() , @@ -582,8 +654,8 @@ Browserify.prototype._recorder = function (opts) { Browserify.prototype._json = function () { return through.obj(function (row, enc, next) { - if (/\.json$/.test(row.file) && !isdedupe(row.source)) { - row.source = 'module.exports=' + row.source; + if (/\.json$/.test(row.file)) { + row.source = 'module.exports=' + sanitize(row.source); } this.push(row); next(); @@ -611,20 +683,19 @@ Browserify.prototype._unshebang = function () { }; Browserify.prototype._syntax = function () { + var self = this; return through.obj(function (row, enc, next) { - var err = syntaxError(row.source, row.file || row.id); - if (err) return this.emit('error', err); + var h = shasum(row.source); + if (typeof self._syntaxCache[h] === 'undefined') { + var err = syntaxError(row.source, row.file || row.id); + if (err) return this.emit('error', err); + self._syntaxCache[h] = true; + } this.push(row); next(); }); }; -function isdedupe (src) { // mega-hack - return /^arguments\[4\]\[/.test(src) - && /\]\[0\]\.apply\(exports,arguments\)$/.test(src) - ; -} - Browserify.prototype._dedupe = function () { return through.obj(function (row, enc, next) { if (!row.dedupeIndex && row.dedupe) { @@ -657,7 +728,7 @@ Browserify.prototype._label = function (opts) { var prev = row.id; if (self._external.indexOf(row.id) >= 0) return next(); - if (self._external.indexOf('/' + path.relative(basedir, row.id)) >= 0) { + if (self._external.indexOf('/' + relativePath(basedir, row.id)) >= 0) { return next(); } if (self._external.indexOf(row.file) >= 0) return next(); @@ -674,7 +745,7 @@ Browserify.prototype._label = function (opts) { } var afile = path.resolve(path.dirname(row.file), key); - var rfile = '/' + path.relative(basedir, afile); + var rfile = '/' + relativePath(basedir, afile); if (self._external.indexOf(rfile) >= 0) { row.deps[key] = rfile; } @@ -717,8 +788,7 @@ Browserify.prototype._debug = function (opts) { return through.obj(function (row, enc, next) { if (opts.debug) { row.sourceRoot = 'file://localhost'; - row.sourceFile = path.relative(basedir, row.file) - .replace(/\\/g, '/'); + row.sourceFile = relativePath(basedir, row.file); } this.push(row); next(); @@ -753,7 +823,7 @@ Browserify.prototype.bundle = function (cb) { var output = readonly(this.pipeline); if (cb) { output.on('error', cb); - this.pipeline.pipe(concat(function (body) { + output.pipe(concat(function (body) { cb(null, body); })); } @@ -783,3 +853,7 @@ function isExternalModule (file) { /^[\/.]/; return !regexp.test(file); } +function relativePath (from, to) { + // Replace \ with / for OS-independent behavior + return cachedPathRelative(from, to).replace(/\\/g, '/'); +} diff --git a/lib/builtins.js b/lib/builtins.js index 743265150..3aaa280e6 100644 --- a/lib/builtins.js +++ b/lib/builtins.js @@ -10,12 +10,14 @@ exports.dns = require.resolve('./_empty.js'); exports.domain = require.resolve('domain-browser'); exports.events = require.resolve('events/'); exports.fs = require.resolve('./_empty.js'); -exports.http = require.resolve('http-browserify'); +exports.http = require.resolve('stream-http'); exports.https = require.resolve('https-browserify'); +exports.inspector = require.resolve('./_empty.js'); exports.module = require.resolve('./_empty.js'); exports.net = require.resolve('./_empty.js'); exports.os = require.resolve('os-browserify/browser.js'); exports.path = require.resolve('path-browserify'); +exports.perf_hooks = require.resolve('./_empty.js') exports.punycode = require.resolve('punycode/'); exports.querystring = require.resolve('querystring-es3/'); exports.readline = require.resolve('./_empty.js'); diff --git a/package.json b/package.json index 4fbe037f5..c29b5f621 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "browserify", - "version": "9.0.8", + "version": "16.2.3", "description": "browser-side require() the node way", "main": "index.js", "bin": { @@ -8,7 +8,10 @@ }, "repository": { "type": "git", - "url": "http://github.com/substack/node-browserify.git" + "url": "http://github.com/browserify/browserify.git" + }, + "engines": { + "node": ">= 0.8" }, "keywords": [ "browser", @@ -20,66 +23,67 @@ "javascript" ], "dependencies": { - "JSONStream": "~0.10.0", - "assert": "~1.3.0", - "browser-pack": "^4.0.0", - "browser-resolve": "^1.7.1", - "browserify-zlib": "~0.1.2", - "buffer": "^3.0.0", - "builtins": "~0.0.3", - "commondir": "0.0.1", - "concat-stream": "~1.4.1", + "JSONStream": "^1.0.3", + "assert": "^1.4.0", + "browser-pack": "^6.0.1", + "browser-resolve": "^1.11.0", + "browserify-zlib": "~0.2.0", + "buffer": "^5.0.2", + "cached-path-relative": "^1.0.0", + "concat-stream": "^1.6.0", "console-browserify": "^1.1.0", - "constants-browserify": "~0.0.1", + "constants-browserify": "~1.0.0", "crypto-browserify": "^3.0.0", - "deep-equal": "^1.0.0", - "defined": "~0.0.0", - "deps-sort": "^1.3.5", - "domain-browser": "~1.1.0", - "duplexer2": "~0.0.2", - "events": "~1.0.0", - "glob": "^4.0.5", + "defined": "^1.0.0", + "deps-sort": "^2.0.0", + "domain-browser": "^1.2.0", + "duplexer2": "~0.1.2", + "events": "^2.0.0", + "glob": "^7.1.0", "has": "^1.0.0", - "http-browserify": "^1.4.0", - "https-browserify": "~0.0.0", + "htmlescape": "^1.1.0", + "https-browserify": "^1.0.0", "inherits": "~2.0.1", - "insert-module-globals": "^6.2.0", - "isarray": "0.0.1", - "labeled-stream-splicer": "^1.0.0", - "module-deps": "^3.7.0", - "os-browserify": "~0.1.1", + "insert-module-globals": "^7.0.0", + "labeled-stream-splicer": "^2.0.0", + "mkdirp": "^0.5.0", + "module-deps": "^6.0.0", + "os-browserify": "~0.3.0", "parents": "^1.0.1", "path-browserify": "~0.0.0", - "process": "^0.10.0", - "punycode": "~1.2.3", + "process": "~0.11.0", + "punycode": "^1.3.2", "querystring-es3": "~0.2.0", - "read-only-stream": "^1.1.1", - "readable-stream": "^1.1.13", + "read-only-stream": "^2.0.0", + "readable-stream": "^2.0.2", "resolve": "^1.1.4", - "shallow-copy": "0.0.1", "shasum": "^1.0.0", - "shell-quote": "~0.0.1", - "stream-browserify": "^1.0.0", - "string_decoder": "~0.10.0", + "shell-quote": "^1.6.1", + "stream-browserify": "^2.0.0", + "stream-http": "^2.0.0", + "string_decoder": "^1.1.1", "subarg": "^1.0.0", "syntax-error": "^1.1.1", - "through2": "^1.0.0", + "through2": "^2.0.0", "timers-browserify": "^1.0.1", - "tty-browserify": "~0.0.0", - "url": "~0.10.1", + "tty-browserify": "0.0.1", + "url": "~0.11.0", "util": "~0.10.1", - "vm-browserify": "~0.0.1", - "xtend": "^3.0.0" + "vm-browserify": "^1.0.0", + "xtend": "^4.0.0" }, "devDependencies": { "backbone": "~0.9.2", - "browser-unpack": "~0.0.0", - "coffee-script": "~1.5.0", - "coffeeify": "~0.6.0", - "es6ify": "~0.4.8", + "browser-unpack": "^1.1.1", + "coffee-script": "~1.10.0", + "coffeeify": "~1.1.0", + "has-object-spread": "^1.0.0", + "has-template-literals": "^1.0.0", "isstream": "^0.1.2", - "seq": "0.3.3", - "tap": "~0.4.0", + "make-generator-function": "^1.1.0", + "semver": "^5.5.0", + "seq": "0.3.5", + "tap": "^10.7.2", "temp": "^0.8.1", "through": "^2.3.4" }, diff --git a/readme.markdown b/readme.markdown index e8972e9cc..7d6f87e62 100644 --- a/readme.markdown +++ b/readme.markdown @@ -9,25 +9,22 @@ browserify will recursively analyze all the `require()` calls in your app in order to build a bundle you can serve up to the browser in a single `