From 628782982e39a081acc595a43af0cc1026bb3c0c Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Tue, 28 May 2024 09:27:33 -0600 Subject: [PATCH] feat: use @oclif/core v4 --- package.json | 2 +- src/commands/schema/generate.ts | 30 ++++++++++++++++++++++-------- yarn.lock | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 7a4c9471..50edbd88 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "author": "Salesforce", "bugs": "https://github.com/oclif/plugin-command-snapshot/issues", "dependencies": { - "@oclif/core": "3.26.6", + "@oclif/core": "^4.0.0-beta.13", "@types/lodash.difference": "^4.5.9", "chalk": "^5.3.0", "globby": "^14.0.1", diff --git a/src/commands/schema/generate.ts b/src/commands/schema/generate.ts index 14ad88a0..31bafd21 100644 --- a/src/commands/schema/generate.ts +++ b/src/commands/schema/generate.ts @@ -1,8 +1,8 @@ -import {Flags} from '@oclif/core' +import {Flags, ux} from '@oclif/core' import chalk from 'chalk' import {globbySync} from 'globby' -import * as fs from 'node:fs' -import * as path from 'node:path' +import fs from 'node:fs' +import path from 'node:path' import {Schema, createGenerator} from 'ts-json-schema-generator' import SnapshotCommand from '../../snapshot-command.js' @@ -107,11 +107,25 @@ export class SchemaGenerator { } private getAllHookFiles(): string[] { - // eslint-disable-next-line unicorn/no-array-reduce - const hookFiles = Object.values(this.base.config.pjson.oclif?.hooks ?? {}).reduce( - (x: string[], y: string | string[]) => (Array.isArray(y) ? [...x, ...y] : [...x, y]), - [], - ) + const hookFiles = Object.values(this.base.config.pjson.oclif?.hooks ?? {}) + .flatMap((hook) => { + if (Array.isArray(hook)) { + return hook.map((h) => { + if (typeof h === 'string') return h + ux.warn(`Identifier/target based hooks are not supported: ${h}`) + return null + }) + } + + if (typeof hook === 'string') { + return hook + } + + ux.warn(`Identifier/target based hooks are not supported: ${hook}`) + return null + }) + .filter((h): h is string => typeof h === 'string') + const {outDir, rootDir} = this.getDirs() return hookFiles.map((h) => `${path.resolve(h)}.ts`.replace(outDir, rootDir)) } diff --git a/yarn.lock b/yarn.lock index 2df636a7..95d04fb9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1510,7 +1510,7 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@oclif/core@3.26.6", "@oclif/core@^3.26.5", "@oclif/core@^3.26.6": +"@oclif/core@^3.26.5", "@oclif/core@^3.26.6": version "3.26.6" resolved "https://registry.yarnpkg.com/@oclif/core/-/core-3.26.6.tgz#f371868cfa0fe150a6547e6af98b359065d2f971" integrity sha512-+FiTw1IPuJTF9tSAlTsY8bGK4sgthehjz7c2SvYdgQncTkxI2xvUch/8QpjNYGLEmUneNygvYMRBax2KJcLccA== @@ -1544,6 +1544,29 @@ wordwrap "^1.0.0" wrap-ansi "^7.0.0" +"@oclif/core@^4.0.0-beta.13": + version "4.0.0-beta.13" + resolved "https://registry.yarnpkg.com/@oclif/core/-/core-4.0.0-beta.13.tgz#0e0a6431cfe612db77073d2f9ef361f14e4090b8" + integrity sha512-ug8CZUCJphgetSZVgd4HQgyewlYVGGG1LIeFXGxjgYsjZ/f5I3nSCj7xpAMEDqjVD/lwmSujtVwa7tvEgLGICw== + 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", "@oclif/plugin-help@^6.0.21": version "6.0.22" resolved "https://registry.yarnpkg.com/@oclif/plugin-help/-/plugin-help-6.0.22.tgz#dca96ad1c28a68170e0bbf9f8f93f7dd171e4667" @@ -2491,7 +2514,7 @@ ansicolors@~0.3.2: resolved "https://registry.npmjs.org/ansicolors/-/ansicolors-0.3.2.tgz#665597de86a9ffe3aa9bfbe6cae5c6ea426b4979" integrity sha1-ZlWX3oap/+Oqm/vmyuXG6kJrSXk= -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== @@ -6143,6 +6166,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.2.0" resolved "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-2.2.0.tgz#4f77b42488765891774b70c79babd87f9bd594bb"