Skip to content

Commit

Permalink
Revert "Add support for yarn and lerna monorepos. (facebook#3741)"
Browse files Browse the repository at this point in the history
This reverts commit b43ad04.
  • Loading branch information
Timer committed Sep 18, 2018
1 parent 245ea0c commit 3af8c49
Show file tree
Hide file tree
Showing 28 changed files with 40 additions and 404 deletions.
5 changes: 1 addition & 4 deletions config/jest/babelTransform.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
// @remove-on-eject-begin
// @remove-file-on-eject
/**
* Copyright (c) 2014-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.
*/
// @remove-on-eject-end
'use strict';

const babelJest = require('babel-jest');

module.exports = babelJest.createTransformer({
presets: [require.resolve('babel-preset-react-app')],
// @remove-on-eject-begin
babelrc: false,
// @remove-on-eject-end
});
59 changes: 11 additions & 48 deletions config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
const path = require('path');
const fs = require('fs');
const url = require('url');
const findPkg = require('find-pkg');
const globby = require('globby');

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebook/create-react-app/issues/637
Expand Down Expand Up @@ -65,8 +63,6 @@ module.exports = {
servedPath: getServedPath(resolveApp('package.json')),
};

let checkForMonorepo = true;

// @remove-on-eject-begin
const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);

Expand All @@ -90,13 +86,17 @@ module.exports = {
ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
};

// detect if template should be used, ie. when cwd is react-scripts itself
const useTemplate =
appDirectory === fs.realpathSync(path.join(__dirname, '..'));

checkForMonorepo = !useTemplate;

if (useTemplate) {
const ownPackageJson = require('../package.json');
const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
const reactScriptsLinked =
fs.existsSync(reactScriptsPath) &&
fs.lstatSync(reactScriptsPath).isSymbolicLink();

// config before publish: we're in ./packages/react-scripts/config/
if (
!reactScriptsLinked &&
__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1
) {
module.exports = {
dotenv: resolveOwn('template/.env'),
appPath: resolveApp('.'),
Expand All @@ -117,40 +117,3 @@ if (useTemplate) {
};
}
// @remove-on-eject-end

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

const findPkgs = (rootPath, globPatterns) => {
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 getMonorepoPkgPaths = () => {
const monoPkgPath = findPkg.sync(path.resolve(appDirectory, '..'));
if (monoPkgPath) {
// get monorepo config from yarn workspace
const pkgPatterns = require(monoPkgPath).workspaces;
const pkgPaths = findPkgs(path.dirname(monoPkgPath), pkgPatterns);
// only include monorepo pkgs if app itself is included in monorepo
if (pkgPaths.indexOf(appDirectory) !== -1) {
return pkgPaths.filter(f => fs.realpathSync(f) !== appDirectory);
}
}
return [];
};

if (checkForMonorepo) {
// if app is in a monorepo (lerna or yarn workspace), treat other packages in
// the monorepo as if they are app source
Array.prototype.push.apply(module.exports.srcPaths, getMonorepoPkgPaths());
}
10 changes: 4 additions & 6 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,18 @@ module.exports = {
options: {
formatter: require.resolve('react-dev-utils/eslintFormatter'),
eslintPath: require.resolve('eslint'),
// @remove-on-eject-begin
baseConfig: {
extends: [require.resolve('eslint-config-react-app')],
},
// @remove-on-eject-begin
ignore: false,
useEslintrc: false,
// @remove-on-eject-end
},
loader: require.resolve('eslint-loader'),
},
],
include: paths.srcPaths,
exclude: [/[/\\\\]node_modules[/\\\\]/],
include: paths.appSrc,
},
{
// "oneOf" will traverse all following loaders until one will
Expand All @@ -216,8 +215,7 @@ module.exports = {
// The preset includes JSX, Flow, and some ESnext features.
{
test: /\.(js|jsx|mjs)$/,
include: paths.srcPaths,
exclude: [/[/\\\\]node_modules[/\\\\]/],
include: paths.appSrc,
use: [
// This loader parallelizes code compilation, it is optional but
// improves compile time on larger projects
Expand All @@ -232,8 +230,8 @@ module.exports = {
options: {
// @remove-on-eject-begin
babelrc: false,
// @remove-on-eject-end
presets: [require.resolve('babel-preset-react-app')],
// @remove-on-eject-end
plugins: [
[
require.resolve('babel-plugin-named-asset-import'),
Expand Down
10 changes: 4 additions & 6 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,20 @@ module.exports = {
options: {
formatter: require.resolve('react-dev-utils/eslintFormatter'),
eslintPath: require.resolve('eslint'),
// @remove-on-eject-begin
// TODO: consider separate config for production,
// e.g. to enable no-console and no-debugger only in production.
baseConfig: {
extends: [require.resolve('eslint-config-react-app')],
},
// @remove-on-eject-begin
ignore: false,
useEslintrc: false,
// @remove-on-eject-end
},
loader: require.resolve('eslint-loader'),
},
],
include: paths.srcPaths,
exclude: [/[/\\\\]node_modules[/\\\\]/],
include: paths.appSrc,
},
{
// "oneOf" will traverse all following loaders until one will
Expand All @@ -255,8 +254,7 @@ module.exports = {
// The preset includes JSX, Flow, and some ESnext features.
{
test: /\.(js|jsx|mjs)$/,
include: paths.srcPaths,
exclude: [/[/\\\\]node_modules[/\\\\]/],
include: paths.appSrc,
use: [
// This loader parallelizes code compilation, it is optional but
// improves compile time on larger projects
Expand All @@ -266,8 +264,8 @@ module.exports = {
options: {
// @remove-on-eject-begin
babelrc: false,
// @remove-on-eject-end
presets: [require.resolve('babel-preset-react-app')],
// @remove-on-eject-end
plugins: [
[
require.resolve('babel-plugin-named-asset-import'),
Expand Down
3 changes: 0 additions & 3 deletions fixtures/kitchensink/.babelrc

This file was deleted.

21 changes: 0 additions & 21 deletions fixtures/monorepos/packages/comp1/index.js

This file was deleted.

8 changes: 0 additions & 8 deletions fixtures/monorepos/packages/comp1/index.test.js

This file was deleted.

10 changes: 0 additions & 10 deletions fixtures/monorepos/packages/comp1/package.json

This file was deleted.

11 changes: 0 additions & 11 deletions fixtures/monorepos/packages/comp2/index.js

This file was deleted.

8 changes: 0 additions & 8 deletions fixtures/monorepos/packages/comp2/index.test.js

This file was deleted.

13 changes: 0 additions & 13 deletions fixtures/monorepos/packages/comp2/package.json

This file was deleted.

21 changes: 0 additions & 21 deletions fixtures/monorepos/packages/cra-app1/.gitignore

This file was deleted.

32 changes: 0 additions & 32 deletions fixtures/monorepos/packages/cra-app1/package.json

This file was deleted.

Binary file not shown.
40 changes: 0 additions & 40 deletions fixtures/monorepos/packages/cra-app1/public/index.html

This file was deleted.

15 changes: 0 additions & 15 deletions fixtures/monorepos/packages/cra-app1/public/manifest.json

This file was deleted.

Loading

0 comments on commit 3af8c49

Please sign in to comment.