Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84efafe

Browse files
committed
file path bug fixes
1 parent 4c5eea3 commit 84efafe

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

lib/getImportGlobalsSrc.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@
1010
*/
1111
const ignore = ['global', 'root', 'process', 'Buffer', 'clearImmediate', 'clearInterval', 'setTimeout', 'module', 'exports', 'require'];
1212

13-
function getImportGlobalsSrc(ignore) {
14-
var key,
15-
value,
16-
src = '',
17-
globalObj = typeof global === 'undefined' ? window : global;
13+
function getImportGlobalsSrc() {
14+
var key,
15+
value,
16+
src = '\n',
17+
globalObj = typeof global === 'undefined' ? window : global;
1818

19-
for (key in globalObj) { /* jshint forin: false */
20-
if (ignore.indexOf(key) !== -1) {
21-
continue;
22-
}
23-
// value = globalObj[key];
24-
25-
// key may be an invalid variable name (e.g. 'a-b')
26-
try {
27-
// eval('var ' + key);
28-
src += `var ${key} = global.${key}`;
29-
} catch(e) {}
19+
for (key in globalObj) { /* jshint forin: false */
20+
if (ignore.indexOf(key) !== -1 || key.match(/^__/)) {
21+
continue;
3022
}
23+
// value = globalObj[key];
24+
25+
// key may be an invalid variable name (e.g. 'a-b')
26+
try {
27+
// eval('var ' + key);
28+
src += `var ${key} = global.${key};`;
29+
} catch(e) {}
30+
}
3131

32-
return src;
32+
return src;
3333
}
3434

3535
module.exports = getImportGlobalsSrc;

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var fileExists = require('./fileExists');
1111
*/
1212
function rewire(filename) {
1313
// is not a node_module path
14-
if (!filename.match(/^[a-zA-Z\_]/)) {
14+
if (!filename.match(/^[a-zA-Z\_]/) || filename.match(/^[A-Z]:)) {
1515
if (!fileExists(filename)) {
1616
// create a __get__ mock to prevent tests breaking
1717
// when file does not exist

lib/rewire.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const Module = require('module');
3-
const { readFileSync, join } = require('fs');
3+
const { readFileSync } = require('fs');
44
const getImportGlobalsSrc = require('./getImportGlobalsSrc');
55
const getDefinePropertySrc = require('./getDefinePropertySrc');
66
const moduleEnv = require('./moduleEnv');
@@ -21,7 +21,7 @@ function internalRewire(parentModulePath, targetPath) {
2121
}
2222

2323
// Resolve full filename relative to the parent module
24-
targetPath = join(targetPath, parentModulePath);
24+
targetPath = Module._resolveFilename(targetPath, parentModulePath);
2525

2626
src = readFileSync(targetPath, 'utf8');
2727

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rewire-coderoad",
3-
"version": "3.1.3",
3+
"version": "3.1.4",
44
"description": "CodeRoad implementation to override 'require' in order to test globals",
55
"keywords": [
66
"coderoad",

0 commit comments

Comments
 (0)