Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Windows support, at least for the tests re: issue #6

  • Loading branch information...
commit 42b10160a2c024b28521951250a640c97fbf89ff 1 parent 010b331
@mixu authored
View
8 lib/glue.js
@@ -107,7 +107,9 @@ Renderer.prototype._render = function(onDone) {
var result = [];
this.build.render(result, function(pkgId) {
- var relpath = self.build.main.replace(/^\.\//, '').replace(new RegExp('^'+self.build.basepath), '');
+ var relpath = self.build.main.replace(/^\.\//, '').replace(new RegExp('^' +
+ (path.sep == '\\' ? self.build.basepath.replace(/\\/g, '\\\\') : self.build.basepath ) // windows
+ ), '');
onDone({
replaced: self.replaced,
code: self.code,
@@ -172,13 +174,13 @@ Renderer.prototype.watch = function(onDone) {
Renderer.prototype._updateBasePath = function() {
var basepath = this.build.basepath;
basepath = this._fullPath(basepath);
- basepath += (basepath[basepath.length-1] !== '/' ? '/' : '');
+ basepath += (basepath[basepath.length-1] !== path.sep ? path.sep : '');
this.build.basepath = basepath;
}
Renderer.prototype._fullPath = function(p) {
if(p.substr(0, 1) == '.') {
- p = path.normalize(this.options.reqpath + '/' + p);
+ p = path.normalize(this.options.reqpath + path.sep + p);
}
return p;
};
View
6 lib/group.js
@@ -1,4 +1,5 @@
-var fs = require('fs');
+var fs = require('fs'),
+ path = require('path');
// A set of file/folder paths defined as:
// - include(path/file)
@@ -16,10 +17,11 @@ Group.prototype.include = function(filepath){
paths = (Array.isArray(filepath) ? filepath : [ filepath ]);
paths.forEach(function(p) {
+ p = path.normalize(p); // for windows
var isDirectory = fs.statSync(p).isDirectory();
if (isDirectory) {
- p += (p[p.length-1] !== '/' ? '/' : '');
+ p += (p[p.length-1] !== path.sep ? path.sep : '');
return fs.readdirSync(p).forEach(function (f) {
self.include(p + f);
});
View
8 lib/package.js
@@ -60,7 +60,7 @@ Package.prototype.dependency = function(name, contextPath) {
resolver.expand(resolvePath, function(basePath, main, files, dependencies) {
child.name = name;
child.files = files;
- child.main = main.replace(new RegExp('^'+basePath), '');
+ child.main = (main.substr(0, basePath.length) == basePath ? main.substr(basePath.length) : main);
child.basepath = basePath;
dependencies.forEach(function(dep) {
child.dependency(dep, basePath);
@@ -75,7 +75,11 @@ Package.prototype.dependency = function(name, contextPath) {
Package.prototype._runHandlers = function(selfId, onDone) {
var self = this;
function relative(filename){
- return filename.replace(new RegExp('^'+self.basepath), '');
+ var temp = (filename.substr(0, self.basepath.length) == self.basepath ? filename.substr(self.basepath.length) : filename);
+ if(path.sep != '/') {
+ temp = temp.replace(/\\/g, '/'); // windows
+ }
+ return temp;
}
var opts = { relative: relative },
result = {},
View
2  test/glue.test.js
@@ -40,7 +40,7 @@ exports['glue'] = {
'concat calls render() on arguments and returns the full result': function(done) {
var assertions = 0;
- this.g.concat([
+ Glue.concat([
{ render: function(done) { assertions++; done(undefined, 'a'); } },
{ render: function(done) { assertions++; done(undefined, 'b'); } },
], function(err, txt) {
View
9 test/group.test.js
@@ -1,4 +1,5 @@
var fs = require('fs'),
+ path = require('path'),
assert = require('assert'),
Group = require('../lib/group');
@@ -13,7 +14,7 @@ exports['given a group'] = {
var g = this.group;
var result = g.include(__dirname+'/fixtures/rendertest/simple.js').resolve();
assert.equal(result.length, 1);
- assert.equal(result[0], __dirname+'/fixtures/rendertest/simple.js');
+ assert.equal(result[0], path.normalize(__dirname+'/fixtures/rendertest/simple.js'));
done();
},
@@ -21,8 +22,8 @@ exports['given a group'] = {
var g = this.group;
var result = g.include(__dirname+'/fixtures/rendertest/').resolve();
assert.equal(result.length, 2);
- assert.equal(result[0], __dirname+'/fixtures/rendertest/has_dependency.js');
- assert.equal(result[1], __dirname+'/fixtures/rendertest/simple.js');
+ assert.equal(result[0], path.normalize(__dirname+'/fixtures/rendertest/has_dependency.js'));
+ assert.equal(result[1], path.normalize(__dirname+'/fixtures/rendertest/simple.js'));
done();
},
@@ -32,7 +33,7 @@ exports['given a group'] = {
.exclude(new RegExp('.*simple\\.js$'))
.resolve();
assert.equal(result.length, 1);
- assert.equal(result[0], __dirname+'/fixtures/rendertest/has_dependency.js');
+ assert.equal(result[0], path.normalize(__dirname+'/fixtures/rendertest/has_dependency.js'));
done();
}
};
View
31 test/package.test.js
@@ -1,4 +1,5 @@
var fs = require('fs'),
+ path = require('path'),
util = require('util'),
assert = require('assert'),
Package = require('../lib/package');
@@ -33,9 +34,9 @@ exports['package'] = {
var child = this.p.children[0];
assert.equal(child.name, 'foo');
assert.equal(child.main, '/foo.js');
- assert.equal(child.basepath, __dirname+'/fixtures/expandsingle/node_modules');
+ assert.equal(child.basepath, path.normalize(__dirname+'/fixtures/expandsingle/node_modules'));
assert.equal(child.files.length, 1);
- assert.equal(child.files[0], __dirname+'/fixtures/expandsingle/node_modules/foo.js');
+ assert.equal(child.files[0], path.normalize(__dirname+'/fixtures/expandsingle/node_modules/foo.js'));
var result = [];
this.p.render(result, function(selfId) {
@@ -54,11 +55,11 @@ exports['package'] = {
var child = this.p.children[0];
assert.equal(child.name, 'foo');
assert.equal(child.main, '/index.js');
- assert.equal(child.basepath, __dirname+'/fixtures/expandindex/node_modules/foo');
+ assert.equal(child.basepath, path.normalize(__dirname+'/fixtures/expandindex/node_modules/foo'));
assert.equal(child.files.length, 3);
- assert.equal(child.files[0], child.basepath+'/index.js');
- assert.equal(child.files[1], child.basepath+'/lib/sub.js');
- assert.equal(child.files[2], child.basepath+'/other.js');
+ assert.equal(child.files[0], path.normalize(child.basepath+'/index.js'));
+ assert.equal(child.files[1], path.normalize(child.basepath+'/lib/sub.js'));
+ assert.equal(child.files[2], path.normalize(child.basepath+'/other.js'));
var result = [];
this.p.render(result, function(selfId) {
@@ -81,11 +82,11 @@ exports['package'] = {
assert.equal(p.children.length, 1);
assert.equal(p.children[0].name, 'foo');
assert.equal(p.children[0].main, '/lib/sub.js');
- assert.equal(p.children[0].basepath, __dirname+'/fixtures/expandpackage/node_modules/foo');
+ assert.equal(p.children[0].basepath, path.normalize(__dirname+'/fixtures/expandpackage/node_modules/foo'));
assert.equal(p.children[0].files.length, 3);
- assert.equal(p.children[0].files[0], p.children[0].basepath+'/lib/sub.js');
- assert.equal(p.children[0].files[1], p.children[0].basepath+'/other.js');
- assert.equal(p.children[0].files[2], p.children[0].basepath+'/package.json');
+ assert.equal(p.children[0].files[0], path.normalize(p.children[0].basepath+'/lib/sub.js'));
+ assert.equal(p.children[0].files[1], path.normalize(p.children[0].basepath+'/other.js'));
+ assert.equal(p.children[0].files[2], path.normalize(p.children[0].basepath+'/package.json'));
var result = [];
p.render(result, function(selfId) {
@@ -106,18 +107,18 @@ exports['package'] = {
assert.equal(p.children.length, 1);
assert.equal(p.children[0].name, 'foo');
assert.equal(p.children[0].main, '/index.js');
- assert.equal(p.children[0].basepath, __dirname+'/fixtures/hassubdependency/node_modules/foo');
+ assert.equal(p.children[0].basepath, path.normalize(__dirname+'/fixtures/hassubdependency/node_modules/foo'));
assert.equal(p.children[0].files.length, 2);
- assert.equal(p.children[0].files[0], p.children[0].basepath+'/index.js');
- assert.equal(p.children[0].files[1], p.children[0].basepath+'/package.json');
+ assert.equal(p.children[0].files[0], path.normalize(p.children[0].basepath+'/index.js'));
+ assert.equal(p.children[0].files[1], path.normalize(p.children[0].basepath+'/package.json'));
// subdependency
assert.equal(p.children[0].children.length, 1);
var child = p.children[0].children[0];
assert.equal(child.name, 'bar');
assert.equal(child.main, '/index.js');
- assert.equal(child.basepath, __dirname+'/fixtures/hassubdependency/node_modules/foo/node_modules/bar');
+ assert.equal(child.basepath, path.normalize(__dirname+'/fixtures/hassubdependency/node_modules/foo/node_modules/bar'));
assert.equal(child.files.length, 1);
- assert.equal(child.files[0], child.basepath+'/index.js');
+ assert.equal(child.files[0], path.normalize(child.basepath+'/index.js'));
var result = [];
p.render(result, function(selfId) {
Please sign in to comment.
Something went wrong with that request. Please try again.