histoire 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node/build.js +17 -11
- package/dist/node/server.js +7 -6
- package/dist/node/virtual/index.d.ts +34 -0
- package/dist/node/virtual/index.js +46 -0
- package/dist/node/virtual/markdown.d.ts +2 -0
- package/dist/node/virtual/markdown.js +19 -0
- package/dist/node/virtual/noop.d.ts +1 -0
- package/dist/node/virtual/noop.js +1 -0
- package/dist/node/virtual/resolved-config.d.ts +2 -0
- package/dist/node/virtual/resolved-config.js +10 -0
- package/dist/node/virtual/resolved-generated-global-setup.d.ts +2 -0
- package/dist/node/virtual/resolved-generated-global-setup.js +23 -0
- package/dist/node/virtual/resolved-generated-setup-code.d.ts +2 -0
- package/dist/node/virtual/resolved-generated-setup-code.js +5 -0
- package/dist/node/virtual/resolved-markdown-files.d.ts +2 -0
- package/dist/node/virtual/resolved-markdown-files.js +17 -0
- package/dist/node/virtual/resolved-stories.d.ts +2 -0
- package/dist/node/virtual/resolved-stories.js +41 -0
- package/dist/node/virtual/resolved-support-plugins-client.d.ts +2 -0
- package/dist/node/virtual/resolved-support-plugins-client.js +11 -0
- package/dist/node/virtual/resolved-support-plugins-collect.d.ts +2 -0
- package/dist/node/virtual/resolved-support-plugins-collect.js +11 -0
- package/dist/node/virtual/resolved-theme.d.ts +2 -0
- package/dist/node/virtual/resolved-theme.js +12 -0
- package/dist/node/virtual/story-source.d.ts +2 -0
- package/dist/node/virtual/story-source.js +16 -0
- package/dist/node/virtual/story.d.ts +2 -0
- package/dist/node/virtual/story.js +7 -0
- package/dist/node/virtual/util.d.ts +2 -0
- package/dist/node/virtual/util.js +4 -0
- package/dist/node/virtual/vite-plugin.d.ts +3 -0
- package/dist/node/virtual/vite-plugin.js +118 -0
- package/dist/node/vite.d.ts +0 -22
- package/dist/node/vite.js +8 -280
- package/package.json +6 -6
- package/src/node/build.ts +19 -11
- package/src/node/server.ts +7 -6
- package/src/node/virtual/index.ts +47 -0
- package/src/node/virtual/markdown.ts +21 -0
- package/src/node/virtual/noop.ts +1 -0
- package/src/node/virtual/resolved-config.ts +12 -0
- package/src/node/virtual/resolved-generated-global-setup.ts +24 -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 +43 -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 +17 -0
- package/src/node/virtual/story.ts +9 -0
- package/src/node/virtual/util.ts +5 -0
- package/src/node/virtual/vite-plugin.ts +135 -0
- package/src/node/vite.ts +9 -295
package/dist/node/build.js
CHANGED
|
@@ -65,13 +65,6 @@ export async function build(ctx) {
|
|
|
65
65
|
join(APP_PATH, 'bundle-main.js'),
|
|
66
66
|
join(APP_PATH, 'bundle-sandbox.js'),
|
|
67
67
|
],
|
|
68
|
-
output: {
|
|
69
|
-
manualChunks(id) {
|
|
70
|
-
if (!id.includes('@histoire/app') && id.includes('node_modules')) {
|
|
71
|
-
return 'vendor';
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
68
|
plugins: [
|
|
76
69
|
{
|
|
77
70
|
name: 'histoire-build-rollup-options-override',
|
|
@@ -83,10 +76,6 @@ export async function build(ctx) {
|
|
|
83
76
|
},
|
|
84
77
|
],
|
|
85
78
|
},
|
|
86
|
-
outDir: ctx.config.outDir,
|
|
87
|
-
emptyOutDir: true,
|
|
88
|
-
cssCodeSplit: false,
|
|
89
|
-
minify: false,
|
|
90
79
|
},
|
|
91
80
|
});
|
|
92
81
|
// For @vite/plugin-vue: Always put our vite server
|
|
@@ -122,6 +111,23 @@ export async function build(ctx) {
|
|
|
122
111
|
config(config) {
|
|
123
112
|
// Don't externalize
|
|
124
113
|
config.build.rollupOptions.external = [];
|
|
114
|
+
// Force chunk strategy
|
|
115
|
+
config.build.rollupOptions.output = {
|
|
116
|
+
manualChunks(id) {
|
|
117
|
+
if (!id.includes('@histoire/app') && id.includes('node_modules')) {
|
|
118
|
+
return 'vendor';
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
// Force vite build options
|
|
123
|
+
Object.assign(config.build, {
|
|
124
|
+
outDir: ctx.config.outDir,
|
|
125
|
+
emptyOutDir: true,
|
|
126
|
+
cssCodeSplit: false,
|
|
127
|
+
minify: false,
|
|
128
|
+
// Don't build in SSR mode
|
|
129
|
+
ssr: false,
|
|
130
|
+
});
|
|
125
131
|
},
|
|
126
132
|
});
|
|
127
133
|
const results = await viteBuild(buildViteConfig);
|
package/dist/node/server.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { performance } from 'node:perf_hooks';
|
|
2
2
|
import { createServer as createViteServer } from 'vite';
|
|
3
3
|
import pc from 'picocolors';
|
|
4
|
-
import { getViteConfigWithPlugins
|
|
4
|
+
import { getViteConfigWithPlugins } from './vite.js';
|
|
5
|
+
import * as VirtualFiles from './virtual/index.js';
|
|
5
6
|
import { onStoryChange, onStoryListChange, watchStories } from './stories.js';
|
|
6
7
|
import { useCollectStories } from './collect/index.js';
|
|
7
8
|
import { DevPluginApi } from './plugin.js';
|
|
@@ -135,19 +136,19 @@ export async function createServer(ctx, options = {}) {
|
|
|
135
136
|
}
|
|
136
137
|
console.log(`Collect stories end ${pc.bold(pc.blue(Math.round(performance.now() - time)))}ms`);
|
|
137
138
|
clearInvalidates();
|
|
138
|
-
invalidateModule(RESOLVED_STORIES_ID);
|
|
139
|
-
invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID);
|
|
139
|
+
invalidateModule(VirtualFiles.RESOLVED_STORIES_ID);
|
|
140
|
+
invalidateModule(VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID);
|
|
140
141
|
collecting = false;
|
|
141
142
|
if (queued) {
|
|
142
143
|
await collect();
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
onStoryListChange(() => {
|
|
146
|
-
invalidateModule(RESOLVED_STORIES_ID);
|
|
147
|
-
invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID);
|
|
147
|
+
invalidateModule(VirtualFiles.RESOLVED_STORIES_ID);
|
|
148
|
+
invalidateModule(VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID);
|
|
148
149
|
});
|
|
149
150
|
onMarkdownListChange(() => {
|
|
150
|
-
invalidateModule(RESOLVED_MARKDOWN_FILES);
|
|
151
|
+
invalidateModule(VirtualFiles.RESOLVED_MARKDOWN_FILES);
|
|
151
152
|
});
|
|
152
153
|
async function close() {
|
|
153
154
|
for (const cb of pluginOnCleanups) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const STORIES_ID = "virtual:$histoire-stories";
|
|
2
|
+
export declare const RESOLVED_STORIES_ID: string;
|
|
3
|
+
export declare const SETUP_ID = "virtual:$histoire-setup";
|
|
4
|
+
export declare const NOOP_ID = "virtual:$histoire-noop";
|
|
5
|
+
export declare const CONFIG_ID = "virtual:$histoire-config";
|
|
6
|
+
export declare const RESOLVED_CONFIG_ID: string;
|
|
7
|
+
export declare const THEME_ID = "virtual:$histoire-theme";
|
|
8
|
+
export declare const RESOLVED_THEME_ID: string;
|
|
9
|
+
export declare const SEARCH_TITLE_DATA_ID = "virtual:$histoire-search-title-data";
|
|
10
|
+
export declare const RESOLVED_SEARCH_TITLE_DATA_ID: string;
|
|
11
|
+
export declare const SEARCH_DOCS_DATA_ID = "virtual:$histoire-search-docs-data";
|
|
12
|
+
export declare const RESOLVED_SEARCH_DOCS_DATA_ID: string;
|
|
13
|
+
export declare const GENERATED_GLOBAL_SETUP = "virtual:$histoire-generated-global-setup";
|
|
14
|
+
export declare const RESOLVED_GENERATED_GLOBAL_SETUP: string;
|
|
15
|
+
export declare const GENERATED_SETUP_CODE = "virtual:$histoire-generated-setup-code";
|
|
16
|
+
export declare const RESOLVED_GENERATED_SETUP_CODE: string;
|
|
17
|
+
export declare const SUPPORT_PLUGINS_CLIENT = "virtual:$histoire-support-plugins-client";
|
|
18
|
+
export declare const RESOLVED_SUPPORT_PLUGINS_CLIENT: string;
|
|
19
|
+
export declare const SUPPORT_PLUGINS_COLLECT = "virtual:$histoire-support-plugins-collect";
|
|
20
|
+
export declare const RESOLVED_SUPPORT_PLUGINS_COLLECT: string;
|
|
21
|
+
export declare const MARKDOWN_FILES = "virtual:$histoire-markdown-files";
|
|
22
|
+
export declare const RESOLVED_MARKDOWN_FILES: string;
|
|
23
|
+
export * from './markdown.js';
|
|
24
|
+
export * from './noop.js';
|
|
25
|
+
export * from './resolved-config.js';
|
|
26
|
+
export * from './resolved-generated-global-setup.js';
|
|
27
|
+
export * from './resolved-generated-setup-code.js';
|
|
28
|
+
export * from './resolved-markdown-files.js';
|
|
29
|
+
export * from './resolved-stories.js';
|
|
30
|
+
export * from './resolved-support-plugins-client.js';
|
|
31
|
+
export * from './resolved-support-plugins-collect.js';
|
|
32
|
+
export * from './resolved-theme.js';
|
|
33
|
+
export * from './story.js';
|
|
34
|
+
export * from './story-source.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// @TODO wait for virtual modules HMR to work in vite to use `virtual:` and `\0` prefix
|
|
2
|
+
// https://github.com/vitejs/vite/pull/10313
|
|
3
|
+
export const STORIES_ID = 'virtual:$histoire-stories';
|
|
4
|
+
export const RESOLVED_STORIES_ID = `/__resolved__${STORIES_ID}`;
|
|
5
|
+
// export const RESOLVED_STORIES_ID = `\0${STORIES_ID}`
|
|
6
|
+
export const SETUP_ID = 'virtual:$histoire-setup';
|
|
7
|
+
export const NOOP_ID = 'virtual:$histoire-noop';
|
|
8
|
+
export const CONFIG_ID = 'virtual:$histoire-config';
|
|
9
|
+
export const RESOLVED_CONFIG_ID = `/__resolved__${CONFIG_ID}`;
|
|
10
|
+
// export const RESOLVED_CONFIG_ID = `\0${CONFIG_ID}`
|
|
11
|
+
export const THEME_ID = 'virtual:$histoire-theme';
|
|
12
|
+
export const RESOLVED_THEME_ID = `/__resolved__${THEME_ID}.css`;
|
|
13
|
+
// export const RESOLVED_THEME_ID = `\0${THEME_ID}.css`
|
|
14
|
+
export const SEARCH_TITLE_DATA_ID = 'virtual:$histoire-search-title-data';
|
|
15
|
+
export const RESOLVED_SEARCH_TITLE_DATA_ID = `/__resolved__${SEARCH_TITLE_DATA_ID}`;
|
|
16
|
+
// export const RESOLVED_SEARCH_TITLE_DATA_ID = `\0${SEARCH_TITLE_DATA_ID}`
|
|
17
|
+
export const SEARCH_DOCS_DATA_ID = 'virtual:$histoire-search-docs-data';
|
|
18
|
+
export const RESOLVED_SEARCH_DOCS_DATA_ID = `/__resolved__${SEARCH_DOCS_DATA_ID}`;
|
|
19
|
+
// export const RESOLVED_SEARCH_DOCS_DATA_ID = `\0${SEARCH_DOCS_DATA_ID}`
|
|
20
|
+
export const GENERATED_GLOBAL_SETUP = 'virtual:$histoire-generated-global-setup';
|
|
21
|
+
export const RESOLVED_GENERATED_GLOBAL_SETUP = `/__resolved__${GENERATED_GLOBAL_SETUP}`;
|
|
22
|
+
// export const RESOLVED_GENERATED_GLOBAL_SETUP = `\0${GENERATED_GLOBAL_SETUP}`
|
|
23
|
+
export const GENERATED_SETUP_CODE = 'virtual:$histoire-generated-setup-code';
|
|
24
|
+
export const RESOLVED_GENERATED_SETUP_CODE = `/__resolved__${GENERATED_SETUP_CODE}`;
|
|
25
|
+
// export const RESOLVED_GENERATED_SETUP_CODE = `\0${GENERATED_SETUP_CODE}`
|
|
26
|
+
export const SUPPORT_PLUGINS_CLIENT = 'virtual:$histoire-support-plugins-client';
|
|
27
|
+
export const RESOLVED_SUPPORT_PLUGINS_CLIENT = `/__resolved__${SUPPORT_PLUGINS_CLIENT}`;
|
|
28
|
+
// export const RESOLVED_SUPPORT_PLUGINS_CLIENT = `\0${SUPPORT_PLUGINS_CLIENT}`
|
|
29
|
+
export const SUPPORT_PLUGINS_COLLECT = 'virtual:$histoire-support-plugins-collect';
|
|
30
|
+
export const RESOLVED_SUPPORT_PLUGINS_COLLECT = `/__resolved__${SUPPORT_PLUGINS_COLLECT}`;
|
|
31
|
+
// export const RESOLVED_SUPPORT_PLUGINS_COLLECT = `\0${SUPPORT_PLUGINS_COLLECT}`
|
|
32
|
+
export const MARKDOWN_FILES = 'virtual:$histoire-markdown-files';
|
|
33
|
+
export const RESOLVED_MARKDOWN_FILES = `/__resolved__${MARKDOWN_FILES}`;
|
|
34
|
+
// export const RESOLVED_MARKDOWN_FILES = `\0${MARKDOWN_FILES}`
|
|
35
|
+
export * from './markdown.js';
|
|
36
|
+
export * from './noop.js';
|
|
37
|
+
export * from './resolved-config.js';
|
|
38
|
+
export * from './resolved-generated-global-setup.js';
|
|
39
|
+
export * from './resolved-generated-setup-code.js';
|
|
40
|
+
export * from './resolved-markdown-files.js';
|
|
41
|
+
export * from './resolved-stories.js';
|
|
42
|
+
export * from './resolved-support-plugins-client.js';
|
|
43
|
+
export * from './resolved-support-plugins-collect.js';
|
|
44
|
+
export * from './resolved-theme.js';
|
|
45
|
+
export * from './story.js';
|
|
46
|
+
export * from './story-source.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const markdown = (ctx, id) => {
|
|
2
|
+
const fileId = id.slice('/__resolved__virtual:md:'.length);
|
|
3
|
+
const file = ctx.markdownFiles.find(f => f.id === fileId);
|
|
4
|
+
if (!file) {
|
|
5
|
+
throw new Error(`Markdown file not found: ${fileId}`);
|
|
6
|
+
}
|
|
7
|
+
const { html, frontmatter, relativePath } = file;
|
|
8
|
+
return `export const html = ${JSON.stringify(html)}
|
|
9
|
+
export const frontmatter = ${JSON.stringify(frontmatter)}
|
|
10
|
+
export const relativePath = ${JSON.stringify(relativePath)}
|
|
11
|
+
|
|
12
|
+
if (import.meta.hot) {
|
|
13
|
+
import.meta.hot.accept(newModule => {
|
|
14
|
+
if (newModule) {
|
|
15
|
+
window.__hst_md_hmr(newModule)
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
}`;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const noop: () => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const noop = () => `export default () => {}`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const resolvedConfig = (ctx) => {
|
|
2
|
+
let js = `export const config = ${JSON.stringify(ctx.config)}\n`;
|
|
3
|
+
if (ctx.config.theme?.logo) {
|
|
4
|
+
for (const key in ctx.config.theme.logo) {
|
|
5
|
+
js += `import Logo_${key} from '${ctx.config.theme.logo[key]}'\n`;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
js += `export const logos = {${Object.keys(ctx.config.theme?.logo ?? {}).map(key => `${key}: Logo_${key}`).join(', ')}}\n`;
|
|
9
|
+
return js;
|
|
10
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GENERATED_SETUP_CODE } from './index.js';
|
|
2
|
+
import { ID_SEPARATOR } from './util.js';
|
|
3
|
+
export const resolvedGeneratedGlobalSetup = (ctx) => {
|
|
4
|
+
if (ctx.config.setupCode) {
|
|
5
|
+
return [
|
|
6
|
+
// Import
|
|
7
|
+
`${ctx.config.setupCode.map((c, index) => `import * as setup_${index} from '${GENERATED_SETUP_CODE}${ID_SEPARATOR}${index}'`).join('\n')}`,
|
|
8
|
+
// List
|
|
9
|
+
`const setupList = [${ctx.config.setupCode.map((c, index) => `setup_${index}`).join(', ')}]`,
|
|
10
|
+
// Setups
|
|
11
|
+
...ctx.supportPlugins.map(p => p.setupFn).map(fnName => `export async function ${fnName} (payload) {
|
|
12
|
+
for (const setup of setupList) {
|
|
13
|
+
if (setup?.${fnName}) {
|
|
14
|
+
await setup.${fnName}(payload)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}`),
|
|
18
|
+
].join('\n');
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getInjectedImport } from '../util/vendors.js';
|
|
2
|
+
export const resolvedMarkdownFiles = (ctx) => {
|
|
3
|
+
const filesJs = ctx.markdownFiles.map(f => `${JSON.stringify(f.relativePath)}: () => import(${JSON.stringify(`virtual:md:${f.id}`)})`).join(',');
|
|
4
|
+
return `import { reactive } from ${process.env.HISTOIRE_DEV ? `'vue'` : getInjectedImport('@histoire/vendors/vue')}
|
|
5
|
+
export const markdownFiles = reactive({${filesJs}})
|
|
6
|
+
if (import.meta.hot) {
|
|
7
|
+
if (!window.__hst_md_hmr) {
|
|
8
|
+
window.__hst_md_hmr = (newModule) => {
|
|
9
|
+
markdownFiles[newModule.relativePath] = () => newModule
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
import.meta.hot.accept(newModule => {
|
|
14
|
+
Object.assign(markdownFiles, newModule.markdownFiles)
|
|
15
|
+
})
|
|
16
|
+
}`;
|
|
17
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { makeTree } from '../tree.js';
|
|
2
|
+
export const resolvedStories = (ctx) => {
|
|
3
|
+
const resolvedStories = ctx.storyFiles.filter(s => !!s.story);
|
|
4
|
+
const files = resolvedStories.map((file, index) => {
|
|
5
|
+
return {
|
|
6
|
+
id: file.id,
|
|
7
|
+
path: file.treePath,
|
|
8
|
+
filePath: file.relativePath,
|
|
9
|
+
story: {
|
|
10
|
+
...file.story,
|
|
11
|
+
docsText: undefined,
|
|
12
|
+
},
|
|
13
|
+
supportPluginId: file.supportPluginId,
|
|
14
|
+
index,
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
return `${ctx.supportPlugins.map(p => p.importStoriesPrepend).filter(Boolean).join('\n')}
|
|
18
|
+
${resolvedStories.map((file, index) => {
|
|
19
|
+
const supportPlugin = ctx.supportPlugins.find(p => p.id === file.supportPluginId);
|
|
20
|
+
if (!supportPlugin) {
|
|
21
|
+
throw new Error(`Could not find support plugin for story ${file.path}: ${file.supportPluginId}`);
|
|
22
|
+
}
|
|
23
|
+
return supportPlugin.importStoryComponent(file, index);
|
|
24
|
+
}).filter(Boolean).join('\n')}
|
|
25
|
+
export let files = [${files.map((file) => `{${JSON.stringify(file).slice(1, -1)}, component: Comp${file.index}, source: () => import('virtual:story-source:${file.story.id}')}`).join(',\n')}]
|
|
26
|
+
export let tree = ${JSON.stringify(makeTree(ctx.config, resolvedStories))}
|
|
27
|
+
const handlers = []
|
|
28
|
+
export function onUpdate (cb) {
|
|
29
|
+
handlers.push(cb)
|
|
30
|
+
}
|
|
31
|
+
if (import.meta.hot) {
|
|
32
|
+
import.meta.hot.accept(newModule => {
|
|
33
|
+
files = newModule.files
|
|
34
|
+
tree = newModule.tree
|
|
35
|
+
handlers.forEach(h => {
|
|
36
|
+
h(newModule.files, newModule.tree)
|
|
37
|
+
newModule.onUpdate(h)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
}`;
|
|
41
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { PLUGINS_HAVE_DEV } from './util.js';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
export const resolvedSupportPluginsClient = (ctx) => {
|
|
5
|
+
const plugins = ctx.supportPlugins.map(p => `'${p.id}': () => import(${JSON.stringify(require.resolve(`${p.moduleName}/client${process.env.HISTOIRE_DEV && PLUGINS_HAVE_DEV.includes(p.moduleName) ? '-dev' : ''}`, {
|
|
6
|
+
paths: [ctx.root, import.meta.url],
|
|
7
|
+
}))})`);
|
|
8
|
+
return `export const clientSupportPlugins = {
|
|
9
|
+
${plugins.join(',\n ')}
|
|
10
|
+
}`;
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { PLUGINS_HAVE_DEV } from './util.js';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
export const resolvedSupportPluginsCollect = (ctx) => {
|
|
5
|
+
const plugins = ctx.supportPlugins.map(p => `'${p.id}': () => import(${JSON.stringify(require.resolve(`${p.moduleName}/collect${process.env.HISTOIRE_DEV && PLUGINS_HAVE_DEV.includes(p.moduleName) ? '-dev' : ''}`, {
|
|
6
|
+
paths: [ctx.root, import.meta.url],
|
|
7
|
+
}))})`);
|
|
8
|
+
return `export const collectSupportPlugins = {
|
|
9
|
+
${plugins.join(',\n ')}
|
|
10
|
+
}`;
|
|
11
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parseColor } from '../colors.js';
|
|
2
|
+
export const resolvedTheme = (ctx) => {
|
|
3
|
+
let css = '*, ::before, ::after {';
|
|
4
|
+
// Colors
|
|
5
|
+
for (const color in ctx.config.theme?.colors ?? {}) {
|
|
6
|
+
for (const key in ctx.config.theme.colors[color]) {
|
|
7
|
+
css += `--_histoire-color-${color}-${key}: ${parseColor(ctx.config.theme.colors[color][key]).color.join(' ')};`;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
css += '}';
|
|
11
|
+
return css;
|
|
12
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import { resolve } from 'pathe';
|
|
3
|
+
export const storySource = async (ctx, id) => {
|
|
4
|
+
const storyId = id.slice('/__resolved__virtual:story-source:'.length);
|
|
5
|
+
const storyFile = ctx.storyFiles.find(f => f.story?.id === storyId);
|
|
6
|
+
if (storyFile) {
|
|
7
|
+
let source;
|
|
8
|
+
if (storyFile.virtual) {
|
|
9
|
+
source = storyFile.moduleCode;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
source = await fs.readFile(resolve(ctx.root, storyFile.relativePath), 'utf-8');
|
|
13
|
+
}
|
|
14
|
+
return `export default ${JSON.stringify(source)}`;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { resolve } from 'pathe';
|
|
2
|
+
import * as VirtualFiles from './index.js';
|
|
3
|
+
import { ID_SEPARATOR } from './util.js';
|
|
4
|
+
import { generateDocSearchData, generateTitleSearchData, getSearchDataJS } from '../search.js';
|
|
5
|
+
export const createVirtualFilesPlugin = (ctx, isServer) => ({
|
|
6
|
+
name: 'histoire-virtual-files',
|
|
7
|
+
async resolveId(id, importer) {
|
|
8
|
+
if (id.startsWith(VirtualFiles.STORIES_ID)) {
|
|
9
|
+
return VirtualFiles.RESOLVED_STORIES_ID;
|
|
10
|
+
}
|
|
11
|
+
if (id.startsWith(VirtualFiles.SETUP_ID)) {
|
|
12
|
+
const setupFileConfig = ctx.config.setupFile;
|
|
13
|
+
if (setupFileConfig) {
|
|
14
|
+
let file;
|
|
15
|
+
if (typeof setupFileConfig === 'string') {
|
|
16
|
+
file = setupFileConfig;
|
|
17
|
+
}
|
|
18
|
+
else if (isServer && 'server' in setupFileConfig) {
|
|
19
|
+
file = setupFileConfig.server;
|
|
20
|
+
}
|
|
21
|
+
else if (!isServer && 'browser' in setupFileConfig) {
|
|
22
|
+
file = setupFileConfig.browser;
|
|
23
|
+
}
|
|
24
|
+
if (file) {
|
|
25
|
+
return this.resolve(resolve(ctx.root, file), importer, {
|
|
26
|
+
skipSelf: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return VirtualFiles.NOOP_ID;
|
|
31
|
+
}
|
|
32
|
+
if (id.startsWith(VirtualFiles.CONFIG_ID)) {
|
|
33
|
+
return VirtualFiles.RESOLVED_CONFIG_ID;
|
|
34
|
+
}
|
|
35
|
+
if (id.startsWith(VirtualFiles.THEME_ID)) {
|
|
36
|
+
return VirtualFiles.RESOLVED_THEME_ID;
|
|
37
|
+
}
|
|
38
|
+
if (id.startsWith(VirtualFiles.SEARCH_TITLE_DATA_ID)) {
|
|
39
|
+
return VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID;
|
|
40
|
+
}
|
|
41
|
+
if (id.startsWith(VirtualFiles.SEARCH_DOCS_DATA_ID)) {
|
|
42
|
+
return VirtualFiles.RESOLVED_SEARCH_DOCS_DATA_ID;
|
|
43
|
+
}
|
|
44
|
+
if (id.startsWith(VirtualFiles.GENERATED_GLOBAL_SETUP)) {
|
|
45
|
+
return VirtualFiles.RESOLVED_GENERATED_GLOBAL_SETUP;
|
|
46
|
+
}
|
|
47
|
+
if (id.startsWith(VirtualFiles.GENERATED_SETUP_CODE)) {
|
|
48
|
+
const [, index] = id.split(ID_SEPARATOR);
|
|
49
|
+
return `${VirtualFiles.RESOLVED_GENERATED_SETUP_CODE}${ID_SEPARATOR}${index}`;
|
|
50
|
+
}
|
|
51
|
+
if (id.startsWith(VirtualFiles.SUPPORT_PLUGINS_CLIENT)) {
|
|
52
|
+
return VirtualFiles.RESOLVED_SUPPORT_PLUGINS_CLIENT;
|
|
53
|
+
}
|
|
54
|
+
if (id.startsWith(VirtualFiles.SUPPORT_PLUGINS_COLLECT)) {
|
|
55
|
+
return VirtualFiles.RESOLVED_SUPPORT_PLUGINS_COLLECT;
|
|
56
|
+
}
|
|
57
|
+
if (id.startsWith(VirtualFiles.MARKDOWN_FILES)) {
|
|
58
|
+
return VirtualFiles.RESOLVED_MARKDOWN_FILES;
|
|
59
|
+
}
|
|
60
|
+
if (id.startsWith('virtual:story:')) {
|
|
61
|
+
return `\0${id}`;
|
|
62
|
+
}
|
|
63
|
+
if (id.startsWith('virtual:story-source:')) {
|
|
64
|
+
return `/__resolved__${id}`;
|
|
65
|
+
// @TODO
|
|
66
|
+
// return `\0${id}`
|
|
67
|
+
}
|
|
68
|
+
if (id.startsWith('virtual:md:')) {
|
|
69
|
+
return `/__resolved__${id}`;
|
|
70
|
+
// @TODO
|
|
71
|
+
// return `\0${id}`
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
async load(id) {
|
|
75
|
+
if (id === VirtualFiles.RESOLVED_STORIES_ID) {
|
|
76
|
+
return VirtualFiles.resolvedStories(ctx);
|
|
77
|
+
}
|
|
78
|
+
if (id === VirtualFiles.NOOP_ID) {
|
|
79
|
+
return VirtualFiles.noop();
|
|
80
|
+
}
|
|
81
|
+
if (id === VirtualFiles.RESOLVED_CONFIG_ID) {
|
|
82
|
+
return VirtualFiles.resolvedConfig(ctx);
|
|
83
|
+
}
|
|
84
|
+
if (id === VirtualFiles.RESOLVED_THEME_ID) {
|
|
85
|
+
return VirtualFiles.resolvedTheme(ctx);
|
|
86
|
+
}
|
|
87
|
+
if (id === VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID) {
|
|
88
|
+
return getSearchDataJS(await generateTitleSearchData(ctx));
|
|
89
|
+
}
|
|
90
|
+
if (id === VirtualFiles.RESOLVED_SEARCH_DOCS_DATA_ID) {
|
|
91
|
+
return getSearchDataJS(await generateDocSearchData(ctx));
|
|
92
|
+
}
|
|
93
|
+
if (id === VirtualFiles.RESOLVED_GENERATED_GLOBAL_SETUP) {
|
|
94
|
+
return VirtualFiles.resolvedGeneratedGlobalSetup(ctx);
|
|
95
|
+
}
|
|
96
|
+
if (id.startsWith(VirtualFiles.RESOLVED_GENERATED_SETUP_CODE)) {
|
|
97
|
+
return VirtualFiles.resolvedGeneratedSetupCode(ctx, id);
|
|
98
|
+
}
|
|
99
|
+
if (id === VirtualFiles.RESOLVED_SUPPORT_PLUGINS_CLIENT) {
|
|
100
|
+
return VirtualFiles.resolvedSupportPluginsClient(ctx);
|
|
101
|
+
}
|
|
102
|
+
if (id === VirtualFiles.RESOLVED_SUPPORT_PLUGINS_COLLECT) {
|
|
103
|
+
return VirtualFiles.resolvedSupportPluginsCollect(ctx);
|
|
104
|
+
}
|
|
105
|
+
if (id === VirtualFiles.RESOLVED_MARKDOWN_FILES) {
|
|
106
|
+
return VirtualFiles.resolvedMarkdownFiles(ctx);
|
|
107
|
+
}
|
|
108
|
+
if (id.startsWith('\0virtual:story:')) {
|
|
109
|
+
return VirtualFiles.story(ctx, id);
|
|
110
|
+
}
|
|
111
|
+
if (id.startsWith('/__resolved__virtual:story-source:')) {
|
|
112
|
+
return VirtualFiles.storySource(ctx, id);
|
|
113
|
+
}
|
|
114
|
+
if (id.startsWith('/__resolved__virtual:md:')) {
|
|
115
|
+
return VirtualFiles.markdown(ctx, id);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
});
|
package/dist/node/vite.d.ts
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
1
|
import { InlineConfig } from 'vite';
|
|
2
2
|
import { Context } from './context.js';
|
|
3
|
-
export declare const STORIES_ID = "virtual:$histoire-stories";
|
|
4
|
-
export declare const RESOLVED_STORIES_ID: string;
|
|
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
|
-
export declare const RESOLVED_CONFIG_ID: string;
|
|
9
|
-
export declare const THEME_ID = "virtual:$histoire-theme";
|
|
10
|
-
export declare const RESOLVED_THEME_ID: string;
|
|
11
|
-
export declare const SEARCH_TITLE_DATA_ID = "virtual:$histoire-search-title-data";
|
|
12
|
-
export declare const RESOLVED_SEARCH_TITLE_DATA_ID: string;
|
|
13
|
-
export declare const SEARCH_DOCS_DATA_ID = "virtual:$histoire-search-docs-data";
|
|
14
|
-
export declare const RESOLVED_SEARCH_DOCS_DATA_ID: string;
|
|
15
|
-
export declare const GENERATED_GLOBAL_SETUP = "virtual:$histoire-generated-global-setup";
|
|
16
|
-
export declare const RESOLVED_GENERATED_GLOBAL_SETUP: string;
|
|
17
|
-
export declare const GENERATED_SETUP_CODE = "virtual:$histoire-generated-setup-code";
|
|
18
|
-
export declare const RESOLVED_GENERATED_SETUP_CODE: string;
|
|
19
|
-
export declare const SUPPORT_PLUGINS_CLIENT = "virtual:$histoire-support-plugins-client";
|
|
20
|
-
export declare const RESOLVED_SUPPORT_PLUGINS_CLIENT: string;
|
|
21
|
-
export declare const SUPPORT_PLUGINS_COLLECT = "virtual:$histoire-support-plugins-collect";
|
|
22
|
-
export declare const RESOLVED_SUPPORT_PLUGINS_COLLECT: string;
|
|
23
|
-
export declare const MARKDOWN_FILES = "virtual:$histoire-markdown-files";
|
|
24
|
-
export declare const RESOLVED_MARKDOWN_FILES: string;
|
|
25
3
|
export declare function mergeHistoireViteConfig(viteConfig: InlineConfig, ctx: Context): Promise<InlineConfig>;
|
|
26
4
|
export interface ViteConfigWithPlugins {
|
|
27
5
|
viteConfig: InlineConfig;
|