histoire 0.17.16 → 0.17.17

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.
Files changed (122) hide show
  1. package/client.d.ts +5 -5
  2. package/client.js +2 -2
  3. package/dist/node/alias.js +1 -1
  4. package/dist/node/bin.js +1 -1
  5. package/dist/node/build-serialize.d.ts +1 -1
  6. package/dist/node/build.d.ts +1 -1
  7. package/dist/node/build.js +2 -2
  8. package/dist/node/builtin-plugins/pinceau-tokens.d.ts +1 -1
  9. package/dist/node/builtin-plugins/pinceau-tokens.js +4 -4
  10. package/dist/node/builtin-plugins/tailwind-tokens.js +3 -1
  11. package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts +1 -1
  12. package/dist/node/builtin-plugins/vanilla-support/MountStory.js +1 -1
  13. package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts +1 -1
  14. package/dist/node/builtin-plugins/vanilla-support/RenderStory.js +1 -2
  15. package/dist/node/builtin-plugins/vanilla-support/plugin.js +1 -1
  16. package/dist/node/builtin-plugins/vanilla-support/types.d.ts +1 -1
  17. package/dist/node/collect/index.js +2 -2
  18. package/dist/node/collect/worker.d.ts +1 -1
  19. package/dist/node/collect/worker.js +2 -2
  20. package/dist/node/colors.js +4 -4
  21. package/dist/node/config.d.ts +1 -1
  22. package/dist/node/config.js +8 -8
  23. package/dist/node/context.d.ts +2 -2
  24. package/dist/node/dom/env.js +6 -6
  25. package/dist/node/dom/util.js +8 -12
  26. package/dist/node/markdown.js +3 -3
  27. package/dist/node/plugin.d.ts +1 -1
  28. package/dist/node/plugin.js +0 -1
  29. package/dist/node/search.d.ts +1 -1
  30. package/dist/node/server.d.ts +1 -1
  31. package/dist/node/server.js +2 -2
  32. package/dist/node/stories.d.ts +1 -1
  33. package/dist/node/stories.js +3 -3
  34. package/dist/node/tree.d.ts +1 -1
  35. package/dist/node/tree.js +1 -1
  36. package/dist/node/util/find-up.js +1 -1
  37. package/dist/node/util/slugify.d.ts +1 -1
  38. package/dist/node/util/slugify.js +3 -3
  39. package/dist/node/virtual/index.d.ts +11 -11
  40. package/dist/node/virtual/markdown.d.ts +1 -1
  41. package/dist/node/virtual/markdown.js +2 -2
  42. package/dist/node/virtual/resolved-commands.d.ts +1 -1
  43. package/dist/node/virtual/resolved-commands.js +2 -2
  44. package/dist/node/virtual/resolved-config.d.ts +1 -1
  45. package/dist/node/virtual/resolved-config.js +2 -2
  46. package/dist/node/virtual/resolved-generated-global-setup.d.ts +1 -1
  47. package/dist/node/virtual/resolved-generated-global-setup.js +3 -3
  48. package/dist/node/virtual/resolved-generated-setup-code.d.ts +1 -1
  49. package/dist/node/virtual/resolved-generated-setup-code.js +2 -2
  50. package/dist/node/virtual/resolved-markdown-files.d.ts +1 -1
  51. package/dist/node/virtual/resolved-markdown-files.js +2 -2
  52. package/dist/node/virtual/resolved-stories.d.ts +1 -1
  53. package/dist/node/virtual/resolved-stories.js +3 -3
  54. package/dist/node/virtual/resolved-support-plugins-client.d.ts +1 -1
  55. package/dist/node/virtual/resolved-support-plugins-client.js +2 -2
  56. package/dist/node/virtual/resolved-support-plugins-collect.d.ts +1 -1
  57. package/dist/node/virtual/resolved-support-plugins-collect.js +2 -2
  58. package/dist/node/virtual/resolved-theme.d.ts +1 -1
  59. package/dist/node/virtual/resolved-theme.js +2 -2
  60. package/dist/node/virtual/story-source.d.ts +1 -1
  61. package/dist/node/virtual/story-source.js +2 -2
  62. package/dist/node/virtual/story.d.ts +1 -1
  63. package/dist/node/virtual/story.js +2 -2
  64. package/dist/node/virtual/vite-plugin.d.ts +1 -1
  65. package/dist/node/virtual/vite-plugin.js +122 -120
  66. package/dist/node/vite.d.ts +2 -2
  67. package/dist/node/vite.js +6 -8
  68. package/package.json +11 -11
  69. package/plugin.d.ts +2 -2
  70. package/plugin.js +2 -2
  71. package/src/node/__tests__/markdown.spec.ts +11 -9
  72. package/src/node/__tests__/tree.spec.ts +6 -6
  73. package/src/node/alias.ts +1 -1
  74. package/src/node/bin.ts +1 -1
  75. package/src/node/build-serialize.ts +7 -7
  76. package/src/node/build.ts +17 -15
  77. package/src/node/builtin-plugins/pinceau-tokens.ts +9 -9
  78. package/src/node/builtin-plugins/tailwind-tokens.ts +10 -7
  79. package/src/node/builtin-plugins/vanilla-support/MountStory.ts +6 -7
  80. package/src/node/builtin-plugins/vanilla-support/RenderStory.ts +9 -10
  81. package/src/node/builtin-plugins/vanilla-support/client.ts +1 -1
  82. package/src/node/builtin-plugins/vanilla-support/collect.ts +3 -2
  83. package/src/node/builtin-plugins/vanilla-support/plugin.ts +3 -3
  84. package/src/node/builtin-plugins/vanilla-support/types.ts +2 -2
  85. package/src/node/collect/index.ts +12 -10
  86. package/src/node/collect/run.ts +1 -1
  87. package/src/node/collect/worker.ts +5 -5
  88. package/src/node/colors.ts +5 -5
  89. package/src/node/commands/build.ts +1 -1
  90. package/src/node/commands/dev.ts +3 -3
  91. package/src/node/commands/preview.ts +1 -1
  92. package/src/node/config.ts +25 -21
  93. package/src/node/context.ts +6 -5
  94. package/src/node/dom/env.ts +9 -9
  95. package/src/node/dom/util.ts +13 -13
  96. package/src/node/load.ts +6 -5
  97. package/src/node/markdown.ts +21 -17
  98. package/src/node/plugin.ts +18 -19
  99. package/src/node/preview.ts +6 -4
  100. package/src/node/search.ts +9 -9
  101. package/src/node/server.ts +14 -11
  102. package/src/node/stories.ts +12 -12
  103. package/src/node/tree.ts +20 -15
  104. package/src/node/util/find-up.ts +2 -2
  105. package/src/node/util/log.ts +3 -2
  106. package/src/node/util/slugify.ts +2 -2
  107. package/src/node/util/vendors.ts +1 -1
  108. package/src/node/virtual/markdown.ts +1 -1
  109. package/src/node/virtual/resolved-commands.ts +4 -3
  110. package/src/node/virtual/resolved-config.ts +1 -1
  111. package/src/node/virtual/resolved-generated-global-setup.ts +4 -3
  112. package/src/node/virtual/resolved-generated-setup-code.ts +1 -1
  113. package/src/node/virtual/resolved-markdown-files.ts +1 -1
  114. package/src/node/virtual/resolved-stories.ts +2 -2
  115. package/src/node/virtual/resolved-support-plugins-client.ts +1 -1
  116. package/src/node/virtual/resolved-support-plugins-collect.ts +1 -1
  117. package/src/node/virtual/resolved-theme.ts +1 -1
  118. package/src/node/virtual/story-source.ts +3 -2
  119. package/src/node/virtual/story.ts +1 -1
  120. package/src/node/virtual/vite-plugin.ts +134 -130
  121. package/src/node/vite.ts +33 -30
  122. package/tsconfig.json +19 -19
