PATH:
usr
/
lib
/
node_modules
/
npm
/
lib
/
commands
const libnpmversion = require('libnpmversion') const { resolve } = require('path') const { promisify } = require('util') const readFile = promisify(require('fs').readFile) const updateWorkspaces = require('../workspaces/update-workspaces.js') const BaseCommand = require('../base-command.js') class Version extends BaseCommand { static description = 'Bump a package version' static name = 'version' static params = [ 'allow-same-version', 'commit-hooks', 'git-tag-version', 'json', 'preid', 'sign-git-tag', 'workspace', 'workspaces', 'workspaces-update', 'include-workspace-root', ] static ignoreImplicitWorkspace = false /* eslint-disable-next-line max-len */ static usage = ['[<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]'] async completion (opts) { const { conf: { argv: { remain }, }, } = opts if (remain.length > 2) { return [] } return [ 'major', 'minor', 'patch', 'premajor', 'preminor', 'prepatch', 'prerelease', 'from-git', ] } async exec (args) { switch (args.length) { case 0: return this.list() case 1: return this.change(args) default: throw this.usageError() } } async execWorkspaces (args, filters) { switch (args.length) { case 0: return this.listWorkspaces(filters) case 1: return this.changeWorkspaces(args, filters) default: throw this.usageError() } } async change (args) { const prefix = this.npm.config.get('tag-version-prefix') const version = await libnpmversion(args[0], { ...this.npm.flatOptions, path: this.npm.prefix, }) return this.npm.output(`${prefix}${version}`) } async changeWorkspaces (args, filters) { const prefix = this.npm.config.get('tag-version-prefix') await this.setWorkspaces(filters) const updatedWorkspaces = [] for (const [name, path] of this.workspaces) { this.npm.output(name) const version = await libnpmversion(args[0], { ...this.npm.flatOptions, 'git-tag-version': false, path, }) updatedWorkspaces.push(name) this.npm.output(`${prefix}${version}`) } return this.update(updatedWorkspaces) } async list (results = {}) { const pj = resolve(this.npm.prefix, 'package.json') const pkg = await readFile(pj, 'utf8') .then(data => JSON.parse(data)) .catch(() => ({})) if (pkg.name && pkg.version) { results[pkg.name] = pkg.version } results.npm = this.npm.version for (const [key, version] of Object.entries(process.versions)) { results[key] = version } if (this.npm.config.get('json')) { this.npm.output(JSON.stringify(results, null, 2)) } else { this.npm.output(results) } } async listWorkspaces (filters) { const results = {} await this.setWorkspaces(filters) for (const path of this.workspacePaths) { const pj = resolve(path, 'package.json') // setWorkspaces has already parsed package.json so we know it won't error const pkg = await readFile(pj, 'utf8').then(data => JSON.parse(data)) if (pkg.name && pkg.version) { results[pkg.name] = pkg.version } } return this.list(results) } async update (workspaces) { const { config, flatOptions, localPrefix, } = this.npm await updateWorkspaces({ config, flatOptions, localPrefix, npm: this.npm, workspaces, }) } } module.exports = Version
[-] star.js
[edit]
[-] ping.js
[edit]
[-] stop.js
[edit]
[-] team.js
[edit]
[-] run-script.js
[edit]
[-] edit.js
[edit]
[-] explore.js
[edit]
[-] access.js
[edit]
[-] explain.js
[edit]
[-] repo.js
[edit]
[-] root.js
[edit]
[-] completion.js
[edit]
[-] bugs.js
[edit]
[-] restart.js
[edit]
[+]
..
[-] pack.js
[edit]
[-] ll.js
[edit]
[-] install-test.js
[edit]
[-] find-dupes.js
[edit]
[-] unstar.js
[edit]
[-] org.js
[edit]
[-] dedupe.js
[edit]
[-] birthday.js
[edit]
[-] test.js
[edit]
[-] audit.js
[edit]
[-] install-ci-test.js
[edit]
[-] cache.js
[edit]
[-] outdated.js
[edit]
[-] link.js
[edit]
[-] diff.js
[edit]
[-] logout.js
[edit]
[-] install.js
[edit]
[-] fund.js
[edit]
[-] ci.js
[edit]
[-] get.js
[edit]
[-] profile.js
[edit]
[-] uninstall.js
[edit]
[-] init.js
[edit]
[-] prune.js
[edit]
[-] dist-tag.js
[edit]
[-] search.js
[edit]
[-] view.js
[edit]
[-] owner.js
[edit]
[-] rebuild.js
[edit]
[-] query.js
[edit]
[-] start.js
[edit]
[-] config.js
[edit]
[-] update.js
[edit]
[-] docs.js
[edit]
[-] help.js
[edit]
[-] ls.js
[edit]
[-] deprecate.js
[edit]
[-] exec.js
[edit]
[-] hook.js
[edit]
[-] publish.js
[edit]
[-] prefix.js
[edit]
[-] adduser.js
[edit]
[-] shrinkwrap.js
[edit]
[-] help-search.js
[edit]
[-] stars.js
[edit]
[-] doctor.js
[edit]
[-] set.js
[edit]
[-] whoami.js
[edit]
[-] version.js
[edit]
[-] pkg.js
[edit]
[-] bin.js
[edit]
[-] token.js
[edit]
[-] set-script.js
[edit]
[-] unpublish.js
[edit]