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

Support React Native #37

Merged
merged 21 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
544e411
Update build system to support a React Native bundle
smithki Apr 10, 2020
cecf18f
Add initial implementation for React Native (requires e2e testing)
smithki Apr 11, 2020
40d5e2c
Fix CJS builds and rename 'WebViewController' to 'ReactNativeWebViewC…
smithki Apr 11, 2020
60c926f
Remove unnecessary return statement
smithki Apr 11, 2020
063b820
Fix React dependency regex in Webpack config
smithki Apr 11, 2020
9e7e68d
Update CircleCI config
smithki Apr 11, 2020
ac50c28
Re-organize '/core' tests to reflect additional view controllers
smithki Apr 11, 2020
93e2657
Organizational comments
smithki Apr 11, 2020
d2e2021
Remove superfluous comment
smithki Apr 11, 2020
73e6c53
Add first draft CHANGELOG entry for React Native feature
smithki Apr 11, 2020
e6a1957
Update 'isViewReady' condition
smithki Apr 11, 2020
768dc7b
Package 'react-native-webview' and 'whatwg-url' in the RN bundle
smithki Apr 11, 2020
1abad60
Add .vscode to git ignores
smithki Apr 11, 2020
337e6c3
Add /dist to eslint ignores
smithki Apr 11, 2020
c62a6a6
Clean up Webpack config
smithki Apr 11, 2020
520e510
Externalize 'react-native-webview' & fix event listener bug in 'Paylo…
smithki Apr 14, 2020
857e503
Merge branch 'master' into react_native
smithki Apr 17, 2020
a690a39
Merge branch 'master' into react_native
smithki Apr 21, 2020
5385d97
Merge branch 'master' into react_native
smithki Apr 21, 2020
849d1b0
React native unit tests (#49)
smithki Apr 22, 2020
62cedc0
Add some testing cleanups
smithki Apr 22, 2020
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
Next Next commit
Update build system to support a React Native bundle
  • Loading branch information
smithki committed Apr 15, 2020
commit 544e411ea152b36578f3bd204333fed14c17d3b3
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/.idea
.DS_Store
/dist
/RN
/coverage
/.nyc_output
/package-lock.json
28 changes: 28 additions & 0 deletions config/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"lib": ["es2018", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
"strict": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"esModuleInterop": true,
"downlevelIteration": true,
"resolveJsonModule": true,
"allowJs": true,
"sourceMap": true,
"declaration": true,
},
"include": [
"../src/**/*.ts",
"../test/**/*.ts",
"../webpack/**/*.ts"
],
"exclude": [
"../node_modules",
"../dist"
]
}
9 changes: 9 additions & 0 deletions config/tsconfig.cdn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"rootDir": "../src",
"outDir": "../dist",
"declaration": false
},
"include": ["../src/**/*.ts"]
}
8 changes: 8 additions & 0 deletions config/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"rootDir": "../src",
"outDir": "../dist/cjs"
},
"include": ["../src/**/*.ts"]
}
8 changes: 8 additions & 0 deletions config/tsconfig.react-native.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"rootDir": "../src",
"outDir": "../RN"
},
"include": ["../src/**/*.ts"]
}
9 changes: 9 additions & 0 deletions config/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"target": "es6",
"strict": false,
"noImplicitAny": false
},
"include": ["../test/**/*.ts"]
}
4 changes: 4 additions & 0 deletions config/tsconfig.webpack.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.base.json",
"include": ["../webpack/**/*.ts"]
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"url": "https://github.com/fortmatic/magic-js"
},
"homepage": "https://www.fortmatic.com",
"main": "dist/cjs/magic.js",
"types": "dist/cjs/src/index.d.ts",
"main": "dist/cjs/index.js",
"types": "dist/cjs/index.d.ts",
"scripts": {
"start": "yarn run clean:build && ./scripts/start.sh",
"build": "yarn run clean:build && ./scripts/build.sh",
"test": "yarn run clean:test-artifacts && ./scripts/test.sh",
"lint": "eslint --fix src/**/*.ts",
"clean": "npm-run-all -s clean:*",
"clean:test-artifacts": "rimraf coverage && rimraf .nyc_output",
"clean:build": "rimraf dist",
"clean:build": "rimraf dist && rimraf RN",
"clean_node_modules": "rimraf node_modules"
},
"dependencies": {},
Expand Down
2 changes: 2 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export WEBPACK_ENV=production
export BABEL_ENV=production

export MAGIC_URL=https://auth.magic.link
export SDK_NAME=$(node -pe "require('./package.json')['name']")
export SDK_VERSION=$(node -pe "require('./package.json')['version']")

# Increase memory limit for Node
export NODE_OPTIONS=--max_old_space_size=4096
Expand Down
2 changes: 2 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export WEBPACK_ENV=development
export BABEL_ENV=development

export LOCAL_MAGIC_PORT=3014
export SDK_NAME=$(node -pe "require('./package.json')['name']")
export SDK_VERSION=$(node -pe "require('./package.json')['version']")

set -e
while test $# -gt 0; do
Expand Down
3 changes: 3 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ echo
echo "Running unit tests..."
echo

export SDK_NAME=$(node -pe "require('./package.json')['name']")
export SDK_VERSION=$(node -pe "require('./package.json')['version']")

