storybook-addon-dependency-previews 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -7
- package/dist/cli/sb-deps.cjs +1124 -297
- package/dist/cli/sb-deps.cjs.map +1 -1
- package/dist/cli/sb-deps.mjs +1125 -298
- package/dist/cli/sb-deps.mjs.map +1 -1
- package/dist/cli/scripts/fileNames.cjs +122 -0
- package/dist/cli/scripts/fileNames.cjs.map +1 -0
- package/dist/cli/scripts/fileNames.mjs +118 -0
- package/dist/cli/scripts/fileNames.mjs.map +1 -0
- package/dist/cli/scripts/postprocess.cjs +70 -20
- package/dist/cli/scripts/postprocess.cjs.map +1 -1
- package/dist/cli/scripts/postprocess.mjs +70 -20
- package/dist/cli/scripts/postprocess.mjs.map +1 -1
- package/dist/cli/setup/detect.cjs +8 -2
- package/dist/cli/setup/detect.cjs.map +1 -1
- package/dist/cli/setup/detect.d.cts +10 -3
- package/dist/cli/setup/detect.d.mts +10 -3
- package/dist/cli/setup/detect.mjs +8 -2
- package/dist/cli/setup/detect.mjs.map +1 -1
- package/dist/cli/setup/index.cjs +32 -1
- package/dist/cli/setup/index.cjs.map +1 -1
- package/dist/cli/setup/index.mjs +32 -1
- package/dist/cli/setup/index.mjs.map +1 -1
- package/dist/cli/setup/patchers/preview.cjs +2 -1
- package/dist/cli/setup/patchers/preview.cjs.map +1 -1
- package/dist/cli/setup/patchers/preview.mjs +2 -1
- package/dist/cli/setup/patchers/preview.mjs.map +1 -1
- package/dist/cli/setup/patchers/sbDepsConfig.cjs +14 -6
- package/dist/cli/setup/patchers/sbDepsConfig.cjs.map +1 -1
- package/dist/cli/setup/patchers/sbDepsConfig.mjs +14 -6
- package/dist/cli/setup/patchers/sbDepsConfig.mjs.map +1 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +72 -1
- package/dist/config.d.mts +72 -1
- package/dist/config.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
A plugin for [Storybook](https://storybook.js.org/) that shows the full dependency tree in both directions (built with and used by) the components in your application.
|
|
10
10
|
|
|
11
|
-
Currently works with **React**, **Svelte**, **Vue 3**, **Angular**, and **Next.js**. The automated `sb-deps setup` wizard handles Vite-based projects (React, Svelte, Vue 3) end-to-end. Webpack-based projects (Angular, Next.js) need a one-time manual setup — see the [manual-setup-webpack guide](https://github.com/Dan503/storybook-addon-dependency-previews/blob/main/storybook-addon-package/docs/manual-setup-webpack.md) below.
|
|
11
|
+
Currently works with **React**, **Svelte**, **Vue 3**, **Solid**, **Angular**, and **Next.js**. The automated `sb-deps setup` wizard handles Vite-based projects (React, Svelte, Vue 3, Solid) end-to-end. Webpack-based projects (Angular, Next.js) need a one-time manual setup — see the [manual-setup-webpack guide](https://github.com/Dan503/storybook-addon-dependency-previews/blob/main/storybook-addon-package/docs/manual-setup-webpack.md) below.
|
|
12
12
|
|
|
13
13
|
This is what you will see in Storybook after Dependency Previews have been installed and configured:
|
|
14
14
|
|
|
@@ -40,6 +40,12 @@ Vue version built for Vue 3.
|
|
|
40
40
|
- [Vue rendered example website](https://dependency-previews-demo-site-vue.netlify.app/)
|
|
41
41
|
- [Vue demo source code](https://github.com/Dan503/storybook-addon-dependency-previews/tree/main/example-site/vue)
|
|
42
42
|
|
|
43
|
+
#### Solid demos
|
|
44
|
+
|
|
45
|
+
- [Solid Storybook demo site](https://dependency-previews-storybook-solid.netlify.app/?path=/docs/04-templates-home-template--docs)
|
|
46
|
+
- [Solid rendered example website](https://dependency-previews-demo-site-solid.netlify.app/)
|
|
47
|
+
- [Solid demo source code](https://github.com/Dan503/storybook-addon-dependency-previews/tree/main/example-site/solid)
|
|
48
|
+
|
|
43
49
|
#### Angular demos
|
|
44
50
|
|
|
45
51
|
- [Angular Storybook demo site](https://dependency-previews-storybook-angular.netlify.app/?path=/docs/04-templates-home-template--docs)
|
|
@@ -50,7 +56,7 @@ Vue version built for Vue 3.
|
|
|
50
56
|
|
|
51
57
|
## Installation guide
|
|
52
58
|
|
|
53
|
-
### Quick start (React, Svelte,
|
|
59
|
+
### Quick start (React, Svelte, Vue 3, and Solid)
|
|
54
60
|
|
|
55
61
|
After running `npx storybook@latest init` in your project, run the setup wizard:
|
|
56
62
|
|
|
@@ -92,9 +98,9 @@ When it finishes, run `npm run sb` (or your package manager's equivalent) to sta
|
|
|
92
98
|
|
|
93
99
|
### Manual setup
|
|
94
100
|
|
|
95
|
-
The wizard supports React (`@storybook/react-vite`), Svelte (`@storybook/sveltekit`, `@storybook/svelte-vite`),
|
|
101
|
+
The wizard supports React (`@storybook/react-vite`), Svelte (`@storybook/sveltekit`, `@storybook/svelte-vite`), Vue 3 (`@storybook/vue3-vite`), and Solid (`storybook-solidjs-vite`) — all Vite-based. **Angular (`@storybook/angular`) and Next.js (`@storybook/nextjs`) projects are both webpack-based and require manual setup** — the wizard's preview-patcher relies on Vite's `import.meta.glob`, which webpack doesn't expose. Follow the matching guide below:
|
|
96
102
|
|
|
97
|
-
- [Manual setup — Vite (React, Svelte, Vue 3)](https://github.com/Dan503/storybook-addon-dependency-previews/blob/main/storybook-addon-package/docs/manual-setup-vite.md)
|
|
103
|
+
- [Manual setup — Vite (React, Svelte, Vue 3, Solid)](https://github.com/Dan503/storybook-addon-dependency-previews/blob/main/storybook-addon-package/docs/manual-setup-vite.md)
|
|
98
104
|
- [Manual setup — webpack (`@storybook/angular`, `@storybook/nextjs`)](https://github.com/Dan503/storybook-addon-dependency-previews/blob/main/storybook-addon-package/docs/manual-setup-webpack.md)
|
|
99
105
|
|
|
100
106
|
## Auto-scaffolding new components and stories
|
|
@@ -104,7 +110,64 @@ While `sb-deps` is watching (`npm run sb`), creating an **empty** source file fi
|
|
|
104
110
|
- **Create a component file** (`Button.tsx`, `Button.svelte`, `Button.vue`, `Button.component.ts`) → the component body is scaffolded **and** a matching story file is generated next to it.
|
|
105
111
|
- **Create a story file** (`Button.stories.tsx`, or the singular `Button.story.tsx`) → the story is scaffolded into that exact file, and if the sibling component doesn't exist yet it is created and scaffolded too.
|
|
106
112
|
|
|
107
|
-
Either way you end up with a working component + story pair. Only empty files are touched, so existing files are never overwritten. A `.stories.ts` with no component beside it is resolved to React, Vue, or Angular from your project's framework (Svelte stories use a `.svelte` file, so `.ts` isn't scaffolded for Svelte).
|
|
113
|
+
Either way you end up with a working component + story pair. Only empty files are touched, so existing files are never overwritten. A `.stories.ts` with no component beside it is resolved to React, Solid, Vue, or Angular from your project's framework (Svelte stories use a `.svelte` file, so `.ts` isn't scaffolded for Svelte).
|
|
114
|
+
|
|
115
|
+
React and Solid both author components in `.tsx`, so the extension alone can't tell them apart. `sb-deps` works it out from your project, so a Solid project gets Solid templates (`solid-js`, `storybook-solidjs-vite`) without being told; anything it does not read as Solid gets React ones. Set `tsxFramework: 'solid'` in your `sb-deps` config to say so outright — worth doing where your project's framework isn't obvious from its files.
|
|
116
|
+
|
|
117
|
+
### What the scaffolded components assume
|
|
118
|
+
|
|
119
|
+
Each generated component is written the way its framework currently recommends, which means some of them assume a fairly recent version of it:
|
|
120
|
+
|
|
121
|
+
- **Vue 3.5+** — the component gives a prop its default value inside the `defineProps` destructure. Vue only keeps a destructured prop reactive from 3.5, so on an earlier version the component stops updating when a parent changes that prop. The starting value still shows.
|
|
122
|
+
- **Svelte 5** — `$props()`, `$state()` and the `Snippet` type.
|
|
123
|
+
- **Angular 17.1+** — `input()` signals.
|
|
124
|
+
|
|
125
|
+
React and Solid add no version floor beyond what the addon itself needs. In a **Next.js** project the React component is written with a `'use client'` line at the top, because it holds state and the App Router renders on the server; you will not see that line in any other React project.
|
|
126
|
+
|
|
127
|
+
None of this affects the dependency graph or anything else `sb-deps` does — it only describes the starter code it writes, so on an older version replace the generated body with whatever your project uses. Or replace the template outright via [`scaffold`](#scaffold), which is what that option is for.
|
|
128
|
+
|
|
129
|
+
### File names must end in lower case
|
|
130
|
+
|
|
131
|
+
`sb-deps` matches file endings exactly, so an extension has to be spelled in lower case, and so do the `.stories` and `.story` parts. `Button.stories.tsx` works; `Button.Stories.tsx` and `Button.TSX` do not. Storybook matches its own `stories` setting exactly too, so a story file spelled with capitals would never show up there whatever this tool did with it.
|
|
132
|
+
|
|
133
|
+
Two more endings are read, but only where they mean anything. `.decorator` is read on `.svelte` files, since only Svelte writes those. `.component` is read on `.ts` and `.html` files **in an Angular project only** — every framework writes `.ts`, so the extension alone can't tell an Angular component from an ordinary dotted name. Anywhere else the two mean nothing here: a NestJS `Roles.Decorator.ts`, or an `Auth.Component.ts` in a React project, is left alone.
|
|
134
|
+
|
|
135
|
+
Create a file with a capitalised ending and `sb-deps` says so, names the spelling to rename it to, and writes nothing for it.
|
|
136
|
+
|
|
137
|
+
It checks files as they are created, which includes ones a branch checkout or a copy brings in while it is running — those arrive as creations like any other and are turned away the same way. What it cannot see is a file that appeared while it was not running, or one already in your project before you installed the addon. Nothing breaks: such a file simply won't be paired with its story until you rename it.
|
|
138
|
+
|
|
139
|
+
On Linux and other systems that tell capitals apart, four spellings go unnoticed entirely — the patterns the watcher listens on match exactly there, and these match none of them, so they are neither refused nor mentioned. Nothing breaks that renaming won't fix; there is just nothing telling you to rename them. On Windows and macOS all four are caught as usual:
|
|
140
|
+
|
|
141
|
+
- **Angular templates** — `Button.Component.html`.
|
|
142
|
+
- **A capitalised extension** — `Gadget.TSX`.
|
|
143
|
+
- **A story outside your source folder** — `stories/Foo.Stories.tsx`.
|
|
144
|
+
- **A capitalised story ending on `.mdx`** — `Foo.Stories.mdx`.
|
|
145
|
+
|
|
146
|
+
The last two have perfectly ordinary extensions; it is the `.Stories` part carrying the capitals.
|
|
147
|
+
|
|
148
|
+
The watcher's patterns can't be widened *across the board* to catch these: on those same systems, matching every pattern loosely would also make a `Src/` folder match a `srcDir` of `src`, and there those really are two different folders.
|
|
149
|
+
|
|
150
|
+
Only the endings are checked, so a component whose own name carries a dot is left alone — as long as none of its dotted parts is an ending that means something here, on that extension and in that framework. `Table.Row.tsx` is fine; `My.Story.tsx` is read as a story file and refused.
|
|
151
|
+
|
|
152
|
+
A story and its component also have to agree on capitals. Creating `cardlisting.stories.tsx` next to an existing `CardListing.tsx` is reported rather than guessed at: on Windows and macOS the two names open the same file and elsewhere they don't, so there is no reading of it that works everywhere.
|
|
153
|
+
|
|
154
|
+
A Svelte decorator is the one exception — it is reported but still written. Creating `cardlisting.decorator.svelte` next to `CardListing.svelte` writes the decorator with an import that works on Windows and macOS and fails elsewhere, and says so.
|
|
155
|
+
|
|
156
|
+
The difference is that a refused decorator would be stuck, while a refused story isn't. An empty story file gets filled later — once you fix the clash, creating the component writes into the empty story that is already there. A decorator has no second file whose creation comes back for it, so refusing would leave you one that only deleting and re-creating could ever fill.
|
|
157
|
+
|
|
158
|
+
### File names must be able to become component names
|
|
159
|
+
|
|
160
|
+
The name of a file is what the templates put in front of `export function`, in the props type name, and in the import the story writes — so a file whose name can't be used that way can't be scaffolded from. Creating one is reported and nothing is written for it:
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
[sb-deps] left "src/routes/[category].tsx" alone — "[category]" can't be used as a component name in the generated code, so nothing was scaffolded for it.
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Router page files are the usual reason. `[category].tsx` is how Solid Start, SvelteKit and Next.js App Router name a page with a changing part of its address, SvelteKit also writes `+page.svelte` and `+layout.svelte`, and a name that starts with a digit (`2-column.tsx`) can't be a function name either.
|
|
167
|
+
|
|
168
|
+
Only files the scaffolder would otherwise have acted on are checked, so a plain `.ts` file such as SvelteKit's `+page.server.ts` is never mentioned — no component or story was ever going to come of it.
|
|
169
|
+
|
|
170
|
+
If a whole folder of these is expected — which it is, for any project with a router — [`scaffoldIgnore`](#scaffoldignore) turns the messages off along with the scaffolding.
|
|
108
171
|
|
|
109
172
|
**Tip — if a brand-new story shows `importers[path] is not a function` in Storybook**, just reload the browser tab. This is an occasional Storybook dev-server timing quirk when a story file is added while the dev server is running (the preview's internal module map briefly lags behind); a refresh clears it and the scaffolded files themselves are correct. Creating the **component** first (and letting the story auto-generate) avoids the hiccup entirely.
|
|
110
173
|
|
|
@@ -185,10 +248,63 @@ export default defineSbDepsConfig({
|
|
|
185
248
|
})
|
|
186
249
|
```
|
|
187
250
|
|
|
251
|
+
### `tsxFramework`
|
|
252
|
+
|
|
253
|
+
Which flavor to scaffold for `.tsx` component and story files — `'react'` or `'solid'`. React and Solid both author components in `.tsx`, so the extension alone can't tell them apart; set this to `'solid'` in a Solid project and scaffolded `.tsx` files get Solid templates (`solid-js` `createSignal`/`mergeProps`, `storybook-solidjs-vite` story imports) instead of React. The setup wizard sets it for you when it detects a Solid project. Per-template overrides for Solid go under [`scaffold.solid`](#scaffold).
|
|
254
|
+
|
|
255
|
+
**Default:** `'solid'` when `sb-deps` detects a Solid project, `'react'` otherwise — so a Solid project gets Solid templates without the key being set. Setting the key is worth it where the framework isn't obvious from your project's files.
|
|
256
|
+
|
|
257
|
+
```js
|
|
258
|
+
// sb-deps.config.mjs
|
|
259
|
+
import { defineSbDepsConfig } from 'storybook-addon-dependency-previews/config'
|
|
260
|
+
|
|
261
|
+
export default defineSbDepsConfig({
|
|
262
|
+
tsxFramework: 'solid',
|
|
263
|
+
})
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### `scaffoldIgnore`
|
|
267
|
+
|
|
268
|
+
Paths the scaffolder leaves alone. Each entry is a path pattern matched against a file's path from your project root, written with forward slashes.
|
|
269
|
+
|
|
270
|
+
**Default:** `[]` (nothing is left alone)
|
|
271
|
+
|
|
272
|
+
A file matching one of the patterns gets nothing written into it, gets no story beside it, and is never mentioned by the two naming checks above — those messages exist only to explain why nothing was scaffolded, so they have nothing to say about a file the tool was told to leave alone.
|
|
273
|
+
|
|
274
|
+
Matching files **still appear in the dependency graph**, so a page still shows what it is built with. This option is about scaffolding, not about hiding files.
|
|
275
|
+
|
|
276
|
+
A router folder is the usual reason to set it. A page takes no props, so the story generated for one has nothing to show — and page names like `[category].tsx` or `+page.svelte` can't be scaffolded from at all.
|
|
277
|
+
|
|
278
|
+
```js
|
|
279
|
+
// sb-deps.config.mjs
|
|
280
|
+
import { defineSbDepsConfig } from 'storybook-addon-dependency-previews/config'
|
|
281
|
+
|
|
282
|
+
export default defineSbDepsConfig({
|
|
283
|
+
scaffoldIgnore: ['src/routes/**'],
|
|
284
|
+
})
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
| Pattern | Matches |
|
|
288
|
+
| ----------------- | ----------------------------------------------- |
|
|
289
|
+
| `'src/routes/**'` | Everything under that one folder |
|
|
290
|
+
| `'**/routes/**'` | Everything under a `routes` folder at any depth |
|
|
291
|
+
| `'src/pages/**'` | Everything under `src/pages` |
|
|
292
|
+
| `'**/*.page.tsx'` | Files named that way, wherever they are |
|
|
293
|
+
|
|
294
|
+
Patterns are read by [`micromatch`](https://github.com/micromatch/micromatch), the same matcher the watcher uses for its own file patterns, so anything it understands works here.
|
|
295
|
+
|
|
296
|
+
On Windows and macOS the **whole path** is matched ignoring capitals — the file name as well as the folders. So `'src/routes/**'` covers a `Src/Routes` folder on disk, and `'**/*.page.tsx'` also covers `Foo.Page.tsx`. That is wider than the rest of the tool, which matches file endings exactly; the difference is deliberate, since these patterns are yours rather than something the tool infers. On Linux every pattern is matched exactly.
|
|
297
|
+
|
|
298
|
+
A story file is checked against its component, not only against itself, and a component is checked against the story name it would be given. A folder pattern covers both, since a story always sits beside its component — the difference only shows with a pattern naming files. With `'**/*.page.tsx'`, creating `Foo.page.stories.tsx` by hand leaves that story empty rather than filling it, because the component it belongs to is one you asked to be left alone. With `'**/*.stories.tsx'`, creating `Foo.tsx` scaffolds the component but writes no story. Either way the reason is printed.
|
|
299
|
+
|
|
300
|
+
An entry that isn't a non-empty string makes the whole option invalid — the CLI says so and carries on with no patterns, rather than applying half the list.
|
|
301
|
+
|
|
188
302
|
### `scaffold`
|
|
189
303
|
|
|
190
304
|
Override the templates used when `sb-deps` auto-scaffolds new component and story files. Each template function receives a context object with relevant variables and must return the full file content as a string.
|
|
191
305
|
|
|
306
|
+
For `.tsx` files the override key follows [`tsxFramework`](#tsxframework): a React project reads `scaffold.react`, a Solid project reads `scaffold.solid` — overrides placed under the wrong key are silently ignored.
|
|
307
|
+
|
|
192
308
|
```js
|
|
193
309
|
// sb-deps.config.mjs
|
|
194
310
|
import { defineSbDepsConfig } from 'storybook-addon-dependency-previews/config'
|
|
@@ -210,8 +326,14 @@ export function ${componentName}({}: ${propsName}) {
|
|
|
210
326
|
svelte: {
|
|
211
327
|
/** Customize the generated .svelte component file */
|
|
212
328
|
component: ({ componentName }) => '...',
|
|
213
|
-
/**
|
|
214
|
-
|
|
329
|
+
/**
|
|
330
|
+
* Customize the generated .decorator.svelte file.
|
|
331
|
+
* Import the wrapped component from `componentImportPath` rather than
|
|
332
|
+
* building the path out of `componentName` — that is the name the
|
|
333
|
+
* import binds to, and it can differ from the file
|
|
334
|
+
* (`card-listing.svelte` binds as `CardListing`).
|
|
335
|
+
*/
|
|
336
|
+
decorator: ({ componentName, componentImportPath }) => '...',
|
|
215
337
|
/** Customize the generated .stories.svelte file */
|
|
216
338
|
story: ({ componentName, title, tags }) => '...',
|
|
217
339
|
},
|
|
@@ -221,6 +343,12 @@ export function ${componentName}({}: ${propsName}) {
|
|
|
221
343
|
/** Customize the generated .stories.ts file */
|
|
222
344
|
story: ({ componentName, title, tags }) => '...',
|
|
223
345
|
},
|
|
346
|
+
solid: {
|
|
347
|
+
/** Customize the generated .tsx component file */
|
|
348
|
+
component: ({ componentName, propsName }) => '...',
|
|
349
|
+
/** Customize the generated .stories.tsx file */
|
|
350
|
+
story: ({ componentName, propsName, title, tags, base }) => '...',
|
|
351
|
+
},
|
|
224
352
|
angular: {
|
|
225
353
|
/** Customize the generated .component.ts file */
|
|
226
354
|
component: ({
|