forked from aws/aws-cdk-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpm.ts
More file actions
30 lines (25 loc) · 1.05 KB
/
npm.ts
File metadata and controls
30 lines (25 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { exec as _exec } from 'child_process';
import { promisify } from 'util';
import { ToolkitError } from '../../toolkit/error';
const exec = promisify(_exec);
export async function execNpmView(currentVersion: string) {
const [latestResult, currentResult] = await Promise.all([
exec('npm view aws-cdk@latest version', { timeout: 3000 })
.catch(err => {
throw new ToolkitError(`Failed to fetch latest version info: ${err.message}`);
}),
exec(`npm view aws-cdk@${currentVersion} name version deprecated --json`, { timeout: 3000 })
.catch(err => {
throw new ToolkitError(`Failed to fetch current version(${currentVersion}) info: ${err.message}`);
})
]);
if (latestResult.stderr && latestResult.stderr.trim().length > 0) {
throw new ToolkitError(`npm view command failed: ${latestResult.stderr.trim()}`);
}
const latestVersion = latestResult.stdout;
const currentInfo = JSON.parse(currentResult.stdout);
return {
latestVersion: latestVersion,
deprecated: currentInfo.deprecated
};
}