Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd5e6aeb

Browse files
committed
continued windows path bug fixes
1 parent552144e commitd5e6aeb

File tree

7 files changed

+42
-13
lines changed

7 files changed

+42
-13
lines changed

‎lib/importPaths.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
varpath_1=require('path');
3-
varisWindows=window.navigator.appVersion.indexOf('Win')>-1;
3+
varsystem_1=require('./system');
44
varimportPathRegex=/require\(["'](BASE.+)["']\)([a-zA-Z0-9\-\_]+)?|^import.+?\s?["'](BASE.+)["'];?$/m;
55
varrelativePathRegex=/^BASE/;
66
functionfixImportPaths(_a){
@@ -14,8 +14,8 @@ function fixImportPaths(_a) {
1414
varimportPath=isMatch[1]||isMatch[2]||isMatch[3];
1515
if(importPath.match(relativePathRegex)){
1616
varnewPath=path_1.join(dir,importPath.replace('BASE',''));
17-
if(isWindows){
18-
newPath=newPath.split('\\').join('\\\\');
17+
if(system_1.isWindows){
18+
newPath=system_1.fixPathForWindows(newPath);
1919
}
2020
varnewLine=line.replace(importPath,newPath);
2121
if(!entries.has(newLine)){

‎lib/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"use strict";
22
varimportPaths_1=require('./importPaths');
3+
varsystem_1=require('./system');
34
varjsCodeRoad=function(_a){
4-
vardir=_a.dir,content=_a.content,isWindows=_a.isWindows;
5-
return("\n(function(){'use strict';\nrequire('babel-register')({plugins:[['transform-es2015-modules-commonjs',{loose:true,sourceRoot:'"+dir+"'}]]});\n"+require('process-console-log').logger+"\nlet _fileExists = require('node-file-exists').default;\nlet _path = require('path');\nglobal.exists = (p) => _fileExists(_path.join('"+dir+"',p));\nrequire = require('rewire-coderoad');\n\n// unit tests\n\n"+importPaths_1.default({dir:dir,content:content})+"\n\n}());");
5+
vardir=_a.dir,content=_a.content;
6+
if(system_1.isWindows){
7+
dir=system_1.fixPathForWindows(dir);
8+
}
9+
return"\n(function(){'use strict';\nrequire('babel-register')({plugins:[['transform-es2015-modules-commonjs',{loose:true,sourceRoot:'"+dir+"'}]]});\n"+require('process-console-log').logger+"\nconst _fileExists = require('node-file-exists').default;\nconst _path = require('path');\nfunction exists(p) { return _fileExists(_path.join('"+dir+"',p)); }\nrequire = require('rewire-coderoad');\n\n// unit tests\n\n"+importPaths_1.default({dir:dir,content:content})+"\n\n}());";
610
};
711
Object.defineProperty(exports,"__esModule",{value:true});
812
exports.default=jsCodeRoad;

‎lib/system.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict";
2+
exports.isWindows=window.navigator.appVersion.indexOf('Win')>-1;
3+
exports.fixPathForWindows=function(p){
4+
p.split('\\\\').join('\\');
5+
p.split('\\').join('\\\\');
6+
p.split('/').join('\\\\');
7+
returnp;
8+
};

‎src/importPaths.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import{join}from'path';
2+
import{isWindows,fixPathForWindows}from'./system';
23

34
/*
45
import paths won't match the context of the test runner
56
fixImportPaths will replace paths with absolute paths
67
*/
7-
constisWindows=window.navigator.appVersion.indexOf('Win')>-1;
88

99
// import or require statement
1010
constimportPathRegex=
@@ -31,7 +31,7 @@ export default function fixImportPaths({dir, content}): string {
3131

3232
// fix buggy Windows paths
3333
if(isWindows){
34-
newPath=newPath.split('\\').join('\\\\');
34+
newPath=fixPathForWindows(newPath);
3535
}
3636

3737
constnewLine=line.replace(importPath,newPath);

‎src/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
importfixImportPathsfrom'./importPaths';
2+
import{isWindows,fixPathForWindows}from'./system';
23

3-
constjsCodeRoad=({dir, content, isWindows})=>(`
4+
constjsCodeRoad=({dir, content})=>{
5+
6+
// fix Windows paths
7+
if(isWindows){
8+
dir=fixPathForWindows(dir);
9+
}
10+
11+
return`
412
(function(){'use strict';
513
require('babel-register')({plugins:[['transform-es2015-modules-commonjs',{loose:true,sourceRoot:'${dir}'}]]});
614
${require('process-console-log').logger}
7-
let _fileExists = require('node-file-exists').default;
8-
let _path = require('path');
9-
global.exists =(p)=>_fileExists(_path.join('${dir}',p));
15+
const _fileExists = require('node-file-exists').default;
16+
const _path = require('path');
17+
function exists(p){ return_fileExists(_path.join('${dir}',p)); }
1018
require = require('rewire-coderoad');
1119
1220
// unit tests
1321
1422
${fixImportPaths({dir, content})}
1523
16-
}());`
17-
);
24+
}());`;
25+
};
1826
exportdefaultjsCodeRoad;

‎src/system.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
exportconstisWindows=window.navigator.appVersion.indexOf('Win')>-1;
2+
3+
exportconstfixPathForWindows=(p:string)=>{
4+
p.split('\\\\').join('\\');
5+
p.split('\\').join('\\\\');
6+
p.split('/').join('\\\\');
7+
returnp;
8+
};

‎tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"files": [
1919
"src/importPaths.ts",
2020
"src/index.ts",
21+
"src/system.ts",
2122
"src/typings/chai/chai.d.ts",
2223
"src/typings/cr/cr.d.ts",
2324
"src/typings/cr/globals.d.ts",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp