histoire 0.7.7 → 0.7.8

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.
@@ -81,7 +81,7 @@ export async function build(ctx) {
81
81
  const vuePlugin = config.plugins.find((p) => p.name === 'vite:vue');
82
82
  if (vuePlugin) {
83
83
  const original = vuePlugin.configureServer.bind(vuePlugin);
84
- vuePlugin.configureServer = () => {
84
+ vuePlugin.configureServer = (s) => {
85
85
  original({
86
86
  ...server,
87
87
  config: {
@@ -93,10 +93,17 @@ export async function build(ctx) {
93
93
  },
94
94
  });
95
95
  };
96
- vuePlugin.configureServer();
96
+ vuePlugin.configureServer(server);
97
97
  }
98
98
  },
99
99
  });
100
+ buildViteConfig.plugins.push({
101
+ name: 'histoire-build-config-override',
102
+ config(config) {
103
+ // Don't externalize
104
+ config.build.rollupOptions.external = [];
105
+ },
106
+ });
100
107
  const results = await viteBuild(buildViteConfig);
101
108
  const result = Array.isArray(results) ? results[0] : results;
102
109
  const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset');
@@ -29,7 +29,7 @@ export async function devCommand(options) {
29
29
  async function restart(source) {
30
30
  if (stop) {
31
31
  console.log(pc.blue(`${source} config changed, restarting...`));
32
- stop();
32
+ await stop();
33
33
  stop = null; // Don't call stop again until new start() is done
34
34
  stop = await start();
35
35
  }
@@ -4,6 +4,7 @@ import { onStoryChange, 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
+ import { wrapLogError } from './util/log.js';
7
8
  export async function createServer(ctx, port) {
8
9
  const server = await createViteServer(await getViteConfigWithPlugins(false, ctx));
9
10
  await server.pluginContainer.buildStart({});
@@ -119,11 +120,11 @@ export async function createServer(ctx, port) {
119
120
  });
120
121
  async function close() {
121
122
  for (const cb of pluginOnCleanups) {
122
- await cb();
123
+ await wrapLogError('plugin.onDev.onCleanup', () => cb());
123
124
  }
124
- await server.close();
125
- await nodeServer.close();
126
- await destroyCollectStories();
125
+ await wrapLogError('server.close', () => server.close());
126
+ await wrapLogError('nodeServer', () => nodeServer.close());
127
+ await wrapLogError('destroyCollectStories', () => destroyCollectStories());
127
128
  }
128
129
  return {
129
130
  server,
@@ -0,0 +1 @@
1
+ export declare function wrapLogError(id: string, cb: () => unknown): Promise<void>;
@@ -0,0 +1,9 @@
1
+ import pc from 'picocolors';
2
+ export async function wrapLogError(id, cb) {
3
+ try {
4
+ await cb();
5
+ }
6
+ catch (e) {
7
+ console.error(pc.red(`[Error] ${id}: ${e}`));
8
+ }
9
+ }
package/dist/node/vite.js CHANGED
@@ -84,7 +84,7 @@ export async function getViteConfigWithPlugins(server, ctx) {
84
84
  allow: [DIST_PATH, TEMP_PATH, resolvedViteConfig.root, process.cwd()],
85
85
  },
86
86
  watch: {
87
- ignored: [`!**/node_modules/.histoire/**`],
87
+ ignored: [`!**/node_modules/.histoire/**`, '**/vite.config.*'],
88
88
  },
89
89
  },
90
90
  define: {
package/index.d.ts CHANGED
@@ -1,3 +1 @@
1
- import './src/components'
2
-
3
1
  export * from './dist/node/index'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "description": "A fast story book powered by Vite",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,9 +33,9 @@
33
33
  "histoire": "./bin.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@histoire/controls": "^0.7.7",
37
- "@histoire/plugin-vue": "^0.7.7",
38
- "@histoire/shared": "^0.7.7",
36
+ "@histoire/controls": "^0.7.8",
37
+ "@histoire/plugin-vue": "^0.7.8",
38
+ "@histoire/shared": "^0.7.8",
39
39
  "@iconify/vue": "^3.2.1",
40
40
  "@types/markdown-it": "^12.2.3",
41
41
  "@vueuse/core": "^8.2.5",
package/src/node/build.ts CHANGED
@@ -2,8 +2,10 @@ import { join } from 'pathe'
2
2
  import {
3
3
  build as viteBuild,
4
4
  createServer as createViteServer,
5
+ InlineConfig as ViteInlineConfig,
5
6
  ResolvedConfig as ViteConfig,
6
7
  mergeConfig as mergeViteConfig,
8
+ Plugin as VitePlugin,
7
9
  } from 'vite'
8
10
  import fs from 'fs-extra'
9
11
  import { lookup as lookupMime } from 'mrmime'
@@ -65,7 +67,7 @@ export async function build (ctx: Context) {
65
67
  const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0)
66
68
  const emptyStoryCount = ctx.storyFiles.length - storyCount
67
69
 
68
- const buildViteConfig = mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
70
+ const buildViteConfig: ViteInlineConfig = mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
69
71
  mode: 'development',
70
72
  build: {
71
73
  rollupOptions: {
@@ -95,10 +97,10 @@ export async function build (ctx: Context) {
95
97
  buildViteConfig.plugins.push({
96
98
  name: 'histoire-vue-plugin-override',
97
99
  config (config) {
98
- const vuePlugin = config.plugins.find((p: any) => p.name === 'vite:vue')
100
+ const vuePlugin = config.plugins.find((p: any) => p.name === 'vite:vue') as VitePlugin
99
101
  if (vuePlugin) {
100
102
  const original = vuePlugin.configureServer.bind(vuePlugin)
101
- vuePlugin.configureServer = () => {
103
+ vuePlugin.configureServer = (s) => {
102
104
  original({
103
105
  ...server,
104
106
  config: {
@@ -110,11 +112,19 @@ export async function build (ctx: Context) {
110
112
  },
111
113
  })
112
114
  }
113
- vuePlugin.configureServer()
115
+ vuePlugin.configureServer(server)
114
116
  }
115
117
  },
116
118
  })
117
119
 
120
+ buildViteConfig.plugins.push({
121
+ name: 'histoire-build-config-override',
122
+ config (config) {
123
+ // Don't externalize
124
+ config.build.rollupOptions.external = []
125
+ },
126
+ })
127
+
118
128
  const results = await viteBuild(buildViteConfig)
119
129
  const result = Array.isArray(results) ? results[0] : results as RollupOutput
120
130
 
@@ -38,7 +38,7 @@ export async function devCommand (options: DevOptions) {
38
38
  async function restart (source: string) {
39
39
  if (stop) {
40
40
  console.log(pc.blue(`${source} config changed, restarting...`))
41
- stop()
41
+ await stop()
42
42
  stop = null // Don't call stop again until new start() is done
43
43
  stop = await start()
44
44
  }
@@ -6,6 +6,7 @@ import { onStoryChange, watchStories } from './stories.js'
6
6
  import { useCollectStories } from './collect/index.js'
7
7
  import { DevPluginApi } from './plugin.js'
8
8
  import { useModuleLoader } from './load.js'
9
+ import { wrapLogError } from './util/log.js'
9
10
 
10
11
  export async function createServer (ctx: Context, port: number) {
11
12
  const server = await createViteServer(await getViteConfigWithPlugins(false, ctx))
@@ -143,11 +144,11 @@ export async function createServer (ctx: Context, port: number) {
143
144
 
144
145
  async function close () {
145
146
  for (const cb of pluginOnCleanups) {
146
- await cb()
147
+ await wrapLogError('plugin.onDev.onCleanup', () => cb())
147
148
  }
148
- await server.close()
149
- await nodeServer.close()
150
- await destroyCollectStories()
149
+ await wrapLogError('server.close', () => server.close())
150
+ await wrapLogError('nodeServer', () => nodeServer.close())
151
+ await wrapLogError('destroyCollectStories', () => destroyCollectStories())
151
152
  }
152
153
 
153
154
  return {
@@ -0,0 +1,9 @@
1
+ import pc from 'picocolors'
2
+
3
+ export async function wrapLogError (id: string, cb: () => unknown) {
4
+ try {
5
+ await cb()
6
+ } catch (e) {
7
+ console.error(pc.red(`[Error] ${id}: ${e}`))
8
+ }
9
+ }
package/src/node/vite.ts CHANGED
@@ -100,7 +100,7 @@ export async function getViteConfigWithPlugins (server: boolean, ctx: Context):
100
100
  allow: [DIST_PATH, TEMP_PATH, resolvedViteConfig.root, process.cwd()],
101
101
  },
102
102
  watch: {
103
- ignored: [`!**/node_modules/.histoire/**`],
103
+ ignored: [`!**/node_modules/.histoire/**`, '**/vite.config.*'],
104
104
  },
105
105
  },
106
106
  define: {
package/vue.d.ts ADDED
@@ -0,0 +1 @@
1
+ import '@histoire/plugin-vue/components'