@@ -8,13 +8,15 @@ import { Inputs } from '../inputs'
88
99export 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.
4555Please specify it by one of the following ways:
0 commit comments