feat: add node-version-file input for reading Node.js version from files#5
feat: add node-version-file input for reading Node.js version from files#5
Conversation
Support reading Node.js version from .nvmrc, .node-version, .tool-versions, and package.json (devEngines.runtime then engines.node), matching actions/setup-node behavior. Ignored when node-version is set. Also extracts resolveWorkspacePath utility to reduce duplication.
There was a problem hiding this comment.
Pull request overview
Adds support for resolving a Node.js version from common “version files” (similar to actions/setup-node) via a new node-version-file input, and centralizes workspace path resolution to reduce duplication.
Changes:
- Add
node-version-fileinput (action.yml + inputs parsing/types) and use it in the main action flow whennode-versionis not provided. - Introduce
resolveNodeVersionFile()with support for.nvmrc,.node-version,.tool-versions, andpackage.json, with accompanying tests. - Extract workspace helpers (
getWorkspaceDir,resolveWorkspacePath) and reuse them in lockfile detection.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils.ts | Adds workspace/path helpers and reuses them in lockfile detection. |
| src/types.ts | Extends Inputs with nodeVersionFile. |
| src/node-version-file.ts | Implements Node.js version resolution from supported files. |
| src/node-version-file.test.ts | Adds unit tests for version-file parsing and path resolution. |
| src/inputs.ts | Reads node-version-file from action inputs. |
| src/inputs.test.ts | Updates defaults + adds test coverage for the new input. |
| src/index.ts | Prefers node-version, otherwise resolves Node version via node-version-file. |
| action.yml | Declares the new node-version-file input. |
| README.md | Documents node-version-file and adds usage example + inputs table row. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let nodeVersion = inputs.nodeVersion; | ||
| if (!nodeVersion && inputs.nodeVersionFile) { | ||
| nodeVersion = resolveNodeVersionFile(inputs.nodeVersionFile); | ||
| } | ||
|
|
||
| if (nodeVersion) { | ||
| info(`Setting up Node.js ${nodeVersion} via vp env use...`); | ||
| await exec("vp", ["env", "use", nodeVersion]); |
There was a problem hiding this comment.
The action entrypoint is dist/index.mjs (per action.yml), but the compiled dist output doesn't include the new node-version-file/resolveNodeVersionFile logic (no references found). Please run the build/pack step and commit the updated dist/index.mjs, otherwise users won't actually get this feature when using the action.
| const originalEnv = process.env; | ||
|
|
||
| beforeEach(() => { | ||
| vi.resetAllMocks(); | ||
| process.env = { ...originalEnv, GITHUB_WORKSPACE: "/workspace" }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.env = originalEnv; | ||
| }); | ||
|
|
There was a problem hiding this comment.
This test mutates process.env by replacing the entire object. Elsewhere in the repo (e.g. utils.test.ts) the convention is vi.stubEnv(...)/vi.unstubAllEnvs(), which avoids leaking env state between tests and prevents issues with Node's env handling. Consider switching to vi.stubEnv('GITHUB_WORKSPACE', '/workspace') and cleaning up with vi.unstubAllEnvs() in afterEach.
| const originalEnv = process.env; | |
| beforeEach(() => { | |
| vi.resetAllMocks(); | |
| process.env = { ...originalEnv, GITHUB_WORKSPACE: "/workspace" }; | |
| }); | |
| afterEach(() => { | |
| process.env = originalEnv; | |
| }); | |
| beforeEach(() => { | |
| vi.resetAllMocks(); | |
| vi.stubEnv("GITHUB_WORKSPACE", "/workspace"); | |
| }); | |
| afterEach(() => { | |
| vi.unstubAllEnvs(); | |
| }); |
.nvmrc: normalize nvm aliases (node/stable → latest, lts/<codename> → lts), strip inline comments, preserve lts/* as-is since vp supports it. .tool-versions: skip non-installable asdf specs (system, ref:*, path:*) and pick the first installable version from multi-version fallback lines.
Support reading Node.js version from .nvmrc, .node-version, .tool-versions, and package.json (devEngines.runtime then engines.node), matching actions/setup-node behavior. Ignored when node-version is set.
Also extracts resolveWorkspacePath utility to reduce duplication.