Skip to content

Commit 5a5acff

Browse files
zsh77dimitropoulosanthonyshew
authored
fix(examples): bug in design system example (#9284)
### Description - add `preview-storybook` task to turbo.json and it's script in the root's package.json - improvement on clean script - changed the tsup config of `@acme/ui` package not to make source map files in order to match the content of `ui/dist` directory stated in README of root - bug fix of README file. Replaced `acme-core` and other names that meant to point to packages/ui with `@acme/ui` ### Testing Instructions Running `npx create-turbo@latest -e design-system` and then `pnpm dev` should work and start storybook in dev mode. README.md file in the root should be fine too. --------- Co-authored-by: Dimitri Mitropoulos <[email protected]> Co-authored-by: Anthony Shew <[email protected]>
1 parent c0a1dbb commit 5a5acff

File tree

7 files changed

+56
-34
lines changed

7 files changed

+56
-34
lines changed

examples/design-system/.changeset/config.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
"linked": [],
77
"access": "public",
88
"updateInternalDependencies": "patch",
9-
"ignore": ["@acme/docs"]
10-
}
9+
"ignore": [
10+
"@repo/docs"
11+
]
12+
}

examples/design-system/README.md

+38-24
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ This Turborepo includes the following packages and applications:
4545

4646
- `apps/docs`: Component documentation site with Storybook
4747
- `packages/ui`: Core React components
48-
- `packages/utils`: Shared React utilities
4948
- `packages/typescript-config`: Shared `tsconfig.json`s used throughout the Turborepo
5049
- `packages/eslint-config`: ESLint preset
5150

@@ -55,44 +54,49 @@ This example sets up your `.gitignore` to exclude all generated files, other fol
5554

5655
### Compilation
5756

58-
To make the core library code work across all browsers, we need to compile the raw TypeScript and React code to plain JavaScript. We can accomplish this with `tsup`, which uses `esbuild` to greatly improve performance.
57+
To make the ui library code work across all browsers, we need to compile the raw TypeScript and React code to plain JavaScript. We can accomplish this with `tsup`, which uses `esbuild` to greatly improve performance.
5958

6059
Running `pnpm build` from the root of the Turborepo will run the `build` command defined in each package's `package.json` file. Turborepo runs each `build` in parallel and caches & hashes the output to speed up future builds.
6160

62-
For `acme-core`, the `build` command is the following:
61+
For `@acme/ui`, the `build` command is equivalent to the following:
6362

6463
```bash
65-
tsup src/index.tsx --format esm,cjs --dts --external react
64+
tsup src/*.tsx --format esm,cjs --dts --external react
6665
```
6766

68-
`tsup` compiles `src/index.tsx`, which exports all of the components in the design system, into both ES Modules and CommonJS formats as well as their TypeScript types. The `package.json` for `acme-core` then instructs the consumer to select the correct format:
67+
`tsup` compiles all of the components in the design system individually, into both ES Modules and CommonJS formats as well as their TypeScript types. The `package.json` for `@acme/ui` then instructs the consumer to select the correct format:
6968

70-
```json:acme-core/package.json
69+
```json:ui/package.json
7170
{
72-
"name": "@acme/core",
71+
"name": "@acme/ui",
7372
"version": "0.0.0",
74-
"main": "./dist/index.js",
75-
"module": "./dist/index.mjs",
76-
"types": "./dist/index.d.ts",
7773
"sideEffects": false,
74+
"exports":{
75+
"./button": {
76+
"types": "./src/button.tsx",
77+
"import": "./dist/button.mjs",
78+
"require": "./dist/button.js"
79+
}
80+
}
7881
}
7982
```
8083

81-
Run `pnpm build` to confirm compilation is working correctly. You should see a folder `acme-core/dist` which contains the compiled output.
84+
Run `pnpm build` to confirm compilation is working correctly. You should see a folder `ui/dist` which contains the compiled output.
8285

8386
```bash
84-
acme-core
87+
ui
8588
└── dist
86-
├── index.d.ts <-- Types
87-
├── index.js <-- CommonJS version
88-
└── index.mjs <-- ES Modules version
89+
├── button.d.ts <-- Types
90+
├── button.js <-- CommonJS version
91+
├── button.mjs <-- ES Modules version
92+
└── button.d.mts <-- ES Modules version with Types
8993
```
9094

9195
## Components
9296

93-
Each file inside of `acme-core/src` is a component inside our design system. For example:
97+
Each file inside of `ui/src` is a component inside our design system. For example:
9498

95-
```tsx:acme-core/src/Button.tsx
99+
```tsx:ui/src/Button.tsx
96100
import * as React from 'react';
97101

98102
export interface ButtonProps {
@@ -106,12 +110,22 @@ export function Button(props: ButtonProps) {
106110
Button.displayName = 'Button';
107111
```
108112

