diff --git a/lib/index.js b/lib/index.js index c7245c7..747a9b8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 + ) + } + }) } } @@ -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, @@ -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} @@ -897,6 +903,21 @@ async function teamRun(context, npmOrg, npmOrgPackages, npmTeam) { await pSeries(tasks) } +/** + * @param {Context} context + * @param {string} name + * @returns {Promise} + */ +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}