@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
1 lines • 3.09 kB
Source Map (JSON)
{"version":3,"file":"getIntlayerBundle.mjs","names":[],"sources":["../../../src/loadDictionaries/getIntlayerBundle.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { builtinModules } from 'node:module';\nimport { join } from 'node:path';\nimport { bundleFile, type ESBuildPlugin } from '@intlayer/config/file';\nimport { getProjectRequire } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\n\n/**\n * Rewrites bare specifiers to absolute paths on the user's disk and externalizes them\n * to preserve directory context (__dirname/import.meta.url).\n */\nconst localResolvePlugin = (\n aliases: Record<string, string>,\n rootRequire: NodeJS.Require\n): ESBuildPlugin => {\n return {\n name: 'local-resolve',\n setup(build) {\n build.onResolve({ filter: /.*/ }, (args) => {\n // Direct alias match\n if (aliases[args.path]) {\n return {\n path: aliases[args.path],\n external: true, // Prevents inlining and context loss\n };\n }\n\n // Dynamic resolution via user workspace\n if (args.path === 'defu' || args.path.startsWith('@intlayer/')) {\n try {\n const absolutePath = rootRequire.resolve(args.path);\n return {\n path: absolutePath,\n external: true, // Injects `require('/absolute/path')`\n };\n } catch {\n return null;\n }\n }\n\n return null;\n });\n },\n };\n};\n\nexport const getIntlayerBundle = async (configuration: IntlayerConfig) => {\n const rootRequire = getProjectRequire(configuration.system.baseDir);\n\n const configurationPath = join(\n configuration.system.configDir,\n `configuration.cjs`\n );\n\n const aliases = {\n '@intlayer/config/built': configurationPath,\n };\n\n const filePath = rootRequire.resolve('intlayer');\n const code = await readFile(filePath, 'utf-8');\n\n const output = await bundleFile(code, filePath, {\n bundle: true,\n platform: 'node',\n external: [\n ...builtinModules,\n ...builtinModules.map((mod) => `node:${mod}`),\n 'vscode',\n 'esbuild',\n ],\n minify: true,\n plugins: [localResolvePlugin(aliases, rootRequire)],\n });\n\n return output ?? '';\n};\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,sBACJ,SACA,gBACkB;CAClB,OAAO;EACL,MAAM;EACN,MAAM,OAAO;GACX,MAAM,UAAU,EAAE,QAAQ,KAAK,IAAI,SAAS;IAE1C,IAAI,QAAQ,KAAK,OACf,OAAO;KACL,MAAM,QAAQ,KAAK;KACnB,UAAU;IACZ;IAIF,IAAI,KAAK,SAAS,UAAU,KAAK,KAAK,WAAW,YAAY,GAC3D,IAAI;KAEF,OAAO;MACL,MAFmB,YAAY,QAAQ,KAAK,IAE3B;MACjB,UAAU;KACZ;IACF,QAAQ;KACN,OAAO;IACT;IAGF,OAAO;GACT,CAAC;EACH;CACF;AACF;AAEA,MAAa,oBAAoB,OAAO,kBAAkC;CACxE,MAAM,cAAc,kBAAkB,cAAc,OAAO,OAAO;CAOlE,MAAM,UAAU,EACd,0BANwB,KACxB,cAAc,OAAO,WACrB,mBAI0C,EAC5C;CAEA,MAAM,WAAW,YAAY,QAAQ,UAAU;CAgB/C,OAAO,MAbc,WAAW,MAFb,SAAS,UAAU,OAAO,GAEP,UAAU;EAC9C,QAAQ;EACR,UAAU;EACV,UAAU;GACR,GAAG;GACH,GAAG,eAAe,KAAK,QAAQ,QAAQ,KAAK;GAC5C;GACA;EACF;EACA,QAAQ;EACR,SAAS,CAAC,mBAAmB,SAAS,WAAW,CAAC;CACpD,CAAC,KAEgB;AACnB"}