UNPKG

@antfu/ni

Version:

Use the right package manager

51 lines (47 loc) 1.14 kB
import { __toModule, parseNr, require_prompts, runCli } from "./chunk-HORULVTV.mjs"; // src/nr.ts var import_prompts = __toModule(require_prompts()); // src/fs.ts import {resolve} from "path"; import fs from "fs"; function getPackageJSON() { const path = resolve(process.cwd(), "package.json"); if (fs.existsSync(path)) { try { const raw = fs.readFileSync(path, "utf-8"); const data = JSON.parse(raw); return data; } catch (e) { console.warn("Failed to parse package.json"); process.exit(0); } } } // src/nr.ts runCli(async (agent, args) => { if (args.length === 0) { const scripts = getPackageJSON().scripts || {}; const names = Object.entries(scripts); if (!names.length) return; try { const {fn} = await (0, import_prompts.default)({ name: "fn", message: "script to run", type: "select", choices: names.map(([value, description]) => ({title: value, value, description})) }); if (!fn) return; args.push(fn); } catch (e) { process.exit(0); } } return parseNr(agent, args); });