diff --git a/README.md b/README.md index fb8fe088..71095cd4 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,7 @@ plugins plugin for oclif - [Aliases](#aliases) - [Environment Variables](#environment-variables) - [Commands](#commands) - - [`mycli plugins`](#mycli-plugins) - - [`mycli plugins:inspect PLUGIN...`](#mycli-pluginsinspect-plugin) - - [`mycli plugins:install PLUGIN...`](#mycli-pluginsinstall-plugin) - - [`mycli plugins:link PLUGIN`](#mycli-pluginslink-plugin) - - [`mycli plugins:uninstall PLUGIN...`](#mycli-pluginsuninstall-plugin) - - [`mycli plugins:update`](#mycli-pluginsupdate) - + # What is this? @@ -94,17 +88,27 @@ For removing plugins that are no longer needed (either because they're sunset or +- [`mycli plugins`](#mycli-plugins) +- [`mycli plugins:inspect PLUGIN...`](#mycli-pluginsinspect-plugin) +- [`mycli plugins:install PLUGIN...`](#mycli-pluginsinstall-plugin) +- [`mycli plugins:link PLUGIN`](#mycli-pluginslink-plugin) +- [`mycli plugins:uninstall PLUGIN...`](#mycli-pluginsuninstall-plugin) +- [`mycli plugins update`](#mycli-plugins-update) + ## `mycli plugins` List installed plugins. ``` USAGE - $ mycli plugins [--core] + $ mycli plugins [--json] [--core] FLAGS --core Show core plugins. +GLOBAL FLAGS + --json Format output as json. + DESCRIPTION List installed plugins. @@ -112,7 +116,7 @@ EXAMPLES $ mycli plugins ``` -_See code: [src/commands/plugins/index.ts](https://github.com/oclif/plugin-plugins/blob/v2.0.12/src/commands/plugins/index.ts)_ +_See code: [src/commands/plugins/index.ts](https://github.com/oclif/plugin-plugins/blob/3.9.4-qa.0/src/commands/plugins/index.ts)_ ## `mycli plugins:inspect PLUGIN...` @@ -129,6 +133,9 @@ FLAGS -h, --help Show CLI help. -v, --verbose +GLOBAL FLAGS + --json Format output as json. + DESCRIPTION Displays installation properties of a plugin. @@ -136,7 +143,7 @@ EXAMPLES $ mycli plugins:inspect myplugin ``` -_See code: [src/commands/plugins/inspect.ts](https://github.com/oclif/plugin-plugins/blob/v2.0.12/src/commands/plugins/inspect.ts)_ +_See code: [src/commands/plugins/inspect.ts](https://github.com/oclif/plugin-plugins/blob/3.9.4-qa.0/src/commands/plugins/inspect.ts)_ ## `mycli plugins:install PLUGIN...` @@ -152,11 +159,11 @@ ARGUMENTS FLAGS -f, --force Run yarn install with force flag. -h, --help Show CLI help. - -v, --verbose + -s, --silent Silences yarn output. + -v, --verbose Show verbose yarn output. DESCRIPTION Installs a plugin into the CLI. - Can be installed from npm or a git url. Installation of a user-installed plugin will override a core plugin. @@ -165,8 +172,9 @@ DESCRIPTION will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in the CLI without the need to patch and update the whole CLI. + ALIASES - $ mycli plugins:add + $ mycli plugins add EXAMPLES $ mycli plugins:install myplugin @@ -176,7 +184,7 @@ EXAMPLES $ mycli plugins:install someuser/someplugin ``` -_See code: [src/commands/plugins/install.ts](https://github.com/oclif/plugin-plugins/blob/v2.0.12/src/commands/plugins/install.ts)_ +_See code: [src/commands/plugins/install.ts](https://github.com/oclif/plugin-plugins/blob/3.9.4-qa.0/src/commands/plugins/install.ts)_ ## `mycli plugins:link PLUGIN` @@ -190,22 +198,23 @@ ARGUMENTS PATH [default: .] path to plugin FLAGS - -h, --help Show CLI help. + -h, --help Show CLI help. -v, --verbose + --[no-]install Install dependencies after linking the plugin. DESCRIPTION Links a plugin into the CLI for development. - Installation of a linked plugin will override a user-installed or core plugin. e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello' command will override the user-installed or core plugin implementation. This is useful for development work. + EXAMPLES $ mycli plugins:link myplugin ``` -_See code: [src/commands/plugins/link.ts](https://github.com/oclif/plugin-plugins/blob/v2.0.12/src/commands/plugins/link.ts)_ +_See code: [src/commands/plugins/link.ts](https://github.com/oclif/plugin-plugins/blob/3.9.4-qa.0/src/commands/plugins/link.ts)_ ## `mycli plugins:uninstall PLUGIN...` @@ -226,19 +235,19 @@ DESCRIPTION Removes a plugin from the CLI. ALIASES - $ mycli plugins:unlink - $ mycli plugins:remove + $ mycli plugins unlink + $ mycli plugins remove ``` -_See code: [src/commands/plugins/uninstall.ts](https://github.com/oclif/plugin-plugins/blob/v2.0.12/src/commands/plugins/uninstall.ts)_ +_See code: [src/commands/plugins/uninstall.ts](https://github.com/oclif/plugin-plugins/blob/3.9.4-qa.0/src/commands/plugins/uninstall.ts)_ -## `mycli plugins:update` +## `mycli plugins update` Update installed plugins. ``` USAGE - $ mycli plugins:update [-h] [-v] + $ mycli plugins update [-h] [-v] FLAGS -h, --help Show CLI help. @@ -248,6 +257,6 @@ DESCRIPTION Update installed plugins. ``` -_See code: [src/commands/plugins/update.ts](https://github.com/oclif/plugin-plugins/blob/v2.0.12/src/commands/plugins/update.ts)_ +_See code: [src/commands/plugins/update.ts](https://github.com/oclif/plugin-plugins/blob/3.9.4-qa.0/src/commands/plugins/update.ts)_ diff --git a/package.json b/package.json index 1893ed70..46d951c3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@oclif/plugin-plugins", "description": "plugins plugin for oclif", - "version": "3.9.3", + "version": "3.9.4-qa.0", "author": "Salesforce", "bugs": "https://github.com/oclif/plugin-plugins/issues", "dependencies": { @@ -21,13 +21,11 @@ "@oclif/prettier-config": "^0.2.1", "@types/chai": "^4.3.6", "@types/debug": "^4.1.9", - "@types/glob": "^8.1.0", "@types/mocha": "^10.0.2", "@types/node": "^18", "@types/semver": "^7.5.3", "@types/shelljs": "^0.8.13", "@types/sinon": "^10.0.19", - "@types/supports-color": "^7.2.0", "@types/validate-npm-package-name": "^4.0.0", "chai": "^4.3.10", "commitlint": "^17.8.0", @@ -35,11 +33,9 @@ "eslint-config-oclif": "^5.0.0", "eslint-config-oclif-typescript": "^3.0.6", "eslint-config-prettier": "^9.0.0", - "globby": "^11.1.0", "husky": "^8.0.3", "lint-staged": "^15.0.1", "mocha": "^10.2.0", - "nock": "^13.3.3", "oclif": "^4.0.2", "prettier": "^3.0.3", "shx": "^0.3.4", diff --git a/src/commands/plugins/inspect.ts b/src/commands/plugins/inspect.ts index a06d8c63..56a6ef6a 100644 --- a/src/commands/plugins/inspect.ts +++ b/src/commands/plugins/inspect.ts @@ -19,7 +19,21 @@ function trimUntil(fsPath: string, part: string): string { } type Dependencies = Record -type PluginWithDeps = Plugin & {deps: Dependencies} +type PluginWithDeps = Omit< + Plugin, + | '_commandsDir' + | '_debug' + | '_manifest' + | 'addErrorScope' + | 'commandIDs' + | 'commandsDir' + | 'findCommand' + | 'flexibleTaxonomy' + | 'load' + | 'topics' + | 'warn' + | 'warned' +> & {deps: Dependencies} export default class PluginsInspect extends Command { static args = { @@ -47,8 +61,6 @@ export default class PluginsInspect extends Command { plugins = new Plugins(this.config) - // In this case we want these operations to happen - // sequentially so the `no-await-in-loop` rule is ignored async findDep(plugin: Plugin, dependency: string): Promise<{pkgPath: null | string; version: null | string}> { const dependencyPath = join(...dependency.split('/')) let start = join(plugin.root, 'node_modules') @@ -58,21 +70,18 @@ export default class PluginsInspect extends Command { paths.push(start) } - // TODO: use promise.any to check the paths in parallel - // requires node >= 16 - for (const p of paths) { - const fullPath = join(p, dependencyPath) - const pkgJsonPath = join(fullPath, 'package.json') - try { - // eslint-disable-next-line no-await-in-loop - const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf8')) - return {pkgPath: fullPath, version: pkgJson.version as string} - } catch { - // try the next path - } + try { + return await Promise.any( + paths.map(async (p) => { + const fullPath = join(p, dependencyPath) + const pkgJsonPath = join(fullPath, 'package.json') + const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf8')) + return {pkgPath: fullPath, version: pkgJson.version as string} + }), + ) + } catch { + return {pkgPath: null, version: null} } - - return {pkgPath: null, version: null} } findPlugin(pluginName: string): Plugin { @@ -122,7 +131,7 @@ export default class PluginsInspect extends Command { if (!this.jsonEnabled()) tree.display() - return {...plugin, deps: depsJson} as PluginWithDeps + return {...plugin, deps: depsJson} } /* eslint-disable no-await-in-loop */ diff --git a/src/plugins.ts b/src/plugins.ts index 74bc27a2..3ee70ca6 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -63,15 +63,16 @@ export default class Plugins { return match?.[1] ?? name } - async hasPlugin(name: string): Promise { + async hasPlugin( + name: string, + ): Promise { const list = await this.list() - const friendly = list.find((p) => this.friendlyName(p.name) === this.friendlyName(name)) - const unfriendly = list.find((p) => this.unfriendlyName(p.name) === this.unfriendlyName(name)) - const link = list.find((p) => p.type === 'link' && resolve(p.root) === resolve(name)) - return (friendly ?? unfriendly ?? link ?? false) as - | Interfaces.PJSON.PluginTypes.Link - | Interfaces.PJSON.User - | false + return ( + list.find((p) => this.friendlyName(p.name) === this.friendlyName(name)) ?? // friendly + list.find((p) => this.unfriendlyName(p.name) === this.unfriendlyName(name)) ?? // unfriendly + list.find((p) => p.type === 'link' && resolve(p.root) === resolve(name)) ?? // link + false + ) } async install(name: string, {force = false, tag = 'latest'} = {}): Promise { diff --git a/src/util.ts b/src/util.ts index 0a923f78..27e461d2 100644 --- a/src/util.ts +++ b/src/util.ts @@ -97,7 +97,7 @@ export async function findNpm(): Promise { } export class WarningsCache { - private static cache: string[] = [] + private static cache = new Set() private static instance: WarningsCache public static getInstance(): WarningsCache { if (!WarningsCache.instance) { @@ -109,9 +109,7 @@ export class WarningsCache { public add(...warnings: string[]): void { for (const warning of warnings) { - if (!WarningsCache.cache.includes(warning)) { - WarningsCache.cache.push(warning) - } + WarningsCache.cache.add(warning) } } diff --git a/yarn.lock b/yarn.lock index b767469f..6953cc36 100644 --- a/yarn.lock +++ b/yarn.lock @@ -651,38 +651,7 @@ wordwrap "^1.0.0" wrap-ansi "^7.0.0" -"@oclif/core@^3.0.4", "@oclif/core@^3.2.1": - version "3.3.2" - resolved "https://registry.yarnpkg.com/@oclif/core/-/core-3.3.2.tgz#1244aa19313681000881d97dd0e956a4ed48daa5" - integrity sha512-8bZa42d86t5BayJUENKqZN6c5CnX0n3j+JyCWmqI5PP7VsRWZl4YSXFoLFw+mZXKtvwAMrgzMxSGltm5iIXT7w== - dependencies: - ansi-escapes "^4.3.2" - ansi-styles "^4.3.0" - cardinal "^2.1.1" - chalk "^4.1.2" - clean-stack "^3.0.1" - cli-progress "^3.12.0" - debug "^4.3.4" - ejs "^3.1.9" - get-package-type "^0.1.0" - globby "^11.1.0" - hyperlinker "^1.0.0" - indent-string "^4.0.0" - is-wsl "^2.2.0" - js-yaml "^3.14.1" - natural-orderby "^2.0.3" - object-treeify "^1.1.33" - password-prompt "^1.1.2" - slice-ansi "^4.0.0" - string-width "^4.2.3" - strip-ansi "^6.0.1" - supports-color "^8.1.1" - supports-hyperlinks "^2.2.0" - widest-line "^3.1.0" - wordwrap "^1.0.0" - wrap-ansi "^7.0.0" - -"@oclif/core@^3.4.0": +"@oclif/core@^3.0.4", "@oclif/core@^3.2.1", "@oclif/core@^3.4.0": version "3.4.0" resolved "https://registry.yarnpkg.com/@oclif/core/-/core-3.4.0.tgz#5400ad77061b4828e2d1b70c5091b38bf25ed389" integrity sha512-+5S7xBa8zPE0iaStTwLgPWP2xwp17bCypMruJW8rti3rueF/4dR+4JHZ6izbRjWGbtD20Ty3nt3e/UhpCYMVQQ== @@ -1012,14 +981,6 @@ resolved "https://registry.yarnpkg.com/@types/expect/-/expect-1.20.4.tgz#8288e51737bf7e3ab5d7c77bfa695883745264e5" integrity sha512-Q5Vn3yjTDyCMV50TB6VRIbQNxSE4OmZR86VSbGaNpfUolm0iePBB4KdEEHmxoY5sT2+2DIvXW0rvMDP2nHZ4Mg== -"@types/glob@^8.1.0": - version "8.1.0" - resolved "https://registry.yarnpkg.com/@types/glob/-/glob-8.1.0.tgz#b63e70155391b0584dce44e7ea25190bbc38f2fc" - integrity sha512-IO+MJPVhoqz+28h1qLAcBEH2+xHMK6MTyHJc7MTnnYb6wsoLR29POVGJ7LycmVXIqyy/4/2ShP5sUwTXuOwb/w== - dependencies: - "@types/minimatch" "^5.1.2" - "@types/node" "*" - "@types/glob@~7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb" @@ -1050,7 +1011,7 @@ dependencies: "@types/node" "*" -"@types/minimatch@*", "@types/minimatch@^5.1.2": +"@types/minimatch@*": version "5.1.2" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca" integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA== @@ -1134,11 +1095,6 @@ resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.3.tgz#575789c5cf6d410cb288b0b4affaf7e6da44ca51" integrity sha512-4g+2YyWe0Ve+LBh+WUm1697PD0Kdi6coG1eU0YjQbwx61AZ8XbEpL1zIT6WjuUKrCMCROpEaYQPDjBnDouBVAQ== -"@types/supports-color@^7.2.0": - version "7.2.1" - resolved "https://registry.yarnpkg.com/@types/supports-color/-/supports-color-7.2.1.tgz#58a6efe82d9eca92cf316b16112fcd2675ffa6c0" - integrity sha512-glb1BXM/pchMWTt9kg67CceKqyAW3NGBviNPKXN84JJhk3shqVpyi5d5MM4MWYoZHHk/Ioct7Yt1TNqQORiIAw== - "@types/validate-npm-package-name@^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@types/validate-npm-package-name/-/validate-npm-package-name-4.0.0.tgz#3b53194dd3888fbb01f794fa368fb3472381d1fe" @@ -4063,11 +4019,6 @@ json-stringify-nice@^1.1.4: resolved "https://registry.yarnpkg.com/json-stringify-nice/-/json-stringify-nice-1.1.4.tgz#2c937962b80181d3f317dd39aa323e14f5a60a67" integrity sha512-5Z5RFW63yxReJ7vANgW6eZFGWaQvnPE3WNmZoOJrSkGju2etKA2L5rrOa1sm877TVTFt57A80BH1bArcmlLfPw== -json-stringify-safe@^5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" - integrity sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA== - json5@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.2.tgz#63d98d60f21b313b77c4d6da18bfa69d80e1d593" @@ -4871,16 +4822,6 @@ no-case@^3.0.4: lower-case "^2.0.2" tslib "^2.0.3" -nock@^13.3.3: - version "13.3.4" - resolved "https://registry.yarnpkg.com/nock/-/nock-13.3.4.tgz#4ed3ed1465a75c87833044a881dbdd6546337e8d" - integrity sha512-DDpmn5oLEdCTclEqweOT4U7bEpuoifBMFUXem9sA4turDAZ5tlbrEoWqCorwXey8CaAw44mst5JOQeVNiwtkhw== - dependencies: - debug "^4.1.0" - json-stringify-safe "^5.0.1" - lodash "^4.17.21" - propagate "^2.0.0" - node-fetch@^2.6.7: version "2.7.0" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" @@ -5739,11 +5680,6 @@ promzard@^1.0.0: dependencies: read "^2.0.0" -propagate@^2.0.0: - version "2.0.1" - resolved "https://registry.yarnpkg.com/propagate/-/propagate-2.0.1.tgz#40cdedab18085c792334e64f0ac17256d38f9a45" - integrity sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag== - pump@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64"