From b6abcc33a121423faaa41d9eef5488df67686fe7 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 28 Jan 2026 18:02:14 +0000 Subject: [PATCH] feat: enable tree-shaking for windmill-client - Remove service re-exports from client.ts - Build default export explicitly in index.ts - Use unbundled ESM output - Add sideEffects: false Results: ~900 bytes vs 91KB for simple imports Co-Authored-By: Claude Opus 4.5 --- typescript-client/build.sh | 154 ++++++++++++++++++++++++++++++++- typescript-client/client.ts | 25 ++---- typescript-client/package.json | 1 + typescript-client/publish.sh | 7 +- typescript-client/sqlUtils.ts | 3 +- 5 files changed, 165 insertions(+), 25 deletions(-) diff --git a/typescript-client/build.sh b/typescript-client/build.sh index f03966751d..bea84d0ebc 100755 --- a/typescript-client/build.sh +++ b/typescript-client/build.sh @@ -41,6 +41,154 @@ echo "" >> "${script_dirpath}/src/index.ts" echo 'export type { DenoS3LightClientSettings } from "./s3Types";' >> "${script_dirpath}/src/index.ts" echo "" >> "${script_dirpath}/src/index.ts" echo 'export { type Base64, setClient, getVariable, setVariable, getResource, setResource, getResumeUrls, setState, setProgress, getProgress, getState, getIdToken, denoS3LightClientSettings, loadS3FileStream, loadS3File, writeS3File, signS3Objects, signS3Object, getPresignedS3PublicUrls, getPresignedS3PublicUrl, task, runScript, runScriptAsync, runScriptByPath, runScriptByHash, runScriptByPathAsync, runScriptByHashAsync, runFlow, runFlowAsync, waitJob, getRootJobId, setFlowUserState, getFlowUserState, usernameToEmail, requestInteractiveSlackApproval, type Sql, requestInteractiveTeamsApproval, appendToResultStream, streamResult, datatable, ducklake, type DatatableSqlTemplateFunction, type SqlTemplateFunction, type S3Object, type S3ObjectRecord, type S3ObjectURI } from "./client";' >> "${script_dirpath}/src/index.ts" -echo "" >> "${script_dirpath}/src/index.ts" -echo 'import * as wmill from "./client";' >> "${script_dirpath}/src/index.ts" -echo 'export default wmill;' >> "${script_dirpath}/src/index.ts" + +# Build default export by combining client utilities + services +# This preserves backward compatibility for `import wmill from "windmill-client"` +# while enabling tree-shaking for named imports +cat >> "${script_dirpath}/src/index.ts" << 'INDEXEOF' + +import { + setClient, + getVariable, + setVariable, + getResource, + setResource, + getResumeUrls, + setState, + setProgress, + getProgress, + getState, + getIdToken, + denoS3LightClientSettings, + loadS3FileStream, + loadS3File, + writeS3File, + signS3Objects, + signS3Object, + getPresignedS3PublicUrls, + getPresignedS3PublicUrl, + task, + runScript, + runScriptAsync, + runScriptByPath, + runScriptByHash, + runScriptByPathAsync, + runScriptByHashAsync, + runFlow, + runFlowAsync, + waitJob, + getRootJobId, + setFlowUserState, + getFlowUserState, + usernameToEmail, + requestInteractiveSlackApproval, + requestInteractiveTeamsApproval, + appendToResultStream, + streamResult, + datatable, + ducklake, + SHARED_FOLDER, + getWorkspace, + getStatePath, + getInternalState, + setInternalState, + getResumeEndpoints, + getResult, + getResultMaybe, + resolveDefaultResource, + databaseUrlFromResource, + base64ToUint8Array, + uint8ArrayToBase64, + parseS3Object, +} from "./client"; + +import { + AdminService, + AuditService, + FlowService, + GranularAclService, + GroupService, + JobService, + ResourceService, + VariableService, + ScriptService, + ScheduleService, + SettingsService, + UserService, + WorkspaceService, + TeamsService, +} from "./services.gen"; + +const wmill = { + // Client utilities + setClient, + getVariable, + setVariable, + getResource, + setResource, + getResumeUrls, + setState, + setProgress, + getProgress, + getState, + getIdToken, + denoS3LightClientSettings, + loadS3FileStream, + loadS3File, + writeS3File, + signS3Objects, + signS3Object, + getPresignedS3PublicUrls, + getPresignedS3PublicUrl, + task, + runScript, + runScriptAsync, + runScriptByPath, + runScriptByHash, + runScriptByPathAsync, + runScriptByHashAsync, + runFlow, + runFlowAsync, + waitJob, + getRootJobId, + setFlowUserState, + getFlowUserState, + usernameToEmail, + requestInteractiveSlackApproval, + requestInteractiveTeamsApproval, + appendToResultStream, + streamResult, + datatable, + ducklake, + SHARED_FOLDER, + getWorkspace, + getStatePath, + getInternalState, + setInternalState, + getResumeEndpoints, + getResult, + getResultMaybe, + resolveDefaultResource, + databaseUrlFromResource, + base64ToUint8Array, + uint8ArrayToBase64, + parseS3Object, + // Services + AdminService, + AuditService, + FlowService, + GranularAclService, + GroupService, + JobService, + ResourceService, + VariableService, + ScriptService, + ScheduleService, + SettingsService, + UserService, + WorkspaceService, + TeamsService, +}; + +export default wmill; +INDEXEOF diff --git a/typescript-client/client.ts b/typescript-client/client.ts index 5b740110a9..60caf10a46 100644 --- a/typescript-client/client.ts +++ b/typescript-client/client.ts @@ -1,3 +1,5 @@ +// Import only the services actually used in this file (not re-exported) +// This enables tree-shaking - importing setClient won't pull in all services import { ResourceService, VariableService, @@ -7,9 +9,8 @@ import { MetricsService, OidcService, UserService, - TeamsService, -} from "./index"; -import { OpenAPI } from "./index"; +} from "./services.gen"; +import { OpenAPI } from "./core/OpenAPI"; // import type { DenoS3LightClientSettings } from "./index"; import { DenoS3LightClientSettings, @@ -29,22 +30,8 @@ export { type DatatableSqlTemplateFunction, } from "./sqlUtils"; -export { - AdminService, - AuditService, - FlowService, - GranularAclService, - GroupService, - JobService, - ResourceService, - VariableService, - ScriptService, - ScheduleService, - SettingsService, - UserService, - WorkspaceService, - TeamsService, -} from "./index"; +// Services are NOT re-exported here to enable tree-shaking +// Import services directly from "windmill-client" or use the default export export type Sql = string; export type Email = string; diff --git a/typescript-client/package.json b/typescript-client/package.json index 1ec6b80568..020d355e85 100644 --- a/typescript-client/package.json +++ b/typescript-client/package.json @@ -4,6 +4,7 @@ "version": "1.618.2", "author": "Ruben Fiszel", "license": "Apache 2.0", + "sideEffects": false, "devDependencies": { "@types/node": "^20.17.16", "tsdown": "^0.12.9", diff --git a/typescript-client/publish.sh b/typescript-client/publish.sh index 4bfc765b80..346e599fa9 100755 --- a/typescript-client/publish.sh +++ b/typescript-client/publish.sh @@ -12,8 +12,11 @@ rm "${script_dirpath}/s3Types.ts" rm "${script_dirpath}/sqlUtils.ts" npm install -# Build JS bundles with tsdown (ESM + CJS, no dts) -npx tsdown --format esm --format cjs --no-dts +# Build bundled CJS for CommonJS compatibility +npx tsdown --format cjs --no-dts + +# Build unbundled ESM for tree-shaking support +npx tsdown --format esm --unbundle --no-dts --no-clean # Generate .d.ts files with tsc (clean output, no bundling) npx tsc diff --git a/typescript-client/sqlUtils.ts b/typescript-client/sqlUtils.ts index 6a396473d2..cf00c60117 100644 --- a/typescript-client/sqlUtils.ts +++ b/typescript-client/sqlUtils.ts @@ -1,4 +1,5 @@ -import { getWorkspace, JobService } from "./client"; +import { getWorkspace } from "./client"; +import { JobService } from "./services.gen"; type ResultCollection = | "last_statement_all_rows"