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.
- package/LICENSE +22 -0
- package/README.md +11 -0
- package/bin.mjs +4 -0
- package/client.d.ts +19 -0
- package/client.js +15 -0
- package/dist/controls.d.ts +2 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +1 -0
- package/dist/node/alias.d.ts +3 -0
- package/dist/node/alias.d.ts.map +1 -0
- package/dist/node/alias.js +5 -0
- package/dist/node/bin.d.ts +2 -0
- package/dist/node/bin.d.ts.map +1 -0
- package/dist/node/bin.js +35 -0
- package/dist/node/build-serialize.d.ts +22 -0
- package/dist/node/build-serialize.d.ts.map +1 -0
- package/dist/node/build-serialize.js +36 -0
- package/dist/node/build.d.ts +3 -0
- package/dist/node/build.d.ts.map +1 -0
- package/dist/node/build.js +228 -0
- package/dist/node/builtin-plugins/pinceau-tokens.d.ts +7 -0
- package/dist/node/builtin-plugins/pinceau-tokens.d.ts.map +1 -0
- package/dist/node/builtin-plugins/pinceau-tokens.js +505 -0
- package/dist/node/builtin-plugins/tailwind-tokens.d.ts +6 -0
- package/dist/node/builtin-plugins/tailwind-tokens.d.ts.map +1 -0
- package/dist/node/builtin-plugins/tailwind-tokens.js +523 -0
- package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts +15 -0
- package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/MountStory.js +39 -0
- package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts +39 -0
- package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/RenderStory.js +129 -0
- package/dist/node/builtin-plugins/vanilla-support/client.d.ts +4 -0
- package/dist/node/builtin-plugins/vanilla-support/client.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/client.js +5 -0
- package/dist/node/builtin-plugins/vanilla-support/collect.d.ts +3 -0
- package/dist/node/builtin-plugins/vanilla-support/collect.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/collect.js +33 -0
- package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts +3 -0
- package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/plugin.js +29 -0
- package/dist/node/builtin-plugins/vanilla-support/types.d.ts +36 -0
- package/dist/node/builtin-plugins/vanilla-support/types.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/types.js +3 -0
- package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts +4 -0
- package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/vanilla.story.js +55 -0
- package/dist/node/collect/index.d.ts +14 -0
- package/dist/node/collect/index.d.ts.map +1 -0
- package/dist/node/collect/index.js +129 -0
- package/dist/node/collect/run.d.ts +3 -0
- package/dist/node/collect/run.d.ts.map +1 -0
- package/dist/node/collect/run.js +7 -0
- package/dist/node/collect/worker.d.ts +14 -0
- package/dist/node/collect/worker.d.ts.map +1 -0
- package/dist/node/collect/worker.js +64 -0
- package/dist/node/colors.d.ts +287 -0
- package/dist/node/colors.d.ts.map +1 -0
- package/dist/node/colors.js +324 -0
- package/dist/node/commands/build.d.ts +5 -0
- package/dist/node/commands/build.d.ts.map +1 -0
- package/dist/node/commands/build.js +9 -0
- package/dist/node/commands/dev.d.ts +8 -0
- package/dist/node/commands/dev.d.ts.map +1 -0
- package/dist/node/commands/dev.js +52 -0
- package/dist/node/commands/preview.d.ts +5 -0
- package/dist/node/commands/preview.d.ts.map +1 -0
- package/dist/node/commands/preview.js +15 -0
- package/dist/node/config.d.ts +40 -0
- package/dist/node/config.d.ts.map +1 -0
- package/dist/node/config.js +330 -0
- package/dist/node/context.d.ts +18 -0
- package/dist/node/context.d.ts.map +1 -0
- package/dist/node/context.js +28 -0
- package/dist/node/dom/dom-keys.d.ts +5 -0
- package/dist/node/dom/dom-keys.d.ts.map +1 -0
- package/dist/node/dom/dom-keys.js +233 -0
- package/dist/node/dom/env.d.ts +5 -0
- package/dist/node/dom/env.d.ts.map +1 -0
- package/dist/node/dom/env.js +47 -0
- package/dist/node/dom/util.d.ts +11 -0
- package/dist/node/dom/util.d.ts.map +1 -0
- package/dist/node/dom/util.js +65 -0
- package/dist/node/index.d.ts +12 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +4 -0
- package/dist/node/load.d.ts +9 -0
- package/dist/node/load.d.ts.map +1 -0
- package/dist/node/load.js +42 -0
- package/dist/node/markdown.d.ts +11 -0
- package/dist/node/markdown.d.ts.map +1 -0
- package/dist/node/markdown.js +228 -0
- package/dist/node/plugin.d.ts +42 -0
- package/dist/node/plugin.d.ts.map +1 -0
- package/dist/node/plugin.js +67 -0
- package/dist/node/preview.d.ts +8 -0
- package/dist/node/preview.d.ts.map +1 -0
- package/dist/node/preview.js +41 -0
- package/dist/node/search.d.ts +17 -0
- package/dist/node/search.d.ts.map +1 -0
- package/dist/node/search.js +72 -0
- package/dist/node/server.d.ts +12 -0
- package/dist/node/server.d.ts.map +1 -0
- package/dist/node/server.js +189 -0
- package/dist/node/stories.d.ts +22 -0
- package/dist/node/stories.d.ts.map +1 -0
- package/dist/node/stories.js +125 -0
- package/dist/node/tree.d.ts +4 -0
- package/dist/node/tree.d.ts.map +1 -0
- package/dist/node/tree.js +117 -0
- package/dist/node/util/find-up.d.ts +2 -0
- package/dist/node/util/find-up.d.ts.map +1 -0
- package/dist/node/util/find-up.js +20 -0
- package/dist/node/util/fs.d.ts +2 -0
- package/dist/node/util/fs.d.ts.map +1 -0
- package/dist/node/util/fs.js +1 -0
- package/dist/node/util/log.d.ts +2 -0
- package/dist/node/util/log.d.ts.map +1 -0
- package/dist/node/util/log.js +9 -0
- package/dist/node/util/slugify.d.ts +2 -0
- package/dist/node/util/slugify.d.ts.map +1 -0
- package/dist/node/util/slugify.js +22 -0
- package/dist/node/util/vendors.d.ts +3 -0
- package/dist/node/util/vendors.d.ts.map +1 -0
- package/dist/node/util/vendors.js +22 -0
- package/dist/node/vendors/controls.d.ts +2 -0
- package/dist/node/vendors/controls.d.ts.map +1 -0
- package/dist/node/vendors/controls.js +1 -0
- package/dist/node/vendors/vue.d.ts +2 -0
- package/dist/node/vendors/vue.d.ts.map +1 -0
- package/dist/node/vendors/vue.js +1 -0
- package/dist/node/virtual/index.d.ts +38 -0
- package/dist/node/virtual/index.d.ts.map +1 -0
- package/dist/node/virtual/index.js +49 -0
- package/dist/node/virtual/markdown.d.ts +3 -0
- package/dist/node/virtual/markdown.d.ts.map +1 -0
- package/dist/node/virtual/markdown.js +19 -0
- package/dist/node/virtual/noop.d.ts +2 -0
- package/dist/node/virtual/noop.d.ts.map +1 -0
- package/dist/node/virtual/noop.js +1 -0
- package/dist/node/virtual/resolved-commands.d.ts +3 -0
- package/dist/node/virtual/resolved-commands.d.ts.map +1 -0
- package/dist/node/virtual/resolved-commands.js +32 -0
- package/dist/node/virtual/resolved-config.d.ts +3 -0
- package/dist/node/virtual/resolved-config.d.ts.map +1 -0
- package/dist/node/virtual/resolved-config.js +10 -0
- package/dist/node/virtual/resolved-generated-global-setup.d.ts +3 -0
- package/dist/node/virtual/resolved-generated-global-setup.d.ts.map +1 -0
- package/dist/node/virtual/resolved-generated-global-setup.js +23 -0
- package/dist/node/virtual/resolved-generated-setup-code.d.ts +3 -0
- package/dist/node/virtual/resolved-generated-setup-code.d.ts.map +1 -0
- package/dist/node/virtual/resolved-generated-setup-code.js +5 -0
- package/dist/node/virtual/resolved-markdown-files.d.ts +3 -0
- package/dist/node/virtual/resolved-markdown-files.d.ts.map +1 -0
- package/dist/node/virtual/resolved-markdown-files.js +17 -0
- package/dist/node/virtual/resolved-stories.d.ts +3 -0
- package/dist/node/virtual/resolved-stories.d.ts.map +1 -0
- package/dist/node/virtual/resolved-stories.js +42 -0
- package/dist/node/virtual/resolved-support-plugins-client.d.ts +3 -0
- package/dist/node/virtual/resolved-support-plugins-client.d.ts.map +1 -0
- package/dist/node/virtual/resolved-support-plugins-client.js +11 -0
- package/dist/node/virtual/resolved-support-plugins-collect.d.ts +3 -0
- package/dist/node/virtual/resolved-support-plugins-collect.d.ts.map +1 -0
- package/dist/node/virtual/resolved-support-plugins-collect.js +11 -0
- package/dist/node/virtual/resolved-theme.d.ts +3 -0
- package/dist/node/virtual/resolved-theme.d.ts.map +1 -0
- package/dist/node/virtual/resolved-theme.js +12 -0
- package/dist/node/virtual/story-source.d.ts +3 -0
- package/dist/node/virtual/story-source.d.ts.map +1 -0
- package/dist/node/virtual/story-source.js +16 -0
- package/dist/node/virtual/story.d.ts +3 -0
- package/dist/node/virtual/story.d.ts.map +1 -0
- package/dist/node/virtual/story.js +7 -0
- package/dist/node/virtual/util.d.ts +3 -0
- package/dist/node/virtual/util.d.ts.map +1 -0
- package/dist/node/virtual/util.js +4 -0
- package/dist/node/virtual/vite-plugin.d.ts +4 -0
- package/dist/node/virtual/vite-plugin.d.ts.map +1 -0
- package/dist/node/virtual/vite-plugin.js +126 -0
- package/dist/node/vite.d.ts +9 -0
- package/dist/node/vite.d.ts.map +1 -0
- package/dist/node/vite.js +337 -0
- package/index.d.ts +1 -0
- package/package.json +89 -0
- package/plugin.d.ts +3 -0
- package/plugin.js +11 -0
- package/src/controls.ts +1 -0
- package/src/node/__tests__/markdown/test1.story.md +7 -0
- package/src/node/__tests__/markdown/test2.story.md +5 -0
- package/src/node/__tests__/markdown.spec.ts +61 -0
- package/src/node/__tests__/tree.spec.ts +109 -0
- package/src/node/alias.ts +8 -0
- package/src/node/bin.ts +43 -0
- package/src/node/build-serialize.ts +62 -0
- package/src/node/build.ts +283 -0
- package/src/node/builtin-plugins/pinceau-tokens.ts +521 -0
- package/src/node/builtin-plugins/tailwind-tokens.ts +536 -0
- package/src/node/builtin-plugins/vanilla-support/MountStory.ts +49 -0
- package/src/node/builtin-plugins/vanilla-support/RenderStory.ts +164 -0
- package/src/node/builtin-plugins/vanilla-support/client.ts +6 -0
- package/src/node/builtin-plugins/vanilla-support/collect.ts +43 -0
- package/src/node/builtin-plugins/vanilla-support/plugin.ts +35 -0
- package/src/node/builtin-plugins/vanilla-support/types.ts +40 -0
- package/src/node/builtin-plugins/vanilla-support/vanilla.story.ts +63 -0
- package/src/node/collect/index.ts +160 -0
- package/src/node/collect/run.ts +9 -0
- package/src/node/collect/worker.ts +97 -0
- package/src/node/colors.ts +340 -0
- package/src/node/commands/build.ts +14 -0
- package/src/node/commands/dev.ts +67 -0
- package/src/node/commands/preview.ts +22 -0
- package/src/node/config.ts +385 -0
- package/src/node/context.ts +60 -0
- package/src/node/dom/dom-keys.ts +238 -0
- package/src/node/dom/env.ts +60 -0
- package/src/node/dom/util.ts +83 -0
- package/src/node/index.ts +12 -0
- package/src/node/load.ts +59 -0
- package/src/node/markdown.ts +267 -0
- package/src/node/plugin.ts +95 -0
- package/src/node/preview.ts +57 -0
- package/src/node/search.ts +84 -0
- package/src/node/server.ts +235 -0
- package/src/node/stories.ts +154 -0
- package/src/node/tree.ts +158 -0
- package/src/node/util/find-up.ts +24 -0
- package/src/node/util/fs.ts +1 -0
- package/src/node/util/log.ts +10 -0
- package/src/node/util/slugify.ts +26 -0
- package/src/node/util/vendors.ts +27 -0
- package/src/node/vendors/controls.ts +1 -0
- package/src/node/vendors/vue.ts +1 -0
- package/src/node/virtual/index.ts +50 -0
- package/src/node/virtual/markdown.ts +21 -0
- package/src/node/virtual/noop.ts +1 -0
- package/src/node/virtual/resolved-commands.ts +42 -0
- package/src/node/virtual/resolved-config.ts +12 -0
- package/src/node/virtual/resolved-generated-global-setup.ts +25 -0
- package/src/node/virtual/resolved-generated-setup-code.ts +7 -0
- package/src/node/virtual/resolved-markdown-files.ts +19 -0
- package/src/node/virtual/resolved-stories.ts +44 -0
- package/src/node/virtual/resolved-support-plugins-client.ts +14 -0
- package/src/node/virtual/resolved-support-plugins-collect.ts +14 -0
- package/src/node/virtual/resolved-theme.ts +14 -0
- package/src/node/virtual/story-source.ts +18 -0
- package/src/node/virtual/story.ts +9 -0
- package/src/node/virtual/util.ts +5 -0
- package/src/node/virtual/vite-plugin.ts +146 -0
- package/src/node/vite.ts +379 -0
- package/tsconfig.json +44 -0
- package/vitest.config.ts +10 -0
package/src/node/vite.ts
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
InlineConfig,
|
|
3
|
+
UserConfig as ViteConfig,
|
|
4
|
+
Plugin as VitePlugin,
|
|
5
|
+
} from 'vite'
|
|
6
|
+
import type { Context } from './context.js'
|
|
7
|
+
import { createRequire } from 'node:module'
|
|
8
|
+
import { lookup as lookupMime } from 'mrmime'
|
|
9
|
+
import { dirname, join, relative } from 'pathe'
|
|
10
|
+
import {
|
|
11
|
+
loadConfigFromFile as loadViteConfigFromFile,
|
|
12
|
+
mergeConfig as mergeViteConfig,
|
|
13
|
+
} from 'vite'
|
|
14
|
+
import { APP_PATH, TEMP_PATH } from './alias.js'
|
|
15
|
+
import { createMarkdownPlugins } from './markdown.js'
|
|
16
|
+
import { notifyStoryChange } from './stories.js'
|
|
17
|
+
import { createVirtualFilesPlugin } from './virtual/vite-plugin.js'
|
|
18
|
+
|
|
19
|
+
const require = createRequire(import.meta.url)
|
|
20
|
+
|
|
21
|
+
export async function mergeHistoireViteConfig(viteConfig: InlineConfig, ctx: Context) {
|
|
22
|
+
if (ctx.config.vite) {
|
|
23
|
+
const command = ctx.mode === 'dev' ? 'serve' : 'build'
|
|
24
|
+
const overrides = typeof ctx.config.vite === 'function'
|
|
25
|
+
? await ctx.config.vite(viteConfig as ViteConfig, {
|
|
26
|
+
mode: ctx.mode,
|
|
27
|
+
command,
|
|
28
|
+
})
|
|
29
|
+
: ctx.config.vite
|
|
30
|
+
if (overrides) {
|
|
31
|
+
viteConfig = mergeViteConfig(viteConfig, overrides)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let flatPlugins = []
|
|
36
|
+
if (viteConfig.plugins) {
|
|
37
|
+
for (const pluginOption of viteConfig.plugins) {
|
|
38
|
+
const resolvedPluginOption = await pluginOption
|
|
39
|
+
if (Array.isArray(resolvedPluginOption)) {
|
|
40
|
+
flatPlugins.push(...await Promise.all(resolvedPluginOption))
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
flatPlugins.push(resolvedPluginOption)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
flatPlugins = flatPlugins.filter(Boolean)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (ctx.config.viteIgnorePlugins) {
|
|
50
|
+
flatPlugins = flatPlugins.filter(plugin => !ctx.config.viteIgnorePlugins.includes(plugin.name))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
viteConfig.plugins = flatPlugins
|
|
54
|
+
|
|
55
|
+
return viteConfig
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ViteConfigWithPlugins {
|
|
59
|
+
viteConfig: InlineConfig
|
|
60
|
+
viteConfigFile: string | null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function getViteConfigWithPlugins(isServer: boolean, ctx: Context): Promise<ViteConfigWithPlugins> {
|
|
64
|
+
const userViteConfigFile = await loadViteConfigFromFile({ command: ctx.mode === 'dev' ? 'serve' : 'build', mode: ctx.mode })
|
|
65
|
+
const userViteConfig = mergeViteConfig(userViteConfigFile?.config ?? {}, { server: { port: 6006 } })
|
|
66
|
+
|
|
67
|
+
const inlineConfig = await mergeHistoireViteConfig(userViteConfig, ctx)
|
|
68
|
+
const plugins: VitePlugin[] = []
|
|
69
|
+
const supportPluginAllowPaths = ctx.supportPlugins.flatMap((plugin) => {
|
|
70
|
+
const paths = [ctx.root, import.meta.url]
|
|
71
|
+
const result = new Set<string>()
|
|
72
|
+
|
|
73
|
+
for (const suffix of ['', '/client', '/collect']) {
|
|
74
|
+
try {
|
|
75
|
+
const resolved = require.resolve(`${plugin.moduleName}${suffix}`, {
|
|
76
|
+
paths,
|
|
77
|
+
})
|
|
78
|
+
result.add(dirname(resolved))
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// Noop
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return Array.from(result)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
function optimizeDeps(deps: string[]): string[] {
|
|
89
|
+
const result = []
|
|
90
|
+
for (const dep of deps) {
|
|
91
|
+
result.push(dep)
|
|
92
|
+
try {
|
|
93
|
+
result.push(dirname(require.resolve(`${dep}/package.json`)))
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
// Noop
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return result
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
plugins.push({
|
|
103
|
+
name: 'histoire-vite-plugin',
|
|
104
|
+
|
|
105
|
+
config(_, { command }) {
|
|
106
|
+
return {
|
|
107
|
+
resolve: {
|
|
108
|
+
dedupe: [
|
|
109
|
+
'vue',
|
|
110
|
+
],
|
|
111
|
+
alias: {
|
|
112
|
+
'histoire-style': join(APP_PATH, process.env.HISTOIRE_DEV ? 'app/style/main.pcss' : 'style.css'),
|
|
113
|
+
},
|
|
114
|
+
...(isServer
|
|
115
|
+
? {
|
|
116
|
+
// Force resolving deps like Node.JS resolution algorithm (in case some modules are not loaded with ssr: true e.g. .vue files)
|
|
117
|
+
conditions: ['node'],
|
|
118
|
+
}
|
|
119
|
+
: {}),
|
|
120
|
+
},
|
|
121
|
+
optimizeDeps: {
|
|
122
|
+
entries: [
|
|
123
|
+
`${APP_PATH}/bundle-main.js`,
|
|
124
|
+
`${APP_PATH}/bundle-sandbox.js`,
|
|
125
|
+
],
|
|
126
|
+
include: optimizeDeps([
|
|
127
|
+
'flexsearch',
|
|
128
|
+
'shiki',
|
|
129
|
+
// Shiki dependencies
|
|
130
|
+
'vscode-oniguruma',
|
|
131
|
+
'vscode-textmate',
|
|
132
|
+
]),
|
|
133
|
+
exclude: [
|
|
134
|
+
'poveste',
|
|
135
|
+
'@poveste/vendors',
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
server: {
|
|
139
|
+
fs: {
|
|
140
|
+
allow: [
|
|
141
|
+
APP_PATH,
|
|
142
|
+
TEMP_PATH,
|
|
143
|
+
ctx.resolvedViteConfig.root,
|
|
144
|
+
process.cwd(),
|
|
145
|
+
...supportPluginAllowPaths,
|
|
146
|
+
...process.env.HISTOIRE_DEV
|
|
147
|
+
? [
|
|
148
|
+
'../../packages/histoire-vendors',
|
|
149
|
+
]
|
|
150
|
+
: [],
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
watch: {
|
|
154
|
+
ignored: [`!**/node_modules/.histoire/**`, '**/vite.config.*'],
|
|
155
|
+
},
|
|
156
|
+
hmr: command === 'build' ? false : !isServer,
|
|
157
|
+
},
|
|
158
|
+
define: {
|
|
159
|
+
// We need to force this to be able to use `devtoolsRawSetupState`
|
|
160
|
+
'__VUE_PROD_DEVTOOLS__': 'true',
|
|
161
|
+
// Disable warnings
|
|
162
|
+
'process.env.NODE_ENV': JSON.stringify(isServer ? 'production' : process.env.NODE_ENV ?? 'development'),
|
|
163
|
+
...!isServer
|
|
164
|
+
? {
|
|
165
|
+
// Collect flag
|
|
166
|
+
'process.env.HST_COLLECT': 'false',
|
|
167
|
+
}
|
|
168
|
+
: {},
|
|
169
|
+
'__HST_COLLECT__': isServer,
|
|
170
|
+
},
|
|
171
|
+
cacheDir: isServer ? 'node_modules/.hst-vite-server' : 'node_modules/.hst-vite',
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
options() {
|
|
176
|
+
(this.meta as any).histoire = {
|
|
177
|
+
isCollecting: isServer,
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
handleHotUpdate(updateContext) {
|
|
182
|
+
const story = ctx.storyFiles.find(file => file.path === updateContext.file)
|
|
183
|
+
if (story) {
|
|
184
|
+
notifyStoryChange(story)
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
configureServer(server) {
|
|
189
|
+
let firstMount = true
|
|
190
|
+
server.ws.on('histoire:mount', () => {
|
|
191
|
+
if (!firstMount) {
|
|
192
|
+
notifyStoryChange()
|
|
193
|
+
}
|
|
194
|
+
firstMount = false
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
server.middlewares.use(async (req, res, next) => {
|
|
198
|
+
if (req.url!.startsWith(`${server.config.base}__sandbox`)) {
|
|
199
|
+
res.statusCode = 200
|
|
200
|
+
let html = `
|
|
201
|
+
<!DOCTYPE html>
|
|
202
|
+
<html>
|
|
203
|
+
<head>
|
|
204
|
+
<title></title>
|
|
205
|
+
<meta charset="utf-8">
|
|
206
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
207
|
+
<meta name="description" content="">
|
|
208
|
+
</head>
|
|
209
|
+
<body>
|
|
210
|
+
<div id="app"></div>
|
|
211
|
+
<script>
|
|
212
|
+
// Hide spammy vite messages
|
|
213
|
+
const origConsoleLog = console.log
|
|
214
|
+
console.log = (...args) => {
|
|
215
|
+
if (typeof args[0] !== 'string' || !args[0].startsWith('[vite] connect')) {
|
|
216
|
+
origConsoleLog(...args)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
</script>
|
|
220
|
+
<script type="module" src="/@fs/${APP_PATH}/bundle-sandbox${process.env.HISTOIRE_DEV ? '-dev' : ''}.js"></script>
|
|
221
|
+
</body>
|
|
222
|
+
</html>`
|
|
223
|
+
// Apply Vite HTML transforms. This injects the Vite HMR client, and
|
|
224
|
+
// also applies HTML transforms from Vite plugins
|
|
225
|
+
html = await server.transformIndexHtml(req.url, html)
|
|
226
|
+
res.setHeader('content-type', 'text/html; charset=UTF-8')
|
|
227
|
+
res.end(html)
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
next()
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
// serve our index.html after vite history fallback
|
|
234
|
+
return () => {
|
|
235
|
+
server.middlewares.use(async (req, res, next) => {
|
|
236
|
+
if (req.url!.endsWith('.html')) {
|
|
237
|
+
res.statusCode = 200
|
|
238
|
+
|
|
239
|
+
let html = `
|
|
240
|
+
<!DOCTYPE html>
|
|
241
|
+
<html>
|
|
242
|
+
<head>
|
|
243
|
+
<title></title>
|
|
244
|
+
<link rel="icon" href=""/>
|
|
245
|
+
<meta charset="utf-8">
|
|
246
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
247
|
+
<meta name="description" content="">
|
|
248
|
+
${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${server.config.base}${ctx.config.theme.favicon}"/>` : ''}
|
|
249
|
+
</head>
|
|
250
|
+
<body>
|
|
251
|
+
<div id="app"></div>
|
|
252
|
+
<script type="module" src="/@fs/${APP_PATH}/bundle-main${process.env.HISTOIRE_DEV ? '-dev' : ''}.js"></script>
|
|
253
|
+
</body>
|
|
254
|
+
</html>`
|
|
255
|
+
// Apply Vite HTML transforms. This injects the Vite HMR client, and
|
|
256
|
+
// also applies HTML transforms from Vite plugins
|
|
257
|
+
html = await server.transformIndexHtml(req.url, html)
|
|
258
|
+
res.setHeader('content-type', 'text/html; charset=UTF-8')
|
|
259
|
+
res.end(html)
|
|
260
|
+
return
|
|
261
|
+
}
|
|
262
|
+
next()
|
|
263
|
+
})
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
plugins.push(createVirtualFilesPlugin(ctx, isServer))
|
|
269
|
+
|
|
270
|
+
// Replace dev flag
|
|
271
|
+
const flags = {
|
|
272
|
+
'_ctx.__HISTOIRE_DEV__': JSON.stringify(ctx.mode === 'dev'),
|
|
273
|
+
'__HISTOIRE_DEV__': JSON.stringify(ctx.mode === 'dev'),
|
|
274
|
+
}
|
|
275
|
+
plugins.push({
|
|
276
|
+
name: 'histoire:flags',
|
|
277
|
+
enforce: 'pre',
|
|
278
|
+
transform(code, id) {
|
|
279
|
+
if (id.match(/\.(vue|js)($|\?)/)) {
|
|
280
|
+
const original = code
|
|
281
|
+
for (const flag in flags) {
|
|
282
|
+
code = code.replace(new RegExp(flag, 'g'), flags[flag])
|
|
283
|
+
}
|
|
284
|
+
if (original !== code) return code
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
if (ctx.mode === 'dev') {
|
|
290
|
+
// Dev commands
|
|
291
|
+
plugins.push({
|
|
292
|
+
name: 'histoire:dev-commands',
|
|
293
|
+
configureServer(server) {
|
|
294
|
+
server.ws.on('histoire:dev-command', ({ id, params }) => {
|
|
295
|
+
const command = ctx.registeredCommands.find(c => c.id === id)
|
|
296
|
+
if (command?.serverAction) {
|
|
297
|
+
command.serverAction(params)
|
|
298
|
+
}
|
|
299
|
+
})
|
|
300
|
+
},
|
|
301
|
+
})
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Markdown
|
|
305
|
+
plugins.push(...await createMarkdownPlugins(ctx))
|
|
306
|
+
|
|
307
|
+
if (ctx.mode === 'build') {
|
|
308
|
+
// Add file name in build mode to have components names instead of <Anonymous>
|
|
309
|
+
const include = [/\.vue$/]
|
|
310
|
+
const exclude = [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/]
|
|
311
|
+
plugins.push({
|
|
312
|
+
name: 'histoire-file-name-plugin',
|
|
313
|
+
enforce: 'post',
|
|
314
|
+
|
|
315
|
+
transform(code, id) {
|
|
316
|
+
if (exclude.some(r => r.test(id))) return
|
|
317
|
+
if (include.some(r => r.test(id))) {
|
|
318
|
+
const file = relative(ctx.resolvedViteConfig.root, id)
|
|
319
|
+
const index = code.indexOf('export default')
|
|
320
|
+
const result = `${code.substring(0, index)}_sfc_main.__file = '${file}'\n${code.substring(index)}`
|
|
321
|
+
return result
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
})
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (process.env.HISTOIRE_DEV && !isServer) {
|
|
328
|
+
plugins.push({
|
|
329
|
+
name: 'histoire-dev-plugin',
|
|
330
|
+
config() {
|
|
331
|
+
// Examples context
|
|
332
|
+
return {
|
|
333
|
+
resolve: {
|
|
334
|
+
alias: [
|
|
335
|
+
...[
|
|
336
|
+
['floating-vue/dist/style.css', 'node_modules/floating-vue/dist/style.css'],
|
|
337
|
+
['floating-vue', 'floating-vue'],
|
|
338
|
+
['@iconify/vue', 'iconify'],
|
|
339
|
+
['pinia', 'pinia'],
|
|
340
|
+
['scroll-into-view-if-needed', 'scroll'],
|
|
341
|
+
['vue-router', 'vue-router'],
|
|
342
|
+
['@vueuse/core', 'vue-use'],
|
|
343
|
+
['vue', 'vue'],
|
|
344
|
+
].reduce((acc, [name, entry]) => {
|
|
345
|
+
acc.push({
|
|
346
|
+
find: new RegExp(`^${name.replace(/\//g, '\\/')}$`),
|
|
347
|
+
replacement: `@poveste/vendors/${entry}`,
|
|
348
|
+
})
|
|
349
|
+
acc.push({
|
|
350
|
+
find: new RegExp(`^${name.replace(/\//g, '\\/')}\\/`),
|
|
351
|
+
replacement: `@poveste/vendors/${entry}/`,
|
|
352
|
+
})
|
|
353
|
+
return acc
|
|
354
|
+
}, [] as any[]),
|
|
355
|
+
|
|
356
|
+
{ find: /@histoire\/controls$/, replacement: '@poveste/controls/src/index.ts' },
|
|
357
|
+
],
|
|
358
|
+
},
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
for (const plugin of ctx.config.plugins) {
|
|
365
|
+
if (plugin.vitePlugins) {
|
|
366
|
+
await plugin.vitePlugins(plugins)
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const viteConfig = mergeViteConfig(inlineConfig, {
|
|
371
|
+
configFile: false,
|
|
372
|
+
plugins,
|
|
373
|
+
}) as InlineConfig
|
|
374
|
+
|
|
375
|
+
return {
|
|
376
|
+
viteConfig,
|
|
377
|
+
viteConfigFile: userViteConfigFile?.path ?? null,
|
|
378
|
+
}
|
|
379
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
// Volar
|
|
5
|
+
"jsx": "preserve",
|
|
6
|
+
"lib": [
|
|
7
|
+
"ESNext",
|
|
8
|
+
"DOM"
|
|
9
|
+
],
|
|
10
|
+
"baseUrl": ".",
|
|
11
|
+
"rootDir": "src",
|
|
12
|
+
"module": "ESNext",
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"types": [
|
|
16
|
+
"node"
|
|
17
|
+
],
|
|
18
|
+
"strictBindCallApply": true,
|
|
19
|
+
"strictFunctionTypes": true,
|
|
20
|
+
"alwaysStrict": true,
|
|
21
|
+
// Strict
|
|
22
|
+
"noImplicitAny": false,
|
|
23
|
+
"noImplicitThis": true,
|
|
24
|
+
// Output
|
|
25
|
+
"declaration": true,
|
|
26
|
+
"declarationMap": true,
|
|
27
|
+
"outDir": "dist",
|
|
28
|
+
"removeComments": false,
|
|
29
|
+
"sourceMap": false,
|
|
30
|
+
"allowSyntheticDefaultImports": true,
|
|
31
|
+
"esModuleInterop": true,
|
|
32
|
+
"skipLibCheck": true,
|
|
33
|
+
"preserveWatchOutput": true
|
|
34
|
+
},
|
|
35
|
+
"include": [
|
|
36
|
+
"src"
|
|
37
|
+
],
|
|
38
|
+
"exclude": [
|
|
39
|
+
"node_modules",
|
|
40
|
+
"generated/**/*",
|
|
41
|
+
"dist/**/*",
|
|
42
|
+
"src/**/*.spec.ts"
|
|
43
|
+
]
|
|
44
|
+
}
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
// The markdown-collection tests boot a real Vite + jiti pipeline (~2.5s each
|
|
6
|
+
// locally, more on slow CI runners), which intermittently blew the 5s default.
|
|
7
|
+
testTimeout: 30000,
|
|
8
|
+
hookTimeout: 30000,
|
|
9
|
+
},
|
|
10
|
+
})
|