From b27f801bf9a3592a294d56dcc4b10be26bbbfd65 Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Sat, 8 Jul 2023 07:02:46 +0800 Subject: [PATCH] feat: add package_json_file option Signed-off-by: Kengo TODA --- README.md | 4 ++++ action.yml | 5 +++++ dist/index.js | Bin 272325 -> 272386 bytes src/inputs/index.ts | 2 ++ src/install-pnpm/run.ts | 8 ++++---- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e24f1ee..40de701 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/action.yml b/action.yml index c99a823..ec60c94 100644 --- a/action.yml +++ b/action.yml @@ -6,6 +6,7 @@ branding: inputs: version: description: Version of pnpm to install + required: false dest: description: Where to store pnpm files required: false @@ -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 diff --git a/dist/index.js b/dist/index.js index 97128e389fd4492d62557e4b9d1d66cbf9c6c9d9..47b87f36ddb41fa28c98f12574ae784e1bdebe57 100644 GIT binary patch delta 397 zcmZXNPfEi;6o*MIDs62FiniStgWwE=Qd|{7#6|JnstdQJ4)LW%+nHfz(xN3BU3h>w zfLBnu@B+FNUFH(r!NgV&T>KXAz3=zEw~xx*XXUA$-*q_guSp+HC8LMo0QNW$5>6Ln&3-JFY?Ehl$ulNS-pOSlnW$-;X`P&(S6rfyJUM{dow0QC3~m?3w8?k5Wz>`P z^7Ay5Qj3c6icITuoc!WcC7o2wT1`#s%ruR($qGCLKphi#9Go?)fdZ+TMX4pF zMR^GYc?G!+D%GjA2@or)-91A*LY?Bn{e!%N100=Qt%_=G3ySiSQ;UoBQuE3{rYTM? zbQjsI#cRsQSTZ?*&p@q6N2wq&IXf{uRWGYJKTk ({ version: getInput('version'), dest: parseInputPath('dest'), runInstall: parseRunInstall('run_install'), + packageJsonFile: parseInputPath('package_json_file'), }) export default getInputs diff --git a/src/install-pnpm/run.ts b/src/install-pnpm/run.ts index 9feafba..6660f09 100644 --- a/src/install-pnpm/run.ts +++ b/src/install-pnpm/run.ts @@ -6,7 +6,7 @@ import { execPath } from 'process' import { Inputs } from '../inputs' export async function runSelfInstaller(inputs: Inputs): Promise { - const { version, dest } = inputs + const { version, dest, packageJsonFile } = inputs // prepare self install await remove(dest) @@ -15,7 +15,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise { 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'], @@ -33,7 +33,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise { 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 @@ -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: