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 <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-01-28 18:02:14 +00:00
parent 0f625580f3
commit b6abcc33a1
5 changed files with 165 additions and 25 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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",

View File

@@ -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

View File

@@ -1,4 +1,5 @@
import { getWorkspace, JobService } from "./client";
import { getWorkspace } from "./client";
import { JobService } from "./services.gen";
type ResultCollection =
| "last_statement_all_rows"