astro-intlayer 9.4.3 → 9.5.0

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/README.md CHANGED
@@ -69,8 +69,6 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
69
69
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/interoperability.png?raw=true" alt="Feature" width="700"> | **Interoperability**<br><br>Allow interoperability with react-i18next, next-i18next, next-intl, react-intl, vue-i18n. <br><br> - [Intlayer and react-intl](https://intlayer.org/blog/intlayer-with-react-intl) <br> - [Intlayer and next-intl](https://intlayer.org/blog/intlayer-with-next-intl) <br> - [Intlayer and next-i18next](https://intlayer.org/blog/intlayer-with-next-i18next) <br> - [Intlayer and vue-i18n](https://intlayer.org/blog/intlayer-with-vue-i18n) <br> - [Intlayer compat adapters](https://intlayer.org/doc/compatibility) |
70
70
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/benchmark.png?raw=true" alt="Feature" width="700"> | **Performances & Benchmark**<br><br>Uses advanced tree-shaking and dynamic loading to boost performances and keep the solution as light as possible. <br><br> - [Performances & Benchmark](https://intlayer.org/doc/benchmark) |
71
71
 
72
- ---
73
-
74
72
  ## 📦 Installation
75
73
 
76
74
  Start your journey with Intlayer today and experience a smoother, more powerful approach to internationalization.
@@ -4,19 +4,34 @@ let node_path = require("node:path");
4
4
  let _intlayer_config_node = require("@intlayer/config/node");
5
5
  let _intlayer_config_utils = require("@intlayer/config/utils");
6
6
  let _intlayer_engine_build = require("@intlayer/engine/build");
7
- let _intlayer_engine_watcher = require("@intlayer/engine/watcher");
8
7
  let vite_intlayer = require("vite-intlayer");
9
8
 
10
9
  //#region src/index.ts
