fix(v1.9.2): subsetCache 改用 Date.now() 启动时戳,修复 LLRT process.uptime 报错

process.uptime() 在 LLRT 运行时不存在(typeof === "undefined"),调用抛
TypeError: not a function,导致容器启动即崩溃(v1.9.1 修完 __filename 后暴露)。

改用模块加载时取一次 Date.now():Node/LLRT 均可用,进程重启即变化,
开发态「重启即重置内存缓存」语义不变,生产态靠 PACKAGE_VERSION。

另增 dev:backend:llrt / serve:llrt 本地命令,用 LLRT 跑后端提前暴露兼容问题。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
崮生(子虚) 2026-06-13 21:32:33 +08:00
parent 8db337d27e
commit 7d0243e6f5
2 changed files with 15 additions and 7 deletions

View File

@ -2,20 +2,26 @@ import { fontSubset } from "../font_util/font";
import type { FontEditor } from "../../vendor/fonteditor-core/lib/ttf/font.js";
import { parseUrl, jsonResponse, stats, subsetCache, findFontPath, readFontBuffer } from "../shared";
/**
*
*
* Date.now() process.uptime() LLRT typeof === "undefined"
* TypeError: not a function
* Date.now() Node LLRT
*/
declare const PACKAGE_VERSION: string;
/** 进程启动时刻,重启进程即变化 —— 用于开发态「重启即重置内存缓存」 */
const PROCESS_START_TIME = Date.now();
/**
*
*
* subsetCache key
* - bump package.json version tsdown define
* - pnpm dev process.uptime()
* - pnpm dev PROCESS_START_TIME
*
*
*
* createRequire(import.meta.url) package.json tsdown CJS
* __filename LLRT __filename ReferenceError
*/
declare const PACKAGE_VERSION: string;
const SUBSET_CACHE_KEY = `${PACKAGE_VERSION}:${process.uptime()}`;
const SUBSET_CACHE_KEY = `${PACKAGE_VERSION}:${PROCESS_START_TIME}`;
/** GET /api?font=...&text=... — 字体裁剪 */
export async function handleFontSubset(req: Request, res: Response) {

View File

@ -1,12 +1,14 @@
{
"name": "webfont",
"private": true,
"version": "1.9.1",
"version": "1.9.2",
"type": "module",
"scripts": {
"dev": "pnpx tsx scripts/dev-all.ts",
"dev:frontend": "vite",
"dev:backend": "pnpx tsx backend/app.ts",
"dev:backend:llrt": "pnpm build_backend && ./llrt ./dist_backend/app.cjs",
"serve:llrt": "./llrt ./dist_backend/app.cjs",
"build": "vite build",
"build_backend": "pnpx tsx scripts/build-backend.ts",
"docker_build": "docker build -t llej0/web-font:${npm_package_version} -t llej0/web-font:latest .",