$ show actions/setup-node
This repository implements the official GitHub Action `actions/setup-node`, which sets up a Node.js environment in GitHub Actions workflows. It downloads and caches the requested Node.js version (including LTS, nightly, RC, and v8-canary builds), adds it to the PATH, optionally caches npm/yarn/pnpm dependencies using `actions/cache`, registers problem matchers for TypeScript and ESLint, and configures authentication for private npm registries. The architecture is a composite action with a main entry point (`src/setup-node.ts`) and a post-job cache-save entry point (`src/cache-save.ts`), both compiled via ncc. The codebase is well-structured with abstract base classes for distribution handling, a factory pattern for selecting the correct distribution, and separate modules for cache utilities and authentication. It relies on the `@actions/*` toolkit libraries and external services (GitHub node-versions manifest, nodejs.org dist mirrors).
The LLM identified 2 files worth highlighting for reuse:
Provides a self-contained function `getNodeVersionFromFile` that parses Node.js version specifications from various file formats (.nvmrc, .node-version, .tool-versions, mise.toml, package.json with volta/engines/devEngines). It can be extracted and reused in any Node.js project that needs to read version constraints from project files. Demonstrates robust handling of multiple formats and edge cases.
Provides a reusable mock implementation of the `@actions/glob` Globber interface for unit testing. Can be extracted and used in any project that uses `@actions/glob` and needs to simulate file globbing in tests. Demonstrates proper implementation of the Globber interface with async generator.