forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use yarn when running inside yarn workspace. (facebook#3997)
* Run yarn after ejecting. * On eject, choose to run yarn instead of npm if yarn is available. * Move monorepo to react-dev-utils. * Fix lint. * Rename monorepo to workspaceUtils. * Add react-dev-utils dep for create-react-app. * getMonorepo -> findMonorepo
- Loading branch information
1 parent
c342677
commit 2c34d5b
Showing
9 changed files
with
87 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (c) 2018-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const findPkg = require('find-pkg'); | ||
const globby = require('globby'); | ||
|
||
const findPkgs = (rootPath, globPatterns) => { | ||
if (!globPatterns) { | ||
return []; | ||
} | ||
const globOpts = { | ||
cwd: rootPath, | ||
strict: true, | ||
absolute: true, | ||
}; | ||
return globPatterns | ||
.reduce( | ||
(pkgs, pattern) => | ||
pkgs.concat(globby.sync(path.join(pattern, 'package.json'), globOpts)), | ||
[] | ||
) | ||
.map(f => path.dirname(path.normalize(f))); | ||
}; | ||
|
||
const findMonorepo = appDir => { | ||
const monoPkgPath = findPkg.sync(path.resolve(appDir, '..')); | ||
const monoPkg = monoPkgPath && require(monoPkgPath); | ||
const patterns = monoPkg && monoPkg.workspaces; | ||
const isYarnWs = Boolean(patterns); | ||
const allPkgs = patterns && findPkgs(path.dirname(monoPkgPath), patterns); | ||
const isIncluded = dir => allPkgs && allPkgs.indexOf(dir) !== -1; | ||
const isAppIncluded = isIncluded(appDir); | ||
const pkgs = allPkgs | ||
? allPkgs.filter(f => fs.realpathSync(f) !== appDir) | ||
: []; | ||
|
||
return { | ||
isAppIncluded, | ||
isYarnWs, | ||
pkgs, | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
findMonorepo, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters