diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index 61bcecfa3af9cc424d11c6e2ea939f9772ad5ff5..85e22212ed73b38865eb6aba949a8d047de46306 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -21,13 +21,12 @@ const envPublicUrl = process.env.PUBLIC_URL; function ensureSlash(inputPath, needsSlash) { const hasSlash = inputPath.endsWith('/'); - if (hasSlash && !needsSlash) { - return inputPath.substr(0, inputPath.length - 1); - } else if (!hasSlash && needsSlash) { - return `${inputPath}/`; - } else { - return inputPath; - } + + return hasSlash && !needsSlash + ? inputPath.slice(0, -1) + : !hasSlash && needsSlash + ? `${inputPath}/` + : inputPath; } const getPublicUrl = appPackageJson => diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index 2561ade86ddfb8bb34894fa652f84d2de7222e2b..ff3bcbf034f6fa3b7fcf608b8ac8d1f35e7debab 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -110,7 +110,7 @@ module.exports = { // There are also additional JS chunk files if you use code splitting. chunkFilename: 'static/js/[name].chunk.js', // This is the URL that app is served from. We use "/" in development. - publicPath: publicPath, + publicPath, // Point sourcemap entries to original disk location (format as URL on Windows) devtoolModuleFilenameTemplate: info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'), @@ -432,7 +432,7 @@ module.exports = { // having to parse `index.html`. new ManifestPlugin({ fileName: 'asset-manifest.json', - publicPath: publicPath, + publicPath, }), ], diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index a45cec6a0fdd18c05e02517cbd99fad40502539f..4d8a9069987087bba6a0c5345b5312b653163e69 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -57,10 +57,7 @@ const getStyleLoaders = (cssOptions, preProcessor) => { const loaders = [ { loader: MiniCssExtractPlugin.loader, - options: Object.assign( - {}, - shouldUseRelativeAssetPaths ? { publicPath: '../../' } : undefined - ), + options: shouldUseRelativeAssetPaths ? { publicPath: '../../' } : {}, }, { loader: require.resolve('css-loader'), @@ -120,7 +117,7 @@ module.exports = { filename: 'static/js/[name].[chunkhash:8].js', chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js', // We inferred the "public path" (such as / or /my-project) from homepage. - publicPath: publicPath, + publicPath, // Point sourcemap entries to original disk location (format as URL on Windows) devtoolModuleFilenameTemplate: info => path @@ -507,7 +504,7 @@ module.exports = { // having to parse `index.html`. new ManifestPlugin({ fileName: 'asset-manifest.json', - publicPath: publicPath, + publicPath, }), // Moment.js is an extremely popular library that bundles large locale files // by default due to how Webpack interprets its code. This is a practical diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index 4ebf9f609a13fc62bd805be74b5fbd23c508fe50..1eaf9f9a3f6dce52906f91bc2b21f306942f9e80 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -42,9 +42,11 @@ const printHostingInstructions = require('react-dev-utils/printHostingInstructio const FileSizeReporter = require('react-dev-utils/FileSizeReporter'); const printBuildError = require('react-dev-utils/printBuildError'); -const measureFileSizesBeforeBuild = - FileSizeReporter.measureFileSizesBeforeBuild; -const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild; +const { + measureFileSizesBeforeBuild, + printFileSizesAfterBuild, +} = FileSizeReporter; + const useYarn = fs.existsSync(paths.yarnLockFile); // These sizes are pretty large. We'll warn for bundles exceeding them. @@ -110,8 +112,8 @@ checkBrowsers(paths.appPath, isInteractive) console.log(); const appPackage = require(paths.appPackageJson); - const publicUrl = paths.publicUrl; - const publicPath = config.output.publicPath; + const { publicUrl } = paths; + const { publicPath } = config.output; const buildFolder = path.relative(process.cwd(), paths.appBuild); printHostingInstructions( appPackage, @@ -138,7 +140,7 @@ checkBrowsers(paths.appPath, isInteractive) function build(previousFileSizes) { console.log('Creating an optimized production build...'); - let compiler = webpack(config); + const compiler = webpack(config); return new Promise((resolve, reject) => { compiler.run((err, stats) => { if (err) { @@ -182,7 +184,7 @@ function build(previousFileSizes) { .catch(error => reject(new Error(error))); } - return resolve(resolveArgs); + resolve(resolveArgs); }); }); } diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index 84353fc3c81d802ff9ce4f8dcb4a8c78f590f25f..edd43c2476bd81a1cd3a86813b2fecba8a2f80b2 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -16,7 +16,7 @@ process.on('unhandledRejection', err => { const fs = require('fs-extra'); const path = require('path'); -const execSync = require('child_process').execSync; +const { execSync } = require('child_process'); const chalk = require('chalk'); const paths = require('../config/paths'); const createJestConfig = require('./utils/createJestConfig'); @@ -24,12 +24,11 @@ const inquirer = require('react-dev-utils/inquirer'); const spawnSync = require('react-dev-utils/crossSpawn').sync; const os = require('os'); -const green = chalk.green; -const cyan = chalk.cyan; +const { green, cyan } = chalk; function getGitStatus() { try { - let stdout = execSync(`git status --porcelain`, { + const stdout = execSync(`git status --porcelain`, { stdio: ['pipe', 'pipe', 'ignore'], }).toString(); return stdout.trim(); @@ -72,8 +71,7 @@ inquirer console.log('Ejecting...'); - const ownPath = paths.ownPath; - const appPath = paths.appPath; + const { ownPath, appPath } = paths; function verifyAbsent(file) { if (fs.existsSync(path.join(appPath, file))) { diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index 2904ae70cfea8a86b9b0e0f2303eb3a6b78f41ae..15d55a59e00978c13500223d5d9a838501673973 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -17,7 +17,7 @@ process.on('unhandledRejection', err => { const fs = require('fs-extra'); const path = require('path'); const chalk = require('chalk'); -const execSync = require('child_process').execSync; +const { execSync } = require('child_process'); const spawn = require('react-dev-utils/crossSpawn'); const { defaultBrowsers } = require('react-dev-utils/browsersHelper'); const os = require('os'); @@ -74,13 +74,7 @@ function tryGitInit(appPath) { } } -module.exports = function( - appPath, - appName, - verbose, - originalDirectory, - template -) { +module.exports = (appPath, appName, verbose, originalDirectory, template) => { const ownPackageName = require(path.join(__dirname, '..', 'package.json')) .name; const ownPath = path.join(appPath, 'node_modules', ownPackageName); @@ -200,12 +194,10 @@ module.exports = function( // Display the most elegant way to cd. // This needs to handle an undefined originalDirectory for // backward compatibility with old global-cli's. - let cdpath; - if (originalDirectory && path.join(originalDirectory, appName) === appPath) { - cdpath = appName; - } else { - cdpath = appPath; - } + const cdpath = + originalDirectory && path.join(originalDirectory, appName) === appPath + ? appName + : appPath; // Change displayed command to yarn instead of yarnpkg const displayedCommand = useYarn ? 'yarn' : 'npm'; @@ -251,9 +243,7 @@ module.exports = function( console.log('Happy hacking!'); }; -function isReactInstalled(appPackage) { - const dependencies = appPackage.dependencies || {}; - +function isReactInstalled({ dependencies = {} }) { return ( typeof dependencies.react !== 'undefined' && typeof dependencies['react-dom'] !== 'undefined' diff --git a/packages/react-scripts/scripts/start.js b/packages/react-scripts/scripts/start.js index db04d758efa4aecfbe49340689d5cde488f559d7..d356b3f1114f944c01782875e89596e32d1a6422 100644 --- a/packages/react-scripts/scripts/start.js +++ b/packages/react-scripts/scripts/start.js @@ -115,8 +115,8 @@ checkBrowsers(paths.appPath, isInteractive) openBrowser(urls.localUrlForBrowser); }); - ['SIGINT', 'SIGTERM'].forEach(function(sig) { - process.on(sig, function() { + ['SIGINT', 'SIGTERM'].forEach(sig => { + process.on(sig, () => { devServer.close(); process.exit(); }); diff --git a/packages/react-scripts/scripts/test.js b/packages/react-scripts/scripts/test.js index 0606549fb344027c125595ba7a6be01ba2d71374..6bdce97956d8905d3239be08eb4cafa88df8e923 100644 --- a/packages/react-scripts/scripts/test.js +++ b/packages/react-scripts/scripts/test.js @@ -82,7 +82,7 @@ function resolveJestDefaultEnvironment(name) { basedir: jestConfigDir, }); } -let cleanArgv = []; +const cleanArgv = []; let env = 'jsdom'; let next; do {