diff --git a/node_modules/amd-loader/.gitignore b/node_modules/amd-loader/.gitignore new file mode 100644 index 00000000..69d39625 --- /dev/null +++ b/node_modules/amd-loader/.gitignore @@ -0,0 +1,3 @@ +.c9revisions/ +amd-loader-*.tgz +package/ diff --git a/node_modules/amd-loader/.npmignore b/node_modules/amd-loader/.npmignore new file mode 100644 index 00000000..a8a239c1 --- /dev/null +++ b/node_modules/amd-loader/.npmignore @@ -0,0 +1,4 @@ +.git/ +.c9revisions/ +package/ +amd-loader-*.tgz diff --git a/node_modules/amd-loader/.travis.yml b/node_modules/amd-loader/.travis.yml new file mode 100644 index 00000000..1cf67b79 --- /dev/null +++ b/node_modules/amd-loader/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - 0.4 + - 0.5 + - 0.6 + - 0.10 \ No newline at end of file diff --git a/node_modules/amd-loader/LICENSE b/node_modules/amd-loader/LICENSE new file mode 100644 index 00000000..8b70a601 --- /dev/null +++ b/node_modules/amd-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2010 ajax.org B.V (Fabian Jakobs) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/node_modules/amd-loader/README.md b/node_modules/amd-loader/README.md new file mode 100644 index 00000000..82d7c060 --- /dev/null +++ b/node_modules/amd-loader/README.md @@ -0,0 +1,73 @@ +AMD loader for node.js +====================== + +node-amd-loader adds the capability to load unmodified AMD (Asynchronous Module DefinitionAsynchronous Module Definition) from node.js applications. + +Installation +------------ + +`node-amd-loader` can be easily installed using [npm](http://npmjs.org). + + npm install amd-loader + +Before being able to load AMD modules the `amd-loader` module has to be required. + + require("amd-loader"); + +This needs to be done only once. + +Features +-------- + +### load modules which use AMD define() ### + +Load modules which are written using AMD [define](http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition#define.28.29_function) from node.js node. + +amd.js + +```javascript + define(function(require, exports, module) { + exports.B = "B"; + }); +``` + +main.js + +``` + require("amd-loader"); + var amd = require("./amd"); +``` + +### support requireJS asyncronous loading syntax ### + +From within an AMD modules the async require syntax introduced by [requireJS](http://requirejs.org) can be used. + +```javascript + require(["fs"], function(fs) { + fs.readFile(...); + }) +``` + +### support requireJS text plugin ### + +From within an AMD module the requireJS text plugin is supported. + +```javascript + var readme = require("text!./readme.md"); +``` + +Continuous Integration status +----------------------------- + +This project is tested with [Travis CI](http://travis-ci.org) +[![Build Status](https://secure.travis-ci.org/ajaxorg/node-amd-loader.png)](http://travis-ci.org/ajaxorg/node-amd-loader) + +Credits +------- + +[Kris Zip](https://github.com/kriszyp) came up the the initial [idea](https://gist.github.com/650000) how to hijack the node module loading. + +License +------- + +MIT license. See the LICENSE file for details. \ No newline at end of file diff --git a/node_modules/amd-loader/amd-loader.js b/node_modules/amd-loader/amd-loader.js new file mode 100644 index 00000000..6addeeb8 --- /dev/null +++ b/node_modules/amd-loader/amd-loader.js @@ -0,0 +1,85 @@ +var fs = require("fs"); +var Module = require("module"); + +var moduleStack = []; +var defaultCompile = module.constructor.prototype._compile; + +module.constructor.prototype._compile = function(content, filename){ + moduleStack.push(this); + try { + return defaultCompile.call(this, content, filename); + } + finally { + moduleStack.pop(); + } +}; + +global.define = function (id, injects, factory) { + var DEFAULT_INJECTS = ["require", "exports", "module"]; + + // infer the module + var currentModule = moduleStack[moduleStack.length-1]; + var mod = currentModule || module.parent || require.main; + + // assign arguments + if (arguments.length === 1) { + factory = id; + injects = DEFAULT_INJECTS; + id = null; + } + else if (arguments.length === 2) { + factory = injects; + injects = id; + id = null; + } + + if (typeof id === "string" && id !== mod.id) { + throw new Error("Can not assign module to a different id than the current file"); + } + + var req = function(module, relativeId, callback) { + if (Array.isArray(relativeId)) { + // async require + return callback.apply(this, relativeId.map(req)) + } + + var chunks = relativeId.split("!"); + var prefix; + if (chunks.length >= 2) { + prefix = chunks[0]; + relativeId = chunks.slice(1).join("!"); + } + + var fileName = Module._resolveFilename(relativeId, module); + if (Array.isArray(fileName)) + fileName = fileName[0]; + + if (prefix && prefix.indexOf("text") !== -1) { + return fs.readFileSync(fileName, "utf8"); + } else + return require(fileName); + }.bind(this, mod); + + id = mod.id; + if (typeof factory !== "function") { + // we can just provide a plain object + return mod.exports = factory; + } + + var returned = factory.apply(mod.exports, injects.map(function (injection) { + switch (injection) { + // check for CommonJS injection variables + case "require": return req; + case "exports": return mod.exports; + case "module": return mod; + default: + // a module dependency + return req(injection); + } + })); + + if (returned) { + // since AMD encapsulates a function/callback, it can allow the factory to return the exports. + mod.exports = returned; + } +}; diff --git a/node_modules/amd-loader/package.json b/node_modules/amd-loader/package.json new file mode 100644 index 00000000..e70e29b5 --- /dev/null +++ b/node_modules/amd-loader/package.json @@ -0,0 +1,24 @@ +{ + "name" : "amd-loader", + "version" : "0.0.5", + "description" : "Add the capability to load AMD (Asynchronous Module Definition) modules to node.js", + "author": "ajax.org B.V. ", + "contributors": [ + { "name": "Fabian Jakobs", "email": "fabian@ajax.org" } + ], + "repository" : { + "type" : "git", + "url" : "http://github.com/ajaxorg/node-amd-loader.git" + }, + "main": "./amd-loader.js", + "scripts" : { + "test" : "node test/test.js && node test/test2.js" + }, + "engines" : { + "node" : ">= 0.4.11" + }, + "licenses" : [{ + "type" : "MIT", + "url" : "http://github.com/ajaxorg/node-amd-loader/raw/master/LICENSE" + }] +} \ No newline at end of file diff --git a/node_modules/amd-loader/test/node_modules/a.js b/node_modules/amd-loader/test/node_modules/a.js new file mode 100644 index 00000000..f199de8d --- /dev/null +++ b/node_modules/amd-loader/test/node_modules/a.js @@ -0,0 +1,8 @@ +define(function(require, exports, module) { + + exports.B = require("./b").B; + exports.D = require("d").D; + exports.A = "A"; + + exports.text = require("text!./c.txt"); +}); \ No newline at end of file diff --git a/node_modules/amd-loader/test/node_modules/b.js b/node_modules/amd-loader/test/node_modules/b.js new file mode 100644 index 00000000..e2a898ec --- /dev/null +++ b/node_modules/amd-loader/test/node_modules/b.js @@ -0,0 +1,3 @@ +define(function(require, exports, module) { + exports.B = "B"; +}); \ No newline at end of file diff --git a/node_modules/amd-loader/test/node_modules/c.txt b/node_modules/amd-loader/test/node_modules/c.txt new file mode 100644 index 00000000..95d09f2b --- /dev/null +++ b/node_modules/amd-loader/test/node_modules/c.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/node_modules/amd-loader/test/node_modules/d.js b/node_modules/amd-loader/test/node_modules/d.js new file mode 100644 index 00000000..5bc470eb --- /dev/null +++ b/node_modules/amd-loader/test/node_modules/d.js @@ -0,0 +1,3 @@ +define(function(require, exports, module) { + exports.D = "D"; +}); \ No newline at end of file diff --git a/node_modules/amd-loader/test/node_modules/e.js b/node_modules/amd-loader/test/node_modules/e.js new file mode 100644 index 00000000..2fb486ac --- /dev/null +++ b/node_modules/amd-loader/test/node_modules/e.js @@ -0,0 +1,6 @@ +require("../.."); + +define(function(require, exports, module) { + exports.A = require("./a").A; + exports.E = "E"; +}); \ No newline at end of file diff --git a/node_modules/amd-loader/test/test.js b/node_modules/amd-loader/test/test.js new file mode 100644 index 00000000..79d578bf --- /dev/null +++ b/node_modules/amd-loader/test/test.js @@ -0,0 +1,34 @@ +require(".."); +var assert = require("assert"); + +console.log("Running amd-loader tests"); +console.log("========================\n"); + +console.log("resolve relative id"); +var a = require("./node_modules/a"); +var b = require("./node_modules/b"); + +assert.equal(a.A, "A"); +assert.equal(a.B, "B"); +assert.equal(a.text, "hello world"); +assert.equal(a.D, "D"); + +assert.equal(b.B, "B"); + +console.log("resolve fully qualified id"); +var a = require("a"); +var b = require("b"); + +assert.equal(a.A, "A"); +assert.equal(a.B, "B"); +assert.equal(a.text, "hello world"); +assert.equal(b.B, "B"); + +console.log("resolve from node_modules"); +var d = require("d"); + +assert.equal(d.D, "D"); + +// TODO +// node_modules + package +// async require diff --git a/node_modules/amd-loader/test/test2.js b/node_modules/amd-loader/test/test2.js new file mode 100644 index 00000000..92674deb --- /dev/null +++ b/node_modules/amd-loader/test/test2.js @@ -0,0 +1,4 @@ +// this tests the case where the AMD-loader is not loaded in the main module and +// the module using amd-loader uses define itself +console.log("require file with amd-loader and define") +require("e"); \ No newline at end of file diff --git a/server.js b/server.js index 73aa6ceb..9cf17cb1 100755 --- a/server.js +++ b/server.js @@ -4,7 +4,7 @@ require("amd-loader"); try { require("heapdump"); -} catch (e) {} +} catch(e) {} var path = require("path"); var architect = require("architect");