diff --git a/src/util.ts b/src/util.ts index a5057d6c..256bc246 100644 --- a/src/util.ts +++ b/src/util.ts @@ -127,19 +127,31 @@ export class YarnMessagesCache { public flush(plugin?: Interfaces.Config | undefined): void { if (YarnMessagesCache.warnings.size === 0) return + let count = 0 for (const warning of YarnMessagesCache.warnings) { - ux.warn(warning) + if (!plugin) { + ux.warn(warning) + count += 1 + return + } + + // If flushing for a specific plugin, only show warnings that are specific to that plugin. + if (warning.startsWith(plugin.name) || warning.startsWith(`"${plugin.name}`)) { + count += 1 + ux.warn(warning) + } } - if (plugin) { + if (plugin && count > 0) { ux.logToStderr(`\nThese warnings can only be addressed by the owner(s) of ${plugin.name}.`) if (plugin.pjson.bugs || plugin.pjson.repository) { ux.logToStderr( - `We suggest that you create an issue at ${ - plugin.pjson.bugs ?? plugin.pjson.repository - } and ask the plugin owners to address them.\n`, + `We suggest that you create an issue at ${extractIssuesLocation( + plugin.pjson.bugs, + plugin.pjson.repository, + )} and ask the plugin owners to address them.\n`, ) } } @@ -151,3 +163,16 @@ export class YarnMessagesCache { } } } + +export function extractIssuesLocation( + bugs: {url: string} | string | undefined, + repository: {type: string; url: string} | string | undefined, +): string | undefined { + if (bugs) { + return typeof bugs === 'string' ? bugs : bugs.url + } + + if (repository) { + return typeof repository === 'string' ? repository : repository.url.replace('git+', '').replace('.git', '') + } +} diff --git a/test/utils.test.ts b/test/utils.test.ts new file mode 100644 index 00000000..ea77347e --- /dev/null +++ b/test/utils.test.ts @@ -0,0 +1,56 @@ +import {expect} from 'chai' + +import {extractIssuesLocation} from '../src/util.js' + +describe('extractIssuesLocation', () => { + it('should return url if pjson.bugs is a string', () => { + const pjson = { + bugs: 'https://github.com/oclif/plugin-plugins/issues', + name: '@oclif/plugin-plugins', + repository: { + type: 'git', + url: 'git+https://github.com/oclif/plugin-plugins.git', + }, + version: '1.0.0', + } + + expect(extractIssuesLocation(pjson.bugs, pjson.repository)).to.equal(pjson.bugs) + }) + + it('should return url is pjson.bugs is an object', () => { + const pjson = { + bugs: {url: 'https://github.com/oclif/plugin-plugins/issues'}, + name: '@oclif/plugin-plugins', + repository: { + type: 'git', + url: 'git+https://github.com/oclif/plugin-plugins.git', + }, + version: '1.0.0', + } + + expect(extractIssuesLocation(pjson.bugs, pjson.repository)).to.equal(pjson.bugs.url) + }) + + it('should return url if pjson.bugs is undefined and pjson.repository is a string', () => { + const pjson = { + name: '@oclif/plugin-plugins', + repository: 'https://github.com/oclif/plugin-plugins.git', + version: '1.0.0', + } + + expect(extractIssuesLocation(undefined, pjson.repository)).to.equal(pjson.repository) + }) + + it('should return url if pjson.bugs is undefined and pjson.repository is an object', () => { + const pjson = { + name: '@oclif/plugin-plugins', + repository: { + type: 'git', + url: 'git+https://github.com/oclif/plugin-plugins.git', + }, + version: '1.0.0', + } + + expect(extractIssuesLocation(undefined, pjson.repository)).to.equal('https://github.com/oclif/plugin-plugins') + }) +})