Skip to content

Commit 083098c

Browse files
Add CommonJS builds for Kysely and Drizzle
1 parent 1b73323 commit 083098c

11 files changed

Lines changed: 848 additions & 734 deletions

File tree

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@
3333
"@actions/core": "^1.10.1",
3434
"@changesets/cli": "2.27.2",
3535
"@pnpm/workspace.find-packages": "^4.0.2",
36+
"@rollup/plugin-commonjs": "^25.0.7",
37+
"@rollup/plugin-node-resolve": "15.2.3",
38+
"@rollup/plugin-typescript": "^12.1.4",
3639
"@vitest/browser": "^3.2.4",
3740
"husky": "^9.0.11",
3841
"lint-staged": "^15.2.2",
3942
"playwright": "^1.51.0",
4043
"prettier": "^3.2.5",
4144
"prettier-plugin-embed": "^0.4.15",
4245
"prettier-plugin-sql": "^0.18.1",
46+
"rollup": "4.14.3",
4347
"typescript": "^5.7.2",
4448
"vitest": "^3.2.4"
4549
}

packages/attachments/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@
1717
},
1818
"description": "An PowerSync library to manage attachments for TypeScript and React Native apps",
1919
"type": "module",
20-
"main": "./lib/index.js",
20+
"main": "./dist/index.cjs",
2121
"module": "./lib/index.js",
2222
"types": "./lib/index.d.ts",
2323
"exports": {
2424
".": {
2525
"types": "./lib/index.d.ts",
2626
"import": "./lib/index.js",
27+
"require": "./dist/index.cjs",
2728
"default": "./lib/index.js"
2829
}
2930
},
3031
"files": [
3132
"lib"
3233
],
3334
"scripts": {
34-
"build": "tsc -b",
35-
"build:prod": "tsc -b --sourceMap false",
35+
"build": "tsc -b && rollup --config",
36+
"build:prod": "tsc -b --sourceMap false && rollup --config --sourceMap=false",
3637
"clean": "rm -rf lib",
3738
"watch": "tsc -b -w",
3839
"test": "pnpm build && vitest"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import commonjs from '@rollup/plugin-commonjs';
2+
import resolve from '@rollup/plugin-node-resolve';
3+
import typescript from '@rollup/plugin-typescript';
4+
5+
/** @type {import('rollup').RollupOptions} */
6+
export default (commandLineArgs) => {
7+
const sourceMap = (commandLineArgs.sourceMap || 'true') == 'true';
8+
9+
// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
10+
delete commandLineArgs.sourceMap;
11+
12+
return {
13+
input: 'src/index.ts',
14+
output: {
15+
format: 'cjs',
16+
file: 'dist/index.cjs',
17+
sourcemap: sourceMap,
18+
exports: 'named'
19+
},
20+
plugins: [
21+
resolve(),
22+
commonjs(),
23+
typescript({
24+
tsconfig: './tsconfig.json',
25+
outDir: 'dist',
26+
sourceMap
27+
})
28+
],
29+
external: ['@powersync/common']
30+
};
31+
};

packages/drizzle-driver/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
"version": "0.4.0",
44
"description": "Drizzle driver for PowerSync",
55
"type": "module",
6-
"main": "lib/src/index.js",
6+
"main": "dist/index.cjs",
77
"module": "lib/src/index.js",
88
"types": "lib/src/index.d.ts",
99
"exports": {
1010
".": {
1111
"types": "./lib/src/index.d.ts",
1212
"import": "./lib/src/index.js",
13+
"require": "./dist/index.cjs",
1314
"default": "./lib/src/index.js"
1415
}
1516
},
@@ -28,8 +29,8 @@
2829
},
2930
"homepage": "https://docs.powersync.com",
3031
"scripts": {
31-
"build": "tsc --build",
32-
"build:prod": "tsc --build --sourceMap false",
32+
"build": "tsc -b && rollup --config",
33+
"build:prod": "tsc -b --sourceMap false && rollup --config --sourceMap=false",
3334
"clean": "rm -rf lib",
3435
"watch": "tsc --build -w",
3536
"test": "vitest"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import commonjs from '@rollup/plugin-commonjs';
2+
import resolve from '@rollup/plugin-node-resolve';
3+
import typescript from '@rollup/plugin-typescript';
4+
5+
/** @type {import('rollup').RollupOptions} */
6+
export default (commandLineArgs) => {
7+
const sourceMap = (commandLineArgs.sourceMap || 'true') == 'true';
8+
9+
// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
10+
delete commandLineArgs.sourceMap;
11+
12+
return {
13+
input: 'src/index.ts',
14+
output: {
15+
format: 'cjs',
16+
file: 'dist/index.cjs',
17+
sourcemap: sourceMap,
18+
exports: 'named'
19+
},
20+
plugins: [
21+
resolve(),
22+
commonjs(),
23+
typescript({
24+
tsconfig: './tsconfig.json',
25+
outDir: 'dist',
26+
sourceMap,
27+
/**
28+
* The Typescript plugin complains about internal Drizzle types not matching when selecting
29+
* other moduleResolution settings.
30+
*/
31+
moduleResolution: 'bundler'
32+
})
33+
],
34+
external: ['@powersync/common', /^drizzle-orm(\/.*)?$/]
35+
};
36+
};

packages/kysely-driver/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
"version": "1.2.0",
44
"description": "Kysely driver for PowerSync",
55
"type": "module",
6-
"main": "lib/src/index.js",
6+
"main": "dist/index.cjs",
77
"module": "lib/src/index.js",
88
"types": "lib/src/index.d.ts",
99
"exports": {
1010
".": {
1111
"types": "./lib/src/index.d.ts",
1212
"import": "./lib/src/index.js",
13+
"require": "./dist/index.cjs",
1314
"default": "./lib/src/index.js"
1415
}
1516
},
@@ -28,8 +29,8 @@
2829
},
2930
"homepage": "https://docs.powersync.com",
3031
"scripts": {
31-
"build": "tsc --build",
32-
"build:prod": "tsc --build --sourceMap false",
32+
"build": "tsc -b && rollup --config",
33+
"build:prod": "tsc -b --sourceMap false && rollup --config --sourceMap=false",
3334
"clean": "rm -rf lib",
3435
"watch": "tsc --build -w",
3536
"test": "pnpm build && vitest"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import commonjs from '@rollup/plugin-commonjs';
2+
import resolve from '@rollup/plugin-node-resolve';
3+
import typescript from '@rollup/plugin-typescript';
4+
5+
/** @type {import('rollup').RollupOptions} */
6+
export default (commandLineArgs) => {
7+
const sourceMap = (commandLineArgs.sourceMap || 'true') == 'true';
8+
9+
// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
10+
delete commandLineArgs.sourceMap;
11+
12+
return {
13+
input: 'src/index.ts',
14+
output: {
15+
format: 'cjs',
16+
file: 'dist/index.cjs',
17+
sourcemap: sourceMap,
18+
exports: 'named'
19+
},
20+
plugins: [
21+
resolve(),
22+
commonjs(),
23+
typescript({
24+
tsconfig: './tsconfig.json',
25+
outDir: 'dist',
26+
sourceMap
27+
})
28+
],
29+
external: ['@powersync/common', 'kysely']
30+
};
31+
};

packages/react/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77
},
88
"description": "React components for JourneyApps PowerSync",
99
"main": "./lib/index.js",
10+
"module": "lib/index.js",
1011
"types": "./lib/index.d.ts",
1112
"files": [
1213
"lib"
1314
],
15+
"exports": {
16+
".": {
17+
"types": "./lib/index.d.ts",
18+
"import": "./lib/index.js",
19+
"default": "./lib/index.js"
20+
}
21+
},
1422
"scripts": {
1523
"build": "tsc -b",
1624
"build:prod": "tsc -b --sourceMap false",

packages/web/src/db/sync/WebStreamingSyncImplementation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
AbstractStreamingSyncImplementation,
33
AbstractStreamingSyncImplementationOptions,
4-
createLogger,
54
LockOptions,
65
LockType
76
} from '@powersync/common';
@@ -25,7 +24,7 @@ export class WebStreamingSyncImplementation extends AbstractStreamingSyncImpleme
2524
return this.options as WebStreamingSyncImplementationOptions;
2625
}
2726

