Skip to content

Commit b27f801

Browse files
committed
feat: add package_json_file option
Signed-off-by: Kengo TODA <skypencil@gmail.com>
1 parent 11dd14d commit b27f801

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ If `run_install` is a YAML string representation of either an object or an array
3838

3939
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --strict-peer-dependencies]`.
4040

41+
### `package_json_file`
42+
43+
**Optional** File path to the `package.json` to read "packageManager" configutation. If not specified, `package.json` in the project root directory is used.
44+
4145
## Outputs
4246

4347
### `dest`

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ branding:
66
inputs:
77
version:
88
description: Version of pnpm to install
9+
required: false
910
dest:
1011
description: Where to store pnpm files
1112
required: false
@@ -14,6 +15,10 @@ inputs:
1415
description: If specified, run `pnpm install`
1516
required: false
1617
default: 'null'
18+
package_json_file:
19+
description: File path to the package.json to read "packageManager" configutation
20+
required: false
21+
default: 'package.json'
1722
runs:
1823
using: node16
1924
main: dist/index.js

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/inputs/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface Inputs {
66
readonly version?: string
77
readonly dest: string
88
readonly runInstall: RunInstall[]
9+
readonly packageJsonFile: string
910
}
1011

1112
const options: InputOptions = {
@@ -18,6 +19,7 @@ export const getInputs = (): Inputs => ({
1819
version: getInput('version'),
1920
dest: parseInputPath('dest'),
2021
runInstall: parseRunInstall('run_install'),
22+
packageJsonFile: parseInputPath('package_json_file'),
2123
})
2224

2325
export default getInputs

src/install-pnpm/run.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { execPath } from 'process'
66
import { Inputs } from '../inputs'
77

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

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

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

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

3939
const { GITHUB_WORKSPACE } = process.env
@@ -44,7 +44,7 @@ please run the actions/checkout before pnpm/action-setup.
4444
Otherwise, please specify the pnpm version in the action configuration.`)
4545
}
4646

47-
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, 'package.json'), 'utf8'))
47+
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8'))
4848
if (typeof packageManager !== 'string') {
4949
throw new Error(`No pnpm version is specified.
5050
Please specify it by one of the following ways:

0 commit comments

Comments
 (0)