Skip to content

Commit

Permalink
[polyfills] Bundling of package dependencies (#237)
Browse files Browse the repository at this point in the history
Co-authored-by: Steven Ontong <[email protected]>
  • Loading branch information
Chriztiaan and stevensJourney authored Jul 29, 2024
1 parent b0b31ac commit 02ae5de
Show file tree
Hide file tree
Showing 40 changed files with 16,582 additions and 21,548 deletions.
9 changes: 9 additions & 0 deletions .changeset/brave-owls-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@powersync/attachments': minor
'@powersync/kysely-driver': minor
'@powersync/react': minor
'@powersync/vue': minor
'@powersync/web': minor
---

Prebundling dependencies with the aim of reducing the need for polyfills.
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.
5 changes: 5 additions & 0 deletions .changeset/nasty-timers-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/common': minor
---

Prebundling common package with the aim of reducing the need for polyfills.
6 changes: 1 addition & 5 deletions demos/angular-supabase-todolist/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@
"path": "./extra-webpack.config.js"
},
"allowedCommonJsDependencies": [
"object-hash",
"event-iterator",
"can-ndjson-stream",
"lodash",
"js-logger",
"websocket"
"ws"
],
"outputPath": "dist",
"index": "src/index.html",
Expand Down
11 changes: 0 additions & 11 deletions demos/django-react-native-todolist/library/stores/system.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import '@azure/core-asynciterator-polyfill';
import 'react-native-polyfill-globals/auto';
import React from 'react';
import { AbstractPowerSyncDatabase, PowerSyncDatabase, SyncStreamConnectionMethod } from '@powersync/react-native';
import { Buffer } from '@craftzdog/react-native-buffer';
import { AppSchema } from '../powersync/AppSchema';
import { DjangoConnector } from '../django/DjangoConnector';

if (typeof process.nextTick == 'undefined') {
process.nextTick = setImmediate;
}

if (typeof global.Buffer == 'undefined') {
// @ts-ignore
global.Buffer = Buffer;
}

