mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-02-23 10:40:10 +08:00
Merge branch 'feat/multiple-registries'
This commit is contained in:
commit
d5ff847057
56
.github/workflows/test.yml
vendored
56
.github/workflows/test.yml
vendored
@ -33,10 +33,26 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
|
||||||
|
tests:
|
||||||
|
name: Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: ./
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: bun install
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: bun test --coverage
|
||||||
|
|
||||||
setup-bun:
|
setup-bun:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
needs: [remove-cache]
|
needs: [remove-cache, tests]
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os:
|
||||||
@ -73,7 +89,7 @@ jobs:
|
|||||||
name: setup-bun from (${{ matrix.os }}, ${{ matrix.file.name }})
|
name: setup-bun from (${{ matrix.os }}, ${{ matrix.file.name }})
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
needs: [remove-cache]
|
needs: [remove-cache, tests]
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os:
|
||||||
@ -134,7 +150,7 @@ jobs:
|
|||||||
name: setup-bun from (${{ matrix.os }}, download url)
|
name: setup-bun from (${{ matrix.os }}, download url)
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
needs: [remove-cache]
|
needs: [remove-cache, tests]
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os:
|
||||||
@ -155,3 +171,37 @@ jobs:
|
|||||||
id: run_bun
|
id: run_bun
|
||||||
run: |
|
run: |
|
||||||
bun --version
|
bun --version
|
||||||
|
|
||||||
|
setup-bun-registry:
|
||||||
|
name: setup-bun registry (${{ matrix.os }})
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
continue-on-error: true
|
||||||
|
needs: [remove-cache, tests]
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- ubuntu-latest
|
||||||
|
- macos-latest
|
||||||
|
- windows-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: ./
|
||||||
|
id: setup_bun
|
||||||
|
with:
|
||||||
|
registries: |
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"url": "https://username:password@registry.myorg.com/",
|
||||||
|
"scope": "@myorg"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
- name: Run Bun
|
||||||
|
id: run_bun
|
||||||
|
run: |
|
||||||
|
bun --version
|
||||||
|
bun add @myorg/example
|
||||||
|
@ -21,6 +21,9 @@ inputs:
|
|||||||
scope:
|
scope:
|
||||||
required: false
|
required: false
|
||||||
description: "The scope for authenticating with the package registry."
|
description: "The scope for authenticating with the package registry."
|
||||||
|
registries:
|
||||||
|
required: false
|
||||||
|
description: "An list of package registries for authenticating with the package registry."
|
||||||
no-cache:
|
no-cache:
|
||||||
required: false
|
required: false
|
||||||
type: boolean
|
type: boolean
|
||||||
|
64
dist/setup/index.js
generated
vendored
64
dist/setup/index.js
generated
vendored
File diff suppressed because one or more lines are too long
39
package-lock.json
generated
39
package-lock.json
generated
@ -17,6 +17,7 @@
|
|||||||
"@actions/tool-cache": "^2.0.1"
|
"@actions/tool-cache": "^2.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/bun": "^1.1.13",
|
||||||
"@types/node": "^20.8.2",
|
"@types/node": "^20.8.2",
|
||||||
"esbuild": "^0.19.2",
|
"esbuild": "^0.19.2",
|
||||||
"prettier": "^2.8.4",
|
"prettier": "^2.8.4",
|
||||||
@ -283,10 +284,21 @@
|
|||||||
"node": ">=8.0.0"
|
"node": ">=8.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/bun": {
|
||||||
|
"version": "1.1.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/bun/-/bun-1.1.13.tgz",
|
||||||
|
"integrity": "sha512-KmQxSBgVWCl6RSuerlLGZlIWfdxkKqat0nxN61+qu4y1KDn0Ll3j7v1Pl8GnaL3a/U6GGWVTJh75ap62kR1E8Q==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"bun-types": "1.1.34"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "20.9.1",
|
"version": "20.12.14",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.9.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.14.tgz",
|
||||||
"integrity": "sha512-HhmzZh5LSJNS5O8jQKpJ/3ZcrrlG6L70hpGqMIAoM9YVD0YBRNWYsfwcXq8VnSjlNpCpgLzMXdiPo+dxcvSmiA==",
|
"integrity": "sha512-scnD59RpYD91xngrQQLGkE+6UrHUPzeKZWhhjBSa3HSkwjbQc38+q3RoIVEwxQGRw3M+j5hpNAM+lgV3cVormg==",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~5.26.4"
|
"undici-types": "~5.26.4"
|
||||||
}
|
}
|
||||||
@ -318,6 +330,16 @@
|
|||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/ws": {
|
||||||
|
"version": "8.5.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.13.tgz",
|
||||||
|
"integrity": "sha512-osM/gWBTPKgHV8XkTunnegTRIsvF6owmf5w+JtAfOw472dptdm0dlGv4xCt6GwQRcC2XVOvvRE/0bAoQcL2QkA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/abort-controller": {
|
"node_modules/abort-controller": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -344,6 +366,17 @@
|
|||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/bun-types": {
|
||||||
|
"version": "1.1.34",
|
||||||
|
"resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.1.34.tgz",
|
||||||
|
"integrity": "sha512-br5QygTEL/TwB4uQOb96Ky22j4Gq2WxWH/8Oqv20fk5HagwKXo/akB+LiYgSfzexCt6kkcUaVm+bKiPl71xPvw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "~20.12.8",
|
||||||
|
"@types/ws": "~8.5.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/combined-stream": {
|
"node_modules/combined-stream": {
|
||||||
"version": "1.0.8",
|
"version": "1.0.8",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
"@actions/tool-cache": "^2.0.1"
|
"@actions/tool-cache": "^2.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/bun": "^1.1.13",
|
||||||
"@types/node": "^20.8.2",
|
"@types/node": "^20.8.2",
|
||||||
"esbuild": "^0.19.2",
|
"esbuild": "^0.19.2",
|
||||||
"prettier": "^2.8.4",
|
"prettier": "^2.8.4",
|
||||||
|
@ -12,9 +12,10 @@ import { addPath, info, warning } from "@actions/core";
|
|||||||
import { isFeatureAvailable, restoreCache } from "@actions/cache";
|
import { isFeatureAvailable, restoreCache } from "@actions/cache";
|
||||||
import { downloadTool, extractZip } from "@actions/tool-cache";
|
import { downloadTool, extractZip } from "@actions/tool-cache";
|
||||||
import { getExecOutput } from "@actions/exec";
|
import { getExecOutput } from "@actions/exec";
|
||||||
import { writeBunfig } from "./bunfig";
|
import { writeBunfig, Registry } from "./bunfig";
|
||||||
import { saveState } from "@actions/core";
|
import { saveState } from "@actions/core";
|
||||||
import { addExtension, retry } from "./utils";
|
import { addExtension, retry } from "./utils";
|
||||||
|
import { cwd } from "node:process";
|
||||||
|
|
||||||
export type Input = {
|
export type Input = {
|
||||||
customUrl?: string;
|
customUrl?: string;
|
||||||
@ -23,8 +24,7 @@ export type Input = {
|
|||||||
arch?: string;
|
arch?: string;
|
||||||
avx2?: boolean;
|
avx2?: boolean;
|
||||||
profile?: boolean;
|
profile?: boolean;
|
||||||
scope?: string;
|
registries?: Registry[];
|
||||||
registryUrl?: string;
|
|
||||||
noCache?: boolean;
|
noCache?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -44,8 +44,8 @@ export type CacheState = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async (options: Input): Promise<Output> => {
|
export default async (options: Input): Promise<Output> => {
|
||||||
const bunfigPath = join(process.cwd(), "bunfig.toml");
|
const bunfigPath = join(cwd(), "bunfig.toml");
|
||||||
writeBunfig(bunfigPath, options);
|
writeBunfig(bunfigPath, options.registries);
|
||||||
|
|
||||||
const url = getDownloadUrl(options);
|
const url = getDownloadUrl(options);
|
||||||
const cacheEnabled = isCacheEnabled(options);
|
const cacheEnabled = isCacheEnabled(options);
|
||||||
|
145
src/bunfig.ts
145
src/bunfig.ts
@ -1,21 +1,32 @@
|
|||||||
import { EOL } from "node:os";
|
import { EOL } from "node:os";
|
||||||
import { appendFileSync } from "node:fs";
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
||||||
import { info } from "@actions/core";
|
import { info } from "@actions/core";
|
||||||
|
|
||||||
type BunfigOptions = {
|
export type Registry = {
|
||||||
registryUrl?: string;
|
url: string;
|
||||||
scope?: string;
|
scope: string;
|
||||||
|
token?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function createBunfig(options: BunfigOptions): string | null {
|
enum FieldType {
|
||||||
const { registryUrl, scope } = options;
|
GLOBAL_REGISTRY,
|
||||||
|
INSTALL_WITH_SCOPE,
|
||||||
|
}
|
||||||
|
|
||||||
|
type Field = {
|
||||||
|
type: FieldType;
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createField(registry: Registry): Field {
|
||||||
|
const { url: registryUrl, scope, token } = registry;
|
||||||
|
|
||||||
let url: URL | undefined;
|
let url: URL | undefined;
|
||||||
if (registryUrl) {
|
if (registryUrl) {
|
||||||
try {
|
try {
|
||||||
url = new URL(registryUrl);
|
url = new URL(registryUrl);
|
||||||
} catch {
|
} catch {
|
||||||
throw new Error(`Invalid registry-url: ${registryUrl}`);
|
throw new Error(`Invalid registry url ${registryUrl}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,24 +38,134 @@ export function createBunfig(options: BunfigOptions): string | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (url && owner) {
|
if (url && owner) {
|
||||||
return `[install.scopes]${EOL}'${owner}' = { token = "$BUN_AUTH_TOKEN", url = "${url}"}${EOL}`;
|
return {
|
||||||
|
type: FieldType.INSTALL_WITH_SCOPE,
|
||||||
|
value: `'${owner}' = { url = "${url}"${
|
||||||
|
token ? `, token = "${token}"` : ""
|
||||||
|
} }`,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url && !owner) {
|
if (url && !owner) {
|
||||||
return `[install]${EOL}registry = "${url}"${EOL}`;
|
return {
|
||||||
|
type: FieldType.GLOBAL_REGISTRY,
|
||||||
|
value: `registry = "${url}"`,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function writeBunfig(path: string, options: BunfigOptions): void {
|
export function createBunfig(registries: Registry[]): Field[] | null {
|
||||||
const bunfig = createBunfig(options);
|
const fields = registries.map(createField).filter((field) => field);
|
||||||
|
if (fields.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
fields.filter((field) => field.type === FieldType.GLOBAL_REGISTRY).length >
|
||||||
|
1
|
||||||
|
) {
|
||||||
|
throw new Error("You can't have more than one global registry.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function serializeInstallScopes(
|
||||||
|
fields: Field[],
|
||||||
|
header: boolean = false
|
||||||
|
): string {
|
||||||
|
const installScopes = fields
|
||||||
|
.filter((field) => field.type === FieldType.INSTALL_WITH_SCOPE)
|
||||||
|
.map((field) => field.value)
|
||||||
|
.join(EOL);
|
||||||
|
|
||||||
|
if (!installScopes) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${header ? `[install.scopes]${EOL}` : ""}${installScopes}${EOL}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function serializeGlobalRegistry(
|
||||||
|
fields: Field[],
|
||||||
|
header: boolean = false
|
||||||
|
): string {
|
||||||
|
const globalRegistry = fields
|
||||||
|
.filter((field) => field.type === FieldType.GLOBAL_REGISTRY)
|
||||||
|
.map((field) => field.value)
|
||||||
|
.join(EOL);
|
||||||
|
|
||||||
|
if (!globalRegistry) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${header ? `[install]${EOL}` : ""}${globalRegistry}${EOL}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function writeBunfig(path: string, registries: Registry[]): void {
|
||||||
|
const bunfig = createBunfig(registries);
|
||||||
if (!bunfig) {
|
if (!bunfig) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
info(`Writing bunfig.toml to '${path}'.`);
|
info(`Writing bunfig.toml to '${path}'.`);
|
||||||
appendFileSync(path, bunfig, {
|
|
||||||
|
if (!existsSync(path)) {
|
||||||
|
writeFileSync(
|
||||||
|
path,
|
||||||
|
`${serializeGlobalRegistry(bunfig, true)}${serializeInstallScopes(
|
||||||
|
bunfig,
|
||||||
|
true
|
||||||
|
)}`,
|
||||||
|
{
|
||||||
|
encoding: "utf8",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let newContent = "";
|
||||||
|
const contents = readFileSync(path, {
|
||||||
|
encoding: "utf-8",
|
||||||
|
}).split(EOL);
|
||||||
|
|
||||||
|
contents.forEach((line, index, array) => {
|
||||||
|
if (index > 0 && array[index - 1].includes("[install.scopes]")) {
|
||||||
|
newContent += serializeInstallScopes(bunfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index > 0 && array[index - 1].includes("[install]")) {
|
||||||
|
newContent += serializeGlobalRegistry(bunfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
line.startsWith("registry = ") ||
|
||||||
|
!bunfig.some(
|
||||||
|
(field) =>
|
||||||
|
field.type === FieldType.INSTALL_WITH_SCOPE &&
|
||||||
|
(line.startsWith(field.value.split(" ")[0]) ||
|
||||||
|
((line[0] === "'" || line[0] === '"') &&
|
||||||
|
line
|
||||||
|
.toLowerCase()
|
||||||
|
.startsWith(field.value.split(" ")[0].slice(1).slice(0, -1))))
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
newContent += line + EOL;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!contents.includes("[install.scopes]")) {
|
||||||
|
newContent += serializeInstallScopes(bunfig, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!contents.includes("[install]")) {
|
||||||
|
newContent += serializeGlobalRegistry(bunfig, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeFileSync(path, newContent, {
|
||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
15
src/index.ts
15
src/index.ts
@ -7,14 +7,25 @@ if (!process.env.RUNNER_TEMP) {
|
|||||||
process.env.RUNNER_TEMP = tmpdir();
|
process.env.RUNNER_TEMP = tmpdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const registries = JSON.parse(getInput("registries") || "[]");
|
||||||
|
const registryUrl = getInput("registry-url");
|
||||||
|
const scope = getInput("scope");
|
||||||
|
|
||||||
|
if (registryUrl) {
|
||||||
|
registries.push({
|
||||||
|
url: registryUrl,
|
||||||
|
scope: scope,
|
||||||
|
token: "$BUN_AUTH_TOKEN",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
runAction({
|
runAction({
|
||||||
version:
|
version:
|
||||||
getInput("bun-version") ||
|
getInput("bun-version") ||
|
||||||
readVersionFromFile(getInput("bun-version-file")) ||
|
readVersionFromFile(getInput("bun-version-file")) ||
|
||||||
undefined,
|
undefined,
|
||||||
customUrl: getInput("bun-download-url") || undefined,
|
customUrl: getInput("bun-download-url") || undefined,
|
||||||
registryUrl: getInput("registry-url") || undefined,
|
registries: registries,
|
||||||
scope: getInput("scope") || undefined,
|
|
||||||
noCache: getBooleanInput("no-cache") || false,
|
noCache: getBooleanInput("no-cache") || false,
|
||||||
})
|
})
|
||||||
.then(({ version, revision, bunPath, url, cacheHit }) => {
|
.then(({ version, revision, bunPath, url, cacheHit }) => {
|
||||||
|
228
tests/bunfig.spec.ts
Normal file
228
tests/bunfig.spec.ts
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
import { afterEach, describe, expect, it } from "bun:test";
|
||||||
|
import { unlinkSync } from "node:fs";
|
||||||
|
import { writeBunfig } from "../src/bunfig";
|
||||||
|
import { EOL } from "os";
|
||||||
|
|
||||||
|
describe("writeBunfig", () => {
|
||||||
|
const filePath = "bunfig.toml";
|
||||||
|
|
||||||
|
async function getFileAndContents() {
|
||||||
|
const file = Bun.file(filePath);
|
||||||
|
const contents = (await file.text()).split(EOL);
|
||||||
|
|
||||||
|
return { file, contents };
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
unlinkSync(filePath);
|
||||||
|
console.log(`${filePath} was deleted`);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when no bunfig.toml file exists", () => {
|
||||||
|
it("should create a new file with scopes content", async () => {
|
||||||
|
writeBunfig(filePath, [
|
||||||
|
{
|
||||||
|
url: "https://npm.pkg.github.com",
|
||||||
|
scope: "foo-bar",
|
||||||
|
token: "$BUN_AUTH_TOKEN",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const { file, contents } = await getFileAndContents();
|
||||||
|
|
||||||
|
expect(file.exists()).resolves.toBeTrue();
|
||||||
|
|
||||||
|
const expectedContents = [
|
||||||
|
"[install.scopes]",
|
||||||
|
'\'@foo-bar\' = { url = "https://npm.pkg.github.com/", token = "$BUN_AUTH_TOKEN" }',
|
||||||
|
"",
|
||||||
|
];
|
||||||
|
|
||||||
|
contents.forEach((content, index) =>
|
||||||
|
expect(content).toBe(expectedContents[index])
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(contents.length).toBe(expectedContents.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create a new file with global registry", async () => {
|
||||||
|
writeBunfig(filePath, [
|
||||||
|
{
|
||||||
|
url: "https://npm.pkg.github.com",
|
||||||
|
scope: "",
|
||||||
|
token: "$BUN_AUTH_TOKEN",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const { file, contents } = await getFileAndContents();
|
||||||
|
|
||||||
|
expect(file.exists()).resolves.toBeTrue();
|
||||||
|
|
||||||
|
const expectedContents = [
|
||||||
|
"[install]",
|
||||||
|
'registry = "https://npm.pkg.github.com/"',
|
||||||
|
"",
|
||||||
|
];
|
||||||
|
|
||||||
|
contents.forEach((content, index) =>
|
||||||
|
expect(content).toBe(expectedContents[index])
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(contents.length).toBe(expectedContents.length);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when local bunfig.toml file exists", () => {
|
||||||
|
it("and no [install.scopes] exists, should concatenate file correctly", async () => {
|
||||||
|
const bunfig = `[install]${EOL}optional = true${EOL}${EOL}[install.cache]${EOL}disable = true`;
|
||||||
|
|
||||||
|
await Bun.write(filePath, bunfig);
|
||||||
|
|
||||||
|
writeBunfig(filePath, [
|
||||||
|
{
|
||||||
|
url: "https://npm.pkg.github.com",
|
||||||
|
scope: "foo-bar",
|
||||||
|
token: "$BUN_AUTH_TOKEN",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const { file, contents } = await getFileAndContents();
|
||||||
|
|
||||||
|
expect(file.exists()).resolves.toBeTrue();
|
||||||
|
|
||||||
|
const expectedContents = [
|
||||||
|
"[install]",
|
||||||
|
"optional = true",
|
||||||
|
"",
|
||||||
|
"[install.cache]",
|
||||||
|
"disable = true",
|
||||||
|
"[install.scopes]",
|
||||||
|
'\'@foo-bar\' = { url = "https://npm.pkg.github.com/", token = "$BUN_AUTH_TOKEN" }',
|
||||||
|
"",
|
||||||
|
];
|
||||||
|
|
||||||
|
contents.forEach((content, index) =>
|
||||||
|
expect(content).toBe(expectedContents[index])
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(contents.length).toBe(expectedContents.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("and [install.scopes] exists and it's not the same registry, should concatenate file correctly", async () => {
|
||||||
|
const bunfig = `[install]${EOL}optional = true${EOL}${EOL}[install.scopes]${EOL}'@bla-ble' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}${EOL}[install.cache]${EOL}disable = true`;
|
||||||
|
|
||||||
|
await Bun.write(filePath, bunfig);
|
||||||
|
|
||||||
|
writeBunfig(filePath, [
|
||||||
|
{
|
||||||
|
url: "https://npm.pkg.github.com",
|
||||||
|
scope: "foo-bar",
|
||||||
|
token: "$BUN_AUTH_TOKEN",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const { file, contents } = await getFileAndContents();
|
||||||
|
|
||||||
|
expect(file.exists()).resolves.toBeTrue();
|
||||||
|
|
||||||
|
const expectedContents = [
|
||||||
|
"[install]",
|
||||||
|
"optional = true",
|
||||||
|
"",
|
||||||
|
"[install.scopes]",
|
||||||
|
'\'@foo-bar\' = { url = "https://npm.pkg.github.com/", token = "$BUN_AUTH_TOKEN" }',
|
||||||
|
'\'@bla-ble\' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }',
|
||||||
|
"",
|
||||||
|
"[install.cache]",
|
||||||
|
"disable = true",
|
||||||
|
"",
|
||||||
|
];
|
||||||
|
|
||||||
|
contents.forEach((content, index) =>
|
||||||
|
expect(content).toBe(expectedContents[index])
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(contents.length).toBe(expectedContents.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("and [install.scopes] exists and it's the same registry, should concatenate file correctly", async () => {
|
||||||
|
const bunfig = `[install]${EOL}optional = true${EOL}${EOL}[install.scopes]${EOL}'@foo-bar' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}'@bla-ble' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}${EOL}[install.cache]${EOL}disable = true`;
|
||||||
|
|
||||||
|
await Bun.write(filePath, bunfig);
|
||||||
|
|
||||||
|
writeBunfig(filePath, [
|
||||||
|
{
|
||||||
|
url: "https://npm.pkg.github.com",
|
||||||
|
scope: "foo-bar",
|
||||||
|
token: "$BUN_AUTH_TOKEN",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const { file, contents } = await getFileAndContents();
|
||||||
|
|
||||||
|
expect(file.exists()).resolves.toBeTrue();
|
||||||
|
|
||||||
|
const expectedContents = [
|
||||||
|
"[install]",
|
||||||
|
"optional = true",
|
||||||
|
"",
|
||||||
|
"[install.scopes]",
|
||||||
|
'\'@foo-bar\' = { url = "https://npm.pkg.github.com/", token = "$BUN_AUTH_TOKEN" }',
|
||||||
|
'\'@bla-ble\' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }',
|
||||||
|
"",
|
||||||
|
"[install.cache]",
|
||||||
|
"disable = true",
|
||||||
|
"",
|
||||||
|
];
|
||||||
|
|
||||||
|
contents.forEach((content, index) =>
|
||||||
|
expect(content).toBe(expectedContents[index])
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(contents.length).toBe(expectedContents.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("and [install.scopes] and [install] exists, should concantenate file correctly", async () => {
|
||||||
|
const bunfig = `[install]${EOL}optional = true${EOL}${EOL}[install.scopes]${EOL}'@foo-bar' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}'@bla-ble' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}${EOL}[install.cache]${EOL}disable = true`;
|
||||||
|
|
||||||
|
await Bun.write(filePath, bunfig);
|
||||||
|
|
||||||
|
writeBunfig(filePath, [
|
||||||
|
{
|
||||||
|
url: "https://npm.pkg.github.com",
|
||||||
|
scope: "foo-bar",
|
||||||
|
token: "$BUN_AUTH_TOKEN",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://bun.sh",
|
||||||
|
scope: "",
|
||||||
|
token: "$BUN_AUTH_TOKEN",
|
||||||
|
}, // global registry
|
||||||
|
]);
|
||||||
|
|
||||||
|
const { file, contents } = await getFileAndContents();
|
||||||
|
|
||||||
|
expect(file.exists()).resolves.toBeTrue();
|
||||||
|
|
||||||
|
const expectedContents = [
|
||||||
|
"[install]",
|
||||||
|
'registry = "https://bun.sh/"',
|
||||||
|
"optional = true",
|
||||||
|
"",
|
||||||
|
"[install.scopes]",
|
||||||
|
'\'@foo-bar\' = { url = "https://npm.pkg.github.com/", token = "$BUN_AUTH_TOKEN" }',
|
||||||
|
'\'@bla-ble\' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }',
|
||||||
|
"",
|
||||||
|
"[install.cache]",
|
||||||
|
"disable = true",
|
||||||
|
"",
|
||||||
|
];
|
||||||
|
|
||||||
|
contents.forEach((content, index) =>
|
||||||
|
expect(content).toBe(expectedContents[index])
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(contents.length).toBe(expectedContents.length);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
8
tests/tsconfig.json
Normal file
8
tests/tsconfig.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"types": [
|
||||||
|
"bun"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user