poveste 0.1.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.
Files changed (251) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +11 -0
  3. package/bin.mjs +4 -0
  4. package/client.d.ts +19 -0
  5. package/client.js +15 -0
  6. package/dist/controls.d.ts +2 -0
  7. package/dist/controls.d.ts.map +1 -0
  8. package/dist/controls.js +1 -0
  9. package/dist/node/alias.d.ts +3 -0
  10. package/dist/node/alias.d.ts.map +1 -0
  11. package/dist/node/alias.js +5 -0
  12. package/dist/node/bin.d.ts +2 -0
  13. package/dist/node/bin.d.ts.map +1 -0
  14. package/dist/node/bin.js +35 -0
  15. package/dist/node/build-serialize.d.ts +22 -0
  16. package/dist/node/build-serialize.d.ts.map +1 -0
  17. package/dist/node/build-serialize.js +36 -0
  18. package/dist/node/build.d.ts +3 -0
  19. package/dist/node/build.d.ts.map +1 -0
  20. package/dist/node/build.js +228 -0
  21. package/dist/node/builtin-plugins/pinceau-tokens.d.ts +7 -0
  22. package/dist/node/builtin-plugins/pinceau-tokens.d.ts.map +1 -0
  23. package/dist/node/builtin-plugins/pinceau-tokens.js +505 -0
  24. package/dist/node/builtin-plugins/tailwind-tokens.d.ts +6 -0
  25. package/dist/node/builtin-plugins/tailwind-tokens.d.ts.map +1 -0
  26. package/dist/node/builtin-plugins/tailwind-tokens.js +523 -0
  27. package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts +15 -0
  28. package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts.map +1 -0
  29. package/dist/node/builtin-plugins/vanilla-support/MountStory.js +39 -0
  30. package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts +39 -0
  31. package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts.map +1 -0
  32. package/dist/node/builtin-plugins/vanilla-support/RenderStory.js +129 -0
  33. package/dist/node/builtin-plugins/vanilla-support/client.d.ts +4 -0
  34. package/dist/node/builtin-plugins/vanilla-support/client.d.ts.map +1 -0
  35. package/dist/node/builtin-plugins/vanilla-support/client.js +5 -0
  36. package/dist/node/builtin-plugins/vanilla-support/collect.d.ts +3 -0
  37. package/dist/node/builtin-plugins/vanilla-support/collect.d.ts.map +1 -0
  38. package/dist/node/builtin-plugins/vanilla-support/collect.js +33 -0
  39. package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts +3 -0
  40. package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts.map +1 -0
  41. package/dist/node/builtin-plugins/vanilla-support/plugin.js +29 -0
  42. package/dist/node/builtin-plugins/vanilla-support/types.d.ts +36 -0
  43. package/dist/node/builtin-plugins/vanilla-support/types.d.ts.map +1 -0
  44. package/dist/node/builtin-plugins/vanilla-support/types.js +3 -0
  45. package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts +4 -0
  46. package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts.map +1 -0
  47. package/dist/node/builtin-plugins/vanilla-support/vanilla.story.js +55 -0
  48. package/dist/node/collect/index.d.ts +14 -0
  49. package/dist/node/collect/index.d.ts.map +1 -0
  50. package/dist/node/collect/index.js +129 -0
  51. package/dist/node/collect/run.d.ts +3 -0
  52. package/dist/node/collect/run.d.ts.map +1 -0
  53. package/dist/node/collect/run.js +7 -0
  54. package/dist/node/collect/worker.d.ts +14 -0
  55. package/dist/node/collect/worker.d.ts.map +1 -0
  56. package/dist/node/collect/worker.js +64 -0
  57. package/dist/node/colors.d.ts +287 -0
  58. package/dist/node/colors.d.ts.map +1 -0
  59. package/dist/node/colors.js +324 -0
  60. package/dist/node/commands/build.d.ts +5 -0
  61. package/dist/node/commands/build.d.ts.map +1 -0
  62. package/dist/node/commands/build.js +9 -0
  63. package/dist/node/commands/dev.d.ts +8 -0
  64. package/dist/node/commands/dev.d.ts.map +1 -0
  65. package/dist/node/commands/dev.js +52 -0
  66. package/dist/node/commands/preview.d.ts +5 -0
  67. package/dist/node/commands/preview.d.ts.map +1 -0
  68. package/dist/node/commands/preview.js +15 -0
  69. package/dist/node/config.d.ts +40 -0
  70. package/dist/node/config.d.ts.map +1 -0
  71. package/dist/node/config.js +330 -0
  72. package/dist/node/context.d.ts +18 -0
  73. package/dist/node/context.d.ts.map +1 -0
  74. package/dist/node/context.js +28 -0
  75. package/dist/node/dom/dom-keys.d.ts +5 -0
  76. package/dist/node/dom/dom-keys.d.ts.map +1 -0
  77. package/dist/node/dom/dom-keys.js +233 -0
  78. package/dist/node/dom/env.d.ts +5 -0
  79. package/dist/node/dom/env.d.ts.map +1 -0
  80. package/dist/node/dom/env.js +47 -0
  81. package/dist/node/dom/util.d.ts +11 -0
  82. package/dist/node/dom/util.d.ts.map +1 -0
  83. package/dist/node/dom/util.js +65 -0
  84. package/dist/node/index.d.ts +12 -0
  85. package/dist/node/index.d.ts.map +1 -0
  86. package/dist/node/index.js +4 -0
  87. package/dist/node/load.d.ts +9 -0
  88. package/dist/node/load.d.ts.map +1 -0
  89. package/dist/node/load.js +42 -0
  90. package/dist/node/markdown.d.ts +11 -0
  91. package/dist/node/markdown.d.ts.map +1 -0
  92. package/dist/node/markdown.js +228 -0
  93. package/dist/node/plugin.d.ts +42 -0
  94. package/dist/node/plugin.d.ts.map +1 -0
  95. package/dist/node/plugin.js +67 -0
  96. package/dist/node/preview.d.ts +8 -0
  97. package/dist/node/preview.d.ts.map +1 -0
  98. package/dist/node/preview.js +41 -0
  99. package/dist/node/search.d.ts +17 -0
  100. package/dist/node/search.d.ts.map +1 -0
  101. package/dist/node/search.js +72 -0
  102. package/dist/node/server.d.ts +12 -0
  103. package/dist/node/server.d.ts.map +1 -0
  104. package/dist/node/server.js +189 -0
  105. package/dist/node/stories.d.ts +22 -0
  106. package/dist/node/stories.d.ts.map +1 -0
  107. package/dist/node/stories.js +125 -0
  108. package/dist/node/tree.d.ts +4 -0
  109. package/dist/node/tree.d.ts.map +1 -0
  110. package/dist/node/tree.js +117 -0
  111. package/dist/node/util/find-up.d.ts +2 -0
  112. package/dist/node/util/find-up.d.ts.map +1 -0
  113. package/dist/node/util/find-up.js +20 -0
  114. package/dist/node/util/fs.d.ts +2 -0
  115. package/dist/node/util/fs.d.ts.map +1 -0
  116. package/dist/node/util/fs.js +1 -0
  117. package/dist/node/util/log.d.ts +2 -0
  118. package/dist/node/util/log.d.ts.map +1 -0
  119. package/dist/node/util/log.js +9 -0
  120. package/dist/node/util/slugify.d.ts +2 -0
  121. package/dist/node/util/slugify.d.ts.map +1 -0
  122. package/dist/node/util/slugify.js +22 -0
  123. package/dist/node/util/vendors.d.ts +3 -0
  124. package/dist/node/util/vendors.d.ts.map +1 -0
  125. package/dist/node/util/vendors.js +22 -0
  126. package/dist/node/vendors/controls.d.ts +2 -0
  127. package/dist/node/vendors/controls.d.ts.map +1 -0
  128. package/dist/node/vendors/controls.js +1 -0
  129. package/dist/node/vendors/vue.d.ts +2 -0
  130. package/dist/node/vendors/vue.d.ts.map +1 -0
  131. package/dist/node/vendors/vue.js +1 -0
  132. package/dist/node/virtual/index.d.ts +38 -0
  133. package/dist/node/virtual/index.d.ts.map +1 -0
  134. package/dist/node/virtual/index.js +49 -0
  135. package/dist/node/virtual/markdown.d.ts +3 -0
  136. package/dist/node/virtual/markdown.d.ts.map +1 -0
  137. package/dist/node/virtual/markdown.js +19 -0
  138. package/dist/node/virtual/noop.d.ts +2 -0
  139. package/dist/node/virtual/noop.d.ts.map +1 -0
  140. package/dist/node/virtual/noop.js +1 -0
  141. package/dist/node/virtual/resolved-commands.d.ts +3 -0
  142. package/dist/node/virtual/resolved-commands.d.ts.map +1 -0
  143. package/dist/node/virtual/resolved-commands.js +32 -0
  144. package/dist/node/virtual/resolved-config.d.ts +3 -0
  145. package/dist/node/virtual/resolved-config.d.ts.map +1 -0
  146. package/dist/node/virtual/resolved-config.js +10 -0
  147. package/dist/node/virtual/resolved-generated-global-setup.d.ts +3 -0
  148. package/dist/node/virtual/resolved-generated-global-setup.d.ts.map +1 -0
  149. package/dist/node/virtual/resolved-generated-global-setup.js +23 -0
  150. package/dist/node/virtual/resolved-generated-setup-code.d.ts +3 -0
  151. package/dist/node/virtual/resolved-generated-setup-code.d.ts.map +1 -0
  152. package/dist/node/virtual/resolved-generated-setup-code.js +5 -0
  153. package/dist/node/virtual/resolved-markdown-files.d.ts +3 -0
  154. package/dist/node/virtual/resolved-markdown-files.d.ts.map +1 -0
  155. package/dist/node/virtual/resolved-markdown-files.js +17 -0
  156. package/dist/node/virtual/resolved-stories.d.ts +3 -0
  157. package/dist/node/virtual/resolved-stories.d.ts.map +1 -0
  158. package/dist/node/virtual/resolved-stories.js +42 -0
  159. package/dist/node/virtual/resolved-support-plugins-client.d.ts +3 -0
  160. package/dist/node/virtual/resolved-support-plugins-client.d.ts.map +1 -0
  161. package/dist/node/virtual/resolved-support-plugins-client.js +11 -0
  162. package/dist/node/virtual/resolved-support-plugins-collect.d.ts +3 -0
  163. package/dist/node/virtual/resolved-support-plugins-collect.d.ts.map +1 -0
  164. package/dist/node/virtual/resolved-support-plugins-collect.js +11 -0
  165. package/dist/node/virtual/resolved-theme.d.ts +3 -0
  166. package/dist/node/virtual/resolved-theme.d.ts.map +1 -0
  167. package/dist/node/virtual/resolved-theme.js +12 -0
  168. package/dist/node/virtual/story-source.d.ts +3 -0
  169. package/dist/node/virtual/story-source.d.ts.map +1 -0
  170. package/dist/node/virtual/story-source.js +16 -0
  171. package/dist/node/virtual/story.d.ts +3 -0
  172. package/dist/node/virtual/story.d.ts.map +1 -0
  173. package/dist/node/virtual/story.js +7 -0
  174. package/dist/node/virtual/util.d.ts +3 -0
  175. package/dist/node/virtual/util.d.ts.map +1 -0
  176. package/dist/node/virtual/util.js +4 -0
  177. package/dist/node/virtual/vite-plugin.d.ts +4 -0
  178. package/dist/node/virtual/vite-plugin.d.ts.map +1 -0
  179. package/dist/node/virtual/vite-plugin.js +126 -0
  180. package/dist/node/vite.d.ts +9 -0
  181. package/dist/node/vite.d.ts.map +1 -0
  182. package/dist/node/vite.js +337 -0
  183. package/index.d.ts +1 -0
  184. package/package.json +89 -0
  185. package/plugin.d.ts +3 -0
  186. package/plugin.js +11 -0
  187. package/src/controls.ts +1 -0
  188. package/src/node/__tests__/markdown/test1.story.md +7 -0
  189. package/src/node/__tests__/markdown/test2.story.md +5 -0
  190. package/src/node/__tests__/markdown.spec.ts +61 -0
  191. package/src/node/__tests__/tree.spec.ts +109 -0
  192. package/src/node/alias.ts +8 -0
  193. package/src/node/bin.ts +43 -0
  194. package/src/node/build-serialize.ts +62 -0
  195. package/src/node/build.ts +283 -0
  196. package/src/node/builtin-plugins/pinceau-tokens.ts +521 -0
  197. package/src/node/builtin-plugins/tailwind-tokens.ts +536 -0
  198. package/src/node/builtin-plugins/vanilla-support/MountStory.ts +49 -0
  199. package/src/node/builtin-plugins/vanilla-support/RenderStory.ts +164 -0
  200. package/src/node/builtin-plugins/vanilla-support/client.ts +6 -0
  201. package/src/node/builtin-plugins/vanilla-support/collect.ts +43 -0
  202. package/src/node/builtin-plugins/vanilla-support/plugin.ts +35 -0
  203. package/src/node/builtin-plugins/vanilla-support/types.ts +40 -0
  204. package/src/node/builtin-plugins/vanilla-support/vanilla.story.ts +63 -0
  205. package/src/node/collect/index.ts +160 -0
  206. package/src/node/collect/run.ts +9 -0
  207. package/src/node/collect/worker.ts +97 -0
  208. package/src/node/colors.ts +340 -0
  209. package/src/node/commands/build.ts +14 -0
  210. package/src/node/commands/dev.ts +67 -0
  211. package/src/node/commands/preview.ts +22 -0
  212. package/src/node/config.ts +385 -0
  213. package/src/node/context.ts +60 -0
  214. package/src/node/dom/dom-keys.ts +238 -0
  215. package/src/node/dom/env.ts +60 -0
  216. package/src/node/dom/util.ts +83 -0
  217. package/src/node/index.ts +12 -0
  218. package/src/node/load.ts +59 -0
  219. package/src/node/markdown.ts +267 -0
  220. package/src/node/plugin.ts +95 -0
  221. package/src/node/preview.ts +57 -0
  222. package/src/node/search.ts +84 -0
  223. package/src/node/server.ts +235 -0
  224. package/src/node/stories.ts +154 -0
  225. package/src/node/tree.ts +158 -0
  226. package/src/node/util/find-up.ts +24 -0
  227. package/src/node/util/fs.ts +1 -0
  228. package/src/node/util/log.ts +10 -0
  229. package/src/node/util/slugify.ts +26 -0
  230. package/src/node/util/vendors.ts +27 -0
  231. package/src/node/vendors/controls.ts +1 -0
  232. package/src/node/vendors/vue.ts +1 -0
  233. package/src/node/virtual/index.ts +50 -0
  234. package/src/node/virtual/markdown.ts +21 -0
  235. package/src/node/virtual/noop.ts +1 -0
  236. package/src/node/virtual/resolved-commands.ts +42 -0
  237. package/src/node/virtual/resolved-config.ts +12 -0
  238. package/src/node/virtual/resolved-generated-global-setup.ts +25 -0
  239. package/src/node/virtual/resolved-generated-setup-code.ts +7 -0
  240. package/src/node/virtual/resolved-markdown-files.ts +19 -0
  241. package/src/node/virtual/resolved-stories.ts +44 -0
  242. package/src/node/virtual/resolved-support-plugins-client.ts +14 -0
  243. package/src/node/virtual/resolved-support-plugins-collect.ts +14 -0
  244. package/src/node/virtual/resolved-theme.ts +14 -0
  245. package/src/node/virtual/story-source.ts +18 -0
  246. package/src/node/virtual/story.ts +9 -0
  247. package/src/node/virtual/util.ts +5 -0
  248. package/src/node/virtual/vite-plugin.ts +146 -0
  249. package/src/node/vite.ts +379 -0
  250. package/tsconfig.json +44 -0
  251. package/vitest.config.ts +10 -0
