Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/neat-jars-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": patch
---

perf: drop the babel dependency
2 changes: 2 additions & 0 deletions packages/cloudflare/src/cli/build/bundle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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 { patchNodeEnvironment } from "./patches/plugins/node-environment.js";
import { patchResolveCache } from "./patches/plugins/open-next.js";
import { handleOptionalDependencies } from "./patches/plugins/optional-deps.js";
import { patchPagesRouterContext } from "./patches/plugins/pages-router-context.js";
Expand Down Expand Up @@ -107,6 +108,7 @@ export async function bundleServer(buildOpts: BuildOptions, projectOpts: Project
patchRouteModules(updater, buildOpts),
patchDepdDeprecations(updater),
patchResolveCache(updater, buildOpts),
patchNodeEnvironment(updater),
// Apply updater updates, must be the last plugin
updater.plugin,
] as Plugin[],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { describe, expect, test } from "vitest";

import { computePatchDiff } from "../../utils/test-patch.js";
import { errorInspectRule } from "./node-environment.js";

describe("NodeEnvironment", () => {
const code = `
// This file should be imported before any others. It sets up the environment
// for later imports to work properly.
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
require("./node-environment-baseline");
require("./node-environment-extensions/error-inspect");
require("./node-environment-extensions/random");
require("./node-environment-extensions/date");
require("./node-environment-extensions/web-crypto");
require("./node-environment-extensions/node-crypto");
if (process.env.NODE_ENV === 'development') {
require('./node-environment-extensions/console-dev');
}

//# sourceMappingURL=node-environment.js.map
`;

test("error inspect", () => {
expect(computePatchDiff("node-environment.js", code, errorInspectRule)).toMatchInlineSnapshot(`
"Index: node-environment.js
===================================================================
--- node-environment.js
+++ node-environment.js
@@ -1,13 +1,13 @@
-
// This file should be imported before any others. It sets up the environment
// for later imports to work properly.
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
require("./node-environment-baseline");
-require("./node-environment-extensions/error-inspect");
+// Removed by OpenNext
+// require("./node-environment-extensions/error-inspect");
require("./node-environment-extensions/random");
require("./node-environment-extensions/date");
require("./node-environment-extensions/web-crypto");
require("./node-environment-extensions/node-crypto");
"
`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Remove a dependency on Babel by dropping the require of error-inspect
*/

import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js";
import type { ContentUpdater, Plugin } from "@opennextjs/aws/plugins/content-updater.js";
import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";

export function patchNodeEnvironment(updater: ContentUpdater): Plugin {
return updater.updateContent("node-environment", [
{
filter: getCrossPlatformPathRegex(String.raw`/next/dist/server/node-environment\.js$`, {
escape: false,
}),
contentFilter: /error-inspect/,
callback: async ({ contents }) => patchCode(contents, errorInspectRule),
},
]);
}

/**
* Drops `require("./node-environment-extensions/error-inspect");`
*/
export const errorInspectRule = `
rule:
pattern: require("./node-environment-extensions/error-inspect");
fix: |-
// Removed by OpenNext
// require("./node-environment-extensions/error-inspect");
`;