From f4eb24c57f69bf1bbfd9e72946461a7926c6a64d Mon Sep 17 00:00:00 2001 From: Jack Works Date: Thu, 24 Feb 2022 19:05:21 +0800 Subject: [PATCH] chore: resolve review --- src/install-pnpm/run.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/install-pnpm/run.ts b/src/install-pnpm/run.ts index 50dd0ce..c3f5761 100644 --- a/src/install-pnpm/run.ts +++ b/src/install-pnpm/run.ts @@ -2,7 +2,7 @@ import { addPath, exportVariable } from '@actions/core' import fetch from '@pnpm/fetch' import { spawn } from 'child_process' import { remove, ensureFile, writeFile, readFile } from 'fs-extra' -import { join } from 'path' +import path from 'path' import { execPath } from 'process' import { Inputs } from '../inputs' @@ -11,7 +11,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise { // prepare self install await remove(dest) - const pkgJson = join(dest, 'package.json') + const pkgJson = path.join(dest, 'package.json') await ensureFile(pkgJson) await writeFile(pkgJson, JSON.stringify({ private: true })) @@ -31,7 +31,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise { cp.on('close', resolve) }) if (exitCode === 0) { - const pnpmHome = join(dest, 'node_modules/.bin') + const pnpmHome = path.join(dest, 'node_modules/.bin') addPath(pnpmHome) exportVariable('PNPM_HOME', pnpmHome) } @@ -41,14 +41,15 @@ export async function runSelfInstaller(inputs: Inputs): Promise { async function readTarget(version?: string | undefined) { if (version) return `pnpm@${version}` - const workspace = process.env.GITHUB_WORKSPACE - if (!workspace) { + const { GITHUB_WORKSPACE } = process.env + if (!GITHUB_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.`) +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(join(workspace, 'package.json'), 'utf8')) + 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: