Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use ESM exports where appropriate #151

Merged
merged 9 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/cli/src/__mocks__/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import path from 'path';
import MemoryFS from 'metro-memory-fs';
import util from 'util';

let fs;

Expand All @@ -26,7 +27,7 @@ function mockDir(dirPath, desc) {
continue; // eslint-disable-line no-continue
}
if (typeof ent !== 'object') {
throw new Error(require('util').format('invalid entity:', ent));
throw new Error(util.format('invalid entity:', ent));
}
if (ent.SYMLINK != null) {
fs.symlinkSync(ent.SYMLINK, entPath);
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import chalk from 'chalk';
import isInstalledGlobally from './util/isInstalledGlobally';
import logger from './util/logger';
import cliEntry from '.';

if (isInstalledGlobally()) {
logger.error(
Expand All @@ -25,5 +26,5 @@ if (isInstalledGlobally()) {
);
process.exit(1);
} else {
require('.').run();
cliEntry.run();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* @emails oncall+javascript_foundation
*/

jest.dontMock('../filterPlatformAssetScales').dontMock('../assetPathUtils');
import filterPlatformAssetScales from '../filterPlatformAssetScales';

const filterPlatformAssetScales = require('../filterPlatformAssetScales');
jest.dontMock('../filterPlatformAssetScales').dontMock('../assetPathUtils');

describe('filterPlatformAssetScales', () => {
it('removes everything but 2x and 3x for iOS', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
* @emails oncall+javascript_foundation
*/

import getAssetDestPathAndroid from '../getAssetDestPathAndroid';

jest.dontMock('../getAssetDestPathAndroid').dontMock('../assetPathUtils');

const path = require('path');
const getAssetDestPathAndroid = require('../getAssetDestPathAndroid');

describe('getAssetDestPathAndroid', () => {
it('should use the right destination folder', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
* @emails oncall+javascript_foundation
*/

import getAssetDestPathIOS from '../getAssetDestPathIOS';

jest.dontMock('../getAssetDestPathIOS');

const path = require('path');
const getAssetDestPathIOS = require('../getAssetDestPathIOS');

describe('getAssetDestPathIOS', () => {
it('should build correct path', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/bundle/buildBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ async function buildBundle(
}
}

module.exports = buildBundle;
export default buildBundle;
2 changes: 1 addition & 1 deletion packages/cli/src/bundle/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function bundleWithOutput(_, config, args, output) {
return buildBundle(args, config, output);
}

module.exports = {
export default {
name: 'bundle',
description: 'builds the javascript bundle for offline use',
func: bundleWithOutput,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/bundle/bundleCommandLineArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type CommandLineArgs = {
verbose: boolean,
};

module.exports = [
export default [
{
command: '--entry-file <path>',
description:
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/bundle/filterPlatformAssetScales.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ function filterPlatformAssetScales(
return result;
}

module.exports = filterPlatformAssetScales;
export default filterPlatformAssetScales;
2 changes: 1 addition & 1 deletion packages/cli/src/bundle/getAssetDestPathAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ function getAssetDestPathAndroid(asset: PackagerAsset, scale: number): string {
return path.join(androidFolder, `${fileName}.${asset.type}`);
}

module.exports = getAssetDestPathAndroid;
export default getAssetDestPathAndroid;
2 changes: 1 addition & 1 deletion packages/cli/src/bundle/getAssetDestPathIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ function getAssetDestPathIOS(asset: PackagerAsset, scale: number): string {
return path.join(asset.httpServerLocation.substr(1), fileName);
}

module.exports = getAssetDestPathIOS;
export default getAssetDestPathIOS;
2 changes: 1 addition & 1 deletion packages/cli/src/bundle/ramBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function ramBundle(argv, config, args) {
return bundleWithOutput(argv, config, args, outputUnbundle);
}

module.exports = {
export default {
name: 'ram-bundle',
description:
'builds javascript as a "Random Access Module" bundle for offline use',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/bundle/saveAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ function copy(src, dest, callback) {
});
}

module.exports = saveAssets;
export default saveAssets;
2 changes: 1 addition & 1 deletion packages/cli/src/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ async function setupAndRun() {
}
}

module.exports = {
export default {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether this shouldn't be export run and export init

run,
init,
};
2 changes: 1 addition & 1 deletion packages/cli/src/core/__fixtures__/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const fs = jest.requireActual('fs');

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

module.exports = {
export default {
valid: {
'package.json': pjson,
android: android.valid,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/core/__fixtures__/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ const withPods = {
ios: ios.pod,
};

module.exports = { flat, nested, withExamples, withPods };
export default { flat, nested, withExamples, withPods };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a series of named exports instead of an object?

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
* @emails oncall+javascript_foundation
*/

import findAndroidAppFolder from '../../android/findAndroidAppFolder';
import mocks from '../../__fixtures__/android';

jest.mock('path');
jest.mock('fs');

const fs = require('fs');
const findAndroidAppFolder = require('../../android/findAndroidAppFolder');
const mocks = require('../../__fixtures__/android');

describe('android::findAndroidAppFolder', () => {
beforeAll(() => {
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/core/__tests__/android/findManifest-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
* @emails oncall+javascript_foundation
*/

import findManifest from '../../android/findManifest';
import mocks from '../../__fixtures__/android';

jest.mock('path');
jest.mock('fs');

const fs = require('fs');
const findManifest = require('../../android/findManifest');
const mocks = require('../../__fixtures__/android');

describe('android::findManifest', () => {
beforeAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
* @emails oncall+javascript_foundation
*/

import mocks from '../../__fixtures__/android';
import findPackageClassName from '../../android/findPackageClassName';

jest.mock('path');
jest.mock('fs');

const fs = require('fs');
const mocks = require('../../__fixtures__/android');
const findPackageClassName = require('../../android/findPackageClassName');

['posix', 'win32'].forEach(platform => {
let root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* @emails oncall+javascript_foundation
*/

import mocks from '../../__fixtures__/android';

jest.mock('path');
jest.mock('fs');

const fs = require('fs');

const getDependencyConfig = require('../../android').dependencyConfig;
const mocks = require('../../__fixtures__/android');

const userConfig = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* @emails oncall+javascript_foundation
*/

import mocks from '../../__fixtures__/android';

jest.mock('path');
jest.mock('fs');

const fs = require('fs');

const getProjectConfig = require('../../android').projectConfig;
const mocks = require('../../__fixtures__/android');

describe('android::getProjectConfig', () => {
beforeAll(() => {
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/core/__tests__/android/readManifest-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* @emails oncall+javascript_foundation
*/

import findManifest from '../../android/findManifest';
import readManifest from '../../android/readManifest';
import mocks from '../../__fixtures__/android';

jest.mock('path');
jest.mock('fs');

const fs = require('fs');
const findManifest = require('../../android/findManifest');
const readManifest = require('../../android/readManifest');
const mocks = require('../../__fixtures__/android');

describe('android::readManifest', () => {
beforeAll(() => {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/core/__tests__/findAssets-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* @emails oncall+javascript_foundation
*/

import dependencies from '../__fixtures__/dependencies';

jest.mock('path');
jest.mock('fs');

const fs = require('fs');

const { findAssets } = require('../getAssets');
const dependencies = require('../__fixtures__/dependencies');

describe('findAssets', () => {
beforeEach(() => {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/core/__tests__/findPlugins-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
* @emails oncall+javascript_foundation
*/

import findPlugins from '../findPlugins';

const path = require('path');
thymikee marked this conversation as resolved.
Show resolved Hide resolved
const findPlugins = require('../findPlugins');

const ROOT = path.join(__dirname, '..', '..');
const pjsonPath = path.join(ROOT, './package.json');
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/core/__tests__/ios/findPodfilePath-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* @emails oncall+javascript_foundation
*/

import findPodfilePath from '../../ios/findPodfilePath';
import projects from '../../__fixtures__/projects';
import ios from '../../__fixtures__/ios';

jest.mock('path');
jest.mock('fs');

const fs = require('fs');
const findPodfilePath = require('../../ios/findPodfilePath');
const projects = require('../../__fixtures__/projects');
const ios = require('../../__fixtures__/ios');

describe('ios::findPodfilePath', () => {
it('returns null if there is no Podfile', () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/core/__tests__/ios/findPodspecName-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* @emails oncall+javascript_foundation
*/

import findPodspecName from '../../ios/findPodspecName';
import projects from '../../__fixtures__/projects';
import ios from '../../__fixtures__/ios';

jest.mock('path');
jest.mock('fs');

const fs = require('fs');
const findPodspecName = require('../../ios/findPodspecName');
const projects = require('../../__fixtures__/projects');
const ios = require('../../__fixtures__/ios');

describe('ios::findPodspecName', () => {
it('returns null if there is not podspec file', () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/core/__tests__/ios/findProject-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* @emails oncall+javascript_foundation
*/

import findProject from '../../ios/findProject';
import projects from '../../__fixtures__/projects';
import ios from '../../__fixtures__/ios';

jest.mock('path');
jest.mock('fs');

const fs = require('fs');
const findProject = require('../../ios/findProject');
const projects = require('../../__fixtures__/projects');
const ios = require('../../__fixtures__/ios');

describe('ios::findProject', () => {
it('returns path to xcodeproj if found', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/core/__tests__/ios/getProjectConfig-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* @emails oncall+javascript_foundation
*/

import projects from '../../__fixtures__/projects';

jest.mock('path');
jest.mock('fs');

const fs = require('fs');

const getProjectConfig = require('../../ios').projectConfig;
const projects = require('../../__fixtures__/projects');

describe('ios::getProjectConfig', () => {
const userConfig = {};
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 @@ -14,7 +14,7 @@ import path from 'path';
* @param {String} folder Folder to seek in
* @return {String}
*/
module.exports = function findAndroidAppFolder(folder) {
export default function findAndroidAppFolder(folder) {
const flat = 'android';
const nested = path.join('android', 'app');

Expand All @@ -27,4 +27,4 @@ module.exports = function findAndroidAppFolder(folder) {
}

return null;
};
}
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 @@ -16,11 +16,11 @@ import path from 'path';
* @param {String} folder Name of the folder where to seek
* @return {String}
*/
module.exports = function findManifest(folder) {
export default function findManifest(folder) {
const manifestPath = glob.sync(path.join('**', 'AndroidManifest.xml'), {
cwd: folder,
ignore: ['node_modules/**', '**/build/**', 'Examples/**', 'examples/**'],
})[0];

return manifestPath ? path.join(folder, manifestPath) : null;
};
}
4 changes: 2 additions & 2 deletions packages/cli/src/core/android/findPackageClassName.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import path from 'path';
*
* @param {String} folder Folder to find java/kt files
*/
module.exports = function getPackageClassName(folder) {
export default function getPackageClassName(folder) {
const files = glob.sync('**/+(*.java|*.kt)', { cwd: folder });

const packages = files
Expand All @@ -26,4 +26,4 @@ module.exports = function getPackageClassName(folder) {
.filter(match => match);

return packages.length ? packages[0][1] : null;
};
}
Loading