Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,38 @@ jobs:
echo "Installed version: ${{ steps.setup.outputs.version }}"
echo "Cache hit: ${{ steps.setup.outputs.cache-hit }}"

test-cache-bun:
strategy:
fail-fast: false
matrix:
version: [latest, alpha]
lockfile: [bun.lock, bun.lockb]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6

- name: Create test project with ${{ matrix.lockfile }}
run: |
mkdir -p test-project
cd test-project
echo '{"name":"test-project","private":true}' > package.json
touch ${{ matrix.lockfile }}

- name: Setup Vite+ (${{ matrix.version }}) with bun cache (${{ matrix.lockfile }})
uses: ./
id: setup
with:
version: ${{ matrix.version }}
run-install: false
cache: true
cache-dependency-path: test-project/${{ matrix.lockfile }}

- name: Verify installation
run: |
vp --version
echo "Installed version: ${{ steps.setup.outputs.version }}"
echo "Cache hit: ${{ steps.setup.outputs.cache-hit }}"

test-vp-exec:
strategy:
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion dist/index.mjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export enum LockFileType {
Npm = "npm",
Pnpm = "pnpm",
Yarn = "yarn",
Bun = "bun",
}

export interface LockFileInfo {
Expand Down
94 changes: 94 additions & 0 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ describe("detectLockFile", () => {
});
});

it("should return lock file info for bun.lockb", () => {
vi.mocked(existsSync).mockReturnValue(true);

const result = detectLockFile("bun.lockb");

expect(result).toEqual({
type: LockFileType.Bun,
path: join(mockWorkspace, "bun.lockb"),
filename: "bun.lockb",
});
});

it("should return lock file info for bun.lock", () => {
vi.mocked(existsSync).mockReturnValue(true);

const result = detectLockFile("bun.lock");

expect(result).toEqual({
type: LockFileType.Bun,
path: join(mockWorkspace, "bun.lock"),
filename: "bun.lock",
});
});

it("should return undefined if explicit file does not exist", () => {
vi.mocked(existsSync).mockReturnValue(false);

Expand Down Expand Up @@ -176,6 +200,63 @@ describe("detectLockFile", () => {
});
});

it("should detect bun.lockb", () => {
vi.mocked(readdirSync).mockReturnValue(["bun.lockb"] as unknown as ReturnType<
typeof readdirSync
>);

const result = detectLockFile();

expect(result).toEqual({
type: LockFileType.Bun,
path: join(mockWorkspace, "bun.lockb"),
filename: "bun.lockb",
});
});

it("should detect bun.lock when bun.lockb is absent", () => {
vi.mocked(readdirSync).mockReturnValue(["bun.lock"] as unknown as ReturnType<
typeof readdirSync
>);

const result = detectLockFile();

expect(result).toEqual({
type: LockFileType.Bun,
path: join(mockWorkspace, "bun.lock"),
filename: "bun.lock",
});
});

it("should prioritize bun.lockb over bun.lock", () => {
vi.mocked(readdirSync).mockReturnValue(["bun.lock", "bun.lockb"] as unknown as ReturnType<
typeof readdirSync
>);

const result = detectLockFile();

expect(result).toEqual({
type: LockFileType.Bun,
path: join(mockWorkspace, "bun.lockb"),
filename: "bun.lockb",
});
});

it("should prioritize pnpm-lock.yaml over bun lock files", () => {
vi.mocked(readdirSync).mockReturnValue([
"bun.lockb",
"pnpm-lock.yaml",
] as unknown as ReturnType<typeof readdirSync>);

const result = detectLockFile();

expect(result).toEqual({
type: LockFileType.Pnpm,
path: join(mockWorkspace, "pnpm-lock.yaml"),
filename: "pnpm-lock.yaml",
});
});

it("should return undefined when no lock files found", () => {
vi.mocked(readdirSync).mockReturnValue([
"package.json",
Expand Down Expand Up @@ -336,6 +417,19 @@ describe("getCacheDirectories", () => {
}),
);
});

it("should run vp pm cache dir for bun", async () => {
vi.mocked(getExecOutput).mockResolvedValue({
exitCode: 0,
stdout: "/tmp/bun-cache\n",
stderr: "",
});

const cacheCwd = join("/test", "workspace", "web");
const result = await getCacheDirectories(LockFileType.Bun, cacheCwd);

expect(result).toEqual(["/tmp/bun-cache"]);
});
});

describe("getInstallCwd", () => {
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export function getInstallCwd(projectDir: string, cwd?: string): string {
// Lock file patterns in priority order
const LOCK_FILES: Array<{ filename: string; type: LockFileType }> = [
{ filename: "pnpm-lock.yaml", type: LockFileType.Pnpm },
{ filename: "bun.lockb", type: LockFileType.Bun },
{ filename: "bun.lock", type: LockFileType.Bun },
{ filename: "package-lock.json", type: LockFileType.Npm },
{ filename: "npm-shrinkwrap.json", type: LockFileType.Npm },
{ filename: "yarn.lock", type: LockFileType.Yarn },
Expand Down Expand Up @@ -108,6 +110,9 @@ function inferLockFileType(fullPath: string, filename: string): LockFileInfo {
if (filename.includes("yarn")) {
return { type: LockFileType.Yarn, path: fullPath, filename };
}
if (filename.startsWith("bun.")) {
return { type: LockFileType.Bun, path: fullPath, filename };
}
// Default to npm
return { type: LockFileType.Npm, path: fullPath, filename };
}
Expand All @@ -120,6 +125,7 @@ export async function getCacheDirectories(lockType: LockFileType, cwd: string):
case LockFileType.Npm:
case LockFileType.Pnpm:
case LockFileType.Yarn:
case LockFileType.Bun:
return getViteCacheDir(cwd);
default:
return [];
Expand Down
Loading