Skip to content

Commit 35ab426

Browse files
authored
fix: packageManager reader (#35)
* fix: packageManager reader * chore: resolve review * chore: run build
1 parent 11ba342 commit 35ab426

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ branding:
66
inputs:
77
version:
88
description: Version of PNPM to install
9-
required: true
109
dest:
1110
description: Where to store PNPM files
1211
required: false

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/install-pnpm/run.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import { Inputs } from '../inputs'
88

99
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
1010
const { version, dest } = inputs
11-
const pkgJson = path.join(dest, 'package.json')
12-
const target = await readTarget(pkgJson, version)
1311

12+
// prepare self install
1413
await remove(dest)
14+
const pkgJson = path.join(dest, 'package.json')
1515
await ensureFile(pkgJson)
1616
await writeFile(pkgJson, JSON.stringify({ private: true }))
1717

18+
// prepare target pnpm
19+
const target = await readTarget(version)
1820
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
1921
cwd: dest,
2022
stdio: ['pipe', 'inherit', 'inherit'],
@@ -36,10 +38,18 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
3638
return exitCode
3739
}
3840

39-
async function readTarget(packageJsonPath: string, version?: string | undefined) {
41+
async function readTarget(version?: string | undefined) {
4042
if (version) return `pnpm@${version}`
4143

42-
const { packageManager } = JSON.parse(await readFile(packageJsonPath, 'utf8'))
44+
const { GITHUB_WORKSPACE } = process.env
45+
if (!GITHUB_WORKSPACE) {
46+
throw new Error(`No workspace is found.
47+
If you're intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,
48+
please run the actions/checkout before pnpm/action-setup.
49+
Otherwise, please specify the pnpm version in the action configuration.`)
50+
}
51+
52+
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, 'package.json'), 'utf8'))
4353
if (typeof packageManager !== 'string') {
4454
throw new Error(`No pnpm version is specified.
4555
Please specify it by one of the following ways:

0 commit comments

Comments
 (0)