From e82b87b0609e4948cfb7cb6a3b29b57c50b93e62 Mon Sep 17 00:00:00 2001 From: Brian Cavalier Date: Tue, 18 Jun 2013 11:11:37 -0400 Subject: [PATCH] Update to latest cujoJS releases: wire 0.10.0, curl 0.7.4, when 2.1.1 --- labs/architecture-examples/cujo/app/main.js | 11 +- labs/architecture-examples/cujo/app/run.js | 10 +- labs/architecture-examples/cujo/bower.json | 8 +- .../cujo/bower_components/cola/.gitignore | 4 - .../cujo/bower_components/cola/.gitmodules | 9 - .../cujo/bower_components/cola/bower.json | 9 - .../cujo/bower_components/curl/.gitmodules | 0 .../cujo/bower_components/curl/bower.json | 8 - .../cujo/bower_components/curl/package.json | 39 - .../cujo/bower_components/curl/src/curl.js | 184 ++-- .../bower_components/curl/src/curl/debug.js | 2 +- .../curl/src/curl/domReady.js | 2 +- .../curl/src/curl/loader/cjsm11.js | 93 +- .../curl/src/curl/plugin/_fetchText.js | 52 + .../curl/src/curl/plugin/async.js | 2 +- .../curl/src/curl/plugin/builder/css.js | 178 ---- .../curl/src/curl/plugin/builder/i18n.js | 14 - .../curl/src/curl/plugin/builder/text.js | 56 -- .../curl/src/curl/plugin/css.js | 5 +- .../curl/src/curl/plugin/domReady.js | 2 +- .../curl/src/curl/plugin/i18n.js | 16 +- .../curl/src/curl/plugin/js.js | 6 +- .../curl/src/curl/plugin/json.js | 68 ++ .../curl/src/curl/plugin/link.js | 2 +- .../curl/src/curl/plugin/style.js | 147 +++ .../curl/src/curl/plugin/text.js | 64 +- .../curl/src/curl/shim/dojo16.js | 2 +- .../curl/src/curl/shim/ssjs.js | 10 +- .../curl/src/curl/tdd/runner.js | 11 +- .../curl/src/curl/tdd/undefine.js | 2 +- .../cujo/bower_components/meld/.editorconfig | 5 - .../cujo/bower_components/meld/.gitignore | 4 - .../cujo/bower_components/meld/.jshintignore | 4 - .../cujo/bower_components/meld/.jshintrc | 29 - .../cujo/bower_components/meld/CHANGES.md | 81 -- .../cujo/bower_components/meld/README.md | 114 --- .../cujo/bower_components/meld/bower.json | 8 - .../cujo/bower_components/meld/package.json | 54 -- .../cujo/bower_components/poly/.gitignore | 1 - .../cujo/bower_components/poly/all.js | 4 +- .../cujo/bower_components/poly/array.js | 2 +- .../cujo/bower_components/poly/bower.json | 8 - .../cujo/bower_components/poly/date.js | 57 +- .../cujo/bower_components/poly/es5-strict.js | 32 + .../cujo/bower_components/poly/es5.js | 20 + .../cujo/bower_components/poly/function.js | 2 +- .../cujo/bower_components/poly/json.js | 6 +- .../cujo/bower_components/poly/lib/_async.js | 48 - .../cujo/bower_components/poly/lib/_base.js | 2 +- .../cujo/bower_components/poly/lib/_json.js | 54 -- .../cujo/bower_components/poly/object.js | 66 +- .../cujo/bower_components/poly/poly.js | 5 +- .../bower_components/poly/setImmediate.js | 220 +++++ .../cujo/bower_components/poly/strict.js | 5 +- .../cujo/bower_components/poly/string.js | 2 +- .../bower_components/poly/support/json2.js | 489 ---------- .../bower_components/poly/support/json3.js | 783 ++++++++++++++++ .../cujo/bower_components/poly/xhr.js | 43 +- .../bower_components/todomvc-common/base.js | 4 - .../cujo/bower_components/when/.editorconfig | 5 - .../cujo/bower_components/when/.gitignore | 5 - .../cujo/bower_components/when/.jshintignore | 4 - .../cujo/bower_components/when/.jshintrc | 30 - .../cujo/bower_components/when/.travis.yml | 12 - .../cujo/bower_components/when/CHANGES.md | 204 ---- .../cujo/bower_components/when/README.md | 118 --- .../cujo/bower_components/when/bower.json | 8 - .../cujo/bower_components/when/package.json | 57 -- .../cujo/bower_components/when/unfold/list.js | 2 +- .../cujo/bower_components/when/when.js | 4 +- .../cujo/bower_components/wire/.editorconfig | 6 - .../cujo/bower_components/wire/.gitignore | 15 - .../cujo/bower_components/wire/.gitmodules | 24 - .../cujo/bower_components/wire/.jshintrc | 73 -- .../cujo/bower_components/wire/README.md | 50 - .../cujo/bower_components/wire/aop.js | 177 ++-- .../cujo/bower_components/wire/base.js | 418 --------- .../cujo/bower_components/wire/bower.json | 8 - .../bower_components/wire/builder/cram.js | 238 +++++ .../cujo/bower_components/wire/connect.js | 84 +- .../bower_components/wire/cram/builder.js | 119 --- .../cujo/bower_components/wire/debug.js | 294 +++--- .../cujo/bower_components/wire/dojo/data.js | 33 +- .../cujo/bower_components/wire/dojo/dijit.js | 77 +- .../cujo/bower_components/wire/dojo/events.js | 16 +- .../cujo/bower_components/wire/dojo/on.js | 2 +- .../cujo/bower_components/wire/dojo/pubsub.js | 20 +- .../cujo/bower_components/wire/dojo/store.js | 8 +- .../cujo/bower_components/wire/dom.js | 2 +- .../cujo/bower_components/wire/dom/render.js | 33 +- .../cujo/bower_components/wire/domReady.js | 7 +- .../cujo/bower_components/wire/jquery/on.js | 6 +- .../cujo/bower_components/wire/jquery/ui.js | 221 +++++ .../wire/lib/ComponentFactory.js | 166 ++++ .../bower_components/wire/lib/Container.js | 174 ++++ .../bower_components/wire/lib/WireContext.js | 34 + .../bower_components/wire/lib/WireProxy.js | 200 ++++ .../cujo/bower_components/wire/lib/advice.js | 82 ++ .../cujo/bower_components/wire/lib/array.js | 29 +- .../cujo/bower_components/wire/lib/async.js | 68 -- .../bower_components/wire/lib/connection.js | 17 +- .../cujo/bower_components/wire/lib/context.js | 887 +----------------- .../bower_components/wire/lib/dom/base.js | 125 +-- .../bower_components/wire/lib/functional.js | 86 +- .../wire/lib/graph/DirectedGraph.js | 95 ++ .../wire/lib/graph/formatCycles.js | 24 + .../bower_components/wire/lib/graph/tarjan.js | 112 +++ .../wire/lib/graph/trackInflightRefs.js | 91 ++ .../wire/lib/{component.js => instantiate.js} | 7 +- .../cujo/bower_components/wire/lib/invoker.js | 4 +- .../bower_components/wire/lib/lifecycle.js | 112 ++- .../cujo/bower_components/wire/lib/loader.js | 74 ++ .../bower_components/wire/lib/moduleLoader.js | 34 - .../cujo/bower_components/wire/lib/object.js | 29 +- .../wire/lib/plugin-base/dom.js | 128 +-- .../wire/lib/plugin-base/on.js | 230 ++--- .../wire/lib/plugin/basePlugin.js | 321 +++++++ .../wire/lib/plugin/defaultPlugins.js | 14 + .../wire/lib/plugin/priority.js | 40 + .../wire/lib/plugin/registry.js | 137 +++ .../wire/lib/plugin/wirePlugin.js | 123 +++ .../bower_components/wire/lib/resolver.js | 84 +- .../cujo/bower_components/wire/lib/scope.js | 433 +++++++++ .../cujo/bower_components/wire/on.js | 2 +- .../cujo/bower_components/wire/package.json | 56 -- .../cujo/bower_components/wire/wire.js | 59 +- labs/architecture-examples/cujo/index.html | 3 +- 127 files changed, 5151 insertions(+), 4477 deletions(-) delete mode 100644 labs/architecture-examples/cujo/bower_components/cola/.gitignore delete mode 100644 labs/architecture-examples/cujo/bower_components/cola/.gitmodules delete mode 100644 labs/architecture-examples/cujo/bower_components/cola/bower.json delete mode 100644 labs/architecture-examples/cujo/bower_components/curl/.gitmodules delete mode 100644 labs/architecture-examples/cujo/bower_components/curl/bower.json delete mode 100644 labs/architecture-examples/cujo/bower_components/curl/package.json create mode 100644 labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/_fetchText.js delete mode 100644 labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/builder/css.js delete mode 100644 labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/builder/i18n.js delete mode 100644 labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/builder/text.js create mode 100644 labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/json.js create mode 100644 labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/style.js delete mode 100644 labs/architecture-examples/cujo/bower_components/meld/.editorconfig delete mode 100644 labs/architecture-examples/cujo/bower_components/meld/.gitignore delete mode 100644 labs/architecture-examples/cujo/bower_components/meld/.jshintignore delete mode 100644 labs/architecture-examples/cujo/bower_components/meld/.jshintrc delete mode 100644 labs/architecture-examples/cujo/bower_components/meld/CHANGES.md delete mode 100644 labs/architecture-examples/cujo/bower_components/meld/README.md delete mode 100644 labs/architecture-examples/cujo/bower_components/meld/bower.json delete mode 100644 labs/architecture-examples/cujo/bower_components/meld/package.json delete mode 100644 labs/architecture-examples/cujo/bower_components/poly/.gitignore delete mode 100644 labs/architecture-examples/cujo/bower_components/poly/bower.json create mode 100644 labs/architecture-examples/cujo/bower_components/poly/es5-strict.js create mode 100644 labs/architecture-examples/cujo/bower_components/poly/es5.js delete mode 100644 labs/architecture-examples/cujo/bower_components/poly/lib/_async.js delete mode 100644 labs/architecture-examples/cujo/bower_components/poly/lib/_json.js create mode 100644 labs/architecture-examples/cujo/bower_components/poly/setImmediate.js delete mode 100644 labs/architecture-examples/cujo/bower_components/poly/support/json2.js create mode 100644 labs/architecture-examples/cujo/bower_components/poly/support/json3.js delete mode 100644 labs/architecture-examples/cujo/bower_components/when/.editorconfig delete mode 100644 labs/architecture-examples/cujo/bower_components/when/.gitignore delete mode 100644 labs/architecture-examples/cujo/bower_components/when/.jshintignore delete mode 100644 labs/architecture-examples/cujo/bower_components/when/.jshintrc delete mode 100644 labs/architecture-examples/cujo/bower_components/when/.travis.yml delete mode 100644 labs/architecture-examples/cujo/bower_components/when/CHANGES.md delete mode 100644 labs/architecture-examples/cujo/bower_components/when/README.md delete mode 100644 labs/architecture-examples/cujo/bower_components/when/bower.json delete mode 100644 labs/architecture-examples/cujo/bower_components/when/package.json delete mode 100644 labs/architecture-examples/cujo/bower_components/wire/.editorconfig delete mode 100644 labs/architecture-examples/cujo/bower_components/wire/.gitignore delete mode 100644 labs/architecture-examples/cujo/bower_components/wire/.gitmodules delete mode 100644 labs/architecture-examples/cujo/bower_components/wire/.jshintrc delete mode 100644 labs/architecture-examples/cujo/bower_components/wire/README.md delete mode 100644 labs/architecture-examples/cujo/bower_components/wire/base.js delete mode 100644 labs/architecture-examples/cujo/bower_components/wire/bower.json create mode 100644 labs/architecture-examples/cujo/bower_components/wire/builder/cram.js delete mode 100644 labs/architecture-examples/cujo/bower_components/wire/cram/builder.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/jquery/ui.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/ComponentFactory.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/Container.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/WireContext.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/WireProxy.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/advice.js delete mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/async.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/graph/DirectedGraph.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/graph/formatCycles.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/graph/tarjan.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/graph/trackInflightRefs.js rename labs/architecture-examples/cujo/bower_components/wire/lib/{component.js => instantiate.js} (93%) create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/loader.js delete mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/moduleLoader.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/plugin/basePlugin.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/plugin/defaultPlugins.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/plugin/priority.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/plugin/registry.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/plugin/wirePlugin.js create mode 100644 labs/architecture-examples/cujo/bower_components/wire/lib/scope.js delete mode 100644 labs/architecture-examples/cujo/bower_components/wire/package.json diff --git a/labs/architecture-examples/cujo/app/main.js b/labs/architecture-examples/cujo/app/main.js index c256ee2b39..9c0cf95d35 100644 --- a/labs/architecture-examples/cujo/app/main.js +++ b/labs/architecture-examples/cujo/app/main.js @@ -174,13 +174,8 @@ define({ } }, - plugins: [ - // { module: 'wire/debug', trace: true }, - { module: 'wire/dom' }, - { module: 'wire/dom/render' }, - { module: 'wire/on' }, - { module: 'wire/aop' }, - { module: 'wire/connect' }, - { module: 'cola' } + plugins: [ //'wire/debug', + 'wire/dom', 'wire/dom/render', 'wire/on', + 'wire/aop', 'wire/connect', 'cola' ] }); diff --git a/labs/architecture-examples/cujo/app/run.js b/labs/architecture-examples/cujo/app/run.js index 2317cddfd1..75f1dd42a8 100644 --- a/labs/architecture-examples/cujo/app/run.js +++ b/labs/architecture-examples/cujo/app/run.js @@ -1,5 +1,6 @@ -/*global curl */ -(function (curl) { +// Bootstrap the app. Notice that curl is not a global, only define. +/*global define*/ +define(['curl'], function (curl) { 'use strict'; curl({ @@ -12,10 +13,9 @@ { name: 'cola', location: 'bower_components/cola', main: 'cola' }, { name: 'poly', location: 'bower_components/poly', main: 'poly' } ], - preloads: ['poly/string', 'poly/array'], + preloads: ['poly/es5'], // Turn off i18n locale sniffing. Change or remove this line if you want to // test specific locales or try automatic locale-sniffing. locale: false }); - -})(curl); +}); diff --git a/labs/architecture-examples/cujo/bower.json b/labs/architecture-examples/cujo/bower.json index 8e79668d6f..707c3ce6c3 100644 --- a/labs/architecture-examples/cujo/bower.json +++ b/labs/architecture-examples/cujo/bower.json @@ -2,12 +2,12 @@ "name": "todomvc-cujoJS", "version": "0.0.0", "dependencies": { - "todomvc-common": "~0.1.4", - "curl": "~0.7.3", + "todomvc-common": "~0.1.7", + "curl": "~0.7.4", "cola": "latest", "poly": "~0.5.1", - "when": "~2.1.0", - "wire": "~0.9.4", + "when": "~2.1.1", + "wire": "~0.10.0", "meld": "~1.3.0" } } diff --git a/labs/architecture-examples/cujo/bower_components/cola/.gitignore b/labs/architecture-examples/cujo/bower_components/cola/.gitignore deleted file mode 100644 index 3a8b5bf354..0000000000 --- a/labs/architecture-examples/cujo/bower_components/cola/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.idea/ -node_modules -/test/curl -test/util diff --git a/labs/architecture-examples/cujo/bower_components/cola/.gitmodules b/labs/architecture-examples/cujo/bower_components/cola/.gitmodules deleted file mode 100644 index 827cdfeec7..0000000000 --- a/labs/architecture-examples/cujo/bower_components/cola/.gitmodules +++ /dev/null @@ -1,9 +0,0 @@ -[submodule "test/curl"] - path = test/curl - url = https://unscriptable@github.com/cujojs/curl.git -[submodule "test/util"] - path = test/util - url = https://unscriptable@github.com/cujojs/util.git -[submodule "support/when"] - path = support/when - url = https://github.com/cujojs/when.git diff --git a/labs/architecture-examples/cujo/bower_components/cola/bower.json b/labs/architecture-examples/cujo/bower_components/cola/bower.json deleted file mode 100644 index 4454dcadcd..0000000000 --- a/labs/architecture-examples/cujo/bower_components/cola/bower.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "cola", - "version": "0.0.0", - "commit": "27b8c7e8fe88feef62a746d29d30af945dcb244d", - "repository": { - "type": "git", - "url": "git://github.com/cujojs/cola" - } -} \ No newline at end of file diff --git a/labs/architecture-examples/cujo/bower_components/curl/.gitmodules b/labs/architecture-examples/cujo/bower_components/curl/.gitmodules deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/labs/architecture-examples/cujo/bower_components/curl/bower.json b/labs/architecture-examples/cujo/bower_components/curl/bower.json deleted file mode 100644 index 0a8f45c43d..0000000000 --- a/labs/architecture-examples/cujo/bower_components/curl/bower.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "curl", - "version": "0.7.3", - "repository": { - "type": "git", - "url": "git://github.com/cujojs/curl" - } -} \ No newline at end of file diff --git a/labs/architecture-examples/cujo/bower_components/curl/package.json b/labs/architecture-examples/cujo/bower_components/curl/package.json deleted file mode 100644 index 3498e8fc2a..0000000000 --- a/labs/architecture-examples/cujo/bower_components/curl/package.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "name": "curl", - "version": "0.7.3", - "description": "A small, fast module and resource loader with dependency management. (AMD, CommonJS Modules/1.1, CSS, HTML, etc.)", - "keywords": ["curl", "cujo", "amd", "loader", "module"], - "licenses": [ - { - "type": "MIT", - "url": "http://www.opensource.org/licenses/mit-license.php" - } - ], - "repositories": [ - { - "type": "git", - "url": "https://github.com/cujojs/curl" - } - ], - "bugs": "https://github.com/cujojs/curl/issues", - "maintainers": [ - { - "name": "John Hann", - "web": "http://unscriptable.com" - } - ], - "contributors": [ - { - "name": "John Hann", - "web": "http://unscriptable.com" - }, - { - "name": "Brian Cavalier", - "web": "http://hovercraftstudios.com" - } - ], - "main": "./src/curl", - "directories": { - "test": "test" - } -} diff --git a/labs/architecture-examples/cujo/bower_components/curl/src/curl.js b/labs/architecture-examples/cujo/bower_components/curl/src/curl.js index d19ced37e2..a9d882dcd6 100644 --- a/labs/architecture-examples/cujo/bower_components/curl/src/curl.js +++ b/labs/architecture-examples/cujo/bower_components/curl/src/curl.js @@ -1,4 +1,4 @@ -/** @license MIT License (c) copyright B Cavalier & J Hann */ +/** @license MIT License (c) copyright 2010-2013 B Cavalier & J Hann */ /** * curl (cujo resource loader) @@ -13,9 +13,10 @@ (function (global) { //"use strict"; don't restore this until the config routine is refactored var - version = '0.7.3', + version = '0.7.4', curlName = 'curl', defineName = 'define', + runModuleAttr = 'data-curl-run', userCfg, prevCurl, prevDefine, @@ -49,8 +50,9 @@ dontAddExtRx = /\?|\.js\b/, absUrlRx = /^\/|^[^:]+:\/\//, findDotsRx = /(\.)(\.?)(?:$|\/([^\.\/]+.*)?)/g, - removeCommentsRx = /\/\*[\s\S]*?\*\/|(?:[^\\])\/\/.*?[\n\r]/g, - findRValueRequiresRx = /require\s*\(\s*["']([^"']+)["']\s*\)|(?:[^\\]?)(["'])/g, + removeCommentsRx = /\/\*[\s\S]*?\*\/|\/\/.*?[\n\r]/g, + findRValueRequiresRx = /require\s*\(\s*(["'])(.*?[^\\])\1\s*\)|[^\\]?(["'])/g, + splitMainDirectives = /\s*,\s*/, cjsGetters, core; @@ -202,7 +204,7 @@ } function isPromise (o) { - return o instanceof Promise; + return o instanceof Promise || o instanceof CurlApi; } function when (promiseOrValue, callback, errback, progback) { @@ -637,18 +639,6 @@ }, - checkPreloads: function (cfg) { - var preloads; - preloads = cfg && cfg['preloads']; - if (preloads && preloads.length > 0) { - // chain from previous preload, if any. - when(preload, function () { - preload = core.getDeps(core.createContext(userCfg, undef, preloads, true)); - }); - } - - }, - resolvePathInfo: function (absId, cfg) { // searches through the configured path mappings and packages var pathMap, pathInfo, path, pkgCfg; @@ -744,8 +734,8 @@ defFunc : defFunc.toSource ? defFunc.toSource() : defFunc.toString(); // remove comments, then look for require() or quotes - source.replace(removeCommentsRx, '').replace(findRValueRequiresRx, function (m, id, qq) { - // if we encounter a quote + source.replace(removeCommentsRx, '').replace(findRValueRequiresRx, function (m, rq, id, qq) { + // if we encounter a string in the source, don't look for require() if (qq) { currQuote = currQuote == qq ? undef : currQuote; } @@ -971,35 +961,44 @@ }, fetchDep: function (depName, parentDef) { - var toAbsId, isPreload, cfg, parts, mainId, loaderId, pluginId, + var toAbsId, isPreload, cfg, parts, absId, mainId, loaderId, pluginId, resId, pathInfo, def, tempDef, resCfg; toAbsId = parentDef.toAbsId; isPreload = parentDef.isPreload; cfg = parentDef.config || userCfg; // is this fallback necessary? - // check for plugin loaderId - // TODO: this runs pluginParts() twice. how to run it just once? - parts = pluginParts(toAbsId(depName)); - resId = parts.resourceId; - // get id of first resource to load (which could be a plugin) - mainId = parts.pluginId || resId; - pathInfo = core.resolvePathInfo(mainId, cfg); + absId = toAbsId(depName); - // get custom module loader from package config if not a plugin - if (parts.pluginId) { - loaderId = mainId; + if (absId in cache) { + // module already exists in cache + mainId = absId; } else { - // TODO: move config.moduleLoader to config.transform - loaderId = pathInfo.config['moduleLoader'] || pathInfo.config.moduleLoader; - if (loaderId) { - // TODO: allow transforms to have relative module ids? - // (we could do this by returning package location from - // resolvePathInfo. why not return all package info?) - resId = mainId; - mainId = loaderId; - pathInfo = core.resolvePathInfo(loaderId, cfg); + // check for plugin loaderId + parts = pluginParts(absId); + resId = parts.resourceId; + // get id of first resource to load (which could be a plugin) + mainId = parts.pluginId || resId; + pathInfo = core.resolvePathInfo(mainId, cfg); + } + + // get custom module loader from package config if not a plugin + if (parts) { + if (parts.pluginId) { + loaderId = mainId; + } + else { + // TODO: move config.moduleLoader to config.transform + loaderId = pathInfo.config['moduleLoader'] || pathInfo.config.moduleLoader; + if (loaderId) { + // TODO: allow transforms to have relative module ids? + // (we could do this by returning package location from + // resolvePathInfo. why not return all package info?) + resId = mainId; + mainId = loaderId; + pathInfo = core.resolvePathInfo(loaderId, cfg); + } } } @@ -1070,8 +1069,8 @@ // but to be compatible with AMD spec, we have to // piggy-back on the callback function parameter: var loaded = function (res) { - normalizedDef.resolve(res); if (!dynamic) cache[fullId] = res; + normalizedDef.resolve(res); }; loaded['resolve'] = loaded; loaded['reject'] = loaded['error'] = normalizedDef.reject; @@ -1110,6 +1109,34 @@ } } return def; + }, + + findScript: function (predicate) { + var i = 0, script; + while (doc && (script = doc.scripts[i++])) { + if (predicate(script)) return script; + } + }, + + extractDataAttrConfig: function (cfg) { + var script; + script = core.findScript(function (script) { + var main; + // find main module(s) in data-curl-run attr on script element + // TODO: extract baseUrl, too? + main = script.getAttribute(runModuleAttr); + if (main) cfg.main = main; + return main; + }); + // removeAttribute is wonky (in IE6?) but this works + if (script) { + script.setAttribute(runModuleAttr, ''); + } + return cfg; + }, + + nextTurn: function (task) { + setTimeout(task, 0); } }; @@ -1118,42 +1145,57 @@ cjsGetters = {'require': core.getCjsRequire, 'exports': core.getCjsExports, 'module': core.getCjsModule}; function _curl (/* various */) { + var args, promise, cfg; - var args = [].slice.call(arguments), cfg; + args = [].slice.call(arguments); // extract config, if it's specified if (isType(args[0], 'Object')) { cfg = args.shift(); - _config(cfg); + promise = _config(cfg); } - return new CurlApi(args[0], args[1], args[2]); - + return new CurlApi(args[0], args[1], args[2], promise); } - function _config (cfg) { + function _config (cfg, callback, errback) { + var pPromise, mPromise, main, devmain, fallback; + if (cfg) { core.setApi(cfg); userCfg = core.config(cfg); // check for preloads - core.checkPreloads(cfg); - // check for main module(s) - if ('main' in cfg) { - // start in next turn to wait for other modules in current file - setTimeout(function () { - var ctx; - ctx = core.createContext(userCfg, undef, [].concat(cfg['main'])); - core.getDeps(ctx); - }, 0); + if ('preloads' in cfg) { + pPromise = new CurlApi(cfg['preloads'], undef, errback, preload, true); + // yes, this is hacky and embarrassing. now that we've got that + // settled... until curl has deferred factory execution, this + // is the only way to stop preloads from dead-locking when + // they have dependencies inside a bundle. + core.nextTurn(function () { preload = pPromise; }); + } + // check for main module(s). all modules wait for preloads implicitly. + main = cfg['main']; + main = main && String(main).split(splitMainDirectives); + if (main) { + mPromise = new Promise(); + mPromise.then(callback, errback); + // figure out if we are using a dev-time fallback + fallback = main[1] + ? function () { new CurlApi(main[1], mPromise.resolve, mPromise.reject); } + : mPromise.reject; + new CurlApi(main[0], mPromise.resolve, fallback); + return mPromise; } } } // thanks to Joop Ringelberg for helping troubleshoot the API - function CurlApi (ids, callback, errback, waitFor) { + function CurlApi (ids, callback, errback, waitFor, isPreload) { var then, ctx; - ctx = core.createContext(userCfg, undef, [].concat(ids)); - this['then'] = then = function (resolved, rejected) { + + ctx = core.createContext(userCfg, undef, [].concat(ids), isPreload); + + this['then'] = this.then = then = function (resolved, rejected) { when(ctx, // return the dependencies as arguments, not an array function (deps) { @@ -1166,13 +1208,22 @@ ); return this; }; + this['next'] = function (ids, cb, eb) { // chain api return new CurlApi(ids, cb, eb, ctx); }; + this['config'] = _config; + if (callback || errback) then(callback, errback); - when(waitFor, function () { core.getDeps(ctx); }); + + // ensure next-turn so inline code can execute first + core.nextTurn(function () { + when(isPreload || preload, function () { + when(waitFor, function () { core.getDeps(ctx); }, errback); + }); + }); } _curl['version'] = version; @@ -1232,18 +1283,23 @@ pathRx: /$^/ }; + // look for "data-curl-run" directive, and override config + userCfg = core.extractDataAttrConfig(userCfg); + // handle pre-existing global prevCurl = global[curlName]; prevDefine = global[defineName]; - if (!prevCurl || isType(prevCurl, 'Function')) { - // set default api - core.setApi(); - } - else { + + // only run config if there is something to config (perf saver?) + if (prevCurl && isType(prevCurl, 'Object') || userCfg.main) { // remove global curl object global[curlName] = undef; // can't use delete in IE 6-8 // configure curl - _config(prevCurl); + _config(prevCurl || userCfg); + } + else { + // set default api + core.setApi(); } // allow curl to be a dependency diff --git a/labs/architecture-examples/cujo/bower_components/curl/src/curl/debug.js b/labs/architecture-examples/cujo/bower_components/curl/src/curl/debug.js index 2279359999..6dbcdb52e7 100644 --- a/labs/architecture-examples/cujo/bower_components/curl/src/curl/debug.js +++ b/labs/architecture-examples/cujo/bower_components/curl/src/curl/debug.js @@ -1,4 +1,4 @@ -/** MIT License (c) copyright B Cavalier & J Hann */ +/** MIT License (c) copyright 2010-2013 B Cavalier & J Hann */ /** * curl debug plugin diff --git a/labs/architecture-examples/cujo/bower_components/curl/src/curl/domReady.js b/labs/architecture-examples/cujo/bower_components/curl/src/curl/domReady.js index 6790de69ad..71630c6dc5 100644 --- a/labs/architecture-examples/cujo/bower_components/curl/src/curl/domReady.js +++ b/labs/architecture-examples/cujo/bower_components/curl/src/curl/domReady.js @@ -1,4 +1,4 @@ -/** MIT License (c) copyright B Cavalier & J Hann */ +/** MIT License (c) copyright 2010-2013 B Cavalier & J Hann */ /** * curl domReady diff --git a/labs/architecture-examples/cujo/bower_components/curl/src/curl/loader/cjsm11.js b/labs/architecture-examples/cujo/bower_components/curl/src/curl/loader/cjsm11.js index 6177cfa68d..025d842f9a 100644 --- a/labs/architecture-examples/cujo/bower_components/curl/src/curl/loader/cjsm11.js +++ b/labs/architecture-examples/cujo/bower_components/curl/src/curl/loader/cjsm11.js @@ -1,4 +1,4 @@ -/** MIT License (c) copyright B Cavalier & J Hann */ +/** MIT License (c) copyright 2010-2013 B Cavalier & J Hann */ /** * curl CommonJS Modules/1.1 loader @@ -16,52 +16,13 @@ define(/*=='curl/loader/cjsm11',==*/ function () { var head, insertBeforeEl /*, findRequiresRx, myId*/; -// findRequiresRx = /require\s*\(\s*['"](\w+)['"]\s*\)/, - -// function nextId (index) { -// var varname = '', part; -// do { -// part = index % 26; -// varname += String.fromCharCode(part + 65); -// index -= part; -// } -// while (index > 0); -// return 'curl$' + varname; -// } - -// /** -// * @description Finds the require() instances in the source text of a cjs -// * module and collects them. If removeRequires is true, it also replaces -// * them with a unique variable name. All unique require()'d module ids -// * are assigned a unique variable name to be used in the define(deps) -// * that will be constructed to wrap the cjs module. -// * @param source - source code of cjs module -// * @param moduleIds - hashMap (object) to receive pairs of moduleId / -// * unique variable name -// * @param removeRequires - if truthy, replaces all require() instances with -// * a unique variable -// * @return - source code of cjs module, possibly with require()s replaced -// */ -// function parseDepModuleIds (source, moduleIds, removeRequires) { -// var index = 0; -// // fast parse -// source = source.replace(findRequiresRx, function (match, id) { -// if (!moduleIds[id]) { -// moduleIds[id] = nextId(index++); -// moduleIds.push(id); -// } -// return removeRequires ? moduleIds[id] : match; -// }); -// return source; -// } - head = document && (document['head'] || document.getElementsByTagName('head')[0]); // to keep IE from crying, we need to put scripts before any // elements, but after any . this should do it: insertBeforeEl = head && head.getElementsByTagName('base')[0] || null; function wrapSource (source, resourceId, fullUrl) { - var sourceUrl = fullUrl ? '////@ sourceURL=' + fullUrl.replace(/\s/g, '%20') + '.js' : ''; + var sourceUrl = fullUrl ? '/*\n////@ sourceURL=' + fullUrl.replace(/\s/g, '%20') + '.js\n*/' : ''; return "define('" + resourceId + "'," + "['require','exports','module'],function(require,exports,module){" + source + "\n});\n" + sourceUrl + "\n"; @@ -82,39 +43,41 @@ define(/*=='curl/loader/cjsm11',==*/ function () { head.insertBefore(el, insertBeforeEl); } - return { - 'load': function (resourceId, require, callback, config) { - // TODO: extract xhr from text! plugin and use that instead (after we upgrade to cram.js) - require(['text!' + resourceId + '.js', 'curl/_privileged'], function (source, priv) { - var moduleMap; + wrapSource['load'] = function (resourceId, require, callback, config) { + // TODO: extract xhr from text! plugin and use that instead (after we upgrade to cram.js) + require(['text!' + resourceId + '.js', 'curl/_privileged'], function (source, priv) { + var moduleMap; - // find (and replace?) dependencies - moduleMap = priv['core'].extractCjsDeps(source); - //source = parseDepModuleIds(source, moduleMap, config.replaceRequires); + // find (and replace?) dependencies + moduleMap = priv['core'].extractCjsDeps(source); + //source = parseDepModuleIds(source, moduleMap, config.replaceRequires); - // get deps - require(moduleMap, function () { + // get deps + require(moduleMap, function () { - // wrap source in a define - source = wrapSource(source, resourceId, config['injectSourceUrl'] !== false && require.toUrl(resourceId)); + // wrap source in a define + source = wrapSource(source, resourceId, config['injectSourceUrl'] !== false && require.toUrl(resourceId)); - if (config['injectScript']) { - injectScript(source); - } - else { - //eval(source); - globalEval(source); - } + if (config['injectScript']) { + injectScript(source); + } + else { + //eval(source); + globalEval(source); + } - // call callback now that the module is defined - callback(require(resourceId)); + // call callback now that the module is defined + callback(require(resourceId)); - }, callback['error'] || function (ex) { throw ex; }); + }, callback['error'] || function (ex) { throw ex; }); - }); - } + }); }; + wrapSource['cramPlugin'] = '../cram/cjsm11'; + + return wrapSource; + }); }(this, this.document, function () { /* FB needs direct eval here */ eval(arguments[0]); })); diff --git a/labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/_fetchText.js b/labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/_fetchText.js new file mode 100644 index 0000000000..c757800691 --- /dev/null +++ b/labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/_fetchText.js @@ -0,0 +1,52 @@ +define([], function () { + + var xhr, progIds; + + progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0']; + + xhr = function () { + if (typeof XMLHttpRequest !== "undefined") { + // rewrite the getXhr method to always return the native implementation + xhr = function () { + return new XMLHttpRequest(); + }; + } + else { + // keep trying progIds until we find the correct one, then rewrite the getXhr method + // to always return that one. + var noXhr = xhr = function () { + throw new Error("getXhr(): XMLHttpRequest not available"); + }; + while (progIds.length > 0 && xhr === noXhr) (function (id) { + try { + new ActiveXObject(id); + xhr = function () { + return new ActiveXObject(id); + }; + } + catch (ex) { + } + }(progIds.shift())); + } + return xhr(); + }; + + function fetchText (url, callback, errback) { + var x = xhr(); + x.open('GET', url, true); + x.onreadystatechange = function (e) { + if (x.readyState === 4) { + if (x.status < 400) { + callback(x.responseText); + } + else { + errback(new Error('fetchText() failed. status: ' + x.statusText)); + } + } + }; + x.send(null); + } + + return fetchText; + +}); diff --git a/labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/async.js b/labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/async.js index a6db064d7f..f14f56cefe 100644 --- a/labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/async.js +++ b/labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/async.js @@ -1,4 +1,4 @@ -/** MIT License (c) copyright B Cavalier & J Hann */ +/** MIT License (c) copyright 2010-2013 B Cavalier & J Hann */ /** * curl async! plugin diff --git a/labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/builder/css.js b/labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/builder/css.js deleted file mode 100644 index 5b8e2a4767..0000000000 --- a/labs/architecture-examples/cujo/bower_components/curl/src/curl/plugin/builder/css.js +++ /dev/null @@ -1,178 +0,0 @@ -/** MIT License (c) copyright B Cavalier & J Hann */ - -/** - * curl css! plugin build-time module - * - * Licensed under the MIT License at: - * http://www.opensource.org/licenses/mit-license.php - */ -define(function () { -"use strict"; - - // collection of modules that have been written to the built file - var built = {}; - - function nameWithExt (name, defaultExt) { - return name.lastIndexOf('.') <= name.lastIndexOf('/') ? - name + '.' + defaultExt : name; - } - - function jsEncode (text) { - // TODO: hoist the map and regex to the enclosing scope for better performance - var map = { 34: '\\"', 13: '\\r', 12: '\\f', 10: '\\n', 9: '\\t', 8: '\\b' }; - return text.replace(/(["\n\f\t\r\b])/g, function (c) { - return map[c.charCodeAt(0)]; - }); - } - - function parseSuffixes (name) { - // creates a dual-structure: both an array and a hashmap - // suffixes[0] is the actual name - var parts = name.split('!'), - suf, i = 1, pair; - while ((suf = parts[i++])) { // double-parens to avoid jslint griping - pair = suf.split('=', 2); - parts[pair[0]] = pair.length == 2 ? pair[1] : true; - } - return parts; - } - - var - // this actually tests for absolute urls and root-relative urls - // they're both non-relative - nonRelUrlRe = /^\/|^[^:]*:\/\//, - // Note: this will fail if there are parentheses in the url - findUrlRx = /url\s*\(['"]?([^'"\)]*)['"]?\)/g; - - function translateUrls (cssText, baseUrl) { - return cssText.replace(findUrlRx, function (all, url) { - return 'url("' + translateUrl(url, baseUrl) + '")'; - }); - } - - function translateUrl (url, parentPath) { - // if this is a relative url - if (!nonRelUrlRe.test(url)) { - // append path onto it - url = parentPath + url; - } - return url; - } - - function createSheetProxy (sheet) { - return { - cssRules: function () { - return sheet.cssRules || sheet.rules; - }, - insertRule: sheet.insertRule || function (text, index) { - var parts = text.split(/\{|\}/g); - sheet.addRule(parts[0], parts[1], index); - return index; - }, - deleteRule: sheet.deleteRule || function (index) { - sheet.removeRule(index); - return index; - }, - sheet: function () { - return sheet; - } - }; - } - - /***** style element functions *****/ - - var currentStyle; - - function createStyle (cssText) { - clearTimeout(createStyle.debouncer); - if (createStyle.accum) { - createStyle.accum.push(cssText); - } - else { - createStyle.accum = [cssText]; - currentStyle = doc.createStyleSheet ? doc.createStyleSheet() : - head.appendChild(doc.createElement('style')); - } - - createStyle.debouncer = setTimeout(function () { - // Note: IE 6-8 won't accept the W3C method for inserting css text - var style, allCssText; - - style = currentStyle; - currentStyle = undef; - - allCssText = createStyle.accum.join('\n'); - createStyle.accum = undef; - - // for safari which chokes on @charset "UTF-8"; - allCssText = allCssText.replace(/.+charset[^;]+;/g, ''); - - // TODO: hoist all @imports to the top of the file to follow w3c spec - - 'cssText' in style ? style.cssText = allCssText : - style.appendChild(doc.createTextNode(allCssText)); - - }, 0); - - return currentStyle; - } - -/* - // return the run-time API - callback({ - 'translateUrls': function (cssText, baseId) { - var baseUrl; - baseUrl = require['toUrl'](baseId); - baseUrl = baseUrl.substr(0, baseUrl.lastIndexOf('/') + 1); - return translateUrls(cssText, baseUrl); - }, - 'injectStyle': function (cssText) { - return createStyle(cssText); - }, - - 'proxySheet': function (sheet) { - // for W3C, `sheet` is a reference to a