Permalink
Browse files

Actually get the code to behave like the API docs for packages: confi…

…g. Add more debug info to node r.js debug mode.
  • Loading branch information...
jrburke committed Oct 3, 2010
1 parent f3bbd7b commit e89c6c1523ac59e7303407d506f8e2ce75cdeb31
Showing with 51 additions and 38 deletions.
  1. +7 −0 build/convert/node/requireAdapter.js
  2. +30 −32 require.js
  3. +4 −0 tasks.txt
  4. +10 −6 tests/packages/packages-tests.js
@@ -31,8 +31,15 @@
//Load the content for the module. Be sure to first check the natives
//modules that are burned into node first.
if (natives[moduleName]) {
+ if (isDebug) {
+ logger.trace("RequireJS loading module: " + moduleName + " from Node cache");
+ }
+
content = natives[moduleName];
} else {
+ if (isDebug) {
+ logger.trace("RequireJS loading module: " + moduleName + " at path: " + url);
+ }
content = require._nodeReadFile(url);
}
View
@@ -80,6 +80,33 @@ var require;
context.loaded[args[0]] = true;
}
+ /**
+ * Used to set up package paths from a packagePaths or packages config object.
+ * @param {Object} packages 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 configurePackageDir(packages, currentPackages, dir) {
+ var i, location, pkgObj;
+ for (i = 0; (pkgObj = currentPackages[i]); i++) {
+ pkgObj = typeof pkgObj === "string" ? { name: pkgObj } : pkgObj;
+ location = pkgObj.location;
+
+ //Add dir to the path, but avoid paths that start with a slash
+ //or have a colon (indicates a protocol)
+ if (dir && (!location || (location.indexOf("/") !== 0 && location.indexOf(":") === -1))) {
+ pkgObj.location = dir + "/" + (pkgObj.location || pkgObj.name);
+ }
+
+ //Normalize package paths.
+ pkgObj.location = pkgObj.location || pkgObj.name;
+ pkgObj.lib = pkgObj.lib || "lib";
+ pkgObj.main = pkgObj.main || "main";
+
+ packages[pkgObj.name] = pkgObj;
+ }
+ }
+
/**
* Resumes tracing of dependencies and then checks if everything is loaded.
*/
@@ -255,7 +282,7 @@ var require;
var context, newContext, loaded, pluginPrefix,
canSetContext, prop, newLength, outDeps, mods, paths, index, i,
deferMods, deferModArgs, lastModArg, waitingName, packages,
- packagePaths, pkgPath, pkgNames, pkgName, pkgObj;
+ packagePaths, pkgPath;
contextName = contextName ? contextName : (config && config.context ? config.context : s.ctxName);
context = s.contexts[contextName];
@@ -371,43 +398,14 @@ var require;
if (packagePaths) {
for (prop in packagePaths) {
if (!(prop in empty)) {
- pkgPath = prop;
- pkgNames = packagePaths[pkgPath];
- for (i = 0; (pkgName = pkgNames[i]); i++) {
- if (typeof pkgName === "string") {
- //Standard package mapping.
- pkgObj = packages[pkgName] = {
- name: pkgName,
- location: pkgPath + "/" + pkgName
- };
- } else {
- //A custom setup.
- pkgObj = context.config.packages[pkgName.name] = pkgName;
- pkgObj.location = pkgPath + "/" + (pkgObj.location || pkgObj.name);
- }
- }
+ configurePackageDir(packages, packagePaths[prop], prop);
}
}
}
//Adjust packages if necessary.
if (config.packages) {
- for (prop in config.packages) {
- if (!(prop in empty)) {
- pkgObj = packages[prop] = config.packages[prop];
- pkgObj.name = pkgObj.name || prop;
- }
- }
- }
-
- //Normalize package paths.
- for (prop in packages) {
- if (!(prop in empty)) {
- pkgObj = packages[prop];
- pkgObj.location = pkgObj.location || pkgObj.name;
- pkgObj.lib = pkgObj.lib || "lib";
- pkgObj.main = pkgObj.main || "main";
- }
+ configurePackageDir(packages, config.packages);
}
//Done with modifications, assing packages back to context config
View
@@ -1,3 +1,5 @@
+- get plugins to work in node?
+
- jQuery 1.4.3:
- Open ticket about just registering via require.def with something like:
if( typeof require !== "undefined" && require.def )
@@ -16,6 +18,8 @@
- in commonJs.js convert, if take out dependency scanning, things break in the Node adapter.
Need to figure out why. Function.toString() seems to work.
+- Build: do not require the user to be in the same directory as build file?
+
- Move to using module.basePath instead of require.nameToUrl inside methods? basePath
would basically call nameToUrl but use no suffix. Hmm, nice thing about nameToUrl is it
works with any name, not just current module. require.nameToUrl(module.id, ".html")
@@ -20,24 +20,28 @@ require({
}
]
},
- packages: {
- bar: {
+ packages: [
+ {
+ name: 'bar',
location: 'bar/0.4',
lib: 'scripts'
},
- foo: {
+ {
+ name: 'foo',
location: 'foo'
},
- baz: {
+ {
+ name: 'baz',
location: 'baz',
main: 'index'
},
- 'dojox/window': {
+ {
+ name: 'dojox/window',
location: 'dojox/window',
lib: '.',
main: 'window'
}
- }
+ ]
},
["require", "alpha", "alpha/replace", "beta", "beta/util", "bar", "baz",
"foo", "foo/second", "dojox/chair", "dojox/table", "dojox/door", "dojox/window/pane",

0 comments on commit e89c6c1

Please sign in to comment.