diff --git a/.travis.yml b/.travis.yml index a014151cf6a..aea00ad24ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,6 @@ script: - 'if [ $TEST_SUITE = "installs" ]; then tasks/e2e-installs.sh; fi' - 'if [ $TEST_SUITE = "kitchensink" ]; then tasks/e2e-kitchensink.sh; fi' - 'if [ $TEST_SUITE = "kitchensink-eject" ]; then tasks/e2e-kitchensink-eject.sh; fi' - - 'if [ $TEST_SUITE = "monorepos" ]; then tasks/e2e-monorepos.sh; fi' - 'if [ $TEST_SUITE = "old-node" ]; then tasks/e2e-old-node.sh; fi' env: matrix: @@ -26,7 +25,6 @@ env: - TEST_SUITE=installs - TEST_SUITE=kitchensink - TEST_SUITE=kitchensink-eject - - TEST_SUITE=monorepos matrix: include: - node_js: 4 diff --git a/appveyor.yml b/appveyor.yml index a4315250399..cc66be280c5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,8 +10,6 @@ environment: test_suite: "kitchensink" - nodejs_version: 10 test_suite: "kitchensink-eject" - - nodejs_version: 10 - test_suite: "monorepos" - nodejs_version: 8 test_suite: "simple" - nodejs_version: 8 @@ -20,8 +18,6 @@ environment: test_suite: "kitchensink" - nodejs_version: 8 test_suite: "kitchensink-eject" - - nodejs_version: 8 - test_suite: "monorepos" cache: - node_modules -> appveyor.cleanup-cache.txt - packages\react-scripts\node_modules -> appveyor.cleanup-cache.txt diff --git a/packages/react-scripts/config/jest/babelTransform.js b/packages/react-scripts/config/jest/babelTransform.js index 8792f3f6473..02742e90c6c 100644 --- a/packages/react-scripts/config/jest/babelTransform.js +++ b/packages/react-scripts/config/jest/babelTransform.js @@ -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 }); diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index 2b77980c12b..eb15377e71e 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -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 @@ -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); @@ -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('.'), @@ -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()); -} diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index b36d81ea01f..3a3f96eeefd 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -182,10 +182,10 @@ 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 @@ -193,8 +193,7 @@ module.exports = { loader: require.resolve('eslint-loader'), }, ], - include: paths.srcPaths, - exclude: [/[/\\\\]node_modules[/\\\\]/], + include: paths.appSrc, }, { // "oneOf" will traverse all following loaders until one will @@ -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 @@ -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'), diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index 5d92c9ef859..f936a8ddbf9 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -220,12 +220,12 @@ 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 @@ -233,8 +233,7 @@ module.exports = { loader: require.resolve('eslint-loader'), }, ], - include: paths.srcPaths, - exclude: [/[/\\\\]node_modules[/\\\\]/], + include: paths.appSrc, }, { // "oneOf" will traverse all following loaders until one will @@ -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 @@ -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'), diff --git a/packages/react-scripts/fixtures/kitchensink/.babelrc b/packages/react-scripts/fixtures/kitchensink/.babelrc deleted file mode 100644 index c14b2828d16..00000000000 --- a/packages/react-scripts/fixtures/kitchensink/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["react-app"] -} diff --git a/packages/react-scripts/fixtures/monorepos/packages/comp1/index.js b/packages/react-scripts/fixtures/monorepos/packages/comp1/index.js deleted file mode 100644 index 104989fe35a..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/comp1/index.js +++ /dev/null @@ -1,21 +0,0 @@ -import React from 'react'; - -class Comp1 extends React.Component { - static parts = { - greeting: 'hello', - region: 'world', - }; - - render() { - const { greeting, region } = Comp1.parts; - - return ( -
- Comp1 - {greeting} {region} -
- ); - } -} - -export default Comp1; diff --git a/packages/react-scripts/fixtures/monorepos/packages/comp1/index.test.js b/packages/react-scripts/fixtures/monorepos/packages/comp1/index.test.js deleted file mode 100644 index 25160484031..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/comp1/index.test.js +++ /dev/null @@ -1,8 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import Comp1 from '.'; - -it('renders Comp1 without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render(, div); -}); diff --git a/packages/react-scripts/fixtures/monorepos/packages/comp1/package.json b/packages/react-scripts/fixtures/monorepos/packages/comp1/package.json deleted file mode 100644 index baa4c31dc71..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/comp1/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "comp1", - "version": "1.0.0", - "main": "index.js", - "license": "MIT", - "devDependencies": { - "react": "^16.2.0", - "react-dom": "^16.2.0" - } -} diff --git a/packages/react-scripts/fixtures/monorepos/packages/comp2/index.js b/packages/react-scripts/fixtures/monorepos/packages/comp2/index.js deleted file mode 100644 index 6dcc69dacf1..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/comp2/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import React from 'react'; - -import Comp1 from 'comp1'; - -const Comp2 = () => ( -
- Comp2, nested Comp1: -
-); - -export default Comp2; diff --git a/packages/react-scripts/fixtures/monorepos/packages/comp2/index.test.js b/packages/react-scripts/fixtures/monorepos/packages/comp2/index.test.js deleted file mode 100644 index 6d022e87d54..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/comp2/index.test.js +++ /dev/null @@ -1,8 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import Comp2 from '.'; - -it('renders Comp2 without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render(, div); -}); diff --git a/packages/react-scripts/fixtures/monorepos/packages/comp2/package.json b/packages/react-scripts/fixtures/monorepos/packages/comp2/package.json deleted file mode 100644 index 329b14077ba..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/comp2/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "comp2", - "dependencies": { - "comp1": "^1.0.0" - }, - "devDependencies": { - "react": "^16.2.0", - "react-dom": "^16.2.0" - }, - "version": "1.0.0", - "main": "index.js", - "license": "MIT" -} diff --git a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/.gitignore b/packages/react-scripts/fixtures/monorepos/packages/cra-app1/.gitignore deleted file mode 100644 index d30f40ef442..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/.gitignore +++ /dev/null @@ -1,21 +0,0 @@ -# See https://help.github.com/ignore-files/ for more about ignoring files. - -# dependencies -/node_modules - -# testing -/coverage - -# production -/build - -# misc -.DS_Store -.env.local -.env.development.local -.env.test.local -.env.production.local - -npm-debug.log* -yarn-debug.log* -yarn-error.log* diff --git a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/package.json b/packages/react-scripts/fixtures/monorepos/packages/cra-app1/package.json deleted file mode 100644 index 218edb79d6b..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "cra-app1", - "version": "0.1.0", - "private": true, - "dependencies": { - "comp2": "^1.0.0", - "react": "^16.2.0", - "react-dom": "^16.2.0" - }, - "devDependencies": { - "react-scripts": "latest" - }, - "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test --env=jsdom", - "eject": "react-scripts eject" - }, - "browserslist": { - "development": [ - "last 2 chrome versions", - "last 2 firefox versions", - "last 2 edge versions" - ], - "production": [ - ">1%", - "last 4 versions", - "Firefox ESR", - "not ie < 11" - ] - } -} diff --git a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/public/favicon.ico b/packages/react-scripts/fixtures/monorepos/packages/cra-app1/public/favicon.ico deleted file mode 100644 index a11777cc471..00000000000 Binary files a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/public/favicon.ico and /dev/null differ diff --git a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/public/index.html b/packages/react-scripts/fixtures/monorepos/packages/cra-app1/public/index.html deleted file mode 100644 index ed0ebafa1b7..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/public/index.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - React App - - - -
- - - diff --git a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/public/manifest.json b/packages/react-scripts/fixtures/monorepos/packages/cra-app1/public/manifest.json deleted file mode 100644 index ef19ec243e7..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/public/manifest.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "short_name": "React App", - "name": "Create React App Sample", - "icons": [ - { - "src": "favicon.ico", - "sizes": "64x64 32x32 24x24 16x16", - "type": "image/x-icon" - } - ], - "start_url": "./index.html", - "display": "standalone", - "theme_color": "#000000", - "background_color": "#ffffff" -} diff --git a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/App.css b/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/App.css deleted file mode 100644 index c5c6e8a68ad..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/App.css +++ /dev/null @@ -1,28 +0,0 @@ -.App { - text-align: center; -} - -.App-logo { - animation: App-logo-spin infinite 20s linear; - height: 80px; -} - -.App-header { - background-color: #222; - height: 150px; - padding: 20px; - color: white; -} - -.App-title { - font-size: 1.5em; -} - -.App-intro { - font-size: large; -} - -@keyframes App-logo-spin { - from { transform: rotate(0deg); } - to { transform: rotate(360deg); } -} diff --git a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/App.js b/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/App.js deleted file mode 100644 index ab9f3f95793..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/App.js +++ /dev/null @@ -1,24 +0,0 @@ -import React, { Component } from 'react'; -import logo from './logo.svg'; -import './App.css'; - -import Comp2 from 'comp2'; - -class App extends Component { - render() { - return ( -
-
- logo -

YarnWS-CraApp1

-
-

- To get started, edit src/App.js and save to reload. -

- -
- ); - } -} - -export default App; diff --git a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/App.test.js b/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/App.test.js deleted file mode 100644 index a754b201bf9..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/App.test.js +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import App from './App'; - -it('renders without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render(, div); - ReactDOM.unmountComponentAtNode(div); -}); diff --git a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/index.css b/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/index.css deleted file mode 100644 index b4cc7250b98..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/index.css +++ /dev/null @@ -1,5 +0,0 @@ -body { - margin: 0; - padding: 0; - font-family: sans-serif; -} diff --git a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/index.js b/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/index.js deleted file mode 100644 index 395b74997b2..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/index.js +++ /dev/null @@ -1,6 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import './index.css'; -import App from './App'; - -ReactDOM.render(, document.getElementById('root')); diff --git a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/logo.svg b/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/logo.svg deleted file mode 100644 index 6b60c1042f5..00000000000 --- a/packages/react-scripts/fixtures/monorepos/packages/cra-app1/src/logo.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/packages/react-scripts/fixtures/monorepos/yarn-ws/package.json b/packages/react-scripts/fixtures/monorepos/yarn-ws/package.json deleted file mode 100644 index aad9ea832aa..00000000000 --- a/packages/react-scripts/fixtures/monorepos/yarn-ws/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "private": true, - "workspaces": ["packages/*"] -} diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 7fe0b2bb1c6..0e639a768dd 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -44,9 +44,7 @@ "eslint-plugin-jsx-a11y": "6.0.3", "eslint-plugin-react": "7.8.2", "file-loader": "1.1.11", - "find-pkg": "1.0.0", "fs-extra": "5.0.0", - "globby": "7.1.1", "graphql": "0.13.2", "graphql-tag": "2.9.2", "html-webpack-plugin": "3.2.0", diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index e8c64a77853..84353fc3c81 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -109,7 +109,7 @@ inquirer const jestConfig = createJestConfig( filePath => path.posix.join('', filePath), null, - paths.srcPaths + true ); console.log(); @@ -205,6 +205,18 @@ inquirer console.log(` Adding ${cyan('Jest')} configuration`); appPackage.jest = jestConfig; + // Add Babel config + console.log(` Adding ${cyan('Babel')} preset`); + appPackage.babel = { + presets: ['react-app'], + }; + + // Add ESlint config + console.log(` Adding ${cyan('ESLint')} configuration`); + appPackage.eslintConfig = { + extends: 'react-app', + }; + fs.writeFileSync( path.join(appPath, 'package.json'), JSON.stringify(appPackage, null, 2) + os.EOL diff --git a/packages/react-scripts/scripts/test.js b/packages/react-scripts/scripts/test.js index b77db920625..60b69e1673f 100644 --- a/packages/react-scripts/scripts/test.js +++ b/packages/react-scripts/scripts/test.js @@ -53,7 +53,7 @@ argv.push( createJestConfig( relativePath => path.resolve(__dirname, '..', relativePath), path.resolve(paths.appSrc, '..'), - paths.srcPaths + false ) ) ); diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index e884518d73a..72c50e1f1b2 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -8,19 +8,16 @@ 'use strict'; const fs = require('fs'); -const path = require('path'); const chalk = require('chalk'); const paths = require('../../config/paths'); -module.exports = (resolve, rootDir, srcRoots) => { +module.exports = (resolve, rootDir, isEjecting) => { // Use this instead of `paths.testsSetup` to avoid putting // an absolute filename into configuration after ejecting. const setupTestsFile = fs.existsSync(paths.testsSetup) ? '/src/setupTests.js' : undefined; - const toRelRootDir = f => '/' + path.relative(rootDir || '', f); - // TODO: I don't know if it's safe or not to just use / as path separator // in Jest configs. We need help from somebody with Windows to determine this. const config = { @@ -28,15 +25,15 @@ module.exports = (resolve, rootDir, srcRoots) => { setupFiles: [resolve('config/polyfills.js')], setupTestFrameworkScriptFile: setupTestsFile, testMatch: [ - '**/__tests__/**/*.{js,jsx,mjs}', - '**/?(*.)(spec|test).{js,jsx,mjs}', + '/src/**/__tests__/**/*.{js,jsx,mjs}', + '/src/**/?(*.)(spec|test).{js,jsx,mjs}', ], - // where to search for files/tests - roots: srcRoots.map(toRelRootDir), testEnvironment: 'node', testURL: 'http://localhost', transform: { - '^.+\\.(js|jsx|mjs)$': resolve('config/jest/babelTransform.js'), + '^.+\\.(js|jsx|mjs)$': isEjecting + ? '/node_modules/babel-jest' + : resolve('config/jest/babelTransform.js'), '^.+\\.css$': resolve('config/jest/cssTransform.js'), '^.+\\.(graphql)$': resolve('config/jest/graphqlTransform.js'), '^(?!.*\\.(js|jsx|mjs|css|json|graphql)$)': resolve( @@ -64,7 +61,6 @@ module.exports = (resolve, rootDir, srcRoots) => { if (rootDir) { config.rootDir = rootDir; } - const overrides = Object.assign({}, require(paths.appPackageJson).jest); const supportedKeys = [ 'collectCoverageFrom', diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index d857bc93c03..edaf7c62f52 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -74,7 +74,6 @@ You can find the most recent version of this guide [here](https://github.com/fac - [Developing Components in Isolation](#developing-components-in-isolation) - [Getting Started with Storybook](#getting-started-with-storybook) - [Getting Started with Styleguidist](#getting-started-with-styleguidist) -- [Sharing Components in a Monorepo](#sharing-components-in-a-monorepo) - [Publishing Components to npm](#publishing-components-to-npm) - [Making a Progressive Web App](#making-a-progressive-web-app) - [Opting Out of Caching](#opting-out-of-caching) @@ -1851,66 +1850,6 @@ Learn more about React Styleguidist: * [GitHub Repo](https://github.com/styleguidist/react-styleguidist) * [Documentation](https://react-styleguidist.js.org/docs/getting-started.html) -## Sharing Components in a Monorepo -A typical monorepo folder structure looks like this: -``` -monorepo/ - app1/ - app2/ - comp1/ - comp2/ -``` - -The monorepo allows components to be separated from the app, providing: -* a level of encapsulation for components -* sharing of components - -### How to Set Up a Monorepo -Below expands on the monorepo structure above, adding the package.json files required to configure the monorepo for [yarn workspaces](https://yarnpkg.com/en/docs/workspaces). -``` -monorepo/ - package.json: - "workspaces": ["*"], - "private": true - app1/ - package.json: - "dependencies": ["@myorg/comp1": ">=0.0.0", "react": "^16.2.0"], - "devDependencies": ["react-scripts": "2.0.0"] - src/ - app.js: import comp1 from '@myorg/comp1'; - app2/ - package.json: - "dependencies": ["@myorg/comp1": ">=0.0.0", "react": "^16.2.0"], - "devDependencies": ["react-scripts": "2.0.0"] - src/ - app.js: import comp1 from '@myorg/comp1'; - comp1/ - package.json: - "name": "@myorg/comp1", - "version": "0.1.0" - index.js - comp2/ - package.json: - "name": "@myorg/comp2", - "version": "0.1.0", - "dependencies": ["@myorg/comp1": ">=0.0.0"], - "devDependencies": ["react": "^16.2.0"] - index.js: import comp1 from '@myorg/comp1' -``` -* Monorepo tools work on a package level, the same level as an npm package. -* The "workspaces" in the top-level package.json is an array of glob patterns specifying where shared packages are located in the monorepo. -* The scoping prefixes, e.g. @myorg/, are not required, but are recommended, allowing you to differentiate your packages from others of the same name. See [scoped packages ](https://docs.npmjs.com/misc/scope) for more info. -* Using a package in the monorepo is accomplished in the same manner as a published npm package, by specifying the shared package as dependency. -* In order to pick up the monorepo version of a package, the specified dependency version must semantically match the package version in the monorepo. See [semver](https://docs.npmjs.com/misc/semver) for info on semantic version matching. - -### CRA Apps in a Monorepo -* CRA apps in a monorepo are just a standard CRA app, they use the same react-script scripts. -* However, when you use react-scripts for an app in a monorepo, all packages in the monorepo are treated as app sources -- they are watched, linted, transpiled, and tested in the same way as if they were part of the app itself. -* Without this functionality, each package would need its own build/test/etc functionality and it would be challenging to link all of these together. - -### Lerna and Publishing -[Lerna](https://github.com/lerna/lerna) is a popular tool for managing monorepos. Lerna can be configured to use yarn workspaces, so it will work with the monorepo structure above. It's important to note that while lerna helps publish various packages in a monorepo, react-scripts does nothing to help publish a component to npm. A component which uses JSX or ES6+ features would need to be built by another tool before it can be published to npm. See [publishing components to npm](#publishing-components-to-npm) for more info. - ## Publishing Components to npm Create React App doesn't provide any built-in functionality to publish a component to npm. If you're ready to extract a component from your project so other people can use it, we recommend moving it to a separate directory outside of your project and then using a tool like [nwb](https://github.com/insin/nwb#react-components-and-libraries) to prepare it for publishing. diff --git a/tasks/e2e-kitchensink.sh b/tasks/e2e-kitchensink.sh index c001a01e4da..c6011997cf8 100755 --- a/tasks/e2e-kitchensink.sh +++ b/tasks/e2e-kitchensink.sh @@ -145,6 +145,10 @@ PORT=3001 \ nohup yarn start &>$tmp_server_log & grep -q 'You can now view' <(tail -f $tmp_server_log) +# Before running Mocha, specify that it should use our preset +# TODO: this is very hacky and we should find some other solution +echo '{"presets":["react-app"]}' > .babelrc + # Test "development" environment E2E_URL="http://localhost:3001" \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ @@ -161,5 +165,9 @@ E2E_FILE=./build/index.html \ PUBLIC_URL=http://www.example.org/spa/ \ node_modules/.bin/mocha --timeout 30000 --compilers js:@babel/register --require @babel/polyfill integration/*.test.js +# Remove the config we just created for Mocha +# TODO: this is very hacky and we should find some other solution +rm .babelrc + # Cleanup cleanup diff --git a/tasks/e2e-monorepos.sh b/tasks/e2e-monorepos.sh deleted file mode 100755 index 0f3f70219bd..00000000000 --- a/tasks/e2e-monorepos.sh +++ /dev/null @@ -1,134 +0,0 @@ -#!/bin/bash -# Copyright (c) 2015-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. - -# ****************************************************************************** -# This is an end-to-end test intended to run on CI. -# You can also run it locally but it's slow. -# ****************************************************************************** - -# Start in tasks/ even if run from root directory -cd "$(dirname "$0")" - -# App temporary location -# http://unix.stackexchange.com/a/84980 -temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'` -custom_registry_url=http://localhost:4873 -original_npm_registry_url=`npm get registry` -original_yarn_registry_url=`yarn config get registry` - -function cleanup { - echo 'Cleaning up.' - cd "$root_path" - # Uncomment when snapshot testing is enabled by default: - # rm ./packages/react-scripts/template/src/__snapshots__/App.test.js.snap - rm -rf "$temp_app_path" - npm set registry "$original_npm_registry_url" - yarn config set registry "$original_yarn_registry_url" -} - -# Error messages are redirected to stderr -function handle_error { - echo "$(basename $0): ERROR! An error was encountered executing line $1." 1>&2; - cleanup - echo 'Exiting with error.' 1>&2; - exit 1 -} - -function handle_exit { - cleanup - echo 'Exiting without error.' 1>&2; - exit -} - -# Check for the existence of one or more files. -function exists { - for f in $*; do - test -e "$f" - done -} - -# Exit the script with a helpful error message when any error is encountered -trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR - -# Cleanup before exit on any termination signal -trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP - -# Echo every command being executed -set -x - -# Go to root -cd .. -root_path=$PWD - -if hash npm 2>/dev/null -then - npm i -g npm@latest -fi - -# Bootstrap create-react-app monorepo -yarn - -# Start local registry -tmp_registry_log=`mktemp` -nohup npx verdaccio@3.2.0 -c tasks/verdaccio.yaml &>$tmp_registry_log & -# Wait for `verdaccio` to boot -grep -q 'http address' <(tail -f $tmp_registry_log) - -# Set registry to local registry -npm set registry "$custom_registry_url" -yarn config set registry "$custom_registry_url" - -# Login so we can publish packages -(cd && npx npm-auth-to-token@1.0.0 -u user -p password -e user@example.com -r "$custom_registry_url") - -git clean -df -./tasks/publish.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest - -function verifyTest { - CI=true yarn test --watch=no --json --outputFile testoutput.json || return 1 - cat testoutput.json - # on windows, output contains double backslashes for path separator - grep -E -q "src([\\]{1,2}|/)App.test.js" testoutput.json || return 1 - grep -E -q "comp1([\\]{1,2}|/)index.test.js" testoutput.json || return 1 - grep -E -q "comp2([\\]{1,2}|/)index.test.js" testoutput.json || return 1 -} - -function verifyBuild { - yarn build || return 1 - grep -F -R --exclude=*.map "YarnWS-CraApp" build/ -q || return 1 -} - -# ****************************************************************************** -# Test yarn workspace monorepo -# ****************************************************************************** -# Set up yarn workspace monorepo -pushd "$temp_app_path" -cp -r "$root_path/packages/react-scripts/fixtures/monorepos/yarn-ws" . -cd "yarn-ws" -cp -r "$root_path/packages/react-scripts/fixtures/monorepos/packages" . -yarn - -# Test cra-app1 -cd packages/cra-app1 -verifyBuild -yarn start --smoke-test -verifyTest - -# Test eject -echo yes | npm run eject -verifyBuild -yarn start --smoke-test -verifyTest - -# ****************************************************************************** -# Test create-react-app inside workspace -# ****************************************************************************** -# npx create-react-app --internal-testing-template="$root_path"/packages/react-scripts/fixtures/yarn-ws/ws/cra-app1 cra-app2 -# -- above needs https://github.com/facebookincubator/create-react-app/pull/3435 to user create-react-app -popd - -# Cleanup -cleanup diff --git a/tasks/local-test.sh b/tasks/local-test.sh index 222630f2170..c9618dda2c9 100755 --- a/tasks/local-test.sh +++ b/tasks/local-test.sh @@ -49,7 +49,7 @@ while [ "$1" != "" ]; do shift done -test_command="./tasks/e2e-simple.sh && ./tasks/e2e-kitchensink.sh && ./tasks/e2e-installs.sh && ./tasks/e2e-monorepos.sh" +test_command="./tasks/e2e-simple.sh && ./tasks/e2e-kitchensink.sh && ./tasks/e2e-installs.sh" case ${test_suite} in "all") ;; @@ -62,9 +62,6 @@ case ${test_suite} in "installs") test_command="./tasks/e2e-installs.sh" ;; - "monorepos") - test_command="./tasks/e2e-monorepos.sh" - ;; *) ;; esac