109-
When adding a new file, ensure the component is also exported from the entry `index.tsx` file:
113+
When adding a new file, ensure that its specifier is defined in `package.json` file:
110114

111-
```tsx:acme-core/src/index.tsx
112-
import * as React from "react";
113-
export { Button, type ButtonProps } from "./Button";
114-
// Add new component exports here
115+
```json:ui/package.json
116+
{
117+
"name": "@acme/ui",
118+
"version": "0.0.0",
119+
"sideEffects": false,
120+
"exports":{
121+
"./button": {
122+
"types": "./src/button.tsx",
123+
"import": "./dist/button.mjs",
124+
"require": "./dist/button.js"
125+
}
126+
// Add new component exports here
127+
}
128+
}
115129
```
116130

117131
## Storybook
@@ -120,13 +134,13 @@ Storybook provides us with an interactive UI playground for our components. This
120134

121135
- Use Vite to bundle stories instantly (in milliseconds)
122136
- Automatically find any stories inside the `stories/` folder
123-
- Support using module path aliases like `@acme-core` for imports
137+
- Support using module path aliases like `@acme/ui` for imports
124138
- Write MDX for component documentation pages
125139

126140
For example, here's the included Story for our `Button` component:
127141

128142
```js:apps/docs/stories/button.stories.mdx
129-
import { Button } from '@acme-core/src';
143+
import { Button } from '@acme/ui/button';
130144
import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks';
131145

132146
<Meta title="Components/Button" component={Button} />

examples/design-system/apps/docs/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dev": "storybook dev -p 6006",
88
"build": "storybook build --docs",
99
"preview-storybook": "serve storybook-static",
10-
"clean": "rm -rf .turbo && rm -rf node_modules",
10+
"clean": "rm -rf .turbo node_modules",
1111
"lint": "eslint ./stories/*.stories.tsx --max-warnings 0"
1212
},
1313
"dependencies": {
@@ -30,4 +30,4 @@
3030
"typescript": "5.5.4",
3131
"vite": "^5.1.4"
3232
}
33-
}
33+
}

examples/design-system/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
99
"changeset": "changeset",
1010
"version-packages": "changeset version",
11-
"release": "turbo run build --filter=docs^... && changeset publish"
11+
"release": "turbo run build --filter=docs^... && changeset publish",
12+
"preview-storybook": "turbo preview-storybook"
1213
},
1314
"devDependencies": {
1415
"@changesets/cli": "^2.27.1",
@@ -17,4 +18,4 @@
1718
},
1819
"packageManager": "[email protected]",
1920
"name": "design-system"
20-
}
21+
}

examples/design-system/packages/ui/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"build": "tsup",
1515
"dev": "tsup --watch",
1616
"lint": "eslint . --max-warnings 0",
17-
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
17+
"clean": "rm -rf .turbo node_modules dist"
1818
},
1919
"devDependencies": {
2020
"@repo/eslint-config": "workspace:*",
@@ -31,4 +31,4 @@
3131
"publishConfig": {
3232
"access": "public"
3333
}
34-
}
34+
}

examples/design-system/packages/ui/tsup.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export default defineConfig((options) => ({
44
entryPoints: ["src/button.tsx"],
55
format: ["cjs", "esm"],
66
dts: true,
7-
sourcemap: true,
87
external: ["react"],
98
...options,
109
}));

examples/design-system/turbo.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
},
1616
"clean": {
1717
"cache": false
18+
},
19+
"preview-storybook": {
20+
"dependsOn": [
21+
"^build"
22+
],
23+
"cache": false
1824
}
1925
}
20-
}
26+
}

0 commit comments

Comments
 (0)