Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support pnpm install #159

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defaults:

env:
NODE_OPTIONS: "--unhandled-rejections=strict"
VOLTA_FEATURE_PNPM: 1

concurrency:
group: ci-${{ github.head_ref || github.ref }}
Expand Down Expand Up @@ -59,9 +60,10 @@ jobs:

- run: ./action/tests/log-info.sh
- run: ./action/tests/check-version.sh 'volta' ${{ matrix.volta-version }}
- run: volta install node@10.17.0 yarn@1.19.0
- run: volta install node@10.17.0 yarn@1.19.0 pnpm@9.0.0
- run: ./action/tests/check-version.sh 'node' 'v10.17.0'
- run: ./action/tests/check-version.sh 'yarn' '1.19.0'
- run: ./action/tests/check-version.sh 'pnpm' '9.0.0'

test-no-options:
runs-on: "${{ matrix.os }}-latest"
Expand All @@ -83,10 +85,11 @@ jobs:

- run: ./action/tests/log-info.sh
- run: ./action/tests/check-version.sh 'volta' 'current'
- run: volta install node@12.16.1 npm@7.5.2 yarn@1.19.1
- run: volta install node@12.16.1 npm@7.5.2 yarn@1.19.1 pnpm@9.0.0
- run: ./action/tests/check-version.sh 'node' 'v12.16.1'
- run: ./action/tests/check-version.sh 'npm' '7.5.2'
- run: ./action/tests/check-version.sh 'yarn' '1.19.1'
- run: ./action/tests/check-version.sh 'pnpm' '9.0.0'

test-specified-node-npm-yarn-overrides-pinned-versions:
runs-on: "${{ matrix.os }}-latest"
Expand Down Expand Up @@ -114,11 +117,13 @@ jobs:
node-version: 12.14.0
npm-version: 7.5.2
yarn-version: 1.22.0
pnpm-version: 9.0.0

- run: ./action/tests/log-info.sh
- run: ./action/tests/check-version.sh 'node' 'v12.14.0'
- run: ./action/tests/check-version.sh 'npm' '7.5.2'
- run: ./action/tests/check-version.sh 'yarn' '1.22.0'
- run: ./action/tests/check-version.sh 'pnpm' '9.0.0'

test-specific-volta-node-npm-yarn:
runs-on: "${{ matrix.os }}-latest"
Expand All @@ -141,12 +146,14 @@ jobs:
node-version: 12.0.0
npm-version: 7.5.2
yarn-version: 1.22.0
pnpm-version: 9.0.0

- run: ./action/tests/log-info.sh
- run: ./action/tests/check-version.sh 'volta' '1.0.8'
- run: ./action/tests/check-version.sh 'node' 'v12.0.0'
- run: ./action/tests/check-version.sh 'npm' '7.5.2'
- run: ./action/tests/check-version.sh 'yarn' '1.22.0'
- run: ./action/tests/check-version.sh 'pnpm' '9.0.0'

test-specified-registry-url:
runs-on: "${{ matrix.os }}-latest"
Expand All @@ -171,9 +178,10 @@ jobs:

- run: ./action/tests/log-info.sh
- run: ./action/tests/check-version.sh 'volta' 'current'
- run: volta install node@10.17.0 yarn@1.19.0
- run: volta install node@10.17.0 yarn@1.19.0 pnpm@9.0.0
- run: ./action/tests/check-version.sh 'node' 'v10.17.0'
- run: ./action/tests/check-version.sh 'yarn' '1.19.0'
- run: ./action/tests/check-version.sh 'pnpm' '9.0.0'
- run: ./action/tests/check-registry.sh 'https://some.path.here.com/lol/'

test-specific-variant:
Expand All @@ -194,10 +202,11 @@ jobs:

- run: ./action/tests/log-info.sh
- run: ./action/tests/check-version.sh 'volta' 'current'
- run: volta install node@12.16.1 npm@7.5.2 yarn@1.19.1
- run: volta install node@12.16.1 npm@7.5.2 yarn@1.19.1 pnpm@9.0.0
- run: ./action/tests/check-version.sh 'node' 'v12.16.1'
- run: ./action/tests/check-version.sh 'npm' '7.5.2'
- run: ./action/tests/check-version.sh 'yarn' '1.19.1'
- run: ./action/tests/check-version.sh 'pnpm' '9.0.0'

