Skip to content

Commit

Permalink
Fix checking of deprecated packages
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Oct 9, 2024
1 parent ddf7396 commit 1983776
Showing 1 changed file with 44 additions and 23 deletions.
67 changes: 44 additions & 23 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,19 @@ async function organizationRun(context, npmOrg) {
})

if (!info) {
console.error(
' ' + chalk.red('✖') + ' npm package `%s` should not be in org `%s`',
name,
npmOrg.npm
)
tasks.push(async function () {
const packageArchived = await deprecated(context, name)

if (!packageArchived) {
console.error(
' ' +
chalk.red('✖') +
' npm package `%s` should not be in org `%s` (or it should be deprecated)',
name,
npmOrg.npm
)
}
})
}
}

Expand Down Expand Up @@ -326,7 +334,7 @@ async function organizationRun(context, npmOrg) {
(actualRole === 'admin' && expectedRole === 'developer')
) {
console.error(
' ' +
' ' +
chalk.red('✖') +
' unexpected user `%s` with more rights (`%s`) than expected (`%s`), ignoring',
human.npm,
Expand Down Expand Up @@ -596,28 +604,26 @@ async function packageRun(context, npmOrg, repo, manifestFilename) {

// We don’t do missing here: people are added to teams, so they’ll be warned
// about in the team pipeline.
const packageArchived = await deprecated(context, packageData.name)

if (!repo.archived) {
const response = await fetch(
'https://registry.npmjs.org/' + encodeURIComponent(packageData.name),
{headers: {Authorization: 'Bearer ' + context.npmToken}}
)
const packument = /** @type {Packument} */ (await response.json())
const version = packument.versions[packument['dist-tags'].latest]
const deprecated = 'deprecated' in version

// Note: archived repos don’t return package manifests, so we can’t check
// if packages from archived repos are deprecated.

if (deprecated) {
console.info(
' ' +
chalk.blue('ℹ') +
' unexpected deprecated `%s`, in unarchived repo `%s`',
if (repo.archived) {
if (!packageArchived) {
console.error(
' ' +
chalk.red('✖') +
'unexpected undeprecated package `%s` in archived repo `%s`',
packageData.name,
repo.name
)
}
} else if (packageArchived) {
console.info(
' ' +
chalk.blue('ℹ') +
' unexpected deprecated package `%s` in unarchived repo `%s`',
packageData.name,
repo.name
)
}

return {name: packageData.name, repo: repo.name}
Expand Down Expand Up @@ -897,6 +903,21 @@ async function teamRun(context, npmOrg, npmOrgPackages, npmTeam) {
await pSeries(tasks)
}

/**
* @param {Context} context
* @param {string} name
* @returns {Promise<boolean>}
*/
async function deprecated(context, name) {
const manifestResponse = await fetch(
'https://registry.npmjs.org/' + encodeURIComponent(name),
{headers: {Authorization: 'Bearer ' + context.npmToken}}
)
const packument = /** @type {Packument} */ (await manifestResponse.json())
const version = packument.versions[packument['dist-tags'].latest]
return 'deprecated' in version
}

/**
* @param {GraphQl} internalFunction
* @returns {GraphQl}
Expand Down

0 comments on commit 1983776

Please sign in to comment.