Skip to content

Commit

Permalink
fix: use native spawn, new inquirer (#788)
Browse files Browse the repository at this point in the history
* fix: use native spawn, new inquirer

* chore(release): 4.2.6-qa.0

---------

Co-authored-by: svc-cli-bot <[email protected]>
  • Loading branch information
mshanemc and svc-cli-bot authored Apr 16, 2024
1 parent 3fa50fa commit a53ff7a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 675 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ EXAMPLES
$ oclif-example update --available
```

_See code: [src/commands/update.ts](https://github.com/oclif/plugin-update/blob/4.2.5/src/commands/update.ts)_
_See code: [src/commands/update.ts](https://github.com/oclif/plugin-update/blob/4.2.6-qa.0/src/commands/update.ts)_

<!-- commandsstop -->

Expand Down
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"name": "@oclif/plugin-update",
"version": "4.2.5",
"version": "4.2.6-qa.0",
"author": "Salesforce",
"bugs": "https://github.com/oclif/plugin-update/issues",
"dependencies": {
"@inquirer/select": "^2.3.1",
"@oclif/core": "^3.21.0",
"chalk": "^5",
"cross-spawn": "^7.0.3",
"debug": "^4.3.1",
"filesize": "^6.1.0",
"http-call": "^5.3.0",
"inquirer": "^9.2.18",
"lodash.throttle": "^4.1.1",
"semver": "^7.6.0",
"tar-fs": "^2.1.1"
Expand All @@ -21,21 +20,19 @@
"@oclif/prettier-config": "^0.2.1",
"@oclif/test": "^3",
"@types/chai": "^4.3.11",
"@types/cross-spawn": "^6.0.6",
"@types/debug": "^4.1.12",
"@types/execa": "^0.9.0",
"@types/inquirer": "^9.0.7",
"@types/lodash.throttle": "^4.1.9",
"@types/mocha": "^10",
"@types/node": "^18",
"@types/semver": "^7.5.8",
"@types/tar-fs": "^2.0.2",
"chai": "^4.4.1",
"commitlint": "^18",
"eslint-config-oclif-typescript": "^3.1.3",
"eslint": "^8.57.0",
"eslint-config-oclif": "^5.1.1",
"eslint-config-oclif-typescript": "^3.1.3",
"eslint-config-prettier": "^9.1.0",
"eslint": "^8.57.0",
"got": "^13.0.0",
"husky": "^9",
"lint-staged": "^15",
Expand Down
27 changes: 12 additions & 15 deletions src/commands/update.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import select from '@inquirer/select'
import {Args, Command, Flags, ux} from '@oclif/core'
import inquirer from 'inquirer'
import {basename} from 'node:path'
import {sort} from 'semver'

Expand Down Expand Up @@ -56,9 +56,8 @@ export default class UpdateCommand extends Command {
const {args, flags} = await this.parse(UpdateCommand)
const updater = new Updater(this.config)
if (flags.available) {
const index = await updater.fetchVersionIndex()
const [index, localVersions] = await Promise.all([updater.fetchVersionIndex(), updater.findLocalVersions()])
const allVersions = sort(Object.keys(index)).reverse()
const localVersions = await updater.findLocalVersions()

const table = allVersions.map((version) => {
const location = localVersions.find((l) => basename(l).startsWith(version)) || index[version]
Expand All @@ -77,18 +76,16 @@ export default class UpdateCommand extends Command {
autoUpdate: flags.autoupdate,
channel: args.channel,
force: flags.force,
version: flags.interactive ? await this.promptForVersion(updater) : flags.version,
version: flags.interactive ? await promptForVersion(updater) : flags.version,
})
}

private async promptForVersion(updater: Updater): Promise<string> {
const choices = sort(Object.keys(await updater.fetchVersionIndex())).reverse()
const {version} = await inquirer.prompt<{version: string}>({
choices: [...choices, new inquirer.Separator()],
message: 'Select a version to update to',
name: 'version',
type: 'list',
})
return version
}
}

const promptForVersion = async (updater: Updater): Promise<string> =>
select({
choices: sort(Object.keys(await updater.fetchVersionIndex()))
.reverse()
.map((v) => ({value: v})),
loop: false,
message: 'Select a version to update to',
})
3 changes: 2 additions & 1 deletion src/hooks/init.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Interfaces} from '@oclif/core'
import {spawn} from 'cross-spawn'
import makeDebug from 'debug'
import {spawn} from 'node:child_process'
import {existsSync} from 'node:fs'
import {open, stat, writeFile} from 'node:fs/promises'
import {join} from 'node:path'
Expand Down Expand Up @@ -70,6 +70,7 @@ export const init: Interfaces.Hook<'init'> = async function (opts) {
detached: !config.windows,
env: autoupdateEnv,
stdio: ['ignore', stream, stream],
...(config.windows ? {shell: true} : {}),
})
.on('error', (e: Error) => process.emitWarning(e))
.unref()
Expand Down
Loading

0 comments on commit a53ff7a

Please sign in to comment.