1 | 'use strict'
|
2 |
|
3 | const debug = require('debug')('elint:env')
|
4 | const path = require('path')
|
5 | const isNpm = require('./utils/is-npm')
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function getInitCwd () {
|
14 | if (process.env.INIT_CWD) {
|
15 | debug(`process.env.INIT_CWD: ${process.env.INIT_CWD}`)
|
16 | return process.env.INIT_CWD
|
17 | }
|
18 |
|
19 | const cwd = process.cwd()
|
20 |
|
21 | debug(`process.cwd(): ${cwd}`)
|
22 |
|
23 |
|
24 | return cwd.split(`${path.sep}node_modules${path.sep}`)[0]
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | const getBaseDir = () => {
|
33 |
|
34 | const baseDir = isNpm ? getInitCwd() : process.cwd()
|
35 |
|
36 | debug(`isNpm: ${isNpm}`)
|
37 | debug(`base dir: ${baseDir}`)
|
38 |
|
39 | return baseDir
|
40 | }
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | const getNodeModulesDir = () => {
|
48 | const nodeModulesDir = path.join(getBaseDir(), 'node_modules')
|
49 |
|
50 | debug(`node_modules dir: ${nodeModulesDir}`)
|
51 | return nodeModulesDir
|
52 | }
|
53 |
|
54 | module.exports = {
|
55 | getBaseDir,
|
56 | getNodeModulesDir
|
57 | }
|