28-
obtainLock<T>(lockOptions: LockOptions<T>): Promise<T> {
27+
async obtainLock<T>(lockOptions: LockOptions<T>): Promise<T> {
2928
const identifier = `streaming-sync-${lockOptions.type}-${this.webOptions.identifier}`;
3029
if (lockOptions.type == LockType.SYNC) {
3130
this.logger.debug('requesting lock for ', identifier);

packages/web/src/worker/db/WASQLiteDB.worker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import '@journeyapps/wa-sqlite';
6+
import { createBaseLogger, createLogger } from '@powersync/common';
67
import * as Comlink from 'comlink';
78
import { AsyncDatabaseConnection } from '../../db/adapters/AsyncDatabaseConnection';
89
import { WASqliteConnection } from '../../db/adapters/wa-sqlite/WASQLiteConnection';
@@ -11,7 +12,6 @@ import {
1112
WorkerDBOpenerOptions
1213
} from '../../db/adapters/wa-sqlite/WASQLiteOpenFactory';
1314
import { getNavigatorLocks } from '../../shared/navigator';
14-
import { createBaseLogger, createLogger } from '@powersync/common';
1515

1616
const baseLogger = createBaseLogger();
1717
baseLogger.useDefaults();
@@ -71,10 +71,10 @@ const openDBShared = async (options: WorkerDBOpenerOptions): Promise<AsyncDataba
7171

7272
const wrappedConnection = {
7373
...db,
74-
init: Comlink.proxy(() => {
74+
init: Comlink.proxy(async () => {
7575
// the init has been done automatically
7676
}),
77-
close: Comlink.proxy(() => {
77+
close: Comlink.proxy(async () => {
7878
const { clientIds } = dbEntry;
7979
logger.debug(`Close requested from client ${clientId} of ${[...clientIds]}`);
8080
clientIds.delete(clientId);

0 commit comments

Comments
 (0)