fix(faith): locate romcal root by walking up from main entry

romcal's package.json is not listed in its exports map, so
require.resolve('romcal/package.json') throws ERR_PACKAGE_PATH_NOT_EXPORTED
under Node's strict exports enforcement. Resolve the main entry instead
and walk up until we find the package.json belonging to romcal itself.
This commit is contained in:
2026-04-20 16:49:39 +02:00
parent f447520aaa
commit 3aa8f38f92
2 changed files with 22 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "homepage", "name": "homepage",
"version": "1.36.1", "version": "1.36.2",
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {
+21 -1
View File
@@ -25,6 +25,7 @@ import type { LiturgicalDay1962, RomcalBundle1962 } from 'romcal/1962';
import { pathToFileURL } from 'node:url'; import { pathToFileURL } from 'node:url';
import { dirname, join as joinPath } from 'node:path'; import { dirname, join as joinPath } from 'node:path';
import { createRequire } from 'node:module'; import { createRequire } from 'node:module';
import { existsSync, readFileSync } from 'node:fs';
import { import {
colorLabel1962, colorLabel1962,
rank1962Label, rank1962Label,
@@ -40,8 +41,27 @@ import type {
Rite1962Detail Rite1962Detail
} from '../calendarTypes'; } from '../calendarTypes';
// romcal's package.json isn't exposed via its exports map, so resolve the
// main entry instead and walk up until we hit the package root.
const requireFromHere = createRequire(import.meta.url); const requireFromHere = createRequire(import.meta.url);
const romcalRoot = dirname(requireFromHere.resolve('romcal/package.json')); function findRomcalRoot(): string {
let dir = dirname(requireFromHere.resolve('romcal'));
while (true) {
const pkgPath = joinPath(dir, 'package.json');
if (existsSync(pkgPath)) {
try {
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { name?: string };
if (pkg.name === 'romcal') return dir;
} catch {
// fall through and keep walking
}
}
const parent = dirname(dir);
if (parent === dir) throw new Error('Could not locate romcal package root');
dir = parent;
}
}
const romcalRoot = findRomcalRoot();
const bundles1969: Record<Diocese1969, Record<CalendarLang, RomcalBundleObject>> = { const bundles1969: Record<Diocese1969, Record<CalendarLang, RomcalBundleObject>> = {
general: { en: GeneralRoman_En, de: GeneralRoman_De, la: GeneralRoman_La }, general: { en: GeneralRoman_En, de: GeneralRoman_De, la: GeneralRoman_La },