test-js-project-in-subdir-no-options:
runs-on: "ubuntu-latest"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This action installs [volta](https://volta.sh) by:
| `node-version` | <p>Version Spec of the node version to use. Examples: 10.6.x, 10.15.1, &gt;=10.15.0</p> | `false` | `""` |
| `npm-version` | <p>Version Spec of the npm version to use. Examples: 7.5.x, 7.5.3, &gt;=7.5.3</p> | `false` | `""` |
| `yarn-version` | <p>Version Spec of the yarn version to use. Examples: 1.6.x, 10.15.1, &gt;=10.15.0</p> | `false` | `""` |
| `pnpm-version` | <p>experimental. Version Spec of the pnpm version to use. Examples: ^8, 8.15.9, &gt;=9. To enable it, ensure that the environment variable [VOLTA_FEATURE_PNPM](https://docs.volta.sh/advanced/pnpm) is set to 1</p> | `false` | `""` |
| `package-json-path` | <p>The path to the package.json to update when using an explicit <code>node-version</code> | <code>yarn-version</code> | <code>npm-version</code> override. By default, we will use <code>package.json</code> in the checkout root.</p> | `false` | `""` |
| `variant` | <p>Specific variant to install. Example: providing the variant "linux-openssl-rhel", which will target installing the volta-${version}-linux-openssl-rhel.tar.gz tarball</p> | `false` | `""` |
| `registry-url` | <p>Optional registry to set up for auth. Will set the registry in a project level .npmrc file, and set up auth to read in from env.NODE<em>AUTH</em>TOKEN</p> | `false` | `""` |
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ inputs:
yarn-version:
description: 'Version Spec of the yarn version to use. Examples: 1.6.x, 10.15.1, >=10.15.0'
default: ''
pnpm-version:
description: 'Version Spec of the pnpm version to use. Examples: ^8, 8.15.9, >=9. ensure that the environment variable VOLTA_FEATURE_PNPM is set to 1'
default: ''
package-json-path:
description: 'The path to the package.json to update when using an explicit `node-version` | `yarn-version` | `npm-version` override. By default, we will use `package.json` in the checkout root.'
default: ''
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ async function run(): Promise<void> {
}
}

const pnpmVersion = core.getInput('pnpm-version', { required: false });
if (pnpmVersion !== '') {
core.info(`installing Pnpm ${pnpmVersion.toUpperCase() === 'TRUE' ? '' : pnpmVersion}`);
await installer.installPnpm(pnpmVersion);

// cannot pin `yarn` when `node` is not pinned as well
if (nodeVersion !== '' && hasPackageJSON) {
await installer.pinPnpm(workingDirectory, pnpmVersion);
}
}

const registryUrl = core.getInput('registry-url', { required: false });
const alwaysAuth = core.getInput('always-auth', { required: false });
if (registryUrl !== '') {
Expand Down
3 changes: 3 additions & 0 deletions src/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ describe('buildLayout', () => {
"node": "shim-file-here",
"npm": "shim-file-here",
"npx": "shim-file-here",
"pnpm": "shim-file-here",
"shim": "shim-file-here",
"yarn": "shim-file-here",
},
Expand All @@ -198,11 +199,13 @@ describe('buildLayout', () => {
"image": {
"node": {},
"packages": {},
"pnpm": {},
"yarn": {},
},
"inventory": {
"node": {},
"packages": {},
"pnpm": {},
"yarn": {},
},
"user": {},
Expand Down
12 changes: 12 additions & 0 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ async function setupShims(voltaHome: string): Promise<void> {
setupShim(voltaHome, 'yarn');
setupShim(voltaHome, 'npm');
setupShim(voltaHome, 'npx');
setupShim(voltaHome, 'pnpm');
}

/*
Expand All @@ -253,9 +254,11 @@ export async function buildLayout(voltaHome: string): Promise<void> {
await io.mkdirP(path.join(voltaHome, 'tools/image/node'));
await io.mkdirP(path.join(voltaHome, 'tools/image/packages'));
await io.mkdirP(path.join(voltaHome, 'tools/image/yarn'));
await io.mkdirP(path.join(voltaHome, 'tools/image/pnpm'));
await io.mkdirP(path.join(voltaHome, 'tools/inventory/node'));
await io.mkdirP(path.join(voltaHome, 'tools/inventory/packages'));
await io.mkdirP(path.join(voltaHome, 'tools/inventory/yarn'));
await io.mkdirP(path.join(voltaHome, 'tools/inventory/pnpm'));
await io.mkdirP(path.join(voltaHome, 'tools/user'));
await setupShims(voltaHome);
}
Expand Down Expand Up @@ -364,6 +367,11 @@ export async function installYarn(version: string): Promise<void> {
await execVolta('.', ['install', `yarn${version === 'true' ? '' : `@${version}`}`]);
}

export async function installPnpm(version: string): Promise<void> {
// using `.` here because `volta install` doesn't care about the working directory at all
await execVolta('.', ['install', `pnpm${version === 'true' ? '' : `@${version}`}`]);
}

export async function pinNode(workingDirectory: string, version: string): Promise<void> {
await execVolta(workingDirectory, ['pin', `node${version === 'true' ? '' : `@${version}`}`]);
}
Expand All @@ -376,6 +384,10 @@ export async function pinYarn(workingDirectory: string, version: string): Promis
await execVolta(workingDirectory, ['pin', `yarn${version === 'true' ? '' : `@${version}`}`]);
}

export async function pinPnpm(workingDirectory: string, version: string): Promise<void> {
await execVolta(workingDirectory, ['pin', `pnpm${version === 'true' ? '' : `@${version}`}`]);
}

export async function getVoltaVersion(versionSpec: string, authToken: string): Promise<string> {
let version = semver.clean(versionSpec) || '';
const validVersionProvided = semver.valid(version) !== null;
Expand Down
1 change: 1 addition & 0 deletions tests/log-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ echo "Current contents of $VOLTA_HOME\n$voltaBinContents"
echo "Path to volta: $(which volta)"
echo "Path to node: $(which node)"
echo "Path to yarn: $(which yarn)"
echo "Path to pnpm: $(which pnpm)"