this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Drop the patch for NextServer#getMiddlewareManifest (#712)

authored by

Victor Berchet and committed by
GitHub
2f6dd81a 05ef1d06

+6 -66
+5
.changeset/wild-readers-remain.md
··· 1 + --- 2 + "@opennextjs/cloudflare": patch 3 + --- 4 + 5 + Drop the patch for NextServer#getMiddlewareManifest (taken care of by was)
+1 -38
packages/cloudflare/src/cli/build/patches/plugins/next-server.spec.ts
··· 1 1 import { describe, expect, test } from "vitest"; 2 2 3 3 import { computePatchDiff } from "../../utils/test-patch.js"; 4 - import { 5 - buildIdRule, 6 - createCacheHandlerRule, 7 - createComposableCacheHandlersRule, 8 - createMiddlewareManifestRule, 9 - } from "./next-server.js"; 4 + import { buildIdRule, createCacheHandlerRule, createComposableCacheHandlersRule } from "./next-server.js"; 10 5 11 6 describe("Next Server", () => { 12 7 const nextServerCode = ` ··· 126 121 if (this.minimalMode) return null; 127 122 const manifest = require(this.middlewareManifestPath); 128 123 return manifest; 129 - " 130 - `); 131 - }); 132 - 133 - test("middleware manifest", () => { 134 - expect(computePatchDiff("next-server.js", nextServerCode, createMiddlewareManifestRule("manifest"))) 135 - .toMatchInlineSnapshot(` 136 - "Index: next-server.js 137 - =================================================================== 138 - --- next-server.js 139 - +++ next-server.js 140 - @@ -1,5 +1,4 @@ 141 - - 142 - class NextNodeServer extends _baseserver.default { 143 - constructor(options){ 144 - // Initialize super class 145 - super(options); 146 - @@ -30,12 +29,10 @@ 147 - throw err; 148 - } 149 - } 150 - getMiddlewareManifest() { 151 - - if (this.minimalMode) return null; 152 - - const manifest = require(this.middlewareManifestPath); 153 - - return manifest; 154 - - } 155 - + return "manifest"; 156 - +} 157 - async loadCustomCacheHandlers() { 158 - const { cacheHandlers } = this.nextConfig.experimental; 159 - if (!cacheHandlers) return; 160 - // If we've already initialized the cache handlers interface, don't do it 161 124 " 162 125 `); 163 126 });
-28
packages/cloudflare/src/cli/build/patches/plugins/next-server.ts
··· 4 4 * Note: we will probably need to revisit the patches when the Next adapter API lands 5 5 * 6 6 * - Inline `getBuildId` as it relies on `readFileSync` that is not supported by workerd 7 - * - Inline the middleware manifest 8 7 * - Override the cache and composable cache handlers 9 8 */ 10 9 11 - import { existsSync, readFileSync } from "node:fs"; 12 10 import path from "node:path"; 13 11 14 12 import { type BuildOptions, getPackagePath } from "@opennextjs/aws/build/helper.js"; ··· 31 29 32 30 contents = patchCode(contents, buildIdRule); 33 31 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 - 47 32 const outputPath = path.join(outputDir, "server-functions/default"); 48 33 const cacheHandler = path.join(outputPath, getPackagePath(buildOpts), "cache.cjs"); 49 34 contents = patchCode(contents, createCacheHandlerRule(cacheHandler)); ··· 71 56 return process.env.NEXT_BUILD_ID; 72 57 } 73 58 `; 74 - 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 59 88 60 /** 89 61 * The cache handler used by Next.js is normally defined in the config file as a path. At runtime,