cli: Decouple Node.js from the Anchor CLI#4388
Open
plind-junior wants to merge 4 commits into
Open
Conversation
|
@plind-dm is attempting to deploy a commit to the Solana Foundation Team on Vercel. A member of the Team first needs to authorize it. |
The `get_npm_init_license()` function shells out to `npm config get init-license` during `anchor init` just to retrieve a license string for the generated package.json. This creates an unnecessary hard dependency on npm being installed even when the user may not need it. Replace with a hardcoded "ISC" default, which is what npm itself defaults to. This removes one Node.js touchpoint from the init path. Partial fix for solana-foundation#4279
`get_node_dns_option()` calls `node --version` to determine DNS options for every test run, including `cargo test` and `cargo test-sbf` where Node.js is not involved at all. This causes Rust-only workflows to fail if Node.js is not installed. Detect whether the test script is Rust-based (starts with "cargo test") and skip the Node.js version check and NODE_OPTIONS setup entirely in that case. Partial fix for solana-foundation#4279
When using Rust-based test templates (litesvm, mollusk, rust), there is no need to generate package.json, tsconfig.json, .prettierignore, deploy scripts, or run npm/yarn install. These are only relevant for JS/TS test workflows (mocha, jest). Add `TestTemplate::is_rust_based()` helper and use it to conditionally skip all Node.js-related scaffolding during project initialization. This allows `anchor init` with default settings (litesvm) to succeed without Node.js installed. Partial fix for solana-foundation#4279
`anchor shell` and `anchor migrate` both require Node.js but would previously fail with an opaque spawn error if node was not installed. Add an `ensure_node_installed()` check that runs `node --version` and returns a clear error message pointing to nodejs.org when Node.js is not found. Call it at the start of both commands so users get actionable feedback instead of a raw OS error. Partial fix for otter-sec#4279
aa7f2ac to
3289878
Compare
Author
|
@jamie-osec If this feature is already merged, do not close this one but just change it to draft status. |
Collaborator
|
You can change it to draft status yourself if you wish but we will close any redundant PRs |
Author
|
@jamie-osec I don't have the authority to mark it as a draft. Feel free to close it if it's redundant. |
Collaborator
Collaborator
|
Is this ready for review or not? |
Author
|
It's fully ready for review |
3e3ed94 to
3289878
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Addresses #4279 — Remove Node.js as a hard dependency from the Anchor CLI default workflow.
Audit Results
The CLI currently depends on Node.js in 9 integration points:
npm configcli/src/lib.rs:1120-1132package.jsonduringanchor initnpxprogram-metadatacli/src/metadata.rs:43-54@solana-program/program-metadatanpxskillscli/src/lib.rs:1506-1518--install-agent-skills)nodeshellcli/src/lib.rs:4568-4572anchor shell— interactive JS REPLnodedeploycli/src/lib.rs:4298-4303deploy.js/deploy.tsscriptsnodeversion checkcli/src/lib.rs:4883-4893cli/src/lib.rs:1533-1549npm/yarn/pnpm installduringanchor initcli/src/rust_template.rs:662-690package.jsongenerationcli/src/rust_template.rs:400-485Implementation Plan
Phase 1 — Remove unnecessary Node.js calls
npm config get init-licensewith a hardcoded default ("ISC") — no reason to shell out to npm for a license stringPhase 2 — Gate JS features behind runtime checks
anchor init: Skippackage.json,node_modules, and JS test scaffolding when Rust test framework is selectedanchor shell: Check for Node.js at invocation time, clear error if missingPhase 3 — Out of scope (depends on other issues)
npx @solana-program/program-metadata(metadata.rs): Needs a pure Rust program-metadata client — aligns with Generation to trait-based collection (Codama integration) #4288npm-package/anchor.js: Optional npm distribution wrapper, not a runtime dependency — no change neededTest plan
anchor initwith Rust test framework creates a working project without Node.js installedanchor initwith JS/TS test framework still works as beforeanchor testwith Rust tests works without Node.jsanchor shellprints a clear error when Node.js is not installedRelates to #4278 (LiteSVM) and #4288 (IDL Generation)