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,15 @@
1
+ import pc from 'picocolors';
2
+ import { createContext } from '../context.js';
3
+ import { startPreview } from '../preview.js';
4
+ export async function previewCommand(options) {
5
+ const ctx = await createContext({
6
+ mode: 'build',
7
+ });
8
+ for (const plugin of ctx.config.plugins) {
9
+ if (plugin.onPreview) {
10
+ await plugin.onPreview();
11
+ }
12
+ }
13
+ const { baseUrl } = await startPreview(options.port, ctx);
14
+ console.log(`Preview server listening on ${pc.cyan(baseUrl)}`);
15
+ }
@@ -0,0 +1,40 @@
1
+ import type { ConfigMode, PovesteConfig } from '@poveste/shared';
2
+ import type { Context } from './context.js';
3
+ export declare function getDefaultConfig(): PovesteConfig;
4
+ export declare const configFileNames: string[];
5
+ export declare function resolveConfigFile(cwd?: string, configFile?: string): string;
6
+ export declare function loadConfigFile(configFile: string): Promise<Partial<PovesteConfig>>;
7
+ export declare const mergeBuildConfig: <Source extends {
8
+ [x: string]: any;
9
+ [x: number]: any;
10
+ [x: symbol]: any;
11
+ }, Defaults extends Array<{
12
+ [x: string]: any;
13
+ [x: number]: any;
14
+ [x: symbol]: any;
15
+ } | (number | boolean | any[] | Record<never, any>)>>(source: Source, ...defaults: Defaults) => import("defu").Defu<Source, Defaults>;
16
+ export declare const mergeConfig: <Source extends {
17
+ [x: string]: any;
18
+ [x: number]: any;
19
+ [x: symbol]: any;
20
+ }, Defaults extends Array<{
21
+ [x: string]: any;
22
+ [x: number]: any;
23
+ [x: symbol]: any;
24
+ } | (number | boolean | any[] | Record<never, any>)>>(source: Source, ...defaults: Defaults) => import("defu").Defu<Source, Defaults>;
25
+ export declare function resolveConfig(cwd: string, mode: ConfigMode, configFile: string): Promise<PovesteConfig>;
26
+ export declare function processConfig(ctx: Context): Promise<void>;
27
+ export declare function defineConfig(config: Partial<PovesteConfig>): Partial<PovesteConfig>;
28
+ declare module 'vite' {
29
+ interface UserConfig {
30
+ /**
31
+ * Poveste configuration
32
+ */
33
+ poveste?: Partial<PovesteConfig>;
34
+ /**
35
+ * @deprecated Use `poveste` instead. Kept for drop-in compat with histoire.
36
+ */
37
+ histoire?: Partial<PovesteConfig>;
38
+ }
39
+ }
40
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/node/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,aAAa,EAEd,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAkB3C,wBAAgB,gBAAgB,IAAI,aAAa,CA2HhD;AAED,eAAO,MAAM,eAAe,UAU3B,CAAA;AAED,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAsB,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ1F;AAED,wBAAsB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAexF;AAED,eAAO,MAAM,gBAAgB;;;;;;;;qIAK3B,CAAA;AAEF,eAAO,MAAM,WAAW;;;;;;;;qIA8DtB,CAAA;AAEF,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAsB,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAa7H;AA2BD,wBAAsB,aAAa,CAAC,GAAG,EAAE,OAAO,iBAoE/C;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,0BAE1D;AAED,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAU,UAAU;QAClB;;WAEG;QACH,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;QAChC;;WAEG;QACH,QAAQ,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;KAClC;CACF"}
@@ -0,0 +1,330 @@
1
+ import fs from 'node:fs';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { createDefu } from 'defu';
4
+ import { createJiti } from 'jiti';
5
+ import path from 'pathe';
6
+ import pc from 'picocolors';
7
+ import { mergeConfig as mergeViteConfig, resolveConfig as resolveViteConfig, } from 'vite';
8
+ import { tailwindTokens } from './builtin-plugins/tailwind-tokens.js';
9
+ import { vanillaSupport } from './builtin-plugins/vanilla-support/plugin.js';
10
+ import { defaultColors } from './colors.js';
11
+ import { findUp } from './util/find-up.js';
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ export function getDefaultConfig() {
14
+ return {
15
+ plugins: [
16
+ vanillaSupport(),
17
+ tailwindTokens(),
18
+ ],
19
+ outDir: '.histoire/dist',
20
+ storyMatch: [
21
+ '**/*.story.vue',
22
+ '**/*.story.svelte',
23
+ ],
24
+ storyIgnored: [
25
+ '**/node_modules/**',
26
+ '**/dist/**',
27
+ ],
28
+ supportMatch: [],
29
+ tree: {
30
+ file: 'title',
31
+ order: 'asc',
32
+ },
33
+ theme: {
34
+ title: 'Poveste',
35
+ colors: {
36
+ primary: defaultColors.emerald,
37
+ gray: defaultColors.zinc,
38
+ },
39
+ defaultColorScheme: 'auto',
40
+ storeColorScheme: true,
41
+ darkClass: 'dark',
42
+ },
43
+ responsivePresets: [
44
+ {
45
+ label: 'Mobile (Small)',
46
+ width: 320,
47
+ height: 560,
48
+ },
49
+ {
50
+ label: 'Mobile (Medium)',
51
+ width: 360,
52
+ height: 640,
53
+ },
54
+ {
55
+ label: 'Mobile (Large)',
56
+ width: 414,
57
+ height: 896,
58
+ },
59
+ {
60
+ label: 'Tablet',
61
+ width: 768,
62
+ height: 1024,
63
+ },
64
+ {
65
+ label: 'Laptop (Small)',
66
+ width: 1024,
67
+ height: null,
68
+ },
69
+ {
70
+ label: 'Laptop (Large)',
71
+ width: 1366,
72
+ height: null,
73
+ },
74
+ {
75
+ label: 'Desktop',
76
+ width: 1920,
77
+ height: null,
78
+ },
79
+ {
80
+ label: '4K',
81
+ width: 3840,
82
+ height: null,
83
+ },
84
+ ],
85
+ backgroundPresets: [
86
+ {
87
+ label: 'Transparent',
88
+ color: 'transparent',
89
+ contrastColor: '#333',
90
+ },
91
+ {
92
+ label: 'White',
93
+ color: '#fff',
94
+ contrastColor: '#333',
95
+ },
96
+ {
97
+ label: 'Light gray',
98
+ color: '#aaa',
99
+ contrastColor: '#000',
100
+ },
101
+ {
102
+ label: 'Dark gray',
103
+ color: '#333',
104
+ contrastColor: '#fff',
105
+ },
106
+ {
107
+ label: 'Black',
108
+ color: '#000',
109
+ contrastColor: '#eee',
110
+ },
111
+ ],
112
+ sandboxDarkClass: 'dark',
113
+ routerMode: 'history',
114
+ build: {
115
+ excludeFromVendorsChunk: [],
116
+ },
117
+ vite: (config) => {
118
+ // Remove vite:legacy plugins https://github.com/histoire-dev/histoire/issues/156
119
+ const index = config.plugins?.findIndex(plugin => Array.isArray(plugin)
120
+ && typeof plugin[0] === 'object'
121
+ && !Array.isArray(plugin[0])
122
+ // @ts-expect-error could have no property 'name'
123
+ && plugin[0].name?.startsWith('vite:legacy'));
124
+ if (index !== -1) {
125
+ config.plugins?.splice(index, 1);
126
+ }
127
+ return {
128
+ build: {
129
+ lib: false,
130
+ },
131
+ };
132
+ },
133
+ viteIgnorePlugins: [],
134
+ };
135
+ }
136
+ export const configFileNames = [
137
+ 'poveste.config.ts',
138
+ 'poveste.config.js',
139
+ '.poveste.ts',
140
+ '.poveste.js',
141
+ // Back-compat with histoire — existing projects keep working as a drop-in.
142
+ 'histoire.config.ts',
143
+ 'histoire.config.js',
144
+ '.histoire.ts',
145
+ '.histoire.js',
146
+ ];
147
+ export function resolveConfigFile(cwd = process.cwd(), configFile) {
148
+ if (configFile) {
149
+ // explicit config path is always resolved from cwd
150
+ return path.resolve(configFile);
151
+ }
152
+ else {
153
+ return findUp(cwd, configFileNames);
154
+ }
155
+ }
156
+ export async function loadConfigFile(configFile) {
157
+ try {
158
+ const jiti = createJiti(__filename, {
159
+ moduleCache: false,
160
+ });
161
+ const result = await jiti.import(configFile, { default: true });
162
+ if (!result) {
163
+ throw new Error(`Expected default export in ${configFile}`);
164
+ }
165
+ return result;
166
+ }
167
+ catch (e) {
168
+ console.error(pc.red(`Error while loading ${configFile}`));
169
+ throw e;
170
+ }
171
+ }
172
+ export const mergeBuildConfig = createDefu((obj, key, value) => {
173
+ if (obj[key] && key === 'excludeFromVendorsChunk') {
174
+ obj[key] = [...obj[key], ...value];
175
+ return true;
176
+ }
177
+ });
178
+ export const mergeConfig = createDefu((obj, key, value) => {
179
+ if (obj[key] && key === 'vite') {
180
+ const initialValue = obj[key];
181
+ // Convert to functions
182
+ const initialFn = typeof initialValue === 'function' ? initialValue : async () => initialValue;
183
+ const valueFn = typeof value === 'function' ? value : async () => value;
184
+ obj[key] = async (...args) => {
185
+ // `mergeViteConfig` doesn't accept functions so we need to call them
186
+ const initialResult = await initialFn(...args);
187
+ const valueResult = await valueFn(...args);
188
+ return mergeViteConfig(initialResult, valueResult);
189
+ };
190
+ return true;
191
+ }
192
+ if (obj[key] && key === 'plugins') {
193
+ const initialValue = obj[key];
194
+ const newValue = obj[key] = [...value];
195
+ const nameMap = newValue.reduce((map, plugin) => {
196
+ map[plugin.name] = true;
197
+ return map;
198
+ }, {});
199
+ for (const plugin of initialValue) {
200
+ if (!nameMap[plugin.name]) {
201
+ newValue.unshift(plugin);
202
+ }
203
+ }
204
+ return true;
205
+ }
206
+ if (obj[key] && key === 'setupCode') {
207
+ obj[key] = [...obj[key], ...value];
208
+ return true;
209
+ }
210
+ if (obj[key] && key === 'supportMatch') {
211
+ for (const item of value) {
212
+ const existing = obj[key].find(p => p.id === item.id);
213
+ if (existing) {
214
+ existing.patterns = [...existing.patterns, ...item.patterns];
215
+ existing.pluginIds = [...existing.pluginIds, ...item.pluginIds];
216
+ }
217
+ else {
218
+ obj[key].push(item);
219
+ }
220
+ }
221
+ return true;
222
+ }
223
+ if (obj[key] && key === 'build') {
224
+ obj[key] = mergeBuildConfig(obj[key], value);
225
+ return true;
226
+ }
227
+ // By default, arrays should be replaced
228
+ if (obj[key] && Array.isArray(obj[key])) {
229
+ obj[key] = value;
230
+ return true;
231
+ }
232
+ });
233
+ export async function resolveConfig(cwd = process.cwd(), mode, configFile) {
234
+ let result;
235
+ const resolvedConfigFile = resolveConfigFile(cwd, configFile);
236
+ if (resolvedConfigFile) {
237
+ result = await loadConfigFile(resolvedConfigFile);
238
+ }
239
+ const viteConfig = await resolveViteConfig({}, 'serve');
240
+ const vitePovesteConfig = (viteConfig.poveste ?? viteConfig.histoire ?? {});
241
+ const preUserConfig = mergeConfig(result, vitePovesteConfig);
242
+ const processedDefaultConfig = await processDefaultConfig(getDefaultConfig(), preUserConfig, mode, cwd);
243
+ return resolveConfigPlugins(mergeConfig(preUserConfig, processedDefaultConfig), mode);
244
+ }
245
+ async function resolveConfigPlugins(config, mode) {
246
+ for (const plugin of config.plugins) {
247
+ if (plugin.config) {
248
+ const result = await plugin.config(config, mode);
249
+ if (result) {
250
+ config = mergeConfig(result, config);
251
+ }
252
+ }
253
+ }
254
+ return config;
255
+ }
256
+ async function processDefaultConfig(defaultConfig, preUserConfig, mode, _cwd) {
257
+ // Apply plugins
258
+ for (const plugin of [...defaultConfig.plugins, ...preUserConfig.plugins ?? []]) {
259
+ if (plugin.defaultConfig) {
260
+ const result = await plugin.defaultConfig(defaultConfig, mode);
261
+ if (result) {
262
+ defaultConfig = mergeConfig(result, defaultConfig);
263
+ }
264
+ }
265
+ }
266
+ return defaultConfig;
267
+ }
268
+ export async function processConfig(ctx) {
269
+ const { config, root } = ctx;
270
+ // Resolve files paths
271
+ const resolveFsPath = (file, force = false) => {
272
+ if (force || file.startsWith('./') || file.startsWith('../')) {
273
+ return path.resolve(root, file);
274
+ }
275
+ return file;
276
+ };
277
+ const fileCheck = (file, resolvedFile, configPathForError) => {
278
+ if (!file.startsWith('http') && !file.startsWith('@') && !fs.existsSync(resolvedFile)) {
279
+ console.warn(pc.yellow(`Poveste config: ${configPathForError} file ${file} does not exist (resolved to ${resolvedFile}), check for typos in the path`));
280
+ }
281
+ };
282
+ config.outDir = resolveFsPath(config.outDir, true);
283
+ // Theme
284
+ if (config.theme?.logo?.square) {
285
+ const file = config.theme.logo.square;
286
+ config.theme.logo.square = resolveFsPath(file);
287
+ fileCheck(file, config.theme.logo.square, 'theme.logo.square');
288
+ }
289
+ if (config.theme?.logo?.light) {
290
+ const file = config.theme.logo.light;
291
+ config.theme.logo.light = resolveFsPath(file);
292
+ fileCheck(file, config.theme.logo.light, 'theme.logo.light');
293
+ }
294
+ if (config.theme?.logo?.dark) {
295
+ const file = config.theme.logo.dark;
296
+ config.theme.logo.dark = resolveFsPath(file);
297
+ fileCheck(file, config.theme.logo.dark, 'theme.logo.dark');
298
+ }
299
+ if (config.theme?.favicon) {
300
+ let file = config.theme.favicon;
301
+ if (file.startsWith('/')) {
302
+ file = file.slice(1);
303
+ }
304
+ if (!file.startsWith('http')) {
305
+ const publicDir = path.resolve(ctx.resolvedViteConfig.root, ctx.resolvedViteConfig.publicDir);
306
+ // Resolve URL path
307
+ if (file.startsWith('./') || file.startsWith('../')) {
308
+ const resolvedFile = resolveFsPath(file, true);
309
+ const relativeFile = path.relative(publicDir, resolvedFile);
310
+ if (relativeFile.startsWith('..')) {
311
+ throw new Error(pc.red(`Poveste config: theme.favicon seems to target a file that is not in the vite 'public' directory: ${file} (resolved as ${resolvedFile})`));
312
+ }
313
+ if (!fs.existsSync(resolvedFile)) {
314
+ throw new Error(pc.red(`Poveste config: theme.favicon seems to target a file that does not exist: ${file} (resolved as ${resolvedFile})`));
315
+ }
316
+ config.theme.favicon = relativeFile;
317
+ }
318
+ else {
319
+ // Check if URL path is valid
320
+ const resolvedFile = path.resolve(publicDir, file);
321
+ if (!fs.existsSync(resolvedFile)) {
322
+ throw new Error(pc.red(`Poveste config: theme.favicon seems to target a file that does not exist: ${file} (resolved as ${resolvedFile}).\nThe favicon file should be placed in the vite 'public' directory.\nExample: if the file is in <project>/public/img/favicon.ico, you can put 'img/favicon.ico' or './public/img/favicon.ico'.`));
323
+ }
324
+ }
325
+ }
326
+ }
327
+ }
328
+ export function defineConfig(config) {
329
+ return config;
330
+ }
@@ -0,0 +1,18 @@
1
+ import type { ConfigMode, FinalSupportPlugin, PluginCommand, PovesteConfig, ServerMarkdownFile, ServerStoryFile } from '@poveste/shared';
2
+ import type { ResolvedConfig } from 'vite';
3
+ export interface Context {
4
+ root: string;
5
+ config: PovesteConfig;
6
+ resolvedViteConfig: ResolvedConfig;
7
+ mode: ConfigMode;
8
+ storyFiles: ServerStoryFile[];
9
+ supportPlugins: FinalSupportPlugin[];
10
+ markdownFiles: ServerMarkdownFile[];
11
+ registeredCommands?: PluginCommand[];
12
+ }
13
+ export interface CreateContextOptions {
14
+ mode: Context['mode'];
15
+ configFile?: string;
16
+ }
17
+ export declare function createContext(options: CreateContextOptions): Promise<Context>;
18
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/node/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,eAAe,EAChB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAK1C,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,aAAa,CAAA;IACrB,kBAAkB,EAAE,cAAc,CAAA;IAClC,IAAI,EAAE,UAAU,CAAA;IAChB,UAAU,EAAE,eAAe,EAAE,CAAA;IAC7B,cAAc,EAAE,kBAAkB,EAAE,CAAA;IACpC,aAAa,EAAE,kBAAkB,EAAE,CAAA;IACnC,kBAAkB,CAAC,EAAE,aAAa,EAAE,CAAA;CACrC;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,CA8BnF"}
@@ -0,0 +1,28 @@
1
+ import { resolveConfig as resolveViteConfig } from 'vite';
2
+ import { processConfig, resolveConfig } from './config.js';
3
+ import { mergeHistoireViteConfig } from './vite.js';
4
+ export async function createContext(options) {
5
+ const config = await resolveConfig(process.cwd(), options.mode, options.configFile);
6
+ const command = options.mode === 'dev' ? 'serve' : 'build';
7
+ const viteConfig = await resolveViteConfig({}, command);
8
+ const supportPlugins = config.plugins.map(p => p.supportPlugin).filter(Boolean);
9
+ const ctx = {
10
+ root: viteConfig.root,
11
+ config,
12
+ resolvedViteConfig: null,
13
+ mode: options.mode,
14
+ storyFiles: [],
15
+ supportPlugins,
16
+ markdownFiles: [],
17
+ registeredCommands: [],
18
+ };
19
+ ctx.resolvedViteConfig = await mergeHistoireViteConfig(viteConfig, ctx);
20
+ await processConfig(ctx);
21
+ // List commands
22
+ for (const plugin of ctx.config.plugins) {
23
+ if (plugin.commands?.length) {
24
+ ctx.registeredCommands.push(...plugin.commands);
25
+ }
26
+ }
27
+ return ctx;
28
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Code from vitest https://github.com/antfu-sponsors/vitest/blob/6066fdbf3b1d17021aac20591b5ef3603056fa5f/src/integrations/dom/keys.ts by @antfu and @patak
3
+ */
4
+ export declare const KEYS: string[];
5
+ //# sourceMappingURL=dom-keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom-keys.d.ts","sourceRoot":"","sources":["../../../src/node/dom/dom-keys.ts"],"names":[],"mappings":"AAAA;;GAEG;AA2OH,eAAO,MAAM,IAAI,UAAiC,CAAA"}
@@ -0,0 +1,233 @@
1
+ /**
2
+ * Code from vitest https://github.com/antfu-sponsors/vitest/blob/6066fdbf3b1d17021aac20591b5ef3603056fa5f/src/integrations/dom/keys.ts by @antfu and @patak
3
+ */
4
+ // SEE https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/interfaces.js
5
+ const LIVING_KEYS = [
6
+ 'DOMException',
7
+ 'URL',
8
+ 'URLSearchParams',
9
+ 'EventTarget',
10
+ 'NamedNodeMap',
11
+ 'Node',
12
+ 'Attr',
13
+ 'Element',
14
+ 'DocumentFragment',
15
+ 'DOMImplementation',
16
+ 'Document',
17
+ 'XMLDocument',
18
+ 'CharacterData',
19
+ 'Text',
20
+ 'CDATASection',
21
+ 'ProcessingInstruction',
22
+ 'Comment',
23
+ 'DocumentType',
24
+ 'NodeList',
25
+ 'RadioNodeList',
26
+ 'HTMLCollection',
27
+ 'HTMLOptionsCollection',
28
+ 'DOMStringMap',
29
+ 'DOMTokenList',
30
+ 'StyleSheetList',
31
+ 'HTMLElement',
32
+ 'HTMLHeadElement',
33
+ 'HTMLTitleElement',
34
+ 'HTMLBaseElement',
35
+ 'HTMLLinkElement',
36
+ 'HTMLMetaElement',
37
+ 'HTMLStyleElement',
38
+ 'HTMLBodyElement',
39
+ 'HTMLHeadingElement',
40
+ 'HTMLParagraphElement',
41
+ 'HTMLHRElement',
42
+ 'HTMLPreElement',
43
+ 'HTMLUListElement',
44
+ 'HTMLOListElement',
45
+ 'HTMLLIElement',
46
+ 'HTMLMenuElement',
47
+ 'HTMLDListElement',
48
+ 'HTMLDivElement',
49
+ 'HTMLAnchorElement',
50
+ 'HTMLAreaElement',
51
+ 'HTMLBRElement',
52
+ 'HTMLButtonElement',
53
+ 'HTMLCanvasElement',
54
+ 'HTMLDataElement',
55
+ 'HTMLDataListElement',
56
+ 'HTMLDetailsElement',
57
+ 'HTMLDialogElement',
58
+ 'HTMLDirectoryElement',
59
+ 'HTMLFieldSetElement',
60
+ 'HTMLFontElement',
61
+ 'HTMLFormElement',
62
+ 'HTMLHtmlElement',
63
+ 'HTMLImageElement',
64
+ 'HTMLInputElement',
65
+ 'HTMLLabelElement',
66
+ 'HTMLLegendElement',
67
+ 'HTMLMapElement',
68
+ 'HTMLMarqueeElement',
69
+ 'HTMLMediaElement',
70
+ 'HTMLMeterElement',
71
+ 'HTMLModElement',
72
+ 'HTMLOptGroupElement',
73
+ 'HTMLOptionElement',
74
+ 'HTMLOutputElement',
75
+ 'HTMLPictureElement',
76
+ 'HTMLProgressElement',
77
+ 'HTMLQuoteElement',
78
+ 'HTMLScriptElement',
79
+ 'HTMLSelectElement',
80
+ 'HTMLSlotElement',
81
+ 'HTMLSourceElement',
82
+ 'HTMLSpanElement',
83
+ 'HTMLTableCaptionElement',
84
+ 'HTMLTableCellElement',
85
+ 'HTMLTableColElement',
86
+ 'HTMLTableElement',
87
+ 'HTMLTimeElement',
88
+ 'HTMLTableRowElement',
89
+ 'HTMLTableSectionElement',
90
+ 'HTMLTemplateElement',
91
+ 'HTMLTextAreaElement',
92
+ 'HTMLUnknownElement',
93
+ 'HTMLFrameElement',
94
+ 'HTMLFrameSetElement',
95
+ 'HTMLIFrameElement',
96
+ 'HTMLEmbedElement',
97
+ 'HTMLObjectElement',
98
+ 'HTMLParamElement',
99
+ 'HTMLVideoElement',
100
+ 'HTMLAudioElement',
101
+ 'HTMLTrackElement',
102
+ 'HTMLFormControlsCollection',
103
+ 'SVGElement',
104
+ 'SVGGraphicsElement',
105
+ 'SVGSVGElement',
106
+ 'SVGTitleElement',
107
+ 'SVGAnimatedString',
108
+ 'SVGNumber',
109
+ 'SVGStringList',
110
+ 'Event',
111
+ 'CloseEvent',
112
+ 'CustomEvent',
113
+ 'MessageEvent',
114
+ 'ErrorEvent',
115
+ 'HashChangeEvent',
116
+ 'PopStateEvent',
117
+ 'StorageEvent',
118
+ 'ProgressEvent',
119
+ 'PageTransitionEvent',
120
+ 'UIEvent',
121
+ 'FocusEvent',
122
+ 'InputEvent',
123
+ 'MouseEvent',
124
+ 'KeyboardEvent',
125
+ 'TouchEvent',
126
+ 'CompositionEvent',
127
+ 'WheelEvent',
128
+ 'BarProp',
129
+ 'External',
130
+ 'Location',
131
+ 'History',
132
+ 'Screen',
133
+ 'Crypto',
134
+ 'Performance',
135
+ 'Navigator',
136
+ 'PluginArray',
137
+ 'MimeTypeArray',
138
+ 'Plugin',
139
+ 'MimeType',
140
+ 'FileReader',
141
+ 'Blob',
142
+ 'File',
143
+ 'FileList',
144
+ 'ValidityState',
145
+ 'DOMParser',
146
+ 'XMLSerializer',
147
+ 'FormData',
148
+ 'XMLHttpRequestEventTarget',
149
+ 'XMLHttpRequestUpload',
150
+ 'XMLHttpRequest',
151
+ 'WebSocket',
152
+ 'NodeFilter',
153
+ 'NodeIterator',
154
+ 'TreeWalker',
155
+ 'AbstractRange',
156
+ 'Range',
157
+ 'StaticRange',
158
+ 'Selection',
159
+ 'Storage',
160
+ 'CustomElementRegistry',
161
+ 'ShadowRoot',
162
+ 'MutationObserver',
163
+ 'MutationRecord',
164
+ 'Headers',
165
+ 'AbortController',
166
+ 'AbortSignal',
167
+ 'ArrayBuffer',
168
+ // not specified in docs, but is available
169
+ 'Image',
170
+ 'Audio',
171
+ 'Option',
172
+ ];
173
+ const OTHER_KEYS = [
174
+ 'addEventListener',
175
+ 'alert',
176
+ 'blur',
177
+ 'cancelAnimationFrame',
178
+ /* 'clearInterval', */
179
+ /* 'clearTimeout', */
180
+ 'close',
181
+ 'confirm',
182
+ /* 'console', */
183
+ 'createPopup',
184
+ 'dispatchEvent',
185
+ 'document',
186
+ 'focus',
187
+ 'frames',
188
+ 'getComputedStyle',
189
+ 'history',
190
+ 'innerHeight',
191
+ 'innerWidth',
192
+ 'length',
193
+ 'location',
194
+ 'matchMedia',
195
+ 'moveBy',
196
+ 'moveTo',
197
+ 'name',
198
+ 'navigator',
199
+ 'open',
200
+ 'outerHeight',
201
+ 'outerWidth',
202
+ 'pageXOffset',
203
+ 'pageYOffset',
204
+ 'parent',
205
+ 'postMessage',
206
+ 'print',
207
+ 'prompt',
208
+ 'removeEventListener',
209
+ 'requestAnimationFrame',
210
+ 'resizeBy',
211
+ 'resizeTo',
212
+ 'screen',
213
+ 'screenLeft',
214
+ 'screenTop',
215
+ 'screenX',
216
+ 'screenY',
217
+ 'scroll',
218
+ 'scrollBy',
219
+ 'scrollLeft',
220
+ 'scrollTo',
221
+ 'scrollTop',
222
+ 'scrollX',
223
+ 'scrollY',
224
+ 'self',
225
+ /* 'setInterval', */
226
+ /* 'setTimeout', */
227
+ 'stop',
228
+ /* 'toString', */
229
+ 'top',
230
+ 'Window',
231
+ 'window',
232
+ ];
233
+ export const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
@@ -0,0 +1,5 @@
1
+ export declare function createDomEnv(): {
2
+ window: Window & typeof globalThis;
3
+ destroy: () => void;
4
+ };
5
+ //# sourceMappingURL=env.d.ts.map