@npmcli/config
Advanced tools
Comparing version 6.1.0 to 6.1.1
@@ -20,2 +20,10 @@ // TODO: set the scope config from package.json or explicit cli config | ||
const fileExists = (...p) => stat(resolve(...p)) | ||
.then((st) => st.isFile()) | ||
.catch(() => false) | ||
const dirExists = (...p) => stat(resolve(...p)) | ||
.then((st) => st.isDirectory()) | ||
.catch(() => false) | ||
const hasOwnProperty = (obj, key) => | ||
@@ -94,2 +102,3 @@ Object.prototype.hasOwnProperty.call(obj, key) | ||
cwd = process.cwd(), | ||
excludeNpmCwd = false, | ||
}) { | ||
@@ -122,2 +131,3 @@ // turn the definitions into nopt's weirdo syntax | ||
this.cwd = cwd | ||
this.excludeNpmCwd = excludeNpmCwd | ||
@@ -127,2 +137,3 @@ // set when we load configs | ||
this.localPrefix = null | ||
this.localPackage = null | ||
@@ -318,11 +329,7 @@ // defaults to env.HOME, but will always be *something* | ||
// returns `/foo/etc/npmrc`, but better to not change it at this point. | ||
settableGetter(data, 'globalconfig', () => | ||
resolve(this[_get]('prefix'), 'etc/npmrc')) | ||
settableGetter(data, 'globalconfig', () => resolve(this[_get]('prefix'), 'etc/npmrc')) | ||
} | ||
loadHome () { | ||
if (this.env.HOME) { | ||
return this.home = this.env.HOME | ||
} | ||
this.home = homedir() | ||
this.home = this.env.HOME || homedir() | ||
} | ||
@@ -338,3 +345,3 @@ | ||
} else if (this.platform === 'win32') { | ||
// c:\node\node.exe --> prefix=c:\node\ | ||
// c:\node\node.exe --> prefix=c:\node\ | ||
this.globalPrefix = dirname(this.execPath) | ||
@@ -608,2 +615,8 @@ } else { | ||
// if we have not detected a local package json yet, try now that we | ||
// have a local prefix | ||
if (this.localPackage == null) { | ||
this.localPackage = await fileExists(this.localPrefix, 'package.json') | ||
} | ||
if (this[_get]('global') === true || this[_get]('location') === 'global') { | ||
@@ -640,12 +653,13 @@ this.data.get('project').source = '(global mode enabled, ignored)' | ||
for (const p of walkUp(this.cwd)) { | ||
const hasNodeModules = await stat(resolve(p, 'node_modules')) | ||
.then((st) => st.isDirectory()) | ||
.catch(() => false) | ||
// HACK: this is an option set in tests to stop the local prefix from being set | ||
// on tests that are created inside the npm repo | ||
if (this.excludeNpmCwd && p === this.npmPath) { | ||
break | ||
} | ||
const hasPackageJson = await stat(resolve(p, 'package.json')) | ||
.then((st) => st.isFile()) | ||
.catch(() => false) | ||
const hasPackageJson = await fileExists(p, 'package.json') | ||
if (!this.localPrefix && (hasNodeModules || hasPackageJson)) { | ||
if (!this.localPrefix && (hasPackageJson || await dirExists(p, 'node_modules'))) { | ||
this.localPrefix = p | ||
this.localPackage = hasPackageJson | ||
@@ -674,7 +688,3 @@ // if workspaces are disabled, or we're in global mode, return now | ||
// see if there's a .npmrc file in the workspace, if so log a warning | ||
const hasNpmrc = await stat(resolve(this.localPrefix, '.npmrc')) | ||
.then((st) => st.isFile()) | ||
.catch(() => false) | ||
if (hasNpmrc) { | ||
if (await fileExists(this.localPrefix, '.npmrc')) { | ||
log.warn(`ignoring workspace config at ${this.localPrefix}/.npmrc`) | ||
@@ -687,2 +697,3 @@ } | ||
this.localPrefix = p | ||
this.localPackage = hasPackageJson | ||
log.info(`found workspace root at ${this.localPrefix}`) | ||
@@ -689,0 +700,0 @@ // we found a root, so we return now |
{ | ||
"name": "@npmcli/config", | ||
"version": "6.1.0", | ||
"version": "6.1.1", | ||
"files": [ | ||
@@ -36,4 +36,4 @@ "bin/", | ||
"@npmcli/eslint-config": "^4.0.0", | ||
"@npmcli/template-oss": "4.8.0", | ||
"tap": "^16.0.1" | ||
"@npmcli/template-oss": "4.11.0", | ||
"tap": "^16.3.2" | ||
}, | ||
@@ -54,4 +54,4 @@ "dependencies": { | ||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", | ||
"version": "4.8.0" | ||
"version": "4.11.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50613
1114