diff --git a/.changeset/gold-mirrors-hide.md b/.changeset/gold-mirrors-hide.md new file mode 100644 index 00000000..db8830e7 --- /dev/null +++ b/.changeset/gold-mirrors-hide.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/cloudflare": patch +--- + +TODO: add a proper changeset diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index dafd1144..734b25b7 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - script: ["prettier:check", "lint:check", "ts:check", "test"] + script: ["prettier:check", "lint:check", "ts:check"] steps: - name: Check out code uses: actions/checkout@v4 @@ -21,5 +21,21 @@ jobs: - name: Install Dependencies uses: ./.github/actions/install-dependencies - - name: ${{ matrix.script }} + - name: run "${{ matrix.script }}" script run: pnpm run ${{ matrix.script }} + tests: + name: tests (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-13, windows-2022, ubuntu-22.04] + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Install Dependencies + uses: ./.github/actions/install-dependencies + + - name: run "test" script + run: pnpm run test diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 4fc920b3..87c1a4c8 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -9,7 +9,12 @@ on: jobs: test: timeout-minutes: 30 - runs-on: ubuntu-latest + name: e2e tests (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-13, windows-2022, ubuntu-22.04] steps: - name: Check out code uses: actions/checkout@v4 diff --git a/examples/vercel-commerce/package.json b/examples/vercel-commerce/package.json index 2e0b5784..e838880a 100644 --- a/examples/vercel-commerce/package.json +++ b/examples/vercel-commerce/package.json @@ -11,7 +11,6 @@ "start": "next start", "prettier": "prettier --write --ignore-unknown .", "prettier:check": "prettier --check --ignore-unknown .", - "test": "pnpm prettier:check", "tofix-build:worker": "opennextjs-cloudflare", "tofix-dev:worker": "wrangler dev --port 8772", "tofix-preview:worker": "pnpm build:worker && pnpm dev:worker" diff --git a/packages/cloudflare/src/cli/build/patches/investigated/patch-cache.ts b/packages/cloudflare/src/cli/build/patches/investigated/patch-cache.ts index 4e82d503..28bb4fc6 100644 --- a/packages/cloudflare/src/cli/build/patches/investigated/patch-cache.ts +++ b/packages/cloudflare/src/cli/build/patches/investigated/patch-cache.ts @@ -2,6 +2,8 @@ import path from "node:path"; import type { BuildOptions } from "@opennextjs/aws/build/helper.js"; +import { normalizePath } from "../../utils/normalize-path.js"; + /** * Sets up the OpenNext cache handler in a Next.js build. * @@ -19,12 +21,12 @@ export async function patchCache(code: string, openNextOptions: BuildOptions): P // TODO: switch to cache.mjs const outputPath = path.join(outputDir, "server-functions", "default"); const packagePath = path.relative(monorepoRoot, appBuildOutputPath); - const cacheFile = path.join(outputPath, packagePath, "cache.cjs"); + const cacheFilePath = path.join(outputPath, packagePath, "cache.cjs"); return code.replace( "const { cacheHandler } = this.nextConfig;", `const cacheHandler = null; -CacheHandler = require('${cacheFile}').default; +CacheHandler = require('${normalizePath(cacheFilePath)}').default; ` ); } diff --git a/packages/cloudflare/src/cli/build/utils/normalize-path.spec.ts b/packages/cloudflare/src/cli/build/utils/normalize-path.spec.ts new file mode 100644 index 00000000..7fa7a04f --- /dev/null +++ b/packages/cloudflare/src/cli/build/utils/normalize-path.spec.ts @@ -0,0 +1,22 @@ +import path from "node:path"; + +import { describe, expect, it } from "vitest"; + +import { normalizePath } from "./normalize-path"; + +describe("normalizePath", () => { + it("should produce an absolute path ready to be embedded in inlined code", () => { + const joined = path.join("/", "Users", "me", "projects", "cloudflare", "index.mjs"); + const result = normalizePath(joined); + // Note: the result is the same both on linux/mac and windows + expect(result).toEqual("/Users/me/projects/cloudflare/index.mjs"); + }); + + it("should produce a relative path ready to be embedded in inlined code", () => { + const joined = path.join("..", "..", "tmp", "index.mjs"); + const result = normalizePath(joined); + + // Note: the result is the same both on linux/mac and windows + expect(result).toEqual("../../tmp/index.mjs"); + }); +});