[Pkg-javascript-commits] [node-stack-utils] 20/67: convert everything to use unix strings

Bastien Roucariès rouca at moszumanska.debian.org
Thu Sep 7 09:53:02 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-stack-utils.

commit 65799353ebea471f0768eba0469d086cf2e83e4c
Author: James Talmage <james at talmage.io>
Date:   Thu Jan 7 15:40:23 2016 -0500

    convert everything to use unix strings
---
 index.js | 23 ++++++++++++-----------
 test.js  | 12 ++++--------
 2 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/index.js b/index.js
index 961e6fa..8d2301e 100644
--- a/index.js
+++ b/index.js
@@ -5,7 +5,7 @@ function StackUtils(opts) {
 		throw new Error('StackUtils constructor must be called with new');
 	}
 	opts = opts || {};
-	this._cwd = opts.cwd || process.cwd();
+	this._cwd = (opts.cwd || process.cwd()).replace(/\\/g, '/');
 	this._internals = opts.internals || [];
 }
 
@@ -45,8 +45,8 @@ StackUtils.prototype.clean = function (stack) {
 
 		return st.trim()
 			.replace(/^\s*at /, '')
-			.replace(this._cwd + '/', '')
-			.replace(this._cwd + '\\', '');
+			.replace(/\\/g, '/')
+			.replace(this._cwd + '/', '');
 	}, this).filter(function (st) {
 		return st;
 	}).join('\n').trim();
@@ -126,8 +126,8 @@ StackUtils.prototype.at = function at(fn) {
 
 	var file = site.getFileName();
 	if (file) {
-		if (file.indexOf(this._cwd + '/') === 0 ||
-			file.indexOf(this._cwd + '\\') === 0) {
+		file = file.replace(/\\/g, '/');
+		if (file.indexOf(this._cwd + '/') === 0) {
 			file = file.substr(this._cwd.length + 1);
 		}
 		res.file = file;
@@ -210,15 +210,16 @@ StackUtils.prototype.parseLine = function parseLine(line) {
 	var native = match[11] === 'native';
 
 	var res = {
-		file: file,
 		line: Number(lnum),
 		column: Number(col)
 	};
 
-	if (res.file &&
-		(res.file.indexOf(this._cwd + '/') === 0 ||
-		res.file.indexOf(this._cwd + '\\') === 0)) {
-		res.file = res.file.substr(this._cwd.length + 1);
+	if (file) {
+		file = file.replace(/\\/g, '/');
+		if ((file.indexOf(this._cwd + '/') === 0)) {
+			file = file.substr(this._cwd.length + 1);
+		}
+		res.file = file;
 	}
 
 	if (ctor) {
@@ -229,7 +230,7 @@ StackUtils.prototype.parseLine = function parseLine(line) {
 		res.evalOrigin = evalOrigin;
 		res.evalLine = evalLine;
 		res.evalColumn = evalCol;
-		res.evalFile = evalFile;
+		res.evalFile = evalFile && evalFile.replace(/\\/g, '/');
 	}
 
 	if (native) {
diff --git a/test.js b/test.js
index 71c34fd..7afc564 100644
--- a/test.js
+++ b/test.js
@@ -43,20 +43,16 @@ test('clean: truncates cwd', t => {
 
 test('clean: eliminates internals', t => {
 	let stack = new StackUtils({cwd: '/user/dev', internals: StackUtils.nodeInternals()});
-	t.is(stack.clean(LinuxStack1), join([
+	var expected = join([
 		'foo (project/foo.js:3:8)',
 		'bar (project/foo.js:7:2)',
 		'bar (project/bar.js:4:2)',
 		'Object.<anonymous> (project/bar.js:7:1)'
-	]));
+	]);
+	t.is(stack.clean(LinuxStack1), expected);
 
 	stack = new StackUtils({cwd: 'Z:\\user\\dev', internals: StackUtils.nodeInternals()});
-	t.is(stack.clean(WindowsStack1), join([
-		'foo (project\\foo.js:3:8)',
-		'bar (project\\foo.js:7:2)',
-		'bar (project\\bar.js:4:2)',
-		'Object.<anonymous> (project\\bar.js:7:1)'
-	]));
+	t.is(stack.clean(WindowsStack1), expected);
 });
 
 test('clean: returns null if it is all internals', t => {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stack-utils.git



More information about the Pkg-javascript-commits mailing list