mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-18 04:28:28 +02:00
Fix bunx (#18)
* Add symlink for bunx * Remove node_modules, use bundled code instead * Add revision support
This commit is contained in:
parent
67e559db2c
commit
c34bee2511
272 changed files with 71159 additions and 37631 deletions
|
@ -10,8 +10,9 @@ setup({
|
|||
version: action.getInput("bun-version") || undefined,
|
||||
customUrl: action.getInput("bun-download-url") || undefined,
|
||||
})
|
||||
.then(({ version, cacheHit }) => {
|
||||
.then(({ version, revision, cacheHit }) => {
|
||||
action.setOutput("bun-version", version);
|
||||
action.setOutput("bun-revision", revision);
|
||||
action.setOutput("cache-hit", cacheHit);
|
||||
})
|
||||
.catch((error) => {
|
||||
|
|
35
src/setup.ts
35
src/setup.ts
|
@ -1,6 +1,6 @@
|
|||
import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { readdir } from "node:fs/promises";
|
||||
import { readdir, symlink } from "node:fs/promises";
|
||||
import * as action from "@actions/core";
|
||||
import { downloadTool, extractZip } from "@actions/tool-cache";
|
||||
import * as cache from "@actions/cache";
|
||||
|
@ -13,6 +13,7 @@ export default async (options?: {
|
|||
customUrl?: string;
|
||||
}): Promise<{
|
||||
version: string;
|
||||
revision: string;
|
||||
cacheHit: boolean;
|
||||
}> => {
|
||||
const { url, cacheKey } = getDownloadUrl(options);
|
||||
|
@ -20,13 +21,13 @@ export default async (options?: {
|
|||
const dir = join(homedir(), ".bun", "bin");
|
||||
action.addPath(dir);
|
||||
const path = join(dir, "bun");
|
||||
let version: string | undefined;
|
||||
let revision: string | undefined;
|
||||
let cacheHit = false;
|
||||
if (cacheEnabled) {
|
||||
const cacheRestored = await restoreCache([path], cacheKey);
|
||||
if (cacheRestored) {
|
||||
version = await verifyBun(path);
|
||||
if (version) {
|
||||
revision = await verifyBun(path);
|
||||
if (revision) {
|
||||
cacheHit = true;
|
||||
action.info("Using a cached version of Bun.");
|
||||
} else {
|
||||
|
@ -44,9 +45,16 @@ export default async (options?: {
|
|||
await mkdirP(dir);
|
||||
await cp(exePath, path);
|
||||
await rmRF(exePath);
|
||||
version = await verifyBun(path);
|
||||
revision = await verifyBun(path);
|
||||
}
|
||||
if (!version) {
|
||||
try {
|
||||
await symlink(path, join(dir, "bunx"));
|
||||
} catch (error) {
|
||||
if (error.code !== "EEXIST") {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
if (!revision) {
|
||||
throw new Error(
|
||||
"Downloaded a new version of Bun, but failed to check its version? Try again in debug mode."
|
||||
);
|
||||
|
@ -58,8 +66,10 @@ export default async (options?: {
|
|||
action.warning("Failed to save Bun to cache.");
|
||||
}
|
||||
}
|
||||
const [version] = revision.split("+");
|
||||
return {
|
||||
version,
|
||||
revision,
|
||||
cacheHit,
|
||||
};
|
||||
};
|
||||
|
@ -119,8 +129,17 @@ async function extractBun(path: string): Promise<string> {
|
|||
}
|
||||
|
||||
async function verifyBun(path: string): Promise<string | undefined> {
|
||||
const { exitCode, stdout } = await getExecOutput(path, ["--version"], {
|
||||
const revision = await getExecOutput(path, ["--revision"], {
|
||||
ignoreReturnCode: true,
|
||||
});
|
||||
return exitCode === 0 ? stdout.trim() : undefined;
|
||||
if (revision.exitCode === 0 && /^\d+\.\d+\.\d+/.test(revision.stdout)) {
|
||||
return revision.stdout.trim();
|
||||
}
|
||||
const version = await getExecOutput(path, ["--version"], {
|
||||
ignoreReturnCode: true,
|
||||
});
|
||||
if (version.exitCode === 0 && /^\d+\.\d+\.\d+/.test(version.stdout)) {
|
||||
return version.stdout.trim();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue