From 5626e8797fb3a5c16204c55df52370d6647101c2 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Thu, 24 Feb 2022 18:49:44 +0800 Subject: [PATCH] fix: packageManager reader --- action.yml | 1 - dist/index.js | Bin 444119 -> 444427 bytes src/install-pnpm/run.ts | 21 +++++++++++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index cbb4c7e..a7c10e2 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,6 @@ branding: inputs: version: description: Version of PNPM to install - required: true dest: description: Where to store PNPM files required: false diff --git a/dist/index.js b/dist/index.js index 440697a2b1671ffdbd117c9033b8cbd2dbe11a8b..5cb33a29a9af1ce44456e2c90fbb2569f461a882 100644 GIT binary patch delta 488 zcmZ8dyGjE=6eT`VL}MjbXfcGKyRfdNQjmxbf(FruiD)61arbUAdCXmAW)orv78WT) z5Ek(_1PihBC-gV`1Sf06U~!tmJ&$`n@8|Cx=AYAvxG*xSnYC~^QCO#K%9OEcQCmP0 zTVNW(+;EUfMR->8fn7t!HEX4O>eOik?3zTL3O^F(vraaW69LpMQBeV9sF%g5Vl45e z4ExiMn`W1J2ABd=Ab8p5ese3`gq_Vz12c)!tx9q)qY5#QR@~m)jP(0q=&22n= zU60RI%121rDC$!80Kz2kFyO9z!Sf#JV6Y@K$rW%HT%wRPKoM2dXVg&)dDM{%l1U4M z959~1ral2O`q)bNJ~Mk`U2wkvR00tJk8XZklVXP!ophM|F>x#naoE`Rmp{Ji24g*@9*y_D3n#L}D+y{!C9pb{OW zg2d$P#Pn3Xtm6DUrOAxk(h_+(C7RZW<%yXk8U{LvdPS+Z`DLk^8by;gaz$)b<@RRe zLp5b`70*;@pq}c?G>sC?qSTVoqP&EHyn { const { version, dest } = inputs - const pkgJson = path.join(dest, 'package.json') - const target = await readTarget(pkgJson, version) + // prepare self install await remove(dest) + const pkgJson = join(dest, 'package.json') await ensureFile(pkgJson) await writeFile(pkgJson, JSON.stringify({ private: true })) + // prepare target pnpm + const target = await readTarget(version) const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], { cwd: dest, stdio: ['pipe', 'inherit', 'inherit'], @@ -29,17 +31,24 @@ export async function runSelfInstaller(inputs: Inputs): Promise { cp.on('close', resolve) }) if (exitCode === 0) { - const pnpmHome = path.join(dest, 'node_modules/.bin') + const pnpmHome = join(dest, 'node_modules/.bin') addPath(pnpmHome) exportVariable('PNPM_HOME', pnpmHome) } return exitCode } -async function readTarget(packageJsonPath: string, version?: string | undefined) { +async function readTarget(version?: string | undefined) { if (version) return `pnpm@${version}` - const { packageManager } = JSON.parse(await readFile(packageJsonPath, 'utf8')) + const workspace = process.env.GITHUB_WORKSPACE + if (!workspace) { + throw new Error(`No workspace is found. +If you're intended to let this action read pnpm version from the package.json/packageManager field, +please run the actions/checkout before this one, otherwise please specify the version in the action config.`) + } + + const { packageManager } = JSON.parse(await readFile(join(workspace, 'package.json'), 'utf8')) if (typeof packageManager !== 'string') { throw new Error(`No pnpm version is specified. Please specify it by one of the following ways: