1
0
mirror of https://github.com/actions/setup-node.git synced 2026-02-07 00:35:12 +08:00

Compare commits

...

15 Commits

Author SHA1 Message Date
gowridurgad
b30ec2846d Check failure fix 2026-01-29 16:59:28 +05:30
dependabot[bot]
9799cba2a7 Bump eslint from 8.57.1 to 9.39.2
Bumps [eslint](https://github.com/eslint/eslint) from 8.57.1 to 9.39.2.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Commits](https://github.com/eslint/eslint/compare/v8.57.1...v9.39.2)

---
updated-dependencies:
- dependency-name: eslint
  dependency-version: 9.39.2
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-19 07:34:44 +00:00
aparnajyothi-y
6044e13b5d Docs: bump actions/checkout from v5 to v6 (#1468)
* Update versions.yml

* Update versions.yml

* doc update

* revert vesrions.yml
2026-01-14 21:04:21 -06:00
Panashe Fundira
8e494633d0 Fix README typo (#1226) 2026-01-14 17:08:53 -06:00
Andreas Deininger
621ac41091 README.md: bump to latest released checkout version v6 (#1446) 2026-01-14 17:06:36 -06:00
Salman Chishti
2951748f4c Bump @actions/cache to v5.0.1 (#1449)
* Bump @actions/cache to v5.0.0

This update removes the punycode deprecation warning by updating to a version of @actions/cache that no longer depends on packages using the deprecated punycode module.

* Update license cache for @actions/cache v5.0.0 dependencies

Regenerated license files to reflect the updated dependency tree after bumping @actions/cache to v5.0.0. This includes license information for new transitive dependencies and removes licenses for dependencies that are no longer used.

* Update license metadata for @actions/http-client

Mark @actions/http-client v2.2.1 and v3.0.0 as MIT license (correctly identified from LICENSE file content)

* prepare release 6.0.1

* Bump version to 6.1.1 in package.json and package-lock.json

* fix: update @actions/cache with storage-blob fix for Node.js 24 punycode deprecation

* fix: update @actions/cache to ^5.0.1 for Node.js 24 punycode fix

Updates @actions/cache to version 5.0.1 which includes the @azure/storage-blob
update that fixes the punycode deprecation warning on Node.js 24.

* fix: update @actions/cache to ^5.0.1 for Node.js 24 punycode fix

Updates @actions/cache to version 5.0.1 which includes the @azure/storage-blob
update that fixes the punycode deprecation warning on Node.js 24.
2026-01-13 17:06:04 -06:00
Mike McCready
21ddc7bc1f Correct mirror option typos (#1442) 2026-01-13 10:46:12 -06:00
mahabaleshwars
65d868f8d4 Update Documentation for Lockfile (#1454)
* update documentation for lockfile

* Update adavance usage in README.md

* Documentation update

* Update lockfile documenation

* fix coplilot suggestion
2025-12-18 10:49:55 -06:00
dependabot[bot]
395ad32622 Bump js-yaml from 3.14.1 to 3.14.2 (#1435)
Bumps [js-yaml](https://github.com/nodeca/js-yaml) from 3.14.1 to 3.14.2.
- [Changelog](https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nodeca/js-yaml/compare/3.14.1...3.14.2)

---
updated-dependencies:
- dependency-name: js-yaml
  dependency-version: 3.14.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-02 21:06:19 -06:00
dependabot[bot]
a4d2e2bbca Bump actions/checkout from 5 to 6 (#1439)
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-02 21:03:23 -06:00
Priya Gupta
b9b25d45f7 Remove always-auth configuration handling from action (#1436)
* Remove always-auth configuration handling from setup-node

* docs: update README to note always-auth removal

Update README to mention removal of always-auth input

* Clarify removal of 'always-auth' input in README

Updated the description of the 'always-auth' input removal for clarity.
2025-11-26 11:37:55 -06:00
dependabot[bot]
633bb92bc0 Bump @actions/cache from 4.0.3 to 4.1.0 (#1384)
* Bump @actions/cache from 4.0.3 to 4.1.0

Bumps [@actions/cache](https://github.com/actions/toolkit/tree/HEAD/packages/cache) from 4.0.3 to 4.1.0.
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/cache/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/cache)

---
updated-dependencies:
- dependency-name: "@actions/cache"
  dependency-version: 4.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* check failure fix

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: gowridurgad <gowridurgad@gmail.com>
2025-11-18 14:33:59 -06:00
aparnajyothi-y
dda4788290 Add example for restore-only cache in documentation (#1419)
* Update versions.yml

* Update versions.yml

* doc update

* update

* update

* doc update
2025-10-21 14:44:57 -05:00
Priya Gupta
2028fbc5c2 Limit automatic caching to npm, update workflows and documentation (#1374)
* default to auto-caching only for npm package manager and documentation update

* refactor: enhance package manager detection for auto-caching

* add devEngines.packageManager detection logic for npm auto-caching

* chore: bump version to 6.0.0 and update documentation

* docs: update README and action.yml for npm caching logic clarification

* chore: update Node.js version in workflows

* chore: update Node.js versions in versions.yml

* chore: update rc Node.js version in versions.yml

* chore: switch macos-13 runner to macos-latest-large in workflow

* docs: update README and advanced usage documentation
2025-10-13 21:37:06 -05:00
dependabot[bot]
13427813f7 Bump actions/publish-action from 0.3.0 to 0.4.0 (#1362)
Bumps [actions/publish-action](https://github.com/actions/publish-action) from 0.3.0 to 0.4.0.
- [Commits](https://github.com/actions/publish-action/compare/v0.3.0...v0.4.0)

---
updated-dependencies:
- dependency-name: actions/publish-action
  dependency-version: 0.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-08 09:32:50 -05:00
94 changed files with 96785 additions and 104219 deletions

View File

@@ -16,4 +16,4 @@ jobs:
name: Check dist/ name: Check dist/
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
with: with:
node-version: '20.x' node-version: '24.x'

View File

@@ -18,10 +18,10 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [18, 20, 22, 24] node-version: [20, 22, 24]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Clean global cache - name: Clean global cache
run: npm cache clean --force run: npm cache clean --force
- name: Setup Node - name: Setup Node
@@ -41,10 +41,10 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [18, 20, 22, 24] node-version: [20, 22, 24]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Install pnpm - name: Install pnpm
uses: pnpm/action-setup@v4 uses: pnpm/action-setup@v4
with: with:
@@ -74,10 +74,10 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [18, 20, 24] node-version: [20, 22, 24]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Yarn version - name: Yarn version
run: yarn --version run: yarn --version
- name: Generate yarn file - name: Generate yarn file
@@ -106,10 +106,10 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [18, 20, 22, 24] node-version: [20, 22, 24]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Update yarn - name: Update yarn
run: yarn set version 3.6.4 run: yarn set version 3.6.4
- name: Yarn version - name: Yarn version
@@ -139,11 +139,11 @@ jobs:
name: Test yarn subprojects name: Test yarn subprojects
strategy: strategy:
matrix: matrix:
node-version: [18, 20, 22, 24] node-version: [20, 22, 24]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: prepare sub-projects - name: prepare sub-projects
run: __tests__/prepare-yarn-subprojects.sh yarn1 run: __tests__/prepare-yarn-subprojects.sh yarn1
@@ -166,11 +166,11 @@ jobs:
name: Test yarn subprojects all locally managed name: Test yarn subprojects all locally managed
strategy: strategy:
matrix: matrix:
node-version: [18, 20, 22, 24] node-version: [20, 22, 24]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: prepare sub-projects - name: prepare sub-projects
run: __tests__/prepare-yarn-subprojects.sh keepcache keepcache run: __tests__/prepare-yarn-subprojects.sh keepcache keepcache
@@ -193,11 +193,11 @@ jobs:
name: Test yarn subprojects some locally managed name: Test yarn subprojects some locally managed
strategy: strategy:
matrix: matrix:
node-version: [18, 20, 22, 24] node-version: [20, 22, 24]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: prepare sub-projects - name: prepare sub-projects
run: __tests__/prepare-yarn-subprojects.sh global run: __tests__/prepare-yarn-subprojects.sh global
@@ -220,11 +220,11 @@ jobs:
name: Test yarn subprojects managed by git name: Test yarn subprojects managed by git
strategy: strategy:
matrix: matrix:
node-version: [18, 20, 22, 24] node-version: [20, 22, 24]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: prepare sub-projects - name: prepare sub-projects
run: /bin/bash __tests__/prepare-yarn-subprojects.sh keepcache run: /bin/bash __tests__/prepare-yarn-subprojects.sh keepcache
@@ -244,16 +244,16 @@ jobs:
sub2/*.lock sub2/*.lock
sub3/*.lock sub3/*.lock
node-npm-package-manager-cache: node-npm-packageManager-auto-cache:
name: Test enabling cache if package manager field is present (Node ${{ matrix.node-version }}, ${{ matrix.os }}) name: Test auto cache with top-level packageManager
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [18, 20, 22] node-version: [20, 22, 24]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Create package.json with packageManager field - name: Create package.json with packageManager field
run: | run: |
echo '{ "name": "test-project", "version": "1.0.0", "packageManager": "npm@8.0.0" }' > package.json echo '{ "name": "test-project", "version": "1.0.0", "packageManager": "npm@8.0.0" }' > package.json
@@ -268,3 +268,37 @@ jobs:
- name: Verify node and npm - name: Verify node and npm
run: __tests__/verify-node.sh "${{ matrix.node-version }}" run: __tests__/verify-node.sh "${{ matrix.node-version }}"
shell: bash shell: bash
node-npm-devEngines-auto-cache:
name: Test auto cache with devEngines.packageManager
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [20, 22, 24]
steps:
- uses: actions/checkout@v6
- name: Create package.json with devEngines field
run: |
echo '{
"name": "test-project",
"version": "1.0.0",
"devEngines": {
"packageManager": {
"name": "npm",
"onFail": "error"
}
}
}' > package.json
- name: Clean global cache
run: npm cache clean --force
- name: Setup Node with caching enabled
uses: ./
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Verify node and npm
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
shell: bash

View File

@@ -25,15 +25,15 @@ jobs:
env: env:
https_proxy: http://squid-proxy:3128 https_proxy: http://squid-proxy:3128
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Clear tool cache - name: Clear tool cache
run: rm -rf $RUNNER_TOOL_CACHE/* run: rm -rf $RUNNER_TOOL_CACHE/*
- name: Setup node 14 - name: Setup node 24
uses: ./ uses: ./
with: with:
node-version: 14.x node-version: 24.x
- name: Verify node and npm - name: Verify node and npm
run: __tests__/verify-node.sh 14 run: __tests__/verify-node.sh 24
test-bypass-proxy: test-bypass-proxy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -41,12 +41,12 @@ jobs:
https_proxy: http://no-such-proxy:3128 https_proxy: http://no-such-proxy:3128
no_proxy: api.github.com,github.com,nodejs.org,registry.npmjs.org,*.s3.amazonaws.com,s3.amazonaws.com no_proxy: api.github.com,github.com,nodejs.org,registry.npmjs.org,*.s3.amazonaws.com,s3.amazonaws.com
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Clear tool cache - name: Clear tool cache
run: rm -rf $RUNNER_TOOL_CACHE/* run: rm -rf $RUNNER_TOOL_CACHE/*
- name: Setup node 11 - name: Setup node 24
uses: ./ uses: ./
with: with:
node-version: 11 node-version: 24
- name: Verify node and npm - name: Verify node and npm
run: __tests__/verify-node.sh 11 run: __tests__/verify-node.sh 24

View File

@@ -14,7 +14,7 @@ jobs:
steps: steps:
- name: Checking out - name: Checking out
uses: actions/checkout@v5 uses: actions/checkout@v6
- name: Publish - name: Publish
id: publish id: publish
uses: actions/publish-immutable-action@v0.0.4 uses: actions/publish-immutable-action@v0.0.4

View File

@@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Update the ${{ env.TAG_NAME }} tag - name: Update the ${{ env.TAG_NAME }} tag
uses: actions/publish-action@v0.3.0 uses: actions/publish-action@v0.4.0
with: with:
source-tag: ${{ env.TAG_NAME }} source-tag: ${{ env.TAG_NAME }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }} slack-webhook: ${{ secrets.SLACK_WEBHOOK }}

View File

@@ -17,10 +17,10 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [18, 20, 22, 24] node-version: [20, 22, 24]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup Node - name: Setup Node
uses: ./ uses: ./
with: with:
@@ -34,10 +34,10 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest-large]
node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1] node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup Node - name: Setup Node
uses: ./ uses: ./
with: with:
@@ -56,7 +56,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: node-version:
[ [
'20-v8-canary', '20-v8-canary',
@@ -64,7 +64,7 @@ jobs:
'20.0.0-v8-canary20221101e50e45c9f8' '20.0.0-v8-canary20221101e50e45c9f8'
] ]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup Node - name: Setup Node
uses: ./ uses: ./
with: with:
@@ -81,10 +81,10 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [20-nightly, 21-nightly, 18.0.0-nightly] node-version: [20-nightly, 25-nightly, 24.0.0-nightly]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup Node - name: Setup Node
uses: ./ uses: ./
with: with:
@@ -101,10 +101,10 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [20.0.0-rc.1, 18.0.0-rc.2, 19.0.0-rc.0] node-version: [20.0.0-rc.1, 22.14.0-rc.1, 24.0.0-rc.4]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup Node - name: Setup Node
uses: ./ uses: ./
with: with:
@@ -121,10 +121,10 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [18.20.0, 20.10.0, 22.0.0] node-version: [20.10.0, 22.0.0, 24.9.0]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup Node - name: Setup Node
uses: ./ uses: ./
with: with:
@@ -138,10 +138,10 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [18, 20, 22, 24] node-version: [20, 22, 24]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup Node and check latest - name: Setup Node and check latest
uses: ./ uses: ./
with: with:
@@ -156,11 +156,11 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version-file: node-version-file:
[.nvmrc, .tool-versions, .tool-versions-node, package.json] [.nvmrc, .tool-versions, .tool-versions-node, package.json]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup node from node version file - name: Setup node from node version file
uses: ./ uses: ./
with: with:
@@ -173,9 +173,9 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup node from node version file - name: Setup node from node version file
uses: ./ uses: ./
with: with:
@@ -188,9 +188,9 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup node from node version file - name: Setup node from node version file
uses: ./ uses: ./
with: with:
@@ -203,10 +203,10 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [17, 19] node-version: [17, 19]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup Node from dist - name: Setup Node from dist
uses: ./ uses: ./
with: with:
@@ -220,9 +220,9 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest-large]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
# test old versions which didn't have npm and layout different # test old versions which didn't have npm and layout different
- name: Setup node 0.12.18 from dist - name: Setup node 0.12.18 from dist
uses: ./ uses: ./
@@ -235,7 +235,7 @@ jobs:
arch: arch:
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup node 20 x86 from dist - name: Setup node 20 x86 from dist
uses: ./ uses: ./
with: with:
@@ -250,7 +250,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
node-version: [current, latest, node] node-version: [current, latest, node]
steps: steps:
- name: Get node version - name: Get node version
@@ -259,7 +259,7 @@ jobs:
echo "LATEST_NODE_VERSION=$latestNodeVersion" >> $GITHUB_OUTPUT echo "LATEST_NODE_VERSION=$latestNodeVersion" >> $GITHUB_OUTPUT
id: version id: version
shell: bash shell: bash
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup Node - name: Setup Node
uses: ./ uses: ./
with: with:

Binary file not shown.

Binary file not shown.

BIN
.licenses/npm/@actions/io-2.0.0.dep.yml generated Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
.licenses/npm/debug.dep.yml generated Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
.licenses/npm/tslib.dep.yml generated Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

108
README.md
View File

@@ -12,7 +12,13 @@ This action provides the following functionality for GitHub Actions users:
- Registering problem matchers for error output - Registering problem matchers for error output
- Configuring authentication for GPR or npm - Configuring authentication for GPR or npm
## Breaking changes in V5 ## Breaking changes in V6
- Caching is now automatically enabled for npm projects when either the `devEngines.packageManager` field or the top-level `packageManager` field in `package.json` is set to `npm`. For other package managers, such as Yarn and pnpm, caching is disabled by default and must be configured manually using the `cache` input.
- The `always-auth` input has been removed, as it is deprecated and will no longer be supported in future npm releases. To ensure your workflows continue to run without warnings or errors, please remove any references to `always-auth` from your configuration.
## Breaking changes in V5
- Enabled caching by default with package manager detection if no cache input is provided. - Enabled caching by default with package manager detection if no cache input is provided.
> For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching by setting `package-manager-cache: false` when caching is not needed for secure operation. > For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching by setting `package-manager-cache: false` when caching is not needed for secure operation.
@@ -28,7 +34,7 @@ See [action.yml](action.yml)
<!-- start usage --> <!-- start usage -->
```yaml ```yaml
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
# Version Spec of the version to use in SemVer notation. # Version Spec of the version to use in SemVer notation.
# It also admits such aliases as lts/*, latest, nightly and canary builds # It also admits such aliases as lts/*, latest, nightly and canary builds
@@ -36,22 +42,22 @@ See [action.yml](action.yml)
node-version: '' node-version: ''
# File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions. # File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.
# If node-version and node-version-file are both provided the action will use version from node-version. # If node-version and node-version-file are both provided the action will use version from node-version.
node-version-file: '' node-version-file: ''
# Set this option if you want the action to check for the latest available version # Set this option if you want the action to check for the latest available version
# that satisfies the version spec. # that satisfies the version spec.
# It will only get affect for lts Nodejs versions (12.x, >=10.15.0, lts/Hydrogen). # It will only get affect for lts Nodejs versions (12.x, >=10.15.0, lts/Hydrogen).
# Default: false # Default: false
check-latest: false check-latest: false
# Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default. # Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.
# Default: ''. The action use system architecture by default # Default: ''. The action use system architecture by default
architecture: '' architecture: ''
# Used to pull node distributions from https://github.com/actions/node-versions. # Used to pull node distributions from https://github.com/actions/node-versions.
# Since there's a default, this is typically not supplied by the user. # Since there's a default, this is typically not supplied by the user.
# When running this action on github.com, the default value is sufficient. # When running this action on github.com, the default value is sufficient.
# When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. # When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
# #
# We recommend using a service account with the least permissions necessary. Also # We recommend using a service account with the least permissions necessary. Also
@@ -67,34 +73,31 @@ See [action.yml](action.yml)
# Default: '' # Default: ''
cache: '' cache: ''
# Used to disable automatic caching based on the package manager field in package.json. By default, caching is enabled if the package manager field is present and no cache input is provided' # Controls automatic caching for npm. By default, caching for npm is enabled if either the devEngines.packageManager field or the top-level packageManager field in package.json specifies npm and no explicit cache input is provided.
# To disable automatic caching for npm, set package-manager-cache to false.
# default: true # default: true
package-manager-cache: true package-manager-cache: true
# Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. # Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc.
# It will generate hash from the target file for primary key. It works only If cache is specified. # It will generate hash from the target file for primary key. It works only If cache is specified.
# Supports wildcards or a list of file names for caching multiple dependencies. # Supports wildcards or a list of file names for caching multiple dependencies.
# Default: '' # Default: ''
cache-dependency-path: '' cache-dependency-path: ''
# Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, # Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file,
# and set up auth to read in from env.NODE_AUTH_TOKEN. # and set up auth to read in from env.NODE_AUTH_TOKEN.
# Default: '' # Default: ''
registry-url: '' registry-url: ''
# Optional scope for authenticating against scoped registries. # Optional scope for authenticating against scoped registries.
# Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/). # Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/).
# Default: '' # Default: ''
scope: '' scope: ''
# Set always-auth option in npmrc file.
# Default: ''
always-auth: ''
# Optional mirror to download binaries from. # Optional mirror to download binaries from.
# Artifacts need to match the official Node.js # Artifacts need to match the official Node.js
# Example: # Example:
# V8 Canaray Build: <mirror_url>/download/v8-canary # V8 Canary Build: <mirror_url>/download/v8-canary
# RC Build: <mirror_url>/download/rc # RC Build: <mirror_url>/download/rc
# Official: Build <mirror_url>/dist # Official: Build <mirror_url>/dist
# Nightly build: <mirror_url>/download/nightly # Nightly build: <mirror_url>/download/nightly
@@ -112,15 +115,15 @@ See [action.yml](action.yml)
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: 18 node-version: 24
- run: npm ci - run: npm ci
- run: npm test - run: npm test
``` ```
The `node-version` input is optional. If not supplied, the node version from PATH will be used. However, it is recommended to always specify Node.js version and don't rely on the system one. The `node-version` input is optional. If not supplied, the node version from PATH will be used. However, it is recommended to always specify Node.js version and not rely on the system one.
The action will first check the local cache for a semver match. If unable to find a specific version in the cache, the action will attempt to download a version of Node.js. It will pull LTS versions from [node-versions releases](https://github.com/actions/node-versions/releases) and on miss or failure will fall back to the previous behavior of downloading directly from [node dist](https://nodejs.org/dist/). The action will first check the local cache for a semver match. If unable to find a specific version in the cache, the action will attempt to download a version of Node.js. It will pull LTS versions from [node-versions releases](https://github.com/actions/node-versions/releases) and on miss or failure will fall back to the previous behavior of downloading directly from [node dist](https://nodejs.org/dist/).
@@ -132,9 +135,9 @@ The `node-version` input supports the Semantic Versioning Specification, for mor
Examples: Examples:
- Major versions: `18`, `20` - Major versions: `22`, `24`
- More specific versions: `10.15`, `16.15.1` , `18.4.0` - More specific versions: `20.19`, `22.17.1` , `24.8.0`
- NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n` - NVM LTS syntax: `lts/iron`, `lts/jod`, `lts/*`, `lts/-n`
- Latest release: `*` or `latest`/`current`/`node` - Latest release: `*` or `latest`/`current`/`node`
**Note:** Like the other values, `*` will get the latest [locally-cached Node.js version](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#nodejs), or the latest version from [actions/node-versions](https://github.com/actions/node-versions/blob/main/versions-manifest.json), depending on the [`check-latest`](docs/advanced-usage.md#check-latest-version) input. **Note:** Like the other values, `*` will get the latest [locally-cached Node.js version](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#nodejs), or the latest version from [actions/node-versions](https://github.com/actions/node-versions/blob/main/versions-manifest.json), depending on the [`check-latest`](docs/advanced-usage.md#check-latest-version) input.
@@ -145,24 +148,12 @@ Since it will not be cached always, there is possibility of hitting rate limit w
### Checking in lockfiles ### Checking in lockfiles
It's **always** recommended to commit the lockfile of your package manager for security and performance reasons. For more information consult the "Working with lockfiles" section of the [Advanced usage](docs/advanced-usage.md#working-with-lockfiles) guide. It's **strongly recommended** to commit the lockfile of your package manager for security and performance reasons. For more information consult the "Working with lockfiles" section of the [Advanced usage](docs/advanced-usage.md#working-with-lockfiles) guide.
## Caching global packages data ## Caching global packages data
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under the hood for caching global packages data but requires less configuration settings. Supported package managers are `npm`, `yarn`, `pnpm` (v6.10+). The `cache` input is optional. The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under the hood for caching global packages data but requires less configuration settings. Supported package managers are `npm`, `yarn`, `pnpm` (v6.10+). The `cache` input is optional.
Caching is turned on by default when a `packageManager` field is detected in the `package.json` file and no `cache` input is provided. The `package-manager-cache` input provides control over this automatic caching behavior. By default, `package-manager-cache` is set to `true`, which enables caching when a valid package manager field is detected in the `package.json` file. To disable this automatic caching, set the `package-manager-cache` input to `false`.
```yaml
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
package-manager-cache: false
- run: npm ci
```
> If no valid `packageManager` field is detected in the `package.json` file, caching will remain disabled unless explicitly configured. For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching by setting `package-manager-cache: false` when caching is not needed for secure operation.
The action defaults to search for the dependency file (`package-lock.json`, `npm-shrinkwrap.json` or `yarn.lock`) in the repository root, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases when multiple dependency files are used, or they are located in different subdirectories. The action defaults to search for the dependency file (`package-lock.json`, `npm-shrinkwrap.json` or `yarn.lock`) in the repository root, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases when multiple dependency files are used, or they are located in different subdirectories.
**Note:** The action does not cache `node_modules` **Note:** The action does not cache `node_modules`
@@ -173,10 +164,10 @@ See the examples of using cache for `yarn`/`pnpm` and `cache-dependency-path` in
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: 20 node-version: 24
cache: 'npm' cache: 'npm'
- run: npm ci - run: npm ci
- run: npm test - run: npm test
@@ -186,16 +177,30 @@ steps:
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: 20 node-version: 24
cache: 'npm' cache: 'npm'
cache-dependency-path: subdir/package-lock.json cache-dependency-path: subdir/package-lock.json
- run: npm ci - run: npm ci
- run: npm test - run: npm test
``` ```
Caching for npm dependencies is automatically enabled when your `package.json` contains either `devEngines.packageManager` field or top-level `packageManager` field set to `npm`, and no explicit cache input is provided.
This behavior is controlled by the `package-manager-cache` input, which defaults to `true`. To turn off automatic caching, set `package-manager-cache` to `false`.
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
package-manager-cache: false
- run: npm ci
```
> If your `package.json` file does not include a `packageManager` field set to `npm`, caching will be disabled unless you explicitly enable it. For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching for npm by setting `package-manager-cache: false` when caching is not required for secure operation.
## Matrix Testing ## Matrix Testing
```yaml ```yaml
@@ -204,12 +209,12 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
node: [ 14, 16, 18 ] node: [ 20, 22, 24 ]
name: Node ${{ matrix.node }} sample name: Node ${{ matrix.node }} sample
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup node - name: Setup node
uses: actions/setup-node@v5 uses: actions/setup-node@v6
with: with:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
- run: npm ci - run: npm ci
@@ -223,10 +228,10 @@ jobs:
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action: To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action:
```yaml ```yaml
uses: actions/setup-node@v5 uses: actions/setup-node@v6
with: with:
token: ${{ secrets.GH_DOTCOM_TOKEN }} token: ${{ secrets.GH_DOTCOM_TOKEN }}
node-version: 20 node-version: 24
``` ```
If the runner is not able to access github.com, any Nodejs versions requested during a workflow run must come from the runner's tool cache. See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/enterprise-server@3.2/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)" for more information. If the runner is not able to access github.com, any Nodejs versions requested during a workflow run must come from the runner's tool cache. See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/enterprise-server@3.2/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)" for more information.
@@ -244,6 +249,7 @@ If the runner is not able to access github.com, any Nodejs versions requested du
- [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm) - [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm)
- [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn) - [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn)
- [Using private packages](docs/advanced-usage.md#use-private-packages) - [Using private packages](docs/advanced-usage.md#use-private-packages)
- [Using private mirror](docs/advanced-usage.md#use-private-mirror)
## Recommended permissions ## Recommended permissions
@@ -264,4 +270,4 @@ Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
## Code of Conduct ## Code of Conduct
:wave: Be nice. See [our code of conduct](CODE_OF_CONDUCT.md) :wave: Be nice. See [our code of conduct](CODE_OF_CONDUCT.md)

View File

@@ -76,115 +76,102 @@ describe('authutil tests', () => {
} }
it('Sets up npmrc for npmjs', async () => { it('Sets up npmrc for npmjs', async () => {
await auth.configAuthentication('https://registry.npmjs.org/', 'false'); await auth.configAuthentication('https://registry.npmjs.org/');
expect(fs.statSync(rcFile)).toBeDefined(); expect(fs.statSync(rcFile)).toBeDefined();
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
const rc = readRcFile(rcFile); const rc = readRcFile(rcFile);
expect(rc['registry']).toBe('https://registry.npmjs.org/'); expect(rc['registry']).toBe('https://registry.npmjs.org/');
expect(rc['always-auth']).toBe('false');
}); });
it('Appends trailing slash to registry', async () => { it('Appends trailing slash to registry', async () => {
await auth.configAuthentication('https://registry.npmjs.org', 'false'); await auth.configAuthentication('https://registry.npmjs.org');
expect(fs.statSync(rcFile)).toBeDefined(); expect(fs.statSync(rcFile)).toBeDefined();
const rc = readRcFile(rcFile); const rc = readRcFile(rcFile);
expect(rc['registry']).toBe('https://registry.npmjs.org/'); expect(rc['registry']).toBe('https://registry.npmjs.org/');
expect(rc['always-auth']).toBe('false');
}); });
it('Configures scoped npm registries', async () => { it('Configures scoped npm registries', async () => {
process.env['INPUT_SCOPE'] = 'myScope'; process.env['INPUT_SCOPE'] = 'myScope';
await auth.configAuthentication('https://registry.npmjs.org', 'false'); await auth.configAuthentication('https://registry.npmjs.org');
expect(fs.statSync(rcFile)).toBeDefined(); expect(fs.statSync(rcFile)).toBeDefined();
const rc = readRcFile(rcFile); const rc = readRcFile(rcFile);
expect(rc['@myscope:registry']).toBe('https://registry.npmjs.org/'); expect(rc['@myscope:registry']).toBe('https://registry.npmjs.org/');
expect(rc['always-auth']).toBe('false');
}); });
it('Automatically configures GPR scope', async () => { it('Automatically configures GPR scope', async () => {
await auth.configAuthentication('npm.pkg.github.com', 'false'); await auth.configAuthentication('npm.pkg.github.com');
expect(fs.statSync(rcFile)).toBeDefined(); expect(fs.statSync(rcFile)).toBeDefined();
const rc = readRcFile(rcFile); const rc = readRcFile(rcFile);
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/'); expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
expect(rc['always-auth']).toBe('false');
});
it('Sets up npmrc for always-auth true', async () => {
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
expect(fs.statSync(rcFile)).toBeDefined();
const rc = readRcFile(rcFile);
expect(rc['registry']).toBe('https://registry.npmjs.org/');
expect(rc['always-auth']).toBe('true');
}); });
it('is already set the NODE_AUTH_TOKEN export it', async () => { it('is already set the NODE_AUTH_TOKEN export it', async () => {
process.env.NODE_AUTH_TOKEN = 'foobar'; process.env.NODE_AUTH_TOKEN = 'foobar';
await auth.configAuthentication('npm.pkg.github.com', 'false'); await auth.configAuthentication('npm.pkg.github.com');
expect(fs.statSync(rcFile)).toBeDefined(); expect(fs.statSync(rcFile)).toBeDefined();
const rc = readRcFile(rcFile); const rc = readRcFile(rcFile);
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/'); expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
expect(rc['always-auth']).toBe('false');
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar'); expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
}); });
it('configAuthentication should overwrite non-scoped with non-scoped', async () => { it('configAuthentication should overwrite non-scoped with non-scoped', async () => {
fs.writeFileSync(rcFile, 'registry=NNN'); fs.writeFileSync(rcFile, 'registry=NNN');
await auth.configAuthentication('https://registry.npmjs.org/', 'true'); await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe( expect(contents).toBe(
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true` `//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/`
); );
}); });
it('configAuthentication should overwrite only non-scoped', async () => { it('configAuthentication should overwrite only non-scoped', async () => {
fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`); fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true'); await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe( expect(contents).toBe(
`@myscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true` `@myscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/`
); );
}); });
it('configAuthentication should add non-scoped to scoped', async () => { it('configAuthentication should add non-scoped to scoped', async () => {
fs.writeFileSync(rcFile, '@myscope:registry=NNN'); fs.writeFileSync(rcFile, '@myscope:registry=NNN');
await auth.configAuthentication('https://registry.npmjs.org/', 'true'); await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe( expect(contents).toBe(
`@myscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true` `@myscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/`
); );
}); });
it('configAuthentication should overwrite scoped with scoped', async () => { it('configAuthentication should overwrite scoped with scoped', async () => {
process.env['INPUT_SCOPE'] = 'myscope'; process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(rcFile, `@myscope:registry=NNN`); fs.writeFileSync(rcFile, `@myscope:registry=NNN`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true'); await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe( expect(contents).toBe(
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true` `//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
); );
}); });
it('configAuthentication should overwrite only scoped', async () => { it('configAuthentication should overwrite only scoped', async () => {
process.env['INPUT_SCOPE'] = 'myscope'; process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`); fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true'); await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe( expect(contents).toBe(
`registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true` `registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
); );
}); });
it('configAuthentication should add scoped to non-scoped', async () => { it('configAuthentication should add scoped to non-scoped', async () => {
process.env['INPUT_SCOPE'] = 'myscope'; process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(rcFile, `registry=MMM`); fs.writeFileSync(rcFile, `registry=MMM`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true'); await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe( expect(contents).toBe(
`registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true` `registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
); );
}); });
@@ -194,20 +181,20 @@ describe('authutil tests', () => {
rcFile, rcFile,
`@otherscope:registry=NNN${os.EOL}@myscope:registry=MMM` `@otherscope:registry=NNN${os.EOL}@myscope:registry=MMM`
); );
await auth.configAuthentication('https://registry.npmjs.org/', 'true'); await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe( expect(contents).toBe(
`@otherscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true` `@otherscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
); );
}); });
it('configAuthentication should add scoped to another scoped', async () => { it('configAuthentication should add scoped to another scoped', async () => {
process.env['INPUT_SCOPE'] = 'myscope'; process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(rcFile, `@otherscope:registry=MMM`); fs.writeFileSync(rcFile, `@otherscope:registry=MMM`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true'); await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe( expect(contents).toBe(
`@otherscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true` `@otherscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
); );
}); });
}); });

View File

@@ -227,7 +227,6 @@ describe('setup-node', () => {
const versionSpec = '11.15.0'; const versionSpec = '11.15.0';
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
// ... but not in the local cache // ... but not in the local cache
@@ -283,7 +282,6 @@ describe('setup-node', () => {
const versionSpec = '19.0.0-v8-canary'; const versionSpec = '19.0.0-v8-canary';
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
@@ -324,7 +322,6 @@ describe('setup-node', () => {
inputs['node-version'] = version; inputs['node-version'] = version;
inputs['architecture'] = arch; inputs['architecture'] = arch;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
const expectedUrl = `https://nodejs.org/download/v8-canary/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`; const expectedUrl = `https://nodejs.org/download/v8-canary/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`;
@@ -569,7 +566,6 @@ describe('setup-node', () => {
const versionSpec = 'v20-v8-canary'; const versionSpec = 'v20-v8-canary';
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
os.platform = 'linux'; os.platform = 'linux';

View File

@@ -285,34 +285,124 @@ describe('main tests', () => {
}); });
describe('cache feature tests', () => { describe('cache feature tests', () => {
it('Should enable caching with the resolved package manager from packageManager field in package.json when the cache input is not provided', async () => { it('Should enable caching when packageManager is npm and cache input is not provided', async () => {
inputs['package-manager-cache'] = 'true'; inputs['package-manager-cache'] = 'true';
inputs['cache'] = ''; // No cache input is provided inputs['cache'] = '';
isCacheActionAvailable.mockImplementation(() => true);
inSpy.mockImplementation(name => inputs[name]); inSpy.mockImplementation(name => inputs[name]);
const readFileSpy = jest.spyOn(fs, 'readFileSync'); const readFileSpy = jest.spyOn(fs, 'readFileSync');
readFileSpy.mockImplementation(() => readFileSpy.mockImplementation(() =>
JSON.stringify({ JSON.stringify({
packageManager: 'yarn@3.2.0' packageManager: 'npm@10.8.2'
}) })
); );
await main.run(); await main.run();
expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'yarn'); expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm');
}); });
it('Should not enable caching if the packageManager field is missing in package.json and the cache input is not provided', async () => { it('Should enable caching when devEngines.packageManager.name is "npm" and cache input is not provided', async () => {
inputs['package-manager-cache'] = 'true'; inputs['package-manager-cache'] = 'true';
inputs['cache'] = ''; // No cache input is provided inputs['cache'] = '';
isCacheActionAvailable.mockImplementation(() => true);
inSpy.mockImplementation(name => inputs[name]); inSpy.mockImplementation(name => inputs[name]);
const readFileSpy = jest.spyOn(fs, 'readFileSync'); const readFileSpy = jest.spyOn(fs, 'readFileSync');
readFileSpy.mockImplementation(() => readFileSpy.mockImplementation(() =>
JSON.stringify({ JSON.stringify({
//packageManager field is not present devEngines: {
packageManager: {name: 'npm'}
}
})
);
await main.run();
expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm');
});
it('Should enable caching when devEngines.packageManager is array and one entry has name "npm"', async () => {
inputs['package-manager-cache'] = 'true';
inputs['cache'] = '';
isCacheActionAvailable.mockImplementation(() => true);
inSpy.mockImplementation(name => inputs[name]);
const readFileSpy = jest.spyOn(fs, 'readFileSync');
readFileSpy.mockImplementation(() =>
JSON.stringify({
devEngines: {
packageManager: [{name: 'pnpm'}, {name: 'npm'}]
}
})
);
await main.run();
expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm');
});
it('Should not enable caching if packageManager is "pnpm@8.0.0" and cache input is not provided', async () => {
inputs['package-manager-cache'] = 'true';
inputs['cache'] = '';
inSpy.mockImplementation(name => inputs[name]);
const readFileSpy = jest.spyOn(fs, 'readFileSync');
readFileSpy.mockImplementation(() =>
JSON.stringify({
packageManager: 'pnpm@8.0.0'
})
);
await main.run();
expect(saveStateSpy).not.toHaveBeenCalled();
});
it('Should not enable caching if devEngines.packageManager.name is "pnpm"', async () => {
inputs['package-manager-cache'] = 'true';
inputs['cache'] = '';
inSpy.mockImplementation(name => inputs[name]);
const readFileSpy = jest.spyOn(fs, 'readFileSync');
readFileSpy.mockImplementation(() =>
JSON.stringify({
devEngines: {
packageManager: {name: 'pnpm'}
}
})
);
await main.run();
expect(saveStateSpy).not.toHaveBeenCalled();
});
it('Should not enable caching if devEngines.packageManager is array without "npm"', async () => {
inputs['package-manager-cache'] = 'true';
inputs['cache'] = '';
inSpy.mockImplementation(name => inputs[name]);
const readFileSpy = jest.spyOn(fs, 'readFileSync');
readFileSpy.mockImplementation(() =>
JSON.stringify({
devEngines: {
packageManager: [{name: 'pnpm'}, {name: 'yarn'}]
}
})
);
await main.run();
expect(saveStateSpy).not.toHaveBeenCalled();
});
it('Should not enable caching if packageManager field is missing in package.json and cache input is not provided', async () => {
inputs['package-manager-cache'] = 'true';
inputs['cache'] = '';
inSpy.mockImplementation(name => inputs[name]);
const readFileSpy = jest.spyOn(fs, 'readFileSync');
readFileSpy.mockImplementation(() =>
JSON.stringify({
// packageManager field is not present
}) })
); );
@@ -323,24 +413,18 @@ describe('main tests', () => {
it('Should skip caching when package-manager-cache is false', async () => { it('Should skip caching when package-manager-cache is false', async () => {
inputs['package-manager-cache'] = 'false'; inputs['package-manager-cache'] = 'false';
inputs['cache'] = ''; // No cache input is provided inputs['cache'] = '';
inSpy.mockImplementation(name => inputs[name]); inSpy.mockImplementation(name => inputs[name]);
await main.run(); await main.run();
expect(saveStateSpy).not.toHaveBeenCalled(); expect(saveStateSpy).not.toHaveBeenCalled();
}); });
it('Should enable caching with cache input explicitly provided', async () => { it('Should enable caching with cache input explicitly provided', async () => {
inputs['package-manager-cache'] = 'true'; inputs['package-manager-cache'] = 'true';
inputs['cache'] = 'npm'; // Explicit cache input provided inputs['cache'] = 'npm';
inSpy.mockImplementation(name => inputs[name]); inSpy.mockImplementation(name => inputs[name]);
isCacheActionAvailable.mockReturnValue(true); isCacheActionAvailable.mockImplementation(() => true);
await main.run(); await main.run();
expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm'); expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm');
}); });
}); });

View File

@@ -255,7 +255,6 @@ describe('setup-node', () => {
const versionSpec = '13.13.1-nightly20200415947ddec091'; const versionSpec = '13.13.1-nightly20200415947ddec091';
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
// ... but not in the local cache // ... but not in the local cache
@@ -291,7 +290,6 @@ describe('setup-node', () => {
]; ];
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
// ... but not in the local cache // ... but not in the local cache
@@ -333,7 +331,6 @@ describe('setup-node', () => {
]; ];
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
// ... but not in the local cache // ... but not in the local cache
@@ -389,7 +386,6 @@ describe('setup-node', () => {
const versionSpec = '18.0.0-nightly202204180699150267'; const versionSpec = '18.0.0-nightly202204180699150267';
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
@@ -427,7 +423,6 @@ describe('setup-node', () => {
inputs['node-version'] = version; inputs['node-version'] = version;
inputs['architecture'] = arch; inputs['architecture'] = arch;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
const expectedUrl = `https://nodejs.org/download/nightly/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`; const expectedUrl = `https://nodejs.org/download/nightly/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`;
@@ -473,7 +468,6 @@ describe('setup-node', () => {
inputs['node-version'] = version; inputs['node-version'] = version;
inputs['architecture'] = arch; inputs['architecture'] = arch;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
inputs['mirror'] = 'https://my-mirror.org'; inputs['mirror'] = 'https://my-mirror.org';
inputs['mirror-token'] = 'my-mirror-token'; inputs['mirror-token'] = 'my-mirror-token';

View File

@@ -235,7 +235,6 @@ describe('setup-node', () => {
const resolvedVersion = versionSpec; const resolvedVersion = versionSpec;
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
const expectedUrl = const expectedUrl =
@@ -290,7 +289,6 @@ describe('setup-node', () => {
const versionSpec = '11.15.0'; const versionSpec = '11.15.0';
const mirror = 'https://my_mirror_url'; const mirror = 'https://my_mirror_url';
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
inputs['mirror'] = mirror; inputs['mirror'] = mirror;
inputs['mirror-token'] = 'faketoken'; inputs['mirror-token'] = 'faketoken';
@@ -327,7 +325,6 @@ describe('setup-node', () => {
const versionSpec = '11.15.0'; const versionSpec = '11.15.0';
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
// ... but not in the local cache // ... but not in the local cache
@@ -385,7 +382,6 @@ describe('setup-node', () => {
const resolvedVersion = versionSpec; const resolvedVersion = versionSpec;
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
@@ -405,7 +401,6 @@ describe('setup-node', () => {
const versionSpec = '11.15.0'; const versionSpec = '11.15.0';
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
// ... but not in the local cache // ... but not in the local cache
@@ -448,7 +443,6 @@ describe('setup-node', () => {
inputs['node-version'] = version; inputs['node-version'] = version;
inputs['architecture'] = arch; inputs['architecture'] = arch;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
const expectedUrl = const expectedUrl =
@@ -560,7 +554,6 @@ describe('setup-node', () => {
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['check-latest'] = 'true'; inputs['check-latest'] = 'true';
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
// ... but not in the local cache // ... but not in the local cache
@@ -602,7 +595,6 @@ describe('setup-node', () => {
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['check-latest'] = 'true'; inputs['check-latest'] = 'true';
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
// ... but not in the local cache // ... but not in the local cache
@@ -882,7 +874,6 @@ describe('setup-node', () => {
inputs['node-version'] = version; inputs['node-version'] = version;
inputs['architecture'] = arch; inputs['architecture'] = arch;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
inputs['mirror'] = 'https://my_mirror_url'; inputs['mirror'] = 'https://my_mirror_url';
inputs['mirror-token'] = 'faketoken'; inputs['mirror-token'] = 'faketoken';

View File

@@ -194,7 +194,6 @@ describe('setup-node', () => {
const versionSpec = '13.0.0-rc.0'; const versionSpec = '13.0.0-rc.0';
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
// ... but not in the local cache // ... but not in the local cache
@@ -239,7 +238,6 @@ describe('setup-node', () => {
const versionSpec = '14.7.0-rc.1'; const versionSpec = '14.7.0-rc.1';
inputs['node-version'] = versionSpec; inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
@@ -268,7 +266,6 @@ describe('setup-node', () => {
inputs['node-version'] = version; inputs['node-version'] = version;
inputs['architecture'] = arch; inputs['architecture'] = arch;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
const expectedUrl = `https://nodejs.org/download/rc/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`; const expectedUrl = `https://nodejs.org/download/rc/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`;

View File

@@ -2,9 +2,6 @@ name: 'Setup Node.js environment'
description: 'Setup a Node.js environment by adding problem matchers and optionally downloading and adding it to the PATH.' description: 'Setup a Node.js environment by adding problem matchers and optionally downloading and adding it to the PATH.'
author: 'GitHub' author: 'GitHub'
inputs: inputs:
always-auth:
description: 'Set always-auth in npmrc.'
default: 'false'
node-version: node-version:
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.' description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
node-version-file: node-version-file:
@@ -24,18 +21,18 @@ inputs:
cache: cache:
description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.' description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
package-manager-cache: package-manager-cache:
description: 'Set to false to disable automatic caching based on the package manager field in package.json. By default, caching is enabled if the package manager field is present.' description: 'Set to false to disable automatic caching. By default, caching is enabled when either devEngines.packageManager or the top-level packageManager field in package.json specifies npm as the package manager.'
default: true default: true
cache-dependency-path: cache-dependency-path:
description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.' description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
mirror: mirror:
description: 'Used to specify an alternative mirror to downlooad Node.js binaries from' description: 'Used to specify an alternative mirror to download Node.js binaries from'
mirror-token: mirror-token:
description: 'The token used as Authorization header when fetching from the mirror' description: 'The token used as Authorization header when fetching from the mirror'
# TODO: add input to control forcing to pull from cloud or dist. # TODO: add input to control forcing to pull from cloud or dist.
# escape valve for someone having issues or needing the absolute latest which isn't cached yet # escape valve for someone having issues or needing the absolute latest which isn't cached yet
outputs: outputs:
cache-hit: cache-hit:
description: 'A boolean value to indicate if a cache was hit.' description: 'A boolean value to indicate if a cache was hit.'
node-version: node-version:
description: 'The installed node version.' description: 'The installed node version.'

98892
dist/cache-save/index.js vendored

File diff suppressed because one or more lines are too long

98179
dist/setup/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -8,7 +8,7 @@ Currently, `actions/setup-node` supports caching dependencies for Npm and Yarn p
For the first iteration, we have decided to not support cases where `package-lock.json` / `yarn.lock` are located outside of repository root. For the first iteration, we have decided to not support cases where `package-lock.json` / `yarn.lock` are located outside of repository root.
Current implementation searches the following file patterns in the repository root: `package-lock.json`, `yarn.lock` (in order of resolving priorities) Current implementation searches the following file patterns in the repository root: `package-lock.json`, `yarn.lock` (in order of resolving priorities)
Obviously, it made build-in caching unusable for mono-repos and repos with complex structure. Obviously, it made built-in caching unusable for mono-repos and repos with complex structure.
We would like to revisit this decision and add customization for dependencies lock file location. We would like to revisit this decision and add customization for dependencies lock file location.
## Proposal ## Proposal
@@ -24,7 +24,7 @@ The second option looks more generic because it allows to:
## Decision ## Decision
Add `cache-dependency-path` input that will accept path (relative to repository root) to dependencies lock file. Add `cache-dependency-path` input that will accept path (relative to repository root) to dependencies lock file.
If provided path contains wildcards, the action will search all maching files and calculate common hash like `${{ hashFiles('**/package-lock.json') }}` YAML construction does. If provided path contains wildcards, the action will search all matching files and calculate common hash like `${{ hashFiles('**/package-lock.json') }}` YAML construction does.
The hash of provided matched files will be used as a part of cache key. The hash of provided matched files will be used as a part of cache key.
Yaml examples: Yaml examples:

View File

@@ -1,6 +1,6 @@
## Working with lockfiles ## Working with lockfiles
All supported package managers recommend that you **always** commit the lockfile, although implementations vary doing so generally provides the following benefits: Most supported package managers recommend that you **always** commit the lockfile, although implementations vary doing so generally provides the following benefits:
- Enables faster installation for CI and production environments, due to being able to skip package resolution. - Enables faster installation for CI and production environments, due to being able to skip package resolution.
- Describes a single representation of a dependency tree such that teammates, deployments, and continuous integration are guaranteed to install exactly the same dependencies. - Describes a single representation of a dependency tree such that teammates, deployments, and continuous integration are guaranteed to install exactly the same dependencies.
@@ -35,6 +35,25 @@ Ensure that `pnpm-lock.yaml` is always committed, when on CI pass `--frozen-lock
- [Working with Git - Lockfiles](https://pnpm.io/git#lockfiles) - [Working with Git - Lockfiles](https://pnpm.io/git#lockfiles)
- [Documentation of `--frozen-lockfile` option](https://pnpm.io/cli/install#--frozen-lockfile) - [Documentation of `--frozen-lockfile` option](https://pnpm.io/cli/install#--frozen-lockfile)
### Running without a lockfile
If you choose not to use a lockfile, you must ensure that **caching is disabled**. The `cache` feature relies on the lockfile to generate a unique key for the cache entry.
To run without a lockfile:
1. Do not set the `cache` input.
2. If your `package.json` contains a `packageManager` field set to npm (or devEngines.packageManager), automatic caching is enabled by default. Override this by setting `package-manager-cache: false`.
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '24'
package-manager-cache: false # Explicitly disable caching if you don't have a lockfile
- run: npm install
- run: npm test
```
## Check latest version ## Check latest version
The `check-latest` flag defaults to `false`. When set to `false`, the action will first check the local cache for a semver match. If unable to find a specific version in the cache, the action will attempt to download a version of Node.js. It will pull LTS versions from [node-versions releases](https://github.com/actions/node-versions/releases) and on miss or failure will fall back to the previous behavior of downloading directly from [node dist](https://nodejs.org/dist/). Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific version of Node.js is always used. The `check-latest` flag defaults to `false`. When set to `false`, the action will first check the local cache for a semver match. If unable to find a specific version in the cache, the action will attempt to download a version of Node.js. It will pull LTS versions from [node-versions releases](https://github.com/actions/node-versions/releases) and on miss or failure will fall back to the previous behavior of downloading directly from [node dist](https://nodejs.org/dist/). Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific version of Node.js is always used.
@@ -45,10 +64,10 @@ If `check-latest` is set to `true`, the action first checks if the cached versio
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '16' node-version: '24'
check-latest: true check-latest: true
- run: npm ci - run: npm ci
- run: npm test - run: npm test
@@ -63,8 +82,8 @@ See [supported version syntax](https://github.com/actions/setup-node#supported-v
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version-file: '.nvmrc' node-version-file: '.nvmrc'
- run: npm ci - run: npm ci
@@ -97,10 +116,10 @@ jobs:
runs-on: windows-latest runs-on: windows-latest
name: Node sample name: Node sample
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '14' node-version: '24'
architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default
- run: npm ci - run: npm ci
- run: npm test - run: npm test
@@ -118,10 +137,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Node sample name: Node sample
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '20.0.0-v8-canary' # it will install the latest v8 canary release for node 20.0.0 node-version: '24.0.0-v8-canary' # it will install the latest v8 canary release for node 24.0.0
- run: npm ci - run: npm ci
- run: npm test - run: npm test
``` ```
@@ -133,10 +152,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Node sample name: Node sample
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '20-v8-canary' # it will install the latest v8 canary release for node 20 node-version: '24-v8-canary' # it will install the latest v8 canary release for node 24
- run: npm ci - run: npm ci
- run: npm test - run: npm test
``` ```
@@ -149,10 +168,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Node sample name: Node sample
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: 'v20.1.1-v8-canary20221103f7e2421e91' node-version: 'v24.0.0-v8-canary2025030537242e55ac'
- run: npm ci - run: npm ci
- run: npm test - run: npm test
``` ```
@@ -169,10 +188,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Node sample name: Node sample
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '16-nightly' # it will install the latest nightly release for node 16 node-version: '24-nightly' # it will install the latest nightly release for node 24
- run: npm ci - run: npm ci
- run: npm test - run: npm test
``` ```
@@ -185,10 +204,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Node sample name: Node sample
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '16.0.0-nightly' # it will install the latest nightly release for node 16.0.0 node-version: '24.0.0-nightly' # it will install the latest nightly release for node 24.0.0
- run: npm ci - run: npm ci
- run: npm test - run: npm test
``` ```
@@ -201,10 +220,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Node sample name: Node sample
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '16.0.0-nightly20210420a0261d231c' node-version: '24.0.0-nightly202505066102159fa1'
- run: npm ci - run: npm ci
- run: npm test - run: npm test
``` ```
@@ -219,27 +238,28 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Node sample name: Node sample
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '16.0.0-rc.1' node-version: '24.0.0-rc.4'
- run: npm ci - run: npm ci
- run: npm test - run: npm test
``` ```
**Note:** Unlike nightly versions, which support version range specifiers, you must specify the exact version for a release candidate: `16.0.0-rc.1`. **Note:** Unlike nightly versions, which support version range specifiers, you must specify the exact version for a release candidate: `24.0.0-rc.4`.
## Caching packages data ## Caching packages data
The action follows [actions/cache](https://github.com/actions/cache/blob/main/examples.md#node---npm) guidelines, and caches global cache on the machine instead of `node_modules`, so cache can be reused between different Node.js versions. The action follows [actions/cache](https://github.com/actions/cache/blob/main/examples.md#node---npm) guidelines, and caches global cache on the machine instead of `node_modules`, so cache can be reused between different Node.js versions.
**Caching yarn dependencies:** **Caching yarn dependencies:**
Yarn caching handles both yarn versions: 1 or 2. Yarn caching handles both Yarn Classic (v1) and Yarn Berry (v2, v3, v4+).
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '14' node-version: '24'
cache: 'yarn' cache: 'yarn'
- run: yarn install --frozen-lockfile # optional, --immutable - run: yarn install --frozen-lockfile # optional, --immutable
- run: yarn test - run: yarn test
@@ -255,13 +275,13 @@ steps:
# NOTE: pnpm caching support requires pnpm version >= 6.10.0 # NOTE: pnpm caching support requires pnpm version >= 6.10.0
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: pnpm/action-setup@v2 - uses: pnpm/action-setup@v4
with: with:
version: 6.32.9 version: 10
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '14' node-version: '24'
cache: 'pnpm' cache: 'pnpm'
- run: pnpm install - run: pnpm install
- run: pnpm test - run: pnpm test
@@ -274,10 +294,10 @@ steps:
**Using wildcard patterns to cache dependencies** **Using wildcard patterns to cache dependencies**
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '14' node-version: '24'
cache: 'npm' cache: 'npm'
cache-dependency-path: '**/package-lock.json' cache-dependency-path: '**/package-lock.json'
- run: npm ci - run: npm ci
@@ -287,10 +307,10 @@ steps:
**Using a list of file paths to cache dependencies** **Using a list of file paths to cache dependencies**
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '14' node-version: '24'
cache: 'npm' cache: 'npm'
cache-dependency-path: | cache-dependency-path: |
server/app/package-lock.json server/app/package-lock.json
@@ -299,6 +319,35 @@ steps:
- run: npm test - run: npm test
``` ```
**Restore-Only Cache**
```yaml
## In some workflows, you may want to restore a cache without saving it. This can help reduce cache writes and storage usage in workflows that only need to read from cache
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
# Restore Node.js modules cache (restore-only)
- name: Restore Node modules cache
uses: actions/cache@v5
id: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
# Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
# Install dependencies
- run: npm install
```
> For more details related to cache scenarios, please refer [Node npm](https://github.com/actions/cache/blob/main/examples.md#node---npm).
## Multiple Operating Systems and Architectures ## Multiple Operating Systems and Architectures
```yaml ```yaml
@@ -312,21 +361,21 @@ jobs:
- macos-latest - macos-latest
- windows-latest - windows-latest
node_version: node_version:
- 12 - 20
- 14 - 22
- 16 - 24
architecture: architecture:
- x64 - x64
# an extra windows-x86 run: # an extra windows-x86 run:
include: include:
- os: windows-2016 - os: windows-latest
node_version: 12 node_version: 24
architecture: x86 architecture: x86
name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }} name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- name: Setup node - name: Setup node
uses: actions/setup-node@v5 uses: actions/setup-node@v6
with: with:
node-version: ${{ matrix.node_version }} node-version: ${{ matrix.node_version }}
architecture: ${{ matrix.architecture }} architecture: ${{ matrix.architecture }}
@@ -337,16 +386,16 @@ jobs:
## Publish to npmjs and GPR with npm ## Publish to npmjs and GPR with npm
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '14.x' node-version: '24.x'
registry-url: 'https://registry.npmjs.org' registry-url: 'https://registry.npmjs.org'
- run: npm ci - run: npm ci
- run: npm publish - run: npm publish
env: env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
registry-url: 'https://npm.pkg.github.com' registry-url: 'https://npm.pkg.github.com'
- run: npm publish - run: npm publish
@@ -357,16 +406,16 @@ steps:
## Publish to npmjs and GPR with yarn ## Publish to npmjs and GPR with yarn
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '14.x' node-version: '24.x'
registry-url: <registry url> registry-url: <registry url>
- run: yarn install --frozen-lockfile - run: yarn install --frozen-lockfile
- run: yarn publish - run: yarn publish
env: env:
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
registry-url: 'https://npm.pkg.github.com' registry-url: 'https://npm.pkg.github.com'
- run: yarn publish - run: yarn publish
@@ -377,10 +426,10 @@ steps:
## Use private packages ## Use private packages
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '14.x' node-version: '24.x'
registry-url: 'https://registry.npmjs.org' registry-url: 'https://registry.npmjs.org'
# Skip post-install scripts here, as a malicious # Skip post-install scripts here, as a malicious
# script could steal NODE_AUTH_TOKEN. # script could steal NODE_AUTH_TOKEN.
@@ -397,10 +446,10 @@ Below you can find a sample "Setup .yarnrc.yml" step, that is going to allow you
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '14.x' node-version: '24.x'
- name: Setup .yarnrc.yml - name: Setup .yarnrc.yml
run: | run: |
yarn config set npmScopes.my-org.npmRegistryServer "https://npm.pkg.github.com" yarn config set npmScopes.my-org.npmRegistryServer "https://npm.pkg.github.com"
@@ -416,9 +465,6 @@ To access private GitHub Packages within the same organization, go to "Manage Ac
Please refer to the [Ensuring workflow access to your package - Configuring a package's access control and visibility](https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility#ensuring-workflow-access-to-your-package) for more details. Please refer to the [Ensuring workflow access to your package - Configuring a package's access control and visibility](https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility#ensuring-workflow-access-to-your-package) for more details.
### always-auth input
The always-auth input sets `always-auth=true` in .npmrc file. With this option set [npm](https://docs.npmjs.com/cli/v6/using-npm/config#always-auth)/yarn sends the authentication credentials when making a request to the registries.
## Use private mirror ## Use private mirror
It is possible to use a private mirror hosting Node.js binaries. This mirror must be a full mirror of the official Node.js distribution. It is possible to use a private mirror hosting Node.js binaries. This mirror must be a full mirror of the official Node.js distribution.
@@ -427,9 +473,9 @@ It is possible to specify a token to authenticate with the mirror using the `mir
The token will be passed as a bearer token in the `Authorization` header. The token will be passed as a bearer token in the `Authorization` header.
```yaml ```yaml
- uses: actions/setup-node@v5 - uses: actions/setup-node@v6
with: with:
node-version: '14.x' node-version: '24.x'
mirror: 'https://nodejs.org/dist' mirror: 'https://nodejs.org/dist'
mirror-token: 'your-mirror-token' mirror-token: 'your-mirror-token'
``` ```

3168
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "setup-node", "name": "setup-node",
"version": "5.0.0", "version": "6.2.0",
"private": true, "private": true,
"description": "setup node action", "description": "setup node action",
"main": "lib/setup-node.js", "main": "lib/setup-node.js",
@@ -28,7 +28,7 @@
"author": "GitHub", "author": "GitHub",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^4.0.3", "@actions/cache": "^5.0.1",
"@actions/core": "^1.11.1", "@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/github": "^6.0.1", "@actions/github": "^6.0.1",
@@ -43,12 +43,12 @@
"@types/jest": "^29.5.14", "@types/jest": "^29.5.14",
"@types/node": "^24.1.0", "@types/node": "^24.1.0",
"@types/semver": "^7.5.8", "@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^5.54.0", "@typescript-eslint/eslint-plugin": "^8.54.0",
"@typescript-eslint/parser": "^5.54.0", "@typescript-eslint/parser": "^8.54.0",
"@vercel/ncc": "^0.38.3", "@vercel/ncc": "^0.38.3",
"eslint": "^8.57.0", "eslint": "^9.39.2",
"eslint-config-prettier": "^8.6.0", "eslint-config-prettier": "^8.6.0",
"eslint-plugin-jest": "^27.9.0", "eslint-plugin-jest": "^28.14.0",
"eslint-plugin-node": "^11.1.0", "eslint-plugin-node": "^11.1.0",
"jest": "^29.7.0", "jest": "^29.7.0",
"jest-circus": "^29.7.0", "jest-circus": "^29.7.0",

View File

@@ -4,7 +4,7 @@ import * as path from 'path';
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as github from '@actions/github'; import * as github from '@actions/github';
export function configAuthentication(registryUrl: string, alwaysAuth: string) { export function configAuthentication(registryUrl: string) {
const npmrc: string = path.resolve( const npmrc: string = path.resolve(
process.env['RUNNER_TEMP'] || process.cwd(), process.env['RUNNER_TEMP'] || process.cwd(),
'.npmrc' '.npmrc'
@@ -13,14 +13,10 @@ export function configAuthentication(registryUrl: string, alwaysAuth: string) {
registryUrl += '/'; registryUrl += '/';
} }
writeRegistryToFile(registryUrl, npmrc, alwaysAuth); writeRegistryToFile(registryUrl, npmrc);
} }
function writeRegistryToFile( function writeRegistryToFile(registryUrl: string, fileLocation: string) {
registryUrl: string,
fileLocation: string,
alwaysAuth: string
) {
let scope: string = core.getInput('scope'); let scope: string = core.getInput('scope');
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) { if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
scope = github.context.repo.owner; scope = github.context.repo.owner;
@@ -47,8 +43,7 @@ function writeRegistryToFile(
const authString: string = const authString: string =
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}'; registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
const registryString = `${scope}registry=${registryUrl}`; const registryString = `${scope}registry=${registryUrl}`;
const alwaysAuthString = `always-auth=${alwaysAuth}`; newContents += `${authString}${os.EOL}${registryString}`;
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
fs.writeFileSync(fileLocation, newContents); fs.writeFileSync(fileLocation, newContents);
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation); core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it // Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it

View File

@@ -62,24 +62,29 @@ export async function run() {
await printEnvDetailsAndSetOutput(); await printEnvDetailsAndSetOutput();
const registryUrl: string = core.getInput('registry-url'); const registryUrl: string = core.getInput('registry-url');
const alwaysAuth: string = core.getInput('always-auth');
if (registryUrl) { if (registryUrl) {
auth.configAuthentication(registryUrl, alwaysAuth); auth.configAuthentication(registryUrl);
} }
const resolvedPackageManager = getNameFromPackageManagerField();
const cacheDependencyPath = core.getInput('cache-dependency-path'); const cacheDependencyPath = core.getInput('cache-dependency-path');
if (cache && isCacheFeatureAvailable()) {
core.saveState(State.CachePackageManager, cache); if (isCacheFeatureAvailable()) {
await restoreCache(cache, cacheDependencyPath); // if the cache input is provided, use it for caching.
} else if (resolvedPackageManager && packagemanagercache) { if (cache) {
core.info( core.saveState(State.CachePackageManager, cache);
"Detected package manager from package.json's packageManager field: " + await restoreCache(cache, cacheDependencyPath);
resolvedPackageManager + // package manager npm is detected from package.json, enable auto-caching for npm.
'. Auto caching has been enabled for it. If you want to disable it, set package-manager-cache input to false' } else if (packagemanagercache) {
); const resolvedPackageManager = getNameFromPackageManagerField();
core.saveState(State.CachePackageManager, resolvedPackageManager); if (resolvedPackageManager) {
await restoreCache(resolvedPackageManager, cacheDependencyPath); core.info(
"Detected npm as the package manager from package.json's packageManager field. " +
'Auto caching has been enabled for npm. If you want to disable it, set package-manager-cache input to false'
);
core.saveState(State.CachePackageManager, resolvedPackageManager);
await restoreCache(resolvedPackageManager, cacheDependencyPath);
}
}
} }
const matchersPath = path.join(__dirname, '../..', '.github'); const matchersPath = path.join(__dirname, '../..', '.github');
@@ -132,8 +137,7 @@ function resolveVersionInput(): string {
} }
export function getNameFromPackageManagerField(): string | undefined { export function getNameFromPackageManagerField(): string | undefined {
// Check packageManager field in package.json const npmRegex = /^(\^)?npm(@.*)?$/; // matches "npm", "npm@...", "^npm@..."
const SUPPORTED_PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm'];
try { try {
const packageJson = JSON.parse( const packageJson = JSON.parse(
fs.readFileSync( fs.readFileSync(
@@ -141,16 +145,24 @@ export function getNameFromPackageManagerField(): string | undefined {
'utf-8' 'utf-8'
) )
); );
const pm = packageJson.packageManager;
if (typeof pm === 'string') { // Check devEngines.packageManager first (object or array)
const regex = new RegExp( const devPM = packageJson?.devEngines?.packageManager;
`^(?:\\^)?(${SUPPORTED_PACKAGE_MANAGERS.join('|')})@` const devPMArray = devPM ? (Array.isArray(devPM) ? devPM : [devPM]) : [];
); for (const obj of devPMArray) {
const match = pm.match(regex); if (typeof obj?.name === 'string' && npmRegex.test(obj.name)) {
return match ? match[1] : undefined; return 'npm';
}
} }
// Check top-level packageManager
const topLevelPM = packageJson?.packageManager;
if (typeof topLevelPM === 'string' && npmRegex.test(topLevelPM)) {
return 'npm';
}
return undefined; return undefined;
} catch (err) { } catch {
return undefined; return undefined;
} }
} }

View File

@@ -1,6 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "target": "ES2022", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */ "outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */