├── .gitattributes ├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── bin └── pure-cjs.js ├── lib ├── astConsts.js ├── index.js ├── parseOptions.js ├── pathUtils.js ├── promise.js ├── replacer.js ├── replacerMap.js └── templates │ ├── external.js │ ├── preamble.js │ └── umdWrapper.js ├── package.json └── test ├── fixtures ├── a.js ├── b │ └── index.js ├── c.js └── data.json ├── mocha.opts ├── suites ├── a (exports A with externals) │ ├── expected.js │ ├── expected.js.map │ └── options.js ├── a (exports A with map and comments) │ ├── expected.js │ ├── expected.js.map │ └── options.js ├── a (exports A with map) │ ├── expected.js │ ├── expected.js.map │ └── options.js ├── a (exports A) │ ├── expected.js │ └── options.js └── c (no exports) │ ├── expected.js │ └── options.js └── test.js /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /node_modules 3 | npm-debug.log 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /test 2 | /.idea 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.11' 4 | - '0.10' 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Ingvar Stepanyan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pure-cjs 2 | 3 | Pure CommonJS Modules builder. 4 | 5 | ## Features 6 | 7 | * Minimal destination overhead (almost as small as concatenated file). 8 | * Resolves all the paths on build stage to static number identifiers (so saves space and execution time used for storing and resolving string paths, but should be used only for projects with static `require('./some/module')` calls and would fail on others (same restriction applicable for [r.js (Simplified CommonJS wrapper)](http://requirejs.org/docs/whyamd.html#sugar) and most projects already match this). 9 | * Ability to export `module.exports` from top module in [UMD](https://github.com/umdjs/umd) style (useful for building libs). 10 | * Allows to use [through](https://github.com/dominictarr/through)-stream(s) for pre-transformations. 11 | * Supports modules installed as `npm` dependencies in `node_modules` hierarchy. 12 | * Does not corrupt `require('systemModule')` calls, transforms only local ones. 13 | 14 | ## Console usage 15 | 16 | Installation: 17 | ```bash 18 | npm install -g pure-cjs 19 | ``` 20 | 21 | Command-line options: 22 | ``` 23 | -h, --help output usage information 24 | -V, --version output the version number 25 | -i, --input input file (required) 26 | -o, --output output file (defaults to .out.js) 27 | -m, --map file to store source map to (optional, defaults to .map) 28 | -c, --comments preserve comments in output 29 | -e, --exports top module exports destination (optional) 30 | -x, --extension default extension for requires (defaults to "js") 31 | -d, --module-dir modules directory name to look in (defaults to "node_modules") 32 | -s, --external [hash] external modules (names or JSON hashes) 33 | ``` 34 | 35 | Example: 36 | ```bash 37 | pure-cjs \ 38 | --input src/index.js \ 39 | --output dist/index.js \ 40 | --map \ 41 | --exports SuperLib \ 42 | --external lodash \ 43 | --external '{"jquery": {"global": "$", "amd": "../vendor/jquery.js"}}' 44 | ``` 45 | 46 | ## Usage from Grunt 47 | 48 | Check out [grunt-pure-cjs](https://github.com/RReverser/grunt-pure-cjs) to use builder as [Grunt](https://gruntjs.com/) plugin. 49 | 50 | ## Usage from Gulp 51 | 52 | Check out [gulp-pure-cjs](https://github.com/parroit/gulp-pure-cjs) to use builder as [Gulp](http://gulpjs.com/) plugin. 53 | 54 | ## Usage from Node.js code 55 | 56 | ```javascript 57 | var cjs = require('pure-cjs'); 58 | 59 | cjs.transform(options).then(function (result) { 60 | // handle successful result 61 | }, function (err) { 62 | // handle error 63 | }); 64 | ``` 65 | 66 | ### Options object 67 | 68 | * `input`: `String` | `Function()`.
69 | Input file.
70 | Example: `'superLib/topModule.js'` 71 | 72 | * `output`: `String` | `Function(input)`
73 | Output file.
74 | Default: `input => input.replace(/(\.js)?$/, '.out.js')` 75 | 76 | * `map`: `Boolean` | `String` | `Function(input, output)`
77 | Source map.
78 | Default: `false` (don't generate source map). 79 | 80 | * `comments`: `Boolean`
81 | Preserve comments in output.
82 | Default: `false` 83 | 84 | * `external`: `{ cjsName: (true | { amd?: String, global?: String }) }`
85 | External dependencies (to be excluded from bundling). Example: 86 | ```javascript 87 | { 88 | jquery: true, 89 | lodash: {amd: '../vendor/lodash.js', global: '_'} 90 | } 91 | ``` 92 | 93 | * `exports`: `String` | `Function(input, output)`
94 | Export top module with [UMD](https://github.com/umdjs/umd) with given global object name.
95 | Default: no exports. 96 | 97 | * `transform`: `Array` | `Function(input)`
98 | Browserify plugins ([through](https://github.com/dominictarr/through)-stream(s) to be used against input files). 99 | 100 | * `moduleDir`: `String`
101 | Modules directory name.
102 | Default: `"node_modules"` 103 | 104 | * `defaultExt`: `String`
105 | Default extension for require calls (`"js"`). 106 | 107 | * `dryRun`: `Boolean`
108 | Don't write output to disk (and don't append `//# sourceMappingURL=...` to code).
109 | Default: `false` 110 | 111 | ### Result object 112 | 113 | * **code**: `String` — generated source code. 114 | * **map**: `Object` — source map object. 115 | * **options**: `Object` — options object with resolved defaults and paths. 116 | -------------------------------------------------------------------------------- /bin/pure-cjs.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var program = require('commander'), 4 | cjs = require(__dirname + '/../lib/'); 5 | 6 | program 7 | .version(require(__dirname + '/../package.json').version) 8 | .option('-i, --input ', 'input file (required)') 9 | .option('-o, --output ', 'output file (defaults to .out.js)') 10 | .option('-x, --extension ', 'default extension for requires (defaults to "js")') 11 | .option('-m, --map [file]', 'file to store source map to (optional)') 12 | .option('-c, --comments', 'preserve comments in output') 13 | .option('-e, --exports ', 'top module exports destination (optional)') 14 | .option('-d, --module-dir ', 'top level location to search for external modules (optional)') 15 | .option('-s, --external [hash]', 'external modules (names or JSON hashes)', function (value, obj) { 16 | try { 17 | var add = JSON.parse(value); 18 | for (var name in add) { 19 | obj[name] = add[name]; 20 | } 21 | } catch (e) { 22 | obj[value] = true; 23 | } 24 | return obj; 25 | }, {}) 26 | .parse(process.argv); 27 | 28 | if (!program.input) { 29 | program.help(); 30 | } 31 | 32 | console.log('Building...'); 33 | 34 | cjs.transform(program).then(function (result) { 35 | console.log('Built to:', result.options.output); 36 | }, function (error) { 37 | console.error(error.stack); 38 | }); 39 | -------------------------------------------------------------------------------- /lib/astConsts.js: -------------------------------------------------------------------------------- 1 | var estemplate = require('estemplate'), 2 | b = require('ast-types').builders, 3 | fs = require('fs'); 4 | 5 | exports.moduleArgs = [b.identifier('module'), b.identifier('exports')]; 6 | 7 | exports.tmpl = {}; 8 | 9 | ['external', 'preamble', 'umdWrapper'].forEach(function (name) { 10 | var tmpl = estemplate.compile(fs.readFileSync(__dirname + '/templates/' + name + '.js', 'utf-8'), { 11 | comment: true, 12 | attachComment: true 13 | }); 14 | 15 | exports.tmpl[name] = function (data) { 16 | data.b = b; 17 | return tmpl(data).body[0].expression; 18 | }; 19 | }); -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'), 2 | b = require('ast-types').builders, 3 | generate = require('escodegen').generate, 4 | Promise = require('./promise'), 5 | astConsts = require('./astConsts'), 6 | parseOptions = require('./parseOptions'), 7 | pathUtils = require('./pathUtils'), 8 | ReplacerMap = require('./replacerMap'), 9 | whenWriteFile = Promise.wrap(fs.writeFile); 10 | 11 | exports.transformAST = function (inOptions) { 12 | var options = parseOptions(inOptions), 13 | map = new ReplacerMap(options), 14 | replacer = map.get(options.input); 15 | 16 | return map.whenAll().then(function (modules) { 17 | var factoryExpr = astConsts.tmpl.preamble({ 18 | deps: options.deps, 19 | exports: options.exports, 20 | modules: modules, 21 | replacer: replacer 22 | }); 23 | 24 | return { 25 | ast: b.program([b.expressionStatement( 26 | options.exports 27 | ? b.callExpression(astConsts.tmpl.umdWrapper(options), [factoryExpr]) 28 | : b.callExpression(factoryExpr, []) 29 | )]), 30 | options: options 31 | }; 32 | }); 33 | }; 34 | 35 | exports.transform = function (inOptions) { 36 | return exports.transformAST(inOptions).then(function (result) { 37 | var options = result.options; 38 | 39 | result = generate(result.ast, { 40 | sourceMap: !!options.map, 41 | comment: options.comments, 42 | sourceMapWithCode: true 43 | }); 44 | 45 | result.options = options; 46 | 47 | var whenOut; 48 | 49 | if (!options.dryRun) { 50 | if (options.map) { 51 | result.code += '\n//# sourceMappingURL=' + pathUtils.relative(pathUtils.std.dirname(options.output), options.map); 52 | whenOut = Promise.all( 53 | whenWriteFile(options.output, result.code), 54 | whenWriteFile(options.map, JSON.stringify(result.map)) 55 | ); 56 | } else { 57 | whenOut = whenWriteFile(options.output, result.code); 58 | } 59 | } else { 60 | whenOut = Promise.resolve(); 61 | } 62 | 63 | return whenOut.then(function () { 64 | return result; 65 | }); 66 | }); 67 | }; -------------------------------------------------------------------------------- /lib/parseOptions.js: -------------------------------------------------------------------------------- 1 | var pathUtils = require('./pathUtils'), 2 | es = require('event-stream'), 3 | b = require('ast-types').builders, 4 | Promise = require('./promise'), 5 | fs = require('fs'), 6 | esprima = require('esprima'); 7 | 8 | function toValue(value) { 9 | return value instanceof Function ? value.apply(null, Array.prototype.slice.call(arguments, 1)) : value; 10 | } 11 | 12 | module.exports = function (inOptions) { 13 | var options = { 14 | defaultExt: inOptions.defaultExt || 'js', 15 | moduleDir: inOptions.moduleDir || 'node_modules', 16 | input: pathUtils.normalizePath(toValue(inOptions.input)) 17 | }; 18 | 19 | options.output = pathUtils.normalizePath(toValue( 20 | inOptions.output || function (input) { 21 | return pathUtils.forceExt(input, 'out.js'); 22 | }, 23 | options.input 24 | )); 25 | 26 | if (inOptions.map) { 27 | options.map = pathUtils.normalizePath(toValue( 28 | inOptions.map !== true ? inOptions.map : function (input, output) { 29 | return output + '.map'; 30 | }, 31 | options.input, 32 | options.output 33 | )); 34 | } 35 | 36 | options.exports = toValue(inOptions.exports, options.input, options.output); 37 | 38 | var transforms = inOptions.transform; 39 | transforms = transforms ? (transforms instanceof Array ? transforms : [transforms]) : []; 40 | 41 | options.comments = !!inOptions.comments; 42 | options.dryRun = !!inOptions.dryRun; 43 | 44 | options.deps = []; 45 | 46 | for (var name in inOptions.external) { 47 | var inDep = inOptions.external[name]; 48 | if (inDep === true) { 49 | inDep = {}; 50 | } 51 | if (inDep === false) { 52 | inDep = {global: false, amd: false}; 53 | } 54 | var globalName = inDep.global || name.replace(/\W/g, ''); 55 | var dep = { 56 | name: inDep.name !== undefined ? inDep.name : name, 57 | global: inDep.global !== undefined ? inDep.global : globalName, 58 | amd: inDep.amd !== undefined ? inDep.amd : name 59 | }; 60 | dep.id = b.identifier(inDep.id || ('__external_' + globalName)); 61 | options.deps.push(dep); 62 | } 63 | 64 | var getFileStream = inOptions.getFileStream || function (path) { 65 | return fs.createReadStream(path, {encoding: 'utf-8'}); 66 | }; 67 | 68 | var getFileContents = inOptions.getFileContents || function (path) { 69 | var pipeline = transforms.reduce(function (stream, transform) { 70 | return stream.pipe(transform(path)); 71 | }, getFileStream(path)); 72 | 73 | var defer = Promise.defer(); 74 | 75 | pipeline.pipe(es.wait(function (err, js) { 76 | err ? defer.reject(err) : defer.fulfill(js); 77 | })); 78 | 79 | return defer.promise; 80 | }; 81 | 82 | options.getFileAST = inOptions.getFileAST || function (parseOpts) { 83 | return getFileContents(parseOpts.source).then(function (js) { 84 | if (pathUtils.ext(parseOpts.source) === 'json') { 85 | js = 'module.exports = ' + js; 86 | } 87 | return esprima.parse(js, parseOpts); 88 | }); 89 | }; 90 | 91 | return options; 92 | }; -------------------------------------------------------------------------------- /lib/pathUtils.js: -------------------------------------------------------------------------------- 1 | var stdUtils = exports.std = require('path'), 2 | nodeResolve = require('resolve'), 3 | badPathSep = /\\/g; 4 | 5 | exports.forceExt = function (path, ext) { 6 | return path + (exports.ext(path) ? '' : '.' + ext); 7 | }; 8 | 9 | exports.normalizePath = function (path) { 10 | return exports.relative('', path); 11 | }; 12 | 13 | exports.relative = function (from, to) { 14 | return stdUtils.relative(from, to).replace(badPathSep, '/'); 15 | }; 16 | 17 | exports.getNodePath = function (from, to, options) { 18 | var fromDir = from + '/..'; 19 | 20 | return exports.normalizePath(nodeResolve.sync(to, { 21 | basedir: stdUtils.resolve('', fromDir), 22 | extensions: (options.defaultExt !== 'js' ? ['.' + options.defaultExt] : []).concat(['.js', '.json']), 23 | moduleDirectory: options.moduleDir 24 | })); 25 | }; 26 | 27 | exports.ext = function (path) { 28 | return stdUtils.extname(path).slice(1).toLowerCase(); 29 | }; -------------------------------------------------------------------------------- /lib/promise.js: -------------------------------------------------------------------------------- 1 | module.exports = require('davy'); -------------------------------------------------------------------------------- /lib/replacer.js: -------------------------------------------------------------------------------- 1 | var Promise = require('./promise'), 2 | pathUtils = require('./pathUtils'), 3 | astTypes = require('ast-types'), 4 | astConsts = require('./astConsts'), 5 | b = astTypes.builders, 6 | n = astTypes.namedTypes; 7 | 8 | function Replacer(options) { 9 | this.id = undefined; 10 | this.map = options.map; 11 | this.path = options.path; 12 | this.refs = []; 13 | 14 | if (options.externalId) { 15 | this.promise = Promise.resolve([b.expressionStatement(astConsts.tmpl.external(options))]); 16 | } else { 17 | this.promise = this.map.getFileAST({ 18 | source: this.path, 19 | loc: true, 20 | comment: options.comments, 21 | attachComment: options.comments 22 | }).then(function (ast) { 23 | this.visit(ast); 24 | return ast.body; 25 | }.bind(this)); 26 | } 27 | 28 | this.promise = this.promise.then(function (body) { 29 | return b.functionExpression(null, astConsts.moduleArgs, b.blockStatement(body)); 30 | }); 31 | } 32 | 33 | Replacer.prototype.getDependency = function (path) { 34 | return this.map.get(pathUtils.getNodePath(this.path, path, this.map)); 35 | }; 36 | 37 | Replacer.prototype.referenceFrom = function (ref) { 38 | this.refs.push(ref); 39 | return this; 40 | }; 41 | 42 | Replacer.prototype.resolveAs = function (id) { 43 | this.id = id; 44 | 45 | this.refs.forEach(function (ref) { 46 | ref.value = this.id; 47 | }, this); 48 | 49 | return this; 50 | }; 51 | 52 | Replacer.prototype.visit = function (ast) { 53 | var replacer = this; 54 | 55 | return astTypes.visit(ast, { 56 | visitCallExpression: function (path) { 57 | var node = path.node, 58 | func = node.callee, 59 | arg = node.arguments[0]; 60 | 61 | if (n.Identifier.check(func) && func.name === 'require' && n.Literal.check(arg)) { 62 | func.name = '_require'; 63 | replacer.getDependency(arg.value).referenceFrom(arg); 64 | } 65 | 66 | this.traverse(path); 67 | } 68 | }); 69 | }; 70 | 71 | module.exports = Replacer; -------------------------------------------------------------------------------- /lib/replacerMap.js: -------------------------------------------------------------------------------- 1 | var Promise = require('./promise'), 2 | Replacer = require('./replacer'), 3 | pathUtils = require('./pathUtils'); 4 | 5 | function ReplacerMap(options) { 6 | this.replacers = {}; 7 | this.promises = []; 8 | this.getFileAST = options.getFileAST; 9 | this.comments = options.comments; 10 | this.defaultExt = options.defaultExt; 11 | this.moduleDir = options.moduleDir; 12 | this.depsMap = options.deps.reduce(function (obj, dep) { 13 | obj[pathUtils.getNodePath('_', dep.name, this)] = dep; 14 | return obj; 15 | }.bind(this), {}); 16 | } 17 | 18 | ReplacerMap.prototype.get = function (path) { 19 | if (path in this.replacers) { 20 | return this.replacers[path]; 21 | } 22 | 23 | var id = this.promises.length++, 24 | replacer = this.replacers[path] = new Replacer({ 25 | map: this, 26 | path: path, 27 | comments: this.comments, 28 | externalId: (this.depsMap[path] || {}).id 29 | }); 30 | 31 | this.promises[id] = replacer.promise; 32 | 33 | return replacer; 34 | }; 35 | 36 | ReplacerMap.prototype.whenAll = function (startIndex) { 37 | var map = this, currentLength = this.promises.length; 38 | 39 | return ( 40 | Promise.all(this.promises.slice(startIndex || 0)) 41 | .then(function () { 42 | if (map.promises.length > currentLength) { 43 | return map.whenAll(currentLength); 44 | } 45 | }) 46 | .then(function () { 47 | return Promise.all(Object.keys(map.replacers).sort().map(function (path, id) { 48 | return this[path].resolveAs(id).promise; 49 | }, map.replacers)); 50 | }) 51 | ); 52 | }; 53 | 54 | module.exports = ReplacerMap; -------------------------------------------------------------------------------- /lib/templates/external.js: -------------------------------------------------------------------------------- 1 | module.exports = <%= externalId %>; -------------------------------------------------------------------------------- /lib/templates/preamble.js: -------------------------------------------------------------------------------- 1 | (function (%= deps.map(function (dep) { return dep.id }) %) { 2 | var global = this, define; 3 | 4 | function _require(id) { 5 | var module = _require.cache[id]; 6 | 7 | if (!module) { 8 | var exports = {}; 9 | module = _require.cache[id] = {id: id, exports: exports}; 10 | _require.modules[id].call(exports, module, exports); 11 | } 12 | 13 | return module.exports; 14 | } 15 | 16 | _require.cache = []; 17 | _require.modules = [%= modules %]; 18 | 19 | return _require(<%= b.literal(replacer.id) %>); 20 | }) -------------------------------------------------------------------------------- /lib/templates/umdWrapper.js: -------------------------------------------------------------------------------- 1 | <% 2 | var undef = b.identifier('undefined'); 3 | %> 4 | (function (factory) { 5 | if (typeof define === 'function' && define.amd) { 6 | // AMD. Register as an anonymous module. 7 | define([%= deps.map(function (dep) { 8 | return b.literal(dep.amd || ''); 9 | }) %], factory); 10 | } else if (typeof exports === 'object') { 11 | // Node. Does not work with strict CommonJS, but 12 | // only CommonJS-like enviroments that support module.exports, 13 | // like Node. 14 | module.exports = factory(%= deps.map(function (dep) { 15 | return dep.name ? b.callExpression(b.identifier('require'), [b.literal(dep.name)]) : undef; 16 | }) %); 17 | } else { 18 | // Browser globals 19 | this[<%= b.literal(exports) %>] = factory(%= deps.map(function (dep) { 20 | return dep.global ? b.identifier(dep.global) : undef; 21 | }) %); 22 | } 23 | }) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pure-cjs", 3 | "version": "1.18.2", 4 | "description": "Pure minimalistic CommonJS builder", 5 | "bin": "./bin/pure-cjs.js", 6 | "main": "./lib/index.js", 7 | "scripts": { 8 | "test": "mocha" 9 | }, 10 | "repository": "RReverser/pure-cjs", 11 | "author": "Ingvar Stepanyan (http://github.com/RReverser)", 12 | "license": "MIT", 13 | "dependencies": { 14 | "ast-types": "^0.6.5", 15 | "commander": "^2.5.0", 16 | "davy": "0.3.3", 17 | "escodegen": "git+https://github.com/RReverser/escodegen.git", 18 | "esprima": "^1.2.2", 19 | "estemplate": "^0.4.0", 20 | "event-stream": "^3.1.7", 21 | "resolve": "^1.0.0" 22 | }, 23 | "devDependencies": { 24 | "chai": "^1.10.0", 25 | "mocha": "^2.0.1", 26 | "source-map": "^0.1.40" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/a.js: -------------------------------------------------------------------------------- 1 | // License of a 2 | 3 | var c = require('./c'), 4 | url = require('url'), 5 | Promise = require('davy'); 6 | 7 | this.topValue = require('./b') * 2; 8 | this.expectedValue = require('./data.json').answer; -------------------------------------------------------------------------------- /test/fixtures/b/index.js: -------------------------------------------------------------------------------- 1 | // License of b 2 | 3 | module.exports = require('../c').value * 7; -------------------------------------------------------------------------------- /test/fixtures/c.js: -------------------------------------------------------------------------------- 1 | // License of c 2 | 3 | var a = require('./a'); 4 | exports.value = 3; -------------------------------------------------------------------------------- /test/fixtures/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "answer": 42 3 | } -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --reporter list 2 | test/test.js -------------------------------------------------------------------------------- /test/suites/a (exports A with externals)/expected.js: -------------------------------------------------------------------------------- 1 | (function (factory) { 2 | if (typeof define === 'function' && define.amd) { 3 | // AMD. Register as an anonymous module. 4 | define([ 5 | 'davy', 6 | '' 7 | ], factory); 8 | } else if (typeof exports === 'object') { 9 | // Node. Does not work with strict CommonJS, but 10 | // only CommonJS-like enviroments that support module.exports, 11 | // like Node. 12 | module.exports = factory(require('davy'), require('url')); 13 | } else { 14 | // Browser globals 15 | this['A'] = factory(davy, undefined); 16 | } 17 | }(function (__external_davy, __external_url) { 18 | var global = this, define; 19 | function _require(id) { 20 | var module = _require.cache[id]; 21 | if (!module) { 22 | var exports = {}; 23 | module = _require.cache[id] = { 24 | id: id, 25 | exports: exports 26 | }; 27 | _require.modules[id].call(exports, module, exports); 28 | } 29 | return module.exports; 30 | } 31 | _require.cache = []; 32 | _require.modules = [ 33 | function (module, exports) { 34 | module.exports = __external_davy; 35 | }, 36 | function (module, exports) { 37 | // License of a 38 | var c = _require(3), url = _require(5), Promise = _require(0); 39 | this.topValue = _require(2) * 2; 40 | this.expectedValue = _require(4).answer; 41 | }, 42 | function (module, exports) { 43 | // License of b 44 | module.exports = _require(3).value * 7; 45 | }, 46 | function (module, exports) { 47 | // License of c 48 | var a = _require(1); 49 | exports.value = 3; 50 | }, 51 | function (module, exports) { 52 | module.exports = { 'answer': 42 }; 53 | }, 54 | function (module, exports) { 55 | module.exports = __external_url; 56 | } 57 | ]; 58 | return _require(1); 59 | })); 60 | //# sourceMappingURL=expected.js.map -------------------------------------------------------------------------------- /test/suites/a (exports A with externals)/expected.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["fixtures/a.js","fixtures/b/index.js","fixtures/c.js","fixtures/data.json"],"names":["c","_require","url","Promise","topValue","expectedValue","answer","module","exports","value","a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAEA;AAAA,gBAAIA,CAAA,GAAIC,QAAA,CAAQ,CAAR,CAAR,EACCC,GAAA,GAAMD,QAAA,CAAQ,CAAR,CADP,EAECE,OAAA,GAAUF,QAAA,CAAQ,CAAR,CAFX,C;YAIA,KAAKG,QAAL,GAAgBH,QAAA,CAAQ,CAAR,IAAiB,CAAjC,C;YACA,KAAKI,aAAL,GAAqBJ,QAAA,CAAQ,CAAR,EAAuBK,MAA5C,C;;;YCLA;AAAA,YAAAC,MAAA,CAAOC,OAAP,GAAiBP,QAAA,CAAQ,CAAR,EAAgBQ,KAAhB,GAAwB,CAAzC,C;;;YCAA;AAAA,gBAAIC,CAAA,GAAIT,QAAA,CAAQ,CAAR,CAAR,C;YACAO,OAAA,CAAQC,KAAR,GAAgB,CAAhB,C;;;YCHAF,MAAA,CAAOC,OAAP,GAAiB,EAChB,UAAU,EADM,EAAjB,C"} -------------------------------------------------------------------------------- /test/suites/a (exports A with externals)/options.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | input: 'fixtures/a.js', 3 | exports: 'A', 4 | map: true, 5 | comments: true, 6 | external: { 7 | davy: true, 8 | url: { 9 | amd: false, 10 | global: false 11 | } 12 | } 13 | }; -------------------------------------------------------------------------------- /test/suites/a (exports A with map and comments)/expected.js: -------------------------------------------------------------------------------- 1 | (function (factory) { 2 | if (typeof define === 'function' && define.amd) { 3 | // AMD. Register as an anonymous module. 4 | define([''], factory); 5 | } else if (typeof exports === 'object') { 6 | // Node. Does not work with strict CommonJS, but 7 | // only CommonJS-like enviroments that support module.exports, 8 | // like Node. 9 | module.exports = factory(require('url')); 10 | } else { 11 | // Browser globals 12 | this['A'] = factory(undefined); 13 | } 14 | }(function (__external_url) { 15 | var global = this, define; 16 | function _require(id) { 17 | var module = _require.cache[id]; 18 | if (!module) { 19 | var exports = {}; 20 | module = _require.cache[id] = { 21 | id: id, 22 | exports: exports 23 | }; 24 | _require.modules[id].call(exports, module, exports); 25 | } 26 | return module.exports; 27 | } 28 | _require.cache = []; 29 | _require.modules = [ 30 | function (module, exports) { 31 | (function (global) { 32 | 'use strict'; 33 | var next; 34 | if (typeof define === 'function' && define.amd) { 35 | define(['subsequent'], function (subsequent) { 36 | next = subsequent; 37 | return Promise; 38 | }); 39 | } else if (typeof module === 'object' && module.exports) { 40 | module.exports = Promise; 41 | next = _require(2); 42 | } else { 43 | global.Davy = Promise; 44 | next = global.subsequent; 45 | } 46 | function Promise(fn) { 47 | this.value = undefined; 48 | this.__deferreds = []; 49 | if (arguments.length > 0) { 50 | var resolver = new Resolver(this); 51 | if (typeof fn == 'function') { 52 | try { 53 | fn(function (val) { 54 | resolver.fulfill(val); 55 | }, function (err) { 56 | resolver.reject(err); 57 | }); 58 | } catch (e) { 59 | resolver.reject(e); 60 | } 61 | } else { 62 | resolver.fulfill(fn); 63 | } 64 | } 65 | } 66 | Promise.prototype.isFulfilled = false; 67 | Promise.prototype.isRejected = false; 68 | Promise.prototype.then = function (onFulfill, onReject) { 69 | var resolver = new Resolver(new Promise()), deferred = defer(resolver, onFulfill, onReject); 70 | if (this.isFulfilled || this.isRejected) { 71 | resolve(deferred, this.isFulfilled ? Promise.SUCCESS : Promise.FAILURE, this.value); 72 | } else { 73 | this.__deferreds.push(deferred); 74 | } 75 | return resolver.promise; 76 | }; 77 | Promise.SUCCESS = 'fulfill'; 78 | Promise.FAILURE = 'reject'; 79 | function defer(resolver, fulfill, reject) { 80 | return { 81 | resolver: resolver, 82 | fulfill: fulfill, 83 | reject: reject 84 | }; 85 | } 86 | function Resolver(promise) { 87 | this.promise = promise; 88 | } 89 | Resolver.prototype.fulfill = function (value) { 90 | var promise = this.promise; 91 | if (promise.isFulfilled || promise.isRejected) 92 | return; 93 | if (value === promise) 94 | throw new TypeError('Can\'t resolve a promise with itself.'); 95 | if (isObject(value) || isFunction(value)) { 96 | var then; 97 | try { 98 | then = value.then; 99 | } catch (e) { 100 | this.reject(e); 101 | return; 102 | } 103 | if (isFunction(then)) { 104 | var isResolved = false, self = this; 105 | try { 106 | then.call(value, function (val) { 107 | if (!isResolved) { 108 | isResolved = true; 109 | self.fulfill(val); 110 | } 111 | }, function (err) { 112 | if (!isResolved) { 113 | isResolved = true; 114 | self.reject(err); 115 | } 116 | }); 117 | } catch (e) { 118 | if (!isResolved) { 119 | this.reject(e); 120 | } 121 | } 122 | return; 123 | } 124 | } 125 | promise.isFulfilled = true; 126 | this.complete(value); 127 | }; 128 | Resolver.prototype.reject = function (error) { 129 | var promise = this.promise; 130 | if (promise.isFulfilled || promise.isRejected) 131 | return; 132 | promise.isRejected = true; 133 | this.complete(error); 134 | }; 135 | Resolver.prototype.complete = function (value) { 136 | var promise = this.promise, deferreds = promise.__deferreds, type = promise.isFulfilled ? Promise.SUCCESS : Promise.FAILURE; 137 | promise.value = value; 138 | for (var i = 0; i < deferreds.length; ++i) { 139 | resolve(deferreds[i], type, value); 140 | } 141 | promise.__deferreds = undefined; 142 | }; 143 | function resolve(deferred, type, value) { 144 | var fn = deferred[type], resolver = deferred.resolver; 145 | if (isFunction(fn)) { 146 | next(function () { 147 | try { 148 | value = fn(value); 149 | resolver.fulfill(value); 150 | } catch (e) { 151 | resolver.reject(e); 152 | } 153 | }); 154 | } else { 155 | resolver[type](value); 156 | } 157 | } 158 | Promise.prototype['catch'] = function (onRejected) { 159 | return this.then(null, onRejected); 160 | }; 161 | Promise.prototype['throw'] = function () { 162 | return this['catch'](function (error) { 163 | next(function () { 164 | throw error; 165 | }); 166 | }); 167 | }; 168 | Promise.prototype['finally'] = function (onResolved) { 169 | return this.then(onResolved, onResolved); 170 | }; 171 | Promise.prototype['yield'] = function (value) { 172 | return this.then(function () { 173 | return value; 174 | }); 175 | }; 176 | Promise.prototype.tap = function (onFulfilled) { 177 | return this.then(onFulfilled)['yield'](this); 178 | }; 179 | Promise.prototype.spread = function (onFulfilled, onRejected) { 180 | return this.then(function (val) { 181 | return onFulfilled.apply(this, val); 182 | }, onRejected); 183 | }; 184 | Promise.resolve = Promise.cast = function (val) { 185 | if (isObject(val) && isFunction(val.then)) { 186 | return val; 187 | } 188 | return new Promise(val); 189 | }; 190 | Promise.reject = function (err) { 191 | var resolver = Promise.defer(); 192 | resolver.reject(err); 193 | return resolver.promise; 194 | }; 195 | Promise.defer = function () { 196 | return new Resolver(new Promise()); 197 | }; 198 | Promise.each = function (list, iterator) { 199 | var resolver = Promise.defer(), len = list.length; 200 | if (len === 0) 201 | resolver.reject(TypeError()); 202 | for (var i = 0; i < len; ++i) { 203 | iterator(list[i], i); 204 | } 205 | return resolver; 206 | }; 207 | Promise.all = function () { 208 | var list = parse(arguments), length = list.length, resolver = Promise.each(list, resolve); 209 | return resolver.promise; 210 | function reject(err) { 211 | resolver.reject(err); 212 | } 213 | function resolve(value, i) { 214 | if (isObject(value) && isFunction(value.then)) { 215 | value.then(function (val) { 216 | resolve(val, i); 217 | }, reject); 218 | return; 219 | } 220 | list[i] = value; 221 | if (--length === 0) { 222 | resolver.fulfill(list); 223 | } 224 | } 225 | }; 226 | Promise.race = function () { 227 | var list = parse(arguments), resolver = Promise.each(list, resolve); 228 | return resolver.promise; 229 | function reject(err) { 230 | resolver.reject(err); 231 | } 232 | function resolve(value) { 233 | if (isObject(value) && isFunction(value.then)) { 234 | value.then(resolve, reject); 235 | return; 236 | } 237 | resolver.fulfill(value); 238 | } 239 | }; 240 | Promise.wrap = function (fn) { 241 | return function () { 242 | var resolver = new Resolver(new Promise()); 243 | arguments[arguments.length++] = function (err, val) { 244 | if (err) { 245 | resolver.reject(err); 246 | } else { 247 | resolver.fulfill(val); 248 | } 249 | }; 250 | fn.apply(this, arguments); 251 | return resolver.promise; 252 | }; 253 | }; 254 | function isObject(obj) { 255 | return obj && typeof obj === 'object'; 256 | } 257 | function isFunction(fn) { 258 | return fn && typeof fn === 'function'; 259 | } 260 | function parse(obj) { 261 | if (obj.length === 1 && Array.isArray(obj[0])) { 262 | return obj[0]; 263 | } else { 264 | var args = new Array(obj.length); 265 | for (var i = 0; i < args.length; ++i) { 266 | args[i] = obj[i]; 267 | } 268 | return args; 269 | } 270 | } 271 | }(this)); 272 | }, 273 | function (module, exports) { 274 | module.exports = _require(0); 275 | }, 276 | function (module, exports) { 277 | module.exports = _require(3); 278 | }, 279 | function (module, exports) { 280 | (function (global) { 281 | 'use strict'; 282 | var next = function (next, buffer, length, tick) { 283 | buffer = new Array(10000); 284 | length = 0; 285 | function enqueue(fn) { 286 | if (length === buffer.length) { 287 | length = buffer.push(fn); 288 | } else { 289 | buffer[length++] = fn; 290 | } 291 | if (!tick) { 292 | return tick = true; 293 | } 294 | } 295 | function execute() { 296 | var i = 0; 297 | while (i < length) { 298 | buffer[i](); 299 | buffer[i++] = undefined; 300 | } 301 | length = 0; 302 | tick = false; 303 | } 304 | if (typeof setImmediate === 'function') { 305 | next = function (fn) { 306 | enqueue(fn) && setImmediate(execute); 307 | }; 308 | } else if (typeof process === 'object' && process.nextTick) { 309 | next = function (fn) { 310 | enqueue(fn) && process.nextTick(execute); 311 | }; 312 | } else if (global.postMessage) { 313 | var message = '__subsequent', onMessage = function (e) { 314 | if (e.data === message) { 315 | e.stopPropagation && e.stopPropagation(); 316 | execute(); 317 | } 318 | }; 319 | if (global.addEventListener) { 320 | global.addEventListener('message', onMessage, true); 321 | } else { 322 | global.attachEvent('onmessage', onMessage); 323 | } 324 | next = function (fn) { 325 | enqueue(fn) && global.postMessage(message, '*'); 326 | }; 327 | } else { 328 | next = function (fn) { 329 | enqueue(fn) && setTimeout(execute, 0); 330 | }; 331 | } 332 | return next; 333 | }(); 334 | if (typeof define === 'function' && define.amd) { 335 | define(function () { 336 | return next; 337 | }); 338 | } else if (typeof module === 'object' && module.exports) { 339 | module.exports = next; 340 | } else { 341 | global.subsequent = next; 342 | } 343 | }(this)); 344 | }, 345 | function (module, exports) { 346 | // License of a 347 | var c = _require(6), url = _require(8), Promise = _require(1); 348 | this.topValue = _require(5) * 2; 349 | this.expectedValue = _require(7).answer; 350 | }, 351 | function (module, exports) { 352 | // License of b 353 | module.exports = _require(6).value * 7; 354 | }, 355 | function (module, exports) { 356 | // License of c 357 | var a = _require(4); 358 | exports.value = 3; 359 | }, 360 | function (module, exports) { 361 | module.exports = { 'answer': 42 }; 362 | }, 363 | function (module, exports) { 364 | module.exports = __external_url; 365 | } 366 | ]; 367 | return _require(4); 368 | })); 369 | //# sourceMappingURL=expected.js.map -------------------------------------------------------------------------------- /test/suites/a (exports A with map and comments)/expected.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../node_modules/davy/davy.js","../node_modules/davy/index.js","../node_modules/davy/node_modules/subsequent/index.js","../node_modules/davy/node_modules/subsequent/subsequent.js","fixtures/a.js","fixtures/b/index.js","fixtures/c.js","fixtures/data.json"],"names":["global","next","define","amd","subsequent","Promise","module","exports","_require","Davy","fn","value","undefined","__deferreds","arguments","length","resolver","Resolver","val","fulfill","err","reject","e","prototype","isFulfilled","isRejected","then","onFulfill","onReject","deferred","defer","resolve","SUCCESS","FAILURE","push","promise","TypeError","isObject","isFunction","isResolved","self","call","complete","error","deferreds","type","i","onRejected","onResolved","tap","onFulfilled","spread","apply","cast","each","list","iterator","len","all","parse","race","wrap","obj","Array","isArray","args","buffer","tick","enqueue","execute","setImmediate","process","nextTick","postMessage","message","onMessage","data","stopPropagation","addEventListener","attachEvent","setTimeout","c","url","topValue","expectedValue","answer","a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAA,CAAC,UAASA,MAAT,EAAiB;AAAA,gBAChB,aADgB;AAAA,gBAEhB,IAAIC,IAAJ,CAFgB;AAAA,gBAGhB,IAAI,OAAOC,MAAP,KAAkB,UAAlB,IAAgCA,MAAA,CAAOC,GAA3C,EAAgD;AAAA,oBAC9CD,MAAA,CAAO,CAAE,YAAF,CAAP,EAAyB,UAASE,UAAT,EAAqB;AAAA,wBAC5CH,IAAA,GAAOG,UAAP,CAD4C;AAAA,wBAE5C,OAAOC,OAAP,CAF4C;AAAA,qBAA9C,EAD8C;AAAA,iBAAhD,MAKO,IAAI,OAAOC,MAAP,KAAkB,QAAlB,IAA8BA,MAAA,CAAOC,OAA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9E,QAAA,CAAQ,CAAR,CAAR,C;YACAD,OAAA,CAAQI,KAAR,GAAgB,CAAhB,C;;;YCHAL,MAAA,CAAOC,OAAP,GAAiB,EAChB,UAAU,EADM,EAAjB,C"} -------------------------------------------------------------------------------- /test/suites/a (exports A with map and comments)/options.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | input: 'fixtures/a.js', 3 | exports: 'A', 4 | map: true, 5 | comments: true, 6 | external: { 7 | url: { 8 | amd: false, 9 | global: false 10 | } 11 | } 12 | }; -------------------------------------------------------------------------------- /test/suites/a (exports A with map)/expected.js: -------------------------------------------------------------------------------- 1 | (function (factory) { 2 | if (typeof define === 'function' && define.amd) { 3 | define([''], factory); 4 | } else if (typeof exports === 'object') { 5 | module.exports = factory(require('url')); 6 | } else { 7 | this['A'] = factory(undefined); 8 | } 9 | }(function (__external_url) { 10 | var global = this, define; 11 | function _require(id) { 12 | var module = _require.cache[id]; 13 | if (!module) { 14 | var exports = {}; 15 | module = _require.cache[id] = { 16 | id: id, 17 | exports: exports 18 | }; 19 | _require.modules[id].call(exports, module, exports); 20 | } 21 | return module.exports; 22 | } 23 | _require.cache = []; 24 | _require.modules = [ 25 | function (module, exports) { 26 | (function (global) { 27 | 'use strict'; 28 | var next; 29 | if (typeof define === 'function' && define.amd) { 30 | define(['subsequent'], function (subsequent) { 31 | next = subsequent; 32 | return Promise; 33 | }); 34 | } else if (typeof module === 'object' && module.exports) { 35 | module.exports = Promise; 36 | next = _require(2); 37 | } else { 38 | global.Davy = Promise; 39 | next = global.subsequent; 40 | } 41 | function Promise(fn) { 42 | this.value = undefined; 43 | this.__deferreds = []; 44 | if (arguments.length > 0) { 45 | var resolver = new Resolver(this); 46 | if (typeof fn == 'function') { 47 | try { 48 | fn(function (val) { 49 | resolver.fulfill(val); 50 | }, function (err) { 51 | resolver.reject(err); 52 | }); 53 | } catch (e) { 54 | resolver.reject(e); 55 | } 56 | } else { 57 | resolver.fulfill(fn); 58 | } 59 | } 60 | } 61 | Promise.prototype.isFulfilled = false; 62 | Promise.prototype.isRejected = false; 63 | Promise.prototype.then = function (onFulfill, onReject) { 64 | var resolver = new Resolver(new Promise()), deferred = defer(resolver, onFulfill, onReject); 65 | if (this.isFulfilled || this.isRejected) { 66 | resolve(deferred, this.isFulfilled ? Promise.SUCCESS : Promise.FAILURE, this.value); 67 | } else { 68 | this.__deferreds.push(deferred); 69 | } 70 | return resolver.promise; 71 | }; 72 | Promise.SUCCESS = 'fulfill'; 73 | Promise.FAILURE = 'reject'; 74 | function defer(resolver, fulfill, reject) { 75 | return { 76 | resolver: resolver, 77 | fulfill: fulfill, 78 | reject: reject 79 | }; 80 | } 81 | function Resolver(promise) { 82 | this.promise = promise; 83 | } 84 | Resolver.prototype.fulfill = function (value) { 85 | var promise = this.promise; 86 | if (promise.isFulfilled || promise.isRejected) 87 | return; 88 | if (value === promise) 89 | throw new TypeError('Can\'t resolve a promise with itself.'); 90 | if (isObject(value) || isFunction(value)) { 91 | var then; 92 | try { 93 | then = value.then; 94 | } catch (e) { 95 | this.reject(e); 96 | return; 97 | } 98 | if (isFunction(then)) { 99 | var isResolved = false, self = this; 100 | try { 101 | then.call(value, function (val) { 102 | if (!isResolved) { 103 | isResolved = true; 104 | self.fulfill(val); 105 | } 106 | }, function (err) { 107 | if (!isResolved) { 108 | isResolved = true; 109 | self.reject(err); 110 | } 111 | }); 112 | } catch (e) { 113 | if (!isResolved) { 114 | this.reject(e); 115 | } 116 | } 117 | return; 118 | } 119 | } 120 | promise.isFulfilled = true; 121 | this.complete(value); 122 | }; 123 | Resolver.prototype.reject = function (error) { 124 | var promise = this.promise; 125 | if (promise.isFulfilled || promise.isRejected) 126 | return; 127 | promise.isRejected = true; 128 | this.complete(error); 129 | }; 130 | Resolver.prototype.complete = function (value) { 131 | var promise = this.promise, deferreds = promise.__deferreds, type = promise.isFulfilled ? Promise.SUCCESS : Promise.FAILURE; 132 | promise.value = value; 133 | for (var i = 0; i < deferreds.length; ++i) { 134 | resolve(deferreds[i], type, value); 135 | } 136 | promise.__deferreds = undefined; 137 | }; 138 | function resolve(deferred, type, value) { 139 | var fn = deferred[type], resolver = deferred.resolver; 140 | if (isFunction(fn)) { 141 | next(function () { 142 | try { 143 | value = fn(value); 144 | resolver.fulfill(value); 145 | } catch (e) { 146 | resolver.reject(e); 147 | } 148 | }); 149 | } else { 150 | resolver[type](value); 151 | } 152 | } 153 | Promise.prototype['catch'] = function (onRejected) { 154 | return this.then(null, onRejected); 155 | }; 156 | Promise.prototype['throw'] = function () { 157 | return this['catch'](function (error) { 158 | next(function () { 159 | throw error; 160 | }); 161 | }); 162 | }; 163 | Promise.prototype['finally'] = function (onResolved) { 164 | return this.then(onResolved, onResolved); 165 | }; 166 | Promise.prototype['yield'] = function (value) { 167 | return this.then(function () { 168 | return value; 169 | }); 170 | }; 171 | Promise.prototype.tap = function (onFulfilled) { 172 | return this.then(onFulfilled)['yield'](this); 173 | }; 174 | Promise.prototype.spread = function (onFulfilled, onRejected) { 175 | return this.then(function (val) { 176 | return onFulfilled.apply(this, val); 177 | }, onRejected); 178 | }; 179 | Promise.resolve = Promise.cast = function (val) { 180 | if (isObject(val) && isFunction(val.then)) { 181 | return val; 182 | } 183 | return new Promise(val); 184 | }; 185 | Promise.reject = function (err) { 186 | var resolver = Promise.defer(); 187 | resolver.reject(err); 188 | return resolver.promise; 189 | }; 190 | Promise.defer = function () { 191 | return new Resolver(new Promise()); 192 | }; 193 | Promise.each = function (list, iterator) { 194 | var resolver = Promise.defer(), len = list.length; 195 | if (len === 0) 196 | resolver.reject(TypeError()); 197 | for (var i = 0; i < len; ++i) { 198 | iterator(list[i], i); 199 | } 200 | return resolver; 201 | }; 202 | Promise.all = function () { 203 | var list = parse(arguments), length = list.length, resolver = Promise.each(list, resolve); 204 | return resolver.promise; 205 | function reject(err) { 206 | resolver.reject(err); 207 | } 208 | function resolve(value, i) { 209 | if (isObject(value) && isFunction(value.then)) { 210 | value.then(function (val) { 211 | resolve(val, i); 212 | }, reject); 213 | return; 214 | } 215 | list[i] = value; 216 | if (--length === 0) { 217 | resolver.fulfill(list); 218 | } 219 | } 220 | }; 221 | Promise.race = function () { 222 | var list = parse(arguments), resolver = Promise.each(list, resolve); 223 | return resolver.promise; 224 | function reject(err) { 225 | resolver.reject(err); 226 | } 227 | function resolve(value) { 228 | if (isObject(value) && isFunction(value.then)) { 229 | value.then(resolve, reject); 230 | return; 231 | } 232 | resolver.fulfill(value); 233 | } 234 | }; 235 | Promise.wrap = function (fn) { 236 | return function () { 237 | var resolver = new Resolver(new Promise()); 238 | arguments[arguments.length++] = function (err, val) { 239 | if (err) { 240 | resolver.reject(err); 241 | } else { 242 | resolver.fulfill(val); 243 | } 244 | }; 245 | fn.apply(this, arguments); 246 | return resolver.promise; 247 | }; 248 | }; 249 | function isObject(obj) { 250 | return obj && typeof obj === 'object'; 251 | } 252 | function isFunction(fn) { 253 | return fn && typeof fn === 'function'; 254 | } 255 | function parse(obj) { 256 | if (obj.length === 1 && Array.isArray(obj[0])) { 257 | return obj[0]; 258 | } else { 259 | var args = new Array(obj.length); 260 | for (var i = 0; i < args.length; ++i) { 261 | args[i] = obj[i]; 262 | } 263 | return args; 264 | } 265 | } 266 | }(this)); 267 | }, 268 | function (module, exports) { 269 | module.exports = _require(0); 270 | }, 271 | function (module, exports) { 272 | module.exports = _require(3); 273 | }, 274 | function (module, exports) { 275 | (function (global) { 276 | 'use strict'; 277 | var next = function (next, buffer, length, tick) { 278 | buffer = new Array(10000); 279 | length = 0; 280 | function enqueue(fn) { 281 | if (length === buffer.length) { 282 | length = buffer.push(fn); 283 | } else { 284 | buffer[length++] = fn; 285 | } 286 | if (!tick) { 287 | return tick = true; 288 | } 289 | } 290 | function execute() { 291 | var i = 0; 292 | while (i < length) { 293 | buffer[i](); 294 | buffer[i++] = undefined; 295 | } 296 | length = 0; 297 | tick = false; 298 | } 299 | if (typeof setImmediate === 'function') { 300 | next = function (fn) { 301 | enqueue(fn) && setImmediate(execute); 302 | }; 303 | } else if (typeof process === 'object' && process.nextTick) { 304 | next = function (fn) { 305 | enqueue(fn) && process.nextTick(execute); 306 | }; 307 | } else if (global.postMessage) { 308 | var message = '__subsequent', onMessage = function (e) { 309 | if (e.data === message) { 310 | e.stopPropagation && e.stopPropagation(); 311 | execute(); 312 | } 313 | }; 314 | if (global.addEventListener) { 315 | global.addEventListener('message', onMessage, true); 316 | } else { 317 | global.attachEvent('onmessage', onMessage); 318 | } 319 | next = function (fn) { 320 | enqueue(fn) && global.postMessage(message, '*'); 321 | }; 322 | } else { 323 | next = function (fn) { 324 | enqueue(fn) && setTimeout(execute, 0); 325 | }; 326 | } 327 | return next; 328 | }(); 329 | if (typeof define === 'function' && define.amd) { 330 | define(function () { 331 | return next; 332 | }); 333 | } else if (typeof module === 'object' && module.exports) { 334 | module.exports = next; 335 | } else { 336 | global.subsequent = next; 337 | } 338 | }(this)); 339 | }, 340 | function (module, exports) { 341 | var c = _require(6), url = _require(8), Promise = _require(1); 342 | this.topValue = _require(5) * 2; 343 | this.expectedValue = _require(7).answer; 344 | }, 345 | function (module, exports) { 346 | module.exports = _require(6).value * 7; 347 | }, 348 | function (module, exports) { 349 | var a = _require(4); 350 | exports.value = 3; 351 | }, 352 | function (module, exports) { 353 | module.exports = { 'answer': 42 }; 354 | }, 355 | function (module, exports) { 356 | module.exports = __external_url; 357 | } 358 | ]; 359 | return _require(4); 360 | })); 361 | //# sourceMappingURL=expected.js.map -------------------------------------------------------------------------------- /test/suites/a (exports A with map)/expected.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../node_modules/davy/davy.js","../node_modules/davy/index.js","../node_modules/davy/node_modules/subsequent/index.js","../node_modules/davy/node_modules/subsequent/subsequent.js","fixtures/a.js","fixtures/b/index.js","fixtures/c.js","fixtures/data.json"],"names":["global","next","define","amd","subsequent","Promise","module","exports","_require","Davy","fn","value","undefined","__deferreds","arguments","length","resolver","Resolver","val","fulfill","err","reject","e","prototype","isFulfilled","isRejected","then","onFulfill","onReject","deferred","defer","resolve","SUCCESS","FAILURE","push","promise","TypeError","isObject","isFunction","isResolved","self","call","complete","error","deferreds","type","i","onRejected","onResolved","tap","onFulfilled","spread","apply","cast","each","list","iterator","len","all","parse","race","wrap","obj","Array","isArray","args","buffer","tick","enqueue","execute","setImmediate","process","nextTick","postMessage","message","onMessage","data","stopPropagation","addEventListener","attachEvent","setTimeout","c","url","topValue","expectedValue","answer","a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;YAAA,CAAC,UAASA,MAAT,EAAiB;AAAA,gBAChB,aADgB;AAAA,gBAEhB,IAAIC,IAAJ,CAFgB;AAAA,gBAGhB,IAAI,OAAOC,MAAP,KAAkB,UAAlB,IAAgCA,MAAA,CAAOC,GAA3C,EAAgD;AAAA,oBAC9CD,MAAA,CAAO,CAAE,YAAF,CAAP,EAAyB,UAASE,UAAT,EAAqB;AAAA,wBAC5CH,IAAA,GAAOG,UAAP,CAD4C;AAAA,wBAE5C,OAAOC,OAAP,CAF4C;AAAA,qBAA9C,EAD8C;AAAA,iBAAhD,MAKO,IAAI,OAAOC,MAAP,KAAkB,QAAlB,IAA8BA,MAAA,CAAOC,OAAzC,EAAkD;AAAA,oBACvDD,MAAA,CAAOC,OAAP,GAAiBF,OAAjB,CADuD;AAAA,oBAEvDJ,IAAA,GAAOO,QAAA,CAAQ,CAAR,CAAP,CAFuD;AAAA,iBAAlD,MAGA;AAAA,oBACLR,MAAA,CAAOS,IAAP,GAAcJ,OAAd,CADK;AAAA,oBAELJ,IAAA,GAAOD,MAAA,CAAOI,UAAd,CAFK;AAAA,iBAXS;AAAA,gBAehB,SAASC,OAAT,CAAiBK,EAAjB,EAAqB;AAAA,oBACnB,KAAKC,KAAL,GAAaC,SAAb,CADmB;AAAA,oBAEnB,KAAKC,WAAL,GAAmB,EAAnB,CAFmB;AAAA,oBAGnB,IAAIC,SAAA,CAAUC,MAAV,GAAmB,CAAvB,EAA0B;AAAA,wBACxB,IAAIC,QAAA,GAAW,IAAIC,QAAJ,CA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AAA,qBAAlB,EAD8C;AAAA,iBAAhD,MAIO,IAAI,OAAOK,MAAP,KAAkB,QAAlB,IAA8BA,MAAA,CAAOC,OAAzC,EAAkD;AAAA,oBACvDD,MAAA,CAAOC,OAAP,GAAiBN,IAAjB,CADuD;AAAA,iBAAlD,MAEA;AAAA,oBACLD,MAAA,CAAOI,UAAP,GAAoBH,IAApB,CADK;AAAA,iBA5DS;AAAA,aAAlB,CA+DG,IA/DH,G;;;YCEA,IAAIgF,CAAA,GAAIzE,QAAA,CAAQ,CAAR,CAAR,EACC0E,GAAA,GAAM1E,QAAA,CAAQ,CAAR,CADP,EAECH,OAAA,GAAUG,QAAA,CAAQ,CAAR,CAFX,C;YAIA,KAAK2E,QAAL,GAAgB3E,QAAA,CAAQ,CAAR,IAAiB,CAAjC,C;YACA,KAAK4E,aAAL,GAAqB5E,QAAA,CAAQ,CAAR,EAAuB6E,MAA5C,C;;;YCLA/E,MAAA,CAAOC,OAAP,GAAiBC,QAAA,CAAQ,CAAR,EAAgBG,KAAhB,GAAwB,CAAzC,C;;;YCAA,IAAI2E,CAAA,GAAI9E,QAAA,CAAQ,CAAR,CAAR,C;YACAD,OAAA,CAAQI,KAAR,GAAgB,CAAhB,C;;;YCHAL,MAAA,CAAOC,OAAP,GAAiB,EAChB,UAAU,EADM,EAAjB,C"} -------------------------------------------------------------------------------- /test/suites/a (exports A with map)/options.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | input: 'fixtures/a.js', 3 | exports: 'A', 4 | map: true, 5 | external: { 6 | url: { 7 | amd: false, 8 | global: false 9 | } 10 | } 11 | }; -------------------------------------------------------------------------------- /test/suites/a (exports A)/expected.js: -------------------------------------------------------------------------------- 1 | (function (factory) { 2 | if (typeof define === 'function' && define.amd) { 3 | define([''], factory); 4 | } else if (typeof exports === 'object') { 5 | module.exports = factory(require('url')); 6 | } else { 7 | this['A'] = factory(undefined); 8 | } 9 | }(function (__external_url) { 10 | var global = this, define; 11 | function _require(id) { 12 | var module = _require.cache[id]; 13 | if (!module) { 14 | var exports = {}; 15 | module = _require.cache[id] = { 16 | id: id, 17 | exports: exports 18 | }; 19 | _require.modules[id].call(exports, module, exports); 20 | } 21 | return module.exports; 22 | } 23 | _require.cache = []; 24 | _require.modules = [ 25 | function (module, exports) { 26 | (function (global) { 27 | 'use strict'; 28 | var next; 29 | if (typeof define === 'function' && define.amd) { 30 | define(['subsequent'], function (subsequent) { 31 | next = subsequent; 32 | return Promise; 33 | }); 34 | } else if (typeof module === 'object' && module.exports) { 35 | module.exports = Promise; 36 | next = _require(2); 37 | } else { 38 | global.Davy = Promise; 39 | next = global.subsequent; 40 | } 41 | function Promise(fn) { 42 | this.value = undefined; 43 | this.__deferreds = []; 44 | if (arguments.length > 0) { 45 | var resolver = new Resolver(this); 46 | if (typeof fn == 'function') { 47 | try { 48 | fn(function (val) { 49 | resolver.fulfill(val); 50 | }, function (err) { 51 | resolver.reject(err); 52 | }); 53 | } catch (e) { 54 | resolver.reject(e); 55 | } 56 | } else { 57 | resolver.fulfill(fn); 58 | } 59 | } 60 | } 61 | Promise.prototype.isFulfilled = false; 62 | Promise.prototype.isRejected = false; 63 | Promise.prototype.then = function (onFulfill, onReject) { 64 | var resolver = new Resolver(new Promise()), deferred = defer(resolver, onFulfill, onReject); 65 | if (this.isFulfilled || this.isRejected) { 66 | resolve(deferred, this.isFulfilled ? Promise.SUCCESS : Promise.FAILURE, this.value); 67 | } else { 68 | this.__deferreds.push(deferred); 69 | } 70 | return resolver.promise; 71 | }; 72 | Promise.SUCCESS = 'fulfill'; 73 | Promise.FAILURE = 'reject'; 74 | function defer(resolver, fulfill, reject) { 75 | return { 76 | resolver: resolver, 77 | fulfill: fulfill, 78 | reject: reject 79 | }; 80 | } 81 | function Resolver(promise) { 82 | this.promise = promise; 83 | } 84 | Resolver.prototype.fulfill = function (value) { 85 | var promise = this.promise; 86 | if (promise.isFulfilled || promise.isRejected) 87 | return; 88 | if (value === promise) 89 | throw new TypeError('Can\'t resolve a promise with itself.'); 90 | if (isObject(value) || isFunction(value)) { 91 | var then; 92 | try { 93 | then = value.then; 94 | } catch (e) { 95 | this.reject(e); 96 | return; 97 | } 98 | if (isFunction(then)) { 99 | var isResolved = false, self = this; 100 | try { 101 | then.call(value, function (val) { 102 | if (!isResolved) { 103 | isResolved = true; 104 | self.fulfill(val); 105 | } 106 | }, function (err) { 107 | if (!isResolved) { 108 | isResolved = true; 109 | self.reject(err); 110 | } 111 | }); 112 | } catch (e) { 113 | if (!isResolved) { 114 | this.reject(e); 115 | } 116 | } 117 | return; 118 | } 119 | } 120 | promise.isFulfilled = true; 121 | this.complete(value); 122 | }; 123 | Resolver.prototype.reject = function (error) { 124 | var promise = this.promise; 125 | if (promise.isFulfilled || promise.isRejected) 126 | return; 127 | promise.isRejected = true; 128 | this.complete(error); 129 | }; 130 | Resolver.prototype.complete = function (value) { 131 | var promise = this.promise, deferreds = promise.__deferreds, type = promise.isFulfilled ? Promise.SUCCESS : Promise.FAILURE; 132 | promise.value = value; 133 | for (var i = 0; i < deferreds.length; ++i) { 134 | resolve(deferreds[i], type, value); 135 | } 136 | promise.__deferreds = undefined; 137 | }; 138 | function resolve(deferred, type, value) { 139 | var fn = deferred[type], resolver = deferred.resolver; 140 | if (isFunction(fn)) { 141 | next(function () { 142 | try { 143 | value = fn(value); 144 | resolver.fulfill(value); 145 | } catch (e) { 146 | resolver.reject(e); 147 | } 148 | }); 149 | } else { 150 | resolver[type](value); 151 | } 152 | } 153 | Promise.prototype['catch'] = function (onRejected) { 154 | return this.then(null, onRejected); 155 | }; 156 | Promise.prototype['throw'] = function () { 157 | return this['catch'](function (error) { 158 | next(function () { 159 | throw error; 160 | }); 161 | }); 162 | }; 163 | Promise.prototype['finally'] = function (onResolved) { 164 | return this.then(onResolved, onResolved); 165 | }; 166 | Promise.prototype['yield'] = function (value) { 167 | return this.then(function () { 168 | return value; 169 | }); 170 | }; 171 | Promise.prototype.tap = function (onFulfilled) { 172 | return this.then(onFulfilled)['yield'](this); 173 | }; 174 | Promise.prototype.spread = function (onFulfilled, onRejected) { 175 | return this.then(function (val) { 176 | return onFulfilled.apply(this, val); 177 | }, onRejected); 178 | }; 179 | Promise.resolve = Promise.cast = function (val) { 180 | if (isObject(val) && isFunction(val.then)) { 181 | return val; 182 | } 183 | return new Promise(val); 184 | }; 185 | Promise.reject = function (err) { 186 | var resolver = Promise.defer(); 187 | resolver.reject(err); 188 | return resolver.promise; 189 | }; 190 | Promise.defer = function () { 191 | return new Resolver(new Promise()); 192 | }; 193 | Promise.each = function (list, iterator) { 194 | var resolver = Promise.defer(), len = list.length; 195 | if (len === 0) 196 | resolver.reject(TypeError()); 197 | for (var i = 0; i < len; ++i) { 198 | iterator(list[i], i); 199 | } 200 | return resolver; 201 | }; 202 | Promise.all = function () { 203 | var list = parse(arguments), length = list.length, resolver = Promise.each(list, resolve); 204 | return resolver.promise; 205 | function reject(err) { 206 | resolver.reject(err); 207 | } 208 | function resolve(value, i) { 209 | if (isObject(value) && isFunction(value.then)) { 210 | value.then(function (val) { 211 | resolve(val, i); 212 | }, reject); 213 | return; 214 | } 215 | list[i] = value; 216 | if (--length === 0) { 217 | resolver.fulfill(list); 218 | } 219 | } 220 | }; 221 | Promise.race = function () { 222 | var list = parse(arguments), resolver = Promise.each(list, resolve); 223 | return resolver.promise; 224 | function reject(err) { 225 | resolver.reject(err); 226 | } 227 | function resolve(value) { 228 | if (isObject(value) && isFunction(value.then)) { 229 | value.then(resolve, reject); 230 | return; 231 | } 232 | resolver.fulfill(value); 233 | } 234 | }; 235 | Promise.wrap = function (fn) { 236 | return function () { 237 | var resolver = new Resolver(new Promise()); 238 | arguments[arguments.length++] = function (err, val) { 239 | if (err) { 240 | resolver.reject(err); 241 | } else { 242 | resolver.fulfill(val); 243 | } 244 | }; 245 | fn.apply(this, arguments); 246 | return resolver.promise; 247 | }; 248 | }; 249 | function isObject(obj) { 250 | return obj && typeof obj === 'object'; 251 | } 252 | function isFunction(fn) { 253 | return fn && typeof fn === 'function'; 254 | } 255 | function parse(obj) { 256 | if (obj.length === 1 && Array.isArray(obj[0])) { 257 | return obj[0]; 258 | } else { 259 | var args = new Array(obj.length); 260 | for (var i = 0; i < args.length; ++i) { 261 | args[i] = obj[i]; 262 | } 263 | return args; 264 | } 265 | } 266 | }(this)); 267 | }, 268 | function (module, exports) { 269 | module.exports = _require(0); 270 | }, 271 | function (module, exports) { 272 | module.exports = _require(3); 273 | }, 274 | function (module, exports) { 275 | (function (global) { 276 | 'use strict'; 277 | var next = function (next, buffer, length, tick) { 278 | buffer = new Array(10000); 279 | length = 0; 280 | function enqueue(fn) { 281 | if (length === buffer.length) { 282 | length = buffer.push(fn); 283 | } else { 284 | buffer[length++] = fn; 285 | } 286 | if (!tick) { 287 | return tick = true; 288 | } 289 | } 290 | function execute() { 291 | var i = 0; 292 | while (i < length) { 293 | buffer[i](); 294 | buffer[i++] = undefined; 295 | } 296 | length = 0; 297 | tick = false; 298 | } 299 | if (typeof setImmediate === 'function') { 300 | next = function (fn) { 301 | enqueue(fn) && setImmediate(execute); 302 | }; 303 | } else if (typeof process === 'object' && process.nextTick) { 304 | next = function (fn) { 305 | enqueue(fn) && process.nextTick(execute); 306 | }; 307 | } else if (global.postMessage) { 308 | var message = '__subsequent', onMessage = function (e) { 309 | if (e.data === message) { 310 | e.stopPropagation && e.stopPropagation(); 311 | execute(); 312 | } 313 | }; 314 | if (global.addEventListener) { 315 | global.addEventListener('message', onMessage, true); 316 | } else { 317 | global.attachEvent('onmessage', onMessage); 318 | } 319 | next = function (fn) { 320 | enqueue(fn) && global.postMessage(message, '*'); 321 | }; 322 | } else { 323 | next = function (fn) { 324 | enqueue(fn) && setTimeout(execute, 0); 325 | }; 326 | } 327 | return next; 328 | }(); 329 | if (typeof define === 'function' && define.amd) { 330 | define(function () { 331 | return next; 332 | }); 333 | } else if (typeof module === 'object' && module.exports) { 334 | module.exports = next; 335 | } else { 336 | global.subsequent = next; 337 | } 338 | }(this)); 339 | }, 340 | function (module, exports) { 341 | var c = _require(6), url = _require(8), Promise = _require(1); 342 | this.topValue = _require(5) * 2; 343 | this.expectedValue = _require(7).answer; 344 | }, 345 | function (module, exports) { 346 | module.exports = _require(6).value * 7; 347 | }, 348 | function (module, exports) { 349 | var a = _require(4); 350 | exports.value = 3; 351 | }, 352 | function (module, exports) { 353 | module.exports = { 'answer': 42 }; 354 | }, 355 | function (module, exports) { 356 | module.exports = __external_url; 357 | } 358 | ]; 359 | return _require(4); 360 | })); -------------------------------------------------------------------------------- /test/suites/a (exports A)/options.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | input: 'fixtures/a.js', 3 | exports: 'A', 4 | external: { 5 | url: { 6 | amd: false, 7 | global: false 8 | } 9 | } 10 | }; -------------------------------------------------------------------------------- /test/suites/c (no exports)/expected.js: -------------------------------------------------------------------------------- 1 | (function (__external_url) { 2 | var global = this, define; 3 | function _require(id) { 4 | var module = _require.cache[id]; 5 | if (!module) { 6 | var exports = {}; 7 | module = _require.cache[id] = { 8 | id: id, 9 | exports: exports 10 | }; 11 | _require.modules[id].call(exports, module, exports); 12 | } 13 | return module.exports; 14 | } 15 | _require.cache = []; 16 | _require.modules = [ 17 | function (module, exports) { 18 | (function (global) { 19 | 'use strict'; 20 | var next; 21 | if (typeof define === 'function' && define.amd) { 22 | define(['subsequent'], function (subsequent) { 23 | next = subsequent; 24 | return Promise; 25 | }); 26 | } else if (typeof module === 'object' && module.exports) { 27 | module.exports = Promise; 28 | next = _require(2); 29 | } else { 30 | global.Davy = Promise; 31 | next = global.subsequent; 32 | } 33 | function Promise(fn) { 34 | this.value = undefined; 35 | this.__deferreds = []; 36 | if (arguments.length > 0) { 37 | var resolver = new Resolver(this); 38 | if (typeof fn == 'function') { 39 | try { 40 | fn(function (val) { 41 | resolver.fulfill(val); 42 | }, function (err) { 43 | resolver.reject(err); 44 | }); 45 | } catch (e) { 46 | resolver.reject(e); 47 | } 48 | } else { 49 | resolver.fulfill(fn); 50 | } 51 | } 52 | } 53 | Promise.prototype.isFulfilled = false; 54 | Promise.prototype.isRejected = false; 55 | Promise.prototype.then = function (onFulfill, onReject) { 56 | var resolver = new Resolver(new Promise()), deferred = defer(resolver, onFulfill, onReject); 57 | if (this.isFulfilled || this.isRejected) { 58 | resolve(deferred, this.isFulfilled ? Promise.SUCCESS : Promise.FAILURE, this.value); 59 | } else { 60 | this.__deferreds.push(deferred); 61 | } 62 | return resolver.promise; 63 | }; 64 | Promise.SUCCESS = 'fulfill'; 65 | Promise.FAILURE = 'reject'; 66 | function defer(resolver, fulfill, reject) { 67 | return { 68 | resolver: resolver, 69 | fulfill: fulfill, 70 | reject: reject 71 | }; 72 | } 73 | function Resolver(promise) { 74 | this.promise = promise; 75 | } 76 | Resolver.prototype.fulfill = function (value) { 77 | var promise = this.promise; 78 | if (promise.isFulfilled || promise.isRejected) 79 | return; 80 | if (value === promise) 81 | throw new TypeError('Can\'t resolve a promise with itself.'); 82 | if (isObject(value) || isFunction(value)) { 83 | var then; 84 | try { 85 | then = value.then; 86 | } catch (e) { 87 | this.reject(e); 88 | return; 89 | } 90 | if (isFunction(then)) { 91 | var isResolved = false, self = this; 92 | try { 93 | then.call(value, function (val) { 94 | if (!isResolved) { 95 | isResolved = true; 96 | self.fulfill(val); 97 | } 98 | }, function (err) { 99 | if (!isResolved) { 100 | isResolved = true; 101 | self.reject(err); 102 | } 103 | }); 104 | } catch (e) { 105 | if (!isResolved) { 106 | this.reject(e); 107 | } 108 | } 109 | return; 110 | } 111 | } 112 | promise.isFulfilled = true; 113 | this.complete(value); 114 | }; 115 | Resolver.prototype.reject = function (error) { 116 | var promise = this.promise; 117 | if (promise.isFulfilled || promise.isRejected) 118 | return; 119 | promise.isRejected = true; 120 | this.complete(error); 121 | }; 122 | Resolver.prototype.complete = function (value) { 123 | var promise = this.promise, deferreds = promise.__deferreds, type = promise.isFulfilled ? Promise.SUCCESS : Promise.FAILURE; 124 | promise.value = value; 125 | for (var i = 0; i < deferreds.length; ++i) { 126 | resolve(deferreds[i], type, value); 127 | } 128 | promise.__deferreds = undefined; 129 | }; 130 | function resolve(deferred, type, value) { 131 | var fn = deferred[type], resolver = deferred.resolver; 132 | if (isFunction(fn)) { 133 | next(function () { 134 | try { 135 | value = fn(value); 136 | resolver.fulfill(value); 137 | } catch (e) { 138 | resolver.reject(e); 139 | } 140 | }); 141 | } else { 142 | resolver[type](value); 143 | } 144 | } 145 | Promise.prototype['catch'] = function (onRejected) { 146 | return this.then(null, onRejected); 147 | }; 148 | Promise.prototype['throw'] = function () { 149 | return this['catch'](function (error) { 150 | next(function () { 151 | throw error; 152 | }); 153 | }); 154 | }; 155 | Promise.prototype['finally'] = function (onResolved) { 156 | return this.then(onResolved, onResolved); 157 | }; 158 | Promise.prototype['yield'] = function (value) { 159 | return this.then(function () { 160 | return value; 161 | }); 162 | }; 163 | Promise.prototype.tap = function (onFulfilled) { 164 | return this.then(onFulfilled)['yield'](this); 165 | }; 166 | Promise.prototype.spread = function (onFulfilled, onRejected) { 167 | return this.then(function (val) { 168 | return onFulfilled.apply(this, val); 169 | }, onRejected); 170 | }; 171 | Promise.resolve = Promise.cast = function (val) { 172 | if (isObject(val) && isFunction(val.then)) { 173 | return val; 174 | } 175 | return new Promise(val); 176 | }; 177 | Promise.reject = function (err) { 178 | var resolver = Promise.defer(); 179 | resolver.reject(err); 180 | return resolver.promise; 181 | }; 182 | Promise.defer = function () { 183 | return new Resolver(new Promise()); 184 | }; 185 | Promise.each = function (list, iterator) { 186 | var resolver = Promise.defer(), len = list.length; 187 | if (len === 0) 188 | resolver.reject(TypeError()); 189 | for (var i = 0; i < len; ++i) { 190 | iterator(list[i], i); 191 | } 192 | return resolver; 193 | }; 194 | Promise.all = function () { 195 | var list = parse(arguments), length = list.length, resolver = Promise.each(list, resolve); 196 | return resolver.promise; 197 | function reject(err) { 198 | resolver.reject(err); 199 | } 200 | function resolve(value, i) { 201 | if (isObject(value) && isFunction(value.then)) { 202 | value.then(function (val) { 203 | resolve(val, i); 204 | }, reject); 205 | return; 206 | } 207 | list[i] = value; 208 | if (--length === 0) { 209 | resolver.fulfill(list); 210 | } 211 | } 212 | }; 213 | Promise.race = function () { 214 | var list = parse(arguments), resolver = Promise.each(list, resolve); 215 | return resolver.promise; 216 | function reject(err) { 217 | resolver.reject(err); 218 | } 219 | function resolve(value) { 220 | if (isObject(value) && isFunction(value.then)) { 221 | value.then(resolve, reject); 222 | return; 223 | } 224 | resolver.fulfill(value); 225 | } 226 | }; 227 | Promise.wrap = function (fn) { 228 | return function () { 229 | var resolver = new Resolver(new Promise()); 230 | arguments[arguments.length++] = function (err, val) { 231 | if (err) { 232 | resolver.reject(err); 233 | } else { 234 | resolver.fulfill(val); 235 | } 236 | }; 237 | fn.apply(this, arguments); 238 | return resolver.promise; 239 | }; 240 | }; 241 | function isObject(obj) { 242 | return obj && typeof obj === 'object'; 243 | } 244 | function isFunction(fn) { 245 | return fn && typeof fn === 'function'; 246 | } 247 | function parse(obj) { 248 | if (obj.length === 1 && Array.isArray(obj[0])) { 249 | return obj[0]; 250 | } else { 251 | var args = new Array(obj.length); 252 | for (var i = 0; i < args.length; ++i) { 253 | args[i] = obj[i]; 254 | } 255 | return args; 256 | } 257 | } 258 | }(this)); 259 | }, 260 | function (module, exports) { 261 | module.exports = _require(0); 262 | }, 263 | function (module, exports) { 264 | module.exports = _require(3); 265 | }, 266 | function (module, exports) { 267 | (function (global) { 268 | 'use strict'; 269 | var next = function (next, buffer, length, tick) { 270 | buffer = new Array(10000); 271 | length = 0; 272 | function enqueue(fn) { 273 | if (length === buffer.length) { 274 | length = buffer.push(fn); 275 | } else { 276 | buffer[length++] = fn; 277 | } 278 | if (!tick) { 279 | return tick = true; 280 | } 281 | } 282 | function execute() { 283 | var i = 0; 284 | while (i < length) { 285 | buffer[i](); 286 | buffer[i++] = undefined; 287 | } 288 | length = 0; 289 | tick = false; 290 | } 291 | if (typeof setImmediate === 'function') { 292 | next = function (fn) { 293 | enqueue(fn) && setImmediate(execute); 294 | }; 295 | } else if (typeof process === 'object' && process.nextTick) { 296 | next = function (fn) { 297 | enqueue(fn) && process.nextTick(execute); 298 | }; 299 | } else if (global.postMessage) { 300 | var message = '__subsequent', onMessage = function (e) { 301 | if (e.data === message) { 302 | e.stopPropagation && e.stopPropagation(); 303 | execute(); 304 | } 305 | }; 306 | if (global.addEventListener) { 307 | global.addEventListener('message', onMessage, true); 308 | } else { 309 | global.attachEvent('onmessage', onMessage); 310 | } 311 | next = function (fn) { 312 | enqueue(fn) && global.postMessage(message, '*'); 313 | }; 314 | } else { 315 | next = function (fn) { 316 | enqueue(fn) && setTimeout(execute, 0); 317 | }; 318 | } 319 | return next; 320 | }(); 321 | if (typeof define === 'function' && define.amd) { 322 | define(function () { 323 | return next; 324 | }); 325 | } else if (typeof module === 'object' && module.exports) { 326 | module.exports = next; 327 | } else { 328 | global.subsequent = next; 329 | } 330 | }(this)); 331 | }, 332 | function (module, exports) { 333 | var c = _require(6), url = _require(8), Promise = _require(1); 334 | this.topValue = _require(5) * 2; 335 | this.expectedValue = _require(7).answer; 336 | }, 337 | function (module, exports) { 338 | module.exports = _require(6).value * 7; 339 | }, 340 | function (module, exports) { 341 | var a = _require(4); 342 | exports.value = 3; 343 | }, 344 | function (module, exports) { 345 | module.exports = { 'answer': 42 }; 346 | }, 347 | function (module, exports) { 348 | module.exports = __external_url; 349 | } 350 | ]; 351 | return _require(6); 352 | }()); -------------------------------------------------------------------------------- /test/suites/c (no exports)/options.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | input: 'fixtures/c.js', 3 | external: { 4 | url: { 5 | amd: false, 6 | global: false 7 | } 8 | } 9 | }; -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'), 2 | assert = require('chai').assert, 3 | cjs = require('..'), 4 | Promise = require('../lib/promise'), 5 | whenReadFile = Promise.wrap(fs.readFile), 6 | suitesPath = 'suites/', 7 | SourceMapConsumer = require('source-map').SourceMapConsumer; 8 | 9 | function assertEqualContents(content1, content2) { 10 | assert.equal(String(content1), String(content2)); 11 | } 12 | 13 | process.chdir(__dirname); 14 | 15 | fs.readdirSync(__dirname + '/' + suitesPath).forEach(function (suiteName) { 16 | it(suiteName, function () { 17 | var suitePath = suitesPath + suiteName + '/'; 18 | 19 | var options = require('./' + suitePath + 'options'); 20 | options.output = suitePath + 'expected.js'; 21 | options.dryRun = true; 22 | 23 | return cjs.transform(options).then(function (output) { 24 | var promises = [ 25 | whenReadFile(output.options.output, 'utf-8').then(function (contents) { 26 | assertEqualContents( 27 | output.code, 28 | contents.replace(/\s*\/\/#\s+sourceMappingURL=.*$/, '') 29 | ); 30 | }) 31 | ]; 32 | 33 | if (output.options.map) { 34 | promises.push( 35 | whenReadFile(output.options.map, 'utf-8').then(function (contents) { 36 | var expectedMap = new SourceMapConsumer(contents); 37 | var actualMap = new SourceMapConsumer(contents); 38 | expectedMap.eachMapping(function (mapping) { 39 | var actualPos = actualMap.originalPositionFor({ 40 | line: mapping.generatedLine, 41 | column: mapping.generatedColumn 42 | }); 43 | var expectedPos = { 44 | source: mapping.source, 45 | line: mapping.originalLine, 46 | column: mapping.originalColumn, 47 | name: mapping.name 48 | }; 49 | for (var prop in expectedPos) { 50 | if (expectedPos[prop] === undefined) { 51 | expectedPos[prop] = null; 52 | } 53 | } 54 | assert.deepEqual(actualPos, expectedPos); 55 | }); 56 | }) 57 | ); 58 | } else { 59 | assert.notOk(output.map); 60 | } 61 | 62 | return Promise.all(promises); 63 | }); 64 | }); 65 | }); --------------------------------------------------------------------------------