UNPKG

@intlayer/dictionaries-entry

Version:

Provides the entry path for Intlayer dictionaries, solving filesystem retrieval issues for bundlers like Webpack and Rollup.

1 lines 1.46 kB
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["/**\n * @intlayer/dictionaries-entry is a package that only returns the 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 { ESMxCJSRequire, getConfiguration } from '@intlayer/config';\nimport { existsSync } from 'fs';\nimport { join } from 'path';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\n\nexport const getDictionaries = () => {\n const { content } = getConfiguration();\n\n const dictionariesPath = join(content.mainDir, 'dictionaries.cjs');\n\n let dictionaries = {};\n if (existsSync(dictionariesPath)) {\n delete ESMxCJSRequire.cache[dictionariesPath];\n\n dictionaries = ESMxCJSRequire(dictionariesPath);\n }\n\n return (dictionaries ?? {}) as Record<\n IntlayerDictionaryTypesConnector['key'],\n IntlayerDictionaryTypesConnector\n >;\n};\n\nexport default getDictionaries();\n"],"mappings":"AAMA,SAAS,gBAAgB,wBAAwB;AACjD,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AAId,MAAM,kBAAkB,MAAM;AACnC,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAErC,QAAM,mBAAmB,KAAK,QAAQ,SAAS,kBAAkB;AAEjE,MAAI,eAAe,CAAC;AACpB,MAAI,WAAW,gBAAgB,GAAG;AAChC,WAAO,eAAe,MAAM,gBAAgB;AAE5C,mBAAe,eAAe,gBAAgB;AAAA,EAChD;AAEA,SAAQ,gBAAgB,CAAC;AAI3B;AAEA,IAAO,gBAAQ,gBAAgB;","names":[]}