Compare commits
59 Commits
add-to-pat
...
master
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ebcfd6995d | ||
![]() |
d2613e087f | ||
![]() |
d928be8e0c | ||
![]() |
d882d12c64 | ||
![]() |
0b715c7ebb | ||
![]() |
2ed49cbb02 | ||
![]() |
218cb35941 | ||
![]() |
3723f63bb4 | ||
![]() |
849d884800 | ||
![]() |
f92eb0edb6 | ||
![]() |
b27f801bf9 | ||
![]() |
11dd14d0c0 | ||
![]() |
61eb8c655a | ||
![]() |
65db188e28 | ||
![]() |
0609f0983b | ||
![]() |
7208fa2733 | ||
![]() |
1bd00a2972 | ||
![]() |
d5601fb603 | ||
![]() |
bc06aa6030 | ||
![]() |
cd2af74528 | ||
![]() |
c8a150e137 | ||
![]() |
ed0172a253 | ||
![]() |
c3b53f6a16 | ||
![]() |
21e88da200 | ||
![]() |
fc3334fa11 | ||
![]() |
d01953a678 | ||
![]() |
3360b50db7 | ||
![]() |
6f9e9a867a | ||
![]() |
537643d491 | ||
![]() |
f4129fb46e | ||
![]() |
6e1964dde3 | ||
![]() |
10693b3829 | ||
![]() |
99ecd24520 | ||
![]() |
958500fcab | ||
![]() |
57b9359b4c | ||
![]() |
ec1a8b444c | ||
![]() |
73e15250cb | ||
![]() |
10b4b0b462 | ||
![]() |
5fa8980bf4 | ||
![]() |
ae78e9abbe | ||
![]() |
35ab4267a1 | ||
![]() |
11ba3424e0 | ||
![]() |
847a737d63 | ||
![]() |
225f3bb4b0 | ||
![]() |
777a50d72e | ||
![]() |
e7c10c6fc5 | ||
![]() |
a576a70bc6 | ||
![]() |
1d51e20937 | ||
![]() |
ad2b35ae0c | ||
![]() |
d8ea532ac4 | ||
![]() |
2270f39ef6 | ||
![]() |
394c848db6 | ||
![]() |
e13928ccc5 | ||
![]() |
93bd5a123d | ||
![]() |
9eb14dd77c | ||
![]() |
eafb777c56 | ||
![]() |
e6378df420 | ||
![]() |
6ff6e97bc6 | ||
![]() |
45d9c91ff6 |
14
.github/FUNDING.yml
vendored
14
.github/FUNDING.yml
vendored
@ -1,12 +1,2 @@
|
|||||||
# These are supported funding model platforms
|
custom:
|
||||||
|
- https://opencollective.com/pnpm
|
||||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
|
||||||
patreon: khai96_
|
|
||||||
open_collective: # Collective unavailable
|
|
||||||
ko_fi: # Replace with a single Ko-fi username
|
|
||||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
||||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
||||||
liberapay: # Replace with a single Liberapay username
|
|
||||||
issuehunt: # disabled
|
|
||||||
otechie: # Replace with a single Otechie username
|
|
||||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
|
||||||
|
3
.github/dependabot.yml
vendored
3
.github/dependabot.yml
vendored
@ -5,6 +5,3 @@ updates:
|
|||||||
schedule:
|
schedule:
|
||||||
interval: weekly
|
interval: weekly
|
||||||
open-pull-requests-limit: 10
|
open-pull-requests-limit: 10
|
||||||
labels:
|
|
||||||
- dependabot
|
|
||||||
- github-actions
|
|
||||||
|
65
.github/workflows/test.yaml
vendored
65
.github/workflows/test.yaml
vendored
@ -22,7 +22,7 @@ jobs:
|
|||||||
- windows-latest
|
- windows-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -35,8 +35,8 @@ jobs:
|
|||||||
- name: 'Test: install'
|
- name: 'Test: install'
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|
||||||
test_explicit_inputs:
|
test_dest:
|
||||||
name: Test with explicit inputs
|
name: Test with dest
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ jobs:
|
|||||||
- windows-latest
|
- windows-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -65,6 +65,61 @@ jobs:
|
|||||||
- name: 'Test: install'
|
- name: 'Test: install'
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|
||||||
|
test_standalone:
|
||||||
|
name: Test with standalone
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- ubuntu-latest
|
||||||
|
- macos-latest
|
||||||
|
- windows-latest
|
||||||
|
|
||||||
|
standalone:
|
||||||
|
- true
|
||||||
|
- false
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Run the action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
version: 7.0.0
|
||||||
|
standalone: ${{ matrix.standalone }}
|
||||||
|
|
||||||
|
- name: install Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
# pnpm@7.0.0 is not compatible with Node.js 12
|
||||||
|
node-version: 12.22.12
|
||||||
|
|
||||||
|
- name: 'Test: which (pnpm)'
|
||||||
|
run: which pnpm
|
||||||
|
|
||||||
|
- name: 'Test: which (pnpx)'
|
||||||
|
if: matrix.standalone == false
|
||||||
|
run: which pnpx
|
||||||
|
|
||||||
|
- name: 'Test: install when standalone is true'
|
||||||
|
if: matrix.standalone
|
||||||
|
run: pnpm install
|
||||||
|
|
||||||
|
- name: 'Test: install when standalone is false'
|
||||||
|
if: matrix.standalone == false
|
||||||
|
# Since the default shell on windows runner is pwsh, we specify bash explicitly
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if pnpm install; then
|
||||||
|
echo "pnpm install should fail"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "pnpm install failed as expected"
|
||||||
|
fi
|
||||||
|
|
||||||
test_run_install:
|
test_run_install:
|
||||||
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
|
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
|
||||||
|
|
||||||
@ -107,7 +162,7 @@ jobs:
|
|||||||
- pnpm
|
- pnpm
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@ node_modules
|
|||||||
*.log
|
*.log
|
||||||
/dist/*
|
/dist/*
|
||||||
!/dist/index.js
|
!/dist/index.js
|
||||||
|
!/dist/pnpm.js
|
||||||
tmp
|
tmp
|
||||||
temp
|
temp
|
||||||
*.tmp
|
*.tmp
|
||||||
|
89
README.md
89
README.md
@ -6,7 +6,11 @@ Install pnpm package manager.
|
|||||||
|
|
||||||
### `version`
|
### `version`
|
||||||
|
|
||||||
**Required** Version of pnpm to install. It supports npm versioning scheme, it could be an exact version (such as `6.24.1`), or a version range (such as `6`, `6.x.x`, `6.24.x`, `^6.24.1`, `*`, etc.), or `latest`.
|
Version of pnpm to install.
|
||||||
|
|
||||||
|
**Optional** when there is a [`packageManager` field in the `package.json`](https://nodejs.org/api/corepack.html).
|
||||||
|
|
||||||
|
otherwise, this field is **required** It supports npm versioning scheme, it could be an exact version (such as `6.24.1`), or a version range (such as `6`, `6.x.x`, `6.24.x`, `^6.24.1`, `*`, etc.), or `latest`.
|
||||||
|
|
||||||
### `dest`
|
### `dest`
|
||||||
|
|
||||||
@ -34,6 +38,16 @@ If `run_install` is a YAML string representation of either an object or an array
|
|||||||
|
|
||||||
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --strict-peer-dependencies]`.
|
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --strict-peer-dependencies]`.
|
||||||
|
|
||||||
|
### `package_json_file`
|
||||||
|
|
||||||
|
**Optional** (_type:_ `string`, _default:_ `package.json`) File path to the `package.json` to read "packageManager" configuration.
|
||||||
|
|
||||||
|
### `standalone`
|
||||||
|
|
||||||
|
**Optional** (_type:_ `boolean`, _default:_ `false`) When set to true, [@pnpm/exe](https://www.npmjs.com/package/@pnpm/exe), which is a Node.js bundled package, will be installed, enabling using `pnpm` without Node.js.
|
||||||
|
|
||||||
|
This is useful when you want to use a incompatible pair of Node.js and pnpm.
|
||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|
||||||
### `dest`
|
### `dest`
|
||||||
@ -54,12 +68,13 @@ on:
|
|||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
runs-on: ubuntu-latest
|
install:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: pnpm/action-setup@v2.0.1
|
- uses: pnpm/action-setup@v2
|
||||||
with:
|
with:
|
||||||
version: 6.0.2
|
version: 8
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install pnpm and a few npm packages
|
### Install pnpm and a few npm packages
|
||||||
@ -70,18 +85,19 @@ on:
|
|||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
runs-on: ubuntu-latest
|
install:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v2.0.1
|
- uses: pnpm/action-setup@v2
|
||||||
with:
|
with:
|
||||||
version: 6.0.2
|
version: 8
|
||||||
run_install: |
|
run_install: |
|
||||||
- recursive: true
|
- recursive: true
|
||||||
args: [--frozen-lockfile, --strict-peer-dependencies]
|
args: [--frozen-lockfile, --strict-peer-dependencies]
|
||||||
- args: [--global, gulp, prettier, typescript]
|
- args: [--global, gulp, prettier, typescript]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Use cache to reduce installation time
|
### Use cache to reduce installation time
|
||||||
@ -92,24 +108,39 @@ on:
|
|||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
runs-on: ubuntu-latest
|
cache-and-install:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
build:
|
- name: Checkout
|
||||||
- uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Cache pnpm modules
|
- name: Install Node.js
|
||||||
uses: actions/cache@v2
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.pnpm-store
|
node-version: 16
|
||||||
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
||||||
|
- uses: pnpm/action-setup@v2
|
||||||
|
name: Install pnpm
|
||||||
|
with:
|
||||||
|
version: 8
|
||||||
|
run_install: false
|
||||||
|
|
||||||
|
- name: Get pnpm store directory
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
name: Setup pnpm cache
|
||||||
|
with:
|
||||||
|
path: ${{ env.STORE_PATH }}
|
||||||
|
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-
|
${{ runner.os }}-pnpm-store-
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v2.0.1
|
- name: Install dependencies
|
||||||
with:
|
run: pnpm install
|
||||||
version: 6.0.2
|
|
||||||
run_install: true
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that.
|
**Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that.
|
||||||
|
20
action.yml
20
action.yml
@ -1,21 +1,29 @@
|
|||||||
name: Setup PNPM
|
name: Setup pnpm
|
||||||
description: Install PNPM package manager
|
description: Install pnpm package manager
|
||||||
branding:
|
branding:
|
||||||
icon: package
|
icon: package
|
||||||
color: orange
|
color: orange
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
description: Version of PNPM to install
|
description: Version of pnpm to install
|
||||||
required: true
|
required: false
|
||||||
dest:
|
dest:
|
||||||
description: Where to store PNPM files
|
description: Where to store pnpm files
|
||||||
required: false
|
required: false
|
||||||
default: ~/setup-pnpm
|
default: ~/setup-pnpm
|
||||||
run_install:
|
run_install:
|
||||||
description: If specified, run `pnpm install`
|
description: If specified, run `pnpm install`
|
||||||
required: false
|
required: false
|
||||||
default: 'null'
|
default: 'null'
|
||||||
|
package_json_file:
|
||||||
|
description: File path to the package.json to read "packageManager" configuration
|
||||||
|
required: false
|
||||||
|
default: 'package.json'
|
||||||
|
standalone:
|
||||||
|
description: When set to true, @pnpm/exe, which is a Node.js bundled package, will be installed, enabling using pnpm without Node.js.
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
runs:
|
runs:
|
||||||
using: node12
|
using: node16
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
post: dist/index.js
|
post: dist/index.js
|
||||||
|
BIN
dist/index.js
vendored
BIN
dist/index.js
vendored
Binary file not shown.
134031
dist/pnpm.js
vendored
Normal file
134031
dist/pnpm.js
vendored
Normal file
File diff suppressed because one or more lines are too long
25
package.json
25
package.json
@ -3,25 +3,24 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build:schemas": "ts-schema-autogen generate",
|
"build:schemas": "ts-schema-autogen generate",
|
||||||
"build:ncc": "ncc build --minify --no-source-map-register --no-cache dist/tsc/index.js --out dist/",
|
"build:ncc": "ncc build --minify --no-source-map-register --no-cache dist/tsc/index.js --out dist/",
|
||||||
"build": "pnpm run build:schemas && tsc && pnpm run build:ncc",
|
"build": "pnpm run build:schemas && tsc && pnpm run build:ncc && cp src/install-pnpm/pnpm.js dist/pnpm.js",
|
||||||
"start": "pnpm run build && sh ./run.sh"
|
"start": "pnpm run build && sh ./run.sh"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"node-fetch": "^2.6.1",
|
"@actions/core": "^1.10.0",
|
||||||
"expand-tilde": "^2.0.2",
|
|
||||||
"js-yaml": "^4.0.0",
|
|
||||||
"ajv": "^6.12.5",
|
|
||||||
"fs-extra": "^9.1.0",
|
|
||||||
"@actions/core": "^1.2.6",
|
|
||||||
"@types/expand-tilde": "^2.0.0",
|
"@types/expand-tilde": "^2.0.0",
|
||||||
"@types/node-fetch": "^2.5.8",
|
"@types/fs-extra": "^9.0.13",
|
||||||
"@types/js-yaml": "^4.0.0",
|
"@types/js-yaml": "^4.0.5",
|
||||||
"@types/fs-extra": "^9.0.8",
|
"@types/node": "^14.18.54",
|
||||||
"@types/node": "^14.14.35"
|
"@types/node-fetch": "^2.6.4",
|
||||||
|
"ajv": "^6.12.6",
|
||||||
|
"expand-tilde": "^2.0.2",
|
||||||
|
"fs-extra": "^10.1.0",
|
||||||
|
"js-yaml": "^4.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^4.2.3",
|
|
||||||
"@ts-schema-autogen/cli": "^0.1.2",
|
"@ts-schema-autogen/cli": "^0.1.2",
|
||||||
"@vercel/ncc": "^0.27.0"
|
"@vercel/ncc": "^0.33.4",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1167
pnpm-lock.yaml
1167
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
1
run.sh
1
run.sh
@ -4,4 +4,5 @@ export HOME="$(pwd)"
|
|||||||
export INPUT_VERSION=4.11.1
|
export INPUT_VERSION=4.11.1
|
||||||
export INPUT_DEST='~/pnpm.temp'
|
export INPUT_DEST='~/pnpm.temp'
|
||||||
export INPUT_RUN_INSTALL=null
|
export INPUT_RUN_INSTALL=null
|
||||||
|
export INPUT_standalone=false
|
||||||
exec node dist/index.js
|
exec node dist/index.js
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { setFailed, saveState, getState } from '@actions/core'
|
import { setFailed, saveState, getState } from '@actions/core'
|
||||||
import getInputs from './inputs'
|
import getInputs from './inputs'
|
||||||
import setOutputs from './outputs'
|
|
||||||
import installPnpm from './install-pnpm'
|
import installPnpm from './install-pnpm'
|
||||||
|
import setOutputs from './outputs'
|
||||||
import pnpmInstall from './pnpm-install'
|
import pnpmInstall from './pnpm-install'
|
||||||
import pruneStore from './pnpm-store-prune'
|
import pruneStore from './pnpm-store-prune'
|
||||||
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import { getInput, InputOptions } from '@actions/core'
|
import { getBooleanInput, getInput, InputOptions } from '@actions/core'
|
||||||
import expandTilde from 'expand-tilde'
|
import expandTilde from 'expand-tilde'
|
||||||
import { RunInstall, parseRunInstall } from './run-install'
|
import { RunInstall, parseRunInstall } from './run-install'
|
||||||
|
|
||||||
export interface Inputs {
|
export interface Inputs {
|
||||||
readonly version: string
|
readonly version?: string
|
||||||
readonly dest: string
|
readonly dest: string
|
||||||
readonly runInstall: RunInstall[]
|
readonly runInstall: RunInstall[]
|
||||||
|
readonly packageJsonFile: string
|
||||||
|
readonly standalone: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const options: InputOptions = {
|
const options: InputOptions = {
|
||||||
@ -15,9 +17,11 @@ const options: InputOptions = {
|
|||||||
const parseInputPath = (name: string) => expandTilde(getInput(name, options))
|
const parseInputPath = (name: string) => expandTilde(getInput(name, options))
|
||||||
|
|
||||||
export const getInputs = (): Inputs => ({
|
export const getInputs = (): Inputs => ({
|
||||||
version: getInput('version', options),
|
version: getInput('version'),
|
||||||
dest: parseInputPath('dest'),
|
dest: parseInputPath('dest'),
|
||||||
runInstall: parseRunInstall('run_install'),
|
runInstall: parseRunInstall('run_install'),
|
||||||
|
packageJsonFile: parseInputPath('package_json_file'),
|
||||||
|
standalone: getBooleanInput('standalone'),
|
||||||
})
|
})
|
||||||
|
|
||||||
export default getInputs
|
export default getInputs
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import process from 'process'
|
|
||||||
import { load } from 'js-yaml'
|
|
||||||
import Ajv from 'ajv'
|
|
||||||
import { getInput, error, InputOptions } from '@actions/core'
|
import { getInput, error, InputOptions } from '@actions/core'
|
||||||
|
import Ajv from 'ajv'
|
||||||
|
import { load } from 'js-yaml'
|
||||||
|
import process from 'process'
|
||||||
import runInstallSchema from './run-install-input.schema.json'
|
import runInstallSchema from './run-install-input.schema.json'
|
||||||
|
|
||||||
export interface RunInstall {
|
export interface RunInstall {
|
||||||
|
134031
src/install-pnpm/pnpm.js
Normal file
134031
src/install-pnpm/pnpm.js
Normal file
File diff suppressed because one or more lines are too long
@ -1,31 +1,72 @@
|
|||||||
|
import { addPath, exportVariable } from '@actions/core'
|
||||||
import { spawn } from 'child_process'
|
import { spawn } from 'child_process'
|
||||||
|
import { remove, ensureFile, writeFile, readFile } from 'fs-extra'
|
||||||
|
import path from 'path'
|
||||||
import { execPath } from 'process'
|
import { execPath } from 'process'
|
||||||
import { join } from 'path'
|
|
||||||
import { remove, ensureFile, writeFile } from 'fs-extra'
|
|
||||||
import fetch from 'node-fetch'
|
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
|
|
||||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||||
const { version, dest } = inputs
|
const { version, dest, packageJsonFile, standalone } = inputs
|
||||||
const target = version ? `pnpm@${version}` : 'pnpm'
|
|
||||||
const pkgJson = join(dest, 'package.json')
|
|
||||||
|
|
||||||
|
// prepare self install
|
||||||
await remove(dest)
|
await remove(dest)
|
||||||
|
const pkgJson = path.join(dest, 'package.json')
|
||||||
await ensureFile(pkgJson)
|
await ensureFile(pkgJson)
|
||||||
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
||||||
|
|
||||||
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
|
// prepare target pnpm
|
||||||
|
const target = await readTarget({ version, packageJsonFile, standalone })
|
||||||
|
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.js'), 'install', target, '--no-lockfile'], {
|
||||||
cwd: dest,
|
cwd: dest,
|
||||||
stdio: ['pipe', 'inherit', 'inherit'],
|
stdio: ['pipe', 'inherit', 'inherit'],
|
||||||
})
|
})
|
||||||
|
|
||||||
const response = await fetch('https://pnpm.js.org/pnpm.js')
|
const exitCode = await new Promise<number>((resolve, reject) => {
|
||||||
response.body.pipe(cp.stdin)
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
cp.on('error', reject)
|
cp.on('error', reject)
|
||||||
cp.on('close', resolve)
|
cp.on('close', resolve)
|
||||||
})
|
})
|
||||||
|
if (exitCode === 0) {
|
||||||
|
const pnpmHome = path.join(dest, 'node_modules/.bin')
|
||||||
|
addPath(pnpmHome)
|
||||||
|
exportVariable('PNPM_HOME', pnpmHome)
|
||||||
|
}
|
||||||
|
return exitCode
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readTarget(opts: {
|
||||||
|
readonly version?: string | undefined
|
||||||
|
readonly packageJsonFile: string
|
||||||
|
readonly standalone: boolean
|
||||||
|
}) {
|
||||||
|
const { version, packageJsonFile, standalone } = opts
|
||||||
|
|
||||||
|
if (version) return `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}`
|
||||||
|
|
||||||
|
const { GITHUB_WORKSPACE } = process.env
|
||||||
|
if (!GITHUB_WORKSPACE) {
|
||||||
|
throw new Error(`No workspace is found.
|
||||||
|
If you're intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,
|
||||||
|
please run the actions/checkout before pnpm/action-setup.
|
||||||
|
Otherwise, please specify the pnpm version in the action configuration.`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8'))
|
||||||
|
if (typeof packageManager !== 'string') {
|
||||||
|
throw new Error(`No pnpm version is specified.
|
||||||
|
Please specify it by one of the following ways:
|
||||||
|
- in the GitHub Action config with the key "version"
|
||||||
|
- in the package.json with the key "packageManager"`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!packageManager.startsWith('pnpm@')) {
|
||||||
|
throw new Error('Invalid packageManager field in package.json')
|
||||||
|
}
|
||||||
|
|
||||||
|
if(standalone){
|
||||||
|
return packageManager.replace('pnpm@', '@pnpm/exe@')
|
||||||
|
}
|
||||||
|
|
||||||
|
return packageManager
|
||||||
}
|
}
|
||||||
|
|
||||||
export default runSelfInstaller
|
export default runSelfInstaller
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { spawnSync } from 'child_process'
|
|
||||||
import { setFailed, startGroup, endGroup } from '@actions/core'
|
import { setFailed, startGroup, endGroup } from '@actions/core'
|
||||||
|
import { spawnSync } from 'child_process'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
import { patchPnpmEnv } from '../utils'
|
import { patchPnpmEnv } from '../utils'
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { spawnSync } from 'child_process'
|
|
||||||
import { warning, startGroup, endGroup } from '@actions/core'
|
import { warning, startGroup, endGroup } from '@actions/core'
|
||||||
|
import { spawnSync } from 'child_process'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
import { patchPnpmEnv } from '../utils'
|
import { patchPnpmEnv } from '../utils'
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ export function pruneStore(inputs: Inputs) {
|
|||||||
const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
|
const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
shell: true,
|
shell: true,
|
||||||
env: patchPnpmEnv(inputs)
|
env: patchPnpmEnv(inputs),
|
||||||
})
|
})
|
||||||
endGroup()
|
endGroup()
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import process from 'process'
|
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import process from 'process'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
|
|
||||||
export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin')
|
export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin')
|
||||||
|
|
||||||
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
|
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
|
||||||
...process.env,
|
...process.env,
|
||||||
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH
|
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user