diff --git a/src/commands/deprecate.ts b/src/commands/deprecate.ts index 123d335..f2fc499 100644 --- a/src/commands/deprecate.ts +++ b/src/commands/deprecate.ts @@ -47,6 +47,7 @@ export async function deprecatePackages(options: Options): Promise { logVerboseInfo([`Found ${registryJsonFiles.length} packages on the NPM registry`]); const fetchPromises: Promise[] = []; + let amountVersionsChanged = 0; for (const pkg of registryJsonFiles) { const distTags = Object.values(pkg['dist-tags']); @@ -64,48 +65,53 @@ export async function deprecatePackages(options: Options): Promise { logVerboseInfo([`Deprecating version ${version.name}@${version.version}`], options.verbose); pkg.versions[version.version].deprecated = options.message; + amountVersionsChanged++; } - fetchPromises.push( - npmFetch(`/${encodeURIComponent(pkg.name).replace(/%40/, '@')}`, { - body: pkg, - fetchRetries: 2, - fetchRetryFactor: 10, - fetchRetryMaxtimeout: 60000, - fetchRetryMintimeout: 10000, - ignoreBody: true, - isFromCI: true, - method: 'PUT', - registry: 'https://registry.npmjs.org/', - spec: packageArg, - strictSSL: true, - token: NodeAuthToken, - userAgent: 'npm/6.14.14 node/v12.22.5 linux x64 workspaces/false', - retry: { + if (amountVersionsChanged >= 1) { + fetchPromises.push( + npmFetch(`/${encodeURIComponent(pkg.name).replace(/%40/, '@')}`, { + body: pkg, fetchRetries: 2, fetchRetryFactor: 10, fetchRetryMaxtimeout: 60000, - fetchRetryMintimeout: 10000 - }, - headers: { - 'user-agent': 'npm/6.14.14 node/v12.22.5 linux x64 workspaces/false', - 'npm-command': 'deprecate', - authorization: `Bearer ${NodeAuthToken}` - } - }) - ); + fetchRetryMintimeout: 10000, + ignoreBody: true, + isFromCI: true, + method: 'PUT', + registry: 'https://registry.npmjs.org/', + spec: packageArg, + strictSSL: true, + token: NodeAuthToken, + userAgent: 'npm/6.14.14 node/v12.22.5 linux x64 workspaces/false', + retry: { + fetchRetries: 2, + fetchRetryFactor: 10, + fetchRetryMaxtimeout: 60000, + fetchRetryMintimeout: 10000 + }, + headers: { + 'user-agent': 'npm/6.14.14 node/v12.22.5 linux x64 workspaces/false', + 'npm-command': 'deprecate', + authorization: `Bearer ${NodeAuthToken}` + } + }) + ); + } } - try { - const responses = await Promise.all(fetchPromises); - logVerboseInfo([`Successfully deprecated packages with responses: ${JSON.stringify(responses)}`]); - } catch (error) { - logVerboseError({ - text: [`Got an error while deprecating!`], - exitAfterLog: true, - verbose: options.verbose, - verboseText: [error], - logWithThrownError: true - }); + if (fetchPromises.length) { + try { + const responses = await Promise.all(fetchPromises); + logVerboseInfo([`Successfully deprecated packages with responses: ${JSON.stringify(responses)}`]); + } catch (error) { + logVerboseError({ + text: [`Got an error while deprecating!`], + exitAfterLog: true, + verbose: options.verbose, + verboseText: [error], + logWithThrownError: true + }); + } } }