1111const path = require ( 'path' ) ;
1212const fs = require ( 'fs' ) ;
1313const url = require ( 'url' ) ;
14- const findPkg = require ( 'find-pkg' ) ;
15- const globby = require ( 'globby' ) ;
14+ const findMonorepo = require ( 'react-dev-utils/workspaceUtils' ) . findMonorepo ;
1615
1716// Make sure any symlinks in the project folder are resolved:
1817// https://github.com/facebook/create-react-app/issues/637
@@ -58,7 +57,6 @@ module.exports = {
5857 appIndexJs : resolveApp ( 'src/index.js' ) ,
5958 appPackageJson : resolveApp ( 'package.json' ) ,
6059 appSrc : resolveApp ( 'src' ) ,
61- yarnLockFile : resolveApp ( 'yarn.lock' ) ,
6260 testsSetup : resolveApp ( 'src/setupTests.js' ) ,
6361 appNodeModules : resolveApp ( 'node_modules' ) ,
6462 publicUrl : getPublicUrl ( resolveApp ( 'package.json' ) ) ,
@@ -80,7 +78,6 @@ module.exports = {
8078 appIndexJs : resolveApp ( 'src/index.js' ) ,
8179 appPackageJson : resolveApp ( 'package.json' ) ,
8280 appSrc : resolveApp ( 'src' ) ,
83- yarnLockFile : resolveApp ( 'yarn.lock' ) ,
8481 testsSetup : resolveApp ( 'src/setupTests.js' ) ,
8582 appNodeModules : resolveApp ( 'node_modules' ) ,
8683 publicUrl : getPublicUrl ( resolveApp ( 'package.json' ) ) ,
@@ -106,7 +103,6 @@ if (useTemplate) {
106103 appIndexJs : resolveOwn ( 'template/src/index.js' ) ,
107104 appPackageJson : resolveOwn ( 'package.json' ) ,
108105 appSrc : resolveOwn ( 'template/src' ) ,
109- yarnLockFile : resolveOwn ( 'template/yarn.lock' ) ,
110106 testsSetup : resolveOwn ( 'template/src/setupTests.js' ) ,
111107 appNodeModules : resolveOwn ( 'node_modules' ) ,
112108 publicUrl : getPublicUrl ( resolveOwn ( 'package.json' ) ) ,
@@ -120,40 +116,16 @@ if (useTemplate) {
120116
121117module . exports . srcPaths = [ module . exports . appSrc ] ;
122118
123- const findPkgs = ( rootPath , globPatterns ) => {
124- const globOpts = {
125- cwd : rootPath ,
126- strict : true ,
127- absolute : true ,
128- } ;
129- return globPatterns
130- . reduce (
131- ( pkgs , pattern ) =>
132- pkgs . concat ( globby . sync ( path . join ( pattern , 'package.json' ) , globOpts ) ) ,
133- [ ]
134- )
135- . map ( f => path . dirname ( path . normalize ( f ) ) ) ;
136- } ;
137-
138- const getMonorepoPkgPaths = ( ) => {
139- const monoPkgPath = findPkg . sync ( path . resolve ( appDirectory , '..' ) ) ;
140- if ( monoPkgPath ) {
141- // get monorepo config from yarn workspace
142- const pkgPatterns = require ( monoPkgPath ) . workspaces ;
143- if ( pkgPatterns == null ) {
144- return [ ] ;
145- }
146- const pkgPaths = findPkgs ( path . dirname ( monoPkgPath ) , pkgPatterns ) ;
147- // only include monorepo pkgs if app itself is included in monorepo
148- if ( pkgPaths . indexOf ( appDirectory ) !== - 1 ) {
149- return pkgPaths . filter ( f => fs . realpathSync ( f ) !== appDirectory ) ;
150- }
151- }
152- return [ ] ;
153- } ;
119+ module . exports . useYarn = fs . existsSync (
120+ path . join ( module . exports . appPath , 'yarn.lock' )
121+ ) ;
154122
155123if ( checkForMonorepo ) {
156124 // if app is in a monorepo (lerna or yarn workspace), treat other packages in
157125 // the monorepo as if they are app source
158- Array . prototype . push . apply ( module . exports . srcPaths , getMonorepoPkgPaths ( ) ) ;
126+ const mono = findMonorepo ( appDirectory ) ;
127+ if ( mono . isAppIncluded ) {
128+ Array . prototype . push . apply ( module . exports . srcPaths , mono . pkgs ) ;
129+ }
130+ module . exports . useYarn = module . exports . useYarn || mono . isYarnWs ;
159131}
0 commit comments