diff --git a/.gitignore b/.gitignore index d8b83df9c..7a7b33aa1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ package-lock.json +node_modules diff --git a/.travis.yml b/.travis.yml index 143cf3d29..0ad727779 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: node_js node_js: + - "10" - "9" - "8" - "6" diff --git a/LICENSE b/LICENSE index eff138cad..59f71e2a1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,84 +1,21 @@ -This software is released under the MIT license: +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: +Copyright (c) 2010 James Halliday + +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: - ----- - -Copyright Joyent, Inc. and other Node contributors. - -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. - ----- - -buffer_ieee754.js has this license in it: - ----- - -Copyright (c) 2008-2015, Fair Oaks Labs, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of Fair Oaks Labs, Inc. nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -Modifications to writeIEEE754 to support negative zeroes made by Brian White - ----- +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. 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/bin/args.js b/bin/args.js index 130ace75b..2f5beec16 100644 --- a/bin/args.js +++ b/bin/args.js @@ -254,7 +254,7 @@ function splitOnColon (f) { 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)]; + return [f.slice(0, pos), f.slice(pos + 1)]; } } } diff --git a/bin/cmd.js b/bin/cmd.js index 1a63b19ac..ab4213753 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -2,7 +2,7 @@ var fs = require('fs'); var JSONStream = require('JSONStream'); var through = require('through2'); -var mkdirp = require('mkdirp'); +var mkdirp = require('mkdirp-classic'); var path = require('path'); var b = require('./args')(process.argv.slice(2)); diff --git a/changelog.markdown b/changelog.markdown index ccd3da31a..a24017b15 100644 --- a/changelog.markdown +++ b/changelog.markdown @@ -1,3 +1,81 @@ +# 17.0.1 +* Use `hasown` instead of `has`. ([4b1a5dc](https://github.com/browserify/browserify/commit/4b1a5dc0db56263b38dc98e155fb1908e810c1a9)) +* Use `String.prototype.slice` instead of `String.prototype.substr`. ([#2036](https://github.com/browserify/browserify/pull/2036)) +* Support relative paths in the `noParse` option. ([#2080](https://github.com/browserify/browserify/pull/2080)) + +# 17.0.0 +* Upgrade events to v3.x. EventEmitter instances now have an `off()` method. `require('events').once` can be used to react to an event being emitted with `async`/`await` syntax. ([#1839](https://github.com/browserify/browserify/pull/1839)) +* Upgrade path-browserify to v1.x. ([#1838](https://github.com/browserify/browserify/pull/1838)) +* Upgrade stream-browserify to v3.x. `require('stream')` now matches the Node.js 10+ API. ([#1970](https://github.com/browserify/browserify/pull/1970)) +* Upgrade util to v0.12. Most notably, `util.promisify` and `util.callbackify` are finally available by default in browserify. ([#1844](https://gihub.com/browserify/browserify/pull/1844)) +* Add JSON syntax checking. Syntax errors in `.json` files will now fail to bundle. ([#1700](https://github.com/browserify/browserify/pull/1700)) + +# 16.5.2 + +Upgrade browser-resolve to v2. + +https://github.com/browserify/browserify/pull/1973 + +# 16.5.1 + +Remove deprecated `mkdirp` version in favour of `mkdirp-classic`. + +https://github.com/browserify/browserify/commit/00c913fa345dbb7f612bdad6b4acc91c706e98b2 + +Pin dependencies for Node.js 0.8 support. + +https://github.com/browserify/browserify/pull/1939 + +# 16.5.0 + +Support custom name for `"browser"` field resolution in `package.json` using the `browserField` option. + +https://github.com/browserify/browserify/pull/1918 + +# 16.4.0 + +Upgrade stream-http to v3. This version drops support for IE10 and below. + +https://github.com/browserify/browserify/pull/1916 + +# 16.3.0 + +add empty stub for the `http2` builtin module. + +https://github.com/browserify/browserify/pull/1913 + +update license text to remove references to code that is no longer included. + +https://github.com/browserify/browserify/pull/1906 + +add more tests for folder resolution. + +https://github.com/browserify/browserify/pull/1139 + +# 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`. @@ -306,7 +384,7 @@ https://github.com/substack/node-browserify/pull/1244 fixes for the "noParse" path matcher. -https://github.com/substack/node-browserify/pull/1259 +https://github.com/substack/node-browserify/pull/1257 add syntax check cache. this speeds up rebuilds (like when using watchify). @@ -314,7 +392,7 @@ 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 +https://github.com/substack/node-browserify/pull/1259 # 10.1.3 diff --git a/index.js b/index.js index b8bf81d25..729cac5a5 100644 --- a/index.js +++ b/index.js @@ -16,9 +16,9 @@ var EventEmitter = require('events').EventEmitter; var xtend = require('xtend'); var isArray = Array.isArray; var defined = require('defined'); -var has = require('has'); +var hasOwn = require('hasown'); var sanitize = require('htmlescape').sanitize; -var shasum = require('shasum'); +var shasum = require('shasum-object'); var bresolve = require('browser-resolve'); var resolve = require('resolve'); @@ -30,7 +30,8 @@ inherits(Browserify, EventEmitter); var fs = require('fs'); var path = require('path'); -var relativePath = require('cached-path-relative') +var cachedPathRelative = require('cached-path-relative'); + var paths = { empty: path.join(__dirname, 'lib/_empty.js') }; @@ -82,12 +83,19 @@ function Browserify (files, opts) { self._transforms = []; self._entryOrder = 0; self._ticked = false; - self._bresolve = opts.browserField === false + + var browserField = opts.browserField + self._bresolve = browserField === false ? function (id, opts, cb) { if (!opts.basedir) opts.basedir = path.dirname(opts.filename) resolve(id, opts, cb) } - : bresolve + : typeof browserField === 'string' + ? function (id, opts, cb) { + opts.browser = browserField + bresolve(id, opts, cb) + } + : bresolve ; self._syntaxCache = {}; @@ -136,14 +144,12 @@ Browserify.prototype.require = function (file, opts) { var expose = opts.expose; if (file === expose && /^[\.]/.test(expose)) { expose = '/' + relativePath(basedir, expose); - expose = expose.replace(/\\/g, '/'); } if (expose === undefined && this._options.exposeAll) { expose = true; } if (expose === true) { expose = '/' + relativePath(basedir, file); - expose = expose.replace(/\\/g, '/'); } if (isStream(file)) { @@ -498,7 +504,7 @@ Browserify.prototype._createDeps = function (opts) { 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) { @@ -548,7 +554,7 @@ Browserify.prototype._createDeps = function (opts) { else mopts.modules = xtend(builtins); Object.keys(builtins).forEach(function (key) { - if (!has(mopts.modules, key)) self._exclude.push(key); + if (!hasOwn(mopts.modules, key)) self._exclude.push(key); }); mopts.globalTransform = []; @@ -568,6 +574,7 @@ Browserify.prototype._createDeps = function (opts) { }).map(function (x) { return path.resolve(basedir, x); }); + mopts.noParse = absno; function globalTr (file) { if (opts.detectGlobals === false) return through(); @@ -576,7 +583,7 @@ Browserify.prototype._createDeps = function (opts) { if (no.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(); @@ -656,7 +663,16 @@ Browserify.prototype._recorder = function (opts) { Browserify.prototype._json = function () { return through.obj(function (row, enc, next) { if (/\.json$/.test(row.file)) { - row.source = 'module.exports=' + sanitize(row.source); + var sanitizedString = sanitize(row.source); + try { + // check json validity + JSON.parse(sanitizedString); + row.source = 'module.exports=' + sanitizedString; + } catch (err) { + err.message = 'While parsing ' + (row.file || row.id) + ': ' + err.message + this.emit('error', err); + return; + } } this.push(row); next(); @@ -789,8 +805,7 @@ Browserify.prototype._debug = function (opts) { return through.obj(function (row, enc, next) { if (opts.debug) { row.sourceRoot = 'file://localhost'; - row.sourceFile = relativePath(basedir, row.file) - .replace(/\\/g, '/'); + row.sourceFile = relativePath(basedir, row.file); } this.push(row); next(); @@ -855,3 +870,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 503be6eeb..d7bdbe1ce 100644 --- a/lib/builtins.js +++ b/lib/builtins.js @@ -12,6 +12,8 @@ exports.events = require.resolve('events/'); exports.fs = require.resolve('./_empty.js'); exports.http = require.resolve('stream-http'); exports.https = require.resolve('https-browserify'); +exports.http2 = require.resolve('./_empty.js'); +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'); diff --git a/package.json b/package.json index 60ef6d8a6..7affe9acc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "browserify", - "version": "16.2.0", + "version": "17.0.1", "description": "browser-side require() the node way", "main": "index.js", "bin": { @@ -23,44 +23,44 @@ "javascript" ], "dependencies": { - "JSONStream": "^1.0.3", "assert": "^1.4.0", "browser-pack": "^6.0.1", - "browser-resolve": "^1.11.0", + "browser-resolve": "^2.0.0", "browserify-zlib": "~0.2.0", - "buffer": "^5.0.2", + "buffer": "~5.2.1", "cached-path-relative": "^1.0.0", "concat-stream": "^1.6.0", "console-browserify": "^1.1.0", "constants-browserify": "~1.0.0", "crypto-browserify": "^3.0.0", "defined": "^1.0.0", - "deps-sort": "^2.0.0", + "deps-sort": "^2.0.1", "domain-browser": "^1.2.0", "duplexer2": "~0.1.2", - "events": "^2.0.0", + "events": "^3.0.0", "glob": "^7.1.0", - "has": "^1.0.0", + "hasown": "^2.0.0", "htmlescape": "^1.1.0", "https-browserify": "^1.0.0", "inherits": "~2.0.1", - "insert-module-globals": "^7.0.0", + "insert-module-globals": "^7.2.1", + "JSONStream": "^1.0.3", "labeled-stream-splicer": "^2.0.0", - "mkdirp": "^0.5.0", - "module-deps": "^6.0.0", + "mkdirp-classic": "^0.5.2", + "module-deps": "^6.2.3", "os-browserify": "~0.3.0", "parents": "^1.0.1", - "path-browserify": "~0.0.0", + "path-browserify": "^1.0.0", "process": "~0.11.0", "punycode": "^1.3.2", "querystring-es3": "~0.2.0", "read-only-stream": "^2.0.0", "readable-stream": "^2.0.2", "resolve": "^1.1.4", - "shasum": "^1.0.0", + "shasum-object": "^1.0.0", "shell-quote": "^1.6.1", - "stream-browserify": "^2.0.0", - "stream-http": "^2.0.0", + "stream-browserify": "^3.0.0", + "stream-http": "^3.0.0", "string_decoder": "^1.1.1", "subarg": "^1.0.0", "syntax-error": "^1.1.1", @@ -68,7 +68,7 @@ "timers-browserify": "^1.0.1", "tty-browserify": "0.0.1", "url": "~0.11.0", - "util": "~0.10.1", + "util": "~0.12.0", "vm-browserify": "^1.0.0", "xtend": "^4.0.0" }, @@ -81,9 +81,10 @@ "has-template-literals": "^1.0.0", "isstream": "^0.1.2", "make-generator-function": "^1.1.0", + "semver": "^5.5.0", "seq": "0.3.5", "tap": "^10.7.2", - "temp": "^0.8.1", + "temp": "=0.8.3", "through": "^2.3.4" }, "author": { diff --git a/readme.markdown b/readme.markdown index b3118771f..864e02b59 100644 --- a/readme.markdown +++ b/readme.markdown @@ -60,7 +60,7 @@ html! With [npm](https://www.npmjs.com/) do: ``` -npm install -g browserify +npm install browserify ``` # usage @@ -447,7 +447,9 @@ useful for preserving the original paths that a bundle was generated with. `opts.bundleExternal` boolean option to set if external modules should be bundled. Defaults to true. -When `opts.browserField` is false, the package.json browser field will be ignored. +When `opts.browserField` is false, the package.json browser field will be +ignored. When `opts.browserField` is set to a `string`, then a custom field name +can be used instead of the default `"browser"` field. When `opts.insertGlobals` is true, always insert `process`, `global`, `__filename`, and `__dirname` without analyzing the AST for faster builds but @@ -476,10 +478,18 @@ You can remove these calls with [derequire](https://www.npmjs.com/package/derequire): ``` -$ npm install -g derequire +$ npm install derequire $ browserify main.js --standalone Foo | derequire > bundle.js ``` +```html + + +``` + `opts.insertGlobalVars` will be passed to [insert-module-globals](https://www.npmjs.com/package/insert-module-globals) as the `opts.vars` parameter. @@ -698,7 +708,7 @@ sophisticated things you can do in the package.json: ## browser field -There is a special "[browser](https://gist.github.com/4339901)" field you can +There is a special "[browser](https://github.com/defunctzombie/package-browser-field-spec)" field you can set in your package.json on a per-module basis to override file resolution for browser-specific versions of files. diff --git a/security.md b/security.md new file mode 100644 index 000000000..a14ace6a5 --- /dev/null +++ b/security.md @@ -0,0 +1,10 @@ +# Security Policy + +## Supported Versions +Only the latest major version is supported at any given time. + +## Reporting a Vulnerability + +To report a security vulnerability, please use the +[Tidelift security contact](https://tidelift.com/security). +Tidelift will coordinate the fix and disclosure. diff --git a/test/bin_tr_error.js b/test/bin_tr_error.js index 039704cca..a68127545 100644 --- a/test/bin_tr_error.js +++ b/test/bin_tr_error.js @@ -2,8 +2,12 @@ var browserify = require('../'); var spawn = require('child_process').spawn; var test = require('tap').test; var path = require('path') +var semver = require('semver'); -test('function transform', function (t) { +// TODO this should be fixable I guess +var flaky = process.platform === 'win32' && semver.satisfies(process.version, 'v0.10.x'); + +test('function transform', { skip: flaky }, function (t) { t.plan(3); var ps = spawn(process.execPath, [ path.resolve(__dirname, '../bin/cmd.js'), diff --git a/test/crypto.js b/test/crypto.js index 7edb25594..453ddb368 100644 --- a/test/crypto.js +++ b/test/crypto.js @@ -4,6 +4,7 @@ var path = require('path'); var fs = require('fs'); var vm = require('vm'); var concat = require('concat-stream'); +var semver = require('semver'); var temp = require('temp'); temp.track(); @@ -13,7 +14,8 @@ fs.writeFileSync(tmpdir + '/main.js', 'beep(require("crypto"))\n'); if (!ArrayBuffer.isView) ArrayBuffer.isView = function () { return false; }; -test('*-browserify libs from node_modules/', function (t) { +// `crypto-browserify` no longer works in node.js <4 +test('*-browserify libs from node_modules/', { skip: semver.lt(process.version, 'v4.0.0') }, function (t) { t.plan(2); var bin = __dirname + '/../bin/cmd.js'; diff --git a/test/crypto_ig.js b/test/crypto_ig.js index c60b5bf60..932ee9ef8 100644 --- a/test/crypto_ig.js +++ b/test/crypto_ig.js @@ -4,6 +4,7 @@ var path = require('path'); var fs = require('fs'); var vm = require('vm'); var concat = require('concat-stream'); +var semver = require('semver'); var temp = require('temp'); temp.track(); @@ -13,7 +14,8 @@ fs.writeFileSync(tmpdir + '/main.js', 'beep(require("crypto"))\n'); if (!ArrayBuffer.isView) ArrayBuffer.isView = function () { return false; }; -test('crypto --insertGlobals', function (t) { +// `crypto-browserify` no longer works in node.js <4 +test('crypto --insertGlobals', { skip: semver.lt(process.version, 'v4.0.0') }, function (t) { t.plan(2); var bin = __dirname + '/../bin/cmd.js'; diff --git a/test/delay.js b/test/delay.js index 6335ee832..63c1d8785 100644 --- a/test/delay.js +++ b/test/delay.js @@ -1,5 +1,6 @@ var browserify = require('../'); var vm = require('vm'); +var path = require('path'); var test = require('tap').test; var through = require('through2'); @@ -9,8 +10,8 @@ test('delay for pipelines', function (t) { var b = browserify(__dirname + '/delay/main.js'); b.pipeline.get('record').push(through.obj(function (row, enc, next) { if (row.file) { - t.equal(row.file, __dirname + '/delay/main.js'); - row.file = __dirname + '/delay/diverted.js'; + t.equal(row.file, path.join(__dirname, 'delay/main.js')); + row.file = path.join(__dirname, 'delay/diverted.js'); } this.push(row); next(); diff --git a/test/entry.js b/test/entry.js index 34d91e9f6..23a2ee254 100644 --- a/test/entry.js +++ b/test/entry.js @@ -1,5 +1,6 @@ var browserify = require('../'); var vm = require('vm'); +var path = require('path'); var test = require('tap').test; test('entry', function (t) { @@ -7,7 +8,7 @@ test('entry', function (t) { var b = browserify(__dirname + '/entry/main.js'); b.on('dep', function(row) { - if (row.entry) t.equal(row.file, __dirname + '/entry/main.js'); + if (row.entry) t.equal(row.file, path.join(__dirname, 'entry/main.js')); }); b.bundle(function (err, src) { var c = { @@ -27,7 +28,7 @@ test('entry via add', function (t) { var b = browserify(); b.add(__dirname + '/entry/main.js'); b.on('dep', function(row) { - if (row.entry) t.equal(row.file, __dirname + '/entry/main.js'); + if (row.entry) t.equal(row.file, path.join(__dirname, 'entry/main.js')); }); b.bundle(function (err, src) { var c = { diff --git a/test/entry_expose.js b/test/entry_expose.js index 2323c2cb9..381bdc5f5 100644 --- a/test/entry_expose.js +++ b/test/entry_expose.js @@ -1,6 +1,5 @@ var test = require('tap').test; var browserify = require('../'); -var path = require('path'); var vm = require('vm'); test('entry expose', function (t) { diff --git a/test/entry_relative.js b/test/entry_relative.js index f1ae37f2c..178a8ac1b 100644 --- a/test/entry_relative.js +++ b/test/entry_relative.js @@ -1,5 +1,6 @@ var browserify = require('../'); var vm = require('vm'); +var path = require('path'); var test = require('tap').test; test('entry - relative path', function (t) { @@ -9,7 +10,7 @@ test('entry - relative path', function (t) { var b = browserify('entry/main.js'); b.on('dep', function(row) { - if (row.entry) t.equal(row.file, __dirname + '/entry/main.js'); + if (row.entry) t.equal(row.file, path.join(__dirname, 'entry/main.js')); }); b.bundle(function (err, src) { var c = { @@ -29,7 +30,7 @@ test('entry - relative path via add', function (t) { var b = browserify({basedir: __dirname}); b.add('entry/main.js'); b.on('dep', function(row) { - if (row.entry) t.equal(row.file, __dirname + '/entry/main.js'); + if (row.entry) t.equal(row.file, path.join(__dirname, 'entry/main.js')); }); b.bundle(function (err, src) { var c = { diff --git a/test/error_code.js b/test/error_code.js index 2f3734c24..5d0b2b1d7 100644 --- a/test/error_code.js +++ b/test/error_code.js @@ -1,8 +1,12 @@ var test = require('tap').test; var spawn = require('child_process').spawn; var path = require('path'); +var semver = require('semver'); -test('error code', function (t) { +// TODO this should be fixable I guess +var knownFailure = process.platform === 'win32' && semver.satisfies(process.version, 'v0.10.x'); + +test('error code', { skip: knownFailure }, function (t) { t.plan(2); var cwd = process.cwd(); diff --git a/test/external_shim.js b/test/external_shim.js index 63739c00a..1c251242a 100644 --- a/test/external_shim.js +++ b/test/external_shim.js @@ -3,6 +3,7 @@ var vm = require('vm'); var test = require('tap').test; test('requiring a shimmed module name from an external bundle', function (t) { + t.plan(1); var b1 = browserify(); var b2 = browserify(); @@ -12,7 +13,6 @@ test('requiring a shimmed module name from an external bundle', function (t) { b1.bundle(function (err, src1) { b2.bundle(function (err, src2) { - t.plan(1); var c = { console: console, diff --git a/test/file_event.js b/test/file_event.js index 285ccafa6..33ac36ce5 100644 --- a/test/file_event.js +++ b/test/file_event.js @@ -8,7 +8,7 @@ test('file event', function (t) { var b = browserify(__dirname + '/entry/main.js'); var files = { - 'main.js': __dirname + '/entry/main.js', + 'main.js': path.join(__dirname, 'entry/main.js'), 'one.js': './one', 'two.js': './two' }; diff --git a/test/global_noparse.js b/test/global_noparse.js index decd772da..a4e5a7051 100644 --- a/test/global_noparse.js +++ b/test/global_noparse.js @@ -1,5 +1,6 @@ var browserify = require('../'); var vm = require('vm'); +var path = require('path'); var test = require('tap').test; test('global noparse module', function (t) { @@ -84,7 +85,7 @@ test('global noparse function', function (t) { var b = browserify({ noParse: function(file) { - return file === __dirname + '/global/filename.js'; + return file === path.join(__dirname, 'global/filename.js'); } }); b.require(__dirname + '/global/filename.js', { expose: 'x' }); diff --git a/test/ignore.js b/test/ignore.js index fe19a2e00..4cb70971f 100644 --- a/test/ignore.js +++ b/test/ignore.js @@ -1,90 +1,91 @@ -var browserify = require('../'); -var test = require('tap').test; -var vm = require('vm'); - -test('ignore', function (t) { - t.plan(1); - - var b = browserify(); - b.add(__dirname + '/ignore/main.js'); - b.ignore( __dirname + '/ignore/skip.js'); - - b.bundle(function (err, src) { - if (err) t.fail(err); - vm.runInNewContext(src, { t: t }); - }); -}); - -test('ignore array', function(t) { - t.plan(2); - - var b = browserify(); - b.add(__dirname + '/ignore/array.js'); - b.ignore([ - __dirname + '/ignore/skip.js', - __dirname + '/ignore/skip2.js' - ]); - - b.bundle(function (err, src) { - if (err) { - t.fail(err); - } - vm.runInNewContext(src, { t: t }); - }); -}); - -test('ignore by package or id', function (t) { - t.plan(3); - - var b = browserify(); - b.add(__dirname + '/ignore/by-id.js'); - b.ignore('events'); - b.ignore('beep'); - b.ignore('bad id'); - - b.bundle(function (err, src) { - if (err) t.fail(err); - vm.runInNewContext(src, { t: t }); - }); -}); - -test('ignore files referenced by relative path', function (t) { - // Change the current working directory relative to this file - var cwd = process.cwd(); - process.chdir(__dirname); - - t.plan(1); - - var b = browserify(); - b.add(__dirname + '/ignore/by-relative.js'); - b.ignore('./ignore/ignored/skip.js'); - - b.bundle(function (err, src) { - if (err) t.fail(err); - vm.runInNewContext(src, { t: t }); - }); - - // Revert CWD - process.chdir(cwd); -}); - -test('do not ignore files with relative paths that do not resolve', function (t) { - // Change the current working directory to the ignore folder - var cwd = process.cwd(); - process.chdir(__dirname + '/ignore'); - - t.plan(2); - - var b = browserify(); - b.add(__dirname + '/ignore/double-skip.js'); - - b.ignore('./skip.js'); - - b.bundle(function (err, src) { - if (err) t.fail(err); - vm.runInNewContext(src, { t: t }); - }); - - // Revert CWD - process.chdir(cwd); -}); +var browserify = require('../'); +var test = require('tap').test; +var vm = require('vm'); +var path = require('path'); + +test('ignore', function (t) { + t.plan(1); + + var b = browserify(); + b.add(__dirname + '/ignore/main.js'); + b.ignore(path.join(__dirname, 'ignore/skip.js')); + + b.bundle(function (err, src) { + if (err) t.fail(err); + vm.runInNewContext(src, { t: t }); + }); +}); + +test('ignore array', function(t) { + t.plan(2); + + var b = browserify(); + b.add(__dirname + '/ignore/array.js'); + b.ignore([ + path.join(__dirname, 'ignore/skip.js'), + path.join(__dirname, 'ignore/skip2.js') + ]); + + b.bundle(function (err, src) { + if (err) { + t.fail(err); + } + vm.runInNewContext(src, { t: t }); + }); +}); + +test('ignore by package or id', function (t) { + t.plan(3); + + var b = browserify(); + b.add(__dirname + '/ignore/by-id.js'); + b.ignore('events'); + b.ignore('beep'); + b.ignore('bad id'); + + b.bundle(function (err, src) { + if (err) t.fail(err); + vm.runInNewContext(src, { t: t }); + }); +}); + +test('ignore files referenced by relative path', function (t) { + // Change the current working directory relative to this file + var cwd = process.cwd(); + process.chdir(__dirname); + + t.plan(1); + + var b = browserify(); + b.add(__dirname + '/ignore/by-relative.js'); + b.ignore('./ignore/ignored/skip.js'); + + b.bundle(function (err, src) { + if (err) t.fail(err); + vm.runInNewContext(src, { t: t }); + }); + + // Revert CWD + process.chdir(cwd); +}); + +test('do not ignore files with relative paths that do not resolve', function (t) { + // Change the current working directory to the ignore folder + var cwd = process.cwd(); + process.chdir(__dirname + '/ignore'); + + t.plan(2); + + var b = browserify(); + b.add(__dirname + '/ignore/double-skip.js'); + + b.ignore('./skip.js'); + + b.bundle(function (err, src) { + if (err) t.fail(err); + vm.runInNewContext(src, { t: t }); + }); + + // Revert CWD + process.chdir(cwd); +}); diff --git a/test/json.js b/test/json.js index ffa5333f4..0ec722028 100644 --- a/test/json.js +++ b/test/json.js @@ -1,6 +1,7 @@ var browserify = require('../'); var fs = require('fs'); var vm = require('vm'); +var semver = require('semver'); var test = require('tap').test; test('json', function (t) { @@ -18,7 +19,10 @@ test('json', function (t) { }); }); -test('verify evil json', function(t) { +// This works in Node v10 and up thanks to the JSON superset proposal, which +// allows the evil chars in javascript strings. +// https://github.com/tc39/proposal-json-superset +test('verify evil json', { skip: semver.gte(process.version, 'v10.0.0') }, function(t) { t.plan(1); fs.readFile(__dirname + '/json/evil-chars.json', function(err, data) { if (err) t.fail(err); @@ -42,3 +46,12 @@ test('evil json', function (t) { vm.runInNewContext(src, c); }); }); + +test('invalid json', function (t) { + var b = browserify(); + t.plan(1); + b.add(__dirname + '/json/invalid.js'); + b.bundle(function (err, src) { + t.ok(err); + }); +}); diff --git a/test/json/invalid.js b/test/json/invalid.js new file mode 100644 index 000000000..36ef338f4 --- /dev/null +++ b/test/json/invalid.js @@ -0,0 +1,2 @@ +ex(require('./invalid.json')); +ex(require('./invalid')); diff --git a/test/json/invalid.json b/test/json/invalid.json new file mode 100644 index 000000000..fb73e57aa --- /dev/null +++ b/test/json/invalid.json @@ -0,0 +1,3 @@ +{ + key: "value" +} \ No newline at end of file diff --git a/test/multi_entry.js b/test/multi_entry.js index f910eddc2..e38a7b3b4 100644 --- a/test/multi_entry.js +++ b/test/multi_entry.js @@ -1,12 +1,13 @@ var browserify = require('../'); var vm = require('vm'); +var path = require('path'); var test = require('tap').test; var fs = require('fs'); var testFiles = [ - __dirname + '/multi_entry/a.js', - __dirname + '/multi_entry/b.js', - __dirname + '/multi_entry/c.js' + path.join(__dirname, 'multi_entry/a.js'), + path.join(__dirname, 'multi_entry/b.js'), + path.join(__dirname, 'multi_entry/c.js') ]; test('multi entry', function (t) { @@ -105,7 +106,7 @@ test('entries as streams', function (t) { if (row.entry) { t.similar( row.file, - RegExp(__dirname + '/multi_entry/_stream_[\\d].js'), + RegExp(path.join(__dirname, 'multi_entry/_stream_').replace(/\\/g, '\\\\') + '[\\d].js'), 'should be full entry path' ); } diff --git a/test/multi_entry_cross_require.js b/test/multi_entry_cross_require.js index 0cc1a8829..43f04ea51 100644 --- a/test/multi_entry_cross_require.js +++ b/test/multi_entry_cross_require.js @@ -1,11 +1,12 @@ var browserify = require('../'); var vm = require('vm'); +var path = require('path'); var test = require('tap').test; var testFiles = [ - __dirname + '/multi_entry_cross_require/a.js', - __dirname + '/multi_entry_cross_require/lib/b.js', - __dirname + '/multi_entry_cross_require/c.js' + path.join(__dirname, 'multi_entry_cross_require/a.js'), + path.join(__dirname, 'multi_entry_cross_require/lib/b.js'), + path.join(__dirname, 'multi_entry_cross_require/c.js') ]; test('multi entry cross require', function (t) { diff --git a/test/multi_symlink.js b/test/multi_symlink.js index 913c7a3be..08a5b1dd6 100644 --- a/test/multi_symlink.js +++ b/test/multi_symlink.js @@ -2,7 +2,7 @@ var browserify = require('../'); var vm = require('vm'); var test = require('tap').test; -test('multiple symlink execution', function (t) { +test('multiple symlink execution', { skip: process.platform === 'win32' }, function (t) { t.plan(1); var b = browserify(__dirname + '/multi_symlink/main.js'); b.bundle(function (err, src) { diff --git a/test/noparse.js b/test/noparse.js index 7d0b3b272..37b2b4053 100644 --- a/test/noparse.js +++ b/test/noparse.js @@ -18,8 +18,8 @@ test('noParse array', function (t) { var b = browserify({ entries: [ __dirname + '/noparse/a.js' ], noParse: [ - __dirname + '/noparse/dir1/1.js', - __dirname + '/noparse/node_modules/robot/main.js' + path.join(__dirname, 'noparse/dir1/1.js'), + path.join(__dirname, 'noparse/node_modules/robot/main.js') ] }); b.on('dep', function(dep) { actual.push(dep.file); }); @@ -29,3 +29,31 @@ test('noParse array', function (t) { t.deepEqual(actual, expected); }); }); + +test('noParse array with relative paths', function (t) { + process.chdir(__dirname); + + t.plan(2); + + var actual = []; + var expected = [ + 'noparse/a.js', + 'noparse/b.js', + 'noparse/dir1/1.js', + 'noparse/node_modules/robot/main.js' + ].map(function (x) { return path.resolve(x); }).sort(); + + var b = browserify({ + entries: [__dirname + '/noparse/a.js'], + noParse: [ + path.join('noparse/dir1/1.js'), + path.join('noparse/node_modules/robot/main.js') + ] + }); + b.on('dep', function (dep) { actual.push(dep.file); }); + b.bundle(function (err, src) { + actual.sort(); + t.ifError(err); + t.deepEqual(actual, expected); + }); +}); diff --git a/test/preserve-symlinks.js b/test/preserve-symlinks.js index aefb99361..83940ddc4 100644 --- a/test/preserve-symlinks.js +++ b/test/preserve-symlinks.js @@ -2,24 +2,24 @@ var browserify = require('../'); var vm = require('vm'); var test = require('tap').test; -test('optionally preserves symlinks', function (t) { +test('optionally preserves symlinks', { skip: process.platform === 'win32' }, function (t) { t.plan(2); var b = browserify(__dirname + '/preserve_symlinks/a/index.js', {preserveSymlinks: true}); b.bundle(function (err, buf) { - t.ok(!err); + t.ifError(err); t.ok(buf); var src = buf.toString('utf8'); vm.runInNewContext(src, {}); }); }); -test('always resolve entry point symlink', function (t) { +test('always resolve entry point symlink', { skip: process.platform === 'win32' }, function (t) { t.plan(2); var b = browserify(__dirname + '/preserve_symlinks/linked-entry.js', {preserveSymlinks: true}); b.bundle(function (err, buf) { - t.ok(!err); + t.ifError(err); t.ok(buf); var src = buf.toString('utf8'); vm.runInNewContext(src, {}); diff --git a/test/resolve_exposed.js b/test/resolve_exposed.js index 0d3efc24b..1dbea4211 100644 --- a/test/resolve_exposed.js +++ b/test/resolve_exposed.js @@ -4,7 +4,7 @@ var test = require('tap').test; test('resolve exposed files', function (t) { t.plan(2); - + var b = browserify(__dirname + '/resolve_exposed/main.js', { basedir: __dirname + '/resolve_exposed' }); @@ -18,3 +18,71 @@ test('resolve exposed files', function (t) { } }); }); + +test('resolve exposed files without extension', function (t) { + t.plan(2); + + var b = browserify(__dirname + '/resolve_exposed/main.js', { + basedir: __dirname + '/resolve_exposed' + }); + b.require('./x', {expose: 'xyz'}); + b.bundle(function (err, src) { + t.ifError(err); + var c = {console: {log: log}}; + vm.runInNewContext(src, c); + function log(x) { + t.equal(x, 333); + } + }); +}); + +test('resolve exposed directories', function (t) { + t.plan(2); + + var b = browserify(__dirname + '/resolve_exposed/main.js', { + basedir: __dirname + '/resolve_exposed' + }); + b.require('./y', {expose: 'xyz'}); + b.bundle(function (err, src) { + t.ifError(err); + var c = {console: {log: log}}; + vm.runInNewContext(src, c); + function log(x) { + t.equal(x, 555); + } + }); +}); + +test('resolve exposed index from directories', function (t) { + t.plan(2); + + var b = browserify(__dirname + '/resolve_exposed/main.js', { + basedir: __dirname + '/resolve_exposed' + }); + b.require('./y/index', {expose: 'xyz'}); + b.bundle(function (err, src) { + t.ifError(err); + var c = {console: {log: log}}; + vm.runInNewContext(src, c); + function log(x) { + t.equal(x, 555); + } + }); +}); + +test('resolve exposed index.js from directories', function (t) { + t.plan(2); + + var b = browserify(__dirname + '/resolve_exposed/main.js', { + basedir: __dirname + '/resolve_exposed' + }); + b.require('./y/index.js', {expose: 'xyz'}); + b.bundle(function (err, src) { + t.ifError(err); + var c = {console: {log: log}}; + vm.runInNewContext(src, c); + function log(x) { + t.equal(x, 555); + } + }); +}); diff --git a/test/resolve_exposed/y/index.js b/test/resolve_exposed/y/index.js new file mode 100644 index 000000000..caedade49 --- /dev/null +++ b/test/resolve_exposed/y/index.js @@ -0,0 +1 @@ +module.exports = 5 diff --git a/test/reverse_multi_bundle.js b/test/reverse_multi_bundle.js index 8d9f8325f..1a7537e65 100644 --- a/test/reverse_multi_bundle.js +++ b/test/reverse_multi_bundle.js @@ -12,7 +12,7 @@ var test = require('tap').test; test('reverse multi bundle', function (t) { t.plan(5); - // Main app bundle has the main app code and the shared libarary code + // Main app bundle has the main app code and the shared library code var app = browserify([__dirname + '/reverse_multi_bundle/app.js']) .external(__dirname + '/reverse_multi_bundle/lazy.js') .require(__dirname + '/reverse_multi_bundle/shared.js', { expose: true }) diff --git a/test/shared_symlink.js b/test/shared_symlink.js index d5287c139..7b37f2aa4 100644 --- a/test/shared_symlink.js +++ b/test/shared_symlink.js @@ -4,13 +4,14 @@ var browserify = require('../'); var vm = require('vm'); var test = require('tap').test; -test('shared symlink', function (t) { +test('shared symlink', { skip: process.platform === 'win32' }, function (t) { t.plan(1); var b = browserify(__dirname + '/shared_symlink/main.js'); b.bundle(function (err, src) { // does the same thing as node: crashes - t.equal(err.message, "Cannot find module 'foo' from '" - + __dirname + "/shared_symlink/shared'" + t.equal(err.message, "Can't walk dependency graph: Cannot find module 'foo' " + + "from '" + __dirname + "/shared_symlink/shared/index.js'\n" + + " required by " + __dirname + "/shared_symlink/shared/index.js" ); }); }); diff --git a/test/symlink_dedupe.js b/test/symlink_dedupe.js index 00d21d15c..dbc7afe63 100644 --- a/test/symlink_dedupe.js +++ b/test/symlink_dedupe.js @@ -2,7 +2,7 @@ var browserify = require('../'); var vm = require('vm'); var test = require('tap').test; -test('hash instances with hashed contexts', function (t) { +test('hash instances with hashed contexts', { skip: process.platform === 'win32' }, function (t) { t.plan(5); var b = browserify(__dirname + '/symlink_dedupe/main.js'); diff --git a/test/syntax_cache.js b/test/syntax_cache.js index ff2a5deec..202e5f6d7 100644 --- a/test/syntax_cache.js +++ b/test/syntax_cache.js @@ -1,7 +1,7 @@ var Seq = require('seq'); var browserify = require('../'); var test = require('tap').test; -var shasum = require('shasum'); +var shasum = require('shasum-object'); test('syntax cache - valid', function (t) { t.plan(2); diff --git a/test/tr_symlink.js b/test/tr_symlink.js index ae3210a50..9fcca56de 100644 --- a/test/tr_symlink.js +++ b/test/tr_symlink.js @@ -6,7 +6,7 @@ var vm = require('vm'); var test = require('tap').test; var through = require('through2'); -test('transform symlink', function (t) { +test('transform symlink', { skip: process.platform === 'win32' }, function (t) { t.plan(4); var expected = [ 9, 555, 777 ]; var b = browserify(__dirname + '/tr_symlink/app/main.js', { diff --git a/test/util.js b/test/util.js index 760acf1e3..a5cc8cdc7 100644 --- a/test/util.js +++ b/test/util.js @@ -1,6 +1,7 @@ var browserify = require('../'); var test = require('tap').test; var util = require('util'); +var xtend = require('xtend'); var vm = require('vm'); test('util.inspect', function (t) { @@ -46,7 +47,8 @@ test('util.inherits without Object.create', function (t) { b.require('events'); b.bundle(function (err, src) { - var c = { Object : { prototype: Object.prototype } }; + var c = xtend({}, Object); + delete c.create; vm.runInNewContext(src, c); var EE = c.require('events').EventEmitter;