Skip to content

Commit 71f56ea

Browse files
authored
refactor: bundle webstudio packages in cli (#4706)
Having all webstudio packages as dependency in CLI leads to very long and bloated install. Before <img width="762" alt="Screenshot 2025-01-03 at 19 49 31" src="https://github.com/user-attachments/assets/96624dae-c72a-4407-83ea-e56ed5d3f7d8" /> After <img width="385" alt="Screenshot 2025-01-03 at 20 00 17" src="https://github.com/user-attachments/assets/f3271c6e-07ca-47f6-9dfb-491ca68e7caf" /> after/before <img width="633" alt="Screenshot 2025-01-03 at 19 58 15" src="https://github.com/user-attachments/assets/8273072a-c71e-485c-aa39-116c9698bc8f" />
1 parent 2a7304e commit 71f56ea

20 files changed

+151
-84
lines changed

apps/builder/app/builder/features/settings-panel/shared.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -400,5 +400,8 @@ export const humanizeAttribute = (string: string) => {
400400
if (string === "className") {
401401
return "Class";
402402
}
403+
if (string === "htmlFor") {
404+
return "For";
405+
}
403406
return humanizeString(string);
404407
};

packages/cli/package.json

+15-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
],
2424
"scripts": {
2525
"typecheck": "tsc",
26-
"build": "rm -rf lib && esbuild src/cli.ts --outdir=lib --bundle --format=esm --packages=external",
26+
"build": "rm -rf lib && vite build",
2727
"test": "vitest run"
2828
},
2929
"license": "AGPL-3.0-or-later",
@@ -32,21 +32,20 @@
3232
},
3333
"dependencies": {
3434
"@clack/prompts": "^0.7.0",
35-
"@webstudio-is/http-client": "workspace:*",
36-
"@webstudio-is/image": "workspace:*",
37-
"@webstudio-is/react-sdk": "workspace:*",
38-
"@webstudio-is/sdk": "workspace:*",
39-
"@webstudio-is/sdk-components-react": "workspace:*",
40-
"@webstudio-is/sdk-components-react-radix": "workspace:*",
41-
"@webstudio-is/sdk-components-react-remix": "workspace:*",
35+
"@emotion/hash": "^0.9.2",
36+
"acorn": "^8.14.0",
37+
"acorn-walk": "^8.3.4",
4238
"change-case": "^5.4.4",
4339
"deepmerge": "^4.3.1",
4440
"env-paths": "^3.0.0",
41+
"nanoid": "^5.0.8",
4542
"p-limit": "^4.0.0",
4643
"parse5": "7.1.2",
4744
"picocolors": "^1.1.0",
48-
"strip-indent": "^4.0.0",
45+
"react": "18.3.0-canary-14898b6a9-20240318",
46+
"reserved-identifiers": "^1.0.0",
4947
"tinyexec": "^0.3.1",
48+
"warn-once": "^0.1.1",
5049
"yargs": "^17.7.2",
5150
"zod": "^3.22.4"
5251
},
@@ -63,9 +62,15 @@
6362
"@types/react-dom": "^18.2.25",
6463
"@types/yargs": "^17.0.33",
6564
"@vitejs/plugin-react": "^4.3.4",
65+
"@webstudio-is/http-client": "workspace:*",
66+
"@webstudio-is/image": "workspace:*",
67+
"@webstudio-is/react-sdk": "workspace:*",
68+
"@webstudio-is/sdk": "workspace:*",
69+
"@webstudio-is/sdk-components-react": "workspace:*",
70+
"@webstudio-is/sdk-components-react-radix": "workspace:*",
71+
"@webstudio-is/sdk-components-react-remix": "workspace:*",
6672
"@webstudio-is/tsconfig": "workspace:*",
6773
"prettier": "3.4.2",
68-
"react": "18.3.0-canary-14898b6a9-20240318",
6974
"react-dom": "18.3.0-canary-14898b6a9-20240318",
7075
"ts-expect": "^1.3.0",
7176
"vike": "^0.4.210",

