Aventuras/scripts/package-manager.js
Tony Frazier 0913b5ce7d
Route dev/build/release scripts through aube when it installed node_modules (#552)
## Summary

- Adds `scripts/package-manager.js`, which detects whether `aube` or
`npm` owns the current
`node_modules` (by checking for `node_modules/.aube-state`, then
confirming `aube` is still
on `PATH`) and builds the right `[cmd, args]` pair for
`spawnSync`/`execFileSync`, including
  the Windows `npm.cmd` workaround.
- Adds `scripts/pm.js`, a thin CLI (`node scripts/pm.js <args...>`) that
runs that detected
  package manager with the given arguments and forwards its exit status.
- Routes `lefthook.yml`'s `pre-push` `lint`/`check` commands and
`tauri.conf.json`'s
`beforeDevCommand`/`beforeBuildCommand` through `scripts/pm.js`, so they
use aube wherever
  aube did the install and npm otherwise.
- `scripts/release.js` keeps the version bump on npm (npm owns
`package-lock.json`), but now
runs its `format`/`lint:fix` steps through the detected package manager.
When that manager
is aube, it adds `--no-install --frozen-lockfile` so aube doesn't
re-resolve the lockfile npm
  just rewrote.
- Documents the new detection/routing behavior in
`docs/development/release.md`.

## Test plan

- [ ] `npm test` / `aube test` passes, including the new
`scripts/package-manager.test.js`
coverage for `detectPackageManager` and `commandFor` on both platforms.
- [ ] `npm run lint` / `aubr lint` and `npm run check` / `aubr check`
pass.
- [ ] Manually verify `npx tauri dev` still launches correctly on a
checkout with only npm
  installed, and on one where aube performed the install.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01YHkuCEJRUTBnsZaUnhfR9N

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Chores**
* Development, build, pre-push checks, and release tasks now use the
package manager detected for the project, supporting both npm and Aube.
* Command execution accounts for platform differences, including
Windows, and the existing lint memory limit is preserved.
* These changes apply to development and release workflows; they do not
change application features or behavior for end users.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-28 14:34:27 -04:00

28 lines
1.2 KiB
JavaScript

/**
* `aube` when it did the install and is still on PATH, `npm` otherwise. The install is the
* tell, not just aube being on PATH — a teammate who has aube for other projects but ran
* `npm ci` here must stay on npm, since aube would otherwise reinstall their `node_modules`
* out from under them.
*/
import fs from 'fs'
import path from 'path'
import { spawnSync } from 'child_process'
export function detectPackageManager(rootDir = process.cwd()) {
if (!fs.existsSync(path.join(rootDir, 'node_modules', '.aube-state'))) return 'npm'
const probe = spawnSync(...commandFor('aube', ['--version']), { stdio: 'ignore' })
return !probe.error && probe.status === 0 ? 'aube' : 'npm'
}
/**
* `[cmd, cmdArgs]` for `spawnSync`/`execFileSync`. On Windows both npm and aube can be
* `.cmd`/`.ps1` shims rather than a real executable — npm always is; aube is too when npm
* installed it globally, as opposed to mise's `.exe` shims. `execFile`/`spawn` cannot launch
* a `.cmd` directly, so both go through `cmd.exe` rather than `shell: true` (Node deprecated
* that combination, DEP0190).
*/
export function commandFor(pm, args, platform = process.platform) {
if (platform === 'win32') return ['cmd.exe', ['/c', pm, ...args]]
return [pm, args]
}