@npmcli/config 6.1.0 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +30 -19
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -17,6 +17,14 @@ const {
|
|
|
17
17
|
mkdir,
|
|
18
18
|
} = require('fs/promises')
|
|
19
19
|
|
|
20
|
+
const fileExists = (...p) => stat(resolve(...p))
|
|
21
|
+
.then((st) => st.isFile())
|
|
22
|
+
.catch(() => false)
|
|
23
|
+
|
|
24
|
+
const dirExists = (...p) => stat(resolve(...p))
|
|
25
|
+
.then((st) => st.isDirectory())
|
|
26
|
+
.catch(() => false)
|
|
27
|
+
|
|
20
28
|
const hasOwnProperty = (obj, key) =>
|
|
21
29
|
Object.prototype.hasOwnProperty.call(obj, key)
|
|
22
30
|
|
|
@@ -90,6 +98,7 @@ class Config {
|
|
|
90
98
|
platform = process.platform,
|
|
91
99
|
execPath = process.execPath,
|
|
92
100
|
cwd = process.cwd(),
|
|
101
|
+
excludeNpmCwd = false,
|
|
93
102
|
}) {
|
|
94
103
|
// turn the definitions into nopt's weirdo syntax
|
|
95
104
|
this.definitions = definitions
|
|
@@ -117,10 +126,12 @@ class Config {
|
|
|
117
126
|
this.execPath = execPath
|
|
118
127
|
this.platform = platform
|
|
119
128
|
this.cwd = cwd
|
|
129
|
+
this.excludeNpmCwd = excludeNpmCwd
|
|
120
130
|
|
|
121
131
|
// set when we load configs
|
|
122
132
|
this.globalPrefix = null
|
|
123
133
|
this.localPrefix = null
|
|
134
|
+
this.localPackage = null
|
|
124
135
|
|
|
125
136
|
// defaults to env.HOME, but will always be *something*
|
|
126
137
|
this.home = null
|
|
@@ -311,15 +322,11 @@ class Config {
|
|
|
311
322
|
// default the globalconfig file to that location, instead of the default
|
|
312
323
|
// global prefix. It's weird that `npm get globalconfig --prefix=/foo`
|
|
313
324
|
// returns `/foo/etc/npmrc`, but better to not change it at this point.
|
|
314
|
-
settableGetter(data, 'globalconfig', () =>
|
|
315
|
-
resolve(this[_get]('prefix'), 'etc/npmrc'))
|
|
325
|
+
settableGetter(data, 'globalconfig', () => resolve(this[_get]('prefix'), 'etc/npmrc'))
|
|
316
326
|
}
|
|
317
327
|
|
|
318
328
|
loadHome () {
|
|
319
|
-
|
|
320
|
-
return this.home = this.env.HOME
|
|
321
|
-
}
|
|
322
|
-
this.home = homedir()
|
|
329
|
+
this.home = this.env.HOME || homedir()
|
|
323
330
|
}
|
|
324
331
|
|
|
325
332
|
loadGlobalPrefix () {
|
|
@@ -330,7 +337,7 @@ class Config {
|
|
|
330
337
|
if (this.env.PREFIX) {
|
|
331
338
|
this.globalPrefix = this.env.PREFIX
|
|
332
339
|
} else if (this.platform === 'win32') {
|
|
333
|
-
|
|
340
|
+
// c:\node\node.exe --> prefix=c:\node\
|
|
334
341
|
this.globalPrefix = dirname(this.execPath)
|
|
335
342
|
} else {
|
|
336
343
|
// /usr/local/bin/node --> prefix=/usr/local
|
|
@@ -599,6 +606,12 @@ class Config {
|
|
|
599
606
|
// we return to make sure localPrefix is set
|
|
600
607
|
await this.loadLocalPrefix()
|
|
601
608
|
|
|
609
|
+
// if we have not detected a local package json yet, try now that we
|
|
610
|
+
// have a local prefix
|
|
611
|
+
if (this.localPackage == null) {
|
|
612
|
+
this.localPackage = await fileExists(this.localPrefix, 'package.json')
|
|
613
|
+
}
|
|
614
|
+
|
|
602
615
|
if (this[_get]('global') === true || this[_get]('location') === 'global') {
|
|
603
616
|
this.data.get('project').source = '(global mode enabled, ignored)'
|
|
604
617
|
this.sources.set(this.data.get('project').source, 'project')
|
|
@@ -630,16 +643,17 @@ class Config {
|
|
|
630
643
|
const isGlobal = this[_get]('global') || this[_get]('location') === 'global'
|
|
631
644
|
|
|
632
645
|
for (const p of walkUp(this.cwd)) {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
646
|
+
// HACK: this is an option set in tests to stop the local prefix from being set
|
|
647
|
+
// on tests that are created inside the npm repo
|
|
648
|
+
if (this.excludeNpmCwd && p === this.npmPath) {
|
|
649
|
+
break
|
|
650
|
+
}
|
|
636
651
|
|
|
637
|
-
const hasPackageJson = await
|
|
638
|
-
.then((st) => st.isFile())
|
|
639
|
-
.catch(() => false)
|
|
652
|
+
const hasPackageJson = await fileExists(p, 'package.json')
|
|
640
653
|
|
|
641
|
-
if (!this.localPrefix && (
|
|
654
|
+
if (!this.localPrefix && (hasPackageJson || await dirExists(p, 'node_modules'))) {
|
|
642
655
|
this.localPrefix = p
|
|
656
|
+
this.localPackage = hasPackageJson
|
|
643
657
|
|
|
644
658
|
// if workspaces are disabled, or we're in global mode, return now
|
|
645
659
|
if (cliWorkspaces === false || isGlobal) {
|
|
@@ -663,11 +677,7 @@ class Config {
|
|
|
663
677
|
for (const w of workspaces.values()) {
|
|
664
678
|
if (w === this.localPrefix) {
|
|
665
679
|
// see if there's a .npmrc file in the workspace, if so log a warning
|
|
666
|
-
|
|
667
|
-
.then((st) => st.isFile())
|
|
668
|
-
.catch(() => false)
|
|
669
|
-
|
|
670
|
-
if (hasNpmrc) {
|
|
680
|
+
if (await fileExists(this.localPrefix, '.npmrc')) {
|
|
671
681
|
log.warn(`ignoring workspace config at ${this.localPrefix}/.npmrc`)
|
|
672
682
|
}
|
|
673
683
|
|
|
@@ -675,6 +685,7 @@ class Config {
|
|
|
675
685
|
const { data } = this.data.get('default')
|
|
676
686
|
data.workspace = [this.localPrefix]
|
|
677
687
|
this.localPrefix = p
|
|
688
|
+
this.localPackage = hasPackageJson
|
|
678
689
|
log.info(`found workspace root at ${this.localPrefix}`)
|
|
679
690
|
// we found a root, so we return now
|
|
680
691
|
return
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@npmcli/config",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"files": [
|
|
5
5
|
"bin/",
|
|
6
6
|
"lib/"
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@npmcli/eslint-config": "^4.0.0",
|
|
36
|
-
"@npmcli/template-oss": "4.
|
|
37
|
-
"tap": "^16.
|
|
36
|
+
"@npmcli/template-oss": "4.11.0",
|
|
37
|
+
"tap": "^16.3.2"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@npmcli/map-workspaces": "^3.0.0",
|
|
@@ -50,6 +50,6 @@
|
|
|
50
50
|
},
|
|
51
51
|
"templateOSS": {
|
|
52
52
|
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
|
53
|
-
"version": "4.
|
|
53
|
+
"version": "4.11.0"
|
|
54
54
|
}
|
|
55
55
|
}
|