mirror of
https://github.com/backnotprop/plannotator.git
synced 2026-09-14 14:17:26 +08:00
929e8f9f59
The Pi extension is distributed and executed as raw TypeScript through Pi's jiti loader. Phantom .js paths force jiti through its last-resort fallback, while extensionless paths still require probing. Exact .ts paths avoid both and match the files that actually ship. - rewrite relative .js and extensionless specifiers in hand-written sources (the existing noEmit bundler tsconfig permits .ts imports) - make vendor.sh emit .ts in explicit rewrite rules and normalize both source styles across verbatim-copied generated modules - guard hand-written and generated sources against either inexact form Extension module import: 43.5ms -> 15ms median (PI_TIMING, n=12 interleaved). bun test: 73/73 (pi-extension), 456/456 (server); all seven TypeScript project checks and the packed-artifact audit pass. Co-authored-by: dca123 <dca123@users.noreply.github.com> Co-authored-by: Michael Ramos <mdramos8@gmail.com>
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
/**
|
|
* Project detection — repo info, project name, remote URL parsing.
|
|
* detectProjectName, getRepoInfo, parseRemoteUrl
|
|
*/
|
|
|
|
import { execSync } from "node:child_process";
|
|
import { basename } from "node:path";
|
|
import { sanitizeTag } from "../generated/project.ts";
|
|
import { parseRemoteUrl, getDirName } from "../generated/repo.ts";
|
|
|
|
/** Run a git command and return stdout (empty string on error). */
|
|
function git(cmd: string): string {
|
|
try {
|
|
return execSync(`git ${cmd}`, {
|
|
encoding: "utf-8",
|
|
stdio: ["pipe", "pipe", "pipe"],
|
|
}).trim();
|
|
} catch {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
export function detectProjectName(): string {
|
|
try {
|
|
const toplevel = execSync("git rev-parse --show-toplevel", {
|
|
encoding: "utf-8",
|
|
stdio: ["pipe", "pipe", "pipe"],
|
|
}).trim();
|
|
const name = basename(toplevel);
|
|
return sanitizeTag(name) ?? "_unknown";
|
|
} catch {
|
|
// Not a git repo — fall back to cwd
|
|
}
|
|
try {
|
|
const name = basename(process.cwd());
|
|
return sanitizeTag(name) ?? "_unknown";
|
|
} catch {
|
|
return "_unknown";
|
|
}
|
|
}
|
|
|
|
export function getRepoInfo(): { display: string; branch?: string } | null {
|
|
const branch = git("rev-parse --abbrev-ref HEAD");
|
|
const safeBranch = branch && branch !== "HEAD" ? branch : undefined;
|
|
|
|
const originUrl = git("remote get-url origin");
|
|
const orgRepo = parseRemoteUrl(originUrl);
|
|
if (orgRepo) {
|
|
return { display: orgRepo, branch: safeBranch };
|
|
}
|
|
|
|
const topLevel = git("rev-parse --show-toplevel");
|
|
const repoName = getDirName(topLevel);
|
|
if (repoName) {
|
|
return { display: repoName, branch: safeBranch };
|
|
}
|
|
|
|
const cwdName = getDirName(process.cwd());
|
|
if (cwdName) {
|
|
return { display: cwdName };
|
|
}
|
|
|
|
return null;
|
|
}
|