Use npm packages for shared skill code (#136)

This commit is contained in:
Jim Liu 宝玉
2026-04-18 21:09:58 -05:00
committed by GitHub
parent 9977ff520c
commit 5b20f9a746
401 changed files with 157775 additions and 24357 deletions
+21 -1
View File
@@ -4,7 +4,27 @@ import { fileURLToPath } from "node:url";
import type { StyleConfig, HtmlDocumentMeta } from "./types.js";
import { DEFAULT_STYLE } from "./constants.js";
const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
function resolveCommonJsDir(): string | undefined {
try {
const value = eval(
"typeof module === 'object' && module && module.exports && typeof __dirname === 'string' ? __dirname : undefined",
);
return typeof value === "string" ? value : undefined;
} catch {
return undefined;
}
}
function resolveModuleDir(metaUrl?: string): string {
const commonJsDir = resolveCommonJsDir();
if (commonJsDir) return commonJsDir;
if (!metaUrl) {
throw new Error("Unable to resolve module directory.");
}
return path.dirname(fileURLToPath(metaUrl));
}
const SCRIPT_DIR = resolveModuleDir(import.meta.url);
const CODE_THEMES_DIR = path.resolve(SCRIPT_DIR, "code-themes");
export function buildCss(baseCss: string, themeCss: string, style: StyleConfig = DEFAULT_STYLE): string {
+21 -1
View File
@@ -3,7 +3,27 @@ import path from "node:path";
import { fileURLToPath } from "node:url";
import type { ThemeName } from "./types.js";
const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
function resolveCommonJsDir(): string | undefined {
try {
const value = eval(
"typeof module === 'object' && module && module.exports && typeof __dirname === 'string' ? __dirname : undefined",
);
return typeof value === "string" ? value : undefined;
} catch {
return undefined;
}
}
function resolveModuleDir(metaUrl?: string): string {
const commonJsDir = resolveCommonJsDir();
if (commonJsDir) return commonJsDir;
if (!metaUrl) {
throw new Error("Unable to resolve module directory.");
}
return path.dirname(fileURLToPath(metaUrl));
}
const SCRIPT_DIR = resolveModuleDir(import.meta.url);
export const THEME_DIR = path.resolve(SCRIPT_DIR, "themes");
const FALLBACK_THEMES: ThemeName[] = ["default", "grace", "simple"];
const THEMES_EXTENDING_DEFAULT = new Set<ThemeName>(["grace", "simple"]);