Merge pull request #88 from KengoTODA/make-path-configurable

support projects that have package.json in non-root directory
This commit is contained in:
Khải 2023-07-25 16:59:00 +07:00 committed by GitHub
commit 2ed49cbb02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 4 deletions

View File

@ -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]`. **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 ## Outputs
### `dest` ### `dest`

View File

@ -15,6 +15,10 @@ inputs:
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" configutation
required: false
default: 'package.json'
runs: runs:
using: node16 using: node16
main: dist/index.js main: dist/index.js

BIN
dist/index.js vendored

Binary file not shown.

View File

@ -6,6 +6,7 @@ export interface Inputs {
readonly version?: string readonly version?: string
readonly dest: string readonly dest: string
readonly runInstall: RunInstall[] readonly runInstall: RunInstall[]
readonly packageJsonFile: string
} }
const options: InputOptions = { const options: InputOptions = {
@ -18,6 +19,7 @@ export const getInputs = (): Inputs => ({
version: getInput('version'), version: getInput('version'),
dest: parseInputPath('dest'), dest: parseInputPath('dest'),
runInstall: parseRunInstall('run_install'), runInstall: parseRunInstall('run_install'),
packageJsonFile: parseInputPath('package_json_file'),
}) })
export default getInputs export default getInputs

View File

@ -6,7 +6,7 @@ import { execPath } from 'process'
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 } = inputs
// prepare self install // prepare self install
await remove(dest) await remove(dest)
@ -15,7 +15,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
await writeFile(pkgJson, JSON.stringify({ private: true })) await writeFile(pkgJson, JSON.stringify({ private: true }))
// prepare target pnpm // 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'], { 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'],
@ -33,7 +33,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
return exitCode return exitCode
} }
async function readTarget(version?: string | undefined) { async function readTarget(packageJsonFile: string, version?: string | undefined) {
if (version) return `pnpm@${version}` if (version) return `pnpm@${version}`
const { GITHUB_WORKSPACE } = process.env const { GITHUB_WORKSPACE } = process.env
@ -44,7 +44,7 @@ please run the actions/checkout before pnpm/action-setup.
Otherwise, please specify the pnpm version in the action configuration.`) 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') { if (typeof packageManager !== 'string') {
throw new Error(`No pnpm version is specified. throw new Error(`No pnpm version is specified.
Please specify it by one of the following ways: Please specify it by one of the following ways: