mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-17 20:18:24 +02:00
Various improvements and fixes to setup-bun (#40)
* Do not save cache on hit * Support Windows (canary only) * Support `registry-url` and `scope`
This commit is contained in:
parent
830e319e28
commit
a93230df19
14 changed files with 994 additions and 78881 deletions
50
src/bunfig.ts
Normal file
50
src/bunfig.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
import { EOL } from "node:os";
|
||||
import { appendFileSync } from "node:fs";
|
||||
import { info } from "@actions/core";
|
||||
|
||||
type BunfigOptions = {
|
||||
registryUrl?: string;
|
||||
scope?: string;
|
||||
};
|
||||
|
||||
export function createBunfig(options: BunfigOptions): string | null {
|
||||
const { registryUrl, scope } = options;
|
||||
|
||||
let url: URL | undefined;
|
||||
if (registryUrl) {
|
||||
try {
|
||||
url = new URL(registryUrl);
|
||||
} catch {
|
||||
throw new Error(`Invalid registry-url: ${registryUrl}`);
|
||||
}
|
||||
}
|
||||
|
||||
let owner: string | undefined;
|
||||
if (scope) {
|
||||
owner = scope.startsWith("@")
|
||||
? scope.toLocaleLowerCase()
|
||||
: `@${scope.toLocaleLowerCase()}`;
|
||||
}
|
||||
|
||||
if (url && owner) {
|
||||
return `[install.scopes]${EOL}'${owner}' = { token = "$BUN_AUTH_TOKEN", url = "${url}"}${EOL}`;
|
||||
}
|
||||
|
||||
if (url && !owner) {
|
||||
return `[install]${EOL}registry = "${url}"${EOL}`;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function writeBunfig(path: string, options: BunfigOptions): void {
|
||||
const bunfig = createBunfig(options);
|
||||
if (!bunfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
info(`Writing bunfig.toml to '${path}'.`);
|
||||
appendFileSync(path, bunfig, {
|
||||
encoding: "utf8",
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue