angular-intlayer 9.5.2 → 9.5.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.
Files changed (61) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/client/intlayerToken.cjs +1 -1
  3. package/dist/cjs/client/useDictionaryAsync.cjs +1 -1
  4. package/dist/cjs/client/useDictionaryDynamic.cjs +1 -1
  5. package/dist/cjs/client/useLocale.cjs +1 -1
  6. package/dist/cjs/esbuild/hiddenDirectory.cjs +20 -0
  7. package/dist/cjs/esbuild/hiddenDirectory.cjs.map +1 -0
  8. package/dist/cjs/esbuild/plugin.cjs +66 -2
  9. package/dist/cjs/esbuild/plugin.cjs.map +1 -1
  10. package/dist/cjs/esbuild/resolvePackageExport.cjs +118 -0
  11. package/dist/cjs/esbuild/resolvePackageExport.cjs.map +1 -0
  12. package/dist/cjs/markdown/installIntlayerMarkdown.cjs +1 -1
  13. package/dist/cjs/plugins.cjs +34 -38
  14. package/dist/cjs/plugins.cjs.map +1 -1
  15. package/dist/cjs/webpack/mergeConfig.cjs +1 -1
  16. package/dist/cjs/webpack/mergeConfig.cjs.map +1 -1
  17. package/dist/esm/client/intlayerToken.mjs +1 -1
  18. package/dist/esm/client/useDictionaryAsync.mjs +1 -1
  19. package/dist/esm/client/useDictionaryDynamic.mjs +1 -1
  20. package/dist/esm/client/useLocale.mjs +1 -1
  21. package/dist/esm/esbuild/hiddenDirectory.mjs +19 -0
  22. package/dist/esm/esbuild/hiddenDirectory.mjs.map +1 -0
  23. package/dist/esm/esbuild/plugin.mjs +67 -4
  24. package/dist/esm/esbuild/plugin.mjs.map +1 -1
  25. package/dist/esm/esbuild/resolvePackageExport.mjs +115 -0
  26. package/dist/esm/esbuild/resolvePackageExport.mjs.map +1 -0
  27. package/dist/esm/markdown/installIntlayerMarkdown.mjs +1 -1
  28. package/dist/esm/plugins.mjs +34 -38
  29. package/dist/esm/plugins.mjs.map +1 -1
  30. package/dist/esm/webpack/mergeConfig.mjs +1 -2
  31. package/dist/esm/webpack/mergeConfig.mjs.map +1 -1
  32. package/dist/types/client/useLocaleStorage.d.ts +4 -5
  33. package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
  34. package/dist/types/esbuild/hiddenDirectory.d.ts +15 -0
  35. package/dist/types/esbuild/hiddenDirectory.d.ts.map +1 -0
  36. package/dist/types/esbuild/index.d.ts +2 -2
  37. package/dist/types/esbuild/plugin.d.ts +34 -18
  38. package/dist/types/esbuild/plugin.d.ts.map +1 -1
  39. package/dist/types/esbuild/resolvePackageExport.d.ts +37 -0
  40. package/dist/types/esbuild/resolvePackageExport.d.ts.map +1 -0
  41. package/dist/types/format/useCompact.d.ts +1 -2
  42. package/dist/types/format/useCompact.d.ts.map +1 -1
  43. package/dist/types/format/useCurrency.d.ts +1 -2
  44. package/dist/types/format/useCurrency.d.ts.map +1 -1
  45. package/dist/types/format/useDate.d.ts +1 -2
  46. package/dist/types/format/useDate.d.ts.map +1 -1
  47. package/dist/types/format/useList.d.ts +1 -2
  48. package/dist/types/format/useList.d.ts.map +1 -1
  49. package/dist/types/format/useNumber.d.ts +1 -2
  50. package/dist/types/format/useNumber.d.ts.map +1 -1
  51. package/dist/types/format/usePercentage.d.ts +1 -2
  52. package/dist/types/format/usePercentage.d.ts.map +1 -1
  53. package/dist/types/format/useRelativeTime.d.ts +1 -2
  54. package/dist/types/format/useRelativeTime.d.ts.map +1 -1
  55. package/dist/types/format/useUnit.d.ts +1 -2
  56. package/dist/types/format/useUnit.d.ts.map +1 -1
  57. package/dist/types/plugins.d.ts.map +1 -1
  58. package/dist/types/webpack/mergeConfig.d.ts.map +1 -1
  59. package/package.json +9 -9
  60. package/dist/esm/_virtual/_rolldown/runtime.mjs +0 -8
  61. package/dist/types/intlayer/dist/types/index.d.ts +0 -14
