@intlayer/config 8.6.1 → 8.6.2
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/cjs/envVars/envVars.cjs +122 -0
- package/dist/cjs/envVars/envVars.cjs.map +1 -0
- package/dist/cjs/envVars/index.cjs +14 -0
- package/dist/cjs/utils/extractErrorMessage.cjs +12 -4
- package/dist/cjs/utils/extractErrorMessage.cjs.map +1 -1
- package/dist/cjs/utils/getUsedNodeTypes.cjs +56 -0
- package/dist/cjs/utils/getUsedNodeTypes.cjs.map +1 -0
- package/dist/cjs/utils/index.cjs +5 -0
- package/dist/esm/envVars/envVars.mjs +110 -0
- package/dist/esm/envVars/envVars.mjs.map +1 -0
- package/dist/esm/envVars/index.mjs +3 -0
- package/dist/esm/utils/extractErrorMessage.mjs +12 -4
- package/dist/esm/utils/extractErrorMessage.mjs.map +1 -1
- package/dist/esm/utils/getUsedNodeTypes.mjs +51 -0
- package/dist/esm/utils/getUsedNodeTypes.mjs.map +1 -0
- package/dist/esm/utils/index.mjs +2 -1
- package/dist/types/configFile/configurationSchema.d.ts +7 -7
- package/dist/types/envVars/envVars.d.ts +97 -0
- package/dist/types/envVars/envVars.d.ts.map +1 -0
- package/dist/types/envVars/index.d.ts +2 -0
- package/dist/types/utils/getUsedNodeTypes.d.ts +20 -0
- package/dist/types/utils/getUsedNodeTypes.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +2 -1
- package/package.json +10 -2
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/envVars/envVars.ts
|
|
4
|
+
/**
|
|
5
|
+
* True when the build-time routing mode is known and is NOT 'no-prefix'.
|
|
6
|
+
* Use to guard no-prefix-specific code paths so bundlers can eliminate them.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* if (!TREE_SHAKE_NO_PREFIX && mode === 'no-prefix') { ... }
|
|
10
|
+
*/
|
|
11
|
+
const TREE_SHAKE_NO_PREFIX = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "no-prefix";
|
|
12
|
+
/**
|
|
13
|
+
* True when the build-time routing mode is known and is NOT 'search-params'.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* if (!TREE_SHAKE_SEARCH_PARAMS && mode === 'search-params') { ... }
|
|
17
|
+
*/
|
|
18
|
+
const TREE_SHAKE_SEARCH_PARAMS = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params";
|
|
19
|
+
/**
|
|
20
|
+
* True when the build-time routing mode is known and is not a prefix-based
|
|
21
|
+
* mode (neither 'prefix-all' nor 'prefix-no-default').
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* if (!TREE_SHAKE_PREFIX_MODES && (mode === 'prefix-all' || mode === 'prefix-no-default')) { ... }
|
|
25
|
+
*/
|
|
26
|
+
const TREE_SHAKE_PREFIX_MODES = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-all" && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-no-default";
|
|
27
|
+
/**
|
|
28
|
+
* True when rewrite rules are explicitly disabled at build time
|
|
29
|
+
* (INTLAYER_ROUTING_REWRITE_RULES === 'false').
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* if (!TREE_SHAKE_REWRITE && rewrite) { ... }
|
|
33
|
+
*/
|
|
34
|
+
const TREE_SHAKE_REWRITE = process.env["INTLAYER_ROUTING_REWRITE_RULES"] === "false";
|
|
35
|
+
/**
|
|
36
|
+
* True when cookie storage is explicitly disabled at build time.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* if (!TREE_SHAKE_STORAGE_COOKIES) { // cookie logic }
|
|
40
|
+
*/
|
|
41
|
+
const TREE_SHAKE_STORAGE_COOKIES = process.env["INTLAYER_ROUTING_STORAGE_COOKIES"] === "false";
|
|
42
|
+
/**
|
|
43
|
+
* True when localStorage is explicitly disabled at build time.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) { // localStorage logic }
|
|
47
|
+
*/
|
|
48
|
+
const TREE_SHAKE_STORAGE_LOCAL_STORAGE = process.env["INTLAYER_ROUTING_STORAGE_LOCALSTORAGE"] === "false";
|
|
49
|
+
/**
|
|
50
|
+
* True when sessionStorage is explicitly disabled at build time.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* if (!TREE_SHAKE_STORAGE_SESSION_STORAGE) { // sessionStorage logic }
|
|
54
|
+
*/
|
|
55
|
+
const TREE_SHAKE_STORAGE_SESSION_STORAGE = process.env["INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE"] === "false";
|
|
56
|
+
/**
|
|
57
|
+
* True when header storage is explicitly disabled at build time.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* if (!TREE_SHAKE_STORAGE_HEADERS) { // header logic }
|
|
61
|
+
*/
|
|
62
|
+
const TREE_SHAKE_STORAGE_HEADERS = process.env["INTLAYER_ROUTING_STORAGE_HEADERS"] === "false";
|
|
63
|
+
/**
|
|
64
|
+
* True when the editor is explicitly disabled at build time.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* if (!TREE_SHAKE_EDITOR) { // editor logic }
|
|
68
|
+
*/
|
|
69
|
+
const TREE_SHAKE_EDITOR = process.env["INTLAYER_EDITOR_ENABLED"] === "false";
|
|
70
|
+
/**
|
|
71
|
+
* Converts a list of unused NodeType keys into env-var definitions.
|
|
72
|
+
* Set to `"false"` so bundlers can eliminate the corresponding plugin code.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* formatNodeTypeToEnvVar(['enumeration'])
|
|
76
|
+
* // { 'INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
77
|
+
*
|
|
78
|
+
* formatNodeTypeToEnvVar(['enumeration'], true)
|
|
79
|
+
* // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
80
|
+
*/
|
|
81
|
+
const formatNodeTypeToEnvVar = (nodeTypes, addProcessEnv = false) => nodeTypes.reduce((acc, nodeType) => {
|
|
82
|
+
acc[addProcessEnv ? `process.env.INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}` : `INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`] = "\"false\"";
|
|
83
|
+
return acc;
|
|
84
|
+
}, {});
|
|
85
|
+
/**
|
|
86
|
+
* Returns env-var definitions for the full Intlayer config to be injected at
|
|
87
|
+
* build time. Allows bundlers to dead-code-eliminate unused routing modes,
|
|
88
|
+
* rewrite logic, storage mechanisms, and editor code.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* getConfigEnvVars(config)
|
|
92
|
+
* // { INTLAYER_ROUTING_MODE: '"prefix-no-default"', INTLAYER_ROUTING_REWRITE_RULES: '"false"', ... }
|
|
93
|
+
*
|
|
94
|
+
* getConfigEnvVars(config, true)
|
|
95
|
+
* // { 'process.env.INTLAYER_ROUTING_MODE': '"prefix-no-default"', ... }
|
|
96
|
+
*/
|
|
97
|
+
const getConfigEnvVars = (config, addProcessEnv = false) => {
|
|
98
|
+
const prefix = addProcessEnv ? "process.env." : "";
|
|
99
|
+
const { routing, editor } = config;
|
|
100
|
+
const envVars = { [`${prefix}INTLAYER_ROUTING_MODE`]: JSON.stringify(routing.mode) };
|
|
101
|
+
if (!routing.rewrite) envVars[`${prefix}INTLAYER_ROUTING_REWRITE_RULES`] = "\"false\"";
|
|
102
|
+
if (routing.storage.cookies.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_COOKIES`] = "\"false\"";
|
|
103
|
+
if (routing.storage.localStorage.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_LOCALSTORAGE`] = "\"false\"";
|
|
104
|
+
if (routing.storage.sessionStorage.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE`] = "\"false\"";
|
|
105
|
+
if (routing.storage.headers.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_HEADERS`] = "\"false\"";
|
|
106
|
+
if (editor?.enabled === false) envVars[`${prefix}INTLAYER_EDITOR_ENABLED`] = "\"false\"";
|
|
107
|
+
return envVars;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
exports.TREE_SHAKE_EDITOR = TREE_SHAKE_EDITOR;
|
|
112
|
+
exports.TREE_SHAKE_NO_PREFIX = TREE_SHAKE_NO_PREFIX;
|
|
113
|
+
exports.TREE_SHAKE_PREFIX_MODES = TREE_SHAKE_PREFIX_MODES;
|
|
114
|
+
exports.TREE_SHAKE_REWRITE = TREE_SHAKE_REWRITE;
|
|
115
|
+
exports.TREE_SHAKE_SEARCH_PARAMS = TREE_SHAKE_SEARCH_PARAMS;
|
|
116
|
+
exports.TREE_SHAKE_STORAGE_COOKIES = TREE_SHAKE_STORAGE_COOKIES;
|
|
117
|
+
exports.TREE_SHAKE_STORAGE_HEADERS = TREE_SHAKE_STORAGE_HEADERS;
|
|
118
|
+
exports.TREE_SHAKE_STORAGE_LOCAL_STORAGE = TREE_SHAKE_STORAGE_LOCAL_STORAGE;
|
|
119
|
+
exports.TREE_SHAKE_STORAGE_SESSION_STORAGE = TREE_SHAKE_STORAGE_SESSION_STORAGE;
|
|
120
|
+
exports.formatNodeTypeToEnvVar = formatNodeTypeToEnvVar;
|
|
121
|
+
exports.getConfigEnvVars = getConfigEnvVars;
|
|
122
|
+
//# sourceMappingURL=envVars.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envVars.cjs","names":[],"sources":["../../../src/envVars/envVars.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when the build-time routing mode is known and is NOT 'no-prefix'.\n * Use to guard no-prefix-specific code paths so bundlers can eliminate them.\n *\n * @example\n * if (!TREE_SHAKE_NO_PREFIX && mode === 'no-prefix') { ... }\n */\nexport const TREE_SHAKE_NO_PREFIX =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'no-prefix';\n\n/**\n * True when the build-time routing mode is known and is NOT 'search-params'.\n *\n * @example\n * if (!TREE_SHAKE_SEARCH_PARAMS && mode === 'search-params') { ... }\n */\nexport const TREE_SHAKE_SEARCH_PARAMS =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'search-params';\n\n/**\n * True when the build-time routing mode is known and is not a prefix-based\n * mode (neither 'prefix-all' nor 'prefix-no-default').\n *\n * @example\n * if (!TREE_SHAKE_PREFIX_MODES && (mode === 'prefix-all' || mode === 'prefix-no-default')) { ... }\n */\nexport const TREE_SHAKE_PREFIX_MODES =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'prefix-all' &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'prefix-no-default';\n\n/**\n * True when rewrite rules are explicitly disabled at build time\n * (INTLAYER_ROUTING_REWRITE_RULES === 'false').\n *\n * @example\n * if (!TREE_SHAKE_REWRITE && rewrite) { ... }\n */\nexport const TREE_SHAKE_REWRITE =\n process.env['INTLAYER_ROUTING_REWRITE_RULES'] === 'false';\n\n// ── Storage tree-shake constants ──────────────────────────────────────────────\n\n/**\n * True when cookie storage is explicitly disabled at build time.\n *\n * @example\n * if (!TREE_SHAKE_STORAGE_COOKIES) { // cookie logic }\n */\nexport const TREE_SHAKE_STORAGE_COOKIES =\n process.env['INTLAYER_ROUTING_STORAGE_COOKIES'] === 'false';\n\n/**\n * True when localStorage is explicitly disabled at build time.\n *\n * @example\n * if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) { // localStorage logic }\n */\nexport const TREE_SHAKE_STORAGE_LOCAL_STORAGE =\n process.env['INTLAYER_ROUTING_STORAGE_LOCALSTORAGE'] === 'false';\n\n/**\n * True when sessionStorage is explicitly disabled at build time.\n *\n * @example\n * if (!TREE_SHAKE_STORAGE_SESSION_STORAGE) { // sessionStorage logic }\n */\nexport const TREE_SHAKE_STORAGE_SESSION_STORAGE =\n process.env['INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE'] === 'false';\n\n/**\n * True when header storage is explicitly disabled at build time.\n *\n * @example\n * if (!TREE_SHAKE_STORAGE_HEADERS) { // header logic }\n */\nexport const TREE_SHAKE_STORAGE_HEADERS =\n process.env['INTLAYER_ROUTING_STORAGE_HEADERS'] === 'false';\n\n/**\n * True when the editor is explicitly disabled at build time.\n *\n * @example\n * if (!TREE_SHAKE_EDITOR) { // editor logic }\n */\nexport const TREE_SHAKE_EDITOR =\n process.env['INTLAYER_EDITOR_ENABLED'] === 'false';\n\n// ── Build-time env-var helpers ────────────────────────────────────────────────\n\n/**\n * Converts a list of unused NodeType keys into env-var definitions.\n * Set to `\"false\"` so bundlers can eliminate the corresponding plugin code.\n *\n * @example\n * formatNodeTypeToEnvVar(['enumeration'])\n * // { 'INTLAYER_NODE_TYPE_ENUMERATION': '\"false\"' }\n *\n * formatNodeTypeToEnvVar(['enumeration'], true)\n * // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '\"false\"' }\n */\nexport const formatNodeTypeToEnvVar = (\n nodeTypes: string[],\n addProcessEnv: boolean = false\n): Record<string, string> =>\n nodeTypes.reduce(\n (acc, nodeType) => {\n acc[\n addProcessEnv\n ? `process.env.INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`\n : `INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`\n ] = '\"false\"';\n return acc;\n },\n {} as Record<string, string>\n );\n\n/**\n * Returns env-var definitions for the full Intlayer config to be injected at\n * build time. Allows bundlers to dead-code-eliminate unused routing modes,\n * rewrite logic, storage mechanisms, and editor code.\n *\n * @example\n * getConfigEnvVars(config)\n * // { INTLAYER_ROUTING_MODE: '\"prefix-no-default\"', INTLAYER_ROUTING_REWRITE_RULES: '\"false\"', ... }\n *\n * getConfigEnvVars(config, true)\n * // { 'process.env.INTLAYER_ROUTING_MODE': '\"prefix-no-default\"', ... }\n */\nexport const getConfigEnvVars = (\n config: IntlayerConfig,\n addProcessEnv: boolean = false\n): Record<string, string> => {\n const prefix = addProcessEnv ? 'process.env.' : '';\n const { routing, editor } = config;\n\n const envVars: Record<string, string> = {\n [`${prefix}INTLAYER_ROUTING_MODE`]: JSON.stringify(routing.mode),\n };\n\n if (!routing.rewrite) {\n envVars[`${prefix}INTLAYER_ROUTING_REWRITE_RULES`] = '\"false\"';\n }\n\n if (routing.storage.cookies.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_COOKIES`] = '\"false\"';\n }\n\n if (routing.storage.localStorage.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_LOCALSTORAGE`] = '\"false\"';\n }\n\n if (routing.storage.sessionStorage.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE`] = '\"false\"';\n }\n\n if (routing.storage.headers.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_HEADERS`] = '\"false\"';\n }\n\n if (editor?.enabled === false) {\n envVars[`${prefix}INTLAYER_EDITOR_ENABLED`] = '\"false\"';\n }\n\n return envVars;\n};\n"],"mappings":";;;;;;;;;;AAaA,MAAa,uBACX,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B;;;;;;;AAQ3C,MAAa,2BACX,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B;;;;;;;;AAS3C,MAAa,0BACX,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B,gBACzC,QAAQ,IAAI,6BAA6B;;;;;;;;AAS3C,MAAa,qBACX,QAAQ,IAAI,sCA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AKE_EDITOR;
|
|
5
|
+
exports.TREE_SHAKE_NO_PREFIX = require_envVars_envVars.TREE_SHAKE_NO_PREFIX;
|
|
6
|
+
exports.TREE_SHAKE_PREFIX_MODES = require_envVars_envVars.TREE_SHAKE_PREFIX_MODES;
|
|
7
|
+
exports.TREE_SHAKE_REWRITE = require_envVars_envVars.TREE_SHAKE_REWRITE;
|
|
8
|
+
exports.TREE_SHAKE_SEARCH_PARAMS = require_envVars_envVars.TREE_SHAKE_SEARCH_PARAMS;
|
|
9
|
+
exports.TREE_SHAKE_STORAGE_COOKIES = require_envVars_envVars.TREE_SHAKE_STORAGE_COOKIES;
|
|
10
|
+
exports.TREE_SHAKE_STORAGE_HEADERS = require_envVars_envVars.TREE_SHAKE_STORAGE_HEADERS;
|
|
11
|
+
exports.TREE_SHAKE_STORAGE_LOCAL_STORAGE = require_envVars_envVars.TREE_SHAKE_STORAGE_LOCAL_STORAGE;
|
|
12
|
+
exports.TREE_SHAKE_STORAGE_SESSION_STORAGE = require_envVars_envVars.TREE_SHAKE_STORAGE_SESSION_STORAGE;
|
|
13
|
+
exports.formatNodeTypeToEnvVar = require_envVars_envVars.formatNodeTypeToEnvVar;
|
|
14
|
+
exports.getConfigEnvVars = require_envVars_envVars.getConfigEnvVars;
|
|
@@ -2,11 +2,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
//#region src/utils/extractErrorMessage.ts
|
|
4
4
|
const extractErrorMessage = (error) => {
|
|
5
|
-
const trimToSingleLine = (text) => text.split(/\r?\n/).map((
|
|
5
|
+
const trimToSingleLine = (text) => text.split(/\r?\n/).map((stringValue) => stringValue.trim()).filter(Boolean)[0] ?? text.trim();
|
|
6
6
|
const looksLikeJson = (value) => {
|
|
7
|
-
const
|
|
8
|
-
if (!
|
|
9
|
-
const first =
|
|
7
|
+
const stringValue = value.trim();
|
|
8
|
+
if (!stringValue) return false;
|
|
9
|
+
const first = stringValue[0];
|
|
10
10
|
return first === "{" || first === "[" || first === "\"";
|
|
11
11
|
};
|
|
12
12
|
const sanitizeUnexpectedTokenMessage = (text) => {
|
|
@@ -23,6 +23,14 @@ const extractErrorMessage = (error) => {
|
|
|
23
23
|
if (!value || typeof value !== "object") return void 0;
|
|
24
24
|
if (seen.has(value)) return void 0;
|
|
25
25
|
seen.add(value);
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
for (const item of value) {
|
|
28
|
+
const fromItem = pickFieldsFromObject(item, seen);
|
|
29
|
+
if (fromItem) return fromItem;
|
|
30
|
+
if (typeof item?.message === "string") return item.message;
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
26
34
|
const obj = value;
|
|
27
35
|
if (typeof obj.message === "string" && obj.message.trim()) return obj.message;
|
|
28
36
|
if (typeof obj.error_description === "string" && obj.error_description.trim()) return obj.error_description;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractErrorMessage.cjs","names":[],"sources":["../../../src/utils/extractErrorMessage.ts"],"sourcesContent":["export const extractErrorMessage = (error: unknown): string => {\n const trimToSingleLine = (text: string): string =>\n text\n .split(/\\r?\\n/)\n .map((
|
|
1
|
+
{"version":3,"file":"extractErrorMessage.cjs","names":[],"sources":["../../../src/utils/extractErrorMessage.ts"],"sourcesContent":["export const extractErrorMessage = (error: unknown): string => {\n const trimToSingleLine = (text: string): string =>\n text\n .split(/\\r?\\n/)\n .map((stringValue) => stringValue.trim())\n .filter(Boolean)[0] ?? text.trim();\n\n const looksLikeJson = (value: string): boolean => {\n const stringValue = value.trim();\n\n if (!stringValue) return false;\n const first = stringValue[0];\n return first === '{' || first === '[' || first === '\"';\n };\n\n const sanitizeUnexpectedTokenMessage = (text: string): string => {\n // If the text mentions an invalid JSON parse, try to extract the meaningful part\n const t = text.trim();\n\n if (/Unexpected token/i.test(t) && /not valid JSON/i.test(t)) {\n const quoted = t.match(/\"([^\"]+)\"/);\n\n if (quoted?.[1]) return quoted[1];\n // Fallback: drop the leading parser error description\n const afterColon = t.split(':').slice(1).join(':').trim();\n\n if (afterColon) return afterColon;\n }\n return t;\n };\n\n const pickFieldsFromObject = (\n value: unknown,\n seen: Set<unknown>\n ): string | undefined => {\n if (!value || typeof value !== 'object') return undefined;\n\n if (seen.has(value)) return undefined;\n\n seen.add(value);\n\n // If the value itself is an array (e.g. ZodError.issues), iterate its items\n\n if (Array.isArray(value)) {\n for (const item of value) {\n const fromItem = pickFieldsFromObject(item, seen);\n\n if (fromItem) return fromItem;\n\n if (typeof (item as any)?.message === 'string')\n return (item as any).message;\n }\n return undefined;\n }\n\n const obj = value as Record<string, unknown>;\n\n // Check for message first (highest priority)\n\n if (typeof obj.message === 'string' && obj.message.trim()) {\n return obj.message;\n }\n\n // Check for error_description\n\n if (\n typeof obj.error_description === 'string' &&\n obj.error_description.trim()\n ) {\n return obj.error_description;\n }\n\n // Check for error\n\n if (typeof obj.error === 'string' && obj.error.trim()) {\n return obj.error;\n }\n\n // Handle title and code combination\n const title = typeof obj.title === 'string' ? obj.title.trim() : '';\n const code = typeof obj.code === 'string' ? obj.code.trim() : '';\n\n if (title && code) {\n return `${title} (${code})`;\n }\n\n if (title) {\n return title;\n }\n\n if (code) {\n return code;\n }\n\n // Check for statusText\n\n if (typeof obj.statusText === 'string' && obj.statusText.trim()) {\n return obj.statusText;\n }\n\n // Common nested structures (Axios/Fetch-like)\n const response = obj.response as Record<string, unknown> | undefined;\n\n if (response && typeof response === 'object') {\n const data = response.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n\n if (fromData) return fromData;\n }\n\n const data = obj.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n\n if (fromData) return fromData;\n\n // Nested cause chain\n const cause = (obj as { cause?: unknown }).cause;\n const fromCause =\n pickFieldsFromObject(cause, seen) ??\n (typeof (cause as any)?.message === 'string'\n ? (cause as any).message\n : undefined);\n\n if (fromCause) return fromCause;\n\n // Arrays of errors\n const errors = obj.errors as unknown;\n\n if (Array.isArray(errors)) {\n for (const item of errors) {\n const fromItem = pickFieldsFromObject(item, seen);\n\n if (fromItem) return fromItem;\n\n if (typeof (item as any)?.message === 'string')\n return (item as any).message;\n }\n }\n\n return undefined;\n };\n\n const tryParseJsonString = (maybeJson: string): string | undefined => {\n if (!looksLikeJson(maybeJson)) return undefined;\n try {\n const parsed = JSON.parse(maybeJson);\n const picked = pickFieldsFromObject(parsed, new Set());\n\n if (picked) return picked;\n\n if (typeof parsed === 'string') return parsed;\n return undefined;\n } catch {\n return undefined;\n }\n };\n\n if (typeof error === 'string') {\n const cleaned = sanitizeUnexpectedTokenMessage(error);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n if (error && typeof error === 'object') {\n // Native Error instance\n\n if (error instanceof Error) {\n const cleaned = sanitizeUnexpectedTokenMessage(error.message);\n const fromMessage = tryParseJsonString(cleaned);\n\n if (fromMessage) return trimToSingleLine(fromMessage);\n // Dive into cause when present\n const fromCause = extractErrorMessage(error.cause as unknown);\n\n if (fromCause && fromCause !== 'An unknown error occurred')\n return trimToSingleLine(fromCause);\n return trimToSingleLine(cleaned);\n }\n\n // Generic object\n const seen = new Set<unknown>();\n const fromObject = pickFieldsFromObject(error, seen);\n\n if (fromObject) {\n const cleaned = sanitizeUnexpectedTokenMessage(fromObject);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n try {\n const serialized = JSON.stringify(error);\n return trimToSingleLine(serialized);\n } catch {\n return trimToSingleLine(String(error));\n }\n }\n\n return 'An unknown error occurred';\n};\n"],"mappings":";;;AAAA,MAAa,uBAAuB,UAA2B;CAC7D,MAAM,oBAAoB,SACxB,KACG,MAAM,QAAQ,CACd,KAAK,gBAAgB,YAAY,MAAM,CAAC,CACxC,OAAO,QAAQ,CAAC,MAAM,KAAK,MAAM;CAEtC,MAAM,iBAAiB,UAA2B;EAChD,MAAM,cAAc,MAAM,MAAM;AAEhC,MAAI,CAAC,YAAa,QAAO;EACzB,MAAM,QAAQ,YA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,QAAO,iBAAiB,UAAU;AACpC,UAAO,iBAAiB,QAAQ;;EAKlC,MAAM,aAAa,qBAAqB,uBAD3B,IAAI,KAAc,CACqB;AAEpD,MAAI,YAAY;GACd,MAAM,UAAU,+BAA+B,WAAW;AAC1D,UAAO,mBAAmB,QAAQ,IAAI,iBAAiB,QAAQ;;AAGjE,MAAI;AAEF,UAAO,iBADY,KAAK,UAAU,MAAM,CACL;UAC7B;AACN,UAAO,iBAAiB,OAAO,MAAM,CAAC;;;AAI1C,QAAO"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
|
|
4
|
+
|
|
5
|
+
//#region src/utils/getUsedNodeTypes.ts
|
|
6
|
+
/** Recursively collect every `nodeType` string found in a value. */
|
|
7
|
+
const collectNodeTypes = (value, result) => {
|
|
8
|
+
if (!value || typeof value !== "object") return;
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
for (const item of value) collectNodeTypes(item, result);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const obj = value;
|
|
14
|
+
if (typeof obj.nodeType === "string") result.add(obj.nodeType);
|
|
15
|
+
for (const key of Object.keys(obj)) collectNodeTypes(obj[key], result);
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Returns the set of NodeType strings actually used across the given
|
|
19
|
+
* built dictionaries.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const used = getUsedNodeTypes(getDictionaries(config));
|
|
23
|
+
* // Set { 'translation', 'enumeration' }
|
|
24
|
+
*/
|
|
25
|
+
const getUsedNodeTypes = (dictionaries) => {
|
|
26
|
+
const result = /* @__PURE__ */ new Set();
|
|
27
|
+
const dicts = Array.isArray(dictionaries) ? dictionaries : Object.values(dictionaries);
|
|
28
|
+
for (const dict of dicts) collectNodeTypes(dict.content, result);
|
|
29
|
+
return [...result];
|
|
30
|
+
};
|
|
31
|
+
const getUnusedNodeTypes = (dictionaries) => {
|
|
32
|
+
const usedNodeTypes = getUsedNodeTypes(dictionaries);
|
|
33
|
+
return _intlayer_types_nodeType.PLUGIN_NODE_TYPES.filter((nodeType) => !usedNodeTypes.includes(nodeType));
|
|
34
|
+
};
|
|
35
|
+
const getUsedNodeTypesAsync = async (dictionaries) => {
|
|
36
|
+
const dictionariesArray = Array.isArray(dictionaries) ? dictionaries : Object.values(dictionaries);
|
|
37
|
+
const results = await Promise.all(dictionariesArray.map(async (dictionary) => {
|
|
38
|
+
const result = /* @__PURE__ */ new Set();
|
|
39
|
+
collectNodeTypes(dictionary.content, result);
|
|
40
|
+
return result;
|
|
41
|
+
}));
|
|
42
|
+
const finalResult = /* @__PURE__ */ new Set();
|
|
43
|
+
for (const res of results) for (const val of res) finalResult.add(val);
|
|
44
|
+
return [...finalResult];
|
|
45
|
+
};
|
|
46
|
+
const getUnusedNodeTypesAsync = async (dictionaries) => {
|
|
47
|
+
const usedNodeTypes = await getUsedNodeTypesAsync(dictionaries);
|
|
48
|
+
return _intlayer_types_nodeType.PLUGIN_NODE_TYPES.filter((nodeType) => !usedNodeTypes.includes(nodeType));
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
exports.getUnusedNodeTypes = getUnusedNodeTypes;
|
|
53
|
+
exports.getUnusedNodeTypesAsync = getUnusedNodeTypesAsync;
|
|
54
|
+
exports.getUsedNodeTypes = getUsedNodeTypes;
|
|
55
|
+
exports.getUsedNodeTypesAsync = getUsedNodeTypesAsync;
|
|
56
|
+
//# sourceMappingURL=getUsedNodeTypes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUsedNodeTypes.cjs","names":["PLUGIN_NODE_TYPES"],"sources":["../../../src/utils/getUsedNodeTypes.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport { PLUGIN_NODE_TYPES } from '@intlayer/types/nodeType';\n\nexport type PluginNodeType = (typeof PLUGIN_NODE_TYPES)[number];\n\n/** Recursively collect every `nodeType` string found in a value. */\nconst collectNodeTypes = (value: unknown, result: Set<string>): void => {\n if (!value || typeof value !== 'object') return;\n\n if (Array.isArray(value)) {\n for (const item of value) collectNodeTypes(item, result);\n return;\n }\n\n const obj = value as Record<string, unknown>;\n\n if (typeof obj.nodeType === 'string') {\n result.add(obj.nodeType);\n }\n\n for (const key of Object.keys(obj)) {\n collectNodeTypes(obj[key], result);\n }\n};\n\n/**\n * Returns the set of NodeType strings actually used across the given\n * built dictionaries.\n *\n * @example\n * const used = getUsedNodeTypes(getDictionaries(config));\n * // Set { 'translation', 'enumeration' }\n */\nexport const getUsedNodeTypes = (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): PluginNodeType[] => {\n const result = new Set<PluginNodeType>();\n const dicts = Array.isArray(dictionaries)\n ? dictionaries\n : Object.values(dictionaries);\n\n for (const dict of dicts) {\n collectNodeTypes(dict.content, result);\n }\n\n return [...result];\n};\n\nexport const getUnusedNodeTypes = (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): PluginNodeType[] => {\n const usedNodeTypes = getUsedNodeTypes(dictionaries);\n\n return PLUGIN_NODE_TYPES.filter(\n (nodeType) => !usedNodeTypes.includes(nodeType)\n );\n};\n\nexport const getUsedNodeTypesAsync = async (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): Promise<PluginNodeType[]> => {\n const dictionariesArray = Array.isArray(dictionaries)\n ? dictionaries\n : Object.values(dictionaries);\n\n const results = await Promise.all(\n dictionariesArray.map(async (dictionary) => {\n const result = new Set<PluginNodeType>();\n\n collectNodeTypes(dictionary.content, result as Set<string>);\n\n return result;\n })\n );\n\n const finalResult = new Set<PluginNodeType>();\n\n for (const res of results) {\n for (const val of res) {\n finalResult.add(val);\n }\n }\n\n return [...finalResult];\n};\n\nexport const getUnusedNodeTypesAsync = async (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): Promise<PluginNodeType[]> => {\n const usedNodeTypes = await getUsedNodeTypesAsync(dictionaries);\n\n return PLUGIN_NODE_TYPES.filter(\n (nodeType) => !usedNodeTypes.includes(nodeType)\n );\n};\n"],"mappings":";;;;;;AAMA,MAAM,oBAAoB,OAAgB,WAA8B;AACtE,KAAI,CAAC,SAAS,OAAO,UAAU,SAAU;AAEzC,KAAI,MAAM,QAAQ,MAAM,EAAE;AACxB,OAAK,MAAM,QAAQ,MAAO,kBAAiB,MAAM,OAAO;AACxD;;CAGF,MAAM,MAAM;AAEZ,KAAI,OAAO,IAAI,aAAa,SAC1B,QAAO,IAAI,IAAI,SAAS;AAG1B,MAAK,MAAM,OAAO,OAAO,KAAK,IAAI,CAChC,kBAAiB,IAAI,MAAM,OAAO;;;;;;;;;;AAYtC,MAAa,oBACX,iBACqB;CACrB,MAAM,yBAAS,IAAI,KAAqB;CACxC,MAAM,QAAQ,MAAM,QAAQ,aAAa,GACrC,eACA,OAAO,OAAO,aAAa;AAE/B,MAAK,MAAM,QAAQ,MACjB,kBAAiB,KAAK,SAAS,OAAO;AAGxC,QAAO,CAAC,GAAG,OAAO;;AAGpB,MAAa,sBACX,iBACqB;CACrB,MAAM,gBAAgB,iBAAiB,aAAa;AAEpD,QAAOA,2CAAkB,QACtB,aAAa,CAAC,cAAc,SAAS,SAAS,CAChD;;AAGH,MAAa,wBAAwB,OACnC,iBAC8B;CAC9B,MAAM,oBAAoB,MAAM,QAAQ,aAAa,GACjD,eACA,OAAO,OAAO,aAAa;CAE/B,MAAM,UAAU,MAAM,QAAQ,IAC5B,kBAAkB,IAAI,OAAO,eAAe;EAC1C,MAAM,yBAAS,IAAI,KAAqB;AAExC,mBAAiB,WAAW,SAAS,OAAsB;AAE3D,SAAO;GACP,CACH;CAED,MAAM,8BAAc,IAAI,KAAqB;AAE7C,MAAK,MAAM,OAAO,QAChB,MAAK,MAAM,OAAO,IAChB,aAAY,IAAI,IAAI;AAIxB,QAAO,CAAC,GAAG,YAAY;;AAGzB,MAAa,0BAA0B,OACrC,iBAC8B;CAC9B,MAAM,gBAAgB,MAAM,sBAAsB,aAAa;AAE/D,QAAOA,2CAAkB,QACtB,aAAa,CAAC,cAAc,SAAS,SAAS,CAChD"}
|
package/dist/cjs/utils/index.cjs
CHANGED
|
@@ -10,6 +10,7 @@ const require_utils_clearModuleCache = require('./clearModuleCache.cjs');
|
|
|
10
10
|
const require_utils_compareVersions = require('./compareVersions.cjs');
|
|
11
11
|
const require_utils_extractErrorMessage = require('./extractErrorMessage.cjs');
|
|
12
12
|
const require_utils_getStorageAttributes = require('./getStorageAttributes.cjs');
|
|
13
|
+
const require_utils_getUsedNodeTypes = require('./getUsedNodeTypes.cjs');
|
|
13
14
|
const require_utils_logStack = require('./logStack.cjs');
|
|
14
15
|
const require_utils_parseFilePathPattern = require('./parseFilePathPattern.cjs');
|
|
15
16
|
const require_utils_retryManager = require('./retryManager.cjs');
|
|
@@ -36,6 +37,10 @@ exports.getExtension = require_utils_getExtension.getExtension;
|
|
|
36
37
|
exports.getPackageJsonPath = require_utils_getPackageJsonPath.getPackageJsonPath;
|
|
37
38
|
exports.getProjectRequire = require_utils_ESMxCJSHelpers.getProjectRequire;
|
|
38
39
|
exports.getStorageAttributes = require_utils_getStorageAttributes.getStorageAttributes;
|
|
40
|
+
exports.getUnusedNodeTypes = require_utils_getUsedNodeTypes.getUnusedNodeTypes;
|
|
41
|
+
exports.getUnusedNodeTypesAsync = require_utils_getUsedNodeTypes.getUnusedNodeTypesAsync;
|
|
42
|
+
exports.getUsedNodeTypes = require_utils_getUsedNodeTypes.getUsedNodeTypes;
|
|
43
|
+
exports.getUsedNodeTypesAsync = require_utils_getUsedNodeTypes.getUsedNodeTypesAsync;
|
|
39
44
|
exports.isESModule = require_utils_ESMxCJSHelpers.isESModule;
|
|
40
45
|
exports.kebabCaseToCamelCase = require_utils_stringFormatter_kebabCaseToCamelCase.kebabCaseToCamelCase;
|
|
41
46
|
exports.logStack = require_utils_logStack.logStack;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
//#region src/envVars/envVars.ts
|
|
2
|
+
/**
|
|
3
|
+
* True when the build-time routing mode is known and is NOT 'no-prefix'.
|
|
4
|
+
* Use to guard no-prefix-specific code paths so bundlers can eliminate them.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* if (!TREE_SHAKE_NO_PREFIX && mode === 'no-prefix') { ... }
|
|
8
|
+
*/
|
|
9
|
+
const TREE_SHAKE_NO_PREFIX = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "no-prefix";
|
|
10
|
+
/**
|
|
11
|
+
* True when the build-time routing mode is known and is NOT 'search-params'.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* if (!TREE_SHAKE_SEARCH_PARAMS && mode === 'search-params') { ... }
|
|
15
|
+
*/
|
|
16
|
+
const TREE_SHAKE_SEARCH_PARAMS = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params";
|
|
17
|
+
/**
|
|
18
|
+
* True when the build-time routing mode is known and is not a prefix-based
|
|
19
|
+
* mode (neither 'prefix-all' nor 'prefix-no-default').
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* if (!TREE_SHAKE_PREFIX_MODES && (mode === 'prefix-all' || mode === 'prefix-no-default')) { ... }
|
|
23
|
+
*/
|
|
24
|
+
const TREE_SHAKE_PREFIX_MODES = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-all" && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-no-default";
|
|
25
|
+
/**
|
|
26
|
+
* True when rewrite rules are explicitly disabled at build time
|
|
27
|
+
* (INTLAYER_ROUTING_REWRITE_RULES === 'false').
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* if (!TREE_SHAKE_REWRITE && rewrite) { ... }
|
|
31
|
+
*/
|
|
32
|
+
const TREE_SHAKE_REWRITE = process.env["INTLAYER_ROUTING_REWRITE_RULES"] === "false";
|
|
33
|
+
/**
|
|
34
|
+
* True when cookie storage is explicitly disabled at build time.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* if (!TREE_SHAKE_STORAGE_COOKIES) { // cookie logic }
|
|
38
|
+
*/
|
|
39
|
+
const TREE_SHAKE_STORAGE_COOKIES = process.env["INTLAYER_ROUTING_STORAGE_COOKIES"] === "false";
|
|
40
|
+
/**
|
|
41
|
+
* True when localStorage is explicitly disabled at build time.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) { // localStorage logic }
|
|
45
|
+
*/
|
|
46
|
+
const TREE_SHAKE_STORAGE_LOCAL_STORAGE = process.env["INTLAYER_ROUTING_STORAGE_LOCALSTORAGE"] === "false";
|
|
47
|
+
/**
|
|
48
|
+
* True when sessionStorage is explicitly disabled at build time.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* if (!TREE_SHAKE_STORAGE_SESSION_STORAGE) { // sessionStorage logic }
|
|
52
|
+
*/
|
|
53
|
+
const TREE_SHAKE_STORAGE_SESSION_STORAGE = process.env["INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE"] === "false";
|
|
54
|
+
/**
|
|
55
|
+
* True when header storage is explicitly disabled at build time.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* if (!TREE_SHAKE_STORAGE_HEADERS) { // header logic }
|
|
59
|
+
*/
|
|
60
|
+
const TREE_SHAKE_STORAGE_HEADERS = process.env["INTLAYER_ROUTING_STORAGE_HEADERS"] === "false";
|
|
61
|
+
/**
|
|
62
|
+
* True when the editor is explicitly disabled at build time.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* if (!TREE_SHAKE_EDITOR) { // editor logic }
|
|
66
|
+
*/
|
|
67
|
+
const TREE_SHAKE_EDITOR = process.env["INTLAYER_EDITOR_ENABLED"] === "false";
|
|
68
|
+
/**
|
|
69
|
+
* Converts a list of unused NodeType keys into env-var definitions.
|
|
70
|
+
* Set to `"false"` so bundlers can eliminate the corresponding plugin code.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* formatNodeTypeToEnvVar(['enumeration'])
|
|
74
|
+
* // { 'INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
75
|
+
*
|
|
76
|
+
* formatNodeTypeToEnvVar(['enumeration'], true)
|
|
77
|
+
* // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
78
|
+
*/
|
|
79
|
+
const formatNodeTypeToEnvVar = (nodeTypes, addProcessEnv = false) => nodeTypes.reduce((acc, nodeType) => {
|
|
80
|
+
acc[addProcessEnv ? `process.env.INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}` : `INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`] = "\"false\"";
|
|
81
|
+
return acc;
|
|
82
|
+
}, {});
|
|
83
|
+
/**
|
|
84
|
+
* Returns env-var definitions for the full Intlayer config to be injected at
|
|
85
|
+
* build time. Allows bundlers to dead-code-eliminate unused routing modes,
|
|
86
|
+
* rewrite logic, storage mechanisms, and editor code.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* getConfigEnvVars(config)
|
|
90
|
+
* // { INTLAYER_ROUTING_MODE: '"prefix-no-default"', INTLAYER_ROUTING_REWRITE_RULES: '"false"', ... }
|
|
91
|
+
*
|
|
92
|
+
* getConfigEnvVars(config, true)
|
|
93
|
+
* // { 'process.env.INTLAYER_ROUTING_MODE': '"prefix-no-default"', ... }
|
|
94
|
+
*/
|
|
95
|
+
const getConfigEnvVars = (config, addProcessEnv = false) => {
|
|
96
|
+
const prefix = addProcessEnv ? "process.env." : "";
|
|
97
|
+
const { routing, editor } = config;
|
|
98
|
+
const envVars = { [`${prefix}INTLAYER_ROUTING_MODE`]: JSON.stringify(routing.mode) };
|
|
99
|
+
if (!routing.rewrite) envVars[`${prefix}INTLAYER_ROUTING_REWRITE_RULES`] = "\"false\"";
|
|
100
|
+
if (routing.storage.cookies.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_COOKIES`] = "\"false\"";
|
|
101
|
+
if (routing.storage.localStorage.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_LOCALSTORAGE`] = "\"false\"";
|
|
102
|
+
if (routing.storage.sessionStorage.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE`] = "\"false\"";
|
|
103
|
+
if (routing.storage.headers.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_HEADERS`] = "\"false\"";
|
|
104
|
+
if (editor?.enabled === false) envVars[`${prefix}INTLAYER_EDITOR_ENABLED`] = "\"false\"";
|
|
105
|
+
return envVars;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
export { TREE_SHAKE_EDITOR, TREE_SHAKE_NO_PREFIX, TREE_SHAKE_PREFIX_MODES, TREE_SHAKE_REWRITE, TREE_SHAKE_SEARCH_PARAMS, TREE_SHAKE_STORAGE_COOKIES, TREE_SHAKE_STORAGE_HEADERS, TREE_SHAKE_STORAGE_LOCAL_STORAGE, TREE_SHAKE_STORAGE_SESSION_STORAGE, formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
110
|
+
//# sourceMappingURL=envVars.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envVars.mjs","names":[],"sources":["../../../src/envVars/envVars.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when the build-time routing mode is known and is NOT 'no-prefix'.\n * Use to guard no-prefix-specific code paths so bundlers can eliminate them.\n *\n * @example\n * if (!TREE_SHAKE_NO_PREFIX && mode === 'no-prefix') { ... }\n */\nexport const TREE_SHAKE_NO_PREFIX =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'no-prefix';\n\n/**\n * True when the build-time routing mode is known and is NOT 'search-params'.\n *\n * @example\n * if (!TREE_SHAKE_SEARCH_PARAMS && mode === 'search-params') { ... }\n */\nexport const TREE_SHAKE_SEARCH_PARAMS =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'search-params';\n\n/**\n * True when the build-time routing mode is known and is not a prefix-based\n * mode (neither 'prefix-all' nor 'prefix-no-default').\n *\n * @example\n * if (!TREE_SHAKE_PREFIX_MODES && (mode === 'prefix-all' || mode === 'prefix-no-default')) { ... }\n */\nexport const TREE_SHAKE_PREFIX_MODES =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'prefix-all' &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'prefix-no-default';\n\n/**\n * True when rewrite rules are explicitly disabled at build time\n * (INTLAYER_ROUTING_REWRITE_RULES === 'false').\n *\n * @example\n * if (!TREE_SHAKE_REWRITE && rewrite) { ... }\n */\nexport const TREE_SHAKE_REWRITE =\n process.env['INTLAYER_ROUTING_REWRITE_RULES'] === 'false';\n\n// ── Storage tree-shake constants ──────────────────────────────────────────────\n\n/**\n * True when cookie storage is explicitly disabled at build time.\n *\n * @example\n * if (!TREE_SHAKE_STORAGE_COOKIES) { // cookie logic }\n */\nexport const TREE_SHAKE_STORAGE_COOKIES =\n process.env['INTLAYER_ROUTING_STORAGE_COOKIES'] === 'false';\n\n/**\n * True when localStorage is explicitly disabled at build time.\n *\n * @example\n * if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) { // localStorage logic }\n */\nexport const TREE_SHAKE_STORAGE_LOCAL_STORAGE =\n process.env['INTLAYER_ROUTING_STORAGE_LOCALSTORAGE'] === 'false';\n\n/**\n * True when sessionStorage is explicitly disabled at build time.\n *\n * @example\n * if (!TREE_SHAKE_STORAGE_SESSION_STORAGE) { // sessionStorage logic }\n */\nexport const TREE_SHAKE_STORAGE_SESSION_STORAGE =\n process.env['INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE'] === 'false';\n\n/**\n * True when header storage is explicitly disabled at build time.\n *\n * @example\n * if (!TREE_SHAKE_STORAGE_HEADERS) { // header logic }\n */\nexport const TREE_SHAKE_STORAGE_HEADERS =\n process.env['INTLAYER_ROUTING_STORAGE_HEADERS'] === 'false';\n\n/**\n * True when the editor is explicitly disabled at build time.\n *\n * @example\n * if (!TREE_SHAKE_EDITOR) { // editor logic }\n */\nexport const TREE_SHAKE_EDITOR =\n process.env['INTLAYER_EDITOR_ENABLED'] === 'false';\n\n// ── Build-time env-var helpers ────────────────────────────────────────────────\n\n/**\n * Converts a list of unused NodeType keys into env-var definitions.\n * Set to `\"false\"` so bundlers can eliminate the corresponding plugin code.\n *\n * @example\n * formatNodeTypeToEnvVar(['enumeration'])\n * // { 'INTLAYER_NODE_TYPE_ENUMERATION': '\"false\"' }\n *\n * formatNodeTypeToEnvVar(['enumeration'], true)\n * // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '\"false\"' }\n */\nexport const formatNodeTypeToEnvVar = (\n nodeTypes: string[],\n addProcessEnv: boolean = false\n): Record<string, string> =>\n nodeTypes.reduce(\n (acc, nodeType) => {\n acc[\n addProcessEnv\n ? `process.env.INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`\n : `INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`\n ] = '\"false\"';\n return acc;\n },\n {} as Record<string, string>\n );\n\n/**\n * Returns env-var definitions for the full Intlayer config to be injected at\n * build time. Allows bundlers to dead-code-eliminate unused routing modes,\n * rewrite logic, storage mechanisms, and editor code.\n *\n * @example\n * getConfigEnvVars(config)\n * // { INTLAYER_ROUTING_MODE: '\"prefix-no-default\"', INTLAYER_ROUTING_REWRITE_RULES: '\"false\"', ... }\n *\n * getConfigEnvVars(config, true)\n * // { 'process.env.INTLAYER_ROUTING_MODE': '\"prefix-no-default\"', ... }\n */\nexport const getConfigEnvVars = (\n config: IntlayerConfig,\n addProcessEnv: boolean = false\n): Record<string, string> => {\n const prefix = addProcessEnv ? 'process.env.' : '';\n const { routing, editor } = config;\n\n const envVars: Record<string, string> = {\n [`${prefix}INTLAYER_ROUTING_MODE`]: JSON.stringify(routing.mode),\n };\n\n if (!routing.rewrite) {\n envVars[`${prefix}INTLAYER_ROUTING_REWRITE_RULES`] = '\"false\"';\n }\n\n if (routing.storage.cookies.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_COOKIES`] = '\"false\"';\n }\n\n if (routing.storage.localStorage.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_LOCALSTORAGE`] = '\"false\"';\n }\n\n if (routing.storage.sessionStorage.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE`] = '\"false\"';\n }\n\n if (routing.storage.headers.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_HEADERS`] = '\"false\"';\n }\n\n if (editor?.enabled === false) {\n envVars[`${prefix}INTLAYER_EDITOR_ENABLED`] = '\"false\"';\n }\n\n return envVars;\n};\n"],"mappings":";;;;;;;;AAaA,MAAa,uBACX,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B;;;;;;;AAQ3C,MAAa,2BACX,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B;;;;;;;;AAS3C,MAAa,0BACX,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B,gBACzC,QAAQ,IAAI,6BAA6B;;;;;;;;AAS3C,MAAa,qBACX,QAAQ,IAAI,sCAAsC;;;;;;;AAUpD,MAAa,6BACX,QAAQ,IAAI,wCAAwC;;;;;;;AAQtD,MAAa,mCACX,QAAQ,IAAI,6CAA6C;;;;;;;AAQ3D,MAAa,qCACX,QAAQ,IAAI,+CAA+C;;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|
+
export { TREE_SHAKE_EDITOR, TREE_SHAKE_NO_PREFIX, TREE_SHAKE_PREFIX_MODES, TREE_SHAKE_REWRITE, TREE_SHAKE_SEARCH_PARAMS, TREE_SHAKE_STORAGE_COOKIES, TREE_SHAKE_STORAGE_HEADERS, TREE_SHAKE_STORAGE_LOCAL_STORAGE, TREE_SHAKE_STORAGE_SESSION_STORAGE, formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
//#region src/utils/extractErrorMessage.ts
|
|
2
2
|
const extractErrorMessage = (error) => {
|
|
3
|
-
const trimToSingleLine = (text) => text.split(/\r?\n/).map((
|
|
3
|
+
const trimToSingleLine = (text) => text.split(/\r?\n/).map((stringValue) => stringValue.trim()).filter(Boolean)[0] ?? text.trim();
|
|
4
4
|
const looksLikeJson = (value) => {
|
|
5
|
-
const
|
|
6
|
-
if (!
|
|
7
|
-
const first =
|
|
5
|
+
const stringValue = value.trim();
|
|
6
|
+
if (!stringValue) return false;
|
|
7
|
+
const first = stringValue[0];
|
|
8
8
|
return first === "{" || first === "[" || first === "\"";
|
|
9
9
|
};
|
|
10
10
|
const sanitizeUnexpectedTokenMessage = (text) => {
|
|
@@ -21,6 +21,14 @@ const extractErrorMessage = (error) => {
|
|
|
21
21
|
if (!value || typeof value !== "object") return void 0;
|
|
22
22
|
if (seen.has(value)) return void 0;
|
|
23
23
|
seen.add(value);
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
for (const item of value) {
|
|
26
|
+
const fromItem = pickFieldsFromObject(item, seen);
|
|
27
|
+
if (fromItem) return fromItem;
|
|
28
|
+
if (typeof item?.message === "string") return item.message;
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
24
32
|
const obj = value;
|
|
25
33
|
if (typeof obj.message === "string" && obj.message.trim()) return obj.message;
|
|
26
34
|
if (typeof obj.error_description === "string" && obj.error_description.trim()) return obj.error_description;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractErrorMessage.mjs","names":[],"sources":["../../../src/utils/extractErrorMessage.ts"],"sourcesContent":["export const extractErrorMessage = (error: unknown): string => {\n const trimToSingleLine = (text: string): string =>\n text\n .split(/\\r?\\n/)\n .map((
|
|
1
|
+
{"version":3,"file":"extractErrorMessage.mjs","names":[],"sources":["../../../src/utils/extractErrorMessage.ts"],"sourcesContent":["export const extractErrorMessage = (error: unknown): string => {\n const trimToSingleLine = (text: string): string =>\n text\n .split(/\\r?\\n/)\n .map((stringValue) => stringValue.trim())\n .filter(Boolean)[0] ?? text.trim();\n\n const looksLikeJson = (value: string): boolean => {\n const stringValue = value.trim();\n\n if (!stringValue) return false;\n const first = stringValue[0];\n return first === '{' || first === '[' || first === '\"';\n };\n\n const sanitizeUnexpectedTokenMessage = (text: string): string => {\n // If the text mentions an invalid JSON parse, try to extract the meaningful part\n const t = text.trim();\n\n if (/Unexpected token/i.test(t) && /not valid JSON/i.test(t)) {\n const quoted = t.match(/\"([^\"]+)\"/);\n\n if (quoted?.[1]) return quoted[1];\n // Fallback: drop the leading parser error description\n const afterColon = t.split(':').slice(1).join(':').trim();\n\n if (afterColon) return afterColon;\n }\n return t;\n };\n\n const pickFieldsFromObject = (\n value: unknown,\n seen: Set<unknown>\n ): string | undefined => {\n if (!value || typeof value !== 'object') return undefined;\n\n if (seen.has(value)) return undefined;\n\n seen.add(value);\n\n // If the value itself is an array (e.g. ZodError.issues), iterate its items\n\n if (Array.isArray(value)) {\n for (const item of value) {\n const fromItem = pickFieldsFromObject(item, seen);\n\n if (fromItem) return fromItem;\n\n if (typeof (item as any)?.message === 'string')\n return (item as any).message;\n }\n return undefined;\n }\n\n const obj = value as Record<string, unknown>;\n\n // Check for message first (highest priority)\n\n if (typeof obj.message === 'string' && obj.message.trim()) {\n return obj.message;\n }\n\n // Check for error_description\n\n if (\n typeof obj.error_description === 'string' &&\n obj.error_description.trim()\n ) {\n return obj.error_description;\n }\n\n // Check for error\n\n if (typeof obj.error === 'string' && obj.error.trim()) {\n return obj.error;\n }\n\n // Handle title and code combination\n const title = typeof obj.title === 'string' ? obj.title.trim() : '';\n const code = typeof obj.code === 'string' ? obj.code.trim() : '';\n\n if (title && code) {\n return `${title} (${code})`;\n }\n\n if (title) {\n return title;\n }\n\n if (code) {\n return code;\n }\n\n // Check for statusText\n\n if (typeof obj.statusText === 'string' && obj.statusText.trim()) {\n return obj.statusText;\n }\n\n // Common nested structures (Axios/Fetch-like)\n const response = obj.response as Record<string, unknown> | undefined;\n\n if (response && typeof response === 'object') {\n const data = response.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n\n if (fromData) return fromData;\n }\n\n const data = obj.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n\n if (fromData) return fromData;\n\n // Nested cause chain\n const cause = (obj as { cause?: unknown }).cause;\n const fromCause =\n pickFieldsFromObject(cause, seen) ??\n (typeof (cause as any)?.message === 'string'\n ? (cause as any).message\n : undefined);\n\n if (fromCause) return fromCause;\n\n // Arrays of errors\n const errors = obj.errors as unknown;\n\n if (Array.isArray(errors)) {\n for (const item of errors) {\n const fromItem = pickFieldsFromObject(item, seen);\n\n if (fromItem) return fromItem;\n\n if (typeof (item as any)?.message === 'string')\n return (item as any).message;\n }\n }\n\n return undefined;\n };\n\n const tryParseJsonString = (maybeJson: string): string | undefined => {\n if (!looksLikeJson(maybeJson)) return undefined;\n try {\n const parsed = JSON.parse(maybeJson);\n const picked = pickFieldsFromObject(parsed, new Set());\n\n if (picked) return picked;\n\n if (typeof parsed === 'string') return parsed;\n return undefined;\n } catch {\n return undefined;\n }\n };\n\n if (typeof error === 'string') {\n const cleaned = sanitizeUnexpectedTokenMessage(error);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n if (error && typeof error === 'object') {\n // Native Error instance\n\n if (error instanceof Error) {\n const cleaned = sanitizeUnexpectedTokenMessage(error.message);\n const fromMessage = tryParseJsonString(cleaned);\n\n if (fromMessage) return trimToSingleLine(fromMessage);\n // Dive into cause when present\n const fromCause = extractErrorMessage(error.cause as unknown);\n\n if (fromCause && fromCause !== 'An unknown error occurred')\n return trimToSingleLine(fromCause);\n return trimToSingleLine(cleaned);\n }\n\n // Generic object\n const seen = new Set<unknown>();\n const fromObject = pickFieldsFromObject(error, seen);\n\n if (fromObject) {\n const cleaned = sanitizeUnexpectedTokenMessage(fromObject);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n try {\n const serialized = JSON.stringify(error);\n return trimToSingleLine(serialized);\n } catch {\n return trimToSingleLine(String(error));\n }\n }\n\n return 'An unknown error occurred';\n};\n"],"mappings":";AAAA,MAAa,uBAAuB,UAA2B;CAC7D,MAAM,oBAAoB,SACxB,KACG,MAAM,QAAQ,CACd,KAAK,gBAAgB,YAAY,MAAM,CAAC,CACxC,OAAO,QAAQ,CAAC,MAAM,KAAK,MAAM;CAEtC,MAAM,iBAAiB,UAA2B;EAChD,MAAM,cAAc,MAAM,MAAM;AAEhC,MAAI,CAAC,YAAa,QAAO;EACzB,MAAM,QAAQ,YAAY;AAC1B,SAAO,UAAU,OAAO,UAAU,OAAO,UAAU;;CAGrD,MAAM,kCAAkC,SAAyB;EAE/D,MAAM,IAAI,KAAK,MAAM;AAErB,MAAI,oBAAoB,KAAK,EAAE,IAAI,kBAAkB,KAAK,EAAE,EAAE;GAC5D,MAAM,SAAS,EAAE,MAAM,YAAY;AAEnC,OAAI,SAAS,GAAI,QAAO,OAAO;GAE/B,MAAM,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC,MAAM;AAEzD,OAAI,WAAY,QAAO;;AAEzB,SAAO;;CAGT,MAAM,wBACJ,OACA,SACuB;AACvB,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAEhD,MAAI,KAAK,IAAI,MAAM,CAAE,QAAO;AAE5B,OAAK,IAAI,MAAM;AAIf,MAAI,MAAM,QAAQ,MAAM,EAAE;AACxB,QAAK,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OAAQ,MAAc,YAAY,SACpC,QAAQ,KAAa;;;CAO7B,MAAM,sBAAsB,cAA0C;AACpE,MAAI,CAAC,cAAc,UAAU,CAAE,QAAO;AACtC,MAAI;GACF,MAAM,SAAS,KAAK,MAAM,UAAU;GACpC,MAAM,SAAS,qBAAqB,wBAAQ,IAAI,KAAK,CAAC;AAEtD,OAAI,OAAQ,QAAO;AAEnB,OAAI,OAAO,WAAW,SAAU,QAAO;AACvC;UACM;AACN;;;AAIJ,KAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,UAAU,+BAA+B,MAAM;AACrD,SAAO,mBAAmB,QAAQ,IAAI,iBAAiB,QAAQ;;AAGjE,KAAI,SAAS,OAAO,UAAU,UAAU;AAGtC,MAAI,iBAAiB,OAAO;GAC1B,MAAM,UAAU,+BAA+B,MAAM,QAAQ;GAC7D,MAAM,cAAc,mBAAmB,QAAQ;AAE/C,OAAI,YAAa,QAAO,iBAAiB,YAAY;GAErD,MAAM,YAAY,oBAAoB,MAAM,MAAiB;AAE7D,OAAI,aAAa,cAAc,4BAC7B,QAAO,iBAAiB,UAAU;AACpC,UAAO,iBAAiB,QAAQ;;EAKlC,MAAM,aAAa,qBAAqB,uBAD3B,IAAI,KAAc,CACqB;AAEpD,MAAI,YAAY;GACd,MAAM,UAAU,+BAA+B,WAAW;AAC1D,UAAO,mBAAmB,QAAQ,IAAI,iBAAiB,QAAQ;;AAGjE,MAAI;AAEF,UAAO,iBADY,KAAK,UAAU,MAAM,CACL;UAC7B;AACN,UAAO,iBAAiB,OAAO,MAAM,CAAC;;;AAI1C,QAAO"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { PLUGIN_NODE_TYPES } from "@intlayer/types/nodeType";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/getUsedNodeTypes.ts
|
|
4
|
+
/** Recursively collect every `nodeType` string found in a value. */
|
|
5
|
+
const collectNodeTypes = (value, result) => {
|
|
6
|
+
if (!value || typeof value !== "object") return;
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
|
+
for (const item of value) collectNodeTypes(item, result);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const obj = value;
|
|
12
|
+
if (typeof obj.nodeType === "string") result.add(obj.nodeType);
|
|
13
|
+
for (const key of Object.keys(obj)) collectNodeTypes(obj[key], result);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Returns the set of NodeType strings actually used across the given
|
|
17
|
+
* built dictionaries.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const used = getUsedNodeTypes(getDictionaries(config));
|
|
21
|
+
* // Set { 'translation', 'enumeration' }
|
|
22
|
+
*/
|
|
23
|
+
const getUsedNodeTypes = (dictionaries) => {
|
|
24
|
+
const result = /* @__PURE__ */ new Set();
|
|
25
|
+
const dicts = Array.isArray(dictionaries) ? dictionaries : Object.values(dictionaries);
|
|
26
|
+
for (const dict of dicts) collectNodeTypes(dict.content, result);
|
|
27
|
+
return [...result];
|
|
28
|
+
};
|
|
29
|
+
const getUnusedNodeTypes = (dictionaries) => {
|
|
30
|
+
const usedNodeTypes = getUsedNodeTypes(dictionaries);
|
|
31
|
+
return PLUGIN_NODE_TYPES.filter((nodeType) => !usedNodeTypes.includes(nodeType));
|
|
32
|
+
};
|
|
33
|
+
const getUsedNodeTypesAsync = async (dictionaries) => {
|
|
34
|
+
const dictionariesArray = Array.isArray(dictionaries) ? dictionaries : Object.values(dictionaries);
|
|
35
|
+
const results = await Promise.all(dictionariesArray.map(async (dictionary) => {
|
|
36
|
+
const result = /* @__PURE__ */ new Set();
|
|
37
|
+
collectNodeTypes(dictionary.content, result);
|
|
38
|
+
return result;
|
|
39
|
+
}));
|
|
40
|
+
const finalResult = /* @__PURE__ */ new Set();
|
|
41
|
+
for (const res of results) for (const val of res) finalResult.add(val);
|
|
42
|
+
return [...finalResult];
|
|
43
|
+
};
|
|
44
|
+
const getUnusedNodeTypesAsync = async (dictionaries) => {
|
|
45
|
+
const usedNodeTypes = await getUsedNodeTypesAsync(dictionaries);
|
|
46
|
+
return PLUGIN_NODE_TYPES.filter((nodeType) => !usedNodeTypes.includes(nodeType));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync };
|
|
51
|
+
//# sourceMappingURL=getUsedNodeTypes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUsedNodeTypes.mjs","names":[],"sources":["../../../src/utils/getUsedNodeTypes.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport { PLUGIN_NODE_TYPES } from '@intlayer/types/nodeType';\n\nexport type PluginNodeType = (typeof PLUGIN_NODE_TYPES)[number];\n\n/** Recursively collect every `nodeType` string found in a value. */\nconst collectNodeTypes = (value: unknown, result: Set<string>): void => {\n if (!value || typeof value !== 'object') return;\n\n if (Array.isArray(value)) {\n for (const item of value) collectNodeTypes(item, result);\n return;\n }\n\n const obj = value as Record<string, unknown>;\n\n if (typeof obj.nodeType === 'string') {\n result.add(obj.nodeType);\n }\n\n for (const key of Object.keys(obj)) {\n collectNodeTypes(obj[key], result);\n }\n};\n\n/**\n * Returns the set of NodeType strings actually used across the given\n * built dictionaries.\n *\n * @example\n * const used = getUsedNodeTypes(getDictionaries(config));\n * // Set { 'translation', 'enumeration' }\n */\nexport const getUsedNodeTypes = (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): PluginNodeType[] => {\n const result = new Set<PluginNodeType>();\n const dicts = Array.isArray(dictionaries)\n ? dictionaries\n : Object.values(dictionaries);\n\n for (const dict of dicts) {\n collectNodeTypes(dict.content, result);\n }\n\n return [...result];\n};\n\nexport const getUnusedNodeTypes = (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): PluginNodeType[] => {\n const usedNodeTypes = getUsedNodeTypes(dictionaries);\n\n return PLUGIN_NODE_TYPES.filter(\n (nodeType) => !usedNodeTypes.includes(nodeType)\n );\n};\n\nexport const getUsedNodeTypesAsync = async (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): Promise<PluginNodeType[]> => {\n const dictionariesArray = Array.isArray(dictionaries)\n ? dictionaries\n : Object.values(dictionaries);\n\n const results = await Promise.all(\n dictionariesArray.map(async (dictionary) => {\n const result = new Set<PluginNodeType>();\n\n collectNodeTypes(dictionary.content, result as Set<string>);\n\n return result;\n })\n );\n\n const finalResult = new Set<PluginNodeType>();\n\n for (const res of results) {\n for (const val of res) {\n finalResult.add(val);\n }\n }\n\n return [...finalResult];\n};\n\nexport const getUnusedNodeTypesAsync = async (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): Promise<PluginNodeType[]> => {\n const usedNodeTypes = await getUsedNodeTypesAsync(dictionaries);\n\n return PLUGIN_NODE_TYPES.filter(\n (nodeType) => !usedNodeTypes.includes(nodeType)\n );\n};\n"],"mappings":";;;;AAMA,MAAM,oBAAoB,OAAgB,WAA8B;AACtE,KAAI,CAAC,SAAS,OAAO,UAAU,SAAU;AAEzC,KAAI,MAAM,QAAQ,MAAM,EAAE;AACxB,OAAK,MAAM,QAAQ,MAAO,kBAAiB,MAAM,OAAO;AACxD;;CAGF,MAAM,MAAM;AAEZ,KAAI,OAAO,IAAI,aAAa,SAC1B,QAAO,IAAI,IAAI,SAAS;AAG1B,MAAK,MAAM,OAAO,OAAO,KAAK,IAAI,CAChC,kBAAiB,IAAI,MAAM,OAAO;;;;;;;;;;AAYtC,MAAa,oBACX,iBACqB;CACrB,MAAM,yBAAS,IAAI,KAAqB;CACxC,MAAM,QAAQ,MAAM,QAAQ,aAAa,GACrC,eACA,OAAO,OAAO,aAAa;AAE/B,MAAK,MAAM,QAAQ,MACjB,kBAAiB,KAAK,SAAS,OAAO;AAGxC,QAAO,CAAC,GAAG,OAAO;;AAGpB,MAAa,sBACX,iBACqB;CACrB,MAAM,gBAAgB,iBAAiB,aAAa;AAEpD,QAAO,kBAAkB,QACtB,aAAa,CAAC,cAAc,SAAS,SAAS,CAChD;;AAGH,MAAa,wBAAwB,OACnC,iBAC8B;CAC9B,MAAM,oBAAoB,MAAM,QAAQ,aAAa,GACjD,eACA,OAAO,OAAO,aAAa;CAE/B,MAAM,UAAU,MAAM,QAAQ,IAC5B,kBAAkB,IAAI,OAAO,eAAe;EAC1C,MAAM,yBAAS,IAAI,KAAqB;AAExC,mBAAiB,WAAW,SAAS,OAAsB;AAE3D,SAAO;GACP,CACH;CAED,MAAM,8BAAc,IAAI,KAAqB;AAE7C,MAAK,MAAM,OAAO,QAChB,MAAK,MAAM,OAAO,IAChB,aAAY,IAAI,IAAI;AAIxB,QAAO,CAAC,GAAG,YAAY;;AAGzB,MAAa,0BAA0B,OACrC,iBAC8B;CAC9B,MAAM,gBAAgB,MAAM,sBAAsB,aAAa;AAE/D,QAAO,kBAAkB,QACtB,aAAa,CAAC,cAAc,SAAS,SAAS,CAChD"}
|
package/dist/esm/utils/index.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { clearModuleCache } from "./clearModuleCache.mjs";
|
|
|
9
9
|
import { compareVersions } from "./compareVersions.mjs";
|
|
10
10
|
import { extractErrorMessage } from "./extractErrorMessage.mjs";
|
|
11
11
|
import { getStorageAttributes } from "./getStorageAttributes.mjs";
|
|
12
|
+
import { getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync } from "./getUsedNodeTypes.mjs";
|
|
12
13
|
import { logStack } from "./logStack.mjs";
|
|
13
14
|
import { parseFilePathPattern, parseStringPattern } from "./parseFilePathPattern.mjs";
|
|
14
15
|
import { retryManager } from "./retryManager.mjs";
|
|
@@ -17,4 +18,4 @@ import { camelCaseToSentence } from "./stringFormatter/camelCaseToSentence.mjs";
|
|
|
17
18
|
import { kebabCaseToCamelCase } from "./stringFormatter/kebabCaseToCamelCase.mjs";
|
|
18
19
|
import { toLowerCamelCase } from "./stringFormatter/toLowerCamelCase.mjs";
|
|
19
20
|
|
|
20
|
-
export { cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getPackageJsonPath, getProjectRequire, getStorageAttributes, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, stableStringify, toLowerCamelCase };
|
|
21
|
+
export { cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getPackageJsonPath, getProjectRequire, getStorageAttributes, getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, stableStringify, toLowerCamelCase };
|
|
@@ -20,9 +20,9 @@ declare const cookiesAttributesSchema: z.ZodObject<{
|
|
|
20
20
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
21
21
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
22
22
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
23
|
-
none: "none";
|
|
24
23
|
strict: "strict";
|
|
25
24
|
lax: "lax";
|
|
25
|
+
none: "none";
|
|
26
26
|
}>>;
|
|
27
27
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
28
28
|
}, z.core.$strip>;
|
|
@@ -47,9 +47,9 @@ declare const storageSchema: z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodEnum
|
|
|
47
47
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
48
48
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
49
49
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
50
|
-
none: "none";
|
|
51
50
|
strict: "strict";
|
|
52
51
|
lax: "lax";
|
|
52
|
+
none: "none";
|
|
53
53
|
}>>;
|
|
54
54
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
55
55
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -72,9 +72,9 @@ declare const storageSchema: z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodEnum
|
|
|
72
72
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
73
73
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
74
74
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
75
|
-
none: "none";
|
|
76
75
|
strict: "strict";
|
|
77
76
|
lax: "lax";
|
|
77
|
+
none: "none";
|
|
78
78
|
}>>;
|
|
79
79
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
80
80
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -155,9 +155,9 @@ declare const routingSchema: z.ZodObject<{
|
|
|
155
155
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
156
156
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
157
157
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
158
|
-
none: "none";
|
|
159
158
|
strict: "strict";
|
|
160
159
|
lax: "lax";
|
|
160
|
+
none: "none";
|
|
161
161
|
}>>;
|
|
162
162
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
163
163
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -180,9 +180,9 @@ declare const routingSchema: z.ZodObject<{
|
|
|
180
180
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
181
181
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
182
182
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
183
|
-
none: "none";
|
|
184
183
|
strict: "strict";
|
|
185
184
|
lax: "lax";
|
|
185
|
+
none: "none";
|
|
186
186
|
}>>;
|
|
187
187
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
188
188
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -349,9 +349,9 @@ declare const intlayerConfigSchema: z.ZodObject<{
|
|
|
349
349
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
350
350
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
351
351
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
352
|
-
none: "none";
|
|
353
352
|
strict: "strict";
|
|
354
353
|
lax: "lax";
|
|
354
|
+
none: "none";
|
|
355
355
|
}>>;
|
|
356
356
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
357
357
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -374,9 +374,9 @@ declare const intlayerConfigSchema: z.ZodObject<{
|
|
|
374
374
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
375
375
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
376
376
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
377
|
-
none: "none";
|
|
378
377
|
strict: "strict";
|
|
379
378
|
lax: "lax";
|
|
379
|
+
none: "none";
|
|
380
380
|
}>>;
|
|
381
381
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
382
382
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { IntlayerConfig } from "@intlayer/types/config";
|
|
2
|
+
|
|
3
|
+
//#region src/envVars/envVars.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* True when the build-time routing mode is known and is NOT 'no-prefix'.
|
|
6
|
+
* Use to guard no-prefix-specific code paths so bundlers can eliminate them.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* if (!TREE_SHAKE_NO_PREFIX && mode === 'no-prefix') { ... }
|
|
10
|
+
*/
|
|
11
|
+
declare const TREE_SHAKE_NO_PREFIX: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* True when the build-time routing mode is known and is NOT 'search-params'.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* if (!TREE_SHAKE_SEARCH_PARAMS && mode === 'search-params') { ... }
|
|
17
|
+
*/
|
|
18
|
+
declare const TREE_SHAKE_SEARCH_PARAMS: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* True when the build-time routing mode is known and is not a prefix-based
|
|
21
|
+
* mode (neither 'prefix-all' nor 'prefix-no-default').
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* if (!TREE_SHAKE_PREFIX_MODES && (mode === 'prefix-all' || mode === 'prefix-no-default')) { ... }
|
|
25
|
+
*/
|
|
26
|
+
declare const TREE_SHAKE_PREFIX_MODES: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* True when rewrite rules are explicitly disabled at build time
|
|
29
|
+
* (INTLAYER_ROUTING_REWRITE_RULES === 'false').
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* if (!TREE_SHAKE_REWRITE && rewrite) { ... }
|
|
33
|
+
*/
|
|
34
|
+
declare const TREE_SHAKE_REWRITE: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* True when cookie storage is explicitly disabled at build time.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* if (!TREE_SHAKE_STORAGE_COOKIES) { // cookie logic }
|
|
40
|
+
*/
|
|
41
|
+
declare const TREE_SHAKE_STORAGE_COOKIES: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* True when localStorage is explicitly disabled at build time.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) { // localStorage logic }
|
|
47
|
+
*/
|
|
48
|
+
declare const TREE_SHAKE_STORAGE_LOCAL_STORAGE: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* True when sessionStorage is explicitly disabled at build time.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* if (!TREE_SHAKE_STORAGE_SESSION_STORAGE) { // sessionStorage logic }
|
|
54
|
+
*/
|
|
55
|
+
declare const TREE_SHAKE_STORAGE_SESSION_STORAGE: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* True when header storage is explicitly disabled at build time.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* if (!TREE_SHAKE_STORAGE_HEADERS) { // header logic }
|
|
61
|
+
*/
|
|
62
|
+
declare const TREE_SHAKE_STORAGE_HEADERS: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* True when the editor is explicitly disabled at build time.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* if (!TREE_SHAKE_EDITOR) { // editor logic }
|
|
68
|
+
*/
|
|
69
|
+
declare const TREE_SHAKE_EDITOR: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Converts a list of unused NodeType keys into env-var definitions.
|
|
72
|
+
* Set to `"false"` so bundlers can eliminate the corresponding plugin code.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* formatNodeTypeToEnvVar(['enumeration'])
|
|
76
|
+
* // { 'INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
77
|
+
*
|
|
78
|
+
* formatNodeTypeToEnvVar(['enumeration'], true)
|
|
79
|
+
* // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
80
|
+
*/
|
|
81
|
+
declare const formatNodeTypeToEnvVar: (nodeTypes: string[], addProcessEnv?: boolean) => Record<string, string>;
|
|
82
|
+
/**
|
|
83
|
+
* Returns env-var definitions for the full Intlayer config to be injected at
|
|
84
|
+
* build time. Allows bundlers to dead-code-eliminate unused routing modes,
|
|
85
|
+
* rewrite logic, storage mechanisms, and editor code.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* getConfigEnvVars(config)
|
|
89
|
+
* // { INTLAYER_ROUTING_MODE: '"prefix-no-default"', INTLAYER_ROUTING_REWRITE_RULES: '"false"', ... }
|
|
90
|
+
*
|
|
91
|
+
* getConfigEnvVars(config, true)
|
|
92
|
+
* // { 'process.env.INTLAYER_ROUTING_MODE': '"prefix-no-default"', ... }
|
|
93
|
+
*/
|
|
94
|
+
declare const getConfigEnvVars: (config: IntlayerConfig, addProcessEnv?: boolean) => Record<string, string>;
|
|
95
|
+
//#endregion
|
|
96
|
+
export { TREE_SHAKE_EDITOR, TREE_SHAKE_NO_PREFIX, TREE_SHAKE_PREFIX_MODES, TREE_SHAKE_REWRITE, TREE_SHAKE_SEARCH_PARAMS, TREE_SHAKE_STORAGE_COOKIES, TREE_SHAKE_STORAGE_HEADERS, TREE_SHAKE_STORAGE_LOCAL_STORAGE, TREE_SHAKE_STORAGE_SESSION_STORAGE, formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
97
|
+
//# sourceMappingURL=envVars.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envVars.d.ts","names":[],"sources":["../../../src/envVars/envVars.ts"],"mappings":";;;;;AAaA;;;;;cAAa,oBAAA;;;;;AAqBb;;cAXa,wBAAA;;;AAuBb;;;;;cAZa,uBAAA;;;;;AAgCb;;;cApBa,kBAAA;;AA6Bb;;;;;cAlBa,0BAAA;;;;;AAoCb;;cA3Ba,gCAAA;;;AA2Cb;;;;cAlCa,kCAAA;;;;;AA8Db;;cArDa,0BAAA;;;;;;;cASA,iBAAA;;;;;;;;;;;;cAgBA,sBAAA,GACX,SAAA,YACA,aAAA,eACC,MAAA;;;;;;;;;;;;;cAyBU,gBAAA,GACX,MAAA,EAAQ,cAAA,EACR,aAAA,eACC,MAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { TREE_SHAKE_EDITOR, TREE_SHAKE_NO_PREFIX, TREE_SHAKE_PREFIX_MODES, TREE_SHAKE_REWRITE, TREE_SHAKE_SEARCH_PARAMS, TREE_SHAKE_STORAGE_COOKIES, TREE_SHAKE_STORAGE_HEADERS, TREE_SHAKE_STORAGE_LOCAL_STORAGE, TREE_SHAKE_STORAGE_SESSION_STORAGE, formatNodeTypeToEnvVar, getConfigEnvVars } from "./envVars.js";
|
|
2
|
+
export { TREE_SHAKE_EDITOR, TREE_SHAKE_NO_PREFIX, TREE_SHAKE_PREFIX_MODES, TREE_SHAKE_REWRITE, TREE_SHAKE_SEARCH_PARAMS, TREE_SHAKE_STORAGE_COOKIES, TREE_SHAKE_STORAGE_HEADERS, TREE_SHAKE_STORAGE_LOCAL_STORAGE, TREE_SHAKE_STORAGE_SESSION_STORAGE, formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Dictionary } from "@intlayer/types/dictionary";
|
|
2
|
+
import { PLUGIN_NODE_TYPES } from "@intlayer/types/nodeType";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/getUsedNodeTypes.d.ts
|
|
5
|
+
type PluginNodeType = (typeof PLUGIN_NODE_TYPES)[number];
|
|
6
|
+
/**
|
|
7
|
+
* Returns the set of NodeType strings actually used across the given
|
|
8
|
+
* built dictionaries.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const used = getUsedNodeTypes(getDictionaries(config));
|
|
12
|
+
* // Set { 'translation', 'enumeration' }
|
|
13
|
+
*/
|
|
14
|
+
declare const getUsedNodeTypes: (dictionaries: Record<string, Dictionary> | Dictionary[]) => PluginNodeType[];
|
|
15
|
+
declare const getUnusedNodeTypes: (dictionaries: Record<string, Dictionary> | Dictionary[]) => PluginNodeType[];
|
|
16
|
+
declare const getUsedNodeTypesAsync: (dictionaries: Record<string, Dictionary> | Dictionary[]) => Promise<PluginNodeType[]>;
|
|
17
|
+
declare const getUnusedNodeTypesAsync: (dictionaries: Record<string, Dictionary> | Dictionary[]) => Promise<PluginNodeType[]>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { PluginNodeType, getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync };
|
|
20
|
+
//# sourceMappingURL=getUsedNodeTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUsedNodeTypes.d.ts","names":[],"sources":["../../../src/utils/getUsedNodeTypes.ts"],"mappings":";;;;KAGY,cAAA,WAAyB,iBAAA;;AAArC;;;;;AA8BA;;cAAa,gBAAA,GACX,YAAA,EAAc,MAAA,SAAe,UAAA,IAAc,UAAA,OAC1C,cAAA;AAAA,cAaU,kBAAA,GACX,YAAA,EAAc,MAAA,SAAe,UAAA,IAAc,UAAA,OAC1C,cAAA;AAAA,cAQU,qBAAA,GACX,YAAA,EAAc,MAAA,SAAe,UAAA,IAAc,UAAA,OAC1C,OAAA,CAAQ,cAAA;AAAA,cA0BE,uBAAA,GACX,YAAA,EAAc,MAAA,SAAe,UAAA,IAAc,UAAA,OAC1C,OAAA,CAAQ,cAAA"}
|
|
@@ -14,6 +14,7 @@ import { compareVersions } from "./compareVersions.js";
|
|
|
14
14
|
import { getExtension } from "./getExtension.js";
|
|
15
15
|
import { getPackageJsonPath } from "./getPackageJsonPath.js";
|
|
16
16
|
import { getStorageAttributes } from "./getStorageAttributes.js";
|
|
17
|
+
import { PluginNodeType, getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync } from "./getUsedNodeTypes.js";
|
|
17
18
|
import { parseFilePathPattern, parseStringPattern } from "./parseFilePathPattern.js";
|
|
18
19
|
import { RetryManagerOptions, retryManager } from "./retryManager.js";
|
|
19
|
-
export { CacheKey, GetAliasOptions, RetryManagerOptions, cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getPackageJsonPath, getProjectRequire, getStorageAttributes, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, stableStringify, toLowerCamelCase };
|
|
20
|
+
export { CacheKey, GetAliasOptions, PluginNodeType, RetryManagerOptions, cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getPackageJsonPath, getProjectRequire, getStorageAttributes, getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, stableStringify, toLowerCamelCase };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/config",
|
|
3
|
-
"version": "8.6.
|
|
3
|
+
"version": "8.6.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Retrieve Intlayer configurations and manage environment variables for both server-side and client-side environments.",
|
|
6
6
|
"keywords": [
|
|
@@ -78,6 +78,11 @@
|
|
|
78
78
|
"require": "./dist/cjs/colors.cjs",
|
|
79
79
|
"import": "./dist/esm/colors.mjs"
|
|
80
80
|
},
|
|
81
|
+
"./envVars": {
|
|
82
|
+
"types": "./dist/types/envVars/index.d.ts",
|
|
83
|
+
"require": "./dist/cjs/envVars/index.cjs",
|
|
84
|
+
"import": "./dist/esm/envVars/index.mjs"
|
|
85
|
+
},
|
|
81
86
|
"./defaultValues": {
|
|
82
87
|
"types": "./dist/types/defaultValues/index.d.ts",
|
|
83
88
|
"require": "./dist/cjs/defaultValues/index.cjs",
|
|
@@ -108,6 +113,9 @@
|
|
|
108
113
|
"env": [
|
|
109
114
|
"./dist/types/loadEnvFile.d.ts"
|
|
110
115
|
],
|
|
116
|
+
"envVars": [
|
|
117
|
+
"./dist/types/envVars/index.d.ts"
|
|
118
|
+
],
|
|
111
119
|
"logger": [
|
|
112
120
|
"./dist/types/logger.d.ts"
|
|
113
121
|
],
|
|
@@ -144,7 +152,7 @@
|
|
|
144
152
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
145
153
|
},
|
|
146
154
|
"dependencies": {
|
|
147
|
-
"@intlayer/types": "8.6.
|
|
155
|
+
"@intlayer/types": "8.6.2",
|
|
148
156
|
"defu": "6.1.4",
|
|
149
157
|
"dotenv": "17.3.1",
|
|
150
158
|
"esbuild": "0.27.4",
|