histoire 1.0.0-alpha.3 → 1.0.0-alpha.5

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.
@@ -72,9 +72,10 @@ export function tailwindTokens(options = {}) {
72
72
  };
73
73
  }
74
74
  function storyTemplate(tailwindConfig) {
75
- // import 'histoire-style'
76
- // import './style.css'
77
- return `import { createApp, h, markRaw, ref } from ${getInjectedImport('@histoire/vendors/vue')}
75
+ return `
76
+ import 'histoire-style'
77
+ import './style.css'
78
+ import { createApp, h, markRaw, ref } from ${getInjectedImport('@histoire/vendors/vue')}
78
79
  import {
79
80
  HstColorShades,
80
81
  HstTokenList,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/collect/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAEzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAY5C,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,aAAa,CAAA;IACrB,UAAU,CAAC,EAAE,aAAa,CAAA;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,EAAE,GAAG,EAAE,OAAO;;kCAyEpC,eAAe;;EA+D3D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/collect/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAEzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAa5C,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,aAAa,CAAA;IACrB,UAAU,CAAC,EAAE,aAAa,CAAA;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,EAAE,GAAG,EAAE,OAAO;;kCA0EpC,eAAe;;EA+D3D"}
@@ -2,9 +2,10 @@ import { cpus } from 'node:os';
2
2
  import { MessageChannel } from 'node:worker_threads';
3
3
  import Tinypool from '@akryum/tinypool';
4
4
  import { createBirpc } from 'birpc';
5
- import { relative } from 'pathe';
5
+ import path, { relative } from 'pathe';
6
6
  import pc from 'picocolors';
7
7
  import { ViteNodeServer } from 'vite-node/server';
8
+ import { TEMP_PATH } from '../alias.js';
8
9
  import { createPath } from '../tree.js';
9
10
  import { slash } from '../util/fs.js';
10
11
  export function useCollectStories(options, ctx) {
@@ -21,6 +22,7 @@ export function useCollectStories(options, ctx) {
21
22
  // @TODO temporary fix for https://github.com/histoire-dev/histoire/issues/409
22
23
  /vite\w*\/dist\/client\/(client|env).mjs/,
23
24
  ...ctx.config.viteNodeInlineDeps ?? [],
25
+ new RegExp(path.resolve(TEMP_PATH, 'plugins')),
24
26
  ],
25
27
  fallbackCJS: true,
26
28
  },
@@ -21,7 +21,7 @@ export async function createServer(ctx, options = {}) {
21
21
  }
22
22
  }
23
23
  const server = await createViteServer(mergeViteConfig(viteConfig, {
24
- optimizeDeps: { include: [], noDiscovery: true },
24
+ optimizeDeps: { include: viteConfig.optimizeDeps?.include ?? [], noDiscovery: collecting },
25
25
  }));
26
26
  await server.pluginContainer.buildStart({});
27
27
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"stories.d.ts","sourceRoot":"","sources":["../../src/node/stories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAO3C,KAAK,kBAAkB,GAAG,CAAC,IAAI,CAAC,EAAE,eAAe,KAAK,OAAO,CAAA;AAG7D;;;GAGG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BAAsB,cAAc,CAAC,UAAU,EAAE,OAAO,iBAWvD"}
@@ -32,16 +32,27 @@ export function notifyStoryListChange() {
32
32
  let context;
33
33
  export async function watchStories(newContext) {
34
34
  context = newContext;
35
- const watcher = chokidar.watch('.', {
35
+ const baseWatchPaths = Array.from(new Set(context.config.storyMatch.map((pattern) => {
36
+ const segments = pattern.split('/');
37
+ return segments.slice(0, segments.findIndex(segment => segment.includes('*'))).join('/') || '.';
38
+ })));
39
+ const resolvedStoryIgnored = context.config.storyIgnored.map((pattern) => {
40
+ return resolve(context.root, pattern);
41
+ });
42
+ const resolveStoryMatch = context.config.storyMatch.map((pattern) => {
43
+ return resolve(context.root, pattern);
44
+ });
45
+ const watcher = chokidar.watch(baseWatchPaths, {
36
46
  cwd: context.root,
37
47
  ignored: (path, stats) => {
38
- if (context.config.storyIgnored.some(pattern => micromatch.isMatch(path, pattern))) {
48
+ if (resolvedStoryIgnored.some(pattern => micromatch.isMatch(path, pattern))) {
39
49
  return true;
40
50
  }
41
- if (context.config.storyMatch.some(pattern => micromatch.isMatch(path, pattern))) {
51
+ if (resolveStoryMatch.some(pattern => micromatch.isMatch(path, pattern))) {
42
52
  return false;
43
53
  }
44
- return stats?.isFile();
54
+ // Allow directories to be traversed, only ignore files that don't match
55
+ return stats?.isFile() ?? false;
45
56
  },
46
57
  });
47
58
  watcher
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/node/vite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAe3C,wBAAsB,uBAAuB,CAAC,UAAU,EAAE,YAAY,EAAE,GAAG,EAAE,OAAO,yBAmCnF;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,YAAY,CAAA;IACxB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B;AAED,wBAAsB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAmS9G"}
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/node/vite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAe3C,wBAAsB,uBAAuB,CAAC,UAAU,EAAE,YAAY,EAAE,GAAG,EAAE,OAAO,yBAmCnF;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,YAAY,CAAA;IACxB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B;AAED,wBAAsB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAyS9G"}
package/dist/node/vite.js CHANGED
@@ -304,6 +304,11 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
304
304
  },
305
305
  });
306
306
  }
307
+ for (const plugin of ctx.config.plugins) {
308
+ if (plugin.vitePlugins) {
309
+ await plugin.vitePlugins(plugins);
310
+ }
311
+ }
307
312
  const viteConfig = mergeViteConfig(inlineConfig, {
308
313
  configFile: false,
309
314
  plugins,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "histoire",
3
3
  "type": "module",
4
- "version": "1.0.0-alpha.3",
4
+ "version": "1.0.0-alpha.5",
5
5
  "description": "A fast story book powered by Vite",
6
6
  "author": {
7
7
  "name": "Guillaume Chau"
@@ -65,10 +65,10 @@
65
65
  "shiki": "^3.0.0",
66
66
  "sirv": "^3.0.0",
67
67
  "vite-node": "3.2.4",
68
- "@histoire/app": "^1.0.0-alpha.3",
69
- "@histoire/controls": "^1.0.0-alpha.3",
70
- "@histoire/vendors": "^1.0.0-alpha.3",
71
- "@histoire/shared": "^1.0.0-alpha.3"
68
+ "@histoire/app": "^1.0.0-alpha.5",
69
+ "@histoire/shared": "^1.0.0-alpha.5",
70
+ "@histoire/vendors": "^1.0.0-alpha.5",
71
+ "@histoire/controls": "^1.0.0-alpha.5"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@types/fs-extra": "^11.0.4",
@@ -84,9 +84,10 @@ export function tailwindTokens(options: TailwindTokensOptions = {}): Plugin {
84
84
  }
85
85
 
86
86
  function storyTemplate(tailwindConfig: any) {
87
- // import 'histoire-style'
88
- // import './style.css'
89
- return `import { createApp, h, markRaw, ref } from ${getInjectedImport('@histoire/vendors/vue')}
87
+ return `
88
+ import 'histoire-style'
89
+ import './style.css'
90
+ import { createApp, h, markRaw, ref } from ${getInjectedImport('@histoire/vendors/vue')}
90
91
  import {
91
92
  HstColorShades,
92
93
  HstTokenList,
@@ -7,9 +7,10 @@ import { cpus } from 'node:os'
7
7
  import { MessageChannel } from 'node:worker_threads'
8
8
  import Tinypool from '@akryum/tinypool'
9
9
  import { createBirpc } from 'birpc'
10
- import { relative } from 'pathe'
10
+ import path, { relative } from 'pathe'
11
11
  import pc from 'picocolors'
12
12
  import { ViteNodeServer } from 'vite-node/server'
13
+ import { TEMP_PATH } from '../alias.js'
13
14
  import { createPath } from '../tree.js'
14
15
  import { slash } from '../util/fs.js'
15
16
 
@@ -34,6 +35,7 @@ export function useCollectStories(options: UseCollectStoriesOptions, ctx: Contex
34
35
  // @TODO temporary fix for https://github.com/histoire-dev/histoire/issues/409
35
36
  /vite\w*\/dist\/client\/(client|env).mjs/,
36
37
  ...ctx.config.viteNodeInlineDeps ?? [],
38
+ new RegExp(path.resolve(TEMP_PATH, 'plugins')),
37
39
  ],
38
40
  fallbackCJS: true,
39
41
  },
@@ -34,7 +34,7 @@ export async function createServer(ctx: Context, options: CreateServerOptions =
34
34
 
35
35
  const server = await createViteServer(
36
36
  mergeViteConfig(viteConfig, {
37
- optimizeDeps: { include: [], noDiscovery: true },
37
+ optimizeDeps: { include: viteConfig.optimizeDeps?.include ?? [], noDiscovery: collecting },
38
38
  }),
39
39
  )
40
40
  await server.pluginContainer.buildStart({})
@@ -45,17 +45,31 @@ let context: Context
45
45
  export async function watchStories(newContext: Context) {
46
46
  context = newContext
47
47
 
48
- const watcher = chokidar.watch('.', {
48
+ const baseWatchPaths = Array.from(new Set(context.config.storyMatch.map((pattern) => {
49
+ const segments = pattern.split('/')
50
+ return segments.slice(0, segments.findIndex(segment => segment.includes('*'))).join('/') || '.'
51
+ })))
52
+
53
+ const resolvedStoryIgnored = context.config.storyIgnored.map((pattern) => {
54
+ return resolve(context.root, pattern)
55
+ })
56
+
57
+ const resolveStoryMatch = context.config.storyMatch.map((pattern) => {
58
+ return resolve(context.root, pattern)
59
+ })
60
+
61
+ const watcher = chokidar.watch(baseWatchPaths, {
49
62
  cwd: context.root,
50
63
  ignored: (path, stats) => {
51
- if (context.config.storyIgnored.some(pattern => micromatch.isMatch(path, pattern))) {
64
+ if (resolvedStoryIgnored.some(pattern => micromatch.isMatch(path, pattern))) {
52
65
  return true
53
66
  }
54
- if (context.config.storyMatch.some(pattern => micromatch.isMatch(path, pattern))) {
67
+ if (resolveStoryMatch.some(pattern => micromatch.isMatch(path, pattern))) {
55
68
  return false
56
69
  }
57
70
 
58
- return stats?.isFile()
71
+ // Allow directories to be traversed, only ignore files that don't match
72
+ return stats?.isFile() ?? false
59
73
  },
60
74
  })
61
75
 
package/src/node/vite.ts CHANGED
@@ -342,6 +342,12 @@ export async function getViteConfigWithPlugins(isServer: boolean, ctx: Context):
342
342
  })
343
343
  }
344
344
 
345
+ for (const plugin of ctx.config.plugins) {
346
+ if (plugin.vitePlugins) {
347
+ await plugin.vitePlugins(plugins)
348
+ }
349
+ }
350
+
345
351
  const viteConfig = mergeViteConfig(inlineConfig, {
346
352
  configFile: false,
347
353
  plugins,