@@ -21,7 +21,7 @@ export async function setupSpecRunner(
2121 const utils = await import (
2222 pathToFileURL ( path . resolve ( SCRIPT_DIR , "lib" , "utils.js" ) ) . toString ( )
2323 ) ;
24- const { YARN_VERSION } = await import (
24+ const { YARN_SCRIPT_PATH , YARN_VERSION } = await import (
2525 pathToFileURL ( path . resolve ( SCRIPT_DIR , "yarn.js" ) ) . toString ( )
2626 ) ;
2727
@@ -51,9 +51,16 @@ export async function setupSpecRunner(
5151 hasher . update (
5252 fs . readFileSync ( path . resolve ( electronRoot , "spec" , "package.json" ) ) ,
5353 ) ;
54- hasher . update (
55- fs . readFileSync ( path . resolve ( electronRoot , "spec" , "yarn.lock" ) ) ,
56- ) ;
54+ try {
55+ hasher . update (
56+ fs . readFileSync ( path . resolve ( electronRoot , "spec" , "yarn.lock" ) ) ,
57+ ) ;
58+ } catch {
59+ // With the Yarn v4 transition, spec/yarn.lock may not exist anymore
60+ hasher . update (
61+ fs . readFileSync ( path . resolve ( electronRoot , "yarn.lock" ) ) ,
62+ ) ;
63+ }
5764 hasher . update (
5865 fs . readFileSync ( path . resolve ( SCRIPT_DIR , "spec-runner.js" ) ) ,
5966 ) ;
@@ -99,17 +106,26 @@ export async function setupSpecRunner(
99106 recursive : true ,
100107 } ) ;
101108 }
102- const { status, stderr } = childProcess . spawnSync (
103- "e" ,
104- [ "d" , "npx" , `yarn@${ YARN_VERSION } ` , "install" , "--frozen-lockfile" ] ,
105- {
106- env,
107- cwd : dir ,
108- stdio : "pipe" ,
109- shell : process . platform === "win32" ,
110- encoding : "utf-8" ,
111- } ,
112- ) ;
109+ let yarnArgs ;
110+ if ( YARN_SCRIPT_PATH ) {
111+ yarnArgs = [ "d" , YARN_SCRIPT_PATH , "install" , "--immutable" ] ;
112+ } else {
113+ yarnArgs = [
114+ "d" ,
115+ "npx" ,
116+ `yarn@${ YARN_VERSION } ` ,
117+ "install" ,
118+ "--frozen-lockfile" ,
119+ ] ;
120+ }
121+
122+ const { status, stderr } = childProcess . spawnSync ( "e" , yarnArgs , {
123+ env,
124+ cwd : dir ,
125+ stdio : "pipe" ,
126+ shell : process . platform === "win32" ,
127+ encoding : "utf-8" ,
128+ } ) ;
113129 if ( status !== 0 && ! process . env . IGNORE_YARN_INSTALL_ERROR ) {
114130 if ( stderr . includes ( "missing any VC++ toolset" ) ) {
115131 throw new Error (
0 commit comments