Skip to content

Commit d6db1cf

Browse files
committed
Add cjs bundle output for @powersync/common.
1 parent 52df1d8 commit d6db1cf

File tree

6 files changed

+58
-14
lines changed

6 files changed

+58
-14
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
node_modules
22
lib
33
dist
4-
tsconfig.tsbuildinfo
4+
cjs
5+
*.tsbuildinfo
56
.vscode
67
.DS_STORE
78
.idea

packages/common/package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@
66
"access": "public"
77
},
88
"description": "API definitions for JourneyApps PowerSync",
9-
"main": "dist/index.js",
10-
"types": "lib/index.d.ts",
119
"type": "module",
10+
"main": "dist/bundle.cjs",
11+
"module": "dist/bundle.mjs",
12+
"types": "lib/index.d.ts",
13+
"exports": {
14+
".": {
15+
"import": "./dist/bundle.mjs",
16+
"require": "./dist/bundle.cjs",
17+
"default": "./dist/bundle.mjs",
18+
"types": "./lib/index.d.ts"
19+
}
20+
},
1221
"author": "JOURNEYAPPS",
1322
"license": "Apache-2.0",
1423
"files": [
@@ -24,8 +33,8 @@
2433
},
2534
"homepage": "https://docs.powersync.com",
2635
"scripts": {
27-
"build": "tsc -b && rollup -c rollup.config.mjs",
28-
"clean": "rm -rf lib tsconfig.tsbuildinfo dist",
36+
"build": "tsc -b && rollup -c rollup.config.mjs && rollup -c rollup-cjs.config.mjs",
37+
"clean": "rm -rf lib dist tsconfig.tsbuildinfo",
2938
"test": "vitest"
3039
},
3140
"dependencies": {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import commonjs from '@rollup/plugin-commonjs';
2+
import inject from '@rollup/plugin-inject';
3+
import json from '@rollup/plugin-json';
4+
import nodeResolve from '@rollup/plugin-node-resolve';
5+
import terser from '@rollup/plugin-terser';
6+
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+
13+
return {
14+
// esm input is better, even for cjs output
15+
input: 'lib/index.js',
16+
output: {
17+
file: 'dist/bundle.cjs',
18+
format: 'cjs',
19+
sourcemap: sourcemap
20+
},
21+
plugins: [
22+
json(),
23+
nodeResolve({ preferBuiltins: false, browser: true }),
24+
commonjs({}),
25+
inject({
26+
Buffer: ['buffer', 'Buffer'],
27+
ReadableStream: ['web-streams-polyfill/ponyfill', 'ReadableStream'],
28+
// Used by can-ndjson-stream
29+
TextDecoder: ['text-encoding', 'TextDecoder']
30+
}),
31+
terser()
32+
],
33+
// This makes life easier
34+
external: [
35+
// This has dynamic logic - makes bundling hard
36+
'cross-fetch',
37+
// TODO: make the useDefaults logic better. Currently need access to this package directly
38+
'js-logger'
39+
]
40+
};
41+
};

packages/common/rollup.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default (commandLineArgs) => {
1313
return {
1414
input: 'lib/index.js',
1515
output: {
16-
file: 'dist/index.js',
16+
file: 'dist/bundle.mjs',
1717
format: 'esm',
1818
sourcemap: sourcemap
1919
},

packages/common/tsconfig-cjs.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/common/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"jsx": "react",
66
"types": ["node"],
77
"rootDir": "src",
8-
"outDir": "./lib/esm",
8+
"outDir": "./lib",
99
"lib": ["esnext"],
1010
"declaration": true,
1111
"module": "node16",

0 commit comments

Comments
 (0)