cloudflare-next-intl 0.10.6 → 0.10.8
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.
- package/dist/src/firebase_auth_check/check_firebase_auth_config.d.ts +5 -0
- package/dist/src/firebase_auth_check/check_firebase_auth_config.js +74 -1
- package/dist/src/firebase_auth_check/index.d.ts +2 -1
- package/dist/src/firebase_auth_check/index.js +2 -1
- package/dist/src/firebase_auth_check/load_resolved_firebase_auth.d.ts +8 -0
- package/dist/src/firebase_auth_check/load_resolved_firebase_auth.js +51 -0
- package/dist/src/vite/buffer_stub.d.ts +3 -0
- package/dist/src/vite/buffer_stub.js +18 -0
- package/dist/src/vite/firebase_auth_check_plugin.js +16 -2
- package/dist/src/vite/index.d.ts +2 -0
- package/dist/src/vite/index.js +2 -0
- package/dist/src/vite/plugin.d.ts +2 -0
- package/dist/src/vite/plugin.js +8 -0
- package/dist/src/vite/react_eval_stub.d.ts +10 -0
- package/dist/src/vite/react_eval_stub.js +91 -0
- package/package.json +1 -1
|
@@ -27,3 +27,8 @@ export declare function extractFieldValue(body: string, key: string): {
|
|
|
27
27
|
} | null;
|
|
28
28
|
export declare function formatFirebaseAuthConfigMessage(issues: FirebaseAuthConfigIssue[], intlConfigPath?: string): string;
|
|
29
29
|
export declare function checkFirebaseAuthConfig(options?: CheckFirebaseAuthConfigOptions): CheckFirebaseAuthConfigReport;
|
|
30
|
+
export interface ValidateFirebaseAuthConfigValuesOptions {
|
|
31
|
+
firebaseAuth: Record<string, unknown> | undefined;
|
|
32
|
+
intlConfigPath?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function validateFirebaseAuthConfigValues(options: ValidateFirebaseAuthConfigValuesOptions): CheckFirebaseAuthConfigReport;
|
|
@@ -337,7 +337,29 @@ function resolveSpreadBodies(mainBody, source, fromFile, cache) {
|
|
|
337
337
|
return { bodies, hasUnresolvedSpread };
|
|
338
338
|
}
|
|
339
339
|
export function extractFieldValue(body, key) {
|
|
340
|
-
const
|
|
340
|
+
const masked = maskCommentsAndStrings(body);
|
|
341
|
+
const keyPattern = new RegExp(`^${key}\\s*:`);
|
|
342
|
+
let searchDepth = 0;
|
|
343
|
+
let scanIndex = 0;
|
|
344
|
+
let keyMatch = null;
|
|
345
|
+
while (scanIndex < masked.length) {
|
|
346
|
+
const char = masked[scanIndex];
|
|
347
|
+
if (char === "{" || char === "[" || char === "(") {
|
|
348
|
+
searchDepth += 1;
|
|
349
|
+
}
|
|
350
|
+
else if (char === "}" || char === "]" || char === ")") {
|
|
351
|
+
searchDepth -= 1;
|
|
352
|
+
}
|
|
353
|
+
else if (searchDepth === 0 && (scanIndex === 0 || /[\s{,]/.test(masked[scanIndex - 1]))) {
|
|
354
|
+
const candidate = keyPattern.exec(masked.slice(scanIndex));
|
|
355
|
+
if (candidate) {
|
|
356
|
+
keyMatch = candidate;
|
|
357
|
+
keyMatch.index = scanIndex;
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
scanIndex += 1;
|
|
362
|
+
}
|
|
341
363
|
if (!keyMatch)
|
|
342
364
|
return null;
|
|
343
365
|
const start = keyMatch.index + keyMatch[0].length;
|
|
@@ -531,3 +553,54 @@ export function checkFirebaseAuthConfig(options = {}) {
|
|
|
531
553
|
}
|
|
532
554
|
return { valid, checked: true, issues, formattedMessage };
|
|
533
555
|
}
|
|
556
|
+
function isUsableFieldValue(value) {
|
|
557
|
+
if (value === undefined || value === null)
|
|
558
|
+
return false;
|
|
559
|
+
if (typeof value === "string")
|
|
560
|
+
return value.trim() !== "";
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
const UNUSABLE_REASON = "resolved to an empty or missing value";
|
|
564
|
+
export function validateFirebaseAuthConfigValues(options) {
|
|
565
|
+
const { firebaseAuth } = options;
|
|
566
|
+
if (!firebaseAuth) {
|
|
567
|
+
return { valid: true, checked: false, issues: [], formattedMessage: "" };
|
|
568
|
+
}
|
|
569
|
+
const issues = [];
|
|
570
|
+
for (const key of REQUIRED_AUTH_FIELDS) {
|
|
571
|
+
if (!isUsableFieldValue(firebaseAuth[key])) {
|
|
572
|
+
issues.push({ field: `firebaseAuth.${key}`, severity: "error", reason: UNUSABLE_REASON });
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
const appCheck = firebaseAuth.appCheck;
|
|
576
|
+
if (appCheck && appCheck.reportMissingServerCredentials !== false) {
|
|
577
|
+
for (const key of REQUIRED_APP_CHECK_FIELDS) {
|
|
578
|
+
if (!isUsableFieldValue(appCheck[key])) {
|
|
579
|
+
issues.push({ field: `firebaseAuth.appCheck.${key}`, severity: "warning", reason: UNUSABLE_REASON });
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
const hasPrivateKey = isUsableFieldValue(appCheck.privateKey);
|
|
583
|
+
const tripleUsable = OAUTH_TRIPLE.map((key) => isUsableFieldValue(appCheck[key]));
|
|
584
|
+
const hasTriple = tripleUsable.every(Boolean);
|
|
585
|
+
if (!hasPrivateKey && !hasTriple) {
|
|
586
|
+
const hasPartialTriple = tripleUsable.some(Boolean);
|
|
587
|
+
if (hasPartialTriple) {
|
|
588
|
+
OAUTH_TRIPLE.forEach((key, index) => {
|
|
589
|
+
if (!tripleUsable[index]) {
|
|
590
|
+
issues.push({ field: `firebaseAuth.appCheck.${key}`, severity: "warning", reason: UNUSABLE_REASON });
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
issues.push({
|
|
596
|
+
field: "firebaseAuth.appCheck.privateKey",
|
|
597
|
+
severity: "warning",
|
|
598
|
+
reason: UNUSABLE_REASON + " — set it, or the full oauthClientId/oauthClientSecret/oauthRefreshToken triple",
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
const valid = !issues.some((issue) => issue.severity === "error");
|
|
604
|
+
const formattedMessage = formatFirebaseAuthConfigMessage(issues, options.intlConfigPath);
|
|
605
|
+
return { valid, checked: true, issues, formattedMessage };
|
|
606
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { checkFirebaseAuthConfig, formatFirebaseAuthConfigMessage, extractObjectLiteral, extractFieldValue, type FirebaseAuthConfigIssue, type CheckFirebaseAuthConfigOptions, type CheckFirebaseAuthConfigReport, } from "./check_firebase_auth_config.js";
|
|
1
|
+
export { checkFirebaseAuthConfig, validateFirebaseAuthConfigValues, formatFirebaseAuthConfigMessage, extractObjectLiteral, extractFieldValue, type FirebaseAuthConfigIssue, type CheckFirebaseAuthConfigOptions, type CheckFirebaseAuthConfigReport, type ValidateFirebaseAuthConfigValuesOptions, } from "./check_firebase_auth_config.js";
|
|
2
|
+
export { loadResolvedFirebaseAuth, type LoadResolvedFirebaseAuthOptions } from "./load_resolved_firebase_auth.js";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { checkFirebaseAuthConfig, formatFirebaseAuthConfigMessage, extractObjectLiteral, extractFieldValue, } from "./check_firebase_auth_config.js";
|
|
1
|
+
export { checkFirebaseAuthConfig, validateFirebaseAuthConfigValues, formatFirebaseAuthConfigMessage, extractObjectLiteral, extractFieldValue, } from "./check_firebase_auth_config.js";
|
|
2
|
+
export { loadResolvedFirebaseAuth } from "./load_resolved_firebase_auth.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ResolvedConfig } from "vite";
|
|
2
|
+
export interface LoadResolvedFirebaseAuthOptions {
|
|
3
|
+
intlConfigPath: string;
|
|
4
|
+
viteConfig: Pick<ResolvedConfig, "root" | "envDir" | "mode"> & {
|
|
5
|
+
resolve: Pick<ResolvedConfig["resolve"], "alias">;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare function loadResolvedFirebaseAuth(options: LoadResolvedFirebaseAuthOptions): Promise<Record<string, unknown> | undefined>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export async function loadResolvedFirebaseAuth(options) {
|
|
2
|
+
let server;
|
|
3
|
+
try {
|
|
4
|
+
const { createServer } = await import("vite");
|
|
5
|
+
server = await createServer({
|
|
6
|
+
configFile: false,
|
|
7
|
+
root: options.viteConfig.root,
|
|
8
|
+
envDir: options.viteConfig.envDir,
|
|
9
|
+
mode: options.viteConfig.mode,
|
|
10
|
+
resolve: { alias: options.viteConfig.resolve.alias },
|
|
11
|
+
server: { middlewareMode: true, hmr: false, watch: null },
|
|
12
|
+
optimizeDeps: { noDiscovery: true },
|
|
13
|
+
logLevel: "silent",
|
|
14
|
+
clearScreen: false,
|
|
15
|
+
ssr: { noExternal: ["cloudflare-next-intl", /^cloudflare:/] },
|
|
16
|
+
plugins: [
|
|
17
|
+
{
|
|
18
|
+
name: "cfni:firebase-auth-check-intl-config-alias",
|
|
19
|
+
enforce: "pre",
|
|
20
|
+
resolveId(id) {
|
|
21
|
+
if (id === "@intl-config")
|
|
22
|
+
return options.intlConfigPath;
|
|
23
|
+
if (id === "cloudflare:workers" || id.startsWith("cloudflare:")) {
|
|
24
|
+
return "\0cfni:cloudflare-workers-stub";
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
load(id) {
|
|
28
|
+
if (id === "\0cfni:cloudflare-workers-stub") {
|
|
29
|
+
return ("export class WorkerEntrypoint {}\n" +
|
|
30
|
+
"export class DurableObject {}\n" +
|
|
31
|
+
"export const env = {};\n" +
|
|
32
|
+
"export default {};\n");
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
const mod = await server.ssrLoadModule(options.intlConfigPath);
|
|
39
|
+
const exported = mod.default;
|
|
40
|
+
const firebaseAuth = exported?.firebaseAuth;
|
|
41
|
+
return firebaseAuth && typeof firebaseAuth === "object"
|
|
42
|
+
? firebaseAuth
|
|
43
|
+
: undefined;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
await server?.close();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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" || id === "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 `export { Buffer } from "buffer";\nexport default { Buffer };`;
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkFirebaseAuthConfig } from "../firebase_auth_check/index.js";
|
|
1
|
+
import { checkFirebaseAuthConfig, validateFirebaseAuthConfigValues, loadResolvedFirebaseAuth, } from "../firebase_auth_check/index.js";
|
|
2
2
|
import { resolveDefaultIntlConfigPath } from "./locale_file_plugin.js";
|
|
3
3
|
export function firebaseAuthCheckPlugin(options = {}) {
|
|
4
4
|
let ran = false;
|
|
@@ -23,7 +23,21 @@ export function firebaseAuthCheckPlugin(options = {}) {
|
|
|
23
23
|
...process.env,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
const
|
|
26
|
+
const previousEnv = { ...process.env };
|
|
27
|
+
Object.assign(process.env, env);
|
|
28
|
+
let firebaseAuth;
|
|
29
|
+
try {
|
|
30
|
+
firebaseAuth = await loadResolvedFirebaseAuth({
|
|
31
|
+
intlConfigPath,
|
|
32
|
+
viteConfig: { root: config.root, envDir: config.envDir, mode: config.mode, resolve: { alias: config.resolve?.alias } },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
process.env = previousEnv;
|
|
37
|
+
}
|
|
38
|
+
const report = firebaseAuth !== undefined
|
|
39
|
+
? validateFirebaseAuthConfigValues({ firebaseAuth, intlConfigPath })
|
|
40
|
+
: checkFirebaseAuthConfig({ intlConfigPath, env, throwOnError: false });
|
|
27
41
|
if (report.issues.length === 0)
|
|
28
42
|
return;
|
|
29
43
|
console.warn(report.formattedMessage);
|
package/dist/src/vite/index.d.ts
CHANGED
|
@@ -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";
|
package/dist/src/vite/index.js
CHANGED
|
@@ -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;
|
package/dist/src/vite/plugin.js
CHANGED
|
@@ -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,10 @@
|
|
|
1
|
+
import type { Plugin } 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 reactEvalEsbuildPlugin: {
|
|
7
|
+
name: string;
|
|
8
|
+
setup(build: PluginBuild): void;
|
|
9
|
+
};
|
|
10
|
+
export declare function reactEvalStubPlugin(): Plugin;
|
|
@@ -0,0 +1,91 @@
|
|
|
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 reactEvalEsbuildPlugin = {
|
|
38
|
+
name: "cfni:react-eval-stub-esbuild",
|
|
39
|
+
setup(build) {
|
|
40
|
+
build.onLoad({ filter: /react-server-dom-webpack.*\.js$/ }, async (args) => {
|
|
41
|
+
const fs = await import("node:fs/promises");
|
|
42
|
+
const raw = await fs.readFile(args.path, "utf8");
|
|
43
|
+
if (raw.includes("eval() is not supported in this environment")) {
|
|
44
|
+
return {
|
|
45
|
+
contents: transformReactEval(raw),
|
|
46
|
+
loader: "js",
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
export function reactEvalStubPlugin() {
|
|
53
|
+
return {
|
|
54
|
+
name: "cfni:react-eval-stub",
|
|
55
|
+
enforce: "pre",
|
|
56
|
+
transform(code) {
|
|
57
|
+
if (code.includes("eval() is not supported in this environment")) {
|
|
58
|
+
return {
|
|
59
|
+
code: transformReactEval(code),
|
|
60
|
+
map: null,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
config() {
|
|
65
|
+
return {
|
|
66
|
+
optimizeDeps: {
|
|
67
|
+
exclude: ["react-server-dom-webpack", "react-server-dom-webpack/client.edge"],
|
|
68
|
+
esbuildOptions: {
|
|
69
|
+
plugins: [reactEvalEsbuildPlugin],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
ssr: {
|
|
73
|
+
optimizeDeps: {
|
|
74
|
+
esbuildOptions: {
|
|
75
|
+
plugins: [reactEvalEsbuildPlugin],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
environments: {
|
|
80
|
+
rsc: {
|
|
81
|
+
optimizeDeps: {
|
|
82
|
+
esbuildOptions: {
|
|
83
|
+
plugins: [reactEvalEsbuildPlugin],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|