From 35ab4267a1a21c8e8cb1c087cf1642e891ff57bd Mon Sep 17 00:00:00 2001 From: Jack Works Date: Fri, 25 Feb 2022 12:43:26 +0800 Subject: [PATCH] fix: packageManager reader (#35) * fix: packageManager reader * chore: resolve review * chore: run build --- action.yml | 1 - dist/index.js | Bin 444119 -> 444496 bytes src/install-pnpm/run.ts | 18 ++++++++++++++---- 3 files changed, 14 insertions(+), 5 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..bc0966bd300c3c353dd2abdae75f4dcb1f2a3d79 100644 GIT binary patch delta 491 zcmZXQJ4*vW6orYeB9bm(VRMP1yAoHsfI)mADxwjejbO&zJIR>M%yMToA;w@~VI>GD z{2PLW_%H1AXINP~n@44FrkHc)p6|}r)AZ-_^y^(Z%bH9WXF1P2!n$gp>yX=Rrx&{4 z>GQ0=+OvU>1*eQEXdLr4H~E`dbK8PD=n|TkWI2*ieSNl#opRAvQk(Y9-s$ey=G8^% zc>m;RV{3cGbXFr$K5FfuY!qL9Zbzr?%ZCb@ifTGyK7!D|RV)MVQtokRsd%33r8Fo5 z48SM|(LmC)#C#)^T-3Ha>ajsY$dSnAk^nT2v`qjfRR>c=$k~P(tKb2X_M{wef#H2% z$M@`k>)q(&kq9w=DWedXMxeMK>38ZSzlwfM#RjgCD+~A!$l{l5B{hY{JPfAj2z|j@ z{jwq9OoBKd=#K~cdt6jvV#$JD+3j=-nF7RKfSkpl@otomj>!+#=>g~52bFnLnUvLt Q)u`2&)%d&0OjJMq0Ps_>g8%>k delta 135 zcmcaGLHc^H^oAO)$rHIW4U_Zpic1udZ4=8AGfNbTQWH}`5{uGPOEmIyN;Iv(q8bJ| ziF!q;x%p+Oni@rucW^~)*5Q7~C=FClotdUlqFIz$Qd*RkP>@%U>!4CyQk!5sc_N=V eV`}pYzV;VrG_U+}SI>;wQwlrks) diff --git a/src/install-pnpm/run.ts b/src/install-pnpm/run.ts index 2a31920..c3f5761 100644 --- a/src/install-pnpm/run.ts +++ b/src/install-pnpm/run.ts @@ -8,13 +8,15 @@ import { Inputs } from '../inputs' export async function runSelfInstaller(inputs: Inputs): Promise { 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 = path.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'], @@ -36,10 +38,18 @@ export async function runSelfInstaller(inputs: Inputs): Promise { 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 { GITHUB_WORKSPACE } = process.env + if (!GITHUB_WORKSPACE) { + throw new Error(`No workspace is found. +If you're intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file, +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')) if (typeof packageManager !== 'string') { throw new Error(`No pnpm version is specified. Please specify it by one of the following ways: