Comparing version 0.0.4 to 0.12.0
@@ -60,3 +60,4 @@ | ||
var loadPackage = function (location, config) { | ||
exports.loadPackage = loadPackage; | ||
function loadPackage(location, config) { | ||
if (location.slice(location.length - 1, location.length) !== "/") { | ||
@@ -68,3 +69,3 @@ location += "/"; | ||
return Require.loadPackage(config.location, config); | ||
}; | ||
} | ||
@@ -86,3 +87,5 @@ var loadFreeModule = function (program, command, args) { | ||
bootstrap(); | ||
if (require.main == module) { | ||
bootstrap(); | ||
} | ||
104
bootstrap.js
@@ -1,7 +0,4 @@ | ||
(function () { | ||
(function (global) { | ||
"use strict"; | ||
// The global context object | ||
var global = new Function("return this")(); | ||
var bootstrap = function (callback) { | ||
@@ -34,13 +31,6 @@ var domLoaded, Require, Promise, URL; | ||
// TODO preloading of optimized bundles | ||
for (var id in pending) { | ||
(function (location) { | ||
var script = document.createElement("script"); | ||
script.src = resolve(params.bootstrapLocation, location); | ||
script.onload = function () { | ||
// remove clutter | ||
script.parentNode.removeChild(script); | ||
}; | ||
document.querySelector("head").appendChild(script); | ||
})(pending[id]); | ||
if (!global.preload) { | ||
for (var id in pending) { | ||
load(pending[id]); | ||
} | ||
} | ||
@@ -101,3 +91,3 @@ | ||
script, | ||
bootstrapFound, | ||
mrLocation, | ||
attr, | ||
@@ -112,12 +102,9 @@ name; | ||
script = scripts[i]; | ||
bootstrapFound = false; | ||
if (script.src && (match = script.src.match(/^(.*)bootstrap.js(?:[\?\.]|$)/i))) { | ||
params.bootstrapLocation = match[1]; | ||
bootstrapFound = true; | ||
mrLocation = match[1]; | ||
} | ||
if (script.hasAttribute("data-bootstrap")) { | ||
params.bootstrapLocation = script.getAttribute("data-bootstrap"); | ||
bootstrapFound = true; | ||
if (script.hasAttribute("data-mr-location")) { | ||
mrLocation = resolve(window.location, script.getAttribute("data-mr-location")); | ||
} | ||
if (bootstrapFound) { | ||
if (mrLocation) { | ||
if (script.dataset) { | ||
@@ -140,2 +127,3 @@ for (name in script.dataset) { | ||
script.parentNode.removeChild(script); | ||
params.mrLocation = mrLocation; | ||
break; | ||
@@ -164,3 +152,3 @@ } | ||
if (!/^[\w\-]+:/.test(base)) { // isAbsolute(base) | ||
throw new Error("Can't resolve from a relative location: " + JSON.stringify(base) + " " + JSON.stringify(relative)); | ||
throw new Error("Can't resolve " + JSON.stringify(relative) + " relative to " + JSON.stringify(base)); | ||
} | ||
@@ -181,4 +169,16 @@ var restore = baseElement.href; | ||
var load = function (location) { | ||
var params = getParams(); | ||
var script = document.createElement("script"); | ||
script.src = resolve(params.mrLocation, location); | ||
script.onload = function () { | ||
// remove clutter | ||
script.parentNode.removeChild(script); | ||
}; | ||
document.querySelector("head").appendChild(script); | ||
}; | ||
bootstrap(function onbootstrap(Require, Promise, URL) { | ||
var params = getParams(); | ||
var config = {}; | ||
@@ -188,14 +188,46 @@ var applicationLocation = URL.resolve(window.location, params.package || "."); | ||
// execute the preloading plan and stall the fallback module loader | ||
// until it has finished | ||
if (global.preload) { | ||
var bundleDefinitions = {}; | ||
var getDefinition = function (name) { | ||
return bundleDefinitions[name] = | ||
bundleDefinitions[name] || | ||
Promise.defer(); | ||
}; | ||
global.bundleLoaded = function (name) { | ||
getDefinition(name).resolve(); | ||
}; | ||
var preloading = Promise.defer(); | ||
config.preloaded = preloading.promise; | ||
// preload bundles sequentially | ||
var preloaded = Promise.resolve(); | ||
global.preload.forEach(function (bundleLocations) { | ||
preloaded = preloaded.then(function () { | ||
return Promise.all(bundleLocations.map(function (bundleLocation) { | ||
load(bundleLocation); | ||
return getDefinition(bundleLocation).promise; | ||
})); | ||
}); | ||
}); | ||
// then release the module loader to run normally | ||
preloading.resolve(preloaded.then(function () { | ||
delete global.preload; | ||
delete global.bundleLoaded; | ||
})); | ||
} | ||
Require.loadPackage({ | ||
location: params.bootstrapLocation, | ||
hash: params.bootstrapHash | ||
}) | ||
.then(function (bootstrapRequire) { | ||
location: params.mrLocation, | ||
hash: params.mrHash | ||
}, config) | ||
.then(function (mrRequire) { | ||
bootstrapRequire.inject("mini-url", URL); | ||
bootstrapRequire.inject("promise", Promise); | ||
bootstrapRequire.inject("require", Require); | ||
mrRequire.inject("mini-url", URL); | ||
mrRequire.inject("promise", Promise); | ||
mrRequire.inject("require", Require); | ||
return bootstrapRequire.loadPackage({ | ||
return mrRequire.loadPackage({ | ||
name: "q", | ||
location: params.qLocation, | ||
hash: params.qHash | ||
@@ -208,6 +240,6 @@ }) | ||
if ("autoPackage" in params) { | ||
bootstrapRequire.injectPackageDescription(applicationLocation, {}); | ||
mrRequire.injectPackageDescription(applicationLocation, {}); | ||
} | ||
return bootstrapRequire.loadPackage({ | ||
return mrRequire.loadPackage({ | ||
location: applicationLocation, | ||
@@ -220,6 +252,6 @@ hash: params.applicationHash | ||
}) | ||
.end(); | ||
.done(); | ||
}); | ||
})(); | ||
})(this); |
@@ -95,3 +95,3 @@ /* <copyright> | ||
return module; | ||
if (config.define) | ||
if (config.useScriptInjection) | ||
throw new Error("Can't use eval."); | ||
@@ -113,3 +113,4 @@ | ||
} catch (exception) { | ||
throw new SyntaxError("in " + module.location + ": " + exception.message); | ||
exception.message = exception.message + " in " + module.location; | ||
throw exception; | ||
} | ||
@@ -142,10 +143,24 @@ | ||
}; | ||
define = function (hash, id, module) { | ||
// global | ||
montageDefine = function (hash, id, module) { | ||
getDefinition(hash, id).resolve(module); | ||
}; | ||
Require.loadScript = function (location) { | ||
var script = document.createElement("script"); | ||
script.onload = function() { | ||
script.parentNode.removeChild(script); | ||
}; | ||
script.onerror = function (error) { | ||
script.parentNode.removeChild(script); | ||
}; | ||
script.src = location; | ||
script.defer = true; | ||
document.getElementsByTagName("head")[0].appendChild(script); | ||
}; | ||
Require.ScriptLoader = function (config) { | ||
var hash = config.packageDescription.hash; | ||
return function (location, module) { | ||
return Promise.call(function () { | ||
return Promise.fcall(function () { | ||
@@ -163,12 +178,3 @@ // short-cut by predefinition | ||
var script = document.createElement("script"); | ||
script.onload = function() { | ||
script.parentNode.removeChild(script); | ||
}; | ||
script.onerror = function (error) { | ||
script.parentNode.removeChild(script); | ||
}; | ||
script.src = location; | ||
script.defer = true; | ||
document.getElementsByTagName("head")[0].appendChild(script); | ||
loadScript(location); | ||
@@ -188,4 +194,31 @@ return getDefinition(hash, module.id).promise | ||
// old version | ||
var loadPackageDescription = Require.loadPackageDescription; | ||
Require.loadPackageDescription = function (dependency, config) { | ||
if (dependency.hash) { // use script injection | ||
// the package.json might come in a preloading bundle. if so, we do not | ||
// want to issue a script injection. however, if by the time preloading | ||
// has finished the package.json has not arrived, we will need to kick off | ||
// a request for the package.json.load.js script. | ||
if (!config.preloaded.isResolved()) { | ||
config.preloaded.then(function () { | ||
if (!result.isResolved()) { | ||
var location = URL.resolve(dependency.location, "package.json.load.js"); | ||
loadScript(location); | ||
} | ||
}); | ||
} | ||
return getDefinition(dependency.hash, 'package.json') | ||
.promise.then(function (module) { | ||
return module.exports; | ||
}) | ||
} else { | ||
// fall back to normal means | ||
return loadPackageDescription(dependency, config); | ||
} | ||
}; | ||
Require.makeLoader = function (config) { | ||
if (config.define) { | ||
if (config.useScriptInjection) { | ||
Loader = Require.ScriptLoader; | ||
@@ -192,0 +225,0 @@ } else { |
{ | ||
"name": "mr", | ||
"version": "0.0.4", | ||
"version": "0.12.0", | ||
"main": "require", | ||
@@ -15,7 +15,17 @@ "bin": { | ||
"dependencies": { | ||
"q": "0.8.x >=0.8.11" | ||
"q": "0.8.11 - 0.9" | ||
}, | ||
"devDependencies": { | ||
"qs": "0.5.x" | ||
} | ||
"qs": "0.5 - 0.6" | ||
}, | ||
"exclude": [ | ||
"README.md", | ||
"LICENSE.md", | ||
"bootstrap-node.js", | ||
"node.js", | ||
"adhoc.*", | ||
"bin", | ||
"demo", | ||
"spec" | ||
] | ||
} |
@@ -1383,4 +1383,3 @@ // vim:ts=4:sts=4:sw=4: | ||
* | ||
* var readFile = require("fs").readFile; | ||
* Q.nfapply(readFile, [__filename]) | ||
* Q.nfapply(FS.readFile, [__filename]) | ||
* .then(function (content) { | ||
@@ -1404,4 +1403,3 @@ * }) | ||
* | ||
* var readFile = require("fs").readFile; | ||
* Q.nfcall(readFile, __filename) | ||
* Q.nfcall(FS.readFile, __filename) | ||
* .then(function (content) { | ||
@@ -1447,3 +1445,2 @@ * }) | ||
* | ||
* var FS = (require)("fs"); | ||
* Q.napply(FS.readFile, FS, [__filename]) | ||
@@ -1463,3 +1460,2 @@ * .then(function (content) { | ||
* | ||
* var FS = (require)("fs"); | ||
* Q.ncall(FS.readFile, FS, __filename) | ||
@@ -1466,0 +1462,0 @@ * .then(function (content) { |
@@ -7,5 +7,5 @@ [![Build Status](https://secure.travis-ci.org/kriskowal/q.png)](http://travis-ci.org/kriskowal/q) | ||
function may eventually provide. A promise can also be used as a | ||
proxy for a [remote object][Q-Comm] to overcome latency. | ||
proxy for a [remote object][Q-Connection] to overcome latency. | ||
[Q-Comm]: https://github.com/kriskowal/q-comm | ||
[Q-Connection]: https://github.com/kriskowal/q-connection | ||
@@ -12,0 +12,0 @@ On the first pass, promises can mitigate the “[Pyramid of |
@@ -82,3 +82,3 @@ | ||
id: id, | ||
display: config.location + "#" + id, // EXTENSION | ||
display: (config.name || config.location) + "#" + id, // EXTENSION | ||
require: require | ||
@@ -286,9 +286,13 @@ }; | ||
require.hasPackage = function (dependency) { | ||
return config.getPackage(dependency, config); | ||
return config.hasPackage(dependency); | ||
}; | ||
require.getPackage = function (dependency) { | ||
return config.getPackage(dependency, config); | ||
return config.getPackage(dependency); | ||
}; | ||
require.isMainPackage = function () { | ||
return require.location === config.mainPackageLocation; | ||
}; | ||
require.injectPackageDescription = function (location, description) { | ||
@@ -353,7 +357,5 @@ Require.injectPackageDescription(location, description, config); | ||
return JSON.parse(json); | ||
} catch (exception) { | ||
throw new SyntaxError( | ||
"in " + JSON.stringify(descriptionLocation) + ": " + | ||
exception.message | ||
); | ||
} catch (error) { | ||
error.message = error.message + " in " + JSON.stringify(descriptionLocation) | ||
throw error; | ||
} | ||
@@ -367,10 +369,16 @@ }); | ||
dependency = normalizeDependency(dependency, config); | ||
if (!dependency.location) { | ||
throw new Error("Can't find dependency: " + JSON.stringify(dependency)); | ||
} | ||
var location = dependency.location; | ||
config = config || {}; | ||
config = Object.create(config || null); | ||
var loadingPackages = config.loadingPackages = config.loadingPackages || {}; | ||
var loadedPackages = config.packages = {}; | ||
var registry = config.registry = config.registry || Object.create(null); | ||
config.mainPackageLocation = location; | ||
config.hasPackage = function (dependency) { | ||
dependency = normalizeDependency(dependency, config); | ||
if (!dependency.location) | ||
return false; | ||
var location = dependency.location; | ||
@@ -382,7 +390,16 @@ return !!loadedPackages[location]; | ||
dependency = normalizeDependency(dependency, config); | ||
if (!dependency.location) { | ||
throw new Error("Can't find dependency: " + JSON.stringify(dependency) + " from " + config.location); | ||
} | ||
var location = dependency.location; | ||
if (!loadedPackages[location]) { | ||
throw new Error( | ||
"Dependency is not loaded: " + JSON.stringify(location) | ||
); | ||
if (loadingPackages[location]) { | ||
throw new Error( | ||
"Dependency has not finished loading: " + JSON.stringify(dependency) | ||
); | ||
} else { | ||
throw new Error( | ||
"Dependency was not loaded: " + JSON.stringify(dependency) | ||
); | ||
} | ||
} | ||
@@ -394,2 +411,5 @@ return loadedPackages[location]; | ||
dependency = normalizeDependency(dependency, viaConfig); | ||
if (!dependency.location) { | ||
throw new Error("Can't find dependency: " + JSON.stringify(dependency) + " from " + config.location); | ||
} | ||
var location = dependency.location; | ||
@@ -430,7 +450,10 @@ if (!loadingPackages[location]) { | ||
} | ||
if (dependency.main) { | ||
dependency.location = config.mainPackageLocation; | ||
} | ||
// 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 && | ||
dependency.name && | ||
config.registry && | ||
config.registry[dependency.name] | ||
@@ -441,13 +464,3 @@ ) { | ||
// default location | ||
if (dependency.location === void 0) { | ||
if ( | ||
config.packagesDirectory === void 0 || | ||
dependency.name === void 0 | ||
) { | ||
throw new Error( | ||
"name or location required for dependency: " + | ||
JSON.stringify(dependency) + " from " + config.location + | ||
" unless already found by name." | ||
); | ||
} | ||
if (!dependency.location && config.packagesDirectory && dependency.name) { | ||
dependency.location = URL.resolve( | ||
@@ -458,2 +471,4 @@ config.packagesDirectory, | ||
} | ||
if (!dependency.location) | ||
return dependency; // partially completed | ||
// make sure the dependency location has a trailing slash so that | ||
@@ -466,3 +481,3 @@ // relative urls will resolve properly | ||
if (!Require.isAbsolute(dependency.location)) { | ||
if (config.location === void 0) { | ||
if (!config.location) { | ||
throw new Error( | ||
@@ -479,3 +494,3 @@ "Dependency locations must be fully qualified: " + | ||
// register the package name so the location can be reused | ||
if (dependency.name !== void 0) { | ||
if (dependency.name) { | ||
config.registry[dependency.name] = dependency.location; | ||
@@ -496,3 +511,3 @@ } | ||
config.packageDescription = description; | ||
config.define = description.define; | ||
config.useScriptInjection = description.useScriptInjection; | ||
@@ -511,3 +526,3 @@ // explicitly mask definitions and modules, which must | ||
var layer; | ||
Require.overlays.forEach(function (engine) { | ||
(config.overlays || Require.overlays).forEach(function (engine) { | ||
if (overlay[engine]) { | ||
@@ -570,7 +585,2 @@ var layer = overlay[engine]; | ||
}; | ||
} else if (typeof console === "object") { | ||
console.warn( | ||
"Dependency for " + JSON.stringify(name) + " " + | ||
"overriden by mapping in " + JSON.stringify(location) | ||
); | ||
} | ||
@@ -674,5 +684,2 @@ }); | ||
Require.LintCompiler = function(config, compile) { | ||
if (!config.lint) { | ||
return compile; | ||
} | ||
return function(module) { | ||
@@ -682,5 +689,7 @@ try { | ||
} catch (error) { | ||
Promise.nextTick(function () { | ||
config.lint(module); | ||
}); | ||
if (config.lint) { | ||
Promise.nextTick(function () { | ||
config.lint(module); | ||
}); | ||
} | ||
throw error; | ||
@@ -733,3 +742,3 @@ } | ||
config.mappings = config.mappings || {}; | ||
config.name = config.name || ""; | ||
config.name = config.name; | ||
@@ -746,3 +755,7 @@ var mappings = config.mappings; | ||
// TODO: remove this when all code has been migrated off of the autonomous name-space problem | ||
if (id.indexOf(config.name) === 0 && id.charAt(config.name.length) === "/") { | ||
if ( | ||
config.name !== void 0 && | ||
id.indexOf(config.name) === 0 && | ||
id.charAt(config.name.length) === "/" | ||
) { | ||
console.warn("Package reflexive module ignored:", id); | ||
@@ -749,0 +762,0 @@ } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
869
17
4
327238
102
7019
+ Addedq@0.9.7(transitive)
- Removedq@0.8.12(transitive)
Updatedq@0.8.11 - 0.9