cloudflare-next-intl 0.10.7 → 0.10.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "vite";
2
+ export declare const BUFFER_STUB_ID = "\0cfni:buffer-stub";
3
+ export declare function bufferStubPlugin(): Plugin;
@@ -0,0 +1,25 @@
1
+ export const BUFFER_STUB_ID = "\0cfni:buffer-stub";
2
+ export function bufferStubPlugin() {
3
+ return {
4
+ name: "cfni:buffer-stub",
5
+ enforce: "pre",
6
+ resolveId(id, _importer, options) {
7
+ if (id === "node:buffer" &&
8
+ (this.environment?.name === "client" || options?.ssr === false)) {
9
+ return BUFFER_STUB_ID;
10
+ }
11
+ },
12
+ load(id) {
13
+ if (id === BUFFER_STUB_ID) {
14
+ return `import bufferModule, { Buffer } from "buffer";\nexport { Buffer };\nexport default bufferModule;`;
15
+ }
16
+ },
17
+ config() {
18
+ return {
19
+ optimizeDeps: {
20
+ include: ["buffer"],
21
+ },
22
+ };
23
+ },
24
+ };
25
+ }
@@ -5,6 +5,8 @@ export { firebaseAuthCheckPlugin, type FirebaseAuthCheckPluginOptions } from "./
5
5
  export { buildIdAsset } from "./build_id_asset.js";
6
6
  export { userAgentStubPlugin, USER_AGENT_STUB_ID, USER_AGENT_STUB_CODE } from "./user_agent_stub.js";
7
7
  export { cfWorkersClientStubPlugin, CF_WORKERS_CLIENT_STUB_ID, CF_WORKERS_CLIENT_STUB_CODE } from "./cf_workers_client_stub.js";
8
+ export { bufferStubPlugin, BUFFER_STUB_ID } from "./buffer_stub.js";
9
+ export { reactEvalStubPlugin, reactEvalEsbuildPlugin, transformReactEval, EVAL_WARNING_RE, EVAL_POLYFILL_SNIPPET, } from "./react_eval_stub.js";
8
10
  export { vinextRouteWiringFixPlugin, patchAppPageRouteWiring, isAppPageRouteWiringFile, isAppPageRouteWiringAlreadyFixed, isVinextAppPageRouteWiringSafeOnDisk, patchAppPageProbe, isAppPageProbeFile, isAppPageProbeAlreadyFixed, isVinextAppPageProbeSafeOnDisk, type VinextRouteWiringFixPluginOptions, } from "./vinext_route_wiring_fix.js";
9
11
  export { localeFilePlugin, resolveDefaultIntlConfigPath, type LocaleFilePluginOptions } from "./locale_file_plugin.js";
10
12
  export { lucideOptimizerPlugin, detectLucideReact, resolveLucideEsmEntry, parseLucideIconMap, transformLucideImports, transformNextJsImports, type LucideOptimizerPluginOptions, } from "./lucide_optimizer_plugin.js";
@@ -5,6 +5,8 @@ export { firebaseAuthCheckPlugin } from "./firebase_auth_check_plugin.js";
5
5
  export { buildIdAsset } from "./build_id_asset.js";
6
6
  export { userAgentStubPlugin, USER_AGENT_STUB_ID, USER_AGENT_STUB_CODE } from "./user_agent_stub.js";
7
7
  export { cfWorkersClientStubPlugin, CF_WORKERS_CLIENT_STUB_ID, CF_WORKERS_CLIENT_STUB_CODE } from "./cf_workers_client_stub.js";
8
+ export { bufferStubPlugin, BUFFER_STUB_ID } from "./buffer_stub.js";
9
+ export { reactEvalStubPlugin, reactEvalEsbuildPlugin, transformReactEval, EVAL_WARNING_RE, EVAL_POLYFILL_SNIPPET, } from "./react_eval_stub.js";
8
10
  export { vinextRouteWiringFixPlugin, patchAppPageRouteWiring, isAppPageRouteWiringFile, isAppPageRouteWiringAlreadyFixed, isVinextAppPageRouteWiringSafeOnDisk, patchAppPageProbe, isAppPageProbeFile, isAppPageProbeAlreadyFixed, isVinextAppPageProbeSafeOnDisk, } from "./vinext_route_wiring_fix.js";
