Skip to content

fix(pkg): ship compiled dist/ instead of TypeScript sources#72

Open
qianhaoq wants to merge 1 commit intoTencent:mainfrom
qianhaoq:fix/ship-compiled-dist
Open

fix(pkg): ship compiled dist/ instead of TypeScript sources#72
qianhaoq wants to merge 1 commit intoTencent:mainfrom
qianhaoq:fix/ship-compiled-dist

Conversation

@qianhaoq
Copy link
Copy Markdown

Summary

Publish the compiled dist/ output and point openclaw.extensions at ./dist/index.js, so the OpenClaw host no longer has to transpile ~34 TypeScript files via jiti on every startup.

Fixes #71 (see that issue for the full diagnosis and CPU profile).

Why

The repo already has a working tsconfig.json (emits to dist/) and prepublishOnly already runs tsc. But dist/ is not listed in package.json#files and openclaw.extensions still points at ./index.ts, so consumers receive only TS sources. That forces the host to invoke jiti on every boot — locally measured at ~5.2s of main-thread CPU out of 7.3s total for openclaw plugins list. This likely contributes to the Docker startup hang in #40 (healthcheck never passes because the CPU-bound transpile happens before the gateway reports healthy).

Change

Two fields in package.json:

  • files: ship dist/ (exclude .map files), drop src/ and index.ts.
  • openclaw.extensions: ./dist/index.js instead of ./index.ts.
  • Adds main: ./dist/index.js for tools that honor it.

No build script or CI change needed — prepublishOnly already produces dist/.

Measured effect

Local install, OpenClaw 2026.4.14, plugin built with this PR's layout and reinstalled:

command before after
openclaw plugins list 7.4s 3.0s
openclaw (bare) 7.2s 2.8s

jiti no longer appears in the top frames of the CPU profile.

Tarball: ~197kB → ~188kB unpacked, and no longer ships source.

Test plan

  • npm install && npm run build produces dist/index.js and dist/src/**/*.js.
  • npm pack --dry-run shows dist/ and no .ts files.
  • Install the resulting tarball via openclaw plugins install <tarball> and verify openclaw plugins list reports entry path ending in dist/index.js and status loaded.
  • Smoke-test the Weixin channel flow (QR login / send message) against a real bot to confirm no runtime regression from shipping compiled output.

Problem:
The published tarball only contains .ts sources (index.ts, src/**/*.ts)
and openclaw.extensions points to ./index.ts. The OpenClaw host has to
transpile ~34 files via jiti on every startup. In a local measurement
this added ~5s of main-thread CPU to every openclaw invocation, and
likely contributes to the Docker startup hangs reported in Tencent#40 (high
CPU, never becomes healthy before the healthcheck times out).

The repo already has a tsconfig.json that emits to dist/ and a build
script, but dist/ is not listed in "files" and openclaw.extensions still
points at ./index.ts, so none of this reaches consumers.

Fix:
- package.json files: ship dist/ (excluding sourcemaps), drop src/ and
  index.ts so we don't double-ship source.
- package.json main: ./dist/index.js for tools that respect it.
- package.json openclaw.extensions: ./dist/index.js so the host loads
  the compiled entry instead of transpiling at runtime.

prepublishOnly already runs `npm run typecheck && npm run build`, so
dist/ is produced before publish; no CI change needed.

Effect on a local install (openclaw 2026.4.14):
  openclaw plugins list:  7.4s -> 3.0s
  openclaw (bare):        7.2s -> 2.8s

Tarball size drops from ~197kB unpacked to ~188kB and no longer exposes
source. Build output is reproducible via `npm run build`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Published tarball ships TypeScript sources, forcing jiti transpile on every host startup (~5s CPU)

1 participant