Skip to content
Browse files

Merge branch 'master' of git://github.com/ajaxorg/dryice

Conflicts:
	lib/dryice/index.js
  • Loading branch information...
2 parents b2c3703 + 6459eae commit 29685d178e36fe2bdfc2f87c9b58c3c316619afb @joewalker joewalker committed Nov 9, 2011
Showing with 28 additions and 20 deletions.
  1. +27 −19 lib/dryice/index.js
  2. +1 −1 package.json
View
46 lib/dryice/index.js
@@ -283,6 +283,7 @@ NullModule.prototype.toString = function() {
function CommonJsProject(opts) {
this.roots = opts.roots;
this.ignoreRequires = opts.ignores || [];
+ this.textPluginPattern = opts.textPluginPattern || /^text!/;
this.currentFiles = {};
this.ignoredFiles = {};
@@ -375,7 +376,8 @@ function CommonJsProject(opts) {
CommonJsProject.prototype.clone = function() {
var clone = new CommonJsProject({
roots: this.roots,
- ignores: this.ignoreRequires
+ ignores: this.ignoreRequires,
+ textPluginPattern: this.textPluginPattern
});
Object.keys(this.currentFiles).forEach(function(module) {
@@ -444,6 +446,25 @@ function CommonJsProject(opts) {
return result.concat(pathB).join('/');
}
+ function normalizeRequire(baseObj, module) {
+ if (module.indexOf("!") !== -1) {
+ var chunks = module.split("!");
+ return normalizeRequire(baseObj, chunks[0]) + "!" + normalizeRequire(baseObj, chunks[1]);
+ }
+
+ if (module.charAt(0) == ".") {
+ var requirersDirectory = path.dirname(path.join(baseObj.base, baseObj.path));
+ var pathToRequiredModule = path.join(requirersDirectory, module);
+ // The call to `define` which makes the module being
+ // relatively required isn't the full relative path,
+ // but the path relative from the base.
+ return relative(baseObj.base, pathToRequiredModule);
+ }
+ else {
+ return module;
+ }
+ }
+
function findRequires(baseObj) {
var code = fs.readFileSync(path.join(baseObj.base, baseObj.path)).toString();
var ast;
@@ -466,19 +487,7 @@ function CommonJsProject(opts) {
// now we detect computed requires, it's not needed.
if (expr[1] === 'require') {
if (args[0][0] === 'string') {
- if (/^\./.test(args[0][1])) {
- var requirersDirectory = path.dirname(path.join(baseObj.base, baseObj.path));
- var pathToRequiredModule = path.join(requirersDirectory,
- args[0][1]);
- // The call to `define` which makes the module being
- // relatively required isn't the full relative path,
- // but the path relative from the base.
- reply.push(relative(baseObj.base,
- pathToRequiredModule));
- }
- else {
- reply.push(args[0][1]);
- }
+ reply.push(normalizeRequire(baseObj, args[0][1]));
}
else {
console.log('- ' + baseObj.path + ' has require(...) ' +
@@ -496,8 +505,6 @@ function CommonJsProject(opts) {
return reply;
}
- var textPluginPattern = /^text!/;
-
CommonJsProject.prototype.require = function(module) {
var baseObj = this.currentFiles[module];
if (baseObj) {
@@ -516,14 +523,15 @@ function CommonJsProject(opts) {
// Find which of the packages it is in
this.roots.forEach(function(root) {
var base = ensureTrailingSlash(root);
- if (textPluginPattern.test(module)) {
- baseObj = findModuleAt(baseObj, base, module.replace(textPluginPattern, ''));
+ if (this.textPluginPattern.test(module)) {
+ baseObj = findModuleAt(baseObj, base, module.replace(this.textPluginPattern, ''));
if (baseObj) {
baseObj.isText = true;
}
} else {
baseObj = findModuleAt(baseObj, base, module + '.js');
- baseObj = findModuleAt(baseObj, base, module + '/index.js');
+ if (!baseObj)
+ baseObj = findModuleAt(baseObj, base, module + '/index.js');
}
}, this);
View
2 package.json
@@ -10,7 +10,7 @@
"type": "git",
"url": "http://github.com/mozilla/dryice.git"
},
- "bugs": { "web": "http://github.com/mozilla/dryice/issues" },
+ "bugs": { "url": "http://github.com/mozilla/dryice/issues" },
"directories": { "lib" : "./lib" },
"main": "./lib/dryice/index.js",
"engines": { "node" : ">=0.2.0" },

0 comments on commit 29685d1

Please sign in to comment.
Something went wrong with that request. Please try again.