From d91fd70cf27516516e75ff4b968ed0c65ff151ac Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Thu, 5 Dec 2024 16:15:44 +0100 Subject: [PATCH] feat: support astro 5 (#43) --- .changeset/four-parrots-leave.md | 5 ++++ .changeset/new-bugs-learn.md | 5 ++++ README.md | 3 ++ demo/package.json | 2 +- docs/package.json | 2 +- docs/src/content/config.ts | 12 +++++++- .../docs/getting-started/installation.mdx | 2 +- docs/src/style.css | 4 ++- package/README.md | 3 ++ package/package.json | 2 +- package/src/i18next/index.ts | 14 ++++++++-- package/src/i18next/types.ts | 25 ----------------- package/src/integration.ts | 28 +++++++++++++------ playground/package.json | 2 +- pnpm-lock.yaml | 25 ++++++++++++++--- 15 files changed, 88 insertions(+), 46 deletions(-) create mode 100644 .changeset/four-parrots-leave.md create mode 100644 .changeset/new-bugs-learn.md delete mode 100644 package/src/i18next/types.ts diff --git a/.changeset/four-parrots-leave.md b/.changeset/four-parrots-leave.md new file mode 100644 index 0000000..f278648 --- /dev/null +++ b/.changeset/four-parrots-leave.md @@ -0,0 +1,5 @@ +--- +"@astrolicious/i18n": minor +--- + +Bumps peer dependencies to support Astro 5. In order to use the integration with Astro 4, you now need to use at least `4.14.0` diff --git a/.changeset/new-bugs-learn.md b/.changeset/new-bugs-learn.md new file mode 100644 index 0000000..f7fc890 --- /dev/null +++ b/.changeset/new-bugs-learn.md @@ -0,0 +1,5 @@ +--- +"@astrolicious/i18n": patch +--- + +Fixes an issue with type generation when a project does not have a `src/env.d.ts` file diff --git a/README.md b/README.md index dff11b2..05801b4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +> [!WARNING] +> This integration is unmaintained due to lack of time. It should mostly work but do not expect fixes or new features. + # @astrolicious/i18n Yet another i18n integration for [Astro](https://astro.build/) with server and client utilities, type safety and translations built-in. diff --git a/demo/package.json b/demo/package.json index 024d287..27b84c4 100644 --- a/demo/package.json +++ b/demo/package.json @@ -19,7 +19,7 @@ "@tailwindcss/forms": "^0.5.7", "@types/react": "^18.3.1", "@types/react-dom": "^18.3.0", - "astro": "^4.7.0", + "astro": "^4.14.0", "i18next": "^23.11.3", "react": "^18.3.1", "react-dom": "^18.3.1", diff --git a/docs/package.json b/docs/package.json index 165f51b..65f27d9 100644 --- a/docs/package.json +++ b/docs/package.json @@ -16,7 +16,7 @@ "@astrojs/starlight-tailwind": "^2.0.2", "@astrojs/tailwind": "^5.1.0", "@expressive-code/plugin-line-numbers": "^0.33.5", - "astro": "^4.7.0", + "astro": "^4.14.0", "sharp": "^0.33.3", "tailwind": "^4.0.0", "tailwindcss": "^3.4.3", diff --git a/docs/src/content/config.ts b/docs/src/content/config.ts index d8d945f..3fddaef 100644 --- a/docs/src/content/config.ts +++ b/docs/src/content/config.ts @@ -1,6 +1,16 @@ import { defineCollection } from "astro:content"; import { docsSchema } from "@astrojs/starlight/schema"; +import { z } from "astro/zod"; export const collections = { - docs: defineCollection({ schema: docsSchema() }), + docs: defineCollection({ + schema: docsSchema({ + extend: z.object({ + // Add a default value to the built-in `banner` field. + banner: z.object({ content: z.string() }).default({ + content: "This integration is unmaintained due to lack of time. It should mostly work but do not expect fixes or new features.", + }), + }), + }), + }), }; diff --git a/docs/src/content/docs/getting-started/installation.mdx b/docs/src/content/docs/getting-started/installation.mdx index 321ced7..230a2fa 100644 --- a/docs/src/content/docs/getting-started/installation.mdx +++ b/docs/src/content/docs/getting-started/installation.mdx @@ -5,7 +5,7 @@ title: Installation import { Tabs, TabItem } from '@astrojs/starlight/components'; :::caution[Prerequisites] -- `astro` must be at least on version `4.12.0` +- `astro` must be at least on version `4.14.0` or `5.0.0` - `tsconfig.json` `compilerOptions.strict` should be set to `true`. If you're using Astro tsconfig presets, use either `astro/tsconfigs/strict` or `astro/tsconfigs/strictest` ::: diff --git a/docs/src/style.css b/docs/src/style.css index ac189ce..5fbfeee 100644 --- a/docs/src/style.css +++ b/docs/src/style.css @@ -13,4 +13,6 @@ :root { --sl-font-system-mono: 'JetBrains Mono Variable', monospace; -} \ No newline at end of file + --sl-color-banner-bg: var(--sl-color-orange); + --sl-color-banner-text: #000; +} diff --git a/package/README.md b/package/README.md index 5a23a13..b25ead2 100644 --- a/package/README.md +++ b/package/README.md @@ -1,3 +1,6 @@ +> [!WARNING] +> This integration is unmaintained due to lack of time. It should mostly work but do not expect fixes or new features. + # `@astrolicious/i18n` This is yet another i18n integration for [Astro](https://astro.build/) with server and client utilities, type safety and translations built-in. diff --git a/package/package.json b/package/package.json index 97ec110..d51af8f 100644 --- a/package/package.json +++ b/package/package.json @@ -48,7 +48,7 @@ }, "type": "module", "peerDependencies": { - "astro": "^4.12.0", + "astro": "^4.14.0 || ^5.0.0", "i18next": "^23.0.0" }, "dependencies": { diff --git a/package/src/i18next/index.ts b/package/src/i18next/index.ts index 723c44c..2ac22c8 100644 --- a/package/src/i18next/index.ts +++ b/package/src/i18next/index.ts @@ -5,7 +5,6 @@ import { normalizePath } from "vite"; import type { Options } from "../options.js"; import { getNamespaces } from "./namespaces.js"; import { getResources } from "./resources.js"; -import { injectTypes } from "./types.js"; const getPaths = (root: URL, options: Options) => { const localesDir = normalizePath( @@ -39,11 +38,22 @@ export const handleI18next = defineUtility("astro:config:setup")( logger, ); const resources = getResources(logger, options, paths.localesDir); - injectTypes(params, options, resources[options.defaultLocale] ?? {}); + const dtsContent = ` + type Resources = ${JSON.stringify(resources[options.defaultLocale] ?? {})} + + declare module "i18next" { + interface CustomTypeOptions { + defaultNS: "${options.defaultNamespace}"; + resources: Resources; + } + } + export {} + `; return { namespaces, resources, + dtsContent, }; }, ); diff --git a/package/src/i18next/types.ts b/package/src/i18next/types.ts deleted file mode 100644 index d4f9ed1..0000000 --- a/package/src/i18next/types.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { addDts, defineUtility } from "astro-integration-kit"; -import type { Options } from "../options.js"; -import type { I18nextConfig } from "../types.js"; - -export const injectTypes = defineUtility("astro:config:setup")( - ( - params, - { defaultNamespace }: Options, - resources: I18nextConfig["resources"][string], - ) => { - const content = ` - type Resources = ${JSON.stringify(resources)} - - declare module "i18next" { - interface CustomTypeOptions { - defaultNS: "${defaultNamespace}"; - resources: Resources; - } - } - export {} - `; - - addDts(params, { name: "i18next", content }); - }, -); diff --git a/package/src/integration.ts b/package/src/integration.ts index 1e6a619..ba403c7 100644 --- a/package/src/integration.ts +++ b/package/src/integration.ts @@ -1,6 +1,5 @@ import { readFileSync } from "node:fs"; import { - addDts, addIntegration, addVirtualImports, createResolver, @@ -20,13 +19,21 @@ export const integration = defineIntegration({ setup({ options, name }) { const { resolve } = createResolver(import.meta.url); + let dtsContent: string; + let i18nextDtsContent: string; + return { hooks: { "astro:config:setup": (params) => { const { addMiddleware, logger, updateConfig } = params; const { routes } = handleRouting(params, options); - const { namespaces, resources } = handleI18next(params, options); + const { + namespaces, + resources, + dtsContent: _dtsContent, + } = handleI18next(params, options); + i18nextDtsContent = _dtsContent; addMiddleware({ entrypoint: resolve("../assets/middleware.ts"), @@ -48,7 +55,7 @@ export const integration = defineIntegration({ locales: '"@@_LOCALES_@@"', }; - let dtsContent = virtualTypesStub + dtsContent = virtualTypesStub .replace(typesPlaceholders.id, VIRTUAL_MODULE_ID) .replace( typesPlaceholders.locale, @@ -98,11 +105,6 @@ export const integration = defineIntegration({ dtsContent += virtualSitemapTypesStub; } - addDts(params, { - name: "astro-i18n", - content: dtsContent, - }); - const enabledClientFeatures = Object.entries(options.client) .map(([name, enabled]) => ({ name, enabled })) .filter((e) => e.enabled); @@ -197,6 +199,16 @@ export const integration = defineIntegration({ }); } }, + "astro:config:done": (params) => { + params.injectTypes({ + filename: "astro-i18n.d.ts", + content: dtsContent, + }); + params.injectTypes({ + filename: "i18next.d.ts", + content: i18nextDtsContent, + }); + }, }, }; }, diff --git a/playground/package.json b/playground/package.json index 67d9874..79c685f 100644 --- a/playground/package.json +++ b/playground/package.json @@ -18,7 +18,7 @@ "@astrolicious/i18n": "workspace:*", "@types/react": "^18.3.1", "@types/react-dom": "^18.3.0", - "astro": "^4.12.0", + "astro": "^4.14.0", "i18next": "^23.11.3", "react": "^18.2.0", "react-dom": "^18.3.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e43f7a0..155490d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -42,7 +42,7 @@ importers: specifier: ^18.3.0 version: 18.3.0 astro: - specifier: ^4.7.0 + specifier: ^4.14.0 version: 4.14.5(@types/node@20.12.7)(rollup@4.21.0)(typescript@5.4.5) i18next: specifier: ^23.11.3 @@ -78,7 +78,7 @@ importers: specifier: ^0.33.5 version: 0.33.5 astro: - specifier: ^4.7.0 + specifier: ^4.14.0 version: 4.14.5(@types/node@20.12.7)(rollup@4.21.0)(typescript@5.4.5) sharp: specifier: ^0.33.3 @@ -99,7 +99,7 @@ importers: specifier: ^0.7.1 version: 0.7.1(@types/node@20.12.7)(astro-integration-kit@0.16.1(astro@4.14.5(@types/node@20.12.7)(rollup@4.21.0)(typescript@5.4.5)))(astro@4.14.5(@types/node@20.12.7)(rollup@4.21.0)(typescript@5.4.5)) astro: - specifier: ^4.12.0 + specifier: ^4.14.0 || ^5.0.0 version: 4.14.5(@types/node@20.12.7)(rollup@4.21.0)(typescript@5.4.5) astro-integration-kit: specifier: ^0.16.1 @@ -154,7 +154,7 @@ importers: specifier: ^18.3.0 version: 18.3.0 astro: - specifier: ^4.12.0 + specifier: ^4.14.0 version: 4.14.5(@types/node@20.12.7)(rollup@4.21.0)(typescript@5.4.5) i18next: specifier: ^23.11.3 @@ -1605,12 +1605,14 @@ packages: commands-events@1.0.4: resolution: {integrity: sha512-HdP/+1Anoc7z+6L2h7nd4Imz54+LW+BjMGt30riBZrZ3ZeP/8el93wD8Jj8ltAaqVslqNgjX6qlhSBJwuDSmpg==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. common-ancestor-path@1.0.1: resolution: {integrity: sha512-L3sHRo1pXXEqX8VU28kfgUY+YGsk09hPqZiZmLacNib6XNTCM8ubYeT7ryXQw8asB1sKgcU5lkB7ONug08aB8w==} comparejs@1.0.0: resolution: {integrity: sha512-Ue/Zd9aOucHzHXwaCe4yeHR7jypp7TKrIBZ5yls35nPNiVXlW14npmNVKM1ZaLlQTKZ6/4ewA//gYKHHIwCpOw==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. compressible@2.0.18: resolution: {integrity: sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==} @@ -1662,6 +1664,7 @@ packages: crypto2@2.0.0: resolution: {integrity: sha512-jdXdAgdILldLOF53md25FiQ6ybj2kUFTiRjs7msKTUoZrzgT/M1FPX5dYGJjbbwFls+RJIiZxNTC02DE/8y0ZQ==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. css-selector-parser@3.0.5: resolution: {integrity: sha512-3itoDFbKUNx1eKmVpYMFyqKX04Ww9osZ+dLgrk6GEv6KMVeXUhUnp4I5X+evw+u3ZxVU6RFXSSRxlTeMh8bA+g==} @@ -1701,6 +1704,7 @@ packages: datasette@1.0.1: resolution: {integrity: sha512-aJdlCBToEJUP4M57r67r4V6tltwGKa3qetnjpBtXYIlqbX9tM9jsoDMxb4xd9AGjpp3282oHRmqI5Z8TVAU0Mg==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. debug@2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} @@ -1798,6 +1802,7 @@ packages: draht@1.0.1: resolution: {integrity: sha512-yNNHL864dniNmIE9ZKD++mKypiAUAvVZtyV0QrbXH/ak3ebzFqo5xsmRBRqV8pZVhImOSBiyq500Wcmrf44zAg==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. dset@3.1.3: resolution: {integrity: sha512-20TuZZHCEZ2O71q9/+8BwKwZ0QtD9D8ObhrihJPr+vLLYlSuAU3/zL4cSlgbfeoGHTjCSJBa7NGcrF9/Bx/WJQ==} @@ -2006,6 +2011,7 @@ packages: flaschenpost@1.1.3: resolution: {integrity: sha512-1VAYPvDsVBGFJyUrOa/6clnJwZYC3qVq9nJLcypy6lvaaNbo1wOQiH8HQ+4Fw/k51pVG7JHzSf5epb8lmIW86g==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. hasBin: true flattie@1.1.1: @@ -2021,6 +2027,7 @@ packages: formats@1.0.0: resolution: {integrity: sha512-For0Y8egwEK96JgJo4NONErPhtl7H2QzeB2NYGmzeGeJ8a1JZqPgLYOtM3oJRCYhmgsdDFd6KGRYyfe37XY4Yg==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. forwarded@0.2.0: resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==} @@ -2160,6 +2167,7 @@ packages: hase@2.0.0: resolution: {integrity: sha512-L83pBR/oZvQQNjv4kw9aUpTqBxERPiY7B42jsmkt1VDeUaRVhYkEIKzkCqrppjtxHe2EZqzZJzuhMXsWsxYIsw==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. hasown@2.0.2: resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==} @@ -2510,6 +2518,7 @@ packages: json-lines@1.0.0: resolution: {integrity: sha512-ytuLZb4RBQb3bTRsG/QBenyIo5oHLpjeCVph3s2NnoAsZE9K6h+uR+OWpEOWV1UeHdX63tYctGppBpGAc+JNMA==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. json-parse-even-better-errors@2.3.1: resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==} @@ -2560,6 +2569,7 @@ packages: limes@2.0.0: resolution: {integrity: sha512-evWD0pnTgPX7QueaSoJl5JBUL30T1ZVzo34ke97tIKmeagqhBTYK/JkKL0vtG3MpNApw8ZY9TlbybfwEz9knBA==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} @@ -3099,6 +3109,7 @@ packages: partof@1.0.0: resolution: {integrity: sha512-+TXdhKCySpJDynCxgAPoGVyAkiK3QPusQ63/BdU5t68QcYzyU6zkP/T7F3gkMQBVUYqdWEADKa6Kx5zg8QIKrg==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. path-browserify@1.0.1: resolution: {integrity: sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==} @@ -3225,6 +3236,7 @@ packages: processenv@1.1.0: resolution: {integrity: sha512-SymqIsn8GjEUy8nG7HiyEjgbfk1xFosRIakUX1NHLpriq3vVpKniGrr9RdMWCaGYWByIovbRt2f/WvmP/IOApQ==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. prompts@2.4.2: resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} @@ -3616,6 +3628,7 @@ packages: stethoskop@1.0.0: resolution: {integrity: sha512-4JnZ+UmTs9SFfDjSHFlD/EoXcb1bfwntkt4h1ipNGrpxtRzmHTxOmdquCJvIrVu608Um7a09cGX0ZSOSllWJNQ==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. stream-replace-string@2.0.0: resolution: {integrity: sha512-TlnjJ1C0QrmxRNrON00JvaFFlNh5TTG00APw23j74ET7gkQpTASi6/L2fuiav8pzK715HXtUeClpBTw2NPSn6w==} @@ -3712,6 +3725,7 @@ packages: tailwind@4.0.0: resolution: {integrity: sha512-LlUNoD/5maFG1h5kQ6/hXfFPdcnYw+1Z7z+kUD/W/E71CUMwcnrskxiBM8c3G8wmPsD1VvCuqGYMHviI8+yrmg==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. tailwindcss@3.4.3: resolution: {integrity: sha512-U7sxQk/n397Bmx4JHbJx/iSOOv5G+II3f1kpLpY2QeUv5DcPdcTsYLlusZfq1NthHS1c1cZoyFmmkex1rzke0A==} @@ -3731,6 +3745,7 @@ packages: timer2@1.0.0: resolution: {integrity: sha512-UOZql+P2ET0da+B7V3/RImN3IhC5ghb+9cpecfUhmYGIm0z73dDr3A781nBLnFYmRzeT1AmoT4w9Lgr8n7n7xg==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. tiny-invariant@1.3.3: resolution: {integrity: sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==} @@ -3972,9 +3987,11 @@ packages: uuidv4@2.0.0: resolution: {integrity: sha512-sAUlwUVepcVk6bwnaW/oi6LCwMdueako5QQzRr90ioAVVcms6p1mV0PaSxK8gyAC4CRvKddsk217uUpZUbKd2Q==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. uuidv4@3.0.1: resolution: {integrity: sha512-PPzksdWRl2a5C9hrs3OOYrArTeyoR0ftJ3jtOy+BnVHkT2UlrrzPNt9nTdiGuxmQItHM/AcTXahwZZC57Njojg==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. validate-npm-package-license@3.0.4: resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==}