histoire 0.10.6 → 0.11.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/client.d.ts +15 -0
- package/client.js +14 -0
- package/dist/node/alias.js +1 -1
- package/dist/node/bin.js +2 -2
- package/dist/node/build.js +2 -1
- package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts +1 -1
- package/dist/node/builtin-plugins/vanilla-support/RenderStory.js +2 -2
- package/dist/node/builtin-plugins/vanilla-support/plugin.js +1 -1
- package/dist/node/collect/index.js +17 -5
- package/dist/node/collect/worker.d.ts +1 -1
- package/dist/node/collect/worker.js +2 -1
- package/dist/node/config.d.ts +1 -1
- package/dist/node/config.js +20 -26
- package/dist/node/markdown.d.ts +1 -0
- package/dist/node/markdown.js +15 -2
- package/dist/node/preview.js +1 -1
- package/dist/node/search.js +3 -3
- package/dist/node/server.js +23 -8
- package/dist/node/stories.d.ts +12 -1
- package/dist/node/stories.js +28 -11
- package/dist/node/util/find-up.js +1 -1
- package/dist/node/vite.d.ts +9 -9
- package/dist/node/vite.js +87 -31
- package/package.json +16 -10
- package/src/node/alias.ts +1 -1
- package/src/node/bin.ts +2 -2
- package/src/node/build.ts +2 -1
- package/src/node/builtin-plugins/vanilla-support/RenderStory.ts +2 -2
- package/src/node/builtin-plugins/vanilla-support/plugin.ts +1 -1
- package/src/node/collect/index.ts +21 -5
- package/src/node/collect/worker.ts +4 -2
- package/src/node/config.ts +21 -26
- package/src/node/markdown.ts +19 -2
- package/src/node/preview.ts +1 -1
- package/src/node/search.ts +3 -3
- package/src/node/server.ts +24 -9
- package/src/node/stories.ts +34 -13
- package/src/node/util/find-up.ts +1 -1
- package/src/node/vite.ts +87 -31
- package/tsconfig.json +0 -1
package/client.d.ts
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated
|
|
3
|
+
*/
|
|
1
4
|
export function hstEvent (name: string, argument): void
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Logs an event to the 'Events' sidepane.
|
|
8
|
+
* @param name Event name
|
|
9
|
+
* @param argument Additional log data displayed when inspecting the event.
|
|
10
|
+
*/
|
|
11
|
+
export function logEvent (name: string, argument): void
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns `true` when in the NodeJS server while collecting stories.
|
|
15
|
+
*/
|
|
16
|
+
export function isCollecting (): boolean
|
package/client.js
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
+
import { logEvent } from '@histoire/app'
|
|
2
|
+
|
|
1
3
|
export * from '@histoire/app'
|
|
4
|
+
|
|
5
|
+
export function isCollecting () {
|
|
6
|
+
return process.env.HST_COLLECT === 'true'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated
|
|
11
|
+
*/
|
|
12
|
+
export function hstEvent (...args) {
|
|
13
|
+
console.warn(`'hstEvent' is deprecated. Use 'logEvent' instead.`)
|
|
14
|
+
return logEvent(...args)
|
|
15
|
+
}
|
package/dist/node/alias.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'pathe';
|
|
2
|
-
import { createRequire } from 'module';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
3
|
const require = createRequire(import.meta.url);
|
|
4
4
|
export const APP_PATH = path.join(path.dirname(require.resolve('@histoire/app/package.json')), 'dist');
|
|
5
5
|
export const TEMP_PATH = path.join(process.cwd(), 'node_modules', '.histoire');
|
package/dist/node/bin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
1
|
+
import fs from 'node:fs';
|
|
2
2
|
import { dirname, resolve } from 'pathe';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import sade from 'sade';
|
|
5
5
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
6
|
const { version } = JSON.parse(fs.readFileSync(resolve(__dirname, '../../package.json'), 'utf8'));
|
package/dist/node/build.js
CHANGED
|
@@ -3,7 +3,7 @@ import { build as viteBuild, createServer as createViteServer, mergeConfig as me
|
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
4
|
import { lookup as lookupMime } from 'mrmime';
|
|
5
5
|
import pc from 'picocolors';
|
|
6
|
-
import { performance } from 'perf_hooks';
|
|
6
|
+
import { performance } from 'node:perf_hooks';
|
|
7
7
|
import { APP_PATH } from './alias.js';
|
|
8
8
|
import { getViteConfigWithPlugins, resolveViteConfig } from './vite.js';
|
|
9
9
|
import { findAllStories } from './stories.js';
|
|
@@ -97,6 +97,7 @@ export async function build(ctx) {
|
|
|
97
97
|
config(config) {
|
|
98
98
|
const vuePlugin = config.plugins.find((p) => p.name === 'vite:vue');
|
|
99
99
|
if (vuePlugin) {
|
|
100
|
+
// @ts-expect-error vue plugin use function form
|
|
100
101
|
const original = vuePlugin.configureServer.bind(vuePlugin);
|
|
101
102
|
vuePlugin.configureServer = () => {
|
|
102
103
|
original({
|
|
@@ -5,7 +5,7 @@ declare const _default: import("@histoire/vendors/vue").DefineComponent<{
|
|
|
5
5
|
type: _PropType<Story>;
|
|
6
6
|
required: true;
|
|
7
7
|
};
|
|
8
|
-
}, void, unknown, {}, {}, import("@histoire/vendors/vue").ComponentOptionsMixin, import("@histoire/vendors/vue").ComponentOptionsMixin,
|
|
8
|
+
}, void, unknown, {}, {}, import("@histoire/vendors/vue").ComponentOptionsMixin, import("@histoire/vendors/vue").ComponentOptionsMixin, {}, string, import("@histoire/vendors/vue").VNodeProps & import("@histoire/vendors/vue").AllowedComponentProps & import("@histoire/vendors/vue").ComponentCustomProps, Readonly<import("@histoire/vendors/vue").ExtractPropTypes<{
|
|
9
9
|
story: {
|
|
10
10
|
type: _PropType<Story>;
|
|
11
11
|
required: true;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* eslint-disable vue/one-component-per-file */
|
|
2
2
|
import { defineComponent as _defineComponent, onBeforeUnmount as _onBeforeUnmount, onMounted as _onMounted, ref as _ref, watch as _watch, h as _h, } from '@histoire/vendors/vue';
|
|
3
3
|
// @ts-expect-error virtual module id
|
|
4
|
-
import * as setup from '
|
|
4
|
+
import * as setup from 'virtual:$histoire-setup';
|
|
5
5
|
// @ts-expect-error virtual module id
|
|
6
|
-
import * as generatedSetup from '
|
|
6
|
+
import * as generatedSetup from 'virtual:$histoire-generated-global-setup';
|
|
7
7
|
export default _defineComponent({
|
|
8
8
|
name: 'RenderStory',
|
|
9
9
|
props: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { MessageChannel } from 'worker_threads';
|
|
1
|
+
import { MessageChannel } from 'node:worker_threads';
|
|
2
2
|
import { ViteNodeServer } from 'vite-node/server';
|
|
3
3
|
import { relative } from 'pathe';
|
|
4
4
|
import pc from 'picocolors';
|
|
5
5
|
import Tinypool from 'tinypool';
|
|
6
6
|
import { createBirpc } from 'birpc';
|
|
7
|
-
import { cpus } from 'os';
|
|
7
|
+
import { cpus } from 'node:os';
|
|
8
8
|
import { createPath } from '../tree.js';
|
|
9
9
|
export function useCollectStories(options, ctx) {
|
|
10
10
|
const { server } = options;
|
|
@@ -71,10 +71,22 @@ export function useCollectStories(options, ctx) {
|
|
|
71
71
|
else if (storyData.length > 1) {
|
|
72
72
|
console.warn(pc.yellow(`⚠️ Multiple stories not supported: ${storyFile.path}`));
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
const finalData = storyData[0];
|
|
75
|
+
// Default props
|
|
76
|
+
if (ctx.config.defaultStoryProps) {
|
|
77
|
+
for (const key in ctx.config.defaultStoryProps) {
|
|
78
|
+
if (finalData[key] == null) {
|
|
79
|
+
finalData[key] = ctx.config.defaultStoryProps[key];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!finalData.layout) {
|
|
84
|
+
finalData.layout = { type: 'single', iframe: true };
|
|
85
|
+
}
|
|
86
|
+
storyFile.id = finalData.id;
|
|
87
|
+
storyFile.story = finalData;
|
|
76
88
|
storyFile.treeFile = {
|
|
77
|
-
title:
|
|
89
|
+
title: finalData.title,
|
|
78
90
|
path: relative(server.config.root, storyFile.path),
|
|
79
91
|
};
|
|
80
92
|
storyFile.treePath = createPath(ctx.config, storyFile.treeFile);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { fileURLToPath } from 'url';
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
2
|
import { ViteNodeRunner } from 'vite-node/client';
|
|
3
3
|
import { createBirpc } from 'birpc';
|
|
4
4
|
import { dirname, resolve } from 'pathe';
|
|
5
5
|
import { createDomEnv } from '../dom/env.js';
|
|
6
6
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
export default async (payload) => {
|
|
8
|
+
process.env.HST_COLLECT = 'true';
|
|
8
9
|
const rpc = createBirpc({}, {
|
|
9
10
|
post: data => payload.port.postMessage(data),
|
|
10
11
|
on: data => payload.port.on('message', data),
|
package/dist/node/config.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare const mergeConfig: <Source extends {
|
|
|
14
14
|
} | (number | boolean | any[] | Record<never, any>))[]>(source: Source, ...defaults: Defaults) => import("defu").Defu<Source, Defaults>;
|
|
15
15
|
export declare function resolveConfig(cwd: string, mode: ConfigMode): Promise<HistoireConfig>;
|
|
16
16
|
export declare function processConfig(config: HistoireConfig, mode: ConfigMode): Promise<HistoireConfig>;
|
|
17
|
-
export declare function processDefaultConfig(defaultConfig: HistoireConfig, preUserConfig: HistoireConfig, mode: ConfigMode): Promise<HistoireConfig>;
|
|
17
|
+
export declare function processDefaultConfig(defaultConfig: HistoireConfig, preUserConfig: HistoireConfig, mode: ConfigMode, cwd: string): Promise<HistoireConfig>;
|
|
18
18
|
export declare function defineConfig(config: Partial<HistoireConfig>): Partial<HistoireConfig>;
|
|
19
19
|
declare module 'vite' {
|
|
20
20
|
interface UserConfig {
|
package/dist/node/config.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import path from 'pathe';
|
|
2
2
|
import { createDefu } from 'defu';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
3
|
+
import { resolveConfig as resolveViteConfig, mergeConfig as mergeViteConfig, } from 'vite';
|
|
4
|
+
import jiti from 'jiti';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import pc from 'picocolors';
|
|
7
7
|
import { defaultColors } from './colors.js';
|
|
8
8
|
import { findUp } from './util/find-up.js';
|
|
9
9
|
import { tailwindTokens } from './builtin-plugins/tailwind-tokens.js';
|
|
10
10
|
import { vanillaSupport } from './builtin-plugins/vanilla-support/plugin.js';
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
12
|
export function getDefaultConfig() {
|
|
12
13
|
return {
|
|
13
14
|
plugins: [
|
|
@@ -131,26 +132,9 @@ export function resolveConfigFile(cwd = process.cwd()) {
|
|
|
131
132
|
}
|
|
132
133
|
export async function loadConfigFile(configFile) {
|
|
133
134
|
try {
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
deps: {
|
|
138
|
-
inline: [
|
|
139
|
-
/histoire\/dist/,
|
|
140
|
-
],
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
const runner = new ViteNodeRunner({
|
|
144
|
-
root: path.dirname(configFile),
|
|
145
|
-
fetchModule(id) {
|
|
146
|
-
return node.fetchModule(id);
|
|
147
|
-
},
|
|
148
|
-
resolveId(id, importer) {
|
|
149
|
-
return node.resolveId(id, importer);
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
const result = await runner.executeFile(configFile);
|
|
153
|
-
await server.close();
|
|
135
|
+
const result = jiti(__filename, {
|
|
136
|
+
esmResolve: true,
|
|
137
|
+
})(configFile);
|
|
154
138
|
if (!result.default) {
|
|
155
139
|
throw new Error(`Expected default export in ${configFile}`);
|
|
156
140
|
}
|
|
@@ -221,7 +205,7 @@ export async function resolveConfig(cwd = process.cwd(), mode) {
|
|
|
221
205
|
const viteConfig = await resolveViteConfig({}, 'serve');
|
|
222
206
|
const viteHistoireConfig = (viteConfig.histoire ?? {});
|
|
223
207
|
const preUserConfig = mergeConfig(result, viteHistoireConfig);
|
|
224
|
-
const processedDefaultConfig = await processDefaultConfig(getDefaultConfig(), preUserConfig, mode);
|
|
208
|
+
const processedDefaultConfig = await processDefaultConfig(getDefaultConfig(), preUserConfig, mode, cwd);
|
|
225
209
|
return processConfig(mergeConfig(preUserConfig, processedDefaultConfig), mode);
|
|
226
210
|
}
|
|
227
211
|
export async function processConfig(config, mode) {
|
|
@@ -236,8 +220,18 @@ export async function processConfig(config, mode) {
|
|
|
236
220
|
config.outDir = path.resolve(process.cwd(), config.outDir);
|
|
237
221
|
return config;
|
|
238
222
|
}
|
|
239
|
-
export async function processDefaultConfig(defaultConfig, preUserConfig, mode) {
|
|
240
|
-
|
|
223
|
+
export async function processDefaultConfig(defaultConfig, preUserConfig, mode, cwd) {
|
|
224
|
+
// Automatically inline dependencies in vite-node
|
|
225
|
+
const pkgFile = await findUp(cwd, ['package.json']);
|
|
226
|
+
const fs = (await import('fs-extra')).default;
|
|
227
|
+
if (pkgFile) {
|
|
228
|
+
const pkg = await fs.readJSON(pkgFile);
|
|
229
|
+
if (pkg.dependencies) {
|
|
230
|
+
defaultConfig.viteNodeInlineDeps = Object.keys(pkg.dependencies).map(d => new RegExp(d));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// Apply plugins
|
|
234
|
+
for (const plugin of [...defaultConfig.plugins, ...preUserConfig.plugins ?? []]) {
|
|
241
235
|
if (plugin.defaultConfig) {
|
|
242
236
|
const result = await plugin.defaultConfig(defaultConfig, mode);
|
|
243
237
|
if (result) {
|
package/dist/node/markdown.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it';
|
|
2
2
|
import type { Plugin as VitePlugin } from 'vite';
|
|
3
3
|
import type { Context } from './context.js';
|
|
4
|
+
export declare function onMarkdownListChange(handler: () => unknown): void;
|
|
4
5
|
export declare function createMarkdownRenderer(): Promise<MarkdownIt>;
|
|
5
6
|
export declare function createMarkdownPlugins(ctx: Context): Promise<VitePlugin[]>;
|
|
6
7
|
export declare function createMarkdownFilesWatcher(ctx: Context): Promise<{
|
package/dist/node/markdown.js
CHANGED
|
@@ -9,6 +9,15 @@ import fs from 'fs-extra';
|
|
|
9
9
|
import path from 'pathe';
|
|
10
10
|
import { slugify } from './util/slugify.js';
|
|
11
11
|
import { addStory, notifyStoryChange, removeStory } from './stories.js';
|
|
12
|
+
const onMarkdownListChangeHandlers = [];
|
|
13
|
+
export function onMarkdownListChange(handler) {
|
|
14
|
+
onMarkdownListChangeHandlers.push(handler);
|
|
15
|
+
}
|
|
16
|
+
function notifyMarkdownListChange() {
|
|
17
|
+
for (const handler of onMarkdownListChangeHandlers) {
|
|
18
|
+
handler();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
12
21
|
export async function createMarkdownRenderer() {
|
|
13
22
|
const highlighter = await shiki.getHighlighter({
|
|
14
23
|
theme: 'github-dark',
|
|
@@ -91,7 +100,9 @@ export const relativePath = ${JSON.stringify(relativePath)}
|
|
|
91
100
|
|
|
92
101
|
if (import.meta.hot) {
|
|
93
102
|
import.meta.hot.accept(newModule => {
|
|
94
|
-
|
|
103
|
+
if (newModule) {
|
|
104
|
+
window.__hst_md_hmr(newModule)
|
|
105
|
+
}
|
|
95
106
|
})
|
|
96
107
|
}`;
|
|
97
108
|
}
|
|
@@ -125,7 +136,7 @@ export async function createMarkdownFilesWatcher(ctx) {
|
|
|
125
136
|
const storyFile = addStory(storyRelativePath, `export default ${JSON.stringify({
|
|
126
137
|
id: frontmatter.id,
|
|
127
138
|
title: frontmatter.title,
|
|
128
|
-
icon: frontmatter.icon,
|
|
139
|
+
icon: frontmatter.icon ?? 'carbon:document-blank',
|
|
129
140
|
iconColor: frontmatter.iconColor,
|
|
130
141
|
group: frontmatter.group,
|
|
131
142
|
docsOnly: true,
|
|
@@ -144,6 +155,7 @@ export async function createMarkdownFilesWatcher(ctx) {
|
|
|
144
155
|
notifyStoryChange(storyFile);
|
|
145
156
|
}
|
|
146
157
|
}
|
|
158
|
+
notifyMarkdownListChange();
|
|
147
159
|
return file;
|
|
148
160
|
}
|
|
149
161
|
function removeFile(relativePath) {
|
|
@@ -155,6 +167,7 @@ export async function createMarkdownFilesWatcher(ctx) {
|
|
|
155
167
|
notifyStoryChange();
|
|
156
168
|
}
|
|
157
169
|
ctx.markdownFiles.splice(index, 1);
|
|
170
|
+
notifyMarkdownListChange();
|
|
158
171
|
}
|
|
159
172
|
}
|
|
160
173
|
async function stop() {
|
package/dist/node/preview.js
CHANGED
package/dist/node/search.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createRequire } from 'module';
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
2
|
import flexsearch from 'flexsearch';
|
|
3
3
|
import path from 'pathe';
|
|
4
|
-
import
|
|
4
|
+
import { noCase } from 'change-case';
|
|
5
5
|
import { loadModule } from './load.js';
|
|
6
6
|
const require = createRequire(import.meta.url);
|
|
7
7
|
export async function generateTitleSearchData(ctx) {
|
|
@@ -93,7 +93,7 @@ async function exportSearchIndex(index) {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
function convertTitleToSentence(text) {
|
|
96
|
-
return text.split(' ').map(str =>
|
|
96
|
+
return text.split(' ').map(str => noCase(str)).join(' ');
|
|
97
97
|
}
|
|
98
98
|
// @TODO clear handlers when SearchPane unmounts
|
|
99
99
|
export function getSearchDataJS(data) {
|
package/dist/node/server.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createServer as createViteServer } from 'vite';
|
|
2
|
-
import { getViteConfigWithPlugins, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js';
|
|
3
|
-
import { onStoryChange, watchStories } from './stories.js';
|
|
2
|
+
import { getViteConfigWithPlugins, RESOLVED_MARKDOWN_FILES, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js';
|
|
3
|
+
import { onStoryChange, onStoryListChange, watchStories } from './stories.js';
|
|
4
4
|
import { useCollectStories } from './collect/index.js';
|
|
5
5
|
import { DevPluginApi } from './plugin.js';
|
|
6
6
|
import { useModuleLoader } from './load.js';
|
|
7
7
|
import { wrapLogError } from './util/log.js';
|
|
8
|
-
import { createMarkdownFilesWatcher } from './markdown.js';
|
|
8
|
+
import { createMarkdownFilesWatcher, onMarkdownListChange } from './markdown.js';
|
|
9
9
|
export async function createServer(ctx, port) {
|
|
10
10
|
const server = await createViteServer(await getViteConfigWithPlugins(false, ctx));
|
|
11
11
|
await server.pluginContainer.buildStart({});
|
|
@@ -67,19 +67,25 @@ export async function createServer(ctx, port) {
|
|
|
67
67
|
if (queue) {
|
|
68
68
|
if (queued) {
|
|
69
69
|
if (changedFile) {
|
|
70
|
-
queuedFiles.
|
|
70
|
+
if (!queuedFiles.includes(changedFile)) {
|
|
71
|
+
queuedFiles.push(changedFile);
|
|
72
|
+
}
|
|
71
73
|
}
|
|
72
74
|
else {
|
|
73
75
|
queuedAll = true;
|
|
74
76
|
}
|
|
75
77
|
return;
|
|
76
78
|
}
|
|
79
|
+
else if (queuedFiles.includes(changedFile)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
77
82
|
else {
|
|
78
83
|
queued = true;
|
|
79
84
|
// Next call
|
|
80
85
|
await queue;
|
|
81
86
|
}
|
|
82
87
|
}
|
|
88
|
+
queuedFiles.unshift(changedFile);
|
|
83
89
|
queued = false;
|
|
84
90
|
queue = new Promise(resolve => {
|
|
85
91
|
queueResolve = resolve;
|
|
@@ -88,10 +94,12 @@ export async function createServer(ctx, port) {
|
|
|
88
94
|
console.log('Collect stories start', changedFile?.path ?? 'all');
|
|
89
95
|
const time = Date.now();
|
|
90
96
|
if (changedFile && !queuedAll) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
await Promise.all(queuedFiles.map(async (storyFile) => {
|
|
98
|
+
await executeStoryFile(storyFile);
|
|
99
|
+
if (storyFile.story) {
|
|
100
|
+
await invalidateModule(`/__resolved__virtual:story-source:${storyFile.story.id}`);
|
|
101
|
+
}
|
|
102
|
+
}));
|
|
95
103
|
}
|
|
96
104
|
else {
|
|
97
105
|
// Full update
|
|
@@ -120,6 +128,13 @@ export async function createServer(ctx, port) {
|
|
|
120
128
|
invalidateModule(RESOLVED_STORIES_ID);
|
|
121
129
|
invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID);
|
|
122
130
|
});
|
|
131
|
+
onStoryListChange(() => {
|
|
132
|
+
invalidateModule(RESOLVED_STORIES_ID);
|
|
133
|
+
invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID);
|
|
134
|
+
});
|
|
135
|
+
onMarkdownListChange(() => {
|
|
136
|
+
invalidateModule(RESOLVED_MARKDOWN_FILES);
|
|
137
|
+
});
|
|
123
138
|
async function close() {
|
|
124
139
|
for (const cb of pluginOnCleanups) {
|
|
125
140
|
await wrapLogError('plugin.onDev.onCleanup', () => cb());
|
package/dist/node/stories.d.ts
CHANGED
|
@@ -2,9 +2,20 @@ import chokidar from 'chokidar';
|
|
|
2
2
|
import type { ServerStoryFile } from '@histoire/shared';
|
|
3
3
|
import { Context } from './context.js';
|
|
4
4
|
declare type StoryChangeHandler = (file?: ServerStoryFile) => unknown;
|
|
5
|
+
/**
|
|
6
|
+
* Called when a new story is added or modified. Collecting should be done.
|
|
7
|
+
* @param handler
|
|
8
|
+
*/
|
|
5
9
|
export declare function onStoryChange(handler: StoryChangeHandler): void;
|
|
6
|
-
export declare function watchStories(newContext: Context): Promise<chokidar.FSWatcher>;
|
|
7
10
|
export declare function notifyStoryChange(file?: ServerStoryFile): void;
|
|
11
|
+
declare type StoryListChangeHandler = () => unknown;
|
|
12
|
+
/**
|
|
13
|
+
* Called when the story list has changed (ex: removed a story). No collecting should be needed.
|
|
14
|
+
* @param handler
|
|
15
|
+
*/
|
|
16
|
+
export declare function onStoryListChange(handler: StoryListChangeHandler): void;
|
|
17
|
+
export declare function notifyStoryListChange(): void;
|
|
18
|
+
export declare function watchStories(newContext: Context): Promise<chokidar.FSWatcher>;
|
|
8
19
|
export declare function addStory(relativeFilePath: string, virtualModuleCode?: string): ServerStoryFile;
|
|
9
20
|
export declare function removeStory(relativeFilePath: string): void;
|
|
10
21
|
export declare function findAllStories(newContext: Context): Promise<void>;
|
package/dist/node/stories.js
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
import chokidar from 'chokidar';
|
|
2
2
|
import { globby } from 'globby';
|
|
3
|
-
import
|
|
3
|
+
import { paramCase } from 'change-case';
|
|
4
4
|
import { resolve, basename } from 'pathe';
|
|
5
5
|
import micromatch from 'micromatch';
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const storyChangeHandlers = [];
|
|
7
|
+
/**
|
|
8
|
+
* Called when a new story is added or modified. Collecting should be done.
|
|
9
|
+
* @param handler
|
|
10
|
+
*/
|
|
8
11
|
export function onStoryChange(handler) {
|
|
9
|
-
|
|
12
|
+
storyChangeHandlers.push(handler);
|
|
10
13
|
}
|
|
14
|
+
export function notifyStoryChange(file) {
|
|
15
|
+
for (const handler of storyChangeHandlers) {
|
|
16
|
+
handler(file);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const storyListChangeHandlers = [];
|
|
20
|
+
/**
|
|
21
|
+
* Called when the story list has changed (ex: removed a story). No collecting should be needed.
|
|
22
|
+
* @param handler
|
|
23
|
+
*/
|
|
24
|
+
export function onStoryListChange(handler) {
|
|
25
|
+
storyListChangeHandlers.push(handler);
|
|
26
|
+
}
|
|
27
|
+
export function notifyStoryListChange() {
|
|
28
|
+
for (const handler of storyListChangeHandlers) {
|
|
29
|
+
handler();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
let context;
|
|
11
33
|
export async function watchStories(newContext) {
|
|
12
34
|
context = newContext;
|
|
13
35
|
const watcher = chokidar.watch(context.config.storyMatch, {
|
|
@@ -21,21 +43,16 @@ export async function watchStories(newContext) {
|
|
|
21
43
|
})
|
|
22
44
|
.on('unlink', (file) => {
|
|
23
45
|
removeStory(file);
|
|
24
|
-
|
|
46
|
+
notifyStoryListChange();
|
|
25
47
|
});
|
|
26
48
|
return watcher;
|
|
27
49
|
}
|
|
28
|
-
export function notifyStoryChange(file) {
|
|
29
|
-
for (const handler of handlers) {
|
|
30
|
-
handler(file);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
50
|
function getAbsoluteFilePath(relativeFilePath) {
|
|
34
51
|
return resolve(context.root, relativeFilePath);
|
|
35
52
|
}
|
|
36
53
|
export function addStory(relativeFilePath, virtualModuleCode) {
|
|
37
54
|
const absoluteFilePath = getAbsoluteFilePath(relativeFilePath);
|
|
38
|
-
const fileId =
|
|
55
|
+
const fileId = paramCase(relativeFilePath.toLowerCase());
|
|
39
56
|
let fileName = basename(relativeFilePath);
|
|
40
57
|
if (fileName.includes('.')) {
|
|
41
58
|
fileName = fileName.substring(0, fileName.indexOf('.'));
|
package/dist/node/vite.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { ResolvedConfig, InlineConfig } from 'vite';
|
|
2
2
|
import { Context } from './context.js';
|
|
3
|
-
export declare const STORIES_ID = "
|
|
3
|
+
export declare const STORIES_ID = "virtual:$histoire-stories";
|
|
4
4
|
export declare const RESOLVED_STORIES_ID: string;
|
|
5
|
-
export declare const SETUP_ID = "
|
|
6
|
-
export declare const NOOP_ID = "
|
|
7
|
-
export declare const CONFIG_ID = "
|
|
5
|
+
export declare const SETUP_ID = "virtual:$histoire-setup";
|
|
6
|
+
export declare const NOOP_ID = "virtual:$histoire-noop";
|
|
7
|
+
export declare const CONFIG_ID = "virtual:$histoire-config";
|
|
8
8
|
export declare const RESOLVED_CONFIG_ID: string;
|
|
9
|
-
export declare const THEME_ID = "
|
|
9
|
+
export declare const THEME_ID = "virtual:$histoire-theme";
|
|
10
10
|
export declare const RESOLVED_THEME_ID: string;
|
|
11
|
-
export declare const SEARCH_TITLE_DATA_ID = "
|
|
11
|
+
export declare const SEARCH_TITLE_DATA_ID = "virtual:$histoire-search-title-data";
|
|
12
12
|
export declare const RESOLVED_SEARCH_TITLE_DATA_ID: string;
|
|
13
|
-
export declare const SEARCH_DOCS_DATA_ID = "
|
|
13
|
+
export declare const SEARCH_DOCS_DATA_ID = "virtual:$histoire-search-docs-data";
|
|
14
14
|
export declare const RESOLVED_SEARCH_DOCS_DATA_ID: string;
|
|
15
|
-
export declare const GENERATED_GLOBAL_SETUP = "
|
|
15
|
+
export declare const GENERATED_GLOBAL_SETUP = "virtual:$histoire-generated-global-setup";
|
|
16
16
|
export declare const RESOLVED_GENERATED_GLOBAL_SETUP: string;
|
|
17
|
-
export declare const GENERATED_SETUP_CODE = "
|
|
17
|
+
export declare const GENERATED_SETUP_CODE = "virtual:$histoire-generated-setup-code";
|
|
18
18
|
export declare const RESOLVED_GENERATED_SETUP_CODE: string;
|
|
19
19
|
export declare const SUPPORT_PLUGINS_CLIENT = "virtual:$histoire-support-plugins-client";
|
|
20
20
|
export declare const RESOLVED_SUPPORT_PLUGINS_CLIENT: string;
|