@@ -36,6 +36,29 @@ process.stdout.prependListener('error', err => {
36
36
throw err ;
37
37
} ) ;
38
38
39
+ function findPackageManager ( base : string ) : ?string {
40
+ let prev = null ;
41
+ let dir = base ;
42
+
43
+ do {
44
+ const p = path . join ( dir , constants . NODE_PACKAGE_JSON ) ;
45
+
46
+ let data ;
47
+ try {
48
+ data = JSON . parse ( fs . readFileSync ( p ) ) ;
49
+ } catch ( err ) { }
50
+
51
+ if ( data && typeof data . packageManager === `string` ) {
52
+ return data . packageManager ;
53
+ }
54
+
55
+ prev = dir ;
56
+ dir = path . dirname ( dir ) ;
57
+ } while ( dir !== prev ) ;
58
+
59
+ return null ;
60
+ }
61
+
39
62
function findProjectRoot ( base : string ) : string {
40
63
let prev = null ;
41
64
let dir = base ;
@@ -266,16 +289,13 @@ export async function main({
266
289
267
290
const config = new Config ( reporter ) ;
268
291
269
- const projectRoot = findProjectRoot ( commander . cwd ) ;
270
- const cwd = command . shouldRunInCurrentCwd ? commander . cwd : projectRoot ;
271
-
272
- if ( ! process . env . COREPACK_ROOT ) {
273
- const rootManifest = await config . readRootManifest ( projectRoot ) ;
274
- if ( typeof rootManifest . packageManager === `string` ) {
275
- if ( ! rootManifest . packageManager . match ( / ^ y a r n @ [ 0 1 ] \. / ) ) {
292
+ if ( ! process . env . COREPACK_ROOT && ! process . env . SKIP_YARN_COREPACK_CHECK ) {
293
+ const packageManager = findPackageManager ( commander . cwd ) ;
294
+ if ( packageManager !== null ) {
295
+ if ( ! packageManager . match ( / ^ y a r n @ [ 0 1 ] \. / ) ) {
276
296
reporter . error (
277
297
`This project's package.json defines ${ chalk . gray ( '"packageManager": "yarn@' ) } ${ chalk . yellow (
278
- `${ rootManifest . packageManager . replace ( / ^ y a r n @ / , `` ) . replace ( / \+ .* / , `` ) } ` ,
298
+ `${ packageManager . replace ( / ^ y a r n @ / , `` ) . replace ( / \+ .* / , `` ) } ` ,
279
299
) } ${ chalk . gray ( `"` ) } . However the current global version of Yarn is ${ chalk . yellow ( version ) } .`,
280
300
) ;
281
301
@@ -501,6 +521,8 @@ export async function main({
501
521
} ) ;
502
522
} ;
503
523
524
+ const cwd = command . shouldRunInCurrentCwd ? commander . cwd : findProjectRoot ( commander . cwd ) ;
525
+
504
526
const folderOptionKeys = [ 'linkFolder' , 'globalFolder' , 'preferredCacheFolder' , 'cacheFolder' , 'modulesFolder' ] ;
505
527
506
528
// Resolve all folder options relative to cwd
@@ -588,6 +610,8 @@ export async function main({
588
610
589
611
if ( err instanceof MessageError ) {
590
612
reporter . error ( err . message ) ;
613
+ } else {
614
+ reporter . error ( err . stack ) ;
591
615
}
592
616
593
617
if ( command . getDocsInfo ) {
0 commit comments