Skip to content

Commit 5b4ec7c

Browse files
committed
💚 [Debug] Try to switch package managers using Corepack in all Node.js
1 parent 5a43fb7 commit 5b4ec7c

File tree

4 files changed

+149
-60
lines changed

4 files changed

+149
-60
lines changed

.github/workflows/ci.yaml

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -64,43 +64,43 @@ jobs:
6464
- id: detector
6565
uses: sounisi5011/npm-packages@actions/get-nodejs-versions-array-v0
6666

67-
lint:
68-
needs: if-run-ci
69-
runs-on: ubuntu-latest
70-
steps:
71-
- uses: actions/checkout@v3
72-
73-
- name: Reconfigure git to use HTTP authentication
74-
# see https://stackoverflow.com/a/69634516
75-
# see https://github.com/actions/setup-node/issues/214#issuecomment-810829250
76-
shell: bash
77-
run: |
78-
git config --global \
79-
'url.https://${{ secrets.GITHUB_TOKEN }}@github.com/.insteadOf' \
80-
81-
82-
- name: Install Node.js
83-
uses: actions/setup-node@v3
84-
with:
85-
node-version: 14.x
86-
cache: npm
87-
88-
- name: Enable Corepack (Automatically setup a package manager for Node.js)
89-
run: |
90-
corepack enable
91-
corepack enable npm
92-
93-
- name: Show node and npm version
94-
shell: bash
95-
run: |
96-
echo node "$(node --version)"
97-
echo npm "$(npm --version)"
98-
99-
- name: Install dependencies
100-
run: npm ci
101-
102-
- name: Run linter
103-
run: npm run test:other-than-unit-test
67+
# lint:
68+
# needs: if-run-ci
69+
# runs-on: ubuntu-latest
70+
# steps:
71+
# - uses: actions/checkout@v3
72+
73+
# - name: Reconfigure git to use HTTP authentication
74+
# # see https://stackoverflow.com/a/69634516
75+
# # see https://github.com/actions/setup-node/issues/214#issuecomment-810829250
76+
# shell: bash
77+
# run: |
78+
# git config --global \
79+
# 'url.https://${{ secrets.GITHUB_TOKEN }}@github.com/.insteadOf' \
80+
# 'ssh://[email protected]/'
81+
82+
# - name: Install Node.js
83+
# uses: actions/setup-node@v3
84+
# with:
85+
# node-version: 14.x
86+
# cache: npm
87+
88+
# - name: Enable Corepack (Automatically setup a package manager for Node.js)
89+
# run: |
90+
# corepack enable
91+
# corepack enable npm
92+
93+
# - name: Show node and npm version
94+
# shell: bash
95+
# run: |
96+
# echo node "$(node --version)"
97+
# echo npm "$(npm --version)"
98+
99+
# - name: Install dependencies
100+
# run: npm ci
101+
102+
# - name: Run linter
103+
# run: npm run test:other-than-unit-test
104104

