histoire 0.12.4 → 0.13.1

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.
Files changed (63) hide show
  1. package/dist/node/build.js +17 -11
  2. package/dist/node/builtin-plugins/pinceau-tokens.d.ts +6 -0
  3. package/dist/node/builtin-plugins/pinceau-tokens.js +505 -0
  4. package/dist/node/collect/index.js +1 -0
  5. package/dist/node/index.d.ts +7 -0
  6. package/dist/node/server.js +7 -6
  7. package/dist/node/util/vendors.d.ts +1 -0
  8. package/dist/node/util/vendors.js +7 -2
  9. package/dist/node/virtual/index.d.ts +34 -0
  10. package/dist/node/virtual/index.js +46 -0
  11. package/dist/node/virtual/markdown.d.ts +2 -0
  12. package/dist/node/virtual/markdown.js +19 -0
  13. package/dist/node/virtual/noop.d.ts +1 -0
  14. package/dist/node/virtual/noop.js +1 -0
  15. package/dist/node/virtual/resolved-config.d.ts +2 -0
  16. package/dist/node/virtual/resolved-config.js +10 -0
  17. package/dist/node/virtual/resolved-generated-global-setup.d.ts +2 -0
  18. package/dist/node/virtual/resolved-generated-global-setup.js +23 -0
  19. package/dist/node/virtual/resolved-generated-setup-code.d.ts +2 -0
  20. package/dist/node/virtual/resolved-generated-setup-code.js +5 -0
  21. package/dist/node/virtual/resolved-markdown-files.d.ts +2 -0
  22. package/dist/node/virtual/resolved-markdown-files.js +17 -0
  23. package/dist/node/virtual/resolved-stories.d.ts +2 -0
  24. package/dist/node/virtual/resolved-stories.js +41 -0
  25. package/dist/node/virtual/resolved-support-plugins-client.d.ts +2 -0
  26. package/dist/node/virtual/resolved-support-plugins-client.js +11 -0
  27. package/dist/node/virtual/resolved-support-plugins-collect.d.ts +2 -0
  28. package/dist/node/virtual/resolved-support-plugins-collect.js +11 -0
  29. package/dist/node/virtual/resolved-theme.d.ts +2 -0
  30. package/dist/node/virtual/resolved-theme.js +12 -0
  31. package/dist/node/virtual/story-source.d.ts +2 -0
  32. package/dist/node/virtual/story-source.js +16 -0
  33. package/dist/node/virtual/story.d.ts +2 -0
  34. package/dist/node/virtual/story.js +7 -0
  35. package/dist/node/virtual/util.d.ts +2 -0
  36. package/dist/node/virtual/util.js +4 -0
  37. package/dist/node/virtual/vite-plugin.d.ts +3 -0
  38. package/dist/node/virtual/vite-plugin.js +118 -0
  39. package/dist/node/vite.d.ts +0 -22
  40. package/dist/node/vite.js +27 -281
  41. package/package.json +9 -9
  42. package/src/node/build.ts +19 -11
  43. package/src/node/builtin-plugins/pinceau-tokens.ts +521 -0
  44. package/src/node/collect/index.ts +1 -0
  45. package/src/node/index.ts +8 -0
  46. package/src/node/server.ts +7 -6
  47. package/src/node/util/vendors.ts +9 -2
  48. package/src/node/virtual/index.ts +47 -0
  49. package/src/node/virtual/markdown.ts +21 -0
  50. package/src/node/virtual/noop.ts +1 -0
  51. package/src/node/virtual/resolved-config.ts +12 -0
  52. package/src/node/virtual/resolved-generated-global-setup.ts +24 -0
  53. package/src/node/virtual/resolved-generated-setup-code.ts +7 -0
  54. package/src/node/virtual/resolved-markdown-files.ts +19 -0
  55. package/src/node/virtual/resolved-stories.ts +43 -0
  56. package/src/node/virtual/resolved-support-plugins-client.ts +14 -0
  57. package/src/node/virtual/resolved-support-plugins-collect.ts +14 -0
  58. package/src/node/virtual/resolved-theme.ts +14 -0
  59. package/src/node/virtual/story-source.ts +17 -0
  60. package/src/node/virtual/story.ts +9 -0
  61. package/src/node/virtual/util.ts +5 -0
  62. package/src/node/virtual/vite-plugin.ts +135 -0
  63. package/src/node/vite.ts +28 -294
