Skip to content

Commit b2a6359

Browse files
Sid Ferreiragrabbou
authored andcommitted
refactor: change require to imports (#150)
* refactor(imports): replaces most uses of require by import * fix: fixes export and revert wrong change * fix: fix import order * fix: revert export change * fix: revert global-cli/index * fix: typo
1 parent b7d2c8f commit b2a6359

File tree

129 files changed

+455
-460
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+455
-460
lines changed

packages/cli/src/__mocks__/fs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
const path = require('path');
9-
const MemoryFS = require('metro-memory-fs');
8+
import path from 'path';
9+
import MemoryFS from 'metro-memory-fs';
1010

1111
let fs;
1212

packages/cli/src/bin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* @format
1010
*/
1111

12-
const chalk = require('chalk');
13-
const isInstalledGlobally = require('./util/isInstalledGlobally');
14-
const logger = require('./util/logger');
12+
import chalk from 'chalk';
13+
import isInstalledGlobally from './util/isInstalledGlobally';
14+
import logger from './util/logger';
1515

1616
if (isInstalledGlobally()) {
1717
logger.error(

packages/cli/src/bundle/assetPathUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function getBasePath(asset: PackagerAsset) {
8181
return basePath;
8282
}
8383

84-
module.exports = {
84+
export default {
8585
getAndroidAssetSuffix,
8686
getAndroidResourceFolderName,
8787
getAndroidResourceIdentifier,

packages/cli/src/bundle/buildBundle.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
* @flow
88
*/
99

10-
import type { ContextT } from '../core/types.flow';
11-
import type { CommandLineArgs } from './bundleCommandLineArgs';
12-
13-
const Server = require('metro/src/Server');
10+
import Server from 'metro/src/Server';
1411

15-
const outputBundle = require('metro/src/shared/output/bundle');
16-
const path = require('path');
17-
const saveAssets = require('./saveAssets');
18-
const loadMetroConfig = require('../util/loadMetroConfig');
19-
const logger = require('../util/logger');
12+
import outputBundle from 'metro/src/shared/output/bundle';
13+
import path from 'path';
14+
import type { CommandLineArgs } from './bundleCommandLineArgs';
15+
import type { ContextT } from '../core/types.flow';
16+
import saveAssets from './saveAssets';
17+
import loadMetroConfig from '../util/loadMetroConfig';
18+
import logger from '../util/logger';
2019

2120
async function buildBundle(
2221
args: CommandLineArgs,

packages/cli/src/bundle/bundle.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @format
88
*/
99

10-
const buildBundle = require('./buildBundle');
11-
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
10+
import buildBundle from './buildBundle';
11+
import bundleCommandLineArgs from './bundleCommandLineArgs';
1212

1313
/**
1414
* Builds the bundle starting to look for dependencies at the given entry path.
@@ -25,3 +25,7 @@ module.exports = {
2525
// Used by `ramBundle.js`
2626
withOutput: bundleWithOutput,
2727
};
28+
29+
const withOutput = bundleWithOutput;
30+
31+
export { withOutput };

packages/cli/src/bundle/bundleCommandLineArgs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
const path = require('path');
10+
import path from 'path';
1111

1212
export type CommandLineArgs = {
1313
assetsDest?: string,

packages/cli/src/bundle/getAssetDestPathAndroid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
* @flow strict
99
*/
1010

11+
import path from 'path';
1112
import type { PackagerAsset } from './assetPathUtils';
1213

13-
const path = require('path');
14-
const assetPathUtils = require('./assetPathUtils');
14+
import assetPathUtils from './assetPathUtils';
1515

1616
function getAssetDestPathAndroid(asset: PackagerAsset, scale: number): string {
1717
const androidFolder = assetPathUtils.getAndroidResourceFolderName(

packages/cli/src/bundle/getAssetDestPathIOS.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
* @flow strict
99
*/
1010

11+
import path from 'path';
1112
import type { PackagerAsset } from './assetPathUtils';
1213

13-
const path = require('path');
14-
1514
function getAssetDestPathIOS(asset: PackagerAsset, scale: number): string {
1615
const suffix = scale === 1 ? '' : `@${scale}x`;
1716
const fileName = `${asset.name + suffix}.${asset.type}`;

packages/cli/src/bundle/ramBundle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
*
77
* @format
88
*/
9-
const outputUnbundle = require('metro/src/shared/output/RamBundle');
9+
import outputUnbundle from 'metro/src/shared/output/RamBundle';
1010

11-
const bundleWithOutput = require('./bundle').withOutput;
12-
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
11+
import { withOutput as bundleWithOutput } from './bundle';
12+
import bundleCommandLineArgs from './bundleCommandLineArgs';
1313

1414
/**
1515
* Builds the bundle starting to look for dependencies at the given entry path.

packages/cli/src/bundle/saveAssets.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
* @format
88
*/
99

10-
const mkdirp = require('mkdirp');
11-
const path = require('path');
12-
const fs = require('fs');
10+
import mkdirp from 'mkdirp';
11+
import path from 'path';
12+
import fs from 'fs';
1313

14-
const filterPlatformAssetScales = require('./filterPlatformAssetScales');
15-
const getAssetDestPathAndroid = require('./getAssetDestPathAndroid');
16-
const getAssetDestPathIOS = require('./getAssetDestPathIOS');
17-
const logger = require('../util/logger');
14+
import filterPlatformAssetScales from './filterPlatformAssetScales';
15+
import getAssetDestPathAndroid from './getAssetDestPathAndroid';
16+
import getAssetDestPathIOS from './getAssetDestPathIOS';
17+
import logger from '../util/logger';
1818

1919
function saveAssets(assets, platform, assetsDest) {
2020
if (!assetsDest) {

packages/cli/src/cliEntry.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@
88
* @flow
99
*/
1010

11+
import chalk from 'chalk';
12+
import childProcess from 'child_process';
13+
import commander from 'commander';
14+
import minimist from 'minimist';
15+
import path from 'path';
1116
import type { CommandT, ContextT } from './core/types.flow';
12-
13-
const chalk = require('chalk');
14-
const childProcess = require('child_process');
15-
const commander = require('commander');
16-
const minimist = require('minimist');
17-
const path = require('path');
18-
const getCommands = require('./core/getCommands');
19-
const getLegacyConfig = require('./core/getLegacyConfig');
20-
const init = require('./init/init');
21-
const assertRequiredOptions = require('./util/assertRequiredOptions');
22-
const logger = require('./util/logger');
23-
const pkg = require('../package.json');
17+
import getCommands from './core/getCommands';
18+
import getLegacyConfig from './core/getLegacyConfig';
19+
import init from './init/init';
20+
import assertRequiredOptions from './util/assertRequiredOptions';
21+
import logger from './util/logger';
22+
import pkg from '../package.json';
2423

2524
commander.version(pkg.version);
2625

packages/cli/src/core/__fixtures__/dependencies.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
* @format
88
*/
99

10+
import path from 'path';
11+
import android from './android';
12+
1013
const fs = jest.requireActual('fs');
11-
const path = require('path');
12-
const android = require('./android');
1314

1415
const pjson = fs.readFileSync(path.join(__dirname, 'files', 'package.json'));
1516

packages/cli/src/core/__fixtures__/ios.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
* @format
88
*/
99

10+
import path from 'path';
11+
1012
const fs = jest.requireActual('fs');
11-
const path = require('path');
1213

1314
exports.valid = {
1415
'demoProject.xcodeproj': {

packages/cli/src/core/__fixtures__/projects.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @format
88
*/
99

10-
const android = require('./android');
11-
const ios = require('./ios');
10+
import android from './android';
11+
import ios from './ios';
1212

1313
const flat = {
1414
android: android.valid,

packages/cli/src/core/android/findAndroidAppFolder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @format
88
*/
99

10-
const fs = require('fs');
11-
const path = require('path');
10+
import fs from 'fs';
11+
import path from 'path';
1212

1313
/**
1414
* @param {String} folder Folder to seek in

packages/cli/src/core/android/findManifest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @format
88
*/
99

10-
const glob = require('glob');
11-
const path = require('path');
10+
import glob from 'glob';
11+
import path from 'path';
1212

1313
/**
1414
* Find an android application path in the folder

packages/cli/src/core/android/findPackageClassName.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* @format
88
*/
99

10-
const fs = require('fs');
11-
const glob = require('glob');
12-
const path = require('path');
10+
import fs from 'fs';
11+
import glob from 'glob';
12+
import path from 'path';
1313

1414
/**
1515
* Gets package's class name (class that implements ReactPackage)

packages/cli/src/core/android/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
* @format
88
*/
99

10-
const path = require('path');
11-
const findAndroidAppFolder = require('./findAndroidAppFolder');
12-
const findManifest = require('./findManifest');
13-
const findPackageClassName = require('./findPackageClassName');
14-
const readManifest = require('./readManifest');
10+
import path from 'path';
11+
import findAndroidAppFolder from './findAndroidAppFolder';
12+
import findManifest from './findManifest';
13+
import findPackageClassName from './findPackageClassName';
14+
import readManifest from './readManifest';
1515

1616
const getPackageName = manifest => manifest.attr.package;
1717

packages/cli/src/core/android/readManifest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @format
88
*/
99

10-
const fs = require('fs');
11-
const xml = require('xmldoc');
10+
import fs from 'fs';
11+
import xml from 'xmldoc';
1212

1313
/**
1414
* @param {String} manifestPath

packages/cli/src/core/findPlugins.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @flow
88
*/
99

10-
const path = require('path');
11-
const { union, uniq, flatten } = require('lodash');
10+
import path from 'path';
11+
import { union, uniq, flatten } from 'lodash';
1212

1313
const RNPM_PLUGIN_PATTERNS = [/^rnpm-plugin-/, /^@(.*)\/rnpm-plugin-/];
1414

packages/cli/src/core/getAssets.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* @flow
33
*/
44

5-
const glob = require('glob');
6-
const path = require('path');
7-
const getPackageConfiguration = require('./getPackageConfiguration');
5+
import glob from 'glob';
6+
import path from 'path';
7+
import getPackageConfiguration from './getPackageConfiguration';
88

99
const findAssetsInFolder = folder =>
1010
glob.sync(path.join(folder, '**'), { nodir: true });

packages/cli/src/core/getCommands.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* @flow
33
*/
44

5+
import path from 'path';
56
import type { CommandT, ProjectCommandT, LocalCommandT } from './types.flow';
67

7-
const path = require('path');
8-
const findPlugins = require('./findPlugins');
9-
const logger = require('../util/logger');
8+
import findPlugins from './findPlugins';
9+
import logger from '../util/logger';
1010

1111
/**
1212
* List of built-in commands

packages/cli/src/core/getHooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* @flow
33
*/
44

5-
const { spawn } = require('child_process');
6-
const getPackageConfiguration = require('./getPackageConfiguration');
5+
import { spawn } from 'child_process';
6+
import getPackageConfiguration from './getPackageConfiguration';
77

88
function makeCommand(command) {
99
return cb => {

packages/cli/src/core/getLegacyConfig.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
22
* @flow
33
*/
4-
const path = require('path');
5-
const util = require('util');
6-
7-
const getPlatforms = require('./getPlatforms');
8-
const getPackageConfiguration = require('./getPackageConfiguration');
9-
const getHooks = require('./getHooks');
10-
const getAssets = require('./getAssets');
11-
const getParams = require('./getParams');
4+
import path from 'path';
5+
import util from 'util';
6+
7+
import getPlatforms from './getPlatforms';
8+
import getPackageConfiguration from './getPackageConfiguration';
9+
import getHooks from './getHooks';
10+
import getAssets from './getAssets';
11+
import getParams from './getParams';
1212

1313
const generateDeprecationMessage = api =>
1414
`${api} is deprecated and will be removed soon. Please check release notes on how to upgrade`;

packages/cli/src/core/getPackageConfiguration.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/**
22
* @flow
33
*/
4+
import path from 'path';
45
import type { PackageConfigurationT } from './types.flow';
56

6-
const path = require('path');
7-
87
/**
98
* Returns configuration of the CLI from `package.json`.
109
*/

packages/cli/src/core/getParams.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @flow
33
*/
44

5-
const getPackageConfiguration = require('./getPackageConfiguration');
5+
import getPackageConfiguration from './getPackageConfiguration';
66

77
module.exports = function getParams(root: string) {
88
const config = getPackageConfiguration(root);

packages/cli/src/core/getPlatforms.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* @flow
33
*/
44

5+
import path from 'path';
56
import type { PlatformsT } from './types.flow';
67

7-
const path = require('path');
8-
const findPlugins = require('./findPlugins');
8+
import findPlugins from './findPlugins';
99

1010
/**
1111
* Support for `ios` and `android` platforms is built-in

packages/cli/src/core/ios/findPodfilePath.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @format
88
*/
99

10-
const fs = require('fs');
11-
const path = require('path');
10+
import fs from 'fs';
11+
import path from 'path';
1212

1313
module.exports = function findPodfilePath(projectFolder) {
1414
const podFilePath = path.join(projectFolder, '..', 'Podfile');

0 commit comments

Comments
 (0)