package/README.md CHANGED
@@ -328,4 +328,4 @@ Contribute on [GitHub](https://github.com/aymericzip/intlayer), [GitLab](https:/
328
328
 
329
329
  If you like Intlayer, give us a ⭐ on GitHub. It helps others discover the project! [See why GitHub Stars matter](https://github.com/aymericzip/intlayer/blob/main/CONTRIBUTING.md#why-github-stars-matter-).
330
330
 
331
- [![Star History Chart](https://api.star-history.com/svg?repos=aymericzip/intlayer&type=Date)](https://api.star-history.com/#aymericzip/intlayer&Date)
331
+ [![Star History Chart](https://api.star-history.com/svg?repos=aymericzip/intlayer&type=Date)](https://star-history.com/#aymericzip/intlayer&Date)
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- let _intlayer_config_built = require("@intlayer/config/built");
3
2
  let _angular_core = require("@angular/core");
3
+ let _intlayer_config_built = require("@intlayer/config/built");
4
4
  let _intlayer_config_client = require("@intlayer/config/client");
5
5
 
6
6
  //#region src/client/intlayerToken.ts
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
  const require_client_intlayerToken = require('./intlayerToken.cjs');
5
5
  const require_client_useDictionary = require('./useDictionary.cjs');
6
- let _intlayer_config_built = require("@intlayer/config/built");
7
6
  let _angular_core = require("@angular/core");
7
+ let _intlayer_config_built = require("@intlayer/config/built");
8
8
 
9
9
  //#region src/client/useDictionaryAsync.ts
10
10
  /**
@@ -5,8 +5,8 @@ const require_getDictionary = require('../getDictionary.cjs');
5
5
  const require_client_intlayerToken = require('./intlayerToken.cjs');
6
6
  const require_client_useDictionary = require('./useDictionary.cjs');
7
7
  const require_client_useLoadDynamic = require('./useLoadDynamic.cjs');
8
- let _intlayer_config_built = require("@intlayer/config/built");
9
8
  let _angular_core = require("@angular/core");
9
+ let _intlayer_config_built = require("@intlayer/config/built");
10
10
  let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
11
11
 
12
12
  //#region src/client/useDictionaryDynamic.ts
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_client_intlayerToken = require('./intlayerToken.cjs');
3
3
  const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
4
- let _intlayer_config_built = require("@intlayer/config/built");
5
4
  let _angular_core = require("@angular/core");
5
+ let _intlayer_config_built = require("@intlayer/config/built");
6
6
 
7
7
  //#region src/client/useLocale.ts
8
8
  const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
@@ -0,0 +1,20 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let node_path = require("node:path");
3
+
4
+ //#region src/esbuild/hiddenDirectory.ts
5
+ /**
6
+ * Whether `directory` sits under a dot-directory (`.intlayer/…`) of `baseDir`.
7
+ *
8
+ * Angular's esbuild dev server ignores `<workspace>/**\/.*\/**` in its file
9
+ * watcher, so generated files living there never invalidate its TypeScript
10
+ * source cache: a key added to a dictionary regenerates the types, but the
11
+ * template type-checker keeps the stale declaration until `ng serve` restarts.
12
+ *
13
+ * @param baseDir - Angular workspace root (the Intlayer `system.baseDir`).
14
+ * @param directory - Absolute directory to test.
15
+ */
16
+ const isInHiddenDirectory = (baseDir, directory) => (0, node_path.relative)(baseDir, directory).split(node_path.sep).some((segment) => segment.startsWith(".") && segment !== "..");
17
+
18
+ //#endregion
19
+ exports.isInHiddenDirectory = isInHiddenDirectory;
20
+ //# sourceMappingURL=hiddenDirectory.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hiddenDirectory.cjs","names":["relative","sep"],"sources":["../../../src/esbuild/hiddenDirectory.ts"],"sourcesContent":["import { relative, sep } from 'node:path';\n\n/**\n * Whether `directory` sits under a dot-directory (`.intlayer/…`) of `baseDir`.\n *\n * Angular's esbuild dev server ignores `<workspace>/**\\/.*\\/**` in its file\n * watcher, so generated files living there never invalidate its TypeScript\n * source cache: a key added to a dictionary regenerates the types, but the\n * template type-checker keeps the stale declaration until `ng serve` restarts.\n *\n * @param baseDir - Angular workspace root (the Intlayer `system.baseDir`).\n * @param directory - Absolute directory to test.\n */\nexport const isInHiddenDirectory = (\n baseDir: string,\n directory: string\n): boolean =>\n relative(baseDir, directory)\n .split(sep)\n .some((segment) => segment.startsWith('.') && segment !== '..');\n"],"mappings":";;;;;;;;;;;;;;;AAaA,MAAa,uBACX,SACA,kBAEAA,oBAAS,SAAS,SAAS,CAAC,CACzB,MAAMC,aAAG,CAAC,CACV,MAAM,YAAY,QAAQ,WAAW,GAAG,KAAK,YAAY,IAAI"}
@@ -1,4 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_esbuild_resolvePackageExport = require('./resolvePackageExport.cjs');
3
+ const require_esbuild_hiddenDirectory = require('./hiddenDirectory.cjs');
2
4
  let node_module = require("node:module");
3
5
  let node_path = require("node:path");
4
6
  let _intlayer_config_node = require("@intlayer/config/node");
@@ -22,9 +24,34 @@ let _intlayer_engine_watcher = require("@intlayer/engine/watcher");
22
24
  * only depends on `intlayer` and its framework binding, so the bare specifier
23
25
  * would resolve from a tree that need not contain the package at all.
24
26
  *
25
- * This package ships both module formats, hence the `require` fallback.
27
+ * Always built from `import.meta.url`: the bundler shims it to `__filename` in
28
+ * the CommonJS output, whereas a `typeof require` guard is unreliable here —
29
+ * the ESM output rewrites `require` into an always-defined proxy that has no
30
+ * `resolve` method.
26
31
  */
27
- const preloadModuleId = (0, _intlayer_config_utils.normalizePath)((0, _intlayer_config_dictionaryPreload.resolvePreloadModuleId)(typeof require !== "undefined" ? require : (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)));
32
+ const preloadModuleId = (0, _intlayer_config_utils.normalizePath)((0, _intlayer_config_dictionaryPreload.resolvePreloadModuleId)((0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)));
33
+ /** Bare specifiers of the packages this plugin keeps inside its own build. */
34
+ const INTLAYER_PACKAGE_FILTER = /^(?:intlayer|angular-intlayer|@intlayer\/[^/]+)(?:\/|$)/;
35
+ /** Namespace of the re-export shims standing in for externalised packages. */
36
+ const INTLAYER_PACKAGE_NAMESPACE = "intlayer-package";
37
+ /** Matches a module that has a default export, on unminified sources. */
38
+ const DEFAULT_EXPORT_PATTERN = /\bexport\s+default\b|\bas\s+default\b|\{\s*default\s*[,}]/;
39
+ /**
40
+ * The dev server's file watcher skips dot-directories, so type declarations
41
+ * generated there are never re-read: a key added to a dictionary stays unknown
42
+ * to template type-checking until `ng serve` restarts. Nothing in the plugin
43
+ * can reach that cache, so the fix is to generate the types elsewhere.
44
+ */
45
+ const warnAboutHiddenTypesDirectory = (configuration, appLogger) => {
46
+ const { baseDir, typesDir, moduleAugmentationDir } = configuration.system;
47
+ const hiddenDirectories = [.../* @__PURE__ */ new Set([typesDir, moduleAugmentationDir])].filter((directory) => require_esbuild_hiddenDirectory.isInHiddenDirectory(baseDir, directory));
48
+ if (hiddenDirectories.length === 0) return;
49
+ appLogger([
50
+ `Type declarations are generated under ${hiddenDirectories.map((directory) => (0, node_path.relative)(baseDir, directory)).join(", ")}.`,
51
+ "The Angular dev server does not watch dot-directories, so keys added to a dictionary stay unknown to template type-checking until 'ng serve' restarts.",
52
+ "Set 'system.typesDir' and 'system.moduleAugmentationDir' to a directory outside any dot-directory (e.g. 'intlayer-types') and point the tsconfig 'include' at it."
53
+ ].join(" "), { level: "warn" });
54
+ };
28
55
  /**
29
56
  * esbuild plugin that integrates Intlayer into the Angular (or any esbuild-based) build process.
30
57
  *
@@ -101,6 +128,36 @@ const intlayerEsbuildPlugin = (options) => {
101
128
  const escapedFrom = from.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
102
129
  build.onResolve({ filter: new RegExp(`^${escapedFrom}$`) }, () => ({ path: to }));
103
130
  }
131
+ let externalizesPackages;
132
+ build.onResolve({ filter: INTLAYER_PACKAGE_FILTER }, (args) => {
133
+ if (!externalizesPackages || !args.resolveDir) return null;
134
+ const importCondition = args.kind.startsWith("require") ? "require" : "import";
135
+ const resolved = require_esbuild_resolvePackageExport.resolvePackageExport(args.path, args.resolveDir, [
136
+ "browser",
137
+ "module",
138
+ importCondition
139
+ ]);
140
+ if (!resolved) return null;
141
+ return {
142
+ path: `${encodeURIComponent((0, node_path.dirname)(resolved.path))}/${args.path}`,
143
+ namespace: INTLAYER_PACKAGE_NAMESPACE,
144
+ pluginData: { realPath: resolved.path },
145
+ sideEffects: resolved.sideEffects
146
+ };
147
+ });
148
+ build.onLoad({
149
+ filter: /.*/,
150
+ namespace: INTLAYER_PACKAGE_NAMESPACE
151
+ }, async (args) => {
152
+ const { realPath } = args.pluginData;
153
+ const source = await (0, node_fs_promises.readFile)(realPath, "utf-8");
154
+ const specifier = JSON.stringify(`./${(0, node_path.basename)(realPath)}`);
155
+ return {
156
+ contents: [`export * from ${specifier};`, DEFAULT_EXPORT_PATTERN.test(source) && `export { default } from ${specifier};`].filter(Boolean).join("\n"),
157
+ loader: "js",
158
+ resolveDir: (0, node_path.dirname)(realPath)
159
+ };
160
+ });
104
161
  if (config.build.dictionariesPreload) {
105
162
  const dynamicDictionariesDir = (0, _intlayer_config_utils.normalizePath)(config.system.dynamicDictionariesDir);
106
163
  build.onLoad({ filter: (0, _intlayer_config_dictionaryPreload.createDynamicEntryFilter)(dynamicDictionariesDir) }, async ({ path }) => {
@@ -121,6 +178,13 @@ const intlayerEsbuildPlugin = (options) => {
121
178
  });
122
179
  await preparePromise;
123
180
  build.onStart(async () => {
181
+ if (externalizesPackages === void 0) {
182
+ externalizesPackages = (await build.resolve("@angular/core", {
183
+ kind: "import-statement",
184
+ resolveDir: config.system.baseDir
185
+ })).external;
186
+ if (externalizesPackages) warnAboutHiddenTypesDirectory(config, appLogger);
187
+ }
124
188
  if ((options?.watch ?? !isBuildMode) && !watcherStarted) {
125
189
  watcherStarted = true;
126
190
  await (0, _intlayer_engine_watcher.watch)({ configuration: config });
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs","names":["normalizePath","resolvePreloadModuleId","createRequire","getConfiguration","getAlias","join","getAppLogger","getConfigEnvVars","getDictionaries","getUnusedNodeTypesAsync","formatNodeTypeToEnvVar","formatDictionarySelectorEnvVar","getHasDictionarySelector","createDynamicEntryFilter","readFile","addDynamicEntryPreload","prepareIntlayer","watch"],"sources":["../../../src/esbuild/plugin.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport {\n addDynamicEntryPreload,\n createDynamicEntryFilter,\n resolvePreloadModuleId,\n} from '@intlayer/config/dictionaryPreload';\nimport {\n formatDictionarySelectorEnvVar,\n formatNodeTypeToEnvVar,\n getConfigEnvVars,\n} from '@intlayer/config/envVars';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n getAlias,\n getHasDictionarySelector,\n getUnusedNodeTypesAsync,\n normalizePath,\n} from '@intlayer/config/utils';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport { logConfigDetails } from '@intlayer/engine/cli';\nimport { watch } from '@intlayer/engine/watcher';\n\n/**\n * Absolute id of the locale resolver the injected preamble imports.\n *\n * Resolved from this package, which declares `@intlayer/core` as a dependency,\n * rather than left bare in the emitted source: the importer is a generated\n * entry point under the application's `.intlayer` directory, and an application\n * only depends on `intlayer` and its framework binding, so the bare specifier\n * would resolve from a tree that need not contain the package at all.\n *\n * This package ships both module formats, hence the `require` fallback.\n */\nconst preloadModuleId = normalizePath(\n resolvePreloadModuleId(\n typeof require !== 'undefined' ? require : createRequire(import.meta.url)\n )\n);\n\n// Minimal subset of the esbuild Plugin interface to avoid a hard dependency on\n// the `esbuild` package for type resolution. The shape is compatible with\n// esbuild >=0.17, `@angular-builders/custom-esbuild`, and NX esbuild builders.\nexport interface EsbuildPluginBuild {\n initialOptions: {\n alias?: Record<string, string>;\n define?: Record<string, string>;\n minify?: boolean;\n watch?: unknown;\n /** Absolute working directory of the esbuild context (set by Angular's builder). */\n absWorkingDir?: string;\n };\n onStart(callback: () => void | Promise<void>): void;\n /** Intercept module resolution — works even for imports inside node_modules. */\n onResolve(\n options: { filter: RegExp; namespace?: string },\n callback: (args: {\n path: string;\n importer: string;\n namespace: string;\n resolveDir: string;\n }) => { path: string; namespace?: string } | null | undefined\n ): void;\n /** Intercept module contents, so a resolved file can be rewritten. */\n onLoad(\n options: { filter: RegExp; namespace?: string },\n callback: (args: {\n path: string;\n namespace: string;\n }) =>\n | { contents: string; loader?: string }\n | null\n | undefined\n | Promise<{ contents: string; loader?: string } | null | undefined>\n ): void;\n}\n\nexport interface EsbuildPlugin {\n name: string;\n setup(build: EsbuildPluginBuild): void | Promise<void>;\n}\n\nexport type IntlayerEsbuildPluginOptions = {\n configOptions?: GetConfigurationOptions;\n /**\n * Whether to start the Intlayer file watcher for dictionary regeneration.\n * - `true`: always start the watcher (useful for `ng serve`)\n * - `false`: never start the watcher (useful for `ng build`)\n * - `undefined` (default): auto-detect based on the build context\n * (skips the watcher when a production build is detected)\n */\n watch?: boolean;\n};\n\n/**\n * esbuild plugin that integrates Intlayer into the Angular (or any esbuild-based) build process.\n *\n * Handles:\n * 1. Injecting `alias` entries so `@intlayer/dictionaries-entry` etc. resolve to\n * the generated files under `.intlayer/`.\n * 2. Defining `process.env.*` tree-shaking constants for production builds.\n * 3. Running `prepareIntlayer` (dictionary generation) before the first build.\n * 4. Starting the chokidar file-watcher in dev / serve mode.\n *\n * Compatible with:\n * - `@angular-builders/custom-esbuild` (`application` or `browser-esbuild` builder)\n * - NX `@nx/angular:browser-esbuild`\n * - Any raw esbuild setup that accepts the standard `Plugin` interface\n *\n * @example\n * ```ts\n * // esbuild.plugins.ts (referenced from angular.json \"plugins\" option)\n * import { intlayerEsbuildPlugin } from 'angular-intlayer/esbuild';\n * export default [intlayerEsbuildPlugin()];\n * ```\n */\nexport const intlayerEsbuildPlugin = (\n options?: IntlayerEsbuildPluginOptions\n): EsbuildPlugin => {\n // All Node.js-heavy initialization (getConfiguration, getAlias, …) is deferred\n // into setup() so it runs in esbuild's Node.js context, not at module-evaluation\n // time. @angular/build loads the plugin file through Vite's SSR module runner\n // (ESM) where CommonJS globals like __filename are undefined. Calling\n // getConfiguration() here would trigger: buildSync → worker threads →\n // __filename → ReferenceError, crashing the plugin before setup() ever runs.\n let config: ReturnType<typeof getConfiguration> | null = null;\n let alias: Record<string, string> | null = null;\n\n // Shared across parallel setup() calls (Angular spawns one per bundle context).\n let preparePromise: Promise<void> | null = null;\n let watcherStarted = false;\n // Once any esbuild context (browser or server) detects a production build,\n // suppress the watcher for all contexts so `ng build` can exit cleanly.\n let isBuildMode = false;\n\n return {\n name: 'intlayer',\n\n async setup(build) {\n if (!config) {\n const baseDir =\n build.initialOptions.absWorkingDir ??\n options?.configOptions?.baseDir ??\n process.cwd();\n\n config = getConfiguration({ baseDir, ...options?.configOptions });\n logConfigDetails({ baseDir, ...options?.configOptions });\n\n alias = getAlias({\n configuration: config,\n formatter: (value: string) => join(config!.system.baseDir, value),\n });\n }\n\n const appLogger = getAppLogger(config);\n const nodeEnvDefine =\n build.initialOptions.define?.['process.env.NODE_ENV'];\n\n // Angular's esbuild builder doesn't set `minify` or `process.env.NODE_ENV`\n // on initialOptions — it handles optimisation through its own pipeline.\n // Instead, Angular defines `ngDevMode` as `\"false\"` in production builds.\n const isProduction =\n nodeEnvDefine === '\"production\"' ||\n nodeEnvDefine === \"'production'\" ||\n build.initialOptions.minify === true ||\n build.initialOptions.define?.['ngDevMode'] === 'false';\n\n if (isProduction) {\n isBuildMode = true;\n }\n\n const wrapKey = (key: string) => `process.env.${key}`;\n const wrapValue = (value: string) => `\"${value}\"`;\n\n const envVars: Record<string, string> = {\n // Catch-all so that any `process.env.*` read NOT covered by a specific\n // key below resolves to `undefined` instead of dereferencing a bare\n // `process`, which is not defined in browser bundles and throws\n // `process is not defined`. esbuild resolves the most specific define\n // first, so the keys below keep their tree-shaking effect.\n 'process.env': '{}',\n [wrapKey('INTLAYER')]: wrapValue('true'),\n [wrapKey('NODE_ENV')]: wrapValue(\n isProduction ? 'production' : 'development'\n ),\n // Tree shaking flags derived from the config (routing / storage /\n // editor). Emitted in every mode so behaviour is consistent in dev.\n ...getConfigEnvVars(config, wrapKey, wrapValue),\n };\n\n if (isProduction) {\n const dictionaries = getDictionaries(config);\n if (Object.keys(dictionaries).length === 0) {\n appLogger('No dictionaries found. Please check your configuration.', {\n isVerbose: true,\n });\n }\n\n const unusedNodeTypes = await getUnusedNodeTypesAsync(dictionaries);\n Object.assign(\n envVars,\n // Tree shaking based on unused node types\n formatNodeTypeToEnvVar(unusedNodeTypes, wrapKey, wrapValue),\n // Tree shaking the dictionary selector logic\n // (collections / variants)\n formatDictionarySelectorEnvVar(\n getHasDictionarySelector(dictionaries),\n wrapKey,\n wrapValue\n )\n );\n }\n\n // Existing defines (Angular's own, or the user's angular.json `define`\n // block) take precedence over the Intlayer ones.\n build.initialOptions.define = {\n ...envVars,\n ...(build.initialOptions.define ?? {}),\n };\n\n build.initialOptions.alias = {\n ...alias,\n ...(build.initialOptions.alias ?? {}),\n };\n\n for (const [from, to] of Object.entries(alias!)) {\n const escapedFrom = from.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n build.onResolve({ filter: new RegExp(`^${escapedFrom}$`) }, () => ({\n path: to,\n }));\n }\n\n // Dictionaries load with the chunk that needs them rather than being\n // fetched once that chunk renders: the entry point starts the browsing\n // locale's load as it evaluates, so a lazily loaded route requests its\n // content on `import()` instead of on first render. Without it every\n // dictionary read renders an empty placeholder first and fills in a tick\n // later.\n //\n // Not gated on the configured `importMode`: a `.content` file can set\n // `importMode: 'dynamic'` on a single dictionary under a `static` or\n // `fetch` global mode, and that dictionary needs the preload just the\n // same. Only entry points the optimizer imported are ever loaded, so the\n // path check below is the accurate gate.\n if (config.build.dictionariesPreload) {\n const dynamicDictionariesDir = normalizePath(\n config.system.dynamicDictionariesDir\n );\n\n build.onLoad(\n { filter: createDynamicEntryFilter(dynamicDictionariesDir) },\n async ({ path }) => {\n const posixPath = normalizePath(path);\n if (!posixPath.startsWith(`${dynamicDictionariesDir}/`))\n return null;\n\n const code = await readFile(path, 'utf-8');\n const result = addDynamicEntryPreload(code, preloadModuleId);\n\n if (result.skipped) return null;\n\n return { contents: result.code, loader: 'js' };\n }\n );\n }\n\n if (!preparePromise) {\n preparePromise = prepareIntlayer(config, {\n clean: isProduction,\n cacheTimeoutMs: isProduction ? 1000 * 30 : 1000 * 60 * 60,\n env: isProduction ? 'prod' : 'dev',\n });\n }\n\n await preparePromise;\n\n build.onStart(async () => {\n // Determine whether the watcher should run:\n // 1. Explicit option from the caller takes precedence\n // 2. If any esbuild context detected a production build, skip\n // 3. esbuild's own watch mode is a positive signal\n const shouldWatch = options?.watch ?? !isBuildMode;\n\n if (shouldWatch && !watcherStarted) {\n watcherStarted = true;\n\n await watch({ configuration: config! });\n }\n });\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAM,sBAAkBA,0CACtBC,2DACE,OAAO,YAAY,cAAc,cAAUC,wEAA6B,CAC1E,CACF;;;;;;;;;;;;;;;;;;;;;;;AA8EA,MAAa,yBACX,YACkB;CAOlB,IAAI,SAAqD;CACzD,IAAI,QAAuC;CAG3C,IAAI,iBAAuC;CAC3C,IAAI,iBAAiB;CAGrB,IAAI,cAAc;CAElB,OAAO;EACL,MAAM;EAEN,MAAM,MAAM,OAAO;GACjB,IAAI,CAAC,QAAQ;IACX,MAAM,UACJ,MAAM,eAAe,iBACrB,SAAS,eAAe,WACxB,QAAQ,IAAI;IAEd,aAASC,wCAAiB;KAAE;KAAS,GAAG,SAAS;IAAc,CAAC;IAChE,2CAAiB;KAAE;KAAS,GAAG,SAAS;IAAc,CAAC;IAEvD,YAAQC,iCAAS;KACf,eAAe;KACf,YAAY,cAAkBC,gBAAK,OAAQ,OAAO,SAAS,KAAK;IAClE,CAAC;GACH;GAEA,MAAM,gBAAYC,sCAAa,MAAM;GACrC,MAAM,gBACJ,MAAM,eAAe,SAAS;GAKhC,MAAM,eACJ,kBAAkB,oBAClB,kBAAkB,kBAClB,MAAM,eAAe,W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BAAS,MAAM,OAAO;KACzC,MAAM,aAASC,2DAAuB,MAAM,eAAe;KAE3D,IAAI,OAAO,SAAS,OAAO;KAE3B,OAAO;MAAE,UAAU,OAAO;MAAM,QAAQ;KAAK;IAC/C,CACF;GACF;GAEA,IAAI,CAAC,gBACH,qBAAiBC,wCAAgB,QAAQ;IACvC,OAAO;IACP,gBAAgB,eAAe,MAAY;IAC3C,KAAK,eAAe,SAAS;GAC/B,CAAC;GAGH,MAAM;GAEN,MAAM,QAAQ,YAAY;IAOxB,KAFoB,SAAS,SAAS,CAAC,gBAEpB,CAAC,gBAAgB;KAClC,iBAAiB;KAEjB,UAAMC,gCAAM,EAAE,eAAe,OAAQ,CAAC;IACxC;GACF,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"plugin.cjs","names":["normalizePath","resolvePreloadModuleId","createRequire","isInHiddenDirectory","relative","getConfiguration","getAlias","join","getAppLogger","getConfigEnvVars","getDictionaries","getUnusedNodeTypesAsync","formatNodeTypeToEnvVar","formatDictionarySelectorEnvVar","getHasDictionarySelector","resolvePackageExport","dirname","readFile","basename","createDynamicEntryFilter","addDynamicEntryPreload","prepareIntlayer","watch"],"sources":["../../../src/esbuild/plugin.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { basename, dirname, join, relative } from 'node:path';\nimport {\n addDynamicEntryPreload,\n createDynamicEntryFilter,\n resolvePreloadModuleId,\n} from '@intlayer/config/dictionaryPreload';\nimport {\n formatDictionarySelectorEnvVar,\n formatNodeTypeToEnvVar,\n getConfigEnvVars,\n} from '@intlayer/config/envVars';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n getAlias,\n getHasDictionarySelector,\n getUnusedNodeTypesAsync,\n normalizePath,\n} from '@intlayer/config/utils';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport { logConfigDetails } from '@intlayer/engine/cli';\nimport { watch } from '@intlayer/engine/watcher';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { isInHiddenDirectory } from './hiddenDirectory';\nimport { resolvePackageExport } from './resolvePackageExport';\n\n/**\n * Absolute id of the locale resolver the injected preamble imports.\n *\n * Resolved from this package, which declares `@intlayer/core` as a dependency,\n * rather than left bare in the emitted source: the importer is a generated\n * entry point under the application's `.intlayer` directory, and an application\n * only depends on `intlayer` and its framework binding, so the bare specifier\n * would resolve from a tree that need not contain the package at all.\n *\n * Always built from `import.meta.url`: the bundler shims it to `__filename` in\n * the CommonJS output, whereas a `typeof require` guard is unreliable here —\n * the ESM output rewrites `require` into an always-defined proxy that has no\n * `resolve` method.\n */\nconst preloadModuleId = normalizePath(\n resolvePreloadModuleId(createRequire(import.meta.url))\n);\n\n/** Bare specifiers of the packages this plugin keeps inside its own build. */\nconst INTLAYER_PACKAGE_FILTER =\n /^(?:intlayer|angular-intlayer|@intlayer\\/[^/]+)(?:\\/|$)/;\n\n/** Namespace of the re-export shims standing in for externalised packages. */\nconst INTLAYER_PACKAGE_NAMESPACE = 'intlayer-package';\n\n/** Matches a module that has a default export, on unminified sources. */\nconst DEFAULT_EXPORT_PATTERN =\n /\\bexport\\s+default\\b|\\bas\\s+default\\b|\\{\\s*default\\s*[,}]/;\n\n// Minimal subset of the esbuild Plugin interface to avoid a hard dependency on\n// the `esbuild` package for type resolution. The shape is compatible with\n// esbuild >=0.17, `@angular-builders/custom-esbuild`, and NX esbuild builders.\nexport type EsbuildResolveArgs = {\n path: string;\n importer: string;\n namespace: string;\n resolveDir: string;\n kind: string;\n pluginData?: unknown;\n};\n\nexport type EsbuildResolveResult = {\n path?: string;\n namespace?: string;\n external?: boolean;\n sideEffects?: boolean;\n pluginData?: unknown;\n errors?: unknown[];\n warnings?: unknown[];\n};\n\nexport type EsbuildLoadArgs = {\n path: string;\n namespace: string;\n pluginData?: unknown;\n};\n\nexport type EsbuildLoadResult = {\n contents: string;\n loader?: string;\n /** Directory relative imports of `contents` resolve from. */\n resolveDir?: string;\n};\n\nexport interface EsbuildPluginBuild {\n initialOptions: {\n alias?: Record<string, string>;\n define?: Record<string, string>;\n minify?: boolean;\n watch?: unknown;\n /** Absolute working directory of the esbuild context (set by Angular's builder). */\n absWorkingDir?: string;\n };\n onStart(callback: () => void | Promise<void>): void;\n /** Intercept module resolution — works even for imports inside node_modules. */\n onResolve(\n options: { filter: RegExp; namespace?: string },\n callback: (\n args: EsbuildResolveArgs\n ) =>\n | EsbuildResolveResult\n | null\n | undefined\n | Promise<EsbuildResolveResult | null | undefined>\n ): void;\n /** Run the remaining resolution pipeline (other plugins, then esbuild). */\n resolve(\n path: string,\n options: Partial<Omit<EsbuildResolveArgs, 'path'>>\n ): Promise<EsbuildResolveResult & { path: string; external: boolean }>;\n /** Intercept module contents, so a resolved file can be rewritten. */\n onLoad(\n options: { filter: RegExp; namespace?: string },\n callback: (\n args: EsbuildLoadArgs\n ) =>\n | EsbuildLoadResult\n | null\n | undefined\n | Promise<EsbuildLoadResult | null | undefined>\n ): void;\n}\n\nexport interface EsbuildPlugin {\n name: string;\n setup(build: EsbuildPluginBuild): void | Promise<void>;\n}\n\nexport type IntlayerEsbuildPluginOptions = {\n configOptions?: GetConfigurationOptions;\n /**\n * Whether to start the Intlayer file watcher for dictionary regeneration.\n * - `true`: always start the watcher (useful for `ng serve`)\n * - `false`: never start the watcher (useful for `ng build`)\n * - `undefined` (default): auto-detect based on the build context\n * (skips the watcher when a production build is detected)\n */\n watch?: boolean;\n};\n\n/**\n * The dev server's file watcher skips dot-directories, so type declarations\n * generated there are never re-read: a key added to a dictionary stays unknown\n * to template type-checking until `ng serve` restarts. Nothing in the plugin\n * can reach that cache, so the fix is to generate the types elsewhere.\n */\nconst warnAboutHiddenTypesDirectory = (\n configuration: IntlayerConfig,\n appLogger: ReturnType<typeof getAppLogger>\n) => {\n const { baseDir, typesDir, moduleAugmentationDir } = configuration.system;\n\n const hiddenDirectories = [\n ...new Set([typesDir, moduleAugmentationDir]),\n ].filter((directory) => isInHiddenDirectory(baseDir, directory));\n\n if (hiddenDirectories.length === 0) return;\n\n appLogger(\n [\n `Type declarations are generated under ${hiddenDirectories.map((directory) => relative(baseDir, directory)).join(', ')}.`,\n \"The Angular dev server does not watch dot-directories, so keys added to a dictionary stay unknown to template type-checking until 'ng serve' restarts.\",\n \"Set 'system.typesDir' and 'system.moduleAugmentationDir' to a directory outside any dot-directory (e.g. 'intlayer-types') and point the tsconfig 'include' at it.\",\n ].join(' '),\n { level: 'warn' }\n );\n};\n\n/**\n * esbuild plugin that integrates Intlayer into the Angular (or any esbuild-based) build process.\n *\n * Handles:\n * 1. Injecting `alias` entries so `@intlayer/dictionaries-entry` etc. resolve to\n * the generated files under `.intlayer/`.\n * 2. Defining `process.env.*` tree-shaking constants for production builds.\n * 3. Running `prepareIntlayer` (dictionary generation) before the first build.\n * 4. Starting the chokidar file-watcher in dev / serve mode.\n *\n * Compatible with:\n * - `@angular-builders/custom-esbuild` (`application` or `browser-esbuild` builder)\n * - NX `@nx/angular:browser-esbuild`\n * - Any raw esbuild setup that accepts the standard `Plugin` interface\n *\n * @example\n * ```ts\n * // esbuild.plugins.ts (referenced from angular.json \"plugins\" option)\n * import { intlayerEsbuildPlugin } from 'angular-intlayer/esbuild';\n * export default [intlayerEsbuildPlugin()];\n * ```\n */\nexport const intlayerEsbuildPlugin = (\n options?: IntlayerEsbuildPluginOptions\n): EsbuildPlugin => {\n // All Node.js-heavy initialization (getConfiguration, getAlias, …) is deferred\n // into setup() so it runs in esbuild's Node.js context, not at module-evaluation\n // time. @angular/build loads the plugin file through Vite's SSR module runner\n // (ESM) where CommonJS globals like __filename are undefined. Calling\n // getConfiguration() here would trigger: buildSync → worker threads →\n // __filename → ReferenceError, crashing the plugin before setup() ever runs.\n let config: ReturnType<typeof getConfiguration> | null = null;\n let alias: Record<string, string> | null = null;\n\n // Shared across parallel setup() calls (Angular spawns one per bundle context).\n let preparePromise: Promise<void> | null = null;\n let watcherStarted = false;\n // Once any esbuild context (browser or server) detects a production build,\n // suppress the watcher for all contexts so `ng build` can exit cleanly.\n let isBuildMode = false;\n\n return {\n name: 'intlayer',\n\n async setup(build) {\n if (!config) {\n const baseDir =\n build.initialOptions.absWorkingDir ??\n options?.configOptions?.baseDir ??\n process.cwd();\n\n config = getConfiguration({ baseDir, ...options?.configOptions });\n logConfigDetails({ baseDir, ...options?.configOptions });\n\n alias = getAlias({\n configuration: config,\n formatter: (value: string) => join(config!.system.baseDir, value),\n });\n }\n\n const appLogger = getAppLogger(config);\n const nodeEnvDefine =\n build.initialOptions.define?.['process.env.NODE_ENV'];\n\n // Angular's esbuild builder doesn't set `minify` or `process.env.NODE_ENV`\n // on initialOptions — it handles optimisation through its own pipeline.\n // Instead, Angular defines `ngDevMode` as `\"false\"` in production builds.\n const isProduction =\n nodeEnvDefine === '\"production\"' ||\n nodeEnvDefine === \"'production'\" ||\n build.initialOptions.minify === true ||\n build.initialOptions.define?.['ngDevMode'] === 'false';\n\n if (isProduction) {\n isBuildMode = true;\n }\n\n const wrapKey = (key: string) => `process.env.${key}`;\n const wrapValue = (value: string) => `\"${value}\"`;\n\n const envVars: Record<string, string> = {\n // Catch-all so that any `process.env.*` read NOT covered by a specific\n // key below resolves to `undefined` instead of dereferencing a bare\n // `process`, which is not defined in browser bundles and throws\n // `process is not defined`. esbuild resolves the most specific define\n // first, so the keys below keep their tree-shaking effect.\n 'process.env': '{}',\n [wrapKey('INTLAYER')]: wrapValue('true'),\n [wrapKey('NODE_ENV')]: wrapValue(\n isProduction ? 'production' : 'development'\n ),\n // Tree shaking flags derived from the config (routing / storage /\n // editor). Emitted in every mode so behaviour is consistent in dev.\n ...getConfigEnvVars(config, wrapKey, wrapValue),\n };\n\n if (isProduction) {\n const dictionaries = getDictionaries(config);\n if (Object.keys(dictionaries).length === 0) {\n appLogger('No dictionaries found. Please check your configuration.', {\n isVerbose: true,\n });\n }\n\n const unusedNodeTypes = await getUnusedNodeTypesAsync(dictionaries);\n Object.assign(\n envVars,\n // Tree shaking based on unused node types\n formatNodeTypeToEnvVar(unusedNodeTypes, wrapKey, wrapValue),\n // Tree shaking the dictionary selector logic\n // (collections / variants)\n formatDictionarySelectorEnvVar(\n getHasDictionarySelector(dictionaries),\n wrapKey,\n wrapValue\n )\n );\n }\n\n // Existing defines (Angular's own, or the user's angular.json `define`\n // block) take precedence over the Intlayer ones.\n build.initialOptions.define = {\n ...envVars,\n ...(build.initialOptions.define ?? {}),\n };\n\n build.initialOptions.alias = {\n ...alias,\n ...(build.initialOptions.alias ?? {}),\n };\n\n for (const [from, to] of Object.entries(alias!)) {\n const escapedFrom = from.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n build.onResolve({ filter: new RegExp(`^${escapedFrom}$`) }, () => ({\n path: to,\n }));\n }\n\n // Angular's dev server marks every import that resolves under\n // `node_modules` as external so Vite can pre-bundle it. Vite's\n // pre-bundler runs without this plugin, so the aliases above never apply\n // there and the real `@intlayer/config/built` — a Node config loader —\n // ends up in the browser. Angular's externalising plugin is registered\n // ahead of this one and only lets a resolution through when the path it\n // gets back is outside `node_modules`; so in that mode an Intlayer\n // package resolves to a re-export shim in its own namespace, whose\n // relative import of the real file the pipeline then bundles as usual.\n // Whether the pipeline externalises packages is probed once, at the\n // first build, so production builds keep the bundler's own resolution.\n let externalizesPackages: boolean | undefined;\n\n build.onResolve({ filter: INTLAYER_PACKAGE_FILTER }, (args) => {\n if (!externalizesPackages || !args.resolveDir) return null;\n\n const importCondition = args.kind.startsWith('require')\n ? 'require'\n : 'import';\n const resolved = resolvePackageExport(args.path, args.resolveDir, [\n 'browser',\n 'module',\n importCondition,\n ]);\n\n if (!resolved) return null;\n\n return {\n // Neither a `node_modules` segment nor a script extension, which the\n // externalising plugin and Angular's own JS loader key on. Ends with\n // the specifier so a lazy chunk is named after it, and starts with\n // the encoded directory so two copies of a package stay distinct.\n path: `${encodeURIComponent(dirname(resolved.path))}/${args.path}`,\n namespace: INTLAYER_PACKAGE_NAMESPACE,\n pluginData: { realPath: resolved.path },\n sideEffects: resolved.sideEffects,\n };\n });\n\n build.onLoad(\n { filter: /.*/, namespace: INTLAYER_PACKAGE_NAMESPACE },\n async (args) => {\n const { realPath } = args.pluginData as { realPath: string };\n const source = await readFile(realPath, 'utf-8');\n const specifier = JSON.stringify(`./${basename(realPath)}`);\n\n const contents = [\n `export * from ${specifier};`,\n DEFAULT_EXPORT_PATTERN.test(source) &&\n `export { default } from ${specifier};`,\n ]\n .filter(Boolean)\n .join('\\n');\n\n return { contents, loader: 'js', resolveDir: dirname(realPath) };\n }\n );\n\n // Dictionaries load with the chunk that needs them rather than being\n // fetched once that chunk renders: the entry point starts the browsing\n // locale's load as it evaluates, so a lazily loaded route requests its\n // content on `import()` instead of on first render. Without it every\n // dictionary read renders an empty placeholder first and fills in a tick\n // later.\n //\n // Not gated on the configured `importMode`: a `.content` file can set\n // `importMode: 'dynamic'` on a single dictionary under a `static` or\n // `fetch` global mode, and that dictionary needs the preload just the\n // same. Only entry points the optimizer imported are ever loaded, so the\n // path check below is the accurate gate.\n if (config.build.dictionariesPreload) {\n const dynamicDictionariesDir = normalizePath(\n config.system.dynamicDictionariesDir\n );\n\n build.onLoad(\n { filter: createDynamicEntryFilter(dynamicDictionariesDir) },\n async ({ path }) => {\n const posixPath = normalizePath(path);\n if (!posixPath.startsWith(`${dynamicDictionariesDir}/`))\n return null;\n\n const code = await readFile(path, 'utf-8');\n const result = addDynamicEntryPreload(code, preloadModuleId);\n\n if (result.skipped) return null;\n\n return { contents: result.code, loader: 'js' };\n }\n );\n }\n\n if (!preparePromise) {\n preparePromise = prepareIntlayer(config, {\n clean: isProduction,\n cacheTimeoutMs: isProduction ? 1000 * 30 : 1000 * 60 * 60,\n env: isProduction ? 'prod' : 'dev',\n });\n }\n\n await preparePromise;\n\n build.onStart(async () => {\n // `@angular/core` is always installed and never worth excluding from\n // pre-bundling, so its fate tells whether packages get externalised.\n if (externalizesPackages === undefined) {\n externalizesPackages = (\n await build.resolve('@angular/core', {\n kind: 'import-statement',\n resolveDir: config!.system.baseDir,\n })\n ).external;\n\n if (externalizesPackages) {\n warnAboutHiddenTypesDirectory(config!, appLogger);\n }\n }\n\n // Determine whether the watcher should run:\n // 1. Explicit option from the caller takes precedence\n // 2. If any esbuild context detected a production build, skip\n // 3. esbuild's own watch mode is a positive signal\n const shouldWatch = options?.watch ?? !isBuildMode;\n\n if (shouldWatch && !watcherStarted) {\n watcherStarted = true;\n\n await watch({ configuration: config! });\n }\n });\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAM,sBAAkBA,0CACtBC,+DAAuBC,wEAA6B,CAAC,CACvD;;AAGA,MAAM,0BACJ;;AAGF,MAAM,6BAA6B;;AAGnC,MAAM,yBACJ;;;;;;;AAmGF,MAAM,iCACJ,eACA,cACG;CACH,MAAM,EAAE,SAAS,UAAU,0BAA0B,cAAc;CAEnE,MAAM,oBAAoB,CACxB,mBAAG,IAAI,IAAI,CAAC,UAAU,qBAAqB,CAAC,CAC9C,CAAC,CAAC,QAAQ,cAAcC,oDAAoB,SAAS,SAAS,CAAC;CAE/D,IAAI,kBAAkB,WAAW,GAAG;CAEpC,UACE;EACE,yCAAyC,kBAAkB,KAAK,kBAAcC,oBAAS,SAAS,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE;EACvH;EACA;CACF,CAAC,CAAC,KAAK,GAAG,GACV,EAAE,OAAO,OAAO,CAClB;AACF;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,yBACX,YACkB;CAOlB,IAAI,SAAqD;CACzD,IAAI,QAAuC;CAG3C,IAAI,iBAAuC;CAC3C,IAAI,iBAAiB;CAGrB,IAAI,cAAc;CAElB,OAAO;EACL,MAAM;EAEN,MAAM,MAAM,OAAO;GACjB,IAAI,CAAC,QAAQ;IACX,MAAM,UACJ,MAAM,eAAe,iBACrB,SAAS,eAAe,WACxB,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;KACzC,MAAM,aAASG,2DAAuB,MAAM,eAAe;KAE3D,IAAI,OAAO,SAAS,OAAO;KAE3B,OAAO;MAAE,UAAU,OAAO;MAAM,QAAQ;KAAK;IAC/C,CACF;GACF;GAEA,IAAI,CAAC,gBACH,qBAAiBC,wCAAgB,QAAQ;IACvC,OAAO;IACP,gBAAgB,eAAe,MAAY;IAC3C,KAAK,eAAe,SAAS;GAC/B,CAAC;GAGH,MAAM;GAEN,MAAM,QAAQ,YAAY;IAGxB,IAAI,yBAAyB,QAAW;KACtC,wBACE,MAAM,MAAM,QAAQ,iBAAiB;MACnC,MAAM;MACN,YAAY,OAAQ,OAAO;KAC7B,CAAC,EAAC,CACF;KAEF,IAAI,sBACF,8BAA8B,QAAS,SAAS;IAEpD;IAQA,KAFoB,SAAS,SAAS,CAAC,gBAEpB,CAAC,gBAAgB;KAClC,iBAAiB;KAEjB,UAAMC,gCAAM,EAAE,eAAe,OAAQ,CAAC;IACxC;GACF,CAAC;EACH;CACF;AACF"}
@@ -0,0 +1,118 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let node_path = require("node:path");
3
+ let node_fs = require("node:fs");
4
+
5
+ //#region src/esbuild/resolvePackageExport.ts
6
+ /** Splits a bare specifier into its package name and `./`-prefixed subpath. */
7
+ const parsePackageSpecifier = (specifier) => {
8
+ const segments = specifier.split("/");
9
+ const nameSegmentCount = specifier.startsWith("@") ? 2 : 1;
10
+ const packageName = segments.slice(0, nameSegmentCount).join("/");
11
+ const rest = segments.slice(nameSegmentCount).join("/");
12
+ return {
13
+ packageName,
14
+ subpath: rest ? `./${rest}` : "."
15
+ };
16
+ };
17
+ /**
18
+ * Locates `node_modules/<packageName>/package.json` the way Node does: from
19
+ * `startDir` upward, first hit wins.
20
+ */
21
+ const findPackageManifest = (packageName, startDir) => {
22
+ let currentDir = (0, node_path.resolve)(startDir);
23
+ while (true) {
24
+ const candidate = (0, node_path.join)(currentDir, "node_modules", packageName, "package.json");
25
+ if ((0, node_fs.existsSync)(candidate)) return candidate;
26
+ const parentDir = (0, node_path.dirname)(currentDir);
27
+ if (parentDir === currentDir) return void 0;
28
+ currentDir = parentDir;
29
+ }
30
+ };
31
+ /**
32
+ * Picks the file for a target, honouring the manifest's own key order for
33
+ * condition maps as the ESM resolver does.
34
+ */
35
+ const resolveExportTarget = (target, conditions) => {
36
+ if (typeof target === "string") return target;
37
+ if (target === null) return void 0;
38
+ if (Array.isArray(target)) {
39
+ for (const candidate of target) {
40
+ const resolved = resolveExportTarget(candidate, conditions);
41
+ if (resolved) return resolved;
42
+ }
43
+ return;
44
+ }
45
+ for (const [condition, value] of Object.entries(target)) {
46
+ if (condition !== "default" && !conditions.has(condition)) continue;
47
+ const resolved = resolveExportTarget(value, conditions);
48
+ if (resolved) return resolved;
49
+ }
50
+ };
51
+ /**
52
+ * Matches `subpath` against the `exports` map: an exact key first, then the
53
+ * `*` pattern with the longest literal prefix, substituting the wildcard into
54
+ * the resolved target.
55
+ */
56
+ const resolveSubpathExport = (exportsMap, subpath, conditions) => {
57
+ if (!(typeof exportsMap === "object" && exportsMap !== null && !Array.isArray(exportsMap) && Object.keys(exportsMap).some((key) => key.startsWith(".")))) return subpath === "." ? resolveExportTarget(exportsMap, conditions) : void 0;
58
+ const subpathMap = exportsMap;
59
+ if (subpath in subpathMap) return resolveExportTarget(subpathMap[subpath], conditions);
60
+ let bestMatch = {
61
+ prefix: "",
62
+ wildcard: "",
63
+ target: null
64
+ };
65
+ for (const [pattern, target] of Object.entries(subpathMap)) {
66
+ const wildcardIndex = pattern.indexOf("*");
67
+ if (wildcardIndex === -1) continue;
68
+ const prefix = pattern.slice(0, wildcardIndex);
69
+ const suffix = pattern.slice(wildcardIndex + 1);
70
+ if (!(subpath.startsWith(prefix) && subpath.length >= prefix.length + suffix.length && subpath.endsWith(suffix)) || prefix.length <= bestMatch.prefix.length) continue;
71
+ bestMatch = {
72
+ prefix,
73
+ wildcard: subpath.slice(prefix.length, subpath.length - suffix.length),
74
+ target
75
+ };
76
+ }
77
+ return resolveExportTarget(bestMatch.target, conditions)?.replaceAll("*", bestMatch.wildcard);
78
+ };
79
+ /**
80
+ * Resolves a bare specifier to an absolute file through the package manifest,
81
+ * without going through the bundler's own resolver.
82
+ *
83
+ * Needed inside Angular's dev server: its esbuild pipeline marks every file
84
+ * resolved under `node_modules` as external so Vite can pre-bundle it, and the
85
+ * pre-bundler neither runs the Intlayer plugin nor sees its aliases — the real
86
+ * `@intlayer/config/built` (a Node config loader) then lands in the browser.
87
+ * Resolving here and returning a plain path keeps the package inside the
88
+ * plugin-aware esbuild build.
89
+ *
90
+ * @param specifier - Bare specifier such as `@intlayer/core/interpreter`.
91
+ * @param resolveDir - Directory the import is issued from.
92
+ * @param conditions - Export conditions to honour, in addition to `default`.
93
+ * @returns The resolved file, or `undefined` when the manifest cannot be found
94
+ * or does not map the subpath — the caller then leaves the bundler to it.
95
+ */
96
+ const resolvePackageExport = (specifier, resolveDir, conditions) => {
97
+ const { packageName, subpath } = parsePackageSpecifier(specifier);
98
+ const manifestPath = findPackageManifest(packageName, resolveDir);
99
+ if (!manifestPath) return void 0;
100
+ const manifest = JSON.parse((0, node_fs.readFileSync)(manifestPath, "utf-8"));
101
+ const packageDir = (0, node_path.dirname)(manifestPath);
102
+ const conditionSet = new Set(conditions);
103
+ let target;
104
+ if (manifest.exports !== void 0) target = resolveSubpathExport(manifest.exports, subpath, conditionSet);
105
+ else if (subpath === ".") target = manifest.module ?? manifest.main ?? "./index.js";
106
+ else if ((0, node_fs.existsSync)((0, node_path.join)(packageDir, subpath))) target = subpath;
107
+ if (!target) return void 0;
108
+ return {
109
+ path: (0, node_path.resolve)(packageDir, target),
110
+ sideEffects: manifest.sideEffects === false ? false : void 0
111
+ };
112
+ };
113
+
114
+ //#endregion
115
+ exports.findPackageManifest = findPackageManifest;
116
+ exports.parsePackageSpecifier = parsePackageSpecifier;
117
+ exports.resolvePackageExport = resolvePackageExport;
118
+ //# sourceMappingURL=resolvePackageExport.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolvePackageExport.cjs","names":["resolve","join","existsSync","dirname","readFileSync"],"sources":["../../../src/esbuild/resolvePackageExport.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\n\n/**\n * A target under a package manifest `exports` map: a file path, a condition\n * map, an ordered fallback list, or `null` to block the subpath.\n */\ntype ExportTarget =\n | string\n | null\n | ExportTarget[]\n | { [condition: string]: ExportTarget };\n\n/** The subset of a `package.json` this resolution reads. */\ntype PackageManifest = {\n main?: string;\n module?: string;\n exports?: ExportTarget;\n sideEffects?: boolean | string[];\n};\n\nexport type ResolvedPackageExport = {\n /** Absolute path of the file the specifier maps to. */\n path: string;\n /** `false` when the manifest declares the whole package side-effect free. */\n sideEffects: false | undefined;\n};\n\n/** Splits a bare specifier into its package name and `./`-prefixed subpath. */\nexport const parsePackageSpecifier = (\n specifier: string\n): { packageName: string; subpath: string } => {\n const segments = specifier.split('/');\n const nameSegmentCount = specifier.startsWith('@') ? 2 : 1;\n const packageName = segments.slice(0, nameSegmentCount).join('/');\n const rest = segments.slice(nameSegmentCount).join('/');\n\n return { packageName, subpath: rest ? `./${rest}` : '.' };\n};\n\n/**\n * Locates `node_modules/<packageName>/package.json` the way Node does: from\n * `startDir` upward, first hit wins.\n */\nexport const findPackageManifest = (\n packageName: string,\n startDir: string\n): string | undefined => {\n let currentDir = resolve(startDir);\n\n while (true) {\n const candidate = join(\n currentDir,\n 'node_modules',\n packageName,\n 'package.json'\n );\n if (existsSync(candidate)) return candidate;\n\n const parentDir = dirname(currentDir);\n if (parentDir === currentDir) return undefined;\n currentDir = parentDir;\n }\n};\n\n/**\n * Picks the file for a target, honouring the manifest's own key order for\n * condition maps as the ESM resolver does.\n */\nconst resolveExportTarget = (\n target: ExportTarget,\n conditions: ReadonlySet<string>\n): string | undefined => {\n if (typeof target === 'string') return target;\n if (target === null) return undefined;\n\n if (Array.isArray(target)) {\n for (const candidate of target) {\n const resolved = resolveExportTarget(candidate, conditions);\n if (resolved) return resolved;\n }\n return undefined;\n }\n\n for (const [condition, value] of Object.entries(target)) {\n if (condition !== 'default' && !conditions.has(condition)) continue;\n\n const resolved = resolveExportTarget(value, conditions);\n if (resolved) return resolved;\n }\n\n return undefined;\n};\n\n/**\n * Matches `subpath` against the `exports` map: an exact key first, then the\n * `*` pattern with the longest literal prefix, substituting the wildcard into\n * the resolved target.\n */\nconst resolveSubpathExport = (\n exportsMap: ExportTarget,\n subpath: string,\n conditions: ReadonlySet<string>\n): string | undefined => {\n const isSubpathMap =\n typeof exportsMap === 'object' &&\n exportsMap !== null &&\n !Array.isArray(exportsMap) &&\n Object.keys(exportsMap).some((key) => key.startsWith('.'));\n\n if (!isSubpathMap) {\n return subpath === '.'\n ? resolveExportTarget(exportsMap, conditions)\n : undefined;\n }\n\n const subpathMap = exportsMap as { [subpath: string]: ExportTarget };\n\n if (subpath in subpathMap) {\n return resolveExportTarget(subpathMap[subpath]!, conditions);\n }\n\n let bestMatch: { prefix: string; wildcard: string; target: ExportTarget } = {\n prefix: '',\n wildcard: '',\n target: null,\n };\n\n for (const [pattern, target] of Object.entries(subpathMap)) {\n const wildcardIndex = pattern.indexOf('*');\n if (wildcardIndex === -1) continue;\n\n const prefix = pattern.slice(0, wildcardIndex);\n const suffix = pattern.slice(wildcardIndex + 1);\n const matches =\n subpath.startsWith(prefix) &&\n subpath.length >= prefix.length + suffix.length &&\n subpath.endsWith(suffix);\n\n if (!matches || prefix.length <= bestMatch.prefix.length) continue;\n\n bestMatch = {\n prefix,\n wildcard: subpath.slice(prefix.length, subpath.length - suffix.length),\n target,\n };\n }\n\n const resolved = resolveExportTarget(bestMatch.target, conditions);\n\n return resolved?.replaceAll('*', bestMatch.wildcard);\n};\n\n/**\n * Resolves a bare specifier to an absolute file through the package manifest,\n * without going through the bundler's own resolver.\n *\n * Needed inside Angular's dev server: its esbuild pipeline marks every file\n * resolved under `node_modules` as external so Vite can pre-bundle it, and the\n * pre-bundler neither runs the Intlayer plugin nor sees its aliases — the real\n * `@intlayer/config/built` (a Node config loader) then lands in the browser.\n * Resolving here and returning a plain path keeps the package inside the\n * plugin-aware esbuild build.\n *\n * @param specifier - Bare specifier such as `@intlayer/core/interpreter`.\n * @param resolveDir - Directory the import is issued from.\n * @param conditions - Export conditions to honour, in addition to `default`.\n * @returns The resolved file, or `undefined` when the manifest cannot be found\n * or does not map the subpath — the caller then leaves the bundler to it.\n */\nexport const resolvePackageExport = (\n specifier: string,\n resolveDir: string,\n conditions: readonly string[]\n): ResolvedPackageExport | undefined => {\n const { packageName, subpath } = parsePackageSpecifier(specifier);\n const manifestPath = findPackageManifest(packageName, resolveDir);\n if (!manifestPath) return undefined;\n\n const manifest = JSON.parse(\n readFileSync(manifestPath, 'utf-8')\n ) as PackageManifest;\n const packageDir = dirname(manifestPath);\n const conditionSet = new Set(conditions);\n\n let target: string | undefined;\n\n if (manifest.exports !== undefined) {\n target = resolveSubpathExport(manifest.exports, subpath, conditionSet);\n } else if (subpath === '.') {\n target = manifest.module ?? manifest.main ?? './index.js';\n } else if (existsSync(join(packageDir, subpath))) {\n target = subpath;\n }\n\n if (!target) return undefined;\n\n return {\n path: resolve(packageDir, target),\n sideEffects: manifest.sideEffects === false ? false : undefined,\n };\n};\n"],"mappings":";;;;;;AA6BA,MAAa,yBACX,cAC6C;CAC7C,MAAM,WAAW,UAAU,MAAM,GAAG;CACpC,MAAM,mBAAmB,UAAU,WAAW,GAAG,IAAI,IAAI;CACzD,MAAM,cAAc,SAAS,MAAM,GAAG,gBAAgB,CAAC,CAAC,KAAK,GAAG;CAChE,MAAM,OAAO,SAAS,MAAM,gBAAgB,CAAC,CAAC,KAAK,GAAG;CAEtD,OAAO;EAAE;EAAa,SAAS,OAAO,KAAK,SAAS;CAAI;AAC1D;;;;;AAMA,MAAa,uBACX,aACA,aACuB;CACvB,IAAI,iBAAaA,mBAAQ,QAAQ;CAEjC,OAAO,MAAM;EACX,MAA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W,MAAM,KACzB,QAAQ,UAAU,OAAO,SAAS,OAAO,UACzC,QAAQ,SAAS,MAAM,MAET,OAAO,UAAU,UAAU,OAAO,QAAQ;EAE1D,YAAY;GACV;GACA,UAAU,QAAQ,MAAM,OAAO,QAAQ,QAAQ,SAAS,OAAO,MAAM;GACrE;EACF;CACF;CAIA,OAFiB,oBAAoB,UAAU,QAAQ,UAEzC,CAAC,EAAE,WAAW,KAAK,UAAU,QAAQ;AACrD;;;;;;;;;;;;;;;;;;AAmBA,MAAa,wBACX,WACA,YACA,eACsC;CACtC,MAAM,EAAE,aAAa,YAAY,sBAAsB,SAAS;CAChE,MAAM,eAAe,oBAAoB,aAAa,UAAU;CAChE,IAAI,CAAC,cAAc,OAAO;CAE1B,MAAM,WAAW,KAAK,UACpBC,sBAAa,cAAc,OAAO,CACpC;CACA,MAAM,iBAAaD,mBAAQ,YAAY;CACvC,MAAM,eAAe,IAAI,IAAI,UAAU;CAEvC,IAAI;CAEJ,IAAI,SAAS,YAAY,QACvB,SAAS,qBAAqB,SAAS,SAAS,SAAS,YAAY;MAChE,IAAI,YAAY,KACrB,SAAS,SAAS,UAAU,SAAS,QAAQ;MACxC,QAAID,wBAAWD,gBAAK,YAAY,OAAO,CAAC,GAC7C,SAAS;CAGX,IAAI,CAAC,QAAQ,OAAO;CAEpB,OAAO;EACL,UAAMD,mBAAQ,YAAY,MAAM;EAChC,aAAa,SAAS,gBAAgB,QAAQ,QAAQ;CACxD;AACF"}
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_decorate = require('../_virtual/_@oxc-project_runtime@0.148.0/helpers/esm/decorate.cjs');
3
- let _intlayer_core_markdown = require("@intlayer/core/markdown");
4
3
  let _angular_core = require("@angular/core");
4
+ let _intlayer_core_markdown = require("@intlayer/core/markdown");
5
5
 
6
6
  //#region src/markdown/installIntlayerMarkdown.ts
7
7
  /**
@@ -4,16 +4,26 @@ const require_renderIntlayerNode = require('./renderIntlayerNode.cjs');
4
4
  const require_analytics_exposureSink = require('./analytics/exposureSink.cjs');
5
5
  const require_editor_ContentSelector_component = require('./editor/ContentSelector.component.cjs');
6
6
  let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
7
+ let _angular_core = require("@angular/core");
7
8
  let _intlayer_config_built = require("@intlayer/config/built");
8
9
  let _intlayer_core_markdown = require("@intlayer/core/markdown");
9
10
  let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
10
11
  _intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
11
12
 
12
13
  //#region src/plugins.ts
13
- let _markdownInstall = null;
14
- if (process.env.INTLAYER_NODE_TYPE_MARKDOWN !== "false" || process.env.INTLAYER_NODE_TYPE_HTML !== "false") Promise.resolve().then(() => require("./markdown/installIntlayerMarkdown.cjs")).then((m) => {
15
- _markdownInstall = m;
16
- }).catch(() => {});
14
+ /**
15
+ * Code-split markdown renderer, held in a signal.
16
+ *
17
+ * The chunk loads asynchronously, so the first dictionary evaluation may run
18
+ * before it lands. `getPlugins` reads this signal inside the `computed` of
19
+ * `useIntlayer`/`useDictionary`, which makes that computed depend on it: nodes
20
+ * stringify to their raw source until the module resolves, then the signal
21
+ * flip re-evaluates the dictionary and every binding re-renders with compiled
22
+ * HTML. This is the Angular counterpart of the `Suspense` boundary the React
23
+ * and Solid packages wrap their markdown renderer in.
24
+ */
25
+ const markdownRendererModule = (0, _angular_core.signal)(null);
26
+ if (process.env.INTLAYER_NODE_TYPE_MARKDOWN !== "false" || process.env.INTLAYER_NODE_TYPE_HTML !== "false") Promise.resolve().then(() => require("./markdown/installIntlayerMarkdown.cjs")).then((module) => markdownRendererModule.set(module)).catch(() => {});
17
27
  /** ---------------------------------------------
18
28
  * UTILS
19
29
  * --------------------------------------------- */
@@ -37,6 +47,18 @@ const createRuntimeWithOverides = (baseRuntime, overrides) => ({
37
47
  return baseRuntime.createElement(tag, props, ...children);
38
48
  }
39
49
  });
50
+ /**
51
+ * Compiles a markdown/HTML source to an HTML string with the code-split
52
+ * runtime, or returns the raw source while the renderer chunk is still
53
+ * loading. Runs at stringify time, so a node kept outside any reactive
54
+ * context still picks the renderer up once it has landed.
55
+ */
56
+ const compileToHtml = (source, components) => {
57
+ const rendererModule = (0, _angular_core.untracked)(markdownRendererModule);
58
+ if (!rendererModule) return source;
59
+ const runtime = components ? createRuntimeWithOverides(rendererModule.htmlRuntime, components) : rendererModule.htmlRuntime;
60
+ return (0, _intlayer_core_markdown.compile)(source, { runtime });
61
+ };
40
62
  /** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
41
63
  const intlayerNodePlugins = {
42
64
  id: "intlayer-node-plugin",
@@ -81,41 +103,25 @@ const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false"
81
103
  dictionaryKey: rest.dictionaryKey,
82
104
  keyPath: []
83
105
  });
106
+ const renderMarkdown = (components) => (0, _angular_core.untracked)(markdownRendererModule)?.useMarkdown().renderMarkdown(node, components) ?? node;
84
107
  const render = (components) => require_renderIntlayerNode.renderIntlayerNode({
85
108
  ...rest,
86
109
  value: node,
87
- children: process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_config_built.editor.enabled ? () => {
88
- const { renderMarkdown } = _markdownInstall?.useMarkdown() ?? { renderMarkdown: () => node };
89
- return renderMarkdown(node, components);
90
- } : () => ({
110
+ children: process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_config_built.editor.enabled ? () => renderMarkdown(components) : () => ({
91
111
  component: require_editor_ContentSelector_component.ContentSelectorWrapperComponent,
92
112
  props: {
93
113
  dictionaryKey: rest.dictionaryKey,
94
114
  keyPath: rest.keyPath,
95
115
  ...components
96
116
  },
97
- children: () => {
98
- const { renderMarkdown } = _markdownInstall?.useMarkdown() ?? { renderMarkdown: () => node };
99
- return renderMarkdown(node, components);
100
- }
117
+ children: () => renderMarkdown(components)
101
118
  }),
102
119
  additionalProps: { metadata: metadataNodes }
103
120
  });
104
121
  const createProxy = (element, components) => new Proxy(element, { get(target, prop, receiver) {
105
122
  if (prop === "value") return node;
106
123
  if (prop === "metadata") return metadataNodes;
107
- if (prop === "toString") return () => {
108
- const htmlRuntime = _markdownInstall?.htmlRuntime;
109
- if (!htmlRuntime || !_intlayer_core_markdown.compile) return node;
110
- const runtime = components ? createRuntimeWithOverides(htmlRuntime, components) : htmlRuntime;
111
- return (0, _intlayer_core_markdown.compile)(node, { runtime });
112
- };
113
- if (prop === Symbol.toPrimitive) return () => {
114
- const htmlRuntime = _markdownInstall?.htmlRuntime;
115
- if (!htmlRuntime || !_intlayer_core_markdown.compile) return node;
116
- const runtime = components ? createRuntimeWithOverides(htmlRuntime, components) : htmlRuntime;
117
- return (0, _intlayer_core_markdown.compile)(node, { runtime });
118
- };
124
+ if (prop === "toString" || prop === Symbol.toPrimitive) return () => compileToHtml(node, components);
119
125
  if (prop === "use") return (newComponents) => {
120
126
  const mergedComponents = {
121
127
  ...components,
@@ -164,19 +170,9 @@ const htmlPlugin = process.env.INTLAYER_NODE_TYPE_HTML === "false" ? _intlayer_c
164
170
  });
165
171
  const createProxy = (element, components) => new Proxy(element, { get(target, prop, receiver) {
166
172
  if (prop === "value") return html;
167
- if (prop === "toString") return () => {
168
- if (!components || typeof components === "object" && Object.keys(components).length === 0) return String(html);
169
- const htmlRuntime = _markdownInstall?.htmlRuntime;
170
- if (!htmlRuntime || !_intlayer_core_markdown.compile) return String(html);
171
- const runtime = createRuntimeWithOverides(htmlRuntime, components);
172
- return (0, _intlayer_core_markdown.compile)(html, { runtime });
173
- };
174
- if (prop === Symbol.toPrimitive) return () => {
175
- if (!components || typeof components === "object" && Object.keys(components).length === 0) return String(html);
176
- const htmlRuntime = _markdownInstall?.htmlRuntime;
177
- if (!htmlRuntime || !_intlayer_core_markdown.compile) return String(html);
178
- const runtime = createRuntimeWithOverides(htmlRuntime, components);
179
- return (0, _intlayer_core_markdown.compile)(html, { runtime });
173
+ if (prop === "toString" || prop === Symbol.toPrimitive) return () => {
174
+ if (!components || Object.keys(components).length === 0) return String(html);
175
+ return compileToHtml(String(html), components);
180
176
  };
181
177
  if (prop === "use") return (userComponents) => {
182
178
  const mergedComponents = {
@@ -217,7 +213,7 @@ const pluginsCache = /* @__PURE__ */ new Map();
217
213
  * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.
218
214
  */
219
215
  const getPlugins = (locale, fallback = true) => {
220
- const cacheKey = `${locale ?? _intlayer_config_built.internationalization.defaultLocale}_${fallback}`;
216
+ const cacheKey = `${locale ?? _intlayer_config_built.internationalization.defaultLocale}_${fallback}_${markdownRendererModule() !== null}`;
221
217
  if (pluginsCache.has(cacheKey)) return pluginsCache.get(cacheKey);
222
218
  const plugins = [
223
219
  (0, _intlayer_core_interpreter.translationPlugin)(locale ?? _intlayer_config_built.internationalization.defaultLocale, fallback ? _intlayer_config_built.internationalization.defaultLocale : void 0),