@@ -65,13 +65,6 @@ export async function build(ctx) {
65
65
  join(APP_PATH, 'bundle-main.js'),
66
66
  join(APP_PATH, 'bundle-sandbox.js'),
67
67
  ],
68
- output: {
69
- manualChunks(id) {
70
- if (!id.includes('@histoire/app') && id.includes('node_modules')) {
71
- return 'vendor';
72
- }
73
- },
74
- },
75
68
  plugins: [
76
69
  {
77
70
  name: 'histoire-build-rollup-options-override',
@@ -83,10 +76,6 @@ export async function build(ctx) {
83
76
  },
84
77
  ],
85
78
  },
86
- outDir: ctx.config.outDir,
87
- emptyOutDir: true,
88
- cssCodeSplit: false,
89
- minify: false,
90
79
  },
91
80
  });
92
81
  // For @vite/plugin-vue: Always put our vite server
@@ -122,6 +111,23 @@ export async function build(ctx) {
122
111
  config(config) {
123
112
  // Don't externalize
124
113
  config.build.rollupOptions.external = [];
114
+ // Force chunk strategy
115
+ config.build.rollupOptions.output = {
116
+ manualChunks(id) {
117
+ if (!id.includes('@histoire/app') && id.includes('node_modules')) {
118
+ return 'vendor';
119
+ }
120
+ },
121
+ };
122
+ // Force vite build options
123
+ Object.assign(config.build, {
124
+ outDir: ctx.config.outDir,
125
+ emptyOutDir: true,
126
+ cssCodeSplit: false,
127
+ minify: false,
128
+ // Don't build in SSR mode
129
+ ssr: false,
130
+ });
125
131
  },
126
132
  });
