| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #!/usr/bin/env node
- import { defineCommand, runMain } from 'citty';
- import { resolve } from 'pathe';
- import { consola } from 'consola';
- import { a as addDependency, i as installDependencies, r as removeDependency, d as detectPackageManager, c as dedupeDependencies, f as runScript } from './shared/nypm.Bcw9TJOu.mjs';
- import 'pkg-types';
- import 'node:module';
- import 'tinyexec';
- import 'node:fs';
- import 'node:fs/promises';
- const name = "nypm";
- const version = "0.6.0";
- const description = "Unified Package Manager for Node.js";
- const operationArgs = {
- cwd: {
- type: "string",
- description: "Current working directory"
- },
- workspace: {
- type: "boolean",
- description: "Add to workspace"
- },
- silent: {
- type: "boolean",
- description: "Run in silent mode"
- }
- };
- const install = defineCommand({
- meta: {
- description: "Install dependencies"
- },
- args: {
- ...operationArgs,
- name: {
- type: "positional",
- description: "Dependency name",
- required: false
- },
- dev: {
- type: "boolean",
- alias: "D",
- description: "Add as dev dependency"
- },
- global: {
- type: "boolean",
- alias: "g",
- description: "Add globally"
- },
- "frozen-lockfile": {
- type: "boolean",
- description: "Install dependencies with frozen lock file"
- }
- },
- run: async ({ args }) => {
- await (args._.length > 0 ? addDependency(args._, args) : installDependencies(args));
- }
- });
- const remove = defineCommand({
- meta: {
- description: "Remove dependencies"
- },
- args: {
- name: {
- type: "positional",
- description: "Dependency name",
- required: true
- },
- ...operationArgs
- },
- run: async ({ args }) => {
- await removeDependency(args.name, args);
- }
- });
- const detect = defineCommand({
- meta: {
- description: "Detect the current package manager"
- },
- args: {
- cwd: {
- type: "string",
- description: "Current working directory"
- }
- },
- run: async ({ args }) => {
- const cwd = resolve(args.cwd || ".");
- const packageManager = await detectPackageManager(cwd);
- if (packageManager?.warnings) {
- for (const warning of packageManager.warnings) {
- consola.warn(warning);
- }
- }
- if (!packageManager) {
- consola.error(`Cannot detect package manager in \`${cwd}\``);
- return process.exit(1);
- }
- consola.log(
- `Detected package manager in \`${cwd}\`: \`${packageManager.name}@${packageManager.version}\``
- );
- }
- });
- const dedupe = defineCommand({
- meta: {
- description: "Dedupe dependencies"
- },
- args: {
- cwd: {
- type: "string",
- description: "Current working directory"
- },
- silent: {
- type: "boolean",
- description: "Run in silent mode"
- },
- recreateLockFile: {
- type: "boolean",
- description: "Recreate lock file"
- }
- },
- run: async ({ args }) => {
- await dedupeDependencies(args);
- }
- });
- const run = defineCommand({
- meta: {
- description: "Run script"
- },
- args: {
- name: {
- type: "positional",
- description: "Script name",
- required: true
- },
- ...operationArgs
- },
- run: async ({ args }) => {
- await runScript(args.name, args);
- }
- });
- const main = defineCommand({
- meta: {
- name,
- version,
- description
- },
- subCommands: {
- install,
- i: install,
- add: install,
- remove,
- rm: remove,
- uninstall: remove,
- un: remove,
- detect,
- dedupe,
- run
- }
- });
- runMain(main);
|