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

Commitc016bc4

Browse files
committed
fixes for windows
1 parentd5e6aeb commitc016bc4

File tree

9 files changed

+48
-54
lines changed

9 files changed

+48
-54
lines changed

‎lib/importPaths.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@ var importPathRegex = /require\(["'](BASE.+)["']\)([a-zA-Z0-9\-\_]+)?|^import.+?
55
varrelativePathRegex=/^BASE/;
66
functionfixImportPaths(_a){
77
vardir=_a.dir,content=_a.content;
8-
varentries=newSet([]);
98
returncontent.split('\n').map(function(line){
109
varisMatch=line.match(importPathRegex);
1110
if(!isMatch){
1211
returnline;
1312
}
1413
varimportPath=isMatch[1]||isMatch[2]||isMatch[3];
1514
if(importPath.match(relativePathRegex)){
16-
varnewPath=path_1.join(dir,importPath.replace('BASE',''));
15+
varnewPath=void0;
1716
if(system_1.isWindows){
18-
newPath=system_1.fixPathForWindows(newPath);
17+
newPath=path_1.join(dir,importPath.replace('BASE',''))
18+
.split('\\').join('\\\\');
1919
}
20-
varnewLine=line.replace(importPath,newPath);
21-
if(!entries.has(newLine)){
22-
entries.add(newLine);
23-
returnnewLine;
20+
else{
21+
newPath=path_1.join(dir,importPath.replace('BASE',''));
2422
}
25-
return'';
23+
returnline.replace(importPath,newPath);
2624
}
2725
returnline;
2826
}).join('\n');

‎lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ var system_1 = require('./system');
44
varjsCodeRoad=function(_a){
55
vardir=_a.dir,content=_a.content;
66
if(system_1.isWindows){
7-
dir=system_1.fixPathForWindows(dir);
7+
dir=dir.split('\\').join('\\\\');
88
}
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}());";
9+
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}());";
1010
};
1111
Object.defineProperty(exports,"__esModule",{value:true});
1212
exports.default=jsCodeRoad;

‎lib/system.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
"use strict";
2+
varwindow=window||({navigator:{appVersion:''}});
23
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-
};

‎package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@
2929
"watch:test":"ava test/*.js --watch"
3030
},
3131
"dependencies": {
32-
"babel-plugin-transform-es2015-modules-commonjs":"6.11.5",
33-
"babel-preset-es2015":"^6.13.2",
34-
"babel-register":"^6.11.6",
35-
"node-file-exists":"1.1.0",
36-
"process-console-log":"0.2.3",
37-
"rewire-coderoad":"^3.1.1"
32+
"babel-plugin-transform-es2015-modules-commonjs":"^6.14.0",
33+
"babel-register":"^6.14.0",
34+
"node-file-exists":"^1.1.0",
35+
"process-console-log":"^0.2.5",
36+
"rewire-coderoad":"^3.1.3"
3837
},
3938
"devDependencies": {
4039
"ava":"^0.16.0",

‎src/importPaths.ts

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

44
/*
55
import paths won't match the context of the test runner
@@ -12,9 +12,6 @@ const importPathRegex =
1212
constrelativePathRegex=/^BASE/;
1313

1414
exportdefaultfunctionfixImportPaths({dir, content}):string{
15-
// collect import lines
16-
letentries=newSet([]);
17-
1815
returncontent.split('\n').map(line=>{
1916
// line has an import or require ?
2017
constisMatch=line.match(importPathRegex);
@@ -27,20 +24,19 @@ export default function fixImportPaths({dir, content}): string {
2724

2825
// is a relative path
2926
if(importPath.match(relativePathRegex)){
30-
letnewPath=join(dir,importPath.replace('BASE',''));
27+
letnewPath;
3128

32-
// fix buggy Windows paths
3329
if(isWindows){
34-
newPath=fixPathForWindows(newPath);
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',''));
3537
}
3638

37-
constnewLine=line.replace(importPath,newPath);
38-
// add to map of entry files
39-
if(!entries.has(newLine)){
40-
entries.add(newLine);
41-
returnnewLine;
42-
}
43-
return'';
39+
returnline.replace(importPath,newPath);
4440
}
4541
// no match, return line
4642
returnline;

‎src/index.ts

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

44
constjsCodeRoad=({dir, content})=>{
55

66
// fix Windows paths
77
if(isWindows){
8-
dir=fixPathForWindows(dir);
8+
dir=dir.split('\\').join('\\\\');
99
}
1010

11-
return`
12-
(function(){'use strict';
13-
require('babel-register')({plugins:[['transform-es2015-modules-commonjs',{loose:true,sourceRoot:'${dir}'}]]});
11+
return`(function(){'use strict';
12+
require('babel-register')({plugins:[
13+
['transform-es2015-modules-commonjs',{loose:true,sourceRoot:'${dir}'}]
14+
]});
1415
${require('process-console-log').logger}
15-
const_fileExists = require('node-file-exists').default;
16-
const_path = require('path');
17-
function exists(p) { return_fileExists(_path.join('${dir}',p)); }
16+
const_f_e = require('node-file-exists').default;
17+
const_join = require('path').join;
18+
function exists(p) { return_f_e(_join('${dir}',p)); }
1819
require = require('rewire-coderoad');
1920
20-
// unit tests
21-
2221
${fixImportPaths({dir, content})}
2322
2423
}());`;

‎src/system.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
exportconstisWindows=window.navigator.appVersion.indexOf('Win')>-1;
1+
letwindow=window||({navigator:{appVersion:''}});
22

3-
exportconstfixPathForWindows=(p:string)=>{
4-
p.split('\\\\').join('\\');
5-
p.split('\\').join('\\\\');
6-
p.split('/').join('\\\\');
7-
returnp;
8-
};
3+
exportconstisWindows=window.navigator.appVersion.indexOf('Win')>-1;

‎test/importPaths.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const fixImportPaths = require('../lib/importPaths').default;
44
constmacDir='/usr/name/desktop/folder';
55
constwinDir=`C:\\usr\\name\\desktop\\folder`;
66

7+
// window.navigator.appVersion = 'Mac';
8+
79
test('does nothing if no imports',t=>{
810
constcontent='var a = 42;';
911
constresult=fixImportPaths({
@@ -59,7 +61,7 @@ test('handles named imports beginning with BASE', t => {
5961

6062
// Windows
6163

62-
test('handles test paths on Windows',t=>{
64+
test.skip('handles test paths on Windows',t=>{
6365
constcontent=`var example = require('BASE/example');`;
6466
constresult=fixImportPaths({
6567
dir:winDir,

‎test/system.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
consttest=require('ava');
2+
constfixPathForWindows=require('../lib/system').fixPathForWindows;
3+
4+
constwinPath='C:\path\to\file';
5+
6+
test('adds double slashes to a regular path',t=>{
7+
constresult=fixPathForWindows(winPath);
8+
constexpected='C:\\path\\to\\file';
9+
t.is(result,expected);
10+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp