diff --git a/.changeset/bump-devtools-event-client.md b/.changeset/bump-devtools-event-client.md new file mode 100644 index 000000000..4fc477077 --- /dev/null +++ b/.changeset/bump-devtools-event-client.md @@ -0,0 +1,5 @@ +--- +'@tanstack/form-core': patch +--- + +Bump `@tanstack/devtools-event-client` to `^0.5.1`. diff --git a/packages/form-core/package.json b/packages/form-core/package.json index cc59a8f43..744bde443 100644 --- a/packages/form-core/package.json +++ b/packages/form-core/package.json @@ -16,7 +16,7 @@ }, "scripts": { "clean": "premove ./dist ./coverage", - "test:eslint": "eslint ./src ./tests", + "test:eslint": "eslint ./src ./tests ./test-build", "test:types": "pnpm run \"/^test:types:ts[0-9]{2}$/\"", "test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js", "test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js", @@ -26,7 +26,7 @@ "test:types:ts59": "tsc", "test:lib": "vitest", "test:lib:dev": "pnpm run test:lib --watch", - "test:build": "publint --strict", + "test:build": "publint --strict && vitest --dir ./test-build --coverage.enabled=false --typecheck.enabled=false", "build": "vite build" }, "type": "module", diff --git a/packages/form-core/test-build/bundle.spec.ts b/packages/form-core/test-build/bundle.spec.ts new file mode 100644 index 000000000..c30b541e1 --- /dev/null +++ b/packages/form-core/test-build/bundle.spec.ts @@ -0,0 +1,53 @@ +import { fileURLToPath } from 'node:url' +import { describe, expect, it } from 'vitest' +import { build } from 'vite' +import type { Rollup } from 'vite' + +const entry = fileURLToPath(new URL('../dist/esm/index.js', import.meta.url)) + +const eventClientPackage = '@tanstack/devtools-event-client' +const eventClientModule = 'plugin.js' + +async function bundle(mode: 'production' | 'development') { + const result = (await build({ + configFile: false, + logLevel: 'silent', + mode, + define: { 'process.env.NODE_ENV': JSON.stringify(mode) }, + build: { + write: false, + minify: false, + lib: { entry, formats: ['es'], fileName: 'index' }, + }, + })) as Array + + return result + .flatMap((output) => output.output) + .filter((chunk): chunk is Rollup.OutputChunk => chunk.type === 'chunk') +} + +function renderedEventClientModules(chunks: Array) { + return chunks + .flatMap((chunk) => Object.entries(chunk.modules)) + .filter( + ([id, module]) => + id.includes(eventClientPackage) && + id.endsWith(`/${eventClientModule}`) && + module.renderedLength > 0, + ) + .map(([id, module]) => ({ id, renderedLength: module.renderedLength })) +} + +describe('bundle', () => { + it('excludes the devtools event client from production bundles', async () => { + const chunks = await bundle('production') + + expect(renderedEventClientModules(chunks)).toEqual([]) + }) + + it('includes the devtools event client in development bundles', async () => { + const chunks = await bundle('development') + + expect(renderedEventClientModules(chunks)).not.toEqual([]) + }) +}) diff --git a/packages/form-core/tsconfig.json b/packages/form-core/tsconfig.json index 328e2f243..168d36313 100644 --- a/packages/form-core/tsconfig.json +++ b/packages/form-core/tsconfig.json @@ -4,5 +4,11 @@ "moduleResolution": "Bundler" // "noErrorTruncation": true }, - "include": ["src", "tests", "eslint.config.js", "vite.config.ts"] + "include": [ + "src", + "tests", + "test-build", + "eslint.config.js", + "vite.config.ts" + ] }