Skip to content

Commit 7b06a42

Browse files
authored
fix a few windows path issues (#599)
1 parent 094c7a6 commit 7b06a42

File tree

6 files changed

+47
-6
lines changed

6 files changed

+47
-6
lines changed

.changeset/olive-lemons-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
Fix multiple Windows path issues.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Setup Playwright"
2+
description: "Setup Playwright with caching"
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Put $HOME in env
8+
if: runner.os == 'windows'
9+
shell: pwsh
10+
run: echo "HOME=$HOME" | Out-File -FilePath $env:GITHUB_ENV -Append
11+
12+
- name: Cache Playwright
13+
id: playwright-cache
14+
uses: actions/cache@v4
15+
with:
16+
path: ${{ runner.os == 'Windows' && format('{0}{1}', env.HOME, '\AppData\Local\ms-playwright') || runner.os == 'Linux' && '~/.cache/ms-playwright' || '~/Library/Caches/ms-playwright' }}
17+
key: playwright-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
18+
19+
- name: Install Playwright with dependencies
20+
if: steps.playwright-cache.outputs.cache-hit != 'true'
21+
shell: bash
22+
run: pnpm playwright install --with-deps
23+
24+
- name: Install Playwright's dependencies
25+
if: steps.playwright-cache.outputs.cache-hit == 'true'
26+
shell: bash
27+
run: pnpm playwright install-deps

.github/workflows/playwright.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
uses: ./.github/actions/install-dependencies
1818

1919
- name: Install Playwright
20-
run: pnpm run install-playwright
20+
uses: ./.github/actions/setup-playwright
2121

2222
- name: Build the tool
2323
run: pnpm build

packages/cloudflare/src/cli/build/patches/plugins/instrumentation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { type BuildOptions, getPackagePath } from "@opennextjs/aws/build/helper.
55
import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js";
66
import type { ContentUpdater, Plugin } from "@opennextjs/aws/plugins/content-updater.js";
77

8+
import { normalizePath } from "../../utils/normalize-path.js";
9+
810
export function patchInstrumentation(updater: ContentUpdater, buildOpts: BuildOptions): Plugin {
911
const builtInstrumentationPath = getBuiltInstrumentationPath(buildOpts);
1012

@@ -84,7 +86,7 @@ function getBuiltInstrumentationPath(buildOpts: BuildOptions): string | null {
8486
getPackagePath(buildOpts),
8587
`.next/server/${INSTRUMENTATION_HOOK_FILENAME}.js`
8688
);
87-
return existsSync(maybeBuiltInstrumentationPath) ? maybeBuiltInstrumentationPath : null;
89+
return existsSync(maybeBuiltInstrumentationPath) ? normalizePath(maybeBuiltInstrumentationPath) : null;
8890
}
8991

9092
/**

packages/cloudflare/src/cli/build/patches/plugins/wrangler-external.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { dirname, resolve } from "node:path";
1818

1919
import type { PluginBuild } from "esbuild";
2020

21+
import { normalizePath } from "../../utils/normalize-path.js";
22+
2123
export function setWranglerExternal() {
2224
return {
2325
name: "wrangler-externals",
@@ -28,7 +30,7 @@ export function setWranglerExternal() {
2830
//TODO: Ideally in the future we would like to analyze the files in case they are using wasm in a Node way (i.e. WebAssembly.instantiate)
2931
build.onResolve({ filter: /(\.bin|\.wasm(\?module)?)$/ }, ({ path, importer }) => {
3032
return {
31-
path: resolve(dirname(importer), path),
33+
path: normalizePath(resolve(dirname(importer), path)),
3234
namespace,
3335
external: true,
3436
};

packages/cloudflare/src/cli/commands/populate-cache.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
BINDING_NAME as D1_TAG_BINDING_NAME,
3434
NAME as D1_TAG_NAME,
3535
} from "../../api/overrides/tag-cache/d1-next-tag-cache.js";
36+
import { normalizePath } from "../build/utils/normalize-path.js";
3637
import type { WranglerTarget } from "../utils/run-wrangler.js";
3738
import { runWrangler } from "../utils/run-wrangler.js";
3839

@@ -57,8 +58,8 @@ export function getCacheAssets(opts: BuildOptions): CacheAsset[] {
5758
const assets: CacheAsset[] = [];
5859

5960
for (const file of allFiles) {
60-
const fullPath = file.fullpathPosix();
61-
const relativePath = path.relative(path.join(opts.outputDir, "cache"), fullPath);
61+
const fullPath = file.fullpath();
62+
const relativePath = normalizePath(path.relative(path.join(opts.outputDir, "cache"), fullPath));
6263

6364
if (relativePath.startsWith("__fetch")) {
6465
const [__fetch, buildId, ...keyParts] = relativePath.split("/");
@@ -129,7 +130,11 @@ async function populateR2IncrementalCache(
129130
});
130131
runWrangler(
131132
options,
132-
["r2 object put", quoteShellMeta(path.join(bucket, cacheKey)), `--file ${quoteShellMeta(fullPath)}`],
133+
[
134+
"r2 object put",
135+
quoteShellMeta(normalizePath(path.join(bucket, cacheKey))),
136+
`--file ${quoteShellMeta(fullPath)}`,
137+
],
133138
// NOTE: R2 does not support the environment flag and results in the following error:
134139
// Incorrect type for the 'cacheExpiry' field on 'HttpMetadata': the provided value is not of type 'date'.
135140
{ target: populateCacheOptions.target, logging: "error" }

0 commit comments

Comments
 (0)