packages/cli/vite.config.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { defineConfig } from "vite";
2+
import pkg from "./package.json";
3+
4+
const isExternal = (id: string, importer: string | undefined) => {
5+
if (id.startsWith("@webstudio-is/")) {
6+
return false;
7+
}
8+
if (id.startsWith("node:")) {
9+
return true;
10+
}
11+
if (id.startsWith("@")) {
12+
const packageName = id.split("/").slice(0, 2).join("/");
13+
if (packageName in pkg.dependencies === false) {
14+
throw Error(
15+
`${packageName} imported from ${importer} is not found in direct dependencies`
16+
);
17+
}
18+
return true;
19+
}
20+
if (id.includes(".") === false) {
21+
const [packageName] = id.split("/");
22+
if (packageName in pkg.dependencies === false) {
23+
throw Error(
24+
`${packageName} imported from ${importer} is not found in direct dependencies`
25+
);
26+
}
27+
return true;
28+
}
29+
return false;
30+
};
31+
32+
export default defineConfig({
33+
// resolve only webstudio condition in tests
34+
resolve: {
35+
conditions: ["webstudio"],
36+
},
37+
build: {
38+
minify: false,
39+
lib: {
40+
entry: ["src/cli.ts"],
41+
formats: ["es"],
42+
},
43+
rollupOptions: {
44+
external: isExternal,
45+
output: {
46+
dir: "lib",
47+
},
48+
},
49+
},
50+
});

packages/image/src/image.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const defaultTag = "img";
99

1010
type ImageProps = ComponentProps<typeof defaultTag> & {
1111
quality?: number;
12+
/** Optimize the image for enhanced performance. */
1213
optimize?: boolean;
1314
loader: ImageLoader;
1415
};

packages/sdk-components-react-radix/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"scripts": {
4343
"build": "vite build --config ../../vite.sdk-components.config.ts",
44-
"build:args": "NODE_OPTIONS=--conditions=webstudio generate-arg-types './src/*.tsx !./src/*.stories.tsx !./src/*.ws.ts !./src/*.test.{ts,tsx}' -e asChild -e modal -e defaultOpen -e defaultChecked && prettier --write \"**/*.props.ts\"",
44+
"build:args": "NODE_OPTIONS=--conditions=webstudio generate-arg-types './src/*.tsx !./src/*.stories.tsx !./src/*.ws.ts !./src/*.template.tsx !./src/*.test.{ts,tsx}' -e asChild -e modal -e defaultOpen -e defaultChecked && prettier --write \"**/*.props.ts\"",
4545
"build:stories": "webstudio-sdk generate-stories && prettier --write \"src/__generated__/*.stories.tsx\"",
4646
"dts": "tsc --project tsconfig.dts.json",
4747
"typecheck": "tsc"

packages/sdk-components-react-radix/src/__generated__/select.props.ts

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sdk-components-react-radix/src/__generated__/tabs.props.ts

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sdk-components-react-radix/src/label.ws.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ export const meta: WsComponentMeta = {
2020
};
2121

2222
export const propsMeta: WsComponentPropsMeta = {
23-
props: {
24-
...props,
25-
htmlFor: {
26-
...props.htmlFor,
27-
label: "For",
28-
},
29-
},
23+
props,
3024
initialProps: ["id", "className", "htmlFor"],
3125
};

packages/sdk-components-react-radix/src/navigation-menu.template.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const components = [
7676
];
7777

7878
const createMenuContentItem = (props: (typeof components)[number]) => (
79-
<radix.NavigationMenuLink>
79+
<radix.NavigationMenuLink key={props.title}>
8080
<$.Link
8181
href={`https://ui.shadcn.com${props.href}`}
8282
// block select-none space-y-1 rounded-md p-3 leading-none

packages/sdk-components-react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"scripts": {
4343
"build": "vite build --config ../../vite.sdk-components.config.ts",
44-
"build:args": "NODE_OPTIONS=--conditions=webstudio generate-arg-types './src/*.tsx !./src/*.stories.tsx !./src/*.test.{ts,tsx} !./src/*.ws.ts' && prettier --write \"**/*.props.ts\"",
44+
"build:args": "NODE_OPTIONS=--conditions=webstudio generate-arg-types './src/*.tsx !./src/*.stories.tsx !./src/*.test.{ts,tsx} !./src/*.ws.ts !./src/*.ws.ts !./src/*.template.tsx' && prettier --write \"**/*.props.ts\"",
4545
"dts": "tsc --project tsconfig.dts.json",
4646
"test": "vitest run",
4747
"typecheck": "tsc"

packages/sdk-components-react/src/__generated__/image.props.ts

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sdk-components-react/src/__generated__/vimeo-preview-image.props.ts

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sdk-components-react/src/__generated__/vimeo.props.ts

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sdk-components-react/src/image.ws.ts

+7-15
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,16 @@ export const meta: WsComponentMeta = {
4545
order: 0,
4646
};
4747

48-
// Automatically generated props don't have the right control.
49-
export const propsOverrides = {
50-
src: {
51-
type: "string",
52-
control: "file",
53-
label: "Source",
54-
required: false,
55-
},
56-
} as const;
57-
58-
const optimize = props.optimize;
59-
optimize.description = "Optimize the image for enhanced performance.";
60-
6148
export const propsMeta: WsComponentPropsMeta = {
6249
props: {
6350
...props,
64-
...propsOverrides,
65-
optimize,
51+
// Automatically generated props don't have the right control.
52+
src: {
53+
type: "string",
54+
control: "file",
55+
label: "Source",
56+
required: false,
57+
},
6658
},
6759
initialProps: [
6860
"id",

packages/sdk-components-react/src/label.ws.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ export const meta: WsComponentMeta = {
2929
};
3030

3131
export const propsMeta: WsComponentPropsMeta = {
32-
props: {
33-
...props,
34-
htmlFor: {
35-
...props.htmlFor,
36-
label: "For",
37-
},
38-
},
32+
props,
3933
initialProps: ["id", "className", "htmlFor"],
4034
};

packages/sdk-components-react/src/vimeo-play-button.ws.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { props } from "./__generated__/vimeo-play-button.props";
88
import { ButtonElementIcon } from "@webstudio-is/icons/svg";
99
import { button } from "@webstudio-is/sdk/normalize.css";
10-
import { defaultTag } from "./vimeo-play-button";
10+
import type { defaultTag } from "./vimeo-play-button";
1111

1212
const presetStyle = {
1313
button,

packages/sdk-components-react/src/vimeo-preview-image.ws.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import {
22
type WsComponentMeta,
33
type WsComponentPropsMeta,
44
} from "@webstudio-is/react-sdk";
5-
import {
6-
propsOverrides as imagePropsOverrides,
7-
propsMeta as imagePropsMeta,
8-
meta as imageMeta,
9-
} from "./image.ws";
5+
import { propsMeta as imagePropsMeta, meta as imageMeta } from "./image.ws";
106
import { props } from "./__generated__/vimeo-preview-image.props";
117

128
export const meta: WsComponentMeta = {
@@ -20,6 +16,15 @@ export const meta: WsComponentMeta = {
2016
};
2117

2218
export const propsMeta: WsComponentPropsMeta = {
23-
props: { ...props, ...imagePropsOverrides },
19+
props: {
20+
...props,
21+
// Automatically generated props don't have the right control.
22+
src: {
23+
type: "string",
24+
control: "file",
25+
label: "Source",
26+
required: false,
27+
},
28+
},
2429
initialProps: imagePropsMeta.initialProps,
2530
};

packages/sdk-components-react/src/vimeo.ws.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from "@webstudio-is/react-sdk";
99
import { div } from "@webstudio-is/sdk/normalize.css";
1010
import { props } from "./__generated__/vimeo.props";
11-
import { Vimeo } from "./vimeo";
11+
import type { Vimeo } from "./vimeo";
1212

1313
const presetStyle = {
1414
div,

packages/sdk/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
"@webstudio-is/template": "workspace:*",
5050
"@webstudio-is/tsconfig": "workspace:*",
5151
"html-tags": "^4.0.0",
52-
"strip-indent": "^4.0.0",
5352
"vitest": "^2.1.8"
5453
}
5554
}

0 commit comments

Comments
 (0)