@intlayer/config 9.0.0-canary.1 → 9.0.0-canary.3
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/bundle/index.cjs +1 -1
- package/dist/cjs/envVars/envVars.cjs +20 -0
- package/dist/cjs/envVars/envVars.cjs.map +1 -1
- package/dist/cjs/envVars/index.cjs +1 -0
- package/dist/cjs/loadExternalFile/transpileTSToCJS.cjs +28 -13
- package/dist/cjs/loadExternalFile/transpileTSToCJS.cjs.map +1 -1
- package/dist/cjs/logger.cjs +1 -1
- package/dist/cjs/logger.cjs.map +1 -1
- package/dist/cjs/utils/getDictionarySelectorUsage.cjs +28 -0
- package/dist/cjs/utils/getDictionarySelectorUsage.cjs.map +1 -0
- package/dist/cjs/utils/index.cjs +2 -0
- package/dist/esm/bundle/index.mjs +1 -1
- package/dist/esm/envVars/envVars.mjs +20 -1
- package/dist/esm/envVars/envVars.mjs.map +1 -1
- package/dist/esm/envVars/index.mjs +2 -2
- package/dist/esm/loadExternalFile/transpileTSToCJS.mjs +28 -13
- package/dist/esm/loadExternalFile/transpileTSToCJS.mjs.map +1 -1
- package/dist/esm/logger.mjs +1 -1
- package/dist/esm/logger.mjs.map +1 -1
- package/dist/esm/utils/getDictionarySelectorUsage.mjs +26 -0
- package/dist/esm/utils/getDictionarySelectorUsage.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 +20 -1
- package/dist/types/envVars/envVars.d.ts.map +1 -1
- package/dist/types/envVars/index.d.ts +2 -2
- package/dist/types/loadExternalFile/transpileTSToCJS.d.ts.map +1 -1
- package/dist/types/utils/getDictionarySelectorUsage.d.ts +23 -0
- package/dist/types/utils/getDictionarySelectorUsage.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +2 -1
- package/package.json +2 -2
|
@@ -2,8 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_utils_alias = require('../utils/alias.cjs');
|
|
4
4
|
const require_configFile_getConfiguration = require('../configFile/getConfiguration.cjs');
|
|
5
|
-
const require_bundle_logBundle = require('./logBundle.cjs');
|
|
6
5
|
const require_envVars_envVars = require('../envVars/envVars.cjs');
|
|
6
|
+
const require_bundle_logBundle = require('./logBundle.cjs');
|
|
7
7
|
let node_path = require("node:path");
|
|
8
8
|
let node_fs_promises = require("node:fs/promises");
|
|
9
9
|
let _intlayer_types_package_json = require("@intlayer/types/package.json");
|
|
@@ -26,6 +26,25 @@ const formatNodeTypeToEnvVar = (nodeTypes, wrapKey = (key) => key, wrapValue = (
|
|
|
26
26
|
return acc;
|
|
27
27
|
}, {});
|
|
28
28
|
/**
|
|
29
|
+
* Returns the env-var definition disabling the dictionary-selector resolution
|
|
30
|
+
* path (collections, variants, meta records) when no built dictionary declares
|
|
31
|
+
* a qualifier. Set to `"false"` so bundlers can dead-code-eliminate the
|
|
32
|
+
* selector branch in `getIntlayer` / `useIntlayer`.
|
|
33
|
+
*
|
|
34
|
+
* Emits nothing when selectors are used, leaving the runtime default in place.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* formatDictionarySelectorEnvVar(false)
|
|
38
|
+
* // { INTLAYER_DICTIONARY_SELECTOR: '"false"' }
|
|
39
|
+
*
|
|
40
|
+
* formatDictionarySelectorEnvVar(true)
|
|
41
|
+
* // {}
|
|
42
|
+
*
|
|
43
|
+
* formatDictionarySelectorEnvVar(false, (k) => `process.env.${k}`, (v) => `"${v}"`)
|
|
44
|
+
* // { 'process.env.INTLAYER_DICTIONARY_SELECTOR': '"false"' }
|
|
45
|
+
*/
|
|
46
|
+
const formatDictionarySelectorEnvVar = (hasDictionarySelector, wrapKey = (key) => key, wrapValue = (value) => value) => hasDictionarySelector ? {} : { [wrapKey("INTLAYER_DICTIONARY_SELECTOR")]: wrapValue("false") };
|
|
47
|
+
/**
|
|
29
48
|
* Returns env-var definitions for the full Intlayer config to be injected at
|
|
30
49
|
* build time. Allows bundlers to dead-code-eliminate unused routing modes,
|
|
31
50
|
* rewrite logic, storage mechanisms, and editor code.
|
|
@@ -51,6 +70,7 @@ const getConfigEnvVars = (config, wrapKey = (key) => key, wrapValue = (value) =>
|
|
|
51
70
|
};
|
|
52
71
|
|
|
53
72
|
//#endregion
|
|
73
|
+
exports.formatDictionarySelectorEnvVar = formatDictionarySelectorEnvVar;
|
|
54
74
|
exports.formatNodeTypeToEnvVar = formatNodeTypeToEnvVar;
|
|
55
75
|
exports.getConfigEnvVars = getConfigEnvVars;
|
|
56
76
|
//# sourceMappingURL=envVars.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envVars.cjs","names":[],"sources":["../../../src/envVars/envVars.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\n\n/**\n * Converts a camelCase node-type string to SCREAMING_SNAKE_CASE so that\n * the generated env-var name matches what the plugin source files check.\n *\n * @example\n * toScreamingSnakeCase('reactNode') // 'REACT_NODE'\n * toScreamingSnakeCase('markdown') // 'MARKDOWN'\n */\nconst toScreamingSnakeCase = (str: string): string =>\n str\n .replace(/([A-Z])/g, '_$1')\n .toUpperCase()\n .replace(/^_/, ''); // strip any leading underscore\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(['reactNode'], (k) => `process.env.${k}`, (v) => `\"${v}\"`)\n * // { 'process.env.INTLAYER_NODE_TYPE_REACT_NODE': '\"false\"' }\n */\nexport const formatNodeTypeToEnvVar = (\n nodeTypes: string[],\n wrapKey = (key: string) => key,\n wrapValue = (value: string) => value\n): Record<string, string> =>\n nodeTypes.reduce(\n (acc, nodeType) => {\n acc[wrapKey(`INTLAYER_NODE_TYPE_${toScreamingSnakeCase(nodeType)}`)] =\n wrapValue('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 wrapKey = (key: string) => key,\n wrapValue = (value: string) => value\n): Record<string, string> => {\n const { routing, editor } = config;\n\n const envVars: Record<string, string> = {\n [wrapKey('INTLAYER_ROUTING_MODE')]: wrapValue(routing.mode),\n };\n\n if (!routing.rewrite) {\n envVars[wrapKey('INTLAYER_ROUTING_REWRITE_RULES')] = wrapValue('false');\n }\n\n if (!routing.domains || Object.keys(routing.domains).length === 0) {\n envVars[wrapKey('INTLAYER_ROUTING_DOMAINS')] = wrapValue('false');\n }\n\n if (!routing.storage.cookies || routing.storage.cookies.length === 0) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_COOKIES')] = wrapValue('false');\n }\n\n if (\n !routing.storage.localStorage ||\n routing.storage.localStorage.length === 0\n ) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_LOCALSTORAGE')] =\n wrapValue('false');\n }\n\n if (\n !routing.storage.sessionStorage ||\n routing.storage.sessionStorage.length === 0\n ) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE')] =\n wrapValue('false');\n }\n\n if (!routing.storage.headers || routing.storage.headers.length === 0) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_HEADERS')] = wrapValue('false');\n }\n\n if (editor?.enabled === false) {\n envVars[wrapKey('INTLAYER_EDITOR_ENABLED')] = wrapValue('false');\n }\n\n return envVars;\n};\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,wBAAwB,QAC5B,IACG,QAAQ,YAAY,MAAM,CAC1B,aAAa,CACb,QAAQ,MAAM,GAAG;;;;;;;;;;;;AAatB,MAAa,0BACX,WACA,WAAW,QAAgB,KAC3B,aAAa,UAAkB,UAE/B,UAAU,QACP,KAAK,aAAa;AACjB,KAAI,QAAQ,sBAAsB,qBAAqB,SAAS,GAAG,IACjE,UAAU,QAAQ;AACpB,QAAO;GAET,EAAE,CACH;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"envVars.cjs","names":[],"sources":["../../../src/envVars/envVars.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\n\n/**\n * Converts a camelCase node-type string to SCREAMING_SNAKE_CASE so that\n * the generated env-var name matches what the plugin source files check.\n *\n * @example\n * toScreamingSnakeCase('reactNode') // 'REACT_NODE'\n * toScreamingSnakeCase('markdown') // 'MARKDOWN'\n */\nconst toScreamingSnakeCase = (str: string): string =>\n str\n .replace(/([A-Z])/g, '_$1')\n .toUpperCase()\n .replace(/^_/, ''); // strip any leading underscore\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(['reactNode'], (k) => `process.env.${k}`, (v) => `\"${v}\"`)\n * // { 'process.env.INTLAYER_NODE_TYPE_REACT_NODE': '\"false\"' }\n */\nexport const formatNodeTypeToEnvVar = (\n nodeTypes: string[],\n wrapKey = (key: string) => key,\n wrapValue = (value: string) => value\n): Record<string, string> =>\n nodeTypes.reduce(\n (acc, nodeType) => {\n acc[wrapKey(`INTLAYER_NODE_TYPE_${toScreamingSnakeCase(nodeType)}`)] =\n wrapValue('false');\n return acc;\n },\n {} as Record<string, string>\n );\n\n/**\n * Returns the env-var definition disabling the dictionary-selector resolution\n * path (collections, variants, meta records) when no built dictionary declares\n * a qualifier. Set to `\"false\"` so bundlers can dead-code-eliminate the\n * selector branch in `getIntlayer` / `useIntlayer`.\n *\n * Emits nothing when selectors are used, leaving the runtime default in place.\n *\n * @example\n * formatDictionarySelectorEnvVar(false)\n * // { INTLAYER_DICTIONARY_SELECTOR: '\"false\"' }\n *\n * formatDictionarySelectorEnvVar(true)\n * // {}\n *\n * formatDictionarySelectorEnvVar(false, (k) => `process.env.${k}`, (v) => `\"${v}\"`)\n * // { 'process.env.INTLAYER_DICTIONARY_SELECTOR': '\"false\"' }\n */\nexport const formatDictionarySelectorEnvVar = (\n hasDictionarySelector: boolean,\n wrapKey = (key: string) => key,\n wrapValue = (value: string) => value\n): Record<string, string> =>\n hasDictionarySelector\n ? {}\n : { [wrapKey('INTLAYER_DICTIONARY_SELECTOR')]: wrapValue('false') };\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 wrapKey = (key: string) => key,\n wrapValue = (value: string) => value\n): Record<string, string> => {\n const { routing, editor } = config;\n\n const envVars: Record<string, string> = {\n [wrapKey('INTLAYER_ROUTING_MODE')]: wrapValue(routing.mode),\n };\n\n if (!routing.rewrite) {\n envVars[wrapKey('INTLAYER_ROUTING_REWRITE_RULES')] = wrapValue('false');\n }\n\n if (!routing.domains || Object.keys(routing.domains).length === 0) {\n envVars[wrapKey('INTLAYER_ROUTING_DOMAINS')] = wrapValue('false');\n }\n\n if (!routing.storage.cookies || routing.storage.cookies.length === 0) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_COOKIES')] = wrapValue('false');\n }\n\n if (\n !routing.storage.localStorage ||\n routing.storage.localStorage.length === 0\n ) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_LOCALSTORAGE')] =\n wrapValue('false');\n }\n\n if (\n !routing.storage.sessionStorage ||\n routing.storage.sessionStorage.length === 0\n ) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE')] =\n wrapValue('false');\n }\n\n if (!routing.storage.headers || routing.storage.headers.length === 0) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_HEADERS')] = wrapValue('false');\n }\n\n if (editor?.enabled === false) {\n envVars[wrapKey('INTLAYER_EDITOR_ENABLED')] = wrapValue('false');\n }\n\n return envVars;\n};\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,wBAAwB,QAC5B,IACG,QAAQ,YAAY,MAAM,CAC1B,aAAa,CACb,QAAQ,MAAM,GAAG;;;;;;;;;;;;AAatB,MAAa,0BACX,WACA,WAAW,QAAgB,KAC3B,aAAa,UAAkB,UAE/B,UAAU,QACP,KAAK,aAAa;AACjB,KAAI,QAAQ,sBAAsB,qBAAqB,SAAS,GAAG,IACjE,UAAU,QAAQ;AACpB,QAAO;GAET,EAAE,CACH;;;;;;;;;;;;;;;;;;;AAoBH,MAAa,kCACX,uBACA,WAAW,QAAgB,KAC3B,aAAa,UAAkB,UAE/B,wBACI,EAAE,GACF,GAAG,QAAQ,+BAA+B,GAAG,UAAU,QAAQ,EAAE;;;;;;;;;;;;;AAcvE,MAAa,oBACX,QACA,WAAW,QAAgB,KAC3B,aAAa,UAAkB,UACJ;CAC3B,MAAM,EAAE,SAAS,WAAW;CAE5B,MAAM,UAAkC,GACrC,QAAQ,wBAAwB,GAAG,UAAU,QAAQ,KAAK,EAC5D;AAED,KAAI,CAAC,QAAQ,QACX,SAAQ,QAAQ,iCAAiC,IAAI,UAAU,QAAQ;AAGzE,KAAI,CAAC,QAAQ,WAAW,OAAO,KAAK,QAAQ,QAAQ,CAAC,WAAW,EAC9D,SAAQ,QAAQ,2BAA2B,IAAI,UAAU,QAAQ;AAGnE,KAAI,CAAC,QAAQ,QAAQ,WAAW,QAAQ,QAAQ,QAAQ,WAAW,EACjE,SAAQ,QAAQ,mCAAmC,IAAI,UAAU,QAAQ;AAG3E,KACE,CAAC,QAAQ,QAAQ,gBACjB,QAAQ,QAAQ,aAAa,WAAW,EAExC,SAAQ,QAAQ,wCAAwC,IACtD,UAAU,QAAQ;AAGtB,KACE,CAAC,QAAQ,QAAQ,kBACjB,QAAQ,QAAQ,eAAe,WAAW,EAE1C,SAAQ,QAAQ,0CAA0C,IACxD,UAAU,QAAQ;AAGtB,KAAI,CAAC,QAAQ,QAAQ,WAAW,QAAQ,QAAQ,QAAQ,WAAW,EACjE,SAAQ,QAAQ,mCAAmC,IAAI,UAAU,QAAQ;AAG3E,KAAI,QAAQ,YAAY,MACtB,SAAQ,QAAQ,0BAA0B,IAAI,UAAU,QAAQ;AAGlE,QAAO"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_envVars_envVars = require('./envVars.cjs');
|
|
3
3
|
|
|
4
|
+
exports.formatDictionarySelectorEnvVar = require_envVars_envVars.formatDictionarySelectorEnvVar;
|
|
4
5
|
exports.formatNodeTypeToEnvVar = require_envVars_envVars.formatNodeTypeToEnvVar;
|
|
5
6
|
exports.getConfigEnvVars = require_envVars_envVars.getConfigEnvVars;
|
|
@@ -41,21 +41,36 @@ const transpileTSToCJSSync = (code, filePath, options) => {
|
|
|
41
41
|
const loader = require_loadExternalFile_bundleFile.getLoader((0, node_path.extname)(filePath));
|
|
42
42
|
const { esbuildInstance, ...buildOptions } = options ?? {};
|
|
43
43
|
const esbuildBuildSync = esbuildInstance?.buildSync ?? esbuild.buildSync;
|
|
44
|
-
|
|
44
|
+
const g = globalThis;
|
|
45
|
+
const hadFilename = typeof g.__filename === "string";
|
|
46
|
+
const prevFilename = g.__filename;
|
|
47
|
+
const prevDirname = g.__dirname;
|
|
48
|
+
if (!hadFilename) try {
|
|
45
49
|
const esbuildEntry = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href).resolve("esbuild");
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
g.__filename = esbuildEntry;
|
|
51
|
+
g.__dirname = (0, node_path.dirname)(esbuildEntry);
|
|
48
52
|
} catch {}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
let moduleResult;
|
|
54
|
+
try {
|
|
55
|
+
moduleResult = esbuildBuildSync({
|
|
56
|
+
stdin: {
|
|
57
|
+
contents: code,
|
|
58
|
+
loader,
|
|
59
|
+
resolveDir: (0, node_path.dirname)(filePath),
|
|
60
|
+
sourcefile: filePath
|
|
61
|
+
},
|
|
62
|
+
...getTransformationOptions(filePath),
|
|
63
|
+
...buildOptions
|
|
64
|
+
});
|
|
65
|
+
} finally {
|
|
66
|
+
if (!hadFilename) {
|
|
67
|
+
if (prevFilename === void 0) delete g.__filename;
|
|
68
|
+
else g.__filename = prevFilename;
|
|
69
|
+
if (prevDirname === void 0) delete g.__dirname;
|
|
70
|
+
else g.__dirname = prevDirname;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return moduleResult.outputFiles?.[0]?.text;
|
|
59
74
|
};
|
|
60
75
|
const transpileTSToCJS = async (code, filePath, options) => {
|
|
61
76
|
const loader = require_loadExternalFile_bundleFile.getLoader((0, node_path.extname)(filePath));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpileTSToCJS.cjs","names":["getPackageJsonPath","getLoader","buildSync","context"],"sources":["../../../src/loadExternalFile/transpileTSToCJS.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, extname, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport {\n type BuildOptions,\n type BuildResult,\n buildSync,\n context,\n} from 'esbuild';\nimport { getPackageJsonPath } from '../utils/getPackageJsonPath';\nimport { getLoader } from './bundleFile';\n\nexport type TranspileOptions = BuildOptions & {\n /**\n * Optional custom esbuild instance to use for transpilation.\n * Useful in environments (e.g. VS Code extensions) where the bundled\n * esbuild binary may not match the host platform.\n * When provided, its `buildSync`/`build` methods are used instead of\n * the ones imported from the `esbuild` package.\n */\n esbuildInstance?: typeof import('esbuild');\n};\n\nconst getTsConfigPath = (filePath: string): string | undefined => {\n const tsconfigPath = join(\n getPackageJsonPath(dirname(filePath)).baseDir,\n 'tsconfig.json'\n );\n\n // Only return the tsconfig path if it exists\n return existsSync(tsconfigPath) ? tsconfigPath : undefined;\n};\n\nconst getTransformationOptions = (filePath: string): BuildOptions => ({\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n '.md': 'text',\n '.mdx': 'text',\n },\n format: 'cjs',\n target: 'node20',\n platform: 'node',\n write: false,\n packages: 'external',\n bundle: true,\n tsconfig: getTsConfigPath(filePath),\n define: {\n 'import.meta.url': JSON.stringify(pathToFileURL(filePath).href),\n 'import.meta.env': 'process.env',\n },\n});\n\nexport const transpileTSToCJSSync = (\n code: string,\n filePath: string,\n options?: TranspileOptions\n): string | undefined => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const { esbuildInstance, ...buildOptions } = options ?? {};\n const esbuildBuildSync = esbuildInstance?.buildSync ?? buildSync;\n\n // esbuild's worker thread service calls `new Worker(__filename, …)` on first use.\n // In Vite's SSR module runner the SSR-optimised chunk is ESM and __filename is\n // never declared (confirmed: accessing it throws ReferenceError, not undefined).\n // Because there is no local declaration the bare `__filename` lookup falls\n // through to globalThis, so we set it there to esbuild's own CJS entry-point –\n // the exact path esbuild would use if it were loaded in a normal CJS context.\n
|
|
1
|
+
{"version":3,"file":"transpileTSToCJS.cjs","names":["getPackageJsonPath","getLoader","buildSync","context"],"sources":["../../../src/loadExternalFile/transpileTSToCJS.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, extname, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport {\n type BuildOptions,\n type BuildResult,\n buildSync,\n context,\n} from 'esbuild';\nimport { getPackageJsonPath } from '../utils/getPackageJsonPath';\nimport { getLoader } from './bundleFile';\n\nexport type TranspileOptions = BuildOptions & {\n /**\n * Optional custom esbuild instance to use for transpilation.\n * Useful in environments (e.g. VS Code extensions) where the bundled\n * esbuild binary may not match the host platform.\n * When provided, its `buildSync`/`build` methods are used instead of\n * the ones imported from the `esbuild` package.\n */\n esbuildInstance?: typeof import('esbuild');\n};\n\nconst getTsConfigPath = (filePath: string): string | undefined => {\n const tsconfigPath = join(\n getPackageJsonPath(dirname(filePath)).baseDir,\n 'tsconfig.json'\n );\n\n // Only return the tsconfig path if it exists\n return existsSync(tsconfigPath) ? tsconfigPath : undefined;\n};\n\nconst getTransformationOptions = (filePath: string): BuildOptions => ({\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n '.md': 'text',\n '.mdx': 'text',\n },\n format: 'cjs',\n target: 'node20',\n platform: 'node',\n write: false,\n packages: 'external',\n bundle: true,\n tsconfig: getTsConfigPath(filePath),\n define: {\n 'import.meta.url': JSON.stringify(pathToFileURL(filePath).href),\n 'import.meta.env': 'process.env',\n },\n});\n\nexport const transpileTSToCJSSync = (\n code: string,\n filePath: string,\n options?: TranspileOptions\n): string | undefined => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const { esbuildInstance, ...buildOptions } = options ?? {};\n const esbuildBuildSync = esbuildInstance?.buildSync ?? buildSync;\n\n // esbuild's worker thread service calls `new Worker(__filename, …)` on first use.\n // In Vite's SSR module runner the SSR-optimised chunk is ESM and __filename is\n // never declared (confirmed: accessing it throws ReferenceError, not undefined).\n // Because there is no local declaration the bare `__filename` lookup falls\n // through to globalThis, so we set it there to esbuild's own CJS entry-point –\n // the exact path esbuild would use if it were loaded in a normal CJS context.\n //\n // IMPORTANT: We save/restore the globals so this temporary shim does not leak\n // to other Vite plugins (e.g. `@vitejs/plugin-react-swc`) that check\n // `typeof __dirname !== \"undefined\"` to locate their own assets.\n const g = globalThis as Record<string, unknown>;\n const hadFilename = typeof g.__filename === 'string';\n const prevFilename = g.__filename;\n const prevDirname = g.__dirname;\n\n if (!hadFilename) {\n try {\n const _require = createRequire(import.meta.url);\n const esbuildEntry = _require.resolve('esbuild');\n g.__filename = esbuildEntry;\n g.__dirname = dirname(esbuildEntry);\n } catch {\n // Best-effort: if esbuild can't be resolved the caller's catch handles it\n }\n }\n\n let moduleResult: BuildResult;\n try {\n moduleResult = esbuildBuildSync({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath), // Add resolveDir to resolve imports relative to the file's location\n sourcefile: filePath, // Add sourcefile for better error messages\n },\n ...getTransformationOptions(filePath),\n ...buildOptions,\n });\n } finally {\n // Always restore the previous values so the globals don't linger.\n if (!hadFilename) {\n if (prevFilename === undefined) {\n delete g.__filename;\n } else {\n g.__filename = prevFilename;\n }\n if (prevDirname === undefined) {\n delete g.__dirname;\n } else {\n g.__dirname = prevDirname;\n }\n }\n }\n\n const moduleResultString = moduleResult!.outputFiles?.[0]?.text;\n\n return moduleResultString;\n};\n\nexport const transpileTSToCJS = async (\n code: string,\n filePath: string,\n options?: TranspileOptions\n): Promise<string | undefined> => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const { esbuildInstance, ...buildOptions } = options ?? {};\n // Use context() + rebuild() + dispose() so esbuild deterministically releases\n // Go-subprocess resources for each one-shot transpilation, preventing them\n // from accumulating between rapid HMR-driven file changes.\n const esbuildContext = esbuildInstance?.context ?? context;\n\n const ctx = await esbuildContext({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath),\n sourcefile: filePath,\n },\n ...getTransformationOptions(filePath),\n ...buildOptions,\n });\n\n try {\n const moduleResult = await ctx.rebuild();\n return moduleResult.outputFiles?.[0].text;\n } finally {\n await ctx.dispose();\n }\n};\n"],"mappings":";;;;;;;;;;;AAwBA,MAAM,mBAAmB,aAAyC;CAChE,MAAM,mCACJA,2EAA2B,SAAS,CAAC,CAAC,SACtC,gBACD;AAGD,gCAAkB,aAAa,GAAG,eAAe;;AAGnD,MAAM,4BAA4B,cAAoC;CACpE,QAAQ;EACN,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,OAAO;EACP,QAAQ;EACT;CACD,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,OAAO;CACP,UAAU;CACV,QAAQ;CACR,UAAU,gBAAgB,SAAS;CACnC,QAAQ;EACN,mBAAmB,KAAK,sCAAwB,SAAS,CAAC,KAAK;EAC/D,mBAAmB;EACpB;CACF;AAED,MAAa,wBACX,MACA,UACA,YACuB;CAEvB,MAAM,SAASC,qEADW,SACQ,CAAC;CAEnC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB,WAAW,EAAE;CAC1D,MAAM,mBAAmB,iBAAiB,aAAaC;CAYvD,MAAM,IAAI;CACV,MAAM,cAAc,OAAO,EAAE,eAAe;CAC5C,MAAM,eAAe,EAAE;CACvB,MAAM,cAAc,EAAE;AAEtB,KAAI,CAAC,YACH,KAAI;EAEF,MAAM,4FAAuB,CAAC,QAAQ,UAAU;AAChD,IAAE,aAAa;AACf,IAAE,mCAAoB,aAAa;SAC7B;CAKV,IAAI;AACJ,KAAI;AACF,iBAAe,iBAAiB;GAC9B,OAAO;IACL,UAAU;IACV;IACA,mCAAoB,SAAS;IAC7B,YAAY;IACb;GACD,GAAG,yBAAyB,SAAS;GACrC,GAAG;GACJ,CAAC;WACM;AAER,MAAI,CAAC,aAAa;AAChB,OAAI,iBAAiB,OACnB,QAAO,EAAE;OAET,GAAE,aAAa;AAEjB,OAAI,gBAAgB,OAClB,QAAO,EAAE;OAET,GAAE,YAAY;;;AAOpB,QAF2B,aAAc,cAAc,IAAI;;AAK7D,MAAa,mBAAmB,OAC9B,MACA,UACA,YACgC;CAEhC,MAAM,SAASD,qEADW,SACQ,CAAC;CAEnC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB,WAAW,EAAE;CAM1D,MAAM,MAAM,OAFW,iBAAiB,WAAWE,iBAElB;EAC/B,OAAO;GACL,UAAU;GACV;GACA,mCAAoB,SAAS;GAC7B,YAAY;GACb;EACD,GAAG,yBAAyB,SAAS;EACrC,GAAG;EACJ,CAAC;AAEF,KAAI;AAEF,UAAO,MADoB,IAAI,SAAS,EACpB,cAAc,GAAG;WAC7B;AACR,QAAM,IAAI,SAAS"}
|
package/dist/cjs/logger.cjs
CHANGED
|
@@ -44,7 +44,7 @@ const getAppLogger = (configuration, globalDetails) => (content, details) => log
|
|
|
44
44
|
...details?.config ?? {}
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
const colorize = (string, color, reset) => color ? `${color}${string}${reset ? typeof reset === "boolean" ? require_colors.RESET : reset : require_colors.RESET}` : string;
|
|
47
|
+
const colorize = (string, color, reset) => color && typeof window === "undefined" ? `${color}${string}${reset ? typeof reset === "boolean" ? require_colors.RESET : reset : require_colors.RESET}` : string;
|
|
48
48
|
const colorizeLocales = (locales, color = require_colors.GREEN, reset = require_colors.RESET) => [locales].flat().map((locale) => colorize(locale, color, reset)).join(`, `);
|
|
49
49
|
const colorizeKey = (keyPath, color = require_colors.BEIGE, reset = require_colors.RESET) => [keyPath].flat().map((key) => colorize(key, color, reset)).join(`, `);
|
|
50
50
|
const colorizePath = (path, color = require_colors.GREY, reset = require_colors.RESET) => [path].flat().map((path) => colorize(path, color, reset)).join(`, `);
|
package/dist/cjs/logger.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.cjs","names":["RESET","GREEN","BEIGE","GREY","BLUE","GREY_DARK","WHITE","GREY_LIGHT","RED"],"sources":["../../src/logger.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type {\n CustomIntlayerConfig,\n IntlayerConfig,\n} from '@intlayer/types/config';\nimport type * as ANSIColorsTypes from './colors';\nimport {\n BEIGE,\n BLUE,\n GREEN,\n GREY,\n GREY_DARK,\n GREY_LIGHT,\n RED,\n RESET,\n WHITE,\n} from './colors';\n\nexport type ANSIColorsType =\n (typeof ANSIColorsTypes)[keyof typeof ANSIColorsTypes];\n\nexport type Details = {\n isVerbose?: boolean;\n level?: 'info' | 'warn' | 'error' | 'debug';\n config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nlet loggerPrefix: string | undefined;\n\nexport const setPrefix = (prefix: string | undefined) => {\n loggerPrefix = prefix;\n};\n\nexport const getPrefix = (configPrefix?: string): string | undefined => {\n if (typeof loggerPrefix !== 'undefined') {\n return loggerPrefix;\n }\n\n return configPrefix;\n};\n\nexport const logger: Logger = (content, details) => {\n const config = details?.config ?? {};\n const mode = config.mode ?? 'default';\n\n if (mode === 'disabled' || (details?.isVerbose && mode !== 'verbose')) return;\n\n const prefix = getPrefix(config.prefix);\n const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n const level = details?.level ?? 'info';\n\n const logMethod =\n config[level] ?? console[level] ?? config.log ?? console.log;\n\n logMethod(...flatContent);\n};\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n (configuration?: Pick<IntlayerConfig, 'log'>, globalDetails?: Details) =>\n (content: any, details?: Details) =>\n logger(content, {\n ...(details ?? {}),\n config: {\n ...configuration?.log,\n ...globalDetails?.config,\n ...(details?.config ?? {}),\n },\n });\n\nexport const colorize = (\n string: string,\n color?: ANSIColorsType,\n reset?: boolean | ANSIColorsType\n): string =>\n color\n ? `${color}${string}${reset ? (typeof reset === 'boolean' ? RESET : reset) : RESET}`\n : string;\n\nexport const colorizeLocales = (\n locales: Locale | Locale[],\n color: ANSIColorsType = GREEN,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [locales]\n .flat()\n .map((locale) => colorize(locale, color, reset))\n .join(`, `);\n\nexport const colorizeKey = (\n keyPath: string | string[],\n color: ANSIColorsType = BEIGE,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [keyPath]\n .flat()\n .map((key) => colorize(key, color, reset))\n .join(`, `);\n\nexport const colorizePath = (\n path: string | string[],\n color: ANSIColorsType = GREY,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [path]\n .flat()\n .map((path) => colorize(path, color, reset))\n .join(`, `);\n\nexport const colorizeNumber = (\n number: number | string,\n options: Partial<Record<Intl.LDMLPluralRule, ANSIColorsType>> = {\n zero: BLUE,\n one: BLUE,\n two: BLUE,\n few: BLUE,\n many: BLUE,\n other: BLUE,\n }\n): string => {\n if (number === 0 || number === '0') {\n const color = options.zero ?? GREEN;\n return colorize(number.toString(), color);\n }\n\n // Kept inside the function. Top-level instantiation of classes/APIs\n // is treated as a side-effect and prevents tree-shaking if the function is unused.\n const rule = new Intl.PluralRules('en').select(Number(number));\n const color = options[rule];\n return colorize(number.toString(), color);\n};\n\nexport const colorizeObject = (\n obj: any,\n indentLevel = 0,\n indentSize = 2,\n key?: string\n): string => {\n const indent = ' '.repeat(indentLevel * indentSize);\n const nextIndent = ' '.repeat((indentLevel + 1) * indentSize);\n\n if (obj === null) {\n return colorize('null', BLUE);\n }\n\n if (typeof obj === 'boolean') {\n return colorize(obj.toString(), BLUE);\n }\n\n if (typeof obj === 'number') {\n return colorize(obj.toString(), BLUE);\n }\n\n if (typeof obj === 'string') {\n const isDateString = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/.test(obj);\n const isUrl = obj.startsWith('http://') || obj.startsWith('https://');\n const isGlob = obj.includes('*') || obj.includes('?') || obj.includes('{');\n const isPath =\n obj.startsWith('/') ||\n obj.startsWith('./') ||\n obj.startsWith('../') ||\n /\\.[a-zA-Z0-9]{2,5}$/.test(obj);\n const isSecret =\n /^[0-9a-fA-F]{24,}$/.test(obj) || (obj.length >= 40 && !/\\s/.test(obj));\n const hasSpaces = /\\s/.test(obj);\n\n if (isDateString) return colorize(`\"${obj}\"`, BEIGE);\n if (isUrl) return colorize(`\"${obj}\"`, GREY_DARK);\n if (isGlob) return colorize(`\"${obj}\"`, GREY);\n if (isPath) return colorize(`\"${obj}\"`, GREY_DARK);\n if (isSecret) return colorize(`\"${obj}\"`, GREY);\n if (hasSpaces) return colorize(`\"${obj}\"`, WHITE);\n return colorize(`\"${obj}\"`, BLUE);\n }\n\n if (Array.isArray(obj)) {\n if (obj.length === 0) {\n return '[]';\n }\n const items = obj\n .map(\n (item) =>\n `${nextIndent}${colorizeObject(item, indentLevel + 1, indentSize, key)}`\n )\n .join(',\\n');\n return `[\\n${items}\\n${indent}]`;\n }\n\n if (typeof obj === 'object') {\n const keys = Object.keys(obj);\n\n if (keys.length === 0) {\n return '{}';\n }\n\n const fields = keys\n .map((key) => {\n const coloredKey = colorize(`\"${key}\"`, GREY_LIGHT);\n const value = obj[key];\n const coloredValue = colorizeObject(\n value,\n indentLevel + 1,\n indentSize,\n key\n );\n return `${nextIndent}${coloredKey}: ${coloredValue}`;\n })\n .join(',\\n');\n return `{\\n${fields}\\n${indent}}`;\n }\n\n return colorize(String(obj), GREY);\n};\n\nexport const removeColor = (text: string) =>\n // biome-ignore lint/suspicious/noControlCharactersInRegex: we need to remove the color codes\n text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n let value: number = 0;\n if (typeof length === 'number') {\n value = length;\n }\n if (typeof length === 'string') {\n value = length.length;\n }\n if (\n Array.isArray(length) &&\n length.every((locale) => typeof locale === 'string')\n ) {\n value = Math.max(...length.map((str) => str.length));\n }\n if (\n Array.isArray(length) &&\n length.every((locale) => typeof locale === 'number')\n ) {\n value = Math.max(...length);\n }\n return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n colSize: 0,\n minSize: 0,\n maxSize: Infinity,\n pad: 'right',\n padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n text: string | string[],\n options?: {\n colSize?: number | number[] | string | string[];\n minSize?: number;\n maxSize?: number;\n pad?: 'left' | 'right';\n padChar?: string;\n }\n): string =>\n [text]\n .flat()\n .map((text) => {\n const { colSize, minSize, maxSize, pad } = {\n ...defaultColonOptions,\n ...(options ?? {}),\n };\n\n const length = getLength(colSize);\n const spacesLength = Math.max(\n minSize!,\n Math.min(maxSize!, length - removeColor(text).length)\n );\n\n if (pad === 'left') {\n return `${' '.repeat(spacesLength)}${text}`;\n }\n\n return `${text}${' '.repeat(spacesLength)}`;\n })\n .join('');\n\nexport const x = colorize('✗', RED);\nexport const v = colorize('✓', GREEN);\nexport const clock = colorize('⏲', BLUE);\n"],"mappings":";;;;AA6BA,IAAI;AAEJ,MAAa,aAAa,WAA+B;AACvD,gBAAe;;AAGjB,MAAa,aAAa,iBAA8C;AACtE,KAAI,OAAO,iBAAiB,YAC1B,QAAO;AAGT,QAAO;;AAGT,MAAa,UAAkB,SAAS,YAAY;CAClD,MAAM,SAAS,SAAS,UAAU,EAAE;CACpC,MAAM,OAAO,OAAO,QAAQ;AAE5B,KAAI,SAAS,cAAe,SAAS,aAAa,SAAS,UAAY;CAEvE,MAAM,SAAS,UAAU,OAAO,OAAO;CACvC,MAAM,cAAc,SAAS,CAAC,QAAQ,GAAG,CAAC,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,SAAS;CACb,MAAM,EAAE,SAAS,SAAS,SAAS,QAAQ;EACzC,GAAG;EACH,GAAI,WAAW,EAAE;EAClB;CAED,MAAM,SAAS,UAAU,QAAQ;CACjC,MAAM,eAAe,KAAK,IACxB,SACA,KAAK,IAAI,SAAU,SAAS,YAAY,KAAK,CAAC,OAAO,CACtD;AAED,KAAI,QAAQ,OACV,QAAO,GAAG,IAAI,OAAO,aAAa,GAAG;AAGvC,QAAO,GAAG,OAAO,IAAI,OAAO,aAAa;EACzC,CACD,KAAK,GAAG;AAEb,MAAa,IAAI,SAAS,KAAKK,mBAAI;AACnC,MAAa,IAAI,SAAS,KAAKP,qBAAM;AACrC,MAAa,QAAQ,SAAS,KAAKG,oBAAK"}
|
|
1
|
+
{"version":3,"file":"logger.cjs","names":["RESET","GREEN","BEIGE","GREY","BLUE","GREY_DARK","WHITE","GREY_LIGHT","RED"],"sources":["../../src/logger.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type {\n CustomIntlayerConfig,\n IntlayerConfig,\n} from '@intlayer/types/config';\nimport type * as ANSIColorsTypes from './colors';\nimport {\n BEIGE,\n BLUE,\n GREEN,\n GREY,\n GREY_DARK,\n GREY_LIGHT,\n RED,\n RESET,\n WHITE,\n} from './colors';\n\nexport type ANSIColorsType =\n (typeof ANSIColorsTypes)[keyof typeof ANSIColorsTypes];\n\nexport type Details = {\n isVerbose?: boolean;\n level?: 'info' | 'warn' | 'error' | 'debug';\n config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nlet loggerPrefix: string | undefined;\n\nexport const setPrefix = (prefix: string | undefined) => {\n loggerPrefix = prefix;\n};\n\nexport const getPrefix = (configPrefix?: string): string | undefined => {\n if (typeof loggerPrefix !== 'undefined') {\n return loggerPrefix;\n }\n\n return configPrefix;\n};\n\nexport const logger: Logger = (content, details) => {\n const config = details?.config ?? {};\n const mode = config.mode ?? 'default';\n\n if (mode === 'disabled' || (details?.isVerbose && mode !== 'verbose')) return;\n\n const prefix = getPrefix(config.prefix);\n const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n const level = details?.level ?? 'info';\n\n const logMethod =\n config[level] ?? console[level] ?? config.log ?? console.log;\n\n logMethod(...flatContent);\n};\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n (configuration?: Pick<IntlayerConfig, 'log'>, globalDetails?: Details) =>\n (content: any, details?: Details) =>\n logger(content, {\n ...(details ?? {}),\n config: {\n ...configuration?.log,\n ...globalDetails?.config,\n ...(details?.config ?? {}),\n },\n });\n\nexport const colorize = (\n string: string,\n color?: ANSIColorsType,\n reset?: boolean | ANSIColorsType\n): string =>\n color && typeof window === 'undefined'\n ? `${color}${string}${reset ? (typeof reset === 'boolean' ? RESET : reset) : RESET}`\n : string;\n\nexport const colorizeLocales = (\n locales: Locale | Locale[],\n color: ANSIColorsType = GREEN,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [locales]\n .flat()\n .map((locale) => colorize(locale, color, reset))\n .join(`, `);\n\nexport const colorizeKey = (\n keyPath: string | string[],\n color: ANSIColorsType = BEIGE,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [keyPath]\n .flat()\n .map((key) => colorize(key, color, reset))\n .join(`, `);\n\nexport const colorizePath = (\n path: string | string[],\n color: ANSIColorsType = GREY,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [path]\n .flat()\n .map((path) => colorize(path, color, reset))\n .join(`, `);\n\nexport const colorizeNumber = (\n number: number | string,\n options: Partial<Record<Intl.LDMLPluralRule, ANSIColorsType>> = {\n zero: BLUE,\n one: BLUE,\n two: BLUE,\n few: BLUE,\n many: BLUE,\n other: BLUE,\n }\n): string => {\n if (number === 0 || number === '0') {\n const color = options.zero ?? GREEN;\n return colorize(number.toString(), color);\n }\n\n // Kept inside the function. Top-level instantiation of classes/APIs\n // is treated as a side-effect and prevents tree-shaking if the function is unused.\n const rule = new Intl.PluralRules('en').select(Number(number));\n const color = options[rule];\n return colorize(number.toString(), color);\n};\n\nexport const colorizeObject = (\n obj: any,\n indentLevel = 0,\n indentSize = 2,\n key?: string\n): string => {\n const indent = ' '.repeat(indentLevel * indentSize);\n const nextIndent = ' '.repeat((indentLevel + 1) * indentSize);\n\n if (obj === null) {\n return colorize('null', BLUE);\n }\n\n if (typeof obj === 'boolean') {\n return colorize(obj.toString(), BLUE);\n }\n\n if (typeof obj === 'number') {\n return colorize(obj.toString(), BLUE);\n }\n\n if (typeof obj === 'string') {\n const isDateString = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/.test(obj);\n const isUrl = obj.startsWith('http://') || obj.startsWith('https://');\n const isGlob = obj.includes('*') || obj.includes('?') || obj.includes('{');\n const isPath =\n obj.startsWith('/') ||\n obj.startsWith('./') ||\n obj.startsWith('../') ||\n /\\.[a-zA-Z0-9]{2,5}$/.test(obj);\n const isSecret =\n /^[0-9a-fA-F]{24,}$/.test(obj) || (obj.length >= 40 && !/\\s/.test(obj));\n const hasSpaces = /\\s/.test(obj);\n\n if (isDateString) return colorize(`\"${obj}\"`, BEIGE);\n if (isUrl) return colorize(`\"${obj}\"`, GREY_DARK);\n if (isGlob) return colorize(`\"${obj}\"`, GREY);\n if (isPath) return colorize(`\"${obj}\"`, GREY_DARK);\n if (isSecret) return colorize(`\"${obj}\"`, GREY);\n if (hasSpaces) return colorize(`\"${obj}\"`, WHITE);\n return colorize(`\"${obj}\"`, BLUE);\n }\n\n if (Array.isArray(obj)) {\n if (obj.length === 0) {\n return '[]';\n }\n const items = obj\n .map(\n (item) =>\n `${nextIndent}${colorizeObject(item, indentLevel + 1, indentSize, key)}`\n )\n .join(',\\n');\n return `[\\n${items}\\n${indent}]`;\n }\n\n if (typeof obj === 'object') {\n const keys = Object.keys(obj);\n\n if (keys.length === 0) {\n return '{}';\n }\n\n const fields = keys\n .map((key) => {\n const coloredKey = colorize(`\"${key}\"`, GREY_LIGHT);\n const value = obj[key];\n const coloredValue = colorizeObject(\n value,\n indentLevel + 1,\n indentSize,\n key\n );\n return `${nextIndent}${coloredKey}: ${coloredValue}`;\n })\n .join(',\\n');\n return `{\\n${fields}\\n${indent}}`;\n }\n\n return colorize(String(obj), GREY);\n};\n\nexport const removeColor = (text: string) =>\n // biome-ignore lint/suspicious/noControlCharactersInRegex: we need to remove the color codes\n text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n let value: number = 0;\n if (typeof length === 'number') {\n value = length;\n }\n if (typeof length === 'string') {\n value = length.length;\n }\n if (\n Array.isArray(length) &&\n length.every((locale) => typeof locale === 'string')\n ) {\n value = Math.max(...length.map((str) => str.length));\n }\n if (\n Array.isArray(length) &&\n length.every((locale) => typeof locale === 'number')\n ) {\n value = Math.max(...length);\n }\n return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n colSize: 0,\n minSize: 0,\n maxSize: Infinity,\n pad: 'right',\n padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n text: string | string[],\n options?: {\n colSize?: number | number[] | string | string[];\n minSize?: number;\n maxSize?: number;\n pad?: 'left' | 'right';\n padChar?: string;\n }\n): string =>\n [text]\n .flat()\n .map((text) => {\n const { colSize, minSize, maxSize, pad } = {\n ...defaultColonOptions,\n ...(options ?? {}),\n };\n\n const length = getLength(colSize);\n const spacesLength = Math.max(\n minSize!,\n Math.min(maxSize!, length - removeColor(text).length)\n );\n\n if (pad === 'left') {\n return `${' '.repeat(spacesLength)}${text}`;\n }\n\n return `${text}${' '.repeat(spacesLength)}`;\n })\n .join('');\n\nexport const x = colorize('✗', RED);\nexport const v = colorize('✓', GRE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,MAAM,QAAQ,OAAO,IACrB,OAAO,OAAO,WAAW,OAAO,WAAW,SAAS,CAEpD,SAAQ,KAAK,IAAI,GAAG,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC;AAEtD,KACE,MAAM,QAAQ,OAAO,IACrB,OAAO,OAAO,WAAW,OAAO,WAAW,SAAS,CAEpD,SAAQ,KAAK,IAAI,GAAG,OAAO;AAE7B,QAAO,KAAK,IAAI,OAAO,EAAE;;AAG3B,MAAM,sBAAsB;CAC1B,SAAS;CACT,SAAS;CACT,SAAS;CACT,KAAK;CACL,SAAS;CACV;;;;;;;AAQD,MAAa,SACX,MACA,YAQA,CAAC,KAAK,CACH,MAAM,CACN,KAAK,SAAS;CACb,MAAM,EAAE,SAAS,SAAS,SAAS,QAAQ;EACzC,GAAG;EACH,GAAI,WAAW,EAAE;EAClB;CAED,MAAM,SAAS,UAAU,QAAQ;CACjC,MAAM,eAAe,KAAK,IACxB,SACA,KAAK,IAAI,SAAU,SAAS,YAAY,KAAK,CAAC,OAAO,CACtD;AAED,KAAI,QAAQ,OACV,QAAO,GAAG,IAAI,OAAO,aAAa,GAAG;AAGvC,QAAO,GAAG,OAAO,IAAI,OAAO,aAAa;EACzC,CACD,KAAK,GAAG;AAEb,MAAa,IAAI,SAAS,KAAKK,mBAAI;AACnC,MAAa,IAAI,SAAS,KAAKP,qBAAM;AACrC,MAAa,QAAQ,SAAS,KAAKG,oBAAK"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/utils/getDictionarySelectorUsage.ts
|
|
4
|
+
/**
|
|
5
|
+
* Detects whether any built dictionary declares qualifier dimensions
|
|
6
|
+
* (collections, variants or meta records).
|
|
7
|
+
*
|
|
8
|
+
* The merge step emits a {@link QualifiedDictionaryGroup} — carrying a
|
|
9
|
+
* non-empty `qualifierTypes` array — for every key whose declarations use a
|
|
10
|
+
* selector. When no group is present, the selector-object resolution path in
|
|
11
|
+
* `getIntlayer` / `useIntlayer` is dead code, and bundlers can eliminate it via
|
|
12
|
+
* the `INTLAYER_DICTIONARY_SELECTOR` env var.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* getHasDictionarySelector(getDictionaries(config));
|
|
16
|
+
* // true → at least one collection / variant / meta dictionary
|
|
17
|
+
* // false → only plain dictionaries (selector logic can be stripped)
|
|
18
|
+
*/
|
|
19
|
+
const getHasDictionarySelector = (dictionaries) => {
|
|
20
|
+
return (Array.isArray(dictionaries) ? dictionaries : Object.values(dictionaries)).some((dictionary) => {
|
|
21
|
+
const { qualifierTypes } = dictionary;
|
|
22
|
+
return Array.isArray(qualifierTypes) && qualifierTypes.length > 0;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.getHasDictionarySelector = getHasDictionarySelector;
|
|
28
|
+
//# sourceMappingURL=getDictionarySelectorUsage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDictionarySelectorUsage.cjs","names":[],"sources":["../../../src/utils/getDictionarySelectorUsage.ts"],"sourcesContent":["import type {\n Dictionary,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\n\ntype DictionaryOrGroup = Dictionary | QualifiedDictionaryGroup;\n\n/**\n * Detects whether any built dictionary declares qualifier dimensions\n * (collections, variants or meta records).\n *\n * The merge step emits a {@link QualifiedDictionaryGroup} — carrying a\n * non-empty `qualifierTypes` array — for every key whose declarations use a\n * selector. When no group is present, the selector-object resolution path in\n * `getIntlayer` / `useIntlayer` is dead code, and bundlers can eliminate it via\n * the `INTLAYER_DICTIONARY_SELECTOR` env var.\n *\n * @example\n * getHasDictionarySelector(getDictionaries(config));\n * // true → at least one collection / variant / meta dictionary\n * // false → only plain dictionaries (selector logic can be stripped)\n */\nexport const getHasDictionarySelector = (\n dictionaries: Record<string, DictionaryOrGroup> | DictionaryOrGroup[]\n): boolean => {\n const dictionariesArray = Array.isArray(dictionaries)\n ? dictionaries\n : Object.values(dictionaries);\n\n return dictionariesArray.some((dictionary) => {\n const { qualifierTypes } = dictionary as QualifiedDictionaryGroup;\n\n return Array.isArray(qualifierTypes) && qualifierTypes.length > 0;\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,MAAa,4BACX,iBACY;AAKZ,SAJ0B,MAAM,QAAQ,aAAa,GACjD,eACA,OAAO,OAAO,aAAa,EAEN,MAAM,eAAe;EAC5C,MAAM,EAAE,mBAAmB;AAE3B,SAAO,MAAM,QAAQ,eAAe,IAAI,eAAe,SAAS;GAChE"}
|
package/dist/cjs/utils/index.cjs
CHANGED
|
@@ -9,6 +9,7 @@ const require_utils_ESMxCJSHelpers = require('./ESMxCJSHelpers.cjs');
|
|
|
9
9
|
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
|
+
const require_utils_getDictionarySelectorUsage = require('./getDictionarySelectorUsage.cjs');
|
|
12
13
|
const require_utils_getStorageAttributes = require('./getStorageAttributes.cjs');
|
|
13
14
|
const require_utils_getUsedNodeTypes = require('./getUsedNodeTypes.cjs');
|
|
14
15
|
const require_utils_logStack = require('./logStack.cjs');
|
|
@@ -37,6 +38,7 @@ exports.extractErrorMessage = require_utils_extractErrorMessage.extractErrorMess
|
|
|
37
38
|
exports.getAlias = require_utils_alias.getAlias;
|
|
38
39
|
exports.getCache = require_utils_cacheMemory.getCache;
|
|
39
40
|
exports.getExtension = require_utils_getExtension.getExtension;
|
|
41
|
+
exports.getHasDictionarySelector = require_utils_getDictionarySelectorUsage.getHasDictionarySelector;
|
|
40
42
|
exports.getPackageJsonPath = require_utils_getPackageJsonPath.getPackageJsonPath;
|
|
41
43
|
exports.getProjectRequire = require_utils_ESMxCJSHelpers.getProjectRequire;
|
|
42
44
|
exports.getStorageAttributes = require_utils_getStorageAttributes.getStorageAttributes;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getAlias } from "../utils/alias.mjs";
|
|
2
2
|
import { getConfiguration } from "../configFile/getConfiguration.mjs";
|
|
3
|
-
import { BundleLogger } from "./logBundle.mjs";
|
|
4
3
|
import { getConfigEnvVars } from "../envVars/envVars.mjs";
|
|
4
|
+
import { BundleLogger } from "./logBundle.mjs";
|
|
5
5
|
import { isAbsolute, join, resolve } from "node:path";
|
|
6
6
|
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
7
7
|
import packageJSON from "@intlayer/types/package.json" with { type: "json" };
|
|
@@ -24,6 +24,25 @@ const formatNodeTypeToEnvVar = (nodeTypes, wrapKey = (key) => key, wrapValue = (
|
|
|
24
24
|
return acc;
|
|
25
25
|
}, {});
|
|
26
26
|
/**
|
|
27
|
+
* Returns the env-var definition disabling the dictionary-selector resolution
|
|
28
|
+
* path (collections, variants, meta records) when no built dictionary declares
|
|
29
|
+
* a qualifier. Set to `"false"` so bundlers can dead-code-eliminate the
|
|
30
|
+
* selector branch in `getIntlayer` / `useIntlayer`.
|
|
31
|
+
*
|
|
32
|
+
* Emits nothing when selectors are used, leaving the runtime default in place.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* formatDictionarySelectorEnvVar(false)
|
|
36
|
+
* // { INTLAYER_DICTIONARY_SELECTOR: '"false"' }
|
|
37
|
+
*
|
|
38
|
+
* formatDictionarySelectorEnvVar(true)
|
|
39
|
+
* // {}
|
|
40
|
+
*
|
|
41
|
+
* formatDictionarySelectorEnvVar(false, (k) => `process.env.${k}`, (v) => `"${v}"`)
|
|
42
|
+
* // { 'process.env.INTLAYER_DICTIONARY_SELECTOR': '"false"' }
|
|
43
|
+
*/
|
|
44
|
+
const formatDictionarySelectorEnvVar = (hasDictionarySelector, wrapKey = (key) => key, wrapValue = (value) => value) => hasDictionarySelector ? {} : { [wrapKey("INTLAYER_DICTIONARY_SELECTOR")]: wrapValue("false") };
|
|
45
|
+
/**
|
|
27
46
|
* Returns env-var definitions for the full Intlayer config to be injected at
|
|
28
47
|
* build time. Allows bundlers to dead-code-eliminate unused routing modes,
|
|
29
48
|
* rewrite logic, storage mechanisms, and editor code.
|
|
@@ -49,5 +68,5 @@ const getConfigEnvVars = (config, wrapKey = (key) => key, wrapValue = (value) =>
|
|
|
49
68
|
};
|
|
50
69
|
|
|
51
70
|
//#endregion
|
|
52
|
-
export { formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
71
|
+
export { formatDictionarySelectorEnvVar, formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
53
72
|
//# sourceMappingURL=envVars.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envVars.mjs","names":[],"sources":["../../../src/envVars/envVars.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\n\n/**\n * Converts a camelCase node-type string to SCREAMING_SNAKE_CASE so that\n * the generated env-var name matches what the plugin source files check.\n *\n * @example\n * toScreamingSnakeCase('reactNode') // 'REACT_NODE'\n * toScreamingSnakeCase('markdown') // 'MARKDOWN'\n */\nconst toScreamingSnakeCase = (str: string): string =>\n str\n .replace(/([A-Z])/g, '_$1')\n .toUpperCase()\n .replace(/^_/, ''); // strip any leading underscore\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(['reactNode'], (k) => `process.env.${k}`, (v) => `\"${v}\"`)\n * // { 'process.env.INTLAYER_NODE_TYPE_REACT_NODE': '\"false\"' }\n */\nexport const formatNodeTypeToEnvVar = (\n nodeTypes: string[],\n wrapKey = (key: string) => key,\n wrapValue = (value: string) => value\n): Record<string, string> =>\n nodeTypes.reduce(\n (acc, nodeType) => {\n acc[wrapKey(`INTLAYER_NODE_TYPE_${toScreamingSnakeCase(nodeType)}`)] =\n wrapValue('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 wrapKey = (key: string) => key,\n wrapValue = (value: string) => value\n): Record<string, string> => {\n const { routing, editor } = config;\n\n const envVars: Record<string, string> = {\n [wrapKey('INTLAYER_ROUTING_MODE')]: wrapValue(routing.mode),\n };\n\n if (!routing.rewrite) {\n envVars[wrapKey('INTLAYER_ROUTING_REWRITE_RULES')] = wrapValue('false');\n }\n\n if (!routing.domains || Object.keys(routing.domains).length === 0) {\n envVars[wrapKey('INTLAYER_ROUTING_DOMAINS')] = wrapValue('false');\n }\n\n if (!routing.storage.cookies || routing.storage.cookies.length === 0) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_COOKIES')] = wrapValue('false');\n }\n\n if (\n !routing.storage.localStorage ||\n routing.storage.localStorage.length === 0\n ) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_LOCALSTORAGE')] =\n wrapValue('false');\n }\n\n if (\n !routing.storage.sessionStorage ||\n routing.storage.sessionStorage.length === 0\n ) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE')] =\n wrapValue('false');\n }\n\n if (!routing.storage.headers || routing.storage.headers.length === 0) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_HEADERS')] = wrapValue('false');\n }\n\n if (editor?.enabled === false) {\n envVars[wrapKey('INTLAYER_EDITOR_ENABLED')] = wrapValue('false');\n }\n\n return envVars;\n};\n"],"mappings":";;;;;;;;;AAUA,MAAM,wBAAwB,QAC5B,IACG,QAAQ,YAAY,MAAM,CAC1B,aAAa,CACb,QAAQ,MAAM,GAAG;;;;;;;;;;;;AAatB,MAAa,0BACX,WACA,WAAW,QAAgB,KAC3B,aAAa,UAAkB,UAE/B,UAAU,QACP,KAAK,aAAa;AACjB,KAAI,QAAQ,sBAAsB,qBAAqB,SAAS,GAAG,IACjE,UAAU,QAAQ;AACpB,QAAO;GAET,EAAE,CACH;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"envVars.mjs","names":[],"sources":["../../../src/envVars/envVars.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\n\n/**\n * Converts a camelCase node-type string to SCREAMING_SNAKE_CASE so that\n * the generated env-var name matches what the plugin source files check.\n *\n * @example\n * toScreamingSnakeCase('reactNode') // 'REACT_NODE'\n * toScreamingSnakeCase('markdown') // 'MARKDOWN'\n */\nconst toScreamingSnakeCase = (str: string): string =>\n str\n .replace(/([A-Z])/g, '_$1')\n .toUpperCase()\n .replace(/^_/, ''); // strip any leading underscore\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(['reactNode'], (k) => `process.env.${k}`, (v) => `\"${v}\"`)\n * // { 'process.env.INTLAYER_NODE_TYPE_REACT_NODE': '\"false\"' }\n */\nexport const formatNodeTypeToEnvVar = (\n nodeTypes: string[],\n wrapKey = (key: string) => key,\n wrapValue = (value: string) => value\n): Record<string, string> =>\n nodeTypes.reduce(\n (acc, nodeType) => {\n acc[wrapKey(`INTLAYER_NODE_TYPE_${toScreamingSnakeCase(nodeType)}`)] =\n wrapValue('false');\n return acc;\n },\n {} as Record<string, string>\n );\n\n/**\n * Returns the env-var definition disabling the dictionary-selector resolution\n * path (collections, variants, meta records) when no built dictionary declares\n * a qualifier. Set to `\"false\"` so bundlers can dead-code-eliminate the\n * selector branch in `getIntlayer` / `useIntlayer`.\n *\n * Emits nothing when selectors are used, leaving the runtime default in place.\n *\n * @example\n * formatDictionarySelectorEnvVar(false)\n * // { INTLAYER_DICTIONARY_SELECTOR: '\"false\"' }\n *\n * formatDictionarySelectorEnvVar(true)\n * // {}\n *\n * formatDictionarySelectorEnvVar(false, (k) => `process.env.${k}`, (v) => `\"${v}\"`)\n * // { 'process.env.INTLAYER_DICTIONARY_SELECTOR': '\"false\"' }\n */\nexport const formatDictionarySelectorEnvVar = (\n hasDictionarySelector: boolean,\n wrapKey = (key: string) => key,\n wrapValue = (value: string) => value\n): Record<string, string> =>\n hasDictionarySelector\n ? {}\n : { [wrapKey('INTLAYER_DICTIONARY_SELECTOR')]: wrapValue('false') };\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 wrapKey = (key: string) => key,\n wrapValue = (value: string) => value\n): Record<string, string> => {\n const { routing, editor } = config;\n\n const envVars: Record<string, string> = {\n [wrapKey('INTLAYER_ROUTING_MODE')]: wrapValue(routing.mode),\n };\n\n if (!routing.rewrite) {\n envVars[wrapKey('INTLAYER_ROUTING_REWRITE_RULES')] = wrapValue('false');\n }\n\n if (!routing.domains || Object.keys(routing.domains).length === 0) {\n envVars[wrapKey('INTLAYER_ROUTING_DOMAINS')] = wrapValue('false');\n }\n\n if (!routing.storage.cookies || routing.storage.cookies.length === 0) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_COOKIES')] = wrapValue('false');\n }\n\n if (\n !routing.storage.localStorage ||\n routing.storage.localStorage.length === 0\n ) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_LOCALSTORAGE')] =\n wrapValue('false');\n }\n\n if (\n !routing.storage.sessionStorage ||\n routing.storage.sessionStorage.length === 0\n ) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE')] =\n wrapValue('false');\n }\n\n if (!routing.storage.headers || routing.storage.headers.length === 0) {\n envVars[wrapKey('INTLAYER_ROUTING_STORAGE_HEADERS')] = wrapValue('false');\n }\n\n if (editor?.enabled === false) {\n envVars[wrapKey('INTLAYER_EDITOR_ENABLED')] = wrapValue('false');\n }\n\n return envVars;\n};\n"],"mappings":";;;;;;;;;AAUA,MAAM,wBAAwB,QAC5B,IACG,QAAQ,YAAY,MAAM,CAC1B,aAAa,CACb,QAAQ,MAAM,GAAG;;;;;;;;;;;;AAatB,MAAa,0BACX,WACA,WAAW,QAAgB,KAC3B,aAAa,UAAkB,UAE/B,UAAU,QACP,KAAK,aAAa;AACjB,KAAI,QAAQ,sBAAsB,qBAAqB,SAAS,GAAG,IACjE,UAAU,QAAQ;AACpB,QAAO;GAET,EAAE,CACH;;;;;;;;;;;;;;;;;;;AAoBH,MAAa,kCACX,uBACA,WAAW,QAAgB,KAC3B,aAAa,UAAkB,UAE/B,wBACI,EAAE,GACF,GAAG,QAAQ,+BAA+B,GAAG,UAAU,QAAQ,EAAE;;;;;;;;;;;;;AAcvE,MAAa,oBACX,QACA,WAAW,QAAgB,KAC3B,aAAa,UAAkB,UACJ;CAC3B,MAAM,EAAE,SAAS,WAAW;CAE5B,MAAM,UAAkC,GACrC,QAAQ,wBAAwB,GAAG,UAAU,QAAQ,KAAK,EAC5D;AAED,KAAI,CAAC,QAAQ,QACX,SAAQ,QAAQ,iCAAiC,IAAI,UAAU,QAAQ;AAGzE,KAAI,CAAC,QAAQ,WAAW,OAAO,KAAK,QAAQ,QAAQ,CAAC,WAAW,EAC9D,SAAQ,QAAQ,2BAA2B,IAAI,UAAU,QAAQ;AAGnE,KAAI,CAAC,QAAQ,QAAQ,WAAW,QAAQ,QAAQ,QAAQ,WAAW,EACjE,SAAQ,QAAQ,mCAAmC,IAAI,UAAU,QAAQ;AAG3E,KACE,CAAC,QAAQ,QAAQ,gBACjB,QAAQ,QAAQ,aAAa,WAAW,EAExC,SAAQ,QAAQ,wCAAwC,IACtD,UAAU,QAAQ;AAGtB,KACE,CAAC,QAAQ,QAAQ,kBACjB,QAAQ,QAAQ,eAAe,WAAW,EAE1C,SAAQ,QAAQ,0CAA0C,IACxD,UAAU,QAAQ;AAGtB,KAAI,CAAC,QAAQ,QAAQ,WAAW,QAAQ,QAAQ,QAAQ,WAAW,EACjE,SAAQ,QAAQ,mCAAmC,IAAI,UAAU,QAAQ;AAG3E,KAAI,QAAQ,YAAY,MACtB,SAAQ,QAAQ,0BAA0B,IAAI,UAAU,QAAQ;AAGlE,QAAO"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { formatNodeTypeToEnvVar, getConfigEnvVars } from "./envVars.mjs";
|
|
1
|
+
import { formatDictionarySelectorEnvVar, formatNodeTypeToEnvVar, getConfigEnvVars } from "./envVars.mjs";
|
|
2
2
|
|
|
3
|
-
export { formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
3
|
+
export { formatDictionarySelectorEnvVar, formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
@@ -39,21 +39,36 @@ const transpileTSToCJSSync = (code, filePath, options) => {
|
|
|
39
39
|
const loader = getLoader(extname(filePath));
|
|
40
40
|
const { esbuildInstance, ...buildOptions } = options ?? {};
|
|
41
41
|
const esbuildBuildSync = esbuildInstance?.buildSync ?? buildSync;
|
|
42
|
-
|
|
42
|
+
const g = globalThis;
|
|
43
|
+
const hadFilename = typeof g.__filename === "string";
|
|
44
|
+
const prevFilename = g.__filename;
|
|
45
|
+
const prevDirname = g.__dirname;
|
|
46
|
+
if (!hadFilename) try {
|
|
43
47
|
const esbuildEntry = createRequire(import.meta.url).resolve("esbuild");
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
g.__filename = esbuildEntry;
|
|
49
|
+
g.__dirname = dirname(esbuildEntry);
|
|
46
50
|
} catch {}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
let moduleResult;
|
|
52
|
+
try {
|
|
53
|
+
moduleResult = esbuildBuildSync({
|
|
54
|
+
stdin: {
|
|
55
|
+
contents: code,
|
|
56
|
+
loader,
|
|
57
|
+
resolveDir: dirname(filePath),
|
|
58
|
+
sourcefile: filePath
|
|
59
|
+
},
|
|
60
|
+
...getTransformationOptions(filePath),
|
|
61
|
+
...buildOptions
|
|
62
|
+
});
|
|
63
|
+
} finally {
|
|
64
|
+
if (!hadFilename) {
|
|
65
|
+
if (prevFilename === void 0) delete g.__filename;
|
|
66
|
+
else g.__filename = prevFilename;
|
|
67
|
+
if (prevDirname === void 0) delete g.__dirname;
|
|
68
|
+
else g.__dirname = prevDirname;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return moduleResult.outputFiles?.[0]?.text;
|
|
57
72
|
};
|
|
58
73
|
const transpileTSToCJS = async (code, filePath, options) => {
|
|
59
74
|
const loader = getLoader(extname(filePath));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpileTSToCJS.mjs","names":[],"sources":["../../../src/loadExternalFile/transpileTSToCJS.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, extname, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport {\n type BuildOptions,\n type BuildResult,\n buildSync,\n context,\n} from 'esbuild';\nimport { getPackageJsonPath } from '../utils/getPackageJsonPath';\nimport { getLoader } from './bundleFile';\n\nexport type TranspileOptions = BuildOptions & {\n /**\n * Optional custom esbuild instance to use for transpilation.\n * Useful in environments (e.g. VS Code extensions) where the bundled\n * esbuild binary may not match the host platform.\n * When provided, its `buildSync`/`build` methods are used instead of\n * the ones imported from the `esbuild` package.\n */\n esbuildInstance?: typeof import('esbuild');\n};\n\nconst getTsConfigPath = (filePath: string): string | undefined => {\n const tsconfigPath = join(\n getPackageJsonPath(dirname(filePath)).baseDir,\n 'tsconfig.json'\n );\n\n // Only return the tsconfig path if it exists\n return existsSync(tsconfigPath) ? tsconfigPath : undefined;\n};\n\nconst getTransformationOptions = (filePath: string): BuildOptions => ({\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n '.md': 'text',\n '.mdx': 'text',\n },\n format: 'cjs',\n target: 'node20',\n platform: 'node',\n write: false,\n packages: 'external',\n bundle: true,\n tsconfig: getTsConfigPath(filePath),\n define: {\n 'import.meta.url': JSON.stringify(pathToFileURL(filePath).href),\n 'import.meta.env': 'process.env',\n },\n});\n\nexport const transpileTSToCJSSync = (\n code: string,\n filePath: string,\n options?: TranspileOptions\n): string | undefined => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const { esbuildInstance, ...buildOptions } = options ?? {};\n const esbuildBuildSync = esbuildInstance?.buildSync ?? buildSync;\n\n // esbuild's worker thread service calls `new Worker(__filename, …)` on first use.\n // In Vite's SSR module runner the SSR-optimised chunk is ESM and __filename is\n // never declared (confirmed: accessing it throws ReferenceError, not undefined).\n // Because there is no local declaration the bare `__filename` lookup falls\n // through to globalThis, so we set it there to esbuild's own CJS entry-point –\n // the exact path esbuild would use if it were loaded in a normal CJS context.\n
|
|
1
|
+
{"version":3,"file":"transpileTSToCJS.mjs","names":[],"sources":["../../../src/loadExternalFile/transpileTSToCJS.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, extname, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport {\n type BuildOptions,\n type BuildResult,\n buildSync,\n context,\n} from 'esbuild';\nimport { getPackageJsonPath } from '../utils/getPackageJsonPath';\nimport { getLoader } from './bundleFile';\n\nexport type TranspileOptions = BuildOptions & {\n /**\n * Optional custom esbuild instance to use for transpilation.\n * Useful in environments (e.g. VS Code extensions) where the bundled\n * esbuild binary may not match the host platform.\n * When provided, its `buildSync`/`build` methods are used instead of\n * the ones imported from the `esbuild` package.\n */\n esbuildInstance?: typeof import('esbuild');\n};\n\nconst getTsConfigPath = (filePath: string): string | undefined => {\n const tsconfigPath = join(\n getPackageJsonPath(dirname(filePath)).baseDir,\n 'tsconfig.json'\n );\n\n // Only return the tsconfig path if it exists\n return existsSync(tsconfigPath) ? tsconfigPath : undefined;\n};\n\nconst getTransformationOptions = (filePath: string): BuildOptions => ({\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n '.md': 'text',\n '.mdx': 'text',\n },\n format: 'cjs',\n target: 'node20',\n platform: 'node',\n write: false,\n packages: 'external',\n bundle: true,\n tsconfig: getTsConfigPath(filePath),\n define: {\n 'import.meta.url': JSON.stringify(pathToFileURL(filePath).href),\n 'import.meta.env': 'process.env',\n },\n});\n\nexport const transpileTSToCJSSync = (\n code: string,\n filePath: string,\n options?: TranspileOptions\n): string | undefined => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const { esbuildInstance, ...buildOptions } = options ?? {};\n const esbuildBuildSync = esbuildInstance?.buildSync ?? buildSync;\n\n // esbuild's worker thread service calls `new Worker(__filename, …)` on first use.\n // In Vite's SSR module runner the SSR-optimised chunk is ESM and __filename is\n // never declared (confirmed: accessing it throws ReferenceError, not undefined).\n // Because there is no local declaration the bare `__filename` lookup falls\n // through to globalThis, so we set it there to esbuild's own CJS entry-point –\n // the exact path esbuild would use if it were loaded in a normal CJS context.\n //\n // IMPORTANT: We save/restore the globals so this temporary shim does not leak\n // to other Vite plugins (e.g. `@vitejs/plugin-react-swc`) that check\n // `typeof __dirname !== \"undefined\"` to locate their own assets.\n const g = globalThis as Record<string, unknown>;\n const hadFilename = typeof g.__filename === 'string';\n const prevFilename = g.__filename;\n const prevDirname = g.__dirname;\n\n if (!hadFilename) {\n try {\n const _require = createRequire(import.meta.url);\n const esbuildEntry = _require.resolve('esbuild');\n g.__filename = esbuildEntry;\n g.__dirname = dirname(esbuildEntry);\n } catch {\n // Best-effort: if esbuild can't be resolved the caller's catch handles it\n }\n }\n\n let moduleResult: BuildResult;\n try {\n moduleResult = esbuildBuildSync({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath), // Add resolveDir to resolve imports relative to the file's location\n sourcefile: filePath, // Add sourcefile for better error messages\n },\n ...getTransformationOptions(filePath),\n ...buildOptions,\n });\n } finally {\n // Always restore the previous values so the globals don't linger.\n if (!hadFilename) {\n if (prevFilename === undefined) {\n delete g.__filename;\n } else {\n g.__filename = prevFilename;\n }\n if (prevDirname === undefined) {\n delete g.__dirname;\n } else {\n g.__dirname = prevDirname;\n }\n }\n }\n\n const moduleResultString = moduleResult!.outputFiles?.[0]?.text;\n\n return moduleResultString;\n};\n\nexport const transpileTSToCJS = async (\n code: string,\n filePath: string,\n options?: TranspileOptions\n): Promise<string | undefined> => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const { esbuildInstance, ...buildOptions } = options ?? {};\n // Use context() + rebuild() + dispose() so esbuild deterministically releases\n // Go-subprocess resources for each one-shot transpilation, preventing them\n // from accumulating between rapid HMR-driven file changes.\n const esbuildContext = esbuildInstance?.context ?? context;\n\n const ctx = await esbuildContext({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath),\n sourcefile: filePath,\n },\n ...getTransformationOptions(filePath),\n ...buildOptions,\n });\n\n try {\n const moduleResult = await ctx.rebuild();\n return moduleResult.outputFiles?.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AAE,YAAY;;;AAOpB,QAF2B,aAAc,cAAc,IAAI;;AAK7D,MAAa,mBAAmB,OAC9B,MACA,UACA,YACgC;CAEhC,MAAM,SAAS,UADG,QAAQ,SACQ,CAAC;CAEnC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB,WAAW,EAAE;CAM1D,MAAM,MAAM,OAFW,iBAAiB,WAAW,SAElB;EAC/B,OAAO;GACL,UAAU;GACV;GACA,YAAY,QAAQ,SAAS;GAC7B,YAAY;GACb;EACD,GAAG,yBAAyB,SAAS;EACrC,GAAG;EACJ,CAAC;AAEF,KAAI;AAEF,UAAO,MADoB,IAAI,SAAS,EACpB,cAAc,GAAG;WAC7B;AACR,QAAM,IAAI,SAAS"}
|
package/dist/esm/logger.mjs
CHANGED
|
@@ -43,7 +43,7 @@ const getAppLogger = (configuration, globalDetails) => (content, details) => log
|
|
|
43
43
|
...details?.config ?? {}
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
|
-
const colorize = (string, color, reset) => color ? `${color}${string}${reset ? typeof reset === "boolean" ? RESET : reset : RESET}` : string;
|
|
46
|
+
const colorize = (string, color, reset) => color && typeof window === "undefined" ? `${color}${string}${reset ? typeof reset === "boolean" ? RESET : reset : RESET}` : string;
|
|
47
47
|
const colorizeLocales = (locales, color = GREEN, reset = RESET) => [locales].flat().map((locale) => colorize(locale, color, reset)).join(`, `);
|
|
48
48
|
const colorizeKey = (keyPath, color = BEIGE, reset = RESET) => [keyPath].flat().map((key) => colorize(key, color, reset)).join(`, `);
|
|
49
49
|
const colorizePath = (path, color = GREY, reset = RESET) => [path].flat().map((path) => colorize(path, color, reset)).join(`, `);
|
package/dist/esm/logger.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.mjs","names":[],"sources":["../../src/logger.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type {\n CustomIntlayerConfig,\n IntlayerConfig,\n} from '@intlayer/types/config';\nimport type * as ANSIColorsTypes from './colors';\nimport {\n BEIGE,\n BLUE,\n GREEN,\n GREY,\n GREY_DARK,\n GREY_LIGHT,\n RED,\n RESET,\n WHITE,\n} from './colors';\n\nexport type ANSIColorsType =\n (typeof ANSIColorsTypes)[keyof typeof ANSIColorsTypes];\n\nexport type Details = {\n isVerbose?: boolean;\n level?: 'info' | 'warn' | 'error' | 'debug';\n config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nlet loggerPrefix: string | undefined;\n\nexport const setPrefix = (prefix: string | undefined) => {\n loggerPrefix = prefix;\n};\n\nexport const getPrefix = (configPrefix?: string): string | undefined => {\n if (typeof loggerPrefix !== 'undefined') {\n return loggerPrefix;\n }\n\n return configPrefix;\n};\n\nexport const logger: Logger = (content, details) => {\n const config = details?.config ?? {};\n const mode = config.mode ?? 'default';\n\n if (mode === 'disabled' || (details?.isVerbose && mode !== 'verbose')) return;\n\n const prefix = getPrefix(config.prefix);\n const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n const level = details?.level ?? 'info';\n\n const logMethod =\n config[level] ?? console[level] ?? config.log ?? console.log;\n\n logMethod(...flatContent);\n};\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n (configuration?: Pick<IntlayerConfig, 'log'>, globalDetails?: Details) =>\n (content: any, details?: Details) =>\n logger(content, {\n ...(details ?? {}),\n config: {\n ...configuration?.log,\n ...globalDetails?.config,\n ...(details?.config ?? {}),\n },\n });\n\nexport const colorize = (\n string: string,\n color?: ANSIColorsType,\n reset?: boolean | ANSIColorsType\n): string =>\n color\n ? `${color}${string}${reset ? (typeof reset === 'boolean' ? RESET : reset) : RESET}`\n : string;\n\nexport const colorizeLocales = (\n locales: Locale | Locale[],\n color: ANSIColorsType = GREEN,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [locales]\n .flat()\n .map((locale) => colorize(locale, color, reset))\n .join(`, `);\n\nexport const colorizeKey = (\n keyPath: string | string[],\n color: ANSIColorsType = BEIGE,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [keyPath]\n .flat()\n .map((key) => colorize(key, color, reset))\n .join(`, `);\n\nexport const colorizePath = (\n path: string | string[],\n color: ANSIColorsType = GREY,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [path]\n .flat()\n .map((path) => colorize(path, color, reset))\n .join(`, `);\n\nexport const colorizeNumber = (\n number: number | string,\n options: Partial<Record<Intl.LDMLPluralRule, ANSIColorsType>> = {\n zero: BLUE,\n one: BLUE,\n two: BLUE,\n few: BLUE,\n many: BLUE,\n other: BLUE,\n }\n): string => {\n if (number === 0 || number === '0') {\n const color = options.zero ?? GREEN;\n return colorize(number.toString(), color);\n }\n\n // Kept inside the function. Top-level instantiation of classes/APIs\n // is treated as a side-effect and prevents tree-shaking if the function is unused.\n const rule = new Intl.PluralRules('en').select(Number(number));\n const color = options[rule];\n return colorize(number.toString(), color);\n};\n\nexport const colorizeObject = (\n obj: any,\n indentLevel = 0,\n indentSize = 2,\n key?: string\n): string => {\n const indent = ' '.repeat(indentLevel * indentSize);\n const nextIndent = ' '.repeat((indentLevel + 1) * indentSize);\n\n if (obj === null) {\n return colorize('null', BLUE);\n }\n\n if (typeof obj === 'boolean') {\n return colorize(obj.toString(), BLUE);\n }\n\n if (typeof obj === 'number') {\n return colorize(obj.toString(), BLUE);\n }\n\n if (typeof obj === 'string') {\n const isDateString = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/.test(obj);\n const isUrl = obj.startsWith('http://') || obj.startsWith('https://');\n const isGlob = obj.includes('*') || obj.includes('?') || obj.includes('{');\n const isPath =\n obj.startsWith('/') ||\n obj.startsWith('./') ||\n obj.startsWith('../') ||\n /\\.[a-zA-Z0-9]{2,5}$/.test(obj);\n const isSecret =\n /^[0-9a-fA-F]{24,}$/.test(obj) || (obj.length >= 40 && !/\\s/.test(obj));\n const hasSpaces = /\\s/.test(obj);\n\n if (isDateString) return colorize(`\"${obj}\"`, BEIGE);\n if (isUrl) return colorize(`\"${obj}\"`, GREY_DARK);\n if (isGlob) return colorize(`\"${obj}\"`, GREY);\n if (isPath) return colorize(`\"${obj}\"`, GREY_DARK);\n if (isSecret) return colorize(`\"${obj}\"`, GREY);\n if (hasSpaces) return colorize(`\"${obj}\"`, WHITE);\n return colorize(`\"${obj}\"`, BLUE);\n }\n\n if (Array.isArray(obj)) {\n if (obj.length === 0) {\n return '[]';\n }\n const items = obj\n .map(\n (item) =>\n `${nextIndent}${colorizeObject(item, indentLevel + 1, indentSize, key)}`\n )\n .join(',\\n');\n return `[\\n${items}\\n${indent}]`;\n }\n\n if (typeof obj === 'object') {\n const keys = Object.keys(obj);\n\n if (keys.length === 0) {\n return '{}';\n }\n\n const fields = keys\n .map((key) => {\n const coloredKey = colorize(`\"${key}\"`, GREY_LIGHT);\n const value = obj[key];\n const coloredValue = colorizeObject(\n value,\n indentLevel + 1,\n indentSize,\n key\n );\n return `${nextIndent}${coloredKey}: ${coloredValue}`;\n })\n .join(',\\n');\n return `{\\n${fields}\\n${indent}}`;\n }\n\n return colorize(String(obj), GREY);\n};\n\nexport const removeColor = (text: string) =>\n // biome-ignore lint/suspicious/noControlCharactersInRegex: we need to remove the color codes\n text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n let value: number = 0;\n if (typeof length === 'number') {\n value = length;\n }\n if (typeof length === 'string') {\n value = length.length;\n }\n if (\n Array.isArray(length) &&\n length.every((locale) => typeof locale === 'string')\n ) {\n value = Math.max(...length.map((str) => str.length));\n }\n if (\n Array.isArray(length) &&\n length.every((locale) => typeof locale === 'number')\n ) {\n value = Math.max(...length);\n }\n return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n colSize: 0,\n minSize: 0,\n maxSize: Infinity,\n pad: 'right',\n padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n text: string | string[],\n options?: {\n colSize?: number | number[] | string | string[];\n minSize?: number;\n maxSize?: number;\n pad?: 'left' | 'right';\n padChar?: string;\n }\n): string =>\n [text]\n .flat()\n .map((text) => {\n const { colSize, minSize, maxSize, pad } = {\n ...defaultColonOptions,\n ...(options ?? {}),\n };\n\n const length = getLength(colSize);\n const spacesLength = Math.max(\n minSize!,\n Math.min(maxSize!, length - removeColor(text).length)\n );\n\n if (pad === 'left') {\n return `${' '.repeat(spacesLength)}${text}`;\n }\n\n return `${text}${' '.repeat(spacesLength)}`;\n })\n .join('');\n\nexport const x = colorize('✗', RED);\nexport const v = colorize('✓', GREEN);\nexport const clock = colorize('⏲', BLUE);\n"],"mappings":";;;AA6BA,IAAI;AAEJ,MAAa,aAAa,WAA+B;AACvD,gBAAe;;AAGjB,MAAa,aAAa,iBAA8C;AACtE,KAAI,OAAO,iBAAiB,YAC1B,QAAO;AAGT,QAAO;;AAGT,MAAa,UAAkB,SAAS,YAAY;CAClD,MAAM,SAAS,SAAS,UAAU,EAAE;CACpC,MAAM,OAAO,OAAO,QAAQ;AAE5B,KAAI,SAAS,cAAe,SAAS,aAAa,SAAS,UAAY;CAEvE,MAAM,SAAS,UAAU,OAAO,OAAO;CACvC,MAAM,cAAc,SAAS,CAAC,QAAQ,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM;CAC7E,MAAM,QAAQ,SAAS,SAAS;AAKhC,EAFE,OAAO,UAAU,QAAQ,UAAU,OAAO,OAAO,QAAQ,KAEjD,GAAG,YAAY;;AAG3B,MAAa,gBAAgB;CAAC;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAI;;;;;;AAO/E,MAAa,gBACV,eAA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b,MAAa,IAAI,SAAS,KAAK,IAAI;AACnC,MAAa,IAAI,SAAS,KAAK,MAAM;AACrC,MAAa,QAAQ,SAAS,KAAK,KAAK"}
|
|
1
|
+
{"version":3,"file":"logger.mjs","names":[],"sources":["../../src/logger.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type {\n CustomIntlayerConfig,\n IntlayerConfig,\n} from '@intlayer/types/config';\nimport type * as ANSIColorsTypes from './colors';\nimport {\n BEIGE,\n BLUE,\n GREEN,\n GREY,\n GREY_DARK,\n GREY_LIGHT,\n RED,\n RESET,\n WHITE,\n} from './colors';\n\nexport type ANSIColorsType =\n (typeof ANSIColorsTypes)[keyof typeof ANSIColorsTypes];\n\nexport type Details = {\n isVerbose?: boolean;\n level?: 'info' | 'warn' | 'error' | 'debug';\n config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nlet loggerPrefix: string | undefined;\n\nexport const setPrefix = (prefix: string | undefined) => {\n loggerPrefix = prefix;\n};\n\nexport const getPrefix = (configPrefix?: string): string | undefined => {\n if (typeof loggerPrefix !== 'undefined') {\n return loggerPrefix;\n }\n\n return configPrefix;\n};\n\nexport const logger: Logger = (content, details) => {\n const config = details?.config ?? {};\n const mode = config.mode ?? 'default';\n\n if (mode === 'disabled' || (details?.isVerbose && mode !== 'verbose')) return;\n\n const prefix = getPrefix(config.prefix);\n const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n const level = details?.level ?? 'info';\n\n const logMethod =\n config[level] ?? console[level] ?? config.log ?? console.log;\n\n logMethod(...flatContent);\n};\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n (configuration?: Pick<IntlayerConfig, 'log'>, globalDetails?: Details) =>\n (content: any, details?: Details) =>\n logger(content, {\n ...(details ?? {}),\n config: {\n ...configuration?.log,\n ...globalDetails?.config,\n ...(details?.config ?? {}),\n },\n });\n\nexport const colorize = (\n string: string,\n color?: ANSIColorsType,\n reset?: boolean | ANSIColorsType\n): string =>\n color && typeof window === 'undefined'\n ? `${color}${string}${reset ? (typeof reset === 'boolean' ? RESET : reset) : RESET}`\n : string;\n\nexport const colorizeLocales = (\n locales: Locale | Locale[],\n color: ANSIColorsType = GREEN,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [locales]\n .flat()\n .map((locale) => colorize(locale, color, reset))\n .join(`, `);\n\nexport const colorizeKey = (\n keyPath: string | string[],\n color: ANSIColorsType = BEIGE,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [keyPath]\n .flat()\n .map((key) => colorize(key, color, reset))\n .join(`, `);\n\nexport const colorizePath = (\n path: string | string[],\n color: ANSIColorsType = GREY,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [path]\n .flat()\n .map((path) => colorize(path, color, reset))\n .join(`, `);\n\nexport const colorizeNumber = (\n number: number | string,\n options: Partial<Record<Intl.LDMLPluralRule, ANSIColorsType>> = {\n zero: BLUE,\n one: BLUE,\n two: BLUE,\n few: BLUE,\n many: BLUE,\n other: BLUE,\n }\n): string => {\n if (number === 0 || number === '0') {\n const color = options.zero ?? GREEN;\n return colorize(number.toString(), color);\n }\n\n // Kept inside the function. Top-level instantiation of classes/APIs\n // is treated as a side-effect and prevents tree-shaking if the function is unused.\n const rule = new Intl.PluralRules('en').select(Number(number));\n const color = options[rule];\n return colorize(number.toString(), color);\n};\n\nexport const colorizeObject = (\n obj: any,\n indentLevel = 0,\n indentSize = 2,\n key?: string\n): string => {\n const indent = ' '.repeat(indentLevel * indentSize);\n const nextIndent = ' '.repeat((indentLevel + 1) * indentSize);\n\n if (obj === null) {\n return colorize('null', BLUE);\n }\n\n if (typeof obj === 'boolean') {\n return colorize(obj.toString(), BLUE);\n }\n\n if (typeof obj === 'number') {\n return colorize(obj.toString(), BLUE);\n }\n\n if (typeof obj === 'string') {\n const isDateString = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/.test(obj);\n const isUrl = obj.startsWith('http://') || obj.startsWith('https://');\n const isGlob = obj.includes('*') || obj.includes('?') || obj.includes('{');\n const isPath =\n obj.startsWith('/') ||\n obj.startsWith('./') ||\n obj.startsWith('../') ||\n /\\.[a-zA-Z0-9]{2,5}$/.test(obj);\n const isSecret =\n /^[0-9a-fA-F]{24,}$/.test(obj) || (obj.length >= 40 && !/\\s/.test(obj));\n const hasSpaces = /\\s/.test(obj);\n\n if (isDateString) return colorize(`\"${obj}\"`, BEIGE);\n if (isUrl) return colorize(`\"${obj}\"`, GREY_DARK);\n if (isGlob) return colorize(`\"${obj}\"`, GREY);\n if (isPath) return colorize(`\"${obj}\"`, GREY_DARK);\n if (isSecret) return colorize(`\"${obj}\"`, GREY);\n if (hasSpaces) return colorize(`\"${obj}\"`, WHITE);\n return colorize(`\"${obj}\"`, BLUE);\n }\n\n if (Array.isArray(obj)) {\n if (obj.length === 0) {\n return '[]';\n }\n const items = obj\n .map(\n (item) =>\n `${nextIndent}${colorizeObject(item, indentLevel + 1, indentSize, key)}`\n )\n .join(',\\n');\n return `[\\n${items}\\n${indent}]`;\n }\n\n if (typeof obj === 'object') {\n const keys = Object.keys(obj);\n\n if (keys.length === 0) {\n return '{}';\n }\n\n const fields = keys\n .map((key) => {\n const coloredKey = colorize(`\"${key}\"`, GREY_LIGHT);\n const value = obj[key];\n const coloredValue = colorizeObject(\n value,\n indentLevel + 1,\n indentSize,\n key\n );\n return `${nextIndent}${coloredKey}: ${coloredValue}`;\n })\n .join(',\\n');\n return `{\\n${fields}\\n${indent}}`;\n }\n\n return colorize(String(obj), GREY);\n};\n\nexport const removeColor = (text: string) =>\n // biome-ignore lint/suspicious/noControlCharactersInRegex: we need to remove the color codes\n text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n let value: number = 0;\n if (typeof length === 'number') {\n value = length;\n }\n if (typeof length === 'string') {\n value = length.length;\n }\n if (\n Array.isArray(length) &&\n length.every((locale) => typeof locale === 'string')\n ) {\n value = Math.max(...length.map((str) => str.length));\n }\n if (\n Array.isArray(length) &&\n length.every((locale) => typeof locale === 'number')\n ) {\n value = Math.max(...length);\n }\n return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n colSize: 0,\n minSize: 0,\n maxSize: Infinity,\n pad: 'right',\n padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n text: string | string[],\n options?: {\n colSize?: number | number[] | string | string[];\n minSize?: number;\n maxSize?: number;\n pad?: 'left' | 'right';\n padChar?: string;\n }\n): string =>\n [text]\n .flat()\n .map((text) => {\n const { colSize, minSize, maxSize, pad } = {\n ...defaultColonOptions,\n ...(options ?? {}),\n };\n\n const length = getLength(colSize);\n const spacesLength = Math.max(\n minSize!,\n Math.min(maxSize!, length - removeColor(text).length)\n );\n\n if (pad === 'left') {\n return `${' '.repeat(spacesLength)}${text}`;\n }\n\n return `${text}${' '.repeat(spacesLength)}`;\n })\n .join('');\n\nexport const x = colorize('✗', RED);\nexport const v = colorize('✓', GREEN);\nexport const clock = colorize('⏲', BLUE);\n"],"mappings":";;;AA6BA,IAAI;AAEJ,MAAa,aAAa,WAA+B;AACvD,gBAAe;;AAGjB,MAAa,aAAa,iBAA8C;AACtE,KAAI,OAAO,iBAAiB,YAC1B,QAAO;AAGT,QAAO;;AAGT,MAAa,UAAkB,SAAS,YAAY;CAClD,MAAM,SAAS,SAAS,UAAU,EAAE;CACpC,MAAM,OAAO,OAAO,QAAQ;AAE5B,KAAI,SAAS,cAAe,SAAS,aAAa,SAAS,UAAY;CAEvE,MAAM,SAAS,UAAU,OAAO,OAAO;CACvC,MAAM,cAAc,SAAS,CAAC,QAAQ,GAAG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S,SAAS,SAAS,QAAQ;EACzC,GAAG;EACH,GAAI,WAAW,EAAE;EAClB;CAED,MAAM,SAAS,UAAU,QAAQ;CACjC,MAAM,eAAe,KAAK,IACxB,SACA,KAAK,IAAI,SAAU,SAAS,YAAY,KAAK,CAAC,OAAO,CACtD;AAED,KAAI,QAAQ,OACV,QAAO,GAAG,IAAI,OAAO,aAAa,GAAG;AAGvC,QAAO,GAAG,OAAO,IAAI,OAAO,aAAa;EACzC,CACD,KAAK,GAAG;AAEb,MAAa,IAAI,SAAS,KAAK,IAAI;AACnC,MAAa,IAAI,SAAS,KAAK,MAAM;AACrC,MAAa,QAAQ,SAAS,KAAK,KAAK"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/utils/getDictionarySelectorUsage.ts
|
|
2
|
+
/**
|
|
3
|
+
* Detects whether any built dictionary declares qualifier dimensions
|
|
4
|
+
* (collections, variants or meta records).
|
|
5
|
+
*
|
|
6
|
+
* The merge step emits a {@link QualifiedDictionaryGroup} — carrying a
|
|
7
|
+
* non-empty `qualifierTypes` array — for every key whose declarations use a
|
|
8
|
+
* selector. When no group is present, the selector-object resolution path in
|
|
9
|
+
* `getIntlayer` / `useIntlayer` is dead code, and bundlers can eliminate it via
|
|
10
|
+
* the `INTLAYER_DICTIONARY_SELECTOR` env var.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* getHasDictionarySelector(getDictionaries(config));
|
|
14
|
+
* // true → at least one collection / variant / meta dictionary
|
|
15
|
+
* // false → only plain dictionaries (selector logic can be stripped)
|
|
16
|
+
*/
|
|
17
|
+
const getHasDictionarySelector = (dictionaries) => {
|
|
18
|
+
return (Array.isArray(dictionaries) ? dictionaries : Object.values(dictionaries)).some((dictionary) => {
|
|
19
|
+
const { qualifierTypes } = dictionary;
|
|
20
|
+
return Array.isArray(qualifierTypes) && qualifierTypes.length > 0;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { getHasDictionarySelector };
|
|
26
|
+
//# sourceMappingURL=getDictionarySelectorUsage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDictionarySelectorUsage.mjs","names":[],"sources":["../../../src/utils/getDictionarySelectorUsage.ts"],"sourcesContent":["import type {\n Dictionary,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\n\ntype DictionaryOrGroup = Dictionary | QualifiedDictionaryGroup;\n\n/**\n * Detects whether any built dictionary declares qualifier dimensions\n * (collections, variants or meta records).\n *\n * The merge step emits a {@link QualifiedDictionaryGroup} — carrying a\n * non-empty `qualifierTypes` array — for every key whose declarations use a\n * selector. When no group is present, the selector-object resolution path in\n * `getIntlayer` / `useIntlayer` is dead code, and bundlers can eliminate it via\n * the `INTLAYER_DICTIONARY_SELECTOR` env var.\n *\n * @example\n * getHasDictionarySelector(getDictionaries(config));\n * // true → at least one collection / variant / meta dictionary\n * // false → only plain dictionaries (selector logic can be stripped)\n */\nexport const getHasDictionarySelector = (\n dictionaries: Record<string, DictionaryOrGroup> | DictionaryOrGroup[]\n): boolean => {\n const dictionariesArray = Array.isArray(dictionaries)\n ? dictionaries\n : Object.values(dictionaries);\n\n return dictionariesArray.some((dictionary) => {\n const { qualifierTypes } = dictionary as QualifiedDictionaryGroup;\n\n return Array.isArray(qualifierTypes) && qualifierTypes.length > 0;\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAsBA,MAAa,4BACX,iBACY;AAKZ,SAJ0B,MAAM,QAAQ,aAAa,GACjD,eACA,OAAO,OAAO,aAAa,EAEN,MAAM,eAAe;EAC5C,MAAM,EAAE,mBAAmB;AAE3B,SAAO,MAAM,QAAQ,eAAe,IAAI,eAAe,SAAS;GAChE"}
|
package/dist/esm/utils/index.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { configESMxCJSRequire, getProjectRequire, isESModule } from "./ESMxCJSHe
|
|
|
8
8
|
import { clearModuleCache } from "./clearModuleCache.mjs";
|
|
9
9
|
import { compareVersions } from "./compareVersions.mjs";
|
|
10
10
|
import { extractErrorMessage } from "./extractErrorMessage.mjs";
|
|
11
|
+
import { getHasDictionarySelector } from "./getDictionarySelectorUsage.mjs";
|
|
11
12
|
import { getStorageAttributes } from "./getStorageAttributes.mjs";
|
|
12
13
|
import { getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync } from "./getUsedNodeTypes.mjs";
|
|
13
14
|
import { logStack } from "./logStack.mjs";
|
|
@@ -20,4 +21,4 @@ import { camelCaseToSentence } from "./stringFormatter/camelCaseToSentence.mjs";
|
|
|
20
21
|
import { kebabCaseToCamelCase } from "./stringFormatter/kebabCaseToCamelCase.mjs";
|
|
21
22
|
import { toLowerCamelCase } from "./stringFormatter/toLowerCamelCase.mjs";
|
|
22
23
|
|
|
23
|
-
export { assertPathWithin, 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, setIntlayerIdentifier, stableStringify, toLowerCamelCase };
|
|
24
|
+
export { assertPathWithin, cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getHasDictionarySelector, getPackageJsonPath, getProjectRequire, getStorageAttributes, getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, setIntlayerIdentifier, stableStringify, toLowerCamelCase };
|
|
@@ -21,8 +21,8 @@ declare const cookiesAttributesSchema: z.ZodObject<{
|
|
|
21
21
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
22
22
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
23
23
|
strict: "strict";
|
|
24
|
-
lax: "lax";
|
|
25
24
|
none: "none";
|
|
25
|
+
lax: "lax";
|
|
26
26
|
}>>;
|
|
27
27
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Date, Date>, z.ZodNumber, z.ZodString]>>;
|
|
28
28
|
maxAge: z.ZodOptional<z.ZodNumber>;
|
|
@@ -49,8 +49,8 @@ declare const storageSchema: z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodEnum
|
|
|
49
49
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
50
50
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
51
51
|
strict: "strict";
|
|
52
|
-
lax: "lax";
|
|
53
52
|
none: "none";
|
|
53
|
+
lax: "lax";
|
|
54
54
|
}>>;
|
|
55
55
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Date, Date>, z.ZodNumber, z.ZodString]>>;
|
|
56
56
|
maxAge: z.ZodOptional<z.ZodNumber>;
|
|
@@ -75,8 +75,8 @@ declare const storageSchema: z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodEnum
|
|
|
75
75
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
76
76
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
77
77
|
strict: "strict";
|
|
78
|
-
lax: "lax";
|
|
79
78
|
none: "none";
|
|
79
|
+
lax: "lax";
|
|
80
80
|
}>>;
|
|
81
81
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Date, Date>, z.ZodNumber, z.ZodString]>>;
|
|
82
82
|
maxAge: z.ZodOptional<z.ZodNumber>;
|
|
@@ -159,8 +159,8 @@ declare const routingSchema: z.ZodObject<{
|
|
|
159
159
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
160
160
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
161
161
|
strict: "strict";
|
|
162
|
-
lax: "lax";
|
|
163
162
|
none: "none";
|
|
163
|
+
lax: "lax";
|
|
164
164
|
}>>;
|
|
165
165
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Date, Date>, z.ZodNumber, z.ZodString]>>;
|
|
166
166
|
maxAge: z.ZodOptional<z.ZodNumber>;
|
|
@@ -185,8 +185,8 @@ declare const routingSchema: z.ZodObject<{
|
|
|
185
185
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
186
186
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
187
187
|
strict: "strict";
|
|
188
|
-
lax: "lax";
|
|
189
188
|
none: "none";
|
|
189
|
+
lax: "lax";
|
|
190
190
|
}>>;
|
|
191
191
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Date, Date>, z.ZodNumber, z.ZodString]>>;
|
|
192
192
|
maxAge: z.ZodOptional<z.ZodNumber>;
|
|
@@ -356,8 +356,8 @@ declare const intlayerConfigSchema: z.ZodObject<{
|
|
|
356
356
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
357
357
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
358
358
|
strict: "strict";
|
|
359
|
-
lax: "lax";
|
|
360
359
|
none: "none";
|
|
360
|
+
lax: "lax";
|
|
361
361
|
}>>;
|
|
362
362
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Date, Date>, z.ZodNumber, z.ZodString]>>;
|
|
363
363
|
maxAge: z.ZodOptional<z.ZodNumber>;
|
|
@@ -382,8 +382,8 @@ declare const intlayerConfigSchema: z.ZodObject<{
|
|
|
382
382
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
383
383
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
384
384
|
strict: "strict";
|
|
385
|
-
lax: "lax";
|
|
386
385
|
none: "none";
|
|
386
|
+
lax: "lax";
|
|
387
387
|
}>>;
|
|
388
388
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Date, Date>, z.ZodNumber, z.ZodString]>>;
|
|
389
389
|
maxAge: z.ZodOptional<z.ZodNumber>;
|
|
@@ -13,6 +13,25 @@ import { IntlayerConfig } from "@intlayer/types/config";
|
|
|
13
13
|
* // { 'process.env.INTLAYER_NODE_TYPE_REACT_NODE': '"false"' }
|
|
14
14
|
*/
|
|
15
15
|
declare const formatNodeTypeToEnvVar: (nodeTypes: string[], wrapKey?: (key: string) => string, wrapValue?: (value: string) => string) => Record<string, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the env-var definition disabling the dictionary-selector resolution
|
|
18
|
+
* path (collections, variants, meta records) when no built dictionary declares
|
|
19
|
+
* a qualifier. Set to `"false"` so bundlers can dead-code-eliminate the
|
|
20
|
+
* selector branch in `getIntlayer` / `useIntlayer`.
|
|
21
|
+
*
|
|
22
|
+
* Emits nothing when selectors are used, leaving the runtime default in place.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* formatDictionarySelectorEnvVar(false)
|
|
26
|
+
* // { INTLAYER_DICTIONARY_SELECTOR: '"false"' }
|
|
27
|
+
*
|
|
28
|
+
* formatDictionarySelectorEnvVar(true)
|
|
29
|
+
* // {}
|
|
30
|
+
*
|
|
31
|
+
* formatDictionarySelectorEnvVar(false, (k) => `process.env.${k}`, (v) => `"${v}"`)
|
|
32
|
+
* // { 'process.env.INTLAYER_DICTIONARY_SELECTOR': '"false"' }
|
|
33
|
+
*/
|
|
34
|
+
declare const formatDictionarySelectorEnvVar: (hasDictionarySelector: boolean, wrapKey?: (key: string) => string, wrapValue?: (value: string) => string) => Record<string, string>;
|
|
16
35
|
/**
|
|
17
36
|
* Returns env-var definitions for the full Intlayer config to be injected at
|
|
18
37
|
* build time. Allows bundlers to dead-code-eliminate unused routing modes,
|
|
@@ -27,5 +46,5 @@ declare const formatNodeTypeToEnvVar: (nodeTypes: string[], wrapKey?: (key: stri
|
|
|
27
46
|
*/
|
|
28
47
|
declare const getConfigEnvVars: (config: IntlayerConfig, wrapKey?: (key: string) => string, wrapValue?: (value: string) => string) => Record<string, string>;
|
|
29
48
|
//#endregion
|
|
30
|
-
export { formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
49
|
+
export { formatDictionarySelectorEnvVar, formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
31
50
|
//# sourceMappingURL=envVars.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envVars.d.ts","names":[],"sources":["../../../src/envVars/envVars.ts"],"mappings":";;;;;AA2BA;;;;;;;;;cAAa,sBAAA,GACX,SAAA,YACA,OAAA,IAAW,GAAA,qBACX,SAAA,IAAa,KAAA,wBACZ,MAAA;;;
|
|
1
|
+
{"version":3,"file":"envVars.d.ts","names":[],"sources":["../../../src/envVars/envVars.ts"],"mappings":";;;;;AA2BA;;;;;;;;;cAAa,sBAAA,GACX,SAAA,YACA,OAAA,IAAW,GAAA,qBACX,SAAA,IAAa,KAAA,wBACZ,MAAA;;;AA4BH;;;;;;;;;;;;AAqBA;;;;cArBa,8BAAA,GACX,qBAAA,WACA,OAAA,IAAW,GAAA,qBACX,SAAA,IAAa,KAAA,wBACZ,MAAA;;;;;;;;;;;;;cAiBU,gBAAA,GACX,MAAA,EAAQ,cAAA,EACR,OAAA,IAAW,GAAA,qBACX,SAAA,IAAa,KAAA,wBACZ,MAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { formatNodeTypeToEnvVar, getConfigEnvVars } from "./envVars.js";
|
|
2
|
-
export { formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
1
|
+
import { formatDictionarySelectorEnvVar, formatNodeTypeToEnvVar, getConfigEnvVars } from "./envVars.js";
|
|
2
|
+
export { formatDictionarySelectorEnvVar, formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpileTSToCJS.d.ts","names":[],"sources":["../../../src/loadExternalFile/transpileTSToCJS.ts"],"mappings":";;;;KAaY,gBAAA,GAAmB,YAAA;;;AAA/B;;;;;EAQE,eAAA,UARyC,SAAA;AAAA;AAAA,cA8C9B,oBAAA,GACX,IAAA,UACA,QAAA,UACA,OAAA,GAAU,gBAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"transpileTSToCJS.d.ts","names":[],"sources":["../../../src/loadExternalFile/transpileTSToCJS.ts"],"mappings":";;;;KAaY,gBAAA,GAAmB,YAAA;;;AAA/B;;;;;EAQE,eAAA,UARyC,SAAA;AAAA;AAAA,cA8C9B,oBAAA,GACX,IAAA,UACA,QAAA,UACA,OAAA,GAAU,gBAAA;AAAA,cAmEC,gBAAA,GACX,IAAA,UACA,QAAA,UACA,OAAA,GAAU,gBAAA,KACT,OAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Dictionary, QualifiedDictionaryGroup } from "@intlayer/types/dictionary";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/getDictionarySelectorUsage.d.ts
|
|
4
|
+
type DictionaryOrGroup = Dictionary | QualifiedDictionaryGroup;
|
|
5
|
+
/**
|
|
6
|
+
* Detects whether any built dictionary declares qualifier dimensions
|
|
7
|
+
* (collections, variants or meta records).
|
|
8
|
+
*
|
|
9
|
+
* The merge step emits a {@link QualifiedDictionaryGroup} — carrying a
|
|
10
|
+
* non-empty `qualifierTypes` array — for every key whose declarations use a
|
|
11
|
+
* selector. When no group is present, the selector-object resolution path in
|
|
12
|
+
* `getIntlayer` / `useIntlayer` is dead code, and bundlers can eliminate it via
|
|
13
|
+
* the `INTLAYER_DICTIONARY_SELECTOR` env var.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* getHasDictionarySelector(getDictionaries(config));
|
|
17
|
+
* // true → at least one collection / variant / meta dictionary
|
|
18
|
+
* // false → only plain dictionaries (selector logic can be stripped)
|
|
19
|
+
*/
|
|
20
|
+
declare const getHasDictionarySelector: (dictionaries: Record<string, DictionaryOrGroup> | DictionaryOrGroup[]) => boolean;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { getHasDictionarySelector };
|
|
23
|
+
//# sourceMappingURL=getDictionarySelectorUsage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDictionarySelectorUsage.d.ts","names":[],"sources":["../../../src/utils/getDictionarySelectorUsage.ts"],"mappings":";;;KAKK,iBAAA,GAAoB,UAAA,GAAa,wBAAA;;AAFF;;;;;AAmBpC;;;;;;;;;cAAa,wBAAA,GACX,YAAA,EAAc,MAAA,SAAe,iBAAA,IAAqB,iBAAA"}
|
|
@@ -12,6 +12,7 @@ import { CacheKey, cacheMemory, clearAllCache, clearCache, computeKeyId, getCach
|
|
|
12
12
|
import { cacheDisk, clearDiskCacheMemory } from "./cacheDisk.js";
|
|
13
13
|
import { clearModuleCache } from "./clearModuleCache.js";
|
|
14
14
|
import { compareVersions } from "./compareVersions.js";
|
|
15
|
+
import { getHasDictionarySelector } from "./getDictionarySelectorUsage.js";
|
|
15
16
|
import { getExtension } from "./getExtension.js";
|
|
16
17
|
import { getPackageJsonPath } from "./getPackageJsonPath.js";
|
|
17
18
|
import { getStorageAttributes } from "./getStorageAttributes.js";
|
|
@@ -19,4 +20,4 @@ import { PluginNodeType, getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNod
|
|
|
19
20
|
import { parseFilePathPattern, parseStringPattern } from "./parseFilePathPattern.js";
|
|
20
21
|
import { assertPathWithin } from "./pathSecurity.js";
|
|
21
22
|
import { RetryManagerOptions, retryManager } from "./retryManager.js";
|
|
22
|
-
export { CacheKey, GetAliasOptions, PluginNodeType, RetryManagerOptions, WindowsWithIntlayer, assertPathWithin, 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, setIntlayerIdentifier, stableStringify, toLowerCamelCase };
|
|
23
|
+
export { CacheKey, GetAliasOptions, PluginNodeType, RetryManagerOptions, WindowsWithIntlayer, assertPathWithin, cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getHasDictionarySelector, getPackageJsonPath, getProjectRequire, getStorageAttributes, getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, setIntlayerIdentifier, stableStringify, toLowerCamelCase };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/config",
|
|
3
|
-
"version": "9.0.0-canary.
|
|
3
|
+
"version": "9.0.0-canary.3",
|
|
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": [
|
|
@@ -160,7 +160,7 @@
|
|
|
160
160
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
161
161
|
},
|
|
162
162
|
"dependencies": {
|
|
163
|
-
"@intlayer/types": "9.0.0-canary.
|
|
163
|
+
"@intlayer/types": "9.0.0-canary.3",
|
|
164
164
|
"defu": "6.1.7",
|
|
165
165
|
"dotenv": "17.4.2",
|
|
166
166
|
"esbuild": "0.28.0",
|