Skip to content

Commit dbce404

Browse files
committed
feat(lib/tool): use disposable temp dir API
1 parent 77403ea commit dbce404

2 files changed

Lines changed: 28 additions & 36 deletions

File tree

dist/index.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path, { join, basename as basename$1, dirname } from 'node:path';
22
import process$1, { env, chdir, exit } from 'node:process';
33
import require$$1$6, { stripVTControlCharacters, promisify, isDeepStrictEqual } from 'node:util';
4-
import { mkdir as mkdir$1, mkdtemp, rm, readFile as readFile$1, access } from 'node:fs/promises';
4+
import { mkdir as mkdir$1, mkdtempDisposable, readFile as readFile$1, access } from 'node:fs/promises';
55
import require$$1$8, { tmpdir, homedir } from 'node:os';
66
import fs$1, { existsSync, appendFileSync } from 'node:fs';
77
import require$$0$4 from 'util';
@@ -59025,21 +59025,17 @@ class ToolManager {
5902559025
const { size: assetSize, name: assetName } = assetDescriptor.asset;
5902659026
logger.info(`Attempting to download '${assetName}' (${humanReadableSize(assetSize)})`);
5902759027
const result = { version: this.versionOrPredicate };
59028-
const tempdir = await mkdtemp(join(tmpdir(), `${pkg.name}-`));
59028+
const tempdir = await mkdtempDisposable(join(tmpdir(), `${pkg.name}-`));
5902959029
await ensureExists(installDir);
59030-
try {
59031-
const compressedArchive = join(tempdir, assetDescriptor.asset.name);
59032-
await download(assetDescriptor.asset.browser_download_url, compressedArchive, assetSize);
59033-
await decompressCommonFormats(compressedArchive, installDir, {
59034-
filter: (file) => basename$1(file.path) == binaryName,
59035-
strip: 5
59036-
// fixme: figure this value out
59037-
}).then(
59038-
(files) => files.length == 0 ? Promise.reject(`Could not find binary '${binaryName}' in downloaded artifact`) : Promise.resolve(files)
59039-
).then(() => result.path = join(installDir, binaryName)).catch((err) => void logger.error(err));
59040-
} finally {
59041-
await rm(tempdir, { recursive: true });
59042-
}
59030+
const compressedArchive = join(tempdir.path, assetDescriptor.asset.name);
59031+
await download(assetDescriptor.asset.browser_download_url, compressedArchive, assetSize);
59032+
await decompressCommonFormats(compressedArchive, installDir, {
59033+
filter: (file) => basename$1(file.path) == binaryName,
59034+
strip: 5
59035+
// fixme: figure this value out
59036+
}).then(
59037+
(files) => files.length == 0 ? Promise.reject(`Could not find binary '${binaryName}' in downloaded artifact`) : Promise.resolve(files)
59038+
).then(() => result.path = join(installDir, binaryName)).catch((err) => void logger.error(err));
5904359039
return result;
5904459040
}
5904559041
async findCompatibleAsset() {

lib/tool.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { tmpdir } from "node:os";
2-
import { mkdtemp, rm } from "node:fs/promises";
2+
import { mkdtempDisposable } from "node:fs/promises";
33
import { basename, join } from "node:path";
44

55
import pkg from "../package.json" with { type: "json" };
@@ -57,28 +57,24 @@ export class ToolManager {
5757
logger.info(`Attempting to download '${assetName}' (${humanReadableSize(assetSize)})`);
5858

5959
const result: InstallResult = { version: this.versionOrPredicate as string };
60-
const tempdir = await mkdtemp(join(tmpdir(), `${pkg.name}-`));
60+
const tempdir = await mkdtempDisposable(join(tmpdir(), `${pkg.name}-`));
6161
await ensureExists(installDir);
6262

63-
try {
64-
const compressedArchive = join(tempdir, assetDescriptor.asset.name);
65-
66-
// download and decompress the file(await import("@actions/tool-cache").
67-
await download(assetDescriptor.asset.browser_download_url, compressedArchive, assetSize);
68-
await decompressCommonFormats(compressedArchive, installDir, {
69-
filter: (file) => basename(file.path) == binaryName,
70-
strip: 5 // fixme: figure this value out
71-
})
72-
.then((files) =>
73-
files.length == 0
74-
? Promise.reject(`Could not find binary '${binaryName}' in downloaded artifact`)
75-
: Promise.resolve(files)
76-
)
77-
.then(() => (result.path = join(installDir, binaryName)))
78-
.catch((err) => void logger.error(err));
79-
} finally {
80-
await rm(tempdir, { recursive: true });
81-
}
63+
const compressedArchive = join(tempdir.path, assetDescriptor.asset.name);
64+
65+
// download and decompress the file(await import("@actions/tool-cache").
66+
await download(assetDescriptor.asset.browser_download_url, compressedArchive, assetSize);
67+
await decompressCommonFormats(compressedArchive, installDir, {
68+
filter: (file) => basename(file.path) == binaryName,
69+
strip: 5 // fixme: figure this value out
70+
})
71+
.then((files) =>
72+
files.length == 0
73+
? Promise.reject(`Could not find binary '${binaryName}' in downloaded artifact`)
74+
: Promise.resolve(files)
75+
)
76+
.then(() => (result.path = join(installDir, binaryName)))
77+
.catch((err) => void logger.error(err));
8278

8379
// if result.path isn't defined, there has been an error
8480
return result;

0 commit comments

Comments
 (0)