UNPKG

pi-lens

Version:

Real-time code feedback for pi — LSP, linters, formatters, type-checking, structural analysis & booboo

23 lines (22 loc) • 906 B
/** * Centralized LAZY accessor for `@ast-grep/napi` (a native addon — loaded on * demand, never at module-eval). See ./typescript.ts for the rationale. * Types are re-exported; the module itself is fetched via `loadAstGrepNapi()`. * * Resolved to an absolute `file://` URL via `createRequire` before importing: an * absolute-path dynamic import works under pi's bundled host, a bare specifier * does not. The path is converted to a `file://` URL (a raw Windows path is not * a valid import specifier); bare import kept as a fallback. */ import { createRequire } from "node:module"; import { pathToFileURL } from "node:url"; const _require = createRequire(import.meta.url); export function loadAstGrepNapi() { try { const entry = _require.resolve("@ast-grep/napi"); return import(pathToFileURL(entry).href); } catch { return import("@ast-grep/napi"); } }