Skip to content

Commit 41c306e

Browse files
authored
fix(build): Do not minify OpenNext bundles (#144)
This is required to apply string replacement patches. Fixes #143
1 parent f0a5f2c commit 41c306e

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

packages/cloudflare/env.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ declare global {
99
OPEN_NEXT_ORIGIN: string;
1010
}
1111
}
12-
13-
interface Window {
14-
[key: string]: string | Fetcher;
15-
}
1612
}
1713

1814
export {};

packages/cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"vitest": "catalog:"
6060
},
6161
"dependencies": {
62-
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@2202f36",
62+
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@d2ead58",
6363
"ts-morph": "catalog:"
6464
},
6565
"peerDependencies": {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export async function bundleServer(config: Config, openNextOptions: BuildOptions
9191
// __dirname is used by unbundled js files (which don't inherit the __dirname present in the define field)
9292
// so we also need to set it on the global scope
9393
// Note: this was hit in the next/dist/compiled/@opentelemetry/api module
94-
9594
globalThis.__dirname ??= "";
9695
9796
// Do not crash on cache not supported
@@ -168,6 +167,7 @@ async function updateWorkerBundledCode(
168167

169168
patchedCode = patchedCode
170169
// workers do not support dynamic require nor require.resolve
170+
// TODO: implement for cf (possibly in @opennextjs/aws)
171171
.replace("patchAsyncStorage();", "//patchAsyncStorage();")
172172
.replace('require.resolve("./cache.cjs")', '"unused"');
173173

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export async function build(projectOpts: ProjectOptions): Promise<void> {
4141
const options = buildHelper.normalizeOptions(config, openNextDistDir, buildDir);
4242
logger.setLevel(options.debug ? "debug" : "info");
4343

44+
// Do not minify the code so that we can apply string replacement patch.
45+
// Note that wrangler will still minify the bundle.
46+
options.minify = false;
47+
4448
// Pre-build validation
4549
buildHelper.checkRunningInsideNextjsApp(options);
4650
logger.info(`App directory: ${options.appPath}`);

packages/cloudflare/src/cli/build/open-next/createServerBundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async function generateBundle(
125125
const isBundled = fnOptions.experimentalBundledNextServer ?? false;
126126
if (isBundled) {
127127
await bundleNextServer(path.join(outputPath, packagePath), appPath, {
128-
debug: options.debug,
128+
minify: options.minify,
129129
});
130130
}
131131

pnpm-lock.yaml

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ catalog:
2626
"tsx": ^4.19.2
2727
"typescript-eslint": ^8.7.0
2828
"vitest": ^2.1.1
29-
"wrangler": ^3.87.0
29+
"wrangler": ^3.91.0

0 commit comments

Comments
 (0)