diff --git a/.changeset/react-start-rsc-browser-decode-types.md b/.changeset/react-start-rsc-browser-decode-types.md new file mode 100644 index 00000000000..cc248e61efd --- /dev/null +++ b/.changeset/react-start-rsc-browser-decode-types.md @@ -0,0 +1,5 @@ +--- +'@tanstack/react-start-rsc': patch +--- + +Type the exports of `@tanstack/react-start-rsc/rsbuild/browser-decode` in its published declarations. They were re-exported from `react-server-dom-rspack/client.browser`, which ships no types, so they resolved to `any`. diff --git a/.changeset/router-plugin-virtual-file-routes-dependency.md b/.changeset/router-plugin-virtual-file-routes-dependency.md new file mode 100644 index 00000000000..72ff9446c82 --- /dev/null +++ b/.changeset/router-plugin-virtual-file-routes-dependency.md @@ -0,0 +1,6 @@ +--- +'@tanstack/router-plugin': patch +'@tanstack/start-plugin-core': patch +--- + +List `@tanstack/virtual-file-routes` as a dependency. The published declarations of both packages refer to its types through the router generator's config, and without the dependency those types resolved to nothing, so `virtualRouteConfig` was typed as `any`. diff --git a/nx.json b/nx.json index b7df8b2c099..6dc311cc0fe 100644 --- a/nx.json +++ b/nx.json @@ -148,7 +148,11 @@ "test:build": { "cache": true, "dependsOn": ["build"], - "inputs": ["buildProduction", "dependentTaskOutputs"] + "inputs": [ + "buildProduction", + "dependentTaskOutputs", + "{workspaceRoot}/scripts/check-published-types.mjs" + ] }, "test:e2e*": { "parallelism": false diff --git a/package.json b/package.json index 3ef11b19697..3447487fca9 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,27 @@ "nx": { "includedScripts": [ "test:docs" - ] + ], + "targets": { + "test:unit": { + "command": "node --test scripts/check-published-types.test.mjs", + "dependsOn": [], + "inputs": [ + "{workspaceRoot}/scripts/check-published-types.mjs", + "{workspaceRoot}/scripts/check-published-types.test.mjs", + { + "externalDependencies": [ + "typescript", + "@types/node" + ] + }, + { + "runtime": "node --version" + } + ], + "outputs": [] + } + } }, "devDependencies": { "@changesets/changelog-github": "^0.7.0", diff --git a/packages/arktype-adapter/package.json b/packages/arktype-adapter/package.json index ceca3fad73f..61fd9913be5 100644 --- a/packages/arktype-adapter/package.json +++ b/packages/arktype-adapter/package.json @@ -35,7 +35,7 @@ "test:types:ts70": "tsc", "test:unit": "vitest", "test:unit:dev": "pnpm run test:unit --watch --typecheck", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/eslint-plugin-router/package.json b/packages/eslint-plugin-router/package.json index 9be54c220e1..f4c56989633 100644 --- a/packages/eslint-plugin-router/package.json +++ b/packages/eslint-plugin-router/package.json @@ -26,7 +26,7 @@ "test:types:ts70": "tsc", "test:unit": "vitest", "test:unit:dev": "pnpm run test:unit --watch --typecheck", - "test:build": "publint --strict && attw --pack .", + "test:build": "publint --strict && attw --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build && tsc --noEmit" }, "type": "module", diff --git a/packages/eslint-plugin-start/package.json b/packages/eslint-plugin-start/package.json index 803264ed107..1ae96a1c36d 100644 --- a/packages/eslint-plugin-start/package.json +++ b/packages/eslint-plugin-start/package.json @@ -26,7 +26,7 @@ "test:types:ts70": "tsc", "test:unit": "vitest", "test:unit:dev": "pnpm run test:unit --watch --typecheck", - "test:build": "publint --strict && attw --pack .", + "test:build": "publint --strict && attw --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build && tsc --noEmit" }, "type": "module", diff --git a/packages/history/package.json b/packages/history/package.json index d09c710d2f9..3d0c83264ba 100644 --- a/packages/history/package.json +++ b/packages/history/package.json @@ -28,7 +28,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "test:unit": "vitest", "test:unit:dev": "pnpm run test:unit --watch", "build": "vite build" diff --git a/packages/react-router-devtools/package.json b/packages/react-router-devtools/package.json index 6af2d3227e5..99bd67ec300 100644 --- a/packages/react-router-devtools/package.json +++ b/packages/react-router-devtools/package.json @@ -33,7 +33,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/react-router-ssr-query/package.json b/packages/react-router-ssr-query/package.json index 73331460478..a0722de1274 100644 --- a/packages/react-router-ssr-query/package.json +++ b/packages/react-router-ssr-query/package.json @@ -35,7 +35,7 @@ "test:types:ts70": "tsc", "test:unit": "exit 0; vitest", "test:unit:dev": "pnpm run test:unit --watch", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/react-router/package.json b/packages/react-router/package.json index 9a61d5af257..98919a3ba0f 100644 --- a/packages/react-router/package.json +++ b/packages/react-router/package.json @@ -37,7 +37,7 @@ "test:unit:dev": "pnpm run test:unit --watch --hideSkippedTests", "test:perf": "vitest bench", "test:perf:dev": "pnpm run test:perf --watch --hideSkippedTests", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/react-start-client/package.json b/packages/react-start-client/package.json index b919d47b923..d1c911a1226 100644 --- a/packages/react-start-client/package.json +++ b/packages/react-start-client/package.json @@ -36,7 +36,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/react-start-rsc/package.json b/packages/react-start-rsc/package.json index 4835e765341..13949736944 100644 --- a/packages/react-start-rsc/package.json +++ b/packages/react-start-rsc/package.json @@ -35,7 +35,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/react-start-rsc/src/rsbuild/browser-decode.ts b/packages/react-start-rsc/src/rsbuild/browser-decode.ts index 040e3e6bd9d..29fbbc17c28 100644 --- a/packages/react-start-rsc/src/rsbuild/browser-decode.ts +++ b/packages/react-start-rsc/src/rsbuild/browser-decode.ts @@ -5,7 +5,19 @@ * Flight decode. */ -export { - createFromReadableStream, - createFromFetch, +import { + createFromFetch as decodeFlightFetch, + createFromReadableStream as decodeFlightStream, } from 'react-server-dom-rspack/client.browser' + +// react-server-dom-rspack ships no declarations. The annotations keep the +// published declaration file free of imports from it. +export const createFromReadableStream: ( + stream: ReadableStream, + options?: object, +) => Promise = decodeFlightStream + +export const createFromFetch: ( + fetchPromise: Promise, + options?: object, +) => Promise = decodeFlightFetch diff --git a/packages/react-start-server/package.json b/packages/react-start-server/package.json index a725b70d9c8..a43b9fc4ad3 100644 --- a/packages/react-start-server/package.json +++ b/packages/react-start-server/package.json @@ -35,7 +35,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/react-start/package.json b/packages/react-start/package.json index 9aa75d142f2..937a5c24553 100644 --- a/packages/react-start/package.json +++ b/packages/react-start/package.json @@ -26,7 +26,7 @@ "scripts": { "clean": "rimraf ./dist && rimraf ./coverage", "test": "pnpm test:build", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build && vite build -c vite.config.server-entry.ts" }, "type": "module", diff --git a/packages/router-cli/package.json b/packages/router-cli/package.json index 3dd9119be3d..7c43756c4c6 100644 --- a/packages/router-cli/package.json +++ b/packages/router-cli/package.json @@ -33,7 +33,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/router-core/package.json b/packages/router-core/package.json index ed2b7942780..333d020f528 100644 --- a/packages/router-core/package.json +++ b/packages/router-core/package.json @@ -28,7 +28,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "test:unit": "vitest", "test:unit:dev": "pnpm run test:unit --watch", "build": "vite build" diff --git a/packages/router-devtools-core/package.json b/packages/router-devtools-core/package.json index 8b49f87e644..af7560e1732 100644 --- a/packages/router-devtools-core/package.json +++ b/packages/router-devtools-core/package.json @@ -34,7 +34,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/router-devtools/package.json b/packages/router-devtools/package.json index 2eb96afce28..3d43a66b89a 100644 --- a/packages/router-devtools/package.json +++ b/packages/router-devtools/package.json @@ -33,7 +33,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/router-generator/package.json b/packages/router-generator/package.json index de9fc5cf1fc..6230d66184d 100644 --- a/packages/router-generator/package.json +++ b/packages/router-generator/package.json @@ -36,7 +36,7 @@ "test:types:ts70": "tsc -p tsconfig.legacy.json", "test:unit": "vitest --typecheck false && vitest run --typecheck.only", "test:unit:dev": "pnpm run test:unit --watch --hideSkippedTests", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/router-plugin/package.json b/packages/router-plugin/package.json index e913f7f5c02..985d790f819 100644 --- a/packages/router-plugin/package.json +++ b/packages/router-plugin/package.json @@ -37,7 +37,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", @@ -123,6 +123,7 @@ "@tanstack/router-core": "workspace:*", "@tanstack/router-generator": "workspace:*", "@tanstack/router-utils": "workspace:*", + "@tanstack/virtual-file-routes": "workspace:*", "chokidar": "catalog:", "unplugin": "^3.5.0", "zod": "catalog:" diff --git a/packages/router-ssr-query-core/package.json b/packages/router-ssr-query-core/package.json index 8254eaae811..2383b8d5c5c 100644 --- a/packages/router-ssr-query-core/package.json +++ b/packages/router-ssr-query-core/package.json @@ -37,7 +37,7 @@ "test:unit:dev": "pnpm run test:unit --watch", "test:perf": "vitest bench", "test:perf:dev": "pnpm run test:perf --watch --hideSkippedTests", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/router-utils/package.json b/packages/router-utils/package.json index 0ce243718fb..9ba72a5cf2d 100644 --- a/packages/router-utils/package.json +++ b/packages/router-utils/package.json @@ -34,7 +34,7 @@ "test:types:ts60": "tsc6", "test:types:ts70": "tsc", "test:unit": "vitest", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/router-vite-plugin/package.json b/packages/router-vite-plugin/package.json index 25e0bdccc7d..0b9b557fb55 100644 --- a/packages/router-vite-plugin/package.json +++ b/packages/router-vite-plugin/package.json @@ -35,7 +35,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/solid-router-devtools/package.json b/packages/solid-router-devtools/package.json index 7da500f34b4..ff1453c8249 100644 --- a/packages/solid-router-devtools/package.json +++ b/packages/solid-router-devtools/package.json @@ -33,7 +33,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build && tsc -p tsconfig.build.json" }, "type": "module", diff --git a/packages/solid-router-ssr-query/package.json b/packages/solid-router-ssr-query/package.json index 4b1ece0f780..eb846b44b54 100644 --- a/packages/solid-router-ssr-query/package.json +++ b/packages/solid-router-ssr-query/package.json @@ -35,7 +35,7 @@ "test:types:ts70": "tsc", "test:unit": "exit 0; vitest", "test:unit:dev": "pnpm run test:unit --watch", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/solid-router/package.json b/packages/solid-router/package.json index 80840069ea8..eb03fa09096 100644 --- a/packages/solid-router/package.json +++ b/packages/solid-router/package.json @@ -37,7 +37,7 @@ "test:unit:dev": "pnpm run test:unit --watch --hideSkippedTests", "test:perf": "vitest bench", "test:perf:dev": "pnpm run test:perf --watch --hideSkippedTests", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build && tsc -p tsconfig.build.json" }, "type": "module", diff --git a/packages/solid-start-client/package.json b/packages/solid-start-client/package.json index 3e30225764d..f0b1f904bfc 100644 --- a/packages/solid-start-client/package.json +++ b/packages/solid-start-client/package.json @@ -36,7 +36,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/solid-start-server/package.json b/packages/solid-start-server/package.json index a87cad7b94a..47790930d8d 100644 --- a/packages/solid-start-server/package.json +++ b/packages/solid-start-server/package.json @@ -35,7 +35,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/solid-start/package.json b/packages/solid-start/package.json index b1ab9167f30..58e45f6bdaa 100644 --- a/packages/solid-start/package.json +++ b/packages/solid-start/package.json @@ -27,7 +27,7 @@ "clean": "rimraf ./dist && rimraf ./coverage", "test": "pnpm test:build", "test:unit": "vitest", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build && vite build -c vite.config.server-entry.ts" }, "type": "module", diff --git a/packages/start-client-core/package.json b/packages/start-client-core/package.json index c74dce13aa7..ed41ea3f40d 100644 --- a/packages/start-client-core/package.json +++ b/packages/start-client-core/package.json @@ -36,7 +36,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/start-fn-stubs/package.json b/packages/start-fn-stubs/package.json index 12621fefd7a..ade34b5e479 100644 --- a/packages/start-fn-stubs/package.json +++ b/packages/start-fn-stubs/package.json @@ -34,7 +34,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/start-plugin-core/package.json b/packages/start-plugin-core/package.json index ec951adae34..c32c9d4edc2 100644 --- a/packages/start-plugin-core/package.json +++ b/packages/start-plugin-core/package.json @@ -38,7 +38,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "nx": { @@ -118,6 +118,7 @@ "@tanstack/router-plugin": "workspace:*", "@tanstack/router-utils": "workspace:*", "@tanstack/start-server-core": "workspace:*", + "@tanstack/virtual-file-routes": "workspace:*", "exsolve": "^1.1.3", "lightningcss": "^1.33.0", "pathe": "catalog:", diff --git a/packages/start-server-core/package.json b/packages/start-server-core/package.json index 020747da699..6e33e7dcb15 100644 --- a/packages/start-server-core/package.json +++ b/packages/start-server-core/package.json @@ -36,7 +36,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "nx": { diff --git a/packages/start-static-server-functions/package.json b/packages/start-static-server-functions/package.json index 603d7524fbd..026a8426bed 100644 --- a/packages/start-static-server-functions/package.json +++ b/packages/start-static-server-functions/package.json @@ -36,7 +36,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/start-storage-context/package.json b/packages/start-storage-context/package.json index 083facb7499..36e42bb110d 100644 --- a/packages/start-storage-context/package.json +++ b/packages/start-storage-context/package.json @@ -36,7 +36,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/valibot-adapter/package.json b/packages/valibot-adapter/package.json index f59bec55a4e..453b7d6d174 100644 --- a/packages/valibot-adapter/package.json +++ b/packages/valibot-adapter/package.json @@ -35,7 +35,7 @@ "test:types:ts70": "tsc", "test:unit": "vitest", "test:unit:dev": "pnpm run test:unit --watch --typecheck", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/virtual-file-routes/package.json b/packages/virtual-file-routes/package.json index 5d682e1db21..1fa8f1efbe9 100644 --- a/packages/virtual-file-routes/package.json +++ b/packages/virtual-file-routes/package.json @@ -26,7 +26,7 @@ "scripts": { "clean": "rimraf ./dist && rimraf ./coverage", "test:eslint": "eslint ./src", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/vue-router-devtools/package.json b/packages/vue-router-devtools/package.json index 6553f0c5ea4..526d24862aa 100644 --- a/packages/vue-router-devtools/package.json +++ b/packages/vue-router-devtools/package.json @@ -33,7 +33,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/vue-router-ssr-query/package.json b/packages/vue-router-ssr-query/package.json index 73e6dd1cc37..59438eb17a5 100644 --- a/packages/vue-router-ssr-query/package.json +++ b/packages/vue-router-ssr-query/package.json @@ -35,7 +35,7 @@ "test:types:ts70": "tsc", "test:unit": "exit 0; vitest", "test:unit:dev": "pnpm run test:unit --watch", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/vue-router/package.json b/packages/vue-router/package.json index 93ae8fdeed0..518111c724b 100644 --- a/packages/vue-router/package.json +++ b/packages/vue-router/package.json @@ -33,7 +33,7 @@ "test:unit:dev": "pnpm run test:unit --watch --hideSkippedTests", "test:perf": "vitest bench", "test:perf:dev": "pnpm run test:perf --watch --hideSkippedTests", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build && tsc -p tsconfig.build.json" }, "type": "module", diff --git a/packages/vue-start-client/package.json b/packages/vue-start-client/package.json index 74b80169243..3e8e2facc21 100644 --- a/packages/vue-start-client/package.json +++ b/packages/vue-start-client/package.json @@ -36,7 +36,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/vue-start-server/package.json b/packages/vue-start-server/package.json index 4fc4c1c9fd3..20c9aab0e05 100644 --- a/packages/vue-start-server/package.json +++ b/packages/vue-start-server/package.json @@ -35,7 +35,7 @@ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js", "test:types:ts60": "tsc6", "test:types:ts70": "tsc", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/packages/vue-start/package.json b/packages/vue-start/package.json index ccd495e3db1..ee6dec79e3f 100644 --- a/packages/vue-start/package.json +++ b/packages/vue-start/package.json @@ -26,7 +26,7 @@ "scripts": { "clean": "rimraf ./dist && rimraf ./coverage", "test": "pnpm test:build", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build && vite build -c vite.config.server-entry.ts" }, "type": "module", diff --git a/packages/zod-adapter/package.json b/packages/zod-adapter/package.json index 0f2c330d0cc..f6c30ebf6c0 100644 --- a/packages/zod-adapter/package.json +++ b/packages/zod-adapter/package.json @@ -35,7 +35,7 @@ "test:types:ts70": "tsc", "test:unit": "vitest", "test:unit:dev": "pnpm run test:unit --watch --typecheck", - "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", + "test:build": "publint --strict && attw --ignore-rules no-resolution --pack . && node ../../scripts/check-published-types.mjs", "build": "vite build" }, "type": "module", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3d649f1518f..a6777fe359d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15055,6 +15055,9 @@ importers: '@tanstack/router-utils': specifier: workspace:* version: link:../router-utils + '@tanstack/virtual-file-routes': + specifier: workspace:* + version: link:../virtual-file-routes chokidar: specifier: 'catalog:' version: 5.0.0 @@ -15617,6 +15620,9 @@ importers: '@tanstack/start-server-core': specifier: workspace:* version: link:../start-server-core + '@tanstack/virtual-file-routes': + specifier: workspace:* + version: link:../virtual-file-routes exsolve: specifier: ^1.1.3 version: 1.2.0 diff --git a/scripts/check-published-types.mjs b/scripts/check-published-types.mjs new file mode 100644 index 00000000000..f794e76b362 --- /dev/null +++ b/scripts/check-published-types.mjs @@ -0,0 +1,289 @@ +// Compiles a package's published declarations the way a user's project sees +// them: `skipLibCheck: false`, no tsconfig `paths`, dependencies resolved +// through `node_modules` to their published `dist`. +// +// Run it from the package directory, after the build: +// node ../../scripts/check-published-types.mjs +// +// With `skipLibCheck: true`, which most apps use, a broken reference in a +// published `.d.ts` silently becomes `any`. This check makes it visible. + +import fs from 'node:fs' +import { createRequire } from 'node:module' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import ts from 'typescript' + +const require = createRequire(import.meta.url) + +// Module specifiers that cannot resolve in published declarations by design, +// because a bundler provides them at build time. Name each one per package. +const unresolvableByDesign = { + '@tanstack/react-start-rsc': [ + 'virtual:tanstack-rsc-runtime', + '#tanstack-start-server-fn-resolver', + ], +} + +const declarationFile = /\.d\.[cm]?ts$/ +const cannotFindModule = new Set([2307, 2792]) + +export function checkPublishedTypes(packageDir, options = {}) { + packageDir = fs.realpathSync(packageDir) + const pkg = JSON.parse( + fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8'), + ) + const allowed = new Set( + options.unresolvableByDesign ?? unresolvableByDesign[pkg.name] ?? [], + ) + const distDir = path.join(packageDir, 'dist') + const compilerOptions = createCompilerOptions(packageDir) + const problems = [] + const trees = [] + const usedAllowances = new Set() + + for (const tree of findTrees(distDir)) { + const rootNames = walk(tree.dir).filter((file) => + declarationFile.test(file), + ) + const program = ts.createProgram({ rootNames, options: compilerOptions }) + const ownFiles = program + .getSourceFiles() + .filter((sf) => isOwnFile(packageDir, sf.fileName)) + trees.push({ name: tree.name, files: ownFiles.length }) + + const diagnostics = [ + ...program.getOptionsDiagnostics(), + ...program.getGlobalDiagnostics(), + ...ownFiles.flatMap((sf) => [ + ...program.getSyntacticDiagnostics(sf), + ...program.getSemanticDiagnostics(sf), + ]), + ] + for (const diagnostic of diagnostics) { + const specifier = unresolvedSpecifier(diagnostic) + if (specifier !== undefined && allowed.has(specifier)) { + usedAllowances.add(specifier) + continue + } + problems.push(fromDiagnostic(packageDir, tree.name, diagnostic)) + } + + for (const sf of ownFiles) { + for (const { specifier, pos } of moduleSpecifiers(sf)) { + const reason = specifierProblem(distDir, sf.fileName, specifier) + if (reason) { + problems.push({ + tree: tree.name, + ...location(packageDir, sf, pos), + code: 'specifier', + message: `'${specifier}' ${reason}`, + }) + } + } + } + } + + for (const specifier of allowed) { + if (!usedAllowances.has(specifier)) { + problems.push({ + tree: '-', + file: path.relative(packageDir, fileURLToPath(import.meta.url)), + line: '-', + code: 'allowance', + message: `'${specifier}' is allowed to stay unresolved, but no declaration imports it. Remove it from the list.`, + }) + } + } + + return { name: pkg.name, trees, problems } +} + +function createCompilerOptions(packageDir) { + // Only the JSX settings come from the package's tsconfig. Everything else is + // fixed, so that `paths`, `customConditions` and other repository-only + // settings never change how the published declarations resolve. + const jsx = {} + const configPath = path.join(packageDir, 'tsconfig.json') + if (fs.existsSync(configPath)) { + const { config } = ts.readConfigFile(configPath, ts.sys.readFile) + const { options } = ts.parseJsonConfigFileContent( + config, + ts.sys, + packageDir, + ) + jsx.jsx = options.jsx + jsx.jsxImportSource = options.jsxImportSource + } + return { + ...jsx, + target: ts.ScriptTarget.ES2022, + module: ts.ModuleKind.ESNext, + moduleResolution: ts.ModuleResolutionKind.Bundler, + lib: [ + 'lib.esnext.d.ts', + 'lib.dom.d.ts', + 'lib.dom.iterable.d.ts', + 'lib.dom.asynciterable.d.ts', + ], + types: ['node'], + typeRoots: [ + path.dirname(path.dirname(require.resolve('@types/node/package.json'))), + ], + strict: true, + skipLibCheck: false, + noEmit: true, + } +} + +// One program per declaration tree (`dist/esm`, `dist/cjs`, `dist/source`, +// ...). The trees repeat the same `declare global` blocks, so a program that +// mixes them reports conflicts that no user sees. +function findTrees(distDir) { + if (!fs.existsSync(distDir)) { + return [] + } + return fs + .readdirSync(distDir, { withFileTypes: true }) + .filter((entry) => entry.isDirectory()) + .map((entry) => ({ name: entry.name, dir: path.join(distDir, entry.name) })) + .filter((tree) => walk(tree.dir).some((f) => declarationFile.test(f))) +} + +function walk(dir) { + return fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => { + const full = path.join(dir, entry.name) + return entry.isDirectory() ? walk(full) : [full] + }) +} + +// A file belongs to the package under test when it sits in the package +// directory and not in a `node_modules` folder. Workspace dependencies resolve +// to their real path in another package directory, so their diagnostics are +// left to that package's own run, and third-party declarations are ignored. +function isOwnFile(packageDir, fileName) { + const relative = path.relative(packageDir, fileName) + return ( + !relative.startsWith('..') && + !path.isAbsolute(relative) && + !relative.split(path.sep).includes('node_modules') + ) +} + +function unresolvedSpecifier(diagnostic) { + if (!diagnostic.file || !cannotFindModule.has(diagnostic.code)) { + return undefined + } + const text = diagnostic.file.text.slice( + diagnostic.start, + diagnostic.start + diagnostic.length, + ) + return /^(['"])(.*)\1$/.exec(text)?.[2] +} + +function moduleSpecifiers(sf) { + const found = [] + const add = (node) => { + if (node && ts.isStringLiteralLike(node)) { + found.push({ specifier: node.text, pos: node.getStart(sf) }) + } + } + const visit = (node) => { + if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) { + add(node.moduleSpecifier) + } else if (ts.isImportTypeNode(node)) { + add( + ts.isLiteralTypeNode(node.argument) ? node.argument.literal : undefined, + ) + } else if ( + ts.isImportEqualsDeclaration(node) && + ts.isExternalModuleReference(node.moduleReference) + ) { + add(node.moduleReference.expression) + } else if (ts.isModuleDeclaration(node)) { + add(node.name) + } + ts.forEachChild(node, visit) + } + visit(sf) + for (const ref of [...sf.referencedFiles, ...sf.typeReferenceDirectives]) { + found.push({ specifier: ref.fileName, pos: ref.pos }) + } + return found +} + +function specifierProblem(distDir, fileName, specifier) { + if (specifier.includes('dist-ts')) { + return 'points into a dist-ts declaration set, which is not published' + } + if (specifier.startsWith('.')) { + const target = path.resolve(path.dirname(fileName), specifier) + if (path.relative(distDir, target).startsWith('..')) { + return "resolves outside the package's dist" + } + } + return undefined +} + +function fromDiagnostic(packageDir, tree, diagnostic) { + const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n') + if (!diagnostic.file) { + return { + tree, + file: '(global)', + line: '-', + code: `TS${diagnostic.code}`, + message, + } + } + return { + tree, + ...location(packageDir, diagnostic.file, diagnostic.start), + code: `TS${diagnostic.code}`, + message, + } +} + +function location(packageDir, sf, pos) { + const { line, character } = sf.getLineAndCharacterOfPosition(pos) + return { + file: path.relative(packageDir, sf.fileName), + line: `${line + 1}:${character + 1}`, + } +} + +function formatResult({ name, trees, problems }, seconds) { + const summary = trees.map((t) => `${t.name} ${t.files}`).join(', ') + if (problems.length === 0) { + return `${name}: published declarations OK (${summary} files, ${seconds}s)` + } + const lines = problems.map( + (p) => + ` [${p.tree}] ${p.file}:${p.line} ${p.code}: ${p.message.replaceAll('\n', '\n ')}`, + ) + return [ + `${name}: ${problems.length} problem(s) in the published declarations (${summary} files)`, + ...lines, + ].join('\n') +} + +if ( + process.argv[1] && + fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url) +) { + const start = performance.now() + const result = checkPublishedTypes(process.cwd()) + const seconds = ((performance.now() - start) / 1000).toFixed(1) + if (result.trees.length === 0) { + console.error( + `${result.name}: no declaration files under dist. Build first.`, + ) + process.exit(1) + } + const output = formatResult(result, seconds) + if (result.problems.length > 0) { + console.error(output) + process.exit(1) + } + console.log(output) +} diff --git a/scripts/check-published-types.test.mjs b/scripts/check-published-types.test.mjs new file mode 100644 index 00000000000..cb284148191 --- /dev/null +++ b/scripts/check-published-types.test.mjs @@ -0,0 +1,131 @@ +import assert from 'node:assert/strict' +import fs from 'node:fs' +import os from 'node:os' +import path from 'node:path' +import test from 'node:test' +import { checkPublishedTypes } from './check-published-types.mjs' + +// Published declarations after `stripInternal` removed `PendingTx`, +// `RouteMatch.__beforeLoadContext`, `RouteMatch._strictParams` and +// `isAbsoluteUrl`, while references to them were left behind. +const core = { + 'package.json': JSON.stringify({ + name: 'core', + type: 'module', + exports: { '.': { types: './dist/esm/index.d.ts' } }, + }), + 'dist/esm/index.d.ts': [ + "export type { RouteMatch } from './Matches.js'", + "export type { TxId } from './router.js'", + // A re-export of a stripped name. + "export { joinPaths, isAbsoluteUrl } from './utils.js'", + ].join('\n'), + 'dist/esm/Matches.d.ts': 'export interface RouteMatch { id: string }', + // A public alias of a stripped type. + 'dist/esm/router.d.ts': "export type TxId = PendingTx['id']", + 'dist/esm/utils.d.ts': + 'export declare function joinPaths(a: string, b: string): string', + // The shape of TanStack/router#8203: no entry point reaches this file. + 'dist/esm/ssr/types.d.ts': [ + "import type { RouteMatch } from '../Matches.js'", + "export interface DehydratedMatch { b?: RouteMatch['__beforeLoadContext'] }", + ].join('\n'), +} + +const binding = { + 'package.json': JSON.stringify({ name: 'binding', type: 'module' }), + 'dist/esm/index.d.ts': [ + "import type { RouteMatch } from 'core'", + // A binding that leaks a stripped core member. + "export type BindingParams = RouteMatch['_strictParams']", + // Compiles, but no user has this path. + "export type { TxId } from '../../../core/dist/esm/index.js'", + "export type Leak = import('../../../core/dist/esm/index.js').RouteMatch", + "export type Internal = import('core/dist-ts/index.js').RouteMatch", + ].join('\n'), +} + +const virtual = { + 'package.json': JSON.stringify({ name: 'virtual', type: 'module' }), + 'dist/esm/index.d.ts': "export { runtime } from 'virtual:runtime'", +} + +function setup() { + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'published-types-')) + for (const [name, files] of Object.entries({ core, binding, virtual })) { + for (const [file, content] of Object.entries(files)) { + const full = path.join(root, name, file) + fs.mkdirSync(path.dirname(full), { recursive: true }) + fs.writeFileSync(full, content) + } + } + fs.mkdirSync(path.join(root, 'binding/node_modules')) + fs.symlinkSync( + path.join(root, 'core'), + path.join(root, 'binding/node_modules/core'), + 'dir', + ) + return root +} + +function summarize(problems) { + return problems + .map((p) => `${p.file}:${p.line.split(':')[0]} ${p.code}`) + .sort() +} + +test('reports references to stripped declarations in the package', (t) => { + const root = setup() + t.after(() => fs.rmSync(root, { recursive: true, force: true })) + + const result = checkPublishedTypes(path.join(root, 'core')) + + assert.deepEqual(result.trees, [{ name: 'esm', files: 5 }]) + assert.deepEqual(summarize(result.problems), [ + 'dist/esm/index.d.ts:3 TS2305', + 'dist/esm/router.d.ts:1 TS2304', + 'dist/esm/ssr/types.d.ts:2 TS2339', + ]) +}) + +test('reports a leaked core member and specifiers that escape dist, not errors inside the dependency', (t) => { + const root = setup() + t.after(() => fs.rmSync(root, { recursive: true, force: true })) + + const result = checkPublishedTypes(path.join(root, 'binding')) + + assert.deepEqual(summarize(result.problems), [ + 'dist/esm/index.d.ts:2 TS2339', + 'dist/esm/index.d.ts:3 specifier', + 'dist/esm/index.d.ts:4 specifier', + 'dist/esm/index.d.ts:5 TS2307', + 'dist/esm/index.d.ts:5 specifier', + ]) + assert.match( + result.problems.find( + (p) => p.line.startsWith('5:') && p.code === 'specifier', + ).message, + /dist-ts/, + ) +}) + +test('accepts only the named unresolvable specifiers, and each one must be used', (t) => { + const root = setup() + t.after(() => fs.rmSync(root, { recursive: true, force: true })) + const dir = path.join(root, 'virtual') + + assert.deepEqual(summarize(checkPublishedTypes(dir).problems), [ + 'dist/esm/index.d.ts:1 TS2307', + ]) + assert.deepEqual( + checkPublishedTypes(dir, { unresolvableByDesign: ['virtual:runtime'] }) + .problems, + [], + ) + assert.deepEqual( + checkPublishedTypes(dir, { + unresolvableByDesign: ['virtual:runtime', 'virtual:unused'], + }).problems.map((p) => p.code), + ['allowance'], + ) +})