Permalink
Browse files

Change handling of path resolution

  • Loading branch information...
1 parent 5428810 commit a3c3f5ccae593f82851280e64c9834888bca921b @justjohn committed Apr 2, 2012
Showing with 24 additions and 13 deletions.
  1. +10 −5 lib/module.js
  2. +1 −1 lib/paths.js
  3. +13 −7 package.js
View
15 lib/module.js
@@ -1,10 +1,15 @@
exports.makeId = function(file, base) {
- // Strip base path off filename
- var rp = new RegExp("^" + base);
+ if (base) {
+ // Strip base path off filename
+ var rp = new RegExp("^" + base);
+ // hacky, but works for now
+ id = file.replace(rp, "");
+ } else {
+ id = file;
+ }
- // hacky, but work for now
- id = file.replace(rp, "").replace(".js", "");
+ id = id.replace(".js", "");
return id;
}
@@ -18,4 +23,4 @@ exports.memoize = function(id, deps, data) {
module += "\n});";
return module;
-}
+}
View
2 lib/paths.js
@@ -35,4 +35,4 @@ exports.findBase = function(file) {
// we're in the file directory
return "";
}
-}
+}
View
20 package.js
@@ -5,7 +5,8 @@ var fs = require("fs")
, jsp = UGLIFY.parser
, pro = UGLIFY.uglify;
-exports.package = function(files) {
+exports.package = function(files, options) {
+ if (!options) options = {};
var processedFile = {}
, modules = {}
@@ -21,7 +22,7 @@ exports.package = function(files) {
base = PATHS.findBase(file);
}
- var id = MODULE.makeId(file, base)
+ var id = options.relative ? MODULE.makeId(file, base) : MODULE.makeId(file)
, data = fs.readFileSync(file, 'utf8')
, ast = jsp.parse(data)
, deps = undefined
@@ -40,7 +41,7 @@ exports.package = function(files) {
, arg_fn;
// Check for a modules.declare call
- if (name[1] == "module" && method == "declare" && args[0]) {
+ if (name && name[1] == "module" && method == "declare" && args[0]) {
// We found the arguments location, check for an array
arg_type = args[0][0];
arg_deps = args[0][1];
@@ -54,7 +55,8 @@ exports.package = function(files) {
arg_deps.forEach(function(dep) {
var type = dep[0]
, value = dep[1]
- , file_name;
+ , file_name
+ , parsed_file;
if (type == "string") {
// handle string dependencies
@@ -67,10 +69,14 @@ exports.package = function(files) {
if (file_name) {
file_name = file_name + ".js";
- var normalized_file = PATHS.relativePath(file, file_name);
+ if (options.relative) {
+ parsed_file = PATHS.relativePath(file, file_name);
+ } else {
+ parsed_file = file_name;
+ }
- if (processedFile[normalized_file] === undefined) {
- files.push(normalized_file);
+ if (processedFile[parsed_file] === undefined) {
+ files.push(parsed_file);
}
}
});

0 comments on commit a3c3f5c

Please sign in to comment.