mirror of
https://github.com/actions/setup-node.git
synced 2025-04-24 04:20:49 +00:00
Cleanup code
This commit is contained in:
parent
3d6c490640
commit
8f9fe012e3
2 changed files with 45 additions and 62 deletions
45
dist/setup/index.js
vendored
45
dist/setup/index.js
vendored
|
@ -71898,35 +71898,30 @@ function resolveVersionInput() {
|
||||||
function printEnvDetailsAndSetOutput() {
|
function printEnvDetailsAndSetOutput() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.startGroup('Environment details');
|
core.startGroup('Environment details');
|
||||||
// Output version of node is being used
|
const promises = ['node', 'npm', 'yarn'].map((tool) => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const output = yield getToolVersion(tool, ['--version']);
|
||||||
|
core.setOutput(`${tool}-version`, output);
|
||||||
|
}));
|
||||||
|
yield Promise.all(promises);
|
||||||
|
core.endGroup();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function getToolVersion(tool, options) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const { stdout: installedNodeVersion } = yield exec.getExecOutput('node', ['--version'], { ignoreReturnCode: true, silent: true });
|
const { stdout, stderr, exitCode } = yield exec.getExecOutput(tool, options, {
|
||||||
core.setOutput('node-version', installedNodeVersion.trim());
|
ignoreReturnCode: true,
|
||||||
|
silent: true
|
||||||
|
});
|
||||||
|
if (exitCode > 0) {
|
||||||
|
core.warning(`[warning]${stderr}`);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return stdout;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
core.setOutput('node-version', '');
|
return '';
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
const { stdout: installedNpmVersion } = yield exec.getExecOutput('npm', ['--version'], {
|
|
||||||
ignoreReturnCode: true,
|
|
||||||
silent: true
|
|
||||||
});
|
|
||||||
core.setOutput('npm-version', installedNpmVersion.trim());
|
|
||||||
}
|
|
||||||
catch (_a) {
|
|
||||||
core.setOutput('npm-version', '');
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const { stdout: installedYarnVersion } = yield exec.getExecOutput('yarn', ['--version'], {
|
|
||||||
ignoreReturnCode: true,
|
|
||||||
silent: true
|
|
||||||
});
|
|
||||||
core.setOutput('yarn-version', installedYarnVersion.trim());
|
|
||||||
}
|
|
||||||
catch (_b) {
|
|
||||||
core.setOutput('yarn-version', '');
|
|
||||||
}
|
|
||||||
core.endGroup();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
62
src/main.ts
62
src/main.ts
|
@ -101,44 +101,32 @@ function resolveVersionInput(): string {
|
||||||
|
|
||||||
async function printEnvDetailsAndSetOutput() {
|
async function printEnvDetailsAndSetOutput() {
|
||||||
core.startGroup('Environment details');
|
core.startGroup('Environment details');
|
||||||
// Output version of node is being used
|
|
||||||
try {
|
|
||||||
const {stdout: installedNodeVersion} = await exec.getExecOutput(
|
|
||||||
'node',
|
|
||||||
['--version'],
|
|
||||||
{ignoreReturnCode: true, silent: true}
|
|
||||||
);
|
|
||||||
core.setOutput('node-version', installedNodeVersion.trim());
|
|
||||||
} catch (err) {
|
|
||||||
core.setOutput('node-version', '');
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const {stdout: installedNpmVersion} = await exec.getExecOutput(
|
|
||||||
'npm',
|
|
||||||
['--version'],
|
|
||||||
{
|
|
||||||
ignoreReturnCode: true,
|
|
||||||
silent: true
|
|
||||||
}
|
|
||||||
);
|
|
||||||
core.setOutput('npm-version', installedNpmVersion.trim());
|
|
||||||
} catch {
|
|
||||||
core.setOutput('npm-version', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
const promises = ['node', 'npm', 'yarn'].map(async tool => {
|
||||||
const {stdout: installedYarnVersion} = await exec.getExecOutput(
|
const output = await getToolVersion(tool, ['--version']);
|
||||||
'yarn',
|
|
||||||
['--version'],
|
core.setOutput(`${tool}-version`, output);
|
||||||
{
|
});
|
||||||
ignoreReturnCode: true,
|
|
||||||
silent: true
|
await Promise.all(promises);
|
||||||
}
|
|
||||||
);
|
|
||||||
core.setOutput('yarn-version', installedYarnVersion.trim());
|
|
||||||
} catch {
|
|
||||||
core.setOutput('yarn-version', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getToolVersion(tool: string, options: string[]) {
|
||||||
|
try {
|
||||||
|
const {stdout, stderr, exitCode} = await exec.getExecOutput(tool, options, {
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: true
|
||||||
|
});
|
||||||
|
|
||||||
|
if (exitCode > 0) {
|
||||||
|
core.warning(`[warning]${stderr}`);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return stdout;
|
||||||
|
} catch (err) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue