Skip to content

Commit

Permalink
Merge pull request #1421 from oclif/mdonnalley/core-v4
Browse files Browse the repository at this point in the history
feat: use @oclif/core v4
  • Loading branch information
iowillhoit committed May 31, 2024
2 parents 0eccb42 + 444d06e commit 532d2b8
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@inquirer/confirm": "^3.1.6",
"@inquirer/input": "^2.1.8",
"@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.10",
"@oclif/plugin-warn-if-update-available": "^3.0.19",
Expand Down
5 changes: 1 addition & 4 deletions src/commands/generate/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ export default class GenerateHook extends GeneratorCommand<typeof GenerateHook>
const outDir = tsConfig.compilerOptions?.outDir ?? 'dist'
const hooks = packageJSON.oclif?.hooks ?? {}
hooks[this.flags.event] = hooks[this.flags.event]
? uniq([
...castArray<string>(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 = {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []

Expand Down Expand Up @@ -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()
}
Expand Down
6 changes: 5 additions & 1 deletion src/commands/pack/win.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 oclif configuration')
}

const buildLocationUnsigned = o.replace(`${arch}.exe`, `${arch}-unsigned.exe`)
await move(o, buildLocationUnsigned)

Expand Down
5 changes: 2 additions & 3 deletions src/generator.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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})
Expand All @@ -63,7 +62,7 @@ export async function exec(

export async function readPJSON(
location: string,
): Promise<({scripts: Record<string, string>} & Interfaces.PJSON.CLI) | undefined> {
): Promise<({scripts: Record<string, string>} & Interfaces.PJSON) | undefined> {
try {
const packageJSON = await readFile(join(location, 'package.json'), 'utf8')
return JSON.parse(packageJSON)
Expand Down
2 changes: 1 addition & 1 deletion src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`)
}
2 changes: 1 addition & 1 deletion src/readme-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default class ReadmeGenerator {
readme = readme.replace(new RegExp(`<!-- ${tag} -->(.|\n)*<!-- ${tag}stop -->`, 'm'), `<!-- ${tag} -->`)
}

ux.log(`replacing <!-- ${tag} --> in ${this.options.readmePath}`)
ux.stdout(`replacing <!-- ${tag} --> in ${this.options.readmePath}`)
}

return readme.replace(`<!-- ${tag} -->`, `<!-- ${tag} -->\n${body}\n<!-- ${tag}stop -->`)
Expand Down
2 changes: 1 addition & 1 deletion src/tarballs/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
10 changes: 5 additions & 5 deletions src/tarballs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 nodeOptions = castArray((updateConfig.node as {options?: string | string[]}).options ?? [])
const targets = compact(options.targets || updateConfig.node.targets || TARGETS)
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)
.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...')
Expand Down
2 changes: 1 addition & 1 deletion src/upload-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/readme-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('ReadmeGenerator', () => {

beforeEach(async () => {
config = await Config.load(__dirname)
sinon.stub(ux, 'log').returns()
sinon.stub(ux, 'stdout').returns()
})

afterEach(() => {
Expand Down
30 changes: 29 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,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"
Expand Down Expand Up @@ -2958,7 +2981,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==
Expand Down Expand Up @@ -6481,6 +6504,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"
Expand Down

0 comments on commit 532d2b8

Please sign in to comment.