Skip to content

Commit eee0a7b

Browse files
committed
minimized version
1 parent 4dee5c3 commit eee0a7b

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

lib/importPaths.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
"use strict";
2-
var path_1 = require('path');
3-
var importPathRegex = /require\(["'](BASE.+)["']\)([a-zA-Z0-9\-\_]+)?|^import.+?\s?["'](BASE.+)["'];?$/m;
4-
var relativePathRegex = /^BASE/;
5-
function fixImportPaths(_a) {
6-
var dir = _a.dir, content = _a.content;
7-
return content.split('\n').map(function (line) {
8-
var isMatch = line.match(importPathRegex);
2+
const path_1 = require('path');
3+
const importPathRegex = /require\(["'](BASE.+)["']\)([a-zA-Z0-9\-\_]+)?|^import.+?\s?["'](BASE.+)["'];?$/m;
4+
const relativePathRegex = /^BASE/;
5+
function fixImportPaths({ dir, content }) {
6+
return content.split('\n').map(line => {
7+
const isMatch = line.match(importPathRegex);
98
if (!isMatch) {
109
return line;
1110
}
12-
var importPath = isMatch[1] || isMatch[2] || isMatch[3];
11+
let importPath = isMatch[1] || isMatch[2] || isMatch[3];
1312
if (importPath.match(relativePathRegex)) {
14-
var newPath = path_1.join(dir, importPath.replace('BASE', ''))
13+
let newPath = path_1.join(dir, importPath.replace('BASE', ''))
1514
.split('\\').join('\\\\');
1615
return line.replace(importPath, newPath);
1716
}

lib/index.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
"use strict";
2-
var importPaths_1 = require('./importPaths');
3-
var jsCodeRoad = function (_a) {
4-
var dir = _a.dir, content = _a.content;
5-
dir = dir.split('\\').join('\\\\');
6-
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}());";
2+
const importPaths_1 = require('./importPaths');
3+
const jsCodeRoad = ({ dir, content }) => {
4+
// fix Windows paths
5+
dir = dir.split('\\').join('\\\\');
6+
7+
return `(function(){'use strict';
8+
require('babel-register')({plugins:[
9+
['transform-es2015-modules-commonjs',{loose:true,sourceRoot:'${dir}'}]
10+
]});
11+
const _f_e = require('node-file-exists').default;
12+
const _join = require('path').join;
13+
function exists(p) { return _f_e(_join('${dir}',p)); }
14+
console.log = require('process-console-log');
15+
require = require('rewire-coderoad');
16+
17+
${fixImportPaths({dir, content})}
18+
19+
}());`;
720
};
821
Object.defineProperty(exports, "__esModule", { value: true });
922
exports.default = jsCodeRoad;

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-coderoad",
3-
"version": "0.1.5",
3+
"version": "0.2.0",
44
"description": "bundled javascript features for coderoad test runners",
55
"keywords": [
66
"coderoad",
@@ -32,7 +32,6 @@
3232
"babel-plugin-transform-es2015-modules-commonjs": "^6.14.0",
3333
"babel-register": "^6.14.0",
3434
"node-file-exists": "^1.1.0",
35-
"process-console-log": "^0.2.5",
3635
"rewire-coderoad": "^3.1.4"
3736
},
3837
"devDependencies": {

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const jsCodeRoad = ({dir, content}) => {
99
require('babel-register')({plugins:[
1010
['transform-es2015-modules-commonjs',{loose:true,sourceRoot:'${dir}'}]
1111
]});
12-
${require('process-console-log').logger}
12+
function _g_t(a){var b=isObject(a);if(b&&b[1]){var c=b[1].toLowerCase();return\"number\"===c?a!==a?\"NaN\":\"number\":c}return typeof a}function _a_t(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];return JSON.stringify(a.map(function(a){var b=_g_t(a);switch(b){case\"object\":case\"array\":a=JSON.stringify(a),a=util_1.inspect(a,inspectOptions),a=a.substring(1,a.length-1);break;case\"undefined\":case\"null\":case\"NaN\":return{type:b}}return{type:b,output:a}}))}var util_1=require(\"util\"),inspectOptions={depth:null};if(console&&console.log){var originalLog_1=console.log;console.log=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];originalLog_1.apply(this,[_a_t(a)])}}var isObject=function(a){var b=Object.prototype.toString.call(a);return b.match(/^\[object ([A-Z][a-z]+)\]/)};
1313
const _f_e = require('node-file-exists').default;
1414
const _join = require('path').join;
1515
function exists(p) { return _f_e(_join('${dir}',p)); }

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "ES5",
3+
"target": "ES6",
44
"module": "commonjs",
55
"declaration": false,
66
"noImplicitAny": false,

0 commit comments

Comments
 (0)