From 72be5ca808aca51a076e93341fbb1b8252908d4f Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 24 May 2024 10:59:11 -0600 Subject: [PATCH 1/4] feat: use @oclif/core v4 --- package.json | 2 +- src/commands/generate/hook.ts | 5 +---- src/commands/manifest.ts | 3 ++- src/commands/pack/win.ts | 6 +++++- src/generator.ts | 5 ++--- src/log.ts | 2 +- src/readme-generator.ts | 2 +- src/tarballs/build.ts | 2 +- src/tarballs/config.ts | 8 ++++---- src/upload-util.ts | 2 +- test/unit/readme-generator.test.ts | 2 +- yarn.lock | 30 +++++++++++++++++++++++++++++- 12 files changed, 49 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 4afff0a36..d5d323f23 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "@inquirer/confirm": "^3.1.6", "@inquirer/input": "^2.1.1", "@inquirer/select": "^2.3.4", - "@oclif/core": "^3.26.5", + "@oclif/core": "^4.0.0-beta.12", "@oclif/plugin-help": "^6.0.21", "@oclif/plugin-not-found": "^3.1.9", "@oclif/plugin-warn-if-update-available": "^3.0.19", diff --git a/src/commands/generate/hook.ts b/src/commands/generate/hook.ts index 0f77850b5..f6f49f10c 100644 --- a/src/commands/generate/hook.ts +++ b/src/commands/generate/hook.ts @@ -45,10 +45,7 @@ export default class GenerateHook extends GeneratorCommand const outDir = tsConfig.compilerOptions?.outDir ?? 'dist' const hooks = packageJSON.oclif?.hooks ?? {} hooks[this.flags.event] = hooks[this.flags.event] - ? uniq([ - ...castArray(hooks[this.flags.event]), - `./${outDir}/hooks/${this.flags.event}/${this.args.name}`, - ]).sort() + ? uniq([...castArray(hooks[this.flags.event]), `./${outDir}/hooks/${this.flags.event}/${this.args.name}`]).sort() : `./${outDir}/hooks/${this.flags.event}/${this.args.name}` const updatedPackageJSON = { diff --git a/src/commands/manifest.ts b/src/commands/manifest.ts index 040f66aed..6483ec1db 100644 --- a/src/commands/manifest.ts +++ b/src/commands/manifest.ts @@ -42,7 +42,7 @@ export default class Manifest extends Command { const {args} = await this.parse(Manifest) const root = path.resolve(args.path) - const packageJson = readJSONSync('package.json') as Interfaces.PJSON.Plugin + const packageJson = readJSONSync('package.json') as Interfaces.PJSON let jitPluginManifests: Interfaces.Manifest[] = [] @@ -91,6 +91,7 @@ export default class Manifest extends Command { await plugin.load() if (!plugin.valid) { const {PluginLegacy} = await import('@oclif/plugin-legacy') + // @ts-expect-error for now because PluginLegacy doesn't use the same major of @oclif/core plugin = new PluginLegacy(this.config, plugin) await plugin.load() } diff --git a/src/commands/pack/win.ts b/src/commands/pack/win.ts index 542ff8742..60457b7cc 100644 --- a/src/commands/pack/win.ts +++ b/src/commands/pack/win.ts @@ -363,8 +363,12 @@ async function signWindows( o: string, arch: string, config: Interfaces.Config, - windows: Interfaces.PJSON.Plugin['windows'], + windows: Interfaces.OclifConfiguration['windows'], ) { + if (!windows) { + throw new Error('windows not set in package.json') + } + const buildLocationUnsigned = o.replace(`${arch}.exe`, `${arch}-unsigned.exe`) await move(o, buildLocationUnsigned) diff --git a/src/generator.ts b/src/generator.ts index c0983562d..e9d1c6325 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -1,4 +1,3 @@ -/* eslint-disable unicorn/no-await-expression-member */ import {Args, Command, Flags, Interfaces, ux} from '@oclif/core' import chalk from 'chalk' import {renderFile} from 'ejs' @@ -50,7 +49,7 @@ export async function exec( ): Promise<{stderr: string; stdout: string}> { const silent = opts ? opts.silent : true return new Promise((resolve, reject) => { - if (!silent) ux.log(chalk.dim(command)) + if (!silent) ux.stdout(chalk.dim(command)) const p = cpExec(command, opts ?? {}, (err, stdout, stderr) => { if (err) return reject(err) resolve({stderr, stdout}) @@ -63,7 +62,7 @@ export async function exec( export async function readPJSON( location: string, -): Promise<({scripts: Record} & Interfaces.PJSON.CLI) | undefined> { +): Promise<({scripts: Record} & Interfaces.PJSON) | undefined> { try { const packageJSON = await readFile(join(location, 'package.json'), 'utf8') return JSON.parse(packageJSON) diff --git a/src/log.ts b/src/log.ts index 417e764db..41e2d4664 100644 --- a/src/log.ts +++ b/src/log.ts @@ -8,5 +8,5 @@ debug.new = (name: string) => require('debug')(`oclif:${name}`) export function log(format: string, ...args: unknown[]): void { args = args.map((arg) => prettifyPaths(arg)) - debug.enabled ? debug(format, ...args) : ux.log(`oclif: ${util.format(format, ...args)}`) + debug.enabled ? debug(format, ...args) : ux.stdout(`oclif: ${util.format(format, ...args)}`) } diff --git a/src/readme-generator.ts b/src/readme-generator.ts index b90e88ac3..37050fc92 100644 --- a/src/readme-generator.ts +++ b/src/readme-generator.ts @@ -210,7 +210,7 @@ export default class ReadmeGenerator { readme = readme.replace(new RegExp(`(.|\n)*`, 'm'), ``) } - ux.log(`replacing in ${this.options.readmePath}`) + ux.stdout(`replacing in ${this.options.readmePath}`) } return readme.replace(``, `\n${body}\n`) diff --git a/src/tarballs/build.ts b/src/tarballs/build.ts index 5c2a52889..139161991 100644 --- a/src/tarballs/build.ts +++ b/src/tarballs/build.ts @@ -236,7 +236,7 @@ const buildTarget = async ( if (c.xz) await pack(workspace, c.dist(xzLocalKey)) } - if (!c.updateConfig.s3.host) return + if (!c.updateConfig.s3?.host) return const rollout = typeof c.updateConfig.autoupdate === 'object' && c.updateConfig.autoupdate.rollout const gzCloudKey = `${commitAWSDir(version, sha, c.updateConfig.s3)}/${gzLocalKey}` diff --git a/src/tarballs/config.ts b/src/tarballs/config.ts index d5ddfb8c9..0b1ddef35 100644 --- a/src/tarballs/config.ts +++ b/src/tarballs/config.ts @@ -17,8 +17,8 @@ export type S3Config = { } & {folder?: string; indexVersionLimit?: number} & BuildConfig['updateConfig']['s3'] export type UpdateConfig = { - s3?: {acl?: ObjectCannedACL} & BuildConfig['config']['pjson']['oclif']['update']['s3'] -} & BuildConfig['config']['pjson']['oclif']['update'] + s3?: {acl?: ObjectCannedACL} & Interfaces.S3 +} & Interfaces.OclifConfiguration['update'] export type BuildConfig = { config: Interfaces.Config @@ -58,9 +58,9 @@ export async function buildConfig( const tmp = await Tmp(config) const updateConfig = (config.pjson.oclif.update || {}) as UpdateConfig updateConfig.s3 = updateConfig.s3 || {} - const nodeVersion = updateConfig.node.version || process.versions.node + const nodeVersion = updateConfig.node?.version || process.versions.node const nodeOptions = castArray((updateConfig.node as {options?: string | string[]}).options ?? []) - const targets = compact(options.targets || updateConfig.node.targets || TARGETS) + const targets = compact(options.targets || updateConfig.node?.targets || TARGETS) .filter((t) => { if (t === 'darwin-arm64' && semver.lt(nodeVersion, '16.0.0')) { ux.warn('darwin-arm64 is only supported for node >=16.0.0. Skipping...') diff --git a/src/upload-util.ts b/src/upload-util.ts index ad27ead0f..837f1c169 100644 --- a/src/upload-util.ts +++ b/src/upload-util.ts @@ -29,7 +29,7 @@ type TemplateOptions = // TODO: refactor this key name lookup helper to oclif/core export function templateShortKey( - type: 'deb' | 'macos' | 'win32' | keyof Interfaces.PJSON.S3.Templates, + type: 'deb' | 'macos' | 'win32' | keyof Interfaces.S3Templates, options?: TemplateOptions, ): string { if (!options) diff --git a/test/unit/readme-generator.test.ts b/test/unit/readme-generator.test.ts index 1b751d1c8..e38bd9f9c 100644 --- a/test/unit/readme-generator.test.ts +++ b/test/unit/readme-generator.test.ts @@ -21,7 +21,7 @@ describe('ReadmeGenerator', () => { beforeEach(async () => { config = await Config.load(__dirname) - sinon.stub(ux, 'log').returns() + sinon.stub(ux, 'stdout').returns() }) afterEach(() => { diff --git a/yarn.lock b/yarn.lock index 0f07b8efb..4335c0842 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1614,6 +1614,29 @@ wordwrap "^1.0.0" wrap-ansi "^7.0.0" +"@oclif/core@^4.0.0-beta.12": + version "4.0.0-beta.12" + resolved "https://registry.yarnpkg.com/@oclif/core/-/core-4.0.0-beta.12.tgz#d8155735249bf3c031a8b6ea88fb6ef3f21a4b94" + integrity sha512-jiLs/PPVaOzoQrQN5NU1pm8JWdyEM52eW/Q+3yDjmHEbLZbQivo1b/uWgZU83wUnVJhbB64zL1F+Vfcp8ygl5Q== + dependencies: + ansi-escapes "^4.3.2" + ansis "^3.0.1" + clean-stack "^3.0.1" + cli-spinners "^2.9.2" + cosmiconfig "^9.0.0" + debug "^4.3.4" + ejs "^3.1.10" + get-package-type "^0.1.0" + globby "^11.1.0" + indent-string "^4.0.0" + is-wsl "^2.2.0" + minimatch "^9.0.4" + string-width "^4.2.3" + supports-color "^9.4.0" + widest-line "^3.1.0" + wordwrap "^1.0.0" + wrap-ansi "^7.0.0" + "@oclif/plugin-help@^6.0.21": version "6.0.21" resolved "https://registry.yarnpkg.com/@oclif/plugin-help/-/plugin-help-6.0.21.tgz#c48e688bf6df574e74557ebe2f877556f08dc60b" @@ -2977,7 +3000,7 @@ ansicolors@~0.3.2: resolved "https://registry.yarnpkg.com/ansicolors/-/ansicolors-0.3.2.tgz#665597de86a9ffe3aa9bfbe6cae5c6ea426b4979" integrity sha512-QXu7BPrP29VllRxH8GwB7x5iX5qWKAAMLqKQGWTeLWVlNHNOpVMJ91dsxQAIWXpjuW5wqvxu3Jd/nRjrJ+0pqg== -ansis@^3.2.0: +ansis@^3.0.1, ansis@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/ansis/-/ansis-3.2.0.tgz#0e050c5be94784f32ffdac4b84fccba064aeae4b" integrity sha512-Yk3BkHH9U7oPyCN3gL5Tc7CpahG/+UFv/6UG03C311Vy9lzRmA5uoxDTpU9CO3rGHL6KzJz/pdDeXZCZ5Mu/Sg== @@ -6507,6 +6530,11 @@ supports-color@^7, supports-color@^7.0.0, supports-color@^7.1.0: dependencies: has-flag "^4.0.0" +supports-color@^9.4.0: + version "9.4.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-9.4.0.tgz#17bfcf686288f531db3dea3215510621ccb55954" + integrity sha512-VL+lNrEoIXww1coLPOmiEmK/0sGigko5COxI09KzHc2VJXJsQ37UaQ+8quuxjDeA7+KnLGTWRyOXSLLR2Wb4jw== + supports-hyperlinks@^2.2.0: version "2.3.0" resolved "https://registry.yarnpkg.com/supports-hyperlinks/-/supports-hyperlinks-2.3.0.tgz#3943544347c1ff90b15effb03fc14ae45ec10624" From ce9215aa81c737bf75d47dc64360ae5c67d8db63 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 24 May 2024 11:23:08 -0600 Subject: [PATCH 2/4] fix: handle undefined node options --- src/tarballs/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tarballs/config.ts b/src/tarballs/config.ts index 0b1ddef35..4ed763541 100644 --- a/src/tarballs/config.ts +++ b/src/tarballs/config.ts @@ -59,7 +59,7 @@ export async function buildConfig( const updateConfig = (config.pjson.oclif.update || {}) as UpdateConfig updateConfig.s3 = updateConfig.s3 || {} const nodeVersion = updateConfig.node?.version || process.versions.node - const nodeOptions = castArray((updateConfig.node as {options?: string | string[]}).options ?? []) + const nodeOptions = castArray((updateConfig.node ?? ({} as {options?: string | string[]})).options ?? []) const targets = compact(options.targets || updateConfig.node?.targets || TARGETS) .filter((t) => { if (t === 'darwin-arm64' && semver.lt(nodeVersion, '16.0.0')) { From 7db58864bde25a92f276294bba7a63285d4993fe Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 24 May 2024 12:41:49 -0600 Subject: [PATCH 3/4] test: fix deb integration tests --- test/integration/deb.test.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/test/integration/deb.test.ts b/test/integration/deb.test.ts index 05e483591..ad0bf558e 100644 --- a/test/integration/deb.test.ts +++ b/test/integration/deb.test.ts @@ -43,22 +43,23 @@ describe('publish:deb', () => { }) onlyLinux('publishes valid releases', async () => { - await runCommand('pack deb') - await runCommand('upload deb') + await runCommand('pack deb', undefined, {print: true}) + + await runCommand('upload deb', undefined, {print: true}) const sha = await gitSha(process.cwd(), {short: true}) - await exec('cat test/release.key | sudo apt-key add -') - await exec( - `sudo sh -c 'echo "deb https://${developerSalesforceCom}/${basePrefix}/versions/${pjson.version}/${sha}/apt/ /" > /etc/apt/sources.list.d/oclif.list'`, - ) - await exec('sudo apt-get update') - await exec('sudo apt-get install -y oclif') - await exec('oclif --version') - // test the binAliases section - const {stdout: oclif2} = await exec('oclif2 --version') - expect(oclif2).to.contain(`oclif/${pjson.version} ${target} node-v${pjson.oclif.update.node.version}`) + const debUrl = `https://${developerSalesforceCom}/${basePrefix}/versions/${pjson.version}/${sha}/apt/oclif_${pjson.version.split('-')[0]}.${sha}-1_amd64.deb` + console.log('downloading .deb from', debUrl) + // download the deb + await exec(`curl -sL ${debUrl} -o ${root}/oclif.deb`) + // install the deb + await exec(`sudo dpkg -i ${root}/oclif.deb`) + // test the bin const {stdout: oclif} = await exec('oclif --version') expect(oclif).to.contain(`oclif/${pjson.version} ${target} node-v${pjson.oclif.update.node.version}`) + // test the bin alias + const {stdout: oclif2} = await exec('oclif2 --version') + expect(oclif2).to.contain(`oclif/${pjson.version} ${target} node-v${pjson.oclif.update.node.version}`) }) }) From 444d06ea485232b1355b59c376805997c72be720 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 31 May 2024 10:25:48 -0600 Subject: [PATCH 4/4] fix: clarify error message --- src/commands/pack/win.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/pack/win.ts b/src/commands/pack/win.ts index 60457b7cc..990cab697 100644 --- a/src/commands/pack/win.ts +++ b/src/commands/pack/win.ts @@ -366,7 +366,7 @@ async function signWindows( windows: Interfaces.OclifConfiguration['windows'], ) { if (!windows) { - throw new Error('windows not set in package.json') + throw new Error('windows not set in oclif configuration') } const buildLocationUnsigned = o.replace(`${arch}.exe`, `${arch}-unsigned.exe`)