package/client.d.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  /**
2
2
  * @deprecated
3
3
  */
4
- export function hstEvent (name: string, argument): void
4
+ export function hstEvent(name: string, argument): void
5
5
 
6
6
  /**
7
7
  * Logs an event to the 'Events' sidepane.
8
8
  * @param name Event name
9
9
  * @param argument Additional log data displayed when inspecting the event.
10
10
  */
11
- export function logEvent (name: string, argument): void
11
+ export function logEvent(name: string, argument): void
12
12
 
13
13
  /**
14
14
  * Returns `true` when in the NodeJS server while collecting stories.
15
15
  */
16
- export function isCollecting (): boolean
16
+ export function isCollecting(): boolean
17
17
 
18
- export function toggleDark (value?: boolean): boolean
19
- export function isDark (): boolean
18
+ export function toggleDark(value?: boolean): boolean
19
+ export function isDark(): boolean
package/client.js CHANGED
@@ -2,14 +2,14 @@ import { logEvent } from '@histoire/app'
2
2
 
3
3
  export * from '@histoire/app'
4
4
 
5
- export function isCollecting () {
5
+ export function isCollecting() {
6
6
  return process.env.HST_COLLECT === 'true'
7
7
  }
8
8
 
9
9
  /**
10
10
  * @deprecated
11
11
  */
12
- export function hstEvent (...args) {
12
+ export function hstEvent(...args) {
13
13
  console.warn(`'hstEvent' is deprecated. Use 'logEvent' instead.`)
14
14
  return logEvent(...args)
15
15
  }
@@ -1,5 +1,5 @@
1
- import path from 'pathe';
2
1
  import { createRequire } from 'node:module';
2
+ import path from 'pathe';
3
3
  const require = createRequire(import.meta.url);
4
4
  export const APP_PATH = path.join(path.dirname(require.resolve('@histoire/app/package.json')), process.env.HISTOIRE_DEV ? 'src' : '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
1
  import fs from 'node:fs';
2
- import { dirname, resolve } from 'pathe';
3
2
  import { fileURLToPath } from 'node:url';
3
+ import { dirname, resolve } from 'pathe';
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'));
@@ -1,5 +1,5 @@
1
- import type { Context } from './context.js';
2
1
  import type { ServerStory } from '@histoire/shared';
2
+ import type { Context } from './context.js';
3
3
  interface SerializedStory extends Omit<ServerStory, 'docsText'> {
4
4
  relativePath: string;
5
5
  supportPluginId: string;
@@ -1,2 +1,2 @@
1
- import { Context } from './context.js';
1
+ import type { Context } from './context.js';
2
2
  export declare function build(ctx: Context): Promise<void>;
@@ -1,9 +1,9 @@
1
+ import { performance } from 'node:perf_hooks';
1
2
  import { join } from 'pathe';
2
- import { build as viteBuild, createServer as createViteServer, mergeConfig as mergeViteConfig, } from 'vite';
3
+ import { createServer as createViteServer, mergeConfig as mergeViteConfig, build as viteBuild, } from 'vite';
3
4
  import fs from 'fs-extra';
4
5
  import { lookup as lookupMime } from 'mrmime';
5
6
  import pc from 'picocolors';
6
- import { performance } from 'node:perf_hooks';
7
7
  import { APP_PATH } from './alias.js';
8
8
  import { getViteConfigWithPlugins } from './vite.js';
9
9
  import { findAllStories } from './stories.js';
@@ -3,4 +3,4 @@ export interface PinceauTokensOptions {
3
3
  configOrPaths?: string | string[];
4
4
  configFileName?: string;
5
5
  }
6
- export declare function pinceauTokens(options?: PinceauTokensOptions): Plugin;
6
+ export declare function pinceauTokens(_options?: PinceauTokensOptions): Plugin;
@@ -1,6 +1,6 @@
1
- import { getInjectedImport } from '../util/vendors.js';
2
1
  import { join } from 'pathe';
3
- export function pinceauTokens(options = {}) {
2
+ import { getInjectedImport } from '../util/vendors.js';
3
+ export function pinceauTokens(_options = {}) {
4
4
  const themePath = join(process.cwd(), 'node_modules/.vite/pinceau/index.js');
5
5
  async function generate(api) {
6
6
  try {
@@ -54,7 +54,7 @@ export function pinceauTokens(options = {}) {
54
54
  },
55
55
  };
56
56
  }
57
- const storyTemplate = (pinceauConfig) => {
57
+ function storyTemplate(pinceauConfig) {
58
58
  pinceauConfig = pinceauConfig?.theme || pinceauConfig?.default?.theme || {};
59
59
  return `import 'histoire-style'
60
60
  import './style.css'
@@ -419,7 +419,7 @@ export default {
419
419
  },
420
420
  ],
421
421
  }`;
422
- };
422
+ }
423
423
  const css = `.__hst-shade {
424
424
  height: 80px;
425
425
  border-radius: 4px;
@@ -71,7 +71,8 @@ export function tailwindTokens(options = {}) {
71
71
  },
72
72
  };
73
73
  }
74
- const storyTemplate = (tailwindConfig) => `import 'histoire-style'
74
+ function storyTemplate(tailwindConfig) {
75
+ return `import 'histoire-style'
75
76
  import './style.css'
76
77
  import { createApp, h, markRaw, ref } from ${getInjectedImport('@histoire/vendors/vue')}
77
78
  import {
@@ -435,6 +436,7 @@ export default {
435
436
  },
436
437
  ],
437
438
  }`;
439
+ }
438
440
  const css = `.__hst-shade {
439
441
  height: 80px;
440
442
  border-radius: 4px;
@@ -1,4 +1,4 @@
1
- import { PropType as _PropType } from '@histoire/vendors/vue';
1
+ import type { PropType as _PropType } from '@histoire/vendors/vue';
2
2
  import type { Story } from '@histoire/shared';
3
3
  declare const _default: import("@histoire/vendors/vue").DefineComponent<{
4
4
  story: {
@@ -1,4 +1,4 @@
1
- import { defineComponent as _defineComponent, } from '@histoire/vendors/vue';
1
+ import { defineComponent as _defineComponent } from '@histoire/vendors/vue';
2
2
  export default _defineComponent({
3
3
  name: 'MountStory',
4
4
  props: {
@@ -1,4 +1,4 @@
1
- import { PropType as _PropType } from '@histoire/vendors/vue';
1
+ import type { PropType as _PropType } from '@histoire/vendors/vue';
2
2
  import type { Story, Variant } from '@histoire/shared';
3
3
  declare const _default: import("@histoire/vendors/vue").DefineComponent<{
4
4
  variant: {
@@ -1,5 +1,4 @@
1
- /* eslint-disable vue/one-component-per-file */
2
- import { defineComponent as _defineComponent, onBeforeUnmount as _onBeforeUnmount, onMounted as _onMounted, ref as _ref, watch as _watch, h as _h, } from '@histoire/vendors/vue';
1
+ import { defineComponent as _defineComponent, h as _h, onBeforeUnmount as _onBeforeUnmount, onMounted as _onMounted, ref as _ref, watch as _watch, } from '@histoire/vendors/vue';
3
2
  // @ts-expect-error virtual module id
4
3
  import * as setup from 'virtual:$histoire-setup';
5
4
  // @ts-expect-error virtual module id
@@ -1,5 +1,5 @@
1
- import { dirname } from 'pathe';
2
1
  import { fileURLToPath } from 'node:url';
2
+ import { dirname } from 'pathe';
3
3
  const __dirname = dirname(fileURLToPath(import.meta.url));
4
4
  export function vanillaSupport() {
5
5
  return {
@@ -1,4 +1,4 @@
1
- import type { StoryProps, VariantProps, Story, Variant, Awaitable } from '@histoire/shared';
1
+ import type { Awaitable, Story, StoryProps, Variant, VariantProps } from '@histoire/shared';
2
2
  export interface App {
3
3
  el: HTMLElement;
4
4
  onMount?: () => void;
@@ -1,10 +1,10 @@
1
1
  import { MessageChannel } from 'node:worker_threads';
2
+ import { cpus } from 'node:os';
2
3
  import { ViteNodeServer } from 'vite-node/server';
3
4
  import { relative } from 'pathe';
4
5
  import pc from 'picocolors';
5
6
  import Tinypool from '@akryum/tinypool';
6
7
  import { createBirpc } from 'birpc';
7
- import { cpus } from 'node:os';
8
8
  import { createPath } from '../tree.js';
9
9
  import { slash } from '../util/fs.js';
10
10
  export function useCollectStories(options, ctx) {
@@ -47,7 +47,7 @@ export function useCollectStories(options, ctx) {
47
47
  const port = channel.port2;
48
48
  const workerPort = channel.port1;
49
49
  createBirpc({
50
- fetchModule: (id) => node.fetchModule(id),
50
+ fetchModule: id => node.fetchModule(id),
51
51
  resolveId: (id, importer) => node.resolveId(id, importer),
52
52
  }, {
53
53
  post: data => port.postMessage(data),
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import type { MessagePort } from 'node:worker_threads';
3
- import type { ServerStoryFile, ServerStory } from '@histoire/shared';
3
+ import type { ServerStory, ServerStoryFile } from '@histoire/shared';
4
4
  export interface Payload {
5
5
  root: string;
6
6
  base: string;
@@ -11,7 +11,7 @@ const _moduleCache = new ModuleCacheMap();
11
11
  let _runner;
12
12
  let _rpc;
13
13
  // Cleanup module cache
14
- parentPort.on('message', message => {
14
+ parentPort.on('message', (message) => {
15
15
  if (message?.kind === 'hst:invalidate') {
16
16
  _moduleCache.delete(message.file);
17
17
  }
@@ -51,7 +51,7 @@ export default async (payload) => {
51
51
  const el = document.createElement('div');
52
52
  el.innerHTML = payload.storyFile.markdownFile.html;
53
53
  const text = el.textContent;
54
- storyData.forEach(s => {
54
+ storyData.forEach((s) => {
55
55
  s.docsText = text;
56
56
  });
57
57
  }
@@ -300,15 +300,15 @@ export function parseColor(value) {
300
300
  if (hex !== null) {
301
301
  return {
302
302
  mode: 'rgb',
303
- color: [parseInt(hex[1], 16), parseInt(hex[2], 16), parseInt(hex[3], 16)].map((v) => v.toString()),
304
- alpha: hex[4] ? (parseInt(hex[4], 16) / 255).toString() : undefined,
303
+ color: [Number.parseInt(hex[1], 16), Number.parseInt(hex[2], 16), Number.parseInt(hex[3], 16)].map(v => v.toString()),
304
+ alpha: hex[4] ? (Number.parseInt(hex[4], 16) / 255).toString() : undefined,
305
305
  };
306
306
  }
307
307
  const rgbMatch = value.match(RGB);
308
308
  if (rgbMatch !== null) {
309
309
  return {
310
310
  mode: 'rgb',
311
- color: [rgbMatch[1], rgbMatch[2], rgbMatch[3]].map((v) => v.toString()),
311
+ color: [rgbMatch[1], rgbMatch[2], rgbMatch[3]].map(v => v.toString()),
312
312
  alpha: rgbMatch[4]?.toString?.(),
313
313
  };
314
314
  }
@@ -316,7 +316,7 @@ export function parseColor(value) {
316
316
  if (hslMatch !== null) {
317
317
  return {
318
318
  mode: 'hsl',
319
- color: [hslMatch[1], hslMatch[2], hslMatch[3]].map((v) => v.toString()),
319
+ color: [hslMatch[1], hslMatch[2], hslMatch[3]].map(v => v.toString()),
320
320
  alpha: hslMatch[4]?.toString?.(),
321
321
  };
322
322
  }
@@ -1,4 +1,4 @@
1
- import type { HistoireConfig, ConfigMode } from '@histoire/shared';
1
+ import type { ConfigMode, HistoireConfig } from '@histoire/shared';
2
2
  import type { Context } from './context.js';
3
3
  export declare function getDefaultConfig(): HistoireConfig;
4
4
  export declare const configFileNames: string[];
@@ -1,10 +1,10 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import fs from 'node:fs';
1
3
  import path from 'pathe';
2
4
  import { createDefu } from 'defu';
3
- import { resolveConfig as resolveViteConfig, mergeConfig as mergeViteConfig, } from 'vite';
5
+ import { mergeConfig as mergeViteConfig, resolveConfig as resolveViteConfig, } from 'vite';
4
6
  import jiti from 'jiti';
5
- import { fileURLToPath } from 'node:url';
6
7
  import pc from 'picocolors';
7
- import fs from 'node:fs';
8
8
  import { defaultColors } from './colors.js';
9
9
  import { findUp } from './util/find-up.js';
10
10
  import { tailwindTokens } from './builtin-plugins/tailwind-tokens.js';
@@ -116,11 +116,11 @@ export function getDefaultConfig() {
116
116
  },
117
117
  vite: (config) => {
118
118
  // Remove vite:legacy plugins https://github.com/histoire-dev/histoire/issues/156
119
- const index = config.plugins?.findIndex(plugin => Array.isArray(plugin) &&
120
- typeof plugin[0] === 'object' &&
121
- !Array.isArray(plugin[0]) &&
119
+ const index = config.plugins?.findIndex(plugin => Array.isArray(plugin)
120
+ && typeof plugin[0] === 'object'
121
+ && !Array.isArray(plugin[0])
122
122
  // @ts-expect-error could have no property 'name'
123
- plugin[0].name?.startsWith('vite:legacy'));
123
+ && plugin[0].name?.startsWith('vite:legacy'));
124
124
  if (index !== -1) {
125
125
  config.plugins?.splice(index, 1);
126
126
  }
@@ -248,7 +248,7 @@ async function resolveConfigPlugins(config, mode) {
248
248
  }
249
249
  return config;
250
250
  }
251
- async function processDefaultConfig(defaultConfig, preUserConfig, mode, cwd) {
251
+ async function processDefaultConfig(defaultConfig, preUserConfig, mode, _cwd) {
252
252
  // Apply plugins
253
253
  for (const plugin of [...defaultConfig.plugins, ...preUserConfig.plugins ?? []]) {
254
254
  if (plugin.defaultConfig) {
@@ -1,5 +1,5 @@
1
- import { ResolvedConfig } from 'vite';
2
- import type { ServerStoryFile, FinalSupportPlugin, ServerMarkdownFile, HistoireConfig, ConfigMode, PluginCommand } from '@histoire/shared';
1
+ import type { ResolvedConfig } from 'vite';
2
+ import type { ConfigMode, FinalSupportPlugin, HistoireConfig, PluginCommand, ServerMarkdownFile, ServerStoryFile } from '@histoire/shared';
3
3
  export interface Context {
4
4
  root: string;
5
5
  config: HistoireConfig;
@@ -5,21 +5,21 @@ export function createDomEnv() {
5
5
  pretendToBeVisual: true,
6
6
  runScripts: 'dangerously',
7
7
  url: 'http://localhost:3000',
8
- virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : undefined,
8
+ virtualConsole: console && globalThis.console ? new VirtualConsole().sendTo(globalThis.console) : undefined,
9
9
  includeNodeLocations: false,
10
10
  contentType: 'text/html',
11
11
  });
12
- const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true });
12
+ const { keys, originals } = populateGlobal(globalThis, dom.window, { bindFunctions: true });
13
13
  function destroy() {
14
- keys.forEach(key => delete global[key]);
14
+ keys.forEach(key => delete globalThis[key]);
15
15
  originals.forEach((v, k) => {
16
- global[k] = v;
16
+ globalThis[k] = v;
17
17
  });
18
18
  }
19
19
  window.ResizeObserver = window.ResizeObserver || class ResizeObserver {
20
20
  disconnect() { }
21
- observe(target, options) { }
22
- unobserve(target) { }
21
+ observe(_target, _options) { }
22
+ unobserve(_target) { }
23
23
  };
24
24
  return {
25
25
  window,
@@ -30,21 +30,18 @@ export function populateGlobal(global, win, options = {}) {
30
30
  const originals = new Map();
31
31
  const overrideObject = new Map();
32
32
  for (const key of keys) {
33
- const boundFunction = bindFunctions &&
34
- typeof win[key] === 'function' &&
35
- !isClassLikeName(key) &&
36
- win[key].bind(win);
37
- if (KEYS.includes(key) && key in global) {
33
+ const boundFunction = bindFunctions
34
+ && typeof win[key] === 'function'
35
+ && !isClassLikeName(key)
36
+ && win[key].bind(win);
37
+ if (KEYS.includes(key) && key in global)
38
38
  originals.set(key, global[key]);
39
- }
40
39
  Object.defineProperty(global, key, {
41
40
  get() {
42
- if (overrideObject.has(key)) {
41
+ if (overrideObject.has(key))
43
42
  return overrideObject.get(key);
44
- }
45
- if (boundFunction) {
43
+ if (boundFunction)
46
44
  return boundFunction;
47
- }
48
45
  return win[key];
49
46
  },
50
47
  set(v) {
@@ -57,9 +54,8 @@ export function populateGlobal(global, win, options = {}) {
57
54
  global.self = global;
58
55
  global.top = global;
59
56
  global.parent = global;
60
- if (global.global) {
57
+ if (global.global)
61
58
  global.global = global;
62
- }
63
59
  skipKeys.forEach(k => keys.add(k));
64
60
  return {
65
61
  keys,
@@ -128,7 +128,7 @@ export async function createMarkdownFilesWatcher(ctx) {
128
128
  const absolutePath = path.resolve(ctx.root, relativePath);
129
129
  const dirFiles = fs.readdirSync(path.dirname(absolutePath));
130
130
  const truncatedName = path.basename(absolutePath, '.md');
131
- const isRelatedToStory = dirFiles.some((file) => !file.endsWith('.md') && file.startsWith(truncatedName));
131
+ const isRelatedToStory = dirFiles.some(file => !file.endsWith('.md') && file.startsWith(truncatedName));
132
132
  const { data: frontmatter, content } = matter(fs.readFileSync(absolutePath, 'utf8'));
133
133
  let html;
134
134
  // We don't immediately render markdown during initial scanning in case
@@ -177,7 +177,7 @@ export async function createMarkdownFilesWatcher(ctx) {
177
177
  return file;
178
178
  }
179
179
  function removeFile(relativePath) {
180
- const index = ctx.markdownFiles.findIndex((file) => file.relativePath === relativePath);
180
+ const index = ctx.markdownFiles.findIndex(file => file.relativePath === relativePath);
181
181
  if (index !== -1) {
182
182
  const file = ctx.markdownFiles[index];
183
183
  if (!file.isRelatedToStory) {
@@ -198,7 +198,7 @@ export async function createMarkdownFilesWatcher(ctx) {
198
198
  .on('unlink', (relativePath) => {
199
199
  removeFile(relativePath);
200
200
  });
201
- await new Promise(resolve => {
201
+ await new Promise((resolve) => {
202
202
  watcher.once('ready', resolve);
203
203
  });
204
204
  try {
@@ -1,7 +1,7 @@
1
1
  import chokidar from 'chokidar';
2
2
  import path from 'pathe';
3
3
  import fs from 'fs-extra';
4
- import type { Plugin, PluginApiBase, PluginApiDev, PluginApiBuild, ChangeViteConfigCallback, BuildEndCallback, PreviewStoryCallback, ModuleLoader, ServerStory, PluginApiDevEvent, HistoireConfig } from '@histoire/shared';
4
+ import type { BuildEndCallback, ChangeViteConfigCallback, HistoireConfig, ModuleLoader, Plugin, PluginApiBase, PluginApiBuild, PluginApiDev, PluginApiDevEvent, PreviewStoryCallback, ServerStory } from '@histoire/shared';
5
5
  import type { Context } from './context.js';
6
6
  export declare class BasePluginApi implements PluginApiBase {
7
7
  protected ctx: Context;
@@ -11,7 +11,6 @@ export class BasePluginApi {
11
11
  colors = pc;
12
12
  path = path;
13
13
  fs = fs;
14
- // eslint-disable-next-line no-useless-constructor
15
14
  constructor(ctx, plugin, moduleLoader) {
16
15
  this.ctx = ctx;
17
16
  this.plugin = plugin;
@@ -1,4 +1,4 @@
1
- import { Context } from './context.js';
1
+ import type { Context } from './context.js';
2
2
  export declare function generateTitleSearchData(ctx: Context): Promise<{
3
3
  index: unknown;
4
4
  idMap: Record<number, {
@@ -1,4 +1,4 @@
1
- import { Context } from './context.js';
1
+ import type { Context } from './context.js';
2
2
  export interface CreateServerOptions {
3
3
  port?: number;
4
4
  open?: boolean;
@@ -5,7 +5,7 @@ import { getViteConfigWithPlugins } from './vite.js';
5
5
  import * as VirtualFiles from './virtual/index.js';
6
6
  import { onStoryChange, onStoryListChange, watchStories } from './stories.js';
7
7
  import { useCollectStories } from './collect/index.js';
8
- import { DevPluginApi, DevEventPluginApi } from './plugin.js';
8
+ import { DevEventPluginApi, DevPluginApi } from './plugin.js';
9
9
  import { useModuleLoader } from './load.js';
10
10
  import { wrapLogError } from './util/log.js';
11
11
  import { createMarkdownFilesWatcher, onMarkdownListChange } from './markdown.js';
@@ -83,7 +83,7 @@ export async function createServer(ctx, options = {}) {
83
83
  type: 'js-update',
84
84
  acceptedPath: mod.url,
85
85
  path: mod.url,
86
- timestamp: timestamp,
86
+ timestamp,
87
87
  },
88
88
  ],
89
89
  });
@@ -1,6 +1,6 @@
1
1
  import chokidar from 'chokidar';
2
2
  import type { ServerStoryFile } from '@histoire/shared';
3
- import { Context } from './context.js';
3
+ import type { Context } from './context.js';
4
4
  type StoryChangeHandler = (file?: ServerStoryFile) => unknown;
5
5
  /**
6
6
  * Called when a new story is added or modified. Collecting should be done.
@@ -1,7 +1,7 @@
1
1
  import chokidar from 'chokidar';
2
2
  import { globby } from 'globby';
3
3
  import { paramCase } from 'change-case';
4
- import { resolve, basename } from 'pathe';
4
+ import { basename, resolve } from 'pathe';
5
5
  import micromatch from 'micromatch';
6
6
  const storyChangeHandlers = [];
7
7
  /**
@@ -75,7 +75,7 @@ export function addStory(relativeFilePath, virtualModuleCode) {
75
75
  throw new Error(`No support plugin found for file ${absoluteFilePath}`);
76
76
  }
77
77
  const file = {
78
- id: fileId,
78
+ id: fileId, // The file id will be changed by the story id after it is collected
79
79
  path: absoluteFilePath,
80
80
  relativePath: relativeFilePath,
81
81
  fileName,
@@ -89,7 +89,7 @@ export function addStory(relativeFilePath, virtualModuleCode) {
89
89
  }
90
90
  export function removeStory(relativeFilePath) {
91
91
  const absoluteFilePath = getAbsoluteFilePath(relativeFilePath);
92
- const index = context.storyFiles.findIndex((file) => file.path === absoluteFilePath);
92
+ const index = context.storyFiles.findIndex(file => file.path === absoluteFilePath);
93
93
  if (index !== -1)
94
94
  context.storyFiles.splice(index, 1);
95
95
  }
@@ -1,3 +1,3 @@
1
- import type { ServerStoryFile, ServerTree, ServerTreeFile, HistoireConfig } from '@histoire/shared';
1
+ import type { HistoireConfig, ServerStoryFile, ServerTree, ServerTreeFile } from '@histoire/shared';
2
2
  export declare function createPath(config: HistoireConfig, file: ServerTreeFile): string[];
3
3
  export declare function makeTree(config: HistoireConfig, files: ServerStoryFile[]): ServerTree;
package/dist/node/tree.js CHANGED
@@ -78,7 +78,7 @@ export function makeTree(config, files) {
78
78
  return subtree[key];
79
79
  }, tree);
80
80
  function isLeaf(element) {
81
- return !isNaN(element);
81
+ return !Number.isNaN(Number(element));
82
82
  }
83
83
  }
84
84
  function setKey(tree, key, value) {
@@ -1,5 +1,5 @@
1
- import path from 'pathe';
2
1
  import fs from 'node:fs';
2
+ import path from 'pathe';
3
3
  export function findUp(cwd = process.cwd(), fileNames) {
4
4
  let { root } = path.parse(cwd);
5
5
  let dir = cwd;
@@ -1 +1 @@
1
- export declare const slugify: (str: string) => string;
1
+ export declare function slugify(str: string): string;
@@ -3,9 +3,9 @@
3
3
  // use a custom implementation here
4
4
  import { remove as removeDiacritics } from 'diacritics';
5
5
  // eslint-disable-next-line no-control-regex
6
- const rControl = /[\u0000-\u001f]/g;
6
+ const rControl = /[\u0000-\u001F]/g;
7
7
  const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g;
8
- export const slugify = (str) => {
8
+ export function slugify(str) {
9
9
  return (removeDiacritics(str)
10
10
  // Remove control characters
11
11
  .replace(rControl, '')
@@ -19,4 +19,4 @@ export const slugify = (str) => {
19
19
  .replace(/^(\d)/, '_$1')
20
20
  // lowercase
21
21
  .toLowerCase());
22
- };
22
+ }
@@ -1,27 +1,27 @@
1
1
  export declare const STORIES_ID = "virtual:$histoire-stories";
2
- export declare const RESOLVED_STORIES_ID: string;
2
+ export declare const RESOLVED_STORIES_ID = "/__resolved__virtual:$histoire-stories";
3
3
  export declare const SETUP_ID = "virtual:$histoire-setup";
4
4
  export declare const NOOP_ID = "virtual:$histoire-noop";
5
5
  export declare const CONFIG_ID = "virtual:$histoire-config";
6
- export declare const RESOLVED_CONFIG_ID: string;
6
+ export declare const RESOLVED_CONFIG_ID = "/__resolved__virtual:$histoire-config";
7
7
  export declare const THEME_ID = "virtual:$histoire-theme";
8
- export declare const RESOLVED_THEME_ID: string;
8
+ export declare const RESOLVED_THEME_ID = "/__resolved__virtual:$histoire-theme.css";
9
9
  export declare const SEARCH_TITLE_DATA_ID = "virtual:$histoire-search-title-data";
10
- export declare const RESOLVED_SEARCH_TITLE_DATA_ID: string;
10
+ export declare const RESOLVED_SEARCH_TITLE_DATA_ID = "/__resolved__virtual:$histoire-search-title-data";
11
11
  export declare const SEARCH_DOCS_DATA_ID = "virtual:$histoire-search-docs-data";
12
- export declare const RESOLVED_SEARCH_DOCS_DATA_ID: string;
12
+ export declare const RESOLVED_SEARCH_DOCS_DATA_ID = "/__resolved__virtual:$histoire-search-docs-data";
13
13
  export declare const GENERATED_GLOBAL_SETUP = "virtual:$histoire-generated-global-setup";
14
- export declare const RESOLVED_GENERATED_GLOBAL_SETUP: string;
14
+ export declare const RESOLVED_GENERATED_GLOBAL_SETUP = "/__resolved__virtual:$histoire-generated-global-setup";
15
15
  export declare const GENERATED_SETUP_CODE = "virtual:$histoire-generated-setup-code";
16
- export declare const RESOLVED_GENERATED_SETUP_CODE: string;
16
+ export declare const RESOLVED_GENERATED_SETUP_CODE = "/__resolved__virtual:$histoire-generated-setup-code";
17
17
  export declare const SUPPORT_PLUGINS_CLIENT = "virtual:$histoire-support-plugins-client";
18
- export declare const RESOLVED_SUPPORT_PLUGINS_CLIENT: string;
18
+ export declare const RESOLVED_SUPPORT_PLUGINS_CLIENT = "/__resolved__virtual:$histoire-support-plugins-client";
19
19
  export declare const SUPPORT_PLUGINS_COLLECT = "virtual:$histoire-support-plugins-collect";
20
- export declare const RESOLVED_SUPPORT_PLUGINS_COLLECT: string;
20
+ export declare const RESOLVED_SUPPORT_PLUGINS_COLLECT = "/__resolved__virtual:$histoire-support-plugins-collect";
21
21
  export declare const MARKDOWN_FILES = "virtual:$histoire-markdown-files";
22
- export declare const RESOLVED_MARKDOWN_FILES: string;
22
+ export declare const RESOLVED_MARKDOWN_FILES = "/__resolved__virtual:$histoire-markdown-files";
23
23
  export declare const COMMANDS = "virtual:$histoire-commands";
24
- export declare const RESOLVED_COMMANDS: string;
24
+ export declare const RESOLVED_COMMANDS = "/__resolved__virtual:$histoire-commands";
25
25
  export * from './markdown.js';
26
26
  export * from './noop.js';
27
27
  export * from './resolved-commands.js';
@@ -1,2 +1,2 @@
1
1
  import type { Context } from '../context.js';
2
- export declare const markdown: (ctx: Context, id: string) => string;
2
+ export declare function markdown(ctx: Context, id: string): string;
@@ -1,4 +1,4 @@
1
- export const markdown = (ctx, id) => {
1
+ export function markdown(ctx, id) {
2
2
  const fileId = id.slice('/__resolved__virtual:md:'.length);
3
3
  const file = ctx.markdownFiles.find(f => f.id === fileId);
4
4
  if (!file) {
@@ -16,4 +16,4 @@ if (import.meta.hot) {
16
16
  }
17
17
  })
18
18
  }`;
19
- };
19
+ }
@@ -1,2 +1,2 @@
1
1
  import type { Context } from '../context.js';
2
- export declare const resolvedCommands: (ctx: Context) => string;
2
+ export declare function resolvedCommands(ctx: Context): string;