@@ -0,0 +1,126 @@
1
+ import { resolve } from 'pathe';
2
+ import { generateDocSearchData, generateTitleSearchData, getSearchDataJS } from '../search.js';
3
+ import * as VirtualFiles from './index.js';
4
+ import { ID_SEPARATOR } from './util.js';
5
+ export function createVirtualFilesPlugin(ctx, isServer) {
6
+ return {
7
+ name: 'histoire-virtual-files',
8
+ async resolveId(id, importer) {
9
+ if (id.startsWith(VirtualFiles.STORIES_ID)) {
10
+ return VirtualFiles.RESOLVED_STORIES_ID;
11
+ }
12
+ if (id.startsWith(VirtualFiles.SETUP_ID)) {
13
+ const setupFileConfig = ctx.config.setupFile;
14
+ if (setupFileConfig) {
15
+ let file;
16
+ if (typeof setupFileConfig === 'string') {
17
+ file = setupFileConfig;
18
+ }
19
+ else if (isServer && 'server' in setupFileConfig) {
20
+ file = setupFileConfig.server;
21
+ }
22
+ else if (!isServer && 'browser' in setupFileConfig) {
23
+ file = setupFileConfig.browser;
24
+ }
25
+ if (file) {
26
+ return this.resolve(resolve(ctx.root, file), importer, {
27
+ skipSelf: true,
28
+ });
29
+ }
30
+ }
31
+ return VirtualFiles.NOOP_ID;
32
+ }
33
+ if (id.startsWith(VirtualFiles.CONFIG_ID)) {
34
+ return VirtualFiles.RESOLVED_CONFIG_ID;
35
+ }
36
+ if (id.startsWith(VirtualFiles.THEME_ID)) {
37
+ return VirtualFiles.RESOLVED_THEME_ID;
38
+ }
39
+ if (id.startsWith(VirtualFiles.SEARCH_TITLE_DATA_ID)) {
40
+ return VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID;
41
+ }
42
+ if (id.startsWith(VirtualFiles.SEARCH_DOCS_DATA_ID)) {
43
+ return VirtualFiles.RESOLVED_SEARCH_DOCS_DATA_ID;
44
+ }
45
+ if (id.startsWith(VirtualFiles.GENERATED_GLOBAL_SETUP)) {
46
+ return VirtualFiles.RESOLVED_GENERATED_GLOBAL_SETUP;
47
+ }
48
+ if (id.startsWith(VirtualFiles.GENERATED_SETUP_CODE)) {
49
+ const [, index] = id.split(ID_SEPARATOR);
50
+ return `${VirtualFiles.RESOLVED_GENERATED_SETUP_CODE}${ID_SEPARATOR}${index}`;
51
+ }
52
+ if (id.startsWith(VirtualFiles.SUPPORT_PLUGINS_CLIENT)) {
53
+ return VirtualFiles.RESOLVED_SUPPORT_PLUGINS_CLIENT;
54
+ }
55
+ if (id.startsWith(VirtualFiles.SUPPORT_PLUGINS_COLLECT)) {
56
+ return VirtualFiles.RESOLVED_SUPPORT_PLUGINS_COLLECT;
57
+ }
58
+ if (id.startsWith(VirtualFiles.MARKDOWN_FILES)) {
59
+ return VirtualFiles.RESOLVED_MARKDOWN_FILES;
60
+ }
61
+ if (id.startsWith(VirtualFiles.COMMANDS)) {
62
+ return VirtualFiles.RESOLVED_COMMANDS;
63
+ }
64
+ if (id.startsWith('virtual:story:')) {
65
+ return `\0${id}`;
66
+ }
67
+ if (id.startsWith('virtual:story-source:')) {
68
+ return `/__resolved__${id}`;
69
+ // @TODO
70
+ // return `\0${id}`
71
+ }
72
+ if (id.startsWith('virtual:md:')) {
73
+ return `/__resolved__${id}`;
74
+ // @TODO
75
+ // return `\0${id}`
76
+ }
77
+ },
78
+ async load(id) {
79
+ if (id === VirtualFiles.RESOLVED_STORIES_ID) {
80
+ return VirtualFiles.resolvedStories(ctx);
81
+ }
82
+ if (id === VirtualFiles.NOOP_ID) {
83
+ return VirtualFiles.noop();
84
+ }
85
+ if (id === VirtualFiles.RESOLVED_CONFIG_ID) {
86
+ return VirtualFiles.resolvedConfig(ctx);
87
+ }
88
+ if (id === VirtualFiles.RESOLVED_THEME_ID) {
89
+ return VirtualFiles.resolvedTheme(ctx);
90
+ }
91
+ if (id === VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID) {
92
+ return getSearchDataJS(await generateTitleSearchData(ctx));
93
+ }
94
+ if (id === VirtualFiles.RESOLVED_SEARCH_DOCS_DATA_ID) {
95
+ return getSearchDataJS(await generateDocSearchData(ctx));
96
+ }
97
+ if (id === VirtualFiles.RESOLVED_GENERATED_GLOBAL_SETUP) {
98
+ return VirtualFiles.resolvedGeneratedGlobalSetup(ctx);
99
+ }
100
+ if (id.startsWith(VirtualFiles.RESOLVED_GENERATED_SETUP_CODE)) {
101
+ return VirtualFiles.resolvedGeneratedSetupCode(ctx, id);
102
+ }
103
+ if (id === VirtualFiles.RESOLVED_SUPPORT_PLUGINS_CLIENT) {
104
+ return VirtualFiles.resolvedSupportPluginsClient(ctx);
105
+ }
106
+ if (id === VirtualFiles.RESOLVED_SUPPORT_PLUGINS_COLLECT) {
107
+ return VirtualFiles.resolvedSupportPluginsCollect(ctx);
108
+ }
109
+ if (id === VirtualFiles.RESOLVED_MARKDOWN_FILES) {
110
+ return VirtualFiles.resolvedMarkdownFiles(ctx);
111
+ }
112
+ if (id === VirtualFiles.RESOLVED_COMMANDS) {
113
+ return VirtualFiles.resolvedCommands(ctx);
114
+ }
115
+ if (id.startsWith('\0virtual:story:')) {
116
+ return VirtualFiles.story(ctx, id);
117
+ }
118
+ if (id.startsWith('/__resolved__virtual:story-source:')) {
119
+ return VirtualFiles.storySource(ctx, id);
120
+ }
121
+ if (id.startsWith('/__resolved__virtual:md:')) {
122
+ return VirtualFiles.markdown(ctx, id);
123
+ }
124
+ },
125
+ };
126
+ }
@@ -0,0 +1,9 @@
1
+ import type { InlineConfig } from 'vite';
2
+ import type { Context } from './context.js';
3
+ export declare function mergeHistoireViteConfig(viteConfig: InlineConfig, ctx: Context): Promise<InlineConfig>;
4
+ export interface ViteConfigWithPlugins {
5
+ viteConfig: InlineConfig;
6
+ viteConfigFile: string | null;
7
+ }
8
+ export declare function getViteConfigWithPlugins(isServer: boolean, ctx: Context): Promise<ViteConfigWithPlugins>;
9
+ //# sourceMappingURL=vite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/node/vite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAe3C,wBAAsB,uBAAuB,CAAC,UAAU,EAAE,YAAY,EAAE,GAAG,EAAE,OAAO,yBAmCnF;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,YAAY,CAAA;IACxB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B;AAED,wBAAsB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA4T9G"}
@@ -0,0 +1,337 @@
1
+ import { createRequire } from 'node:module';
2
+ import { lookup as lookupMime } from 'mrmime';
3
+ import { dirname, join, relative } from 'pathe';
4
+ import { loadConfigFromFile as loadViteConfigFromFile, mergeConfig as mergeViteConfig, } from 'vite';
5
+ import { APP_PATH, TEMP_PATH } from './alias.js';
6
+ import { createMarkdownPlugins } from './markdown.js';
7
+ import { notifyStoryChange } from './stories.js';
8
+ import { createVirtualFilesPlugin } from './virtual/vite-plugin.js';
9
+ const require = createRequire(import.meta.url);
10
+ export async function mergeHistoireViteConfig(viteConfig, ctx) {
11
+ if (ctx.config.vite) {
12
+ const command = ctx.mode === 'dev' ? 'serve' : 'build';
13
+ const overrides = typeof ctx.config.vite === 'function'
14
+ ? await ctx.config.vite(viteConfig, {
15
+ mode: ctx.mode,
16
+ command,
17
+ })
18
+ : ctx.config.vite;
19
+ if (overrides) {
20
+ viteConfig = mergeViteConfig(viteConfig, overrides);
21
+ }
22
+ }
23
+ let flatPlugins = [];
24
+ if (viteConfig.plugins) {
25
+ for (const pluginOption of viteConfig.plugins) {
26
+ const resolvedPluginOption = await pluginOption;
27
+ if (Array.isArray(resolvedPluginOption)) {
28
+ flatPlugins.push(...await Promise.all(resolvedPluginOption));
29
+ }
30
+ else {
31
+ flatPlugins.push(resolvedPluginOption);
32
+ }
33
+ }
34
+ flatPlugins = flatPlugins.filter(Boolean);
35
+ }
36
+ if (ctx.config.viteIgnorePlugins) {
37
+ flatPlugins = flatPlugins.filter(plugin => !ctx.config.viteIgnorePlugins.includes(plugin.name));
38
+ }
39
+ viteConfig.plugins = flatPlugins;
40
+ return viteConfig;
41
+ }
42
+ export async function getViteConfigWithPlugins(isServer, ctx) {
43
+ const userViteConfigFile = await loadViteConfigFromFile({ command: ctx.mode === 'dev' ? 'serve' : 'build', mode: ctx.mode });
44
+ const userViteConfig = mergeViteConfig(userViteConfigFile?.config ?? {}, { server: { port: 6006 } });
45
+ const inlineConfig = await mergeHistoireViteConfig(userViteConfig, ctx);
46
+ const plugins = [];
47
+ const supportPluginAllowPaths = ctx.supportPlugins.flatMap((plugin) => {
48
+ const paths = [ctx.root, import.meta.url];
49
+ const result = new Set();
50
+ for (const suffix of ['', '/client', '/collect']) {
51
+ try {
52
+ const resolved = require.resolve(`${plugin.moduleName}${suffix}`, {
53
+ paths,
54
+ });
55
+ result.add(dirname(resolved));
56
+ }
57
+ catch {
58
+ // Noop
59
+ }
60
+ }
61
+ return Array.from(result);
62
+ });
63
+ function optimizeDeps(deps) {
64
+ const result = [];
65
+ for (const dep of deps) {
66
+ result.push(dep);
67
+ try {
68
+ result.push(dirname(require.resolve(`${dep}/package.json`)));
69
+ }
70
+ catch (e) {
71
+ // Noop
72
+ }
73
+ }
74
+ return result;
75
+ }
76
+ plugins.push({
77
+ name: 'histoire-vite-plugin',
78
+ config(_, { command }) {
79
+ return {
80
+ resolve: {
81
+ dedupe: [
82
+ 'vue',
83
+ ],
84
+ alias: {
85
+ 'histoire-style': join(APP_PATH, process.env.HISTOIRE_DEV ? 'app/style/main.pcss' : 'style.css'),
86
+ },
87
+ ...(isServer
88
+ ? {
89
+ // Force resolving deps like Node.JS resolution algorithm (in case some modules are not loaded with ssr: true e.g. .vue files)
90
+ conditions: ['node'],
91
+ }
92
+ : {}),
93
+ },
94
+ optimizeDeps: {
95
+ entries: [
96
+ `${APP_PATH}/bundle-main.js`,
97
+ `${APP_PATH}/bundle-sandbox.js`,
98
+ ],
99
+ include: optimizeDeps([
100
+ 'flexsearch',
101
+ 'shiki',
102
+ // Shiki dependencies
103
+ 'vscode-oniguruma',
104
+ 'vscode-textmate',
105
+ ]),
106
+ exclude: [
107
+ 'poveste',
108
+ '@poveste/vendors',
109
+ ],
110
+ },
111
+ server: {
112
+ fs: {
113
+ allow: [
114
+ APP_PATH,
115
+ TEMP_PATH,
116
+ ctx.resolvedViteConfig.root,
117
+ process.cwd(),
118
+ ...supportPluginAllowPaths,
119
+ ...process.env.HISTOIRE_DEV
120
+ ? [
121
+ '../../packages/histoire-vendors',
122
+ ]
123
+ : [],
124
+ ],
125
+ },
126
+ watch: {
127
+ ignored: [`!**/node_modules/.histoire/**`, '**/vite.config.*'],
128
+ },
129
+ hmr: command === 'build' ? false : !isServer,
130
+ },
131
+ define: {
132
+ // We need to force this to be able to use `devtoolsRawSetupState`
133
+ '__VUE_PROD_DEVTOOLS__': 'true',
134
+ // Disable warnings
135
+ 'process.env.NODE_ENV': JSON.stringify(isServer ? 'production' : process.env.NODE_ENV ?? 'development'),
136
+ ...!isServer
137
+ ? {
138
+ // Collect flag
139
+ 'process.env.HST_COLLECT': 'false',
140
+ }
141
+ : {},
142
+ '__HST_COLLECT__': isServer,
143
+ },
144
+ cacheDir: isServer ? 'node_modules/.hst-vite-server' : 'node_modules/.hst-vite',
145
+ };
146
+ },
147
+ options() {
148
+ this.meta.histoire = {
149
+ isCollecting: isServer,
150
+ };
151
+ },
152
+ handleHotUpdate(updateContext) {
153
+ const story = ctx.storyFiles.find(file => file.path === updateContext.file);
154
+ if (story) {
155
+ notifyStoryChange(story);
156
+ }
157
+ },
158
+ configureServer(server) {
159
+ let firstMount = true;
160
+ server.ws.on('histoire:mount', () => {
161
+ if (!firstMount) {
162
+ notifyStoryChange();
163
+ }
164
+ firstMount = false;
165
+ });
166
+ server.middlewares.use(async (req, res, next) => {
167
+ if (req.url.startsWith(`${server.config.base}__sandbox`)) {
168
+ res.statusCode = 200;
169
+ let html = `
170
+ <!DOCTYPE html>
171
+ <html>
172
+ <head>
173
+ <title></title>
174
+ <meta charset="utf-8">
175
+ <meta name="viewport" content="width=device-width,initial-scale=1">
176
+ <meta name="description" content="">
177
+ </head>
178
+ <body>
179
+ <div id="app"></div>
180
+ <script>
181
+ // Hide spammy vite messages
182
+ const origConsoleLog = console.log
183
+ console.log = (...args) => {
184
+ if (typeof args[0] !== 'string' || !args[0].startsWith('[vite] connect')) {
185
+ origConsoleLog(...args)
186
+ }
187
+ }
188
+ </script>
189
+ <script type="module" src="/@fs/${APP_PATH}/bundle-sandbox${process.env.HISTOIRE_DEV ? '-dev' : ''}.js"></script>
190
+ </body>
191
+ </html>`;
192
+ // Apply Vite HTML transforms. This injects the Vite HMR client, and
193
+ // also applies HTML transforms from Vite plugins
194
+ html = await server.transformIndexHtml(req.url, html);
195
+ res.setHeader('content-type', 'text/html; charset=UTF-8');
196
+ res.end(html);
197
+ return;
198
+ }
199
+ next();
200
+ });
201
+ // serve our index.html after vite history fallback
202
+ return () => {
203
+ server.middlewares.use(async (req, res, next) => {
204
+ if (req.url.endsWith('.html')) {
205
+ res.statusCode = 200;
206
+ let html = `
207
+ <!DOCTYPE html>
208
+ <html>
209
+ <head>
210
+ <title></title>
211
+ <link rel="icon" href=""/>
212
+ <meta charset="utf-8">
213
+ <meta name="viewport" content="width=device-width,initial-scale=1">
214
+ <meta name="description" content="">
215
+ ${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${server.config.base}${ctx.config.theme.favicon}"/>` : ''}
216
+ </head>
217
+ <body>
218
+ <div id="app"></div>
219
+ <script type="module" src="/@fs/${APP_PATH}/bundle-main${process.env.HISTOIRE_DEV ? '-dev' : ''}.js"></script>
220
+ </body>
221
+ </html>`;
222
+ // Apply Vite HTML transforms. This injects the Vite HMR client, and
223
+ // also applies HTML transforms from Vite plugins
224
+ html = await server.transformIndexHtml(req.url, html);
225
+ res.setHeader('content-type', 'text/html; charset=UTF-8');
226
+ res.end(html);
227
+ return;
228
+ }
229
+ next();
230
+ });
231
+ };
232
+ },
233
+ });
234
+ plugins.push(createVirtualFilesPlugin(ctx, isServer));
235
+ // Replace dev flag
236
+ const flags = {
237
+ '_ctx.__HISTOIRE_DEV__': JSON.stringify(ctx.mode === 'dev'),
238
+ '__HISTOIRE_DEV__': JSON.stringify(ctx.mode === 'dev'),
239
+ };
240
+ plugins.push({
241
+ name: 'histoire:flags',
242
+ enforce: 'pre',
243
+ transform(code, id) {
244
+ if (id.match(/\.(vue|js)($|\?)/)) {
245
+ const original = code;
246
+ for (const flag in flags) {
247
+ code = code.replace(new RegExp(flag, 'g'), flags[flag]);
248
+ }
249
+ if (original !== code)
250
+ return code;
251
+ }
252
+ },
253
+ });
254
+ if (ctx.mode === 'dev') {
255
+ // Dev commands
256
+ plugins.push({
257
+ name: 'histoire:dev-commands',
258
+ configureServer(server) {
259
+ server.ws.on('histoire:dev-command', ({ id, params }) => {
260
+ const command = ctx.registeredCommands.find(c => c.id === id);
261
+ if (command?.serverAction) {
262
+ command.serverAction(params);
263
+ }
264
+ });
265
+ },
266
+ });
267
+ }
268
+ // Markdown
269
+ plugins.push(...await createMarkdownPlugins(ctx));
270
+ if (ctx.mode === 'build') {
271
+ // Add file name in build mode to have components names instead of <Anonymous>
272
+ const include = [/\.vue$/];
273
+ const exclude = [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/];
274
+ plugins.push({
275
+ name: 'histoire-file-name-plugin',
276
+ enforce: 'post',
277
+ transform(code, id) {
278
+ if (exclude.some(r => r.test(id)))
279
+ return;
280
+ if (include.some(r => r.test(id))) {
281
+ const file = relative(ctx.resolvedViteConfig.root, id);
282
+ const index = code.indexOf('export default');
283
+ const result = `${code.substring(0, index)}_sfc_main.__file = '${file}'\n${code.substring(index)}`;
284
+ return result;
285
+ }
286
+ },
287
+ });
288
+ }
289
+ if (process.env.HISTOIRE_DEV && !isServer) {
290
+ plugins.push({
291
+ name: 'histoire-dev-plugin',
292
+ config() {
293
+ // Examples context
294
+ return {
295
+ resolve: {
296
+ alias: [
297
+ ...[
298
+ ['floating-vue/dist/style.css', 'node_modules/floating-vue/dist/style.css'],
299
+ ['floating-vue', 'floating-vue'],
300
+ ['@iconify/vue', 'iconify'],
301
+ ['pinia', 'pinia'],
302
+ ['scroll-into-view-if-needed', 'scroll'],
303
+ ['vue-router', 'vue-router'],
304
+ ['@vueuse/core', 'vue-use'],
305
+ ['vue', 'vue'],
306
+ ].reduce((acc, [name, entry]) => {
307
+ acc.push({
308
+ find: new RegExp(`^${name.replace(/\//g, '\\/')}$`),
309
+ replacement: `@poveste/vendors/${entry}`,
310
+ });
311
+ acc.push({
312
+ find: new RegExp(`^${name.replace(/\//g, '\\/')}\\/`),
313
+ replacement: `@poveste/vendors/${entry}/`,
314
+ });
315
+ return acc;
316
+ }, []),
317
+ { find: /@histoire\/controls$/, replacement: '@poveste/controls/src/index.ts' },
318
+ ],
319
+ },
320
+ };
321
+ },
322
+ });
323
+ }
324
+ for (const plugin of ctx.config.plugins) {
325
+ if (plugin.vitePlugins) {
326
+ await plugin.vitePlugins(plugins);
327
+ }
328
+ }
329
+ const viteConfig = mergeViteConfig(inlineConfig, {
330
+ configFile: false,
331
+ plugins,
332
+ });
333
+ return {
334
+ viteConfig,
335
+ viteConfigFile: userViteConfigFile?.path ?? null,
336
+ };
337
+ }
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/node/index'
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "poveste",
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "description": "A fast story book powered by Vite",
6
+ "author": {
7
+ "name": "Sorin Gitlan"
8
+ },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "url": "https://github.com/poveste-dev/poveste.git",
12
+ "type": "git",
13
+ "directory": "packages/poveste"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/node/index.d.ts",
21
+ "default": "./dist/node/index.js"
22
+ },
23
+ "./client": {
24
+ "types": "./client.d.ts",
25
+ "default": "./client.js"
26
+ },
27
+ "./plugin": {
28
+ "types": "./plugin.d.ts",
29
+ "default": "./plugin.js"
30
+ },
31
+ "./*": "./*"
32
+ },
33
+ "main": "./dist/node/index.js",
34
+ "module": "./dist/node/index.js",
35
+ "types": "./index.d.ts",
36
+ "bin": {
37
+ "poveste": "./bin.mjs",
38
+ "histoire": "./bin.mjs"
39
+ },
40
+ "peerDependencies": {
41
+ "vite": "^7.0.0 || ^8.0.0"
42
+ },
43
+ "dependencies": {
44
+ "@akryum/tinypool": "^0.3.1",
45
+ "@types/markdown-it": "^14.1.2",
46
+ "birpc": "^0.2.19",
47
+ "change-case": "^5.4.4",
48
+ "chokidar": "^4.0.1",
49
+ "connect": "^3.7.0",
50
+ "defu": "^6.1.4",
51
+ "diacritics": "^1.3.0",
52
+ "fs-extra": "^11.2.0",
53
+ "globby": "^14.0.2",
54
+ "gray-matter": "^4.0.3",
55
+ "jiti": "^2.4.1",
56
+ "jsdom": "^27.4.0",
57
+ "markdown-it": "^14.1.0",
58
+ "markdown-it-anchor": "^9.2.0",
59
+ "markdown-it-attrs": "^4.3.0",
60
+ "markdown-it-emoji": "^3.0.0",
61
+ "micromatch": "^4.0.8",
62
+ "mrmime": "^2.0.0",
63
+ "pathe": "^1.1.2",
64
+ "picocolors": "^1.1.1",
65
+ "sade": "^1.8.1",
66
+ "shiki": "^3.0.0",
67
+ "sirv": "^3.0.0",
68
+ "vite-node": "3.2.4",
69
+ "@poveste/app": "^0.1.0",
70
+ "@poveste/controls": "^0.1.0",
71
+ "@poveste/shared": "^0.1.0",
72
+ "@poveste/vendors": "^0.1.0"
73
+ },
74
+ "devDependencies": {
75
+ "@types/fs-extra": "^11.0.4",
76
+ "@types/node": "^22.10.1",
77
+ "esbuild": "^0.27.2",
78
+ "rollup": "^4.28.0",
79
+ "typescript": "5.6.3",
80
+ "vite": "^7.3.0",
81
+ "vitest": "4.0.16"
82
+ },
83
+ "scripts": {
84
+ "build": "rimraf dist && tsc",
85
+ "watch": "tsc -w --sourceMap",
86
+ "test": "vitest run",
87
+ "test:dev": "vitest"
88
+ }
89
+ }
package/plugin.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export function sendEvent(event: string, payload?: any): Promise<any>
2
+
3
+ export function openStory(storyId: string): void
package/plugin.js ADDED
@@ -0,0 +1,11 @@
1
+ export function sendEvent(event, payload) {
2
+ if (window.__HST_PLUGIN_API__) {
3
+ return window.__HST_PLUGIN_API__.sendEvent(event, payload)
4
+ }
5
+ }
6
+
7
+ export function openStory(storyId) {
8
+ if (window.__HST_PLUGIN_API__) {
9
+ return window.__HST_PLUGIN_API__.openStory(storyId)
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ export * from '@poveste/controls'
@@ -0,0 +1,7 @@
1
+ <!-- File should link to test2 file. -->
2
+ <!-- File should return test2 successfully, even though test1 loads before test2. -->
3
+
4
+ # Test1
5
+
6
+ Link to test 2
7
+ [Test2](./test2.story.md)
@@ -0,0 +1,5 @@
1
+ <!-- File should link to test1 file. -->
2
+ # Test2
3
+
4
+ Link to test 1
5
+ [Test1](./test1.story.md)
@@ -0,0 +1,61 @@
1
+ import type { Context } from '../context.js'
2
+ import { createWriteStream, unlinkSync } from 'node:fs'
3
+ import path from 'node:path'
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
5
+ import { createContext } from '../context.js'
6
+ import { createMarkdownFilesWatcher } from '../markdown.js'
7
+ import { watchStories } from '../stories.js'
8
+
9
+ describe('markdown', async () => {
10
+ vi.spyOn(process, 'cwd').mockReturnValue(path.resolve(__dirname, './markdown'))
11
+
12
+ let ctx: Context
13
+ let storyWatcher: Awaited<ReturnType<typeof watchStories>>
14
+
15
+ beforeEach(async () => {
16
+ ctx = await createContext({
17
+ mode: 'dev',
18
+ })
19
+
20
+ // create watch stories to set context root etc.
21
+ storyWatcher = await watchStories(ctx)
22
+ })
23
+
24
+ afterEach(() => {
25
+ storyWatcher.close()
26
+ })
27
+
28
+ it('should not throw error or depend on - resolve order for linking', async () => {
29
+ // FileWatcher should pickup the test markdown files (test1 and test2)
30
+ // test1 links to test2 (issue previously as test1 resolved first)
31
+ // test 2 links to test1
32
+ const { stop } = await createMarkdownFilesWatcher(ctx)
33
+ expect(ctx.markdownFiles.length).toEqual(2)
34
+ stop()
35
+ })
36
+
37
+ it('should render html from md', async () => {
38
+ const { stop } = await createMarkdownFilesWatcher(ctx)
39
+ expect(ctx.markdownFiles[0].html).toContain('<p>')
40
+ stop()
41
+ })
42
+
43
+ it('should throw error on missing [md] story file.', async () => {
44
+ const testFile3 = '/markdown/test3.story.md'
45
+ const writer = createWriteStream(__dirname.concat(testFile3))
46
+ // link to missing file.
47
+ writer.write(
48
+ '<!-- File should link to test1 file. -->\n'
49
+ + '# Test3\n\n'
50
+ + 'Link to test 4\n'
51
+ + '[TEST](./test4.story.md)\n',
52
+ )
53
+ writer.end()
54
+ await new Promise(resolve => writer.on('finish', resolve))
55
+
56
+ // create markdownWatcher and check for error
57
+ await expect(async () => createMarkdownFilesWatcher(ctx)).rejects.toThrowError()
58
+ // delete test file, so failures are removed as well.
59
+ unlinkSync(__dirname.concat(testFile3))
60
+ })
61
+ })