Skip to content

Commit 4c7ef4c

Browse files
add new normalizePathForInlineCode utility
1 parent 12a1f75 commit 4c7ef4c

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

.changeset/gold-mirrors-hide.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+
TODO: add a proper changeset

packages/cloudflare/src/cli/build/patches/investigated/patch-cache.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import path from "node:path";
22

33
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
44

5+
import { normalizePathForInlineCode } from "../../utils/normalize-path-for-inline-code.js";
6+
57
/**
68
* Sets up the OpenNext cache handler in a Next.js build.
79
*
@@ -19,12 +21,12 @@ export async function patchCache(code: string, openNextOptions: BuildOptions): P
1921
// TODO: switch to cache.mjs
2022
const outputPath = path.join(outputDir, "server-functions", "default");
2123
const packagePath = path.relative(monorepoRoot, appBuildOutputPath);
22-
const cacheFile = path.join(outputPath, packagePath, "cache.cjs");
24+
const cacheFilePath = path.join(outputPath, packagePath, "cache.cjs");
2325

2426
return code.replace(
2527
"const { cacheHandler } = this.nextConfig;",
2628
`const cacheHandler = null;
27-
CacheHandler = require('${cacheFile}').default;
29+
CacheHandler = require('${normalizePathForInlineCode(cacheFilePath)}').default;
2830
`
2931
);
3032
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { normalizePathForInlineCode } from "./normalize-path-for-inline-code";
4+
5+
describe("normalizePathForInlineCode", () => {
6+
it("should extract production env vars", () => {
7+
const result = normalizePathForInlineCode("TODO");
8+
expect(result).toBeFalsy();
9+
});
10+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { normalizePath } from "./normalize-path.js";
2+
3+
/**
4+
* TODO: add proper comment
5+
*
6+
* @param path
7+
*/
8+
export function normalizePathForInlineCode(path: string): string {
9+
// let's normalize the path for good measure
10+
const normalizedPath = normalizePath(path);
11+
12+
// we need to escape
13+
const doublyEscaped = normalizedPath.replaceAll("\\", "\\\\");
14+
15+
return doublyEscaped;
16+
}

0 commit comments

Comments
 (0)