mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 02:00:44 +00:00
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import path from "node:path";
|
|
|
|
export function isTypeScriptPackageEntry(entryPath: string): boolean {
|
|
return [".ts", ".mts", ".cts"].includes(path.extname(entryPath).toLowerCase());
|
|
}
|
|
|
|
export function listBuiltRuntimeEntryCandidates(entryPath: string): string[] {
|
|
if (!isTypeScriptPackageEntry(entryPath)) {
|
|
return [];
|
|
}
|
|
const normalized = entryPath.replace(/\\/g, "/");
|
|
const withoutExtension = normalized.replace(/\.[^.]+$/u, "");
|
|
const normalizedRelative = normalized.replace(/^\.\//u, "");
|
|
const distWithoutExtension = normalizedRelative.startsWith("src/")
|
|
? `./dist/${normalizedRelative.slice("src/".length).replace(/\.[^.]+$/u, "")}`
|
|
: `./dist/${withoutExtension.replace(/^\.\//u, "")}`;
|
|
const withJavaScriptExtensions = (basePath: string) => [
|
|
`${basePath}.js`,
|
|
`${basePath}.mjs`,
|
|
`${basePath}.cjs`,
|
|
];
|
|
const candidates = [
|
|
...withJavaScriptExtensions(distWithoutExtension),
|
|
...withJavaScriptExtensions(withoutExtension),
|
|
];
|
|
return [...new Set(candidates)].filter((candidate) => candidate !== normalized);
|
|
}
|