Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/kind-apricots-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@powersync/drizzle-driver': minor
'@powersync/kysely-driver': minor
'@powersync/attachments': minor
---

Updated package exports to reflect ESM exports. Added CommonJS exports.
6 changes: 6 additions & 0 deletions .changeset/modern-feet-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@powersync/common': minor
'@powersync/node': minor
---

Added CJS specific type declarations.
7 changes: 7 additions & 0 deletions .changeset/soft-swans-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@powersync/tanstack-react-query': minor
'@powersync/react': minor
'@powersync/vue': minor
---

Updated package exports to reflect ESM nature.
5 changes: 5 additions & 0 deletions .changeset/unlucky-singers-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/react': minor
---

Update package exports to reflect ESM exports.
3 changes: 3 additions & 0 deletions .github/workflows/test-isolated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
- name: Build Packages
run: pnpm build:packages

- name: Test Package Exports
run: pnpm test:packages:exports

- name: Start Verdaccio
run: |
npm install -g verdaccio
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"format": "prettier --write .",
"lint": "eslint .",
"release": "pnpm build:packages:prod && pnpm changeset publish",
"test": "pnpm run -r --workspace-concurrency=0 test"
"test": "pnpm run -r --workspace-concurrency=1 test --run",
"test:packages:exports": "pnpm -r --filter {./packages/**} test:exports"
},
"keywords": [],
"type": "module",
Expand All @@ -31,15 +32,21 @@
},
"devDependencies": {
"@actions/core": "^1.10.1",
"@arethetypeswrong/cli": "^0.18.2",
"@changesets/cli": "2.27.2",
"@pnpm/workspace.find-packages": "^4.0.2",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-typescript": "^12.1.4",
"@vitest/browser": "^3.2.4",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"playwright": "^1.51.0",
"prettier": "^3.2.5",
"prettier-plugin-embed": "^0.4.15",
"prettier-plugin-sql": "^0.18.1",
"rollup": "4.14.3",
"rollup-plugin-dts": "^6.2.1",
"typescript": "^5.7.2",
"vitest": "^3.2.4"
}
Expand Down
28 changes: 22 additions & 6 deletions packages/attachments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,33 @@
"url": "https://github.com/powersync-ja/powersync-js/issues"
},
"description": "An PowerSync library to manage attachments for TypeScript and React Native apps",
"main": "./lib/index.js",
"type": "module",
"main": "./dist/index.cjs",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"exports": {
".": {
"import": {
"default": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"require": {
"default": "./dist/index.cjs",
"types": "./dist/index.d.cts"
}
}
},
"files": [
"lib"
"lib",
"dist"
],
"scripts": {
"build": "tsc -b",
"build:prod": "tsc -b --sourceMap false",
"clean": "rm -rf lib tsconfig.tsbuildinfo node_modules",
"build": "tsc -b && rollup --config",
"build:prod": "tsc -b --sourceMap false && rollup --config --sourceMap=false",
"clean": "rm -rf lib dist tsconfig.tsbuildinfo",
"watch": "tsc -b -w",
"test": "pnpm build && vitest"
"test": "pnpm build && vitest",
"test:exports": "attw --pack ."
},
"peerDependencies": {
"@powersync/common": "workspace:^1.35.0"
Expand Down
40 changes: 40 additions & 0 deletions packages/attachments/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import { dts } from 'rollup-plugin-dts';

/** @type {import('rollup').RollupOptions} */
export default (commandLineArgs) => {
const sourceMap = (commandLineArgs.sourceMap || 'true') == 'true';

// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
delete commandLineArgs.sourceMap;

return [
{
input: 'src/index.ts',
output: {
format: 'cjs',
file: 'dist/index.cjs',
sourcemap: sourceMap,
exports: 'named'
},
plugins: [
resolve(),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
outDir: 'dist',
sourceMap
})
],
external: ['@powersync/common']
},
// This is required to avoid https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseESM.md
{
input: './lib/index.d.ts',
output: [{ file: 'dist/index.d.cts', format: 'cjs' }],
plugins: [dts()]
}
];
};
4 changes: 2 additions & 2 deletions packages/attachments/src/AbstractAttachmentQueue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractPowerSyncDatabase, Transaction } from '@powersync/common';
import { ATTACHMENT_TABLE, AttachmentRecord, AttachmentState } from './Schema';
import { EncodingType, StorageAdapter } from './StorageAdapter';
import { ATTACHMENT_TABLE, AttachmentRecord, AttachmentState } from './Schema.js';
import { EncodingType, StorageAdapter } from './StorageAdapter.js';

export interface AttachmentQueueOptions {
powersync: AbstractPowerSyncDatabase;
Expand Down
6 changes: 3 additions & 3 deletions packages/attachments/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './Schema';
export * from './StorageAdapter';
export * from './Schema.js';
export * from './StorageAdapter.js';

export * from './AbstractAttachmentQueue';
export * from './AbstractAttachmentQueue.js';
32 changes: 15 additions & 17 deletions packages/attachments/tests/attachments/AttachmentQueue.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import * as commonSdk from '@powersync/common';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { AbstractAttachmentQueue } from '../../src/AbstractAttachmentQueue';
import { AttachmentRecord, AttachmentState } from '../../src/Schema';
import { AbstractPowerSyncDatabase } from '@powersync/common';
import { StorageAdapter } from '../../src/StorageAdapter';
import { AbstractAttachmentQueue } from '../../src/AbstractAttachmentQueue.js';
import { AttachmentRecord, AttachmentState } from '../../src/Schema.js';
import { StorageAdapter } from '../../src/StorageAdapter.js';

const record = {
id: 'test-1',
filename: 'test.jpg',
state: AttachmentState.QUEUED_DOWNLOAD
}
};

