From 2e04af953463643791f6362bd8ef4c6ba190abfa Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 18 Apr 2012 13:48:51 -0700 Subject: Squashed commit of the following: commit 2054551bfb01a0f4ca2e138b9d724835462d45cd Merge: 765c2da 616a853 Author: Valerio Virgillito Date: Wed Apr 18 13:48:21 2012 -0700 Merge branch 'refs/heads/master' into integration commit 765c2da8e1aa03550caf42b2bd5f367555ad2843 Author: Valerio Virgillito Date: Tue Apr 17 15:29:41 2012 -0700 updating the picasa carousel Signed-off-by: Valerio Virgillito commit 9484f1c82b81e27edf2dc0a1bcc1fa3b12077406 Merge: d27f2df cacb4a2 Author: Valerio Virgillito Date: Tue Apr 17 15:03:50 2012 -0700 Merge branch 'refs/heads/master' into integration commit d27f2df4d846064444263d7832d213535962abe7 Author: Valerio Virgillito Date: Wed Apr 11 10:39:36 2012 -0700 integrating new picasa carousel component Signed-off-by: Valerio Virgillito commit 6f98384c9ecbc8abe55ccfe1fc25a0c7ce22c493 Author: Valerio Virgillito Date: Tue Apr 10 14:33:00 2012 -0700 fixed the text area case issue Text area was renamed from TextArea to Textarea Signed-off-by: Valerio Virgillito commit 1e83e26652266136802bc7af930379c1ecd631a6 Author: Valerio Virgillito Date: Mon Apr 9 22:10:45 2012 -0700 integrating montage v0.8 into ninja. Signed-off-by: Valerio Virgillito Signed-off-by: Valerio Virgillito --- node_modules/montage/require/require.js | 213 +++++++++++++++++++++++++------- 1 file changed, 168 insertions(+), 45 deletions(-) (limited to 'node_modules/montage/require/require.js') diff --git a/node_modules/montage/require/require.js b/node_modules/montage/require/require.js index aad6cef7..4ea8a46d 100755 --- a/node_modules/montage/require/require.js +++ b/node_modules/montage/require/require.js @@ -35,7 +35,8 @@ var globalEval = eval; // reassigning causes eval to not use lexical scope. - // Non-CommonJS speced extensions should be marked with an "// EXTENSION" comment. + // Non-CommonJS speced extensions should be marked with an "// EXTENSION" + // comment. Require.makeRequire = function (config) { var require; @@ -52,7 +53,8 @@ config.makeCompiler = config.makeCompiler || Require.makeCompiler; config.compile = config.compile || config.makeCompiler(config); - // Modules: { exports, id, location, directory, factory, dependencies, dependees, text, type } + // Modules: { exports, id, location, directory, factory, dependencies, + // dependees, text, type } var modules = config.modules = config.modules || {}; // produces an entry in the module state table, which gets built @@ -103,7 +105,9 @@ .then(function () { // compile and analyze dependencies config.compile(module); - var dependencies = module.dependencies = module.dependencies || []; + var dependencies = + module.dependencies = + module.dependencies || []; if (module.redirect !== void 0) { dependencies.push(module.redirect); } @@ -136,7 +140,8 @@ }) } - // Initializes a module by executing the factory function with a new module "exports" object. + // Initializes a module by executing the factory function with a new + // module "exports" object. function getExports(topId, viaId) { var module = getModule(topId); @@ -157,7 +162,10 @@ // do not initialize modules that do not define a factory function if (module.factory === void 0) { - throw new Error("Can't require module " + JSON.stringify(topId) + " via " + JSON.stringify(viaId)); + throw new Error( + "Can't require module " + JSON.stringify(topId) + + " via " + JSON.stringify(viaId) + ); } module.directory = URL.resolve(module.location, "."); // EXTENSION @@ -211,11 +219,14 @@ if (internal) { return null; } else { - throw new Error("Can't identify " + id2 + " from " + require2.location); + throw new Error( + "Can't identify " + id2 + " from " + require2.location + ); } } - // Creates a unique require function for each module that encapsulates that module's id for resolving relative module IDs against. + // Creates a unique require function for each module that encapsulates + // that module's id for resolving relative module IDs against. function makeRequire(viaId) { // Main synchronously executing "require()" function @@ -224,7 +235,8 @@ return getExports(topId, viaId); }; - // Asynchronous "require.async()" which ensures async executation (even with synchronous loaders) + // Asynchronous "require.async()" which ensures async executation + // (even with synchronous loaders) require.async = function(id, callback) { var topId = resolve(id, viaId); return deepLoad(topId, viaId) @@ -248,7 +260,19 @@ require.load = load; require.deepLoad = deepLoad; - require.loadPackage = config.loadPackage; + + require.loadPackage = function (dependency, givenConfig) { + if (givenConfig) { // explicit configuration, fresh environment + return Require.loadPackage(dependency, givenConfig); + } else { // inherited environment + return config.loadPackage(dependency, config); + } + }; + + require.injectPackageDescription = function (location, description) { + Require.injectPackageDescription(location, description, config); + }; + require.identify = identify; require.inject = inject; require.progress = Require.progress; @@ -272,34 +296,55 @@ initializedModules: [] }; + Require.injectPackageDescription = function (location, description, config) { + var descriptions = config.descriptions = config.descriptions || {}; + descriptions[location] = Promise.call(function () { + return description; + }); + }; + + Require.loadPackageDescription = function (location, config) { + var descriptions = config.descriptions = config.descriptions || {}; + if (descriptions[location] === void 0) { + var jsonPath = URL.resolve(location, 'package.json'); + descriptions[location] = Require.read(jsonPath) + .then(function (json) { + try { + return JSON.parse(json); + } catch (exception) { + throw new SyntaxError( + "in " + JSON.stringify(jsonPath) + ": " + + exception.message + ); + } + }); + } + return descriptions[location]; + }; + Require.loadPackage = function (location, config) { location = URL.resolve(location, "."); config = config || {}; var loadingPackages = config.loadingPackages = config.loadingPackages || {}; var loadedPackages = config.packages = {}; + var registry = config.registry = config.registry || Object.create(null); config.getPackage = function (dependency) { - dependency = Dependency(dependency); - // TODO handle other kinds of dependency + dependency = normalizeDependency(dependency, config); var location = dependency.location; if (!loadedPackages[location]) - throw new Error("Dependency is not loaded: " + JSON.stringify(location)); + throw new Error( + "Dependency is not loaded: " + JSON.stringify(location) + ); return loadedPackages[location]; }; - config.loadPackage = function (dependency) { - dependency = Dependency(dependency); - // TODO handle other kinds of dependency - var location = URL.resolve(dependency.location, "."); + config.loadPackage = function (dependency, viaConfig) { + dependency = normalizeDependency(dependency, viaConfig); + var location = dependency.location; if (!loadingPackages[location]) { - var jsonPath = URL.resolve(location, 'package.json'); - loadingPackages[location] = Require.read(jsonPath) - .then(function (json) { - try { - var packageDescription = JSON.parse(json); - } catch (exception) { - throw new SyntaxError("in " + JSON.stringify(jsonPath) + ": " + exception.message); - } + loadingPackages[location] = Require.loadPackageDescription(location, config) + .then(function (packageDescription) { var subconfig = configurePackage( location, packageDescription, @@ -324,9 +369,67 @@ return pkg; }; - function Dependency(dependency) { + function normalizeDependency(dependency, config, name) { + config = config || {}; if (typeof dependency === "string") { - dependency = {"location": dependency}; + if (dependency.indexOf("@") >= 0) { + var parts = dependency.split("@"); + dependency = { + name: parts[0] || name, + version: parts[1] + }; + } else { + dependency = { + location: dependency + }; + } + } + // if the named dependency has already been found at another + // location, refer to the same eventual instance + if ( + dependency.name !== void 0 && + config.registry !== void 0 && + config.registry[dependency.name] + ) { + dependency.location = config.registry[dependency.name]; + } + // default location + if (dependency.location === void 0) { + if ( + config.packagesDirectory === void 0 || + dependency.name === void 0 + ) { + throw new Error( + "name, version, or location required for dependency: " + + JSON.stringify(dependency) + " from " + location + ); + } + dependency.location = URL.resolve( + config.packagesDirectory, + dependency.name + "/" + ); + } + // make sure the dependency location has a trailing slash so that + // relative urls will resolve properly + if (!/\/$/.test(dependency.location)) { + dependency.location += "/"; + } + // resolve the location relative to the current package + if (!Require.isAbsolute(dependency.location)) { + if (config.location === void 0) { + throw new Error( + "Dependency locations must be fully qualified: " + + JSON.stringify(dependency) + ); + } + dependency.location = URL.resolve( + config.location, + dependency.location + ); + } + // register the package name so the location can be reused + if (dependency.name !== void 0) { + config.registry[dependency.name] = dependency.location; } return dependency; } @@ -341,11 +444,15 @@ config.name = description.name; config.location = location || Require.getLocation(); config.packageDescription = description; - config.define = description.define; // explicitly mask definitions and modules, which must // not apply to child packages var modules = config.modules = config.modules || {}; + var registry = config.registry; + if (config.name !== void 0 && !registry[config.name]) { + registry[config.name] = config.location; + } + // overlay var overlay = description.overlay || {}; Require.overlays.forEach(function (engine) { @@ -360,12 +467,16 @@ // directories description.directories = description.directories || {}; - description.directories.lib = description.directories.lib === void 0 ? "." : description.directories.lib; + description.directories.lib = + description.directories.lib === void 0 + ? "." + : description.directories.lib; var lib = description.directories.lib; // lib config.lib = URL.resolve(location, "./" + lib); - var packageRoot = description.directories.packages || "node_modules"; - packageRoot = URL.resolve(location, packageRoot + "/"); + var packagesDirectory = description.directories.packages || "node_modules"; + packagesDirectory = URL.resolve(location, packagesDirectory + "/"); + config.packagesDirectory = packagesDirectory; // The default "main" module of a package has the same name as the // package. @@ -394,21 +505,27 @@ // dependencies var dependencies = description.dependencies || {}; Object.keys(dependencies).forEach(function (name) { - var versionPredicateString = dependencies[name]; - // TODO (version presently ignored for debug mode) if (!mappings[name]) { - mappings[name] = {"location": URL.resolve( - packageRoot, - name + "/" - )}; + // dependencies are equivalent to name and version mappings, + // though the version predicate string is presently ignored + // (TODO) + mappings[name] = { + name: name, + version: dependencies[name] + }; + } else if (typeof console === "object") { + console.warn( + "Dependency for " + JSON.stringify(name) + " " + + "overriden by mapping in " + JSON.stringify(location) + ); } }); Object.keys(mappings).forEach(function (name) { - var mapping = mappings[name] = Dependency(mappings[name]); - if (!/\/$/.test(mapping.location)) - mapping.location += "/"; - if (!Require.isAbsolute(mapping.location)) - mapping.location = URL.resolve(location, mapping.location); + var mapping = mappings[name] = normalizeDependency( + mappings[name], + config, + name + ); }); config.mappings = mappings; @@ -487,7 +604,8 @@ }; }; - // Support she-bang for shell scripts by commenting it out (it is never valid JavaScript syntax anyway) + // Support she-bang for shell scripts by commenting it out (it is never + // valid JavaScript syntax anyway) Require.ShebangCompiler = function(config, compile) { return function (module) { if (module.text) { @@ -578,7 +696,7 @@ ) { var mapping = mappings[prefix]; var rest = id.slice(prefix.length + 1); - return config.loadPackage(mapping) + return config.loadPackage(mapping, config) .then(function (mappingRequire) { module.mappingRedirect = rest; module.mappingRequire = mappingRequire; @@ -620,7 +738,8 @@ } }; - // Attempts to load using multiple base paths (or one absolute path) with a single loader. + // Attempts to load using multiple base paths (or one absolute path) with a + // single loader. Require.PathsLoader = function(config, load) { var loadFromPaths = config.paths.reduceRight(function (next, path) { return function (id, module) { @@ -635,7 +754,11 @@ }); }; }, function (id, module) { - throw new Error("Can't find " + JSON.stringify(id) + " from paths " + JSON.stringify(config.paths) + " in package at " + JSON.stringify(config.location)); + throw new Error( + "Can't find " + JSON.stringify(id) + " from paths " + + JSON.stringify(config.paths) + " in package at " + + JSON.stringify(config.location) + ); }); return function(id, module) { if (Require.isAbsolute(id)) { -- cgit v1.2.3