aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/require
diff options
context:
space:
mode:
authorJon Reid2012-06-20 15:05:26 -0700
committerJon Reid2012-06-20 15:05:26 -0700
commit6e6c146f6e59c3942076b5d2f46b2962cc709926 (patch)
treeaa6becc1e97aecbe6fb43aa33770def3c3de227d /node_modules/montage/require
parentf887a74a7d03a2008a2c43d455a2b3e9223028af (diff)
parentc9852665eadc1acb9c1c881d207c4bd9ef88805f (diff)
downloadninja-6e6c146f6e59c3942076b5d2f46b2962cc709926.tar.gz
Merge remote-tracking branch 'ninja-internal/master' into timeline-local
Diffstat (limited to 'node_modules/montage/require')
-rwxr-xr-xnode_modules/montage/require/browser.js4
-rwxr-xr-xnode_modules/montage/require/require.js67
-rw-r--r--node_modules/montage/require/worker-script.js233
-rw-r--r--node_modules/montage/require/worker.js62
4 files changed, 351 insertions, 15 deletions
diff --git a/node_modules/montage/require/browser.js b/node_modules/montage/require/browser.js
index a6a8af5a..1b4029ad 100755
--- a/node_modules/montage/require/browser.js
+++ b/node_modules/montage/require/browser.js
@@ -17,7 +17,7 @@ Require.getLocation = function() {
17 return URL.resolve(window.location, "."); 17 return URL.resolve(window.location, ".");
18}; 18};
19 19
20Require.overlays = ["browser", "montage"]; 20Require.overlays = ["window", "browser", "montage"];
21 21
22// Due to crazy variabile availability of new and old XHR APIs across 22// Due to crazy variabile availability of new and old XHR APIs across
23// platforms, this implementation registers every known name for the event 23// platforms, this implementation registers every known name for the event
@@ -116,8 +116,6 @@ Require.Compiler = function (config) {
116 // module.factory = new Function("require", "exports", "module", module.text + "\n//*/"+sourceURLComment); 116 // module.factory = new Function("require", "exports", "module", module.text + "\n//*/"+sourceURLComment);
117 117
118 module.factory.displayName = displayName; 118 module.factory.displayName = displayName;
119
120 return module;
121 } 119 }
122}; 120};
123 121
diff --git a/node_modules/montage/require/require.js b/node_modules/montage/require/require.js
index eaa2d9fc..36372053 100755
--- a/node_modules/montage/require/require.js
+++ b/node_modules/montage/require/require.js
@@ -8,12 +8,24 @@
8 8
9 // Boostrapping Browser 9 // Boostrapping Browser
10 if (typeof bootstrap !== "undefined") { 10 if (typeof bootstrap !== "undefined") {
11 bootstrap("require/require", function (require, exports) { 11
12 var Promise = require("core/promise").Promise; 12 // Window
13 var URL = require("core/mini-url"); 13 if (typeof window !== "undefined") {
14 definition(exports, Promise, URL); 14 bootstrap("require/require", function (require, exports) {
15 require("require/browser"); 15 var Promise = require("core/promise").Promise;
16 }); 16 var URL = require("core/mini-url");
17 definition(exports, Promise, URL);
18 require("require/browser");
19 });
20
21 // Worker
22 } else {
23 bootstrap("require/require", function (require, exports) {
24 var Promise = require("core/promise").Promise;
25 var URL = require("core/url");
26 definition(exports, Promise, URL);
27 });
28 }
17 29
18 // Node Server 30 // Node Server
19 } else if (typeof process !== "undefined") { 31 } else if (typeof process !== "undefined") {
@@ -183,8 +195,8 @@
183 // Modules should never have a return value. 195 // Modules should never have a return value.
184 if (returnValue !== void 0) { 196 if (returnValue !== void 0) {
185 console.warn( 197 console.warn(
186 'require: module ' + JSON.stringify(topId) + 198 "require: module " + JSON.stringify(topId) +
187 ' returned a value.' 199 " returned a value."
188 ); 200 );
189 } 201 }
190 202
@@ -258,6 +270,8 @@
258 return resolve(id, viaId); 270 return resolve(id, viaId);
259 }; 271 };
260 272
273 require.getModule = getModule;
274
261 require.load = load; 275 require.load = load;
262 require.deepLoad = deepLoad; 276 require.deepLoad = deepLoad;
263 277
@@ -269,10 +283,18 @@
269 } 283 }
270 }; 284 };
271 285
286 require.getPackage = function (dependency) {
287 return config.getPackage(dependency, config);
288 };
289
272 require.injectPackageDescription = function (location, description) { 290 require.injectPackageDescription = function (location, description) {
273 Require.injectPackageDescription(location, description, config); 291 Require.injectPackageDescription(location, description, config);
274 }; 292 };
275 293
294 require.injectPackageDescriptionLocation = function (location, descriptionLocation) {
295 Require.injectPackageDescriptionLocation(location, descriptionLocation, config);
296 };
297
276 require.identify = identify; 298 require.identify = identify;
277 require.inject = inject; 299 require.inject = inject;
278 require.progress = Require.progress; 300 require.progress = Require.progress;
@@ -283,6 +305,8 @@
283 305
284 require.config = config; 306 require.config = config;
285 307
308 require.read = Require.read;
309
286 return require; 310 return require;
287 } 311 }
288 312
@@ -297,17 +321,35 @@
297 }; 321 };
298 322
299 Require.injectPackageDescription = function (location, description, config) { 323 Require.injectPackageDescription = function (location, description, config) {
300 var descriptions = config.descriptions = config.descriptions || {}; 324 var descriptions =
325 config.descriptions =
326 config.descriptions || {};
301 descriptions[location] = Promise.call(function () { 327 descriptions[location] = Promise.call(function () {
302 return description; 328 return description;
303 }); 329 });
304 }; 330 };
305 331
332 Require.injectPackageDescriptionLocation = function (location, descriptionLocation, config) {
333 var descriptionLocations =
334 config.descriptionLocations =
335 config.descriptionLocations || {};
336 descriptionLocations[location] = descriptionLocation;
337 };
338
306 Require.loadPackageDescription = function (location, config) { 339 Require.loadPackageDescription = function (location, config) {
307 var descriptions = config.descriptions = config.descriptions || {}; 340 var descriptions =
341 config.descriptions =
342 config.descriptions || {};
308 if (descriptions[location] === void 0) { 343 if (descriptions[location] === void 0) {
309 var jsonPath = URL.resolve(location, 'package.json'); 344 var descriptionLocations =
310 descriptions[location] = Require.read(jsonPath) 345 config.descriptionLocations =
346 config.descriptionLocations || {};
347 if (descriptionLocations[location]) {
348 descriptionLocation = descriptionLocations[location];
349 } else {
350 descriptionLocation = URL.resolve(location, "package.json");
351 }
352 descriptions[location] = Require.read(descriptionLocation)
311 .then(function (json) { 353 .then(function (json) {
312 try { 354 try {
313 return JSON.parse(json); 355 return JSON.parse(json);
@@ -447,6 +489,7 @@
447 489
448 // overlay 490 // overlay
449 var overlay = description.overlay || {}; 491 var overlay = description.overlay || {};
492 var layer;
450 Require.overlays.forEach(function (engine) { 493 Require.overlays.forEach(function (engine) {
451 if (overlay[engine]) { 494 if (overlay[engine]) {
452 var layer = overlay[engine]; 495 var layer = overlay[engine];
diff --git a/node_modules/montage/require/worker-script.js b/node_modules/montage/require/worker-script.js
new file mode 100644
index 00000000..58a3da7f
--- /dev/null
+++ b/node_modules/montage/require/worker-script.js
@@ -0,0 +1,233 @@
1(function (global) {
2
3var postMessage = global.postMessage.bind(global);
4var addEventListener = global.addEventListener.bind(global);
5var removeEventListener = global.removeEventListener.bind(global);
6
7console = {
8 log: function () {
9 postMessage({
10 type: "console",
11 method: "log",
12 args: Array.prototype.map.call(arguments, function (value) {
13 if (typeof value === "string") {
14 return value;
15 } else {
16 return JSON.stringify(value);
17 }
18 })
19 });
20 },
21 error: function () {
22 postMessage({
23 type: "console",
24 method: "error",
25 args: Array.prototype.map.call(arguments, function (value) {
26 if (typeof value === "string") {
27 return value;
28 } else {
29 return JSON.stringify(value);
30 }
31 })
32 });
33 }
34};
35
36var factories = {};
37bootstrap = function (id, factory) {
38 factories[id] = factory;
39};
40
41importScripts(
42 "require.js",
43 "../core/promise.js",
44 "../core/next-tick.js",
45 "../core/url.js"
46);