|
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
|
@@ -159,37 +158,16 @@ module.exports.moduleFileExtensions = moduleFileExtensions;
|
159 | 158 |
|
160 | 159 | module.exports.srcPaths = [module.exports.appSrc];
|
161 | 160 |
|
162 |
| -const findPkgs = (rootPath, globPatterns) => { |
163 |
| - const globOpts = { |
164 |
| - cwd: rootPath, |
165 |
| - strict: true, |
166 |
| - absolute: true, |
167 |
| - }; |
168 |
| - return globPatterns |
169 |
| - .reduce( |
170 |
| - (pkgs, pattern) => |
171 |
| - pkgs.concat(globby.sync(path.join(pattern, 'package.json'), globOpts)), |
172 |
| - [] |
173 |
| - ) |
174 |
| - .map(f => path.dirname(path.normalize(f))); |
175 |
| -}; |
176 |
| - |
177 |
| -const getMonorepoPkgPaths = () => { |
178 |
| - const monoPkgPath = findPkg.sync(path.resolve(appDirectory, '..')); |
179 |
| - if (monoPkgPath) { |
180 |
| - // get monorepo config from yarn workspace |
181 |
| - const pkgPatterns = require(monoPkgPath).workspaces; |
182 |
| - const pkgPaths = findPkgs(path.dirname(monoPkgPath), pkgPatterns); |
183 |
| - // only include monorepo pkgs if app itself is included in monorepo |
184 |
| - if (pkgPaths.indexOf(appDirectory) !== -1) { |
185 |
| - return pkgPaths.filter(f => fs.realpathSync(f) !== appDirectory); |
186 |
| - } |
187 |
| - } |
188 |
| - return []; |
189 |
| -}; |
| 161 | +module.exports.useYarn = fs.existsSync( |
| 162 | + path.join(module.exports.appPath, 'yarn.lock') |
| 163 | +); |
190 | 164 |
|
191 | 165 | if (checkForMonorepo) {
|
192 | 166 | // if app is in a monorepo (lerna or yarn workspace), treat other packages in
|
193 | 167 | // the monorepo as if they are app source
|
194 |
| - Array.prototype.push.apply(module.exports.srcPaths, getMonorepoPkgPaths()); |
| 168 | + const mono = findMonorepo(appDirectory); |
| 169 | + if (mono.isAppIncluded) { |
| 170 | + Array.prototype.push.apply(module.exports.srcPaths, mono.pkgs); |
| 171 | + } |
| 172 | + module.exports.useYarn = module.exports.useYarn || mono.isYarnWs; |
195 | 173 | }
|
0 commit comments