fix(website): inject the fallback version instead of importing package.json

`website:lint` failed on master since the per-OS download pages landed:
`src/lib/downloads.ts` imported the workspace root `package.json` through a
relative path, which `@nx/enforce-module-boundaries` rejects ("external
resources cannot be imported using a relative or absolute path").

The value is only needed as a build-time constant for the offline fallback,
so `astro.config.mjs` now reads the root manifest through the file system
and injects `__IPTVNATOR_VERSION__` via Vite `define`; `downloads.ts` uses
that constant and `src/env.d.ts` declares its type. Verified with
`WEBSITE_SKIP_RELEASE_FETCH=1`: the built download pages link the
`iptvnator-<version>` assets and no define literal leaks into the output.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
4grayandClaude Fable 5.1 committed 2026-09-03 21:47:01 +02:00
1 parent 2fc1bd5601
commit 70fff19977
3 files changed
+32 -3

No files matched your search

+18
View File
@@ -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),
},
},
});
+8
View File
@@ -0,0 +1,8 @@
/// <reference types="astro/client" />
/**
* 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;
+6 -3
View File
@@ -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}.`);
}