Skip to content

Commit

Permalink
Testing dev publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriztiaan committed Jul 1, 2024
1 parent 6b5ced4 commit 2b3d100
Show file tree
Hide file tree
Showing 6 changed files with 984 additions and 7,478 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-clouds-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/react-native': minor
---

Prebundling react-native dependencies with the aim of reducing the need for polyfills.
21 changes: 17 additions & 4 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"dist"
],
"scripts": {
"build": "tsc -b",
"build": "tsc -b && rollup -c rollup.config.mjs",
"build:bundle": "rollup -c rollup.config.mjs",
"clean": "rm -rf lib tsconfig.tsbuildinfo",
"watch": "tsc -b -w"
},
Expand All @@ -31,24 +32,36 @@
"@journeyapps/react-native-quick-sqlite": "^1.1.6",
"@powersync/common": "workspace:^1.10.0",
"react": "*",
"react-native": "*",
"react-native-polyfill-globals": "^3.1.0"
"react-native": "*"
},
"dependencies": {
"@powersync/common": "workspace:*",
"@powersync/react": "workspace:*",
"async-lock": "^1.4.0",
"bson": "^6.6.0"
"bson": "^6.6.0",
"react-native-fetch-api": "^3.0.0",
"react-native-get-random-values": "^1.11.0",
"@craftzdog/react-native-buffer": "^6.0.5",
"web-streams-polyfill": "3.2.1"
},
"devDependencies": {
"@babel/core": "^7.24.6",
"@babel/preset-env": "^7.24.6",
"@babel/preset-react": "^7.24.6",
"@journeyapps/react-native-quick-sqlite": "^1.1.6",
"@rollup/plugin-inject": "^5.0.5",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-typescript": "11.1.6",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@types/async-lock": "^1.4.0",
"babel-loader": "^9.1.3",
"magic-string": "0.30.10",
"react": "18.2.0",
"react-native": "0.72.4",
"rollup": "4.14.3",
"rollup-plugin-esbuild": "^6.1.1",
"text-encoding": "^0.7.0",
"typescript": "^5.1.3",
"webpack": "^5.90.1",
"webpack-cli": "^5.1.4"
Expand Down
31 changes: 31 additions & 0 deletions packages/react-native/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import inject from '@rollup/plugin-inject';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';

const input = 'lib/index.js';

const config = [
{
input,
output: {
file: 'dist/main.js',
format: 'cjs',
sourcemap: true
},
plugins: [
json(),
nodeResolve({}),
commonjs(),
inject({
Buffer: ['@craftzdog/react-native-buffer', 'Buffer'],
ReadableStream: ['web-streams-polyfill', 'ReadableStream'],
TextEncoder: ['text-encoding', 'TextEncoder'],
TextDecoder: ['text-encoding', 'TextDecoder']
})
],
external: ['bson', 'react-native', 'react', '@powersync/react', 'node-fetch']
}
];

export default config;
44 changes: 22 additions & 22 deletions packages/react-native/src/sync/stream/ReactNativeRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ type PolyfillTest = {
};

const CommonPolyfills: PolyfillTest[] = [
{
name: 'TextEncoder',
test: () => typeof TextEncoder == 'undefined'
}
// {
// name: 'TextEncoder',
// test: () => typeof TextEncoder == 'undefined'
// }
];

const SocketPolyfillTests: PolyfillTest[] = [
...CommonPolyfills,
{
name: 'nextTick',
test: () => typeof process.nextTick == 'undefined'
},
{
name: 'Buffer',
test: () => typeof global.Buffer == 'undefined'
}
...CommonPolyfills
// {
// name: 'nextTick',
// test: () => typeof process.nextTick == 'undefined'
// },
// {
// name: 'Buffer',
// test: () => typeof global.Buffer == 'undefined'
// }
];

const HttpPolyfillTests: PolyfillTest[] = [
...CommonPolyfills,
{
name: 'TextDecoder',
test: () => typeof TextDecoder == 'undefined'
},
{
name: 'ReadableStream',
test: () => typeof ReadableStream == 'undefined'
}
...CommonPolyfills
// {
// name: 'TextDecoder',
// test: () => typeof TextDecoder == 'undefined'
// },
// {
// name: 'ReadableStream',
// test: () => typeof ReadableStream == 'undefined'
// }
];

const validatePolyfills = (tests: PolyfillTest[]) => {
Expand Down
8 changes: 2 additions & 6 deletions packages/react-native/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ module.exports = {
react: "require('react')",
'react-native': "require('react-native')",
'@powersync/react': "require('@powersync/react')",
bson: "require('bson')"
// crypto: "require('crypto')"
crypto: 'crypto'
},
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist')
},
target: ['es5', 'web'],
module: {
rules: [
{
Expand All @@ -24,9 +22,7 @@ module.exports = {
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ['module:metro-react-native-babel-preset'],
plugins: [['react-native-web', { commonjs: true }]]
presets: ['@babel/preset-env', '@babel/preset-react']
}
}
}
Expand Down
Loading

0 comments on commit 2b3d100

Please sign in to comment.