pkgmgr 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,6 +24,10 @@ pkgmgr exec vitest # runs: <detected-pm> exec vitest
24
24
 
25
25
  ## Available Binaries
26
26
 
27
+ ### Package Manager Binaries (`pkgmgr`)
28
+
29
+ Forward commands directly to the detected package manager.
30
+
27
31
  | Binary | Fallback |
28
32
  |--------|----------|
29
33
  | `pkgmgr` | npm |
@@ -31,6 +35,22 @@ pkgmgr exec vitest # runs: <detected-pm> exec vitest
31
35
  | `pkgmgr-pnpm` | pnpm |
32
36
  | `pkgmgr-yarn` | yarn |
33
37
 
38
+ ### Exec Binaries (`pkgmgrx`)
39
+
40
+ Forward commands to the detected package manager's "exec" equivalent.
41
+
42
+ | Binary | Fallback | Executes |
43
+ |--------|----------|----------|
44
+ | `pkgmgrx` | npm | `npx <args>` |
45
+ | `pkgmgrx-bun` | bun | `bunx <args>` |
46
+ | `pkgmgrx-pnpm` | pnpm | `pnpm dlx <args>` |
47
+ | `pkgmgrx-yarn` | yarn | `yarn dlx <args>` |
48
+
49
+ ```bash
50
+ pkgmgrx cowsay "Hello" # runs: npx cowsay "Hello" (or bunx, pnpm dlx, yarn dlx)
51
+ pkgmgrx tsc --version # runs: npx tsc --version
52
+ ```
53
+
34
54
  All binaries use the same detection logic. The only difference is which package manager is used when detection fails (no `PKGMGR` env var and no `npm_config_user_agent`).
35
55
 
36
56
  ## Detection Logic
package/bin/lib.js CHANGED
@@ -1,5 +1,13 @@
1
1
  const SUPPORTED = new Set(['npm', 'pnpm', 'yarn', 'bun'])
2
2
 
3
+ // Maps package manager to its "exec" command equivalent
4
+ const EXEC_COMMANDS = {
5
+ npm: { bin: 'npx', args: [] },
6
+ pnpm: { bin: 'pnpm', args: ['dlx'] },
7
+ yarn: { bin: 'yarn', args: ['dlx'] },
8
+ bun: { bin: 'bunx', args: [] },
9
+ }
10
+
3
11
  export function detectPackageManager(fallback = 'npm') {
4
12
  // 1. Explicit override via environment variable
5
13
  const envOverride = process.env.PKGMGR
@@ -45,3 +53,32 @@ export async function run(fallback = 'npm') {
45
53
  process.exit(code ?? 0)
46
54
  })
47
55
  }
56
+
57
+ export async function runExec(fallback = 'npm') {
58
+ const pm = detectPackageManager(fallback)
59
+ const args = process.argv.slice(2)
60
+
61
+ if (args.length === 0) {
62
+ console.error('pkgmgrx: no command specified')
63
+ process.exit(1)
64
+ }
65
+
66
+ const { bin, args: prefixArgs } = EXEC_COMMANDS[pm]
67
+ const command = [...prefixArgs, ...args]
68
+
69
+ const { spawn } = await import('node:child_process')
70
+
71
+ const child = spawn(bin, command, {
72
+ stdio: 'inherit',
73
+ shell: process.platform === 'win32',
74
+ })
75
+
76
+ child.on('error', (err) => {
77
+ console.error(`pkgmgrx: failed to execute ${bin}: ${err.message}`)
78
+ process.exit(1)
79
+ })
80
+
81
+ child.on('close', (code) => {
82
+ process.exit(code ?? 0)
83
+ })
84
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { runExec } from './lib.js'
3
+ runExec('bun')
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { runExec } from './lib.js'
3
+ runExec('pnpm')
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { runExec } from './lib.js'
3
+ runExec('yarn')
package/bin/pkgmgrx.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { runExec } from './lib.js'
3
+ runExec('npm')
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "pkgmgr",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Forward commands to the package manager you're already using",
5
5
  "bin": {
6
6
  "pkgmgr": "./bin/pkgmgr.js",
7
7
  "pkgmgr-bun": "./bin/pkgmgr-bun.js",
8
8
  "pkgmgr-pnpm": "./bin/pkgmgr-pnpm.js",
9
- "pkgmgr-yarn": "./bin/pkgmgr-yarn.js"
9
+ "pkgmgr-yarn": "./bin/pkgmgr-yarn.js",
10
+ "pkgmgrx": "./bin/pkgmgrx.js",
11
+ "pkgmgrx-bun": "./bin/pkgmgrx-bun.js",
12
+ "pkgmgrx-pnpm": "./bin/pkgmgrx-pnpm.js",
13
+ "pkgmgrx-yarn": "./bin/pkgmgrx-yarn.js"
10
14
  },
11
15
  "files": [
12
16
  "bin"