Skip to content

Commit 3e4a25c

Browse files
authored
Refactor build logic (#753)
Include partial source maps in outputs, bundle fewer dependencies, don't use minified builds.
1 parent a1d7e79 commit 3e4a25c

File tree

25 files changed

+582
-305
lines changed

25 files changed

+582
-305
lines changed

.changeset/nasty-pugs-brake.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@powersync/tanstack-react-query': patch
3+
'@powersync/op-sqlite': patch
4+
'@powersync/adapter-sql-js': patch
5+
'@powersync/drizzle-driver': patch
6+
'@powersync/kysely-driver': patch
7+
'@powersync/react-native': patch
8+
'@powersync/diagnostics-app': patch
9+
'@powersync/attachments': patch
10+
'@powersync/capacitor': patch
11+
'@powersync/common': patch
12+
'@powersync/react': patch
13+
'@powersync/node': patch
14+
'@powersync/vue': patch
15+
'@powersync/web': patch
16+
---
17+
18+
Don't minify releases, enable source maps.

demos/example-electron-node/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ To see it in action:
2121
1. Make sure to run `pnpm install` and `pnpm build:packages` in the root directory of this repo.
2222
2. Copy `.env.local.template` to `.env.local`, and complete the environment variables. You can generate a [temporary development token](https://docs.powersync.com/usage/installation/authentication-setup/development-tokens), or leave blank to test with local-only data.
2323
The example works with the schema from the [PowerSync + Supabase tutorial](https://docs.powersync.com/integration-guides/supabase-+-powersync#supabase-powersync).
24-
3. `cd` into this directory. In this mono-repo, you'll have to run `./node_modules/.bin/electron-rebuild` once to make sure `@powersync/better-sqlite3` was compiled with Electron's toolchain.
24+
3. `cd` into this directory. In this mono-repo, you'll have to run `./node_modules/.bin/electron-rebuild` once to make sure `better-sqlite3` was compiled with Electron's toolchain.
25+
Sometimes that doesn't work, you can also go to `node_modules/better-sqlite3` and manually run `HOME=~/.electron-gyp node-gyp rebuild --target=37.0.0 --arch=arm64 --dist-url=https://electronjs.org/headers` (or `--arch=x64` depending on your machine).
2526
4. Finally, run `pnpm start`.
2627

2728
Apart from the build setup, this example is purposefully kept simple.

demos/react-native-web-supabase-todolist/library/powersync/system.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import '@azure/core-asynciterator-polyfill';
22

33
import React from 'react';
4-
import { LogLevel, PowerSyncDatabase as PowerSyncDatabaseNative } from '@powersync/react-native';
4+
import { PowerSyncDatabase as PowerSyncDatabaseNative } from '@powersync/react-native';
55
import { PowerSyncDatabase as PowerSyncDatabaseWeb, WASQLiteOpenFactory } from '@powersync/web';
6-
import { AbstractPowerSyncDatabase, createBaseLogger } from '@powersync/common';
6+
import { LogLevel, AbstractPowerSyncDatabase, createBaseLogger } from '@powersync/common';
77
import { SupabaseStorageAdapter } from '../storage/SupabaseStorageAdapter';
88
import { type AttachmentRecord } from '@powersync/attachments';
99
import { KVStorage } from '../storage/KVStorage';

packages/adapter-sql-js/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"license": "Apache-2.0",
1515
"files": [
1616
"lib",
17-
"dist"
17+
"dist",
18+
"src"
1819
],
1920
"repository": {
2021
"type": "git",
@@ -26,13 +27,13 @@
2627
"homepage": "https://docs.powersync.com",
2728
"scripts": {
2829
"build": "tsc -b && rollup -c rollup.config.mjs",
29-
"build:prod": "tsc -b --sourceMap false && rollup -c rollup.config.mjs --sourceMap false",
30+
"build:prod": "tsc -b && rollup -c rollup.config.mjs",
3031
"clean": "rm -rf lib dist tsconfig.tsbuildinfo",
3132
"test": "vitest"
3233
},
3334
"dependencies": {
3435
"@powersync/common": "workspace:^",
35-
"async-mutex": "^0.4.0"
36+
"async-mutex": "^0.5.0"
3637
},
3738
"devDependencies": {
3839
"@powersync/sql-js": "0.0.5",

packages/adapter-sql-js/rollup.config.mjs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@ const __dirname = path.dirname(__filename);
1010
/**
1111
* @returns {import('rollup').RollupOptions}
1212
*/
13-
export default (commandLineArgs) => {
14-
const sourceMap = (commandLineArgs.sourceMap || 'true') == 'true';
15-
16-
// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
17-
delete commandLineArgs.sourceMap;
18-
13+
export default () => {
1914
return {
2015
input: 'lib/index.js',
2116
output: {
2217
file: 'dist/bundle.mjs',
2318
format: 'esm',
24-
sourcemap: sourceMap
19+
sourcemap: true
2520
},
2621
plugins: [
2722
nodeResolve({ preferBuiltins: false, browser: true }),
@@ -36,6 +31,6 @@ export default (commandLineArgs) => {
3631
]
3732
})
3833
],
39-
external: ['@powersync/common']
34+
external: ['@powersync/common', 'async-mutex']
4035
};
4136
};

packages/attachments/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
},
3535
"files": [
3636
"lib",
37-
"dist"
37+
"dist",
38+
"src"
3839
],
3940
"scripts": {
4041
"build": "tsc -b && rollup --config",
41-
"build:prod": "tsc -b --sourceMap false && rollup --config --sourceMap=false",
42+
"build:prod": "tsc -b --sourceMap false && rollup",
4243
"clean": "rm -rf lib dist tsconfig.tsbuildinfo",
4344
"watch": "tsc -b -w",
4445
"test": "pnpm build && vitest",

packages/attachments/rollup.config.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@ import typescript from '@rollup/plugin-typescript';
44
import { dts } from 'rollup-plugin-dts';
55

66
/** @type {import('rollup').RollupOptions} */
7-
export default (commandLineArgs) => {
8-
const sourceMap = (commandLineArgs.sourceMap || 'true') == 'true';
9-
10-
// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
11-
delete commandLineArgs.sourceMap;
12-
7+
export default () => {
138
return [
149
{
1510
input: 'src/index.ts',
1611
output: {
1712
format: 'cjs',
1813
file: 'dist/index.cjs',
19-
sourcemap: sourceMap,
14+
sourcemap: true,
2015
exports: 'named'
2116
},
2217
plugins: [
@@ -25,7 +20,7 @@ export default (commandLineArgs) => {
2520
typescript({
2621
tsconfig: './tsconfig.json',
2722
outDir: 'dist',
28-
sourceMap
23+
sourceMap: true
2924
})
3025
],
3126
external: ['@powersync/common']

packages/capacitor/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"android/build.gradle",
1616
"android/proguard-rules.pro",
1717
"dist/",
18+
"src",
1819
"ios/Sources",
1920
"ios/Tests",
2021
"Package.swift",

packages/common/package.json

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
"types": "lib/index.d.ts",
1313
"exports": {
1414
".": {
15+
"node": {
16+
"import": {
17+
"types": "./lib/index.d.ts",
18+
"default": "./dist/bundle.node.mjs"
19+
},
20+
"require": {
21+
"types": "./dist/index.d.cts",
22+
"require": "./dist/bundle.node.cjs"
23+
}
24+
},
1525
"import": {
1626
"types": "./lib/index.d.ts",
1727
"default": "./dist/bundle.mjs"
@@ -26,7 +36,8 @@
2636
"license": "Apache-2.0",
2737
"files": [
2838
"lib",
29-
"dist"
39+
"dist",
40+
"src"
3041
],
3142
"repository": {
3243
"type": "git",
@@ -38,31 +49,28 @@
3849
"homepage": "https://docs.powersync.com",
3950
"scripts": {
4051
"build": "tsc -b && rollup -c rollup.config.mjs",
41-
"build:prod": "tsc -b --sourceMap false && rollup -c rollup.config.mjs --sourceMap false",
52+
"build:prod": "tsc -b && rollup -c rollup.config.mjs",
4253
"clean": "rm -rf lib dist tsconfig.tsbuildinfo",
4354
"test": "vitest",
4455
"test:exports": "attw --pack ."
4556
},
4657
"dependencies": {
47-
"js-logger": "^1.6.1"
58+
"async-mutex": "^0.5.0",
59+
"buffer": "^6.0.3",
60+
"event-iterator": "^2.0.0"
4861
},
4962
"devDependencies": {
50-
"@rollup/plugin-commonjs": "^25.0.7",
63+
"@rollup/plugin-commonjs": "^29.0.0",
5164
"@rollup/plugin-inject": "^5.0.5",
5265
"@rollup/plugin-json": "^6.1.0",
53-
"@rollup/plugin-node-resolve": "15.2.3",
54-
"@rollup/plugin-terser": "^0.4.4",
66+
"@rollup/plugin-node-resolve": "^16.0.3",
5567
"@types/node": "^20.5.9",
5668
"@types/uuid": "^9.0.1",
57-
"async-mutex": "^0.4.0",
58-
"bson": "^6.6.0",
59-
"buffer": "^6.0.3",
60-
"cross-fetch": "^4.0.0",
61-
"event-iterator": "^2.0.0",
62-
"rollup": "4.14.3",
69+
"rollup": "^4.52.5",
70+
"cross-fetch": "^4.1.0",
71+
"js-logger": "^1.6.1",
6372
"rsocket-core": "1.0.0-alpha.3",
6473
"rsocket-websocket-client": "1.0.0-alpha.3",
65-
"text-encoding": "^0.7.0",
66-
"web-streams-polyfill": "3.2.1"
74+
"bson": "^6.10.4"
6775
}
6876
}

packages/common/rollup.config.mjs

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,49 @@
1+
import * as path from 'node:path';
2+
13
import commonjs from '@rollup/plugin-commonjs';
24
import inject from '@rollup/plugin-inject';
35
import json from '@rollup/plugin-json';
46
import nodeResolve from '@rollup/plugin-node-resolve';
5-
import terser from '@rollup/plugin-terser';
67
import { dts } from 'rollup-plugin-dts';
78

8-
/**
9-
* @returns {import('rollup').RollupOptions}
10-
*/
11-
export default (commandLineArgs) => {
12-
const sourceMap = (commandLineArgs.sourceMap || 'true') == 'true';
13-
14-
// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
15-
delete commandLineArgs.sourceMap;
9+
function defineBuild(isNode) {
10+
const suffix = isNode ? '.node' : '';
1611

17-
return [
18-
{
19-
input: 'lib/index.js',
20-
output: [
21-
{
22-
file: 'dist/bundle.mjs',
23-
format: 'esm',
24-
sourcemap: sourceMap
25-
},
26-
{
27-
file: 'dist/bundle.cjs',
28-
format: 'cjs',
29-
sourcemap: sourceMap
30-
}
31-
],
32-
plugins: [
12+
return {
13+
input: 'lib/index.js',
14+
output: [
15+
{
16+
file: `dist/bundle${suffix}.mjs`,
17+
format: 'esm',
18+
sourcemap: true
19+
},
20+
{
21+
file: `dist/bundle${suffix}.cjs`,
22+
format: 'cjs',
23+
sourcemap: true
24+
}
25+
],
26+
plugins: [
27+
[
3328
json(),
3429
nodeResolve({ preferBuiltins: false, browser: true }),
3530
commonjs({}),
3631
inject({
37-
Buffer: ['buffer', 'Buffer'],
38-
ReadableStream: ['web-streams-polyfill/ponyfill', 'ReadableStream'],
39-
// Used by can-ndjson-stream
40-
TextDecoder: ['text-encoding', 'TextDecoder']
41-
}),
42-
terser({ sourceMap })
43-
],
44-
// This makes life easier
45-
external: [
46-
// This has dynamic logic - makes bundling hard
47-
'cross-fetch'
32+
Buffer: isNode ? ['node:buffer', 'Buffer'] : ['buffer/', 'Buffer']
33+
})
4834
]
49-
},
35+
],
36+
external: ['async-mutex', 'bson', 'buffer/', 'event-iterator']
37+
};
38+
}
39+
40+
/**
41+
* @returns {import('rollup').RollupOptions}
42+
*/
43+
export default () => {
44+
return [
45+
defineBuild(false),
46+
defineBuild(true),
5047
{
5148
input: './lib/index.d.ts',
5249
output: [{ file: 'dist/index.d.cts', format: 'cjs' }],

0 commit comments

Comments
 (0)