Permalink
Browse files

Mostly implements package mappings/C

  • Loading branch information...
1 parent c0f3f9f commit f6a8067cd3e543b85c39db7c670068893151e9dd @kriszyp committed Jul 28, 2010
Showing with 30 additions and 16 deletions.
  1. +6 −7 README.md
  2. +24 −9 lib/nodules.js
View
@@ -46,13 +46,13 @@ for module configuration and id mapping, use the "lib" as one of the default pat
and execute the "lib/index.js" file if it exists. The package.json's mappings can contain
mappings to URIs so that you don't have to use URIs directly in your require calls in
your modules. For example, your package.json could define this mapping to map the
-foo namespace to the modules from a package available from somesite.com:
+foo namespace to the modules from a package archive available from somesite.com:
package.json
{
"name":"my-project",
"mappings": {
- "foo": "http://somesite.com/foo/lib/"
+ "foo": "http://somesite.com/foo.zip"
}
}
@@ -70,21 +70,20 @@ Now we can run our package by simply starting nodules from inside this directory
Mappings
--------
-Nodules supports referening modules within zip file via the jar: scheme, and for the vast
-majority of projects that are in github repos, it is recommmended that you use jar: URIs.
+Nodules supports referening package zip file which is the recommended mechanism for referencing packages:
For example:
"mappings": {
- "commonjs-utils": "jar:http://github.com/kriszyp/commonjs-utils/zipball/master!/lib/"
+ "commonjs-utils": "http://github.com/kriszyp/commonjs-utils/zipball/master"
}
When the target ends with a slash, the mapping will only match module ids in require statements
where the mapping is the first term in a path, so this would match something of the form:
require(""commonjs-utils/lazy-array");
-You can also map directly to individual modules by specifying the full URL with an extension.
-For example:
+You can also map directly to individual modules by specifying the full URL with an extension
+(and Nodules support the jar: scheme). For example:
"lazy-array": "jar:http://github.com/kriszyp/commonjs-utils/zipball/master!/lib/lazy-array.js"
View
@@ -336,15 +336,28 @@ function processPackage(packageUri, packageData, engine){
if(mappings){
mappingsArray = mappingsArray.concat(Object.keys(mappings).map(function(key){
var to = mappings[key];
- // if it ends with a slash, only match paths
- if(to.charAt(to.length - 1) === '/' && key.charAt(key.length - 1) !== '/'){
+ if(typeof to == "string"){
+ if(to.substring(0,5) == "http:"){
+ to = "jar:" + to + "!/lib/";
+ }
+ // if it ends with a slash, only match paths
+ if(to.charAt(to.length - 1) === '/' && key.charAt(key.length - 1) !== '/'){
+ key += '/';
+ }
+ // for backwards compatibility with regex exact matches
+ else if(key.charAt(0) === "^" && key.charAt(key.length - 1) === "$"){
+ to += packageData.extension || ".js";
+ key = key.substring(1, key.length - 1);
+ }
+ }else if(to.archive){
+ var libDir = to.descriptor && to.descriptor.directories && to.descriptor.directories.lib;
+ if(typeof libDir != "string"){
+ libDir = "lib";
+ }
key += '/';
+ to = to.archive ? "jar:" + to.archive + "!/" + libDir + "/" : to.location;
}
- // for backwards compatibility with regex exact matches
- else if(key.charAt(0) === "^" && key.charAt(key.length - 1) === "$"){
- to += packageData.extension || ".js";
- key = key.substring(1, key.length - 1);
- }
+
return {
from: key,
exact: to.match(/\.\w+$/),
@@ -620,7 +633,7 @@ function readModuleFile(path, uri){
}, print);
}
});
- }, 300);
+ }, 1000);
}
watchedFiles.push({
oldstat: fs.statSync(path),
@@ -632,7 +645,9 @@ function readModuleFile(path, uri){
return source;
function possibleChange(oldstat, newstat){
if(oldstat.mtime.getTime() !== newstat.mtime.getTime() && waitingOn === 0){
- print("Reloading " + uri);
+ if(!process.env._IS_CHILD_){
+ print("Reloading " + uri);
+ }
delete factories[uri];
exports.ensure(uri, function(){
onFileChange(uri);

0 comments on commit f6a8067

Please sign in to comment.