Skip to content

Commit cc328d6

Browse files
committed
Revert "Use yarn when running inside yarn workspace. (facebook#3997)"
This reverts commit 2c34d5b.
1 parent d8c2da5 commit cc328d6

File tree

9 files changed

+49
-84
lines changed

9 files changed

+49
-84
lines changed

Diff for: packages/create-react-app/createReactApp.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const url = require('url');
4949
const hyperquest = require('hyperquest');
5050
const envinfo = require('envinfo');
5151
const os = require('os');
52-
const findMonorepo = require('react-dev-utils/workspaceUtils').findMonorepo;
52+
5353
const packageJson = require('./package.json');
5454

5555
// These files should be allowed to remain on a failed install,
@@ -204,7 +204,7 @@ function createApp(name, verbose, version, useNpm, template) {
204204
JSON.stringify(packageJson, null, 2) + os.EOL
205205
);
206206

207-
const useYarn = useNpm ? false : shouldUseYarn(root);
207+
const useYarn = useNpm ? false : shouldUseYarn();
208208
const originalDirectory = process.cwd();
209209
process.chdir(root);
210210
if (!useYarn && !checkThatNpmCanReadCwd()) {
@@ -244,7 +244,7 @@ function createApp(name, verbose, version, useNpm, template) {
244244
run(root, appName, version, verbose, originalDirectory, template, useYarn);
245245
}
246246

247-
function isYarnAvailable() {
247+
function shouldUseYarn() {
248248
try {
249249
execSync('yarnpkg --version', { stdio: 'ignore' });
250250
return true;
@@ -253,11 +253,6 @@ function isYarnAvailable() {
253253
}
254254
}
255255

256-
function shouldUseYarn(appDir) {
257-
const mono = findMonorepo(appDir);
258-
return (mono.isYarnWs && mono.isAppIncluded) || isYarnAvailable();
259-
}
260-
261256
function install(root, useYarn, dependencies, verbose, isOnline) {
262257
return new Promise((resolve, reject) => {
263258
let command;

Diff for: packages/create-react-app/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"envinfo": "5.4.0",
2828
"fs-extra": "^5.0.0",
2929
"hyperquest": "^2.1.2",
30-
"react-dev-utils": "^5.0.0",
3130
"semver": "^5.0.3",
3231
"tar-pack": "^3.4.0",
3332
"tmp": "0.0.33",

Diff for: packages/react-dev-utils/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
"printHostingInstructions.js",
3535
"WatchMissingNodeModulesPlugin.js",
3636
"WebpackDevServerUtils.js",
37-
"webpackHotDevClient.js",
38-
"workspaceUtils.js"
37+
"webpackHotDevClient.js"
3938
],
4039
"dependencies": {
4140
"@babel/code-frame": "7.0.0-beta.46",
@@ -46,9 +45,7 @@
4645
"detect-port-alt": "1.1.6",
4746
"escape-string-regexp": "1.0.5",
4847
"filesize": "3.6.1",
49-
"find-pkg": "1.0.0",
5048
"global-modules": "1.0.0",
51-
"globby": "8.0.1",
5249
"gzip-size": "4.1.0",
5350
"inquirer": "5.1.0",
5451
"is-root": "1.0.0",

Diff for: packages/react-dev-utils/workspaceUtils.js

-53
This file was deleted.

Diff for: packages/react-scripts/config/paths.js

+37-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
const path = require('path');
1212
const fs = require('fs');
1313
const url = require('url');
14-
const findMonorepo = require('react-dev-utils/workspaceUtils').findMonorepo;
14+
const findPkg = require('find-pkg');
15+
const globby = require('globby');
1516

1617
// Make sure any symlinks in the project folder are resolved:
1718
// https://github.com/facebook/create-react-app/issues/637
@@ -57,6 +58,7 @@ module.exports = {
5758
appIndexJs: resolveApp('src/index.js'),
5859
appPackageJson: resolveApp('package.json'),
5960
appSrc: resolveApp('src'),
61+
yarnLockFile: resolveApp('yarn.lock'),
6062
testsSetup: resolveApp('src/setupTests.js'),
6163
appNodeModules: resolveApp('node_modules'),
6264
publicUrl: getPublicUrl(resolveApp('package.json')),
@@ -78,6 +80,7 @@ module.exports = {
7880
appIndexJs: resolveApp('src/index.js'),
7981
appPackageJson: resolveApp('package.json'),
8082
appSrc: resolveApp('src'),
83+
yarnLockFile: resolveApp('yarn.lock'),
8184
testsSetup: resolveApp('src/setupTests.js'),
8285
appNodeModules: resolveApp('node_modules'),
8386
publicUrl: getPublicUrl(resolveApp('package.json')),
@@ -103,6 +106,7 @@ if (useTemplate) {
103106
appIndexJs: resolveOwn('template/src/index.js'),
104107
appPackageJson: resolveOwn('package.json'),
105108
appSrc: resolveOwn('template/src'),
109+
yarnLockFile: resolveOwn('template/yarn.lock'),
106110
testsSetup: resolveOwn('template/src/setupTests.js'),
107111
appNodeModules: resolveOwn('node_modules'),
108112
publicUrl: getPublicUrl(resolveOwn('package.json')),
@@ -116,16 +120,40 @@ if (useTemplate) {
116120

117121
module.exports.srcPaths = [module.exports.appSrc];
118122

119-
module.exports.useYarn = fs.existsSync(
120-
path.join(module.exports.appPath, 'yarn.lock')
121-
);
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+
};
122154

123155
if (checkForMonorepo) {
124156
// if app is in a monorepo (lerna or yarn workspace), treat other packages in
125157
// the monorepo as if they are app source
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;
158+
Array.prototype.push.apply(module.exports.srcPaths, getMonorepoPkgPaths());
131159
}

Diff for: packages/react-scripts/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
"eslint-plugin-jsx-a11y": "6.0.3",
4545
"eslint-plugin-react": "7.8.2",
4646
"file-loader": "1.1.11",
47+
"find-pkg": "1.0.0",
4748
"fs-extra": "5.0.0",
49+
"globby": "7.1.1",
4850
"graphql": "0.13.2",
4951
"graphql-tag": "2.9.2",
5052
"html-webpack-plugin": "3.2.0",

Diff for: packages/react-scripts/scripts/build.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const { printBrowsers } = require('react-dev-utils/browsersHelper');
4646
const measureFileSizesBeforeBuild =
4747
FileSizeReporter.measureFileSizesBeforeBuild;
4848
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
49+
const useYarn = fs.existsSync(paths.yarnLockFile);
4950

5051
// These sizes are pretty large. We'll warn for bundles exceeding them.
5152
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
@@ -116,7 +117,7 @@ checkBrowsers(paths.appPath)
116117
publicUrl,
117118
publicPath,
118119
buildFolder,
119-
paths.useYarn
120+
useYarn
120121
);
121122
printBrowsers(paths.appPath);
122123
},

Diff for: packages/react-scripts/scripts/eject.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ inquirer
224224
}
225225
}
226226

227-
if (paths.useYarn) {
227+
if (fs.existsSync(paths.yarnLockFile)) {
228228
const windowsCmdFilePath = path.join(
229229
appPath,
230230
'node_modules',

Diff for: packages/react-scripts/scripts/start.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if (process.env.SKIP_PREFLIGHT_CHECK !== 'true') {
2929
}
3030
// @remove-on-eject-end
3131

32+
const fs = require('fs');
3233
const chalk = require('chalk');
3334
const webpack = require('webpack');
3435
const WebpackDevServer = require('webpack-dev-server');
@@ -45,6 +46,7 @@ const paths = require('../config/paths');
4546
const config = require('../config/webpack.config.dev');
4647
const createDevServerConfig = require('../config/webpackDevServer.config');
4748

49+
const useYarn = fs.existsSync(paths.yarnLockFile);
4850
const isInteractive = process.stdout.isTTY;
4951

5052
// Warn and crash if required files are missing
@@ -91,13 +93,7 @@ checkBrowsers(paths.appPath)
9193
const appName = require(paths.appPackageJson).name;
9294
const urls = prepareUrls(protocol, HOST, port);
9395
// Create a webpack compiler that is configured with custom messages.
94-
const compiler = createCompiler(
95-
webpack,
96-
config,
97-
appName,
98-
urls,
99-
paths.useYarn
100-
);
96+
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
10197
// Load proxy config
10298
const proxySetting = require(paths.appPackageJson).proxy;
10399
const proxyConfig = prepareProxy(proxySetting, paths.appPublic);

0 commit comments

Comments
 (0)