Skip to content

Commit 92a18c4

Browse files
authored
refactor: simplify the code (#724)
1 parent dd5150d commit 92a18c4

File tree

7 files changed

+6
-47
lines changed

7 files changed

+6
-47
lines changed

packages/cloudflare/src/cli/build/bundle-server.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { build, type Plugin } from "esbuild";
1010
import { getOpenNextConfig } from "../../api/config.js";
1111
import { patchVercelOgLibrary } from "./patches/ast/patch-vercel-og-library.js";
1212
import { patchWebpackRuntime } from "./patches/ast/webpack-runtime.js";
13-
import * as patches from "./patches/index.js";
1413
import { inlineDynamicRequires } from "./patches/plugins/dynamic-requires.js";
1514
import { inlineFindDir } from "./patches/plugins/find-dir.js";
1615
import { patchInstrumentation } from "./patches/plugins/instrumentation.js";
@@ -23,7 +22,7 @@ import { patchDepdDeprecations } from "./patches/plugins/patch-depd-deprecations
2322
import { fixRequire } from "./patches/plugins/require.js";
2423
import { shimRequireHook } from "./patches/plugins/require-hook.js";
2524
import { setWranglerExternal } from "./patches/plugins/wrangler-external.js";
26-
import { needsExperimentalReact, normalizePath, patchCodeWithValidations } from "./utils/index.js";
25+
import { copyPackageCliFiles, needsExperimentalReact, normalizePath } from "./utils/index.js";
2726

2827
/** The dist directory of the Cloudflare adapter package */
2928
const packageDistDir = path.join(path.dirname(fileURLToPath(import.meta.url)), "../..");
@@ -46,7 +45,7 @@ const optionalDependencies = [
4645
* Bundle the Open Next server.
4746
*/
4847
export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
49-
patches.copyPackageCliFiles(packageDistDir, buildOpts);
48+
copyPackageCliFiles(packageDistDir, buildOpts);
5049

5150
const { appPath, outputDir, monorepoRoot, debug } = buildOpts;
5251
const baseManifestPath = path.join(
@@ -174,13 +173,11 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
174173
}
175174

176175
/**
177-
* This function applies patches required for the code to run on workers.
176+
* This function apply updates to the bundled code.
178177
*/
179178
export async function updateWorkerBundledCode(workerOutputFile: string): Promise<void> {
180179
const code = await readFile(workerOutputFile, "utf8");
181-
const patchedCode = await patchCodeWithValidations(code, [
182-
["require", patches.patchRequire, { isOptional: true }],
183-
]);
180+
const patchedCode = code.replace(/__require\d?\(/g, "require(").replace(/__require\d?\./g, "require.");
184181
await writeFile(workerOutputFile, patchedCode);
185182
}
186183

packages/cloudflare/src/cli/build/patches/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/cloudflare/src/cli/build/patches/investigated/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

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

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/cloudflare/src/cli/build/utils/apply-patches.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/cloudflare/src/cli/build/patches/investigated/copy-package-cli-files.ts renamed to packages/cloudflare/src/cli/build/utils/copy-package-cli-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from "node:path";
33

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

6-
import { getOutputWorkerPath } from "../../bundle-server.js";
6+
import { getOutputWorkerPath } from "../bundle-server.js";
77

88
/**
99
* Copies

packages/cloudflare/src/cli/build/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from "./apply-patches.js";
1+
export * from "./copy-package-cli-files.js";
22
export * from "./create-config-files.js";
33
export * from "./ensure-cf-config.js";
44
export * from "./extract-project-env-vars.js";

0 commit comments

Comments
 (0)