Skip to content

Commit 441fdb6

Browse files
authored
fix web dependency handling and example testing mechanism (#6)
1 parent 3723e44 commit 441fdb6

File tree

13 files changed

+70
-13
lines changed

13 files changed

+70
-13
lines changed

.circleci/config.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ jobs:
109109
command: |-
110110
cd example/ToolbarAndroidExample-061
111111
rm -rf node_modules
112-
113-
# to avoid yarn integrity failure due to our file-based package installation
114-
rm yarn.lock
115112
yarn cache clean
113+
114+
yarn sync & wait
116115
yarn install --network-concurrency 1 --non-interactive --cache-folder ~/.cache/yarn & wait
117116
- persist_to_workspace:
118117
root: .

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ DerivedData
2929
*.ipa
3030
*.xcuserstate
3131
project.xcworkspace
32+
*.tgz
3233

3334

3435
# Android/IntelliJ
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
# Examples
3+
These examples are meant to test with the local toolbar-android changes.
4+
5+
# How to run:
6+
7+
- install `@react-native-community/toolbar-android` from local repo: `yarn sync` (this is a passive sync, i.e. you need to do this manually when you want to test the changes)
8+
- test: `yarn test`
9+
- run: `yarn ios` or `yarn android`

example/ToolbarAndroidExample-060/__tests__/App-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'react-native';
66
import React from 'react';
7-
import App from '../App';
7+
import App from '../ToolbarAndroidExample';
88

99
// Note: test renderer must be required after react-native.
1010
import renderer from 'react-test-renderer';

example/ToolbarAndroidExample-060/package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
"version": "0.0.1",
44
"private": true,
55
"scripts": {
6+
"sync": "../scripts/update-local-pkg.sh ../..",
7+
"android": "react-native run-android",
8+
"ios": "react-native run-ios",
69
"start": "react-native start",
7-
"test": "jest"
10+
"test": "jest",
11+
"lint": "eslint ."
812
},
913
"dependencies": {
10-
"@react-native-community/toolbar-android": "file:../../react-native-community-toolbar-android-0.1.0-rc.1.tgz",
14+
"@react-native-community/toolbar-android": "file:../../react-native-community-toolbar-android-current.tgz",
1115
"react": "16.8.6",
1216
"react-native": "0.60.0"
1317
},

example/ToolbarAndroidExample-060/yarn.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -928,9 +928,9 @@
928928
eslint-plugin-react-native "3.6.0"
929929
prettier "1.16.4"
930930

931-
"@react-native-community/toolbar-android@file:../../react-native-community-toolbar-android-0.1.0-rc.1.tgz":
931+
"@react-native-community/toolbar-android@file:../../react-native-community-toolbar-android-current.tgz":
932932
version "0.1.0-rc.1"
933-
resolved "file:../../react-native-community-toolbar-android-0.1.0-rc.1.tgz#5cd8451295628d6a5f87b2e6c162a94c0124de8d"
933+
resolved "file:../../react-native-community-toolbar-android-current.tgz#d88a050f13df0c50eb03bb2e993d1ebbf6483751"
934934

935935
"@types/babel__core@^7.1.0":
936936
version "7.1.3"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
# Examples
3+
These examples are meant to test with the local toolbar-android changes.
4+
5+
# How to run:
6+
7+
- install `@react-native-community/toolbar-android` from local repo: `yarn sync` (this is a passive sync, i.e. you need to do this manually when you want to test the changes)
8+
- test: `yarn test`
9+
- run: `yarn ios` or `yarn android`

example/ToolbarAndroidExample-061/__tests__/App-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'react-native';
66
import React from 'react';
7-
import App from '../App';
7+
import App from '../ToolbarAndroidExample';
88

99
// Note: test renderer must be required after react-native.
1010
import renderer from 'react-test-renderer';

example/ToolbarAndroidExample-061/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
"version": "0.0.1",
44
"private": true,
55
"scripts": {
6+
"sync": "../scripts/update-local-pkg.sh ../..",
67
"android": "react-native run-android",
78
"ios": "react-native run-ios",
89
"start": "react-native start",
910
"test": "jest",
1011
"lint": "eslint ."
1112
},
1213
"dependencies": {
13-
"@react-native-community/toolbar-android": "file:../../react-native-community-toolbar-android-0.1.0-rc.1.tgz",
14+
"@react-native-community/toolbar-android": "file:../../react-native-community-toolbar-android-current.tgz",
1415
"react": "16.9.0",
1516
"react-native": "0.61.5"
1617
},

example/ToolbarAndroidExample-061/yarn.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,9 @@
948948
eslint-plugin-react-native "3.6.0"
949949
prettier "1.16.4"
950950

951-
"@react-native-community/toolbar-android@file:../../react-native-community-toolbar-android-0.1.0-rc.1.tgz":
951+
"@react-native-community/toolbar-android@file:../../react-native-community-toolbar-android-current.tgz":
952952
version "0.1.0-rc.1"
953-
resolved "file:../../react-native-community-toolbar-android-0.1.0-rc.1.tgz#5cd8451295628d6a5f87b2e6c162a94c0124de8d"
953+
resolved "file:../../react-native-community-toolbar-android-current.tgz#d88a050f13df0c50eb03bb2e993d1ebbf6483751"
954954

955955
"@types/babel__core@^7.1.0":
956956
version "7.1.3"

example/scripts/update-local-pkg.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
#
4+
# setup example environment by creating a local repo for main code base
5+
# Note: this should be executed from the actual example directory
6+
#
7+
PROJECT_ROOT="$1"
8+
PKG_NAME="@react-native-community/toolbar-android"
9+
LOCAL_REPO="../${SCRIPT_DIR}/repo"
10+
PKG_CURRENT="react-native-community-toolbar-android-current.tgz"
11+
CWD=`pwd`
12+
13+
echo "** packaging @react-native-community/toolbar-android..."
14+
cd "${PROJECT_ROOT}"
15+
PKG_FILE=`npm pack 2> /dev/null`
16+
mv "${PKG_FILE}" "${PKG_CURRENT}"
17+
echo "${PKG_FILE} => ${PKG_CURRENT}"
18+
echo "${PKG_CURRENT} is ready..."
19+
20+
cd ${CWD}
21+
echo "** install the local package..."
22+
yarn cache clean
23+
yarn add "file:${PROJECT_ROOT}/${PKG_CURRENT}"

js/ToolbarAndroid.web.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,15 @@
99

1010
'use strict';
1111

12-
module.exports = require('react-native/Libraries/Components/UnimplementedViews/UnimplementedView');
12+
let m;
13+
try {
14+
// This is an optional dependency. However, webpack might still show warning message.
15+
m = require('react-native/Libraries/Components/UnimplementedViews/UnimplementedView');
16+
} catch {
17+
// If failed to find react-native UnimplementedView, just returns an empty module so
18+
// this won't cause bundling related error, however any subsequent attempt of using this module
19+
// in such situation shall caused compile-error because it really should not be used for web.
20+
m = {};
21+
}
22+
23+
module.exports = m;
Binary file not shown.

0 commit comments

Comments
 (0)