export class System {
djangoConnector: DjangoConnector;
powersync: AbstractPowerSyncDatabase;
Expand Down
9 changes: 1 addition & 8 deletions demos/django-react-native-todolist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
},
"dependencies": {
"@azure/core-asynciterator-polyfill": "^1.0.2",
"@craftzdog/react-native-buffer": "^6.0.5",
"@expo/vector-icons": "^14.0.0",
"@journeyapps/react-native-quick-sqlite": "^1.1.7",
"@powersync/common": "workspace:*",
Expand All @@ -20,7 +19,6 @@
"@react-navigation/drawer": "^6.6.15",
"@react-navigation/native": "^6.1.17",
"@supabase/supabase-js": "^2.42.4",
"base-64": "^1.0.0",
"expo": "~51.0.10",
"expo-build-properties": "~0.12.1",
"expo-constants": "~16.0.2",
Expand All @@ -36,21 +34,16 @@
"react-native": "0.74.1",
"react-native-elements": "^3.4.3",
"react-native-encrypted-storage": "^4.0.3",
"react-native-fetch-api": "^3.0.0",
"react-native-gesture-handler": "~2.16.2",
"react-native-polyfill-globals": "^3.1.0",
"react-native-prompt-android": "^1.1.0",
"react-native-reanimated": "~3.10.1",
"react-native-safe-area-context": "4.10.1",
"react-native-safe-area-view": "^1.1.1",
"react-native-screens": "~3.31.1",
"react-native-table-component": "^1.2.2",
"react-native-url-polyfill": "^2.0.0",
"react-native-vector-icons": "^10.0.0",
"react-navigation-stack": "^2.10.4",
"text-encoding": "^0.7.0",
"typed-async-storage": "^3.1.2",
"web-streams-polyfill": "^3.3.3"
"typed-async-storage": "^3.1.2"
},
"devDependencies": {
"@babel/plugin-transform-async-generator-functions": "^7.24.3",
Expand Down
8 changes: 1 addition & 7 deletions demos/example-capacitor/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ export default defineConfig({
// Don't optimize these packages as they contain web workers and WASM files.
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
include: [
'@powersync/web > uuid',
'@powersync/web > event-iterator',
'@powersync/web > js-logger',
'@powersync/web > lodash/throttle',
'@powersync/web > can-ndjson-stream'
]
include: []
},
plugins: [wasm(), topLevelAwait()],
worker: {
Expand Down
11 changes: 1 addition & 10 deletions demos/example-electron/vite.renderer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ export default defineConfig((env) => {
// Don't optimize these packages as they contain web workers and WASM files.
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
include: [
'@powersync/web > event-iterator',
'@powersync/web > js-logger',
'@powersync/web > lodash/throttle',
'@powersync/web > can-ndjson-stream',
'@powersync/web > buffer',
'@powersync/web > rsocket-core',
'@powersync/web > rsocket-websocket-client',
'@powersync/web > cross-fetch'
]
include: []
},
plugins: [
// @ts-expect-error there is TS issue that doesn't actually affect the runtime
Expand Down
1 change: 0 additions & 1 deletion demos/example-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"@mui/material": "^5.15.18",
"@powersync/react": "workspace:*",
"@powersync/web": "workspace:*",
"buffer": "^6.0.3",
"js-logger": "^1.6.1",
"lato-font": "^3.0.0",
"lexical": "^0.15.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import { CircularProgress } from '@mui/material';
import Logger from 'js-logger';
import React, { Suspense } from 'react';

import { Buffer } from 'buffer';

// Polyfill for WebSockets
if (typeof self.Buffer == 'undefined') {
self.Buffer = Buffer;
}

// eslint-disable-next-line react-hooks/rules-of-hooks
Logger.useDefaults();
Logger.setLevel(Logger.DEBUG);
Expand Down
11 changes: 1 addition & 10 deletions demos/example-vite/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ export default defineConfig({
// Don't optimize these packages as they contain web workers and WASM files.
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
include: [
'@powersync/web > event-iterator',
'@powersync/web > js-logger',
'@powersync/web > lodash/throttle',
'@powersync/web > can-ndjson-stream',
'@powersync/web > buffer',
'@powersync/web > rsocket-core',
'@powersync/web > rsocket-websocket-client',
'@powersync/web > cross-fetch'
]
include: []
},
plugins: [wasm(), topLevelAwait()],
worker: {
Expand Down
11 changes: 1 addition & 10 deletions demos/react-multi-client/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ export default defineConfig({
// Don't optimize these packages as they contain web workers and WASM files.
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
include: [
'@powersync/web > event-iterator',
'@powersync/web > js-logger',
'@powersync/web > lodash/throttle',
'@powersync/web > can-ndjson-stream',
'@powersync/web > buffer',
'@powersync/web > rsocket-core',
'@powersync/web > rsocket-websocket-client',
'@powersync/web > cross-fetch'
]
include: []
},
plugins: [
wasm(),
Expand Down
8 changes: 1 addition & 7 deletions demos/react-native-supabase-group-chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@tamagui/font-inter": "1.79.6",
"@tamagui/lucide-icons": "1.79.6",
"@tamagui/theme-base": "1.79.6",
"base-64": "^1.0.0",
"date-fns": "^2.30.0",
"expo": "~51.0.10",
"expo-build-properties": "~0.12.1",
Expand All @@ -48,19 +47,14 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.74.1",
"react-native-fetch-api": "^3.0.0",
"react-native-gesture-handler": "~2.16.2",
"react-native-pager-view": "6.3.0",
"react-native-polyfill-globals": "^3.1.0",
"react-native-reanimated": "~3.10.1",
"react-native-safe-area-context": "4.10.1",
"react-native-screens": "~3.31.1",
"react-native-svg": "15.2.0",
"react-native-url-polyfill": "^2.0.0",
"react-native-web": "0.19.12",
"tamagui": "1.79.6",
"text-encoding": "^0.7.0",
"web-streams-polyfill": "3.2.1"
"tamagui": "1.79.6"
},
"devDependencies": {
"@babel/core": "7.24.5",
Expand Down
28 changes: 11 additions & 17 deletions demos/react-native-supabase-group-chat/src/lib/supabase.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import "react-native-url-polyfill/auto";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { createClient } from "@supabase/supabase-js";
import AsyncStorage from '@react-native-async-storage/async-storage';
import { createClient } from '@supabase/supabase-js';

import { config } from "./config";
import { Database } from "./database.types";
import { config } from './config';
import { Database } from './database.types';

const authStorage = {
setItem: async (key: string, value: string) =>
await AsyncStorage.setItem(key, value),
setItem: async (key: string, value: string) => await AsyncStorage.setItem(key, value),
getItem: async (key: string) => await AsyncStorage.getItem(key),
removeItem: async (key: string) => await AsyncStorage.removeItem(key),
removeItem: async (key: string) => await AsyncStorage.removeItem(key)
};

export const supabase = createClient<Database>(
config.supabaseUrl,
config.supabaseAnonKey,
{
auth: {
storage: authStorage,
},
},
);
export const supabase = createClient<Database>(config.supabaseUrl, config.supabaseAnonKey, {
auth: {
storage: authStorage
}
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '@azure/core-asynciterator-polyfill';
import 'react-native-polyfill-globals/auto';
import { PowerSyncContext, PowerSyncDatabase } from '@powersync/react-native';
import Logger from 'js-logger';
import { ReactNode, useMemo } from 'react';
Expand Down
Loading

0 comments on commit 02ae5de

Please sign in to comment.