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

feat: try support packageManager #33

Merged
merged 5 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ Install pnpm package manager.

### `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`

Expand Down
39 changes: 38 additions & 1 deletion dist/index.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
},
"dependencies": {
"@actions/core": "^1.6.0",
"@pnpm/fetch": "^4.2.4",
"@pnpm/fetch": "^4.2.5",
"@pnpm/logger": "^4.0.0",
"@types/expand-tilde": "^2.0.0",
"@types/fs-extra": "^9.0.13",
"@types/js-yaml": "^4.0.5",
"@types/node": "^14.18.10",
"@types/node-fetch": "^2.5.12",
"@types/node-fetch": "^2.6.1",
"ajv": "^6.12.6",
"expand-tilde": "^2.0.2",
"fs-extra": "^9.1.0",
"fs-extra": "^10.0.0",
"js-yaml": "^4.1.0"
},
"devDependencies": {
"@ts-schema-autogen/cli": "^0.1.2",
"@vercel/ncc": "^0.27.0",
"@vercel/ncc": "^0.33.3",
"typescript": "^4.5.5"
}
}
64 changes: 29 additions & 35 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/inputs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import expandTilde from 'expand-tilde'
import { RunInstall, parseRunInstall } from './run-install'

export interface Inputs {
readonly version: string
readonly version?: string
readonly dest: string
readonly runInstall: RunInstall[]
}
Expand All @@ -15,7 +15,7 @@ const options: InputOptions = {
const parseInputPath = (name: string) => expandTilde(getInput(name, options))

export const getInputs = (): Inputs => ({
version: getInput('version', options),
version: getInput('version'),
KSXGitHub marked this conversation as resolved.
Show resolved Hide resolved
dest: parseInputPath('dest'),
runInstall: parseRunInstall('run_install'),
})
Expand Down
18 changes: 16 additions & 2 deletions src/install-pnpm/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@ import { addPath, exportVariable } from '@actions/core'
import { spawn } from 'child_process'
import { execPath } from 'process'
import path from 'path'
import { remove, ensureFile, writeFile } from 'fs-extra'
import { remove, ensureFile, writeFile, readFile } from 'fs-extra'
import fetch from '@pnpm/fetch'
import { Inputs } from '../inputs'

export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const { version, dest } = inputs
const target = version ? `pnpm@${version}` : 'pnpm'
const pkgJson = path.join(dest, 'package.json')
let target: string

if (!version) {
const packageManager = JSON.parse(await readFile(pkgJson, 'utf8')).packageManager
Jack-Works marked this conversation as resolved.
Show resolved Hide resolved
if (packageManager) {
Jack-Works marked this conversation as resolved.
Show resolved Hide resolved
if (!packageManager.startsWith('pnpm@')) {
Jack-Works marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('packageManager field is not pnpm')
Jack-Works marked this conversation as resolved.
Show resolved Hide resolved
}
target = packageManager
} else {
throw new Error('None of packageManager (in package.json) or version (in action config) is defined')
}
} else {
target = `pnpm@${version}`
}
Jack-Works marked this conversation as resolved.
Show resolved Hide resolved

await remove(dest)
await ensureFile(pkgJson)
Expand Down