mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-17 20:18:24 +02:00
feat: support for multiple registries (#109)
Some checks failed
autofix.ci / format (push) Failing after 1m14s
🧪 Test / remove-cache (push) Successful in 58s
🧪 Test / setup-bun (1.x, ubuntu-latest) (push) Failing after 1m28s
🧪 Test / setup-bun (< 2, ubuntu-latest) (push) Failing after 1m28s
🧪 Test / setup-bun from (ubuntu-latest, .tool-versions (bun 1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, .tool-versions (bun1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, /foo/package.json (bun@1.1.0)) (push) Failing after 55s
🧪 Test / setup-bun from (ubuntu-latest, package.json (bun@1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, package.json (yarn@bun@1.1.0)) (push) Successful in 58s
🧪 Test / test installing deps from custom registries (ubuntu-latest) (push) Failing after 3m12s
🧪 Test / Tests (push) Successful in 3m13s
🧪 Test / setup-bun (1, ubuntu-latest) (push) Failing after 1m28s
🧪 Test / setup-bun (1.1.0, ubuntu-latest) (push) Successful in 56s
🧪 Test / setup-bun (> 1.0.0, ubuntu-latest) (push) Failing after 1m27s
🧪 Test / setup-bun (canary, ubuntu-latest) (push) Successful in 1m1s
🧪 Test / setup-bun (latest, ubuntu-latest) (push) Successful in 58s
🧪 Test / setup-bun from (ubuntu-latest, .bumrc (1.1.0)) (push) Successful in 56s
🧪 Test / setup-bun from (ubuntu-latest, .bun-version (1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, .tool-versions (bun 1.1.0)) (push) Successful in 56s
🧪 Test / setup-bun from (ubuntu-latest, download url) (push) Successful in 59s
🧪 Test / setup-bun (latest, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .tool-versions (bun1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, download url) (push) Has been cancelled
🧪 Test / setup-bun (1, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (1, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.1.0, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.1.0, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.x, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.x, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (< 2, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (< 2, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (> 1.0.0, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (> 1.0.0, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (canary, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (canary, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (latest, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .bumrc (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .bumrc (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .bun-version (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .bun-version (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .tool-versions (bun1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, /foo/package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, /foo/package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, package.json (yarn@bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, package.json (yarn@bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, download url) (push) Has been cancelled
Some checks failed
autofix.ci / format (push) Failing after 1m14s
🧪 Test / remove-cache (push) Successful in 58s
🧪 Test / setup-bun (1.x, ubuntu-latest) (push) Failing after 1m28s
🧪 Test / setup-bun (< 2, ubuntu-latest) (push) Failing after 1m28s
🧪 Test / setup-bun from (ubuntu-latest, .tool-versions (bun 1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, .tool-versions (bun1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, /foo/package.json (bun@1.1.0)) (push) Failing after 55s
🧪 Test / setup-bun from (ubuntu-latest, package.json (bun@1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, package.json (yarn@bun@1.1.0)) (push) Successful in 58s
🧪 Test / test installing deps from custom registries (ubuntu-latest) (push) Failing after 3m12s
🧪 Test / Tests (push) Successful in 3m13s
🧪 Test / setup-bun (1, ubuntu-latest) (push) Failing after 1m28s
🧪 Test / setup-bun (1.1.0, ubuntu-latest) (push) Successful in 56s
🧪 Test / setup-bun (> 1.0.0, ubuntu-latest) (push) Failing after 1m27s
🧪 Test / setup-bun (canary, ubuntu-latest) (push) Successful in 1m1s
🧪 Test / setup-bun (latest, ubuntu-latest) (push) Successful in 58s
🧪 Test / setup-bun from (ubuntu-latest, .bumrc (1.1.0)) (push) Successful in 56s
🧪 Test / setup-bun from (ubuntu-latest, .bun-version (1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, .tool-versions (bun 1.1.0)) (push) Successful in 56s
🧪 Test / setup-bun from (ubuntu-latest, download url) (push) Successful in 59s
🧪 Test / setup-bun (latest, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .tool-versions (bun1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, download url) (push) Has been cancelled
🧪 Test / setup-bun (1, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (1, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.1.0, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.1.0, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.x, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.x, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (< 2, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (< 2, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (> 1.0.0, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (> 1.0.0, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (canary, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (canary, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (latest, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .bumrc (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .bumrc (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .bun-version (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .bun-version (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .tool-versions (bun1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, /foo/package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, /foo/package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, package.json (yarn@bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, package.json (yarn@bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, download url) (push) Has been cancelled
* feat: support for multiple registries * [autofix.ci] apply automated fixes * refactor: drop unnecessary check * fix: pass empty array instead undefined * [autofix.ci] apply automated fixes * fix: dont add registry set line * [autofix.ci] apply automated fixes * feat: few more tests * feat: add bun types * docs: explain registries * feat: save globally * [autofix.ci] apply automated fixes * ci: jsr registry test * ci: add , * ci: test * ci: test * ci: test * ci: test * [autofix.ci] apply automated fixes * feat: use @iarna/toml * [autofix.ci] apply automated fixes * feat: registry parsing * [autofix.ci] apply automated fixes * ci: verbose add * ci: registry install check * ci: registry install check * ci: registry install check * ci: verify registry usage * docs: registries * docs: important block * docs: show table * docs: show table * ci: shell * ci: registry test on linux * ci: registry test on linux * build: text lockfile --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
7c641390eb
commit
34f777aec1
14 changed files with 901 additions and 117 deletions
113
src/bunfig.ts
113
src/bunfig.ts
|
@ -1,50 +1,81 @@
|
|||
import { EOL } from "node:os";
|
||||
import { appendFileSync } from "node:fs";
|
||||
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { info } from "@actions/core";
|
||||
import { parse, stringify } from "@iarna/toml";
|
||||
import { Registry } from "./registry";
|
||||
|
||||
type BunfigOptions = {
|
||||
registryUrl?: string;
|
||||
scope?: string;
|
||||
type BunfigConfig = {
|
||||
install?: {
|
||||
registry?: {
|
||||
url: string;
|
||||
token?: string;
|
||||
};
|
||||
scopes?: Record<string, { url: string; token?: string }>;
|
||||
};
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
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) {
|
||||
export function writeBunfig(path: string, registries: Registry[]): void {
|
||||
if (!registries.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
info(`Writing bunfig.toml to '${path}'.`);
|
||||
appendFileSync(path, bunfig, {
|
||||
encoding: "utf8",
|
||||
let globalRegistryCount = 0;
|
||||
registries.forEach((registry) => {
|
||||
try {
|
||||
new URL(registry.url);
|
||||
} catch {
|
||||
throw new Error(`Invalid registry URL: ${registry.url}`);
|
||||
}
|
||||
|
||||
if (!registry.scope) {
|
||||
globalRegistryCount++;
|
||||
}
|
||||
});
|
||||
|
||||
if (globalRegistryCount > 1) {
|
||||
throw new Error("You can't have more than one global registry.");
|
||||
}
|
||||
|
||||
info(`Writing bunfig.toml to '${path}'.`);
|
||||
|
||||
let config: BunfigConfig = {};
|
||||
if (existsSync(path)) {
|
||||
try {
|
||||
const content = readFileSync(path, { encoding: "utf-8" });
|
||||
config = parse(content) as BunfigConfig;
|
||||
} catch (error) {
|
||||
info(`Error reading existing bunfig: ${error.message}`);
|
||||
config = {};
|
||||
}
|
||||
}
|
||||
|
||||
config.install = config?.install || {};
|
||||
config.install.scopes = config?.install.scopes || {};
|
||||
|
||||
const globalRegistry = registries.find((r) => !r.scope);
|
||||
if (globalRegistry) {
|
||||
config.install.registry = {
|
||||
url: globalRegistry.url,
|
||||
...(globalRegistry.token ? { token: globalRegistry.token } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
for (const registry of registries) {
|
||||
if (registry.scope) {
|
||||
const scopeName = registry.scope.startsWith("@")
|
||||
? registry.scope.toLowerCase()
|
||||
: `@${registry.scope.toLowerCase()}`;
|
||||
|
||||
config.install.scopes[scopeName] = {
|
||||
url: registry.url,
|
||||
...(registry.token ? { token: registry.token } : {}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(config.install.scopes).length === 0) {
|
||||
delete config.install.scopes;
|
||||
}
|
||||
|
||||
writeFileSync(path, stringify(config), { encoding: "utf8" });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue