Skip to content

Commit bc3feba

Browse files
committed
Changed options name and added test to support NODE_PATH
1 parent d37a356 commit bc3feba

File tree

6 files changed

+33
-13
lines changed

6 files changed

+33
-13
lines changed

cli.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (debug.enabled) {
1717
require('time-require');
1818
}
1919

20+
var path = require('path');
2021
var updateNotifier = require('update-notifier');
2122
var figures = require('figures');
2223
var arrify = require('arrify');
@@ -93,20 +94,22 @@ if (cli.flags.init) {
9394
return;
9495
}
9596

96-
var additionalPaths = [];
97+
var nodePaths;
9798
if (process.env.NODE_PATH) {
98-
var osSplitChar = process.platform === 'win32' ? ';' : ':';
99-
process.env.NODE_PATH.split(osSplitChar).forEach(function (additionalPath) {
100-
additionalPaths.push(path.resolve(opts.projectRoot, additionalPath));
101-
});
99+
var osSplitChar = process.platform === 'win32' ? ';' : ':';
100+
nodePaths = process.env.NODE_PATH.split(osSplitChar).map(function (p) {
101+
return path.resolve(process.cwd(), p)
102+
});
103+
} else {
104+
nodePaths = []
102105
}
103106

104107
var api = new Api(cli.input.length ? cli.input : arrify(conf.files), {
105108
failFast: cli.flags.failFast,
106109
serial: cli.flags.serial,
107110
require: arrify(cli.flags.require),
108111
cacheEnabled: cli.flags.cache !== false,
109-
additionalPaths: additionalPaths
112+
nodePaths: nodePaths
110113
});
111114

112115
var logger = new Logger();

lib/fork.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ module.exports = function (file, opts) {
1313
tty: process.stdout.isTTY ? {
1414
columns: process.stdout.columns,
1515
rows: process.stdout.rows
16-
} : false,
17-
additionalPaths: opts.additionalPaths
16+
} : false
1817
}, opts);
1918

2019
var ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), [JSON.stringify(opts)], {

lib/test-worker.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ var oldNodeModulesPaths = module.constructor._nodeModulePaths;
8686
module.constructor._nodeModulePaths = function () {
8787
var ret = oldNodeModulesPaths.apply(this, arguments);
8888
ret.push(nodeModulesDir);
89-
if (opts.additionalPaths && opts.additionalPaths.length > 0) {
90-
opts.additionalPaths.forEach(function (additionalPath) {
91-
ret.push(additionalPath);
92-
});
89+
if (opts.nodePaths && opts.nodePaths.length > 0) {
90+
ret = ret.concat(opts.nodePaths);
9391
}
9492
return ret;
9593
};

test/cli.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ function execCli(args, dirname, cb) {
1515
dirname = path.join(__dirname, dirname);
1616
}
1717

18-
var env = {};
18+
var env = {
19+
// This probably should be set only for the corresponding test
20+
NODE_PATH: 'node-paths/modules'
21+
};
1922

2023
if (process.env.AVA_APPVEYOR) {
2124
env.AVA_APPVEYOR = 1;
@@ -110,3 +113,10 @@ test('pkg-conf: cli takes precedence', function (t) {
110113
t.end();
111114
});
112115
});
116+
117+
test('handles NODE_PATH', function (t) {
118+
execCli('fixture/node-paths.js', function (err) {
119+
t.notOk(err);
120+
t.end();
121+
});
122+
});

test/fixture/node-paths.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import test from '../../';
2+
3+
import foo from 'nested/foo';
4+
5+
test('relative require', t => {
6+
t.is(foo(), 'bar');
7+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function() {
2+
return 'bar';
3+
}

0 commit comments

Comments
 (0)