cloudflare-next-intl 0.10.5 → 0.10.6
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.
|
@@ -12,6 +12,7 @@ export interface DynamicApiCheck {
|
|
|
12
12
|
name: string;
|
|
13
13
|
pattern: RegExp;
|
|
14
14
|
}
|
|
15
|
+
export declare function hasSetLocaleCall(sourceText: string): boolean;
|
|
15
16
|
export declare const USE_CLIENT_DIRECTIVE: RegExp;
|
|
16
17
|
export declare function detectDynamicUsage(sourceText: string, extraChecks?: readonly DynamicApiCheck[]): DynamicDetectionResult;
|
|
17
18
|
export declare function readExplicitDynamicValue(sourceText: string): 'force-static' | 'force-dynamic' | 'auto' | 'error' | null;
|
|
@@ -32,7 +32,6 @@ export function stripComments(sourceText) {
|
|
|
32
32
|
const DYNAMIC_API_CHECKS = [
|
|
33
33
|
{ name: 'cookies()', pattern: /\bcookies\s*\(/ },
|
|
34
34
|
{ name: 'headers()', pattern: /\bheaders\s*\(\s*\)/ },
|
|
35
|
-
{ name: 'searchParams', pattern: /\bsearchParams\b/ },
|
|
36
35
|
{ name: 'unstable_noStore()', pattern: /\bunstable_noStore\s*\(/ },
|
|
37
36
|
{ name: 'connection()', pattern: /\bconnection\s*\(\s*\)/ },
|
|
38
37
|
{ name: 'cache: "no-store"', pattern: /cache:\s*['"]no-store['"]/ },
|
|
@@ -41,8 +40,12 @@ const DYNAMIC_API_CHECKS = [
|
|
|
41
40
|
{ name: 'withUserDb()', pattern: /\bwithUserDb\s*\(/ },
|
|
42
41
|
];
|
|
43
42
|
const USE_AUTH_USER_CALL = /\buseAuthUser\s*\(/;
|
|
43
|
+
const SEARCH_PARAMS_IDENTIFIER = /\bsearchParams\b/;
|
|
44
44
|
const TRANSLATIONS_CALL_NO_LOCALE = /\b(?:getTranslations|useTranslations)\s*\(\s*(?:['"][^'"]*['"]|[A-Za-z_$][\w$]*)\s*\)/;
|
|
45
45
|
const SET_LOCALE_CALL = /\bsetLocale(?:Async)?\s*\(/;
|
|
46
|
+
export function hasSetLocaleCall(sourceText) {
|
|
47
|
+
return SET_LOCALE_CALL.test(stripComments(sourceText));
|
|
48
|
+
}
|
|
46
49
|
export const USE_CLIENT_DIRECTIVE = /^(?:\s*['"]use \w[\w-]*['"]\s*;?\s*)*['"]use client['"]\s*;?/;
|
|
47
50
|
const EXPLICIT_DYNAMIC_EXPORT = /export\s+const\s+dynamic\s*=/;
|
|
48
51
|
export function detectDynamicUsage(sourceText, extraChecks = []) {
|
|
@@ -59,7 +62,12 @@ export function detectDynamicUsage(sourceText, extraChecks = []) {
|
|
|
59
62
|
if (found !== null)
|
|
60
63
|
matches.push({ name: 'useAuthUser()', line: lineOf(sourceText, found.index) });
|
|
61
64
|
}
|
|
62
|
-
if (!
|
|
65
|
+
if (!USE_CLIENT_DIRECTIVE.test(sourceText)) {
|
|
66
|
+
const found = SEARCH_PARAMS_IDENTIFIER.exec(code);
|
|
67
|
+
if (found !== null)
|
|
68
|
+
matches.push({ name: 'searchParams', line: lineOf(sourceText, found.index) });
|
|
69
|
+
}
|
|
70
|
+
if (!USE_CLIENT_DIRECTIVE.test(sourceText) && !SET_LOCALE_CALL.test(code)) {
|
|
63
71
|
const found = TRANSLATIONS_CALL_NO_LOCALE.exec(code);
|
|
64
72
|
if (found !== null)
|
|
65
73
|
matches.push({ name: 'getTranslations()/useTranslations() (cookie-derived locale)', line: lineOf(sourceText, found.index) });
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { detectDynamicUsage } from './detect_dynamic_usage.js';
|
|
1
|
+
import { detectDynamicUsage, hasSetLocaleCall } from './detect_dynamic_usage.js';
|
|
2
2
|
import { collectReachableFiles } from './collect_reachable_files.js';
|
|
3
3
|
export function traceDynamicUsage(entryFile, entrySource, aliases, io, extraChecks = []) {
|
|
4
4
|
const files = collectReachableFiles(entryFile, entrySource, aliases, io);
|
|
5
|
+
const entryHasSetLocale = hasSetLocaleCall(entrySource);
|
|
5
6
|
let hasExplicitDynamicExport = false;
|
|
6
7
|
const detectedApis = new Set();
|
|
7
8
|
const signals = [];
|
|
@@ -13,6 +14,9 @@ export function traceDynamicUsage(entryFile, entrySource, aliases, io, extraChec
|
|
|
13
14
|
first = false;
|
|
14
15
|
}
|
|
15
16
|
detection.matches.forEach(({ name, line }) => {
|
|
17
|
+
if (entryHasSetLocale && file !== entryFile && name === 'getTranslations()/useTranslations() (cookie-derived locale)') {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
16
20
|
detectedApis.add(name);
|
|
17
21
|
signals.push({ api: name, file, line });
|
|
18
22
|
});
|