Skip to content

Commit 4dee5c3

Browse files
committed
windows path fix
1 parent c016bc4 commit 4dee5c3

File tree

9 files changed

+9
-49
lines changed

9 files changed

+9
-49
lines changed

lib/importPaths.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use strict";
22
var path_1 = require('path');
3-
var system_1 = require('./system');
43
var importPathRegex = /require\(["'](BASE.+)["']\)([a-zA-Z0-9\-\_]+)?|^import.+?\s?["'](BASE.+)["'];?$/m;
54
var relativePathRegex = /^BASE/;
65
function fixImportPaths(_a) {
@@ -12,14 +11,8 @@ function fixImportPaths(_a) {
1211
}
1312
var importPath = isMatch[1] || isMatch[2] || isMatch[3];
1413
if (importPath.match(relativePathRegex)) {
15-
var newPath = void 0;
16-
if (system_1.isWindows) {
17-
newPath = path_1.join(dir, importPath.replace('BASE', ''))
18-
.split('\\').join('\\\\');
19-
}
20-
else {
21-
newPath = path_1.join(dir, importPath.replace('BASE', ''));
22-
}
14+
var newPath = path_1.join(dir, importPath.replace('BASE', ''))
15+
.split('\\').join('\\\\');
2316
return line.replace(importPath, newPath);
2417
}
2518
return line;

lib/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
"use strict";
22
var importPaths_1 = require('./importPaths');
3-
var system_1 = require('./system');
43
var jsCodeRoad = function (_a) {
54
var dir = _a.dir, content = _a.content;
6-
if (system_1.isWindows) {
7-
dir = dir.split('\\').join('\\\\');
8-
}
5+
dir = dir.split('\\').join('\\\\');
96
return "(function(){'use strict';\nrequire('babel-register')({plugins:[\n ['transform-es2015-modules-commonjs',{loose:true,sourceRoot:'" + dir + "'}]\n]});\n" + require('process-console-log').logger + "\nconst _f_e = require('node-file-exists').default;\nconst _join = require('path').join;\nfunction exists(p) { return _f_e(_join('" + dir + "',p)); }\nrequire = require('rewire-coderoad');\n\n" + importPaths_1.default({ dir: dir, content: content }) + "\n\n}());";
107
};
118
Object.defineProperty(exports, "__esModule", { value: true });

lib/system.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-coderoad",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "bundled javascript features for coderoad test runners",
55
"keywords": [
66
"coderoad",
@@ -33,7 +33,7 @@
3333
"babel-register": "^6.14.0",
3434
"node-file-exists": "^1.1.0",
3535
"process-console-log": "^0.2.5",
36-
"rewire-coderoad": "^3.1.3"
36+
"rewire-coderoad": "^3.1.4"
3737
},
3838
"devDependencies": {
3939
"ava": "^0.16.0",

src/importPaths.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { join } from 'path';
2-
import { isWindows } from './system';
32

43
/*
54
import paths won't match the context of the test runner
@@ -24,18 +23,9 @@ export default function fixImportPaths({dir, content}): string {
2423

2524
// is a relative path
2625
if (importPath.match(relativePathRegex)) {
27-
let newPath;
28-
29-
if (isWindows) {
30-
// fix buggy Windows paths
31-
// note: necessary to split and join before newPath is set to
32-
// a variable or backslashes are interpreted as escaped characters
33-
newPath = join(dir, importPath.replace('BASE', ''))
34-
.split('\\').join('\\\\');
35-
} else {
36-
newPath = join(dir, importPath.replace('BASE', ''));
37-
}
38-
26+
let newPath = join(dir, importPath.replace('BASE', ''))
27+
// fix windows paths
28+
.split('\\').join('\\\\');
3929
return line.replace(importPath, newPath);
4030
}
4131
// no match, return line

src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import fixImportPaths from './importPaths';
2-
import { isWindows } from './system';
32

43
const jsCodeRoad = ({dir, content}) => {
54

65
// fix Windows paths
7-
if (isWindows) {
8-
dir = dir.split('\\').join('\\\\');
9-
}
6+
dir = dir.split('\\').join('\\\\');
107

118
return `(function(){'use strict';
129
require('babel-register')({plugins:[

src/system.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/system.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"files": [
1919
"src/importPaths.ts",
2020
"src/index.ts",
21-
"src/system.ts",
2221
"src/typings/chai/chai.d.ts",
2322
"src/typings/cr/cr.d.ts",
2423
"src/typings/cr/globals.d.ts",

0 commit comments

Comments
 (0)