Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions packages/cloudflare/src/cli/build/bundle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { getOpenNextConfig } from "../../api/config.js";
import { patchVercelOgLibrary } from "./patches/ast/patch-vercel-og-library.js";
import { patchWebpackRuntime } from "./patches/ast/webpack-runtime.js";
import * as patches from "./patches/index.js";
import { inlineBuildId } from "./patches/plugins/build-id.js";
import { inlineDynamicRequires } from "./patches/plugins/dynamic-requires.js";
import { inlineEvalManifest } from "./patches/plugins/eval-manifest.js";
import { inlineFindDir } from "./patches/plugins/find-dir.js";
import { patchInstrumentation } from "./patches/plugins/instrumentation.js";
import { inlineLoadManifest } from "./patches/plugins/load-manifest.js";
import { patchNextServer } from "./patches/plugins/next-server.js";
import { handleOptionalDependencies } from "./patches/plugins/optional-deps.js";
import { patchPagesRouterContext } from "./patches/plugins/pages-router-context.js";
import { patchDepdDeprecations } from "./patches/plugins/patch-depd-deprecations.js";
Expand Down Expand Up @@ -99,7 +99,7 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
inlineEvalManifest(updater, buildOpts),
inlineFindDir(updater, buildOpts),
inlineLoadManifest(updater, buildOpts),
inlineBuildId(updater),
patchNextServer(updater, buildOpts),
patchDepdDeprecations(updater),
// Apply updater updates, must be the last plugin
updater.plugin,
Expand Down Expand Up @@ -182,11 +182,6 @@ export async function updateWorkerBundledCode(
["require", patches.patchRequire],
["cacheHandler", (code) => patches.patchCache(code, buildOpts)],
["composableCache", (code) => patches.patchComposableCache(code, buildOpts), { isOptional: true }],
[
"'require(this.middlewareManifestPath)'",
(code) => patches.inlineMiddlewareManifestRequire(code, buildOpts),
{ isOptional: true },
],
[
"`require.resolve` call",
// workers do not support dynamic require nor require.resolve
Expand Down
1 change: 0 additions & 1 deletion packages/cloudflare/src/cli/build/patches/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from "./investigated/index.js";
export * from "./to-investigate/inline-middleware-manifest.js";
85 changes: 0 additions & 85 deletions packages/cloudflare/src/cli/build/patches/plugins/build-id.spec.ts

This file was deleted.

33 changes: 0 additions & 33 deletions packages/cloudflare/src/cli/build/patches/plugins/build-id.ts

This file was deleted.

180 changes: 180 additions & 0 deletions packages/cloudflare/src/cli/build/patches/plugins/next-server.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js";
import { describe, expect, test } from "vitest";

import { buildIdRule, createMiddlewareManifestRule } from "./next-server.js";

describe("Next Server", () => {
test("build ID", () => {
const code = `
class NextNodeServer extends _baseserver.default {
constructor(options){
// Initialize super class
super(options);
this.handleNextImageRequest = async (req, res, parsedUrl) => { /* ... */ };
}
async handleUpgrade() {
// The web server does not support web sockets, it's only used for HMR in
// development.
}
loadEnvConfig({ dev, forceReload, silent }) {
(0, _env.loadEnvConfig)(this.dir, dev, silent ? {
info: ()=>{},
error: ()=>{}
} : _log, forceReload);
}
async hasPage(pathname) {
var _this_nextConfig_i18n;
return !!(0, _require.getMaybePagePath)(pathname, this.distDir, (_this_nextConfig_i18n = this.nextConfig.i18n) == null ? void 0 : _this_nextConfig_i18n.locales, this.enabledDirectories.app);
}
getBuildId() {
const buildIdFile = (0, _path.join)(this.distDir, _constants.BUILD_ID_FILE);
try {
return _fs.default.readFileSync(buildIdFile, "utf8").trim();
} catch (err) {
if (err.code === "ENOENT") {
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\`);
}
throw err;
}
}
getEnabledDirectories(dev) {
const dir = dev ? this.dir : this.serverDistDir;
return {
app: (0, _findpagesdir.findDir)(dir, "app") ? true : false,
pages: (0, _findpagesdir.findDir)(dir, "pages") ? true : false
};
}
// ...
}`;

expect(patchCode(code, buildIdRule)).toMatchInlineSnapshot(`
"class NextNodeServer extends _baseserver.default {
constructor(options){
// Initialize super class
super(options);
this.handleNextImageRequest = async (req, res, parsedUrl) => { /* ... */ };
}
async handleUpgrade() {
// The web server does not support web sockets, it's only used for HMR in
// development.
}
loadEnvConfig({ dev, forceReload, silent }) {
(0, _env.loadEnvConfig)(this.dir, dev, silent ? {
info: ()=>{},
error: ()=>{}
} : _log, forceReload);
}
async hasPage(pathname) {
var _this_nextConfig_i18n;
return !!(0, _require.getMaybePagePath)(pathname, this.distDir, (_this_nextConfig_i18n = this.nextConfig.i18n) == null ? void 0 : _this_nextConfig_i18n.locales, this.enabledDirectories.app);
}
getBuildId() {
return process.env.NEXT_BUILD_ID;
}
getEnabledDirectories(dev) {
const dir = dev ? this.dir : this.serverDistDir;
return {
app: (0, _findpagesdir.findDir)(dir, "app") ? true : false,
pages: (0, _findpagesdir.findDir)(dir, "pages") ? true : false
};
}
// ...
}"
`);
});

test("build ID", () => {
const code = `
class NextNodeServer extends _baseserver.default {
constructor(options){
// Initialize super class
super(options);
this.handleNextImageRequest = async (req, res, parsedUrl) => { /* ... */ };
}
async handleUpgrade() {
// The web server does not support web sockets, it's only used for HMR in
// development.
}
loadEnvConfig({ dev, forceReload, silent }) {
(0, _env.loadEnvConfig)(this.dir, dev, silent ? {
info: ()=>{},
error: ()=>{}
} : _log, forceReload);
}
async hasPage(pathname) {
var _this_nextConfig_i18n;
return !!(0, _require.getMaybePagePath)(pathname, this.distDir, (_this_nextConfig_i18n = this.nextConfig.i18n) == null ? void 0 : _this_nextConfig_i18n.locales, this.enabledDirectories.app);
}
getBuildId() {
const buildIdFile = (0, _path.join)(this.distDir, _constants.BUILD_ID_FILE);
try {
return _fs.default.readFileSync(buildIdFile, "utf8").trim();
} catch (err) {
if (err.code === "ENOENT") {
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\`);
}
throw err;
}
}
getMiddlewareManifest() {
if (this.minimalMode) return null;
const manifest = require(this.middlewareManifestPath);
return manifest;
}
getEnabledDirectories(dev) {
const dir = dev ? this.dir : this.serverDistDir;
return {
app: (0, _findpagesdir.findDir)(dir, "app") ? true : false,
pages: (0, _findpagesdir.findDir)(dir, "pages") ? true : false
};
}
// ...
}`;

expect(patchCode(code, createMiddlewareManifestRule("manifest"))).toMatchInlineSnapshot(`
"class NextNodeServer extends _baseserver.default {
constructor(options){
// Initialize super class
super(options);
this.handleNextImageRequest = async (req, res, parsedUrl) => { /* ... */ };
}
async handleUpgrade() {
// The web server does not support web sockets, it's only used for HMR in
// development.
}
loadEnvConfig({ dev, forceReload, silent }) {
(0, _env.loadEnvConfig)(this.dir, dev, silent ? {
info: ()=>{},
error: ()=>{}
} : _log, forceReload);
}
async hasPage(pathname) {
var _this_nextConfig_i18n;
return !!(0, _require.getMaybePagePath)(pathname, this.distDir, (_this_nextConfig_i18n = this.nextConfig.i18n) == null ? void 0 : _this_nextConfig_i18n.locales, this.enabledDirectories.app);
}
getBuildId() {
const buildIdFile = (0, _path.join)(this.distDir, _constants.BUILD_ID_FILE);
try {
return _fs.default.readFileSync(buildIdFile, "utf8").trim();
} catch (err) {
if (err.code === "ENOENT") {
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\`);
}
throw err;
}
}
getMiddlewareManifest() {
return "manifest";
}
getEnabledDirectories(dev) {
const dir = dev ? this.dir : this.serverDistDir;
return {
app: (0, _findpagesdir.findDir)(dir, "app") ? true : false,
pages: (0, _findpagesdir.findDir)(dir, "pages") ? true : false
};
}
// ...
}"
`);
});
});
Loading