Skip to content

Commit

Permalink
chore: Get the version of pnpm with getpnpmInfo (web-infra-dev#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanianlisao authored Jun 5, 2024
1 parent 176ff3c commit be9fbdd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/src/sdk/sdk/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export abstract class SDKCore<T extends RsdoctorSDKOptions>
EnvInfo.getNodeVersion(),
EnvInfo.getYarnVersion(),
EnvInfo.getNpmVersion(),
EnvInfo.getGlobalNpmPackageVersion('pnpm'),
EnvInfo.getPnpmVersion(),
]);

this._envinfo = {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"@types/babel__code-frame": "7.0.3",
"@types/bytes": "3.1.1",
"@types/connect": "3.4.35",
"@types/envinfo": "7.8.1",
"@types/envinfo": "7.8.4",
"@types/fs-extra": "^11.0.2",
"@types/lodash": "^4.17.0",
"@types/node": "^16",
Expand Down
59 changes: 27 additions & 32 deletions packages/utils/src/build/envinfo.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,53 @@
import { helpers, run } from 'envinfo';
import { exec } from 'child_process';

export const getCPUInfo = () =>
helpers.getCPUInfo().then((res) => res[1]);
export const getCPUInfo = () => helpers.getCPUInfo().then((res) => res[1]);

export const getOSInfo = () =>
helpers.getOSInfo().then((res) => res[1]);
export const getOSInfo = () => helpers.getOSInfo().then((res) => res[1]);

export const getMemoryInfo = () =>
helpers.getMemoryInfo().then((res) => res[1]);

export const getNodeVersion = () =>
helpers.getNodeInfo().then((res) => res[1]);
export const getNodeVersion = () => helpers.getNodeInfo().then((res) => res[1]);

export const getYarnVersion = () =>
helpers.getYarnInfo().then((res) => res[1]);
export const getYarnVersion = () => helpers.getYarnInfo().then((res) => res[1]);

export const getNpmVersion = () =>
helpers.getnpmInfo().then((res) => res[1]);
export const getNpmVersion = () => helpers.getnpmInfo().then((res) => res[1]);

export const getPnpmVersion = () => helpers.getpnpmInfo().then((res) => res[1]);

export function getNpmPackageVersion(pkg: string): Promise<string>;
export function getNpmPackageVersion(pkgs: string[]): Promise<string[]>;
export function getNpmPackageVersion(pkg: unknown): Promise<unknown> {
const isArray = Array.isArray(pkg);
return run(
{
npmPackages: isArray ? pkg : [pkg],
},
{ json: true, showNotFound: true },
)
.then((res) => {
const { npmPackages = {} } = JSON.parse(res) || {};
return isArray
? pkg.map((e) => npmPackages[e] || 'Not Found')
: npmPackages[pkg as string];
});
{
npmPackages: isArray ? pkg : [pkg],
},
{ json: true, showNotFound: true },
).then((res) => {
const { npmPackages = {} } = JSON.parse(res) || {};
return isArray
? pkg.map((e) => npmPackages[e] || 'Not Found')
: npmPackages[pkg as string];
});
}

export function getGlobalNpmPackageVersion(pkg: string): Promise<string>;
export function getGlobalNpmPackageVersion(pkgs: string[]): Promise<string[]>;
export function getGlobalNpmPackageVersion(pkg: unknown): Promise<unknown> {
const isArray = Array.isArray(pkg);
return run(
{
npmGlobalPackages: isArray ? pkg : [pkg],
},
{ json: true, showNotFound: true },
)
.then((res) => {
const { npmGlobalPackages = {} } = JSON.parse(res) || {};
return isArray
? pkg.map((e) => npmGlobalPackages[e] || 'Not Found')
: npmGlobalPackages[pkg as string];
});
{
npmGlobalPackages: isArray ? pkg : [pkg],
},
{ json: true, showNotFound: true },
).then((res) => {
const { npmGlobalPackages = {} } = JSON.parse(res) || {};
return isArray
? pkg.map((e) => npmGlobalPackages[e] || 'Not Found')
: npmGlobalPackages[pkg as string];
});
}

export function getGitBranch() {
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be9fbdd

Please sign in to comment.