@intlayer/unmerged-dictionaries-entry
Version:
Provides the entry path for Intlayer dictionaries, solving filesystem retrieval issues for bundlers like Webpack and Rollup.
1 lines • 2.19 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","names":["system"],"sources":["../../src/index.ts"],"sourcesContent":["/**\n * @intlayer/unmerged-dictionaries-entry is a package that only returns the unmerged dictionary entry file.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\n\nimport { existsSync, readdirSync, readFileSync } from 'node:fs';\nimport { basename, extname, join } from 'node:path';\nimport { build, system } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { DictionaryKeys } from '@intlayer/types/module_augmentation';\n\nexport type UnmergedDictionaries = Record<DictionaryKeys, Dictionary[]>;\n\ntype GetUnmergedDictionaries = (\n configuration?: Pick<IntlayerConfig, 'system' | 'build'>\n) => UnmergedDictionaries;\n\nexport const getUnmergedDictionaries: GetUnmergedDictionaries = (\n configuration: Pick<IntlayerConfig, 'system' | 'build'> = { system, build }\n) => {\n const { system } = configuration;\n const { unmergedDictionariesDir } = system;\n\n const dictionaries: Record<string, any> = {};\n\n if (existsSync(unmergedDictionariesDir)) {\n // Read JSON files directly to avoid require.cache memory leak\n const files = readdirSync(unmergedDictionariesDir).filter((file) =>\n file.endsWith('.json')\n );\n\n for (const file of files) {\n const key = basename(file, extname(file));\n const content = readFileSync(\n join(unmergedDictionariesDir, file),\n 'utf-8'\n );\n dictionaries[key] = JSON.parse(content);\n }\n }\n\n return dictionaries as UnmergedDictionaries;\n};\n"],"mappings":";;;;;;;;;;;AAmBA,MAAa,2BACX,gBAA0D;CAAE;CAAQ;AAAM,MACvE;CACH,MAAM,EAAE,qBAAW;CACnB,MAAM,EAAE,4BAA4BA;CAEpC,MAAM,eAAoC,CAAC;CAE3C,4BAAe,uBAAuB,GAAG;EAEvC,MAAM,iCAAoB,uBAAuB,EAAE,QAAQ,SACzD,KAAK,SAAS,OAAO,CACvB;EAEA,KAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,8BAAe,6BAAc,IAAI,CAAC;GACxC,MAAM,wDACC,yBAAyB,IAAI,GAClC,OACF;GACA,aAAa,OAAO,KAAK,MAAM,OAAO;EACxC;CACF;CAEA,OAAO;AACT"}