Skip to content

Commit

Permalink
fix: scope install warnings to plugin being installed (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Nov 16, 2023
1 parent a659c74 commit 51f7721
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
)
}
}
Expand All @@ -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', '')
}
}
56 changes: 56 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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')
})
})

0 comments on commit 51f7721

Please sign in to comment.