11
10
  /**
11
+ * Keeps the intlayer packages out of Node's native module loader in *every*
12
+ * Vite environment Astro renders from.
13
+ *
14
+ * A static dev server renders from `ssr`, but other setups render from Astro's
15
+ * `astro` or `prerender` environments, and a top-level `ssr.noExternal` only
16
+ * seeds the `ssr` one. Declaring it per environment covers the rest.
17
+ */
18
+ const intlayerNoExternalEnvironments = () => ({
19
+ name: "astro-intlayer-no-external",
20
+ configEnvironment: () => ({ resolve: { noExternal: [vite_intlayer.INTLAYER_NO_EXTERNAL_PATTERN] } })
21
+ });
22
+ /**
12
23
  * Astro integration for Intlayer.
13
24
  *
14
25
  * It handles:
15
26
  * 1. Preparing Intlayer resources (dictionaries) at config setup.
16
27
  * 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).
17
28
  * 3. Configuring Vite aliases for dictionary access.
18
- * 4. Starting a file watcher for dictionary changes during development.
19
- * 5. Emitting the prerendered pages at their rewritten (localized) URLs.
29
+ * 4. Emitting the prerendered pages at their rewritten (localized) URLs.
30
+ *
31
+ * The dev-time content watcher is not started here: the bundled
32
+ * `vite-intlayer` plugin already starts one from `configureServer`, and
33
+ * `watch()` subscribes anew on every call, so doing both would rebuild each
34
+ * content edit twice.
20
35
  *
21
36
  * @returns An Astro integration object.
22
37
  *
@@ -38,17 +53,14 @@ const intlayer = () => ({
38
53
  const configuration = (0, _intlayer_config_node.getConfiguration)();
39
54
  await (0, _intlayer_engine_build.prepareIntlayer)(configuration);
40
55
  updateConfig({ vite: {
41
- plugins: [(0, vite_intlayer.intlayer)(), (0, vite_intlayer.intlayerProxy)()],
56
+ plugins: [(0, vite_intlayer.intlayer)(), intlayerNoExternalEnvironments()],
42
57
  resolve: { alias: { ...(0, _intlayer_config_utils.getAlias)({
43
58
  configuration,
44
59
  formatter: (value) => (0, node_path.resolve)(value)
45
- }) } }
60
+ }) } },
61
+ ssr: { noExternal: [vite_intlayer.INTLAYER_NO_EXTERNAL_PATTERN] }
46
62
  } });
47
63
  },
48
- "astro:server:setup": async () => {
49
- const configuration = (0, _intlayer_config_node.getConfiguration)();
50
- if (configuration.content.watch) await (0, _intlayer_engine_watcher.watch)({ configuration });
51
- },
52
64
  "astro:build:done": async ({ dir, logger }) => {
53
65
  const configuration = (0, _intlayer_config_node.getConfiguration)();
54
66
  const emittedPages = await require_emitRewrittenPages.emitRewrittenPages(configuration, dir);
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["getConfiguration","prepareIntlayer","viteIntlayerPlugin","viteIntlayerProxyPlugin","getAlias","resolve","watch","emitRewrittenPages"],"sources":["../../src/index.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport { watch } from '@intlayer/engine/watcher';\nimport type { AstroIntegration } from 'astro';\nimport type { PluginOption } from 'vite';\nimport {\n intlayer as viteIntlayerPlugin,\n intlayerProxy as viteIntlayerProxyPlugin,\n} from 'vite-intlayer';\nimport { emitRewrittenPages } from './emitRewrittenPages';\n\n/**\n * Astro integration for Intlayer.\n *\n * It handles:\n * 1. Preparing Intlayer resources (dictionaries) at config setup.\n * 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).\n * 3. Configuring Vite aliases for dictionary access.\n * 4. Starting a file watcher for dictionary changes during development.\n * 5. Emitting the prerendered pages at their rewritten (localized) URLs.\n *\n * @returns An Astro integration object.\n *\n * @example\n * ```ts\n * // astro.config.mjs\n * import { defineConfig } from 'astro/config';\n * import { intlayer } from 'astro-intlayer';\n *\n * export default defineConfig({\n * integrations: [intlayer()],\n * });\n * ```\n */\nexport const intlayer = (): AstroIntegration =>\n ({\n name: 'astro-intlayer',\n hooks: {\n 'astro:config:setup': async ({ updateConfig }) => {\n const configuration = getConfiguration();\n\n // Prepare once per process start to ensure generated entries exist\n await prepareIntlayer(configuration);\n\n updateConfig({\n vite: {\n plugins: [\n // Aliases + watcher + buildStart prep\n // (also handles optimize/prune/minify internally)\n viteIntlayerPlugin(),\n // Dev-time middleware for locale routing\n viteIntlayerProxyPlugin(),\n ] as PluginOption[],\n resolve: {\n alias: {\n ...getAlias({\n configuration,\n formatter: (value) => resolve(value),\n }),\n },\n },\n },\n });\n },\n\n 'astro:server:setup': async () => {\n const configuration = getConfiguration();\n\n if (configuration.content.watch) {\n await watch({ configuration });\n }\n },\n\n // Astro renders each page from its canonical file-system route, so a\n // static build has no file for the localized paths declared in\n // `routing.rewrite`. Mirror them here, otherwise the URLs produced by\n // `getLocalizedUrl` (links, hreflang, sitemap) 404 once deployed.\n 'astro:build:done': async ({ dir, logger }) => {\n const configuration = getConfiguration();\n\n const emittedPages = await emitRewrittenPages(configuration, dir);\n\n if (emittedPages.length > 0) {\n logger.info(\n `Emitted ${emittedPages.length} rewritten page(s): ${emittedPages\n .map(([from, to]) => `${from} \\u2192 ${to}`)\n .join(', ')}`\n );\n }\n },\n },\n }) satisfies AstroIntegration;\n\n/**\n * Alias of {@link intlayer}, kept so `astro add astro-intlayer` works.\n *\n * Astro's CLI codemod always writes a default import\n * (`import intlayer from 'astro-intlayer'`) without checking what the package\n * exports, so the integration has to be reachable that way too. The named\n * export stays the documented one.\n */\nexport default intlayer;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,kBACV;CACC,MAAM;CACN,OAAO;EACL,sBAAsB,OAAO,EAAE,mBAAmB;GAChD,MAAM,oBAAgBA,wCAAiB;GAGvC,UAAMC,wCAAgB,aAAa;GAEnC,aAAa,EACX,MAAM;IACJ,SAAS,KAGPC,wBAAmB,OAEnBC,6BAAwB,CAC1B;IACA,SAAS,EACP,OAAO,EACL,OAAGC,iCAAS;KACV;KACA,YAAY,cAAUC,mBAAQ,KAAK;IACrC,CAAC,EACH,EACF;GACF,EACF,CAAC;EACH;EAEA,sBAAsB,YAAY;GAChC,MAAM,oBAAgBL,wCAAiB;GAEvC,IAAI,cAAc,QAAQ,OACxB,UAAMM,gCAAM,EAAE,cAAc,CAAC;EAEjC;EAMA,oBAAoB,OAAO,EAAE,KAAK,aAAa;GAC7C,MAAM,oBAAgBN,wCAAiB;GAEvC,MAAM,eAAe,MAAMO,8CAAmB,eAAe,GAAG;GAEhE,IAAI,aAAa,SAAS,GACxB,OAAO,KACL,WAAW,aAAa,OAAO,sBAAsB,aAClD,KAAK,CAAC,MAAM,QAAQ,GAAG,KAAK,UAAU,IAAI,CAAC,CAC3C,KAAK,IAAI,GACd;EAEJ;CACF;AACF"}
1
+ {"version":3,"file":"index.cjs","names":["INTLAYER_NO_EXTERNAL_PATTERN","getConfiguration","prepareIntlayer","viteIntlayerPlugin","getAlias","resolve","emitRewrittenPages"],"sources":["../../src/index.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport type { AstroIntegration } from 'astro';\nimport type { PluginOption } from 'vite';\nimport {\n INTLAYER_NO_EXTERNAL_PATTERN,\n intlayer as viteIntlayerPlugin,\n} from 'vite-intlayer';\nimport { emitRewrittenPages } from './emitRewrittenPages';\n\n/**\n * Keeps the intlayer packages out of Node's native module loader in *every*\n * Vite environment Astro renders from.\n *\n * A static dev server renders from `ssr`, but other setups render from Astro's\n * `astro` or `prerender` environments, and a top-level `ssr.noExternal` only\n * seeds the `ssr` one. Declaring it per environment covers the rest.\n */\nconst intlayerNoExternalEnvironments = (): PluginOption => ({\n name: 'astro-intlayer-no-external',\n configEnvironment: () => ({\n resolve: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] },\n }),\n});\n\n/**\n * Astro integration for Intlayer.\n *\n * It handles:\n * 1. Preparing Intlayer resources (dictionaries) at config setup.\n * 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).\n * 3. Configuring Vite aliases for dictionary access.\n * 4. Emitting the prerendered pages at their rewritten (localized) URLs.\n *\n * The dev-time content watcher is not started here: the bundled\n * `vite-intlayer` plugin already starts one from `configureServer`, and\n * `watch()` subscribes anew on every call, so doing both would rebuild each\n * content edit twice.\n *\n * @returns An Astro integration object.\n *\n * @example\n * ```ts\n * // astro.config.mjs\n * import { defineConfig } from 'astro/config';\n * import { intlayer } from 'astro-intlayer';\n *\n * export default defineConfig({\n * integrations: [intlayer()],\n * });\n * ```\n */\nexport const intlayer = (): AstroIntegration =>\n ({\n name: 'astro-intlayer',\n hooks: {\n 'astro:config:setup': async ({ updateConfig }) => {\n const configuration = getConfiguration();\n\n // Prepare once per process start to ensure generated entries exist\n await prepareIntlayer(configuration);\n\n updateConfig({\n vite: {\n plugins: [\n viteIntlayerPlugin(),\n intlayerNoExternalEnvironments(),\n ] as PluginOption[],\n resolve: {\n alias: {\n ...getAlias({\n configuration,\n formatter: (value) => resolve(value),\n }),\n },\n },\n // `astro-intlayer` is tagged with the `astro` keyword, so Astro\n // treats it as an Astro package and crawls its dependency tree\n // (`vitefu`), force-externalizing every dependency it finds —\n // `@intlayer/core`, `@intlayer/config`, … — into\n // `resolve.external`. Vite checks `external` before `noExternal`,\n // so the `ssr.noExternal` that `vite-intlayer` returns from its\n // Vite `config` hook loses that race and the packages are loaded\n // natively by Node, stranding dictionary edits behind Node's\n // require cache. Declaring it here instead runs before the crawl,\n // which drops explicitly no-externalized packages from its result.\n ssr: {\n noExternal: [INTLAYER_NO_EXTERNAL_PATTERN],\n },\n },\n });\n },\n\n // Astro renders each page from its canonical file-system route, so a\n // static build has no file for the localized paths declared in\n // `routing.rewrite`. Mirror them here, otherwise the URLs produced by\n // `getLocalizedUrl` (links, hreflang, sitemap) 404 once deployed.\n 'astro:build:done': async ({ dir, logger }) => {\n const configuration = getConfiguration();\n\n const emittedPages = await emitRewrittenPages(configuration, dir);\n\n if (emittedPages.length > 0) {\n logger.info(\n `Emitted ${emittedPages.length} rewritten page(s): ${emittedPages\n .map(([from, to]) => `${from} \\u2192 ${to}`)\n .join(', ')}`\n );\n }\n },\n },\n }) satisfies AstroIntegration;\n\n/**\n * Alias of {@link intlayer}, kept so `astro add astro-intlayer` works.\n *\n * Astro's CLI codemod always writes a default import\n * (`import intlayer from 'astro-intlayer'`) without checking what the package\n * exports, so the integration has to be reachable that way too. The named\n * export stays the documented one.\n */\nexport default intlayer;\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,MAAM,wCAAsD;CAC1D,MAAM;CACN,0BAA0B,EACxB,SAAS,EAAE,YAAY,CAACA,0CAA4B,EAAE,EACxD;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,kBACV;CACC,MAAM;CACN,OAAO;EACL,sBAAsB,OAAO,EAAE,mBAAmB;GAChD,MAAM,oBAAgBC,wCAAiB;GAGvC,UAAMC,wCAAgB,aAAa;GAEnC,aAAa,EACX,MAAM;IACJ,SAAS,KACPC,wBAAmB,GACnB,+BAA+B,CACjC;IACA,SAAS,EACP,OAAO,EACL,OAAGC,iCAAS;KACV;KACA,YAAY,cAAUC,mBAAQ,KAAK;IACrC,CAAC,EACH,EACF;IAWA,KAAK,EACH,YAAY,CAACL,0CAA4B,EAC3C;GACF,EACF,CAAC;EACH;EAMA,oBAAoB,OAAO,EAAE,KAAK,aAAa;GAC7C,MAAM,oBAAgBC,wCAAiB;GAEvC,MAAM,eAAe,MAAMK,8CAAmB,eAAe,GAAG;GAEhE,IAAI,aAAa,SAAS,GACxB,OAAO,KACL,WAAW,aAAa,OAAO,sBAAsB,aAClD,KAAK,CAAC,MAAM,QAAQ,GAAG,KAAK,UAAU,IAAI,CAAC,CAC3C,KAAK,IAAI,GACd;EAEJ;CACF;AACF"}
@@ -3,19 +3,34 @@ import { resolve } from "node:path";
3
3
  import { getConfiguration } from "@intlayer/config/node";
4
4
  import { getAlias } from "@intlayer/config/utils";
5
5
  import { prepareIntlayer } from "@intlayer/engine/build";
6
- import { watch } from "@intlayer/engine/watcher";
7
- import { intlayer as intlayer$1, intlayerProxy } from "vite-intlayer";
6
+ import { INTLAYER_NO_EXTERNAL_PATTERN, intlayer as intlayer$1 } from "vite-intlayer";
8
7
 
9
8
  //#region src/index.ts
10
9
  /**
10
+ * Keeps the intlayer packages out of Node's native module loader in *every*
11
+ * Vite environment Astro renders from.
12
+ *
13
+ * A static dev server renders from `ssr`, but other setups render from Astro's
14
+ * `astro` or `prerender` environments, and a top-level `ssr.noExternal` only
15
+ * seeds the `ssr` one. Declaring it per environment covers the rest.
16
+ */
17
+ const intlayerNoExternalEnvironments = () => ({
18
+ name: "astro-intlayer-no-external",
19
+ configEnvironment: () => ({ resolve: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] } })
20
+ });
21
+ /**
11
22
  * Astro integration for Intlayer.
12
23
  *
13
24
  * It handles:
14
25
  * 1. Preparing Intlayer resources (dictionaries) at config setup.
15
26
  * 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).
16
27
  * 3. Configuring Vite aliases for dictionary access.
17
- * 4. Starting a file watcher for dictionary changes during development.
18
- * 5. Emitting the prerendered pages at their rewritten (localized) URLs.
28
+ * 4. Emitting the prerendered pages at their rewritten (localized) URLs.
29
+ *
30
+ * The dev-time content watcher is not started here: the bundled
31
+ * `vite-intlayer` plugin already starts one from `configureServer`, and
32
+ * `watch()` subscribes anew on every call, so doing both would rebuild each
33
+ * content edit twice.
19
34
  *
20
35
  * @returns An Astro integration object.
21
36
  *
@@ -37,17 +52,14 @@ const intlayer = () => ({
37
52
  const configuration = getConfiguration();
38
53
  await prepareIntlayer(configuration);
39
54
  updateConfig({ vite: {
40
- plugins: [intlayer$1(), intlayerProxy()],
55
+ plugins: [intlayer$1(), intlayerNoExternalEnvironments()],
41
56
  resolve: { alias: { ...getAlias({
42
57
  configuration,
43
58
  formatter: (value) => resolve(value)
44
- }) } }
59
+ }) } },
60
+ ssr: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] }
45
61
  } });
46
62
  },
47
- "astro:server:setup": async () => {
48
- const configuration = getConfiguration();
49
- if (configuration.content.watch) await watch({ configuration });
50
- },
51
63
  "astro:build:done": async ({ dir, logger }) => {
52
64
  const configuration = getConfiguration();
53
65
  const emittedPages = await emitRewrittenPages(configuration, dir);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["viteIntlayerPlugin","viteIntlayerProxyPlugin"],"sources":["../../src/index.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport { watch } from '@intlayer/engine/watcher';\nimport type { AstroIntegration } from 'astro';\nimport type { PluginOption } from 'vite';\nimport {\n intlayer as viteIntlayerPlugin,\n intlayerProxy as viteIntlayerProxyPlugin,\n} from 'vite-intlayer';\nimport { emitRewrittenPages } from './emitRewrittenPages';\n\n/**\n * Astro integration for Intlayer.\n *\n * It handles:\n * 1. Preparing Intlayer resources (dictionaries) at config setup.\n * 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).\n * 3. Configuring Vite aliases for dictionary access.\n * 4. Starting a file watcher for dictionary changes during development.\n * 5. Emitting the prerendered pages at their rewritten (localized) URLs.\n *\n * @returns An Astro integration object.\n *\n * @example\n * ```ts\n * // astro.config.mjs\n * import { defineConfig } from 'astro/config';\n * import { intlayer } from 'astro-intlayer';\n *\n * export default defineConfig({\n * integrations: [intlayer()],\n * });\n * ```\n */\nexport const intlayer = (): AstroIntegration =>\n ({\n name: 'astro-intlayer',\n hooks: {\n 'astro:config:setup': async ({ updateConfig }) => {\n const configuration = getConfiguration();\n\n // Prepare once per process start to ensure generated entries exist\n await prepareIntlayer(configuration);\n\n updateConfig({\n vite: {\n plugins: [\n // Aliases + watcher + buildStart prep\n // (also handles optimize/prune/minify internally)\n viteIntlayerPlugin(),\n // Dev-time middleware for locale routing\n viteIntlayerProxyPlugin(),\n ] as PluginOption[],\n resolve: {\n alias: {\n ...getAlias({\n configuration,\n formatter: (value) => resolve(value),\n }),\n },\n },\n },\n });\n },\n\n 'astro:server:setup': async () => {\n const configuration = getConfiguration();\n\n if (configuration.content.watch) {\n await watch({ configuration });\n }\n },\n\n // Astro renders each page from its canonical file-system route, so a\n // static build has no file for the localized paths declared in\n // `routing.rewrite`. Mirror them here, otherwise the URLs produced by\n // `getLocalizedUrl` (links, hreflang, sitemap) 404 once deployed.\n 'astro:build:done': async ({ dir, logger }) => {\n const configuration = getConfiguration();\n\n const emittedPages = await emitRewrittenPages(configuration, dir);\n\n if (emittedPages.length > 0) {\n logger.info(\n `Emitted ${emittedPages.length} rewritten page(s): ${emittedPages\n .map(([from, to]) => `${from} \\u2192 ${to}`)\n .join(', ')}`\n );\n }\n },\n },\n }) satisfies AstroIntegration;\n\n/**\n * Alias of {@link intlayer}, kept so `astro add astro-intlayer` works.\n *\n * Astro's CLI codemod always writes a default import\n * (`import intlayer from 'astro-intlayer'`) without checking what the package\n * exports, so the integration has to be reachable that way too. The named\n * export stays the documented one.\n */\nexport default intlayer;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,kBACV;CACC,MAAM;CACN,OAAO;EACL,sBAAsB,OAAO,EAAE,mBAAmB;GAChD,MAAM,gBAAgB,iBAAiB;GAGvC,MAAM,gBAAgB,aAAa;GAEnC,aAAa,EACX,MAAM;IACJ,SAAS,CAGPA,WAAmB,GAEnBC,cAAwB,CAC1B;IACA,SAAS,EACP,OAAO,EACL,GAAG,SAAS;KACV;KACA,YAAY,UAAU,QAAQ,KAAK;IACrC,CAAC,EACH,EACF;GACF,EACF,CAAC;EACH;EAEA,sBAAsB,YAAY;GAChC,MAAM,gBAAgB,iBAAiB;GAEvC,IAAI,cAAc,QAAQ,OACxB,MAAM,MAAM,EAAE,cAAc,CAAC;EAEjC;EAMA,oBAAoB,OAAO,EAAE,KAAK,aAAa;GAC7C,MAAM,gBAAgB,iBAAiB;GAEvC,MAAM,eAAe,MAAM,mBAAmB,eAAe,GAAG;GAEhE,IAAI,aAAa,SAAS,GACxB,OAAO,KACL,WAAW,aAAa,OAAO,sBAAsB,aAClD,KAAK,CAAC,MAAM,QAAQ,GAAG,KAAK,UAAU,IAAI,CAAC,CAC3C,KAAK,IAAI,GACd;EAEJ;CACF;AACF"}
1
+ {"version":3,"file":"index.mjs","names":["viteIntlayerPlugin"],"sources":["../../src/index.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport type { AstroIntegration } from 'astro';\nimport type { PluginOption } from 'vite';\nimport {\n INTLAYER_NO_EXTERNAL_PATTERN,\n intlayer as viteIntlayerPlugin,\n} from 'vite-intlayer';\nimport { emitRewrittenPages } from './emitRewrittenPages';\n\n/**\n * Keeps the intlayer packages out of Node's native module loader in *every*\n * Vite environment Astro renders from.\n *\n * A static dev server renders from `ssr`, but other setups render from Astro's\n * `astro` or `prerender` environments, and a top-level `ssr.noExternal` only\n * seeds the `ssr` one. Declaring it per environment covers the rest.\n */\nconst intlayerNoExternalEnvironments = (): PluginOption => ({\n name: 'astro-intlayer-no-external',\n configEnvironment: () => ({\n resolve: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] },\n }),\n});\n\n/**\n * Astro integration for Intlayer.\n *\n * It handles:\n * 1. Preparing Intlayer resources (dictionaries) at config setup.\n * 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).\n * 3. Configuring Vite aliases for dictionary access.\n * 4. Emitting the prerendered pages at their rewritten (localized) URLs.\n *\n * The dev-time content watcher is not started here: the bundled\n * `vite-intlayer` plugin already starts one from `configureServer`, and\n * `watch()` subscribes anew on every call, so doing both would rebuild each\n * content edit twice.\n *\n * @returns An Astro integration object.\n *\n * @example\n * ```ts\n * // astro.config.mjs\n * import { defineConfig } from 'astro/config';\n * import { intlayer } from 'astro-intlayer';\n *\n * export default defineConfig({\n * integrations: [intlayer()],\n * });\n * ```\n */\nexport const intlayer = (): AstroIntegration =>\n ({\n name: 'astro-intlayer',\n hooks: {\n 'astro:config:setup': async ({ updateConfig }) => {\n const configuration = getConfiguration();\n\n // Prepare once per process start to ensure generated entries exist\n await prepareIntlayer(configuration);\n\n updateConfig({\n vite: {\n plugins: [\n viteIntlayerPlugin(),\n intlayerNoExternalEnvironments(),\n ] as PluginOption[],\n resolve: {\n alias: {\n ...getAlias({\n configuration,\n formatter: (value) => resolve(value),\n }),\n },\n },\n // `astro-intlayer` is tagged with the `astro` keyword, so Astro\n // treats it as an Astro package and crawls its dependency tree\n // (`vitefu`), force-externalizing every dependency it finds —\n // `@intlayer/core`, `@intlayer/config`, … — into\n // `resolve.external`. Vite checks `external` before `noExternal`,\n // so the `ssr.noExternal` that `vite-intlayer` returns from its\n // Vite `config` hook loses that race and the packages are loaded\n // natively by Node, stranding dictionary edits behind Node's\n // require cache. Declaring it here instead runs before the crawl,\n // which drops explicitly no-externalized packages from its result.\n ssr: {\n noExternal: [INTLAYER_NO_EXTERNAL_PATTERN],\n },\n },\n });\n },\n\n // Astro renders each page from its canonical file-system route, so a\n // static build has no file for the localized paths declared in\n // `routing.rewrite`. Mirror them here, otherwise the URLs produced by\n // `getLocalizedUrl` (links, hreflang, sitemap) 404 once deployed.\n 'astro:build:done': async ({ dir, logger }) => {\n const configuration = getConfiguration();\n\n const emittedPages = await emitRewrittenPages(configuration, dir);\n\n if (emittedPages.length > 0) {\n logger.info(\n `Emitted ${emittedPages.length} rewritten page(s): ${emittedPages\n .map(([from, to]) => `${from} \\u2192 ${to}`)\n .join(', ')}`\n );\n }\n },\n },\n }) satisfies AstroIntegration;\n\n/**\n * Alias of {@link intlayer}, kept so `astro add astro-intlayer` works.\n *\n * Astro's CLI codemod always writes a default import\n * (`import intlayer from 'astro-intlayer'`) without checking what the package\n * exports, so the integration has to be reachable that way too. The named\n * export stays the documented one.\n */\nexport default intlayer;\n"],"mappings":";;;;;;;;;;;;;;;;AAoBA,MAAM,wCAAsD;CAC1D,MAAM;CACN,0BAA0B,EACxB,SAAS,EAAE,YAAY,CAAC,4BAA4B,EAAE,EACxD;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,kBACV;CACC,MAAM;CACN,OAAO;EACL,sBAAsB,OAAO,EAAE,mBAAmB;GAChD,MAAM,gBAAgB,iBAAiB;GAGvC,MAAM,gBAAgB,aAAa;GAEnC,aAAa,EACX,MAAM;IACJ,SAAS,CACPA,WAAmB,GACnB,+BAA+B,CACjC;IACA,SAAS,EACP,OAAO,EACL,GAAG,SAAS;KACV;KACA,YAAY,UAAU,QAAQ,KAAK;IACrC,CAAC,EACH,EACF;IAWA,KAAK,EACH,YAAY,CAAC,4BAA4B,EAC3C;GACF,EACF,CAAC;EACH;EAMA,oBAAoB,OAAO,EAAE,KAAK,aAAa;GAC7C,MAAM,gBAAgB,iBAAiB;GAEvC,MAAM,eAAe,MAAM,mBAAmB,eAAe,GAAG;GAEhE,IAAI,aAAa,SAAS,GACxB,OAAO,KACL,WAAW,aAAa,OAAO,sBAAsB,aAClD,KAAK,CAAC,MAAM,QAAQ,GAAG,KAAK,UAAU,IAAI,CAAC,CAC3C,KAAK,IAAI,GACd;EAEJ;CACF;AACF"}
@@ -17,7 +17,6 @@ import { IntlayerConfig } from "@intlayer/types/config";
17
17
  * @param outputDirectoryUrl - The build output directory, as given by `astro:build:done`.
18
18
  * @returns The list of `[from, to]` URL paths that were emitted.
19
19
  */
20
- declare const emitRewrittenPages: (configuration: IntlayerConfig, outputDirectoryUrl: URL) => Promise<[from: string, to: string][]>;
20
+ export declare const emitRewrittenPages: (configuration: IntlayerConfig, outputDirectoryUrl: URL) => Promise<[from: string, to: string][]>;
21
21
  //#endregion
22
- export { emitRewrittenPages };
23
22
  //# sourceMappingURL=emitRewrittenPages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"emitRewrittenPages.d.ts","names":[],"sources":["../../src/emitRewrittenPages.ts"],"mappings":";;;;;;;;;;;;;;;;;;;cAuHa,qBAAkB,eACd,gBAAc,oBACT,QACnB,SAAS,cAAc"}
1
+ {"version":3,"file":"emitRewrittenPages.d.ts","names":[],"sources":["../../src/emitRewrittenPages.ts"],"mappings":";;;;;;;;;;;;;;;;;;;qBAuHa,qBAAkB,eACd,gBAAc,oBACT,QACnB,SAAS,cAAc"}
@@ -7,8 +7,12 @@ import { AstroIntegration } from "astro";
7
7
  * 1. Preparing Intlayer resources (dictionaries) at config setup.
8
8
  * 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).
9
9
  * 3. Configuring Vite aliases for dictionary access.
10
- * 4. Starting a file watcher for dictionary changes during development.
11
- * 5. Emitting the prerendered pages at their rewritten (localized) URLs.
10
+ * 4. Emitting the prerendered pages at their rewritten (localized) URLs.
11
+ *
12
+ * The dev-time content watcher is not started here: the bundled
13
+ * `vite-intlayer` plugin already starts one from `configureServer`, and
14
+ * `watch()` subscribes anew on every call, so doing both would rebuild each
15
+ * content edit twice.
12
16
  *
13
17
  * @returns An Astro integration object.
14
18
  *
@@ -23,7 +27,7 @@ import { AstroIntegration } from "astro";
23
27
  * });
24
28
  * ```
25
29
  */
26
- declare const intlayer: () => AstroIntegration;
30
+ export declare const intlayer: () => AstroIntegration;
27
31
  //#endregion
28
- export { intlayer as default, intlayer };
32
+ export { intlayer as default };
29
33
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;cAoCa,gBAAe"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAsDa,gBAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-intlayer",
3
- "version": "9.4.3",
3
+ "version": "9.5.0",
4
4
  "private": false,
5
5
  "description": "Easily internationalize i18n your Astro applications with type-safe multilingual content management.",
6
6
  "keywords": [
@@ -78,22 +78,22 @@
78
78
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
79
79
  },
80
80
  "dependencies": {
81
- "@intlayer/config": "9.4.3",
82
- "@intlayer/core": "9.4.3",
83
- "@intlayer/engine": "9.4.3",
84
- "@intlayer/types": "9.4.3",
85
- "vite-intlayer": "9.4.3"
81
+ "@intlayer/config": "9.5.0",
82
+ "@intlayer/core": "9.5.0",
83
+ "@intlayer/engine": "9.5.0",
84
+ "@intlayer/types": "9.5.0",
85
+ "vite-intlayer": "9.5.0"
86
86
  },
87
87
  "devDependencies": {
88
- "@types/node": "26.4.1",
88
+ "@types/node": "26.5.0",
89
89
  "@utils/ts-config": "1.0.4",
90
90
  "@utils/ts-config-types": "1.0.4",
91
91
  "@utils/tsdown-config": "1.0.4",
92
92
  "fast-glob": "3.3.3",
93
93
  "rimraf": "6.1.3",
94
- "tsdown": "0.22.14",
94
+ "tsdown": "0.23.0",
95
95
  "typescript": "7.0.2",
96
- "vitest": "4.1.11"
96
+ "vitest": "5.0.0"
97
97
  },
98
98
  "peerDependencies": {
99
99
  "astro": ">=4.0.0",