PHP 8.2.30
Preview: version.js Size: 3.58 KB
//proc/thread-self/root/opt/alt/alt-nodejs19/root/usr/lib/node_modules/npm/lib/commands/version.js

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 workspaces = true
  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) {
    switch (args.length) {
      case 0:
        return this.listWorkspaces()
      case 1:
        return this.changeWorkspaces(args)
      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) {
    const prefix = this.npm.config.get('tag-version-prefix')
    await this.setWorkspaces()
    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 () {
    const results = {}
    await this.setWorkspaces()
    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

Directory Contents

Dirs: 0 × Files: 66

Name Size Perms Modified Actions
6.08 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
1.32 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
13.86 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
815 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
7.07 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
3.51 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
8.73 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
10.04 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
1.40 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
2.03 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
8.12 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
5.45 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
447 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
11.51 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
2.00 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
2.54 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
3.55 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
2.30 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
622 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
6.51 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
524 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
5.49 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
3.54 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
3.77 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
6.90 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
373 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
370 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
5.11 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
5.15 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
234 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
1.32 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
1.30 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
16.73 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
4.14 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
8.76 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
5.91 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
2.37 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
917 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
3.50 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
303 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
11.19 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
779 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
6.50 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
2.90 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
2.14 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
1.24 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
310 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
258 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
6.81 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
2.68 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
572 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
2.64 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
1.87 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
1.03 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
300 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
295 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
4.44 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
295 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
6.64 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
1.51 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
4.54 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
182 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download
1.71 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
3.58 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
14.38 KB lrw-r--r-- 2023-12-06 18:07:50
Edit Download
474 B lrw-r--r-- 2023-12-06 18:07:50
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).