Skip to content

Commit aab1457

Browse files
committed
Drop the patch for NextServer#getMiddlewareManifest
1 parent 5f197fc commit aab1457

File tree

5 files changed

+13
-125
lines changed

5 files changed

+13
-125
lines changed

.changeset/wild-readers-remain.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+
Drop the patch for NextServer#getMiddlewareManifest

packages/cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"homepage": "https://github.com/opennextjs/opennextjs-cloudflare",
5454
"dependencies": {
5555
"@dotenvx/dotenvx": "catalog:",
56-
"@opennextjs/aws": "3.6.5",
56+
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@892",
5757
"enquirer": "^2.4.1",
5858
"glob": "catalog:",
5959
"ts-tqdm": "^0.8.6"

packages/cloudflare/src/cli/build/patches/plugins/next-server.spec.ts

Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js";
22
import { describe, expect, test } from "vitest";
33

4-
import {
5-
buildIdRule,
6-
createCacheHandlerRule,
7-
createComposableCacheHandlersRule,
8-
createMiddlewareManifestRule,
9-
} from "./next-server.js";
4+
import { buildIdRule, createCacheHandlerRule, createComposableCacheHandlersRule } from "./next-server.js";
105

116
describe("Next Server", () => {
127
const nextServerCode = `
@@ -172,91 +167,6 @@ class NextNodeServer extends _baseserver.default {
172167
`);
173168
});
174169

175-
test("middleware manifest", () => {
176-
expect(patchCode(nextServerCode, createMiddlewareManifestRule("manifest"))).toMatchInlineSnapshot(`
177-
"class NextNodeServer extends _baseserver.default {
178-
constructor(options){
179-
// Initialize super class
180-
super(options);
181-
this.handleNextImageRequest = async (req, res, parsedUrl) => { /* ... */ };
182-
}
183-
async handleUpgrade() {
184-
// The web server does not support web sockets, it's only used for HMR in
185-
// development.
186-
}
187-
loadEnvConfig({ dev, forceReload, silent }) {
188-
(0, _env.loadEnvConfig)(this.dir, dev, silent ? {
189-
info: ()=>{},
190-
error: ()=>{}
191-
} : _log, forceReload);
192-
}
193-
async hasPage(pathname) {
194-
var _this_nextConfig_i18n;
195-
return !!(0, _require.getMaybePagePath)(pathname, this.distDir, (_this_nextConfig_i18n = this.nextConfig.i18n) == null ? void 0 : _this_nextConfig_i18n.locales, this.enabledDirectories.app);
196-
}
197-
getBuildId() {
198-
const buildIdFile = (0, _path.join)(this.distDir, _constants.BUILD_ID_FILE);
199-
try {
200-
return _fs.default.readFileSync(buildIdFile, "utf8").trim();
201-
} catch (err) {
202-
if (err.code === "ENOENT") {
203-
throw new Error(\`Could not find a production build in the '\${this.distDir}' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id\`);
204-
}
205-
throw err;
206-
}
207-
}
208-
getMiddlewareManifest() {
209-
return "manifest";
210-
}
211-
async loadCustomCacheHandlers() {
212-
const { cacheHandlers } = this.nextConfig.experimental;
213-
if (!cacheHandlers) return;
214-
// If we've already initialized the cache handlers interface, don't do it
215-
// again.
216-
if (!(0, _handlers.initializeCacheHandlers)()) return;
217-
for (const [kind, handler] of Object.entries(cacheHandlers)){
218-
if (!handler) continue;
219-
(0, _handlers.setCacheHandler)(kind, (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, handler))));
220-
}
221-
}
222-
async getIncrementalCache({ requestHeaders, requestProtocol }) {
223-
const dev = !!this.renderOpts.dev;
224-
let CacheHandler;
225-
const { cacheHandler } = this.nextConfig;
226-
if (cacheHandler) {
227-
CacheHandler = (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, cacheHandler)));
228-
}
229-
await this.loadCustomCacheHandlers();
230-
// incremental-cache is request specific
231-
// although can have shared caches in module scope
232-
// per-cache handler
233-
return new _incrementalcache.IncrementalCache({
234-
fs: this.getCacheFilesystem(),
235-
dev,
236-
requestHeaders,
237-
requestProtocol,
238-
allowedRevalidateHeaderKeys: this.nextConfig.experimental.allowedRevalidateHeaderKeys,
239-
minimalMode: this.minimalMode,
240-
serverDistDir: this.serverDistDir,
241-
fetchCacheKeyPrefix: this.nextConfig.experimental.fetchCacheKeyPrefix,
242-
maxMemoryCacheSize: this.nextConfig.cacheMaxMemorySize,
243-
flushToDisk: !this.minimalMode && this.nextConfig.experimental.isrFlushToDisk,
244-
getPrerenderManifest: ()=>this.getPrerenderManifest(),
245-
CurCacheHandler: CacheHandler
246-
});
247-
}
248-
getEnabledDirectories(dev) {
249-
const dir = dev ? this.dir : this.serverDistDir;
250-
return {
251-
app: (0, _findpagesdir.findDir)(dir, "app") ? true : false,
252-
pages: (0, _findpagesdir.findDir)(dir, "pages") ? true : false
253-
};
254-
}
255-
// ...
256-
}"
257-
`);
258-
});
259-
260170
test("cache handler", () => {
261171
expect(patchCode(nextServerCode, createCacheHandlerRule("manifest"))).toMatchInlineSnapshot(`
262172
"class NextNodeServer extends _baseserver.default {

packages/cloudflare/src/cli/build/patches/plugins/next-server.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
* Note: we will probably need to revisit the patches when the Next adapter API lands
55
*
66
* - Inline `getBuildId` as it relies on `readFileSync` that is not supported by workerd
7-
* - Inline the middleware manifest
87
* - Override the cache and composable cache handlers
98
*/
109

11-
import { existsSync, readFileSync } from "node:fs";
1210
import path from "node:path";
1311

1412
import { type BuildOptions, getPackagePath } from "@opennextjs/aws/build/helper.js";
@@ -31,19 +29,6 @@ export function patchNextServer(updater: ContentUpdater, buildOpts: BuildOptions
3129

3230
contents = patchCode(contents, buildIdRule);
3331

34-
const manifestPath = path.join(
35-
outputDir,
36-
"server-functions/default",
37-
getPackagePath(buildOpts),
38-
".next/server/middleware-manifest.json"
39-
);
40-
41-
const manifest = existsSync(manifestPath)
42-
? JSON.parse(await readFileSync(manifestPath, "utf-8"))
43-
: {};
44-
45-
contents = patchCode(contents, createMiddlewareManifestRule(manifest));
46-
4732
const outputPath = path.join(outputDir, "server-functions/default");
4833
const cacheHandler = path.join(outputPath, getPackagePath(buildOpts), "cache.cjs");
4934
contents = patchCode(contents, createCacheHandlerRule(cacheHandler));
@@ -72,19 +57,6 @@ fix: |-
7257
}
7358
`;
7459

75-
export function createMiddlewareManifestRule(manifest: unknown) {
76-
return `
77-
rule:
78-
pattern:
79-
selector: method_definition
80-
context: "class { getMiddlewareManifest($$$PARAMS) { $$$_ } }"
81-
fix: |-
82-
getMiddlewareManifest($$$PARAMS) {
83-
return ${JSON.stringify(manifest)};
84-
}
85-
`;
86-
}
87-
8860
/**
8961
* The cache handler used by Next.js is normally defined in the config file as a path. At runtime,
9062
* Next.js would then do a dynamic require on a transformed version of the path to retrieve the

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)