diff --git a/apps/website/astro.config.mjs b/apps/website/astro.config.mjs index 5e746c928..c89e7d4cc 100644 --- a/apps/website/astro.config.mjs +++ b/apps/website/astro.config.mjs @@ -1,8 +1,21 @@ // @ts-check +import { readFileSync } from 'node:fs'; import { defineConfig } from 'astro/config'; import sitemap from '@astrojs/sitemap'; import mdx from '@astrojs/mdx'; +/** + * Repository version for the download pages' offline fallback + * (`src/lib/downloads.ts`). Read from the workspace root through the file + * system and injected as a build-time constant: importing the root + * `package.json` from inside the project trips the Nx module-boundaries rule + * ("external resources cannot be imported using a relative path"), and a + * value fixed at build time is what the fallback needs anyway. + */ +const { version } = JSON.parse( + readFileSync(new URL('../../package.json', import.meta.url), 'utf8'), +); + // Tailwind (v3) is applied via apps/website/postcss.config.mjs — the // @astrojs/tailwind integration only supports Astro <= 5. // https://astro.build/config @@ -11,4 +24,9 @@ export default defineConfig({ base: '/iptvnator', outDir: '../../dist/apps/website', integrations: [sitemap(), mdx()], + vite: { + define: { + __IPTVNATOR_VERSION__: JSON.stringify(version), + }, + }, }); diff --git a/apps/website/src/env.d.ts b/apps/website/src/env.d.ts new file mode 100644 index 000000000..ee4d25b10 --- /dev/null +++ b/apps/website/src/env.d.ts @@ -0,0 +1,8 @@ +/// + +/** + * Repository version from the workspace root `package.json`, injected at + * build time by `astro.config.mjs` through Vite `define`. Used by the download + * pages' offline fallback (`src/lib/downloads.ts`). + */ +declare const __IPTVNATOR_VERSION__: string; diff --git a/apps/website/src/lib/downloads.ts b/apps/website/src/lib/downloads.ts index d3607da59..09997587b 100644 --- a/apps/website/src/lib/downloads.ts +++ b/apps/website/src/lib/downloads.ts @@ -1,4 +1,3 @@ -import rootPackage from '../../../../package.json'; import type { DownloadPlatform } from './platforms'; /** @@ -9,9 +8,13 @@ import type { DownloadPlatform } from './platforms'; * exists, and so file sizes and the publish date can be shown. When the API * is unreachable (offline build, rate limit, `WEBSITE_SKIP_RELEASE_FETCH=1`) * the pages fall back to the repository version from the root `package.json` + * — injected as `__IPTVNATOR_VERSION__` by `astro.config.mjs`, since a + * relative import of the root manifest violates the Nx module boundaries — * and the known asset naming pattern from `electron-builder.json`. */ +const FALLBACK_VERSION = __IPTVNATOR_VERSION__; + export const GITHUB_REPO = '4gray/iptvnator'; export const REPO_URL = `https://github.com/${GITHUB_REPO}`; export const RELEASES_URL = `${REPO_URL}/releases`; @@ -304,7 +307,7 @@ function normalizeAsset(value: unknown): ReleaseAsset[] { } function fallbackRelease(): ResolvedRelease { - const version = rootPackage.version; + const version = FALLBACK_VERSION; const tag = `v${version}`; const assets = Object.values(DOWNLOAD_OPTIONS) .flat() @@ -323,5 +326,5 @@ function fallbackRelease(): ResolvedRelease { } function warnFallback(reason: string): void { - console.warn(`[website] Latest release lookup failed (${reason}); using package.json version ${rootPackage.version}.`); + console.warn(`[website] Latest release lookup failed (${reason}); using package.json version ${FALLBACK_VERSION}.`); }