Skip to content
Browse files

Removed all hardcoded "/" and repaced with generic regexes for workin…

…g on windows
  • Loading branch information...
1 parent 22bf39f commit fb442c154b1f184d31fe3b164cfd4e3f38360d1d @gatapia committed
Showing with 27 additions and 19 deletions.
  1. +2 −0 TODO.txt
  2. +8 −5 bin/nccompile.js
  3. +1 −1 bin/ncdoc.js
  4. +1 −1 bin/ncstyle.js
  5. +3 −3 bin/nodetestinstance.js
  6. +2 −2 lib/nclosurebase.js
  7. +10 −7 lib/settingsloader.js
View
2 TODO.txt
@@ -3,6 +3,8 @@ TODO
HIGH
----
+- npm link does not work on windows so hard coding rootLibDir which means that
+ the lib may now work when installed in npm install.
- ncstyle cannot be run in the lib directory as it does not ignore the
node directory and the -e flag is being ignored.
View
13 bin/nccompile.js
@@ -24,13 +24,16 @@
* annotation docs</a>.
*/
+// TODO: Since npm link does not work on windows lets just hack this for now.
+// this probably means that npm install will now no longer work.
+var rootLibDir = '../lib/';
/**
* @private
* @const
* @type {nclosure.core}
*/
-var ng_ = require('nclosure').nclosure();
+var ng_ = require(rootLibDir + 'nclosure').nclosure();
goog.provide('nclosure.nccompile');
@@ -345,7 +348,7 @@ nclosure.nccompile.prototype.addAdditionalRoots_ =
} else if (ng_.args.additionalDeps) {
// Only try to guess roots if additionalCompileRoots not specified
goog.array.forEach(ng_.args.additionalDeps, function(dep) {
- var path = dep.substring(0, dep.lastIndexOf('/'));
+ var path = dep.substring(0, dep.search(/[\/\\][^\/\\]*$/g));
this.addRoot_(addedPaths, clArgs, path, wPrefix);
}, this);
}
@@ -395,8 +398,8 @@ nclosure.nccompile.prototype.addRoot_ =
* @return {string} The path to take between the directories.
*/
nclosure.nccompile.prototype.getPathToDir_ = function(realFrom, realTo) {
- var from = realFrom.split('/').reverse(),
- to = realTo.split('/').reverse(),
+ var from = realFrom.split(/[\/\\]/).reverse(),
+ to = realTo.split(/[\/\\]/).reverse(),
fl = from.length - 1,
tl = to.length - 1,
path = [];
@@ -454,7 +457,7 @@ nclosure.nccompile.prototype.isPathInMap_ = function(map, s) {
* @return {string} The parent directory of the soecified file.
*/
nclosure.nccompile.prototype.getDirectory_ = function(file) {
- var pathIdx = file.lastIndexOf('/');
+ var pathIdx = file.search(/[\/\\][^\/\\]*$/g);
var path = pathIdx > 0 ? file.substring(0, pathIdx) : '.';
return path;
};
View
2 bin/ncdoc.js
@@ -84,7 +84,7 @@ nclosure.ncdoc.prototype.init_ = function(args) {
* @param {string} entryPoint The file/directory to document.
*/
nclosure.ncdoc.prototype.createJSDocArgs_ = function(args, entryPoint) {
- var entryPointDirIdx = entryPoint.lastIndexOf('/');
+ var entryPointDirIdx = entryPoint.search(/[\/\\][^\/\\]*$/g);;
var title = entryPointDirIdx > 0 ?
entryPoint.substring(entryPointDirIdx + 1) : entryPoint;
var entryPointDir = entryPointDirIdx > 0 ?
View
2 bin/ncstyle.js
@@ -66,7 +66,7 @@ nclosure.ncstyle = function() {
var dir = process.argv[2];
var isDir = nclosure.ncstyle.isDir_(dir);
if (!isDir) {
- dir = dir.substring(0, dir.lastIndexOf('/') + 1);
+ dir = dir.substring(0, dir.search(/[\/\\][^\/\\]*$/g) + 1);
}
var that = this;
var onexit = function(err) {
View
6 bin/nodetestinstance.js
@@ -65,7 +65,7 @@ nclosure.NodeTestInstance = function(file, args) {
* @private
* @type {string}
*/
- this.shortName_ = file.substring(file.lastIndexOf('/') + 1);
+ this.shortName_ = file.substring(file.search(/[\/\\][^\/\\]*$/g) + 1);
/**
* @private
@@ -95,7 +95,7 @@ nclosure.NodeTestInstance = function(file, args) {
*/
nclosure.NodeTestInstance.prototype.loadAdditionalTestingDependencies_ =
function() {
- var dir = this.file_.substring(0, this.file_.lastIndexOf('/'));
+ var dir = this.file_.substring(0, this.file_.search(/[\/\\][^\/\\]*$/g));
ng_.loadAditionalDependenciesInSettingsFile(ng_.getPath(dir, 'closure.json'));
ng_.loadDependenciesFile(dir, 'deps.js');
};
@@ -276,7 +276,7 @@ nclosure.NodeTestInstance.parseStackFrameLine_ = function(line) {
line = line.substring(line.indexOf(' at ') + 4);
// return new goog.testing.stacktrace.Frame('', line, '', '', line);
- if (line.charAt(0) === '/') { // Path to test file
+ if (line.charAt(0) === '/' || line.charAt(0) === '\\') { // Path to test file
return new goog.testing.stacktrace.Frame('', '', '', '', line);
}
var contextAndFunct = line.substring(0, line.lastIndexOf(' ')).split('.');
View
4 lib/nclosurebase.js
@@ -270,7 +270,7 @@ nclosure.base.prototype.loadScript = function(dir, file) {
if (!this.closureScriptLoading(dir, file)) { return; }
// TODO: Do we need absolute file support?
- var path = (file.indexOf('/') === 0 ? file :
+ var path = (file.search(/[\/\\]/) === 0 ? file :
require('path').resolve(dir, file));
if (this.scriptsWritten_[path]) { return; }
@@ -336,7 +336,7 @@ nclosure.base.prototype.loadAdditionalDepsInSettingsObject_ =
for (var i = 0, len = opts.additionalDeps.length; i < len; i++) {
var fileName = opts.additionalDeps[i];
- var idx = fileName.lastIndexOf('/');
+ var idx = fileName.search(/[\/\\][^\/\\]*$/g);
this.loadScript(fileName.substring(0, idx + 1),
fileName.substring(idx + 1));
}
View
17 lib/settingsloader.js
@@ -40,8 +40,10 @@ nclosure.settingsLoader = function() {
* represent the full path to the specific file/dir.
*/
nclosure.settingsLoader.prototype.getPath = function(baseDir, file) {
- if (baseDir && baseDir.charAt(baseDir.length - 1) !== '/') baseDir += '/';
- if (file.charAt(0) === '/') file = file.substring(1);
+ var lastChar = baseDir.charAt(baseDir.length - 1);
+ if (baseDir && lastChar !== '/' && lastChar !== '\\') baseDir += '/';
+ if (file.charAt(0) === '/' || file.charAt(0) === '\\')
+ file = file.substring(1);
var path = baseDir + file;
var cwd = process.cwd() + '/';
path = require('path').resolve(path);
@@ -60,9 +62,9 @@ nclosure.settingsLoader.prototype.getFileDirectory = function(file) {
if (require('path').existsSync(file) &&
require('fs').statSync(file).isDirectory()) return file;
- var didx = file.lastIndexOf('/');
+ var didx = file.search(/[\/\\][^\/\\]*$/g);
if (didx < 0) return './';
- return file.substring(0, file.lastIndexOf('/') + 1);
+ return file.substring(0, didx + 1);
};
@@ -98,8 +100,9 @@ nclosure.settingsLoader.prototype.parseCompilerArgsFromFile = function(file) {
*/
nclosure.settingsLoader.prototype.readArgsFromJSONFile = function(path) {
if (!path || !require('path').existsSync(path)) return null;
- var json = require('fs').readFileSync(path).toString();
- var dir = path.substring(0, path.lastIndexOf('/'));
+ var json = require('fs').readFileSync(path).toString();
+ var lastSlash = path.search(/[\/\\][^\/\\]*$/g);
+ var dir = path.substring(0, lastSlash);
return this.getOptsObject_(dir, json);
};
@@ -206,7 +209,7 @@ nclosure.settingsLoader.prototype.parseCompilerArgsFromFileImpl_ =
code = this.removeShebang(code);
try { process.binding('evals').Script.runInNewContext(code, ctx, file); }
catch (e) {}
- var dirIdx = file.lastIndexOf('/');
+ var dirIdx = file.search(/[\/\\][^\/\\]*$/g);
var dir = dirIdx < 0 ? '.' : file.substring(0, dirIdx);
return this.validateOpsObject_(
this.getPath(process.cwd(), dir), opts || {}, true);

0 comments on commit fb442c1

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