+31
-118
@@ -10,10 +10,5 @@ #!/usr/bin/env node | ||
| import { join as join$1 } from "node:path"; | ||
| //#region package.json | ||
| var name = "nypm"; | ||
| var version = "0.6.3"; | ||
| var version = "0.6.4"; | ||
| var description = "Unified Package Manager for Node.js"; | ||
| //#endregion | ||
| //#region src/package-manager.ts | ||
| const packageManagers = [ | ||
@@ -49,9 +44,2 @@ { | ||
| ]; | ||
| /** | ||
| * Detect the package manager used in a directory (and up) by checking various sources: | ||
| * | ||
| * 1. Use `packageManager` field from package.json | ||
| * | ||
| * 2. Known lock files and other files | ||
| */ | ||
| async function detectPackageManager(cwd, options = {}) { | ||
@@ -64,10 +52,10 @@ const detected = await findup(resolve(cwd || "."), async (path) => { | ||
| if (packageJSON?.packageManager) { | ||
| const { name: name$1, version: version$1 = "0.0.0", buildMeta, warnings } = parsePackageManagerField(packageJSON.packageManager); | ||
| if (name$1) { | ||
| const majorVersion = version$1.split(".")[0]; | ||
| const packageManager = packageManagers.find((pm) => pm.name === name$1 && pm.majorVersion === majorVersion) || packageManagers.find((pm) => pm.name === name$1); | ||
| const { name, version = "0.0.0", buildMeta, warnings } = parsePackageManagerField(packageJSON.packageManager); | ||
| if (name) { | ||
| const majorVersion = version.split(".")[0]; | ||
| const packageManager = packageManagers.find((pm) => pm.name === name && pm.majorVersion === majorVersion) || packageManagers.find((pm) => pm.name === name); | ||
| return { | ||
| name: name$1, | ||
| command: name$1, | ||
| version: version$1, | ||
| name, | ||
| command: name, | ||
| version, | ||
| majorVersion, | ||
@@ -91,3 +79,3 @@ buildMeta, | ||
| if (scriptArg) { | ||
| for (const packageManager of packageManagers) if ((/* @__PURE__ */ new RegExp(`[/\\\\]\\.?${packageManager.command}`)).test(scriptArg)) return packageManager; | ||
| for (const packageManager of packageManagers) if (new RegExp(`[/\\\\]\\.?${packageManager.command}`).test(scriptArg)) return packageManager; | ||
| } | ||
@@ -97,5 +85,2 @@ } | ||
| } | ||
| //#endregion | ||
| //#region src/_utils.ts | ||
| async function findup(cwd, match, options = {}) { | ||
@@ -178,29 +163,17 @@ const segments = normalize(cwd).split("/"); | ||
| function parsePackageManagerField(packageManager) { | ||
| const [name$1, _version] = (packageManager || "").split("@"); | ||
| const [version$1, buildMeta] = _version?.split("+") || []; | ||
| if (name$1 && name$1 !== "-" && /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(name$1)) return { | ||
| name: name$1, | ||
| version: version$1, | ||
| const [name, _version] = (packageManager || "").split("@"); | ||
| const [version, buildMeta] = _version?.split("+") || []; | ||
| if (name && name !== "-" && /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(name)) return { | ||
| name, | ||
| version, | ||
| buildMeta | ||
| }; | ||
| const sanitized = (name$1 || "").replace(/\W+/g, ""); | ||
| const sanitized = (name || "").replace(/\W+/g, ""); | ||
| return { | ||
| name: sanitized, | ||
| version: version$1, | ||
| version, | ||
| buildMeta, | ||
| warnings: [`Abnormal characters found in \`packageManager\` field, sanitizing from \`${name$1}\` to \`${sanitized}\``] | ||
| warnings: [`Abnormal characters found in \`packageManager\` field, sanitizing from \`${name}\` to \`${sanitized}\``] | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/api.ts | ||
| /** | ||
| * Installs project dependencies. | ||
| * | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.frozenLockFile - Whether to install dependencies with frozen lock file. | ||
| */ | ||
| async function installDependencies(options = {}) { | ||
@@ -226,17 +199,5 @@ const resolvedOptions = await resolveOperationOptions(options); | ||
| } | ||
| /** | ||
| * Adds dependency to the project. | ||
| * | ||
| * @param name - Name of the dependency to add. | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.dev - Whether to add the dependency as dev dependency. | ||
| * @param options.workspace - The name of the workspace to use. | ||
| * @param options.global - Whether to run the command in global mode. | ||
| */ | ||
| async function addDependency(name$1, options = {}) { | ||
| async function addDependency(name, options = {}) { | ||
| const resolvedOptions = await resolveOperationOptions(options); | ||
| const names = Array.isArray(name$1) ? name$1 : [name$1]; | ||
| const names = Array.isArray(name) ? name : [name]; | ||
| if (resolvedOptions.packageManager.name === "deno") { | ||
@@ -268,10 +229,11 @@ for (let i = 0; i < names.length; i++) if (!/^(npm|jsr|file):.+$/.test(names[i] || "")) names[i] = `npm:${names[i]}`; | ||
| const peerDevDeps = []; | ||
| const _require = createRequire(join$1(resolvedOptions.cwd, "/_.js")); | ||
| for (const _name of names) { | ||
| const pkgName = _name.match(/^(.[^@]+)/)?.[0]; | ||
| const pkg = createRequire(join$1(resolvedOptions.cwd, "/_.js"))(`${pkgName}/package.json`); | ||
| if (!pkg.peerDependencies || pkg.name !== pkgName) continue; | ||
| for (const [peerDependency, version$1] of Object.entries(pkg.peerDependencies)) { | ||
| const pkg = await readPackageJSON(_require.resolve(pkgName)); | ||
| if (!pkg?.peerDependencies || pkg?.name !== pkgName) continue; | ||
| for (const [peerDependency, version] of Object.entries(pkg.peerDependencies)) { | ||
| if (pkg.peerDependenciesMeta?.[peerDependency]?.optional) continue; | ||
| if (existingPkg?.dependencies?.[peerDependency] || existingPkg?.devDependencies?.[peerDependency]) continue; | ||
| (pkg.peerDependenciesMeta?.[peerDependency]?.dev ? peerDevDeps : peerDeps).push(`${peerDependency}@${version$1}`); | ||
| (pkg.peerDependenciesMeta?.[peerDependency]?.dev ? peerDevDeps : peerDeps).push(`${peerDependency}@${version}`); | ||
| } | ||
@@ -287,16 +249,4 @@ } | ||
| } | ||
| /** | ||
| * Adds dev dependency to the project. | ||
| * | ||
| * @param name - Name of the dev dependency to add. | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.workspace - The name of the workspace to use. | ||
| * @param options.global - Whether to run the command in global mode. | ||
| * | ||
| */ | ||
| async function addDevDependency(name$1, options = {}) { | ||
| return await addDependency(name$1, { | ||
| async function addDevDependency(name, options = {}) { | ||
| return await addDependency(name, { | ||
| ...options, | ||
@@ -306,17 +256,5 @@ dev: true | ||
| } | ||
| /** | ||
| * Removes dependency from the project. | ||
| * | ||
| * @param name - Name of the dependency to remove. | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.dev - Whether to remove dev dependency. | ||
| * @param options.workspace - The name of the workspace to use. | ||
| * @param options.global - Whether to run the command in global mode. | ||
| */ | ||
| async function removeDependency(name$1, options = {}) { | ||
| async function removeDependency(name, options = {}) { | ||
| const resolvedOptions = await resolveOperationOptions(options); | ||
| const names = Array.isArray(name$1) ? name$1 : [name$1]; | ||
| const names = Array.isArray(name) ? name : [name]; | ||
| if (names.length === 0) return {}; | ||
@@ -347,11 +285,2 @@ const args = (resolvedOptions.packageManager.name === "yarn" ? [ | ||
| } | ||
| /** | ||
| * Dedupe dependencies in the project. | ||
| * | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.recreateLockfile - Whether to recreate the lockfile instead of deduping. | ||
| */ | ||
| async function dedupeDependencies(options = {}) { | ||
@@ -379,18 +308,7 @@ const resolvedOptions = await resolveOperationOptions(options); | ||
| } | ||
| /** | ||
| * Runs a script defined in the package.json file. | ||
| * | ||
| * @param name - Name of the script to run. | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.env - Additional environment variables to set for the script execution. | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.args - Additional arguments to pass to the script. | ||
| */ | ||
| async function runScript(name$1, options = {}) { | ||
| async function runScript(name, options = {}) { | ||
| const resolvedOptions = await resolveOperationOptions(options); | ||
| const args = [ | ||
| resolvedOptions.packageManager.name === "deno" ? "task" : "run", | ||
| name$1, | ||
| name, | ||
| ...options.args || [] | ||
@@ -409,5 +327,2 @@ ]; | ||
| } | ||
| //#endregion | ||
| //#region src/cli.ts | ||
| const operationArgs = { | ||
@@ -558,4 +473,2 @@ cwd: { | ||
| } | ||
| //#endregion | ||
| export { }; | ||
| export {}; |
+14
-14
@@ -34,22 +34,22 @@ //#region src/types.d.ts | ||
| /** | ||
| * Whether to ignore the lock file | ||
| * | ||
| * @default false | ||
| */ | ||
| * Whether to ignore the lock file | ||
| * | ||
| * @default false | ||
| */ | ||
| ignoreLockFile?: boolean; | ||
| /** | ||
| * Whether to ignore the package.json file | ||
| * | ||
| * @default false | ||
| */ | ||
| * Whether to ignore the package.json file | ||
| * | ||
| * @default false | ||
| */ | ||
| ignorePackageJSON?: boolean; | ||
| /** | ||
| * Whether to include parent directories | ||
| * | ||
| * @default false | ||
| */ | ||
| * Whether to include parent directories | ||
| * | ||
| * @default false | ||
| */ | ||
| includeParentDirs?: boolean; | ||
| /** | ||
| * Weather to ignore argv[1] to detect script | ||
| */ | ||
| * Weather to ignore argv[1] to detect script | ||
| */ | ||
| ignoreArgv?: boolean; | ||
@@ -56,0 +56,0 @@ }; |
+5
-123
@@ -8,4 +8,2 @@ import { createRequire } from "node:module"; | ||
| import { join as join$1 } from "node:path"; | ||
| //#region src/_utils.ts | ||
| async function findup(cwd, match, options = {}) { | ||
@@ -123,5 +121,2 @@ const segments = normalize(cwd).split("/"); | ||
| } | ||
| //#endregion | ||
| //#region src/package-manager.ts | ||
| const packageManagers = [ | ||
@@ -157,9 +152,2 @@ { | ||
| ]; | ||
| /** | ||
| * Detect the package manager used in a directory (and up) by checking various sources: | ||
| * | ||
| * 1. Use `packageManager` field from package.json | ||
| * | ||
| * 2. Known lock files and other files | ||
| */ | ||
| async function detectPackageManager(cwd, options = {}) { | ||
@@ -198,3 +186,3 @@ const detected = await findup(resolve(cwd || "."), async (path) => { | ||
| if (scriptArg) { | ||
| for (const packageManager of packageManagers) if ((/* @__PURE__ */ new RegExp(`[/\\\\]\\.?${packageManager.command}`)).test(scriptArg)) return packageManager; | ||
| for (const packageManager of packageManagers) if (new RegExp(`[/\\\\]\\.?${packageManager.command}`).test(scriptArg)) return packageManager; | ||
| } | ||
@@ -204,8 +192,2 @@ } | ||
| } | ||
| //#endregion | ||
| //#region src/cmd.ts | ||
| /** | ||
| * Get the command to install dependencies with the package manager. | ||
| */ | ||
| function installDependenciesCommand(packageManager, options = {}) { | ||
@@ -222,5 +204,2 @@ const installCmd = options.short ? "i" : "install"; | ||
| } | ||
| /** | ||
| * Get the command to add a dependency with the package manager. | ||
| */ | ||
| function addDependencyCommand(packageManager, name, options = {}) { | ||
@@ -251,5 +230,2 @@ const names = Array.isArray(name) ? name : [name]; | ||
| } | ||
| /** | ||
| * Get the command to run a script with the package manager. | ||
| */ | ||
| function runScriptCommand(packageManager, name, options = {}) { | ||
@@ -262,5 +238,2 @@ return fmtCommand([packageManager, ...[ | ||
| } | ||
| /** | ||
| * Get the command to download and execute a package with the package manager. | ||
| */ | ||
| function dlxCommand(packageManager, name, options = {}) { | ||
@@ -293,14 +266,2 @@ const command = { | ||
| } | ||
| //#endregion | ||
| //#region src/api.ts | ||
| /** | ||
| * Installs project dependencies. | ||
| * | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.frozenLockFile - Whether to install dependencies with frozen lock file. | ||
| */ | ||
| async function installDependencies(options = {}) { | ||
@@ -326,14 +287,2 @@ const resolvedOptions = await resolveOperationOptions(options); | ||
| } | ||
| /** | ||
| * Adds dependency to the project. | ||
| * | ||
| * @param name - Name of the dependency to add. | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.dev - Whether to add the dependency as dev dependency. | ||
| * @param options.workspace - The name of the workspace to use. | ||
| * @param options.global - Whether to run the command in global mode. | ||
| */ | ||
| async function addDependency(name, options = {}) { | ||
@@ -368,6 +317,7 @@ const resolvedOptions = await resolveOperationOptions(options); | ||
| const peerDevDeps = []; | ||
| const _require = createRequire(join$1(resolvedOptions.cwd, "/_.js")); | ||
| for (const _name of names) { | ||
| const pkgName = _name.match(/^(.[^@]+)/)?.[0]; | ||
| const pkg = createRequire(join$1(resolvedOptions.cwd, "/_.js"))(`${pkgName}/package.json`); | ||
| if (!pkg.peerDependencies || pkg.name !== pkgName) continue; | ||
| const pkg = await readPackageJSON(_require.resolve(pkgName)); | ||
| if (!pkg?.peerDependencies || pkg?.name !== pkgName) continue; | ||
| for (const [peerDependency, version] of Object.entries(pkg.peerDependencies)) { | ||
@@ -387,14 +337,2 @@ if (pkg.peerDependenciesMeta?.[peerDependency]?.optional) continue; | ||
| } | ||
| /** | ||
| * Adds dev dependency to the project. | ||
| * | ||
| * @param name - Name of the dev dependency to add. | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.workspace - The name of the workspace to use. | ||
| * @param options.global - Whether to run the command in global mode. | ||
| * | ||
| */ | ||
| async function addDevDependency(name, options = {}) { | ||
@@ -406,14 +344,2 @@ return await addDependency(name, { | ||
| } | ||
| /** | ||
| * Removes dependency from the project. | ||
| * | ||
| * @param name - Name of the dependency to remove. | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.dev - Whether to remove dev dependency. | ||
| * @param options.workspace - The name of the workspace to use. | ||
| * @param options.global - Whether to run the command in global mode. | ||
| */ | ||
| async function removeDependency(name, options = {}) { | ||
@@ -447,11 +373,2 @@ const resolvedOptions = await resolveOperationOptions(options); | ||
| } | ||
| /** | ||
| * Ensures dependency is installed. | ||
| * | ||
| * @param name - Name of the dependency. | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.dev - Whether to install as dev dependency (if not already installed). | ||
| * @param options.workspace - The name of the workspace to install dependency in (if not already installed). | ||
| */ | ||
| async function ensureDependencyInstalled(name, options = {}) { | ||
@@ -462,11 +379,2 @@ const resolvedOptions = await resolveOperationOptions(options); | ||
| } | ||
| /** | ||
| * Dedupe dependencies in the project. | ||
| * | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.recreateLockfile - Whether to recreate the lockfile instead of deduping. | ||
| */ | ||
| async function dedupeDependencies(options = {}) { | ||
@@ -494,13 +402,2 @@ const resolvedOptions = await resolveOperationOptions(options); | ||
| } | ||
| /** | ||
| * Runs a script defined in the package.json file. | ||
| * | ||
| * @param name - Name of the script to run. | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.env - Additional environment variables to set for the script execution. | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.args - Additional arguments to pass to the script. | ||
| */ | ||
| async function runScript(name, options = {}) { | ||
@@ -524,15 +421,2 @@ const resolvedOptions = await resolveOperationOptions(options); | ||
| } | ||
| /** | ||
| * Download and execute a package with the package manager. | ||
| * | ||
| * @param name - Name of the package to download and execute. | ||
| * @param options - Options to pass to the API call. | ||
| * @param options.cwd - The directory to run the command in. | ||
| * @param options.env - Additional environment variables to set for the command execution. | ||
| * @param options.silent - Whether to run the command in silent mode. | ||
| * @param options.packageManager - The package manager info to use (auto-detected). | ||
| * @param options.args - The arguments to pass to the command. | ||
| * @param options.short - Whether to use the short version of the command (e.g. pnpx instead of pnpm dlx). | ||
| * @param options.packages - The packages to pass to the command (e.g. npx --package=<package1> --package=<package2> <command>). | ||
| */ | ||
| async function dlx(name, options = {}) { | ||
@@ -556,4 +440,2 @@ const resolvedOptions = await resolveOperationOptions(options); | ||
| } | ||
| //#endregion | ||
| export { addDependency, addDependencyCommand, addDevDependency, dedupeDependencies, detectPackageManager, dlx, dlxCommand, ensureDependencyInstalled, installDependencies, installDependenciesCommand, packageManagers, removeDependency, runScript, runScriptCommand }; | ||
| export { addDependency, addDependencyCommand, addDevDependency, dedupeDependencies, detectPackageManager, dlx, dlxCommand, ensureDependencyInstalled, installDependencies, installDependenciesCommand, packageManagers, removeDependency, runScript, runScriptCommand }; |
+19
-19
| { | ||
| "name": "nypm", | ||
| "version": "0.6.4", | ||
| "version": "0.6.5", | ||
| "description": "Unified Package Manager for Node.js", | ||
| "license": "MIT", | ||
| "repository": "unjs/nypm", | ||
| "license": "MIT", | ||
| "sideEffects": false, | ||
| "type": "module", | ||
| "exports": { | ||
| ".": "./dist/index.mjs" | ||
| }, | ||
| "module": "./dist/index.mjs", | ||
| "types": "./dist/index.d.mts", | ||
| "bin": { | ||
@@ -20,2 +13,9 @@ "nypm": "./dist/cli.mjs" | ||
| ], | ||
| "type": "module", | ||
| "sideEffects": false, | ||
| "module": "./dist/index.mjs", | ||
| "types": "./dist/index.d.mts", | ||
| "exports": { | ||
| ".": "./dist/index.mjs" | ||
| }, | ||
| "dependencies": { | ||
@@ -27,16 +27,16 @@ "citty": "^0.2.0", | ||
| "devDependencies": { | ||
| "@types/node": "^25.0.9", | ||
| "@typescript/native-preview": "7.0.0-dev.20260120.1", | ||
| "@vitest/coverage-v8": "^4.0.17", | ||
| "automd": "^0.4.2", | ||
| "@types/node": "^25.2.1", | ||
| "@typescript/native-preview": "^7.0.0-dev.20260205.1", | ||
| "@vitest/coverage-v8": "^4.0.18", | ||
| "automd": "^0.4.3", | ||
| "changelogen": "^0.6.2", | ||
| "eslint": "^9.39.2", | ||
| "eslint-config-unjs": "^0.6.2", | ||
| "obuild": "^0.4.18", | ||
| "obuild": "^0.4.22", | ||
| "oxfmt": "^0.28.0", | ||
| "oxlint": "^1.43.0", | ||
| "pkg-types": "^2.3.0", | ||
| "prettier": "^3.8.0", | ||
| "std-env": "^3.10.0", | ||
| "typescript": "^5.9.3", | ||
| "ufo": "^1.6.3", | ||
| "vitest": "^4.0.17" | ||
| "vitest": "^4.0.18" | ||
| }, | ||
@@ -49,4 +49,4 @@ "engines": { | ||
| "dev": "vitest dev", | ||
| "lint": "eslint . && prettier -c src test", | ||
| "lint:fix": "eslint . --fix && prettier -w src test", | ||
| "lint": "oxlint . && oxfmt --check src test", | ||
| "lint:fix": "oxlint . --fix && oxfmt src test", | ||
| "nypm": "node ./src/cli.ts", | ||
@@ -53,0 +53,0 @@ "release": "pnpm test && pnpm build && changelogen --release --push && pnpm publish", |
46170
-15.03%883
-17.86%