function makeError(id, msg, err) {
Constructs an error with a pointer to an URL with more information.
param {String} id the error ID that maps to an ID on a web page.
param {String} message human readable error.
param {Error} [err] the original error, if there is one.
returns {Error}
function configurePackageDir(pkgs, currentPackages, dir) {
Used to set up package paths from a packagePaths or packages config object.
param {Object} pkgs the object to store the new package config
param {Array} currentPackages an array of packages to configure
param {String} [dir] a prefix dir to use.
function jQueryHoldReady($, shouldHold) {
jQuery 1.4.3-1.5.x use a readyWait/ready() pairing to hold DOM ready callbacks, but jQuery 1.6 supports a holdReady() API instead. At some point remove the readyWait/ready() support and just stick with using holdReady.
function newContext(contextName) {
Creates a new context for use in require and define calls. Handle most of the heavy lifting. Do not want to use an object with prototype here to avoid using "this" in require, in case it needs to be used in more super secure envs that do not want this. Also there should not be that many contexts in the page. Usually just one for the default context, but could be extra for multiversion cases or if a package needs a special context for a dependency that conflicts with the standard context.
function trimDots(ary) {
Trims the . and .. from an array of path segments. It will keep a leading path segment if a .. will become the first path segment, to help with module name lookups, which act like paths, but can be remapped. But the end result, all paths that use this function should look normalized. NOTE: this method MODIFIES the input array.
param {Array} ary the array of path segments.
function normalize(name, baseName) {
Given a relative module name, like ./something, normalize it to a real name that can be mapped to a path.
param {String} name the relative name
param {String} baseName a real name that the name arg is relative to.
returns {String} normalized name
function makeModuleMap(name, parentModuleMap) {
Creates a module mapping that includes plugin prefix, module name, and path. If parentModuleMap is provided it will also normalize the name via require.normalize()
param {String} name the module name
param {String} [parentModuleMap] parent module map for the module name, used to resolve relative names.
returns {Object}
function isPriorityDone() {
Determine if priority loading is done. If so clear the priorityWait
function makeRequire(relModuleMap, enableBuildCallback) {
Helper function that creates a require function object to give to modules that ask for it as a dependency. It needs to be specific per module because of the implication of path mappings that may need to be relative to the module name.
function makeArgCallback(manager, i) {
Helper that creates a callack function that is called when a dependency is ready, and sets the i-th dependency for the manager as the value passed to the callback generated by this function.
function addWait(manager) {
Adds the manager to the waiting queue. Only fully resolved items should be in the waiting queue.
function managerAdd(cb) {
Function added to every manager object. Created out here to avoid new function creation for each manager instance.
function callDefMain(args) {
Convenience method to call main for a define call that was put on hold in the defQueue.
jQueryCheck = function (jqCandidate) {
jQuery 1.4.3+ supports ways to hold off calling calling jQuery ready callbacks until all scripts are loaded. Be sure to track it if the capability exists.. Also, since jQuery 1.4.3 does not register as a module, need to do some global inference checking. Even if it does register as a module, not guaranteed to be the precise name of the global. If a jQuery is tracked for this context, then go ahead and register it as a module too, if not already in process.
function checkLoaded() {
Checks if all modules for a context are loaded, and if so, evaluates the new ones in right dependency order.
private
resume = function () {
Resumes tracing of dependencies and then checks if everything is loaded.
configure: function (cfg) {
Set a configuration for the context.
param {Object} cfg config object to integrate.
takeGlobalQueue: function () {
Internal method to transfer globalQueue items to this context's defQueue.
completeLoad: function (moduleName) {
Internal method used by environment adapters to complete a load event. A load event could be a script load or just a load pass from a synchronous load call.
param {String} moduleName the name of the module to potentially complete.
toUrl: function (moduleNamePlusExt, relModuleMap) {
Converts a module name + .extension into an URL path. *Requires* the use of a module name. It does not support using plain URLs like nameToUrl.
nameToUrl: function (moduleName, ext, relModuleMap) {
Converts a module name to a file path. Supports cases where moduleName may actually be just an URL.
req = requirejs = function (deps, callback) {
Main entry point. If the only argument to require is a string, then the module that is represented by that string is fetched for the appropriate context. If the first argument is an array, then it will be treated as an array of dependency string names to fetch. An optional function callback can be specified to execute when all of those dependencies are available. Make a local req variable to help Caja compliance (it assumes things on a require that are not standardized), and to give a short name for minification/local scope use.
req.config = function (config) {
Support require.config() to make it easier to cooperate with other AMD loaders on globally agreed names.
if (!require) {
Export require as a global, but only if it does not already exist.
req.toUrl = function (moduleNamePlusExt) {
Global require.toUrl(), to match global require, mostly useful for debugging/work in the global space.
req.onError = function (err) {
Any errors that require explicitly generates will be passed to this function. Intercept/override it if you want custom error handling.
param {Error} err the error object.
req.load = function (context, moduleName, url) {
Does the request to load a module for the browser case. Make this a separate function to allow other environments to override it.
param {Object} context the require context to find state.
param {String} moduleName the name of the module.
param {Object} url the URL to the module.
define = function (name, deps, callback) {
The function that handles definitions of modules. Differs from require() in that a string for the module should be the first argument, and the function to execute after dependencies are loaded should return a value to define the module corresponding to the first argument's name.
req.exec = function (text) {
Executes the text. Normally just uses eval, but can be modified to use a more environment specific call.
param {String} text the text to execute/evaluate.
req.execCb = function (name, callback, args, exports) {
Executes a module callack function. Broken out as a separate function solely to allow the build system to sequence the files in the built layer in the right sequence.
private
req.addScriptToDom = function (node) {
Adds a node to the DOM. Public function since used by the order plugin. This method should not normally be called by outside code.
req.onScriptLoad = function (evt) {
callback for script loads, used to check status of loading.
param {Event} evt the event from the browser for the script that was loaded.
private
req.attach = function (url, context, moduleName, callback, type, fetchOnlyFunction) {
Attaches the script represented by the URL to the current environment. Right now only supports browser loading, but can be redefined in other environments to do the right thing.
param {String} url the url of the script to attach.
param {Object} context the context that wants the script.
param {moduleName} the name of the module that is associated with the script.
param {Function} [callback] optional callback, defaults to require.onScriptLoad
param {String} [type] optional type, defaults to text/javascript
param {Function} [fetchOnlyFunction] optional function to indicate the script node should be set up to fetch the script but do not attach it to the DOM so that it can later be attached to execute it. This is a way for the order plugin to support ordered loading in IE. Once the script is fetched, but not executed, the fetchOnlyFunction will be called.
req.resourcesReady = function (isReady) {
Internal function that is triggered whenever all scripts/resources have been loaded by the loader. Can be overridden by other, for instance the domReady plugin, which wants to know when all resources are loaded.