Skip to content

Commit 2b06180

Browse files
vincentkocRomneyDa
andauthored
fix(package): restore npm package size headroom (#129782)
* fix(package): externalize diffs build outputs * chore: remove release-owned changelog entry * fix(build): generate selected plugin assets before Docker staging --------- Co-authored-by: Dallin Romney <[email protected]>
1 parent a5f36ae commit 2b06180

10 files changed

Lines changed: 73 additions & 46 deletions

‎extensions/diffs-language-pack/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"build": "node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full"
2929
},
3030
"build": {
31+
"bundledDist": false,
3132
"openclawVersion": "2026.8.1",
3233
"staticAssets": [
3334
{

‎extensions/diffs/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"build": "node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated"
3535
},
3636
"build": {
37+
"bundledDist": false,
3738
"openclawVersion": "2026.8.1",
3839
"staticAssets": [
3940
{

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@
15171517
"audit:seams": "node --import tsx scripts/audit-seams.mts",
15181518
"build": "node --import tsx scripts/build-all.mts",
15191519
"build:ci-artifacts": "node --import tsx scripts/build-all.mts ciArtifacts",
1520-
"build:docker": "node --import tsx scripts/tsdown-build.mts && node --import tsx scripts/check-cli-bootstrap-imports.mts && node scripts/runtime-postbuild.mjs && node --import tsx scripts/build-stamp.mts && node --import tsx scripts/runtime-postbuild-stamp.mts && pnpm plugins:assets:build && pnpm plugins:assets:copy && node --import tsx scripts/write-build-info.ts && node --import tsx scripts/write-cli-startup-metadata.ts",
1520+
"build:docker": "pnpm plugins:assets:build && node --import tsx scripts/tsdown-build.mts && node --import tsx scripts/check-cli-bootstrap-imports.mts && node scripts/runtime-postbuild.mjs && node --import tsx scripts/build-stamp.mts && node --import tsx scripts/runtime-postbuild-stamp.mts && pnpm plugins:assets:copy && node --import tsx scripts/write-build-info.ts && node --import tsx scripts/write-cli-startup-metadata.ts",
15211521
"build:package": "node --import tsx scripts/build-all.mts package",
15221522
"build:plugin-sdk:dts": "node scripts/run-tsgo.mjs -p tsconfig.plugin-sdk.dts.json --declaration true",
15231523
"build:plugin-sdk:strict-smoke": "node --import tsx scripts/tsdown-build.mts && node scripts/runtime-postbuild.mjs && node --import tsx scripts/run-with-env.mts OPENCLAW_PLUGIN_SDK_CANONICAL_DTS=1 -- node --import tsx scripts/write-plugin-sdk-entry-dts.ts && node --import tsx scripts/check-plugin-sdk-exports.mts",

‎scripts/lib/bundled-plugin-build-entries-types.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type BundledPluginBuildEntryParams = {
1414

1515
export const NON_PACKAGED_BUNDLED_PLUGIN_DIRS: Set<string>;
1616
export const DOCKER_SELECTED_PLUGIN_BUILD_IDS_ENV: string;
17+
export function parseDockerSelectedPluginBuildIdFilter(env?: NodeJS.ProcessEnv): Set<string> | null;
1718
export function collectPluginSourceEntries(packageJson: unknown): string[];
1819
export function collectTopLevelPublicSurfaceEntries(pluginDir: string): string[];
1920
export function collectRootPackageExcludedExtensionDirs(

‎scripts/lib/bundled-plugin-build-entries.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function parseBundledPluginBuildIdFilter(env = process.env) {
3737
);
3838
}
3939

40-
function parseDockerSelectedPluginBuildIdFilter(env = process.env) {
40+
export function parseDockerSelectedPluginBuildIdFilter(env = process.env) {
4141
const raw = env[DOCKER_SELECTED_PLUGIN_BUILD_IDS_ENV];
4242
if (typeof raw !== "string" || raw.trim() === "") {
4343
return null;

‎scripts/lib/static-extension-assets.mts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { spawnSync } from "node:child_process";
33
import fs from "node:fs";
44
import path from "node:path";
5+
import { parseDockerSelectedPluginBuildIdFilter } from "./bundled-plugin-build-entries.mjs";
56
import { isRecord } from "./record-shared.mjs";
67

78
type StaticExtensionAsset = {
@@ -13,6 +14,7 @@ type StaticExtensionAsset = {
1314
type StaticExtensionAssetParams = {
1415
rootDir?: string;
1516
fs?: typeof fs;
17+
env?: NodeJS.ProcessEnv;
1618
includeExternalPlugins?: boolean;
1719
assets?: StaticExtensionAsset[];
1820
warn?: (message: string) => void;
@@ -164,6 +166,7 @@ export function discoverStaticExtensionAssets(params: StaticExtensionAssetParams
164166
const rootDir = params.rootDir ?? process.cwd();
165167
const fsImpl = params.fs ?? fs;
166168
const includeExternalPlugins = params.includeExternalPlugins ?? false;
169+
const dockerSelectedPluginIds = parseDockerSelectedPluginBuildIdFilter(params.env ?? process.env);
167170
const assets: StaticExtensionAsset[] = [];
168171
for (const { dirName, hasPackageJson, packageJsonPath } of listExtensionPackageDirs(
169172
rootDir,
@@ -173,7 +176,11 @@ export function discoverStaticExtensionAssets(params: StaticExtensionAssetParams
173176
continue;
174177
}
175178
const packageJson = readJsonFile(packageJsonPath, fsImpl);
176-
if (!includeExternalPlugins && isExternalDistPackage(packageJson)) {
179+
if (
180+
!includeExternalPlugins &&
181+
isExternalDistPackage(packageJson) &&
182+
!dockerSelectedPluginIds?.has(dirName)
183+
) {
177184
continue;
178185
}
179186
for (const entry of readPackageStaticAssetEntries(packageJson)) {
@@ -196,7 +203,8 @@ function discoverStaticExtensionRuntimeOverlayAssets(params: StaticExtensionAsse
196203
const rootDir = params.rootDir ?? process.cwd();
197204
const fsImpl = params.fs ?? fs;
198205
const assetsByDest = new Map<string, StaticExtensionAsset>();
199-
for (const asset of params.assets ?? discoverStaticExtensionAssets({ rootDir, fs: fsImpl })) {
206+
for (const asset of params.assets ??
207+
discoverStaticExtensionAssets({ rootDir, fs: fsImpl, env: params.env })) {
200208
assetsByDest.set(asset.dest, asset);
201209
}
202210
for (const { dirName, packageDir } of listDistExtensionPackageDirs(rootDir, fsImpl)) {
@@ -278,7 +286,8 @@ export function listGeneratedExtensionAssetSources(params: StaticExtensionAssetP
278286
export function copyStaticExtensionAssets(params: StaticExtensionAssetParams = {}) {
279287
const rootDir = params.rootDir ?? process.cwd();
280288
const fsImpl = params.fs ?? fs;
281-
const assets = params.assets ?? discoverStaticExtensionAssets({ rootDir, fs: fsImpl });
289+
const assets =
290+
params.assets ?? discoverStaticExtensionAssets({ rootDir, fs: fsImpl, env: params.env });
282291
const warn = params.warn ?? console.warn;
283292
for (const { src, dest } of assets) {
284293
const srcPath = path.join(rootDir, src);
@@ -332,7 +341,12 @@ export function copyStaticExtensionAssetsForPackage(
332341
const fsImpl = params.fs ?? fs;
333342
const assets =
334343
params.assets ??
335-
discoverStaticExtensionAssets({ rootDir, fs: fsImpl, includeExternalPlugins: true });
344+
discoverStaticExtensionAssets({
345+
rootDir,
346+
fs: fsImpl,
347+
env: params.env,
348+
includeExternalPlugins: true,
349+
});
336350
const packagePrefix = `extensions/${params.pluginDir}/`;
337351
const rootDistPrefix = `dist/extensions/${params.pluginDir}/`;
338352
const copied: string[] = [];

‎test/package-scripts.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ describe("package scripts", () => {
182182
);
183183
});
184184

185+
it("builds generated plugin assets before Docker runtime postbuild", () => {
186+
const commands = expectDefined(
187+
readPackageJson().scripts["build:docker"],
188+
"package script build:docker",
189+
).split(" && ");
190+
191+
expect(commands.indexOf("pnpm plugins:assets:build")).toBeLessThan(
192+
commands.indexOf("node scripts/runtime-postbuild.mjs"),
193+
);
194+
});
195+
185196
it("cleans package builds before validating release contents", () => {
186197
const scripts = readPackageJson().scripts;
187198

‎test/scripts/build-external-plugin-local-dist.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ describe("external plugin local dist build", () => {
1313
const packageDirs = listExternalPluginLocalDistPackageDirs();
1414
const excludedPluginIds = collectRootPackageExcludedExtensionDirs();
1515

16-
expect(packageDirs).toHaveLength(61);
16+
expect(packageDirs).toHaveLength(63);
1717
expect(packageDirs).toEqual(
18-
expect.arrayContaining(["extensions/slack", "extensions/sms", "extensions/mxc"]),
18+
expect.arrayContaining([
19+
"extensions/diffs",
20+
"extensions/diffs-language-pack",
21+
"extensions/slack",
22+
"extensions/sms",
23+
"extensions/mxc",
24+
]),
1925
);
2026
expect(packageDirs).not.toContain("extensions/whatsapp");
2127
expect(

‎test/scripts/bundled-plugin-build-entries.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,14 @@ describe("bundled plugin build entries", () => {
196196
const entries = listBundledPluginBuildEntries();
197197
const artifacts = listBundledPluginPackArtifacts();
198198

199-
for (const pluginId of ["copilot", "openshell", "slack", "tokenjuice"]) {
199+
for (const pluginId of [
200+
"copilot",
201+
"diffs",
202+
"diffs-language-pack",
203+
"openshell",
204+
"slack",
205+
"tokenjuice",
206+
]) {
200207
expectNoPrefixMatches(Object.keys(entries), `extensions/${pluginId}/`);
201208
expectNoPrefixMatches(artifacts, `dist/extensions/${pluginId}/`);
202209
}

‎test/scripts/runtime-postbuild.test.ts‎

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,17 @@ describe("runtime postbuild static assets", () => {
108108
"dist/extensions/acpx/mcp-command-line.mjs",
109109
"dist/extensions/acpx/mcp-proxy.mjs",
110110
"dist/extensions/crabbox/assets/openclaw-worker-wallpaper.png",
111-
"dist/extensions/diffs-language-pack/assets/viewer-runtime.js",
112-
"dist/extensions/diffs/assets/viewer-runtime.js",
113111
"dist/extensions/discord/assets/embedded-app-sdk.mjs",
114112
"dist/extensions/onepassword/onepassword-op-path.js",
115113
"dist/extensions/onepassword/onepassword-secret-id.js",
116114
"dist/extensions/onepassword/onepassword-secret-ref-resolver.js",
117115
"dist/extensions/vault/vault-secret-id.js",
118116
"dist/extensions/vault/vault-secret-ref-resolver.js",
119117
]);
120-
expect(payload.sources).toContain("extensions/diffs-language-pack/assets/viewer-runtime.js");
121-
expect(payload.sources).toContain("extensions/diffs/assets/viewer-runtime.js");
118+
expect(payload.sources).not.toContain(
119+
"extensions/diffs-language-pack/assets/viewer-runtime.js",
120+
);
121+
expect(payload.sources).not.toContain("extensions/diffs/assets/viewer-runtime.js");
122122
expect(payload.sources).toContain("extensions/discord/assets/embedded-app-sdk.mjs");
123123
expect(payload.sources).toContain("extensions/crabbox/assets/openclaw-worker-wallpaper.png");
124124
});
@@ -177,7 +177,15 @@ describe("runtime postbuild static assets", () => {
177177
expect(discoverStaticExtensionAssets({ rootDir })).toEqual([]);
178178
});
179179

180-
it("excludes external plugin (bundledDist: false) static assets by default", async () => {
180+
it.each([
181+
{ name: "normal root build", params: {}, included: false },
182+
{ name: "isolated external build", params: { includeExternalPlugins: true }, included: true },
183+
{
184+
name: "Docker-selected build",
185+
params: { env: { OPENCLAW_INTERNAL_DOCKER_BUILD_PLUGIN_IDS: "external-demo" } },
186+
included: true,
187+
},
188+
])("$name handles external plugin assets", async ({ params, included }) => {
181189
const rootDir = createTempDir("openclaw-runtime-postbuild-");
182190
const packageDir = path.join(rootDir, "extensions", "external-demo");
183191
await fs.mkdir(packageDir, { recursive: true });
@@ -200,39 +208,17 @@ describe("runtime postbuild static assets", () => {
200208
"utf8",
201209
);
202210

203-
expect(discoverStaticExtensionAssets({ rootDir })).toEqual([]);
204-
});
205-
206-
it("includes external plugin (bundledDist: false) static assets when includeExternalPlugins is true", async () => {
207-
const rootDir = createTempDir("openclaw-runtime-postbuild-");
208-
const packageDir = path.join(rootDir, "extensions", "external-demo");
209-
await fs.mkdir(packageDir, { recursive: true });
210-
await fs.writeFile(
211-
path.join(packageDir, "package.json"),
212-
JSON.stringify({
213-
name: "@openclaw/external-demo",
214-
openclaw: {
215-
build: {
216-
bundledDist: false,
217-
staticAssets: [
218-
{
219-
source: "./assets/runtime.js",
220-
output: "assets/runtime.js",
221-
},
222-
],
223-
},
224-
},
225-
}),
226-
"utf8",
211+
expect(discoverStaticExtensionAssets({ rootDir, ...params })).toEqual(
212+
included
213+
? [
214+
{
215+
pluginDir: "external-demo",
216+
src: "extensions/external-demo/assets/runtime.js",
217+
dest: "dist/extensions/external-demo/assets/runtime.js",
218+
},
219+
]
220+
: [],
227221
);
228-
229-
expect(discoverStaticExtensionAssets({ rootDir, includeExternalPlugins: true })).toEqual([
230-
{
231-
pluginDir: "external-demo",
232-
src: "extensions/external-demo/assets/runtime.js",
233-
dest: "dist/extensions/external-demo/assets/runtime.js",
234-
},
235-
]);
236222
});
237223

238224
it("copies declared static assets into root and package dist", async () => {

0 commit comments

Comments
 (0)