Last change
on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
766 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | const path = require('path');
|
---|
3 | const pathKey = require('path-key');
|
---|
4 |
|
---|
5 | module.exports = opts => {
|
---|
6 | opts = Object.assign({
|
---|
7 | cwd: process.cwd(),
|
---|
8 | path: process.env[pathKey()]
|
---|
9 | }, opts);
|
---|
10 |
|
---|
11 | let prev;
|
---|
12 | let pth = path.resolve(opts.cwd);
|
---|
13 | const ret = [];
|
---|
14 |
|
---|
15 | while (prev !== pth) {
|
---|
16 | ret.push(path.join(pth, 'node_modules/.bin'));
|
---|
17 | prev = pth;
|
---|
18 | pth = path.resolve(pth, '..');
|
---|
19 | }
|
---|
20 |
|
---|
21 | // ensure the running `node` binary is used
|
---|
22 | ret.push(path.dirname(process.execPath));
|
---|
23 |
|
---|
24 | return ret.concat(opts.path).join(path.delimiter);
|
---|
25 | };
|
---|
26 |
|
---|
27 | module.exports.env = opts => {
|
---|
28 | opts = Object.assign({
|
---|
29 | env: process.env
|
---|
30 | }, opts);
|
---|
31 |
|
---|
32 | const env = Object.assign({}, opts.env);
|
---|
33 | const path = pathKey({env});
|
---|
34 |
|
---|
35 | opts.path = env[path];
|
---|
36 | env[path] = module.exports(opts);
|
---|
37 |
|
---|
38 | return env;
|
---|
39 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.