11
11
const path = require ( 'path' ) ;
12
12
const fs = require ( 'fs' ) ;
13
13
const url = require ( 'url' ) ;
14
- const findPkg = require ( 'find-pkg' ) ;
15
- const globby = require ( 'globby' ) ;
14
+ const findMonorepo = require ( 'react-dev-utils/workspaceUtils' ) . findMonorepo ;
16
15
17
16
// Make sure any symlinks in the project folder are resolved:
18
17
// https://github.com/facebook/create-react-app/issues/637
@@ -58,7 +57,6 @@ module.exports = {
58
57
appIndexJs : resolveApp ( 'src/index.js' ) ,
59
58
appPackageJson : resolveApp ( 'package.json' ) ,
60
59
appSrc : resolveApp ( 'src' ) ,
61
- yarnLockFile : resolveApp ( 'yarn.lock' ) ,
62
60
testsSetup : resolveApp ( 'src/setupTests.js' ) ,
63
61
proxySetup : resolveApp ( 'src/setupProxy.js' ) ,
64
62
appNodeModules : resolveApp ( 'node_modules' ) ,
@@ -81,7 +79,6 @@ module.exports = {
81
79
appIndexJs : resolveApp ( 'src/index.js' ) ,
82
80
appPackageJson : resolveApp ( 'package.json' ) ,
83
81
appSrc : resolveApp ( 'src' ) ,
84
- yarnLockFile : resolveApp ( 'yarn.lock' ) ,
85
82
testsSetup : resolveApp ( 'src/setupTests.js' ) ,
86
83
proxySetup : resolveApp ( 'src/setupProxy.js' ) ,
87
84
appNodeModules : resolveApp ( 'node_modules' ) ,
@@ -108,7 +105,6 @@ if (useTemplate) {
108
105
appIndexJs : resolveOwn ( 'template/src/index.js' ) ,
109
106
appPackageJson : resolveOwn ( 'package.json' ) ,
110
107
appSrc : resolveOwn ( 'template/src' ) ,
111
- yarnLockFile : resolveOwn ( 'template/yarn.lock' ) ,
112
108
testsSetup : resolveOwn ( 'template/src/setupTests.js' ) ,
113
109
proxySetup : resolveOwn ( 'template/src/setupProxy.js' ) ,
114
110
appNodeModules : resolveOwn ( 'node_modules' ) ,
@@ -123,37 +119,16 @@ if (useTemplate) {
123
119
124
120
module . exports . srcPaths = [ module . exports . appSrc ] ;
125
121
126
- const findPkgs = ( rootPath , globPatterns ) => {
127
- const globOpts = {
128
- cwd : rootPath ,
129
- strict : true ,
130
- absolute : true ,
131
- } ;
132
- return globPatterns
133
- . reduce (
134
- ( pkgs , pattern ) =>
135
- pkgs . concat ( globby . sync ( path . join ( pattern , 'package.json' ) , globOpts ) ) ,
136
- [ ]
137
- )
138
- . map ( f => path . dirname ( path . normalize ( f ) ) ) ;
139
- } ;
140
-
141
- const getMonorepoPkgPaths = ( ) => {
142
- const monoPkgPath = findPkg . sync ( path . resolve ( appDirectory , '..' ) ) ;
143
- if ( monoPkgPath ) {
144
- // get monorepo config from yarn workspace
145
- const pkgPatterns = require ( monoPkgPath ) . workspaces ;
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
- } ;
122
+ module . exports . useYarn = fs . existsSync (
123
+ path . join ( module . exports . appPath , 'yarn.lock' )
124
+ ) ;
154
125
155
126
if ( checkForMonorepo ) {
156
127
// if app is in a monorepo (lerna or yarn workspace), treat other packages in
157
128
// the monorepo as if they are app source
158
- Array . prototype . push . apply ( module . exports . srcPaths , getMonorepoPkgPaths ( ) ) ;
129
+ const mono = findMonorepo ( appDirectory ) ;
130
+ if ( mono . isAppIncluded ) {
131
+ Array . prototype . push . apply ( module . exports . srcPaths , mono . pkgs ) ;
132
+ }
133
+ module . exports . useYarn = module . exports . useYarn || mono . isYarnWs ;
159
134
}
0 commit comments