Skip to content

Commit

Permalink
fix: use native spawn, new inquirer
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Apr 16, 2024
1 parent 3fa50fa commit 1f60ff3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 673 deletions.
9 changes: 3 additions & 6 deletions package.json
Expand Up @@ -4,13 +4,12 @@
"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
@@ -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
@@ -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

0 comments on commit 1f60ff3

Please sign in to comment.