const mockPowerSync = {
currentStatus: { status: 'initial' },
registerListener: vi.fn(() => {}),
resolveTables: vi.fn(() => ['table1', 'table2']),
onChangeWithCallback: vi.fn(),
getAll: vi.fn(() => Promise.resolve([{id: 'test-1'}, {id: 'test-2'}])),
getAll: vi.fn(() => Promise.resolve([{ id: 'test-1' }, { id: 'test-2' }])),
execute: vi.fn(() => Promise.resolve()),
getOptional: vi.fn((_query, params) => Promise.resolve(record)),
watch: vi.fn((query, params, callbacks) => {
callbacks?.onResult?.({ rows: { _array: [{id: 'test-1'}, {id: 'test-2'}] } });
callbacks?.onResult?.({ rows: { _array: [{ id: 'test-1' }, { id: 'test-2' }] } });
}),
writeTransaction: vi.fn(async (callback) => {
await callback({
Expand Down Expand Up @@ -57,9 +55,9 @@ describe('attachments', () => {

it('should not download attachments when downloadRecord is called with downloadAttachments false', async () => {
const queue = new TestAttachmentQueue({
powersync: mockPowerSync as any,
storage: mockStorage,
downloadAttachments: false
powersync: mockPowerSync as any,
storage: mockStorage,
downloadAttachments: false
});

await queue.downloadRecord(record);
Expand All @@ -69,9 +67,9 @@ describe('attachments', () => {

it('should download attachments when downloadRecord is called with downloadAttachments true', async () => {
const queue = new TestAttachmentQueue({
powersync: mockPowerSync as any,
storage: mockStorage,
downloadAttachments: true
powersync: mockPowerSync as any,
storage: mockStorage,
downloadAttachments: true
});

await queue.downloadRecord(record);
Expand All @@ -82,9 +80,9 @@ describe('attachments', () => {
// Testing the inverse of this test, i.e. when downloadAttachments is false, is not required as you can't wait for something that does not happen
it('should not download attachments with watchDownloads is called with downloadAttachments false', async () => {
const queue = new TestAttachmentQueue({
powersync: mockPowerSync as any,
storage: mockStorage,
downloadAttachments: true
powersync: mockPowerSync as any,
storage: mockStorage,
downloadAttachments: true
});

queue.watchDownloads();
Expand Down
4 changes: 3 additions & 1 deletion packages/attachments/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"extends": "../../tsconfig.base",
"compilerOptions": {
"baseUrl": "./",
"jsx": "react",
"rootDir": "src",
"module": "node16",
"moduleResolution": "node16",
"target": "es6",
"outDir": "./lib"
},
"references": [
Expand Down
17 changes: 11 additions & 6 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
"types": "lib/index.d.ts",
"exports": {
".": {
"import": "./dist/bundle.mjs",
"require": "./dist/bundle.cjs",
"types": "./lib/index.d.ts",
"default": "./dist/bundle.mjs"
"import": {
"types": "./lib/index.d.ts",
"default": "./dist/bundle.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"require": "./dist/bundle.cjs"
}
}
},
"author": "JOURNEYAPPS",
Expand All @@ -35,8 +39,9 @@
"scripts": {
"build": "tsc -b && rollup -c rollup.config.mjs",
"build:prod": "tsc -b --sourceMap false && rollup -c rollup.config.mjs --sourceMap false",
"clean": "rm -rf lib dist tsconfig.tsbuildinfo node_modules",
"test": "vitest"
"clean": "rm -rf lib dist tsconfig.tsbuildinfo",
"test": "vitest",
"test:exports": "attw --pack ."
},
"dependencies": {
"js-logger": "^1.6.1"
Expand Down
72 changes: 40 additions & 32 deletions packages/common/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import inject from '@rollup/plugin-inject';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import { dts } from 'rollup-plugin-dts';

/**
* @returns {import('rollup').RollupOptions}
Expand All @@ -13,36 +14,43 @@ export default (commandLineArgs) => {
// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
delete commandLineArgs.sourceMap;

return {
input: 'lib/index.js',
output: [
{
file: 'dist/bundle.mjs',
format: 'esm',
sourcemap: sourceMap
},
{
file: 'dist/bundle.cjs',
format: 'cjs',
sourcemap: sourceMap
}
],
plugins: [
json(),
nodeResolve({ preferBuiltins: false, browser: true }),
commonjs({}),
inject({
Buffer: ['buffer', 'Buffer'],
ReadableStream: ['web-streams-polyfill/ponyfill', 'ReadableStream'],
// Used by can-ndjson-stream
TextDecoder: ['text-encoding', 'TextDecoder']
}),
terser({ sourceMap })
],
// This makes life easier
external: [
// This has dynamic logic - makes bundling hard
'cross-fetch'
]
};
return [
{
input: 'lib/index.js',
output: [
{
file: 'dist/bundle.mjs',
format: 'esm',
sourcemap: sourceMap
},
{
file: 'dist/bundle.cjs',
format: 'cjs',
sourcemap: sourceMap
}
],
plugins: [
json(),
nodeResolve({ preferBuiltins: false, browser: true }),
commonjs({}),
inject({
Buffer: ['buffer', 'Buffer'],
ReadableStream: ['web-streams-polyfill/ponyfill', 'ReadableStream'],
// Used by can-ndjson-stream
TextDecoder: ['text-encoding', 'TextDecoder']
}),
terser({ sourceMap })
],
// This makes life easier
external: [
// This has dynamic logic - makes bundling hard
'cross-fetch'
]
},
{
input: './lib/index.d.ts',
output: [{ file: 'dist/index.d.cts', format: 'cjs' }],
plugins: [dts()]
}
];
};
Loading