{"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"],"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"}