├── .eslintignore ├── .eslintrc ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── .yarnrc ├── CHANGELOG-0.x.md ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── appveyor.cleanup-cache.txt ├── appveyor.yml ├── lerna.json ├── package.json ├── packages ├── babel-preset-react-app │ ├── README.md │ ├── create.js │ ├── dev.js │ ├── index.js │ ├── package.json │ ├── prod.js │ └── test.js ├── create-react-app │ ├── README.md │ ├── createReactApp.js │ ├── index.js │ └── package.json ├── eslint-config-react-app │ ├── README.md │ ├── index.js │ └── package.json ├── react-dev-utils │ ├── FileSizeReporter.js │ ├── InterpolateHtmlPlugin.js │ ├── ModuleScopePlugin.js │ ├── README.md │ ├── WatchMissingNodeModulesPlugin.js │ ├── WebpackDevServerUtils.js │ ├── __tests__ │ │ ├── .eslintrc │ │ └── ignoredFiles.test.js │ ├── checkRequiredFiles.js │ ├── clearConsole.js │ ├── crossSpawn.js │ ├── errorOverlayMiddleware.js │ ├── eslintFormatter.js │ ├── formatWebpackMessages.js │ ├── getProcessForPort.js │ ├── ignoredFiles.js │ ├── inquirer.js │ ├── launchEditor.js │ ├── launchEditorEndpoint.js │ ├── noopServiceWorkerMiddleware.js │ ├── openBrowser.js │ ├── openChrome.applescript │ ├── package.json │ ├── printBuildError.js │ ├── printHostingInstructions.js │ └── webpackHotDevClient.js ├── react-error-overlay │ ├── .babelrc │ ├── .eslintrc │ ├── .flowconfig │ ├── .gitattributes │ ├── .gitignore │ ├── .npmignore │ ├── README.md │ ├── build.js │ ├── fixtures │ │ ├── bundle-default.json │ │ ├── bundle.json │ │ ├── bundle.mjs │ │ ├── bundle.mjs.map │ │ ├── bundle2.json │ │ ├── bundle_u.mjs │ │ ├── bundle_u.mjs.map │ │ ├── inline.es6.mjs │ │ ├── inline.mjs │ │ └── junk-inline.mjs │ ├── flow │ │ └── env.js │ ├── package.json │ ├── src │ │ ├── __tests__ │ │ │ ├── __snapshots__ │ │ │ │ ├── lines-around.js.snap │ │ │ │ ├── script-lines.js.snap │ │ │ │ ├── stack-frame.js.snap │ │ │ │ └── unmapper.js.snap │ │ │ ├── extract-source-map.js │ │ │ ├── get-source-map.js │ │ │ ├── lines-around.js │ │ │ ├── mapper.js │ │ │ ├── parser │ │ │ │ ├── __snapshots__ │ │ │ │ │ ├── chrome.js.snap │ │ │ │ │ ├── firefox.js.snap │ │ │ │ │ ├── react.js.snap │ │ │ │ │ └── safari.js.snap │ │ │ │ ├── chrome.js │ │ │ │ ├── firefox.js │ │ │ │ ├── generic.js │ │ │ │ ├── react.js │ │ │ │ └── safari.js │ │ │ ├── script-lines.js │ │ │ ├── setupJest.js │ │ │ ├── stack-frame.js │ │ │ └── unmapper.js │ │ ├── components │ │ │ ├── CloseButton.js │ │ │ ├── CodeBlock.js │ │ │ ├── Collapsible.js │ │ │ ├── ErrorOverlay.js │ │ │ ├── Footer.js │ │ │ ├── Header.js │ │ │ └── NavigationBar.js │ │ ├── containers │ │ │ ├── CompileErrorContainer.js │ │ │ ├── RuntimeError.js │ │ │ ├── RuntimeErrorContainer.js │ │ │ ├── StackFrame.js │ │ │ ├── StackFrameCodeBlock.js │ │ │ └── StackTrace.js │ │ ├── effects │ │ │ ├── proxyConsole.js │ │ │ ├── stackTraceLimit.js │ │ │ ├── unhandledError.js │ │ │ └── unhandledRejection.js │ │ ├── iframeScript.js │ │ ├── index.js │ │ ├── listenToRuntimeErrors.js │ │ ├── styles.js │ │ └── utils │ │ │ ├── dom │ │ │ ├── absolutifyCaret.js │ │ │ └── css.js │ │ │ ├── generateAnsiHTML.js │ │ │ ├── getLinesAround.js │ │ │ ├── getPrettyURL.js │ │ │ ├── getSourceMap.js │ │ │ ├── getStackFrames.js │ │ │ ├── isBultinErrorName.js │ │ │ ├── isInternalFile.js │ │ │ ├── mapper.js │ │ │ ├── parseCompileError.js │ │ │ ├── parser.js │ │ │ ├── pollyfills.js │ │ │ ├── stack-frame.js │ │ │ ├── unmapper.js │ │ │ └── warnings.js │ ├── webpack.config.iframe.js │ └── webpack.config.js └── react-scripts │ ├── .npmignore │ ├── README.md │ ├── bin │ └── react-scripts.js │ ├── config │ ├── env.js │ ├── jest │ │ ├── babelTransform.js │ │ ├── cssTransform.js │ │ └── fileTransform.js │ ├── paths.js │ ├── polyfills.js │ ├── webpack.config.dev.js │ ├── webpack.config.prod.js │ └── webpackDevServer.config.js │ ├── fixtures │ └── kitchensink │ │ ├── .babelrc │ │ ├── .env │ │ ├── .env.development │ │ ├── .env.local │ │ ├── .env.production │ │ ├── .flowconfig │ │ ├── .template.dependencies.json │ │ ├── README.md │ │ ├── gitignore │ │ ├── integration │ │ ├── env.test.js │ │ ├── initDOM.js │ │ ├── syntax.test.js │ │ └── webpack.test.js │ │ ├── public │ │ ├── favicon.ico │ │ └── index.html │ │ └── src │ │ ├── App.js │ │ ├── absoluteLoad.js │ │ ├── features │ │ ├── env │ │ │ ├── ExpandEnvVariables.js │ │ │ ├── ExpandEnvVariables.test.js │ │ │ ├── FileEnvVariables.js │ │ │ ├── FileEnvVariables.test.js │ │ │ ├── NodePath.js │ │ │ ├── NodePath.test.js │ │ │ ├── PublicUrl.js │ │ │ ├── PublicUrl.test.js │ │ │ ├── ShellEnvVariables.js │ │ │ └── ShellEnvVariables.test.js │ │ ├── syntax │ │ │ ├── ArrayDestructuring.js │ │ │ ├── ArrayDestructuring.test.js │ │ │ ├── ArraySpread.js │ │ │ ├── ArraySpread.test.js │ │ │ ├── AsyncAwait.js │ │ │ ├── AsyncAwait.test.js │ │ │ ├── ClassProperties.js │ │ │ ├── ClassProperties.test.js │ │ │ ├── ComputedProperties.js │ │ │ ├── ComputedProperties.test.js │ │ │ ├── CustomInterpolation.js │ │ │ ├── CustomInterpolation.test.js │ │ │ ├── DefaultParameters.js │ │ │ ├── DefaultParameters.test.js │ │ │ ├── DestructuringAndAwait.js │ │ │ ├── DestructuringAndAwait.test.js │ │ │ ├── Generators.js │ │ │ ├── Generators.test.js │ │ │ ├── ObjectDestructuring.js │ │ │ ├── ObjectDestructuring.test.js │ │ │ ├── ObjectSpread.js │ │ │ ├── ObjectSpread.test.js │ │ │ ├── Promises.js │ │ │ ├── Promises.test.js │ │ │ ├── RestAndDefault.js │ │ │ ├── RestAndDefault.test.js │ │ │ ├── RestParameters.js │ │ │ ├── RestParameters.test.js │ │ │ ├── TemplateInterpolation.js │ │ │ └── TemplateInterpolation.test.js │ │ └── webpack │ │ │ ├── CssInclusion.js │ │ │ ├── CssInclusion.test.js │ │ │ ├── ImageInclusion.js │ │ │ ├── ImageInclusion.test.js │ │ │ ├── JsonInclusion.js │ │ │ ├── JsonInclusion.test.js │ │ │ ├── LinkedModules.js │ │ │ ├── LinkedModules.test.js │ │ │ ├── NoExtInclusion.js │ │ │ ├── NoExtInclusion.test.js │ │ │ ├── SvgInclusion.js │ │ │ ├── SvgInclusion.test.js │ │ │ ├── UnknownExtInclusion.js │ │ │ ├── UnknownExtInclusion.test.js │ │ │ └── assets │ │ │ ├── aFileWithExt.unknown │ │ │ ├── aFileWithoutExt │ │ │ ├── abstract.json │ │ │ ├── logo.svg │ │ │ ├── style.css │ │ │ └── tiniest-cat.jpg │ │ ├── index.js │ │ └── subfolder │ │ └── lol.js │ ├── package.json │ ├── scripts │ ├── build.js │ ├── eject.js │ ├── init.js │ ├── start.js │ ├── test.js │ └── utils │ │ └── createJestConfig.js │ └── template │ ├── .babelrc │ ├── .editorconfig │ ├── .eslintrc.js │ ├── .stylelintrc.js │ ├── README.md │ ├── gitignore │ ├── public │ ├── favicon.ico │ ├── index.html │ └── manifest.json │ └── src │ ├── components │ └── App │ │ ├── index.js │ │ ├── index.test.js │ │ ├── logo.inline.svg │ │ ├── logo.svg │ │ └── style.scss │ ├── index.js │ ├── shared │ └── styles │ │ ├── colors.scss │ │ ├── index.scss │ │ ├── mixins.scss │ │ ├── typography.scss │ │ └── z-index.scss │ └── utils │ └── registerServiceWorker.js ├── screencast.svg └── tasks ├── cra.js ├── e2e-installs.sh ├── e2e-kitchensink.sh ├── e2e-old-node.sh ├── e2e-simple.sh ├── local-test.sh ├── publish.sh └── replace-own-deps.js /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | build 3 | my-app* 4 | packages/react-scripts/template 5 | packages/react-scripts/fixtures 6 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint:recommended", 3 | "env": { 4 | "browser": true, 5 | "commonjs": true, 6 | "node": true, 7 | "es6": true 8 | }, 9 | "parserOptions": { 10 | "ecmaVersion": 6 11 | }, 12 | "rules": { 13 | "no-console": "off", 14 | "strict": ["error", "global"], 15 | "curly": "warn" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vscode/ 3 | node_modules/ 4 | build 5 | .DS_Store 6 | *.tgz 7 | my-app* 8 | template/src/__tests__/__snapshots__/ 9 | lerna-debug.log 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | /.changelog 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dist: trusty 3 | language: node_js 4 | node_js: 5 | - 8 6 | - 9 7 | cache: 8 | directories: 9 | - node_modules 10 | - packages/create-react-app/node_modules 11 | - packages/react-scripts/node_modules 12 | install: true 13 | script: 14 | - 'if [ $TEST_SUITE = "simple" ]; then tasks/e2e-simple.sh; fi' 15 | - 'if [ $TEST_SUITE = "installs" ]; then tasks/e2e-installs.sh; fi' 16 | - 'if [ $TEST_SUITE = "kitchensink" ]; then tasks/e2e-kitchensink.sh; fi' 17 | - 'if [ $TEST_SUITE = "old-node" ]; then tasks/e2e-old-node.sh; fi' 18 | env: 19 | matrix: 20 | - TEST_SUITE=simple 21 | - TEST_SUITE=installs 22 | - TEST_SUITE=kitchensink 23 | matrix: 24 | include: 25 | - node_js: 0.10 26 | env: TEST_SUITE=old-node 27 | - node_js: 6 28 | env: TEST_SUITE=kitchensink 29 | -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | --install.no-lockfile true 2 | --install.check-files true 3 | --add.no-lockfile true 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](https://code.facebook.com/pages/876921332402685/open-source-code-of-conduct) so that you can understand what actions will and will not be tolerated. 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2013-present, Facebook, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /appveyor.cleanup-cache.txt: -------------------------------------------------------------------------------- 1 | Edit this file to trigger a cache rebuild. 2 | http://help.appveyor.com/discussions/questions/1310-delete-cache 3 | 4 | ---- 5 | Just testing if this works. 6 | lalala. 7 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2017 2 | 3 | environment: 4 | matrix: 5 | - nodejs_version: 8 6 | test_suite: "simple" 7 | - nodejs_version: 8 8 | test_suite: "installs" 9 | - nodejs_version: 8 10 | test_suite: "kitchensink" 11 | - nodejs_version: 6 12 | test_suite: "simple" 13 | - nodejs_version: 6 14 | test_suite: "installs" 15 | - nodejs_version: 6 16 | test_suite: "kitchensink" 17 | 18 | cache: 19 | - node_modules -> appveyor.cleanup-cache.txt 20 | - packages\react-scripts\node_modules -> appveyor.cleanup-cache.txt 21 | 22 | clone_depth: 50 23 | 24 | matrix: 25 | fast_finish: true 26 | 27 | platform: 28 | - x64 29 | 30 | install: 31 | - ps: Install-Product node $env:nodejs_version $env:platform 32 | 33 | build: off 34 | 35 | skip_commits: 36 | files: 37 | - '**/*.md' 38 | 39 | test_script: 40 | - node --version 41 | - npm --version 42 | - bash tasks/e2e-%test_suite%.sh 43 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "lerna": "2.6.0", 3 | "npmClient": "yarn", 4 | "useWorkspaces": true, 5 | "version": "independent", 6 | "changelog": { 7 | "repo": "facebookincubator/create-react-app", 8 | "labels": { 9 | "tag: new feature": ":rocket: New Feature", 10 | "tag: breaking change": ":boom: Breaking Change", 11 | "tag: bug fix": ":bug: Bug Fix", 12 | "tag: enhancement": ":nail_care: Enhancement", 13 | "tag: documentation": ":memo: Documentation", 14 | "tag: internal": ":house: Internal" 15 | }, 16 | "cacheDir": ".changelog" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "workspaces": [ 4 | "packages/*" 5 | ], 6 | "scripts": { 7 | "build": "cd packages/react-scripts && node scripts/build.js", 8 | "changelog": "lerna-changelog", 9 | "create-react-app": "node tasks/cra.js", 10 | "e2e": "tasks/e2e-simple.sh", 11 | "e2e:docker": "tasks/local-test.sh", 12 | "postinstall": "cd packages/react-error-overlay/ && yarn build:prod", 13 | "publish": "tasks/publish.sh", 14 | "start": "cd packages/react-scripts && node scripts/start.js", 15 | "screencast": "svg-term --cast hItN7sl5yfCPTHxvFg5glhhfp --out screencast.svg --window", 16 | "test": "cd packages/react-scripts && node scripts/test.js --env=jsdom", 17 | "format": "prettier --trailing-comma es5 --single-quote --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'", 18 | "precommit": "lint-staged" 19 | }, 20 | "devDependencies": { 21 | "eslint": "^4.4.1", 22 | "husky": "^0.13.2", 23 | "lerna": "2.6.0", 24 | "lerna-changelog": "^0.6.0", 25 | "lint-staged": "^3.3.1", 26 | "prettier": "1.6.1", 27 | "svg-term-cli": "^2.0.3" 28 | }, 29 | "lint-staged": { 30 | "*.js": [ 31 | "prettier --trailing-comma es5 --single-quote --write", 32 | "git add" 33 | ], 34 | "yarn.lock": [ 35 | "git rm --cached" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/babel-preset-react-app/README.md: -------------------------------------------------------------------------------- 1 | # babel-preset-react-app 2 | 3 | This package includes the Babel preset used by [Create React App](https://github.com/facebookincubator/create-react-app).
4 | Please refer to its documentation: 5 | 6 | * [Getting Started](https://github.com/facebookincubator/create-react-app/blob/master/README.md#getting-started) – How to create a new app. 7 | * [User Guide](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md) – How to develop apps bootstrapped with Create React App. 8 | 9 | ## Usage in Create React App Projects 10 | 11 | The easiest way to use this configuration is with [Create React App](https://github.com/facebookincubator/create-react-app), which includes it by default. **You don’t need to install it separately in Create React App projects.** 12 | 13 | ## Usage Outside of Create React App 14 | 15 | If you want to use this Babel preset in a project not built with Create React App, you can install it with following steps. 16 | 17 | First, [install Babel](https://babeljs.io/docs/setup/). 18 | 19 | Then install babel-preset-react-app. 20 | 21 | ```sh 22 | npm install babel-preset-react-app --save-dev 23 | ``` 24 | 25 | Then create a file named `.babelrc` with following contents in the root folder of your project: 26 | 27 | ```js 28 | { 29 | "presets": ["react-app"] 30 | } 31 | ``` 32 | 33 | This preset uses the `useBuiltIns` option with [transform-object-rest-spread](http://babeljs.io/docs/plugins/transform-object-rest-spread/) and [transform-react-jsx](http://babeljs.io/docs/plugins/transform-react-jsx/), which assumes that `Object.assign` is available or polyfilled. 34 | -------------------------------------------------------------------------------- /packages/babel-preset-react-app/dev.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 'use strict'; 8 | 9 | const create = require('./create'); 10 | 11 | module.exports = create('development'); 12 | -------------------------------------------------------------------------------- /packages/babel-preset-react-app/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 'use strict'; 8 | 9 | const create = require('./create'); 10 | 11 | // This is similar to how `env` works in Babel: 12 | // https://babeljs.io/docs/usage/babelrc/#env-option 13 | // We are not using `env` because it’s ignored in versions > babel-core@6.10.4: 14 | // https://github.com/babel/babel/issues/4539 15 | // https://github.com/facebookincubator/create-react-app/issues/720 16 | // It’s also nice that we can enforce `NODE_ENV` being specified. 17 | var env = process.env.BABEL_ENV || process.env.NODE_ENV; 18 | 19 | module.exports = create(env); 20 | -------------------------------------------------------------------------------- /packages/babel-preset-react-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-preset-react-app", 3 | "version": "3.1.2", 4 | "description": "Babel preset used by Create React App", 5 | "repository": "facebookincubator/create-react-app", 6 | "license": "MIT", 7 | "bugs": { 8 | "url": "https://github.com/facebookincubator/create-react-app/issues" 9 | }, 10 | "files": [ 11 | "index.js", 12 | "create.js", 13 | "dev.js", 14 | "prod.js", 15 | "test.js" 16 | ], 17 | "dependencies": { 18 | "babel-plugin-dynamic-import-node": "1.1.0", 19 | "babel-plugin-syntax-dynamic-import": "6.18.0", 20 | "babel-plugin-transform-class-properties": "6.24.1", 21 | "babel-plugin-transform-es2015-destructuring": "6.23.0", 22 | "babel-plugin-transform-object-rest-spread": "6.26.0", 23 | "babel-plugin-transform-react-constant-elements": "6.23.0", 24 | "babel-plugin-transform-react-jsx": "6.24.1", 25 | "babel-plugin-transform-react-jsx-self": "6.22.0", 26 | "babel-plugin-transform-react-jsx-source": "6.22.0", 27 | "babel-plugin-transform-regenerator": "6.26.0", 28 | "babel-plugin-transform-runtime": "6.23.0", 29 | "babel-preset-env": "1.6.1", 30 | "babel-preset-react": "6.24.1" 31 | }, 32 | "peerDependencies": { 33 | "babel-runtime": "^6.23.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/babel-preset-react-app/prod.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 'use strict'; 8 | 9 | const create = require('./create'); 10 | 11 | module.exports = create('production'); 12 | -------------------------------------------------------------------------------- /packages/babel-preset-react-app/test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 'use strict'; 8 | 9 | const create = require('./create'); 10 | 11 | module.exports = create('test'); 12 | -------------------------------------------------------------------------------- /packages/create-react-app/README.md: -------------------------------------------------------------------------------- 1 | # create-react-app 2 | 3 | This package includes the global command for [Create React App](https://github.com/facebookincubator/create-react-app).
4 | Please refer to its documentation: 5 | 6 | * [Getting Started](https://github.com/facebookincubator/create-react-app/blob/master/README.md#getting-started) – How to create a new app. 7 | * [User Guide](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md) – How to develop apps bootstrapped with Create React App. 8 | -------------------------------------------------------------------------------- /packages/create-react-app/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Copyright (c) 2015-present, Facebook, Inc. 5 | * 6 | * This source code is licensed under the MIT license found in the 7 | * LICENSE file in the root directory of this source tree. 8 | */ 9 | 10 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 11 | // /!\ DO NOT MODIFY THIS FILE /!\ 12 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 13 | // 14 | // create-react-app is installed globally on people's computers. This means 15 | // that it is extremely difficult to have them upgrade the version and 16 | // because there's only one global version installed, it is very prone to 17 | // breaking changes. 18 | // 19 | // The only job of create-react-app is to init the repository and then 20 | // forward all the commands to the local version of create-react-app. 21 | // 22 | // If you need to add a new command, please add it to the scripts/ folder. 23 | // 24 | // The only reason to modify this file is to add more warnings and 25 | // troubleshooting information for the `create-react-app` command. 26 | // 27 | // Do not make breaking changes! We absolutely don't want to have to 28 | // tell people to update their global version of create-react-app. 29 | // 30 | // Also be careful with new language features. 31 | // This file must work on Node 0.10+. 32 | // 33 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 34 | // /!\ DO NOT MODIFY THIS FILE /!\ 35 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 36 | 37 | 'use strict'; 38 | 39 | var chalk = require('chalk'); 40 | 41 | var currentNodeVersion = process.versions.node; 42 | var semver = currentNodeVersion.split('.'); 43 | var major = semver[0]; 44 | 45 | if (major < 4) { 46 | console.error( 47 | chalk.red( 48 | 'You are running Node ' + 49 | currentNodeVersion + 50 | '.\n' + 51 | 'Create React App requires Node 4 or higher. \n' + 52 | 'Please update your version of Node.' 53 | ) 54 | ); 55 | process.exit(1); 56 | } 57 | 58 | require('./createReactApp'); 59 | -------------------------------------------------------------------------------- /packages/create-react-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "create-react-app", 3 | "version": "1.5.2", 4 | "keywords": [ 5 | "react" 6 | ], 7 | "description": "Create React apps with no build configuration.", 8 | "repository": "facebookincubator/create-react-app", 9 | "license": "MIT", 10 | "engines": { 11 | "node": ">=4" 12 | }, 13 | "bugs": { 14 | "url": "https://github.com/facebookincubator/create-react-app/issues" 15 | }, 16 | "files": [ 17 | "index.js", 18 | "createReactApp.js" 19 | ], 20 | "bin": { 21 | "create-react-app": "./index.js" 22 | }, 23 | "dependencies": { 24 | "chalk": "^1.1.1", 25 | "commander": "^2.9.0", 26 | "cross-spawn": "^4.0.0", 27 | "envinfo": "3.4.2", 28 | "fs-extra": "^1.0.0", 29 | "hyperquest": "^2.1.2", 30 | "semver": "^5.0.3", 31 | "tar-pack": "^3.4.0", 32 | "tmp": "0.0.31", 33 | "validate-npm-package-name": "^3.0.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/eslint-config-react-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-config-react-app", 3 | "version": "2.1.0", 4 | "description": "ESLint configuration used by Create React App", 5 | "repository": "facebookincubator/create-react-app", 6 | "license": "MIT", 7 | "bugs": { 8 | "url": "https://github.com/facebookincubator/create-react-app/issues" 9 | }, 10 | "files": [ 11 | "index.js" 12 | ], 13 | "peerDependencies": { 14 | "babel-eslint": "^7.2.3", 15 | "eslint": "^4.1.1", 16 | "eslint-plugin-flowtype": "^2.34.1", 17 | "eslint-plugin-import": "^2.6.0", 18 | "eslint-plugin-jsx-a11y": "^5.1.1", 19 | "eslint-plugin-react": "^7.1.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/react-dev-utils/InterpolateHtmlPlugin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // This Webpack plugin lets us interpolate custom variables into `index.html`. 9 | // Usage: `new InterpolateHtmlPlugin({ 'MY_VARIABLE': 42 })` 10 | // Then, you can use %MY_VARIABLE% in your `index.html`. 11 | 12 | // It works in tandem with HtmlWebpackPlugin. 13 | // Learn more about creating plugins like this: 14 | // https://github.com/ampedandwired/html-webpack-plugin#events 15 | 16 | 'use strict'; 17 | const escapeStringRegexp = require('escape-string-regexp'); 18 | 19 | class InterpolateHtmlPlugin { 20 | constructor(replacements) { 21 | this.replacements = replacements; 22 | } 23 | 24 | apply(compiler) { 25 | compiler.plugin('compilation', compilation => { 26 | compilation.plugin( 27 | 'html-webpack-plugin-before-html-processing', 28 | (data, callback) => { 29 | // Run HTML through a series of user-specified string replacements. 30 | Object.keys(this.replacements).forEach(key => { 31 | const value = this.replacements[key]; 32 | data.html = data.html.replace( 33 | new RegExp('%' + escapeStringRegexp(key) + '%', 'g'), 34 | value 35 | ); 36 | }); 37 | callback(null, data); 38 | } 39 | ); 40 | }); 41 | } 42 | } 43 | 44 | module.exports = InterpolateHtmlPlugin; 45 | -------------------------------------------------------------------------------- /packages/react-dev-utils/ModuleScopePlugin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | const chalk = require('chalk'); 11 | const path = require('path'); 12 | 13 | class ModuleScopePlugin { 14 | constructor(appSrc, allowedFiles = []) { 15 | this.appSrc = appSrc; 16 | this.allowedFiles = new Set(allowedFiles); 17 | } 18 | 19 | apply(resolver) { 20 | const { appSrc } = this; 21 | resolver.plugin('file', (request, callback) => { 22 | // Unknown issuer, probably webpack internals 23 | if (!request.context.issuer) { 24 | return callback(); 25 | } 26 | if ( 27 | // If this resolves to a node_module, we don't care what happens next 28 | request.descriptionFileRoot.indexOf('/node_modules/') !== -1 || 29 | request.descriptionFileRoot.indexOf('\\node_modules\\') !== -1 || 30 | // Make sure this request was manual 31 | !request.__innerRequest_request 32 | ) { 33 | return callback(); 34 | } 35 | // Resolve the issuer from our appSrc and make sure it's one of our files 36 | // Maybe an indexOf === 0 would be better? 37 | const relative = path.relative(appSrc, request.context.issuer); 38 | // If it's not in src/ or a subdirectory, not our request! 39 | if (relative.startsWith('../') || relative.startsWith('..\\')) { 40 | return callback(); 41 | } 42 | const requestFullPath = path.resolve( 43 | path.dirname(request.context.issuer), 44 | request.__innerRequest_request 45 | ); 46 | if (this.allowedFiles.has(requestFullPath)) { 47 | return callback(); 48 | } 49 | // Find path from src to the requested file 50 | // Error if in a parent directory of src/ 51 | const requestRelative = path.relative(appSrc, requestFullPath); 52 | if ( 53 | requestRelative.startsWith('../') || 54 | requestRelative.startsWith('..\\') 55 | ) { 56 | callback( 57 | new Error( 58 | `You attempted to import ${chalk.cyan( 59 | request.__innerRequest_request 60 | )} which falls outside of the project ${chalk.cyan( 61 | 'src/' 62 | )} directory. ` + 63 | `Relative imports outside of ${chalk.cyan( 64 | 'src/' 65 | )} are not supported. ` + 66 | `You can either move it inside ${chalk.cyan( 67 | 'src/' 68 | )}, or add a symlink to it from project's ${chalk.cyan( 69 | 'node_modules/' 70 | )}.` 71 | ), 72 | request 73 | ); 74 | } else { 75 | callback(); 76 | } 77 | }); 78 | } 79 | } 80 | 81 | module.exports = ModuleScopePlugin; 82 | -------------------------------------------------------------------------------- /packages/react-dev-utils/WatchMissingNodeModulesPlugin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // This Webpack plugin ensures `npm install ` forces a project rebuild. 9 | // We’re not sure why this isn't Webpack's default behavior. 10 | // See https://github.com/facebookincubator/create-react-app/issues/186. 11 | 12 | 'use strict'; 13 | 14 | class WatchMissingNodeModulesPlugin { 15 | constructor(nodeModulesPath) { 16 | this.nodeModulesPath = nodeModulesPath; 17 | } 18 | 19 | apply(compiler) { 20 | compiler.plugin('emit', (compilation, callback) => { 21 | var missingDeps = compilation.missingDependencies; 22 | var nodeModulesPath = this.nodeModulesPath; 23 | 24 | // If any missing files are expected to appear in node_modules... 25 | if (missingDeps.some(file => file.indexOf(nodeModulesPath) !== -1)) { 26 | // ...tell webpack to watch node_modules recursively until they appear. 27 | compilation.contextDependencies.push(nodeModulesPath); 28 | } 29 | 30 | callback(); 31 | }); 32 | } 33 | } 34 | 35 | module.exports = WatchMissingNodeModulesPlugin; 36 | -------------------------------------------------------------------------------- /packages/react-dev-utils/__tests__/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "jest": true 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/react-dev-utils/__tests__/ignoredFiles.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | const ignoredFiles = require('../ignoredFiles'); 11 | 12 | describe('ignore watch files regex', () => { 13 | it('normal file', () => { 14 | const appSrc = '/root/src/'; 15 | const isIgnored = ignoredFiles(appSrc).test('/foo'); 16 | const isIgnoredInSrc = ignoredFiles(appSrc).test('/root/src/foo'); 17 | 18 | expect(isIgnored).toBe(false); 19 | expect(isIgnoredInSrc).toBe(false); 20 | }); 21 | 22 | it('node modules', () => { 23 | const appSrc = '/root/src/'; 24 | const isIgnored = ignoredFiles(appSrc).test('/root/node_modules/foo'); 25 | 26 | expect(isIgnored).toBe(true); 27 | }); 28 | 29 | it('node modules inside source directory', () => { 30 | const appSrc = '/root/src/'; 31 | const isIgnored = ignoredFiles(appSrc).test('/root/src/node_modules/foo'); 32 | const isIgnoredMoreThanOneLevel = ignoredFiles(appSrc).test( 33 | '/root/src/bar/node_modules/foo' 34 | ); 35 | 36 | expect(isIgnored).toBe(false); 37 | expect(isIgnoredMoreThanOneLevel).toBe(false); 38 | }); 39 | 40 | it('path contains source directory', () => { 41 | const appSrc = '/root/src/'; 42 | const isIgnored = ignoredFiles(appSrc).test( 43 | '/bar/root/src/node_modules/foo' 44 | ); 45 | 46 | expect(isIgnored).toBe(true); 47 | }); 48 | 49 | it('path starts with source directory', () => { 50 | const appSrc = '/root/src/'; 51 | const isIgnored = ignoredFiles(appSrc).test('/root/src2/node_modules/foo'); 52 | 53 | expect(isIgnored).toBe(true); 54 | }); 55 | }); 56 | -------------------------------------------------------------------------------- /packages/react-dev-utils/checkRequiredFiles.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var fs = require('fs'); 11 | var path = require('path'); 12 | var chalk = require('chalk'); 13 | 14 | function checkRequiredFiles(files) { 15 | var currentFilePath; 16 | try { 17 | files.forEach(filePath => { 18 | currentFilePath = filePath; 19 | fs.accessSync(filePath, fs.F_OK); 20 | }); 21 | return true; 22 | } catch (err) { 23 | var dirName = path.dirname(currentFilePath); 24 | var fileName = path.basename(currentFilePath); 25 | console.log(chalk.red('Could not find a required file.')); 26 | console.log(chalk.red(' Name: ') + chalk.cyan(fileName)); 27 | console.log(chalk.red(' Searched in: ') + chalk.cyan(dirName)); 28 | return false; 29 | } 30 | } 31 | 32 | module.exports = checkRequiredFiles; 33 | -------------------------------------------------------------------------------- /packages/react-dev-utils/clearConsole.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | function clearConsole() { 11 | process.stdout.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H'); 12 | } 13 | 14 | module.exports = clearConsole; 15 | -------------------------------------------------------------------------------- /packages/react-dev-utils/crossSpawn.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var crossSpawn = require('cross-spawn'); 11 | 12 | module.exports = crossSpawn; 13 | -------------------------------------------------------------------------------- /packages/react-dev-utils/errorOverlayMiddleware.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 'use strict'; 8 | 9 | const launchEditor = require('./launchEditor'); 10 | const launchEditorEndpoint = require('./launchEditorEndpoint'); 11 | 12 | module.exports = function createLaunchEditorMiddleware() { 13 | return function launchEditorMiddleware(req, res, next) { 14 | if (req.url.startsWith(launchEditorEndpoint)) { 15 | const lineNumber = parseInt(req.query.lineNumber, 10) || 1; 16 | const colNumber = parseInt(req.query.colNumber, 10) || 1; 17 | launchEditor(req.query.fileName, lineNumber, colNumber); 18 | res.end(); 19 | } else { 20 | next(); 21 | } 22 | }; 23 | }; 24 | -------------------------------------------------------------------------------- /packages/react-dev-utils/eslintFormatter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | const chalk = require('chalk'); 11 | const table = require('text-table'); 12 | 13 | function isError(message) { 14 | if (message.fatal || message.severity === 2) { 15 | return true; 16 | } 17 | return false; 18 | } 19 | 20 | function formatter(results) { 21 | let output = '\n'; 22 | let hasErrors = false; 23 | let reportContainsErrorRuleIDs = false; 24 | 25 | results.forEach(result => { 26 | let messages = result.messages; 27 | if (messages.length === 0) { 28 | return; 29 | } 30 | 31 | messages = messages.map(message => { 32 | let messageType; 33 | if (isError(message)) { 34 | messageType = 'error'; 35 | hasErrors = true; 36 | if (message.ruleId) { 37 | reportContainsErrorRuleIDs = true; 38 | } 39 | } else { 40 | messageType = 'warn'; 41 | } 42 | 43 | let line = message.line || 0; 44 | let position = chalk.bold('Line ' + line + ':'); 45 | return [ 46 | '', 47 | position, 48 | messageType, 49 | message.message.replace(/\.$/, ''), 50 | chalk.underline(message.ruleId || ''), 51 | ]; 52 | }); 53 | 54 | // if there are error messages, we want to show only errors 55 | if (hasErrors) { 56 | messages = messages.filter(m => m[2] === 'error'); 57 | } 58 | 59 | // add color to rule keywords 60 | messages.forEach(m => { 61 | m[4] = m[2] === 'error' ? chalk.red(m[4]) : chalk.yellow(m[4]); 62 | m.splice(2, 1); 63 | }); 64 | 65 | let outputTable = table(messages, { 66 | align: ['l', 'l', 'l'], 67 | stringLength(str) { 68 | return chalk.stripColor(str).length; 69 | }, 70 | }); 71 | 72 | output += `${outputTable}\n\n`; 73 | }); 74 | 75 | if (reportContainsErrorRuleIDs) { 76 | // Unlike with warnings, we have to do it here. 77 | // We have similar code in react-scripts for warnings, 78 | // but warnings can appear in multiple files so we only 79 | // print it once at the end. For errors, however, we print 80 | // it here because we always show at most one error, and 81 | // we can only be sure it's an ESLint error before exiting 82 | // this function. 83 | output += 84 | 'Search for the ' + 85 | chalk.underline(chalk.red('keywords')) + 86 | ' to learn more about each error.'; 87 | } 88 | 89 | return output; 90 | } 91 | 92 | module.exports = formatter; 93 | -------------------------------------------------------------------------------- /packages/react-dev-utils/getProcessForPort.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var chalk = require('chalk'); 11 | var execSync = require('child_process').execSync; 12 | var path = require('path'); 13 | 14 | var execOptions = { 15 | encoding: 'utf8', 16 | stdio: [ 17 | 'pipe', // stdin (default) 18 | 'pipe', // stdout (default) 19 | 'ignore', //stderr 20 | ], 21 | }; 22 | 23 | function isProcessAReactApp(processCommand) { 24 | return /^node .*react-scripts\/scripts\/start\.js\s?$/.test(processCommand); 25 | } 26 | 27 | function getProcessIdOnPort(port) { 28 | return execSync('lsof -i:' + port + ' -P -t -sTCP:LISTEN', execOptions) 29 | .split('\n')[0] 30 | .trim(); 31 | } 32 | 33 | function getPackageNameInDirectory(directory) { 34 | var packagePath = path.join(directory.trim(), 'package.json'); 35 | 36 | try { 37 | return require(packagePath).name; 38 | } catch (e) { 39 | return null; 40 | } 41 | } 42 | 43 | function getProcessCommand(processId, processDirectory) { 44 | var command = execSync( 45 | 'ps -o command -p ' + processId + ' | sed -n 2p', 46 | execOptions 47 | ); 48 | 49 | command = command.replace(/\n$/, ''); 50 | 51 | if (isProcessAReactApp(command)) { 52 | const packageName = getPackageNameInDirectory(processDirectory); 53 | return packageName ? packageName : command; 54 | } else { 55 | return command; 56 | } 57 | } 58 | 59 | function getDirectoryOfProcessById(processId) { 60 | return execSync( 61 | 'lsof -p ' + processId + ' | awk \'$4=="cwd" {for (i=9; i<=NF; i++) printf "%s ", $i}\'', 62 | execOptions 63 | ).trim(); 64 | } 65 | 66 | function getProcessForPort(port) { 67 | try { 68 | var processId = getProcessIdOnPort(port); 69 | var directory = getDirectoryOfProcessById(processId); 70 | var command = getProcessCommand(processId, directory); 71 | return ( 72 | chalk.cyan(command) + 73 | chalk.grey(' (pid ' + processId + ')\n') + 74 | chalk.blue(' in ') + 75 | chalk.cyan(directory) 76 | ); 77 | } catch (e) { 78 | return null; 79 | } 80 | } 81 | 82 | module.exports = getProcessForPort; 83 | -------------------------------------------------------------------------------- /packages/react-dev-utils/ignoredFiles.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | const path = require('path'); 11 | const escape = require('escape-string-regexp'); 12 | 13 | module.exports = function ignoredFiles(appSrc) { 14 | return new RegExp( 15 | `^(?!${escape( 16 | path.normalize(appSrc + '/').replace(/[\\]+/g, '/') 17 | )}).+/node_modules/`, 18 | 'g' 19 | ); 20 | }; 21 | -------------------------------------------------------------------------------- /packages/react-dev-utils/inquirer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var inquirer = require('inquirer'); 11 | 12 | module.exports = inquirer; 13 | -------------------------------------------------------------------------------- /packages/react-dev-utils/launchEditorEndpoint.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 'use strict'; 8 | 9 | // TODO: we might want to make this injectable to support DEV-time non-root URLs. 10 | module.exports = '/__open-stack-frame-in-editor'; 11 | -------------------------------------------------------------------------------- /packages/react-dev-utils/noopServiceWorkerMiddleware.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | module.exports = function createNoopServiceWorkerMiddleware() { 11 | return function noopServiceWorkerMiddleware(req, res, next) { 12 | if (req.url === '/service-worker.js') { 13 | res.setHeader('Content-Type', 'text/javascript'); 14 | res.send( 15 | `// This service worker file is effectively a 'no-op' that will reset any 16 | // previous service worker registered for the same host:port combination. 17 | // In the production build, this file is replaced with an actual service worker 18 | // file that will precache your site's local assets. 19 | // See https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432 20 | 21 | self.addEventListener('install', () => self.skipWaiting()); 22 | 23 | self.addEventListener('activate', () => { 24 | self.clients.matchAll({ type: 'window' }).then(windowClients => { 25 | for (let windowClient of windowClients) { 26 | // Force open pages to refresh, so that they have a chance to load the 27 | // fresh navigation response from the local dev server. 28 | windowClient.navigate(windowClient.url); 29 | } 30 | }); 31 | }); 32 | ` 33 | ); 34 | } else { 35 | next(); 36 | } 37 | }; 38 | }; 39 | -------------------------------------------------------------------------------- /packages/react-dev-utils/openChrome.applescript: -------------------------------------------------------------------------------- 1 | (* 2 | Copyright (c) 2015-present, Facebook, Inc. 3 | 4 | This source code is licensed under the MIT license found in the 5 | LICENSE file in the root directory of this source tree. 6 | *) 7 | 8 | property targetTab: null 9 | property targetTabIndex: -1 10 | property targetWindow: null 11 | 12 | on run argv 13 | set theURL to item 1 of argv 14 | 15 | tell application "Chrome" 16 | 17 | if (count every window) = 0 then 18 | make new window 19 | end if 20 | 21 | -- 1: Looking for tab running debugger 22 | -- then, Reload debugging tab if found 23 | -- then return 24 | set found to my lookupTabWithUrl(theURL) 25 | if found then 26 | set targetWindow's active tab index to targetTabIndex 27 | tell targetTab to reload 28 | tell targetWindow to activate 29 | set index of targetWindow to 1 30 | return 31 | end if 32 | 33 | -- 2: Looking for Empty tab 34 | -- In case debugging tab was not found 35 | -- We try to find an empty tab instead 36 | set found to my lookupTabWithUrl("chrome://newtab/") 37 | if found then 38 | set targetWindow's active tab index to targetTabIndex 39 | set URL of targetTab to theURL 40 | tell targetWindow to activate 41 | return 42 | end if 43 | 44 | -- 3: Create new tab 45 | -- both debugging and empty tab were not found 46 | -- make a new tab with url 47 | tell window 1 48 | activate 49 | make new tab with properties {URL:theURL} 50 | end tell 51 | end tell 52 | end run 53 | 54 | -- Function: 55 | -- Lookup tab with given url 56 | -- if found, store tab, index, and window in properties 57 | -- (properties were declared on top of file) 58 | on lookupTabWithUrl(lookupUrl) 59 | tell application "Chrome" 60 | -- Find a tab with the given url 61 | set found to false 62 | set theTabIndex to -1 63 | repeat with theWindow in every window 64 | set theTabIndex to 0 65 | repeat with theTab in every tab of theWindow 66 | set theTabIndex to theTabIndex + 1 67 | if (theTab's URL as string) contains lookupUrl then 68 | -- assign tab, tab index, and window to properties 69 | set targetTab to theTab 70 | set targetTabIndex to theTabIndex 71 | set targetWindow to theWindow 72 | set found to true 73 | exit repeat 74 | end if 75 | end repeat 76 | 77 | if found then 78 | exit repeat 79 | end if 80 | end repeat 81 | end tell 82 | return found 83 | end lookupTabWithUrl 84 | -------------------------------------------------------------------------------- /packages/react-dev-utils/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-dev-utils", 3 | "version": "5.0.2", 4 | "description": "Webpack utilities used by Create React App", 5 | "repository": "facebookincubator/create-react-app", 6 | "license": "MIT", 7 | "bugs": { 8 | "url": "https://github.com/facebookincubator/create-react-app/issues" 9 | }, 10 | "engines": { 11 | "node": ">=6" 12 | }, 13 | "files": [ 14 | "checkRequiredFiles.js", 15 | "clearConsole.js", 16 | "crashOverlay.js", 17 | "crossSpawn.js", 18 | "eslintFormatter.js", 19 | "errorOverlayMiddleware.js", 20 | "FileSizeReporter.js", 21 | "printBuildError.js", 22 | "formatWebpackMessages.js", 23 | "getProcessForPort.js", 24 | "ignoredFiles.js", 25 | "inquirer.js", 26 | "InterpolateHtmlPlugin.js", 27 | "launchEditor.js", 28 | "launchEditorEndpoint.js", 29 | "ModuleScopePlugin.js", 30 | "noopServiceWorkerMiddleware.js", 31 | "openBrowser.js", 32 | "openChrome.applescript", 33 | "printHostingInstructions.js", 34 | "WatchMissingNodeModulesPlugin.js", 35 | "WebpackDevServerUtils.js", 36 | "webpackHotDevClient.js" 37 | ], 38 | "dependencies": { 39 | "address": "1.0.3", 40 | "babel-code-frame": "6.26.0", 41 | "chalk": "1.1.3", 42 | "cross-spawn": "5.1.0", 43 | "detect-port-alt": "1.1.6", 44 | "escape-string-regexp": "1.0.5", 45 | "filesize": "3.5.11", 46 | "global-modules": "1.0.0", 47 | "gzip-size": "3.0.0", 48 | "inquirer": "3.3.0", 49 | "is-root": "1.0.0", 50 | "opn": "5.2.0", 51 | "react-error-overlay": "^4.0.1", 52 | "recursive-readdir": "2.2.1", 53 | "shell-quote": "1.6.1", 54 | "sockjs-client": "1.1.5", 55 | "strip-ansi": "3.0.1", 56 | "text-table": "0.2.0" 57 | }, 58 | "devDependencies": { 59 | "jest": "20.0.4" 60 | }, 61 | "scripts": { 62 | "test": "jest" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /packages/react-dev-utils/printBuildError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | const chalk = require('chalk'); 11 | 12 | module.exports = function printBuildError(err) { 13 | const message = err != null && err.message; 14 | const stack = err != null && err.stack; 15 | 16 | // Add more helpful message for UglifyJs error 17 | if ( 18 | stack && 19 | typeof message === 'string' && 20 | message.indexOf('from UglifyJs') !== -1 21 | ) { 22 | try { 23 | const matched = /(.+)\[(.+):(.+),(.+)\]\[.+\]/.exec(stack); 24 | if (!matched) { 25 | throw new Error('Using errors for control flow is bad.'); 26 | } 27 | const problemPath = matched[2]; 28 | const line = matched[3]; 29 | const column = matched[4]; 30 | console.log( 31 | 'Failed to minify the code from this file: \n\n', 32 | chalk.yellow( 33 | `\t${problemPath}:${line}${column !== '0' ? ':' + column : ''}` 34 | ), 35 | '\n' 36 | ); 37 | } catch (ignored) { 38 | console.log('Failed to minify the bundle.', err); 39 | } 40 | console.log('Read more here: http://bit.ly/2tRViJ9'); 41 | } else { 42 | console.log((message || err) + '\n'); 43 | } 44 | console.log(); 45 | }; 46 | -------------------------------------------------------------------------------- /packages/react-error-overlay/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["react-app"] 3 | } 4 | -------------------------------------------------------------------------------- /packages/react-error-overlay/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "react-app", 3 | "rules": { 4 | "curly": "warn" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/react-error-overlay/.flowconfig: -------------------------------------------------------------------------------- 1 | [include] 2 | /src/**/*.js 3 | 4 | [ignore] 5 | .*/node_modules/.* 6 | .*/.git/.* 7 | .*/__test__/.* 8 | .*/fixtures/.* 9 | 10 | [libs] 11 | flow/ 12 | 13 | [options] 14 | module.file_ext=.js 15 | sharedmemory.hash_table_pow=19 16 | -------------------------------------------------------------------------------- /packages/react-error-overlay/.gitattributes: -------------------------------------------------------------------------------- 1 | *.js text eol=lf 2 | -------------------------------------------------------------------------------- /packages/react-error-overlay/.gitignore: -------------------------------------------------------------------------------- 1 | lib/ 2 | coverage/ 3 | -------------------------------------------------------------------------------- /packages/react-error-overlay/.npmignore: -------------------------------------------------------------------------------- 1 | __tests__ 2 | *.test.js 3 | *.spec.js 4 | -------------------------------------------------------------------------------- /packages/react-error-overlay/README.md: -------------------------------------------------------------------------------- 1 | # `react-error-overlay` 2 | 3 | `react-error-overlay` is an overlay which displays when there is a runtime error. 4 | 5 | ## Development 6 | 7 | When developing within this package, make sure you run `npm start` (or `yarn start`) so that the files are compiled as you work. 8 | This is ran in watch mode by default. 9 | 10 | If you would like to build this for production, run `npm run build:prod` (or `yarn build:prod`).
11 | If you would like to build this one-off for development, you can run `NODE_ENV=development npm run build` (or `NODE_ENV=development yarn build`). 12 | -------------------------------------------------------------------------------- /packages/react-error-overlay/build.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | const webpack = require('webpack'); 8 | const chalk = require('chalk'); 9 | const webpackConfig = require('./webpack.config.js'); 10 | const iframeWebpackConfig = require('./webpack.config.iframe.js'); 11 | const rimraf = require('rimraf'); 12 | const chokidar = require('chokidar'); 13 | 14 | const args = process.argv.slice(2); 15 | const watchMode = args[0] === '--watch' || args[0] === '-w'; 16 | 17 | const isCI = 18 | process.env.CI && 19 | (typeof process.env.CI !== 'string' || 20 | process.env.CI.toLowerCase() !== 'false'); 21 | 22 | function build(config, name, callback) { 23 | console.log(chalk.cyan('Compiling ' + name)); 24 | webpack(config).run((error, stats) => { 25 | if (error) { 26 | console.log(chalk.red('Failed to compile.')); 27 | console.log(error.message || error); 28 | console.log(); 29 | } 30 | 31 | if (stats.compilation.errors.length) { 32 | console.log(chalk.red('Failed to compile.')); 33 | console.log(stats.toString({ all: false, errors: true })); 34 | } 35 | 36 | if (stats.compilation.warnings.length) { 37 | console.log(chalk.yellow('Compiled with warnings.')); 38 | console.log(stats.toString({ all: false, warnings: true })); 39 | } 40 | 41 | // Fail the build if running in a CI server 42 | if ( 43 | error || 44 | stats.compilation.errors.length || 45 | stats.compilation.warnings.length 46 | ) { 47 | isCI && process.exit(1); 48 | return; 49 | } 50 | 51 | console.log( 52 | stats.toString({ colors: true, modules: false, version: false }) 53 | ); 54 | console.log(); 55 | 56 | callback(stats); 57 | }); 58 | } 59 | 60 | function runBuildSteps() { 61 | build(iframeWebpackConfig, 'iframeScript.js', () => { 62 | build(webpackConfig, 'index.js', () => { 63 | console.log(chalk.bold.green('Compiled successfully!\n\n')); 64 | }); 65 | }); 66 | } 67 | 68 | function setupWatch() { 69 | const watcher = chokidar.watch('./src', { 70 | ignoreInitial: true, 71 | }); 72 | 73 | watcher.on('change', runBuildSteps); 74 | watcher.on('add', runBuildSteps); 75 | 76 | watcher.on('ready', () => { 77 | runBuildSteps(); 78 | }); 79 | 80 | process.on('SIGINT', function() { 81 | watcher.close(); 82 | process.exit(0); 83 | }); 84 | 85 | watcher.on('error', error => { 86 | console.error('Watcher failure', error); 87 | process.exit(1); 88 | }); 89 | } 90 | 91 | // Clean up lib folder 92 | rimraf('lib/', () => { 93 | console.log('Cleaned up the lib folder.\n'); 94 | watchMode ? setupWatch() : runBuildSteps(); 95 | }); 96 | -------------------------------------------------------------------------------- /packages/react-error-overlay/fixtures/bundle-default.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "functionName": "App.componentDidMount", 4 | "fileName": "http://localhost:3000/static/js/bundle.js", 5 | "lineNumber": 26122, 6 | "columnNumber": 21, 7 | "_originalFunctionName": "App.componentDidMount", 8 | "_originalFileName": "webpack:///packages/react-scripts/template/src/App.js", 9 | "_originalLineNumber": 7, 10 | "_originalColumnNumber": 0, 11 | "_scriptCode": [ 12 | { 13 | "lineNumber": 26119, 14 | "content": " _createClass(App, [{", 15 | "highlight": false 16 | }, 17 | { 18 | "lineNumber": 26120, 19 | "content": " key: 'componentDidMount',", 20 | "highlight": false 21 | }, 22 | { 23 | "lineNumber": 26121, 24 | "content": " value: function componentDidMount() {", 25 | "highlight": false 26 | }, 27 | { 28 | "lineNumber": 26122, 29 | "content": " document.body.missing();", 30 | "highlight": true 31 | }, 32 | { 33 | "lineNumber": 26123, 34 | "content": " }", 35 | "highlight": false 36 | }, 37 | { 38 | "lineNumber": 26124, 39 | "content": " }, {", 40 | "highlight": false 41 | }, 42 | { 43 | "lineNumber": 26125, 44 | "content": " key: 'render',", 45 | "highlight": false 46 | } 47 | ], 48 | "_originalScriptCode": [ 49 | { 50 | "lineNumber": 4, 51 | "content": "", 52 | "highlight": false 53 | }, 54 | { 55 | "lineNumber": 5, 56 | "content": "class App extends Component {", 57 | "highlight": false 58 | }, 59 | { 60 | "lineNumber": 6, 61 | "content": " componentDidMount() {", 62 | "highlight": false 63 | }, 64 | { 65 | "lineNumber": 7, 66 | "content": " document.body.missing()", 67 | "highlight": true 68 | }, 69 | { 70 | "lineNumber": 8, 71 | "content": " }", 72 | "highlight": false 73 | }, 74 | { 75 | "lineNumber": 9, 76 | "content": "", 77 | "highlight": false 78 | }, 79 | { 80 | "lineNumber": 10, 81 | "content": " render() {", 82 | "highlight": false 83 | } 84 | ] 85 | } 86 | ] 87 | -------------------------------------------------------------------------------- /packages/react-error-overlay/fixtures/inline.es6.mjs: -------------------------------------------------------------------------------- 1 | function foo() { 2 | console.log('bar') 3 | } 4 | 5 | export { foo } 6 | -------------------------------------------------------------------------------- /packages/react-error-overlay/fixtures/inline.mjs: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | function foo() { 7 | console.log('bar'); 8 | } 9 | 10 | exports.foo = foo; 11 | 12 | //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxTQUFTLEdBQVQsR0FBZTtBQUNiLFVBQVEsR0FBUixDQUFZLEtBQVo7QUFDRDs7UUFFUSxHLEdBQUEsRyIsImZpbGUiOiJzdGRvdXQiLCJzb3VyY2VzQ29udGVudCI6WyJmdW5jdGlvbiBmb28oKSB7XG4gIGNvbnNvbGUubG9nKCdiYXInKVxufVxuXG5leHBvcnQgeyBmb28gfVxuIl19 13 | -------------------------------------------------------------------------------- /packages/react-error-overlay/fixtures/junk-inline.mjs: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | function foo() { 7 | console.log('bar'); 8 | } 9 | 10 | exports.foo = foo; 11 | 12 | //# sourceMappingURL=data:application/json;charset=utf-8;base64vlq,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxTQUFTLEdBQVQsR0FBZTtBQUNiLFVBQVEsR0FBUixDQUFZLEtBQVo7QUFDRDs7UUFFUSxHLEdBQUEsRyIsImZpbGUiOiJzdGRvdXQiLCJzb3VyY2VzQ29udGVudCI6WyJmdW5jdGlvbiBmb28oKSB7XG4gIGNvbnNvbGUubG9nKCdiYXInKVxufVxuXG5leHBvcnQgeyBmb28gfVxuIl19 13 | -------------------------------------------------------------------------------- /packages/react-error-overlay/flow/env.js: -------------------------------------------------------------------------------- 1 | declare module 'anser' { 2 | declare module.exports: any; 3 | } 4 | 5 | declare module 'babel-code-frame' { 6 | declare module.exports: any; 7 | } 8 | 9 | declare module 'html-entities' { 10 | declare module.exports: any; 11 | } 12 | 13 | declare module 'settle-promise' { 14 | declare module.exports: any; 15 | } 16 | 17 | declare module 'source-map' { 18 | declare module.exports: any; 19 | } 20 | -------------------------------------------------------------------------------- /packages/react-error-overlay/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-error-overlay", 3 | "version": "4.0.1", 4 | "description": "An overlay for displaying stack frames.", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "prepublishOnly": "npm run build:prod && npm test", 8 | "start": "cross-env NODE_ENV=development node build.js --watch", 9 | "test": "cross-env NODE_ENV=test jest", 10 | "build": "cross-env NODE_ENV=development node build.js", 11 | "build:prod": "cross-env NODE_ENV=production node build.js" 12 | }, 13 | "repository": "facebookincubator/create-react-app", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/facebookincubator/create-react-app/issues" 17 | }, 18 | "keywords": [ 19 | "overlay", 20 | "syntax", 21 | "error", 22 | "red", 23 | "box", 24 | "redbox", 25 | "crash", 26 | "warning" 27 | ], 28 | "author": "Joe Haddad ", 29 | "files": [ 30 | "lib/index.js" 31 | ], 32 | "devDependencies": { 33 | "anser": "1.4.4", 34 | "babel-code-frame": "6.26.0", 35 | "babel-core": "^6.26.0", 36 | "babel-eslint": "7.2.3", 37 | "babel-loader": "^7.1.2", 38 | "babel-preset-react-app": "^3.1.1", 39 | "babel-runtime": "6.26.0", 40 | "chalk": "^2.1.0", 41 | "chokidar": "^1.7.0", 42 | "cross-env": "5.0.5", 43 | "eslint": "4.4.1", 44 | "eslint-config-react-app": "^2.1.0", 45 | "eslint-plugin-flowtype": "2.35.0", 46 | "eslint-plugin-import": "2.7.0", 47 | "eslint-plugin-jsx-a11y": "5.1.1", 48 | "eslint-plugin-react": "7.1.0", 49 | "flow-bin": "^0.63.1", 50 | "html-entities": "1.2.1", 51 | "jest": "20.0.4", 52 | "jest-fetch-mock": "1.2.1", 53 | "object-assign": "4.1.1", 54 | "promise": "8.0.1", 55 | "raw-loader": "^0.5.1", 56 | "react": "^16.0.0", 57 | "react-dom": "^16.0.0", 58 | "rimraf": "^2.6.1", 59 | "settle-promise": "1.0.0", 60 | "source-map": "0.5.6", 61 | "webpack": "^3.6.0" 62 | }, 63 | "jest": { 64 | "setupFiles": [ 65 | "./src/__tests__/setupJest.js" 66 | ], 67 | "collectCoverage": true, 68 | "coverageReporters": [ 69 | "json" 70 | ], 71 | "testMatch": [ 72 | "/src/**/__tests__/**/*.js?(x)", 73 | "/src/**/?(*.)(spec|test).js?(x)" 74 | ], 75 | "testPathIgnorePatterns": [ 76 | "/node_modules/", 77 | "/fixtures/", 78 | "setupJest.js" 79 | ] 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/__snapshots__/lines-around.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`should return lines around from a string 1`] = ` 4 | Array [ 5 | ScriptLine { 6 | "content": "two", 7 | "highlight": false, 8 | "lineNumber": 2, 9 | }, 10 | ScriptLine { 11 | "content": "three", 12 | "highlight": false, 13 | "lineNumber": 3, 14 | }, 15 | ScriptLine { 16 | "content": "four", 17 | "highlight": true, 18 | "lineNumber": 4, 19 | }, 20 | ScriptLine { 21 | "content": "five", 22 | "highlight": false, 23 | "lineNumber": 5, 24 | }, 25 | ScriptLine { 26 | "content": "six", 27 | "highlight": false, 28 | "lineNumber": 6, 29 | }, 30 | ] 31 | `; 32 | 33 | exports[`should return lines around from an array 1`] = ` 34 | Array [ 35 | ScriptLine { 36 | "content": "two", 37 | "highlight": false, 38 | "lineNumber": 2, 39 | }, 40 | ScriptLine { 41 | "content": "three", 42 | "highlight": false, 43 | "lineNumber": 3, 44 | }, 45 | ScriptLine { 46 | "content": "four", 47 | "highlight": true, 48 | "lineNumber": 4, 49 | }, 50 | ScriptLine { 51 | "content": "five", 52 | "highlight": false, 53 | "lineNumber": 5, 54 | }, 55 | ScriptLine { 56 | "content": "six", 57 | "highlight": false, 58 | "lineNumber": 6, 59 | }, 60 | ] 61 | `; 62 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/__snapshots__/script-lines.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`script line shape 1`] = ` 4 | ScriptLine { 5 | "content": "foobar", 6 | "highlight": true, 7 | "lineNumber": 5, 8 | } 9 | `; 10 | 11 | exports[`script line to provide default highlight 1`] = ` 12 | ScriptLine { 13 | "content": "foobar", 14 | "highlight": false, 15 | "lineNumber": 5, 16 | } 17 | `; 18 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/__snapshots__/stack-frame.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`proper empty shape 1`] = ` 4 | StackFrame { 5 | "_originalColumnNumber": null, 6 | "_originalFileName": null, 7 | "_originalFunctionName": null, 8 | "_originalLineNumber": null, 9 | "_originalScriptCode": null, 10 | "_scriptCode": null, 11 | "columnNumber": null, 12 | "fileName": null, 13 | "functionName": null, 14 | "lineNumber": null, 15 | } 16 | `; 17 | 18 | exports[`proper full shape 1`] = ` 19 | StackFrame { 20 | "_originalColumnNumber": 13, 21 | "_originalFileName": "test.js", 22 | "_originalFunctionName": "apple", 23 | "_originalLineNumber": 37, 24 | "_originalScriptCode": null, 25 | "_scriptCode": null, 26 | "columnNumber": 37, 27 | "fileName": "b.js", 28 | "functionName": "a", 29 | "lineNumber": 13, 30 | } 31 | `; 32 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/extract-source-map.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import { extractSourceMapUrl } from '../utils/getSourceMap'; 9 | 10 | test('extracts last source map directive', async () => { 11 | const res = await extractSourceMapUrl( 12 | `test.js`, 13 | `//# sourceMappingURL=test.js.map\nconsole.log('a')\n//# sourceMappingURL=bundle.js.map` 14 | ); 15 | expect(res).toBe('bundle.js.map'); 16 | }); 17 | 18 | test('errors when no source map', async () => { 19 | expect.assertions(1); 20 | 21 | const testFileName = 'test.js'; 22 | try { 23 | await extractSourceMapUrl( 24 | testFileName, 25 | `console.log('hi')\n\nconsole.log('bye')` 26 | ); 27 | } catch (e) { 28 | expect(e).toBe(`Cannot find a source map directive for ${testFileName}.`); 29 | } 30 | }); 31 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/get-source-map.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import { getSourceMap } from '../utils/getSourceMap'; 9 | import fs from 'fs'; 10 | import { resolve } from 'path'; 11 | 12 | test('finds an external source map', async () => { 13 | const file = fs 14 | .readFileSync(resolve(__dirname, '../../fixtures/bundle.mjs')) 15 | .toString('utf8'); 16 | fetch.mockResponseOnce( 17 | fs 18 | .readFileSync(resolve(__dirname, '../../fixtures/bundle.mjs.map')) 19 | .toString('utf8') 20 | ); 21 | 22 | const sm = await getSourceMap('/', file); 23 | expect(sm.getOriginalPosition(26122, 21)).toEqual({ 24 | line: 7, 25 | column: 0, 26 | source: 'webpack:///packages/react-scripts/template/src/App.js', 27 | }); 28 | }); 29 | 30 | test('find an inline source map', async () => { 31 | const sourceName = 'test.js'; 32 | 33 | const file = fs 34 | .readFileSync(resolve(__dirname, '../../fixtures/inline.mjs')) 35 | .toString('utf8'); 36 | const fileO = fs 37 | .readFileSync(resolve(__dirname, '../../fixtures/inline.es6.mjs')) 38 | .toString('utf8'); 39 | 40 | const sm = await getSourceMap('/', file); 41 | expect(sm.getSources()).toEqual([sourceName]); 42 | expect(sm.getSource(sourceName)).toBe(fileO); 43 | expect(sm.getGeneratedPosition(sourceName, 5, 10)).toEqual({ 44 | line: 10, 45 | column: 8, 46 | }); 47 | }); 48 | 49 | test('error on a source map with unsupported encoding', async () => { 50 | expect.assertions(2); 51 | 52 | const file = fs 53 | .readFileSync(resolve(__dirname, '../../fixtures/junk-inline.mjs')) 54 | .toString('utf8'); 55 | try { 56 | await getSourceMap('/', file); 57 | } catch (e) { 58 | expect(e instanceof Error).toBe(true); 59 | expect(e.message).toBe( 60 | 'Sorry, non-base64 inline source-map encoding is not supported.' 61 | ); 62 | } 63 | }); 64 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/lines-around.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import { getLinesAround } from '../utils/getLinesAround'; 9 | 10 | const arr = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight']; 11 | 12 | test('should return lines around from a string', () => { 13 | expect(getLinesAround(4, 2, arr)).toMatchSnapshot(); 14 | }); 15 | 16 | test('should return lines around from an array', () => { 17 | expect(getLinesAround(4, 2, arr.join('\n'))).toMatchSnapshot(); 18 | }); 19 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/parser/__snapshots__/chrome.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`stack with eval 1`] = ` 4 | Array [ 5 | StackFrame { 6 | "_originalColumnNumber": null, 7 | "_originalFileName": null, 8 | "_originalFunctionName": null, 9 | "_originalLineNumber": null, 10 | "_originalScriptCode": null, 11 | "_scriptCode": null, 12 | "columnNumber": 18, 13 | "fileName": "file:///Users/joe/Documents/Development/OSS/stack-frame/index.html", 14 | "functionName": "e", 15 | "lineNumber": 25, 16 | }, 17 | StackFrame { 18 | "_originalColumnNumber": null, 19 | "_originalFileName": null, 20 | "_originalFunctionName": null, 21 | "_originalLineNumber": null, 22 | "_originalScriptCode": null, 23 | "_scriptCode": null, 24 | "columnNumber": 9, 25 | "fileName": "file:///Users/joe/Documents/Development/OSS/stack-frame/index.html", 26 | "functionName": "eval", 27 | "lineNumber": 12, 28 | }, 29 | StackFrame { 30 | "_originalColumnNumber": null, 31 | "_originalFileName": null, 32 | "_originalFunctionName": null, 33 | "_originalLineNumber": null, 34 | "_originalScriptCode": null, 35 | "_scriptCode": null, 36 | "columnNumber": 9, 37 | "fileName": "file:///Users/joe/Documents/Development/OSS/stack-frame/index.html", 38 | "functionName": "a", 39 | "lineNumber": 8, 40 | }, 41 | StackFrame { 42 | "_originalColumnNumber": null, 43 | "_originalFileName": null, 44 | "_originalFunctionName": null, 45 | "_originalLineNumber": null, 46 | "_originalScriptCode": null, 47 | "_scriptCode": null, 48 | "columnNumber": 7, 49 | "fileName": "file:///Users/joe/Documents/Development/OSS/stack-frame/index.html", 50 | "functionName": null, 51 | "lineNumber": 32, 52 | }, 53 | ] 54 | `; 55 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/parser/__snapshots__/react.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`15.y.z 1`] = ` 4 | Array [ 5 | StackFrame { 6 | "_originalColumnNumber": null, 7 | "_originalFileName": null, 8 | "_originalFunctionName": null, 9 | "_originalLineNumber": null, 10 | "_originalScriptCode": null, 11 | "_scriptCode": null, 12 | "columnNumber": null, 13 | "fileName": "FileA.js", 14 | "functionName": "div", 15 | "lineNumber": 9, 16 | }, 17 | StackFrame { 18 | "_originalColumnNumber": null, 19 | "_originalFileName": null, 20 | "_originalFunctionName": null, 21 | "_originalLineNumber": null, 22 | "_originalScriptCode": null, 23 | "_scriptCode": null, 24 | "columnNumber": null, 25 | "fileName": "App.js", 26 | "functionName": "FileA", 27 | "lineNumber": 9, 28 | }, 29 | StackFrame { 30 | "_originalColumnNumber": null, 31 | "_originalFileName": null, 32 | "_originalFunctionName": null, 33 | "_originalLineNumber": null, 34 | "_originalScriptCode": null, 35 | "_scriptCode": null, 36 | "columnNumber": null, 37 | "fileName": "App.js", 38 | "functionName": "div", 39 | "lineNumber": 8, 40 | }, 41 | StackFrame { 42 | "_originalColumnNumber": null, 43 | "_originalFileName": null, 44 | "_originalFunctionName": null, 45 | "_originalLineNumber": null, 46 | "_originalScriptCode": null, 47 | "_scriptCode": null, 48 | "columnNumber": null, 49 | "fileName": "index.js", 50 | "functionName": "App", 51 | "lineNumber": 7, 52 | }, 53 | ] 54 | `; 55 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/parser/__snapshots__/safari.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`stack with eval 1`] = ` 4 | Array [ 5 | StackFrame { 6 | "_originalColumnNumber": null, 7 | "_originalFileName": null, 8 | "_originalFunctionName": null, 9 | "_originalLineNumber": null, 10 | "_originalScriptCode": null, 11 | "_scriptCode": null, 12 | "columnNumber": 18, 13 | "fileName": "file:///Users/joe/Documents/Development/OSS/stack-frame/index.html", 14 | "functionName": "e", 15 | "lineNumber": 25, 16 | }, 17 | StackFrame { 18 | "_originalColumnNumber": null, 19 | "_originalFileName": null, 20 | "_originalFunctionName": null, 21 | "_originalLineNumber": null, 22 | "_originalScriptCode": null, 23 | "_scriptCode": null, 24 | "columnNumber": 10, 25 | "fileName": "file:///Users/joe/Documents/Development/OSS/stack-frame/index.html", 26 | "functionName": "a", 27 | "lineNumber": 8, 28 | }, 29 | StackFrame { 30 | "_originalColumnNumber": null, 31 | "_originalFileName": null, 32 | "_originalFunctionName": null, 33 | "_originalLineNumber": null, 34 | "_originalScriptCode": null, 35 | "_scriptCode": null, 36 | "columnNumber": 8, 37 | "fileName": "file:///Users/joe/Documents/Development/OSS/stack-frame/index.html", 38 | "functionName": "global code", 39 | "lineNumber": 32, 40 | }, 41 | ] 42 | `; 43 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/parser/chrome.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import { parse } from '../../utils/parser'; 9 | 10 | test('stack with eval', () => { 11 | expect( 12 | parse( 13 | `TypeError: window[f] is not a function 14 | at e (file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:25:18) 15 | at eval (eval at c (file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:12:9), :1:1) 16 | at a (file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:8:9) 17 | at file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:32:7` 18 | ) 19 | ).toMatchSnapshot(); 20 | }); 21 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/parser/firefox.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import { parse } from '../../utils/parser'; 9 | 10 | test('eval 1', () => { 11 | expect( 12 | parse( 13 | `test1@file:///C:/example.html line 7 > eval line 1 > eval:1:1 14 | test2@file:///C:/example.html line 7 > eval:1:1 15 | test3@file:///C:/example.html:7:6`.split('\n') 16 | ) 17 | ).toMatchSnapshot(); 18 | }); 19 | 20 | test('eval 2', () => { 21 | expect( 22 | parse({ 23 | stack: `anonymous@file:///C:/example.html line 7 > Function:1:1 24 | @file:///C:/example.html:7:6`, 25 | }) 26 | ).toMatchSnapshot(); 27 | }); 28 | 29 | test('stack with eval', () => { 30 | expect( 31 | parse( 32 | `e@file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:25:9 33 | @file:///Users/joe/Documents/Development/OSS/stack-frame/index.html line 17 > eval:1:1 34 | a@file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:8:9 35 | @file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:32:7` 36 | ) 37 | ).toMatchSnapshot(); 38 | }); 39 | 40 | test('v14 to v29', () => { 41 | expect( 42 | parse( 43 | `trace@file:///C:/example.html:9 44 | b@file:///C:/example.html:16 45 | a@file:///C:/example.html:19 46 | @file:///C:/example.html:21` 47 | ) 48 | ).toMatchSnapshot(); 49 | }); 50 | 51 | test('v30+', () => { 52 | expect( 53 | parse( 54 | `trace@file:///C:/example.html:9:17 55 | b@file:///C:/example.html:16:13 56 | a@file:///C:/example.html:19:13 57 | @file:///C:/example.html:21:9` 58 | ) 59 | ).toMatchSnapshot(); 60 | }); 61 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/parser/generic.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import { parse } from '../../utils/parser'; 9 | 10 | test('throws on null', () => { 11 | expect.assertions(2); 12 | try { 13 | parse(null); 14 | } catch (e) { 15 | expect(e instanceof Error).toBe(true); 16 | expect(e.message).toBe('You cannot pass a null object.'); 17 | } 18 | }); 19 | 20 | test('throws on unparsable', () => { 21 | expect.assertions(2); 22 | try { 23 | parse({}); 24 | } catch (e) { 25 | expect(e instanceof Error).toBe(true); 26 | expect(e.message).toBe( 27 | 'The error you provided does not contain a stack trace.' 28 | ); 29 | } 30 | }); 31 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/parser/react.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import { parse } from '../../utils/parser'; 9 | 10 | test('15.y.z', () => { 11 | expect( 12 | parse( 13 | `Warning: Each child in array should have a unique "key" prop. Check render method of \`FileA\`. 14 | in div (at FileA.js:9) 15 | in FileA (at App.js:9) 16 | in div (at App.js:8) 17 | in App (at index.js:7)` 18 | ) 19 | ).toMatchSnapshot(); 20 | }); 21 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/parser/safari.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import { parse } from '../../utils/parser'; 9 | 10 | test('stack with eval', () => { 11 | expect( 12 | parse( 13 | `e@file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:25:18 14 | eval code 15 | eval@[native code] 16 | a@file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:8:10 17 | global code@file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:32:8` 18 | ) 19 | ).toMatchSnapshot(); 20 | }); 21 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/script-lines.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import { ScriptLine } from '../utils/stack-frame'; 9 | 10 | test('script line shape', () => { 11 | expect(new ScriptLine(5, 'foobar', true)).toMatchSnapshot(); 12 | }); 13 | 14 | test('script line to provide default highlight', () => { 15 | expect(new ScriptLine(5, 'foobar')).toMatchSnapshot(); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/setupJest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | global.fetch = require('jest-fetch-mock'); 9 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/stack-frame.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import { StackFrame } from '../utils/stack-frame'; 9 | 10 | test('proper empty shape', () => { 11 | const empty = new StackFrame(); 12 | expect(empty).toMatchSnapshot(); 13 | 14 | expect(empty.getFunctionName()).toBe('(anonymous function)'); 15 | expect(empty.getSource()).toBe(''); 16 | expect(empty.toString()).toBe('(anonymous function)'); 17 | }); 18 | 19 | test('proper full shape', () => { 20 | const empty = new StackFrame( 21 | 'a', 22 | 'b.js', 23 | 13, 24 | 37, 25 | undefined, 26 | 'apple', 27 | 'test.js', 28 | 37, 29 | 13 30 | ); 31 | expect(empty).toMatchSnapshot(); 32 | 33 | expect(empty.getFunctionName()).toBe('a'); 34 | expect(empty.getSource()).toBe('b.js:13:37'); 35 | expect(empty.toString()).toBe('a (b.js:13:37)'); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/__tests__/unmapper.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import { unmap } from '../utils/unmapper'; 9 | import { parse } from '../utils/parser'; 10 | import fs from 'fs'; 11 | import { resolve } from 'path'; 12 | 13 | test('basic warning', async () => { 14 | expect.assertions(2); 15 | const error = `Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of \`B\`. See https://fb.me/react-warning-keys for more information. 16 | in div (at B.js:8) 17 | in B (at A.js:6) 18 | in A (at App.js:8) 19 | in div (at App.js:10) 20 | in App (at index.js:6)`; 21 | 22 | fetch.mockResponseOnce( 23 | fs 24 | .readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs')) 25 | .toString('utf8') 26 | ); 27 | fetch.mockResponseOnce( 28 | fs 29 | .readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs.map')) 30 | .toString('utf8') 31 | ); 32 | const frames = await unmap('/static/js/bundle.js', parse(error), 0); 33 | 34 | const expected = JSON.parse( 35 | fs 36 | .readFileSync(resolve(__dirname, '../../fixtures/bundle2.json')) 37 | .toString('utf8') 38 | ); 39 | expect(frames).toEqual(expected); 40 | 41 | fetch.mockResponseOnce( 42 | fs 43 | .readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs')) 44 | .toString('utf8') 45 | ); 46 | fetch.mockResponseOnce( 47 | fs 48 | .readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs.map')) 49 | .toString('utf8') 50 | ); 51 | expect(await unmap('/static/js/bundle.js', expected)).toEqual(expected); 52 | }); 53 | 54 | test('default context & unfound source', async () => { 55 | expect.assertions(1); 56 | const error = `Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of \`B\`. See https://fb.me/react-warning-keys for more information. 57 | in div (at B.js:8) 58 | in unknown (at blabla.js:10)`; 59 | 60 | fetch.mockResponseOnce( 61 | fs 62 | .readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs')) 63 | .toString('utf8') 64 | ); 65 | fetch.mockResponseOnce( 66 | fs 67 | .readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs.map')) 68 | .toString('utf8') 69 | ); 70 | const frames = await unmap('/static/js/bundle.js', parse(error)); 71 | expect(frames).toMatchSnapshot(); 72 | }); 73 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/components/CloseButton.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | /* @flow */ 9 | import React from 'react'; 10 | import { black } from '../styles'; 11 | 12 | const closeButtonStyle = { 13 | color: black, 14 | lineHeight: '1rem', 15 | fontSize: '1.5rem', 16 | padding: '1rem', 17 | cursor: 'pointer', 18 | position: 'absolute', 19 | right: 0, 20 | top: 0, 21 | }; 22 | 23 | type CloseCallback = () => void; 24 | function CloseButton({ close }: {| close: CloseCallback |}) { 25 | return ( 26 | 31 | × 32 | 33 | ); 34 | } 35 | 36 | export default CloseButton; 37 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/components/CodeBlock.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | /* @flow */ 9 | import React from 'react'; 10 | import { redTransparent, yellowTransparent } from '../styles'; 11 | 12 | const _preStyle = { 13 | display: 'block', 14 | padding: '0.5em', 15 | marginTop: '0.5em', 16 | marginBottom: '0.5em', 17 | overflowX: 'auto', 18 | whiteSpace: 'pre-wrap', 19 | borderRadius: '0.25rem', 20 | }; 21 | 22 | const primaryPreStyle = { 23 | ..._preStyle, 24 | backgroundColor: redTransparent, 25 | }; 26 | 27 | const secondaryPreStyle = { 28 | ..._preStyle, 29 | backgroundColor: yellowTransparent, 30 | }; 31 | 32 | const codeStyle = { 33 | fontFamily: 'Consolas, Menlo, monospace', 34 | }; 35 | 36 | type CodeBlockPropsType = {| 37 | main: boolean, 38 | codeHTML: string, 39 | |}; 40 | 41 | function CodeBlock(props: CodeBlockPropsType) { 42 | const preStyle = props.main ? primaryPreStyle : secondaryPreStyle; 43 | const codeBlock = { __html: props.codeHTML }; 44 | 45 | return ( 46 |
47 |       
48 |     
49 | ); 50 | } 51 | 52 | export default CodeBlock; 53 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/components/Collapsible.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | /* @flow */ 9 | import React, { Component } from 'react'; 10 | import { black } from '../styles'; 11 | 12 | import type { Element as ReactElement } from 'react'; 13 | 14 | const _collapsibleStyle = { 15 | color: black, 16 | cursor: 'pointer', 17 | border: 'none', 18 | display: 'block', 19 | width: '100%', 20 | textAlign: 'left', 21 | background: '#fff', 22 | fontFamily: 'Consolas, Menlo, monospace', 23 | fontSize: '1em', 24 | padding: '0px', 25 | lineHeight: '1.5', 26 | }; 27 | 28 | const collapsibleCollapsedStyle = { 29 | ..._collapsibleStyle, 30 | marginBottom: '1.5em', 31 | }; 32 | 33 | const collapsibleExpandedStyle = { 34 | ..._collapsibleStyle, 35 | marginBottom: '0.6em', 36 | }; 37 | 38 | type Props = {| 39 | children: ReactElement[], 40 | |}; 41 | 42 | type State = {| 43 | collapsed: boolean, 44 | |}; 45 | 46 | class Collapsible extends Component { 47 | state = { 48 | collapsed: true, 49 | }; 50 | 51 | toggleCollaped = () => { 52 | this.setState(state => ({ 53 | collapsed: !state.collapsed, 54 | })); 55 | }; 56 | 57 | render() { 58 | const count = this.props.children.length; 59 | const collapsed = this.state.collapsed; 60 | return ( 61 |
62 | 72 |
73 | {this.props.children} 74 | 80 |
81 |
82 | ); 83 | } 84 | } 85 | 86 | export default Collapsible; 87 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/components/ErrorOverlay.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | /* @flow */ 9 | import React, { Component } from 'react'; 10 | import { black } from '../styles'; 11 | 12 | import type { Node as ReactNode } from 'react'; 13 | 14 | const overlayStyle = { 15 | position: 'relative', 16 | display: 'inline-flex', 17 | flexDirection: 'column', 18 | height: '100%', 19 | width: '1024px', 20 | maxWidth: '100%', 21 | overflowX: 'hidden', 22 | overflowY: 'auto', 23 | padding: '0.5rem', 24 | boxSizing: 'border-box', 25 | textAlign: 'left', 26 | fontFamily: 'Consolas, Menlo, monospace', 27 | fontSize: '11px', 28 | whiteSpace: 'pre-wrap', 29 | wordBreak: 'break-word', 30 | lineHeight: 1.5, 31 | color: black, 32 | }; 33 | 34 | type Props = {| 35 | children: ReactNode, 36 | shortcutHandler?: (eventKey: string) => void, 37 | |}; 38 | 39 | type State = {| 40 | collapsed: boolean, 41 | |}; 42 | 43 | class ErrorOverlay extends Component { 44 | iframeWindow: window = null; 45 | 46 | getIframeWindow = (element: ?HTMLDivElement) => { 47 | if (element) { 48 | const document = element.ownerDocument; 49 | this.iframeWindow = document.defaultView; 50 | } 51 | }; 52 | 53 | onKeyDown = (e: KeyboardEvent) => { 54 | const { shortcutHandler } = this.props; 55 | if (shortcutHandler) { 56 | shortcutHandler(e.key); 57 | } 58 | }; 59 | 60 | componentDidMount() { 61 | window.addEventListener('keydown', this.onKeyDown); 62 | if (this.iframeWindow) { 63 | this.iframeWindow.addEventListener('keydown', this.onKeyDown); 64 | } 65 | } 66 | 67 | componentWillUnmount() { 68 | window.removeEventListener('keydown', this.onKeyDown); 69 | if (this.iframeWindow) { 70 | this.iframeWindow.removeEventListener('keydown', this.onKeyDown); 71 | } 72 | } 73 | 74 | render() { 75 | return ( 76 |
77 | {this.props.children} 78 |
79 | ); 80 | } 81 | } 82 | 83 | export default ErrorOverlay; 84 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/components/Footer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | /* @flow */ 9 | import React from 'react'; 10 | import { darkGray } from '../styles'; 11 | 12 | const footerStyle = { 13 | fontFamily: 'sans-serif', 14 | color: darkGray, 15 | marginTop: '0.5rem', 16 | flex: '0 0 auto', 17 | }; 18 | 19 | type FooterPropsType = {| 20 | line1: string, 21 | line2?: string, 22 | |}; 23 | 24 | function Footer(props: FooterPropsType) { 25 | return ( 26 |
27 | {props.line1} 28 |
29 | {props.line2} 30 |
31 | ); 32 | } 33 | 34 | export default Footer; 35 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/components/Header.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | /* @flow */ 9 | import React from 'react'; 10 | import { red } from '../styles'; 11 | 12 | const headerStyle = { 13 | fontSize: '2em', 14 | fontFamily: 'sans-serif', 15 | color: red, 16 | whiteSpace: 'pre-wrap', 17 | // Top bottom margin spaces header 18 | // Right margin revents overlap with close button 19 | margin: '0 2rem 0.75rem 0', 20 | flex: '0 0 auto', 21 | maxHeight: '50%', 22 | overflow: 'auto', 23 | }; 24 | 25 | type HeaderPropType = {| 26 | headerText: string, 27 | |}; 28 | 29 | function Header(props: HeaderPropType) { 30 | return
{props.headerText}
; 31 | } 32 | 33 | export default Header; 34 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/components/NavigationBar.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | /* @flow */ 9 | import React from 'react'; 10 | import { red, redTransparent } from '../styles'; 11 | 12 | const navigationBarStyle = { 13 | marginBottom: '0.5rem', 14 | }; 15 | 16 | const buttonContainerStyle = { 17 | marginRight: '1em', 18 | }; 19 | 20 | const _navButtonStyle = { 21 | backgroundColor: redTransparent, 22 | color: red, 23 | border: 'none', 24 | borderRadius: '4px', 25 | padding: '3px 6px', 26 | cursor: 'pointer', 27 | }; 28 | 29 | const leftButtonStyle = { 30 | ..._navButtonStyle, 31 | borderTopRightRadius: '0px', 32 | borderBottomRightRadius: '0px', 33 | marginRight: '1px', 34 | }; 35 | 36 | const rightButtonStyle = { 37 | ..._navButtonStyle, 38 | borderTopLeftRadius: '0px', 39 | borderBottomLeftRadius: '0px', 40 | }; 41 | 42 | type Callback = () => void; 43 | 44 | type NavigationBarPropsType = {| 45 | currentError: number, 46 | totalErrors: number, 47 | previous: Callback, 48 | next: Callback, 49 | |}; 50 | 51 | function NavigationBar(props: NavigationBarPropsType) { 52 | const { currentError, totalErrors, previous, next } = props; 53 | return ( 54 |
55 | 56 | 59 | 62 | 63 | {`${currentError} of ${totalErrors} errors on the page`} 64 |
65 | ); 66 | } 67 | 68 | export default NavigationBar; 69 | -------------------------------------------------------------------------------- /packages/react-error-overlay/src/containers/CompileErrorContainer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | /* @flow */ 9 | import React, { PureComponent } from 'react'; 10 | import ErrorOverlay from '../components/ErrorOverlay'; 11 | import Footer from '../components/Footer'; 12 | import Header from '../components/Header'; 13 | import CodeBlock from '../components/CodeBlock'; 14 | import generateAnsiHTML from '../utils/generateAnsiHTML'; 15 | import parseCompileError from '../utils/parseCompileError'; 16 | import type { ErrorLocation } from '../utils/parseCompileError'; 17 | 18 | const codeAnchorStyle = { 19 | cursor: 'pointer', 20 | }; 21 | 22 | type Props = {| 23 | error: string, 24 | editorHandler: (errorLoc: ErrorLocation) => void, 25 | |}; 26 | 27 | class CompileErrorContainer extends PureComponent { 28 | render() { 29 | const { error, editorHandler } = this.props; 30 | const errLoc: ?ErrorLocation = parseCompileError(error); 31 | const canOpenInEditor = errLoc !== null && editorHandler !== null; 32 | return ( 33 | 34 |
35 | editorHandler(errLoc) : null 38 | } 39 | style={canOpenInEditor ? codeAnchorStyle : null} 40 | > 41 | 42 | 43 |