Skip to content

Commit 0cb0538

Browse files
authored
feat: support package.yaml (#156)
1 parent e303250 commit 0cb0538

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/install-pnpm/run.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import path from 'path'
66
import { execPath } from 'process'
77
import util from 'util'
88
import { Inputs } from '../inputs'
9+
import YAML from 'yaml'
910

1011
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
1112
const { version, dest, packageJsonFile, standalone } = inputs
@@ -49,7 +50,11 @@ async function readTarget(opts: {
4950

5051
if (GITHUB_WORKSPACE) {
5152
try {
52-
({ packageManager } = JSON.parse(readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8')))
53+
const content = readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8');
54+
({ packageManager } = packageJsonFile.endsWith(".yaml")
55+
? YAML.parse(content, { merge: true })
56+
: JSON.parse(content)
57+
)
5358
} catch (error: unknown) {
5459
// Swallow error if package.json doesn't exist in root
5560
if (!util.types.isNativeError(error) || !('code' in error) || error.code !== 'ENOENT') throw error
@@ -66,7 +71,7 @@ async function readTarget(opts: {
6671
- version ${packageManager} in the package.json with the key "packageManager"
6772
Remove one of these versions to avoid version mismatch errors like ERR_PNPM_BAD_PM_VERSION`)
6873
}
69-
74+
7075
return `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}`
7176
}
7277

0 commit comments

Comments
 (0)