if [ -n "$1" ]; then
input=$(echo $(npx glob $1))
fi
Expand Down
3 changes: 3 additions & 0 deletions src/constants/config.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export const MAGIC_URL = process.env.MAGIC_URL || 'https://auth.magic.link/';
export const IS_REACT_NATIVE = Boolean(Number(process.env.IS_REACT_NATIVE));
export const SDK_NAME = process.env.SDK_NAME!;
export const SDK_VERSION = process.env.SDK_VERSION!;
7 changes: 3 additions & 4 deletions src/core/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* eslint-disable no-underscore-dangle */

import { encodeQueryParameters } from '../util/query-params';
import { name as sdkName, version as sdkVersion } from '../../package.json';
import { createMissingApiKeyError } from './sdk-exceptions';
import { IframeController } from './iframe-controller';
import { PayloadTransport } from './payload-transport';
import { AuthModule } from '../modules/auth';
import { UserModule } from '../modules/user';
import { MAGIC_URL } from '../constants/config';
import { MAGIC_URL, SDK_NAME, SDK_VERSION, IS_REACT_NATIVE } from '../constants/config';
import { MagicSDKAdditionalConfiguration } from '../types';
import { RPCProviderModule } from '../modules/rpc-provider';

Expand Down Expand Up @@ -47,8 +46,8 @@ export class MagicSDK {
DOMAIN_ORIGIN: window.location ? window.location.origin : '',
ETH_NETWORK: options?.network,
host: new URL(this.endpoint).host,
sdk: sdkName,
version: sdkVersion,
sdk: IS_REACT_NATIVE ? `${SDK_NAME}-rn` : SDK_NAME,
version: SDK_VERSION,
});

/* istanbul ignore next */
Expand Down
13 changes: 1 addition & 12 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"strict": false,
"noImplicitAny": false,
"downlevelIteration": true,
"esModuleInterop": true
},
"include": [
"./**/*.ts"
]
"extends": "../config/tsconfig.test.json"
}
27 changes: 1 addition & 26 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
{
"compilerOptions": {
"lib": ["es2018", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
"strict": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"esModuleInterop": true,
"downlevelIteration": true,
"resolveJsonModule": true,
"allowJs": true,
"sourceMap": true,
"declaration": true,
"outDir": "dist/cjs"
},
"include": [
"src"
],
"exclude": [
"node_modules",
"dist",
"lib"
]
"extends": "./config/tsconfig.base.json"
}
4 changes: 3 additions & 1 deletion webpack/env-variables.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[
"MAGIC_URL"
"MAGIC_URL",
"SDK_NAME",
"SDK_VERSION"
]
3 changes: 1 addition & 2 deletions webpack/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"extends": "../tsconfig.json",
"include": ["."]
"extends": "../config/tsconfig.webpack.json"
}
42 changes: 30 additions & 12 deletions webpack/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
/* eslint-disable import/no-extraneous-dependencies */

import { resolve } from 'path';
import { EnvironmentPlugin } from 'webpack';
import { EnvironmentPlugin, DefinePlugin } from 'webpack';
import Config from 'webpack-chain';
import envVariables from './env-variables.json';

const isDevelopment = process.env.NODE_ENV !== 'production';

function configBase(transpileOnly = false) {
function configBase(tsconfig: string, transpileOnly = false) {
const config = new Config();

config.context(resolve(__dirname, '..'));
config.mode(isDevelopment ? 'development' : 'production');

/* eslint-disable prettier/prettier */
config.module
.rule('compile')
.test(/.tsx?$/)
.use('typescript')
.loader('ts-loader')
.options({ transpileOnly });
/* eslint-enable prettier/prettier */
.test(/.tsx?$/)
.use('typescript')
.loader('ts-loader')
.options({ transpileOnly, configFile: resolve(__dirname, `../config/${tsconfig}`) });

config.plugin('environment').use(EnvironmentPlugin, [envVariables]);

Expand All @@ -35,15 +33,35 @@ function configBase(transpileOnly = false) {
TypeScript to build ESM files for distribution.
*/

const configCJS = configBase();
const configCJS = configBase('tsconfig.cjs.json');
configCJS.name('cjs');
configCJS.entry('main').add('./src/index.ts');
configCJS.output
.path(resolve(__dirname, '../dist/cjs'))
.filename('magic.js')
.filename('index.js')
.libraryTarget('commonjs2');

const configCDN = configBase();
const configReactNative = configBase('tsconfig.react-native.json');
configReactNative.name('rn');
configReactNative.entry('main').add('./src/index.ts');
configReactNative.plugin('rn-environment').use(DefinePlugin, [
{
'process.env.IS_REACT_NATIVE': JSON.stringify(1),
},
]);
configReactNative.externals({
react: 'react',
'react-native': 'react-native',
'react-dom': 'react-dom',
'react-native-webview': 'react-native-webview',
});
configReactNative.output
.path(resolve(__dirname, '../RN'))
.filename('index.js')
.libraryTarget('commonjs2')
.libraryExport('default');

const configCDN = configBase('tsconfig.cdn.json');
configCDN.name('cdn');
configCDN.entry('main').add('./src/index.cdn.ts');
configCDN.output
Expand All @@ -53,4 +71,4 @@ configCDN.output
.libraryExport('default')
.library('Magic');

module.exports = [configCJS.toConfig(), configCDN.toConfig()];
module.exports = [configCJS.toConfig(), configReactNative.toConfig(), configCDN.toConfig()];