diff --git a/.changeset/svelte-db-provider-declarations.md b/.changeset/svelte-db-provider-declarations.md new file mode 100644 index 0000000000..9d34093acc --- /dev/null +++ b/.changeset/svelte-db-provider-declarations.md @@ -0,0 +1,5 @@ +--- +'@tanstack/svelte-db': patch +--- + +Fix the published DbProvider declarations so TypeScript can resolve the component and its props without Svelte-specific tooling. diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 5dda1a9b15..c6847f5e85 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -195,6 +195,8 @@ jobs: run: pnpm run build - name: Check that no build carries an oracle probe run: node scripts/check-dist-probes.mjs + - name: Check package exports and types + run: pnpm run test:build - name: Publish Previews run: pnpx pkg-pr-new publish --pnpm --compact './packages/*' --template './examples/*/*' size: diff --git a/package.json b/package.json index fc7b61a7c7..cd762134f2 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "scripts": { "build": "pnpm --filter \"./packages/**\" build", "build:minified": "pnpm --filter \"./packages/**\" build:minified", + "test:build": "node --test scripts/check-built-package.test.mjs && pnpm --no-sort --filter \"./packages/**\" test:build", "changeset": "changeset", "changeset:publish": "node scripts/publish-packages.mjs", "changeset:version": "node scripts/version-packages.mjs", @@ -44,6 +45,7 @@ "test:collection-adapters:oracles:browser": "node scripts/run-collection-adapter-oracles.mjs --browser" }, "devDependencies": { + "@arethetypeswrong/cli": "^0.18.5", "@changesets/apply-release-plan": "7.1.1", "@changesets/assemble-release-plan": "6.0.10", "@changesets/cli": "^2.31.1", @@ -67,6 +69,7 @@ "@typescript-eslint/eslint-plugin": "^8.72.1", "@typescript-eslint/parser": "^8.72.1", "@vitejs/plugin-react": "^6.2.1", + "cross-spawn": "7.0.6", "esbuild": "0.28.2", "eslint": "^9.39.5", "eslint-import-resolver-typescript": "^4.4.5", diff --git a/packages/angular-db/package.json b/packages/angular-db/package.json index 917c5fa148..4ce3b5c228 100644 --- a/packages/angular-db/package.json +++ b/packages/angular-db/package.json @@ -18,6 +18,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs", "dev": "vite build --watch", "test": "vitest --run", "lint": "eslint . --fix" diff --git a/packages/browser-db-sqlite-persistence/package.json b/packages/browser-db-sqlite-persistence/package.json index e386f872fb..d42c67ce42 100644 --- a/packages/browser-db-sqlite-persistence/package.json +++ b/packages/browser-db-sqlite-persistence/package.json @@ -20,6 +20,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs --profile node16 --exclude-entrypoints ./wa-sqlite.wasm ./opfs-worker.js", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/capacitor-db-sqlite-persistence/package.json b/packages/capacitor-db-sqlite-persistence/package.json index 0e4e06cd76..5d02c526bb 100644 --- a/packages/capacitor-db-sqlite-persistence/package.json +++ b/packages/capacitor-db-sqlite-persistence/package.json @@ -19,6 +19,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs --profile node16", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/cloudflare-durable-objects-db-sqlite-persistence/package.json b/packages/cloudflare-durable-objects-db-sqlite-persistence/package.json index 90e7ad58ea..05c1481a2a 100644 --- a/packages/cloudflare-durable-objects-db-sqlite-persistence/package.json +++ b/packages/cloudflare-durable-objects-db-sqlite-persistence/package.json @@ -19,6 +19,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/convex-db-collection/package.json b/packages/convex-db-collection/package.json index 38a08b33ed..a8b51d27a1 100644 --- a/packages/convex-db-collection/package.json +++ b/packages/convex-db-collection/package.json @@ -18,6 +18,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs --profile node16", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest run", diff --git a/packages/db-ivm/package.json b/packages/db-ivm/package.json index e125ec08b7..da4f6de571 100644 --- a/packages/db-ivm/package.json +++ b/packages/db-ivm/package.json @@ -20,6 +20,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/db-sqlite-persistence-core/package.json b/packages/db-sqlite-persistence-core/package.json index 50e396b0f5..6a031a3522 100644 --- a/packages/db-sqlite-persistence-core/package.json +++ b/packages/db-sqlite-persistence-core/package.json @@ -18,6 +18,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs --profile node16", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/db/package.json b/packages/db/package.json index dc7503eebc..03b26a995b 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -18,6 +18,7 @@ "scripts": { "build": "vite build", "build:minified": "vite build --minify", + "test:build": "node ../../scripts/check-built-package.mjs", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/electric-db-collection/package.json b/packages/electric-db-collection/package.json index cc90a98f26..c03512ca93 100644 --- a/packages/electric-db-collection/package.json +++ b/packages/electric-db-collection/package.json @@ -18,6 +18,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest run", diff --git a/packages/electron-db-sqlite-persistence/package.json b/packages/electron-db-sqlite-persistence/package.json index 924bd80ef9..5cdd4c745e 100644 --- a/packages/electron-db-sqlite-persistence/package.json +++ b/packages/electron-db-sqlite-persistence/package.json @@ -19,6 +19,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs --profile node16", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/expo-db-sqlite-persistence/package.json b/packages/expo-db-sqlite-persistence/package.json index dc2955bfb7..3ddc098f96 100644 --- a/packages/expo-db-sqlite-persistence/package.json +++ b/packages/expo-db-sqlite-persistence/package.json @@ -19,6 +19,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs --profile node16", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/node-db-sqlite-persistence/package.json b/packages/node-db-sqlite-persistence/package.json index a35d41a173..9dd4767279 100644 --- a/packages/node-db-sqlite-persistence/package.json +++ b/packages/node-db-sqlite-persistence/package.json @@ -19,6 +19,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/offline-transactions/package.json b/packages/offline-transactions/package.json index b6353fc184..76455f3b0b 100644 --- a/packages/offline-transactions/package.json +++ b/packages/offline-transactions/package.json @@ -20,6 +20,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs --profile node16", "dev": "vite build --watch", "test": "vitest", "test:watch": "vitest --watch", diff --git a/packages/powersync-db-collection/package.json b/packages/powersync-db-collection/package.json index 4ec86e0ef5..c966cbe3fa 100644 --- a/packages/powersync-db-collection/package.json +++ b/packages/powersync-db-collection/package.json @@ -25,6 +25,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/powersync-direct-db-collection/package.json b/packages/powersync-direct-db-collection/package.json index 6a98681da8..271b5ec14d 100644 --- a/packages/powersync-direct-db-collection/package.json +++ b/packages/powersync-direct-db-collection/package.json @@ -20,6 +20,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/preact-db/package.json b/packages/preact-db/package.json index 9dc0d9ee9b..fff45b1b8a 100644 --- a/packages/preact-db/package.json +++ b/packages/preact-db/package.json @@ -18,6 +18,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs --profile esm-only", "dev": "vite build --watch", "test": "vitest --run", "lint": "eslint . --fix" diff --git a/packages/query-db-collection/package.json b/packages/query-db-collection/package.json index 62d51f73f5..1a0cffe84a 100644 --- a/packages/query-db-collection/package.json +++ b/packages/query-db-collection/package.json @@ -18,6 +18,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest run", diff --git a/packages/react-db/package.json b/packages/react-db/package.json index e9640b1c50..3e7a9c249f 100644 --- a/packages/react-db/package.json +++ b/packages/react-db/package.json @@ -19,6 +19,7 @@ "scripts": { "build": "vite build && node scripts/check-use-client.mjs", "build:minified": "vite build --minify", + "test:build": "node ../../scripts/check-built-package.mjs", "dev": "vite build --watch", "test": "vitest --run", "lint": "eslint . --fix" diff --git a/packages/react-native-db-sqlite-persistence/package.json b/packages/react-native-db-sqlite-persistence/package.json index 88160ab914..fba1cf358a 100644 --- a/packages/react-native-db-sqlite-persistence/package.json +++ b/packages/react-native-db-sqlite-persistence/package.json @@ -19,6 +19,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs --profile node16", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/react-router-with-db/package.json b/packages/react-router-with-db/package.json index 10ed988f92..00edb3a53f 100644 --- a/packages/react-router-with-db/package.json +++ b/packages/react-router-with-db/package.json @@ -21,6 +21,7 @@ "scripts": { "build": "vite build", "build:minified": "vite build --minify", + "test:build": "node ../../scripts/check-built-package.mjs", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run" diff --git a/packages/rxdb-db-collection/package.json b/packages/rxdb-db-collection/package.json index 9c5fdb5cf1..63970524bf 100644 --- a/packages/rxdb-db-collection/package.json +++ b/packages/rxdb-db-collection/package.json @@ -35,6 +35,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs", "dev": "vite build --watch", "lint": "eslint . --fix", "test": "vitest --run", diff --git a/packages/solid-db/package.json b/packages/solid-db/package.json index 99c6905915..acbfee5321 100644 --- a/packages/solid-db/package.json +++ b/packages/solid-db/package.json @@ -18,6 +18,7 @@ ], "scripts": { "build": "vite build", + "test:build": "node ../../scripts/check-built-package.mjs --profile esm-only", "dev": "vite build --watch", "test": "vitest --run", "lint": "eslint . --fix" diff --git a/packages/svelte-db/package.json b/packages/svelte-db/package.json index ca8045145d..f8a5914c59 100644 --- a/packages/svelte-db/package.json +++ b/packages/svelte-db/package.json @@ -18,6 +18,7 @@ ], "scripts": { "build": "svelte-package --input ./src --output ./dist --tsconfig ./tsconfig.build.json", + "test:build": "tsc --noEmit --strict --skipLibCheck --target ES2022 --module NodeNext scripts/check-provider-types.mts && tsc --noEmit --strict --skipLibCheck --target ES2022 --module ESNext --moduleResolution Bundler scripts/check-provider-types.mts && node ../../scripts/check-built-package.mjs --profile esm-only", "lint": "eslint . --fix", "test": "vitest --run", "test:types": "svelte-check --tsconfig ./tsconfig.json" diff --git a/packages/svelte-db/scripts/check-provider-types.mts b/packages/svelte-db/scripts/check-provider-types.mts new file mode 100644 index 0000000000..2f4ac77f2e --- /dev/null +++ b/packages/svelte-db/scripts/check-provider-types.mts @@ -0,0 +1,24 @@ +// Resolve the public export and compare it with the declaration generated from the component. +import type { DbProvider } from '@tanstack/svelte-db' +import type SourceProvider from '../dist/DbProvider.svelte.d.ts' +import type { DbClient } from '@tanstack/db' +import type { Component, Snippet } from 'svelte' + +type Equal = + (() => T extends Left ? 1 : 2) extends () => T extends Right ? 1 : 2 + ? true + : false +type Assert = T +type PublicProvider = typeof DbProvider +type ExpectedProvider = Component< + { client: DbClient; hydrating?: boolean; children?: Snippet }, + Record, + '' +> +export type PublicContract = Assert> +export type AgreesWithComponent = Assert< + Equal +> +export type InstanceContract = Assert< + Equal> +> diff --git a/packages/svelte-db/src/DbProvider.svelte b/packages/svelte-db/src/DbProvider.svelte index 9905db4cf3..2632dc955d 100644 --- a/packages/svelte-db/src/DbProvider.svelte +++ b/packages/svelte-db/src/DbProvider.svelte @@ -1,19 +1,13 @@