9
11
  export { localeFilePlugin, resolveDefaultIntlConfigPath } from "./locale_file_plugin.js";
10
12
  export { lucideOptimizerPlugin, detectLucideReact, resolveLucideEsmEntry, parseLucideIconMap, transformLucideImports, transformNextJsImports, } from "./lucide_optimizer_plugin.js";
@@ -14,6 +14,8 @@ export interface CloudflareNextIntlOptions extends LocaleFilePluginOptions {
14
14
  localeFiles?: boolean;
15
15
  userAgentStub?: boolean;
16
16
  cfWorkersClientStub?: boolean;
17
+ bufferStub?: boolean;
18
+ reactEvalStub?: boolean;
17
19
  imageOptimizer?: boolean | ImageOptimizerPluginOptions;
18
20
  vinextRouteWiringFix?: boolean | VinextRouteWiringFixPluginOptions;
19
21
  autoLocaleParams?: boolean | AutoLocaleParamsPluginOptions;
@@ -1,6 +1,8 @@
1
1
  import { buildIdAsset } from "./build_id_asset.js";
2
2
  import { userAgentStubPlugin } from "./user_agent_stub.js";
3
3
  import { cfWorkersClientStubPlugin } from "./cf_workers_client_stub.js";
4
+ import { bufferStubPlugin } from "./buffer_stub.js";
5
+ import { reactEvalStubPlugin } from "./react_eval_stub.js";
4
6
  import { localeFilePlugin } from "./locale_file_plugin.js";
5
7
  import { imageOptimizerPlugin } from "../image_optimizer/index.js";
6
8
  import { autoDynamicPagesPlugin } from "./auto_dynamic_pages_plugin.js";
@@ -54,6 +56,12 @@ export function cloudflareNextIntl(options = {}) {
54
56
  const fileName = typeof options.buildIdAsset === "string" ? options.buildIdAsset : "BUILD_ID";
55
57
  plugins.push(buildIdAsset(fileName));
56
58
  }
59
+ if (options.bufferStub !== false) {
60
+ plugins.push(bufferStubPlugin());
61
+ }
62
+ if (options.reactEvalStub !== false) {
63
+ plugins.push(reactEvalStubPlugin());
64
+ }
57
65
  if (options.cfWorkersClientStub !== false) {
58
66
  plugins.push(cfWorkersClientStubPlugin());
59
67
  }
@@ -0,0 +1,18 @@
1
+ import type { Plugin, UserConfig } from "vite";
2
+ import type { PluginBuild } from "esbuild";
3
+ export declare const EVAL_WARNING_RE: RegExp;
4
+ export declare const EVAL_POLYFILL_SNIPPET = "\nif (typeof globalThis !== \"undefined\") {\n try {\n (0, eval)(\"null\");\n } catch {\n var _origEval = globalThis.eval;\n globalThis.eval = function (code) {\n if (code === \"null\") return null;\n if (typeof code === \"string\") {\n var match = code.match(/\\(\\{\\s*(\"(?:[^\"\\\\\\\\]|\\\\.)*\")\\s*:\\s*(?:async\\s+)?(?:function|\\(?\\)?\\s*=>|class)/);\n if (match) {\n try {\n var name = JSON.parse(match[1]);\n var fn = function () {};\n Object.defineProperty(fn, \"name\", { value: name, configurable: true });\n return { [name]: fn };\n } catch {}\n }\n }\n if (typeof _origEval === \"function\") {\n try {\n return _origEval.call(this, code);\n } catch {}\n }\n return null;\n };\n }\n}\n";
5
+ export declare function transformReactEval(code: string): string;
6
+ export declare const reactEvalRolldownPlugin: {
7
+ name: string;
8
+ transform(code: string): {
9
+ code: string;
10
+ map: null;
11
+ } | undefined;
12
+ };
13
+ export declare const reactEvalEsbuildPlugin: {
14
+ name: string;
15
+ setup(build: PluginBuild): void;
16
+ };
17
+ export declare function getReactEvalConfig(): UserConfig;
18
+ export declare function reactEvalStubPlugin(): Plugin;
@@ -0,0 +1,108 @@
1
+ export const EVAL_WARNING_RE = /console\.error\(\s*["']eval\(\) is not supported in this environment[\s\S]*?React will never use eval\(\) in production mode["']\s*\);?/g;
2
+ export const EVAL_POLYFILL_SNIPPET = `
3
+ if (typeof globalThis !== "undefined") {
4
+ try {
5
+ (0, eval)("null");
6
+ } catch {
7
+ var _origEval = globalThis.eval;
8
+ globalThis.eval = function (code) {
9
+ if (code === "null") return null;
10
+ if (typeof code === "string") {
11
+ var match = code.match(/\\(\\{\\s*("(?:[^"\\\\\\\\]|\\\\.)*")\\s*:\\s*(?:async\\s+)?(?:function|\\(?\\)?\\s*=>|class)/);
12
+ if (match) {
13
+ try {
14
+ var name = JSON.parse(match[1]);
15
+ var fn = function () {};
16
+ Object.defineProperty(fn, "name", { value: name, configurable: true });
17
+ return { [name]: fn };
18
+ } catch {}
19
+ }
20
+ }
21
+ if (typeof _origEval === "function") {
22
+ try {
23
+ return _origEval.call(this, code);
24
+ } catch {}
25
+ }
26
+ return null;
27
+ };
28
+ }
29
+ }
30
+ `;
31
+ export function transformReactEval(code) {
32
+ if (!code.includes("eval() is not supported in this environment")) {
33
+ return code;
34
+ }
35
+ return EVAL_POLYFILL_SNIPPET + "\n" + code.replace(EVAL_WARNING_RE, "/* silenced react eval warning */");
36
+ }
37
+ export const reactEvalRolldownPlugin = {
38
+ name: "cfni:react-eval-stub-rolldown",
39
+ transform(code) {
40
+ if (code.includes("eval() is not supported in this environment")) {
41
+ return {
42
+ code: transformReactEval(code),
43
+ map: null,
44
+ };
45
+ }
46
+ },
47
+ };
48
+ export const reactEvalEsbuildPlugin = {
49
+ name: "cfni:react-eval-stub-esbuild",
50
+ setup(build) {
51
+ build.onLoad({ filter: /react-server-dom-webpack.*\.js$/ }, async (args) => {
52
+ const fs = await import("node:fs/promises");
53
+ const raw = await fs.readFile(args.path, "utf8");
54
+ if (raw.includes("eval() is not supported in this environment")) {
55
+ return {
56
+ contents: transformReactEval(raw),
57
+ loader: "js",
58
+ };
59
+ }
60
+ });
61
+ },
62
+ };
63
+ export function getReactEvalConfig() {
64
+ const rolldownConfig = {
65
+ rolldownOptions: {
66
+ plugins: [reactEvalRolldownPlugin],
67
+ },
68
+ };
69
+ return {
70
+ optimizeDeps: rolldownConfig,
71
+ ssr: {
72
+ noExternal: ["cloudflare-next-intl", "cloudflare-next-intl-db"],
73
+ optimizeDeps: rolldownConfig,
74
+ },
75
+ environments: {
76
+ rsc: {
77
+ resolve: {
78
+ noExternal: ["cloudflare-next-intl", "cloudflare-next-intl-db"],
79
+ },
80
+ optimizeDeps: {
81
+ include: [
82
+ "cloudflare-next-intl-db",
83
+ "cloudflare-next-intl-db/schema",
84
+ "cloudflare-next-intl-db/helpers",
85
+ ],
86
+ ...rolldownConfig,
87
+ },
88
+ },
89
+ },
90
+ };
91
+ }
92
+ export function reactEvalStubPlugin() {
93
+ return {
94
+ name: "cfni:react-eval-stub",
95
+ enforce: "pre",
96
+ transform(code) {
97
+ if (code.includes("eval() is not supported in this environment")) {
98
+ return {
99
+ code: transformReactEval(code),
100
+ map: null,
101
+ };
102
+ }
103
+ },
104
+ config() {
105
+ return getReactEvalConfig();
106
+ },
107
+ };
108
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.10.7",
3
+ "version": "0.10.9",
4
4
  "description": "Optimized Next Intl Package Special for App Router and Cloudflare",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",