Skip to content

Commit

Permalink
Merge branch 'v2'
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed Mar 27, 2021
2 parents b7b9d63 + 2124926 commit 3236b20
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 48 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ jobs:
with:
version: 4.11.1
dest: ~/test/pnpm
bin_dest: ~/test/pnpm/.bin
registry: http://registry.yarnpkg.com/

- name: 'Test: which'
run: which pnpm && which pnpx
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ temp
*.temp
tmp.*
temp.*
.pnpm-store
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ Install PNPM package manager.

**Optional** Where to store PNPM files.

### `bin_dest`

**Optional** Where to store executables (`pnpm` and `pnpx` commands).

### `registry`

**Optional** (_default:_ `https://registry.npmjs.com`) Registry to download PNPM from.

### `run_install`

**Optional** (_default:_ `null`) If specified, run `pnpm install`.
Expand Down Expand Up @@ -50,7 +42,7 @@ Expanded path of inputs#dest.

### `bin_dest`

Expanded path of inputs#bin_dest.
Location of `pnpm` and `pnpx` command.

## Usage example

Expand Down
8 changes: 0 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ inputs:
description: Where to store PNPM files
required: false
default: ~/setup-pnpm
bin_dest:
description: Where to store executables (pnpm and pnpx commands)
required: false
default: ~/setup-pnpm/.bin
registry:
description: Registry to download PNPM from
required: false
default: https://registry.npmjs.com
run_install:
description: If specified, run `pnpm install`
required: false
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
"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/node-fetch": "^2.5.8",
"@types/js-yaml": "^4.0.0",
"@types/fs-extra": "^9.0.8",
"@types/node": "^14.14.35"
},
"devDependencies": {
Expand Down
42 changes: 41 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
export HOME="$(pwd)"
export INPUT_VERSION=4.11.1
export INPUT_DEST='~/pnpm.temp'
export INPUT_BIN_DEST='~/pnpm.temp/.bin'
export INPUT_REGISTRY=https://registry.npmjs.com
export INPUT_RUN_INSTALL=null
exec node dist/index.js
4 changes: 0 additions & 4 deletions src/inputs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { RunInstall, parseRunInstall } from './run-install'
export interface Inputs {
readonly version: string
readonly dest: string
readonly binDest: string
readonly registry: string
readonly runInstall: RunInstall[]
}

Expand All @@ -19,8 +17,6 @@ const parseInputPath = (name: string) => expandTilde(getInput(name, options))
export const getInputs = (): Inputs => ({
version: getInput('version', options),
dest: parseInputPath('dest'),
binDest: parseInputPath('bin_dest'),
registry: getInput('registry', options),
runInstall: parseRunInstall('run_install'),
})

Expand Down
23 changes: 14 additions & 9 deletions src/install-pnpm/run.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { spawn } from 'child_process'
import { execPath } from 'process'
import { downloadSelfInstaller } from '../self-installer'
import { join } from 'path'
import { remove, ensureFile, writeFile } from 'fs-extra'
import fetch from 'node-fetch'
import { Inputs } from '../inputs'

export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const cp = spawn(execPath, {
env: {
PNPM_VERSION: inputs.version,
PNPM_DEST: inputs.dest,
PNPM_BIN_DEST: inputs.binDest,
PNPM_REGISTRY: inputs.registry,
},
const { version, dest } = inputs
const target = version ? `pnpm@${version}` : 'pnpm'
const pkgJson = join(dest, 'package.json')

await remove(dest)
await ensureFile(pkgJson)
await writeFile(pkgJson, JSON.stringify({ private: true }))

const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
cwd: dest,
stdio: ['pipe', 'inherit', 'inherit'],
})

const response = await downloadSelfInstaller()
const response = await fetch('https://pnpm.js.org/pnpm.js')
response.body.pipe(cp.stdin)

return new Promise((resolve, reject) => {
Expand Down
6 changes: 4 additions & 2 deletions src/outputs/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { setOutput, addPath } from '@actions/core'
import { Inputs } from '../inputs'
import { getBinDest } from '../utils'

export function setOutputs(inputs: Inputs) {
addPath(inputs.binDest)
const binDest = getBinDest(inputs)
addPath(binDest)
setOutput('dest', inputs.dest)
setOutput('bin_dest', inputs.binDest)
setOutput('bin_dest', binDest)
}

export default setOutputs
4 changes: 0 additions & 4 deletions src/self-installer/download.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/self-installer/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/self-installer/url.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import process from 'process'
import path from 'path'
import { Inputs } from '../inputs'

export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin')

export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
...process.env,
PATH: inputs.binDest + path.delimiter + process.env.PATH
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH
})

0 comments on commit 3236b20

Please sign in to comment.