├── test ├── spec │ ├── case-sensitive │ │ ├── a.js │ │ ├── package.json │ │ └── program.js │ ├── directory-index │ │ ├── bar.js │ │ ├── package.json │ │ ├── foo │ │ │ └── index.js │ │ └── program.js │ ├── comments │ │ ├── package.json │ │ └── program.js │ ├── cyclic │ │ ├── package.json │ │ ├── a.js │ │ ├── b.js │ │ └── program.js │ ├── identify │ │ ├── node_modules │ │ │ ├── x │ │ │ │ ├── x.js │ │ │ │ └── package.json │ │ │ └── cyclic │ │ │ │ ├── module.js │ │ │ │ └── package.json │ │ ├── package.json │ │ └── program.js │ ├── inject │ │ ├── package.json │ │ └── program.js │ ├── method │ │ ├── package.json │ │ ├── a.js │ │ └── program.js │ ├── missing │ │ ├── package.json │ │ └── program.js │ ├── module-html │ │ ├── package.json │ │ ├── program.js │ │ └── simple-template.html │ ├── module-reel │ │ ├── package.json │ │ ├── test.reel │ │ │ └── test.js │ │ └── program.js │ ├── monkeys │ │ ├── package.json │ │ ├── a.js │ │ └── program.js │ ├── nested │ │ ├── package.json │ │ ├── a │ │ │ └── b │ │ │ │ └── c │ │ │ │ └── d.js │ │ └── program.js │ ├── relative │ │ ├── package.json │ │ ├── submodule │ │ │ ├── a.js │ │ │ └── b.js │ │ └── program.js │ ├── return │ │ ├── package.json │ │ ├── returns.js │ │ └── program.js │ ├── determinism │ │ ├── package.json │ │ ├── submodule │ │ │ ├── b.js │ │ │ └── a.js │ │ └── program.js │ ├── exactExports │ │ ├── package.json │ │ ├── a.js │ │ └── program.js │ ├── load-package │ │ ├── package.json │ │ ├── a │ │ │ ├── package.json │ │ │ └── a.js │ │ └── program.js │ ├── module-error │ │ ├── package.json │ │ ├── error.js │ │ └── program.js │ ├── moduleTypes │ │ ├── a │ │ │ ├── five.plus-one │ │ │ ├── package.json │ │ │ ├── b.js │ │ │ └── c.json │ │ ├── package.json │ │ └── program.js │ ├── not-found │ │ ├── package.json │ │ └── program.js │ ├── top-level │ │ ├── package.json │ │ ├── b.js │ │ ├── submodule │ │ │ └── a.js │ │ └── program.js │ ├── transitive │ │ ├── package.json │ │ ├── a.js │ │ ├── b.js │ │ ├── c.js │ │ └── program.js │ ├── extension-loader │ │ ├── package.json │ │ ├── a.extension │ │ │ └── a.js │ │ └── program.js │ ├── hasOwnProperty │ ├── inject-dependency │ │ ├── package.json │ │ ├── node_modules │ │ │ └── dependency │ │ │ │ ├── package.json │ │ │ │ └── module.js │ │ └── program.js │ ├── inject-mapping │ │ ├── package.json │ │ ├── mapping │ │ │ ├── package.json │ │ │ └── module.js │ │ └── program.js │ ├── load-package-digit │ │ ├── 0 │ │ │ ├── a.js │ │ │ └── package.json │ │ ├── package.json │ │ └── program.js │ ├── module-exports │ │ ├── package.json │ │ ├── module-exports.js │ │ └── program.js │ ├── serialization-compiler │ │ ├── package.json │ │ ├── model.js │ │ ├── object.js │ │ └── program.js │ ├── flat-module-tree │ │ ├── node_modules │ │ │ ├── path │ │ │ │ ├── index.js │ │ │ │ └── package.json │ │ │ ├── url │ │ │ │ ├── index.js │ │ │ │ └── package.json │ │ │ └── http-server │ │ │ │ ├── node_modules │ │ │ │ ├── path │ │ │ │ │ ├── index.js │ │ │ │ │ └── package.json │ │ │ │ └── url │ │ │ │ │ ├── index.js │ │ │ │ │ └── package.json │ │ │ │ ├── index.js │ │ │ │ └── package.json │ │ ├── package.json │ │ └── program.js │ ├── load-package-name │ │ ├── package.json │ │ ├── node_modules │ │ │ └── a │ │ │ │ ├── package.json │ │ │ │ └── a.js │ │ └── program.js │ ├── sandbox │ │ ├── b.js │ │ ├── node_modules │ │ │ └── dependency │ │ │ │ ├── package.json │ │ │ │ ├── c.js │ │ │ │ ├── other.js │ │ │ │ └── main.js │ │ ├── a.js │ │ ├── package.json │ │ └── program.js │ ├── inject-into-mapping │ │ ├── somedir │ │ │ └── mapping │ │ │ │ ├── package.json │ │ │ │ └── module.js │ │ ├── package.json │ │ └── program.js │ ├── main │ │ ├── node_modules │ │ │ ├── dot-slash │ │ │ │ ├── a.js │ │ │ │ └── package.json │ │ │ ├── js-ext │ │ │ │ ├── a.js │ │ │ │ └── package.json │ │ │ ├── no-ext │ │ │ │ ├── a.js │ │ │ │ └── package.json │ │ │ └── dot-js-ext │ │ │ │ ├── a.something.js │ │ │ │ └── package.json │ │ ├── package.json │ │ └── program.js │ ├── module-main-default │ │ ├── node_modules │ │ │ └── sub-module │ │ │ │ ├── package.json │ │ │ │ └── index.js │ │ ├── package.json │ │ └── program.js │ ├── module-metadata │ │ ├── node_modules │ │ │ └── a │ │ │ │ ├── a.js │ │ │ │ └── package.json │ │ ├── package.json │ │ └── program.js │ ├── package-lock │ │ ├── node_modules │ │ │ ├── url │ │ │ │ ├── node_modules │ │ │ │ │ └── path │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ └── package.json │ │ │ │ ├── index.js │ │ │ │ └── package.json │ │ │ └── http-server │ │ │ │ ├── node_modules │ │ │ │ ├── path │ │ │ │ │ ├── index.js │ │ │ │ │ └── package.json │ │ │ │ └── url │ │ │ │ │ ├── index.js │ │ │ │ │ └── package.json │ │ │ │ ├── index.js │ │ │ │ └── package.json │ │ ├── package.json │ │ ├── program.js │ │ └── package-lock.json │ ├── redirects │ │ ├── barz.js │ │ ├── package.json │ │ └── program.js │ ├── main-name │ │ ├── node_modules │ │ │ └── dependency │ │ │ │ ├── dependency.js │ │ │ │ └── package.json │ │ ├── package.json │ │ └── program.js │ ├── named-mappings │ │ ├── node_modules │ │ │ ├── foo │ │ │ │ ├── package.json │ │ │ │ └── foo.js │ │ │ └── bar │ │ │ │ └── package.json │ │ ├── package.json │ │ └── program.js │ ├── named-packages │ │ ├── node_modules │ │ │ ├── foo │ │ │ │ ├── package.json │ │ │ │ └── foo.js │ │ │ └── bar │ │ │ │ └── package.json │ │ ├── package.json │ │ └── program.js │ ├── production │ │ ├── node_modules │ │ │ └── dev-dependency │ │ │ │ ├── dev-dependency.js │ │ │ │ └── package.json │ │ ├── package.json │ │ └── program.js │ ├── dev-dependencies │ │ ├── node_modules │ │ │ └── dev-dependency │ │ │ │ ├── dev-dependency.js │ │ │ │ └── package.json │ │ ├── package.json │ │ └── program.js │ ├── legacy-bundling │ │ ├── package.json │ │ ├── node_modules │ │ │ └── nested │ │ │ │ ├── node_modules │ │ │ │ └── child │ │ │ │ │ ├── package.json │ │ │ │ │ └── index.js │ │ │ │ ├── index.js │ │ │ │ └── package.json │ │ └── program.js │ ├── redirects-package │ │ ├── node_modules │ │ │ └── foo │ │ │ │ ├── barz.js │ │ │ │ └── package.json │ │ ├── package.json │ │ └── program.js │ ├── dot-js-module │ │ ├── package.json │ │ ├── node_modules │ │ │ └── test.js │ │ │ │ ├── package.json │ │ │ │ └── main.load.js │ │ └── program.js │ ├── script-injection-dep │ │ ├── package.json │ │ ├── node_modules │ │ │ └── dependency │ │ │ │ ├── package.json │ │ │ │ ├── second.load.js │ │ │ │ └── main.load.js │ │ └── program.js │ ├── browser-alternative │ │ ├── program.js │ │ ├── node_modules │ │ │ └── shimmy │ │ │ │ ├── index.js │ │ │ │ ├── browser.js │ │ │ │ └── package.json │ │ └── package.json │ ├── browser-alternatives │ │ ├── program.js │ │ ├── package.json │ │ └── node_modules │ │ │ └── shimmy │ │ │ ├── browser.js │ │ │ ├── index.js │ │ │ └── package.json │ ├── read │ │ ├── package.json │ │ └── program.js │ ├── overlay │ │ ├── package.json │ │ └── program.js │ ├── script-injection │ │ ├── packages │ │ │ └── dependency │ │ │ │ ├── package.json.load.js │ │ │ │ └── main.load.js │ │ ├── program.js │ │ └── package.json │ └── named-parent-package │ │ ├── package.json │ │ ├── node_modules │ │ └── child-package │ │ │ ├── package.json │ │ │ └── child-module.js │ │ ├── parent-module.js │ │ └── program.js ├── run-karma.html ├── run.html ├── package.json ├── run-node.js ├── run-karma.js ├── run-browser.js ├── all.js └── README.md ├── demo ├── data.js ├── index.js ├── package.json └── index.html ├── .jshintignore ├── bin └── mr ├── .gitignore ├── .editorconfig ├── .npmignore ├── .jshintrc ├── adhoc.html ├── .travis.yml ├── adhoc.js ├── LICENSE.md ├── CONTRIBUTING.md ├── package.json ├── docs ├── Node-compatability.md ├── Package-API.md ├── Script-attributes.md ├── Module-API.md ├── Require-API.md ├── Config-API.md └── How-it-works.md ├── sandbox.js ├── karma.conf.js ├── bootstrap-node.js ├── README.md ├── CHANGES.md └── node.js /test/spec/case-sensitive/a.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/spec/directory-index/bar.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/spec/comments/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/cyclic/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/identify/node_modules/x/x.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/spec/inject/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/method/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/missing/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/module-html/package.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /test/spec/module-reel/package.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /test/spec/monkeys/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/nested/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/relative/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/return/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/determinism/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/exactExports/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/load-package/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/module-error/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/moduleTypes/a/five.plus-one: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /test/spec/moduleTypes/a/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/moduleTypes/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/not-found/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/top-level/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/transitive/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/case-sensitive/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/directory-index/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/extension-loader/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/hasOwnProperty/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/identify/node_modules/cyclic/module.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/spec/inject-dependency/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/inject-mapping/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/load-package-digit/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/module-exports/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/serialization-compiler/package.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /test/spec/flat-module-tree/node_modules/path/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/spec/inject-mapping/mapping/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/load-package-name/package.json: -------------------------------------------------------------------------------- 1 | { 2 | } 3 | -------------------------------------------------------------------------------- /test/spec/moduleTypes/a/b.js: -------------------------------------------------------------------------------- 1 | module.exports = "pass" 2 | -------------------------------------------------------------------------------- /test/spec/sandbox/b.js: -------------------------------------------------------------------------------- 1 | module.exports = "original"; 2 | -------------------------------------------------------------------------------- /test/spec/load-package-digit/0/a.js: -------------------------------------------------------------------------------- 1 | module.exports = 10; 2 | -------------------------------------------------------------------------------- /test/spec/module-error/error.js: -------------------------------------------------------------------------------- 1 | throw new Error("whoops"); 2 | -------------------------------------------------------------------------------- /test/spec/module-reel/test.reel/test.js: -------------------------------------------------------------------------------- 1 | exports.Hello = "World"; -------------------------------------------------------------------------------- /test/spec/moduleTypes/a/c.json: -------------------------------------------------------------------------------- 1 | { 2 | "pass": true 3 | } 4 | -------------------------------------------------------------------------------- /test/spec/sandbox/node_modules/dependency/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/extension-loader/a.extension/a.js: -------------------------------------------------------------------------------- 1 | module.exports = 10; 2 | -------------------------------------------------------------------------------- /test/spec/inject-into-mapping/somedir/mapping/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/inject-mapping/mapping/module.js: -------------------------------------------------------------------------------- 1 | module.exports = 10; 2 | -------------------------------------------------------------------------------- /test/spec/main/node_modules/dot-slash/a.js: -------------------------------------------------------------------------------- 1 | module.exports = 10; 2 | -------------------------------------------------------------------------------- /test/spec/main/node_modules/js-ext/a.js: -------------------------------------------------------------------------------- 1 | module.exports = 20; 2 | -------------------------------------------------------------------------------- /test/spec/main/node_modules/no-ext/a.js: -------------------------------------------------------------------------------- 1 | module.exports = 30; 2 | -------------------------------------------------------------------------------- /test/spec/module-main-default/node_modules/sub-module/package.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /test/spec/module-metadata/node_modules/a/a.js: -------------------------------------------------------------------------------- 1 | exports.Exported = {}; -------------------------------------------------------------------------------- /test/spec/package-lock/node_modules/url/node_modules/path/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /demo/data.js: -------------------------------------------------------------------------------- 1 | module.exports = "This text was required from data.js!"; 2 | -------------------------------------------------------------------------------- /test/spec/flat-module-tree/node_modules/url/index.js: -------------------------------------------------------------------------------- 1 | require("path"); 2 | -------------------------------------------------------------------------------- /test/spec/inject-dependency/node_modules/dependency/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/spec/load-package/a/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "a.js" 3 | } 4 | -------------------------------------------------------------------------------- /test/spec/package-lock/node_modules/url/index.js: -------------------------------------------------------------------------------- 1 | require("path"); 2 | -------------------------------------------------------------------------------- /test/spec/sandbox/node_modules/dependency/c.js: -------------------------------------------------------------------------------- 1 | module.exports = {}; 2 | -------------------------------------------------------------------------------- /test/spec/identify/node_modules/x/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "x" 3 | } 4 | -------------------------------------------------------------------------------- /test/spec/main/node_modules/dot-js-ext/a.something.js: -------------------------------------------------------------------------------- 1 | module.exports = 40; 2 | -------------------------------------------------------------------------------- /test/spec/redirects/barz.js: -------------------------------------------------------------------------------- 1 | exports.foo = function() { 2 | return 1; 3 | } -------------------------------------------------------------------------------- /test/spec/flat-module-tree/node_modules/http-server/node_modules/path/index.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /test/spec/main/node_modules/js-ext/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "a.js" 3 | } 4 | -------------------------------------------------------------------------------- /test/spec/main/node_modules/no-ext/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "a" 3 | } 4 | -------------------------------------------------------------------------------- /test/spec/module-main-default/node_modules/sub-module/index.js: -------------------------------------------------------------------------------- 1 | exports.Exported = 1; -------------------------------------------------------------------------------- /test/spec/module-metadata/node_modules/a/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "a" 3 | } 4 | -------------------------------------------------------------------------------- /test/spec/package-lock/node_modules/http-server/node_modules/path/index.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /test/spec/sandbox/node_modules/dependency/other.js: -------------------------------------------------------------------------------- 1 | module.exports = "other"; 2 | -------------------------------------------------------------------------------- /.jshintignore: -------------------------------------------------------------------------------- 1 | **/node_modules/** 2 | **/test/spec/** 3 | **/report/** 4 | **/packages/** -------------------------------------------------------------------------------- /test/spec/inject-dependency/node_modules/dependency/module.js: -------------------------------------------------------------------------------- 1 | module.exports = 10; 2 | -------------------------------------------------------------------------------- /test/spec/main-name/node_modules/dependency/dependency.js: -------------------------------------------------------------------------------- 1 | module.exports = true; 2 | -------------------------------------------------------------------------------- /test/spec/main/node_modules/dot-slash/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "./a.js" 3 | } 4 | -------------------------------------------------------------------------------- /test/spec/sandbox/node_modules/dependency/main.js: -------------------------------------------------------------------------------- 1 | module.exports = require("other"); 2 | -------------------------------------------------------------------------------- /test/spec/load-package-name/node_modules/a/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "a.js" 3 | } 4 | -------------------------------------------------------------------------------- /test/spec/module-metadata/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "a": "*" 4 | } 5 | } -------------------------------------------------------------------------------- /test/spec/named-mappings/node_modules/foo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "foo.js" 3 | } 4 | -------------------------------------------------------------------------------- /test/spec/named-packages/node_modules/foo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "foo.js" 3 | } 4 | -------------------------------------------------------------------------------- /test/spec/production/node_modules/dev-dependency/dev-dependency.js: -------------------------------------------------------------------------------- 1 | module.exports = 10; 2 | -------------------------------------------------------------------------------- /test/spec/dev-dependencies/node_modules/dev-dependency/dev-dependency.js: -------------------------------------------------------------------------------- 1 | module.exports = 10; 2 | -------------------------------------------------------------------------------- /test/spec/flat-module-tree/node_modules/http-server/node_modules/url/index.js: -------------------------------------------------------------------------------- 1 | require("path"); 2 | -------------------------------------------------------------------------------- /test/spec/legacy-bundling/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "nested":"*" 4 | } 5 | } -------------------------------------------------------------------------------- /test/spec/main/node_modules/dot-js-ext/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "a.something.js" 3 | } 4 | -------------------------------------------------------------------------------- /test/spec/package-lock/node_modules/http-server/index.js: -------------------------------------------------------------------------------- 1 | require("path"); 2 | require("url"); 3 | -------------------------------------------------------------------------------- /test/spec/package-lock/node_modules/http-server/node_modules/url/index.js: -------------------------------------------------------------------------------- 1 | require("path"); 2 | -------------------------------------------------------------------------------- /bin/mr: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node --harmony_weakmaps --harmony_proxies 2 | require("../bootstrap-node"); 3 | -------------------------------------------------------------------------------- /test/spec/flat-module-tree/node_modules/http-server/index.js: -------------------------------------------------------------------------------- 1 | require("path"); 2 | require("url"); 3 | -------------------------------------------------------------------------------- /test/spec/load-package-digit/0/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "0", 3 | "main": "a.js" 4 | } 5 | -------------------------------------------------------------------------------- /test/spec/module-main-default/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "sub-module": "*" 4 | } 5 | } -------------------------------------------------------------------------------- /test/spec/redirects-package/node_modules/foo/barz.js: -------------------------------------------------------------------------------- 1 | exports.foo = function() { 2 | return 1; 3 | } -------------------------------------------------------------------------------- /test/spec/sandbox/a.js: -------------------------------------------------------------------------------- 1 | exports.value = require("./b"); 2 | exports.c = require("dependency/c"); 3 | -------------------------------------------------------------------------------- /demo/index.js: -------------------------------------------------------------------------------- 1 | var data = require("data"); 2 | 3 | document.getElementById("hello").textContent = data; 4 | -------------------------------------------------------------------------------- /test/spec/legacy-bundling/node_modules/nested/node_modules/child/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "index" 3 | } -------------------------------------------------------------------------------- /test/spec/dot-js-module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "test.js": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/spec/main-name/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "dependency": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mr-demo", 3 | "dependencies": { 4 | "mr": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/spec/flat-module-tree/node_modules/path/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "path", 3 | "version": "2" 4 | } 5 | -------------------------------------------------------------------------------- /test/spec/legacy-bundling/node_modules/nested/index.js: -------------------------------------------------------------------------------- 1 | var child = require('child'); 2 | 3 | exports.foo = child.foo; -------------------------------------------------------------------------------- /test/spec/directory-index/foo/index.js: -------------------------------------------------------------------------------- 1 | 2 | exports.program = function () { 3 | return require('program'); 4 | }; 5 | -------------------------------------------------------------------------------- /test/spec/inject-into-mapping/somedir/mapping/module.js: -------------------------------------------------------------------------------- 1 | module.exports = require("dependency"); // Injected by program 2 | -------------------------------------------------------------------------------- /test/spec/script-injection-dep/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "dependency": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/spec/serialization-compiler/model.js: -------------------------------------------------------------------------------- 1 | exports.Model = function Model(value) { 2 | this.value = value; 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /test/spec/serialization-compiler/object.js: -------------------------------------------------------------------------------- 1 | var Model = require('./model').Model; 2 | 3 | exports.model = new Model(10) 4 | -------------------------------------------------------------------------------- /test/spec/browser-alternative/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | require("shimmy"); 3 | test.print('DONE', 'info'); 4 | -------------------------------------------------------------------------------- /test/spec/browser-alternatives/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | require("shimmy"); 3 | test.print('DONE', 'info'); 4 | -------------------------------------------------------------------------------- /test/spec/dev-dependencies/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "dev-dependency": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/spec/dot-js-module/node_modules/test.js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "hash": "xxx", 3 | "useScriptInjection": true 4 | } 5 | -------------------------------------------------------------------------------- /test/spec/inject-into-mapping/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "mappings": { 3 | "mapping": "somedir/mapping" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/spec/legacy-bundling/node_modules/nested/node_modules/child/index.js: -------------------------------------------------------------------------------- 1 | exports.foo = function () { 2 | return 1; 3 | }; -------------------------------------------------------------------------------- /test/spec/main-name/node_modules/dependency/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dependency", 3 | "main": "missing.js" 4 | } 5 | -------------------------------------------------------------------------------- /test/spec/named-packages/node_modules/bar/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "foo": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/spec/read/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "mappings": { 3 | "bluebird": "../../../node_modules/bluebird" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/spec/named-packages/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "foo": "*", 4 | "bar": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/spec/package-lock/node_modules/url/node_modules/path/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "path", 3 | "version": "2" 4 | } 5 | -------------------------------------------------------------------------------- /test/spec/redirects/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "redirects", 3 | "redirects": { 4 | "bar": "barz" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/spec/legacy-bundling/node_modules/nested/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "index", 3 | "dependencies": { 4 | "child":"*" 5 | } 6 | } -------------------------------------------------------------------------------- /test/spec/overlay/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "overlay": { 3 | "abc": { 4 | "pass": 10 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/spec/package-lock/node_modules/http-server/node_modules/path/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "path", 3 | "version": "1" 4 | } 5 | -------------------------------------------------------------------------------- /test/spec/script-injection-dep/node_modules/dependency/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "hash": "xxx", 3 | "useScriptInjection": true 4 | } 5 | -------------------------------------------------------------------------------- /test/spec/flat-module-tree/node_modules/http-server/node_modules/path/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "path", 3 | "version": "1" 4 | } 5 | -------------------------------------------------------------------------------- /test/spec/production/node_modules/dev-dependency/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dev-dependency", 3 | "main": "dev-dependency" 4 | } 5 | -------------------------------------------------------------------------------- /test/spec/dev-dependencies/node_modules/dev-dependency/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dev-dependency", 3 | "main": "dev-dependency" 4 | } 5 | -------------------------------------------------------------------------------- /test/spec/production/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "production": true, 3 | "devDependencies": { 4 | "dev-dependency": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/spec/redirects-package/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "redirects-package", 3 | "dependencies": { 4 | "foo": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/spec/identify/node_modules/cyclic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cyclic", 3 | "dependencies": { 4 | "identify": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/spec/named-mappings/node_modules/bar/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.0.0", 3 | "dependencies": { 4 | "foo": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/spec/named-mappings/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "mappings": { 3 | "bar": {"name": "bar"}, 4 | "foo": {"name": "foo"} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/spec/redirects-package/node_modules/foo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "foo", 3 | "redirects": { 4 | "bar": "barz" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/spec/package-lock/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "_args": [], 3 | "dependencies": { 4 | "http-server": "1", 5 | "url": "2" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/spec/browser-alternative/node_modules/shimmy/index.js: -------------------------------------------------------------------------------- 1 | var test = require("browser-alternative-spec/test"); 2 | test.assert(typeof window === "undefined"); 3 | -------------------------------------------------------------------------------- /test/spec/browser-alternative/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "browser-alternative-spec", 3 | "dependencies": { 4 | "shimmy": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/spec/browser-alternatives/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "browser-alternatives-spec", 3 | "dependencies": { 4 | "shimmy": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/spec/flat-module-tree/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "_args": [], 3 | "dependencies": { 4 | "http-server": "1", 5 | "url": "2" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/spec/redirects/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | test.assert(require('bar').foo() == 1, 'nested module identifier'); 3 | test.print('DONE', 'info'); -------------------------------------------------------------------------------- /test/spec/browser-alternative/node_modules/shimmy/browser.js: -------------------------------------------------------------------------------- 1 | var test = require("browser-alternative-spec/test"); 2 | test.assert(typeof window !== "undefined"); 3 | -------------------------------------------------------------------------------- /test/spec/browser-alternatives/node_modules/shimmy/browser.js: -------------------------------------------------------------------------------- 1 | var test = require("browser-alternatives-spec/test"); 2 | test.assert(typeof window !== "undefined"); 3 | -------------------------------------------------------------------------------- /test/spec/browser-alternatives/node_modules/shimmy/index.js: -------------------------------------------------------------------------------- 1 | var test = require("browser-alternatives-spec/test"); 2 | test.assert(typeof window === "undefined"); 3 | -------------------------------------------------------------------------------- /test/spec/module-main-default/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | var Exported = require('sub-module').Exported; 3 | 4 | test.assert(typeof Exported, 1); 5 | -------------------------------------------------------------------------------- /test/spec/package-lock/node_modules/url/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "url", 3 | "version": "2", 4 | "dependencies": { 5 | "path": "2" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/spec/redirects-package/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | test.assert(require('foo/bar').foo() == 1, 'nested module identifier'); 3 | test.print('DONE', 'info'); -------------------------------------------------------------------------------- /test/spec/flat-module-tree/node_modules/url/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "url", 3 | "version": "2", 4 | "dependencies": { 5 | "path": "2" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .npmignore 2 | .tmp 3 | .idea 4 | .DS_Store 5 | atlassian-ide-plugin.xml 6 | npm-debug.log 7 | report/ 8 | node_modules/ 9 | !test/spec/**/node_modules 10 | out/ 11 | -------------------------------------------------------------------------------- /test/spec/main/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "dot-slash": "*", 4 | "js-ext": "*", 5 | "no-ext": "*", 6 | "dot-js-ext": "*" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/spec/module-reel/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | var reel = require("test.reel"); 3 | 4 | test.assert(reel.Hello === "World", 'import string'); 5 | test.print('DONE', 'info'); -------------------------------------------------------------------------------- /test/spec/package-lock/node_modules/http-server/node_modules/url/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "url", 3 | "version": "1", 4 | "dependencies": { 5 | "path": "1" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/spec/flat-module-tree/node_modules/http-server/node_modules/url/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "url", 3 | "version": "1", 4 | "dependencies": { 5 | "path": "1" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/spec/legacy-bundling/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | var nested = require('nested'); 3 | test.assert(nested.foo() === 1, 'child module identifier'); 4 | test.print('DONE', 'info'); 5 | -------------------------------------------------------------------------------- /test/spec/dev-dependencies/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | var ten = require("dev-dependency"); 3 | test.assert(10 === ten, "can require module from devDependency"); 4 | test.print("DONE", "info"); 5 | -------------------------------------------------------------------------------- /test/spec/identify/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "identify", 3 | "dependencies": { 4 | "cyclic": "*", 5 | "a": "*", 6 | "x": "*", 7 | "y": "*" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/spec/package-lock/node_modules/http-server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "http-server", 3 | "version": "1", 4 | "dependencies": { 5 | "path": "1", 6 | "url": "1" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/spec/script-injection/packages/dependency/package.json.load.js: -------------------------------------------------------------------------------- 1 | montageDefine("xxx", "package.json", { 2 | exports: { 3 | "hash": "xxx", 4 | "useScriptInjection": true 5 | } 6 | }); 7 | -------------------------------------------------------------------------------- /test/spec/flat-module-tree/node_modules/http-server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "http-server", 3 | "version": "1", 4 | "dependencies": { 5 | "path": "1", 6 | "url": "1" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/spec/browser-alternative/node_modules/shimmy/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "./index.js", 3 | "browser": "./browser.js", 4 | "dependencies": { 5 | "browser-alternative-spec": "*" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/spec/dot-js-module/node_modules/test.js/main.load.js: -------------------------------------------------------------------------------- 1 | montageDefine("xxx", "main", { 2 | dependencies: [], 3 | factory: function(require, exports, module) { 4 | module.exports = 10; 5 | }}); 6 | 7 | -------------------------------------------------------------------------------- /test/spec/dot-js-module/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | 3 | test.assert(require("test.js/main") === 10, "can require dependency with .js in, in script-injection mode"); 4 | 5 | test.print('DONE', 'info'); 6 | -------------------------------------------------------------------------------- /test/spec/named-parent-package/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "named-parent-package", 3 | "version": "0.0.0", 4 | "main": "program", 5 | "dependencies": { 6 | "child-package": "0.0.0" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/spec/main-name/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | var dep = require("dependency/dependency"); 3 | 4 | test.assert(dep === true, "can require module with name of package"); 5 | test.print("DONE", "info"); 6 | 7 | -------------------------------------------------------------------------------- /test/spec/module-html/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | var html = require("simple-template.html"); 3 | 4 | test.assert(html.content.indexOf('') !== -1, 'can require html'); 5 | test.print("DONE", "info"); 6 | -------------------------------------------------------------------------------- /test/spec/script-injection/packages/dependency/main.load.js: -------------------------------------------------------------------------------- 1 | montageDefine("xxx", "main", { 2 | dependencies: [], 3 | factory: function(require, exports, module) { 4 | exports.main = true; 5 | } 6 | }); 7 | 8 | -------------------------------------------------------------------------------- /test/spec/script-injection-dep/node_modules/dependency/second.load.js: -------------------------------------------------------------------------------- 1 | montageDefine("xxx", "second", { 2 | dependencies: [], 3 | factory: function(require, exports, module) { 4 | module.exports = true; 5 | }}); 6 | 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://EditorConfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | indent_style = space 8 | indent_size = 4 9 | end_of_line = lf 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | -------------------------------------------------------------------------------- /test/spec/script-injection/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | 3 | var main = require("dependency/main"); 4 | 5 | test.assert(main.main === true, "can load module in script injection package"); 6 | 7 | test.print("DONE", "info"); 8 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .git 2 | .DS_Store 3 | .idea 4 | .jshintignore 5 | .jshintrc 6 | .npmignore 7 | .tmp 8 | .travis.yml 9 | adhoc.html 10 | adhoc.js 11 | demo 12 | docs 13 | lcov-report/ 14 | lcov.info 15 | node_modules 16 | test 17 | report 18 | -------------------------------------------------------------------------------- /test/spec/inject/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | require.inject("dependency", { 3 | foo: true 4 | }); 5 | var dependency = require("dependency"); 6 | test.assert(dependency.foo === true, "the injected dependency should export true"); 7 | -------------------------------------------------------------------------------- /test/spec/load-package-digit/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | module.exports = require.loadPackage("0") 3 | .then(function (zero) { 4 | return zero.async(""); 5 | }) 6 | .then(function () { 7 | test.print("DONE", "info"); 8 | }) 9 | -------------------------------------------------------------------------------- /test/spec/case-sensitive/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | try { 3 | require("a"); 4 | require("A"); 5 | test.assert(false, "should fail to require alternate spelling"); 6 | } catch (error) { 7 | } 8 | test.print("DONE", "info"); 9 | -------------------------------------------------------------------------------- /test/spec/named-parent-package/node_modules/child-package/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "child-package", 3 | "version": "0.0.0", 4 | "main": "child-module", 5 | "dependencies": { 6 | "named-parent-package": "0.0.0" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/spec/script-injection/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "mappings": { 3 | "dependency": { 4 | "name": "dependency", 5 | "hash": "xxx", 6 | "location": "packages/dependency/" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/spec/browser-alternatives/node_modules/shimmy/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "./index.js", 3 | "browser": { 4 | "index": "./browser.js" 5 | }, 6 | "dependencies": { 7 | "browser-alternatives-spec": "*" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/spec/script-injection-dep/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | 3 | var dep = require("dependency/main"); 4 | 5 | test.assert(dep.main, "dependency loaded"); 6 | test.assert(dep.second, "dependency's dependency loaded"); 7 | 8 | test.print("DONE", "info"); 9 | -------------------------------------------------------------------------------- /test/spec/inject-into-mapping/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | require.inject("mapping/dependency", { 3 | foo: true 4 | }) 5 | var Dependency = require("mapping/module"); 6 | test.assert(Dependency.foo === true, "the injected depency should export foo"); 7 | 8 | -------------------------------------------------------------------------------- /test/spec/sandbox/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "mappings": { 3 | "mr": "../../..", 4 | "bluebird": "../../../node_modules/bluebird" 5 | }, 6 | "redirects": { 7 | "d": "a" 8 | }, 9 | 10 | "dependencies": { 11 | "dependency": "*" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/spec/script-injection-dep/node_modules/dependency/main.load.js: -------------------------------------------------------------------------------- 1 | montageDefine("xxx", "main", { 2 | dependencies: ["second"], 3 | factory: function(require, exports, module) { 4 | var second = require("second"); 5 | exports.main = true; 6 | exports.second = second; 7 | }}); 8 | 9 | -------------------------------------------------------------------------------- /test/spec/inject-dependency/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | require.injectDependency("dependency"); 3 | module.exports = require.async("dependency/module") 4 | .then(function (value) { 5 | test.assert(value === 10, "the injected dependency should export 10"); 6 | test.print("DONE", "info"); 7 | }); 8 | -------------------------------------------------------------------------------- /test/spec/identify/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | 3 | // ensure relevant packages are loaded 4 | require("x/x"); 5 | require("cyclic/module"); 6 | 7 | var xRequire = require.getPackage({name: "x"}); 8 | 9 | test.assert(require.identify('z', xRequire) === 'x/z'); 10 | 11 | test.print("DONE", "info"); 12 | -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Mr demo 5 | 6 | 7 | 8 | 9 | 10 |

Hello Mr

11 | 12 |

13 | 14 | 15 | -------------------------------------------------------------------------------- /test/spec/package-lock/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Note that the node_modules structure is not an expected result from 3 | * running npm install, but the package should still load using the 4 | * package-lock.json. 5 | */ 6 | 7 | var test = require('test'); 8 | 9 | require("http-server"); 10 | require("url"); 11 | test.print('DONE', 'info'); 12 | -------------------------------------------------------------------------------- /test/spec/overlay/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | 3 | var config = { 4 | overlays: ["abc"] 5 | }; 6 | 7 | return require.loadPackage(module.directory, config) 8 | .then(function (packageRequire) { 9 | test.assert(packageRequire.packageDescription.pass === 10, "overlay applied") 10 | test.print("DONE", "info"); 11 | }); 12 | -------------------------------------------------------------------------------- /test/spec/inject-mapping/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | require.injectMapping({ 3 | "location": "mapping", 4 | "name": "dependency" 5 | }); 6 | module.exports = require.async("dependency/module") 7 | .then(function (value) { 8 | test.assert(value === 10, "the injected dependency should export 10"); 9 | test.print("DONE", "info"); 10 | }); 11 | -------------------------------------------------------------------------------- /test/spec/module-error/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | 3 | function run() { 4 | try { 5 | require("./error"); 6 | } catch (_error) { 7 | if (_error.message === "whoops") { 8 | return true; 9 | } 10 | } 11 | return false; 12 | } 13 | 14 | test.assert(run() === true, "First require fails"); 15 | test.assert(run() === true, "Second require still fails"); 16 | 17 | test.print('DONE', 'info'); 18 | -------------------------------------------------------------------------------- /test/spec/module-metadata/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | var Exported = require('a').Exported; 3 | 4 | test.assert(typeof Exported._montage_metadata === 'object', 'import metadata'); 5 | test.assert(typeof Exported._montage_metadata.require === 'function', 'import metadata'); 6 | test.assert(Exported._montage_metadata.module === 'a', 'import metadata'); 7 | test.assert(Exported._montage_metadata.property === 'Exported', 'import metadata'); 8 | test.print('DONE', 'info'); -------------------------------------------------------------------------------- /test/spec/main/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | 3 | test.assert(require('dot-slash') === 10, 'main with "./"'); 4 | test.assert(require('js-ext') === 20, 'main with ".js" extension'); 5 | test.assert(require('no-ext') === 30, 'main with no extension'); 6 | test.assert(require('dot-js-ext') === 40, 'main with "." in module name and ".js" extension'); 7 | 8 | test.assert(require('js-ext') === require("js-ext/a"), 'can require "main" without extension'); 9 | 10 | test.print('DONE', 'info'); 11 | -------------------------------------------------------------------------------- /test/spec/production/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | module.exports = require.async("dev-dependency") 3 | .then(function (a) { 4 | throw "should not be able to require dev-dependency in production mode"; 5 | }, function (error) { 6 | console.log(error.message); 7 | test.assert( 8 | /Can\'t require module "dev-dependency" via "program"/.test(error.message), 9 | "cannot require dev-dependency in production mode" 10 | ); 11 | }) 12 | .then(function () { 13 | test.print("DONE", "info"); 14 | }); 15 | -------------------------------------------------------------------------------- /test/spec/serialization-compiler/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | var object = require("./object"); 3 | 4 | test.assert(object.model._montage_metadata, "should expose _montage_metadata on exports properties"); 5 | test.assert(object.model._montage_metadata.module === 'object', "should expose module on _montage_metadata"); 6 | test.assert(object.model._montage_metadata.property === 'model', "should expose module on _montage_metadata"); 7 | test.assert(object.model._montage_metadata.require, "should expose require on _montage_metadata"); 8 | test.print("DONE", "info"); 9 | -------------------------------------------------------------------------------- /test/spec/module-html/simple-template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/run-karma.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Montage-Require - Karma 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/run.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Montage-Require - Browser 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "bitwise": true, 3 | "camelcase": true, 4 | "curly": true, 5 | "eqeqeq": true, 6 | "forin": true, 7 | "noarg": true, 8 | "noempty": true, 9 | "nonew": true, 10 | "undef": true, 11 | "unused": "paramsignore", 12 | "trailing": true, 13 | "indent": 4, 14 | "boss": true, 15 | "eqnull": true, 16 | "browser": true, 17 | "globals": { 18 | "CustomEvent": true, 19 | "WebSocket": false, 20 | 21 | "require": false, 22 | "exports": false, 23 | "module": false, 24 | "global": false, 25 | 26 | "WeakMap": true, 27 | "Map": true, 28 | "Set": true, 29 | 30 | "console": false 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "_comment": [ 3 | "# If you use npm to generate or modify this file, make sure", 4 | "# to restore the file's 4 space indents after the generation", 5 | "# or modification so it matches other source files in the", 6 | "# project. npm only generates files with 2 space indents", 7 | "# (see https://github.com/npm/npm/pull/3180#issuecomment-16336516)." 8 | ], 9 | "name": "run", 10 | "version": "1.0.0-alpha.1", 11 | "license": "BSD-3-Clause", 12 | "author": "Montage Studio, inc. (http://montagestudio.com/)", 13 | "scripts": { 14 | "postinstall": "npm link ./.." 15 | }, 16 | "mappings": { 17 | "bluebird": "../node_modules/bluebird" 18 | }, 19 | "dependencies": {}, 20 | "private": true 21 | } -------------------------------------------------------------------------------- /test/spec/read/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | var Promise = require("bluebird"); 3 | 4 | function read(location) { 5 | if (location === "http://test/package.json") { 6 | return Promise.resolve(JSON.stringify({name: "pass"})); 7 | } else if (location === "http://test/module.js") { 8 | return Promise.resolve("module.exports = 5"); 9 | } else { 10 | return Promise.reject(new Error(location + " not here")); 11 | } 12 | } 13 | 14 | module.exports = require.loadPackage({location: "http://test/"}, { read: read }) 15 | .then(function (pkg) { 16 | test.assert(pkg.config.name === "pass"); 17 | 18 | return pkg.async("module"); 19 | }) 20 | .then(function (exports) { 21 | test.assert(exports === 5); 22 | 23 | test.print("DONE", "info"); 24 | }); 25 | -------------------------------------------------------------------------------- /adhoc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Open your browser's console.

8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
Package location:
Module Identifier:
23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /test/spec/extension-loader/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | 3 | var extensionRe = /([^\/]+)\.extension$/; 4 | var ExtensionLoader = function (config, load) { 5 | return function (id, module) { 6 | var match = extensionRe.exec(id); 7 | if (match) { 8 | module.redirect = id + "/" + match[1]; 9 | return module; 10 | } else { 11 | return load(id, module); 12 | } 13 | }; 14 | }; 15 | 16 | var config = {}; 17 | config.makeLoader = function (config) { 18 | return ExtensionLoader(config, require.config.makeLoader(config)); 19 | }; 20 | 21 | return require.loadPackage(module.directory, config) 22 | .then(function (packageRequire) { 23 | return packageRequire.async("a.extension"); 24 | }).then(function (aExports) { 25 | test.assert(aExports === 10, 'require with extension loader'); 26 | test.print('DONE', 'info'); 27 | }); 28 | 29 | -------------------------------------------------------------------------------- /test/spec/package-lock/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "package-lock", 3 | "lockfileVersion": 1, 4 | "requires": true, 5 | "dependencies": { 6 | "http-server": { 7 | "version": "1", 8 | "requires": { 9 | "path": "1", 10 | "url": "1" 11 | }, 12 | "dependencies": { 13 | "path": { 14 | "version": "1" 15 | }, 16 | "url": { 17 | "version": "1", 18 | "requires": { 19 | "path": "1" 20 | } 21 | } 22 | } 23 | }, 24 | "url": { 25 | "version": "2", 26 | "requires": { 27 | "path": "2" 28 | }, 29 | "dependencies": { 30 | "path": { 31 | "version": "2" 32 | } 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | cache: 3 | directories: 4 | - node_modules 5 | node_js: 6 | - "10" 7 | - "8" 8 | - "6" 9 | - "4" 10 | script: npm run $COMMAND 11 | env: 12 | - COMMAND=test 13 | - COMMAND=test:karma 14 | - COMMAND=integration MR_VERSION=. MOP_VERSION=latest 15 | - COMMAND=integration MR_VERSION=. MOP_VERSION="#master" 16 | - COMMAND=integration MR_VERSION=. MOP_VERSION="18.0.0" 17 | jobs: 18 | include: 19 | - stage: lint 20 | node_js: 9 21 | env: 22 | script: npm run lint 23 | - stage: deploy 24 | node_js: 4 25 | script: skip 26 | env: 27 | deploy: 28 | provider: npm 29 | email: "${NPM_EMAIL}" 30 | api_key: "${NPM_API_KEY}" 31 | on: 32 | tags: true 33 | stages: 34 | - lint 35 | - test 36 | - deploy 37 | notifications: 38 | irc: 39 | channels: 40 | - "chat.freenode.net#montage" 41 | on_success: false 42 | template: 43 | - "%{author} broke the %{repository} tests on %{branch}: %{build_url}" 44 | -------------------------------------------------------------------------------- /adhoc.js: -------------------------------------------------------------------------------- 1 | /* global URL:true */ 2 | 3 | var URL = require("mini-url"); 4 | var QS = require("qs"); 5 | 6 | var a = document.createElement("a"); 7 | 8 | var packageLocation; 9 | var moduleId; 10 | 11 | if (window.location.search) { 12 | var query = QS.parse(window.location.search.slice(1)); 13 | var packageLocation = query['package-location']; 14 | var moduleId = query['module-id']; 15 | document.querySelector("[name=package-location]").value = packageLocation; 16 | document.querySelector("[name=module-id]").value = moduleId; 17 | run(packageLocation, moduleId); 18 | } 19 | 20 | function run(packageLocation, moduleId) { 21 | packageLocation = URL.resolve(window.location, packageLocation); 22 | moduleId = moduleId || ""; 23 | 24 | console.log("Require:", "package:", JSON.stringify(packageLocation), "id:", JSON.stringify(moduleId)); 25 | require.loadPackage(packageLocation) 26 | .invoke("async", moduleId) 27 | .then(function (exports) { 28 | console.log("Exports:", exports); 29 | console.log("Packages:", require.packages); 30 | }); 31 | } 32 | -------------------------------------------------------------------------------- /test/spec/moduleTypes/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | 3 | var config = { 4 | moduleTypes: ["plus-one"], 5 | makeCompiler: function (config) { 6 | var compile = require.config.makeCompiler(config); 7 | return function (module) { 8 | var isPlusOne = (module.location || "").match(/\.plus-one$/); 9 | if (isPlusOne) { 10 | module.exports = parseInt(module.text, 10) + 1; 11 | return Promise.resolve(module); 12 | } else { 13 | return compile(module); 14 | } 15 | }; 16 | } 17 | }; 18 | 19 | return require.loadPackage(module.directory + "a", config) 20 | .then(function (packageRequire) { 21 | return packageRequire.async("five.plus-one") 22 | .then(function (six) { 23 | test.assert(six === 6, 'can require .plus-one modules'); 24 | return packageRequire.async("b"); 25 | }) 26 | .then(function (b) { 27 | test.assert(b === "pass", 'can require javascript module'); 28 | return packageRequire.async("c.json"); 29 | }) 30 | .then(function (json) { 31 | test.assert(json.pass === true, 'can require json module'); 32 | test.print('DONE', 'info'); 33 | 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /test/spec/sandbox/program.js: -------------------------------------------------------------------------------- 1 | var test = require("test"); 2 | var Promise = require("bluebird"); 3 | 4 | var sandbox = require("mr/sandbox"); 5 | 6 | var a = require("./a"); 7 | var dep = require("dependency/main"); 8 | 9 | return Promise.all([ 10 | sandbox(require, "./a", { 11 | "./b": "mocked" 12 | }), 13 | sandbox(require, "dependency/main", { 14 | "other": "mocked" 15 | }), 16 | sandbox(require, "d", { 17 | "./b": "redirected" 18 | }) 19 | ]) 20 | .spread(function (sandboxedA, sandboxedDep, sandboxedD) { 21 | var a2 = require("./a"); 22 | var dep2 = require("dependency/main"); 23 | 24 | test.assert(a.value === "original", "a.b is the original"); 25 | test.assert(sandboxedA.value === "mocked", "sandboxedA.b is the mock"); 26 | test.assert(a.c === sandboxedA.c, "a.c and sandboxedA.c are the same"); 27 | test.assert(a.d === sandboxedA.d, "a.d and sandboxedA.d are the same"); 28 | test.assert(a2.value === "original", "a2.b is the original"); 29 | 30 | test.assert(dep === "other", "dep is the original"); 31 | test.assert(sandboxedDep === "mocked", "sandboxedDep is the mock"); 32 | test.assert(dep2 === "other", "dep2 is the original"); 33 | 34 | test.assert(sandboxedD.value === "redirected", "sandboxedD.b is redirected"); 35 | }).then(function () { 36 | test.print('DONE', 'info'); 37 | }); 38 | -------------------------------------------------------------------------------- /test/run-node.js: -------------------------------------------------------------------------------- 1 | /*jshint node:true, browser:false */ 2 | var jasmineRequire = require('jasmine-core/lib/jasmine-core/jasmine.js'); 3 | var JasmineConsoleReporter = require('jasmine-console-reporter'); 4 | 5 | // Init 6 | var jasmine = jasmineRequire.core(jasmineRequire); 7 | var jasmineEnv = jasmine.getEnv(); 8 | 9 | // Export interface 10 | var jasmineInterface = jasmineRequire.interface(jasmine, jasmineEnv); 11 | global.jasmine = jasmine; 12 | global.jasmineRequire = jasmineRequire; 13 | for (var property in jasmineInterface) { 14 | if (jasmineInterface.hasOwnProperty(property)) { 15 | global[property] = jasmineInterface[property]; 16 | } 17 | } 18 | 19 | // Default reporter 20 | jasmineEnv.addReporter(jasmineInterface.jsApiReporter); 21 | 22 | // Html reporter 23 | var consoleReporter = new JasmineConsoleReporter({ 24 | colors: 1, 25 | cleanStack: 1, 26 | verbosity: 4, 27 | listStyle: 'indent', 28 | activity: false 29 | }); 30 | jasmineEnv.addReporter(consoleReporter); 31 | 32 | // Exit code 33 | var exitCode = 0; 34 | jasmineEnv.addReporter({ 35 | specDone: function(result) { 36 | exitCode = exitCode || result.status === 'failed'; 37 | } 38 | }); 39 | 40 | // Execute 41 | var mrRequire = require('../bootstrap-node'); 42 | var PATH = require("path"); 43 | 44 | mrRequire.loadPackage(PATH.join(__dirname, ".")).then(function (mr) { 45 | return mr.async("all"); 46 | }).then(function () { 47 | console.log('Done'); 48 | process.exit(exitCode); 49 | }).thenReturn(); -------------------------------------------------------------------------------- /test/spec/determinism/submodule/b.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | -------------------------------------------------------------------------------- /test/spec/hasOwnProperty/toString.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | -------------------------------------------------------------------------------- /test/spec/hasOwnProperty/hasOwnProperty.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | -------------------------------------------------------------------------------- /test/spec/return/returns.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | return 10; 33 | -------------------------------------------------------------------------------- /test/spec/load-package/a/a.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | module.exports = 10; 33 | -------------------------------------------------------------------------------- /test/spec/monkeys/a.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | require('program').monkey = 10; 33 | -------------------------------------------------------------------------------- /test/spec/top-level/b.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | exports.foo = function() {}; 33 | -------------------------------------------------------------------------------- /test/spec/transitive/a.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | exports.foo = require('b').foo; 33 | -------------------------------------------------------------------------------- /test/spec/transitive/b.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | exports.foo = require('c').foo; 33 | -------------------------------------------------------------------------------- /test/spec/module-exports/module-exports.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | module.exports = 10; 33 | -------------------------------------------------------------------------------- /test/spec/load-package-name/node_modules/a/a.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | module.exports = 10; 33 | -------------------------------------------------------------------------------- /test/spec/named-mappings/node_modules/foo/foo.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | exports.foo = 10; 33 | -------------------------------------------------------------------------------- /test/spec/named-packages/node_modules/foo/foo.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | exports.foo = 10; 33 | -------------------------------------------------------------------------------- /test/spec/named-parent-package/parent-module.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | module.exports = 10; 33 | -------------------------------------------------------------------------------- /test/spec/relative/submodule/a.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | exports.foo = require('./b').foo; 33 | -------------------------------------------------------------------------------- /test/spec/relative/submodule/b.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | exports.foo = function () { 33 | }; 34 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 3-clause BSD license 2 | ==================== 3 | 4 | Copyright 2012-2014 Motorola Mobility LLC, Montage Studio Inc, and contributors. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name of Motorola Mobility LLC, Montage Studio, Montage nor the 18 | names of its contributors may be used to endorse or promote products derived 19 | from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /test/spec/nested/a/b/c/d.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | exports.foo = function () { 33 | return 1; 34 | }; 35 | -------------------------------------------------------------------------------- /test/spec/transitive/c.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | exports.foo = function () { 33 | return 1; 34 | }; 35 | -------------------------------------------------------------------------------- /test/spec/cyclic/a.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | exports.a = function () { 32 | return b; 33 | }; 34 | var b = require('b'); 35 | -------------------------------------------------------------------------------- /test/spec/cyclic/b.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | var a = require('a'); 32 | exports.b = function () { 33 | return a; 34 | }; 35 | -------------------------------------------------------------------------------- /test/spec/exactExports/a.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | exports.program = function () { 33 | return require('program'); 34 | }; 35 | -------------------------------------------------------------------------------- /test/spec/top-level/submodule/a.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | exports.foo = function () { 33 | return require('b'); 34 | }; 35 | -------------------------------------------------------------------------------- /test/spec/named-parent-package/node_modules/child-package/child-module.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | module.exports = require("named-parent-package/parent-module"); 33 | -------------------------------------------------------------------------------- /test/spec/transitive/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require('test'); 33 | test.assert(require('a').foo() == 1, 'transitive'); 34 | test.print('DONE', 'info'); 35 | -------------------------------------------------------------------------------- /test/spec/determinism/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | var test = require('test'); 32 | var a = require('submodule/a'); 33 | test.assert(a, "a is defined"); 34 | test.print('DONE', 'info'); 35 | -------------------------------------------------------------------------------- /test/spec/nested/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require('test'); 33 | test.assert(require('a/b/c/d').foo() == 1, 'nested module identifier'); 34 | test.print('DONE', 'info'); 35 | -------------------------------------------------------------------------------- /test/spec/monkeys/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var a = require('a'); 33 | var test = require('test'); 34 | test.assert(exports.monkey == 10, 'monkeys permitted'); 35 | test.print('DONE', 'info'); 36 | -------------------------------------------------------------------------------- /test/spec/return/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require("test"); 33 | test.assert(require("returns") === 10, 'module return value should replace exports'); 34 | test.print('DONE', 'info'); 35 | -------------------------------------------------------------------------------- /test/spec/comments/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | // require("a"); 32 | // require("a"); 33 | /* require("b"); */ 34 | /* require("b"); */ 35 | var test = require('test'); 36 | test.print('DONE', 'info'); 37 | -------------------------------------------------------------------------------- /test/spec/exactExports/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require('test'); 33 | var a = require('a'); 34 | test.assert(a.program() === exports, 'exact exports'); 35 | test.print('DONE', 'info'); 36 | -------------------------------------------------------------------------------- /test/spec/named-mappings/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require("test"); 33 | test.assert(require("bar/foo").foo === 10, 'can require through shared dependency'); 34 | test.print("DONE", "info"); 35 | -------------------------------------------------------------------------------- /test/spec/named-packages/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require("test"); 33 | test.assert(require("bar/foo").foo === 10, 'can require through shared dependency'); 34 | test.print("DONE", "info"); 35 | -------------------------------------------------------------------------------- /test/spec/hasOwnProperty/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var hasOwnProperty = require('hasOwnProperty'); 33 | var toString = require('toString'); 34 | var test = require('test'); 35 | test.print('DONE', 'info'); 36 | -------------------------------------------------------------------------------- /test/spec/module-exports/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require('test'); 33 | test.assert(require('module-exports') === 10, 'replacing module exports should replace the module exports'); 34 | test.print('DONE', 'info'); 35 | -------------------------------------------------------------------------------- /test/spec/named-parent-package/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require("test"); 33 | test.assert(require("child-package") === require("parent-module"), 'child package requires module from named parent package'); 34 | test.print("DONE", "info"); 35 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | Pull requests are gladly accepted. We also really appreciate tests. 5 | 6 | Tests 7 | ----- 8 | 9 | On the command line the tests can be run by running `npm test`. This will run the tests in Node, and then in PhantomJS. 10 | 11 | The tests can also be run directly in the browser by opening `spec/run.html`. Note that the tests must be accessed through a web server, and not through a `file://` url. 12 | 13 | ### Creating 14 | 15 | Here's how to create a new test: 16 | 17 | 1. Create a new directory in `spec/`. 18 | 2. Add the name of the directory to the bottom of the array in `spec/require-spec.js`. If the test should not be run on Node.js then instead of a string add an object: `{name: "YOUR-NAME", node: false}`. 19 | 3. Inside the new directory create a `package.json` file. The contents of this file can just be `{}` (an empty JSON object), unless you are testing or using some of the `package.json` features. 20 | 4. Inside the new directory create a `program.js` file. This is where the test is. The contents of this file depends on whether the test is synchronous or asynchronous: 21 | 22 | * Synchronous test 23 | 24 | ```javascript 25 | var test = require('test'); 26 | 27 | // your test here 28 | test.assert(true === true, "assertion message"); 29 | 30 | test.print('DONE', 'info'); 31 | ``` 32 | 33 | * Asynchronous test 34 | 35 | ```javascript 36 | var test = require('test'); 37 | 38 | // your test starts here... 39 | return /* async call */.then(function () { 40 | // ...and continues here 41 | test.assert(true === true, "assertion message"); 42 | 43 | test.print('DONE', 'info'); 44 | }); 45 | ``` 46 | 47 | Add any other modules you need inside the directory, including `node_modules` directories if you are testing package dependencies. 48 | -------------------------------------------------------------------------------- /test/spec/load-package/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require("test"); 33 | module.exports = require.loadPackage("a") 34 | .then(function (a) { 35 | return a.async(""); 36 | }) 37 | .then(function () { 38 | test.print("DONE", "info"); 39 | }) 40 | -------------------------------------------------------------------------------- /test/spec/top-level/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require('test'); 33 | var a = require('submodule/a'); 34 | var b = require('b'); 35 | test.assert(a.foo().foo === b.foo, 'require works with top-level identifiers'); 36 | test.print('DONE', 'info'); 37 | -------------------------------------------------------------------------------- /test/spec/relative/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require('test'); 33 | var a = require('submodule/a'); 34 | var b = require('submodule/b'); 35 | test.assert(a.foo == b.foo, 'a and b share foo through a relative require'); 36 | test.print('DONE', 'info'); 37 | -------------------------------------------------------------------------------- /test/spec/load-package-name/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require("test"); 33 | module.exports = require.loadPackage({name: "a"}) 34 | .then(function (a) { 35 | return a.async(""); 36 | }) 37 | .then(function () { 38 | test.print("DONE", "info"); 39 | }) 40 | -------------------------------------------------------------------------------- /test/spec/method/a.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | exports.foo = function () { 33 | return this; 34 | }; 35 | exports.set = function (x) { 36 | this.x = x; 37 | }; 38 | exports.get = function () { 39 | return this.x; 40 | }; 41 | exports.getClosed = function () { 42 | return exports.x; 43 | }; 44 | -------------------------------------------------------------------------------- /test/spec/flat-module-tree/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Up to npm 3, npm always installed packages in the package's node_modules 3 | * directory. Starting in npm 3, npm now tries to avoid duplication by floating 4 | * dependencies-of-dependencies as far up the directory structure as possible 5 | * without causing version conflicts. 6 | * 7 | * This means when a module requires a node_module, that dependency may have 8 | * been installed to ./node_modules, ../node_modules, ../../node_modules, etc. 9 | * There is no way to determine where a dependency has been installed (until 10 | * npm 5's package-lock.json), as npm 3+ is non-deterministic and the location 11 | * a dependency is installed to can change depending on install order. 12 | * 13 | * Imagine a simple web application project that runs an http server. The 14 | * packages are: http-server, url, and path. The dependencies between packages 15 | * are: 16 | * 17 | * flat-module-tree -> [http-server@1, url@2] flat-module-tree 18 | * http-server@1 -> [path@1, url@1] / \ 19 | * url@1 -> [path@1] http-server@1 url@2 20 | * url@2 -> [path@2] / \ | 21 | * path@1 -> [] path@1 <- url@1 path@2 22 | * path@2 -> [] 23 | * 24 | * This test's directory structure is a possible result of running npm install: 25 | * 26 | * flat-module-tree 27 | * | 28 | * node_modules 29 | * / | \ 30 | * http-server@1 path@2 url@2 31 | * | 32 | * node_modules 33 | * / \ 34 | * url@1 path@1 35 | * 36 | * To understand how npm 3+ works and why it is non-deterministic, see 37 | * https://npm.github.io/how-npm-works-docs/npm3/how-npm3-works.html 38 | */ 39 | 40 | var test = require('test'); 41 | 42 | require("http-server"); 43 | require("url"); 44 | test.print('DONE', 'info'); 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mr", 3 | "version": "18.0.0", 4 | "description": "A refresh-only CommonJS module system for browsers, used in Montage", 5 | "license": "BSD-3-Clause", 6 | "keywords": [ 7 | "montage", 8 | "require", 9 | "commonjs", 10 | "module", 11 | "modules", 12 | "loader" 13 | ], 14 | "engines": { 15 | "node": ">=8.2.1", 16 | "npm": ">=6.7.0" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/montagejs/mr.git" 21 | }, 22 | "main": "require", 23 | "scripts": { 24 | "test": "node test/run-node.js", 25 | "lint": "jshint .", 26 | "integration": "mop-integration", 27 | "test:karma": "karma start --no-auto-watch --single-run", 28 | "test:karma-dev": "karma start --auto-watch --no-single-run", 29 | "test:jasmine": "concurrently \"http-server -p 8081\" \"open http://localhost:8081/test/run.html\"", 30 | "test:demo": "concurrently \"http-server -a localhost -p 8082\" \"open http://localhost:8082/demo/\"" 31 | }, 32 | "bin": { 33 | "mr": "bin/mr" 34 | }, 35 | "production": true, 36 | "dependencies": { 37 | "bluebird": "~3.5.5" 38 | }, 39 | "devDependencies": { 40 | "concurrently": "^3.4.0", 41 | "http-server": "^0.9.0", 42 | "jasmine-console-reporter": "^1.2.7", 43 | "jasmine-core": "^2.5.2", 44 | "jshint": "^2.9.5", 45 | "karma": "^1.5.0", 46 | "karma-chrome-launcher": "^2.0.0", 47 | "karma-coverage": "^1.1.1", 48 | "karma-firefox-launcher": "^1.0.1", 49 | "karma-jasmine": "^1.1.0", 50 | "karma-phantomjs-launcher": "^1.0.2", 51 | "mop-integration": "git://github.com/montagejs/mop-integration.git#master", 52 | "open": "7.0.0" 53 | }, 54 | "exclude": [ 55 | "README.md", 56 | "CHANGES.md", 57 | "LICENSE.md", 58 | "bootstrap-node.js", 59 | "node.js", 60 | "adhoc.*", 61 | "bin", 62 | "demo", 63 | "test" 64 | ] 65 | } 66 | -------------------------------------------------------------------------------- /test/spec/cyclic/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | var test = require('test'); 32 | var a = require('a'); 33 | var b = require('b'); 34 | 35 | test.assert(a.a, 'a exists'); 36 | test.assert(b.b, 'b exists') 37 | test.assert(a.a().b === b.b, 'a gets b'); 38 | test.assert(b.b().a === a.a, 'b gets a'); 39 | 40 | test.print('DONE', 'info'); 41 | -------------------------------------------------------------------------------- /test/spec/determinism/submodule/a.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | var test = require('test'); 32 | var pass = false; 33 | var test = require('test'); 34 | try { 35 | require('a'); 36 | } catch (exception) { 37 | pass = true; 38 | } 39 | test.assert(pass, 'require does not fall back to relative modules when absolutes are not available.') 40 | -------------------------------------------------------------------------------- /docs/Node-compatability.md: -------------------------------------------------------------------------------- 1 | Node and npm compatibility 2 | ========================== 3 | 4 | Montage fully supports CommonJS Modules and Packages. It also supports 5 | some of the extensions from NodeJS and npm: 6 | 7 | - **module.exports**: Modules that do not have cyclic dependencies 8 | (modules with dependencies that in turn ultimately depend their own 9 | exports) can redefine their exports object by assigning to 10 | `module.exports`. 11 | - **dependencies**: If a package declares a package dependency using 12 | NPM’s `dependencies` property, Montage looks for that package in 13 | the package’s `node_modules` subdirectory. Mr also 14 | supports the case where a package with the same name is already 15 | loaded by a parent package. Unlike NPM, with Montage packages, you 16 | can use mappings to find individual packages in alternate locations or 17 | give them different local names. 18 | - **devDependencies**: Development dependencies are treated the same as 19 | `dependencies`, except in production mode where they are ignored. 20 | - **JSON**: Resources with the `.json` extension can be loaded as JSON 21 | formatted modules. 22 | 23 | 24 | ## Differences 25 | 26 | There are some differences with the Node.js module system you should be aware 27 | of: 28 | 29 | - `dependencies` version predicates are ignored. 30 | - `__filename` and `__dirname` are not injected into module scope. Consider 31 | using `module.location` and `module.directory` instead. 32 | - Because Mr cannot know if a URL points to a file or a directory, when you 33 | require a directory `index.js` is not sought. To make a package using an 34 | `index.js` compatible with Montage Require, add a `redirects` block to 35 | `package.json`. See the [package API](./Package-API.md) 36 | 37 | In addition to these differences Mr adds some additional properties to 38 | [package.json](./Package-API.md), [module](./Module-API.md) and 39 | [require](./Require-API.md). 40 | -------------------------------------------------------------------------------- /test/spec/missing/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require('test'); 33 | try { 34 | require('bogus'); 35 | test.print('FAIL require throws error when module missing', 'fail'); 36 | } catch (exception) { 37 | test.print('PASS require throws error when module missing', 'pass'); 38 | } 39 | test.print('DONE', 'info'); 40 | -------------------------------------------------------------------------------- /test/spec/method/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require('test'); 33 | var a = require('a'); 34 | var foo = a.foo; 35 | test.assert(a.foo() == a, 'calling a module member'); 36 | test.assert(foo() == (function (){return this})(), 'members not implicitly bound'); 37 | a.set(10); 38 | test.assert(a.get() == 10, 'get and set') 39 | test.print('DONE', 'info'); 40 | -------------------------------------------------------------------------------- /test/spec/not-found/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require('test'); 33 | test.print("Can't XHR a.js expected", "info"); 34 | try { 35 | require("a"); 36 | } catch (exception) { 37 | test.print(exception.message); 38 | test.assert(/Can't require module "a" via "program" because Can't XHR /.test(exception.message)); 39 | } 40 | test.print('DONE', 'info'); 41 | -------------------------------------------------------------------------------- /test/spec/directory-index/program.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Motorola Mobility LLC. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of Motorola Mobility LLC nor the names of its 16 | contributors may be used to endorse or promote products derived from this 17 | software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | var test = require('test'); 33 | var bar = require('bar'); 34 | 35 | // Should all resolve same module 36 | var foo1 = require('foo'); 37 | var foo2 = require('foo/index'); 38 | var foo3 = require('foo/index.js'); 39 | 40 | test.assert(foo1.program() === exports, 'exact exports'); 41 | test.assert(foo2.program() === exports, 'exact exports'); 42 | test.assert(foo3.program() === exports, 'exact exports'); 43 | test.print('DONE', 'info'); 44 | -------------------------------------------------------------------------------- /docs/Package-API.md: -------------------------------------------------------------------------------- 1 | package.json (package description) 2 | ================================== 3 | 4 | Mr configures each package based on the contents of `package.json`, the 5 | package description, and the shared configuration. These properties are 6 | meaningful to Mr: 7 | 8 | - **name**: the name of the package, which may be used to connect 9 | common dependencies of the same name in subpackages. 10 | - **dependencies**: an object mapping a string that represents both a 11 | module identifier prefix and a package name, to an ignored version 12 | predicate. 13 | - **mappings**: an object that maps a module identifier prefix to a 14 | dependency. The dependency may be a location string, or an object 15 | with `location`, `name`, or `hash` properties. The location may be 16 | inferred from dependencies of already discovered packages, or from 17 | the location of the dependent package and the name. The `hash` is 18 | generated by an optimizer and only used for loading modules with 19 | script injection. 20 | 21 | ```json 22 | "mappings": { 23 | "q": { 24 | "name": "q", 25 | "location": "packages/q" 26 | } 27 | } 28 | ``` 29 | 30 | will cause Mr to load the Q package from `./packages/q` instead of 31 | `./node_modules/q`. 32 | 33 | - **overlay**: an object defining alternate configurations depending 34 | on the platform. Keys correspond to engines and values are 35 | alternate properties to overwrite on the package description. For 36 | the browser, the `window`, `browser`, and `montage` engines are 37 | applied. This property is likely to be deprecated and replaced by 38 | an `if` block or other content-negotiation blocks in the future. 39 | - **main**: the module identifier of the module that represents this 40 | package when required in other packages by the mapping module 41 | identier, or in this package by its own name. 42 | - **production**: when set to `true` it puts the system into production mode. 43 | Currently this only ignores any `devDependencies`. 44 | - **redirects**: an object that maps module identifiers to an alternate module identifier. 45 | 46 | ```json 47 | "redirects": { 48 | "foo": "foo/index" 49 | } 50 | ``` 51 | 52 | will cause `require("foo")` to return the exports from the `foo/index` module. 53 | -------------------------------------------------------------------------------- /sandbox.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Inject dependencies into a module. 3 | * @param {function} parentRequire Your require. 4 | * @param {String} sandboxId The module id to load 5 | * @param {Object} sandboxDependencies An object mapping from module ids 6 | * relative to the sandboxId module, to the exports that should be returned. 7 | * @return {Promise} A promise for the exports 8 | * @example 9 | * var mockFileReader = sandbox(require, "./file-reader", { 10 | * "fs": { 11 | * "readFile": function () { return "content"; } 12 | * } 13 | * }); 14 | */ 15 | module.exports = function (parentRequire, sandboxId, sandboxDependencies) { 16 | var topId = parentRequire.resolve(sandboxId); 17 | var originalModule = parentRequire.getModuleDescriptor(topId); 18 | 19 | while (originalModule.redirect || originalModule.mappingRedirect) { 20 | if (originalModule.redirect) { 21 | topId = originalModule.redirect; 22 | } else { 23 | parentRequire = originalModule.mappingRequire; 24 | topId = originalModule.mappingRedirect; 25 | } 26 | originalModule = parentRequire.getModuleDescriptor(topId); 27 | } 28 | 29 | return parentRequire.deepLoad(topId) 30 | .then(function () { 31 | // delete the exports to cause the factory to get called again 32 | var originalExports = originalModule.exports; 33 | delete originalModule.exports; 34 | 35 | // wrap the factory to work our magic 36 | var originalFactory = originalModule.factory; 37 | originalModule.factory = function (require, exports, module) { 38 | var sandboxRequire = function (id) { 39 | if (id in sandboxDependencies) { 40 | return sandboxDependencies[id]; 41 | } 42 | return require(id); 43 | }; 44 | var sandboxModule = JSON.parse(JSON.stringify(module)); 45 | var sandboxExports = sandboxModule.exports; 46 | 47 | return originalFactory(sandboxRequire, sandboxExports, sandboxModule) || sandboxModule.exports; 48 | }; 49 | 50 | var sandboxExports = parentRequire(topId); 51 | 52 | // restore normality 53 | originalModule.exports = originalExports; 54 | originalModule.factory = originalFactory; 55 | 56 | return sandboxExports; 57 | }); 58 | }; 59 | -------------------------------------------------------------------------------- /docs/Script-attributes.md: -------------------------------------------------------------------------------- 1 | Script attributes 2 | ================= 3 | 4 | ### data-module 5 | 6 | `data-module` instructs Mr to `require` the given module after it 7 | has finished bootstrapping and the DOM content has loaded. 8 | 9 | ```html 10 | 11 | ``` 12 | 13 | will load `package.json` and then `index.js`. 14 | 15 | ### data-auto-package 16 | 17 | `data-auto-package` indicates that there is no `package.json` for this 18 | application, and instructs Mr to pretend that an empty one exists 19 | in the same directory as the HTML document. 20 | 21 | ```html 22 | 23 | ``` 24 | 25 | will load just `index.js`. 26 | 27 | ### data-package 28 | 29 | `data-package` indicates that there is a `package.json` and that it can be 30 | found at the given location. The default location is the same directory as 31 | the HTML file. 32 | 33 | ```html 34 | 35 | ``` 36 | 37 | will load `../package.json` and then `../index.js`, because the module id is 38 | relative to the root of the package. 39 | 40 | 41 | Optimizer script attributes 42 | =========================== 43 | 44 | The Montage Optimizer can convert entire packages to production ready versions 45 | without manual alteration. The optimizer rewrites HTML, particularly replacing 46 | the bootstrapping script with a bundle. As such, the run-time supports some 47 | additional options. 48 | 49 | These options are added automatically by Mop and should not be added or 50 | modified manually. 51 | 52 | ### data-bootstrap 53 | 54 | Indicates that this script element is the `bootstrap.js` script and denotes 55 | the location of that script. 56 | 57 | This is normally inferred from being a script with a `bootstrap.js` file name, 58 | but thw optimizer replaces the ` 27 | ``` 28 | 29 | Start writing your code in `index.js`, using the `require` function as you 30 | would in Node. Have a look at the [demo](https://github.com/montagejs/mr/tree/master/demo) 31 | for working example. 32 | 33 | You can place your `package.json` in a different location, or avoid having one 34 | at all, with other [script tag attributes](https://github.com/montagejs/mr/tree/master/docs/Script-attributes.md). 35 | 36 | ## Optimization 37 | 38 | Take a look at [Mop, the Montage Optimizer](https://github.com/montagejs/mop) 39 | to optimize applications for production. The optimizer can bundle packages with 40 | all of the dependent modules, can preload bundles of progressive enhancements 41 | in phases, and can generate HTML5 application cache manifests. 42 | 43 | ## Documentation 44 | 45 | Mr is [compatible with Node and npm](https://github.com/montagejs/mr/tree/master/docs/Node-compatability.md), although 46 | there are some differences. 47 | 48 | There is documentation for: 49 | 50 | - [`package.json` properties](https://github.com/montagejs/mr/tree/master/docs/Package-API.md) 51 | - [`require` function](https://github.com/montagejs/mr/tree/master/docs/Require-API.md) 52 | - [`module` object](https://github.com/montagejs/mr/tree/master/docs/Module-API.md) 53 | - [The package `config` object](https://github.com/montagejs/mr/tree/master/docs/Config-API.md) 54 | 55 | And you may be interested in an in-depth look at [how Mr works](https://github.com/montagejs/mr/tree/master/docs/How-it-works.md). 56 | 57 | ## Compatibility 58 | 59 | At present, Mr depends on `document.querySelector` and 60 | probably several other recent EcmaScript methods that might not be 61 | available in legacy browsers. With your help, I intend to isolate and 62 | fix these bugs. 63 | 64 | At time of writing, tests pass in Chrome 21, Safari 5.1.5, and Firefox 65 | 13 on Mac OS 10.6. 66 | 67 | 68 | ## Maintenance 69 | 70 | Tests are in the `spec` directory. Use `npm test` to run the tests in 71 | NodeJS or open `spec/run.html` in a browser. 72 | 73 | To run the tests in your browser, simply use `npm run test:jasmine`. 74 | 75 | To run the tests using Karma use `npm run test:karma` and for continious tests run with file changes detection `npm run test:karma-dev`. 76 | 77 | ## About 78 | 79 | This implementation is a part from Motorola Mobility’s [Montage][] web 80 | application framework. The module system was written by Tom Robinson 81 | and Kris Kowal. Motorola holds the copyright on much of the original 82 | content, and provided it as open source under the permissive BSD 83 | 3-Clause license. This project is maintained by Kris Kowal and Stuart 84 | Knightley, continuing with that license. 85 | 86 | [Montage]: http://github.com/montage.js/montage 87 | 88 | -------------------------------------------------------------------------------- /test/all.js: -------------------------------------------------------------------------------- 1 | /* global it, fail, expect, jasmine, Promise */ 2 | console.log('mr-testing', 'Start'); 3 | 4 | function run(suiteRequire, modules) { 5 | 6 | // Filter node:false 7 | modules = modules.filter(function (module) { 8 | if (typeof module === "object") { 9 | if (module.node === false && typeof process !== "undefined") { 10 | return false; 11 | } else if (module.browser === false && typeof window !== "undefined") { 12 | return false; 13 | } 14 | } 15 | return true; 16 | }).map(function (module) { 17 | if (typeof module === "object") { 18 | return module.name; 19 | } else { 20 | return module; 21 | } 22 | }); 23 | 24 | var promises = modules.map(function (module) { 25 | 26 | var spec = this, 27 | packagePath = module + '/'; 28 | 29 | return suiteRequire.loadPackage(packagePath, { 30 | location: require.location 31 | }).then(function (pkg) { 32 | 33 | pkg.inject("test", { 34 | print: function (msg, level) {}, 35 | assert: function (guard, msg) { 36 | expect(!!guard).toBe(true); 37 | } 38 | }); 39 | 40 | it(module, function (done) { 41 | pkg.async("program").then(function () { 42 | expect("DONE").toBe("DONE"); 43 | }).catch(function (err) { 44 | fail(err); 45 | }).finally(function () { 46 | done(); 47 | }); 48 | }); 49 | }); 50 | }); 51 | 52 | return Promise.all(promises).then(function(results) { 53 | return new Promise(function (resolve, reject) { 54 | var jasmineEnv = jasmine.getEnv(); 55 | jasmineEnv.addReporter({ 56 | jasmineDone: function(result) { 57 | resolve(); 58 | } 59 | }); 60 | 61 | if (global.__karma__) { 62 | global.__karma__.start(); 63 | } else { 64 | jasmine.getEnv().execute(); 65 | } 66 | }); 67 | }); 68 | } 69 | 70 | module.exports = run(require, [ 71 | "spec/cyclic", 72 | "spec/determinism", 73 | "spec/exactExports", 74 | "spec/hasOwnProperty", 75 | "spec/method", 76 | "spec/missing", 77 | "spec/monkeys", 78 | "spec/nested", 79 | "spec/relative", 80 | "spec/top-level", 81 | "spec/transitive", 82 | "spec/module-exports", 83 | "spec/return", 84 | {name: "spec/named-packages", node: false}, 85 | {name: "spec/named-mappings", node: false}, 86 | "spec/named-parent-package", 87 | "spec/load-package", 88 | "spec/load-package-name", 89 | "spec/load-package-digit", 90 | {name: "spec/not-found", node: false}, 91 | "spec/redirects", 92 | "spec/redirects-package", 93 | "spec/comments", 94 | "spec/identify", 95 | "spec/dev-dependencies", 96 | "spec/production", 97 | "spec/case-sensitive", 98 | "spec/inject", 99 | "spec/inject-dependency", 100 | "spec/inject-into-mapping", 101 | "spec/inject-mapping", 102 | {name: "spec/script-injection-dep", node: false}, 103 | {name: "spec/script-injection", node: false}, 104 | "spec/read", 105 | "spec/main-name", 106 | "spec/main", 107 | "spec/sandbox", 108 | "spec/browser-alternative", 109 | "spec/browser-alternatives", 110 | "spec/extension-loader", 111 | "spec/overlay", 112 | "spec/moduleTypes", 113 | "spec/module-html", 114 | "spec/module-main-default", 115 | "spec/module-reel", 116 | "spec/module-error", 117 | "spec/module-metadata", 118 | "spec/legacy-bundling", 119 | "spec/flat-module-tree", 120 | "spec/package-lock", 121 | "spec/serialization-compiler", 122 | "spec/directory-index", 123 | {name: "spec/dot-js-module", node: false} 124 | ]).then(function () { 125 | console.log('mr-testing', 'End'); 126 | }, function (err) { 127 | console.log('mr-testing', 'Fail', err, err.stack); 128 | }); 129 | -------------------------------------------------------------------------------- /docs/Require-API.md: -------------------------------------------------------------------------------- 1 | `require` API 2 | ============= 3 | 4 | A `require` function stands for a package. Specialized `require` 5 | functions exist within each module. Calling `require` from outside a 6 | module will return the exports of the module with the given top-level 7 | identifier. Calling `require` within a module will resolve the given 8 | identifier relative to the current module and return the exports of the 9 | corresponding module. `require` will throw an exception if a needed 10 | module has not yet been loaded. 11 | 12 | - **async(id)**: returns a promise for the exports of the module with 13 | the given identifier. 14 | - **location**: the URL of the package, including the trailing slash 15 | for the directory. 16 | - **resolve(id)**: returns the top-level identifier for a module, 17 | relative to the current module. 18 | - **load(id)**: returns a memoized promise for the loading of the 19 | corresponding module. 20 | - **deepLoad(id)**: returns a memoized promise that the module and its 21 | transitive dependencies have all loaded. 22 | - **identify(id, require)**: a module may have a different identifier 23 | in another package. This returns the identifier for a module in a 24 | subpackage. 25 | - **getModuleDescriptor(id)**: returns a memoized `module` object 26 | describing the module in this package for the given identifier. If 27 | one does not exist, it creates one with `id`, `display`, and 28 | `require` properties to get things started. 29 | - **loadPackage(dependency)**: returns a promise for a `require` 30 | function representing the given package. The `dependency` may be by 31 | `name`, `location`, or both. If by `name` without `location`, the 32 | `location` is inferred from the registry of known packages, or from 33 | the `node_modules` directory within this package. If by `name` and 34 | `location`, the location is added to the registry of known package 35 | names. 36 | - **getPackage(dependency)**: returns the `require` function for an 37 | already loaded package, or throws an error. 38 | - **inject(id, exports)**: adds a module for a given identifier with 39 | the given exports, and sets its `module.injected` to true. This 40 | prevents the module system from attempting to load the module. 41 | - **injectMapping(mapping, prefix)**: Adds a mapping-style dependency 42 | to a package. The mapping object describes the dependent package in 43 | the same fashion as the value from the `mappings` property of a 44 | package.json. If the mapping does not provide a module name-space 45 | prefix, you can provide one as the second argument. 46 | - **injectDependency(name, version)**: Adds an NPM-style dependency to 47 | a package. The name and version should be as in an NPM `dependency` 48 | property in a `package.json`. The version is presently ignored but 49 | may in the future detect incompatibilities with another package 50 | installed with the same name. Mr will not support multiple versions 51 | of the same package. 52 | - **injectPackageDescription(location, description)**: informs the 53 | module system of the parsed contents of the `package.json` for the 54 | package at the given location. This may be a lie. This prevents 55 | the module system from attempting to load the `package.json`. The 56 | corresponding `package.json` need not actually exist. 57 | - **injectPackageDescriptionLocation(location, descriptionLocation)**: 58 | informs the module system of an alternate URL from which to download 59 | the `package.json` for this package. 60 | - **read(location)**: an exposed internal utility for reading the 61 | contents of a resource at a given URL. Returns a promise for the 62 | corresponding text. 63 | - **config**: the configuration object for this package. The `config` 64 | provided by the module system to each package prototypically 65 | inherits from the `config` given to the initial 66 | `Require.loadPackage` and contains additional properties obtained by 67 | analyzing `package.json`. Many but not all of these properties have 68 | the same name and shape as those in `package.json`. 69 | - **packageDescription**: the original parsed contents of the 70 | `package.json`, or that object delegated by 71 | `injectPackageDescription`. 72 | -------------------------------------------------------------------------------- /docs/Config-API.md: -------------------------------------------------------------------------------- 1 | Package `config` API 2 | ==================== 3 | 4 | `Require.loadPackage` accepts the following configuration options for 5 | all packages in a fresh module system. 6 | 7 | - **makeLoader**: the module loader maker, which by default depends on 8 | whether the loader is running on a browser or on Node. On the 9 | browser, it is a stack of `Require.MappingsLoader`, 10 | `Require.ExtensionsLoader`, `Require.PathsLoader`, 11 | `Require.MemoizedLoader`, then either `Require.ScriptLoader` or 12 | `Require.XhrLoader` depending on `config.define` for the config of 13 | the particular package. 14 | - **makeCompiler**: the compiler maker for each package, which by 15 | default is a stack of the `Require.JsonCompiler`, 16 | `Require.ShebangCompiler`, `Require.DependenciesCompiler`, and 17 | `LintCompiler` middleware. 18 | - **lint**: an optional event handler that accepts a `module` if its 19 | `text` is invalid JavaScript. There is no default value. `lint` is 20 | used by `Require.LintCompiler` middleware. 21 | - **read**: an optional resource reader, a function that must accept a 22 | fully qualified URL and return a promise for the content of that 23 | resource as a string. The default reader depends on whether Montage 24 | Require is running in a browser or on Node. 25 | 26 | Mr then adds shared state for all packages to the `config`. 27 | 28 | - **registry**: the location of each known package by name, for those 29 | packages that have either designated their own name, or been named 30 | by a dependent package in the `dependencies` or `mappings` 31 | properties of their package description. 32 | - **getPackage**: returns the `require` function for a package that 33 | has already been loaded, or throws an error. 34 | - **loadPackage**: returns a memoized promise for the description of a 35 | package at a given location. 36 | - **descriptions**: promises for each package description that is 37 | loading or has been loaded, by location. 38 | - **descriptionLocations**: an object mapping package locations to the 39 | locations of their package descriptions if an alternate is injected 40 | with `require.injectPackageDescriptionLocation`. 41 | 42 | Then, for each package, Mr creates a `config` that 43 | prototypically inherits from the master `config` and expands on that 44 | configuration with details synthesized from the content of the package 45 | description, `package.json`. This is the config that gets passed to 46 | `Require.makeRequire(config)`. 47 | 48 | - **location**: the package's location directory, including a trailing 49 | slash. 50 | - **name**: the name of this package, if it has one. 51 | - **packageDescription**: the original package description, either 52 | parsed from a `package.json` or injected by 53 | `require.injectPackageDescription`. 54 | - **define**: true if this package uses script injection to load 55 | resources. 56 | - **modules**: object mapping module descriptions by identifier 57 | - **lib**: the root directory location where modules can be found, by 58 | default the same as `location`. 59 | - **paths**: a prioritized array of directories in which to search for 60 | modules for this package, by default just the `lib` directory. It 61 | is inadvisable to give this array multiple entries on the 62 | client-side, and thus inadvisable for packages that might be used 63 | both client and server side. Really, just don't use this. It is 64 | used only by `PathsLoaders` middleware to convert module identifiers 65 | to locations. 66 | - **mappings**: object mapping module identifier prefixes to 67 | dependencies. These dependencies are suitable for passing to 68 | `require.loadPackage`. 69 | - **packagesDirectory**: the location in which to look for unknown 70 | packages by name, by default `node_modules` within this package. 71 | - **exposedConfigs**: an array of `config` properties instructing 72 | `makeRequire` to copy those properties from `config` to each 73 | `require` function, by default `paths`, `mappings`, `location`, 74 | `packageDescription`, `packages`, and `modules`. 75 | 76 | Within `Require.makeRequire(config)`, Mr uses `makeLoader` 77 | and `makeConfig` with its own `config` to produce `config.load` and 78 | `config.compile` properties. The `config.load` in particular is 79 | distinct and used internally by `require.load`, which memoizes and 80 | compiles modules. 81 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | 2 | # CommonJS Modules 3 | 4 | ## top-level 5 | 6 | Verifies that top-level identifiers refer to modules at the top level 7 | of a package, even when used from a child level. 8 | 9 | ## relative 10 | 11 | Verifies that relative module identifiers find neighboring modules in 12 | the module identifier space. 13 | 14 | ## cyclic 15 | 16 | Verifies that modules can have cyclic references. 17 | 18 | ## determinism 19 | 20 | Verifies that the module loader does not fall back to using relative 21 | module identifiers when a top-level module identifier doesn't exist. 22 | 23 | ## exactExports 24 | 25 | Verifies that the exports object within a module matches the exports 26 | object returned by require. Alternate designs were proposed where the 27 | exports as returned by require would be a "defensive" snapshot, 28 | preventing lazy definition. 29 | 30 | ## hasOwnProperty 31 | 32 | Verifies that "hasOwnProperty" is a valid module identifier, 33 | indicating that the implementation considers this special case if 34 | using objects as maps. 35 | 36 | ## method 37 | 38 | Verifies that the functions exported by a module are not implicitly 39 | bound to an object, albeit the exports or the module object. 40 | 41 | ## transitive 42 | 43 | Verifies that an exported object can be imported and exported from 44 | module to module. 45 | 46 | 47 | # CommonJS Modules Amendments 48 | 49 | ## monkeys 50 | 51 | Verifies that modules can be modified by other modules. 52 | 53 | ## return 54 | 55 | Verifies that a module can replace its exports by returning a defined 56 | value. 57 | 58 | ## module-exports 59 | 60 | Verifies that a module can replace its exports by assigning directly to 61 | `module.exports`. 62 | 63 | ## missing 64 | 65 | Verifies that a module will be executed even if it fails to load. The 66 | execution will throw an error. 67 | 68 | ## not-found 69 | 70 | Verifies that a module will be executed even if it fails to load. The 71 | execution will throw an error with a specific message. This test 72 | overlaps with `missing` and might be consolidated. 73 | 74 | ## comments 75 | 76 | Verifies that a module will be executed even if it has a spurious 77 | dependency mentioned in a comment. The commented dependency may fail to 78 | load but will not prevent the dependee from executing. 79 | 80 | ## case-sensitive 81 | 82 | Verifies that this system does case consistency checks. A module may 83 | only be loaded with one case convention, as a slight integrity check to 84 | verify that it can be hosted on a case-insensitive file system. It 85 | would be better to do integrity checks verifying that module identifiers 86 | are always lower-case (per the specification), but this is too strict in 87 | practice. 88 | 89 | ## reexecute 90 | 91 | This test is not included in the suite because it is a non-normative 92 | behavior. Illustrates that the current implementation has an edge case 93 | whereby a module can cause itself to be reexecuted for every user. 94 | 95 | 96 | # CommonJS Packages 97 | 98 | ## named-packages 99 | 100 | Verifies that named dependencies can be shared if they have a common 101 | ancestor. 102 | 103 | ## named-mappings 104 | 105 | Verifies that named mappings can be shared if they have a common 106 | ancestor. 107 | 108 | ## load-package 109 | 110 | Verifies that packages can be loaded asynchronously based on their 111 | location relative to the requesting package. 112 | 113 | As a byproduct, verifies that require.loadPackage and require.async 114 | return functioning promises. 115 | 116 | As a byproduct, also verifies that module exports reassignment works 117 | properly. 118 | 119 | ## legacy-bundling 120 | 121 | Verifies that dependencies can be loaded from a directory installed 122 | with legacy bundling, i.e. using npm <=2 or npm 3+ with the 123 | --legacy-bundling flag. In either of these situations, dependencies 124 | are installed without flattening. 125 | 126 | ## flat-module-tree 127 | 128 | Verifies that dependencies can be loaded from a directory installed 129 | with flattening, i.e. using npm 3+ without the --legacy-bundling 130 | flag. In this situation, dependencies will be installed as close to 131 | the root package as possible without causing version conflicts, and 132 | under npm 5+ a package-lock.json file is present that . 133 | 134 | ## package-lock 135 | 136 | Verifies that if a package-lock.json file exists, it is used to 137 | determine the locations of dependencies. 138 | 139 | ## load-package-name 140 | 141 | Verifies that packages can be loaded asynchronously based on their 142 | name, in the context of the requesting package. 143 | 144 | ## named-parent-package 145 | 146 | Verifies that a dependee package can use the dependent package by its 147 | name. 148 | 149 | ## dev-dependencies 150 | 151 | Verifies that modules linked in `devDependencies` of `package.json` can 152 | be loaded. 153 | 154 | ## production 155 | 156 | Verifies that when `package.json` has `production` set, modules linked in 157 | `devDependencies` are not loaded. 158 | 159 | ## identify 160 | 161 | Verifies that `require.identify(id, require2)` can reverse-lookup the 162 | identifier for a module in another package, by its id as known in the 163 | other package. 164 | 165 | ## redirects 166 | 167 | Verifies that a package can describe redirects from one module 168 | identifier to an alternative. 169 | 170 | ## redirects-package 171 | 172 | Verifies that a package can describe redirects from one module 173 | identifier to an alternative in a dependency package. 174 | -------------------------------------------------------------------------------- /docs/How-it-works.md: -------------------------------------------------------------------------------- 1 | How It Works 2 | ============ 3 | 4 | In broad strokes, Montage Require uses so-called "XML" HTTP requests to 5 | fetch modules, then uses a regular expression to scan for `require` 6 | calls within each JavaScript module, then executes the module with some 7 | variation of `eval`. Then, with the Montage Optimizer, `mop`, Montage 8 | Require can also serve as the runtime for loading modules with bundled 9 | script-injection with no alteration to the source code of an 10 | application. With script-injection, XHR and `eval` are not necessary, 11 | so applications are suitable for production, cross-domain, and with 12 | content security policies (CSP) that forbid `eval`. 13 | 14 | In slightly thinner strokes, Montage Require has an asynchronous phase 15 | and a synchronous phase. In the asynchronous "loading" phase, Montage 16 | Require fetches every module that it will need in the synchronous phase. 17 | It then passes into the synchronous "execution" phase, where `require` 18 | calls actually occur. The asynchronous portion includes 19 | `require.async`, `require.load`, and `require.deepLoad`, which return 20 | [Q][] promises. The synchronous phase employs `require` calls directly 21 | to transitively instantiate modules on demand. The system must be 22 | kicked off with `require.async` since no modules are loaded initially. 23 | 24 | [Q]: http://github.com/kriskowal/q 25 | 26 | Some alternatives to Montage Require use a full JavaScript parser to 27 | cull the false positives you will occasionally see when using regular 28 | expressions to scan for static `require` calls. This is a trade-off 29 | between weight and accuracy. Montage Require does not block execution 30 | when it is unable to load these false-positive modules, but instead 31 | continues to the execution to "wait and see" whether the module can run 32 | to completion without the module that failed to load. Also, Montage 33 | Require can be configured to use an alternate dependency parser. 34 | 35 | Around this system, Montage Require supports packages. This entails 36 | asynchronously loading and parsing `package.json` files, then 37 | configuring and connecting the module systems of each package in the 38 | "load" phase. Package dependencies are loaded on demand. 39 | 40 | Each package has an isolated module identifier name space. The 41 | `package.json` dictates how that name space forwards to other packages 42 | through the `dependencies` property, as well as internal aliases from 43 | the package's `name`, `main`, and `redirects` properties. 44 | 45 | Additionally, Montage Require is very configurable and pluggable. 46 | Montage itself vastly extends the capabilities of Montage Require so 47 | that it can load HTML templates. Montage's internal configuration 48 | includes middleware stacks for loading and compiling. The loader 49 | middleware stack can be overridden with `config.makeLoader` or 50 | `config.load`. The compiler middleware can be overridden with 51 | `config.makeCompiler` or `config.compile`. The makers are called to 52 | create loaders or compilers *per package*, each receiving the 53 | configuration for their particular package. 54 | 55 | The signature of loader middleware is `makeLoader(config, nextLoader)` 56 | which must return a function of the form `load(id, module)`. The 57 | signature of compiler middleware if `makeCompiler(config, nextCompiler)` 58 | which must return a function of the form `compile(module)`. 59 | 60 | As part of the bootstrapping process, configuration begins with a call 61 | to `Require.loadPackage(dependency, config)` that returns a promise for 62 | the `require` function of the package. 63 | 64 | `config` is an optional base configuration that can contain alternate 65 | `makeLoader`, `makeCompiler`, and `parseDependencies` functions. 66 | Montage Require then takes ownership of the `config` object and uses it 67 | to store information shared by all packages like the registries of known 68 | packages by name and location, and memoized promises for each package 69 | while they load. 70 | 71 | `dependency` declares the location of the package, and can also inform 72 | the module system of the consistent `hash` of the package. Dependency 73 | can be a `location` string for short, but gets internally normalized to 74 | an object with a `location` property. The `hash` is only necessary for 75 | optimized packages since they use script-injection. The injected 76 | scripts call `define` for each module, identifying the module by the 77 | containing package `hash` and module `id`. 78 | 79 | The `require` function for any package has a similar `loadPackage` 80 | function that can take a dependency argument. That dependency may have 81 | a `name` instead of `location`. In that case, Montage Require infers 82 | the location based on the known locations of packages with that name, or 83 | assumes the package exists within the `node_modules` directory of the 84 | dependent package. This is a relatively safe assumption if the 85 | application was installed with NPM. 86 | 87 | Montage Require also supports a form of dependency injection. These 88 | features were implemented because `bootstrap.js` (and in Montage proper, 89 | `montage.js`) would need to load and instantiate certain resources 90 | before being able to instantiate a module system. To avoid reloading 91 | these already-instantiated resources, the bootstrapper would inject them 92 | into the packages before handing control over to the application. 93 | 94 | `require.inject(id, exports)` adds the exports for a given module to a 95 | package. 96 | 97 | `require.injectPackageDescription(location, description)` allows the 98 | module system to read the content of a `package.json` for the package at 99 | `location` without fetching the corresponding file. 100 | 101 | `require.injectPackageDescriptionLocation(location, 102 | descriptionLocation)` instructs the module system to look in an 103 | alternate location for the `package.json` for a particular package. 104 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | ### 17.0.12 2 | - Fix commented require issue 3 | - Add support for require('dir') dir/index.js 4 | 5 | ### 17.0.0 6 | - Update Travis NodeJS to 4.8.0 7 | - Migrate Montage custom loaders to MontageRequire 8 | - Import support for module types html, mjson and reel from Montage.js 9 | - Import module metadata annotation from Montage.js 10 | - Upgrade tests stack 11 | - Migrate specs to Jasmine 2.5.2O (npm run test:jasmine) 12 | - Revamp NodeJS tests runner (npm test) 13 | - Migrate Phantom.js tests runner to Karma (npm run test:karma) 14 | 15 | ### 16.0.4 16 | - Memory optimization by caching a regex and making sure XHRs that are re-used don’t hold on their responses by calling abort() after the request succeeded or failed 17 | - Minimize object creation and closure scope 18 | - speed optimization 19 | - reducing scope lookup 20 | - reducing scope lookup in closure 21 | 22 | ### 16.0.3 23 | - updates bluebird dependency to ~3.4.6 24 | 25 | ### 16.0.2 26 | 27 | - Fixes a bug where a JSON module would fail to load because it would try to re-parse the content while it was already done 28 | 29 | ### 16.0.1 30 | 31 | - Addresses an issue caused by IE11 non-standard Map.prototype.set that returns undefined instead of Map itself 32 | 33 | ### 16.0.0 34 | 35 | - Performance Improvements 36 | 37 | ### 0.15.7 38 | 39 | - Don't load Mr's `devDependencies` into the mappings 40 | 41 | ### 0.15.6 42 | 43 | - Update Q to v1.0.1 44 | 45 | ### 0.15.5 46 | 47 | - Disable Firebug workaround that breaks modern Firefox 48 | 49 | ### 0.15.4 50 | 51 | - Fix display name for packages beginning with digits 52 | 53 | ### 0.15.3 54 | 55 | - Revert sourceMappingURL change, causes issues in Chrome and doesn't work great in Firefox. 56 | 57 | ### 0.15.2 58 | 59 | - Change `//@` for `//#` for SourceURL comment to match the spec 60 | - Use `sourceMappingURL` instead of `sourceURL`. This allows the evaled code 61 | to appear as source files in Firefox. 62 | - Friendlier display names for modules: 63 | `__FILE__http______localhost__8081__montagejs__mr__demo__data__` is now 64 | `mr_demo__data` 65 | 66 | ### 0.15.1 67 | 68 | - Fix requiring dependencies with ".js" in their name in script-injection mode 69 | (thanks @evax) 70 | - Fix requiring twice a module that throws an error 71 | 72 | ## 0.15.0 73 | 74 | - Added `moduleTypes` config parameter so that all loadable extensions are 75 | known. This fixes a bug where modules with a "." in them would not be loaded 76 | as JavaScript modules. When implementing a custom extension loader you must 77 | add the extension to the `config.moduleTypes` array when loading a package. 78 | 79 | ### 0.14.2 80 | 81 | - Use overlays in config given to `loadPackage`. 82 | 83 | ### 0.14.1 84 | 85 | - Correct extension detection 86 | 87 | ## 0.14.0 88 | 89 | - Remove support for `directories` `package.json` property. Node ignores the 90 | property, and continuing to support it breaks compatibility 91 | - Remove support for package reflexive module names 92 | - Fix main linkage for relative identifiers. Previously, a package with a 93 | `main` property that started with "./" would be linked incorrectly. 94 | - Fix loading of modules with a `.min.js` extension 95 | - Don't block XHR for the `file:` protocol. Firefox and Safari allow it as 96 | long as requests remain within the HTML page's directory. 97 | - Add support for the `browser` property in `package.json`, as pioneered by 98 | Browserify 99 | - Add "sandbox", to inject dependencies into a module. Require with 100 | `require("mr/sandbox")` 101 | 102 | ### 0.13.4 103 | 104 | - Update Q from v0.9.6 to v0.9.7 105 | - Fix loading of bundles 106 | - Wait for preload to finish before issuing requests for modules that might 107 | be included in one of the bundles 108 | 109 | ### 0.13.3 110 | 111 | - Use `config.read` when running on Node 112 | 113 | ### 0.13.2 114 | 115 | - Use `config.read` to load `package.json` if given to `loadPackage` 116 | 117 | ### 0.13.1 118 | 119 | - Fix `require.identify` to work with cyclic package dependencies 120 | 121 | ## 0.13.0 122 | 123 | - Fix bootstrap stopping if document had finished loading. 124 | - Update to Q v0.9.6 125 | - Add more complete demo and split the readme into multiple documentation 126 | files. 127 | 128 | ### 0.12.14 129 | 130 | - Fix bug when loading dependencies that use script-injection which are not 131 | included in a preloading bundle. Before Mr would hang when waiting for them 132 | to load. 133 | 134 | ### 0.12.13 135 | 136 | - Fix bug in preloading, where isResolved was replaced with isPending in Q 0.9 137 | 138 | ### 0.12.12 139 | 140 | - Fix preloading. Fixes some logic in figuring out whether to issue a script 141 | request for a package.json in production 142 | - Test runner updates 143 | 144 | ### 0.12.11 145 | 146 | - Add injectDependency and injectMapping 147 | - Update case sensitivity test to capture errors on first require, for case 148 | sensitive file systems 149 | - Add support for running tests under PhantomJS and Travis 150 | 151 | ### 0.12.10 152 | 153 | - Update Q from v0.9.0 to v0.9.2 154 | 155 | ### 0.12.9 156 | 157 | - Update Q from v0.8.12 to v0.9.0 158 | 159 | ### 0.12.8 160 | 161 | - Defer throwing load errors to execution (Fixes #14) 162 | - Update bootstrapping for latest Q 163 | 164 | ### 0.12.7 165 | 166 | - Support returned exports in bootstrapping 167 | - Export more Node utilities (when used on Node) 168 | - Require.urlToPath -> Require.locationToPath(location) 169 | - Add Require.filePathToLocation(path) 170 | - Add Require.directoryPathToLocation(path) 171 | - Add Require.findPackagePath(directory) 172 | - Add Require.findPackageLocationAndModuleId(path) 173 | 174 | ### 0.12.6 175 | 176 | - Add support for `production` mode. Currently causes Mr to ignore 177 | `devDependencies` 178 | 179 | ## 0.12.5 180 | 181 | - Update Q to 0.8.12 182 | -------------------------------------------------------------------------------- /node.js: -------------------------------------------------------------------------------- 1 | /* 2 | Based in part on Motorola Mobility’s Montage 3 | Copyright (c) 2012, Motorola Mobility LLC. All Rights Reserved. 4 | 3-Clause BSD License 5 | https://github.com/motorola-mobility/montage/blob/master/LICENSE.md 6 | */ 7 | /*jshint node:true */ 8 | var Require = require("./require"); 9 | var Promise = require("bluebird"); 10 | var FS = require("fs"); 11 | var URL = require("url"); 12 | var PATH = require("path"); 13 | var globalEval = eval; 14 | 15 | Require.getLocation = function getLocation() { 16 | return URL.resolve("file:///", process.cwd() + "/"); 17 | }; 18 | 19 | Require.locationToPath = function locationToPath(location) { 20 | var parsed = URL.parse(location); 21 | return parsed.path; 22 | }; 23 | 24 | Require.filePathToLocation = function filePathToLocation(path) { 25 | return URL.resolve(Require.getLocation(), path); 26 | }; 27 | 28 | Require.directoryPathToLocation = function directoryPathToLocation(path) { 29 | if (!/\/$/.test(path)) { 30 | path += "/"; 31 | } 32 | path = Require.filePathToLocation(path); 33 | return path; 34 | }; 35 | 36 | var jsIndexPrefix = '/index.js', 37 | jsPreffix = '.js'; 38 | Require.read = function read(location, module) { 39 | return new Promise(function (resolve, reject) { 40 | var path = Require.locationToPath(location); 41 | FS.readFile(path, "utf-8", function (error, text) { 42 | if (error) { 43 | // Re-use xhr on read on .js failure if not /index.js file and 44 | // retry on /index.js dynamically. 45 | if ( 46 | path.indexOf(jsPreffix) !== -1 && // is .js 47 | path.indexOf(jsIndexPrefix) === -1 // is not /index.js 48 | ) { 49 | path = path.replace(jsPreffix, jsIndexPrefix); 50 | 51 | // Attempt to read if file exists 52 | FS.readFile(path, "utf-8", function (error, text) { 53 | if (error) { 54 | reject(new Error(error)); 55 | } else { 56 | //We found a folder/index.js, we need to update the module to reflect that somehow 57 | module.location = location.replace(jsPreffix, jsIndexPrefix); 58 | module.redirect = module.id; 59 | module.redirect += "/index"; 60 | resolve(text); 61 | } 62 | }); 63 | } else { 64 | reject(new Error(error)); 65 | } 66 | } else { 67 | resolve(text); 68 | } 69 | }); 70 | }); 71 | }; 72 | 73 | // Compiles module text into a function. 74 | // Can be overriden by the platform to make the engine aware of the source path. Uses sourceURL hack by default. 75 | Require.Compiler = function Compiler(config) { 76 | config.scope = config.scope || {}; 77 | var names = ["require", "exports", "module"]; 78 | var scopeNames = Object.keys(config.scope); 79 | names.push.apply(names, scopeNames); 80 | return function (module) { 81 | 82 | if (module.location && (module.location.endsWith(".meta") || module.location.endsWith(".mjson"))) { 83 | return module; 84 | } 85 | 86 | if (module.factory) { 87 | return module; 88 | } else if ( 89 | module.text !== void 0 && 90 | module.type === "javascript" 91 | ) { 92 | var factory = globalEval( 93 | "(function(" + names.join(",") + "){" + 94 | module.text + 95 | "\n//*/\n})\n//@ sourceURL=" + module.location 96 | ); 97 | module.factory = function (require, exports, module) { 98 | Array.prototype.push.apply(arguments, scopeNames.map(function (name) { 99 | return config.scope[name]; 100 | })); 101 | return factory.apply(this, arguments); 102 | }; 103 | // new Function will have its body reevaluated at every call, hence using eval instead 104 | // https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope 105 | //module.factory = new Function("require", "exports", "module", module.text + "\n//*/\n//@ sourceURL="+module.path); 106 | } 107 | }; 108 | }; 109 | 110 | Require.Loader = function Loader(config, load) { 111 | return function (location, module) { 112 | return config.read(location, module) 113 | .then(function (text) { 114 | module.type = "javascript"; 115 | module.text = text; 116 | //module.location is now possibly changed by read if it encounters the pattern of 117 | //folder/index.js when it couldn't find folder.js, so we don't want to override that. 118 | //module.location = location; 119 | }, function (reason, error, rejection) { 120 | return load(location, module); 121 | }); 122 | }; 123 | }; 124 | 125 | Require.NodeLoader = function NodeLoader(config) { 126 | return function nodeLoad(location, module) { 127 | var id = location.slice(config.location.length); 128 | id = id.substr(0,id.lastIndexOf('.')); 129 | module.type = "native"; 130 | module.exports = require(id); 131 | module.location = location; 132 | return module; 133 | }; 134 | }; 135 | 136 | Require.makeLoader = function makeLoader(config) { 137 | return Require.ReelLoader(config, 138 | Require.MappingsLoader( 139 | config, 140 | Require.LocationLoader( 141 | config, 142 | Require.MemoizedLoader( 143 | config, 144 | Require.Loader( 145 | config, 146 | Require.NodeLoader(config) 147 | ) 148 | ) 149 | ) 150 | ) 151 | ); 152 | }; 153 | 154 | Require.findPackagePath = function findPackagePath(directory) { 155 | if (directory === PATH.dirname(directory)) { 156 | return Promise.reject(new Error("Can't find package")); 157 | } 158 | var packageJson = PATH.join(directory, "package.json"); 159 | return Promise.ninvoke(FS, "stat", packageJson) 160 | .then(function (stat) { 161 | return stat.isFile(); 162 | }, function (error) { 163 | return false; 164 | }).then(function (isFile) { 165 | if (isFile) { 166 | return directory; 167 | } else { 168 | return Require.findPackagePath(PATH.dirname(directory)); 169 | } 170 | }); 171 | }; 172 | 173 | Require.findPackageLocationAndModuleId = function findPackageLocationAndModuleId(path) { 174 | path = PATH.resolve(process.cwd(), path); 175 | var directory = PATH.dirname(path); 176 | return Require.findPackagePath(directory) 177 | .then(function (packageDirectory) { 178 | var modulePath = PATH.relative(packageDirectory, path); 179 | modulePath = modulePath.replace(/\.js$/, ""); 180 | return { 181 | location: Require.directoryPathToLocation(packageDirectory), 182 | id: modulePath 183 | }; 184 | }, function (error) { 185 | throw new Error("Can't find package: " + path); 186 | }); 187 | }; 188 | --------------------------------------------------------------------------------