Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for bun #307

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
LATEST_PNPM=$(curl https://registry.npmjs.org/pnpm | jq '.["dist-tags"].latest + "+sha1." + .versions[.["dist-tags"].latest].dist.shasum')
LATEST_YARN=$(curl https://registry.npmjs.org/yarn | jq '.["dist-tags"].latest + "+sha1." + .versions[.["dist-tags"].latest].dist.shasum')
LATEST_BERRY=$(jq -n '$version + "+sha224." + $checksum' --arg version "$LATEST_BERRY_VERSION" --arg checksum "$(curl https://repo.yarnpkg.com/"$LATEST_BERRY_VERSION"/packages/yarnpkg-cli/bin/yarn.js | openssl dgst -sha224 | cut -d' ' -f2)")
LATEST_BUN=$(curl https://registry.npmjs.org/bun | jq '.["dist-tags"].latest + "+sha1." + .versions[.["dist-tags"].latest].dist.shasum')

git --no-pager show HEAD:config.json | jq '. * '"{
definitions: {
Expand All @@ -41,6 +42,9 @@ jobs:
default: $LATEST_BERRY,
},
},
bun: {
default: $LATEST_BUN,
}
},
}" > config.json

Expand Down
34 changes: 34 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,40 @@
}
}
}
},
"bun": {
"default": "1.0.0+sha1.318110dc2c46e1559fb5fef40884ebe77b711934",
"fetchLatestFrom": {
"type": "npm",
"package": "bun"
},
"transparent": {
"commands": [
[
"bun",
"init"
],
[
"bunx"
]
]
},
"ranges": {
"*": {
"url": "https://registry.npmjs.org/bun/-/bun-{}.tgz",
"bin": {
"bun": "./bin/bun",
"bunx": "./bin/bun"
},
"registry": {
"type": "npm",
"package": "bun"
},
"commands": {
"use": ["bun", "install"]
}
}
}
}
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
"pnpm": "./dist/pnpm.js",
"pnpx": "./dist/pnpx.js",
"yarn": "./dist/yarn.js",
"yarnpkg": "./dist/yarnpkg.js"
"yarnpkg": "./dist/yarnpkg.js",
"bun": "./dist/bun",
"bunx": "./dist/bunx"
},
"executableFiles": [
"./dist/npm.js",
Expand All @@ -81,6 +83,7 @@
"./dist/yarn.js",
"./dist/yarnpkg.js",
"./dist/corepack.js",
"./dist/bun",
"./shims/npm",
"./shims/npm.ps1",
"./shims/npx",
Expand Down
37 changes: 36 additions & 1 deletion tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ const testedPackageManagers: Array<[string, string]> = [
[`npm`, `6.14.2`],
[`npm`, `6.14.2+sha1.f057d35cd4792c4c511bb1fa332edb43143d07b0`],
[`npm`, `6.14.2+sha224.50512c1eb404900ee78586faa6d756b8d867ff46a328e6fb4cdf3a87`],
[`bun`, `1.0.26`],
[`bun`, `1.0.26+sha1.a27af658d87e0487321c3e8b8bbd69f9e408a9f1`],
[`bun`, `1.0.26+sha224.a27af658d87e0487321c3e8b8bbd69f9e408a9f1`],
];

for (const [name, version] of testedPackageManagers) {
Expand Down Expand Up @@ -272,6 +275,12 @@ it(`should use the pinned version when local projects don't list any spec`, asyn
stderr: ``,
exitCode: 0,
});

await expect(runCli(cwd, [`bun`, `--version`])).resolves.toMatchObject({
stdout: `${config.definitions.bun.default.split(`+`, 1)[0]}\n`,
stderr: ``,
exitCode: 0,
});
});
});

Expand Down Expand Up @@ -385,6 +394,11 @@ it(`should refuse to run a different package manager within a configured project
stderr: ``,
exitCode: 0,
});
await expect(runCli(cwd, [`bun`, `--version`])).resolves.toMatchObject({
stdout: `${config.definitions.bun.default.split(`+`, 1)[0]}\n`,
stderr: ``,
exitCode: 0,
});
} finally {
delete process.env.COREPACK_ENABLE_STRICT;
delete process.env.FORCE_COLOR;
Expand All @@ -411,6 +425,11 @@ it(`should always use fallback version when project spec env is disabled`, async
stderr: ``,
exitCode: 0,
});
await expect(runCli(cwd, [`bun`, `--version`])).resolves.toMatchObject({
stdout: `${config.definitions.bun.default.split(`+`, 1)[0]}\n`,
stderr: ``,
exitCode: 0,
});
} finally {
delete process.env.COREPACK_ENABLE_PROJECT_SPEC;
}
Expand Down Expand Up @@ -448,6 +467,12 @@ it(`should allow to call "corepack install -g --all" to prepare all package mana
stderr: ``,
exitCode: 0,
});

await expect(runCli(cwd, [`bun`, `--version`])).resolves.toMatchObject({
stdout: `${config.definitions.bun.default.split(`+`, 1)[0]}\n`,
stderr: ``,
exitCode: 0,
});
} finally {
delete process.env.COREPACK_ENABLE_NETWORK;
}
Expand Down Expand Up @@ -547,7 +572,7 @@ it(`should support hydrating package managers if cache folder was removed`, asyn

it(`should support hydrating multiple package managers from cached archives`, async () => {
await xfs.mktempPromise(async cwd => {
await expect(runCli(cwd, [`pack`, `yarn@2.2.2`, `pnpm@5.8.0`])).resolves.toMatchObject({
await expect(runCli(cwd, [`pack`, `yarn@2.2.2`, `pnpm@5.8.0`, `bun@1.0.26`])).resolves.toMatchObject({
exitCode: 0,
stderr: ``,
});
Expand Down Expand Up @@ -583,6 +608,16 @@ it(`should support hydrating multiple package managers from cached archives`, as
stderr: ``,
exitCode: 0,
});

await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
packageManager: `bun@1.0.26`,
});

await expect(runCli(cwd, [`bun`, `--version`])).resolves.toMatchObject({
stdout: `1.0.26\n`,
stderr: ``,
exitCode: 0,
});
} finally {
delete process.env.COREPACK_ENABLE_NETWORK;
}
Expand Down