From 6f2aaebb8cca36045dc6b32d3db56d9a4378b29a Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Fri, 6 Dec 2024 09:23:20 -0700 Subject: [PATCH 01/10] Fix node 16 cjs import --- packages/typescript-client/package.json | 69 ++++++++++++----------- packages/typescript-client/tsup.config.ts | 57 +++++++++++-------- 2 files changed, 69 insertions(+), 57 deletions(-) diff --git a/packages/typescript-client/package.json b/packages/typescript-client/package.json index 342b885513..f53e249182 100644 --- a/packages/typescript-client/package.json +++ b/packages/typescript-client/package.json @@ -1,34 +1,11 @@ { "name": "@electric-sql/client", - "version": "0.9.0", "description": "Postgres everywhere - your data, in sync, wherever you need it.", - "type": "module", - "main": "dist/cjs/index.cjs", - "module": "dist/index.legacy-esm.js", - "types": "dist/index.d.ts", - "exports": { - "./package.json": "./package.json", - ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/cjs/index.cjs" - } - }, - "files": [ - "dist", - "src" - ], - "sideEffects": false, - "repository": { - "type": "git", - "url": "git+https://github.com/electric-sql/electric.git" - }, + "version": "0.9.0", "author": "ElectricSQL team and contributors.", - "license": "Apache-2", "bugs": { "url": "https://github.com/electric-sql/electric/issues" }, - "homepage": "https://electric-sql.com", "dependencies": {}, "devDependencies": { "@types/pg": "^8.11.6", @@ -49,22 +26,50 @@ "uuid": "^10.0.0", "vitest": "^2.0.2" }, + "type": "module", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.mjs" + }, + "require": { + "types": "./dist/cjs/index.d.cts", + "default": "./dist/cjs/index.cjs" + } + } + }, + "files": [ + "dist", + "src" + ], + "homepage": "https://electric-sql.com", + "license": "Apache-2", + "main": "./dist/cjs/index.cjs", + "module": "./dist/index.legacy-esm.js", + "types": "./dist/index.d.ts", "optionalDependencies": { "@rollup/rollup-darwin-arm64": "^4.18.1" }, + "repository": { + "type": "git", + "url": "git+https://github.com/electric-sql/electric.git" + }, + "scripts": { + "build": "shx rm -rf dist && concurrently \"tsup\" \"tsc -p tsconfig.build.json\"", + "format": "eslint . --fix", + "prepack": "pnpm build", + "stylecheck": "eslint . --quiet", + "test": "pnpm exec vitest", + "typecheck": "tsc -p tsconfig.json" + }, + "sideEffects": false, "typesVersions": { "*": { "*": [ "./dist/index.d.ts" ] } - }, - "scripts": { - "test": "pnpm exec vitest", - "typecheck": "tsc -p tsconfig.json", - "build": "shx rm -rf dist && concurrently \"tsup\" \"tsc -p tsconfig.build.json\"", - "prepack": "pnpm build", - "stylecheck": "eslint . --quiet", - "format": "eslint . --fix" } } diff --git a/packages/typescript-client/tsup.config.ts b/packages/typescript-client/tsup.config.ts index 075298b6c3..86bac32eb4 100644 --- a/packages/typescript-client/tsup.config.ts +++ b/packages/typescript-client/tsup.config.ts @@ -2,59 +2,66 @@ import type { Options } from 'tsup' import { defineConfig } from 'tsup' export default defineConfig((options) => { - const entry = { - index: 'src/index.ts', - } const commonOptions: Partial = { - entry, + entry: { + index: 'src/index.ts', + }, tsconfig: `./tsconfig.build.json`, sourcemap: true, ...options, } return [ - // Standard ESM, embedded `process.env.NODE_ENV` checks + // ESM build with .d.ts { ...commonOptions, format: ['esm'], - outExtension: () => ({ js: '.mjs' }), // Add dts: '.d.ts' when egoist/tsup#1053 lands - dts: true, + outExtension: () => ({ js: '.mjs' }), + dts: { + entry: commonOptions.entry, + resolve: true, + }, clean: true, }, - // Support Webpack 4 by pointing `"module"` to a file with a `.js` extension + // CJS build with .d.cts + { + ...commonOptions, + format: ['cjs'], + outDir: './dist/cjs/', + outExtension: () => ({ js: '.cjs' }), + dts: { + entry: commonOptions.entry, + resolve: true, + compilerOptions: { + declarationDir: '../', + declaration: true, + declarationMap: true, + outDir: '../', + }, + }, + clean: false, + }, + // Support Webpack 4 by pointing "module" to a file with a .js extension { ...commonOptions, format: ['esm'], target: 'es2017', dts: false, outExtension: () => ({ js: '.js' }), - entry: Object.fromEntries( - Object.entries(entry).map(([key, value]) => [ - `${key}.legacy-esm`, - value, - ]) - ), + entry: { 'index.legacy-esm': 'src/index.ts' }, }, // Browser-ready ESM, production + minified { ...commonOptions, - - entry: Object.fromEntries( - Object.entries(entry).map(([key, value]) => [`${key}.browser`, value]) - ), - define: { 'process.env.NODE_ENV': JSON.stringify('production'), }, format: ['esm'], outExtension: () => ({ js: '.mjs' }), minify: true, - }, - { - ...commonOptions, - format: 'cjs', - outDir: './dist/cjs/', - outExtension: () => ({ js: '.cjs' }), + entry: { + 'index.browser': 'src/index.ts', + }, }, ] }) From ccd9d70b36483a68ca520b8ebaa0b38d7d842c13 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Fri, 6 Dec 2024 09:29:59 -0700 Subject: [PATCH 02/10] Remove unneeded options --- packages/typescript-client/tsup.config.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/typescript-client/tsup.config.ts b/packages/typescript-client/tsup.config.ts index 86bac32eb4..ad899720ed 100644 --- a/packages/typescript-client/tsup.config.ts +++ b/packages/typescript-client/tsup.config.ts @@ -32,12 +32,6 @@ export default defineConfig((options) => { dts: { entry: commonOptions.entry, resolve: true, - compilerOptions: { - declarationDir: '../', - declaration: true, - declarationMap: true, - outDir: '../', - }, }, clean: false, }, From ffb22aaf8df6c5adfe59cca42f59580e801665aa Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Fri, 6 Dec 2024 09:33:07 -0700 Subject: [PATCH 03/10] add changeset --- .changeset/hot-beds-pump.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hot-beds-pump.md diff --git a/.changeset/hot-beds-pump.md b/.changeset/hot-beds-pump.md new file mode 100644 index 0000000000..486f398afe --- /dev/null +++ b/.changeset/hot-beds-pump.md @@ -0,0 +1,5 @@ +--- +"@electric-sql/client": patch +--- + +Fix node 16 cjs import From f1c3c453c0c10675f2a8d78be23a8fe211b1fdcf Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 9 Dec 2024 08:15:03 -0700 Subject: [PATCH 04/10] fix --- packages/react-hooks/package.json | 69 +++++++++++++----------- packages/react-hooks/tsconfig.build.json | 7 ++- packages/react-hooks/tsconfig.json | 7 ++- packages/react-hooks/tsup.config.ts | 46 +++++++++------- packages/typescript-client/tsconfig.json | 1 + tsconfig.base.json | 7 +-- tsconfig.build.json | 4 +- 7 files changed, 83 insertions(+), 58 deletions(-) diff --git a/packages/react-hooks/package.json b/packages/react-hooks/package.json index 5af6e0f280..2880df3002 100644 --- a/packages/react-hooks/package.json +++ b/packages/react-hooks/package.json @@ -1,34 +1,11 @@ { "name": "@electric-sql/react", - "version": "0.6.1", "description": "React hooks for ElectricSQL", - "type": "module", - "main": "dist/cjs/index.cjs", - "module": "dist/index.legacy-esm.js", - "types": "dist/index.d.ts", - "exports": { - "./package.json": "./package.json", - ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/cjs/index.cjs" - } - }, - "files": [ - "dist", - "src" - ], - "sideEffects": false, - "repository": { - "type": "git", - "url": "git+https://github.com/electric-sql/electric.git" - }, + "version": "0.6.1", "author": "ElectricSQL team and contributors.", - "license": "Apache-2", "bugs": { "url": "https://github.com/electric-sql/electric/issues" }, - "homepage": "https://electric-sql.com", "dependencies": { "@electric-sql/client": "workspace:*", "use-sync-external-store": "^1.2.2" @@ -56,6 +33,27 @@ "uuid": "^10.0.0", "vitest": "^2.0.2" }, + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.mjs" + }, + "require": { + "types": "./dist/cjs/index.d.cts", + "default": "./dist/cjs/index.cjs" + } + } + }, + "files": [ + "dist", + "src" + ], + "homepage": "https://electric-sql.com", + "license": "Apache-2", + "main": "dist/cjs/index.cjs", + "module": "dist/index.legacy-esm.js", "peerDependencies": { "react": "^18.3.1" }, @@ -64,19 +62,26 @@ "optional": true } }, + "repository": { + "type": "git", + "url": "git+https://github.com/electric-sql/electric.git" + }, + "scripts": { + "build": "shx rm -rf dist && concurrently \"tsup\" \"tsc -p tsconfig.build.json\"", + "format": "eslint . --fix", + "prepack": "pnpm build", + "stylecheck": "eslint . --quiet", + "test": "pnpm exec vitest", + "typecheck": "tsc -p tsconfig.json" + }, + "sideEffects": false, + "type": "module", + "types": "dist/index.d.ts", "typesVersions": { "*": { "*": [ "./dist/index.d.ts" ] } - }, - "scripts": { - "test": "pnpm exec vitest", - "typecheck": "tsc -p tsconfig.json", - "build": "shx rm -rf dist && concurrently \"tsup\" \"tsc -p tsconfig.build.json\"", - "prepack": "pnpm build", - "stylecheck": "eslint . --quiet", - "format": "eslint . --fix" } } diff --git a/packages/react-hooks/tsconfig.build.json b/packages/react-hooks/tsconfig.build.json index c147f4334f..fd4bf9703a 100644 --- a/packages/react-hooks/tsconfig.build.json +++ b/packages/react-hooks/tsconfig.build.json @@ -1,5 +1,10 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "paths": { + "@electric-sql/client": ["../typescript-client/src"] + } + }, "include": ["src/**/*"], "exclude": ["node_modules", "tests", "dist"] } diff --git a/packages/react-hooks/tsconfig.json b/packages/react-hooks/tsconfig.json index 9536a0f413..b5c3207611 100644 --- a/packages/react-hooks/tsconfig.json +++ b/packages/react-hooks/tsconfig.json @@ -1,3 +1,8 @@ { - "extends": "../../tsconfig.base.json" + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "paths": { + "@electric-sql/client": ["../typescript-client/src"] + } + } } diff --git a/packages/react-hooks/tsup.config.ts b/packages/react-hooks/tsup.config.ts index 155957c2dd..855d7d5288 100644 --- a/packages/react-hooks/tsup.config.ts +++ b/packages/react-hooks/tsup.config.ts @@ -1,53 +1,61 @@ import type { Options } from 'tsup' import { defineConfig } from 'tsup' -export default defineConfig(options => { +export default defineConfig((options: Options) => { const commonOptions: Partial = { entry: { - index: 'src/index.ts' + index: 'src/index.ts', }, tsconfig: `./tsconfig.build.json`, - // esbuildPlugins: [mangleErrorsTransform], sourcemap: true, - ...options + ...options, } return [ - // Standard ESM, embedded `process.env.NODE_ENV` checks + // ESM build with .d.ts { ...commonOptions, format: ['esm'], - outExtension: () => ({ js: '.mjs' }), // Add dts: '.d.ts' when egoist/tsup#1053 lands - dts: true, - clean: true + outExtension: () => ({ js: '.mjs' }), + dts: { + entry: commonOptions.entry, + resolve: true, + }, + clean: true, }, - // Support Webpack 4 by pointing `"module"` to a file with a `.js` extension + // CJS build with .d.cts + { + ...commonOptions, + format: ['cjs'], + outDir: './dist/cjs/', + outExtension: () => ({ js: '.cjs' }), + dts: { + entry: commonOptions.entry, + resolve: true, + }, + clean: false, + }, + // Support Webpack 4 by pointing "module" to a file with a .js extension { ...commonOptions, format: ['esm'], target: 'es2017', dts: false, outExtension: () => ({ js: '.js' }), - entry: { 'index.legacy-esm': 'src/index.ts' } as Record + entry: { 'index.legacy-esm': 'src/index.ts' } as Record, }, // Browser-ready ESM, production + minified { ...commonOptions, define: { - 'process.env.NODE_ENV': JSON.stringify('production') + 'process.env.NODE_ENV': JSON.stringify('production'), }, format: ['esm'], outExtension: () => ({ js: '.mjs' }), minify: true, entry: { - 'index.browser': 'src/index.ts' - }, + 'index.browser': 'src/index.ts', + } as Record, }, - { - ...commonOptions, - format: 'cjs', - outDir: './dist/cjs/', - outExtension: () => ({ js: '.cjs' }) - } ] }) diff --git a/packages/typescript-client/tsconfig.json b/packages/typescript-client/tsconfig.json index 5bd3117ad9..87d0bec14c 100644 --- a/packages/typescript-client/tsconfig.json +++ b/packages/typescript-client/tsconfig.json @@ -1,4 +1,5 @@ { + "extends": "../../tsconfig.base.json", "compilerOptions": { /* Visit https://aka.ms/tsconfig.json to read more about this file */ diff --git a/tsconfig.base.json b/tsconfig.base.json index d272c3e097..445b21cff9 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -8,11 +8,12 @@ ], "jsx": "preserve", "noEmit": true, - "module": "preserve", + "module": "esnext", + "moduleResolution": "node", "esModuleInterop": true, + "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, "strict": true, - "skipLibCheck": true, - "moduleResolution": "bundler" + "skipLibCheck": true } } diff --git a/tsconfig.build.json b/tsconfig.build.json index f73b101227..a7c830052c 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -5,7 +5,7 @@ "target": "es2016", "noEmit": true, "jsx": "preserve", - "module": "preserve", - "moduleResolution": "bundler" + "module": "esnext", + "moduleResolution": "node" } } From 6ad5559dc70edd16e29f5009777387e498907eeb Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 9 Dec 2024 08:52:47 -0700 Subject: [PATCH 05/10] Run build commands sequentially to prevent race conditions --- packages/react-hooks/package.json | 2 +- packages/typescript-client/package.json | 2 +- packages/typescript-client/tsconfig.build.json | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/react-hooks/package.json b/packages/react-hooks/package.json index 2880df3002..ba56888e91 100644 --- a/packages/react-hooks/package.json +++ b/packages/react-hooks/package.json @@ -67,7 +67,7 @@ "url": "git+https://github.com/electric-sql/electric.git" }, "scripts": { - "build": "shx rm -rf dist && concurrently \"tsup\" \"tsc -p tsconfig.build.json\"", + "build": "shx rm -rf dist && tsup && tsc -p tsconfig.build.json", "format": "eslint . --fix", "prepack": "pnpm build", "stylecheck": "eslint . --quiet", diff --git a/packages/typescript-client/package.json b/packages/typescript-client/package.json index f53e249182..bc4294f216 100644 --- a/packages/typescript-client/package.json +++ b/packages/typescript-client/package.json @@ -57,7 +57,7 @@ "url": "git+https://github.com/electric-sql/electric.git" }, "scripts": { - "build": "shx rm -rf dist && concurrently \"tsup\" \"tsc -p tsconfig.build.json\"", + "build": "shx rm -rf dist && tsup && tsc -p tsconfig.build.json", "format": "eslint . --fix", "prepack": "pnpm build", "stylecheck": "eslint . --quiet", diff --git a/packages/typescript-client/tsconfig.build.json b/packages/typescript-client/tsconfig.build.json index c147f4334f..4ed632629a 100644 --- a/packages/typescript-client/tsconfig.build.json +++ b/packages/typescript-client/tsconfig.build.json @@ -1,5 +1,8 @@ { "extends": "../../tsconfig.build.json", + "compilerOptions": { + "skipLibCheck": true + }, "include": ["src/**/*"], "exclude": ["node_modules", "tests", "dist"] } From ee2a365033caef8e880c38a8d78738cbe3156ec2 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 9 Dec 2024 08:53:23 -0700 Subject: [PATCH 06/10] update changeset --- .changeset/hot-beds-pump.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/hot-beds-pump.md b/.changeset/hot-beds-pump.md index 486f398afe..8e2f295542 100644 --- a/.changeset/hot-beds-pump.md +++ b/.changeset/hot-beds-pump.md @@ -1,5 +1,6 @@ --- "@electric-sql/client": patch +"@electric-sql/react": patch --- Fix node 16 cjs import From 5aaef8beea9536ca4e591cc4631767ef3fc5a28d Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 9 Dec 2024 09:00:17 -0700 Subject: [PATCH 07/10] DRY --- packages/react-hooks/tsconfig.build.json | 7 +------ tsconfig.build.json | 10 +--------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/packages/react-hooks/tsconfig.build.json b/packages/react-hooks/tsconfig.build.json index fd4bf9703a..c147f4334f 100644 --- a/packages/react-hooks/tsconfig.build.json +++ b/packages/react-hooks/tsconfig.build.json @@ -1,10 +1,5 @@ { - "extends": "../../tsconfig.base.json", - "compilerOptions": { - "paths": { - "@electric-sql/client": ["../typescript-client/src"] - } - }, + "extends": "../../tsconfig.build.json", "include": ["src/**/*"], "exclude": ["node_modules", "tests", "dist"] } diff --git a/tsconfig.build.json b/tsconfig.build.json index a7c830052c..162b53870c 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,11 +1,3 @@ { - "compilerOptions": { - "incremental": false, - "baseUrl": "./", - "target": "es2016", - "noEmit": true, - "jsx": "preserve", - "module": "esnext", - "moduleResolution": "node" - } + "extends": "./tsconfig.base.json", } From 52f4a56594f40a68f4faae1de82f09c7f694596e Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 9 Dec 2024 09:03:08 -0700 Subject: [PATCH 08/10] Remove redundant setting --- packages/typescript-client/tsconfig.build.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/typescript-client/tsconfig.build.json b/packages/typescript-client/tsconfig.build.json index 4ed632629a..c147f4334f 100644 --- a/packages/typescript-client/tsconfig.build.json +++ b/packages/typescript-client/tsconfig.build.json @@ -1,8 +1,5 @@ { "extends": "../../tsconfig.build.json", - "compilerOptions": { - "skipLibCheck": true - }, "include": ["src/**/*"], "exclude": ["node_modules", "tests", "dist"] } From 093ce51b67f6fcfeabd3bc83416b5a434d7ce2ac Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 9 Dec 2024 09:11:44 -0700 Subject: [PATCH 09/10] Fix type errors --- examples/yjs/app/y-electric.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/examples/yjs/app/y-electric.ts b/examples/yjs/app/y-electric.ts index 50ec608ad4..f6245cf035 100644 --- a/examples/yjs/app/y-electric.ts +++ b/examples/yjs/app/y-electric.ts @@ -316,11 +316,13 @@ export class ElectricProvider extends ObservableV2 { ) { this.synced = true - updateShapeState( - `operations`, - this.operationsStream!.lastOffset, - this.operationsStream!.shapeHandle - ) + if (this.operationsStream?.lastOffset && this.operationsStream?.shapeHandle) { + updateShapeState( + `operations`, + this.operationsStream.lastOffset, + this.operationsStream.shapeHandle + ) + } } }) } @@ -347,11 +349,13 @@ export class ElectricProvider extends ObservableV2 { } }) - updateShapeState( - `awareness`, - this.awarenessStream!.lastOffset, - this.awarenessStream!.shapeHandle - ) + if (this.awarenessStream?.lastOffset && this.awarenessStream?.shapeHandle) { + updateShapeState( + `awareness`, + this.awarenessStream.lastOffset, + this.awarenessStream.shapeHandle + ) + } } const unsubscribeAwarenessHandler = this.awarenessStream.subscribe( From a01d96838deda850e477be187529b328fe2d2af5 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 9 Dec 2024 09:20:09 -0700 Subject: [PATCH 10/10] Fix prettier --- examples/nextjs-example/app/shape-proxy/route.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/nextjs-example/app/shape-proxy/route.ts b/examples/nextjs-example/app/shape-proxy/route.ts index 0e66e0506f..aadfae4d3a 100644 --- a/examples/nextjs-example/app/shape-proxy/route.ts +++ b/examples/nextjs-example/app/shape-proxy/route.ts @@ -41,4 +41,4 @@ export async function GET(request: Request) { }) } return resp -} \ No newline at end of file +}