From a2cac24194ef44b848be67fe7a70705bb0ea935f Mon Sep 17 00:00:00 2001 From: Christiaan Landman Date: Mon, 15 Jul 2024 10:46:28 +0200 Subject: [PATCH] Testing rollup common with tsc web. --- packages/web/package.json | 4 ++-- .../SharedWebStreamingSyncImplementation.ts | 18 +++++++------- .../web/src/worker/db/open-worker-database.ts | 24 +++++++++---------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/packages/web/package.json b/packages/web/package.json index d78f6053..2a1ea879 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -2,7 +2,7 @@ "name": "@powersync/web", "version": "1.2.0", "description": "A Web SDK for JourneyApps PowerSync", - "main": "dist/index.js", + "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "files": [ "lib", @@ -19,7 +19,7 @@ }, "homepage": "https://docs.powersync.com", "scripts": { - "build": "tsc --build && vite build", + "build": "tsc --build", "clean": "rm -rf lib tsconfig.tsbuildinfo", "watch": "tsc --build -w", "test": "pnpm build && vitest" diff --git a/packages/web/src/db/sync/SharedWebStreamingSyncImplementation.ts b/packages/web/src/db/sync/SharedWebStreamingSyncImplementation.ts index 40671fce..5dc0a8d7 100644 --- a/packages/web/src/db/sync/SharedWebStreamingSyncImplementation.ts +++ b/packages/web/src/db/sync/SharedWebStreamingSyncImplementation.ts @@ -11,7 +11,6 @@ import { import { AbstractSharedSyncClientProvider } from '../../worker/sync/AbstractSharedSyncClientProvider'; import { PowerSyncConnectionOptions, PowerSyncCredentials, SyncStatus, SyncStatusOptions } from '@powersync/common'; import { openWorkerDatabasePort } from '../../worker/db/open-worker-database'; -import SharedSyncImplementationWorker from '../../worker/sync/SharedSyncImplementation.worker?sharedworker&inline'; /** * The shared worker will trigger methods on this side of the message port @@ -94,13 +93,14 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem * Configure or connect to the shared sync worker. * This worker will manage all syncing operations remotely. */ - const syncWorker = new SharedSyncImplementationWorker({ name: `shared-sync-${this.webOptions.identifier}` }); - - // new SharedWorker(new URL('../../worker/sync/SharedSyncImplementation.worker.js', import.meta.url), { - // /* @vite-ignore */ - // name: `shared-sync-${this.webOptions.identifier}`, - // type: 'module' - // }); + const syncWorker = new SharedWorker( + new URL('../../worker/sync/SharedSyncImplementation.worker.js', import.meta.url), + { + /* @vite-ignore */ + name: `shared-sync-${this.webOptions.identifier}`, + type: 'module' + } + ); this.messagePort = syncWorker.port; this.syncManager = Comlink.wrap(this.messagePort); this.triggerCrudUpload = this.syncManager.triggerCrudUpload; @@ -112,7 +112,7 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem * sync worker. */ const { crudUploadThrottleMs, identifier, retryDelayMs } = this.options; - const dbOpenerPort = openWorkerDatabasePort(this.options.identifier!, true) as any; + const dbOpenerPort = openWorkerDatabasePort(this.options.identifier!, true) as MessagePort; this.isInitialized = this.syncManager.init(Comlink.transfer(dbOpenerPort, [dbOpenerPort]), { dbName: this.options.identifier!, streamOptions: { diff --git a/packages/web/src/worker/db/open-worker-database.ts b/packages/web/src/worker/db/open-worker-database.ts index 9d0238b2..c3400659 100644 --- a/packages/web/src/worker/db/open-worker-database.ts +++ b/packages/web/src/worker/db/open-worker-database.ts @@ -1,6 +1,5 @@ import * as Comlink from 'comlink'; import type { OpenDB } from '../../shared/types'; -import SharedPsWorker from './SharedWASQLiteDB.worker?sharedworker&inline'; /** * Opens a shared or dedicated worker which exposes opening of database connections @@ -12,18 +11,17 @@ export function openWorkerDatabasePort(workerIdentifier: string, multipleTabs = * This enables multi tab support by default, but falls back if SharedWorker is not available * (in the case of Android) */ - return new SharedPsWorker({ name: `shared-DB-worker-${workerIdentifier}` }).port; - // return multipleTabs - // ? new SharedWorker(new URL('./SharedWASQLiteDB.worker.js', import.meta.url), { - // /* @vite-ignore */ - // name: `shared-DB-worker-${workerIdentifier}`, - // type: 'module' - // }).port - // : new Worker(new URL('./WASQLiteDB.worker.js', import.meta.url), { - // /* @vite-ignore */ - // name: `DB-worker-${workerIdentifier}`, - // type: 'module' - // }); + return multipleTabs + ? new SharedWorker(new URL('./SharedWASQLiteDB.worker.js', import.meta.url), { + /* @vite-ignore */ + name: `shared-DB-worker-${workerIdentifier}`, + type: 'module' + }).port + : new Worker(new URL('./WASQLiteDB.worker.js', import.meta.url), { + /* @vite-ignore */ + name: `DB-worker-${workerIdentifier}`, + type: 'module' + }); } /**