diff --git a/packages/cli/src/__mocks__/fs.js b/packages/cli/src/__mocks__/fs.js index a449fb685..53c88175d 100644 --- a/packages/cli/src/__mocks__/fs.js +++ b/packages/cli/src/__mocks__/fs.js @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -const path = require('path'); -const MemoryFS = require('metro-memory-fs'); +import path from 'path'; +import MemoryFS from 'metro-memory-fs'; let fs; diff --git a/packages/cli/src/bin.js b/packages/cli/src/bin.js index 8e9ff5b4e..eed6ab22d 100755 --- a/packages/cli/src/bin.js +++ b/packages/cli/src/bin.js @@ -9,9 +9,9 @@ * @format */ -const chalk = require('chalk'); -const isInstalledGlobally = require('./util/isInstalledGlobally'); -const logger = require('./util/logger'); +import chalk from 'chalk'; +import isInstalledGlobally from './util/isInstalledGlobally'; +import logger from './util/logger'; if (isInstalledGlobally()) { logger.error( diff --git a/packages/cli/src/bundle/assetPathUtils.js b/packages/cli/src/bundle/assetPathUtils.js index 24aa8344f..7778684de 100644 --- a/packages/cli/src/bundle/assetPathUtils.js +++ b/packages/cli/src/bundle/assetPathUtils.js @@ -81,7 +81,7 @@ function getBasePath(asset: PackagerAsset) { return basePath; } -module.exports = { +export default { getAndroidAssetSuffix, getAndroidResourceFolderName, getAndroidResourceIdentifier, diff --git a/packages/cli/src/bundle/buildBundle.js b/packages/cli/src/bundle/buildBundle.js index 2fba0839e..556dab739 100644 --- a/packages/cli/src/bundle/buildBundle.js +++ b/packages/cli/src/bundle/buildBundle.js @@ -7,16 +7,15 @@ * @flow */ -import type { ContextT } from '../core/types.flow'; -import type { CommandLineArgs } from './bundleCommandLineArgs'; - -const Server = require('metro/src/Server'); +import Server from 'metro/src/Server'; -const outputBundle = require('metro/src/shared/output/bundle'); -const path = require('path'); -const saveAssets = require('./saveAssets'); -const loadMetroConfig = require('../util/loadMetroConfig'); -const logger = require('../util/logger'); +import outputBundle from 'metro/src/shared/output/bundle'; +import path from 'path'; +import type { CommandLineArgs } from './bundleCommandLineArgs'; +import type { ContextT } from '../core/types.flow'; +import saveAssets from './saveAssets'; +import loadMetroConfig from '../util/loadMetroConfig'; +import logger from '../util/logger'; async function buildBundle( args: CommandLineArgs, diff --git a/packages/cli/src/bundle/bundle.js b/packages/cli/src/bundle/bundle.js index f0642598e..e933f5654 100644 --- a/packages/cli/src/bundle/bundle.js +++ b/packages/cli/src/bundle/bundle.js @@ -7,8 +7,8 @@ * @format */ -const buildBundle = require('./buildBundle'); -const bundleCommandLineArgs = require('./bundleCommandLineArgs'); +import buildBundle from './buildBundle'; +import bundleCommandLineArgs from './bundleCommandLineArgs'; /** * Builds the bundle starting to look for dependencies at the given entry path. @@ -25,3 +25,7 @@ module.exports = { // Used by `ramBundle.js` withOutput: bundleWithOutput, }; + +const withOutput = bundleWithOutput; + +export { withOutput }; diff --git a/packages/cli/src/bundle/bundleCommandLineArgs.js b/packages/cli/src/bundle/bundleCommandLineArgs.js index 55dcf0be8..68b667849 100644 --- a/packages/cli/src/bundle/bundleCommandLineArgs.js +++ b/packages/cli/src/bundle/bundleCommandLineArgs.js @@ -7,7 +7,7 @@ * @flow */ -const path = require('path'); +import path from 'path'; export type CommandLineArgs = { assetsDest?: string, diff --git a/packages/cli/src/bundle/getAssetDestPathAndroid.js b/packages/cli/src/bundle/getAssetDestPathAndroid.js index ff7576dfa..98d06a183 100644 --- a/packages/cli/src/bundle/getAssetDestPathAndroid.js +++ b/packages/cli/src/bundle/getAssetDestPathAndroid.js @@ -8,10 +8,10 @@ * @flow strict */ +import path from 'path'; import type { PackagerAsset } from './assetPathUtils'; -const path = require('path'); -const assetPathUtils = require('./assetPathUtils'); +import assetPathUtils from './assetPathUtils'; function getAssetDestPathAndroid(asset: PackagerAsset, scale: number): string { const androidFolder = assetPathUtils.getAndroidResourceFolderName( diff --git a/packages/cli/src/bundle/getAssetDestPathIOS.js b/packages/cli/src/bundle/getAssetDestPathIOS.js index 3978b8a97..7b414602d 100644 --- a/packages/cli/src/bundle/getAssetDestPathIOS.js +++ b/packages/cli/src/bundle/getAssetDestPathIOS.js @@ -8,10 +8,9 @@ * @flow strict */ +import path from 'path'; import type { PackagerAsset } from './assetPathUtils'; -const path = require('path'); - function getAssetDestPathIOS(asset: PackagerAsset, scale: number): string { const suffix = scale === 1 ? '' : `@${scale}x`; const fileName = `${asset.name + suffix}.${asset.type}`; diff --git a/packages/cli/src/bundle/ramBundle.js b/packages/cli/src/bundle/ramBundle.js index 1697bfa30..ee0aa547b 100644 --- a/packages/cli/src/bundle/ramBundle.js +++ b/packages/cli/src/bundle/ramBundle.js @@ -6,10 +6,10 @@ * * @format */ -const outputUnbundle = require('metro/src/shared/output/RamBundle'); +import outputUnbundle from 'metro/src/shared/output/RamBundle'; -const bundleWithOutput = require('./bundle').withOutput; -const bundleCommandLineArgs = require('./bundleCommandLineArgs'); +import { withOutput as bundleWithOutput } from './bundle'; +import bundleCommandLineArgs from './bundleCommandLineArgs'; /** * Builds the bundle starting to look for dependencies at the given entry path. diff --git a/packages/cli/src/bundle/saveAssets.js b/packages/cli/src/bundle/saveAssets.js index 428304008..c9d91b870 100644 --- a/packages/cli/src/bundle/saveAssets.js +++ b/packages/cli/src/bundle/saveAssets.js @@ -7,14 +7,14 @@ * @format */ -const mkdirp = require('mkdirp'); -const path = require('path'); -const fs = require('fs'); +import mkdirp from 'mkdirp'; +import path from 'path'; +import fs from 'fs'; -const filterPlatformAssetScales = require('./filterPlatformAssetScales'); -const getAssetDestPathAndroid = require('./getAssetDestPathAndroid'); -const getAssetDestPathIOS = require('./getAssetDestPathIOS'); -const logger = require('../util/logger'); +import filterPlatformAssetScales from './filterPlatformAssetScales'; +import getAssetDestPathAndroid from './getAssetDestPathAndroid'; +import getAssetDestPathIOS from './getAssetDestPathIOS'; +import logger from '../util/logger'; function saveAssets(assets, platform, assetsDest) { if (!assetsDest) { diff --git a/packages/cli/src/cliEntry.js b/packages/cli/src/cliEntry.js index 30bbbe51f..c463b0a34 100644 --- a/packages/cli/src/cliEntry.js +++ b/packages/cli/src/cliEntry.js @@ -8,19 +8,18 @@ * @flow */ +import chalk from 'chalk'; +import childProcess from 'child_process'; +import commander from 'commander'; +import minimist from 'minimist'; +import path from 'path'; import type { CommandT, ContextT } from './core/types.flow'; - -const chalk = require('chalk'); -const childProcess = require('child_process'); -const commander = require('commander'); -const minimist = require('minimist'); -const path = require('path'); -const getCommands = require('./core/getCommands'); -const getLegacyConfig = require('./core/getLegacyConfig'); -const init = require('./init/init'); -const assertRequiredOptions = require('./util/assertRequiredOptions'); -const logger = require('./util/logger'); -const pkg = require('../package.json'); +import getCommands from './core/getCommands'; +import getLegacyConfig from './core/getLegacyConfig'; +import init from './init/init'; +import assertRequiredOptions from './util/assertRequiredOptions'; +import logger from './util/logger'; +import pkg from '../package.json'; commander.version(pkg.version); diff --git a/packages/cli/src/core/__fixtures__/dependencies.js b/packages/cli/src/core/__fixtures__/dependencies.js index f5a3c1c33..4c83247ca 100644 --- a/packages/cli/src/core/__fixtures__/dependencies.js +++ b/packages/cli/src/core/__fixtures__/dependencies.js @@ -7,9 +7,10 @@ * @format */ +import path from 'path'; +import android from './android'; + const fs = jest.requireActual('fs'); -const path = require('path'); -const android = require('./android'); const pjson = fs.readFileSync(path.join(__dirname, 'files', 'package.json')); diff --git a/packages/cli/src/core/__fixtures__/ios.js b/packages/cli/src/core/__fixtures__/ios.js index eb043ea11..9e4ac610f 100644 --- a/packages/cli/src/core/__fixtures__/ios.js +++ b/packages/cli/src/core/__fixtures__/ios.js @@ -7,8 +7,9 @@ * @format */ +import path from 'path'; + const fs = jest.requireActual('fs'); -const path = require('path'); exports.valid = { 'demoProject.xcodeproj': { diff --git a/packages/cli/src/core/__fixtures__/projects.js b/packages/cli/src/core/__fixtures__/projects.js index a3e8d0b67..45158b903 100644 --- a/packages/cli/src/core/__fixtures__/projects.js +++ b/packages/cli/src/core/__fixtures__/projects.js @@ -7,8 +7,8 @@ * @format */ -const android = require('./android'); -const ios = require('./ios'); +import android from './android'; +import ios from './ios'; const flat = { android: android.valid, diff --git a/packages/cli/src/core/android/findAndroidAppFolder.js b/packages/cli/src/core/android/findAndroidAppFolder.js index 0d8848b36..eb3979535 100644 --- a/packages/cli/src/core/android/findAndroidAppFolder.js +++ b/packages/cli/src/core/android/findAndroidAppFolder.js @@ -7,8 +7,8 @@ * @format */ -const fs = require('fs'); -const path = require('path'); +import fs from 'fs'; +import path from 'path'; /** * @param {String} folder Folder to seek in diff --git a/packages/cli/src/core/android/findManifest.js b/packages/cli/src/core/android/findManifest.js index 1354a85d1..9d243c20d 100644 --- a/packages/cli/src/core/android/findManifest.js +++ b/packages/cli/src/core/android/findManifest.js @@ -7,8 +7,8 @@ * @format */ -const glob = require('glob'); -const path = require('path'); +import glob from 'glob'; +import path from 'path'; /** * Find an android application path in the folder diff --git a/packages/cli/src/core/android/findPackageClassName.js b/packages/cli/src/core/android/findPackageClassName.js index 01436454b..e07eec7cf 100644 --- a/packages/cli/src/core/android/findPackageClassName.js +++ b/packages/cli/src/core/android/findPackageClassName.js @@ -7,9 +7,9 @@ * @format */ -const fs = require('fs'); -const glob = require('glob'); -const path = require('path'); +import fs from 'fs'; +import glob from 'glob'; +import path from 'path'; /** * Gets package's class name (class that implements ReactPackage) diff --git a/packages/cli/src/core/android/index.js b/packages/cli/src/core/android/index.js index 1a674af6a..2cf3b534b 100644 --- a/packages/cli/src/core/android/index.js +++ b/packages/cli/src/core/android/index.js @@ -7,11 +7,11 @@ * @format */ -const path = require('path'); -const findAndroidAppFolder = require('./findAndroidAppFolder'); -const findManifest = require('./findManifest'); -const findPackageClassName = require('./findPackageClassName'); -const readManifest = require('./readManifest'); +import path from 'path'; +import findAndroidAppFolder from './findAndroidAppFolder'; +import findManifest from './findManifest'; +import findPackageClassName from './findPackageClassName'; +import readManifest from './readManifest'; const getPackageName = manifest => manifest.attr.package; diff --git a/packages/cli/src/core/android/readManifest.js b/packages/cli/src/core/android/readManifest.js index b86cc725f..fa6ab1e73 100644 --- a/packages/cli/src/core/android/readManifest.js +++ b/packages/cli/src/core/android/readManifest.js @@ -7,8 +7,8 @@ * @format */ -const fs = require('fs'); -const xml = require('xmldoc'); +import fs from 'fs'; +import xml from 'xmldoc'; /** * @param {String} manifestPath diff --git a/packages/cli/src/core/findPlugins.js b/packages/cli/src/core/findPlugins.js index 43b061a75..a6ced9d55 100644 --- a/packages/cli/src/core/findPlugins.js +++ b/packages/cli/src/core/findPlugins.js @@ -7,8 +7,8 @@ * @flow */ -const path = require('path'); -const { union, uniq, flatten } = require('lodash'); +import path from 'path'; +import { union, uniq, flatten } from 'lodash'; const RNPM_PLUGIN_PATTERNS = [/^rnpm-plugin-/, /^@(.*)\/rnpm-plugin-/]; diff --git a/packages/cli/src/core/getAssets.js b/packages/cli/src/core/getAssets.js index 97fffd78b..504a4ef62 100644 --- a/packages/cli/src/core/getAssets.js +++ b/packages/cli/src/core/getAssets.js @@ -2,9 +2,9 @@ * @flow */ -const glob = require('glob'); -const path = require('path'); -const getPackageConfiguration = require('./getPackageConfiguration'); +import glob from 'glob'; +import path from 'path'; +import getPackageConfiguration from './getPackageConfiguration'; const findAssetsInFolder = folder => glob.sync(path.join(folder, '**'), { nodir: true }); diff --git a/packages/cli/src/core/getCommands.js b/packages/cli/src/core/getCommands.js index 2c598f2e8..3c959ca00 100644 --- a/packages/cli/src/core/getCommands.js +++ b/packages/cli/src/core/getCommands.js @@ -2,11 +2,11 @@ * @flow */ +import path from 'path'; import type { CommandT, ProjectCommandT, LocalCommandT } from './types.flow'; -const path = require('path'); -const findPlugins = require('./findPlugins'); -const logger = require('../util/logger'); +import findPlugins from './findPlugins'; +import logger from '../util/logger'; /** * List of built-in commands diff --git a/packages/cli/src/core/getHooks.js b/packages/cli/src/core/getHooks.js index 84d193073..77f1813db 100644 --- a/packages/cli/src/core/getHooks.js +++ b/packages/cli/src/core/getHooks.js @@ -2,8 +2,8 @@ * @flow */ -const { spawn } = require('child_process'); -const getPackageConfiguration = require('./getPackageConfiguration'); +import { spawn } from 'child_process'; +import getPackageConfiguration from './getPackageConfiguration'; function makeCommand(command) { return cb => { diff --git a/packages/cli/src/core/getLegacyConfig.js b/packages/cli/src/core/getLegacyConfig.js index 88b61c81a..d6f425305 100644 --- a/packages/cli/src/core/getLegacyConfig.js +++ b/packages/cli/src/core/getLegacyConfig.js @@ -1,14 +1,14 @@ /** * @flow */ -const path = require('path'); -const util = require('util'); - -const getPlatforms = require('./getPlatforms'); -const getPackageConfiguration = require('./getPackageConfiguration'); -const getHooks = require('./getHooks'); -const getAssets = require('./getAssets'); -const getParams = require('./getParams'); +import path from 'path'; +import util from 'util'; + +import getPlatforms from './getPlatforms'; +import getPackageConfiguration from './getPackageConfiguration'; +import getHooks from './getHooks'; +import getAssets from './getAssets'; +import getParams from './getParams'; const generateDeprecationMessage = api => `${api} is deprecated and will be removed soon. Please check release notes on how to upgrade`; diff --git a/packages/cli/src/core/getPackageConfiguration.js b/packages/cli/src/core/getPackageConfiguration.js index e9e46a81f..cc0ce11a4 100644 --- a/packages/cli/src/core/getPackageConfiguration.js +++ b/packages/cli/src/core/getPackageConfiguration.js @@ -1,10 +1,9 @@ /** * @flow */ +import path from 'path'; import type { PackageConfigurationT } from './types.flow'; -const path = require('path'); - /** * Returns configuration of the CLI from `package.json`. */ diff --git a/packages/cli/src/core/getParams.js b/packages/cli/src/core/getParams.js index 9dc3d792f..f242d8692 100644 --- a/packages/cli/src/core/getParams.js +++ b/packages/cli/src/core/getParams.js @@ -2,7 +2,7 @@ * @flow */ -const getPackageConfiguration = require('./getPackageConfiguration'); +import getPackageConfiguration from './getPackageConfiguration'; module.exports = function getParams(root: string) { const config = getPackageConfiguration(root); diff --git a/packages/cli/src/core/getPlatforms.js b/packages/cli/src/core/getPlatforms.js index 2e4bbb901..94618be2b 100644 --- a/packages/cli/src/core/getPlatforms.js +++ b/packages/cli/src/core/getPlatforms.js @@ -2,10 +2,10 @@ * @flow */ +import path from 'path'; import type { PlatformsT } from './types.flow'; -const path = require('path'); -const findPlugins = require('./findPlugins'); +import findPlugins from './findPlugins'; /** * Support for `ios` and `android` platforms is built-in diff --git a/packages/cli/src/core/ios/findPodfilePath.js b/packages/cli/src/core/ios/findPodfilePath.js index f2263046b..c52814ad0 100644 --- a/packages/cli/src/core/ios/findPodfilePath.js +++ b/packages/cli/src/core/ios/findPodfilePath.js @@ -7,8 +7,8 @@ * @format */ -const fs = require('fs'); -const path = require('path'); +import fs from 'fs'; +import path from 'path'; module.exports = function findPodfilePath(projectFolder) { const podFilePath = path.join(projectFolder, '..', 'Podfile'); diff --git a/packages/cli/src/core/ios/findPodspecName.js b/packages/cli/src/core/ios/findPodspecName.js index cd3d6c7a5..529b821da 100644 --- a/packages/cli/src/core/ios/findPodspecName.js +++ b/packages/cli/src/core/ios/findPodspecName.js @@ -7,8 +7,8 @@ * @format */ -const glob = require('glob'); -const path = require('path'); +import glob from 'glob'; +import path from 'path'; module.exports = function findPodspecName(folder) { const podspecs = glob.sync('*.podspec', { cwd: folder }); diff --git a/packages/cli/src/core/ios/findProject.js b/packages/cli/src/core/ios/findProject.js index f4ea052a1..6bfe9b354 100644 --- a/packages/cli/src/core/ios/findProject.js +++ b/packages/cli/src/core/ios/findProject.js @@ -7,8 +7,8 @@ * @format */ -const glob = require('glob'); -const path = require('path'); +import glob from 'glob'; +import path from 'path'; /** * Glob pattern to look for xcodeproj diff --git a/packages/cli/src/core/ios/index.js b/packages/cli/src/core/ios/index.js index 70842f0e0..faced3d71 100644 --- a/packages/cli/src/core/ios/index.js +++ b/packages/cli/src/core/ios/index.js @@ -7,10 +7,10 @@ * @format */ -const path = require('path'); -const findProject = require('./findProject'); -const findPodfilePath = require('./findPodfilePath'); -const findPodspecName = require('./findPodspecName'); +import path from 'path'; +import findProject from './findProject'; +import findPodfilePath from './findPodfilePath'; +import findPodspecName from './findPodspecName'; /** * For libraries specified without an extension, add '.tbd' for those that diff --git a/packages/cli/src/dependencies/dependencies.js b/packages/cli/src/dependencies/dependencies.js index 6a0e1504b..6158d7d1f 100644 --- a/packages/cli/src/dependencies/dependencies.js +++ b/packages/cli/src/dependencies/dependencies.js @@ -6,12 +6,12 @@ * */ -const Metro = require('metro'); +import Metro from 'metro'; -const denodeify = require('denodeify'); -const fs = require('fs'); -const path = require('path'); -const util = require('util'); +import denodeify from 'denodeify'; +import fs from 'fs'; +import path from 'path'; +import util from 'util'; async function dependencies(argv, configPromise, args, packagerInstance) { const rootModuleAbsolutePath = args.entryFile; diff --git a/packages/cli/src/eject/eject.js b/packages/cli/src/eject/eject.js index c871e645e..4ef7e75fa 100644 --- a/packages/cli/src/eject/eject.js +++ b/packages/cli/src/eject/eject.js @@ -7,10 +7,10 @@ * @format */ -const path = require('path'); -const fs = require('fs'); -const copyProjectTemplateAndReplace = require('../generator/copyProjectTemplateAndReplace'); -const logger = require('../util/logger'); +import path from 'path'; +import fs from 'fs'; +import copyProjectTemplateAndReplace from '../generator/copyProjectTemplateAndReplace'; +import logger from '../util/logger'; /** * The eject command re-creates the `android` and `ios` native folders. Because native code can be diff --git a/packages/cli/src/generator/copyProjectTemplateAndReplace.js b/packages/cli/src/generator/copyProjectTemplateAndReplace.js index f49e1f313..c95235789 100644 --- a/packages/cli/src/generator/copyProjectTemplateAndReplace.js +++ b/packages/cli/src/generator/copyProjectTemplateAndReplace.js @@ -7,12 +7,14 @@ * @format */ -const chalk = require('chalk'); -const path = require('path'); -const copyAndReplace = require('../util/copyAndReplace'); -const prompt = require('./promptSync')(); -const walk = require('../util/walk'); -const logger = require('../util/logger'); +import chalk from 'chalk'; +import path from 'path'; +import copyAndReplace from '../util/copyAndReplace'; +import promptInitializer from './promptSync'; +import walk from '../util/walk'; +import logger from '../util/logger'; + +const prompt = promptInitializer(); /** * Util for creating a new React Native project. diff --git a/packages/cli/src/generator/printRunInstructions.js b/packages/cli/src/generator/printRunInstructions.js index ea816a58b..d48ed657e 100644 --- a/packages/cli/src/generator/printRunInstructions.js +++ b/packages/cli/src/generator/printRunInstructions.js @@ -7,8 +7,8 @@ * @format */ -const path = require('path'); -const logger = require('../util/logger'); +import path from 'path'; +import logger from '../util/logger'; function printRunInstructions(projectDir, projectName) { const absoluteProjectDir = path.resolve(projectDir); diff --git a/packages/cli/src/generator/promptSync.js b/packages/cli/src/generator/promptSync.js index 41a874f23..753a8e080 100644 --- a/packages/cli/src/generator/promptSync.js +++ b/packages/cli/src/generator/promptSync.js @@ -12,7 +12,7 @@ /* eslint-disable */ -const fs = require('fs'); +import fs from 'fs'; const term = 13; // carriage return diff --git a/packages/cli/src/generator/templates.js b/packages/cli/src/generator/templates.js index c0ce11010..3157c7fba 100644 --- a/packages/cli/src/generator/templates.js +++ b/packages/cli/src/generator/templates.js @@ -7,11 +7,11 @@ * @format */ -const { execSync } = require('child_process'); -const fs = require('fs'); -const path = require('path'); -const copyProjectTemplateAndReplace = require('./copyProjectTemplateAndReplace'); -const logger = require('../util/logger'); +import { execSync } from 'child_process'; +import fs from 'fs'; +import path from 'path'; +import copyProjectTemplateAndReplace from './copyProjectTemplateAndReplace'; +import logger from '../util/logger'; /** * @param destPath Create the new project at this path. @@ -183,6 +183,4 @@ function installTemplateDevDependencies(templatePath, yarnVersion) { } } -module.exports = { - createProjectFromTemplate, -}; +export { createProjectFromTemplate }; diff --git a/packages/cli/src/index.js b/packages/cli/src/index.js index 2fa02c0e5..c0d18bbc1 100644 --- a/packages/cli/src/index.js +++ b/packages/cli/src/index.js @@ -8,9 +8,10 @@ */ // gracefulify() has to be called before anything else runs -require('graceful-fs').gracefulify(require('fs')); +// eslint-disable-next-line no-unused-vars +import gracefulFs from './util/gracefulFs'; -const cli = require('./cliEntry'); +import cli from './cliEntry'; if (require.main === module) { cli.run(); diff --git a/packages/cli/src/info/info.js b/packages/cli/src/info/info.js index 2c7c924c0..ed91be294 100644 --- a/packages/cli/src/info/info.js +++ b/packages/cli/src/info/info.js @@ -7,8 +7,8 @@ * @format */ -const envinfo = require('envinfo'); -const logger = require('../util/logger'); +import envinfo from 'envinfo'; +import logger from '../util/logger'; const info = function getInfo(argv, ctx, options) { try { diff --git a/packages/cli/src/init/init.js b/packages/cli/src/init/init.js index ae5cc4496..3e3a44f97 100644 --- a/packages/cli/src/init/init.js +++ b/packages/cli/src/init/init.js @@ -7,15 +7,15 @@ * @format */ -const { execSync } = require('child_process'); -const fs = require('fs'); -const minimist = require('minimist'); -const path = require('path'); -const process = require('process'); -const printRunInstructions = require('../generator/printRunInstructions'); -const { createProjectFromTemplate } = require('../generator/templates'); -const yarn = require('../util/yarn'); -const logger = require('../util/logger'); +import { execSync } from 'child_process'; +import fs from 'fs'; +import minimist from 'minimist'; +import path from 'path'; +import process from 'process'; +import printRunInstructions from '../generator/printRunInstructions'; +import { createProjectFromTemplate } from '../generator/templates'; +import yarn from '../util/yarn'; +import logger from '../util/logger'; /** * Creates the template for a React Native project given the provided diff --git a/packages/cli/src/install/install.js b/packages/cli/src/install/install.js index b19bf2269..37e821491 100644 --- a/packages/cli/src/install/install.js +++ b/packages/cli/src/install/install.js @@ -7,9 +7,9 @@ * @format */ -const { spawnSync } = require('child_process'); -const logger = require('../util/logger'); -const PackageManager = require('../util/PackageManager'); +import { spawnSync } from 'child_process'; +import logger from '../util/logger'; +import PackageManager from '../util/PackageManager'; const spawnOpts = { stdio: 'inherit', diff --git a/packages/cli/src/install/uninstall.js b/packages/cli/src/install/uninstall.js index e8e1c0c8e..1f55de821 100644 --- a/packages/cli/src/install/uninstall.js +++ b/packages/cli/src/install/uninstall.js @@ -7,9 +7,9 @@ * @format */ -const { spawnSync } = require('child_process'); -const logger = require('../util/logger'); -const PackageManager = require('../util/PackageManager'); +import { spawnSync } from 'child_process'; +import logger from '../util/logger'; +import PackageManager from '../util/PackageManager'; const spawnOpts = { stdio: 'inherit', diff --git a/packages/cli/src/library/library.js b/packages/cli/src/library/library.js index f0b7c69d2..763713a5f 100644 --- a/packages/cli/src/library/library.js +++ b/packages/cli/src/library/library.js @@ -7,12 +7,12 @@ * @format */ -const fs = require('fs'); -const path = require('path'); -const copyAndReplace = require('../util/copyAndReplace'); -const isValidPackageName = require('../util/isValidPackageName'); -const walk = require('../util/walk'); -const logger = require('../util/logger'); +import fs from 'fs'; +import path from 'path'; +import copyAndReplace from '../util/copyAndReplace'; +import isValidPackageName from '../util/isValidPackageName'; +import walk from '../util/walk'; +import logger from '../util/logger'; /** * Creates a new native library with the given name diff --git a/packages/cli/src/link/android/copyAssets.js b/packages/cli/src/link/android/copyAssets.js index 36d54c381..90e06d06a 100644 --- a/packages/cli/src/link/android/copyAssets.js +++ b/packages/cli/src/link/android/copyAssets.js @@ -7,9 +7,9 @@ * @format */ -const fs = require('fs-extra'); -const path = require('path'); -const groupFilesByType = require('../groupFilesByType'); +import fs from 'fs-extra'; +import path from 'path'; +import groupFilesByType from '../groupFilesByType'; /** * Copies each file from an array of assets provided to targetPath directory diff --git a/packages/cli/src/link/android/fs.js b/packages/cli/src/link/android/fs.js index a7cf3d029..26ecbdae0 100644 --- a/packages/cli/src/link/android/fs.js +++ b/packages/cli/src/link/android/fs.js @@ -7,7 +7,7 @@ * @format */ -const fs = require('fs-extra'); +import fs from 'fs-extra'; exports.readFile = file => () => fs.readFileSync(file, 'utf8'); diff --git a/packages/cli/src/link/android/isInstalled.js b/packages/cli/src/link/android/isInstalled.js index 24f077887..bb00c9c56 100644 --- a/packages/cli/src/link/android/isInstalled.js +++ b/packages/cli/src/link/android/isInstalled.js @@ -7,8 +7,8 @@ * @format */ -const fs = require('fs'); -const makeBuildPatch = require('./patches/makeBuildPatch'); +import fs from 'fs'; +import makeBuildPatch from './patches/makeBuildPatch'; module.exports = function isInstalled(config, name) { const buildGradle = fs.readFileSync(config.buildGradlePath); diff --git a/packages/cli/src/link/android/patches/applyParams.js b/packages/cli/src/link/android/patches/applyParams.js index c34d226ed..9a3a4e2d5 100644 --- a/packages/cli/src/link/android/patches/applyParams.js +++ b/packages/cli/src/link/android/patches/applyParams.js @@ -7,7 +7,7 @@ * @format */ -const toCamelCase = require('lodash').camelCase; +import { camelCase as toCamelCase } from 'lodash'; module.exports = function applyParams(str, params, prefix) { return str.replace(/\$\{(\w+)\}/g, (pattern, param) => { diff --git a/packages/cli/src/link/android/patches/applyPatch.js b/packages/cli/src/link/android/patches/applyPatch.js index 51205e8e4..dd4f87252 100644 --- a/packages/cli/src/link/android/patches/applyPatch.js +++ b/packages/cli/src/link/android/patches/applyPatch.js @@ -7,7 +7,7 @@ * @format */ -const fs = require('fs'); +import fs from 'fs'; module.exports = function applyPatch(file, patch) { fs.writeFileSync( diff --git a/packages/cli/src/link/android/patches/makeBuildPatch.js b/packages/cli/src/link/android/patches/makeBuildPatch.js index 31c1c0c8c..5ea0269f1 100644 --- a/packages/cli/src/link/android/patches/makeBuildPatch.js +++ b/packages/cli/src/link/android/patches/makeBuildPatch.js @@ -7,7 +7,7 @@ * @format */ -const normalizeProjectName = require('./normalizeProjectName'); +import normalizeProjectName from './normalizeProjectName'; module.exports = function makeBuildPatch(name) { const normalizedProjectName = normalizeProjectName(name); diff --git a/packages/cli/src/link/android/patches/makePackagePatch.js b/packages/cli/src/link/android/patches/makePackagePatch.js index 7c1698104..94ad6d73f 100644 --- a/packages/cli/src/link/android/patches/makePackagePatch.js +++ b/packages/cli/src/link/android/patches/makePackagePatch.js @@ -7,7 +7,7 @@ * @format */ -const applyParams = require('./applyParams'); +import applyParams from './applyParams'; module.exports = function makePackagePatch(packageInstance, params, prefix) { const processedInstance = applyParams(packageInstance, params, prefix); diff --git a/packages/cli/src/link/android/patches/makeSettingsPatch.js b/packages/cli/src/link/android/patches/makeSettingsPatch.js index 081768d16..2b1a6058f 100644 --- a/packages/cli/src/link/android/patches/makeSettingsPatch.js +++ b/packages/cli/src/link/android/patches/makeSettingsPatch.js @@ -7,9 +7,9 @@ * @format */ -const path = require('path'); -const slash = require('slash'); -const normalizeProjectName = require('./normalizeProjectName'); +import path from 'path'; +import slash from 'slash'; +import normalizeProjectName from './normalizeProjectName'; module.exports = function makeSettingsPatch( name, diff --git a/packages/cli/src/link/android/patches/makeStringsPatch.js b/packages/cli/src/link/android/patches/makeStringsPatch.js index 17838f624..971ede89e 100644 --- a/packages/cli/src/link/android/patches/makeStringsPatch.js +++ b/packages/cli/src/link/android/patches/makeStringsPatch.js @@ -7,7 +7,7 @@ * @format */ -const toCamelCase = require('lodash').camelCase; +import { camelCase as toCamelCase } from 'lodash'; module.exports = function makeStringsPatch(params, prefix) { const values = Object.keys(params).map(param => { diff --git a/packages/cli/src/link/android/patches/revokePatch.js b/packages/cli/src/link/android/patches/revokePatch.js index 56e612660..900b639b7 100644 --- a/packages/cli/src/link/android/patches/revokePatch.js +++ b/packages/cli/src/link/android/patches/revokePatch.js @@ -7,7 +7,7 @@ * @format */ -const fs = require('fs'); +import fs from 'fs'; module.exports = function revokePatch(file, patch) { fs.writeFileSync( diff --git a/packages/cli/src/link/android/registerNativeModule.js b/packages/cli/src/link/android/registerNativeModule.js index 1fe3484bd..5ac51129b 100644 --- a/packages/cli/src/link/android/registerNativeModule.js +++ b/packages/cli/src/link/android/registerNativeModule.js @@ -7,12 +7,12 @@ * @format */ -const applyPatch = require('./patches/applyPatch'); -const makeStringsPatch = require('./patches/makeStringsPatch'); -const makeSettingsPatch = require('./patches/makeSettingsPatch'); -const makeBuildPatch = require('./patches/makeBuildPatch'); -const makeImportPatch = require('./patches/makeImportPatch'); -const makePackagePatch = require('./patches/makePackagePatch'); +import applyPatch from './patches/applyPatch'; +import makeStringsPatch from './patches/makeStringsPatch'; +import makeSettingsPatch from './patches/makeSettingsPatch'; +import makeBuildPatch from './patches/makeBuildPatch'; +import makeImportPatch from './patches/makeImportPatch'; +import makePackagePatch from './patches/makePackagePatch'; module.exports = function registerNativeAndroidModule( name, diff --git a/packages/cli/src/link/android/unlinkAssets.js b/packages/cli/src/link/android/unlinkAssets.js index 3f5c8bebd..2b8a6651d 100644 --- a/packages/cli/src/link/android/unlinkAssets.js +++ b/packages/cli/src/link/android/unlinkAssets.js @@ -7,9 +7,9 @@ * @format */ -const fs = require('fs-extra'); -const path = require('path'); -const groupFilesByType = require('../groupFilesByType'); +import fs from 'fs-extra'; +import path from 'path'; +import groupFilesByType from '../groupFilesByType'; /** * Copies each file from an array of assets provided to targetPath directory diff --git a/packages/cli/src/link/android/unregisterNativeModule.js b/packages/cli/src/link/android/unregisterNativeModule.js index 53bbbc522..bed5bddeb 100644 --- a/packages/cli/src/link/android/unregisterNativeModule.js +++ b/packages/cli/src/link/android/unregisterNativeModule.js @@ -7,15 +7,15 @@ * @format */ -const fs = require('fs'); -const toCamelCase = require('lodash').camelCase; - -const revokePatch = require('./patches/revokePatch'); -const makeSettingsPatch = require('./patches/makeSettingsPatch'); -const makeBuildPatch = require('./patches/makeBuildPatch'); -const makeStringsPatch = require('./patches/makeStringsPatch'); -const makeImportPatch = require('./patches/makeImportPatch'); -const makePackagePatch = require('./patches/makePackagePatch'); +import fs from 'fs'; +import { camelCase as toCamelCase } from 'lodash'; + +import revokePatch from './patches/revokePatch'; +import makeSettingsPatch from './patches/makeSettingsPatch'; +import makeBuildPatch from './patches/makeBuildPatch'; +import makeStringsPatch from './patches/makeStringsPatch'; +import makeImportPatch from './patches/makeImportPatch'; +import makePackagePatch from './patches/makePackagePatch'; module.exports = function unregisterNativeAndroidModule( name, diff --git a/packages/cli/src/link/getDependencyConfig.js b/packages/cli/src/link/getDependencyConfig.js index b24fac88c..e234de62d 100644 --- a/packages/cli/src/link/getDependencyConfig.js +++ b/packages/cli/src/link/getDependencyConfig.js @@ -2,6 +2,7 @@ * @flow */ +import path from 'path'; import type { PlatformsT, ContextT, @@ -9,12 +10,10 @@ import type { DependencyConfigT, } from '../core/types.flow'; -const path = require('path'); - -const getPackageConfiguration = require('../core/getPackageConfiguration'); -const getParams = require('../core/getParams'); -const getHooks = require('../core/getHooks'); -const getAssets = require('../core/getAssets'); +import getPackageConfiguration from '../core/getPackageConfiguration'; +import getParams from '../core/getParams'; +import getHooks from '../core/getHooks'; +import getAssets from '../core/getAssets'; type DependenciesConfig = { config: DependencyConfigT, diff --git a/packages/cli/src/link/getProjectConfig.js b/packages/cli/src/link/getProjectConfig.js index 905022193..a800c6c62 100644 --- a/packages/cli/src/link/getProjectConfig.js +++ b/packages/cli/src/link/getProjectConfig.js @@ -4,7 +4,7 @@ import type { PlatformsT, ContextT, ProjectConfigT } from '../core/types.flow'; -const getPackageConfiguration = require('../core/getPackageConfiguration'); +import getPackageConfiguration from '../core/getPackageConfiguration'; module.exports = function getProjectConfig( ctx: ContextT, diff --git a/packages/cli/src/link/getProjectDependencies.js b/packages/cli/src/link/getProjectDependencies.js index 5e9639c84..5d70f2b61 100644 --- a/packages/cli/src/link/getProjectDependencies.js +++ b/packages/cli/src/link/getProjectDependencies.js @@ -7,7 +7,7 @@ * @format */ -const path = require('path'); +import path from 'path'; /** * List of projects that should not be treated as projects to be linked. diff --git a/packages/cli/src/link/groupFilesByType.js b/packages/cli/src/link/groupFilesByType.js index 54cb8ef5d..89d23d1cb 100644 --- a/packages/cli/src/link/groupFilesByType.js +++ b/packages/cli/src/link/groupFilesByType.js @@ -7,8 +7,8 @@ * @format */ -const { groupBy } = require('lodash'); -const mime = require('mime'); +import { groupBy } from 'lodash'; +import mime from 'mime'; /** * Since there are no officially registered MIME types diff --git a/packages/cli/src/link/ios/addFileToProject.js b/packages/cli/src/link/ios/addFileToProject.js index a53439966..febd571e1 100644 --- a/packages/cli/src/link/ios/addFileToProject.js +++ b/packages/cli/src/link/ios/addFileToProject.js @@ -7,7 +7,7 @@ * @format */ -const PbxFile = require('xcode/lib/pbxFile'); +import PbxFile from 'xcode/lib/pbxFile'; /** * Given xcodeproj and filePath, it creates new file diff --git a/packages/cli/src/link/ios/addSharedLibraries.js b/packages/cli/src/link/ios/addSharedLibraries.js index a97e3f69a..818b92f35 100644 --- a/packages/cli/src/link/ios/addSharedLibraries.js +++ b/packages/cli/src/link/ios/addSharedLibraries.js @@ -7,7 +7,7 @@ * @format */ -const createGroupWithMessage = require('./createGroupWithMessage'); +import createGroupWithMessage from './createGroupWithMessage'; module.exports = function addSharedLibraries(project, libraries) { if (!libraries.length) { diff --git a/packages/cli/src/link/ios/addToHeaderSearchPaths.js b/packages/cli/src/link/ios/addToHeaderSearchPaths.js index e3cd6db2f..578a38c8a 100644 --- a/packages/cli/src/link/ios/addToHeaderSearchPaths.js +++ b/packages/cli/src/link/ios/addToHeaderSearchPaths.js @@ -7,7 +7,7 @@ * @format */ -const mapHeaderSearchPaths = require('./mapHeaderSearchPaths'); +import mapHeaderSearchPaths from './mapHeaderSearchPaths'; module.exports = function addToHeaderSearchPaths(project, path) { mapHeaderSearchPaths(project, searchPaths => searchPaths.concat(path)); diff --git a/packages/cli/src/link/ios/common/isInstalled.js b/packages/cli/src/link/ios/common/isInstalled.js index 3e5542fe1..92be6e142 100644 --- a/packages/cli/src/link/ios/common/isInstalled.js +++ b/packages/cli/src/link/ios/common/isInstalled.js @@ -7,8 +7,8 @@ * @format */ -const isInstalledIOS = require('../isInstalled'); -const isInstalledPods = require('../../pods/isInstalled'); +import isInstalledIOS from '../isInstalled'; +import isInstalledPods from '../../pods/isInstalled'; module.exports = function isInstalled(projectConfig, name, dependencyConfig) { return ( diff --git a/packages/cli/src/link/ios/common/registerNativeModule.js b/packages/cli/src/link/ios/common/registerNativeModule.js index 4b5d0ec86..937e67448 100644 --- a/packages/cli/src/link/ios/common/registerNativeModule.js +++ b/packages/cli/src/link/ios/common/registerNativeModule.js @@ -7,8 +7,8 @@ * @format */ -const registerDependencyIOS = require('../registerNativeModule'); -const registerDependencyPods = require('../../pods/registerNativeModule'); +import registerDependencyIOS from '../registerNativeModule'; +import registerDependencyPods from '../../pods/registerNativeModule'; module.exports = function registerNativeModule( name, diff --git a/packages/cli/src/link/ios/common/unregisterNativeModule.js b/packages/cli/src/link/ios/common/unregisterNativeModule.js index 3cf4c718d..689d8cb4e 100644 --- a/packages/cli/src/link/ios/common/unregisterNativeModule.js +++ b/packages/cli/src/link/ios/common/unregisterNativeModule.js @@ -7,11 +7,11 @@ * @format */ -const { compact } = require('lodash'); -const isInstalledIOS = require('../isInstalled'); -const isInstalledPods = require('../../pods/isInstalled'); -const unregisterDependencyIOS = require('../unregisterNativeModule'); -const unregisterDependencyPods = require('../../pods/unregisterNativeModule'); +import { compact } from 'lodash'; +import isInstalledIOS from '../isInstalled'; +import isInstalledPods from '../../pods/isInstalled'; +import unregisterDependencyIOS from '../unregisterNativeModule'; +import unregisterDependencyPods from '../../pods/unregisterNativeModule'; module.exports = function unregisterNativeModule( name, diff --git a/packages/cli/src/link/ios/copyAssets.js b/packages/cli/src/link/ios/copyAssets.js index cca28d8ac..0acfdb6c2 100644 --- a/packages/cli/src/link/ios/copyAssets.js +++ b/packages/cli/src/link/ios/copyAssets.js @@ -7,13 +7,13 @@ * @format */ -const fs = require('fs-extra'); -const path = require('path'); -const xcode = require('xcode'); -const groupFilesByType = require('../groupFilesByType'); -const createGroupWithMessage = require('./createGroupWithMessage'); -const getPlist = require('./getPlist'); -const writePlist = require('./writePlist'); +import fs from 'fs-extra'; +import path from 'path'; +import xcode from 'xcode'; +import groupFilesByType from '../groupFilesByType'; +import createGroupWithMessage from './createGroupWithMessage'; +import getPlist from './getPlist'; +import writePlist from './writePlist'; /** * This function works in a similar manner to its Android version, diff --git a/packages/cli/src/link/ios/createGroup.js b/packages/cli/src/link/ios/createGroup.js index 473bb4ccd..cfe916b1e 100644 --- a/packages/cli/src/link/ios/createGroup.js +++ b/packages/cli/src/link/ios/createGroup.js @@ -7,7 +7,7 @@ * @format */ -const getGroup = require('./getGroup'); +import getGroup from './getGroup'; const hasGroup = (pbxGroup, name) => pbxGroup.children.find(group => group.comment === name); diff --git a/packages/cli/src/link/ios/createGroupWithMessage.js b/packages/cli/src/link/ios/createGroupWithMessage.js index aebdc7c2d..61620d6ae 100644 --- a/packages/cli/src/link/ios/createGroupWithMessage.js +++ b/packages/cli/src/link/ios/createGroupWithMessage.js @@ -7,9 +7,9 @@ * @format */ -const log = require('../../util/logger'); -const createGroup = require('./createGroup'); -const getGroup = require('./getGroup'); +import log from '../../util/logger'; +import createGroup from './createGroup'; +import getGroup from './getGroup'; /** * Given project and path of the group, it checks if a group exists at that path, diff --git a/packages/cli/src/link/ios/getHeaderSearchPath.js b/packages/cli/src/link/ios/getHeaderSearchPath.js index 323c4e439..ba3a25b3c 100644 --- a/packages/cli/src/link/ios/getHeaderSearchPath.js +++ b/packages/cli/src/link/ios/getHeaderSearchPath.js @@ -7,8 +7,8 @@ * @format */ -const path = require('path'); -const { last, union } = require('lodash'); +import path from 'path'; +import { last, union } from 'lodash'; /** * Given an array of directories, it returns the one that contains diff --git a/packages/cli/src/link/ios/getHeadersInFolder.js b/packages/cli/src/link/ios/getHeadersInFolder.js index 562cac9a5..94440d99c 100644 --- a/packages/cli/src/link/ios/getHeadersInFolder.js +++ b/packages/cli/src/link/ios/getHeadersInFolder.js @@ -7,8 +7,8 @@ * @format */ -const glob = require('glob'); -const path = require('path'); +import glob from 'glob'; +import path from 'path'; const GLOB_EXCLUDE_PATTERN = [ 'node_modules/**', diff --git a/packages/cli/src/link/ios/getPlist.js b/packages/cli/src/link/ios/getPlist.js index ee51c549b..3d15bc723 100644 --- a/packages/cli/src/link/ios/getPlist.js +++ b/packages/cli/src/link/ios/getPlist.js @@ -7,9 +7,9 @@ * @format */ -const plistParser = require('plist'); -const fs = require('fs'); -const getPlistPath = require('./getPlistPath'); +import plistParser from 'plist'; +import fs from 'fs'; +import getPlistPath from './getPlistPath'; /** * Returns Info.plist located in the iOS project diff --git a/packages/cli/src/link/ios/getPlistPath.js b/packages/cli/src/link/ios/getPlistPath.js index 4fdbd0305..3211a2368 100644 --- a/packages/cli/src/link/ios/getPlistPath.js +++ b/packages/cli/src/link/ios/getPlistPath.js @@ -7,8 +7,8 @@ * @format */ -const path = require('path'); -const getBuildProperty = require('./getBuildProperty'); +import path from 'path'; +import getBuildProperty from './getBuildProperty'; module.exports = function getPlistPath(project, sourceDir) { const plistFile = getBuildProperty(project, 'INFOPLIST_FILE'); diff --git a/packages/cli/src/link/ios/isInstalled.js b/packages/cli/src/link/ios/isInstalled.js index 07cfb1254..1bdd06165 100644 --- a/packages/cli/src/link/ios/isInstalled.js +++ b/packages/cli/src/link/ios/isInstalled.js @@ -7,9 +7,9 @@ * @format */ -const xcode = require('xcode'); -const getGroup = require('./getGroup'); -const hasLibraryImported = require('./hasLibraryImported'); +import xcode from 'xcode'; +import getGroup from './getGroup'; +import hasLibraryImported from './hasLibraryImported'; /** * Returns true if `xcodeproj` specified by dependencyConfig is present diff --git a/packages/cli/src/link/ios/registerNativeModule.js b/packages/cli/src/link/ios/registerNativeModule.js index cd2ba13ea..fba182d8d 100644 --- a/packages/cli/src/link/ios/registerNativeModule.js +++ b/packages/cli/src/link/ios/registerNativeModule.js @@ -7,19 +7,19 @@ * @format */ -const xcode = require('xcode'); -const fs = require('fs'); -const path = require('path'); -const { isEmpty } = require('lodash'); +import xcode from 'xcode'; +import fs from 'fs'; +import path from 'path'; +import { isEmpty } from 'lodash'; -const addToHeaderSearchPaths = require('./addToHeaderSearchPaths'); -const getHeadersInFolder = require('./getHeadersInFolder'); -const getHeaderSearchPath = require('./getHeaderSearchPath'); -const getTargets = require('./getTargets'); -const createGroupWithMessage = require('./createGroupWithMessage'); -const addFileToProject = require('./addFileToProject'); -const addProjectToLibraries = require('./addProjectToLibraries'); -const addSharedLibraries = require('./addSharedLibraries'); +import addToHeaderSearchPaths from './addToHeaderSearchPaths'; +import getHeadersInFolder from './getHeadersInFolder'; +import getHeaderSearchPath from './getHeaderSearchPath'; +import getTargets from './getTargets'; +import createGroupWithMessage from './createGroupWithMessage'; +import addFileToProject from './addFileToProject'; +import addProjectToLibraries from './addProjectToLibraries'; +import addSharedLibraries from './addSharedLibraries'; /** * Register native module IOS adds given dependency to project by adding diff --git a/packages/cli/src/link/ios/removeFromHeaderSearchPaths.js b/packages/cli/src/link/ios/removeFromHeaderSearchPaths.js index 10c6b3cfd..d19c05725 100644 --- a/packages/cli/src/link/ios/removeFromHeaderSearchPaths.js +++ b/packages/cli/src/link/ios/removeFromHeaderSearchPaths.js @@ -7,7 +7,7 @@ * @format */ -const mapHeaderSearchPaths = require('./mapHeaderSearchPaths'); +import mapHeaderSearchPaths from './mapHeaderSearchPaths'; /** * Given Xcode project and absolute path, it makes sure there are no headers referring to it diff --git a/packages/cli/src/link/ios/removeFromStaticLibraries.js b/packages/cli/src/link/ios/removeFromStaticLibraries.js index 7beaf8804..acc7f44c6 100644 --- a/packages/cli/src/link/ios/removeFromStaticLibraries.js +++ b/packages/cli/src/link/ios/removeFromStaticLibraries.js @@ -7,8 +7,8 @@ * @format */ -const PbxFile = require('xcode/lib/pbxFile'); -const removeFromPbxReferenceProxySection = require('./removeFromPbxReferenceProxySection'); +import PbxFile from 'xcode/lib/pbxFile'; +import removeFromPbxReferenceProxySection from './removeFromPbxReferenceProxySection'; /** * Removes file from static libraries diff --git a/packages/cli/src/link/ios/removeProjectFromProject.js b/packages/cli/src/link/ios/removeProjectFromProject.js index fbae783f4..baff8cba9 100644 --- a/packages/cli/src/link/ios/removeProjectFromProject.js +++ b/packages/cli/src/link/ios/removeProjectFromProject.js @@ -7,10 +7,10 @@ * @format */ -const PbxFile = require('xcode/lib/pbxFile'); -const removeFromPbxItemContainerProxySection = require('./removeFromPbxItemContainerProxySection'); -const removeFromProjectReferences = require('./removeFromProjectReferences'); -const removeProductGroup = require('./removeProductGroup'); +import PbxFile from 'xcode/lib/pbxFile'; +import removeFromPbxItemContainerProxySection from './removeFromPbxItemContainerProxySection'; +import removeFromProjectReferences from './removeFromProjectReferences'; +import removeProductGroup from './removeProductGroup'; /** * Given xcodeproj and filePath, it creates new file diff --git a/packages/cli/src/link/ios/unlinkAssets.js b/packages/cli/src/link/ios/unlinkAssets.js index 8e4ef502e..d76a70784 100644 --- a/packages/cli/src/link/ios/unlinkAssets.js +++ b/packages/cli/src/link/ios/unlinkAssets.js @@ -6,15 +6,15 @@ * */ -const fs = require('fs-extra'); -const path = require('path'); -const xcode = require('xcode'); -const { difference } = require('lodash'); -const log = require('../../util/logger'); - -const groupFilesByType = require('../groupFilesByType'); -const getPlist = require('./getPlist'); -const writePlist = require('./writePlist'); +import fs from 'fs-extra'; +import path from 'path'; +import xcode from 'xcode'; +import { difference } from 'lodash'; +import log from '../../util/logger'; + +import groupFilesByType from '../groupFilesByType'; +import getPlist from './getPlist'; +import writePlist from './writePlist'; /** * Unlinks assets from iOS project. Removes references for fonts from `Info.plist` diff --git a/packages/cli/src/link/ios/unregisterNativeModule.js b/packages/cli/src/link/ios/unregisterNativeModule.js index 71b1f2ced..f2096aaa4 100644 --- a/packages/cli/src/link/ios/unregisterNativeModule.js +++ b/packages/cli/src/link/ios/unregisterNativeModule.js @@ -7,20 +7,20 @@ * @format */ -const xcode = require('xcode'); -const path = require('path'); -const fs = require('fs'); -const { difference, isEmpty } = require('lodash'); +import xcode from 'xcode'; +import path from 'path'; +import fs from 'fs'; +import { difference, isEmpty } from 'lodash'; -const getGroup = require('./getGroup'); -const getTargets = require('./getTargets'); -const getHeadersInFolder = require('./getHeadersInFolder'); -const getHeaderSearchPath = require('./getHeaderSearchPath'); -const removeProjectFromProject = require('./removeProjectFromProject'); -const removeProjectFromLibraries = require('./removeProjectFromLibraries'); -const removeFromStaticLibraries = require('./removeFromStaticLibraries'); -const removeFromHeaderSearchPaths = require('./removeFromHeaderSearchPaths'); -const removeSharedLibraries = require('./removeSharedLibraries'); +import getGroup from './getGroup'; +import getTargets from './getTargets'; +import getHeadersInFolder from './getHeadersInFolder'; +import getHeaderSearchPath from './getHeaderSearchPath'; +import removeProjectFromProject from './removeProjectFromProject'; +import removeProjectFromLibraries from './removeProjectFromLibraries'; +import removeFromStaticLibraries from './removeFromStaticLibraries'; +import removeFromHeaderSearchPaths from './removeFromHeaderSearchPaths'; +import removeSharedLibraries from './removeSharedLibraries'; /** * Unregister native module IOS diff --git a/packages/cli/src/link/ios/writePlist.js b/packages/cli/src/link/ios/writePlist.js index a0477bd48..143b19dff 100644 --- a/packages/cli/src/link/ios/writePlist.js +++ b/packages/cli/src/link/ios/writePlist.js @@ -7,9 +7,9 @@ * @format */ -const plistParser = require('plist'); -const fs = require('fs'); -const getPlistPath = require('./getPlistPath'); +import plistParser from 'plist'; +import fs from 'fs'; +import getPlistPath from './getPlistPath'; /** * Writes to Info.plist located in the iOS project diff --git a/packages/cli/src/link/link.js b/packages/cli/src/link/link.js index c83522677..8839df34b 100644 --- a/packages/cli/src/link/link.js +++ b/packages/cli/src/link/link.js @@ -8,20 +8,20 @@ * @flow */ +import { pick } from 'lodash'; import type { ContextT } from '../core/types.flow'; -const { pick } = require('lodash'); -const promiseWaterfall = require('./promiseWaterfall'); -const log = require('../util/logger'); -const getDependencyConfig = require('./getDependencyConfig'); -const commandStub = require('./commandStub'); -const promisify = require('./promisify'); -const getProjectConfig = require('./getProjectConfig'); -const linkDependency = require('./linkDependency'); -const linkAssets = require('./linkAssets'); -const linkAll = require('./linkAll'); -const findReactNativeScripts = require('../util/findReactNativeScripts'); -const getPlatforms = require('../core/getPlatforms'); +import promiseWaterfall from './promiseWaterfall'; +import log from '../util/logger'; +import getDependencyConfig from './getDependencyConfig'; +import commandStub from './commandStub'; +import promisify from './promisify'; +import getProjectConfig from './getProjectConfig'; +import linkDependency from './linkDependency'; +import linkAssets from './linkAssets'; +import linkAll from './linkAll'; +import findReactNativeScripts from '../util/findReactNativeScripts'; +import getPlatforms from '../core/getPlatforms'; type FlagsType = { platforms: Array, diff --git a/packages/cli/src/link/linkAll.js b/packages/cli/src/link/linkAll.js index 1d99b01e6..11eb6812c 100644 --- a/packages/cli/src/link/linkAll.js +++ b/packages/cli/src/link/linkAll.js @@ -1,18 +1,17 @@ // @flow +import { uniqBy, flatten } from 'lodash'; +import path from 'path'; import type { ContextT, PlatformsT, ProjectConfigT } from '../core/types.flow'; - -const { uniqBy, flatten } = require('lodash'); -const path = require('path'); -const log = require('../util/logger'); -const getAssets = require('../core/getAssets'); -const getProjectDependencies = require('./getProjectDependencies'); -const getDependencyConfig = require('./getDependencyConfig'); -const promiseWaterfall = require('./promiseWaterfall'); -const commandStub = require('./commandStub'); -const promisify = require('./promisify'); -const linkAssets = require('./linkAssets'); -const linkDependency = require('./linkDependency'); +import log from '../util/logger'; +import getAssets from '../core/getAssets'; +import getProjectDependencies from './getProjectDependencies'; +import getDependencyConfig from './getDependencyConfig'; +import promiseWaterfall from './promiseWaterfall'; +import commandStub from './commandStub'; +import promisify from './promisify'; +import linkAssets from './linkAssets'; +import linkDependency from './linkDependency'; const dedupeAssets = assets => uniqBy(assets, asset => path.basename(asset)); diff --git a/packages/cli/src/link/linkAssets.js b/packages/cli/src/link/linkAssets.js index 1d629392a..197b2ca76 100644 --- a/packages/cli/src/link/linkAssets.js +++ b/packages/cli/src/link/linkAssets.js @@ -1,9 +1,9 @@ // @flow +import { isEmpty } from 'lodash'; import type { PlatformsT, ProjectConfigT } from '../core/types.flow'; -const { isEmpty } = require('lodash'); -const log = require('../util/logger'); +import log from '../util/logger'; const linkAssets = ( platforms: PlatformsT, diff --git a/packages/cli/src/link/linkDependency.js b/packages/cli/src/link/linkDependency.js index ef9489053..dd8892767 100644 --- a/packages/cli/src/link/linkDependency.js +++ b/packages/cli/src/link/linkDependency.js @@ -1,10 +1,10 @@ // @flow +import chalk from 'chalk'; import type { PlatformsT, ProjectConfigT } from '../core/types.flow'; -const chalk = require('chalk'); -const log = require('../util/logger'); -const pollParams = require('./pollParams'); +import log from '../util/logger'; +import pollParams from './pollParams'; const linkDependency = async ( platforms: PlatformsT, diff --git a/packages/cli/src/link/pods/isInstalled.js b/packages/cli/src/link/pods/isInstalled.js index 35e484c70..062fa4c5a 100644 --- a/packages/cli/src/link/pods/isInstalled.js +++ b/packages/cli/src/link/pods/isInstalled.js @@ -7,7 +7,7 @@ * @format */ -const readPodfile = require('./readPodfile'); +import readPodfile from './readPodfile'; module.exports = function isInstalled(iOSProject, dependencyConfig) { if (!iOSProject.podfile) { diff --git a/packages/cli/src/link/pods/readPodfile.js b/packages/cli/src/link/pods/readPodfile.js index 0e86affa2..8d2b18725 100644 --- a/packages/cli/src/link/pods/readPodfile.js +++ b/packages/cli/src/link/pods/readPodfile.js @@ -7,7 +7,7 @@ * @format */ -const fs = require('fs'); +import fs from 'fs'; module.exports = function readPodfile(podfilePath) { const podContent = fs.readFileSync(podfilePath, 'utf8'); diff --git a/packages/cli/src/link/pods/registerNativeModule.js b/packages/cli/src/link/pods/registerNativeModule.js index b8d96517e..5ff0c9a26 100644 --- a/packages/cli/src/link/pods/registerNativeModule.js +++ b/packages/cli/src/link/pods/registerNativeModule.js @@ -7,12 +7,12 @@ * @format */ -const readPodfile = require('./readPodfile'); -const findPodTargetLine = require('./findPodTargetLine'); -const findLineToAddPod = require('./findLineToAddPod'); -const findMarkedLinesInPodfile = require('./findMarkedLinesInPodfile'); -const addPodEntry = require('./addPodEntry'); -const savePodFile = require('./savePodFile'); +import readPodfile from './readPodfile'; +import findPodTargetLine from './findPodTargetLine'; +import findLineToAddPod from './findLineToAddPod'; +import findMarkedLinesInPodfile from './findMarkedLinesInPodfile'; +import addPodEntry from './addPodEntry'; +import savePodFile from './savePodFile'; module.exports = function registerNativeModulePods( name, diff --git a/packages/cli/src/link/pods/savePodFile.js b/packages/cli/src/link/pods/savePodFile.js index adb3baf53..1fbfac687 100644 --- a/packages/cli/src/link/pods/savePodFile.js +++ b/packages/cli/src/link/pods/savePodFile.js @@ -7,7 +7,7 @@ * @format */ -const fs = require('fs'); +import fs from 'fs'; module.exports = function savePodFile(podfilePath, podLines) { const newPodfile = podLines.join('\n'); diff --git a/packages/cli/src/link/pods/unregisterNativeModule.js b/packages/cli/src/link/pods/unregisterNativeModule.js index 235dd11c7..451f3b650 100644 --- a/packages/cli/src/link/pods/unregisterNativeModule.js +++ b/packages/cli/src/link/pods/unregisterNativeModule.js @@ -7,8 +7,8 @@ * @format */ -const fs = require('fs'); -const removePodEntry = require('./removePodEntry'); +import fs from 'fs'; +import removePodEntry from './removePodEntry'; /** * Unregister native module IOS with CocoaPods diff --git a/packages/cli/src/link/pollParams.js b/packages/cli/src/link/pollParams.js index 039160c33..3badacefc 100644 --- a/packages/cli/src/link/pollParams.js +++ b/packages/cli/src/link/pollParams.js @@ -7,7 +7,7 @@ * @format */ -const inquirer = require('inquirer'); +import inquirer from 'inquirer'; module.exports = questions => new Promise((resolve, reject) => { diff --git a/packages/cli/src/link/unlink.js b/packages/cli/src/link/unlink.js index 519b4a7ba..d1348abf4 100644 --- a/packages/cli/src/link/unlink.js +++ b/packages/cli/src/link/unlink.js @@ -7,18 +7,18 @@ * @flow */ +import { flatten, isEmpty, difference } from 'lodash'; import type { ContextT } from '../core/types.flow'; -const { flatten, isEmpty, difference } = require('lodash'); -const log = require('../util/logger'); -const getProjectConfig = require('./getProjectConfig'); -const getDependencyConfig = require('./getDependencyConfig'); -const getProjectDependencies = require('./getProjectDependencies'); -const promiseWaterfall = require('./promiseWaterfall'); -const commandStub = require('./commandStub'); -const promisify = require('./promisify'); +import log from '../util/logger'; +import getProjectConfig from './getProjectConfig'; +import getDependencyConfig from './getDependencyConfig'; +import getProjectDependencies from './getProjectDependencies'; +import promiseWaterfall from './promiseWaterfall'; +import commandStub from './commandStub'; +import promisify from './promisify'; -const getPlatforms = require('../core/getPlatforms'); +import getPlatforms from '../core/getPlatforms'; const unlinkDependency = ( platforms, diff --git a/packages/cli/src/logAndroid/logAndroid.js b/packages/cli/src/logAndroid/logAndroid.js index 41a0f6e60..28b05e961 100644 --- a/packages/cli/src/logAndroid/logAndroid.js +++ b/packages/cli/src/logAndroid/logAndroid.js @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -const { spawnSync } = require('child_process'); -const logger = require('../util/logger'); +import { spawnSync } from 'child_process'; +import logger from '../util/logger'; /** * Starts adb logcat diff --git a/packages/cli/src/logIOS/logIOS.js b/packages/cli/src/logIOS/logIOS.js index 098815215..8b3c92845 100644 --- a/packages/cli/src/logIOS/logIOS.js +++ b/packages/cli/src/logIOS/logIOS.js @@ -7,10 +7,10 @@ * @format */ -const { execFileSync, spawnSync } = require('child_process'); -const os = require('os'); -const path = require('path'); -const logger = require('../util/logger'); +import { execFileSync, spawnSync } from 'child_process'; +import os from 'os'; +import path from 'path'; +import logger from '../util/logger'; function findAvailableDevice(devices) { for (const key of Object.keys(devices)) { diff --git a/packages/cli/src/runAndroid/adb.js b/packages/cli/src/runAndroid/adb.js index 27f03054d..e7fa62580 100644 --- a/packages/cli/src/runAndroid/adb.js +++ b/packages/cli/src/runAndroid/adb.js @@ -8,7 +8,7 @@ * @flow strict */ -const { execSync } = require('child_process'); +import { execSync } from 'child_process'; /** * Parses the output of the 'adb devices' command diff --git a/packages/cli/src/runAndroid/runAndroid.js b/packages/cli/src/runAndroid/runAndroid.js index 121816fd8..b024c0915 100644 --- a/packages/cli/src/runAndroid/runAndroid.js +++ b/packages/cli/src/runAndroid/runAndroid.js @@ -9,19 +9,20 @@ /* eslint-disable consistent-return */ +import path from 'path'; +import { spawnSync, spawn, execFileSync } from 'child_process'; +import fs from 'fs'; +import isString from 'lodash/isString'; + +import isPackagerRunning from '../util/isPackagerRunning'; import type { ContextT } from '../core/types.flow'; -const { spawnSync, spawn, execFileSync } = require('child_process'); -const fs = require('fs'); -const isString = require('lodash/isString'); -const path = require('path'); -const isPackagerRunning = require('../util/isPackagerRunning'); -const logger = require('../util/logger'); -const adb = require('./adb'); -const runOnAllDevices = require('./runOnAllDevices'); -const tryRunAdbReverse = require('./tryRunAdbReverse'); -const tryLaunchAppOnDevice = require('./tryLaunchAppOnDevice'); -const getAdbPath = require('./getAdbPath'); +import adb from './adb'; +import runOnAllDevices from './runOnAllDevices'; +import tryRunAdbReverse from './tryRunAdbReverse'; +import tryLaunchAppOnDevice from './tryLaunchAppOnDevice'; +import getAdbPath from './getAdbPath'; +import logger from '../util/logger'; // Verifies this is an Android project function checkAndroid(root) { diff --git a/packages/cli/src/runAndroid/runOnAllDevices.js b/packages/cli/src/runAndroid/runOnAllDevices.js index ecd3e2d9b..29568b5b0 100644 --- a/packages/cli/src/runAndroid/runOnAllDevices.js +++ b/packages/cli/src/runAndroid/runOnAllDevices.js @@ -9,11 +9,11 @@ /* eslint-disable consistent-return */ -const { spawnSync, execFileSync } = require('child_process'); -const logger = require('../util/logger'); -const adb = require('./adb'); -const tryRunAdbReverse = require('./tryRunAdbReverse'); -const tryLaunchAppOnDevice = require('./tryLaunchAppOnDevice'); +import { spawnSync, execFileSync } from 'child_process'; +import logger from '../util/logger'; +import adb from './adb'; +import tryRunAdbReverse from './tryRunAdbReverse'; +import tryLaunchAppOnDevice from './tryLaunchAppOnDevice'; function getCommand(appFolder, command) { return appFolder ? `${appFolder}:${command}` : command; diff --git a/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js b/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js index fac8f3465..5ef9b567d 100644 --- a/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js +++ b/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js @@ -7,8 +7,8 @@ * @flow */ -const { spawnSync } = require('child_process'); -const logger = require('../util/logger'); +import { spawnSync } from 'child_process'; +import logger from '../util/logger'; function tryLaunchAppOnDevice( device: string, diff --git a/packages/cli/src/runAndroid/tryRunAdbReverse.js b/packages/cli/src/runAndroid/tryRunAdbReverse.js index f45fb23e8..89dda62a1 100644 --- a/packages/cli/src/runAndroid/tryRunAdbReverse.js +++ b/packages/cli/src/runAndroid/tryRunAdbReverse.js @@ -7,9 +7,9 @@ * @flow */ -const { execFileSync } = require('child_process'); -const logger = require('../util/logger'); -const getAdbPath = require('./getAdbPath'); +import { execFileSync } from 'child_process'; +import logger from '../util/logger'; +import getAdbPath from './getAdbPath'; // Runs ADB reverse tcp:8081 tcp:8081 to allow loading the jsbundle from the packager function tryRunAdbReverse(packagerPort: number | string, device: string) { diff --git a/packages/cli/src/runIOS/findXcodeProject.js b/packages/cli/src/runIOS/findXcodeProject.js index 5e94e7928..7dd95c25c 100644 --- a/packages/cli/src/runIOS/findXcodeProject.js +++ b/packages/cli/src/runIOS/findXcodeProject.js @@ -8,7 +8,7 @@ * @flow strict */ -const path = require('path'); +import path from 'path'; type ProjectInfo = { name: string, diff --git a/packages/cli/src/runIOS/runIOS.js b/packages/cli/src/runIOS/runIOS.js index e137c97b9..2d6d37cb2 100644 --- a/packages/cli/src/runIOS/runIOS.js +++ b/packages/cli/src/runIOS/runIOS.js @@ -8,17 +8,16 @@ * @format */ -import type { ContextT } from '../core/types.flow'; - // eslint-disable-next-line -const child_process = require('child_process'); -const fs = require('fs'); -const path = require('path'); -const logger = require('../util/logger'); -const findXcodeProject = require('./findXcodeProject'); -const parseIOSDevicesList = require('./parseIOSDevicesList'); -const findMatchingSimulator = require('./findMatchingSimulator'); -const { ProcessError } = require('../util/errors'); +import child_process from 'child_process'; +import fs from 'fs'; +import path from 'path'; +import type { ContextT } from '../core/types.flow'; +import findXcodeProject from './findXcodeProject'; +import parseIOSDevicesList from './parseIOSDevicesList'; +import findMatchingSimulator from './findMatchingSimulator'; +import { ProcessError } from '../util/errors'; +import logger from '../util/logger'; type FlagsT = { simulator: string, diff --git a/packages/cli/src/server/middleware/MiddlewareManager.js b/packages/cli/src/server/middleware/MiddlewareManager.js index c1c529432..ccad367cc 100644 --- a/packages/cli/src/server/middleware/MiddlewareManager.js +++ b/packages/cli/src/server/middleware/MiddlewareManager.js @@ -8,21 +8,21 @@ * @flow */ -const compression = require('compression'); -const connect = require('connect'); -const errorhandler = require('errorhandler'); -const path = require('path'); -const serveStatic = require('serve-static'); -const WebSocketServer = require('ws').Server; +import compression from 'compression'; +import connect from 'connect'; +import errorhandler from 'errorhandler'; +import path from 'path'; +import serveStatic from 'serve-static'; +import { Server as WebSocketServer } from 'ws'; -const indexPageMiddleware = require('./indexPage'); -const copyToClipBoardMiddleware = require('./copyToClipBoardMiddleware'); -const getSecurityHeadersMiddleware = require('./getSecurityHeadersMiddleware'); -const loadRawBodyMiddleware = require('./loadRawBodyMiddleware'); -const openStackFrameInEditorMiddleware = require('./openStackFrameInEditorMiddleware'); -const statusPageMiddleware = require('./statusPageMiddleware'); -const systraceProfileMiddleware = require('./systraceProfileMiddleware'); -const getDevToolsMiddleware = require('./getDevToolsMiddleware'); +import indexPageMiddleware from './indexPage'; +import copyToClipBoardMiddleware from './copyToClipBoardMiddleware'; +import getSecurityHeadersMiddleware from './getSecurityHeadersMiddleware'; +import loadRawBodyMiddleware from './loadRawBodyMiddleware'; +import openStackFrameInEditorMiddleware from './openStackFrameInEditorMiddleware'; +import statusPageMiddleware from './statusPageMiddleware'; +import systraceProfileMiddleware from './systraceProfileMiddleware'; +import getDevToolsMiddleware from './getDevToolsMiddleware'; type Options = { +watchFolders: $ReadOnlyArray, diff --git a/packages/cli/src/server/middleware/copyToClipBoardMiddleware.js b/packages/cli/src/server/middleware/copyToClipBoardMiddleware.js index 9346ea693..18b1ef311 100644 --- a/packages/cli/src/server/middleware/copyToClipBoardMiddleware.js +++ b/packages/cli/src/server/middleware/copyToClipBoardMiddleware.js @@ -7,8 +7,8 @@ * @format */ -const copyToClipBoard = require('../util/copyToClipBoard'); -const logger = require('../../util/logger'); +import copyToClipBoard from '../util/copyToClipBoard'; +import logger from '../../util/logger'; /** * Handle the request from JS to copy contents onto host system clipboard. diff --git a/packages/cli/src/server/middleware/getDevToolsMiddleware.js b/packages/cli/src/server/middleware/getDevToolsMiddleware.js index 489c30aed..8d634b928 100644 --- a/packages/cli/src/server/middleware/getDevToolsMiddleware.js +++ b/packages/cli/src/server/middleware/getDevToolsMiddleware.js @@ -6,8 +6,8 @@ * * @format */ -const launchChrome = require('../util/launchChrome'); -const logger = require('../../util/logger'); +import launchChrome from '../util/launchChrome'; +import logger from '../../util/logger'; function launchChromeDevTools(host, port, args = '') { const debuggerURL = `http://${host}:${port}/debugger-ui${args}`; diff --git a/packages/cli/src/server/middleware/indexPage.js b/packages/cli/src/server/middleware/indexPage.js index 7407bc20a..9b972651a 100644 --- a/packages/cli/src/server/middleware/indexPage.js +++ b/packages/cli/src/server/middleware/indexPage.js @@ -7,8 +7,8 @@ * @format */ -const fs = require('fs'); -const path = require('path'); +import fs from 'fs'; +import path from 'path'; module.exports = function indexPageMiddleware(req, res, next) { if (req.url === '/') { diff --git a/packages/cli/src/server/middleware/openStackFrameInEditorMiddleware.js b/packages/cli/src/server/middleware/openStackFrameInEditorMiddleware.js index 0c53c55f1..bf1880706 100644 --- a/packages/cli/src/server/middleware/openStackFrameInEditorMiddleware.js +++ b/packages/cli/src/server/middleware/openStackFrameInEditorMiddleware.js @@ -7,7 +7,7 @@ * @format */ -const launchEditor = require('../util/launchEditor'); +import launchEditor from '../util/launchEditor'; module.exports = function getOpenStackFrameInEditorMiddleware({ watchFolders, diff --git a/packages/cli/src/server/middleware/systraceProfileMiddleware.js b/packages/cli/src/server/middleware/systraceProfileMiddleware.js index 5ad2a1069..45f44ceb6 100644 --- a/packages/cli/src/server/middleware/systraceProfileMiddleware.js +++ b/packages/cli/src/server/middleware/systraceProfileMiddleware.js @@ -7,8 +7,8 @@ * @format */ -const fs = require('fs'); -const logger = require('../../util/logger'); +import fs from 'fs'; +import logger from '../../util/logger'; module.exports = function systraceProfileMiddleware(req, res, next) { if (req.url !== '/systrace') { diff --git a/packages/cli/src/server/runServer.js b/packages/cli/src/server/runServer.js index 0214299c4..be9024726 100644 --- a/packages/cli/src/server/runServer.js +++ b/packages/cli/src/server/runServer.js @@ -7,19 +7,18 @@ * @flow */ -import type { ContextT } from '../core/types.flow'; - -const Metro = require('metro'); +import Metro from 'metro'; -const { Terminal } = require('metro-core'); +import { Terminal } from 'metro-core'; -const morgan = require('morgan'); -const path = require('path'); -const messageSocket = require('./util/messageSocket'); -const webSocketProxy = require('./util/webSocketProxy'); -const MiddlewareManager = require('./middleware/MiddlewareManager'); +import morgan from 'morgan'; +import path from 'path'; +import type { ContextT } from '../core/types.flow'; +import messageSocket from './util/messageSocket'; +import webSocketProxy from './util/webSocketProxy'; +import MiddlewareManager from './middleware/MiddlewareManager'; -const loadMetroConfig = require('../util/loadMetroConfig'); +import loadMetroConfig from '../util/loadMetroConfig'; export type Args = {| assetExts?: string[], diff --git a/packages/cli/src/server/server.js b/packages/cli/src/server/server.js index c6eed0d37..737c6f3ed 100644 --- a/packages/cli/src/server/server.js +++ b/packages/cli/src/server/server.js @@ -8,7 +8,7 @@ * @flow */ -const path = require('path'); +import path from 'path'; module.exports = { name: 'start', diff --git a/packages/cli/src/server/util/copyToClipBoard.js b/packages/cli/src/server/util/copyToClipBoard.js index ebc728ccc..4f9173c67 100644 --- a/packages/cli/src/server/util/copyToClipBoard.js +++ b/packages/cli/src/server/util/copyToClipBoard.js @@ -7,10 +7,10 @@ * @format */ -const { spawn } = require('child_process'); +import { spawn } from 'child_process'; -const path = require('path'); -const fs = require('fs'); +import path from 'path'; +import fs from 'fs'; const xsel = path.join(__dirname, 'external/xsel'); fs.chmodSync(xsel, '0755'); diff --git a/packages/cli/src/server/util/debugger-ui/DeltaPatcher.js b/packages/cli/src/server/util/debugger-ui/DeltaPatcher.js index ed950295f..7793792f4 100644 --- a/packages/cli/src/server/util/debugger-ui/DeltaPatcher.js +++ b/packages/cli/src/server/util/debugger-ui/DeltaPatcher.js @@ -55,7 +55,7 @@ // Make sure that the first received bundle is a base. if (!this._initialized && !bundle.base) { throw new Error( - 'DeltaPatcher should receive a base Bundle when being initialized', + 'DeltaPatcher should receive a base Bundle when being initialized' ); } @@ -120,7 +120,7 @@ return [].concat( [this._lastBundle.pre], Array.from(this._lastBundle.modules.values()), - [this._lastBundle.post], + [this._lastBundle.post] ); } } diff --git a/packages/cli/src/server/util/debugger-ui/debuggerWorker.js b/packages/cli/src/server/util/debugger-ui/debuggerWorker.js index 070d753b7..4873b4193 100644 --- a/packages/cli/src/server/util/debugger-ui/debuggerWorker.js +++ b/packages/cli/src/server/util/debugger-ui/debuggerWorker.js @@ -25,7 +25,7 @@ onmessage = (function() { console.warn( 'Remote debugger is in a background tab which may cause apps to ' + 'perform slowly. Fix this by foregrounding the tab (or opening it in ' + - 'a separate window).', + 'a separate window).' ); }; })(); @@ -56,7 +56,7 @@ onmessage = (function() { var object = message.data; var sendReply = function(result, error) { - postMessage({replyID: object.id, result: result, error: error}); + postMessage({ replyID: object.id, result: result, error: error }); }; var handler = messageHandlers[object.method]; @@ -71,7 +71,7 @@ onmessage = (function() { if (typeof __fbBatchedBridge === 'object') { returnValue = __fbBatchedBridge[object.method].apply( null, - object.arguments, + object.arguments ); } else { error = 'Failed to call function, __fbBatchedBridge is undefined'; diff --git a/packages/cli/src/server/util/jsPackagerClient.js b/packages/cli/src/server/util/jsPackagerClient.js index 101e98f66..5ead40e34 100644 --- a/packages/cli/src/server/util/jsPackagerClient.js +++ b/packages/cli/src/server/util/jsPackagerClient.js @@ -7,9 +7,9 @@ * @format */ -const WebSocket = require('ws'); -const logger = require('../../util/logger'); -const { parseMessage } = require('./messageSocket'); +import WebSocket from 'ws'; +import logger from '../../util/logger'; +import MessageSocket from './messageSocket'; const PROTOCOL_VERSION = 2; const TARGET_SERVER = 'server'; @@ -29,7 +29,7 @@ class JsPackagerClient { }); this.ws.on('message', (data, flags) => { - const message = parseMessage(data, flags.binary); + const message = MessageSocket.parseMessage(data, flags.binary); const msgCallback = this.msgCallbacks.get(message.id); if (message === undefined || message.id === undefined) { // gracefully ignore wrong messages or broadcasts diff --git a/packages/cli/src/server/util/launchChrome.js b/packages/cli/src/server/util/launchChrome.js index 56172d6bc..3c8f105f8 100644 --- a/packages/cli/src/server/util/launchChrome.js +++ b/packages/cli/src/server/util/launchChrome.js @@ -11,9 +11,9 @@ /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error * found when Flow v0.54 was deployed. To see the error delete this comment and * run Flow. */ -const opn = require('opn'); -const { execSync } = require('child_process'); -const logger = require('../../util/logger'); +import opn from 'opn'; +import { execSync } from 'child_process'; +import logger from '../../util/logger'; function commandExistsUnixSync(commandName) { try { diff --git a/packages/cli/src/server/util/launchEditor.js b/packages/cli/src/server/util/launchEditor.js index 406683cfc..8b3d6aef3 100644 --- a/packages/cli/src/server/util/launchEditor.js +++ b/packages/cli/src/server/util/launchEditor.js @@ -7,12 +7,12 @@ * @format */ -const chalk = require('chalk'); -const fs = require('fs'); -const path = require('path'); -const { execSync, spawn } = require('child_process'); -const shellQuote = require('shell-quote'); -const logger = require('../../util/logger'); +import chalk from 'chalk'; +import fs from 'fs'; +import path from 'path'; +import { execSync, spawn } from 'child_process'; +import shellQuote from 'shell-quote'; +import logger from '../../util/logger'; function isTerminalEditor(editor) { switch (editor) { diff --git a/packages/cli/src/server/util/messageSocket.js b/packages/cli/src/server/util/messageSocket.js index 95713e46a..38d9121fb 100644 --- a/packages/cli/src/server/util/messageSocket.js +++ b/packages/cli/src/server/util/messageSocket.js @@ -5,12 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -const url = require('url'); -const WebSocketServer = require('ws').Server; +import url from 'url'; +import { Server as WebSocketServer } from 'ws'; +import notifier from 'node-notifier'; +import logger from '../../util/logger'; const PROTOCOL_VERSION = 2; -const notifier = require('node-notifier'); -const logger = require('../../util/logger'); function parseMessage(data, binary) { if (binary) { @@ -232,7 +232,4 @@ function attachToServer(server, path) { }; } -module.exports = { - attachToServer, - parseMessage, -}; +export default { attachToServer, parseMessage }; diff --git a/packages/cli/src/upgrade/upgrade.js b/packages/cli/src/upgrade/upgrade.js index ce0d15a77..41dc635a9 100644 --- a/packages/cli/src/upgrade/upgrade.js +++ b/packages/cli/src/upgrade/upgrade.js @@ -8,13 +8,12 @@ * @flow */ +import fs from 'fs'; +import path from 'path'; +import semver from 'semver'; import type { ContextT } from '../core/types.flow'; - -const fs = require('fs'); -const path = require('path'); -const semver = require('semver'); -const copyProjectTemplateAndReplace = require('../generator/copyProjectTemplateAndReplace'); -const logger = require('../util/logger'); +import logger from '../util/logger'; +import copyProjectTemplateAndReplace from '../generator/copyProjectTemplateAndReplace'; /** * Migrate application to a new version of React Native. diff --git a/packages/cli/src/util/PackageManager.js b/packages/cli/src/util/PackageManager.js index ef6840170..807b87c01 100644 --- a/packages/cli/src/util/PackageManager.js +++ b/packages/cli/src/util/PackageManager.js @@ -7,8 +7,8 @@ * @format */ -const { spawnSync } = require('child_process'); -const yarn = require('../util/yarn'); +import { spawnSync } from 'child_process'; +import yarn from './yarn'; const spawnOpts = { stdio: 'inherit', diff --git a/packages/cli/src/util/assertRequiredOptions.js b/packages/cli/src/util/assertRequiredOptions.js index bddd4ebe3..40ff8e64c 100644 --- a/packages/cli/src/util/assertRequiredOptions.js +++ b/packages/cli/src/util/assertRequiredOptions.js @@ -7,8 +7,8 @@ * @format */ -const { Option } = require('commander'); -const { camelCase } = require('lodash'); +import { Option } from 'commander'; +import { camelCase } from 'lodash'; // Commander.js has a 2 years old open issue to support <...> syntax // for options. Until that gets merged, we run the checks manually diff --git a/packages/cli/src/util/copyAndReplace.js b/packages/cli/src/util/copyAndReplace.js index 9d9ec7c33..33a2dad33 100644 --- a/packages/cli/src/util/copyAndReplace.js +++ b/packages/cli/src/util/copyAndReplace.js @@ -7,8 +7,8 @@ * @format */ -const fs = require('fs'); -const path = require('path'); +import fs from 'fs'; +import path from 'path'; // Binary files, don't process these (avoid decoding as utf8) const binaryExtensions = ['.png', '.jar']; diff --git a/packages/cli/src/util/errors.js b/packages/cli/src/util/errors.js index 5581263df..278d35cc2 100644 --- a/packages/cli/src/util/errors.js +++ b/packages/cli/src/util/errors.js @@ -1,15 +1,11 @@ /** * @flow */ -const chalk = require('chalk'); +import chalk from 'chalk'; -class ProcessError extends Error { +export class ProcessError extends Error { constructor(msg: string, processError: string) { super(`${chalk.red(msg)}\n\n${chalk.gray(processError)}`); Error.captureStackTrace(this, ProcessError); } } - -module.exports = { - ProcessError, -}; diff --git a/packages/cli/src/util/findReactNativeScripts.js b/packages/cli/src/util/findReactNativeScripts.js index 0bacfc209..7a6c8fa23 100644 --- a/packages/cli/src/util/findReactNativeScripts.js +++ b/packages/cli/src/util/findReactNativeScripts.js @@ -8,8 +8,8 @@ * @flow strict */ -const path = require('path'); -const fs = require('fs'); +import path from 'path'; +import fs from 'fs'; function findReactNativeScripts(): ?string { const executablePath = path.resolve( diff --git a/packages/cli/src/util/findSymlinkedModules.js b/packages/cli/src/util/findSymlinkedModules.js index c64b65d7f..557efed21 100644 --- a/packages/cli/src/util/findSymlinkedModules.js +++ b/packages/cli/src/util/findSymlinkedModules.js @@ -8,8 +8,8 @@ * @flow strict */ -const path = require('path'); -const fs = require('fs'); +import path from 'path'; +import fs from 'fs'; /** * Find symlinked modules inside "node_modules." diff --git a/packages/cli/src/util/gracefulFs.js b/packages/cli/src/util/gracefulFs.js new file mode 100644 index 000000000..68b4affcd --- /dev/null +++ b/packages/cli/src/util/gracefulFs.js @@ -0,0 +1,6 @@ +import realFs from 'fs'; +import gracefulFs from 'graceful-fs'; + +gracefulFs.gracefulify(realFs); + +export default gracefulFs; diff --git a/packages/cli/src/util/isPackagerRunning.js b/packages/cli/src/util/isPackagerRunning.js index 57d2be844..51bd39201 100644 --- a/packages/cli/src/util/isPackagerRunning.js +++ b/packages/cli/src/util/isPackagerRunning.js @@ -7,7 +7,7 @@ * @format */ -const fetch = require('node-fetch'); +import fetch from 'node-fetch'; /** * Indicates whether or not the packager is running. It returns a promise that diff --git a/packages/cli/src/util/loadMetroConfig.js b/packages/cli/src/util/loadMetroConfig.js index eba5a9c33..2ee51498a 100644 --- a/packages/cli/src/util/loadMetroConfig.js +++ b/packages/cli/src/util/loadMetroConfig.js @@ -3,15 +3,12 @@ * @flow */ import type { ConfigT } from 'metro-config/src/configTypes.flow'; +import path from 'path'; +import { createBlacklist } from 'metro'; +import { loadConfig } from 'metro-config'; import type { ContextT } from '../core/types.flow'; - -const path = require('path'); - -const { createBlacklist } = require('metro'); -const { loadConfig } = require('metro-config'); -const findSymlinkedModules = require('./findSymlinkedModules'); - -const findPlugins = require('../core/findPlugins'); +import findPlugins from '../core/findPlugins'; +import findSymlinkedModules from './findSymlinkedModules'; const resolveSymlinksForRoots = roots => roots.reduce( diff --git a/packages/cli/src/util/logger.js b/packages/cli/src/util/logger.js index 8886d8d27..9ba26e747 100644 --- a/packages/cli/src/util/logger.js +++ b/packages/cli/src/util/logger.js @@ -1,7 +1,7 @@ /** * @flow */ -const chalk = require('chalk'); +import chalk from 'chalk'; const SEPARATOR = ', '; diff --git a/packages/cli/src/util/walk.js b/packages/cli/src/util/walk.js index 743c87e84..780803c4a 100644 --- a/packages/cli/src/util/walk.js +++ b/packages/cli/src/util/walk.js @@ -7,8 +7,8 @@ * @format */ -const fs = require('fs'); -const path = require('path'); +import fs from 'fs'; +import path from 'path'; function walk(current) { if (!fs.lstatSync(current).isDirectory()) { diff --git a/packages/cli/src/util/yarn.js b/packages/cli/src/util/yarn.js index ca12f1297..f0436e0e0 100644 --- a/packages/cli/src/util/yarn.js +++ b/packages/cli/src/util/yarn.js @@ -7,11 +7,11 @@ * @format */ -const { execSync } = require('child_process'); -const fs = require('fs'); -const path = require('path'); -const semver = require('semver'); -const logger = require('./logger'); +import { execSync } from 'child_process'; +import fs from 'fs'; +import path from 'path'; +import semver from 'semver'; +import logger from './logger'; /** * Use Yarn if available, it's much faster than the npm client.