| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3d89623 commit 9711ccf
285 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -159,7 +159,7 @@ <h3 id="description">Description</h3> | |||
| 159 | 159 | the results to only the paths to the packages named. Note that nested | |
| 160 | 160 | packages will <em>also</em> show the paths to the specified packages. For | |
| 161 | 161 | example, running <code>npm ls promzard</code> in npm’s source tree will show:</p> | |
| 162 | - <pre lang="bash"><code>npm@8.1.2 /path/to/npm | ||
| 162 | + <pre lang="bash"><code>npm@8.1.3 /path/to/npm | ||
| 163 | 163 | └─┬ init-package-json@0.0.4 | |
| 164 | 164 | └── promzard@0.1.5 | |
| 165 | 165 | </code></pre> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,7 +148,7 @@ <h2 id="table-of-contents">Table of contents</h2> | |||
| 148 | 148 | <pre lang="bash"><code>npm <command> [args] | |
| 149 | 149 | </code></pre> | |
| 150 | 150 | <h3 id="version">Version</h3> | |
| 151 | - <p>8.1.2</p> | ||
| 151 | + <p>8.1.3</p> | ||
| 152 | 152 | <h3 id="description">Description</h3> | |
| 153 | 153 | <p>npm is the package manager for the Node JavaScript platform. It puts | |
| 154 | 154 | modules in place so that node can find them, and manages dependency | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,4 @@ | |||
| 1 | - if (require.main === module) { | ||
| 1 | + if (require.main === module) | ||
| 2 | 2 | require('./lib/cli.js')(process) | |
| 3 | - } else { | ||
| 3 | + else | ||
| 4 | 4 | throw new Error('The programmatic API was removed in npm v8.0.0') | |
| 5 | - } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | // a list of workspace names and passes it on to new Arborist() to | |
| 3 | 3 | // be able to run a filtered Arborist.reify() at some point. | |
| 4 | 4 | ||
| 5 | - const BaseCommand = require('../base-command.js') | ||
| 5 | + const BaseCommand = require('./base-command.js') | ||
| 6 | 6 | class ArboristCmd extends BaseCommand { | |
| 7 | 7 | get isArboristCmd () { | |
| 8 | 8 | return true | |
@@ -17,12 +17,9 @@ class ArboristCmd extends BaseCommand { | |||
| 17 | 17 | ] | |
| 18 | 18 | } | |
| 19 | 19 | ||
| 20 | - execWorkspaces (args, filters, cb) { | ||
| 21 | - this.setWorkspaces(filters, true) | ||
| 22 | - .then(() => { | ||
| 23 | - this.exec(args, cb) | ||
| 24 | - }) | ||
| 25 | - .catch(er => cb(er)) | ||
| 20 | + async execWorkspaces (args, filters) { | ||
| 21 | + await this.setWorkspaces(filters) | ||
| 22 | + return this.exec(args) | ||
| 26 | 23 | } | |
| 27 | 24 | } | |
| 28 | 25 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - // Base class for npm.commands[cmd] | ||
| 1 | + // Base class for npm commands | ||
| 2 | 2 | const usageUtil = require('./utils/usage.js') | |
| 3 | 3 | const ConfigDefinitions = require('./utils/config/definitions.js') | |
| 4 | 4 | const getWorkspaces = require('./workspaces/get-workspaces.js') | |
@@ -53,19 +53,15 @@ class BaseCommand { | |||
| 53 | 53 | return results | |
| 54 | 54 | } | |
| 55 | 55 | ||
| 56 | - usageError (msg) { | ||
| 57 | - if (!msg) { | ||
| 58 | - return Object.assign(new Error(`\nUsage: ${this.usage}`), { | ||
| 59 | - code: 'EUSAGE', | ||
| 60 | - }) | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - return Object.assign(new Error(`\nUsage: ${msg}\n\n${this.usage}`), { | ||
| 56 | + usageError (prefix = '') { | ||
| 57 | + if (prefix) | ||
| 58 | + prefix += '\n\n' | ||
| 59 | + return Object.assign(new Error(`\nUsage: ${prefix}${this.usage}`), { | ||
| 64 | 60 | code: 'EUSAGE', | |
| 65 | 61 | }) | |
| 66 | 62 | } | |
| 67 | 63 | ||
| 68 | - execWorkspaces (args, filters, cb) { | ||
| 64 | + async execWorkspaces (args, filters) { | ||
| 69 | 65 | throw Object.assign( | |
| 70 | 66 | new Error('This command does not support workspaces.'), | |
| 71 | 67 | { code: 'ENOWORKSPACES' } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,8 @@ module.exports = async (process) => { | |||
| 18 | 18 | ||
| 19 | 19 | checkForUnsupportedNode() | |
| 20 | 20 | ||
| 21 | - const npm = require('../lib/npm.js') | ||
| 21 | + const Npm = require('../lib/npm.js') | ||
| 22 | + const npm = new Npm() | ||
| 22 | 23 | const exitHandler = require('../lib/utils/exit-handler.js') | |
| 23 | 24 | exitHandler.setNpm(npm) | |
| 24 | 25 | ||
@@ -38,6 +39,7 @@ module.exports = async (process) => { | |||
| 38 | 39 | ||
| 39 | 40 | const updateNotifier = require('../lib/utils/update-notifier.js') | |
| 40 | 41 | ||
| 42 | + let cmd | ||
| 41 | 43 | // now actually fire up npm and run the command. | |
| 42 | 44 | // this is how to use npm programmatically: | |
| 43 | 45 | try { | |
@@ -55,24 +57,23 @@ module.exports = async (process) => { | |||
| 55 | 57 | ||
| 56 | 58 | updateNotifier(npm) | |
| 57 | 59 | ||
| 58 | - const cmd = npm.argv.shift() | ||
| 60 | + cmd = npm.argv.shift() | ||
| 59 | 61 | if (!cmd) { | |
| 60 | - npm.output(npm.usage) | ||
| 62 | + npm.output(await npm.usage) | ||
| 61 | 63 | process.exitCode = 1 | |
| 62 | 64 | return exitHandler() | |
| 63 | 65 | } | |
| 64 | 66 | ||
| 65 | - const impl = npm.commands[cmd] | ||
| 66 | - if (!impl) { | ||
| 67 | + await npm.exec(cmd, npm.argv) | ||
| 68 | + exitHandler() | ||
| 69 | + } catch (err) { | ||
| 70 | + if (err.code === 'EUNKNOWNCOMMAND') { | ||
| 67 | 71 | const didYouMean = require('./utils/did-you-mean.js') | |
| 68 | 72 | const suggestions = await didYouMean(npm, npm.localPrefix, cmd) | |
| 69 | 73 | npm.output(`Unknown command: "${cmd}"${suggestions}\n\nTo see a list of supported npm commands, run:\n npm help`) | |
| 70 | 74 | process.exitCode = 1 | |
| 71 | 75 | return exitHandler() | |
| 72 | 76 | } | |
| 73 | - | ||
| 74 | - impl(npm.argv, exitHandler) | ||
| 75 | - } catch (err) { | ||
| 76 | 77 | return exitHandler(err) | |
| 77 | 78 | } | |
| 78 | 79 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,9 +3,9 @@ const path = require('path') | |||
| 3 | 3 | const libaccess = require('libnpmaccess') | |
| 4 | 4 | const readPackageJson = require('read-package-json-fast') | |
| 5 | 5 | ||
| 6 | - const otplease = require('./utils/otplease.js') | ||
| 7 | - const getIdentity = require('./utils/get-identity.js') | ||
| 8 | - const BaseCommand = require('./base-command.js') | ||
| 6 | + const otplease = require('../utils/otplease.js') | ||
| 7 | + const getIdentity = require('../utils/get-identity.js') | ||
| 8 | + const BaseCommand = require('../base-command.js') | ||
| 9 | 9 | ||
| 10 | 10 | const subcommands = [ | |
| 11 | 11 | 'public', | |
@@ -76,11 +76,7 @@ class Access extends BaseCommand { | |||
| 76 | 76 | } | |
| 77 | 77 | } | |
| 78 | 78 | ||
| 79 | - exec (args, cb) { | ||
| 80 | - this.access(args).then(() => cb()).catch(cb) | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - async access ([cmd, ...args]) { | ||
| 79 | + async exec ([cmd, ...args]) { | ||
| 84 | 80 | if (!cmd) | |
| 85 | 81 | throw this.usageError('Subcommand is required.') | |
| 86 | 82 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,11 @@ | |||
| 1 | 1 | const log = require('npmlog') | |
| 2 | - const replaceInfo = require('./utils/replace-info.js') | ||
| 3 | - const BaseCommand = require('./base-command.js') | ||
| 2 | + const replaceInfo = require('../utils/replace-info.js') | ||
| 3 | + const BaseCommand = require('../base-command.js') | ||
| 4 | 4 | const authTypes = { | |
| 5 | - legacy: require('./auth/legacy.js'), | ||
| 6 | - oauth: require('./auth/oauth.js'), | ||
| 7 | - saml: require('./auth/saml.js'), | ||
| 8 | - sso: require('./auth/sso.js'), | ||
| 5 | + legacy: require('../auth/legacy.js'), | ||
| 6 | + oauth: require('../auth/oauth.js'), | ||
| 7 | + saml: require('../auth/saml.js'), | ||
| 8 | + sso: require('../auth/sso.js'), | ||
| 9 | 9 | } | |
| 10 | 10 | ||
| 11 | 11 | class AddUser extends BaseCommand { | |
@@ -24,11 +24,7 @@ class AddUser extends BaseCommand { | |||
| 24 | 24 | ] | |
| 25 | 25 | } | |
| 26 | 26 | ||
| 27 | - exec (args, cb) { | ||
| 28 | - this.adduser(args).then(() => cb()).catch(cb) | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - async adduser (args) { | ||
| 27 | + async exec (args) { | ||
| 32 | 28 | const { scope } = this.npm.flatOptions | |
| 33 | 29 | const registry = this.getRegistry(this.npm.flatOptions) | |
| 34 | 30 | const auth = this.getAuthType(this.npm.flatOptions) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,8 @@ | |||
| 1 | 1 | const Arborist = require('@npmcli/arborist') | |
| 2 | 2 | const auditReport = require('npm-audit-report') | |
| 3 | - const reifyFinish = require('./utils/reify-finish.js') | ||
| 4 | - const auditError = require('./utils/audit-error.js') | ||
| 5 | - const ArboristWorkspaceCmd = require('./workspaces/arborist-cmd.js') | ||
| 3 | + const reifyFinish = require('../utils/reify-finish.js') | ||
| 4 | + const auditError = require('../utils/audit-error.js') | ||
| 5 | + const ArboristWorkspaceCmd = require('../arborist-cmd.js') | ||
| 6 | 6 | ||
| 7 | 7 | class Audit extends ArboristWorkspaceCmd { | |
| 8 | 8 | /* istanbul ignore next - see test/lib/load-all-commands.js */ | |
@@ -47,11 +47,7 @@ class Audit extends ArboristWorkspaceCmd { | |||
| 47 | 47 | } | |
| 48 | 48 | } | |
| 49 | 49 | ||
| 50 | - exec (args, cb) { | ||
| 51 | - this.audit(args).then(() => cb()).catch(cb) | ||
| 52 | - } | ||
| 53 | - | ||
| 54 | - async audit (args) { | ||
| 50 | + async exec (args) { | ||
| 55 | 51 | const reporter = this.npm.config.get('json') ? 'json' : 'detail' | |
| 56 | 52 | const opts = { | |
| 57 | 53 | ...this.npm.flatOptions, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | - const envPath = require('./utils/path.js') | ||
| 2 | - const BaseCommand = require('./base-command.js') | ||
| 1 | + const envPath = require('../utils/path.js') | ||
| 2 | + const BaseCommand = require('../base-command.js') | ||
| 3 | 3 | ||
| 4 | 4 | class Bin extends BaseCommand { | |
| 5 | 5 | static get description () { | |
@@ -14,11 +14,7 @@ class Bin extends BaseCommand { | |||
| 14 | 14 | return ['global'] | |
| 15 | 15 | } | |
| 16 | 16 | ||
| 17 | - exec (args, cb) { | ||
| 18 | - this.bin(args).then(() => cb()).catch(cb) | ||
| 19 | - } | ||
| 20 | - | ||
| 21 | - async bin (args) { | ||
| 17 | + async exec (args) { | ||
| 22 | 18 | const b = this.npm.bin | |
| 23 | 19 | this.npm.output(b) | |
| 24 | 20 | if (this.npm.config.get('global') && !envPath.includes(b)) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments