Skip to content

Commit

Permalink
feat: add package_json_file option
Browse files Browse the repository at this point in the history
Signed-off-by: Kengo TODA <skypencil@gmail.com>
  • Loading branch information
KengoTODA committed Jul 7, 2023
1 parent 11dd14d commit b27f801
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ 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]`.

### `package_json_file`

**Optional** File path to the `package.json` to read "packageManager" configutation. If not specified, `package.json` in the project root directory is used.

## Outputs

### `dest`
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ branding:
inputs:
version:
description: Version of pnpm to install
required: false
dest:
description: Where to store pnpm files
required: false
Expand All @@ -14,6 +15,10 @@ inputs:
description: If specified, run `pnpm install`
required: false
default: 'null'
package_json_file:
description: File path to the package.json to read "packageManager" configutation
required: false
default: 'package.json'
runs:
using: node16
main: dist/index.js
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/inputs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Inputs {
readonly version?: string
readonly dest: string
readonly runInstall: RunInstall[]
readonly packageJsonFile: string
}

const options: InputOptions = {
Expand All @@ -18,6 +19,7 @@ export const getInputs = (): Inputs => ({
version: getInput('version'),
dest: parseInputPath('dest'),
runInstall: parseRunInstall('run_install'),
packageJsonFile: parseInputPath('package_json_file'),
})

export default getInputs
8 changes: 4 additions & 4 deletions src/install-pnpm/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { execPath } from 'process'
import { Inputs } from '../inputs'

export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const { version, dest } = inputs
const { version, dest, packageJsonFile } = inputs

// prepare self install
await remove(dest)
Expand All @@ -15,7 +15,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
await writeFile(pkgJson, JSON.stringify({ private: true }))

// prepare target pnpm
const target = await readTarget(version)
const target = await readTarget(packageJsonFile, version)
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.js'), 'install', target, '--no-lockfile'], {
cwd: dest,
stdio: ['pipe', 'inherit', 'inherit'],
Expand All @@ -33,7 +33,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
return exitCode
}

async function readTarget(version?: string | undefined) {
async function readTarget(packageJsonFile: string, version?: string | undefined) {
if (version) return `pnpm@${version}`

const { GITHUB_WORKSPACE } = process.env
Expand All @@ -44,7 +44,7 @@ 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, 'package.json'), 'utf8'))
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:
Expand Down

0 comments on commit b27f801

Please sign in to comment.