Skip to content

Commit

Permalink
fix: fixed CLI throwing an error when no versions are deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Aug 24, 2021
1 parent 28cbec1 commit 15134b8
Showing 1 changed file with 42 additions and 36 deletions.
78 changes: 42 additions & 36 deletions src/commands/deprecate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export async function deprecatePackages(options: Options): Promise<void> {
logVerboseInfo([`Found ${registryJsonFiles.length} packages on the NPM registry`]);

const fetchPromises: Promise<unknown>[] = [];
let amountVersionsChanged = 0;

for (const pkg of registryJsonFiles) {
const distTags = Object.values(pkg['dist-tags']);
Expand All @@ -64,48 +65,53 @@ export async function deprecatePackages(options: Options): Promise<void> {
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
});
}
}
}

0 comments on commit 15134b8

Please sign in to comment.