@intlayer/config 8.6.3 → 8.6.5
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/built.browser.cjs +26 -1
- package/dist/cjs/built.browser.cjs.map +1 -1
- package/dist/cjs/built.cjs +26 -1
- package/dist/cjs/built.cjs.map +1 -1
- package/dist/cjs/bundle/index.cjs +130 -0
- package/dist/cjs/bundle/index.cjs.map +1 -0
- package/dist/cjs/bundle/logBundle.cjs +79 -0
- package/dist/cjs/bundle/logBundle.cjs.map +1 -0
- package/dist/cjs/client.cjs +2 -0
- package/dist/cjs/configFile/buildBrowserConfiguration.cjs +1 -10
- package/dist/cjs/configFile/buildBrowserConfiguration.cjs.map +1 -1
- package/dist/cjs/configFile/buildConfigurationFields.cjs +0 -1
- package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
- package/dist/cjs/envVars/envVars.cjs +10 -11
- package/dist/cjs/envVars/envVars.cjs.map +1 -1
- package/dist/cjs/logger.cjs.map +1 -1
- package/dist/cjs/utils/getStorageAttributes.cjs +13 -8
- package/dist/cjs/utils/getStorageAttributes.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +2 -0
- package/dist/cjs/utils/setIntlayerIdentifier.cjs +14 -0
- package/dist/cjs/utils/setIntlayerIdentifier.cjs.map +1 -0
- package/dist/esm/built.browser.mjs +13 -1
- package/dist/esm/built.browser.mjs.map +1 -1
- package/dist/esm/built.mjs +13 -1
- package/dist/esm/built.mjs.map +1 -1
- package/dist/esm/bundle/index.mjs +126 -0
- package/dist/esm/bundle/index.mjs.map +1 -0
- package/dist/esm/bundle/logBundle.mjs +78 -0
- package/dist/esm/bundle/logBundle.mjs.map +1 -0
- package/dist/esm/client.mjs +2 -1
- package/dist/esm/configFile/buildBrowserConfiguration.mjs +1 -8
- package/dist/esm/configFile/buildBrowserConfiguration.mjs.map +1 -1
- package/dist/esm/configFile/buildConfigurationFields.mjs +0 -1
- package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
- package/dist/esm/envVars/envVars.mjs +10 -11
- package/dist/esm/envVars/envVars.mjs.map +1 -1
- package/dist/esm/logger.mjs.map +1 -1
- package/dist/esm/utils/cacheDisk.mjs +4 -4
- package/dist/esm/utils/cacheDisk.mjs.map +1 -1
- package/dist/esm/utils/getStorageAttributes.mjs +13 -8
- package/dist/esm/utils/getStorageAttributes.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +2 -1
- package/dist/esm/utils/setIntlayerIdentifier.mjs +12 -0
- package/dist/esm/utils/setIntlayerIdentifier.mjs.map +1 -0
- package/dist/types/built.browser.d.ts +15 -1
- package/dist/types/built.browser.d.ts.map +1 -1
- package/dist/types/built.d.ts +15 -1
- package/dist/types/built.d.ts.map +1 -1
- package/dist/types/bundle/index.d.ts +23 -0
- package/dist/types/bundle/index.d.ts.map +1 -0
- package/dist/types/bundle/logBundle.d.ts +23 -0
- package/dist/types/bundle/logBundle.d.ts.map +1 -0
- package/dist/types/client.d.ts +2 -1
- package/dist/types/configFile/buildBrowserConfiguration.d.ts +0 -1
- package/dist/types/configFile/buildBrowserConfiguration.d.ts.map +1 -1
- package/dist/types/configFile/configurationSchema.d.ts +7 -7
- package/dist/types/configFile/index.d.ts +1 -1
- package/dist/types/envVars/envVars.d.ts +2 -2
- package/dist/types/envVars/envVars.d.ts.map +1 -1
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/logger.d.ts.map +1 -1
- package/dist/types/node.d.ts +1 -1
- package/dist/types/utils/getStorageAttributes.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +2 -1
- package/dist/types/utils/setIntlayerIdentifier.d.ts +15 -0
- package/dist/types/utils/setIntlayerIdentifier.d.ts.map +1 -0
- package/package.json +10 -2
|
@@ -12,8 +12,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
12
12
|
* formatNodeTypeToEnvVar(['enumeration'], true)
|
|
13
13
|
* // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
14
14
|
*/
|
|
15
|
-
const formatNodeTypeToEnvVar = (nodeTypes,
|
|
16
|
-
acc[
|
|
15
|
+
const formatNodeTypeToEnvVar = (nodeTypes, wrapKey = (key) => key, wrapValue = (value) => value) => nodeTypes.reduce((acc, nodeType) => {
|
|
16
|
+
acc[wrapKey(`INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`)] = wrapValue("false");
|
|
17
17
|
return acc;
|
|
18
18
|
}, {});
|
|
19
19
|
/**
|
|
@@ -28,16 +28,15 @@ const formatNodeTypeToEnvVar = (nodeTypes, addProcessEnv = false) => nodeTypes.r
|
|
|
28
28
|
* getConfigEnvVars(config, true)
|
|
29
29
|
* // { 'process.env.INTLAYER_ROUTING_MODE': '"prefix-no-default"', ... }
|
|
30
30
|
*/
|
|
31
|
-
const getConfigEnvVars = (config,
|
|
32
|
-
const prefix = addProcessEnv ? "process.env." : "";
|
|
31
|
+
const getConfigEnvVars = (config, wrapKey = (key) => key, wrapValue = (value) => value) => {
|
|
33
32
|
const { routing, editor } = config;
|
|
34
|
-
const envVars = { [
|
|
35
|
-
if (!routing.rewrite) envVars[
|
|
36
|
-
if (routing.storage.cookies.length === 0) envVars[
|
|
37
|
-
if (routing.storage.localStorage.length === 0) envVars[
|
|
38
|
-
if (routing.storage.sessionStorage.length === 0) envVars[
|
|
39
|
-
if (routing.storage.headers.length === 0) envVars[
|
|
40
|
-
if (editor?.enabled === false) envVars[
|
|
33
|
+
const envVars = { [wrapKey("INTLAYER_ROUTING_MODE")]: wrapValue(routing.mode) };
|
|
34
|
+
if (!routing.rewrite) envVars[wrapKey("INTLAYER_ROUTING_REWRITE_RULES")] = wrapValue("false");
|
|
35
|
+
if (!routing.storage.cookies || routing.storage.cookies.length === 0) envVars[wrapKey("INTLAYER_ROUTING_STORAGE_COOKIES")] = wrapValue("false");
|
|
36
|
+
if (!routing.storage.localStorage || routing.storage.localStorage.length === 0) envVars[wrapKey("INTLAYER_ROUTING_STORAGE_LOCALSTORAGE")] = wrapValue("false");
|
|
37
|
+
if (!routing.storage.sessionStorage || routing.storage.sessionStorage.length === 0) envVars[wrapKey("INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE")] = wrapValue("false");
|
|
38
|
+
if (!routing.storage.headers || routing.storage.headers.length === 0) envVars[wrapKey("INTLAYER_ROUTING_STORAGE_HEADERS")] = wrapValue("false");
|
|
39
|
+
if (editor?.enabled === false) envVars[wrapKey("INTLAYER_EDITOR_ENABLED")] = wrapValue("false");
|
|
41
40
|
return envVars;
|
|
42
41
|
};
|
|
43
42
|
|
|
@@ -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 list of unused NodeType keys into env-var definitions.\n * Set to `\"false\"` so bundlers can eliminate the corresponding plugin code.\n *\n * @example\n * formatNodeTypeToEnvVar(['enumeration'])\n * // { 'INTLAYER_NODE_TYPE_ENUMERATION': '\"false\"' }\n *\n * formatNodeTypeToEnvVar(['enumeration'], true)\n * // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '\"false\"' }\n */\nexport const formatNodeTypeToEnvVar = (\n nodeTypes: string[],\n
|
|
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 list of unused NodeType keys into env-var definitions.\n * Set to `\"false\"` so bundlers can eliminate the corresponding plugin code.\n *\n * @example\n * formatNodeTypeToEnvVar(['enumeration'])\n * // { 'INTLAYER_NODE_TYPE_ENUMERATION': '\"false\"' }\n *\n * formatNodeTypeToEnvVar(['enumeration'], true)\n * // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '\"false\"' }\n */\nexport const formatNodeTypeToEnvVar = (\n nodeTypes: string[],\n 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_${nodeType.toUpperCase()}`)] =\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.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":";;;;;;;;;;;;;;AAaA,MAAa,0BACX,WACA,WAAW,QAAgB,KAC3B,aAAa,UAAkB,UAE/B,UAAU,QACP,KAAK,aAAa;AACjB,KAAI,QAAQ,sBAAsB,SAAS,aAAa,GAAG,IACzD,UAAU,QAAQ;AACpB,QAAO;GAET,EAAE,CACH;;;;;;;;;;;;;AAcH,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,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"}
|
package/dist/cjs/logger.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.cjs","names":["RESET","GREEN","BEIGE","GREY","BLUE","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 { BEIGE, BLUE, GREEN, GREY, RED, RESET } 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?: IntlayerConfig, 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 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":";;;;AAmBA,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,
|
|
1
|
+
{"version":3,"file":"logger.cjs","names":["RESET","GREEN","BEIGE","GREY","BLUE","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 { BEIGE, BLUE, GREEN, GREY, RED, RESET } 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 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":";;;;AAmBA,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,eAA6C,mBAC7C,SAAc,YACb,OAAO,SAAS;CACd,GAAI,WAAW,EAAE;CACjB,QAAQ;EACN,GAAG,eAAe;EAClB,GAAG,eAAe;EAClB,GAAI,SAAS,UAAU,EAAE;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,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,KAAKC,mBAAI;AACnC,MAAa,IAAI,SAAS,KAAKJ,qBAAM;AACrC,MAAa,QAAQ,SAAS,KAAKG,oBAAK"}
|
|
@@ -53,10 +53,10 @@ const processStorageEntry = (entry) => {
|
|
|
53
53
|
};
|
|
54
54
|
};
|
|
55
55
|
const mergeStorageAttributes = (accumulated, partial) => ({
|
|
56
|
-
cookies: [...accumulated.cookies, ...partial.cookies ?? []],
|
|
57
|
-
localStorage: [...accumulated.localStorage, ...partial.localStorage ?? []],
|
|
58
|
-
sessionStorage: [...accumulated.sessionStorage, ...partial.sessionStorage ?? []],
|
|
59
|
-
headers: [...accumulated.headers, ...partial.headers ?? []]
|
|
56
|
+
cookies: [...accumulated.cookies ?? [], ...partial.cookies ?? []],
|
|
57
|
+
localStorage: [...accumulated.localStorage ?? [], ...partial.localStorage ?? []],
|
|
58
|
+
sessionStorage: [...accumulated.sessionStorage ?? [], ...partial.sessionStorage ?? []],
|
|
59
|
+
headers: [...accumulated.headers ?? [], ...partial.headers ?? []]
|
|
60
60
|
});
|
|
61
61
|
/**
|
|
62
62
|
* Extracts and normalizes storage configuration into separate arrays for each storage type.
|
|
@@ -72,11 +72,16 @@ const getStorageAttributes = (options) => {
|
|
|
72
72
|
sessionStorage: [],
|
|
73
73
|
headers: []
|
|
74
74
|
};
|
|
75
|
-
if (options === false || options === void 0) return
|
|
76
|
-
|
|
75
|
+
if (options === false || options === void 0) return {};
|
|
76
|
+
const result = Array.isArray(options) ? options.reduce((acc, entry) => {
|
|
77
77
|
return mergeStorageAttributes(acc, processStorageEntry(entry));
|
|
78
|
-
}, emptyResult);
|
|
79
|
-
|
|
78
|
+
}, emptyResult) : mergeStorageAttributes(emptyResult, processStorageEntry(options));
|
|
79
|
+
const cleanedResult = {};
|
|
80
|
+
if (result.cookies && result.cookies.length > 0) cleanedResult.cookies = result.cookies;
|
|
81
|
+
if (result.localStorage && result.localStorage.length > 0) cleanedResult.localStorage = result.localStorage;
|
|
82
|
+
if (result.sessionStorage && result.sessionStorage.length > 0) cleanedResult.sessionStorage = result.sessionStorage;
|
|
83
|
+
if (result.headers && result.headers.length > 0) cleanedResult.headers = result.headers;
|
|
84
|
+
return cleanedResult;
|
|
80
85
|
};
|
|
81
86
|
|
|
82
87
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStorageAttributes.cjs","names":[],"sources":["../../../src/utils/getStorageAttributes.ts"],"sourcesContent":["import type {\n CookiesAttributes,\n ProcessedStorageAttributes,\n RoutingStorageInput,\n StorageAttributes,\n} from '@intlayer/types/config';\nimport {\n COOKIE_NAME,\n HEADER_NAME,\n LOCALE_STORAGE_NAME,\n} from '../defaultValues/routing';\n\n// ============================================================================\n// Types\n// ============================================================================\n\ntype CookieEntry = {\n name: string;\n attributes: Omit<CookiesAttributes, 'type' | 'name'>;\n};\n\ntype WebStorageEntry = {\n name: string;\n};\n\ntype HeaderEntry = {\n name: string;\n};\n\ntype StorageEntry =\n | 'cookie'\n | 'localStorage'\n | 'sessionStorage'\n | 'header'\n | CookiesAttributes\n | StorageAttributes;\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\nconst createCookieEntry = (\n options?: Partial<CookiesAttributes>\n): CookieEntry => {\n const { name, path, expires, domain, secure, sameSite, httpOnly } =\n options ?? {};\n return {\n name: name ?? COOKIE_NAME,\n attributes: { path, expires, domain, secure, sameSite, httpOnly },\n };\n};\n\nconst createWebStorageEntry = (\n options?: Partial<StorageAttributes>\n): WebStorageEntry => ({\n name: options?.name ?? LOCALE_STORAGE_NAME,\n});\n\nconst createHeaderEntry = (\n options?: Partial<StorageAttributes>\n): HeaderEntry => ({\n name: options?.name ?? HEADER_NAME,\n});\n\nconst isCookieEntry = (entry: unknown): boolean => {\n if (typeof entry !== 'object' || entry === null) return false;\n const e = entry as Record<string, unknown>;\n return (\n e['type'] === 'cookie' ||\n 'sameSite' in e ||\n 'httpOnly' in e ||\n 'secure' in e\n );\n};\n\nconst isStorageType = (\n value: string\n): value is 'cookie' | 'localStorage' | 'sessionStorage' | 'header' =>\n value === 'cookie' ||\n value === 'localStorage' ||\n value === 'sessionStorage' ||\n value === 'header';\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\nconst processStorageEntry = (\n entry: StorageEntry\n): Partial<ProcessedStorageAttributes> => {\n if (typeof entry === 'string') {\n if (!isStorageType(entry)) {\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n }\n if (entry === 'cookie') return { cookies: [createCookieEntry()] };\n if (entry === 'localStorage')\n return { localStorage: [createWebStorageEntry()] };\n if (entry === 'sessionStorage')\n return { sessionStorage: [createWebStorageEntry()] };\n if (entry === 'header') return { headers: [createHeaderEntry()] };\n }\n\n if (typeof entry === 'object' && entry !== null) {\n const typedEntry = entry as CookiesAttributes | StorageAttributes;\n\n if (isCookieEntry(typedEntry)) {\n return { cookies: [createCookieEntry(typedEntry as CookiesAttributes)] };\n }\n if ('type' in typedEntry && typedEntry.type === 'localStorage') {\n return {\n localStorage: [createWebStorageEntry(typedEntry as StorageAttributes)],\n };\n }\n if ('type' in typedEntry && typedEntry.type === 'sessionStorage') {\n return {\n sessionStorage: [\n createWebStorageEntry(typedEntry as StorageAttributes),\n ],\n };\n }\n if ('type' in typedEntry && typedEntry.type === 'header') {\n return { headers: [createHeaderEntry(typedEntry as StorageAttributes)] };\n }\n // Default to localStorage for ambiguous objects\n return {\n localStorage: [\n createWebStorageEntry(typedEntry as Omit<StorageAttributes, 'type'>),\n ],\n };\n }\n\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n};\n\nconst mergeStorageAttributes = (\n accumulated: ProcessedStorageAttributes,\n partial: Partial<ProcessedStorageAttributes>\n): ProcessedStorageAttributes => ({\n cookies: [...accumulated.cookies, ...(partial.cookies ?? [])],\n localStorage: [...accumulated.localStorage
|
|
1
|
+
{"version":3,"file":"getStorageAttributes.cjs","names":[],"sources":["../../../src/utils/getStorageAttributes.ts"],"sourcesContent":["import type {\n CookiesAttributes,\n ProcessedStorageAttributes,\n RoutingStorageInput,\n StorageAttributes,\n} from '@intlayer/types/config';\nimport {\n COOKIE_NAME,\n HEADER_NAME,\n LOCALE_STORAGE_NAME,\n} from '../defaultValues/routing';\n\n// ============================================================================\n// Types\n// ============================================================================\n\ntype CookieEntry = {\n name: string;\n attributes: Omit<CookiesAttributes, 'type' | 'name'>;\n};\n\ntype WebStorageEntry = {\n name: string;\n};\n\ntype HeaderEntry = {\n name: string;\n};\n\ntype StorageEntry =\n | 'cookie'\n | 'localStorage'\n | 'sessionStorage'\n | 'header'\n | CookiesAttributes\n | StorageAttributes;\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\nconst createCookieEntry = (\n options?: Partial<CookiesAttributes>\n): CookieEntry => {\n const { name, path, expires, domain, secure, sameSite, httpOnly } =\n options ?? {};\n return {\n name: name ?? COOKIE_NAME,\n attributes: { path, expires, domain, secure, sameSite, httpOnly },\n };\n};\n\nconst createWebStorageEntry = (\n options?: Partial<StorageAttributes>\n): WebStorageEntry => ({\n name: options?.name ?? LOCALE_STORAGE_NAME,\n});\n\nconst createHeaderEntry = (\n options?: Partial<StorageAttributes>\n): HeaderEntry => ({\n name: options?.name ?? HEADER_NAME,\n});\n\nconst isCookieEntry = (entry: unknown): boolean => {\n if (typeof entry !== 'object' || entry === null) return false;\n const e = entry as Record<string, unknown>;\n return (\n e['type'] === 'cookie' ||\n 'sameSite' in e ||\n 'httpOnly' in e ||\n 'secure' in e\n );\n};\n\nconst isStorageType = (\n value: string\n): value is 'cookie' | 'localStorage' | 'sessionStorage' | 'header' =>\n value === 'cookie' ||\n value === 'localStorage' ||\n value === 'sessionStorage' ||\n value === 'header';\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\nconst processStorageEntry = (\n entry: StorageEntry\n): Partial<ProcessedStorageAttributes> => {\n if (typeof entry === 'string') {\n if (!isStorageType(entry)) {\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n }\n if (entry === 'cookie') return { cookies: [createCookieEntry()] };\n if (entry === 'localStorage')\n return { localStorage: [createWebStorageEntry()] };\n if (entry === 'sessionStorage')\n return { sessionStorage: [createWebStorageEntry()] };\n if (entry === 'header') return { headers: [createHeaderEntry()] };\n }\n\n if (typeof entry === 'object' && entry !== null) {\n const typedEntry = entry as CookiesAttributes | StorageAttributes;\n\n if (isCookieEntry(typedEntry)) {\n return { cookies: [createCookieEntry(typedEntry as CookiesAttributes)] };\n }\n if ('type' in typedEntry && typedEntry.type === 'localStorage') {\n return {\n localStorage: [createWebStorageEntry(typedEntry as StorageAttributes)],\n };\n }\n if ('type' in typedEntry && typedEntry.type === 'sessionStorage') {\n return {\n sessionStorage: [\n createWebStorageEntry(typedEntry as StorageAttributes),\n ],\n };\n }\n if ('type' in typedEntry && typedEntry.type === 'header') {\n return { headers: [createHeaderEntry(typedEntry as StorageAttributes)] };\n }\n // Default to localStorage for ambiguous objects\n return {\n localStorage: [\n createWebStorageEntry(typedEntry as Omit<StorageAttributes, 'type'>),\n ],\n };\n }\n\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n};\n\nconst mergeStorageAttributes = (\n accumulated: ProcessedStorageAttributes,\n partial: Partial<ProcessedStorageAttributes>\n): ProcessedStorageAttributes => ({\n cookies: [...(accumulated.cookies ?? []), ...(partial.cookies ?? [])],\n localStorage: [\n ...(accumulated.localStorage ?? []),\n ...(partial.localStorage ?? []),\n ],\n sessionStorage: [\n ...(accumulated.sessionStorage ?? []),\n ...(partial.sessionStorage ?? []),\n ],\n headers: [...(accumulated.headers ?? []), ...(partial.headers ?? [])],\n});\n\n/**\n * Extracts and normalizes storage configuration into separate arrays for each storage type.\n * Called at config-build time so the result is pre-computed and stored in the config.\n *\n * @param options - The storage configuration from IntlayerConfig\n * @returns An object containing arrays for cookies, localStorage, sessionStorage and headers\n */\nexport const getStorageAttributes = (\n options: RoutingStorageInput\n): ProcessedStorageAttributes => {\n const emptyResult: ProcessedStorageAttributes = {\n cookies: [],\n localStorage: [],\n sessionStorage: [],\n headers: [],\n };\n\n if (options === false || options === undefined) return {};\n\n const result = Array.isArray(options)\n ? options.reduce<ProcessedStorageAttributes>((acc, entry) => {\n const partial = processStorageEntry(entry);\n return mergeStorageAttributes(acc, partial);\n }, emptyResult)\n : mergeStorageAttributes(emptyResult, processStorageEntry(options));\n\n // Remove empty arrays\n const cleanedResult: ProcessedStorageAttributes = {};\n\n if (result.cookies && result.cookies.length > 0) {\n cleanedResult.cookies = result.cookies;\n }\n\n if (result.localStorage && result.localStorage.length > 0) {\n cleanedResult.localStorage = result.localStorage;\n }\n\n if (result.sessionStorage && result.sessionStorage.length > 0) {\n cleanedResult.sessionStorage = result.sessionStorage;\n }\n\n if (result.headers && result.headers.length > 0) {\n cleanedResult.headers = result.headers;\n }\n\n return cleanedResult;\n};\n"],"mappings":";;;;AAyCA,MAAM,qBACJ,YACgB;CAChB,MAAM,EAAE,MAAM,MAAM,SAAS,QAAQ,QAAQ,UAAU,aACrD,WA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AAc,UAAU,OAAO;AAGjC,QAAO"}
|
package/dist/cjs/utils/index.cjs
CHANGED
|
@@ -14,6 +14,7 @@ const require_utils_getUsedNodeTypes = require('./getUsedNodeTypes.cjs');
|
|
|
14
14
|
const require_utils_logStack = require('./logStack.cjs');
|
|
15
15
|
const require_utils_parseFilePathPattern = require('./parseFilePathPattern.cjs');
|
|
16
16
|
const require_utils_retryManager = require('./retryManager.cjs');
|
|
17
|
+
const require_utils_setIntlayerIdentifier = require('./setIntlayerIdentifier.cjs');
|
|
17
18
|
const require_utils_stringFormatter_camelCaseToKebabCase = require('./stringFormatter/camelCaseToKebabCase.cjs');
|
|
18
19
|
const require_utils_stringFormatter_camelCaseToSentence = require('./stringFormatter/camelCaseToSentence.cjs');
|
|
19
20
|
const require_utils_stringFormatter_kebabCaseToCamelCase = require('./stringFormatter/kebabCaseToCamelCase.cjs');
|
|
@@ -49,5 +50,6 @@ exports.parseFilePathPattern = require_utils_parseFilePathPattern.parseFilePathP
|
|
|
49
50
|
exports.parseStringPattern = require_utils_parseFilePathPattern.parseStringPattern;
|
|
50
51
|
exports.retryManager = require_utils_retryManager.retryManager;
|
|
51
52
|
exports.setCache = require_utils_cacheMemory.setCache;
|
|
53
|
+
exports.setIntlayerIdentifier = require_utils_setIntlayerIdentifier.setIntlayerIdentifier;
|
|
52
54
|
exports.stableStringify = require_utils_cacheMemory.stableStringify;
|
|
53
55
|
exports.toLowerCamelCase = require_utils_stringFormatter_toLowerCamelCase.toLowerCamelCase;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/utils/setIntlayerIdentifier.ts
|
|
4
|
+
/**
|
|
5
|
+
* Sets the version of Intlayer in the window object.
|
|
6
|
+
* This is used for Intlayer detection in the browser.
|
|
7
|
+
*/
|
|
8
|
+
const setIntlayerIdentifier = () => {
|
|
9
|
+
if (typeof window !== "undefined") window.intlayer = { enabled: true };
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.setIntlayerIdentifier = setIntlayerIdentifier;
|
|
14
|
+
//# sourceMappingURL=setIntlayerIdentifier.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setIntlayerIdentifier.cjs","names":[],"sources":["../../../src/utils/setIntlayerIdentifier.ts"],"sourcesContent":["type Meta = {\n enabled: true;\n};\n\nexport type WindowsWithIntlayer = typeof window & {\n intlayer?: Meta;\n};\n\n/**\n * Sets the version of Intlayer in the window object.\n * This is used for Intlayer detection in the browser.\n */\nexport const setIntlayerIdentifier = (): void => {\n if (typeof window !== 'undefined') {\n (window as WindowsWithIntlayer).intlayer = {\n enabled: true,\n };\n }\n};\n"],"mappings":";;;;;;;AAYA,MAAa,8BAAoC;AAC/C,KAAI,OAAO,WAAW,YACpB,CAAC,OAA+B,WAAW,EACzC,SAAS,MACV"}
|
|
@@ -14,7 +14,19 @@ const configuration = new Proxy({}, {
|
|
|
14
14
|
return config != null && prop in config;
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
+
const internationalization = configuration.internationalization;
|
|
18
|
+
const dictionary = configuration.dictionary;
|
|
19
|
+
const routing = configuration.routing;
|
|
20
|
+
const content = configuration.content;
|
|
21
|
+
const system = configuration.system;
|
|
22
|
+
const editor = configuration.editor;
|
|
23
|
+
const log = configuration.log;
|
|
24
|
+
const ai = configuration.ai;
|
|
25
|
+
const build = configuration.build;
|
|
26
|
+
const compiler = configuration.compiler;
|
|
27
|
+
const schemas = configuration.schemas;
|
|
28
|
+
const plugins = configuration.plugins;
|
|
17
29
|
|
|
18
30
|
//#endregion
|
|
19
|
-
export { configuration as default };
|
|
31
|
+
export { ai, build, compiler, content, configuration as default, dictionary, editor, internationalization, log, plugins, routing, schemas, system };
|
|
20
32
|
//# sourceMappingURL=built.browser.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"built.browser.mjs","names":[],"sources":["../../src/built.browser.ts"],"sourcesContent":["/**\n * @intlayer/config/built — browser build\n *\n * In browser bundles this module is selected automatically via the `browser`\n * export condition in package.json (supported by Vite, webpack, Rollup, etc.).\n *\n * Configuration is resolved at *access time* (lazy) from `window.INTLAYER_CONFIG`\n * so that it works both when:\n *\n * - A build plugin (vite-intlayer / withIntlayer) injects the value via\n * bundler `define` (static replacement at build time), OR\n * - The application calls `installIntlayer(config)` at runtime before any\n * config field is first accessed.\n */\nimport type { IntlayerConfig } from '@intlayer/types/config';\n// This import brings in the `declare global { interface Window { INTLAYER_CONFIG } }` augmentation\nimport type {} from './configFile/buildBrowserConfiguration';\n\n/**\n * Proxy that reads each top-level key from `window.INTLAYER_CONFIG` lazily.\n * This avoids the module-evaluation timing issue: the proxy is safe to import\n * at the top of any file because the actual `window.INTLAYER_CONFIG` value is\n * only read when a property is first accessed.\n */\nconst configuration = new Proxy({} as IntlayerConfig, {\n get(_target, prop: string) {\n const config =\n typeof window !== 'undefined' ? window.INTLAYER_CONFIG : undefined;\n return (config as Record<string, unknown> | undefined)?.[prop];\n },\n has(_target, prop: string) {\n const config =\n typeof window !== 'undefined' ? window.INTLAYER_CONFIG : undefined;\n return config != null && prop in config;\n },\n});\n\nexport default configuration;\n"],"mappings":";;;;;;;AAwBA,MAAM,gBAAgB,IAAI,MAAM,EAAE,EAAoB;CACpD,IAAI,SAAS,MAAc;AAGzB,UADE,OAAO,WAAW,cAAc,OAAO,kBAAkB,UACF;;CAE3D,IAAI,SAAS,MAAc;EACzB,MAAM,SACJ,OAAO,WAAW,cAAc,OAAO,kBAAkB;AAC3D,SAAO,UAAU,QAAQ,QAAQ;;CAEpC,CAAC"}
|
|
1
|
+
{"version":3,"file":"built.browser.mjs","names":[],"sources":["../../src/built.browser.ts"],"sourcesContent":["/**\n * @intlayer/config/built — browser build\n *\n * In browser bundles this module is selected automatically via the `browser`\n * export condition in package.json (supported by Vite, webpack, Rollup, etc.).\n *\n * Configuration is resolved at *access time* (lazy) from `window.INTLAYER_CONFIG`\n * so that it works both when:\n *\n * - A build plugin (vite-intlayer / withIntlayer) injects the value via\n * bundler `define` (static replacement at build time), OR\n * - The application calls `installIntlayer(config)` at runtime before any\n * config field is first accessed.\n */\nimport type { IntlayerConfig } from '@intlayer/types/config';\n// This import brings in the `declare global { interface Window { INTLAYER_CONFIG } }` augmentation\nimport type {} from './configFile/buildBrowserConfiguration';\n\n/**\n * Proxy that reads each top-level key from `window.INTLAYER_CONFIG` lazily.\n * This avoids the module-evaluation timing issue: the proxy is safe to import\n * at the top of any file because the actual `window.INTLAYER_CONFIG` value is\n * only read when a property is first accessed.\n */\nconst configuration = new Proxy({} as IntlayerConfig, {\n get(_target, prop: string) {\n const config =\n typeof window !== 'undefined' ? window.INTLAYER_CONFIG : undefined;\n return (config as Record<string, unknown> | undefined)?.[prop];\n },\n has(_target, prop: string) {\n const config =\n typeof window !== 'undefined' ? window.INTLAYER_CONFIG : undefined;\n return config != null && prop in config;\n },\n});\n\nexport const internationalization = configuration.internationalization;\nexport const dictionary = configuration.dictionary;\nexport const routing = configuration.routing;\nexport const content = configuration.content;\nexport const system = configuration.system;\nexport const editor = configuration.editor;\nexport const log = configuration.log;\nexport const ai = configuration.ai;\nexport const build = configuration.build;\nexport const compiler = configuration.compiler;\nexport const schemas = configuration.schemas;\nexport const plugins = configuration.plugins;\n\nexport default configuration;\n"],"mappings":";;;;;;;AAwBA,MAAM,gBAAgB,IAAI,MAAM,EAAE,EAAoB;CACpD,IAAI,SAAS,MAAc;AAGzB,UADE,OAAO,WAAW,cAAc,OAAO,kBAAkB,UACF;;CAE3D,IAAI,SAAS,MAAc;EACzB,MAAM,SACJ,OAAO,WAAW,cAAc,OAAO,kBAAkB;AAC3D,SAAO,UAAU,QAAQ,QAAQ;;CAEpC,CAAC;AAEF,MAAa,uBAAuB,cAAc;AAClD,MAAa,aAAa,cAAc;AACxC,MAAa,UAAU,cAAc;AACrC,MAAa,UAAU,cAAc;AACrC,MAAa,SAAS,cAAc;AACpC,MAAa,SAAS,cAAc;AACpC,MAAa,MAAM,cAAc;AACjC,MAAa,KAAK,cAAc;AAChC,MAAa,QAAQ,cAAc;AACnC,MAAa,WAAW,cAAc;AACtC,MAAa,UAAU,cAAc;AACrC,MAAa,UAAU,cAAc"}
|
package/dist/esm/built.mjs
CHANGED
|
@@ -2,7 +2,19 @@ import { getConfiguration } from "./configFile/getConfiguration.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/built.ts
|
|
4
4
|
const configuration = getConfiguration();
|
|
5
|
+
const internationalization = configuration.internationalization;
|
|
6
|
+
const dictionary = configuration.dictionary;
|
|
7
|
+
const routing = configuration.routing;
|
|
8
|
+
const content = configuration.content;
|
|
9
|
+
const system = configuration.system;
|
|
10
|
+
const editor = configuration.editor;
|
|
11
|
+
const log = configuration.log;
|
|
12
|
+
const ai = configuration.ai;
|
|
13
|
+
const build = configuration.build;
|
|
14
|
+
const compiler = configuration.compiler;
|
|
15
|
+
const schemas = configuration.schemas;
|
|
16
|
+
const plugins = configuration.plugins;
|
|
5
17
|
|
|
6
18
|
//#endregion
|
|
7
|
-
export { configuration as default };
|
|
19
|
+
export { ai, build, compiler, content, configuration as default, dictionary, editor, internationalization, log, plugins, routing, schemas, system };
|
|
8
20
|
//# sourceMappingURL=built.mjs.map
|
package/dist/esm/built.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"built.mjs","names":[],"sources":["../../src/built.ts"],"sourcesContent":["/**\n * @intlayer/config/built is a package that only returns the configuration file as a JSON object.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n */\n\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { getConfiguration } from './configFile/getConfiguration';\n\nconst configuration: IntlayerConfig = getConfiguration();\n\nexport default configuration;\n"],"mappings":";;;AAQA,MAAM,gBAAgC,kBAAkB"}
|
|
1
|
+
{"version":3,"file":"built.mjs","names":[],"sources":["../../src/built.ts"],"sourcesContent":["/**\n * @intlayer/config/built is a package that only returns the configuration file as a JSON object.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n */\n\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { getConfiguration } from './configFile/getConfiguration';\n\nconst configuration: IntlayerConfig = getConfiguration();\n\nexport const internationalization = configuration.internationalization;\nexport const dictionary = configuration.dictionary;\nexport const routing = configuration.routing;\nexport const content = configuration.content;\nexport const system = configuration.system;\nexport const editor = configuration.editor;\nexport const log = configuration.log;\nexport const ai = configuration.ai;\nexport const build = configuration.build;\nexport const compiler = configuration.compiler;\nexport const schemas = configuration.schemas;\nexport const plugins = configuration.plugins;\n\nexport default configuration;\n"],"mappings":";;;AAQA,MAAM,gBAAgC,kBAAkB;AAExD,MAAa,uBAAuB,cAAc;AAClD,MAAa,aAAa,cAAc;AACxC,MAAa,UAAU,cAAc;AACrC,MAAa,UAAU,cAAc;AACrC,MAAa,SAAS,cAAc;AACpC,MAAa,SAAS,cAAc;AACpC,MAAa,MAAM,cAAc;AACjC,MAAa,KAAK,cAAc;AAChC,MAAa,QAAQ,cAAc;AACnC,MAAa,WAAW,cAAc;AACtC,MAAa,UAAU,cAAc;AACrC,MAAa,UAAU,cAAc"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { getAlias } from "../utils/alias.mjs";
|
|
2
|
+
import { getConfiguration } from "../configFile/getConfiguration.mjs";
|
|
3
|
+
import { getConfigEnvVars } from "../envVars/envVars.mjs";
|
|
4
|
+
import { BundleLogger } from "./logBundle.mjs";
|
|
5
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
6
|
+
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
7
|
+
import packageJSON from "@intlayer/types/package.json" with { type: "json" };
|
|
8
|
+
import { build } from "esbuild";
|
|
9
|
+
import { exec } from "node:child_process";
|
|
10
|
+
import { promisify } from "node:util";
|
|
11
|
+
|
|
12
|
+
//#region src/bundle/index.ts
|
|
13
|
+
const execAsync = promisify(exec);
|
|
14
|
+
const packageList = [
|
|
15
|
+
"next-intlayer",
|
|
16
|
+
"react-intlayer",
|
|
17
|
+
"vue-intlayer",
|
|
18
|
+
"svelte-intlayer",
|
|
19
|
+
"preact-intlayer",
|
|
20
|
+
"solid-intlayer",
|
|
21
|
+
"angular-intlayer",
|
|
22
|
+
"lit-intlayer",
|
|
23
|
+
"express-intlayer",
|
|
24
|
+
"hono-intlayer",
|
|
25
|
+
"fastify-intlayer",
|
|
26
|
+
"adonis-intlayer",
|
|
27
|
+
"vanilla-intlayer",
|
|
28
|
+
"intlayer"
|
|
29
|
+
];
|
|
30
|
+
const defaultVersion = packageJSON.version;
|
|
31
|
+
/**
|
|
32
|
+
* Bundle the application content using esbuild.
|
|
33
|
+
* It uses the Intlayer configuration to set up aliases and other esbuild options.
|
|
34
|
+
*
|
|
35
|
+
* @param options - Bundle options including entryPoint, outfile, and esbuild options.
|
|
36
|
+
* @returns The build result.
|
|
37
|
+
*/
|
|
38
|
+
const bundleIntlayer = async (options) => {
|
|
39
|
+
const { outfile = "intlayer-bundle.js", configOptions, bundlePackages = [...packageList], version = defaultVersion, ...esbuildOptions } = options;
|
|
40
|
+
const intlayerConfig = getConfiguration(configOptions);
|
|
41
|
+
const logger = new BundleLogger(intlayerConfig);
|
|
42
|
+
const alias = getAlias({
|
|
43
|
+
configuration: intlayerConfig,
|
|
44
|
+
formatter: (value) => resolve(process.cwd(), value)
|
|
45
|
+
});
|
|
46
|
+
const treeShakingDefines = getConfigEnvVars(intlayerConfig, (key) => `process.env.${key}`, (value) => `"${value}"`);
|
|
47
|
+
const intlayerBundlePlugin = {
|
|
48
|
+
name: "intlayer-bundle-plugin",
|
|
49
|
+
setup(build) {
|
|
50
|
+
const packagesRegex = new RegExp(`^(${bundlePackages.map((packages) => packages.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})(\\/.*)?$`);
|
|
51
|
+
build.onResolve({ filter: packagesRegex }, () => ({ external: false }));
|
|
52
|
+
build.onResolve({ filter: /^@intlayer\// }, () => ({ external: false }));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const tempDir = join(intlayerConfig.system.tempDir, "intlayer-bundle-tmp");
|
|
56
|
+
logger.setStatus("installing");
|
|
57
|
+
try {
|
|
58
|
+
await rm(tempDir, {
|
|
59
|
+
recursive: true,
|
|
60
|
+
force: true
|
|
61
|
+
});
|
|
62
|
+
await mkdir(tempDir, { recursive: true });
|
|
63
|
+
const deps = Object.fromEntries(bundlePackages.map((pkg) => [pkg, version]));
|
|
64
|
+
await writeFile(join(tempDir, "package.json"), JSON.stringify({
|
|
65
|
+
dependencies: deps,
|
|
66
|
+
type: "module"
|
|
67
|
+
}));
|
|
68
|
+
let pm = "npm install";
|
|
69
|
+
try {
|
|
70
|
+
await execAsync("bun --version");
|
|
71
|
+
pm = "bun install";
|
|
72
|
+
} catch {}
|
|
73
|
+
await execAsync(pm, { cwd: tempDir });
|
|
74
|
+
const buildOptions = {
|
|
75
|
+
bundle: true,
|
|
76
|
+
outfile: isAbsolute(outfile) ? outfile : join(process.cwd(), outfile),
|
|
77
|
+
absWorkingDir: tempDir,
|
|
78
|
+
platform: "browser",
|
|
79
|
+
conditions: [
|
|
80
|
+
"browser",
|
|
81
|
+
"module",
|
|
82
|
+
"import",
|
|
83
|
+
"default"
|
|
84
|
+
],
|
|
85
|
+
minify: true,
|
|
86
|
+
minifyIdentifiers: true,
|
|
87
|
+
treeShaking: true,
|
|
88
|
+
format: "iife",
|
|
89
|
+
ignoreAnnotations: true,
|
|
90
|
+
stdin: {
|
|
91
|
+
contents: bundlePackages.map((packageName) => {
|
|
92
|
+
const globalName = packageName.split("-").map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
|
|
93
|
+
return `import * as ${globalName} from '${packageName}';\nif (typeof window !== 'undefined') { window['${globalName}'] = ${globalName}; }`;
|
|
94
|
+
}).join("\n"),
|
|
95
|
+
resolveDir: tempDir
|
|
96
|
+
},
|
|
97
|
+
define: {
|
|
98
|
+
"process.env": "{}",
|
|
99
|
+
...treeShakingDefines,
|
|
100
|
+
...esbuildOptions.define
|
|
101
|
+
},
|
|
102
|
+
alias: {
|
|
103
|
+
...alias,
|
|
104
|
+
...esbuildOptions.alias
|
|
105
|
+
},
|
|
106
|
+
...esbuildOptions,
|
|
107
|
+
plugins: [intlayerBundlePlugin, ...esbuildOptions.plugins || []]
|
|
108
|
+
};
|
|
109
|
+
logger.setStatus("bundling");
|
|
110
|
+
const result = await build(buildOptions);
|
|
111
|
+
logger.setStatus("success");
|
|
112
|
+
return result;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
logger.setError(error);
|
|
115
|
+
throw error;
|
|
116
|
+
} finally {
|
|
117
|
+
await rm(tempDir, {
|
|
118
|
+
recursive: true,
|
|
119
|
+
force: true
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
export { bundleIntlayer, packageList };
|
|
126
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/bundle/index.ts"],"sourcesContent":["import { exec } from 'node:child_process';\nimport { mkdir, rm, writeFile } from 'node:fs/promises';\nimport { isAbsolute, join, resolve } from 'node:path';\nimport { promisify } from 'node:util';\nimport packageJSON from '@intlayer/types/package.json' with { type: 'json' };\nimport { type BuildOptions, build, type Plugin } from 'esbuild';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '../configFile/getConfiguration';\nimport { getConfigEnvVars } from '../envVars/envVars';\nimport { getAlias } from '../utils/alias';\nimport { BundleLogger } from './logBundle';\n\nconst execAsync = promisify(exec);\n\nexport const packageList = [\n 'next-intlayer',\n 'react-intlayer',\n 'vue-intlayer',\n 'svelte-intlayer',\n 'preact-intlayer',\n 'solid-intlayer',\n 'angular-intlayer',\n 'lit-intlayer',\n 'express-intlayer',\n 'hono-intlayer',\n 'fastify-intlayer',\n 'adonis-intlayer',\n 'vanilla-intlayer',\n 'intlayer',\n] as const;\n\nconst defaultVersion = packageJSON.version;\n\nexport type BundleIntlayerOptions = {\n outfile?: string;\n configOptions?: GetConfigurationOptions;\n bundlePackages?: string[];\n version?: string;\n} & BuildOptions;\n\n/**\n * Bundle the application content using esbuild.\n * It uses the Intlayer configuration to set up aliases and other esbuild options.\n *\n * @param options - Bundle options including entryPoint, outfile, and esbuild options.\n * @returns The build result.\n */\nexport const bundleIntlayer = async (options: BundleIntlayerOptions) => {\n const {\n outfile = 'intlayer-bundle.js',\n configOptions,\n bundlePackages = [...packageList],\n version = defaultVersion,\n ...esbuildOptions\n } = options;\n\n const intlayerConfig = getConfiguration(configOptions);\n\n const logger = new BundleLogger(intlayerConfig);\n\n const alias = getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(process.cwd(), value),\n });\n\n // Fetch dictionaries and calculate tree-shaking variables\n\n const treeShakingDefines = getConfigEnvVars(\n intlayerConfig,\n (key) => `process.env.${key}`,\n (value) => `\"${value}\"` // Properly wraps the string in quotes\n );\n\n const intlayerBundlePlugin: Plugin = {\n name: 'intlayer-bundle-plugin',\n setup(build) {\n // Create a regex that matches the provided packages\n // It matches both the package name and any sub-exports\n const packagesRegex = new RegExp(\n `^(${bundlePackages\n .map((packages) => packages.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'))\n .join('|')})(\\\\/.*)?$`\n );\n\n build.onResolve({ filter: packagesRegex }, () => ({\n external: false,\n }));\n\n // Also ensure @intlayer/ packages are bundled if not explicitly excluded\n build.onResolve({ filter: /^@intlayer\\// }, () => ({\n external: false,\n }));\n },\n };\n\n const tempDir = join(intlayerConfig.system.tempDir, 'intlayer-bundle-tmp');\n\n logger.setStatus('installing');\n\n try {\n // Clean and prepare temp directory\n await rm(tempDir, { recursive: true, force: true });\n await mkdir(tempDir, { recursive: true });\n\n // Write package.json to fetch packages via npm/bun\n const deps = Object.fromEntries(\n bundlePackages.map((pkg) => [pkg, version])\n );\n await writeFile(\n join(tempDir, 'package.json'),\n JSON.stringify({ dependencies: deps, type: 'module' })\n );\n\n // Determine package manager (prefer bun if available)\n let pm = 'npm install';\n try {\n await execAsync('bun --version');\n pm = 'bun install';\n } catch {}\n\n // Install the packages in the temp directory\n await execAsync(pm, { cwd: tempDir });\n\n const absoluteOutfile = isAbsolute(outfile)\n ? outfile\n : join(process.cwd(), outfile);\n\n const buildOptions: BuildOptions = {\n bundle: true,\n outfile: absoluteOutfile,\n absWorkingDir: tempDir,\n platform: 'browser',\n conditions: ['browser', 'module', 'import', 'default'],\n minify: true,\n minifyIdentifiers: true,\n treeShaking: true,\n format: 'iife',\n ignoreAnnotations: true,\n stdin: {\n contents: bundlePackages\n .map((packageName) => {\n // Convert package name to global name (e.g. vanilla-intlayer -> VanillaIntlayer)\n const globalName = packageName\n .split('-')\n .map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`)\n .join('');\n // Create a global variable for each package\n return `import * as ${globalName} from '${packageName}';\\nif (typeof window !== 'undefined') { window['${globalName}'] = ${globalName}; }`;\n })\n .join('\\n'),\n resolveDir: tempDir,\n },\n define: {\n 'process.env': '{}', // Fix ReferenceError: process is not defined\n // Inject generated environment variables\n ...treeShakingDefines,\n ...esbuildOptions.define,\n },\n alias: {\n ...alias,\n ...esbuildOptions.alias,\n },\n ...esbuildOptions,\n plugins: [intlayerBundlePlugin, ...(esbuildOptions.plugins || [])],\n };\n\n logger.setStatus('bundling');\n const result = await build(buildOptions);\n logger.setStatus('success');\n return result;\n } catch (error) {\n logger.setError(error);\n throw error;\n } finally {\n // Clean up temp directory\n await rm(tempDir, { recursive: true, force: true });\n }\n};\n"],"mappings":";;;;;;;;;;;;AAcA,MAAM,YAAY,UAAU,KAAK;AAEjC,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,iBAAiB,YAAY;;;;;;;;AAgBnC,MAAa,iBAAiB,OAAO,YAAm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AK,EAAE,QAAQ;GAK9B,eAAe;GACf,UAAU;GACV,YAAY;IAAC;IAAW;IAAU;IAAU;IAAU;GACtD,QAAQ;GACR,mBAAmB;GACnB,aAAa;GACb,QAAQ;GACR,mBAAmB;GACnB,OAAO;IACL,UAAU,eACP,KAAK,gBAAgB;KAEpB,MAAM,aAAa,YAChB,MAAM,IAAI,CACV,KAAK,SAAS,GAAG,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE,GAAG,CAChE,KAAK,GAAG;AAEX,YAAO,eAAe,WAAW,SAAS,YAAY,mDAAmD,WAAW,OAAO,WAAW;MACtI,CACD,KAAK,KAAK;IACb,YAAY;IACb;GACD,QAAQ;IACN,eAAe;IAEf,GAAG;IACH,GAAG,eAAe;IACnB;GACD,OAAO;IACL,GAAG;IACH,GAAG,eAAe;IACnB;GACD,GAAG;GACH,SAAS,CAAC,sBAAsB,GAAI,eAAe,WAAW,EAAE,CAAE;GACnE;AAED,SAAO,UAAU,WAAW;EAC5B,MAAM,SAAS,MAAM,MAAM,aAAa;AACxC,SAAO,UAAU,UAAU;AAC3B,SAAO;UACA,OAAO;AACd,SAAO,SAAS,MAAM;AACtB,QAAM;WACE;AAER,QAAM,GAAG,SAAS;GAAE,WAAW;GAAM,OAAO;GAAM,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { BLUE, RED } from "../colors.mjs";
|
|
2
|
+
import { extractErrorMessage } from "../utils/extractErrorMessage.mjs";
|
|
3
|
+
import { colorize, getPrefix, spinnerFrames, v, x } from "../logger.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/bundle/logBundle.ts
|
|
6
|
+
var BundleLogger = class {
|
|
7
|
+
status = "pending";
|
|
8
|
+
spinnerTimer = null;
|
|
9
|
+
spinnerIndex = 0;
|
|
10
|
+
renderedLines = 0;
|
|
11
|
+
isFinished = false;
|
|
12
|
+
prefix;
|
|
13
|
+
lastRenderedState = "";
|
|
14
|
+
error;
|
|
15
|
+
constructor(configuration) {
|
|
16
|
+
this.prefix = getPrefix(configuration?.log?.prefix) ?? "";
|
|
17
|
+
}
|
|
18
|
+
setStatus(status) {
|
|
19
|
+
if (this.isFinished) return;
|
|
20
|
+
this.status = status;
|
|
21
|
+
if (status === "success") this.finish();
|
|
22
|
+
else {
|
|
23
|
+
this.startSpinner();
|
|
24
|
+
this.render();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
setError(error) {
|
|
28
|
+
if (this.isFinished) return;
|
|
29
|
+
this.status = "error";
|
|
30
|
+
this.error = extractErrorMessage(error);
|
|
31
|
+
this.finish();
|
|
32
|
+
}
|
|
33
|
+
startSpinner() {
|
|
34
|
+
if (this.spinnerTimer || this.isFinished) return;
|
|
35
|
+
this.spinnerTimer = setInterval(() => {
|
|
36
|
+
this.spinnerIndex = (this.spinnerIndex + 1) % spinnerFrames.length;
|
|
37
|
+
this.render();
|
|
38
|
+
}, 100);
|
|
39
|
+
}
|
|
40
|
+
stopSpinner() {
|
|
41
|
+
if (!this.spinnerTimer) return;
|
|
42
|
+
clearInterval(this.spinnerTimer);
|
|
43
|
+
this.spinnerTimer = null;
|
|
44
|
+
}
|
|
45
|
+
finish() {
|
|
46
|
+
this.isFinished = true;
|
|
47
|
+
this.stopSpinner();
|
|
48
|
+
this.render();
|
|
49
|
+
}
|
|
50
|
+
render() {
|
|
51
|
+
const frame = spinnerFrames[this.spinnerIndex];
|
|
52
|
+
const clock = colorize(frame, BLUE);
|
|
53
|
+
const lines = [];
|
|
54
|
+
if (this.status === "installing") lines.push(`${this.prefix} ${clock} Fetching and resolving packages...`);
|
|
55
|
+
else if (this.status === "bundling") {
|
|
56
|
+
lines.push(`${this.prefix} ${v} Fetching and resolving packages...`);
|
|
57
|
+
lines.push(`${this.prefix} ${clock} Bundling application...`);
|
|
58
|
+
} else if (this.status === "success") {
|
|
59
|
+
lines.push(`${this.prefix} ${v} Fetching and resolving packages...`);
|
|
60
|
+
lines.push(`${this.prefix} ${v} Bundling application...`);
|
|
61
|
+
} else if (this.status === "error") lines.push(`${this.prefix} ${x} Bundle failed: ${colorize(this.error ?? "Unknown error", RED)}`);
|
|
62
|
+
const currentState = lines.join("\n");
|
|
63
|
+
if (currentState === this.lastRenderedState) return;
|
|
64
|
+
this.lastRenderedState = currentState;
|
|
65
|
+
if (this.renderedLines > 0) process.stdout.write(`\x1b[${this.renderedLines}F`);
|
|
66
|
+
const totalLinesToClear = Math.max(this.renderedLines, lines.length);
|
|
67
|
+
for (let i = 0; i < totalLinesToClear; i++) {
|
|
68
|
+
process.stdout.write("\x1B[2K");
|
|
69
|
+
if (lines[i] !== void 0) process.stdout.write(lines[i]);
|
|
70
|
+
process.stdout.write("\n");
|
|
71
|
+
}
|
|
72
|
+
this.renderedLines = lines.length;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
export { BundleLogger };
|
|
78
|
+
//# sourceMappingURL=logBundle.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logBundle.mjs","names":["ANSIColors.BLUE","ANSIColors.RED"],"sources":["../../../src/bundle/logBundle.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\nimport * as ANSIColors from '../colors';\nimport { colorize, getPrefix, spinnerFrames, v, x } from '../logger';\nimport { extractErrorMessage } from '../utils/extractErrorMessage';\n\nexport class BundleLogger {\n private status: 'pending' | 'installing' | 'bundling' | 'success' | 'error' =\n 'pending';\n private spinnerTimer: NodeJS.Timeout | null = null;\n private spinnerIndex = 0;\n private renderedLines = 0;\n private isFinished = false;\n private readonly prefix: string;\n private lastRenderedState = '';\n private error: string | undefined;\n\n constructor(configuration?: IntlayerConfig) {\n this.prefix = getPrefix(configuration?.log?.prefix) ?? '';\n }\n\n setStatus(status: 'installing' | 'bundling' | 'success') {\n if (this.isFinished) return;\n this.status = status;\n if (status === 'success') {\n this.finish();\n } else {\n this.startSpinner();\n this.render();\n }\n }\n\n setError(error?: unknown) {\n if (this.isFinished) return;\n this.status = 'error';\n this.error = extractErrorMessage(error);\n this.finish();\n }\n\n private startSpinner() {\n if (this.spinnerTimer || this.isFinished) return;\n this.spinnerTimer = setInterval(() => {\n this.spinnerIndex = (this.spinnerIndex + 1) % spinnerFrames.length;\n this.render();\n }, 100);\n }\n\n private stopSpinner() {\n if (!this.spinnerTimer) return;\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n\n private finish() {\n this.isFinished = true;\n this.stopSpinner();\n this.render();\n }\n\n private render() {\n const frame = spinnerFrames[this.spinnerIndex];\n const clock = colorize(frame, ANSIColors.BLUE);\n const lines: string[] = [];\n\n if (this.status === 'installing') {\n lines.push(`${this.prefix} ${clock} Fetching and resolving packages...`);\n } else if (this.status === 'bundling') {\n lines.push(`${this.prefix} ${v} Fetching and resolving packages...`);\n lines.push(`${this.prefix} ${clock} Bundling application...`);\n } else if (this.status === 'success') {\n lines.push(`${this.prefix} ${v} Fetching and resolving packages...`);\n lines.push(`${this.prefix} ${v} Bundling application...`);\n } else if (this.status === 'error') {\n lines.push(\n `${this.prefix} ${x} Bundle failed: ${colorize(this.error ?? 'Unknown error', ANSIColors.RED)}`\n );\n }\n\n const currentState = lines.join('\\n');\n if (currentState === this.lastRenderedState) return;\n this.lastRenderedState = currentState;\n\n if (this.renderedLines > 0) {\n process.stdout.write(`\\x1b[${this.renderedLines}F`);\n }\n\n const totalLinesToClear = Math.max(this.renderedLines, lines.length);\n for (let i = 0; i < totalLinesToClear; i++) {\n process.stdout.write('\\x1b[2K');\n if (lines[i] !== undefined) {\n process.stdout.write(lines[i]);\n }\n process.stdout.write('\\n');\n }\n\n this.renderedLines = lines.length;\n }\n}\n"],"mappings":";;;;;AAKA,IAAa,eAAb,MAA0B;CACxB,AAAQ,SACN;CACF,AAAQ,eAAsC;CAC9C,AAAQ,eAAe;CACvB,AAAQ,gBAAgB;CACxB,AAAQ,aAAa;CACrB,AAAiB;CACjB,AAAQ,oBAAoB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,SAAS,iBAAiBC,IAAe,GAC9F;EAGH,MAAM,eAAe,MAAM,KAAK,KAAK;AACrC,MAAI,iBAAiB,KAAK,kBAAmB;AAC7C,OAAK,oBAAoB;AAEzB,MAAI,KAAK,gBAAgB,EACvB,SAAQ,OAAO,MAAM,QAAQ,KAAK,cAAc,GAAG;EAGrD,MAAM,oBAAoB,KAAK,IAAI,KAAK,eAAe,MAAM,OAAO;AACpE,OAAK,IAAI,IAAI,GAAG,IAAI,mBAAmB,KAAK;AAC1C,WAAQ,OAAO,MAAM,UAAU;AAC/B,OAAI,MAAM,OAAO,OACf,SAAQ,OAAO,MAAM,MAAM,GAAG;AAEhC,WAAQ,OAAO,MAAM,KAAK;;AAG5B,OAAK,gBAAgB,MAAM"}
|
package/dist/esm/client.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { normalizePath } from "./utils/normalizePath.mjs";
|
|
2
2
|
import { extractErrorMessage } from "./utils/extractErrorMessage.mjs";
|
|
3
3
|
import { logStack } from "./utils/logStack.mjs";
|
|
4
|
+
import { setIntlayerIdentifier } from "./utils/setIntlayerIdentifier.mjs";
|
|
4
5
|
import { camelCaseToKebabCase } from "./utils/stringFormatter/camelCaseToKebabCase.mjs";
|
|
5
6
|
import { camelCaseToSentence } from "./utils/stringFormatter/camelCaseToSentence.mjs";
|
|
6
7
|
import { kebabCaseToCamelCase } from "./utils/stringFormatter/kebabCaseToCamelCase.mjs";
|
|
7
8
|
import { toLowerCamelCase } from "./utils/stringFormatter/toLowerCamelCase.mjs";
|
|
8
9
|
import { buildBrowserConfiguration, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, extractBrowserConfiguration } from "./configFile/buildBrowserConfiguration.mjs";
|
|
9
10
|
|
|
10
|
-
export { buildBrowserConfiguration, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, camelCaseToKebabCase, camelCaseToSentence, extractBrowserConfiguration, extractErrorMessage, kebabCaseToCamelCase, logStack, normalizePath, toLowerCamelCase };
|
|
11
|
+
export { buildBrowserConfiguration, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, camelCaseToKebabCase, camelCaseToSentence, extractBrowserConfiguration, extractErrorMessage, kebabCaseToCamelCase, logStack, normalizePath, setIntlayerIdentifier, toLowerCamelCase };
|
|
@@ -3,7 +3,6 @@ import { getStorageAttributes } from "../utils/getStorageAttributes.mjs";
|
|
|
3
3
|
import { APPLICATION_URL, BACKEND_URL, CMS_URL, DICTIONARY_PRIORITY_STRATEGY, EDITOR_URL, IS_ENABLED, LIVE_SYNC, LIVE_SYNC_PORT, PORT } from "../defaultValues/editor.mjs";
|
|
4
4
|
import { DEFAULT_LOCALE, LOCALES, REQUIRED_LOCALES, STRICT_MODE } from "../defaultValues/internationalization.mjs";
|
|
5
5
|
import { MODE, PREFIX } from "../defaultValues/log.mjs";
|
|
6
|
-
import configPackageJson from "@intlayer/types/package.json" with { type: "json" };
|
|
7
6
|
|
|
8
7
|
//#region src/configFile/buildBrowserConfiguration.ts
|
|
9
8
|
/**
|
|
@@ -112,11 +111,6 @@ const buildBrowserConfiguration = (customConfig) => {
|
|
|
112
111
|
log: {
|
|
113
112
|
mode,
|
|
114
113
|
prefix
|
|
115
|
-
},
|
|
116
|
-
metadata: {
|
|
117
|
-
name: "Intlayer",
|
|
118
|
-
version: configPackageJson.version,
|
|
119
|
-
doc: "https://intlayer.org/docs"
|
|
120
114
|
}
|
|
121
115
|
};
|
|
122
116
|
};
|
|
@@ -157,8 +151,7 @@ const extractBrowserConfiguration = (config) => ({
|
|
|
157
151
|
log: {
|
|
158
152
|
mode: config.log.mode,
|
|
159
153
|
prefix: config.log.prefix
|
|
160
|
-
}
|
|
161
|
-
metadata: config.metadata
|
|
154
|
+
}
|
|
162
155
|
});
|
|
163
156
|
|
|
164
157
|
//#endregion
|