127
133
  const results = await viteBuild(buildViteConfig);
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from '@histoire/shared';
2
+ export interface PinceauTokensOptions {
3
+ configOrPaths?: string | string[];
4
+ configFileName?: string;
5
+ }
6
+ export declare function pinceauTokens(options?: PinceauTokensOptions): Plugin;
@@ -0,0 +1,505 @@
1
+ import { getInjectedImport } from '../util/vendors.js';
2
+ import { join } from 'pathe';
3
+ export function pinceauTokens(options = {}) {
4
+ const themePath = join(process.cwd(), 'node_modules/.vite/pinceau/index.js');
5
+ async function generate(api) {
6
+ try {
7
+ await api.fs.ensureDir(api.pluginTempDir);
8
+ await api.fs.emptyDir(api.pluginTempDir);
9
+ api.moduleLoader.clearCache();
10
+ await api.fs.writeFile(api.path.resolve(api.pluginTempDir, 'style.css'), css);
11
+ const theme = await api.moduleLoader.loadModule(themePath);
12
+ const storyFile = api.path.resolve(api.pluginTempDir, 'Pinceau.story.js');
13
+ await api.fs.writeFile(storyFile, storyTemplate(theme));
14
+ api.addStoryFile(storyFile);
15
+ }
16
+ catch (e) {
17
+ api.error(e.stack ?? e.message);
18
+ }
19
+ }
20
+ return {
21
+ name: 'builtin:pinceau-tokens',
22
+ config(config) {
23
+ // Add 'design-system' group
24
+ if (!config.tree) {
25
+ config.tree = {};
26
+ }
27
+ if (!config.tree.groups) {
28
+ config.tree.groups = [];
29
+ }
30
+ if (!config.tree.groups.some(g => g.id === 'design-system')) {
31
+ let index = 0;
32
+ // After 'top' group
33
+ const topIndex = config.tree.groups.findIndex(g => g.id === 'top');
34
+ if (topIndex > -1) {
35
+ index = topIndex + 1;
36
+ }
37
+ // Insert group
38
+ config.tree.groups.splice(index, 0, {
39
+ id: 'design-system',
40
+ title: 'Design System',
41
+ });
42
+ }
43
+ },
44
+ onDev(api, onCleanup) {
45
+ const watcher = api.watcher.watch(themePath)
46
+ .on('change', () => generate(api))
47
+ .on('add', () => generate(api));
48
+ onCleanup(() => {
49
+ watcher.close();
50
+ });
51
+ },
52
+ async onBuild(api) {
53
+ await generate(api);
54
+ },
55
+ };
56
+ }
57
+ const storyTemplate = (pinceauConfig) => {
58
+ pinceauConfig = pinceauConfig?.theme || pinceauConfig?.default?.theme || {};
59
+ return `import 'histoire-style'
60
+ import './style.css'
61
+ import { createApp, h, markRaw, ref } from ${getInjectedImport('@histoire/vendors/vue')}
62
+ import {
63
+ HstColorShades,
64
+ HstTokenList,
65
+ HstTokenGrid,
66
+ HstText,
67
+ HstTextarea,
68
+ HstNumber,
69
+ } from ${getInjectedImport('@histoire/controls')}
70
+
71
+ const config = markRaw(${JSON.stringify(pinceauConfig, null, 2)})
72
+ const search = ref('')
73
+ const sampleText = ref('Cat sit like bread eat prawns daintily with a claw then lick paws clean wash down prawns with a lap of carnation milk then retire to the warmest spot on the couch to claw at the fabric before taking a catnap mrow cat cat moo moo lick ears lick paws')
74
+ const fontSize = ref(16)
75
+ const flattenTokens = (data, transformValue = (value) => (value?.value || value)) => {
76
+ const output = {}
77
+ function step(obj, prev) {
78
+ Object.keys(obj).forEach((key) => {
79
+ const value = obj[key]
80
+ const isarray = Array.isArray(value)
81
+ const type = Object.prototype.toString.call(value)
82
+ const isobject
83
+ = type === '[object Object]'
84
+ || type === '[object Array]'
85
+
86
+ const newKey = prev ? prev + '.' + key : key
87
+
88
+ if (value.value && !output[newKey]) {
89
+ output[newKey] = transformValue(value)
90
+ }
91
+
92
+ if (!isarray && isobject && Object.keys(value).length) { return step(value, newKey) }
93
+ })
94
+ }
95
+ step(data)
96
+ return output
97
+ }
98
+
99
+ function mountApp ({ el, state, onUnmount }, render) {
100
+ Object.assign(state, {
101
+ search,
102
+ sampleText,
103
+ fontSize,
104
+ })
105
+
106
+ const app = createApp({
107
+ render,
108
+ })
109
+ app.mount(el)
110
+
111
+ onUnmount(() => {
112
+ app.unmount()
113
+ })
114
+ }
115
+
116
+ /*
117
+ media?: PinceauTokens
118
+ colors?: ScaleTokens
119
+ fonts?: PinceauTokens
120
+ fontWeights?: FontWeightTokens
121
+ fontSizes?: BreakpointsTokens
122
+ size?: BreakpointsTokens
123
+ space?: BreakpointsTokens
124
+ radii?: BreakpointsTokens
125
+ borders?: BreakpointsTokens
126
+ borderWidths?: BreakpointsTokens
127
+ borderStyles?: BreakpointsTokens
128
+ shadows?: BreakpointsTokens
129
+ opacity?: BreakpointsTokens
130
+ leads?: BreakpointsTokens
131
+ letterSpacings?: BreakpointsTokens
132
+ transitions?: PinceauTokens
133
+ zIndices?: PinceauTokens
134
+ */
135
+
136
+ export default {
137
+ id: 'pinceau',
138
+ title: 'Pinceau',
139
+ group: 'design-system',
140
+ icon: 'noto:paintbrush',
141
+ responsiveDisabled: true,
142
+ layout: { type: 'single', iframe: false },
143
+ variants: [
144
+ {
145
+ id: 'media-queries',
146
+ title: 'Media Queries',
147
+ icon: 'carbon:screen',
148
+ onMount: (api) => mountApp(api, () => h(HstTokenGrid, {
149
+ tokens: flattenTokens(config.media),
150
+ getName: key => '@mq.' + key,
151
+ colSize: 180,
152
+ }, ({ token }) => h('div', {
153
+ class: '__hst-drop-shadow',
154
+ }))),
155
+ },
156
+ {
157
+ id: 'colors',
158
+ title: 'Colors',
159
+ icon: 'carbon:color-palette',
160
+ onMount: (api) => mountApp(api, () => Object.entries(config.colors).map(([key, shades]) => h(HstColorShades, {
161
+ key,
162
+ shades: shades.value ? { DEFAULT: shades.value } : flattenTokens(shades),
163
+ getName: shade => '{colors.' + key + '.' + shade + '}',
164
+ search: search.value,
165
+ }, ({ color}) => h('div', {
166
+ class: '__hst-shade',
167
+ style: {
168
+ backgroundColor: color,
169
+ },
170
+ })))),
171
+ onMountControls: (api) => mountApp(api, () => [
172
+ h(HstText, {
173
+ title: 'Filter...',
174
+ modelValue: search.value,
175
+ 'onUpdate:modelValue': value => { search.value = value },
176
+ }),
177
+ ]),
178
+ },
179
+ // SPACES
180
+ {
181
+ id: 'Spaces',
182
+ title: 'Spaces',
183
+ icon: 'carbon:area',
184
+ onMount: (api) => mountApp(api, () => h(HstTokenList, {
185
+ tokens: flattenTokens(config.space),
186
+ getName: key => '{space.' + key + '}',
187
+ }, ({ token }) => h('div', {
188
+ class: '__hst-spaces',
189
+ style: {
190
+ padding: token.value,
191
+ },
192
+ }, [
193
+ h('div', {
194
+ class: '__hst-spaces-box',
195
+ }),
196
+ ]))),
197
+ },
198
+ // SIZES
199
+ {
200
+ id: 'sizes',
201
+ title: 'Sizes',
202
+ icon: 'carbon:pan-horizontal',
203
+ onMount: (api) => mountApp(api, () => h(HstTokenList, {
204
+ tokens: flattenTokens(config.size),
205
+ getName: key => '{size.' + key + '}',
206
+ }, ({ token }) => h('div', {
207
+ class: '__hst-width',
208
+ }, [
209
+ h('div', {
210
+ class: '__hst-width-box',
211
+ style: {
212
+ width: token.value,
213
+ },
214
+ }),
215
+ ]))),
216
+ },
217
+ // FONTSIZES
218
+ {
219
+ id: 'font-size',
220
+ title: 'Font Size',
221
+ icon: 'carbon:text-font',
222
+ onMount: (api) => mountApp(api, () => h(HstTokenList, {
223
+ tokens: flattenTokens(config.fontSizes),
224
+ getName: key => '{fontSizes.' + key + '}',
225
+ }, ({ token }) => h('div', {
226
+ class: '__hst-truncate',
227
+ style: {
228
+ fontSize: token.value,
229
+ },
230
+ }, sampleText.value))),
231
+ onMountControls: (api) => mountApp(api, () => [
232
+ h(HstTextarea, {
233
+ title: 'Sample text',
234
+ modelValue: sampleText.value,
235
+ 'onUpdate:modelValue': value => { sampleText.value = value },
236
+ rows: 5,
237
+ }),
238
+ ]),
239
+ },
240
+ // FONTWEIGHTS
241
+ {
242
+ id: 'font-weight',
243
+ title: 'Font Weight',
244
+ icon: 'carbon:text-font',
245
+ onMount: (api) => mountApp(api, () => h(HstTokenList, {
246
+ tokens: flattenTokens(config.fontWeights),
247
+ getName: key => '{fontWeights.' + key + '}',
248
+ }, ({ token }) => h('div', {
249
+ class: '__hst-truncate',
250
+ style: {
251
+ fontWeight: token.value,
252
+ fontSize: \`\${fontSize.value}px\`,
253
+ },
254
+ }, sampleText.value))),
255
+ onMountControls: (api) => mountApp(api, () => [
256
+ h(HstTextarea, {
257
+ title: 'Sample text',
258
+ modelValue: sampleText.value,
259
+ 'onUpdate:modelValue': value => { sampleText.value = value },
260
+ rows: 5,
261
+ }),
262
+ h(HstNumber, {
263
+ title: 'Font size',
264
+ modelValue: fontSize.value,
265
+ 'onUpdate:modelValue': value => { fontSize.value = value },
266
+ min: 1,
267
+ }),
268
+ ]),
269
+ },
270
+ // FONTS
271
+ {
272
+ id: 'fonts',
273
+ title: 'Fonts',
274
+ icon: 'carbon:text-font',
275
+ onMount: (api) => mountApp(api, () => h(HstTokenList, {
276
+ tokens: flattenTokens(config.fonts),
277
+ getName: key => '{fonts.' + key + '}',
278
+ }, ({ token }) => h('div', {
279
+ class: '__hst-truncate',
280
+ style: {
281
+ fontFamily: token.value,
282
+ fontSize: \`\${fontSize.value}px\`,
283
+ },
284
+ }, sampleText.value))),
285
+ onMountControls: (api) => mountApp(api, () => [
286
+ h(HstTextarea, {
287
+ title: 'Sample text',
288
+ modelValue: sampleText.value,
289
+ 'onUpdate:modelValue': value => { sampleText.value = value },
290
+ rows: 5,
291
+ }),
292
+ h(HstNumber, {
293
+ title: 'Font size',
294
+ modelValue: fontSize.value,
295
+ 'onUpdate:modelValue': value => { fontSize.value = value },
296
+ min: 1,
297
+ }),
298
+ ]),
299
+ },
300
+ // LETTERSPACINGS
301
+ {
302
+ id: 'letter-spacing',
303
+ title: 'Letter Spacing',
304
+ icon: 'carbon:text-font',
305
+ onMount: (api) => mountApp(api, () => h(HstTokenList, {
306
+ tokens: flattenTokens(config.letterSpacings),
307
+ getName: key => '{letterSpacings.' + key + '}',
308
+ }, ({ token }) => h('div', {
309
+ class: '__hst-truncate',
310
+ style: {
311
+ letterSpacing: token.value,
312
+ fontSize: \`\${fontSize.value}px\`,
313
+ },
314
+ }, sampleText.value))),
315
+ onMountControls: (api) => mountApp(api, () => [
316
+ h(HstTextarea, {
317
+ title: 'Sample text',
318
+ modelValue: sampleText.value,
319
+ 'onUpdate:modelValue': value => { sampleText.value = value },
320
+ rows: 5,
321
+ }),
322
+ h(HstNumber, {
323
+ title: 'Font size',
324
+ modelValue: fontSize.value,
325
+ 'onUpdate:modelValue': value => { fontSize.value = value },
326
+ min: 1,
327
+ }),
328
+ ]),
329
+ },
330
+ // LEADS
331
+ {
332
+ id: 'leads',
333
+ title: 'Leads',
334
+ icon: 'carbon:text-font',
335
+ onMount: (api) => mountApp(api, () => h(HstTokenList, {
336
+ tokens: flattenTokens(config.leads),
337
+ getName: key => '{leads.' + key + '}',
338
+ }, ({ token }) => h('div', {
339
+ style: {
340
+ lineHeight: token.value,
341
+ },
342
+ }, sampleText.value))),
343
+ onMountControls: (api) => mountApp(api, () => [
344
+ h(HstTextarea, {
345
+ title: 'Sample text',
346
+ modelValue: sampleText.value,
347
+ 'onUpdate:modelValue': value => { sampleText.value = value },
348
+ rows: 5,
349
+ }),
350
+ // @TODO select font size
351
+ ]),
352
+ },
353
+ // SHADOWS
354
+ {
355
+ id: 'shadows',
356
+ title: 'Shadows',
357
+ icon: 'carbon:shape-except',
358
+ onMount: (api) => mountApp(api, () => h(HstTokenGrid, {
359
+ tokens: flattenTokens(config.shadows),
360
+ getName: key => '{shadows.' + key + '}',
361
+ colSize: 180,
362
+ }, ({ token }) => h('div', {
363
+ class: '__hst-drop-shadow',
364
+ style: 'box-shadow:' + token.value,
365
+ }))),
366
+ },
367
+ // OPACITIES
368
+ {
369
+ id: 'opacities',
370
+ title: 'Opacities',
371
+ icon: 'carbon:bring-forward',
372
+ onMount: (api) => mountApp(api, () => h(HstTokenGrid, {
373
+ tokens: flattenTokens(config.opacity),
374
+ getName: key => '{opacity.' + key + '}',
375
+ colSize: 180,
376
+ }, ({ token }) => h('div', {
377
+ class: '__hst-drop-shadow',
378
+ style: 'opacity:' + token.value,
379
+ }))),
380
+ },
381
+ // RADII
382
+ {
383
+ id: 'border-radius',
384
+ title: 'Border Radius',
385
+ icon: 'carbon:condition-wait-point',
386
+ onMount: (api) => mountApp(api, () => h(HstTokenGrid, {
387
+ tokens: flattenTokens(config.radii),
388
+ getName: key => '{radii.' + key + '}',
389
+ colSize: 180,
390
+ }, ({ token }) => h('div', {
391
+ class: '__hst-border-radius',
392
+ style: {
393
+ borderRadius: token.value,
394
+ },
395
+ }))),
396
+ },
397
+ // BORDERWIDTHS
398
+ {
399
+ id: 'border-width',
400
+ title: 'Border Width',
401
+ icon: 'carbon:checkbox',
402
+ onMount: (api) => mountApp(api, () => h(HstTokenGrid, {
403
+ tokens: flattenTokens(config.borderWidths),
404
+ getName: key => '{borderWidths.' + key + '}',
405
+ colSize: 180,
406
+ }, ({ token }) => h('div', {
407
+ class: '__hst-border-width',
408
+ style: {
409
+ borderWidth: token.value,
410
+ },
411
+ }))),
412
+ },
413
+ // FULL CONFIG
414
+ {
415
+ id: 'full-config',
416
+ title: 'Full Config',
417
+ icon: 'carbon:code',
418
+ onMount: (api) => mountApp(api, () => h('pre', JSON.stringify(config, null, 2))),
419
+ },
420
+ ],
421
+ }`;
422
+ };
423
+ const css = `.__hst-shade {
424
+ height: 80px;
425
+ border-radius: 4px;
426
+ }
427
+
428
+ .__hst-text {
429
+ font-size: 4rem;
430
+ display: flex;
431
+ align-items: flex-end;
432
+ }
433
+
434
+ .__hst-border {
435
+ border-style: solid;
436
+ border-width: 2px;
437
+ }
438
+
439
+ .__hst-spaces {
440
+ background-color: rgb(113 113 122 / 0.1);
441
+ width: min-content;
442
+ }
443
+
444
+ .__hst-margin {
445
+ border: dashed 1px rgb(113 113 122 / 0.5);
446
+ width: min-content;
447
+ }
448
+
449
+ .__hst-spaces-box,
450
+ .__hst-margin-box {
451
+ width: 5rem;
452
+ height: 5rem;
453
+ background-color: rgb(113 113 122 / 0.5);
454
+ }
455
+
456
+ .__hst-spaces,
457
+ .__hst-spaces-box,
458
+ .__hst-margin,
459
+ .__hst-margin-box,
460
+ .__hst-drop-shadow {
461
+ border-radius: 4px;
462
+ }
463
+
464
+ .__hst-truncate {
465
+ overflow: hidden;
466
+ text-overflow: ellipsis;
467
+ white-space: nowrap;
468
+ }
469
+
470
+ .__hst-drop-shadow {
471
+ width: 8rem;
472
+ height: 8rem;
473
+ background: white;
474
+ margin-bottom: 0.5rem;
475
+ }
476
+
477
+ .__hst-drop-shadow {
478
+ background: #4e4e57;
479
+ }
480
+
481
+ .__hst-border-radius {
482
+ width: 8rem;
483
+ height: 8rem;
484
+ background-color: rgb(113 113 122 / 0.5);
485
+ }
486
+
487
+ .__hst-border-width {
488
+ width: 8rem;
489
+ height: 8rem;
490
+ border-color: rgb(113 113 122 / 0.5);
491
+ background-color: rgb(113 113 122 / 0.1);
492
+ }
493
+
494
+ .__hst-width {
495
+ background-color: rgb(113 113 122 / 0.1);
496
+ }
497
+
498
+ .__hst-width-box,
499
+ .__hst-height {
500
+ background-color: rgb(113 113 122 / 0.5);
501
+ }
502
+
503
+ .__hst-width-box {
504
+ height: 5rem;
505
+ }`;
@@ -21,6 +21,7 @@ export function useCollectStories(options, ctx) {
21
21
  /vite\w*\/dist\/client\/(client|env).mjs/,
22
22
  ...ctx.config.viteNodeInlineDeps ?? [],
23
23
  ],
