summaryrefslogtreecommitdiff
path: root/deps/npm/lib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/lib/utils')
-rw-r--r--deps/npm/lib/utils/config/definitions.js15
-rw-r--r--deps/npm/lib/utils/get-identity.js45
2 files changed, 30 insertions, 30 deletions
diff --git a/deps/npm/lib/utils/config/definitions.js b/deps/npm/lib/utils/config/definitions.js
index c4be3a6584..92fbbd1e6d 100644
--- a/deps/npm/lib/utils/config/definitions.js
+++ b/deps/npm/lib/utils/config/definitions.js
@@ -811,6 +811,9 @@ define('global', {
default: false,
type: Boolean,
short: 'g',
+ deprecated: `
+ \`--global\`, \`--local\` are deprecated. Use \`--location=global\` instead.
+ `,
description: `
Operates in "global" mode, so that packages are installed into the
\`prefix\` folder instead of the current working directory. See
@@ -1179,12 +1182,24 @@ define('location', {
`,
description: `
When passed to \`npm config\` this refers to which config file to use.
+
+ When set to "global" mode, packages are installed into the \`prefix\` folder
+ instead of the current working directory. See
+ [folders](/configuring-npm/folders) for more on the differences in behavior.
+
+ * packages are installed into the \`{prefix}/lib/node_modules\` folder,
+ instead of the current working directory.
+ * bin files are linked to \`{prefix}/bin\`
+ * man pages are linked to \`{prefix}/share/man\`
`,
flatten: (key, obj, flatOptions) => {
flatten(key, obj, flatOptions)
if (flatOptions.global) {
flatOptions.location = 'global'
}
+ if (obj.location === 'global') {
+ flatOptions.global = true
+ }
},
})
diff --git a/deps/npm/lib/utils/get-identity.js b/deps/npm/lib/utils/get-identity.js
index e77c2eea4c..f4aedb89b3 100644
--- a/deps/npm/lib/utils/get-identity.js
+++ b/deps/npm/lib/utils/get-identity.js
@@ -1,39 +1,24 @@
const npmFetch = require('npm-registry-fetch')
-const needsAuthError = (msg) =>
- Object.assign(new Error(msg), { code: 'ENEEDAUTH' })
-
-module.exports = async (npm, opts = {}) => {
+module.exports = async (npm, opts) => {
const { registry } = opts
- if (!registry) {
- throw Object.assign(new Error('No registry specified.'), { code: 'ENOREGISTRY' })
- }
// First, check if we have a user/pass-based auth
const creds = npm.config.getCredentialsByURI(registry)
- const { username: usernameFromURI, token } = creds
+ if (creds.username) {
+ return creds.username
+ }
- if (usernameFromURI) {
- // Found username; return it
- return usernameFromURI
- } else if (token) {
- // No username, but we have a token; fetch the username from registry
- const registryData = await npmFetch.json('/-/whoami', {
- ...opts,
- })
- const { username: usernameFromRegistry } = registryData
- // Retrieved username from registry; return it
- if (usernameFromRegistry) {
- return usernameFromRegistry
- } else {
- // Didn't get username from registry; bad token
- throw needsAuthError(
- 'Your auth token is no longer valid. Please login again.'
- )
- }
- } else {
- // At this point, if they have a credentials object, it doesn't have a
- // token or auth in it. Probably just the default registry.
- throw needsAuthError('This command requires you to be logged in.')
+ // No username, but we have a token; fetch the username from registry
+ if (creds.token) {
+ const registryData = await npmFetch.json('/-/whoami', { ...opts })
+ return registryData.username
}
+
+ // At this point, even if they have a credentials object, it doesn't have a
+ // valid token.
+ throw Object.assign(
+ new Error('This command requires you to be logged in.'),
+ { code: 'ENEEDAUTH' }
+ )
}