chore(vendor): import pi 0.85.1
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree. git-subtree-dir: third_party/pi git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
This commit is contained in:
31
third_party/pi/packages/tui/src/native-module-path.ts
vendored
Normal file
31
third_party/pi/packages/tui/src/native-module-path.ts
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { createRequire } from "node:module";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const moduleRequire = createRequire(import.meta.url);
|
||||
const TUI_PACKAGE_NAME = "@earendil-works/pi-tui";
|
||||
|
||||
export interface NativeModuleCandidateOptions {
|
||||
moduleUrl?: string;
|
||||
execPath?: string;
|
||||
resolvePackage?: (specifier: string) => string;
|
||||
}
|
||||
|
||||
export function getNativeModuleCandidates(nativePath: string, options: NativeModuleCandidateOptions = {}): string[] {
|
||||
const moduleDir = dirname(fileURLToPath(options.moduleUrl ?? import.meta.url));
|
||||
const candidates: string[] = [];
|
||||
|
||||
try {
|
||||
const packageEntry = (options.resolvePackage ?? moduleRequire.resolve)(TUI_PACKAGE_NAME);
|
||||
candidates.push(join(dirname(packageEntry), "..", nativePath));
|
||||
} catch {
|
||||
// Standalone binaries do not have an installed TUI package.
|
||||
}
|
||||
|
||||
candidates.push(
|
||||
join(moduleDir, "..", nativePath),
|
||||
join(moduleDir, nativePath),
|
||||
join(dirname(options.execPath ?? process.execPath), nativePath),
|
||||
);
|
||||
return Array.from(new Set(candidates));
|
||||
}
|
||||
Reference in New Issue
Block a user