Skip to content

feat: add node-version-file input for reading Node.js version from files#5

Merged
fengmk2 merged 3 commits intomainfrom
support-node-version-file
Mar 12, 2026
Merged

feat: add node-version-file input for reading Node.js version from files#5
fengmk2 merged 3 commits intomainfrom
support-node-version-file

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Mar 12, 2026

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.

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.
Copilot AI review requested due to automatic review settings March 12, 2026 13:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-file input (action.yml + inputs parsing/types) and use it in the main action flow when node-version is not provided.
  • Introduce resolveNodeVersionFile() with support for .nvmrc, .node-version, .tool-versions, and package.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.

Comment on lines +20 to +27
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]);
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +24
const originalEnv = process.env;

beforeEach(() => {
vi.resetAllMocks();
process.env = { ...originalEnv, GITHUB_WORKSPACE: "/workspace" };
});

afterEach(() => {
process.env = originalEnv;
});

Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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();
});

Copilot uses AI. Check for mistakes.
fengmk2 added 2 commits March 12, 2026 21:14
.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.
@fengmk2 fengmk2 merged commit b5d848f into main Mar 12, 2026
9 checks passed
@fengmk2 fengmk2 deleted the support-node-version-file branch March 12, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants