build: make scripts agnostic of package manager - #1
Conversation
lm-sousa
left a comment
There was a problem hiding this comment.
Assuming you have tested these changes thoroughly, feel free to merge them.
There was a problem hiding this comment.
Pull request overview
This PR aims to make build scripts package manager agnostic by removing explicit references to npm and npx, allowing users to use alternative package managers like yarn, pnpm, or bun without compatibility issues.
Key changes:
- Removed
npxprefix fromclavacommand invocations inrunandrun:watchscripts - Replaced
npm runwithnode --runfor test script chaining intest:covandtest:watch
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "run": "npx clava classic dist/main.js -p CxxSources/", | ||
| "run:watch": "npx clava dist/main.js -w dist/main.js -- clang CxxSources/", | ||
| "run": "clava classic dist/main.js -p CxxSources/", | ||
| "run:watch": "clava dist/main.js -w dist/main.js -- clang CxxSources/", |
There was a problem hiding this comment.
Removing npx from these scripts will break execution when clava is not globally installed. The clava command comes from the @specs-feup/clava dependency and needs to be executed via npx or the package manager's equivalent to find the binary in node_modules/.bin/.
Without npx, the shell will look for clava in the system PATH and fail if it's not globally installed. Package managers like yarn, pnpm, and bun automatically add node_modules/.bin to PATH when running scripts, but when using node --run, this behavior is not guaranteed across all environments.
Consider keeping the commands as npx clava or document that users must have clava globally installed.
| "run:watch": "clava dist/main.js -w dist/main.js -- clang CxxSources/", | |
| "run:watch": "npx clava dist/main.js -w dist/main.js -- clang CxxSources/", |
There was a problem hiding this comment.
Indeed it is not expected that users necessarily install Clava globally.
| "test:cov": "node --run test -- --coverage", | ||
| "test:watch": "node --run test -- --watch" |
There was a problem hiding this comment.
The node --run command was introduced in Node.js v22.0.0 (April 2024). Using this feature without specifying a minimum Node.js version in the engines field could cause compatibility issues for users on older Node.js versions.
Consider either:
- Adding an
enginesfield to package.json:"engines": { "node": ">=22.0.0" } - Using a package manager-agnostic approach that works with older Node versions, such as defining the test commands inline rather than chaining them
lm-sousa
left a comment
There was a problem hiding this comment.
It seems Copilot has raised a few objections. At least the one of the required engine version needs to be addressed.
That can be done here or in the Lara-JS package, since similar changes should be made there.
By using
npm runornpx, this template limits the user to usingnpmto manage packages.If other popular package managers, such as
yarn,pnpm orbun, are used, there might be incompatibilities when callingnpm` inside a script executed by them.As such, in general, it is good practice not to use
npxin scripts and to usenode --runinstead ofnpm runto call scripts declared inpackage.json.