From 2c804dc8c81ce96e2f14be318305e386530de8ce Mon Sep 17 00:00:00 2001 From: Peter Hale Date: Wed, 28 Dec 2022 13:37:28 -0700 Subject: [PATCH] feat: plugin to sf parity @W-12084133@ --- .eslintrc.js | 2 +- README.md | 57 +++++++-- command-snapshot.json | 2 +- messages/display.js | 22 ---- messages/display.md | 39 ++++++ messages/doctor.js | 33 ----- messages/doctor.md | 54 +++++++++ messages/messages.json | 22 ---- package.json | 12 +- src/commands/doctor.ts | 75 +++++++----- src/commands/info/releasenotes/display.ts | 41 ++++--- test/commands/doctor.test.ts | 8 +- .../info/releasenotes/display.test.ts | 6 +- yarn.lock | 114 ++++++++++++------ 14 files changed, 299 insertions(+), 188 deletions(-) delete mode 100644 messages/display.js create mode 100644 messages/display.md delete mode 100644 messages/doctor.js create mode 100644 messages/doctor.md delete mode 100644 messages/messages.json diff --git a/.eslintrc.js b/.eslintrc.js index 296e72d1..a2f1e49c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,5 +5,5 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ module.exports = { - extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license'], + extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license', 'plugin:sf-plugin/recommended'], }; diff --git a/README.md b/README.md index c5fa7535..a3cda57a 100644 --- a/README.md +++ b/README.md @@ -76,31 +76,64 @@ sfdx plugins -- [`sfdx info:releasenotes:display [-v ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-inforeleasenotesdisplay--v-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal) +- [`sfdx doctor`](#sfdx-doctor) +- [`sfdx info:releasenotes:display`](#sfdx-inforeleasenotesdisplay) -## `sfdx info:releasenotes:display [-v ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` +## `sfdx doctor` -Display Salesforce CLI release notes on the command line. +Gather CLI configuration data and run diagnostic tests to discover and report potential problems in your environment. ``` USAGE - $ sfdx info:releasenotes:display [-v ] [--json] [--loglevel - trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL] + $ sfdx doctor OPTIONS - -v, --version=version CLI version or tag for which to - display release notes. + -c, --command=command + -d, --output-dir=output-dir + -i, --create-issue + -p, --plugin=plugin + --json Format output as json. + +DESCRIPTION + When you run the doctor command without parameters, it first displays a diagnostic overview of your environment. It + then writes a detailed diagnosis to a JSON file in the current directory. Use the --outputdir to specify a different + directory. To run diagnostic tests on a specific plugin, use the --plugin parameter. If the plugin isn't listening to + the doctor, then you get a warning. + + Use the --command parameter to run a specific command in debug mode; the doctor writes both stdout and stderr to *.log + files that you can provide to Salesforce Customer Support or attach to a GitHub issue. + + Plugin providers can also implement their own doctor diagnostic tests by listening to the "sf-doctor" event and + running plugin specific tests that are then included in the doctor diagnostics log. + +EXAMPLES + - Run CLI doctor diagnostics: + $ sfdx doctor + Run CLI doctor diagnostics and the specified command, and write the debug output to a file: + $ sfdx doctor --command "force:org:list --all" + Run CLI doctor diagnostics for a specific plugin: + $ sfdx doctor --plugin @salesforce/plugin-source +``` + +_See code: [src/commands/doctor.ts](https://github.com/salesforcecli/plugin-info/blob/v2.2.14-t.0/src/commands/doctor.ts)_ - --json format output as json +## `sfdx info:releasenotes:display` - --loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for - this command invocation +Display Salesforce CLI release notes on the command line. + +``` +USAGE + $ sfdx info:releasenotes:display + +OPTIONS + -v, --version=version CLI version or tag for which to display release notes. + --json Format output as json. ALIASES $ sfdx whatsnew EXAMPLES - Display release notes for the currently installed CLI version: + - Display release notes for the currently installed CLI version: $ sfdx info:releasenotes:display Display release notes for CLI version 7.120.0: $ sfdx info:releasenotes:display --version 7.120.0 @@ -108,6 +141,6 @@ EXAMPLES $ sfdx info:releasenotes:display --version latest ``` -_See code: [src/commands/info/releasenotes/display.ts](https://github.com/salesforcecli/plugin-info/blob/v2.0.1/src/commands/info/releasenotes/display.ts)_ +_See code: [src/commands/info/releasenotes/display.ts](https://github.com/salesforcecli/plugin-info/blob/v2.2.14-t.0/src/commands/info/releasenotes/display.ts)_ diff --git a/command-snapshot.json b/command-snapshot.json index 40c8ff0b..fc950b0a 100644 --- a/command-snapshot.json +++ b/command-snapshot.json @@ -2,7 +2,7 @@ { "command": "doctor", "plugin": "@salesforce/plugin-info", - "flags": ["command", "createissue", "json", "loglevel", "outputdir", "plugin"], + "flags": ["command", "create-issue", "json", "loglevel", "output-dir", "plugin"], "alias": [] }, { diff --git a/messages/display.js b/messages/display.js deleted file mode 100644 index 40e80167..00000000 --- a/messages/display.js +++ /dev/null @@ -1,22 +0,0 @@ -module.exports = { - commandDescription: 'Display Salesforce CLI release notes on the command line.', - flags: { - version: 'CLI version or tag for which to display release notes.', - hook: 'This hidden parameter is used in post install or update hooks.', - }, - examples: [ - `Display release notes for the currently installed CLI version: -$ <%= config.bin %> <%= command.id %> -Display release notes for CLI version 7.120.0: -$ <%= config.bin %> <%= command.id %> --version 7.120.0 -Display release notes for the CLI version that corresponds to a tag (%s): -$ <%= config.bin %> <%= command.id %> --version latest - `, - ], - footer: `--- -- Run \`%s whatsnew\` to manually view the current release notes. -- You can also view them on GitHub by visiting the [forcedotcom/cli](%s) repo. -- Silence notes by setting the \`%s\` env var to \`true\`. -- Hide this footer by setting the \`%s\` env var to \`true\`. ----`, -}; diff --git a/messages/display.md b/messages/display.md new file mode 100644 index 00000000..58e27234 --- /dev/null +++ b/messages/display.md @@ -0,0 +1,39 @@ +# commandDescription + +Display Salesforce CLI release notes on the command line. + +# flags.version.summary + +CLI version or tag for which to display release notes. + +# flags.version.description + +CLI version or tag for which to display release notes. + +# flags.hook.summary + +This hidden parameter is used in post install or update hooks. + +# flags.hook.description + +This hidden parameter is used in post install or update hooks. + +# examples + +- Display release notes for the currently installed CLI version: + $ <%= config.bin %> <%= command.id %> + Display release notes for CLI version 7.120.0: + $ <%= config.bin %> <%= command.id %> --version 7.120.0 + Display release notes for the CLI version that corresponds to a tag (%s): + $ <%= config.bin %> <%= command.id %> --version latest + +# footer + +--- + +- Run `%s whatsnew` to manually view the current release notes. +- You can also view them on GitHub by visiting the [forcedotcom/cli](%s) repo. +- Silence notes by setting the `%s` env var to `true`. +- Hide this footer by setting the `%s` env var to `true`. + +--- diff --git a/messages/doctor.js b/messages/doctor.js deleted file mode 100644 index f501e501..00000000 --- a/messages/doctor.js +++ /dev/null @@ -1,33 +0,0 @@ -module.exports = { - commandDescription: `Gather CLI configuration data and run diagnostic tests to discover and report potential problems in your environment. - -When you run the doctor command without parameters, it first displays a diagnostic overview of your environment. It then writes a detailed diagnosis to a JSON file in the current directory. Use the --outputdir to specify a different directory. To run diagnostic tests on a specific plugin, use the --plugin parameter. If the plugin isn't listening to the doctor, then you get a warning. - -Use the --command parameter to run a specific command in debug mode; the doctor writes both stdout and stderr to *.log files that you can provide to Salesforce Customer Support or attach to a GitHub issue. - -Plugin providers can also implement their own doctor diagnostic tests by listening to the "sf-doctor" event and running plugin specific tests that are then included in the doctor diagnostics log. -`, - flags: { - command: 'command to run in debug mode ; results are written to a log file', - newissue: 'create a new GitHub issue and attach all diagnostic results', - plugin: 'specific plugin on which to run diagnostics ', - outputdir: 'directory to save all created files rather than the current working directory', - createissue: 'create a new issue on our GitHub repo and attach all diagnostic results', - }, - examples: [ - `Run CLI doctor diagnostics: - $ <%= config.bin %> doctor -Run CLI doctor diagnostics and the specified command, and write the debug output to a file: - $ <%= config.bin %> doctor --command "force:org:list --all" -Run CLI doctor diagnostics for a specific plugin: - $ <%= config.bin %> doctor --plugin @salesforce/plugin-source`, - ], - pinnedSuggestions: { - checkGitHubIssues: 'Check https://github.com/forcedotcom/cli/issues for CLI issues posted by the community.', - checkSfdcStatus: 'Check http://status.salesforce.com for general Salesforce availability and performance.', - }, - doctorNotInitializedError: 'Must first initialize a new SfDoctor.', - doctorAlreadyInitializedError: 'SfDoctor has already been initialized.', - pluginNotInstalledError: - "Specified plugin [%s] isn't installed. Install it, correct the name, or choose another plugin.", -}; diff --git a/messages/doctor.md b/messages/doctor.md new file mode 100644 index 00000000..893abcf7 --- /dev/null +++ b/messages/doctor.md @@ -0,0 +1,54 @@ +# commandDescription + +Gather CLI configuration data and run diagnostic tests to discover and report potential problems in your environment. + +When you run the doctor command without parameters, it first displays a diagnostic overview of your environment. It then writes a detailed diagnosis to a JSON file in the current directory. Use the --outputdir to specify a different directory. To run diagnostic tests on a specific plugin, use the --plugin parameter. If the plugin isn't listening to the doctor, then you get a warning. + +Use the --command parameter to run a specific command in debug mode; the doctor writes both stdout and stderr to \*.log files that you can provide to Salesforce Customer Support or attach to a GitHub issue. + +Plugin providers can also implement their own doctor diagnostic tests by listening to the "sf-doctor" event and running plugin specific tests that are then included in the doctor diagnostics log. + +# flags.command + +command to run in debug mode ; results are written to a log file + +# flags.plugin + +specific plugin on which to run diagnostics + +# flags.output-dir.summary + +directory to save all created files rather than the current working directory + +# flags.create-issue.summary + +create a new issue on our GitHub repo and attach all diagnostic results + +# examples + +- Run CLI doctor diagnostics: + $ <%= config.bin %> doctor + Run CLI doctor diagnostics and the specified command, and write the debug output to a file: + $ <%= config.bin %> doctor --command "force:org:list --all" + Run CLI doctor diagnostics for a specific plugin: + $ <%= config.bin %> doctor --plugin @salesforce/plugin-source + +# pinnedSuggestions.checkGitHubIssues + +Check https://github.com/forcedotcom/cli/issues for CLI issues posted by the community. + +# pinnedSuggestions.checkSfdcStatus + +Check http://status.salesforce.com for general Salesforce availability and performance. + +# doctorNotInitializedError + +Must first initialize a new SfDoctor. + +# doctorAlreadyInitializedError + +SfDoctor has already been initialized. + +# pluginNotInstalledError + +Specified plugin [%s] isn't installed. Install it, correct the name, or choose another plugin. diff --git a/messages/messages.json b/messages/messages.json deleted file mode 100644 index 9a166f4f..00000000 --- a/messages/messages.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "HelpDefaults": "If not supplied, the apiversion, template, and outputdir use default values.\n", - "HelpOutputDirRelative": "The outputdir can be an absolute path or relative to the current working directory.\n", - "HelpOutputDirRelativeLightning": "If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we create force-app/myBundle/ to store the files in the bundle.\n", - "HelpExamplesTitle": "\nExamples:\n", - "OutputDirFlagDescription": "folder for saving the created files", - "OutputDirFlagLongDescription": "The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.", - "TemplateFlagDescription": "template to use for file creation", - "TemplateFlagLongDescription": "The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.", - "TargetDirOutput": "target dir = %s", - "App": "app", - "Event": "event", - "Interface": "interface", - "Test": "test", - "Component": "component", - "Page": "page", - - "AlphaNumericNameError": "Name must contain only alphanumeric characters.", - "NameMustStartWithLetterError": "Name must start with a letter.", - "EndWithUnderscoreError": "Name can't end with an underscore.", - "DoubleUnderscoreError": "Name can't contain 2 consecutive underscores." -} diff --git a/package.json b/package.json index f1b4e155..e190d85a 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,10 @@ "bugs": "https://github.com/forcedotcom/cli/issues", "main": "lib/index.js", "dependencies": { - "@oclif/core": "^1.20.0", - "@salesforce/command": "^5.2.27", - "@salesforce/core": "^3.30.12", - "@salesforce/kit": "^1.6.1", + "@oclif/core": "^1.23.0", + "@salesforce/core": "^3.32.12", + "@salesforce/kit": "^1.8.0", + "@salesforce/sf-plugins-core": "^1.21.3", "got": "^11.8.6", "marked": "^4.2.4", "marked-terminal": "^4.2.0", @@ -45,6 +45,7 @@ "eslint-plugin-header": "^3.1.1", "eslint-plugin-import": "^2.26.0", "eslint-plugin-jsdoc": "^39.6.4", + "eslint-plugin-sf-plugin": "^1.3.1", "husky": "^7.0.4", "mocha": "^9.1.3", "nyc": "^15.1.0", @@ -118,10 +119,11 @@ "test": "sf-test", "test:command-reference": "./bin/dev commandreference:generate --erroronwarnings", "test:deprecation-policy": "./bin/dev snapshot:compare", + "test:json-schema": "./bin/dev schema:compare", "test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel", "version": "oclif-dev readme" }, "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/src/commands/doctor.ts b/src/commands/doctor.ts index d04b938a..0dcbfc63 100644 --- a/src/commands/doctor.ts +++ b/src/commands/doctor.ts @@ -8,8 +8,8 @@ import * as os from 'os'; import * as path from 'path'; import { exec } from 'child_process'; -import { flags, SfdxCommand } from '@salesforce/command'; -import { Messages, Lifecycle, SfError } from '@salesforce/core'; +import { Flags, loglevel, SfCommand } from '@salesforce/sf-plugins-core'; +import { Lifecycle, Messages, SfError } from '@salesforce/core'; import * as open from 'open'; import got from 'got'; import * as ProxyAgent from 'proxy-agent'; @@ -20,28 +20,32 @@ import { DiagnosticStatus } from '../diagnostics'; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/plugin-info', 'doctor'); -export default class Doctor extends SfdxCommand { - public static description = messages.getMessage('commandDescription'); - public static examples = messages.getMessage('examples').split(os.EOL); +export default class Doctor extends SfCommand { + public static readonly summary = messages.getMessage('commandDescription'); + public static readonly description = messages.getMessage('commandDescription'); + public static readonly examples = messages.getMessage('examples').split(os.EOL); - protected static flagsConfig = { - command: flags.string({ + public static readonly flags = { + command: Flags.string({ char: 'c', - description: messages.getMessage('flags.command'), + summary: messages.getMessage('flags.command'), }), - plugin: flags.string({ + plugin: Flags.string({ char: 'p', - description: messages.getMessage('flags.plugin'), + summary: messages.getMessage('flags.plugin'), }), - outputdir: flags.directory({ - char: 'o', - description: messages.getMessage('flags.outputdir'), + 'output-dir': Flags.directory({ + char: 'd', + summary: messages.getMessage('flags.output-dir.summary'), + aliases: ['outputdir', 'o'], }), - createissue: flags.boolean({ + 'create-issue': Flags.boolean({ char: 'i', - description: messages.getMessage('flags.createissue'), + summary: messages.getMessage('flags.create-issue.summary'), default: false, + aliases: ['createissue'], }), + loglevel, }; // Array of promises that are various doctor tasks to perform @@ -53,18 +57,19 @@ export default class Doctor extends SfdxCommand { private filesWrittenMsgs: string[] = []; public async run(): Promise { + const { flags } = await this.parse(Doctor); this.doctor = SFDoctor.getInstance(); const lifecycle = Lifecycle.getInstance(); - const pluginFlag = this.flags.plugin as string; - const commandFlag = this.flags.command as string; - const outputdirFlag = this.flags.outputdir as string; - const createissueFlag = this.flags.createissue as boolean; + const pluginFlag = flags.plugin; + const commandFlag = flags.command; + const outputdirFlag = flags['output-dir']; + const createissueFlag = flags['create-issue']; this.outputDir = path.resolve(outputdirFlag ?? process.cwd()); // eslint-disable-next-line @typescript-eslint/require-await lifecycle.on('Doctor:diagnostic', async (data) => { - this.ux.log(`${data.status} - ${data.testName}`); + this.log(`${data.status} - ${data.testName}`); this.doctor.addDiagnosticStatus(data); }); @@ -79,16 +84,16 @@ export default class Doctor extends SfdxCommand { const eventName = `sf-doctor-${pluginFlag}`; const hasDoctorHook = plugin.hooks && Object.keys(plugin.hooks).some((hook) => hook === eventName); if (hasDoctorHook) { - this.ux.styledHeader(`Running diagnostics for plugin: ${pluginFlag}`); + this.styledHeader(`Running diagnostics for plugin: ${pluginFlag}`); this.tasks.push(this.config.runHook(eventName, { doctor: this.doctor })); } else { - this.ux.log(`${pluginFlag} doesn't have diagnostic tests to run.`); + this.log(`${pluginFlag} doesn't have diagnostic tests to run.`); } } else { throw new SfError(messages.getMessage('pluginNotInstalledError', [pluginFlag]), 'UnknownPluginError'); } } else { - this.ux.styledHeader('Running all diagnostics'); + this.styledHeader('Running all diagnostics'); // Fire events for plugins that have sf-doctor hooks this.config.plugins.forEach((plugin) => { const eventName = `sf-doctor-${plugin.name}`; @@ -108,12 +113,12 @@ export default class Doctor extends SfdxCommand { ); this.filesWrittenMsgs.push(`Wrote doctor diagnosis to: ${diagnosisLocation}`); - this.ux.log(); - this.filesWrittenMsgs.forEach((msg) => this.ux.log(msg)); + this.log(); + this.filesWrittenMsgs.forEach((msg) => this.log(msg)); - this.ux.log(); - this.ux.styledHeader('Suggestions'); - diagnosis.suggestions.forEach((s) => this.ux.log(` * ${s}`)); + this.log(); + this.styledHeader('Suggestions'); + diagnosis.suggestions.forEach((s) => this.log(` * ${s}`)); if (createissueFlag) { const raw = 'https://raw.githubusercontent.com/forcedotcom/cli/main/.github/ISSUE_TEMPLATE/bug_report.md'; @@ -122,9 +127,13 @@ export default class Doctor extends SfdxCommand { agent: { https: ProxyAgent(getProxyForUrl(raw)) }, }); - const title = await this.ux.prompt('Enter a title for your new issue'); + const title: Record = await this.prompt({ + type: 'input', + name: 'title', + message: 'Enter a title for your new issue', + }); const url = encodeURI( - `https://github.com/forcedotcom/cli/issues/new?title=${title}&body=${this.generateIssueMarkdown( + `https://github.com/forcedotcom/cli/issues/new?title=${title.title}&body=${this.generateIssueMarkdown( ghIssue.body, diagnosis )}&labels=doctor,investigating,${this.config.bin}` @@ -149,7 +158,7 @@ export default class Doctor extends SfdxCommand { const info = ` \`\`\` ${diagnosis.cliConfig.userAgent} -${diagnosis.versionDetail.pluginVersions.join(os.EOL)} +${diagnosis.versionDetail.pluginVersions?.join(os.EOL)} \`\`\` ${ diagnosis.sfdxEnvVars.length @@ -214,8 +223,8 @@ ${this.doctor // in the current or specified directory. private setupCommandExecution(command: string): void { const cmdString = this.parseCommand(command); - this.ux.styledHeader('Running command with debugging'); - this.ux.log(`${cmdString}\n`); + this.styledHeader('Running command with debugging'); + this.log(`${cmdString}\n`); this.doctor.addCommandName(cmdString); const execPromise = new Promise((resolve) => { diff --git a/src/commands/info/releasenotes/display.ts b/src/commands/info/releasenotes/display.ts index 3f949569..624ec9a9 100644 --- a/src/commands/info/releasenotes/display.ts +++ b/src/commands/info/releasenotes/display.ts @@ -12,8 +12,8 @@ import * as os from 'os'; import { marked } from 'marked'; import * as TerminalRenderer from 'marked-terminal'; import { Env } from '@salesforce/kit'; -import { flags, SfdxCommand } from '@salesforce/command'; -import { Lifecycle, Messages } from '@salesforce/core'; +import { Flags, SfCommand, loglevel } from '@salesforce/sf-plugins-core'; +import { Lifecycle, Logger, Messages } from '@salesforce/core'; import { AnyJson, JsonMap } from '@salesforce/ts-types'; import { getInfoConfig } from '../../../shared/getInfoConfig'; import { getReleaseNotes } from '../../../shared/getReleaseNotes'; @@ -30,30 +30,37 @@ const HIDE_FOOTER = 'SFDX_HIDE_RELEASE_NOTES_FOOTER'; // or any library that is using the messages framework can also be loaded this way. const messages = Messages.loadMessages('@salesforce/plugin-info', 'display'); -export default class Display extends SfdxCommand { +export default class Display extends SfCommand { private static helpers = ['stable', 'stable-rc', 'latest', 'latest-rc', 'rc']; - public static description = messages.getMessage('commandDescription'); + public static readonly summary = messages.getMessage('commandDescription'); + public static readonly description = messages.getMessage('commandDescription'); public static aliases = ['whatsnew']; - public static examples = messages.getMessage('examples', [Display.helpers.join(', ')]).split(os.EOL); + public static readonly examples = messages.getMessage('examples', [Display.helpers.join(', ')]).split(os.EOL); - protected static flagsConfig = { - version: flags.string({ + public static readonly flags = { + version: Flags.string({ char: 'v', - description: messages.getMessage('flags.version'), + summary: messages.getMessage('flags.version.summary'), + description: messages.getMessage('flags.version.description'), }), - hook: flags.boolean({ + hook: Flags.boolean({ hidden: true, - description: messages.getMessage('flags.hook'), + summary: messages.getMessage('flags.hook.summary'), + description: messages.getMessage('flags.hook.description'), }), + loglevel, }; + private logger: Logger; public async run(): Promise { + this.logger = Logger.childFromRoot(this.constructor.name); + const { flags } = await this.parse(Display); const env = new Env(); - const isHook = !!this.flags.hook; + const isHook = !!flags.hook; if (env.getBoolean(HIDE_NOTES) && isHook) { // We don't ever want to exit the process for info:releasenotes:display (whatsnew) @@ -72,7 +79,7 @@ export default class Display extends SfdxCommand { const { distTagUrl, releaseNotesPath, releaseNotesFilename } = infoConfig.releasenotes; - let version = (this.flags.version as string) ?? installedVersion; + let version = flags.version ?? installedVersion; if (Display.helpers.includes(version)) { version = await getDistTagVersion(distTagUrl, version); @@ -88,12 +95,12 @@ export default class Display extends SfdxCommand { tokens.unshift(marked.lexer(`# Release notes for '${this.config.bin}':`)[0]); - if (this.flags.json) { + if (flags.json) { const body = tokens.map((token) => token.raw).join(os.EOL); return { body, url: releaseNotesPath }; } else { - this.ux.log(marked.parser(tokens)); + this.log(marked.parser(tokens)); } if (isHook) { @@ -101,7 +108,7 @@ export default class Display extends SfdxCommand { await Lifecycle.getInstance().emitTelemetry({ eventName: 'FOOTER_HIDDEN' }); } else { const footer = messages.getMessage('footer', [this.config.bin, releaseNotesPath, HIDE_NOTES, HIDE_FOOTER]); - this.ux.log(marked.parse(footer)); + this.log(marked.parse(footer)); } } } catch (err) { @@ -110,7 +117,7 @@ export default class Display extends SfdxCommand { // --hook is passed in the post install/update scripts const { message, stack, name } = err as Error; - this.ux.warn(`${this.id} failed: ${message}`); + this.warn(`${this.id} failed: ${message}`); this.logger.trace(stack); await Lifecycle.getInstance().emitTelemetry({ @@ -136,7 +143,7 @@ export default class Display extends SfdxCommand { } } -interface DisplayOutput { +export interface DisplayOutput { body: string; url: string; } diff --git a/test/commands/doctor.test.ts b/test/commands/doctor.test.ts index 6e92b87c..dbc73118 100644 --- a/test/commands/doctor.test.ts +++ b/test/commands/doctor.test.ts @@ -11,10 +11,10 @@ import * as childProcess from 'child_process'; import * as Sinon from 'sinon'; import { expect } from 'chai'; import { fromStub, stubInterface, stubMethod } from '@salesforce/ts-sinon'; -import { UX } from '@salesforce/command'; import { Lifecycle, Messages } from '@salesforce/core'; import { Config } from '@oclif/core'; import { VersionDetail } from '@oclif/plugin-version'; +import { SfCommand } from '@salesforce/sf-plugins-core'; import DoctorCmd from '../../src/commands/doctor'; import { Doctor, SfDoctorDiagnosis, Diagnostics, DiagnosticStatus } from '../../src'; @@ -88,13 +88,13 @@ describe('Doctor Command', () => { const runDoctorCmd = async (params: string[]) => { const cmd = new TestDoctor(params, oclifConfigStub); - uxLogStub = stubMethod(sandbox, UX.prototype, 'log'); - promptStub = stubMethod(sandbox, UX.prototype, 'prompt').resolves('my new and crazy issue'); + uxLogStub = stubMethod(sandbox, SfCommand.prototype, 'log'); + promptStub = stubMethod(sandbox, SfCommand.prototype, 'prompt').resolves({ title: 'my new and crazy issue' }); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore openStub = sandbox.stub(cmd, 'openUrl').resolves(); - uxStyledHeaderStub = stubMethod(sandbox, UX.prototype, 'styledHeader'); + uxStyledHeaderStub = stubMethod(sandbox, SfCommand.prototype, 'styledHeader'); return cmd.runIt(); }; diff --git a/test/commands/info/releasenotes/display.test.ts b/test/commands/info/releasenotes/display.test.ts index dfdfe736..1607bead 100644 --- a/test/commands/info/releasenotes/display.test.ts +++ b/test/commands/info/releasenotes/display.test.ts @@ -11,11 +11,11 @@ import * as SinonChai from 'sinon-chai'; import { expect, use as chaiUse } from 'chai'; import { fromStub, stubInterface, stubMethod, spyMethod } from '@salesforce/ts-sinon'; import { shouldThrow } from '@salesforce/core/lib/testSetup'; -import { UX } from '@salesforce/command'; import { marked } from 'marked'; import { Env } from '@salesforce/kit'; import { Lifecycle } from '@salesforce/core'; import { Config } from '@oclif/core'; +import { SfCommand } from '@salesforce/sf-plugins-core'; import * as getInfoConfig from '../../../../src/shared/getInfoConfig'; import * as getReleaseNotes from '../../../../src/shared/getReleaseNotes'; import * as getDistTagVersion from '../../../../src/shared/getDistTagVersion'; @@ -52,8 +52,8 @@ describe('info:releasenotes:display', () => { const cmd = new TestDisplay(params, oclifConfigStub); - uxLogStub = stubMethod(sandbox, UX.prototype, 'log'); - uxWarnStub = stubMethod(sandbox, UX.prototype, 'warn'); + uxLogStub = stubMethod(sandbox, SfCommand.prototype, 'log'); + uxWarnStub = stubMethod(sandbox, SfCommand.prototype, 'warn'); return cmd.runIt(); }; diff --git a/yarn.lock b/yarn.lock index 86e87bc1..33e3927d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -742,10 +742,10 @@ is-wsl "^2.1.1" tslib "^2.3.1" -"@oclif/core@^1.14.1", "@oclif/core@^1.20.0", "@oclif/core@^1.20.3", "@oclif/core@^1.20.4", "@oclif/core@^1.21.0", "@oclif/core@^1.22.0": - version "1.22.0" - resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.22.0.tgz#dfdd76db6435cc1be2de7bbe25c23302332b9297" - integrity sha512-Bvyi6uFbmpkFl9XUATsGMlqEDGfqMKWL0Mu5VQTuPg7/NIyfygYkaburn11uGkOp0a8yG6fPpyVBfGmztjNPGA== +"@oclif/core@^1.14.1", "@oclif/core@^1.20.3", "@oclif/core@^1.20.4", "@oclif/core@^1.21.0", "@oclif/core@^1.22.0", "@oclif/core@^1.23.0": + version "1.23.0" + resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.23.0.tgz#4bad6f950dd9431f90f481c7253b67857540def4" + integrity sha512-LnQoRtyQLQCsEHQsY7Ju0Z+g84XIVTxtVWr9hq81Juzj0o2f4zaFZ3f39VfnXvxI4m+QmROaoUJvr417eSEuhg== dependencies: "@oclif/linewrap" "^1.0.0" "@oclif/screen" "^3.0.3" @@ -1060,7 +1060,7 @@ strip-ansi "6.0.1" ts-retry-promise "^0.7.0" -"@salesforce/command@^5.2.27", "@salesforce/command@^5.2.33": +"@salesforce/command@^5.2.33": version "5.2.35" resolved "https://registry.yarnpkg.com/@salesforce/command/-/command-5.2.35.tgz#2f0e721c49aee0db4531b291722c8ebab5b68598" integrity sha512-OMy4kASYFyIOrenJ2r0o9PvRECv+OwlAa45lf0Ip4M5UwvRQvQPay+AqVdvd4olPlqgyrHAEw4wTe5lMHK6cxA== @@ -1072,7 +1072,7 @@ "@salesforce/ts-types" "^1.7.1" chalk "^2.4.2" -"@salesforce/core@^3.30.12", "@salesforce/core@^3.32.12": +"@salesforce/core@^3.32.12", "@salesforce/core@^3.32.9": version "3.32.12" resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.32.12.tgz#853cc5b6a5f95d4896b2d34a40a6042ef9aa6d2c" integrity sha512-27rqSiQWul7b/OkJs19FYDv2M/S4oI4efiGv+6sR7UWv7D7CG1P+0XpgLS3d9xRYF30h98n6VQr4W2a+BWFRvA== @@ -1139,7 +1139,7 @@ typedoc-plugin-missing-exports "0.23.0" typescript "^4.1.3" -"@salesforce/kit@^1.6.1", "@salesforce/kit@^1.8.0": +"@salesforce/kit@^1.7.1", "@salesforce/kit@^1.8.0": version "1.8.0" resolved "https://registry.yarnpkg.com/@salesforce/kit/-/kit-1.8.0.tgz#d5b8d83d5b0b866cb76840dc7a18e115589d86a0" integrity sha512-Pr9CWAIzVYKZRWvM76lyhEtF3CPmVdIfgbqRD7KT/YZdbLstX3KHYBxCyx3TyWZr5qROv96n+jRIBiIFI9LGGw== @@ -1172,6 +1172,18 @@ resolved "https://registry.yarnpkg.com/@salesforce/schemas/-/schemas-1.4.0.tgz#7dff427c8059895d8108176047aee600703c82d6" integrity sha512-BJ25uphssN42Zy6kksheFHMTLiR98AAHe/Wxnv0T4dYxtrEbUjSXVAGKZqfewJPFXA4xB5gxC+rQZtfz6xKCFg== +"@salesforce/sf-plugins-core@^1.21.3": + version "1.21.3" + resolved "https://registry.yarnpkg.com/@salesforce/sf-plugins-core/-/sf-plugins-core-1.21.3.tgz#f2ecc6e8a6c0b59ff15bb59d81408199983e18aa" + integrity sha512-Q5E+BLORRA92Em0IDuRESe/2qc/zrarJA7uRhDvLEaqic4V8rM8q9jVy7lddaOyqo1DYPbYx9Ck7YST3g3k3kQ== + dependencies: + "@oclif/core" "^1.22.0" + "@salesforce/core" "^3.32.9" + "@salesforce/kit" "^1.7.1" + "@salesforce/ts-types" "^1.7.1" + chalk "^4" + inquirer "^8.2.5" + "@salesforce/ts-sinon@1.4.2": version "1.4.2" resolved "https://registry.yarnpkg.com/@salesforce/ts-sinon/-/ts-sinon-1.4.2.tgz#7b76f80c104c891334b84ad664ab048fd1fbb1ff" @@ -1618,6 +1630,14 @@ "@typescript-eslint/types" "5.47.0" "@typescript-eslint/visitor-keys" "5.47.0" +"@typescript-eslint/scope-manager@5.47.1": + version "5.47.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.47.1.tgz#0d302b3c2f20ab24e4787bf3f5a0d8c449b823bd" + integrity sha512-9hsFDsgUwrdOoW1D97Ewog7DYSHaq4WKuNs0LHF9RiCmqB0Z+XRR4Pf7u7u9z/8CciHuJ6yxNws1XznI3ddjEw== + dependencies: + "@typescript-eslint/types" "5.47.1" + "@typescript-eslint/visitor-keys" "5.47.1" + "@typescript-eslint/type-utils@5.42.1": version "5.42.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.42.1.tgz#21328feb2d4b193c5852b35aabd241ccc1449daa" @@ -1638,6 +1658,11 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.47.0.tgz#67490def406eaa023dbbd8da42ee0d0c9b5229d3" integrity sha512-eslFG0Qy8wpGzDdYKu58CEr3WLkjwC5Usa6XbuV89ce/yN5RITLe1O8e+WFEuxnfftHiJImkkOBADj58ahRxSg== +"@typescript-eslint/types@5.47.1": + version "5.47.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.47.1.tgz#459f07428aec5a8c4113706293c2ae876741ac8e" + integrity sha512-CmALY9YWXEpwuu6377ybJBZdtSAnzXLSQcxLSqSQSbC7VfpMu/HLVdrnVJj7ycI138EHqocW02LPJErE35cE9A== + "@typescript-eslint/typescript-estree@5.42.1": version "5.42.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.42.1.tgz#f9a223ecb547a781d37e07a5ac6ba9ff681eaef0" @@ -1664,6 +1689,19 @@ semver "^7.3.7" tsutils "^3.21.0" +"@typescript-eslint/typescript-estree@5.47.1": + version "5.47.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.47.1.tgz#b9d8441308aca53df7f69b2c67a887b82c9ed418" + integrity sha512-4+ZhFSuISAvRi2xUszEj0xXbNTHceV9GbH9S8oAD2a/F9SW57aJNQVOCxG8GPfSWH/X4eOPdMEU2jYVuWKEpWA== + dependencies: + "@typescript-eslint/types" "5.47.1" + "@typescript-eslint/visitor-keys" "5.47.1" + debug "^4.3.4" + globby "^11.1.0" + is-glob "^4.0.3" + semver "^7.3.7" + tsutils "^3.21.0" + "@typescript-eslint/utils@5.42.1": version "5.42.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.42.1.tgz#2789b1cd990f0c07aaa3e462dbe0f18d736d5071" @@ -1678,6 +1716,20 @@ eslint-utils "^3.0.0" semver "^7.3.7" +"@typescript-eslint/utils@^5.47.0": + version "5.47.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.47.1.tgz#595f25ac06e9ee28c339fd43c709402820b13d7b" + integrity sha512-l90SdwqfmkuIVaREZ2ykEfCezepCLxzWMo5gVfcJsJCaT4jHT+QjgSkYhs5BMQmWqE9k3AtIfk4g211z/sTMVw== + dependencies: + "@types/json-schema" "^7.0.9" + "@types/semver" "^7.3.12" + "@typescript-eslint/scope-manager" "5.47.1" + "@typescript-eslint/types" "5.47.1" + "@typescript-eslint/typescript-estree" "5.47.1" + eslint-scope "^5.1.1" + eslint-utils "^3.0.0" + semver "^7.3.7" + "@typescript-eslint/visitor-keys@5.42.1": version "5.42.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.42.1.tgz#df10839adf6605e1cdb79174cf21e46df9be4872" @@ -1694,6 +1746,14 @@ "@typescript-eslint/types" "5.47.0" eslint-visitor-keys "^3.3.0" +"@typescript-eslint/visitor-keys@5.47.1": + version "5.47.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.47.1.tgz#d35c2da544dbb685db9c5b5b85adac0a1d74d1f2" + integrity sha512-rF3pmut2JCCjh6BLRhNKdYjULMb1brvoaiWDlHfLNVgmnZ0sBVJrs3SyaKE1XoDDnJuAx/hDQryHYmPUuNq0ig== + dependencies: + "@typescript-eslint/types" "5.47.1" + eslint-visitor-keys "^3.3.0" + "@ungap/promise-all-settled@1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" @@ -1773,17 +1833,7 @@ ajv@^6.10.0, ajv@^6.12.4: json-schema-traverse "^0.4.1" uri-js "^4.2.2" -ajv@^8.0.1, ajv@^8.11.0: - version "8.11.0" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.11.0.tgz#977e91dd96ca669f54a11e23e378e33b884a565f" - integrity sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg== - dependencies: - fast-deep-equal "^3.1.1" - json-schema-traverse "^1.0.0" - require-from-string "^2.0.2" - uri-js "^4.2.2" - -ajv@^8.11.2: +ajv@^8.0.1, ajv@^8.11.0, ajv@^8.11.2: version "8.11.2" resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.11.2.tgz#aecb20b50607acf2569b6382167b65a96008bb78" integrity sha512-E4bfmKAhGiSTvMfL1Myyycaub+cUEU2/IvpylXkUu7CHBkBj1f/ikdzbD7YQ6FKUbixDxeYvB/xY4fvyroDlQg== @@ -2359,7 +2409,7 @@ chalk@^3.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" -chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2: +chalk@^4, chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== @@ -3322,6 +3372,13 @@ eslint-plugin-prefer-arrow@^1.2.1: resolved "https://registry.yarnpkg.com/eslint-plugin-prefer-arrow/-/eslint-plugin-prefer-arrow-1.2.3.tgz#e7fbb3fa4cd84ff1015b9c51ad86550e55041041" integrity sha512-J9I5PKCOJretVuiZRGvPQxCbllxGAV/viI20JO3LYblAodofBxyMnZAJ+WGeClHgANnSJberTNoFWWjrWKBuXQ== +eslint-plugin-sf-plugin@^1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-sf-plugin/-/eslint-plugin-sf-plugin-1.3.1.tgz#c122b74719cdc46bdd27c7d5dd157357c00a110e" + integrity sha512-KqH/XpbkbMR4tPdcjDNBoCpgBZK6YiDSdc03XEM/zr0LrzdZUtos0K1Y76n+A3ZMROHr9xzRu127e1/oLEK0bg== + dependencies: + "@typescript-eslint/utils" "^5.47.0" + eslint-scope@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" @@ -4454,7 +4511,7 @@ inquirer@^7.0.0: strip-ansi "^6.0.0" through "^2.3.6" -inquirer@^8.0.0: +inquirer@^8.0.0, inquirer@^8.2.5: version "8.2.5" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.2.5.tgz#d8654a7542c35a9b9e069d27e2df4858784d54f8" integrity sha512-QAgPDQMEgrDssk1XiwwHoOGYF9BAbUcc1+j+FhEvaOt8/cKRqyLn0U5qA6F74fGhTMGxf92pOvPBeh29jQJDTQ== @@ -8172,7 +8229,7 @@ yargs-parser@^20.2.2, yargs-parser@^20.2.3: resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w== -yargs-parser@^21.0.0, yargs-parser@^21.1.1: +yargs-parser@^21.1.1: version "21.1.1" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35" integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw== @@ -8217,20 +8274,7 @@ yargs@^15.0.2: y18n "^4.0.0" yargs-parser "^18.1.2" -yargs@^17.0.0: - version "17.6.0" - resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.6.0.tgz#e134900fc1f218bc230192bdec06a0a5f973e46c" - integrity sha512-8H/wTDqlSwoSnScvV2N/JHfLWOKuh5MVla9hqLjK3nsfyy6Y4kDSYSvkU5YCUEPOSnRXfIyx3Sq+B/IWudTo4g== - dependencies: - cliui "^8.0.1" - escalade "^3.1.1" - get-caller-file "^2.0.5" - require-directory "^2.1.1" - string-width "^4.2.3" - y18n "^5.0.5" - yargs-parser "^21.0.0" - -yargs@^17.3.1: +yargs@^17.0.0, yargs@^17.3.1: version "17.6.2" resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.6.2.tgz#2e23f2944e976339a1ee00f18c77fedee8332541" integrity sha512-1/9UrdHjDZc0eOU0HxOHoS78C69UD3JRMvzlJ7S79S2nTaWRA/whGCTV8o9e/N/1Va9YIV7Q4sOxD8VV4pCWOw==