@@ -8,13 +8,15 @@ import { Inputs } from '../inputs'
8
8
9
9
export async function runSelfInstaller ( inputs : Inputs ) : Promise < number > {
10
10
const { version, dest } = inputs
11
- const pkgJson = path . join ( dest , 'package.json' )
12
- const target = await readTarget ( pkgJson , version )
13
11
12
+ // prepare self install
14
13
await remove ( dest )
14
+ const pkgJson = path . join ( dest , 'package.json' )
15
15
await ensureFile ( pkgJson )
16
16
await writeFile ( pkgJson , JSON . stringify ( { private : true } ) )
17
17
18
+ // prepare target pnpm
19
+ const target = await readTarget ( version )
18
20
const cp = spawn ( execPath , [ '-' , 'install' , target , '--no-lockfile' ] , {
19
21
cwd : dest ,
20
22
stdio : [ 'pipe' , 'inherit' , 'inherit' ] ,
@@ -36,10 +38,18 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
36
38
return exitCode
37
39
}
38
40
39
- async function readTarget ( packageJsonPath : string , version ?: string | undefined ) {
41
+ async function readTarget ( version ?: string | undefined ) {
40
42
if ( version ) return `pnpm@${ version } `
41
43
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' ) )
43
53
if ( typeof packageManager !== 'string' ) {
44
54
throw new Error ( `No pnpm version is specified.
45
55
Please specify it by one of the following ways:
0 commit comments