From f977bc09ab874501a45800286fc9cfe9baeff8b5 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Sat, 8 Aug 2020 09:36:14 -0600 Subject: [PATCH 1/4] Correct spacing --- webpack.config.js | 72 +++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index dd0498425ca4..70eec666b729 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,42 +3,42 @@ const {CleanWebpackPlugin} = require('clean-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { - mode: 'development', - entry: { - app: './src/index.js', - }, - output: { - filename: '[name]-[hash].bundle.js', - path: path.resolve(__dirname, 'dist'), - }, - devtool: 'inline-source-map', - devServer: { - contentBase: path.join(__dirname, 'dist'), - hot: true, - }, - plugins: [ - new CleanWebpackPlugin(), - new HtmlWebpackPlugin({ - template: 'src/index.html', - // With the dev server, we need to put this file in the dist folder - filename: 'index.html', - }), - ], - module: { - rules: [ - // Transpiles ES6 and JSX - { - test: /\.js$/, - exclude: /node_modules|\.native.js$/, - use: { - loader: 'babel-loader', - }, - }, + mode: 'development', + entry: { + app: './src/index.js', + }, + output: { + filename: '[name]-[hash].bundle.js', + path: path.resolve(__dirname, 'dist'), + }, + devtool: 'inline-source-map', + devServer: { + contentBase: path.join(__dirname, 'dist'), + hot: true, + }, + plugins: [ + new CleanWebpackPlugin(), + new HtmlWebpackPlugin({ + template: 'src/index.html', + // With the dev server, we need to put this file in the dist folder + filename: 'index.html', + }), ], - }, - resolve: { - alias: { - 'react-native$': 'react-native-web', + module: { + rules: [ + // Transpiles ES6 and JSX + { + test: /\.js$/, + exclude: /node_modules|\.native.js$/, + use: { + loader: 'babel-loader', + }, + }, + ], + }, + resolve: { + alias: { + 'react-native$': 'react-native-web', + }, }, - }, }; From 7696d385d9cc4d22bc8d734ffc1092a6306d8ead Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Sat, 8 Aug 2020 09:44:16 -0600 Subject: [PATCH 2/4] Remove redundant exports --- babel.config.js | 16 ++++++++-------- js/lib/Router/index.js | 1 - js/lib/Router/index.native.js | 1 - package-lock.json | 26 +++++++++++++------------- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/babel.config.js b/babel.config.js index 749a2c2f2242..2b93d523829c 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,16 +1,16 @@ const webpack = { - presets: [require('@babel/preset-react')], - plugins: [['react-native-web', {commonjs: true}]], + presets: ['@babel/preset-react', '@babel/preset-env'], + plugins: [['react-native-web', {commonjs: true}]], }; const metro = { - presets: [require('metro-react-native-babel-preset')], - plugins: [], + presets: [require('metro-react-native-babel-preset')], + plugins: [], }; module.exports = ({caller}) => { - // For `react-native` (iOS/Android) caller will be "metro" - // For `webpack` (Web) caller will be "@babel-loader" - const runningIn = caller(({name}) => name); - return runningIn === 'metro' ? metro : webpack; + // For `react-native` (iOS/Android) caller will be "metro" + // For `webpack` (Web) caller will be "@babel-loader" + const runningIn = caller(({name}) => name); + return runningIn === 'metro' ? metro : webpack; }; diff --git a/js/lib/Router/index.js b/js/lib/Router/index.js index 18caea5b8a8f..524ccb8fddf1 100644 --- a/js/lib/Router/index.js +++ b/js/lib/Router/index.js @@ -7,5 +7,4 @@ import { withRouter, } from 'react-router-dom'; -export default {Link, Route, Redirect, Router, Switch, withRouter}; export {Link, Route, Redirect, Router, Switch, withRouter}; diff --git a/js/lib/Router/index.native.js b/js/lib/Router/index.native.js index ce9f98686e87..860751fae08c 100644 --- a/js/lib/Router/index.native.js +++ b/js/lib/Router/index.native.js @@ -7,5 +7,4 @@ import { withRouter, } from 'react-router-native'; -export default {Link, Route, Redirect, Router, Switch, withRouter}; export {Link, Route, Redirect, Router, Switch, withRouter}; diff --git a/package-lock.json b/package-lock.json index b57ac0e0426a..1c546c765a84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3443,15 +3443,15 @@ } }, "browserslist": { - "version": "4.13.0", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.13.0.tgz", - "integrity": "sha512-MINatJ5ZNrLnQ6blGvePd/QOz9Xtu+Ne+x29iQSCHfkU5BugKVJwZKn/iiL8UbpIpa3JhviKjz+XxMo0m2caFQ==", + "version": "4.14.0", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.14.0.tgz", + "integrity": "sha512-pUsXKAF2lVwhmtpeA3LJrZ76jXuusrNyhduuQs7CDFf9foT4Y38aQOserd2lMe5DSSrjf3fx34oHwryuvxAUgQ==", "dev": true, "requires": { - "caniuse-lite": "^1.0.30001093", - "electron-to-chromium": "^1.3.488", - "escalade": "^3.0.1", - "node-releases": "^1.1.58" + "caniuse-lite": "^1.0.30001111", + "electron-to-chromium": "^1.3.523", + "escalade": "^3.0.2", + "node-releases": "^1.1.60" } }, "bser": { @@ -3606,9 +3606,9 @@ "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" }, "caniuse-lite": { - "version": "1.0.30001111", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001111.tgz", - "integrity": "sha512-xnDje2wchd/8mlJu8sXvWxOGvMgv+uT3iZ3bkIAynKOzToCssWCmkz/ZIkQBs/2pUB4uwnJKVORWQ31UkbVjOg==", + "version": "1.0.30001112", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001112.tgz", + "integrity": "sha512-J05RTQlqsatidif/38aN3PGULCLrg8OYQOlJUKbeYVzC2mGZkZLIztwRlB3MtrfLmawUmjFlNJvy/uhwniIe1Q==", "dev": true }, "capture-exit": { @@ -4697,9 +4697,9 @@ "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, "electron-to-chromium": { - "version": "1.3.523", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.523.tgz", - "integrity": "sha512-D4/3l5DpciddD92IDRtpLearQSGzly8FwBJv+nITvLH8YJrFabpDFe4yuiOJh2MS4/EsXqyQTXyw1toeYPtshQ==", + "version": "1.3.526", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.526.tgz", + "integrity": "sha512-HiroW5ZbGwgT8kCnoEO8qnGjoTPzJxduvV/Vv/wH63eo2N6Zj3xT5fmmaSPAPUM05iN9/5fIEkIg3owTtV6QZg==", "dev": true }, "elliptic": { From e92330cc05ebf70804d8fd68465bd14650898d41 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Sat, 8 Aug 2020 09:52:05 -0600 Subject: [PATCH 3/4] Move files into different locations --- __tests__/App-test.js | 2 +- index.js | 2 +- metro.config.js | 17 +++++++++-------- {js => src}/App.js | 0 {js => src}/Expensify.js | 0 {js => src}/ROUTES.js | 0 {js => src}/config.js | 0 {js => src}/lib/ActiveClientManager.js | 0 {js => src}/lib/DateUtils.js | 0 {js => src}/lib/ExpensiMark.js | 0 {js => src}/lib/Guid.js | 0 {js => src}/lib/Network.js | 0 {js => src}/lib/PersistentStorage.js | 0 {js => src}/lib/Router/index.js | 0 {js => src}/lib/Router/index.native.js | 0 {js => src}/lib/Str.js | 0 {js => src}/page/HomePage/HomePage.js | 0 {js => src}/page/SignInPage.js | 0 {js => src}/store/STOREKEYS.js | 0 {js => src}/store/Store.js | 0 {js => src}/store/actions/ReportActions.js | 0 {js => src}/store/actions/SessionActions.js | 0 {src => web}/index.html | 0 {src => web}/index.js | 2 +- webpack.config.js | 4 ++-- 25 files changed, 14 insertions(+), 13 deletions(-) rename {js => src}/App.js (100%) rename {js => src}/Expensify.js (100%) rename {js => src}/ROUTES.js (100%) rename {js => src}/config.js (100%) rename {js => src}/lib/ActiveClientManager.js (100%) rename {js => src}/lib/DateUtils.js (100%) rename {js => src}/lib/ExpensiMark.js (100%) rename {js => src}/lib/Guid.js (100%) rename {js => src}/lib/Network.js (100%) rename {js => src}/lib/PersistentStorage.js (100%) rename {js => src}/lib/Router/index.js (100%) rename {js => src}/lib/Router/index.native.js (100%) rename {js => src}/lib/Str.js (100%) rename {js => src}/page/HomePage/HomePage.js (100%) rename {js => src}/page/SignInPage.js (100%) rename {js => src}/store/STOREKEYS.js (100%) rename {js => src}/store/Store.js (100%) rename {js => src}/store/actions/ReportActions.js (100%) rename {js => src}/store/actions/SessionActions.js (100%) rename {src => web}/index.html (100%) rename {src => web}/index.js (85%) diff --git a/__tests__/App-test.js b/__tests__/App-test.js index 5f1f77a6ee4e..4edaa0a8d851 100644 --- a/__tests__/App-test.js +++ b/__tests__/App-test.js @@ -4,7 +4,7 @@ import 'react-native'; import React from 'react'; -import App from '../js/App'; +import App from '../src/App'; // Note: test renderer must be required after react-native. import renderer from 'react-test-renderer'; diff --git a/index.js b/index.js index 48e7a839f9e8..752e7ee3c142 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ */ import { AppRegistry } from 'react-native'; -import App from './js/App'; +import App from './src/App'; import { name as appName } from './app.json'; AppRegistry.registerComponent(appName, () => App); diff --git a/metro.config.js b/metro.config.js index 13a964217f20..bcbc37660496 100644 --- a/metro.config.js +++ b/metro.config.js @@ -6,12 +6,13 @@ */ module.exports = { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: false, - }, - }), - }, + transformer: { + getTransformOptions: async () => ({ + transform: { + experimentalImportSupport: false, + inlineRequires: false, + }, + }), + }, + projectRoot: './src', }; diff --git a/js/App.js b/src/App.js similarity index 100% rename from js/App.js rename to src/App.js diff --git a/js/Expensify.js b/src/Expensify.js similarity index 100% rename from js/Expensify.js rename to src/Expensify.js diff --git a/js/ROUTES.js b/src/ROUTES.js similarity index 100% rename from js/ROUTES.js rename to src/ROUTES.js diff --git a/js/config.js b/src/config.js similarity index 100% rename from js/config.js rename to src/config.js diff --git a/js/lib/ActiveClientManager.js b/src/lib/ActiveClientManager.js similarity index 100% rename from js/lib/ActiveClientManager.js rename to src/lib/ActiveClientManager.js diff --git a/js/lib/DateUtils.js b/src/lib/DateUtils.js similarity index 100% rename from js/lib/DateUtils.js rename to src/lib/DateUtils.js diff --git a/js/lib/ExpensiMark.js b/src/lib/ExpensiMark.js similarity index 100% rename from js/lib/ExpensiMark.js rename to src/lib/ExpensiMark.js diff --git a/js/lib/Guid.js b/src/lib/Guid.js similarity index 100% rename from js/lib/Guid.js rename to src/lib/Guid.js diff --git a/js/lib/Network.js b/src/lib/Network.js similarity index 100% rename from js/lib/Network.js rename to src/lib/Network.js diff --git a/js/lib/PersistentStorage.js b/src/lib/PersistentStorage.js similarity index 100% rename from js/lib/PersistentStorage.js rename to src/lib/PersistentStorage.js diff --git a/js/lib/Router/index.js b/src/lib/Router/index.js similarity index 100% rename from js/lib/Router/index.js rename to src/lib/Router/index.js diff --git a/js/lib/Router/index.native.js b/src/lib/Router/index.native.js similarity index 100% rename from js/lib/Router/index.native.js rename to src/lib/Router/index.native.js diff --git a/js/lib/Str.js b/src/lib/Str.js similarity index 100% rename from js/lib/Str.js rename to src/lib/Str.js diff --git a/js/page/HomePage/HomePage.js b/src/page/HomePage/HomePage.js similarity index 100% rename from js/page/HomePage/HomePage.js rename to src/page/HomePage/HomePage.js diff --git a/js/page/SignInPage.js b/src/page/SignInPage.js similarity index 100% rename from js/page/SignInPage.js rename to src/page/SignInPage.js diff --git a/js/store/STOREKEYS.js b/src/store/STOREKEYS.js similarity index 100% rename from js/store/STOREKEYS.js rename to src/store/STOREKEYS.js diff --git a/js/store/Store.js b/src/store/Store.js similarity index 100% rename from js/store/Store.js rename to src/store/Store.js diff --git a/js/store/actions/ReportActions.js b/src/store/actions/ReportActions.js similarity index 100% rename from js/store/actions/ReportActions.js rename to src/store/actions/ReportActions.js diff --git a/js/store/actions/SessionActions.js b/src/store/actions/SessionActions.js similarity index 100% rename from js/store/actions/SessionActions.js rename to src/store/actions/SessionActions.js diff --git a/src/index.html b/web/index.html similarity index 100% rename from src/index.html rename to web/index.html diff --git a/src/index.js b/web/index.js similarity index 85% rename from src/index.js rename to web/index.js index 32c81fa6c519..a95184850f43 100644 --- a/src/index.js +++ b/web/index.js @@ -1,5 +1,5 @@ import {AppRegistry} from 'react-native'; -import App from '../js/App'; +import App from '../src/App'; AppRegistry.registerComponent('App', () => App); diff --git a/webpack.config.js b/webpack.config.js index 70eec666b729..56c60e212ec2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -5,7 +5,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { mode: 'development', entry: { - app: './src/index.js', + app: './web/index.js', }, output: { filename: '[name]-[hash].bundle.js', @@ -19,7 +19,7 @@ module.exports = { plugins: [ new CleanWebpackPlugin(), new HtmlWebpackPlugin({ - template: 'src/index.html', + template: 'web/index.html', // With the dev server, we need to put this file in the dist folder filename: 'index.html', }), From 79b39eb29bbe46cfb16c832861fedac4b934cb0d Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Sat, 8 Aug 2020 10:16:13 -0600 Subject: [PATCH 4/4] Remove project root --- metro.config.js | 1 - src/lib/PersistentStorage.js | 35 ++++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/metro.config.js b/metro.config.js index bcbc37660496..783f3499c2cb 100644 --- a/metro.config.js +++ b/metro.config.js @@ -14,5 +14,4 @@ module.exports = { }, }), }, - projectRoot: './src', }; diff --git a/src/lib/PersistentStorage.js b/src/lib/PersistentStorage.js index 7cca31d69462..925f61fb3d32 100644 --- a/src/lib/PersistentStorage.js +++ b/src/lib/PersistentStorage.js @@ -2,21 +2,23 @@ * This module is an abstraction around a persistent storage system. This file can be modified to use whatever * persistent storage method is desired. */ - import AsyncStorage from '@react-native-community/async-storage'; /** * Get a key from storage * * @param {string} key + * @returns {Promise} */ -const get = async (key) => { - try { - const jsonValue = await AsyncStorage.getItem(key); - return jsonValue != null ? JSON.parse(jsonValue) : null; - } catch (e) { - console.error(`Could not parse value from local storage. Key: ${key}`); - } +function get(key) { + return AsyncStorage.getItem(key) + .then(val => { + const jsonValue = JSON.parse(val); + return jsonValue; + }) + .catch(err => { + console.error(`Unable to get item from persistent storage. Key: ${key} Error: ${err}`); + }); }; /** @@ -24,16 +26,23 @@ const get = async (key) => { * * @param {string} key * @param {mixed} val + * @returns {Promise} */ -const set = async (key, val) => { - await AsyncStorage.setItem(key, JSON.stringify(val)); +function set(key, val) { + return AsyncStorage.setItem(key, JSON.stringify(val)); }; /** * Empty out the storage (like when the user signs out) + * + * @returns {Promise} */ -const clear = async () => { - await AsyncStorage.clear(); +function clear() { + return AsyncStorage.clear(); }; -export {get, set, clear}; +export { + get, + set, + clear, +};