From e53a9feb20e5851d29f0913fc6c2704dbe00af2e Mon Sep 17 00:00:00 2001 From: Pontus Abrahamsson Date: Tue, 10 Dec 2019 08:40:06 +0100 Subject: [PATCH] Use lodash submodules to reduce bundle size (#5734) Import lodash sub modules --- e2e/ApplicationLifecycleTest.test.js | 4 +-- integration/env.test.js | 15 ++++++----- integration/redux/MyStore.js | 9 ++++--- lib/src/Navigation.ts | 2 +- lib/src/adapters/UniqueIdProvider.ts | 4 +-- lib/src/commands/Commands.test.ts | 10 ++++--- lib/src/commands/Commands.ts | 23 ++++++++-------- lib/src/commands/LayoutTreeCrawler.ts | 7 ++--- lib/src/commands/LayoutTreeParser.test.ts | 8 +++--- lib/src/commands/OptionsProcessor.ts | 26 +++++++++++-------- lib/src/components/ComponentWrapper.tsx | 6 ++--- lib/src/events/ComponentEventsObserver.ts | 18 ++++++++----- package.json | 15 ++++++----- playground/src/commons/Layouts.js | 3 ++- .../src/screens/FullScreenModalScreen.js | 7 ++--- playground/src/screens/ModalScreen.js | 13 ++++++---- playground/src/screens/PushedScreen.js | 8 +++--- playground/src/services/Navigation.js | 4 ++- scripts/gen-docs/MarkdownWriter.ts | 4 +-- scripts/install-android.js | 4 +-- scripts/release.js | 4 +-- scripts/test-e2e.js | 14 +++++----- scripts/test-js.js | 10 +++---- scripts/test-unit.js | 6 ++--- tsconfig-strict.json | 2 +- tsconfig.json | 1 + 26 files changed, 125 insertions(+), 102 deletions(-) diff --git a/e2e/ApplicationLifecycleTest.test.js b/e2e/ApplicationLifecycleTest.test.js index 4872c8efcdd..494936f1902 100644 --- a/e2e/ApplicationLifecycleTest.test.js +++ b/e2e/ApplicationLifecycleTest.test.js @@ -1,10 +1,10 @@ const Utils = require('./Utils'); const Android = require('./AndroidUtils'); const TestIDs = require('../playground/src/testIDs'); -const _ = require('lodash'); +const includes = require('lodash/includes'); const { elementByLabel, elementById, sleep } = Utils; -const IS_RELEASE = _.includes(process.argv, '--release'); +const IS_RELEASE = includes(process.argv, '--release'); const KEY_CODE_R = 46; describe('application lifecycle test', () => { diff --git a/integration/env.test.js b/integration/env.test.js index ed9d7c32f44..16ac08bcdf4 100644 --- a/integration/env.test.js +++ b/integration/env.test.js @@ -1,4 +1,5 @@ -const _ = require('lodash'); +const eq = require('lodash/eq'); +const isEqual = require('lodash/isEqual'); describe('testing that the environment is working properly', () => { it('object spread', () => { @@ -14,16 +15,16 @@ describe('testing that the environment is working properly', () => { }); it('equality tests', () => { - expect(_.eq('hello', 'hello')).toBe(true); - expect(_.isEqual('hello', 'hello')).toBe(true); + expect(eq('hello', 'hello')).toBe(true); + expect(isEqual('hello', 'hello')).toBe(true); - expect(_.eq('hello', Object('hello'))).toBe(false); - expect(_.isEqual('hello', Object('hello'))).toBe(true); + expect(eq('hello', Object('hello'))).toBe(false); + expect(isEqual('hello', Object('hello'))).toBe(true); const a = {}; const b = {}; - expect(_.eq(a, b)).toBe(false); - expect(_.isEqual(a, b)).toBe(true); + expect(eq(a, b)).toBe(false); + expect(isEqual(a, b)).toBe(true); }); }); diff --git a/integration/redux/MyStore.js b/integration/redux/MyStore.js index 423bd362e68..124344550d0 100644 --- a/integration/redux/MyStore.js +++ b/integration/redux/MyStore.js @@ -1,5 +1,6 @@ const redux = require('redux'); -const _ = require('lodash'); +const merge = require('lodash/merge'); +const get = require('lodash/get'); const initialState = { person: { @@ -10,10 +11,10 @@ const initialState = { const reducer = (state = initialState, action) => { switch (action.type) { case 'redux.MyStore.setName': { - return _.merge({}, state, { person: { name: action.name } }); + return merge({}, state, { person: { name: action.name } }); } case 'redux.MyStore.setAge': { - return _.merge({}, state, { person: { age: action.age } }); + return merge({}, state, { person: { age: action.age } }); } default: { return state; @@ -23,7 +24,7 @@ const reducer = (state = initialState, action) => { const selectors = { getName(state) { - return _.get(state, 'person.name'); + return get(state, 'person.name'); }, getAge(state) { diff --git a/lib/src/Navigation.ts b/lib/src/Navigation.ts index 612c85062ee..1346498cd5f 100644 --- a/lib/src/Navigation.ts +++ b/lib/src/Navigation.ts @@ -1,4 +1,4 @@ -import { isArray } from 'lodash'; +import isArray from 'lodash/isArray'; import { NativeCommandsSender } from './adapters/NativeCommandsSender'; import { NativeEventsReceiver } from './adapters/NativeEventsReceiver'; import { UniqueIdProvider } from './adapters/UniqueIdProvider'; diff --git a/lib/src/adapters/UniqueIdProvider.ts b/lib/src/adapters/UniqueIdProvider.ts index 0eaaff6c672..d929efe5b1f 100644 --- a/lib/src/adapters/UniqueIdProvider.ts +++ b/lib/src/adapters/UniqueIdProvider.ts @@ -1,7 +1,7 @@ -import * as _ from 'lodash'; +import uniqueId from 'lodash/uniqueId'; export class UniqueIdProvider { generate(prefix?: string): string { - return _.uniqueId(prefix); + return uniqueId(prefix); } } diff --git a/lib/src/commands/Commands.test.ts b/lib/src/commands/Commands.test.ts index c6a6052479d..2d5eb06bffa 100644 --- a/lib/src/commands/Commands.test.ts +++ b/lib/src/commands/Commands.test.ts @@ -1,4 +1,6 @@ -import * as _ from 'lodash'; +import forEach from 'lodash/forEach' +import filter from 'lodash/filter' +import invoke from 'lodash/invoke' import { mock, verify, instance, deepEqual, when, anything, anyString } from 'ts-mockito'; import { LayoutTreeParser } from './LayoutTreeParser'; @@ -398,7 +400,7 @@ describe('Commands', () => { function getAllMethodsOfUut() { const uutFns = Object.getOwnPropertyNames(Commands.prototype); - const methods = _.filter(uutFns, (fn) => fn !== 'constructor'); + const methods = filter(uutFns, (fn) => fn !== 'constructor'); expect(methods.length).toBeGreaterThan(1); return methods; } @@ -445,11 +447,11 @@ describe('Commands', () => { dismissOverlay: { commandId: 'dismissOverlay+UNIQUE_ID', componentId: 'id' }, getLaunchArgs: { commandId: 'getLaunchArgs+UNIQUE_ID' } }; - _.forEach(getAllMethodsOfUut(), (m) => { + forEach(getAllMethodsOfUut(), (m) => { it(`for ${m}`, () => { expect(argsForMethodName).toHaveProperty(m); expect(paramsForMethodName).toHaveProperty(m); - _.invoke(uut, m, ...argsForMethodName[m]); + invoke(uut, m, ...argsForMethodName[m]); expect(cb).toHaveBeenCalledTimes(1); expect(cb).toHaveBeenCalledWith(m, paramsForMethodName[m]); }); diff --git a/lib/src/commands/Commands.ts b/lib/src/commands/Commands.ts index bbbdc47c5c2..8f5629f0a65 100644 --- a/lib/src/commands/Commands.ts +++ b/lib/src/commands/Commands.ts @@ -1,4 +1,5 @@ -import * as _ from 'lodash'; +import cloneDeep from 'lodash/cloneDeep' +import map from 'lodash/map' import { CommandsObserver } from '../events/CommandsObserver'; import { NativeCommandsSender } from '../adapters/NativeCommandsSender'; import { UniqueIdProvider } from '../adapters/UniqueIdProvider'; @@ -21,14 +22,14 @@ export class Commands { ) {} public setRoot(simpleApi: LayoutRoot) { - const input = _.cloneDeep(simpleApi); + const input = cloneDeep(simpleApi); const root = this.layoutTreeParser.parse(input.root); - const modals = _.map(input.modals, (modal) => { + const modals = map(input.modals, (modal) => { return this.layoutTreeParser.parse(modal); }); - const overlays = _.map(input.overlays, (overlay) => { + const overlays = map(input.overlays, (overlay) => { return this.layoutTreeParser.parse(overlay); }); @@ -48,7 +49,7 @@ export class Commands { } public setDefaultOptions(options: Options) { - const input = _.cloneDeep(options); + const input = cloneDeep(options); this.optionsProcessor.processOptions(input); this.nativeCommandsSender.setDefaultOptions(input); @@ -56,7 +57,7 @@ export class Commands { } public mergeOptions(componentId: string, options: Options) { - const input = _.cloneDeep(options); + const input = cloneDeep(options); this.optionsProcessor.processOptions(input); this.nativeCommandsSender.mergeOptions(componentId, input); @@ -64,13 +65,13 @@ export class Commands { } public updateProps(componentId: string, props: object) { - const input = _.cloneDeep(props); + const input = cloneDeep(props); this.store.updateProps(componentId, input); this.commandsObserver.notify('updateProps', { componentId, props }); } public showModal(layout: Layout) { - const layoutCloned = _.cloneDeep(layout); + const layoutCloned = cloneDeep(layout); const layoutNode = this.layoutTreeParser.parse(layoutCloned); const commandId = this.uniqueIdProvider.generate('showModal'); @@ -96,7 +97,7 @@ export class Commands { } public push(componentId: string, simpleApi: Layout) { - const input = _.cloneDeep(simpleApi); + const input = cloneDeep(simpleApi); const layout = this.layoutTreeParser.parse(input); const commandId = this.uniqueIdProvider.generate('push'); @@ -129,7 +130,7 @@ export class Commands { } public setStackRoot(componentId: string, children: Layout[]) { - const input = _.map(_.cloneDeep(children), (simpleApi) => { + const input = map(cloneDeep(children), (simpleApi) => { const layout = this.layoutTreeParser.parse(simpleApi); return layout; }); @@ -145,7 +146,7 @@ export class Commands { } public showOverlay(simpleApi: Layout) { - const input = _.cloneDeep(simpleApi); + const input = cloneDeep(simpleApi); const layout = this.layoutTreeParser.parse(input); const commandId = this.uniqueIdProvider.generate('showOverlay'); diff --git a/lib/src/commands/LayoutTreeCrawler.ts b/lib/src/commands/LayoutTreeCrawler.ts index b8d3e142bbc..af57d71dded 100644 --- a/lib/src/commands/LayoutTreeCrawler.ts +++ b/lib/src/commands/LayoutTreeCrawler.ts @@ -1,4 +1,5 @@ -import * as _ from 'lodash'; +import merge from 'lodash/merge' +import isFunction from 'lodash/isFunction' import { LayoutType } from './LayoutType'; import { OptionsProcessor } from './OptionsProcessor'; import { Store } from '../components/Store'; @@ -47,14 +48,14 @@ export class LayoutTreeCrawler { } private applyStaticOptions(node: LayoutNode) { - node.data.options = _.merge({}, this.staticOptionsIfPossible(node), node.data.options); + node.data.options = merge({}, this.staticOptionsIfPossible(node), node.data.options); } private staticOptionsIfPossible(node: LayoutNode) { const foundReactGenerator = this.store.getComponentClassForName(node.data.name!); const reactComponent = foundReactGenerator ? foundReactGenerator() : undefined; if (reactComponent && this.isComponentWithOptions(reactComponent)) { - return _.isFunction(reactComponent.options) ? reactComponent.options(node.data.passProps || {}) : reactComponent.options; + return isFunction(reactComponent.options) ? reactComponent.options(node.data.passProps || {}) : reactComponent.options; } return {}; } diff --git a/lib/src/commands/LayoutTreeParser.test.ts b/lib/src/commands/LayoutTreeParser.test.ts index 9aa34440791..1469341d3a8 100644 --- a/lib/src/commands/LayoutTreeParser.test.ts +++ b/lib/src/commands/LayoutTreeParser.test.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import keys from 'lodash/keys'; import { LayoutTreeParser } from './LayoutTreeParser'; import { LayoutType } from './LayoutType'; import { Options } from '../interfaces/Options'; @@ -89,7 +89,7 @@ describe('LayoutTreeParser', () => { it('bottom tabs', () => { const result = uut.parse(LayoutExamples.bottomTabs); - expect(_.keys(result)).toEqual(['id', 'type', 'data', 'children']); + expect(keys(result)).toEqual(['id', 'type', 'data', 'children']); expect(result.id).toEqual('myUniqueId'); expect(result.type).toEqual(LayoutType.BottomTabs); expect(result.data).toEqual({}); @@ -101,7 +101,7 @@ describe('LayoutTreeParser', () => { it('side menus', () => { const result = uut.parse(LayoutExamples.sideMenu); - expect(_.keys(result)).toEqual(['id', 'type', 'data', 'children']); + expect(keys(result)).toEqual(['id', 'type', 'data', 'children']); expect(result.id).toEqual('myUniqueId'); expect(result.type).toEqual(LayoutType.SideMenuRoot); expect(result.data).toEqual({}); @@ -119,7 +119,7 @@ describe('LayoutTreeParser', () => { it('top tabs', () => { const result = uut.parse(LayoutExamples.topTabs); - expect(_.keys(result)).toEqual(['id', 'type', 'data', 'children']); + expect(keys(result)).toEqual(['id', 'type', 'data', 'children']); expect(result.id).toEqual('myUniqueId'); expect(result.type).toEqual(LayoutType.TopTabs); expect(result.data).toEqual({ options: LayoutExamples.options }); diff --git a/lib/src/commands/OptionsProcessor.ts b/lib/src/commands/OptionsProcessor.ts index c8ec7e86319..50d09375ce6 100644 --- a/lib/src/commands/OptionsProcessor.ts +++ b/lib/src/commands/OptionsProcessor.ts @@ -1,4 +1,8 @@ -import * as _ from 'lodash'; +import isEqual from 'lodash/isEqual' +import isObject from 'lodash/isObject' +import isArray from 'lodash/isArray' +import endsWith from 'lodash/endsWith' +import forEach from 'lodash/forEach' import { Store } from '../components/Store'; import { UniqueIdProvider } from '../adapters/UniqueIdProvider'; @@ -19,7 +23,7 @@ export class OptionsProcessor { } private processObject(objectToProcess: object) { - _.forEach(objectToProcess, (value, key) => { + forEach(objectToProcess, (value, key) => { this.processColor(key, value, objectToProcess); if (!value) { @@ -30,32 +34,32 @@ export class OptionsProcessor { this.processImage(key, value, objectToProcess); this.processButtonsPassProps(key, value); - if (!_.isEqual(key, 'passProps') && (_.isObject(value) || _.isArray(value))) { + if (!isEqual(key, 'passProps') && (isObject(value) || isArray(value))) { this.processObject(value); } }); } private processColor(key: string, value: any, options: Record) { - if (_.isEqual(key, 'color') || _.endsWith(key, 'Color')) { + if (isEqual(key, 'color') || endsWith(key, 'Color')) { options[key] = value === null ? 'NoColor' : this.colorService.toNativeColor(value); } } private processImage(key: string, value: any, options: Record) { if ( - _.isEqual(key, 'icon') || - _.isEqual(key, 'image') || - _.endsWith(key, 'Icon') || - _.endsWith(key, 'Image') + isEqual(key, 'icon') || + isEqual(key, 'image') || + endsWith(key, 'Icon') || + endsWith(key, 'Image') ) { options[key] = this.assetService.resolveFromRequire(value); } } private processButtonsPassProps(key: string, value: any) { - if (_.endsWith(key, 'Buttons')) { - _.forEach(value, (button) => { + if (endsWith(key, 'Buttons')) { + forEach(value, (button) => { if (button.passProps && button.id) { this.store.updateProps(button.id, button.passProps); button.passProps = undefined; @@ -65,7 +69,7 @@ export class OptionsProcessor { } private processComponent(key: string, value: any, options: Record) { - if (_.isEqual(key, 'component')) { + if (isEqual(key, 'component')) { value.componentId = value.id ? value.id : this.uniqueIdProvider.generate('CustomComponent'); if (value.passProps) { this.store.updateProps(value.componentId, value.passProps); diff --git a/lib/src/components/ComponentWrapper.tsx b/lib/src/components/ComponentWrapper.tsx index 9b7d0ce8b54..9948a1bcd4e 100644 --- a/lib/src/components/ComponentWrapper.tsx +++ b/lib/src/components/ComponentWrapper.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import { ComponentProvider } from 'react-native'; -import * as _ from 'lodash'; +import merge from 'lodash/merge' import { polyfill } from 'react-lifecycles-compat'; import hoistNonReactStatics = require('hoist-non-react-statics'); @@ -28,7 +28,7 @@ export class ComponentWrapper { class WrappedComponent extends React.Component { static getDerivedStateFromProps(nextProps: any, prevState: HocState) { return { - allProps: _.merge({}, nextProps, store.getPropsForId(prevState.componentId)) + allProps: merge({}, nextProps, store.getPropsForId(prevState.componentId)) }; } @@ -43,7 +43,7 @@ export class ComponentWrapper { } public setProps(newProps: any) { - this.setState({allProps: newProps}); + this.setState({ allProps: newProps }); } componentWillUnmount() { diff --git a/lib/src/events/ComponentEventsObserver.ts b/lib/src/events/ComponentEventsObserver.ts index 4581ba180dc..2c45d2abd48 100644 --- a/lib/src/events/ComponentEventsObserver.ts +++ b/lib/src/events/ComponentEventsObserver.ts @@ -1,4 +1,8 @@ -import * as _ from 'lodash'; +import isString from 'lodash/isString' +import isNil from 'lodash/isNil' +import uniqueId from 'lodash/uniqueId' +import unset from 'lodash/unset' +import forEach from 'lodash/forEach' import { EventSubscription } from '../interfaces/EventSubscription'; import { ComponentDidAppearEvent, @@ -47,20 +51,20 @@ export class ComponentEventsObserver { public bindComponent(component: React.Component, componentId?: string): EventSubscription { const computedComponentId = componentId || component.props.componentId; - if (!_.isString(computedComponentId)) { + if (!isString(computedComponentId)) { throw new Error(`bindComponent expects a component with a componentId in props or a componentId as the second argument`); } - if (_.isNil(this.listeners[computedComponentId])) { + if (isNil(this.listeners[computedComponentId])) { this.listeners[computedComponentId] = {}; } - const key = _.uniqueId(); + const key = uniqueId(); this.listeners[computedComponentId][key] = component; - return { remove: () => _.unset(this.listeners[computedComponentId], key) }; + return { remove: () => unset(this.listeners[computedComponentId], key) }; } public unmounted(componentId: string) { - _.unset(this.listeners, componentId); + unset(this.listeners, componentId); } notifyComponentDidAppear(event: ComponentDidAppearEvent) { @@ -93,7 +97,7 @@ export class ComponentEventsObserver { } private triggerOnAllListenersByComponentId(event: ComponentEvent, method: string) { - _.forEach(this.listeners[event.componentId], (component) => { + forEach(this.listeners[event.componentId], (component) => { if (component && component[method]) { component[method](event); } diff --git a/package.json b/package.json index 725c5ec7cdd..13c145ab9a4 100644 --- a/package.json +++ b/package.json @@ -58,27 +58,28 @@ }, "devDependencies": { "@babel/core": "7.6.4", - "@babel/types": "7.6.x", "@babel/plugin-proposal-export-default-from": "7.2.0", "@babel/plugin-proposal-export-namespace-from": "7.2.0", - "@types/hoist-non-react-statics": "^3.0.1", + "@babel/types": "7.6.x", "@react-native-community/eslint-config": "0.0.3", - "babel-jest": "24.9.x", + "@types/hoist-non-react-statics": "^3.0.1", "@types/jest": "24.x.x", - "@types/lodash": "4.x.x", + "@types/lodash": "^4.14.149", "@types/react": "16.x.x", "@types/react-native": "0.57.7", "@types/react-test-renderer": "16.x.x", + "babel-jest": "24.9.x", "detox": "14.x.x", - "react-native-ui-lib": "3.24.2", "handlebars": "4.x.x", "jest": "24.9.x", + "lodash": "^4.17.15", "metro-react-native-babel-preset": "0.57.x", "react": "16.9.0", "react-native": "0.61.4", + "react-native-keyboard-tracking-view": "5.x.x", "react-native-typescript-transformer": "1.2.12", + "react-native-ui-lib": "3.24.2", "react-native-view-overflow": "0.0.4", - "react-native-keyboard-tracking-view": "5.x.x", "react-redux": "5.x.x", "react-test-renderer": "16.9.x", "redux": "3.x.x", @@ -160,4 +161,4 @@ } } } -} \ No newline at end of file +} diff --git a/playground/src/commons/Layouts.js b/playground/src/commons/Layouts.js index 66ab23dfae2..4bb97b1826c 100644 --- a/playground/src/commons/Layouts.js +++ b/playground/src/commons/Layouts.js @@ -1,4 +1,5 @@ -const { isString, isArray } = require('lodash'); +const isString = require('lodash/isString'); +const isArray = require('lodash/isArray'); const stack = (rawChildren, id) => { const childrenArray = isArray(rawChildren) ? rawChildren : [rawChildren]; diff --git a/playground/src/screens/FullScreenModalScreen.js b/playground/src/screens/FullScreenModalScreen.js index 2f2fc114cc1..ca88bcea0e4 100644 --- a/playground/src/screens/FullScreenModalScreen.js +++ b/playground/src/screens/FullScreenModalScreen.js @@ -1,4 +1,5 @@ -const _ = require('lodash'); +const concat = require('lodash/concat'); +const last = require('lodash/last'); const React = require('react'); const Root = require('../components/Root'); const Button = require('../components/Button') @@ -42,7 +43,7 @@ class FullScreenModalScreen extends React.Component { name: Screens.Modal, passProps: { modalPosition: this.getModalPosition() + 1, - previousModalIds: _.concat([], this.props.previousModalIds || [], this.props.componentId) + previousModalIds: concat([], this.props.previousModalIds || [], this.props.componentId) } } }); @@ -65,6 +66,6 @@ class FullScreenModalScreen extends React.Component { getModalPosition = () => this.props.modalPosition || 1; - getPreviousModalId = () => _.last(this.props.previousModalIds); + getPreviousModalId = () => last(this.props.previousModalIds); } module.exports = FullScreenModalScreen; diff --git a/playground/src/screens/ModalScreen.js b/playground/src/screens/ModalScreen.js index fb11315c660..7c5f42bfa5e 100644 --- a/playground/src/screens/ModalScreen.js +++ b/playground/src/screens/ModalScreen.js @@ -1,4 +1,7 @@ -const _ = require('lodash'); +const last = require('lodash/last'); +const concat = require('lodash/concat'); +const forEach = require('lodash/forEach'); +const head = require('lodash/head'); const React = require('react'); const Root = require('../components/Root'); const Button = require('../components/Button') @@ -54,7 +57,7 @@ class ModalScreen extends React.Component { name: Screens.Modal, passProps: { modalPosition: this.getModalPosition() + 1, - previousModalIds: _.concat([], this.props.previousModalIds || [], this.props.componentId) + previousModalIds: concat([], this.props.previousModalIds || [], this.props.componentId) } } }); @@ -66,9 +69,9 @@ class ModalScreen extends React.Component { dismissUnknownModal = () => Navigation.dismissModal('unknown'); - dismissAllPreviousModals = () => _.forEach(this.props.previousModalIds, (id) => Navigation.dismissModal(id)); + dismissAllPreviousModals = () => forEach(this.props.previousModalIds, (id) => Navigation.dismissModal(id)); - dismissFirstModal = () => Navigation.dismissModal(_.head(this.props.previousModalIds)); + dismissFirstModal = () => Navigation.dismissModal(head(this.props.previousModalIds)); dismissAllModals = () => Navigation.dismissAllModals(); @@ -85,6 +88,6 @@ class ModalScreen extends React.Component { getModalPosition = () => this.props.modalPosition || 1; - getPreviousModalId = () => _.last(this.props.previousModalIds); + getPreviousModalId = () => last(this.props.previousModalIds); } module.exports = ModalScreen; diff --git a/playground/src/screens/PushedScreen.js b/playground/src/screens/PushedScreen.js index 23d7990d1e3..a40ceb9ab1d 100644 --- a/playground/src/screens/PushedScreen.js +++ b/playground/src/screens/PushedScreen.js @@ -1,4 +1,4 @@ -const _ = require('lodash'); +const concat = require('lodash/concat'); const React = require('react'); const { BackHandler } = require('react-native'); const Navigation = require('../services/Navigation'); @@ -99,7 +99,7 @@ class PushedScreen extends React.Component { name: Screens.Pushed, passProps: { stackPosition: this.getStackPosition() + 1, - previousScreenIds: _.concat([], this.props.previousScreenIds || [], this.props.componentId) + previousScreenIds: concat([], this.props.previousScreenIds || [], this.props.componentId) }, options: { animations: { @@ -120,7 +120,7 @@ class PushedScreen extends React.Component { name: Screens.Pushed, passProps: { stackPosition: this.getStackPosition() + 1, - previousScreenIds: _.concat([], this.props.previousScreenIds || [], this.props.componentId) + previousScreenIds: concat([], this.props.previousScreenIds || [], this.props.componentId) }, options: { animations: { @@ -152,7 +152,7 @@ class PushedScreen extends React.Component { createPassProps = () => { return { stackPosition: this.getStackPosition() + 1, - previousScreenIds: _.concat([], this.props.previousScreenIds || [], this.props.componentId) + previousScreenIds: concat([], this.props.previousScreenIds || [], this.props.componentId) } }; getStackPosition = () => this.props.stackPosition || 1; diff --git a/playground/src/services/Navigation.js b/playground/src/services/Navigation.js index c19d471be7e..53c095b85db 100644 --- a/playground/src/services/Navigation.js +++ b/playground/src/services/Navigation.js @@ -1,4 +1,6 @@ -const { isString, get } = require('lodash'); +const get = require('lodash/get'); +const isString= require('lodash/isString'); + const { stack, component } = require('../commons/Layouts'); const { Navigation } = require('react-native-navigation'); diff --git a/scripts/gen-docs/MarkdownWriter.ts b/scripts/gen-docs/MarkdownWriter.ts index 0100152f5e3..235e5549dde 100644 --- a/scripts/gen-docs/MarkdownWriter.ts +++ b/scripts/gen-docs/MarkdownWriter.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import concat from 'lodash/concat' import * as Handlebars from 'handlebars'; import * as fs from 'fs'; import { ClassContext } from './ClassParser'; @@ -34,7 +34,7 @@ export class MarkdownWriter { const files2 = interfaceContexts.map(mapper); const files3 = enumContexts.map(mapper); - const menuMarkdown = this.menuFn({ files: _.concat(files, files2, files3) }); + const menuMarkdown = this.menuFn({ files: concat(files, files2, files3) }); fs.writeFileSync(`${this.outputDir}/_sidebar.md`, menuMarkdown, { encoding: 'utf8' }); fs.writeFileSync(`${this.outputDir}/README.md`, menuMarkdown, { encoding: 'utf8' }); } diff --git a/scripts/install-android.js b/scripts/install-android.js index db92d6c88ce..86c8a7265a4 100644 --- a/scripts/install-android.js +++ b/scripts/install-android.js @@ -1,7 +1,7 @@ -const _ = require('lodash'); +const includes = require('lodash/includes') const exec = require('shell-utils').exec; -const release = _.includes(process.argv, '--release'); +const release = includes(process.argv, '--release'); run(); diff --git a/scripts/release.js b/scripts/release.js index eb0292b6b12..e0f81ef0bd7 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -2,7 +2,7 @@ const exec = require('shell-utils').exec; const semver = require('semver'); const fs = require('fs'); -const _ = require('lodash'); +const includes = require('lodash/includes'); const path = require('path'); // Workaround JS @@ -82,7 +82,7 @@ function tryPublishAndTag(version) { console.log(`Released ${theCandidate}`); return; } catch (err) { - const alreadyPublished = _.includes(err.toString(), 'You cannot publish over the previously published version'); + const alreadyPublished = includes(err.toString(), 'You cannot publish over the previously published version'); if (!alreadyPublished) { throw err; } diff --git a/scripts/test-e2e.js b/scripts/test-e2e.js index 28c937594fb..9d7b0e44c45 100644 --- a/scripts/test-e2e.js +++ b/scripts/test-e2e.js @@ -1,12 +1,12 @@ -const _ = require('lodash'); +const includes = require('lodash/includes'); const exec = require('shell-utils').exec; -const android = _.includes(process.argv, '--android'); -const release = _.includes(process.argv, '--release'); -const skipBuild = _.includes(process.argv, '--skipBuild'); -const headless = _.includes(process.argv, '--headless'); -const multi = _.includes(process.argv, '--multi'); -const verbose = _.includes(process.argv, '--verbose'); +const android = includes(process.argv, '--android'); +const release = includes(process.argv, '--release'); +const skipBuild = includes(process.argv, '--skipBuild'); +const headless = includes(process.argv, '--headless'); +const multi = includes(process.argv, '--multi'); +const verbose = includes(process.argv, '--verbose'); run(); diff --git a/scripts/test-js.js b/scripts/test-js.js index b923d3a4bec..975367738ae 100644 --- a/scripts/test-js.js +++ b/scripts/test-js.js @@ -1,7 +1,7 @@ const exec = require('shell-utils').exec; -const _ = require('lodash'); +const { includes, chain, split, filter } = require('lodash'); -const fix = _.includes(process.argv, '--fix') ? '--fix' : ''; +const fix = includes(process.argv, '--fix') ? '--fix' : ''; const dirs = [ 'lib/src', @@ -14,7 +14,7 @@ const dirs = [ run(); function run() { - const paths = _.chain(dirs).map((d) => d === 'e2e' ? `${d}/**/*.[tj]s` : `${d}/**/*.[tj]sx?`).join(' ').value(); + const paths = chain(dirs).map((d) => d === 'e2e' ? `${d}/**/*.[tj]s` : `${d}/**/*.[tj]sx?`).join(' ').value(); exec.execSync(`tslint ${paths} ${fix} --format verbose`); assertAllTsFilesInSrc(); exec.execSync(`jest --coverage`); @@ -22,8 +22,8 @@ function run() { function assertAllTsFilesInSrc() { const allFiles = exec.execSyncRead('find ./lib/src -type f'); - const lines = _.split(allFiles, '\n'); - const offenders = _.filter(lines, (f) => !f.endsWith('.ts') && !f.endsWith('.tsx')); + const lines = split(allFiles, '\n'); + const offenders = filter(lines, (f) => !f.endsWith('.ts') && !f.endsWith('.tsx')); if (offenders.length) { throw new Error(`\n\nOnly ts/tsx files are allowed:\n${offenders.join('\n')}\n\n\n`); } diff --git a/scripts/test-unit.js b/scripts/test-unit.js index 7654a5e4650..f2ff0181a09 100644 --- a/scripts/test-unit.js +++ b/scripts/test-unit.js @@ -1,8 +1,8 @@ -const _ = require('lodash'); +const includes = require('lodash/includes'); const exec = require('shell-utils').exec; -const android = _.includes(process.argv, '--android'); -const release = _.includes(process.argv, '--release'); +const android = includes(process.argv, '--android'); +const release = includes(process.argv, '--release'); function run() { if (android) { diff --git a/tsconfig-strict.json b/tsconfig-strict.json index 6e54709df9e..7ddfd0fff23 100644 --- a/tsconfig-strict.json +++ b/tsconfig-strict.json @@ -1,7 +1,7 @@ { "$schema": "http://json.schemastore.org/tsconfig", "compilerOptions": { - "allowSyntheticDefaultImports": false, + "allowSyntheticDefaultImports": true, "allowUnreachableCode": false, "allowUnusedLabels": false, "diagnostics": true, diff --git a/tsconfig.json b/tsconfig.json index 6a8f0eedd78..1b52f6384f0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "module": "commonjs", "jsx": "react-native", "declaration": true, + "esModuleInterop": true, "skipLibCheck": true, "types": [ "jest",