24
+ fallbackCJS: true,
24
25
  },
25
26
  transformMode: ctx.config.viteNodeTransformMode,
26
27
  });
@@ -2,3 +2,10 @@ export * from '@histoire/shared';
2
2
  export * from './config.js';
3
3
  export * from './plugin.js';
4
4
  export { defaultColors } from './colors.js';
5
+ declare module 'rollup' {
6
+ interface PluginContextMeta {
7
+ histoire: {
8
+ isCollecting: boolean;
9
+ };
10
+ }
11
+ }
@@ -1,7 +1,8 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { createServer as createViteServer } from 'vite';
3
3
  import pc from 'picocolors';
4
- import { getViteConfigWithPlugins, RESOLVED_MARKDOWN_FILES, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js';
4
+ import { getViteConfigWithPlugins } from './vite.js';
5
+ import * as VirtualFiles from './virtual/index.js';
5
6
  import { onStoryChange, onStoryListChange, watchStories } from './stories.js';
6
7
  import { useCollectStories } from './collect/index.js';
7
8
  import { DevPluginApi } from './plugin.js';
@@ -135,19 +136,19 @@ export async function createServer(ctx, options = {}) {
135
136
  }
136
137
  console.log(`Collect stories end ${pc.bold(pc.blue(Math.round(performance.now() - time)))}ms`);
137
138
  clearInvalidates();
138
- invalidateModule(RESOLVED_STORIES_ID);
139
- invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID);
139
+ invalidateModule(VirtualFiles.RESOLVED_STORIES_ID);
140
+ invalidateModule(VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID);
140
141
  collecting = false;
