├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── bin.js ├── index.js ├── package.json └── test ├── assert.sh ├── cases ├── 1 │ ├── a.js │ ├── b.js │ └── index.js ├── 2 │ └── index.js ├── 3 │ ├── index1.js │ └── index2.js ├── 4 │ ├── a.js │ ├── b.js │ ├── index.js │ ├── index1.js │ └── index2.js ├── 5 │ ├── foo.json │ └── index.js ├── 6 │ ├── w.js │ ├── x.js │ ├── y.js │ └── z.js ├── 7 │ └── index.js ├── 8 │ ├── alpha │ │ ├── a.js │ │ └── z.js │ ├── index.js │ ├── w.js │ ├── x.js │ └── y.js └── 9 │ ├── a.js │ ├── b.js │ └── index.js └── test.sh /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "6" 5 | 6 | sudo: false 7 | 8 | script: npm test 9 | 10 | branches: 11 | only: 12 | - master 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | browserify-count-modules [![Build Status](https://travis-ci.org/nolanlawson/browserify-count-modules.svg?branch=master)](https://travis-ci.org/nolanlawson/browserify-count-modules) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) 2 | ======== 3 | 4 | Count the total number of modules in a Browserify bundle. 5 | 6 | npm install -g browserify-count-modules 7 | 8 | CLI Usage 9 | --- 10 | 11 | browserify path/to/module/root | bcm 12 | 13 | This will output the total number of modules as an integer. 14 | 15 | ### Example 16 | 17 | Let's say you have three JavaScript files: 18 | 19 | ```js 20 | // a.js 21 | module.exports = 'a' 22 | ``` 23 | 24 | ```js 25 | // b.js 26 | module.exports = 'b' 27 | ``` 28 | 29 | ```js 30 | // index.js 31 | module.exports = require('./a') + require('./b') 32 | ``` 33 | 34 | Now count the modules: 35 | 36 | $ browserify ./index.js | bcm 37 | 3 38 | 39 | In this example, there are three modules: `index.js`, `a.js`, `b.js`. 40 | 41 | Note that "modules" includes both first-party and third-party modules. So for instance, if you have one npm dependency, 42 | and that dependency has 5 modules, then its 5 modules will be added to your total module count. This also applies to 43 | implicit Browserify dependencies, such as `Buffer` (which resolves to [feross/buffer](https://github.com/feross/buffer)). 44 | 45 | This tool correctly handles `--standalone`, `factor-bundle`, `bundle-collapser`, and minified bundles as well. 46 | Just pass in any Browserify bundle and it'll work. 47 | 48 | ### Verbose mode 49 | 50 | If you are able to `browserify --full-paths`, then you can use `--verbose` 51 | to get a full list of modules in the bundle: 52 | 53 | browserify --full-paths path/to/module/root | bcm --verbose 54 | 55 | This prints out something like: 56 | 57 | ``` 58 | Total number of modules: 3 59 | 60 | Modules: 61 | - /Users/me/project/a.js 62 | - /Users/me/project/b.js 63 | - /Users/me/project/index.js 64 | ``` 65 | 66 | Note that this only works with `--full-paths`. 67 | 68 | JavaScript API 69 | ---- 70 | 71 | Via the JavaScript API, you can get the total count of modules for a given JavaScript bundle 72 | by passing it in as a string. The count you get back will be an integer. 73 | 74 | ```js 75 | var browserifyCountModules = require('browserify-count-modules') 76 | 77 | var jsFile = readFileSync('./my-bundle.js', 'utf8') 78 | 79 | browserifyCountModules(jsFile, function (err, count) { 80 | if (err) { 81 | return 'oh no an error' 82 | } 83 | console.log('here is the count', count) 84 | }) 85 | ``` 86 | 87 | You can also get the list of dedup'ed and sorted modules by passing in `{verbose: true}`: 88 | 89 | ```js 90 | var browserifyCountModules = require('browserify-count-modules') 91 | 92 | var jsFile = readFileSync('./my-bundle.js', 'utf8') 93 | 94 | browserifyCountModules(jsFile, {verbose: true}, function (err, modules) { 95 | if (err) { 96 | return 'oh no an error' 97 | } 98 | console.log('here are the modules', modules) 99 | }) 100 | ``` 101 | -------------------------------------------------------------------------------- /bin.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict' 4 | 5 | var concat = require('concat-stream') 6 | var browserifyCountModules = require('./') 7 | var yargs = require('yargs') 8 | var argv = yargs 9 | .usage('Usage: $0 [ --verbose ]') 10 | .example('browserify index.js | $0', 'count the number of modules') 11 | .example('browserify --full-paths index.js | $0 --verbose', 'show a full list of modules') 12 | .alias('v', 'verbose') 13 | .describe('v', 'Verbose mode') 14 | .help('h') 15 | .alias('h', 'help') 16 | .argv 17 | 18 | process.stdin.pipe(concat(function (buf) { 19 | var str = buf.toString('utf8') 20 | browserifyCountModules(str, {verbose: argv.verbose}, function (err, res) { 21 | if (err) { 22 | console.error(err) 23 | process.exit(1) 24 | return 25 | } 26 | if (argv.verbose) { 27 | console.log('\nTotal number of modules: ' + res.length + '\n') 28 | console.log('Modules:') 29 | console.log(res.map(function (x) { return ' - ' + x }).join('\n') + '\n') 30 | } else { 31 | console.log(res) 32 | } 33 | process.exit(0) 34 | }) 35 | })).on('error', function (err) { 36 | console.error(err) 37 | process.exit(1) 38 | }) 39 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var acorn = require('acorn') 4 | var walk = require('walk-ast') 5 | var uniq = require('lodash.uniq') 6 | 7 | function getDepth (node) { 8 | var depth = 1 9 | while ((node = node.parentNode)) { 10 | depth++ 11 | } 12 | return depth 13 | } 14 | 15 | function browserifyCountModules (jsString, opts, cb) { 16 | if (typeof opts === 'function') { 17 | cb = opts 18 | opts = {} 19 | } 20 | var ast = acorn.parse(jsString) 21 | 22 | function parseForVerbose () { 23 | var modules = [] 24 | // You really have to look at the browserify --full-paths output 25 | // to understand what's going on here... the ArrayExpressions are at the end 26 | // and enumerate the top-level paths. then there are also ObjectExpressions 27 | // inside which define the dependencies. I just grab them all and then uniq() 28 | // at the end. 29 | // The getDepth() checks are to ensure we ignore any browserify bundles-within-bundles, 30 | // e.g. in case somebody literally included a browserify bundle itself within a module. 31 | walk(ast, function (node) { 32 | if (node.type === 'ArrayExpression' && 33 | node.parentNode.type === 'CallExpression' && 34 | node.parentNode.callee.type === 'FunctionExpression' && 35 | getDepth(node) === 4) { 36 | modules = modules.concat(node.elements.map(function (el) { 37 | return el.value 38 | })) 39 | } else if (node.type === 'ObjectExpression' && 40 | node.parentNode.type === 'ArrayExpression' && 41 | getDepth(node) === 6) { 42 | node.properties.forEach(function (prop) { 43 | modules.push(prop.value.value) 44 | }) 45 | } 46 | }) 47 | modules = modules.filter(function (mod) { 48 | return typeof mod === 'string' // excluded bundles-within-bundles and other extranea 49 | }) 50 | if (modules.length) { 51 | return cb(null, uniq(modules).sort()) 52 | } 53 | cb(new Error("Couldn't parse this input. " + 54 | 'Verbose mode requires browserify --full-paths. Is this a full-paths file?')) 55 | } 56 | 57 | function parseForCountOnly () { 58 | // This seems to consistently match the Browserify modules definition and gives the uniq'd count. 59 | // Exiting early ensures that we ignore Browserify bundles-within-bundles. 60 | walk(ast, function (node) { 61 | if (node.type === 'ObjectExpression' && 62 | node.parentNode.type === 'CallExpression' && 63 | node.parentNode.callee.type === 'FunctionExpression') { 64 | cb(null, node.properties.length) 65 | } 66 | }) 67 | cb(new Error("Couldn't parse this input. Are you sure it's a Browserify bundle?")) 68 | } 69 | 70 | if (opts.verbose) { 71 | parseForVerbose() 72 | } else { 73 | parseForCountOnly() 74 | } 75 | } 76 | 77 | module.exports = browserifyCountModules 78 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "browserify-count-modules", 3 | "version": "1.1.1", 4 | "description": "Count the total number of modules in a Browserify bundle", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "standard && bash test/test.sh" 8 | }, 9 | "bin": { 10 | "browserify-count-modules": "bin.js", 11 | "bcm": "bin.js" 12 | }, 13 | "keywords": [ 14 | "browserify", 15 | "count", 16 | "modules" 17 | ], 18 | "author": "Nolan Lawson ", 19 | "license": "Apache-2.0", 20 | "dependencies": { 21 | "acorn": "^3.3.0", 22 | "concat-stream": "^1.5.1", 23 | "lodash.uniq": "^4.5.0", 24 | "walk-ast": "^0.0.2", 25 | "yargs": "^4.8.1" 26 | }, 27 | "devDependencies": { 28 | "browserify": "13.1.0", 29 | "bundle-collapser": "1.2.1", 30 | "factor-bundle": "2.5.0", 31 | "rimraf": "2.5.4", 32 | "standard": "^7.1.2", 33 | "uglify-js": "2.7.0" 34 | }, 35 | "files": [ 36 | "bin.js", 37 | "index.js" 38 | ], 39 | "standard": { 40 | "ignore": [ 41 | "test/cases/**" 42 | ] 43 | }, 44 | "repository": { 45 | "type": "git", 46 | "url": "git+https://github.com/nolanlawson/browserify-count-modules.git" 47 | }, 48 | "bugs": { 49 | "url": "https://github.com/nolanlawson/browserify-count-modules/issues" 50 | }, 51 | "homepage": "https://github.com/nolanlawson/browserify-count-modules#readme" 52 | } 53 | -------------------------------------------------------------------------------- /test/assert.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # assert.sh 1.1 - bash unit testing framework 3 | # Copyright (C) 2009-2015 Robert Lehmann 4 | # 5 | # http://github.com/lehmannro/assert.sh 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU Lesser General Public License as published 9 | # by the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public License 18 | # along with this program. If not, see . 19 | 20 | export DISCOVERONLY=${DISCOVERONLY:-} 21 | export DEBUG=${DEBUG:-} 22 | export STOP=${STOP:-} 23 | export INVARIANT=${INVARIANT:-} 24 | export CONTINUE=${CONTINUE:-} 25 | 26 | args="$(getopt -n "$0" -l \ 27 | verbose,help,stop,discover,invariant,continue vhxdic $*)" \ 28 | || exit -1 29 | for arg in $args; do 30 | case "$arg" in 31 | -h) 32 | echo "$0 [-vxidc]" \ 33 | "[--verbose] [--stop] [--invariant] [--discover] [--continue]" 34 | echo "`sed 's/./ /g' <<< "$0"` [-h] [--help]" 35 | exit 0;; 36 | --help) 37 | cat < [stdin] 103 | (( tests_ran++ )) || : 104 | [[ -z "$DISCOVERONLY" ]] || return 105 | expected=$(echo -ne "${2:-}") 106 | result="$(eval 2>/dev/null $1 <<< ${3:-})" || true 107 | if [[ "$result" == "$expected" ]]; then 108 | [[ -z "$DEBUG" ]] || echo -n . 109 | return 110 | fi 111 | result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<< "$result")" 112 | [[ -z "$result" ]] && result="nothing" || result="\"$result\"" 113 | [[ -z "$2" ]] && expected="nothing" || expected="\"$2\"" 114 | _assert_fail "expected $expected${_indent}got $result" "$1" "$3" 115 | } 116 | 117 | assert_raises() { 118 | # assert_raises [stdin] 119 | (( tests_ran++ )) || : 120 | [[ -z "$DISCOVERONLY" ]] || return 121 | status=0 122 | (eval $1 <<< ${3:-}) > /dev/null 2>&1 || status=$? 123 | expected=${2:-0} 124 | if [[ "$status" -eq "$expected" ]]; then 125 | [[ -z "$DEBUG" ]] || echo -n . 126 | return 127 | fi 128 | _assert_fail "program terminated with code $status instead of $expected" "$1" "$3" 129 | } 130 | 131 | _assert_fail() { 132 | # _assert_fail 133 | [[ -n "$DEBUG" ]] && echo -n X 134 | report="test #$tests_ran \"$2${3:+ <<< $3}\" failed:${_indent}$1" 135 | if [[ -n "$STOP" ]]; then 136 | [[ -n "$DEBUG" ]] && echo 137 | echo "$report" 138 | exit 1 139 | fi 140 | tests_errors[$tests_failed]="$report" 141 | (( tests_failed++ )) || : 142 | } 143 | 144 | skip_if() { 145 | # skip_if 146 | (eval $@) > /dev/null 2>&1 && status=0 || status=$? 147 | [[ "$status" -eq 0 ]] || return 148 | skip 149 | } 150 | 151 | skip() { 152 | # skip (no arguments) 153 | shopt -q extdebug && tests_extdebug=0 || tests_extdebug=1 154 | shopt -q -o errexit && tests_errexit=0 || tests_errexit=1 155 | # enable extdebug so returning 1 in a DEBUG trap handler skips next command 156 | shopt -s extdebug 157 | # disable errexit (set -e) so we can safely return 1 without causing exit 158 | set +o errexit 159 | tests_trapped=0 160 | trap _skip DEBUG 161 | } 162 | _skip() { 163 | if [[ $tests_trapped -eq 0 ]]; then 164 | # DEBUG trap for command we want to skip. Do not remove the handler 165 | # yet because *after* the command we need to reset extdebug/errexit (in 166 | # another DEBUG trap.) 167 | tests_trapped=1 168 | [[ -z "$DEBUG" ]] || echo -n s 169 | return 1 170 | else 171 | trap - DEBUG 172 | [[ $tests_extdebug -eq 0 ]] || shopt -u extdebug 173 | [[ $tests_errexit -eq 1 ]] || set -o errexit 174 | return 0 175 | fi 176 | } 177 | 178 | 179 | _assert_reset 180 | : ${tests_suite_status:=0} # remember if any of the tests failed so far 181 | _assert_cleanup() { 182 | local status=$? 183 | # modify exit code if it's not already non-zero 184 | [[ $status -eq 0 && -z $CONTINUE ]] && exit $tests_suite_status 185 | } 186 | trap _assert_cleanup EXIT 187 | -------------------------------------------------------------------------------- /test/cases/1/a.js: -------------------------------------------------------------------------------- 1 | var b = require('./b') 2 | module.exports = ['a', b] 3 | -------------------------------------------------------------------------------- /test/cases/1/b.js: -------------------------------------------------------------------------------- 1 | module.exports = 'b' 2 | -------------------------------------------------------------------------------- /test/cases/1/index.js: -------------------------------------------------------------------------------- 1 | console.log(require('./a'), require('./b')) 2 | -------------------------------------------------------------------------------- /test/cases/2/index.js: -------------------------------------------------------------------------------- 1 | module.exports = 'hello' 2 | -------------------------------------------------------------------------------- /test/cases/3/index1.js: -------------------------------------------------------------------------------- 1 | module.exports = 'foobar' 2 | -------------------------------------------------------------------------------- /test/cases/3/index2.js: -------------------------------------------------------------------------------- 1 | module.exports = 'hello' 2 | -------------------------------------------------------------------------------- /test/cases/4/a.js: -------------------------------------------------------------------------------- 1 | var b = require('./b') 2 | module.exports = ['a', b] 3 | -------------------------------------------------------------------------------- /test/cases/4/b.js: -------------------------------------------------------------------------------- 1 | module.exports = 'b' 2 | -------------------------------------------------------------------------------- /test/cases/4/index.js: -------------------------------------------------------------------------------- 1 | console.log(require('./a'), require('./b')) 2 | -------------------------------------------------------------------------------- /test/cases/4/index1.js: -------------------------------------------------------------------------------- 1 | module.exports = 'foobar' 2 | -------------------------------------------------------------------------------- /test/cases/4/index2.js: -------------------------------------------------------------------------------- 1 | module.exports = 'hello' 2 | -------------------------------------------------------------------------------- /test/cases/5/foo.json: -------------------------------------------------------------------------------- 1 | {"foo": "bar"} -------------------------------------------------------------------------------- /test/cases/5/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./foo.json') 2 | -------------------------------------------------------------------------------- /test/cases/6/w.js: -------------------------------------------------------------------------------- 1 | module.exports = function (n) { return n * 50 } 2 | -------------------------------------------------------------------------------- /test/cases/6/x.js: -------------------------------------------------------------------------------- 1 | var z = require('./z.js') 2 | var w = require('./w.js') 3 | console.log(z(5) * w(2)) 4 | -------------------------------------------------------------------------------- /test/cases/6/y.js: -------------------------------------------------------------------------------- 1 | var z = require('./z.js') 2 | console.log(z(2) + 111) 3 | -------------------------------------------------------------------------------- /test/cases/6/z.js: -------------------------------------------------------------------------------- 1 | module.exports = function (n) { return n * 111 } 2 | -------------------------------------------------------------------------------- /test/cases/7/index.js: -------------------------------------------------------------------------------- 1 | var buff = new Buffer('yolo') 2 | console.log(buff) 3 | -------------------------------------------------------------------------------- /test/cases/8/alpha/a.js: -------------------------------------------------------------------------------- 1 | module.exports = 12 2 | -------------------------------------------------------------------------------- /test/cases/8/alpha/z.js: -------------------------------------------------------------------------------- 1 | var a = require('./a') 2 | module.exports = function (n) { return a + n * 111 } 3 | -------------------------------------------------------------------------------- /test/cases/8/index.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | require('./w'), 3 | require('./x'), 4 | require('./y'), 5 | require('./alpha/a'), 6 | require('./alpha/z') 7 | ] 8 | -------------------------------------------------------------------------------- /test/cases/8/w.js: -------------------------------------------------------------------------------- 1 | module.exports = function (n) { return n * 50 } 2 | -------------------------------------------------------------------------------- /test/cases/8/x.js: -------------------------------------------------------------------------------- 1 | var z = require('./alpha/z.js') 2 | var w = require('./w.js') 3 | var a = require('./alpha/a') 4 | console.log(z(5) * w(2) * a) 5 | -------------------------------------------------------------------------------- /test/cases/8/y.js: -------------------------------------------------------------------------------- 1 | var z = require('./alpha/z.js') 2 | console.log(z(2) + 111) 3 | -------------------------------------------------------------------------------- /test/cases/9/a.js: -------------------------------------------------------------------------------- 1 | var b = require('./b') 2 | module.exports = ['a', b] 3 | -------------------------------------------------------------------------------- /test/cases/9/b.js: -------------------------------------------------------------------------------- 1 | 2 | // side effects from a derequire'd bundle 3 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.yolo = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o