Skip to content

Commit

Permalink
C3: Add bun support (#4065)
Browse files Browse the repository at this point in the history
* Adding bun to pm detection

* Adding bun to pm e2e matrix

* Install bun in CI setup action

* Passing git flag through to nuxi

* Change astro template to basics
  • Loading branch information
jculvey authored Sep 29, 2023
1 parent 1d0b7ad commit 55298d9
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-rules-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": minor
---

Add support for bun
6 changes: 4 additions & 2 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ description: "Install dependencies, fetching from cache when possible"
runs:
using: "composite"
steps:
- uses: pnpm/action-setup@v2
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js ${{ env.node-version }}

- name: Install Node.js ${{ env.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.node-version }}
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/test-c3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ on:

env:
node-version: 18.17.1
bun-version: 1.0.3

jobs:
check:
name: "Checks"
strategy:
matrix:
# TODO: add back windows
# os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -63,7 +62,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
pm: [npm, pnpm]
pm: [npm, pnpm, bun]
quarantine: [true, false]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -75,6 +74,11 @@ jobs:
- name: Install Dependencies
uses: ./.github/actions/install-dependencies

- name: Install Bun ${{ env.bun-version }}
uses: oven-sh/setup-bun@v1
with:
bun-version: ${{ env.bun-version }}

- name: E2E Tests
run: pnpm run --filter create-cloudflare test:e2e:${{matrix.pm}}
env:
Expand Down Expand Up @@ -137,7 +141,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
pm: [npm, pnpm]
pm: [npm, pnpm, bun]
quarantine: [true, false]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -149,6 +153,11 @@ jobs:
- name: Install Dependencies
uses: ./.github/actions/install-dependencies

- name: Install Bun ${{ env.bun-version }}
uses: oven-sh/setup-bun@v1
with:
bun-version: ${{ env.bun-version }}

- name: E2E Tests
run: pnpm run --filter create-cloudflare test:e2e:${{matrix.pm}}
env:
Expand Down
11 changes: 1 addition & 10 deletions packages/create-cloudflare/e2e-tests/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe.concurrent(`E2E: Web frameworks`, () => {
// These are ordered based on speed and reliability for ease of debugging
const frameworkTests: Record<string, FrameworkTestConfig> = {
astro: {
expectResponseToContain: "Hello, Astronaut!",
expectResponseToContain: "Welcome to Astro",
testCommitMessage: true,
},
hono: {
Expand Down Expand Up @@ -175,15 +175,6 @@ describe.concurrent(`E2E: Web frameworks`, () => {
},
nuxt: {
expectResponseToContain: "Welcome to Nuxt!",
promptHandlers: [
{
matcher: /Which package manager would you like to use\?/,
input: [
...(process.env.TEST_PM === "pnpm" ? [keys.down] : []),
keys.enter,
],
},
],
overrides: {
packageScripts: {
build: "NITRO_PRESET=cloudflare-pages nuxt build",
Expand Down
1 change: 1 addition & 0 deletions packages/create-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"test:e2e:cleanup": "node -r esbuild-register scripts/e2eCleanup.ts",
"test:e2e:npm": "pnpm run build && TEST_PM=npm vitest run --config ./vitest-e2e.config.ts",
"test:e2e:pnpm": "pnpm run build && TEST_PM=pnpm vitest run --config ./vitest-e2e.config.ts",
"test:e2e:bun": "pnpm run build && TEST_PM=bun vitest run --config ./vitest-e2e.config.ts",
"test:unit": "vitest run --config ./vitest.config.ts",
"test:unit:watch": "vitest --config ./vitest.config.ts",
"watch": "node -r esbuild-register scripts/build.ts --watch"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/src/frameworks/astro/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const config: FrameworkConfig = {
"--no-install",
"--no-git",
"--template",
"blog",
"basics",
"--typescript",
"strict",
],
Expand Down
12 changes: 8 additions & 4 deletions packages/create-cloudflare/src/frameworks/nuxt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import { detectPackageManager } from "helpers/packages";
import { getFrameworkCli } from "../index";
import type { PagesGeneratorContext, FrameworkConfig } from "types";

const { dlx } = detectPackageManager();
const { npm, dlx } = detectPackageManager();

const generate = async (ctx: PagesGeneratorContext) => {
const cli = getFrameworkCli(ctx);
const gitFlag = ctx.args.git ? `--gitInit` : `--no-gitInit`;

await runFrameworkGenerator(ctx, `${dlx} ${cli} init ${ctx.project.name}`);
await runFrameworkGenerator(
ctx,
`${dlx} ${cli} init ${ctx.project.name} --packageManager ${npm} ${gitFlag}`
);

logRaw(""); // newline
};
Expand All @@ -28,8 +32,8 @@ const config: FrameworkConfig = {
displayName: "Nuxt",
packageScripts: {
build: (cmd) => `NITRO_PRESET=cloudflare-pages ${cmd}`,
"pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- npm run dev`,
"pages:deploy": "npm run build && wrangler pages deploy ./dist",
"pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- ${npm} run dev`,
"pages:deploy": `${npm} run build && wrangler pages deploy ./dist`,
},
};
export default config;
4 changes: 4 additions & 0 deletions packages/create-cloudflare/src/helpers/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ export const installPackages = async (
cmd = "add";
saveFlag = config.dev ? "-D" : "";
break;
case "bun":
cmd = "add";
saveFlag = config.dev ? "-d" : "";
break;
case "npm":
case "pnpm":
default:
Expand Down
13 changes: 13 additions & 0 deletions packages/create-cloudflare/src/helpers/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export const detectPackageManager = () => {
name = "yarn";
version = devDependencies["yarn"].replace("^", "");
break;
case "bun":
name = "bun";
version = "1.0.0";
break;
case "npm":
name = "npm";
version = "0.0.0";
Expand Down Expand Up @@ -66,6 +70,15 @@ export const detectPackageManager = () => {
npx: "yarn",
dlx: "yarn",
};
case "bun":
return {
name,
version,
npm: "bun",
npx: "bunx",
dlx: "bunx",
};

case "npm":
default:
return {
Expand Down

0 comments on commit 55298d9

Please sign in to comment.