histoire 0.11.6 → 0.11.7

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.
@@ -28,7 +28,8 @@ export async function build(ctx) {
28
28
  const { stop } = await createMarkdownFilesWatcher(ctx);
29
29
  await stop();
30
30
  }
31
- const server = await createViteServer(await getViteConfigWithPlugins(true, ctx));
31
+ const { viteConfig } = await getViteConfigWithPlugins(true, ctx);
32
+ const server = await createViteServer(viteConfig);
32
33
  await server.pluginContainer.buildStart({});
33
34
  const moduleLoader = useModuleLoader({
34
35
  server,
@@ -54,7 +55,8 @@ export async function build(ctx) {
54
55
  const storyCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ? 1 : 0), 0);
55
56
  const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0);
56
57
  const emptyStoryCount = ctx.storyFiles.length - storyCount;
57
- const buildViteConfig = mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
58
+ const { viteConfig: buildViteConfigRaw } = await getViteConfigWithPlugins(false, ctx);
59
+ const buildViteConfig = mergeViteConfig(buildViteConfigRaw, {
58
60
  mode: 'development',
59
61
  build: {
60
62
  lib: false,
@@ -125,7 +125,6 @@ export default _defineComponent({
125
125
  render() {
126
126
  return _h('div', {
127
127
  ref: 'sandbox',
128
- class: '__histoire-sandbox htw-overflow-auto',
129
128
  });
130
129
  },
131
130
  });
@@ -9,12 +9,12 @@ export async function devCommand(options) {
9
9
  const ctx = await createContext({
10
10
  mode: 'dev',
11
11
  });
12
- const { server, close } = await createServer(ctx, { port: options.port });
12
+ const { server, viteConfigFile, close } = await createServer(ctx, { port: options.port });
13
13
  server.printUrls();
14
14
  // Histoire config watcher
15
15
  let watcher;
16
- if (server.config.configFile) {
17
- watcher = chokidar.watch(server.config.configFile, {
16
+ if (viteConfigFile) {
17
+ watcher = chokidar.watch(viteConfigFile, {
18
18
  ignoreInitial: true,
19
19
  });
20
20
  watcher.on('change', () => {
@@ -139,6 +139,7 @@ export async function loadConfigFile(configFile) {
139
139
  try {
140
140
  const result = jiti(__filename, {
141
141
  esmResolve: true,
142
+ requireCache: false,
142
143
  })(configFile);
143
144
  if (!result.default) {
144
145
  throw new Error(`Expected default export in ${configFile}`);
@@ -4,5 +4,6 @@ export interface CreateServerOptions {
4
4
  }
5
5
  export declare function createServer(ctx: Context, options?: CreateServerOptions): Promise<{
6
6
  server: import("vite").ViteDevServer;
7
+ viteConfigFile: string;
7
8
  close: () => Promise<void>;
8
9
  }>;
@@ -10,11 +10,15 @@ import { wrapLogError } from './util/log.js';
10
10
  import { createMarkdownFilesWatcher, onMarkdownListChange } from './markdown.js';
11
11
  export async function createServer(ctx, options = {}) {
12
12
  const getViteServer = async (collecting) => {
13
- const server = await createViteServer(await getViteConfigWithPlugins(collecting, ctx));
13
+ const { viteConfig, viteConfigFile } = await getViteConfigWithPlugins(collecting, ctx);
14
+ const server = await createViteServer(viteConfig);
14
15
  await server.pluginContainer.buildStart({});
15
- return server;
16
+ return {
17
+ server,
18
+ viteConfigFile,
19
+ };
16
20
  };
17
- const [server, nodeServer, , { stop: stopMdFileWatcher },] = await Promise.all([
21
+ const [{ server, viteConfigFile }, { server: nodeServer }, , { stop: stopMdFileWatcher },] = await Promise.all([
18
22
  getViteServer(false),
19
23
  getViteServer(true),
20
24
  watchStories(ctx),
@@ -157,6 +161,7 @@ export async function createServer(ctx, options = {}) {
157
161
  collect();
158
162
  return {
159
163
  server,
164
+ viteConfigFile,
160
165
  close,
161
166
  };
162
167
  }
@@ -23,4 +23,8 @@ export declare const RESOLVED_SUPPORT_PLUGINS_COLLECT: string;
23
23
  export declare const MARKDOWN_FILES = "virtual:$histoire-markdown-files";
24
24
  export declare const RESOLVED_MARKDOWN_FILES: string;
25
25
  export declare function mergeHistoireViteConfig(viteConfig: InlineConfig, ctx: Context): Promise<InlineConfig>;
26
- export declare function getViteConfigWithPlugins(isServer: boolean, ctx: Context): Promise<InlineConfig>;
26
+ export interface ViteConfigWithPlugins {
27
+ viteConfig: InlineConfig;
28
+ viteConfigFile: string | null;
29
+ }
30
+ export declare function getViteConfigWithPlugins(isServer: boolean, ctx: Context): Promise<ViteConfigWithPlugins>;
package/dist/node/vite.js CHANGED
@@ -3,7 +3,6 @@ import { relative, resolve, join, dirname } from 'pathe';
3
3
  import { mergeConfig as mergeViteConfig, loadConfigFromFile as loadViteConfigFromFile, } from 'vite';
4
4
  import { lookup as lookupMime } from 'mrmime';
5
5
  import fs from 'fs-extra';
6
- import ViteInspect from 'vite-plugin-inspect';
7
6
  import { APP_PATH, TEMP_PATH } from './alias.js';
8
7
  import { notifyStoryChange } from './stories.js';
9
8
  import { makeTree } from './tree.js';
@@ -99,7 +98,6 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
99
98
  }
100
99
  return result;
101
100
  }
102
- plugins.push(ViteInspect());
103
101
  plugins.push({
104
102
  name: 'histoire-vite-plugin',
105
103
  config() {
@@ -172,7 +170,7 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
172
170
  else if (isServer && 'server' in setupFileConfig) {
173
171
  file = setupFileConfig.server;
174
172
  }
175
- else if ('browser' in setupFileConfig) {
173
+ else if (!isServer && 'browser' in setupFileConfig) {
176
174
  file = setupFileConfig.browser;
177
175
  }
178
176
  if (file) {
@@ -532,8 +530,12 @@ if (import.meta.hot) {
532
530
  },
533
531
  });
534
532
  }
535
- return mergeViteConfig(inlineConfig, {
533
+ const viteConfig = mergeViteConfig(inlineConfig, {
536
534
  configFile: false,
537
535
  plugins,
538
536
  });
537
+ return {
538
+ viteConfig,
539
+ viteConfigFile: userViteConfigFile?.path ?? null,
540
+ };
539
541
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.11.6",
3
+ "version": "0.11.7",
4
4
  "description": "A fast story book powered by Vite",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,10 +33,10 @@
33
33
  "histoire": "./bin.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@histoire/app": "^0.11.6",
37
- "@histoire/controls": "^0.11.6",
38
- "@histoire/shared": "^0.11.6",
39
- "@histoire/vendors": "^0.11.6",
36
+ "@histoire/app": "^0.11.7",
37
+ "@histoire/controls": "^0.11.7",
38
+ "@histoire/shared": "^0.11.7",
39
+ "@histoire/vendors": "^0.11.7",
40
40
  "@types/flexsearch": "^0.7.3",
41
41
  "@types/markdown-it": "^12.2.3",
42
42
  "birpc": "^0.1.1",
@@ -63,7 +63,6 @@
63
63
  "shiki": "0.10.1",
64
64
  "sirv": "^2.0.2",
65
65
  "tinypool": "^0.1.2",
66
- "vite-plugin-inspect": "^0.7.5",
67
66
  "vite-node": "0.23.4"
68
67
  },
69
68
  "peerDependencies": {
package/src/node/build.ts CHANGED
@@ -45,7 +45,8 @@ export async function build (ctx: Context) {
45
45
  await stop()
46
46
  }
47
47
 
48
- const server = await createViteServer(await getViteConfigWithPlugins(true, ctx))
48
+ const { viteConfig } = await getViteConfigWithPlugins(true, ctx)
49
+ const server = await createViteServer(viteConfig)
49
50
  await server.pluginContainer.buildStart({})
50
51
 
51
52
  const moduleLoader = useModuleLoader({
@@ -75,7 +76,8 @@ export async function build (ctx: Context) {
75
76
  const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0)
76
77
  const emptyStoryCount = ctx.storyFiles.length - storyCount
77
78
 
78
- const buildViteConfig: ViteInlineConfig = mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
79
+ const { viteConfig: buildViteConfigRaw } = await getViteConfigWithPlugins(false, ctx)
80
+ const buildViteConfig: ViteInlineConfig = mergeViteConfig(buildViteConfigRaw, {
79
81
  mode: 'development',
80
82
  build: {
81
83
  lib: false,
@@ -160,7 +160,6 @@ export default _defineComponent({
160
160
  render () {
161
161
  return _h('div', {
162
162
  ref: 'sandbox',
163
- class: '__histoire-sandbox htw-overflow-auto',
164
163
  })
165
164
  },
166
165
  })
@@ -15,13 +15,13 @@ export async function devCommand (options: DevOptions) {
15
15
  const ctx = await createContext({
16
16
  mode: 'dev',
17
17
  })
18
- const { server, close } = await createServer(ctx, { port: options.port })
18
+ const { server, viteConfigFile, close } = await createServer(ctx, { port: options.port })
19
19
  server.printUrls()
20
20
 
21
21
  // Histoire config watcher
22
22
  let watcher: chokidar.FSWatcher
23
- if (server.config.configFile) {
24
- watcher = chokidar.watch(server.config.configFile, {
23
+ if (viteConfigFile) {
24
+ watcher = chokidar.watch(viteConfigFile, {
25
25
  ignoreInitial: true,
26
26
  })
27
27
  watcher.on('change', () => {
@@ -154,6 +154,7 @@ export async function loadConfigFile (configFile: string): Promise<Partial<Histo
154
154
  try {
155
155
  const result = jiti(__filename, {
156
156
  esmResolve: true,
157
+ requireCache: false,
157
158
  })(configFile)
158
159
  if (!result.default) {
159
160
  throw new Error(`Expected default export in ${configFile}`)
@@ -17,14 +17,18 @@ export interface CreateServerOptions {
17
17
 
18
18
  export async function createServer (ctx: Context, options: CreateServerOptions = {}) {
19
19
  const getViteServer = async (collecting: boolean) => {
20
- const server = await createViteServer(await getViteConfigWithPlugins(collecting, ctx))
20
+ const { viteConfig, viteConfigFile } = await getViteConfigWithPlugins(collecting, ctx)
21
+ const server = await createViteServer(viteConfig)
21
22
  await server.pluginContainer.buildStart({})
22
- return server
23
+ return {
24
+ server,
25
+ viteConfigFile,
26
+ }
23
27
  }
24
28
 
25
29
  const [
26
- server,
27
- nodeServer,
30
+ { server, viteConfigFile },
31
+ { server: nodeServer },
28
32
  ,
29
33
  { stop: stopMdFileWatcher },
30
34
  ] = await Promise.all([
@@ -199,6 +203,7 @@ export async function createServer (ctx: Context, options: CreateServerOptions =
199
203
 
200
204
  return {
201
205
  server,
206
+ viteConfigFile,
202
207
  close,
203
208
  }
204
209
  }
package/src/node/vite.ts CHANGED
@@ -9,7 +9,6 @@ import {
9
9
  } from 'vite'
10
10
  import { lookup as lookupMime } from 'mrmime'
11
11
  import fs from 'fs-extra'
12
- import ViteInspect from 'vite-plugin-inspect'
13
12
  import { APP_PATH, TEMP_PATH } from './alias.js'
14
13
  import { Context } from './context.js'
15
14
  import { notifyStoryChange } from './stories.js'
@@ -97,7 +96,12 @@ export async function mergeHistoireViteConfig (viteConfig: InlineConfig, ctx: Co
97
96
  return viteConfig
98
97
  }
99
98
 
100
- export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context): Promise<InlineConfig> {
99
+ export interface ViteConfigWithPlugins {
100
+ viteConfig: InlineConfig
101
+ viteConfigFile: string | null
102
+ }
103
+
104
+ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context): Promise<ViteConfigWithPlugins> {
101
105
  const userViteConfigFile = await loadViteConfigFromFile({ command: ctx.mode === 'dev' ? 'serve' : 'build', mode: ctx.mode })
102
106
  const userViteConfig = mergeViteConfig(userViteConfigFile?.config ?? {}, { server: { port: 6006 } })
103
107
 
@@ -117,8 +121,6 @@ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context)
117
121
  return result
118
122
  }
119
123
 
120
- plugins.push(ViteInspect())
121
-
122
124
  plugins.push({
123
125
  name: 'histoire-vite-plugin',
124
126
 
@@ -191,7 +193,7 @@ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context)
191
193
  file = setupFileConfig
192
194
  } else if (isServer && 'server' in setupFileConfig) {
193
195
  file = setupFileConfig.server
194
- } else if ('browser' in setupFileConfig) {
196
+ } else if (!isServer && 'browser' in setupFileConfig) {
195
197
  file = setupFileConfig.browser
196
198
  }
197
199
  if (file) {
@@ -574,8 +576,13 @@ if (import.meta.hot) {
574
576
  })
575
577
  }
576
578
 
577
- return mergeViteConfig(inlineConfig, {
579
+ const viteConfig = mergeViteConfig(inlineConfig, {
578
580
  configFile: false,
579
581
  plugins,
580
582
  }) as InlineConfig
583
+
584
+ return {
585
+ viteConfig,
586
+ viteConfigFile: userViteConfigFile?.path ?? null,
587
+ }
581
588
  }