105105
unit-test:
106106
needs: detect-supported-node
@@ -156,6 +156,8 @@ jobs:
156156
157157
readonly npmSemver="${packageManager##npm@}"
158158
echo "required-npm-version=${npmSemver%%+*}" >> "${GITHUB_ENV}"
159+
else
160+
echo "corepack-available=1" >> "${GITHUB_ENV}"
159161
fi
160162
161163
# If yarn is not available, install it
@@ -202,23 +204,23 @@ jobs:
202204
# So we can simplify our GitHub status check configuration.
203205
# see https://github.com/orgs/community/discussions/26822
204206
# see https://github.com/sounisi5011/npm-packages/blob/2a5ca2de696eeb8b40a38de90580441c4c6c96e0/.github/workflows/ci.yaml#L482-L498
205-
complete:
206-
name: Complete CI
207-
needs: [lint, unit-test]
208-
if:
209-
${{ always() && github.event.pull_request }}
210-
# This job is required only for Pull Requests.
211-
# It does not need to be run on other branches.
212-
runs-on: ubuntu-latest
213-
steps:
214-
- name: Check all job status
215-
# see https://docs.github.com/en/actions/learn-github-actions/contexts#needs-context
216-
# see https://docs.github.com/en/actions/learn-github-actions/expressions#contains
217-
# see https://stackoverflow.com/a/67532120/4907315
218-
if: >-
219-
${{
220-
contains(needs.*.result, 'failure')
221-
|| contains(needs.*.result, 'cancelled')
222-
|| contains(needs.*.result, 'skipped')
223-
}}
224-
run: exit 1
207+
# complete:
208+
# name: Complete CI
209+
# needs: [lint, unit-test]
210+
# if:
211+
# ${{ always() && github.event.pull_request }}
212+
# # This job is required only for Pull Requests.
213+
# # It does not need to be run on other branches.
214+
# runs-on: ubuntu-latest
215+
# steps:
216+
# - name: Check all job status
217+
# # see https://docs.github.com/en/actions/learn-github-actions/contexts#needs-context
218+
# # see https://docs.github.com/en/actions/learn-github-actions/expressions#contains
219+
# # see https://stackoverflow.com/a/67532120/4907315
220+
# if: >-
221+
# ${{
222+
# contains(needs.*.result, 'failure')
223+
# || contains(needs.*.result, 'cancelled')
224+
# || contains(needs.*.result, 'skipped')
225+
# }}
226+
# run: exit 1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Go to the latest release page on npm](https://img.shields.io/npm/v/package-version-git-tag.svg)][npm]
44
[![License: MIT](https://img.shields.io/static/v1?label=license&message=MIT&color=green)][github-license]
5-
![Supported Node.js version: 14.x || 16.x](https://img.shields.io/static/v1?label=node&message=14.x%20%7C%7C%2016.x&color=brightgreen)
5+
![Supported Node.js version: 14.x - 19.x](https://img.shields.io/static/v1?label=node&message=14.x%20-%2019.x&color=brightgreen)
66
[![Minified Bundle Size Details](https://img.shields.io/bundlephobia/min/package-version-git-tag/3.0.0)](https://bundlephobia.com/[email protected])
77
[![Install Size Details](https://packagephobia.now.sh/[email protected])](https://packagephobia.now.sh/[email protected])
88
[![Dependencies Status](https://david-dm.org/sounisi5011/package-version-git-tag/status.svg)](https://david-dm.org/sounisi5011/package-version-git-tag)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,6 @@
9898
},
9999
"packageManager": "[email protected]",
100100
"engines": {
101-
"node": "14.x || 16.x"
101+
"node": "14.x - 19.x"
102102
}
103103
}

test/index.ts

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { execFileAsync, getRandomInt, rmrf } from './helpers';
77
import { initGit } from './helpers/git';
88

99
import escapeRegExp = require('escape-string-regexp');
10+
import execa = require('execa');
1011

1112
const PROJECT_ROOT = path.resolve(__dirname, '..');
1213
const FIXTURES_DIR = path.resolve(__dirname, 'fixtures');
@@ -21,7 +22,7 @@ function tmpDir(dirname: string): string {
2122
return path.resolve(__dirname, 'tmp', dirname);
2223
}
2324

24-
test.before(async () => {
25+
test.before.skip(async () => {
2526
await execFileAsync('npm', ['run', 'build'], { cwd: PROJECT_ROOT });
2627
await Promise.all([
2728
rmrf(path.resolve(FIXTURES_DIR, 'package-lock.json')),
@@ -41,6 +42,92 @@ test.before(async () => {
4142
});
4243
});
4344

45+
test.only('check npm version', async (t) => {
46+
t.like(await execa('npm', ['--version']), { stdout: '7.24.2', stderr: '' });
47+
});
48+
49+
test.only('check yarn version', async (t) => {
50+
const { exec, gitDirpath } = await initGit(tmpDir('yarn1-ver'));
51+
52+
await fs.writeFile(
53+
path.join(gitDirpath, 'package.json'),
54+
JSON.stringify({
55+
packageManager: '[email protected]',
56+
}),
57+
);
58+
59+
t.like(await exec(['yarn', '--version']), {
60+
stdout: '1.22.19',
61+
stderr: '',
62+
});
63+
});
64+
65+
if (process.env['corepack-available']) {
66+
test.only('check yarn2 version', async (t) => {
67+
const { exec, gitDirpath } = await initGit(tmpDir('yarn2-ver'));
68+
69+
await fs.writeFile(
70+
path.join(gitDirpath, 'package.json'),
71+
JSON.stringify({
72+
packageManager: '[email protected]',
73+
}),
74+
);
75+
76+
t.like(await exec(['yarn', '--version']), {
77+
stdout: '2.4.3',
78+
stderr: '',
79+
});
80+
});
81+
82+
test.only('check yarn3 version', async (t) => {
83+
const { exec, gitDirpath } = await initGit(tmpDir('yarn3-ver'));
84+
85+
await fs.writeFile(
86+
path.join(gitDirpath, 'package.json'),
87+
JSON.stringify({
88+
packageManager: '[email protected]',
89+
}),
90+
);
91+
92+
t.like(await exec(['yarn', '--version']), {
93+
stdout: '3.4.1',
94+
stderr: '',
95+
});
96+
});
97+
98+
test.only('check yarn4 version', async (t) => {
99+
const { exec, gitDirpath } = await initGit(tmpDir('yarn4-ver'));
100+
101+
await fs.writeFile(
102+
path.join(gitDirpath, 'package.json'),
103+
JSON.stringify({
104+
packageManager: '[email protected]',
105+
}),
106+
);
107+
108+
t.like(await exec(['yarn', '--version']), {
109+
stdout: '4.0.0-rc.40',
110+
stderr: '',
111+
});
112+
});
113+
114+
test.only('check pnpm version', async (t) => {
115+
const { exec, gitDirpath } = await initGit(tmpDir('pnpm-ver'));
116+
117+
await fs.writeFile(
118+
path.join(gitDirpath, 'package.json'),
119+
JSON.stringify({
120+
packageManager: '[email protected]',
121+
}),
122+
);
123+
124+
t.like(await exec(['pnpm', '--version']), {
125+
stdout: '7.29.1',
126+
stderr: '',
127+
});
128+
});
129+
}
130+
44131
test('CLI should add Git tag', async (t) => {
45132
const { exec } = await initGit(tmpDir('not-exists-git-tag'));
46133

0 commit comments

Comments
 (0)