141
142
  if (queued) {
142
143
  await collect();
143
144
  }
144
145
  }
145
146
  onStoryListChange(() => {
146
- invalidateModule(RESOLVED_STORIES_ID);
147
- invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID);
147
+ invalidateModule(VirtualFiles.RESOLVED_STORIES_ID);
148
+ invalidateModule(VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID);
148
149
  });
149
150
  onMarkdownListChange(() => {
150
- invalidateModule(RESOLVED_MARKDOWN_FILES);
151
+ invalidateModule(VirtualFiles.RESOLVED_MARKDOWN_FILES);
151
152
  });
152
153
  async function close() {
153
154
  for (const cb of pluginOnCleanups) {
@@ -1 +1,2 @@
1
+ export declare const __dirname: string;
1
2
  export declare function getInjectedImport(request: string): string;
@@ -1,7 +1,12 @@
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ // Resolve an absolute path to e.g. node_modules/.pnpm/histoire@0.11.7_vite@3.2.4/node_modules/histoire/dist/node/vendors/controls.js
4
+ // https://github.com/histoire-dev/histoire/issues/282
5
+ export const __dirname = path.dirname(fileURLToPath(import.meta.url));
1
6
  // https://github.com/vitejs/vite/issues/9661
2
7
  const alias = {
3
- '@histoire/vendors/vue': 'histoire/dist/node/vendors/vue.js',
4
- '@histoire/controls': 'histoire/dist/node/vendors/controls.js',
8
+ '@histoire/vendors/vue': path.resolve(__dirname, '../vendors/vue.js'),
9
+ '@histoire/controls': path.resolve(__dirname, '../vendors/controls.js'),
5
10
  };
6
11
  export function getInjectedImport(request) {
7
12
  let id = request;
@@ -0,0 +1,34 @@
1
+ export declare const STORIES_ID = "virtual:$histoire-stories";
2
+ export declare const RESOLVED_STORIES_ID: string;
3
+ export declare const SETUP_ID = "virtual:$histoire-setup";
4
+ export declare const NOOP_ID = "virtual:$histoire-noop";
5
+ export declare const CONFIG_ID = "virtual:$histoire-config";
6
+ export declare const RESOLVED_CONFIG_ID: string;
7
+ export declare const THEME_ID = "virtual:$histoire-theme";
8
+ export declare const RESOLVED_THEME_ID: string;
9
+ export declare const SEARCH_TITLE_DATA_ID = "virtual:$histoire-search-title-data";
10
+ export declare const RESOLVED_SEARCH_TITLE_DATA_ID: string;
11
+ export declare const SEARCH_DOCS_DATA_ID = "virtual:$histoire-search-docs-data";
12
+ export declare const RESOLVED_SEARCH_DOCS_DATA_ID: string;
13
+ export declare const GENERATED_GLOBAL_SETUP = "virtual:$histoire-generated-global-setup";
14
+ export declare const RESOLVED_GENERATED_GLOBAL_SETUP: string;
15
+ export declare const GENERATED_SETUP_CODE = "virtual:$histoire-generated-setup-code";
16
+ export declare const RESOLVED_GENERATED_SETUP_CODE: string;
17
+ export declare const SUPPORT_PLUGINS_CLIENT = "virtual:$histoire-support-plugins-client";
18
+ export declare const RESOLVED_SUPPORT_PLUGINS_CLIENT: string;
19
+ export declare const SUPPORT_PLUGINS_COLLECT = "virtual:$histoire-support-plugins-collect";
20
+ export declare const RESOLVED_SUPPORT_PLUGINS_COLLECT: string;
21
+ export declare const MARKDOWN_FILES = "virtual:$histoire-markdown-files";
22
+ export declare const RESOLVED_MARKDOWN_FILES: string;
23
+ export * from './markdown.js';
24
+ export * from './noop.js';
25
+ export * from './resolved-config.js';
26
+ export * from './resolved-generated-global-setup.js';
27
+ export * from './resolved-generated-setup-code.js';
28
+ export * from './resolved-markdown-files.js';
29
+ export * from './resolved-stories.js';
30
+ export * from './resolved-support-plugins-client.js';
31
+ export * from './resolved-support-plugins-collect.js';
32
+ export * from './resolved-theme.js';
33
+ export * from './story.js';
34
+ export * from './story-source.js';