Skip to content

Commit

Permalink
[WIP] Change require to imports (alt) (#150)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Sid Ferreira authored and grabbou committed Feb 5, 2019
1 parent b7d2c8f commit ef220e2
Show file tree
Hide file tree
Showing 129 changed files with 455 additions and 460 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/__mocks__/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/bundle/assetPathUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function getBasePath(asset: PackagerAsset) {
return basePath;
}

module.exports = {
export default {
getAndroidAssetSuffix,
getAndroidResourceFolderName,
getAndroidResourceIdentifier,
Expand Down
17 changes: 8 additions & 9 deletions packages/cli/src/bundle/buildBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/bundle/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -25,3 +25,7 @@ module.exports = {
// Used by `ramBundle.js`
withOutput: bundleWithOutput,
};

const withOutput = bundleWithOutput;

export { withOutput };
2 changes: 1 addition & 1 deletion packages/cli/src/bundle/bundleCommandLineArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

const path = require('path');
import path from 'path';

export type CommandLineArgs = {
assetsDest?: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/bundle/getAssetDestPathAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/bundle/getAssetDestPathIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/bundle/ramBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/src/bundle/saveAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 11 additions & 12 deletions packages/cli/src/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/core/__fixtures__/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/core/__fixtures__/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
* @format
*/

import path from 'path';

const fs = jest.requireActual('fs');
const path = require('path');

exports.valid = {
'demoProject.xcodeproj': {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/core/__fixtures__/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/core/android/findAndroidAppFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/core/android/findManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/core/android/findPackageClassName.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/core/android/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/core/android/readManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* @format
*/

const fs = require('fs');
const xml = require('xmldoc');
import fs from 'fs';
import xml from 'xmldoc';

/**
* @param {String} manifestPath
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/core/findPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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-/];

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/core/getAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/core/getCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/core/getHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/core/getLegacyConfig.js
Original file line number Diff line number Diff line change
@@ -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`;
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/core/getPackageConfiguration.js
Original file line number Diff line number Diff line change
@@ -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`.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/core/getParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @flow
*/

const getPackageConfiguration = require('./getPackageConfiguration');
import getPackageConfiguration from './getPackageConfiguration';

module.exports = function getParams(root: string) {
const config = getPackageConfiguration(root);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/core/getPlatforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/core/ios/findPodfilePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading

0 comments on commit ef220e2

Please sign in to comment.