histoire 0.11.7 → 0.11.9

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.
@@ -22,7 +22,7 @@ interface CommonProps {
22
22
  variant: Variant;
23
23
  }) => unknown;
24
24
  }
25
- export declare type StoryOptions = Omit<StoryProps, 'setupApp'> & CommonProps & ((VanillaApi & {
25
+ export type StoryOptions = Omit<StoryProps, 'setupApp'> & CommonProps & ((VanillaApi & {
26
26
  variants?: never;
27
27
  }) | {
28
28
  variants?: VariantOptions[];
@@ -32,9 +32,6 @@ export default async (payload) => {
32
32
  _moduleCache.delete(file);
33
33
  }
34
34
  const { destroy: destroyDomEnv } = createDomEnv();
35
- if (!global.CSS.supports) {
36
- global.CSS.supports = () => false;
37
- }
38
35
  const el = window.document.createElement('div');
39
36
  const beforeExectureTime = performance.now();
40
37
  // Mount app to collect stories/variants
@@ -227,15 +227,6 @@ export async function processConfig(config, mode) {
227
227
  return config;
228
228
  }
229
229
  export async function processDefaultConfig(defaultConfig, preUserConfig, mode, cwd) {
230
- // Automatically inline dependencies in vite-node
231
- const pkgFile = await findUp(cwd, ['package.json']);
232
- const fs = (await import('fs-extra')).default;
233
- if (pkgFile) {
234
- const pkg = await fs.readJSON(pkgFile);
235
- if (pkg.dependencies) {
236
- defaultConfig.viteNodeInlineDeps = Object.keys(pkg.dependencies).map(d => new RegExp(d));
237
- }
238
- }
239
230
  // Apply plugins
240
231
  for (const plugin of [...defaultConfig.plugins, ...preUserConfig.plugins ?? []]) {
241
232
  if (plugin.defaultConfig) {
@@ -22,6 +22,7 @@ const LIVING_KEYS = [
22
22
  'Comment',
23
23
  'DocumentType',
24
24
  'NodeList',
25
+ 'RadioNodeList',
25
26
  'HTMLCollection',
26
27
  'HTMLOptionsCollection',
27
28
  'DOMStringMap',
@@ -98,6 +99,7 @@ const LIVING_KEYS = [
98
99
  'HTMLVideoElement',
99
100
  'HTMLAudioElement',
100
101
  'HTMLTrackElement',
102
+ 'HTMLFormControlsCollection',
101
103
  'SVGElement',
102
104
  'SVGGraphicsElement',
103
105
  'SVGSVGElement',
@@ -128,6 +130,7 @@ const LIVING_KEYS = [
128
130
  'Location',
129
131
  'History',
130
132
  'Screen',
133
+ 'Crypto',
131
134
  'Performance',
132
135
  'Navigator',
133
136
  'PluginArray',
@@ -161,6 +164,11 @@ const LIVING_KEYS = [
161
164
  'Headers',
162
165
  'AbortController',
163
166
  'AbortSignal',
167
+ 'ArrayBuffer',
168
+ // not specified in docs, but is available
169
+ 'Image',
170
+ 'Audio',
171
+ 'Option',
164
172
  ];
165
173
  const OTHER_KEYS = [
166
174
  'addEventListener',
@@ -168,6 +176,7 @@ const OTHER_KEYS = [
168
176
  'atob',
169
177
  'blur',
170
178
  'btoa',
179
+ 'cancelAnimationFrame',
171
180
  /* 'clearInterval', */
172
181
  /* 'clearTimeout', */
173
182
  'close',
@@ -184,6 +193,7 @@ const OTHER_KEYS = [
184
193
  'innerWidth',
185
194
  'length',
186
195
  'location',
196
+ 'matchMedia',
187
197
  'moveBy',
188
198
  'moveTo',
189
199
  'name',
@@ -198,6 +208,7 @@ const OTHER_KEYS = [
198
208
  'print',
199
209
  'prompt',
200
210
  'removeEventListener',
211
+ 'requestAnimationFrame',
201
212
  'resizeBy',
202
213
  'resizeTo',
203
214
  'screen',
@@ -218,6 +229,7 @@ const OTHER_KEYS = [
218
229
  'stop',
219
230
  /* 'toString', */
220
231
  'top',
232
+ 'Window',
221
233
  'window',
222
234
  ];
223
235
  export const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
@@ -1,5 +1,4 @@
1
- import { Window } from 'happy-dom';
2
1
  export declare function createDomEnv(): {
3
- window: Window;
2
+ window: Window & typeof globalThis;
4
3
  destroy: () => void;
5
4
  };
@@ -1,19 +1,20 @@
1
- import { Window } from 'happy-dom';
2
- import { KEYS } from './dom-keys.js';
1
+ import { JSDOM, VirtualConsole, } from 'jsdom';
2
+ import { populateGlobal } from './util.js';
3
3
  export function createDomEnv() {
4
- // @ts-ignore
5
- const window = global.window = new Window();
6
- const globalKeys = KEYS.concat(Object.getOwnPropertyNames(window))
7
- .filter(k => !k.startsWith('_'))
8
- .filter(k => !(k in global));
9
- for (const key of globalKeys) {
10
- global[key] = window[key];
11
- }
4
+ const dom = new JSDOM('<!DOCTYPE html>', {
5
+ pretendToBeVisual: true,
6
+ runScripts: 'dangerously',
7
+ url: 'http://localhost:3000',
8
+ virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : undefined,
9
+ includeNodeLocations: false,
10
+ contentType: 'text/html',
11
+ });
12
+ const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true });
12
13
  function destroy() {
13
- globalKeys.forEach(key => delete global[key]);
14
- globalKeys.length = 0;
15
- window.happyDOM.cancelAsync();
16
- delete global.window;
14
+ keys.forEach(key => delete global[key]);
15
+ originals.forEach((v, k) => {
16
+ global[k] = v;
17
+ });
17
18
  }
18
19
  return {
19
20
  window,
@@ -0,0 +1,10 @@
1
+ export declare function getWindowKeys(global: any, win: any): Set<string>;
2
+ interface PopulateOptions {
3
+ bindFunctions?: boolean;
4
+ }
5
+ export declare function populateGlobal(global: any, win: any, options?: PopulateOptions): {
6
+ keys: Set<string>;
7
+ skipKeys: string[];
8
+ originals: Map<string | symbol, any>;
9
+ };
10
+ export {};
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Code from vitest https://github.com/vitest-dev/vitest/blob/98974ba4a5b95a57a98bc2077b74bc5609d6bb3a/packages/vitest/src/integrations/env/utils.ts#L1 by @antfu and @patak
3
+ */
4
+ import { KEYS } from './dom-keys.js';
5
+ const skipKeys = [
6
+ 'window',
7
+ 'self',
8
+ 'top',
9
+ 'parent',
10
+ ];
11
+ export function getWindowKeys(global, win) {
12
+ const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win))
13
+ .filter((k) => {
14
+ if (skipKeys.includes(k)) {
15
+ return false;
16
+ }
17
+ if (k in global) {
18
+ return KEYS.includes(k);
19
+ }
20
+ return true;
21
+ }));
22
+ return keys;
23
+ }
24
+ function isClassLikeName(name) {
25
+ return name[0] === name[0].toUpperCase();
26
+ }
27
+ export function populateGlobal(global, win, options = {}) {
28
+ const { bindFunctions = false } = options;
29
+ const keys = getWindowKeys(global, win);
30
+ const originals = new Map();
31
+ const overrideObject = new Map();
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) {
38
+ originals.set(key, global[key]);
39
+ }
40
+ Object.defineProperty(global, key, {
41
+ get() {
42
+ if (overrideObject.has(key)) {
43
+ return overrideObject.get(key);
44
+ }
45
+ if (boundFunction) {
46
+ return boundFunction;
47
+ }
48
+ return win[key];
49
+ },
50
+ set(v) {
51
+ overrideObject.set(key, v);
52
+ },
53
+ configurable: true,
54
+ });
55
+ }
56
+ global.window = global;
57
+ global.self = global;
58
+ global.top = global;
59
+ global.parent = global;
60
+ if (global.global) {
61
+ global.global = global;
62
+ }
63
+ skipKeys.forEach(k => keys.add(k));
64
+ return {
65
+ keys,
66
+ skipKeys,
67
+ originals,
68
+ };
69
+ }
@@ -7,4 +7,4 @@ export declare function createMarkdownPlugins(ctx: Context): Promise<VitePlugin[
7
7
  export declare function createMarkdownFilesWatcher(ctx: Context): Promise<{
8
8
  stop: () => Promise<void>;
9
9
  }>;
10
- export declare type MarkdownFilesWatcher = ReturnType<typeof createMarkdownFilesWatcher>;
10
+ export type MarkdownFilesWatcher = ReturnType<typeof createMarkdownFilesWatcher>;
@@ -1,14 +1,14 @@
1
1
  import chokidar from 'chokidar';
2
2
  import type { ServerStoryFile } from '@histoire/shared';
3
3
  import { Context } from './context.js';
4
- declare type StoryChangeHandler = (file?: ServerStoryFile) => unknown;
4
+ type StoryChangeHandler = (file?: ServerStoryFile) => unknown;
5
5
  /**
6
6
  * Called when a new story is added or modified. Collecting should be done.
7
7
  * @param handler
8
8
  */
9
9
  export declare function onStoryChange(handler: StoryChangeHandler): void;
10
10
  export declare function notifyStoryChange(file?: ServerStoryFile): void;
11
- declare type StoryListChangeHandler = () => unknown;
11
+ type StoryListChangeHandler = () => unknown;
12
12
  /**
13
13
  * Called when the story list has changed (ex: removed a story). No collecting should be needed.
14
14
  * @param handler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.11.7",
3
+ "version": "0.11.9",
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.7",
37
- "@histoire/controls": "^0.11.7",
38
- "@histoire/shared": "^0.11.7",
39
- "@histoire/vendors": "^0.11.7",
36
+ "@histoire/app": "^0.11.9",
37
+ "@histoire/controls": "^0.11.9",
38
+ "@histoire/shared": "^0.11.9",
39
+ "@histoire/vendors": "^0.11.9",
40
40
  "@types/flexsearch": "^0.7.3",
41
41
  "@types/markdown-it": "^12.2.3",
42
42
  "birpc": "^0.1.1",
@@ -49,8 +49,8 @@
49
49
  "fs-extra": "^10.0.1",
50
50
  "globby": "^13.1.1",
51
51
  "gray-matter": "^4.0.3",
52
- "happy-dom": "^2.55.0",
53
52
  "jiti": "^1.16.0",
53
+ "jsdom": "^20.0.3",
54
54
  "markdown-it": "^12.3.2",
55
55
  "markdown-it-anchor": "^8.6.2",
56
56
  "markdown-it-attrs": "^4.1.3",
@@ -60,7 +60,7 @@
60
60
  "pathe": "^0.2.0",
61
61
  "picocolors": "^1.0.0",
62
62
  "sade": "^1.8.1",
63
- "shiki": "0.10.1",
63
+ "shiki": "0.11.1",
64
64
  "sirv": "^2.0.2",
65
65
  "tinypool": "^0.1.2",
66
66
  "vite-node": "0.23.4"
@@ -60,9 +60,6 @@ export default async (payload: Payload): Promise<ReturnData> => {
60
60
  }
61
61
 
62
62
  const { destroy: destroyDomEnv } = createDomEnv()
63
- if (!global.CSS.supports) {
64
- global.CSS.supports = () => false
65
- }
66
63
 
67
64
  const el = window.document.createElement('div')
68
65
 
@@ -249,16 +249,6 @@ export async function processConfig (config: HistoireConfig, mode: ConfigMode):
249
249
  }
250
250
 
251
251
  export async function processDefaultConfig (defaultConfig: HistoireConfig, preUserConfig: HistoireConfig, mode: ConfigMode, cwd: string): Promise<HistoireConfig> {
252
- // Automatically inline dependencies in vite-node
253
- const pkgFile = await findUp(cwd, ['package.json'])
254
- const fs = (await import('fs-extra')).default
255
- if (pkgFile) {
256
- const pkg = await fs.readJSON(pkgFile)
257
- if (pkg.dependencies) {
258
- defaultConfig.viteNodeInlineDeps = Object.keys(pkg.dependencies).map(d => new RegExp(d))
259
- }
260
- }
261
-
262
252
  // Apply plugins
263
253
  for (const plugin of [...defaultConfig.plugins, ...preUserConfig.plugins ?? []]) {
264
254
  if (plugin.defaultConfig) {
@@ -24,6 +24,7 @@ const LIVING_KEYS = [
24
24
  'Comment',
25
25
  'DocumentType',
26
26
  'NodeList',
27
+ 'RadioNodeList',
27
28
  'HTMLCollection',
28
29
  'HTMLOptionsCollection',
29
30
  'DOMStringMap',
@@ -100,6 +101,7 @@ const LIVING_KEYS = [
100
101
  'HTMLVideoElement',
101
102
  'HTMLAudioElement',
102
103
  'HTMLTrackElement',
104
+ 'HTMLFormControlsCollection',
103
105
  'SVGElement',
104
106
  'SVGGraphicsElement',
105
107
  'SVGSVGElement',
@@ -130,6 +132,7 @@ const LIVING_KEYS = [
130
132
  'Location',
131
133
  'History',
132
134
  'Screen',
135
+ 'Crypto',
133
136
  'Performance',
134
137
  'Navigator',
135
138
  'PluginArray',
@@ -163,6 +166,12 @@ const LIVING_KEYS = [
163
166
  'Headers',
164
167
  'AbortController',
165
168
  'AbortSignal',
169
+ 'ArrayBuffer',
170
+
171
+ // not specified in docs, but is available
172
+ 'Image',
173
+ 'Audio',
174
+ 'Option',
166
175
  ]
167
176
 
168
177
  const OTHER_KEYS = [
@@ -171,6 +180,7 @@ const OTHER_KEYS = [
171
180
  'atob',
172
181
  'blur',
173
182
  'btoa',
183
+ 'cancelAnimationFrame',
174
184
  /* 'clearInterval', */
175
185
  /* 'clearTimeout', */
176
186
  'close',
@@ -187,6 +197,7 @@ const OTHER_KEYS = [
187
197
  'innerWidth',
188
198
  'length',
189
199
  'location',
200
+ 'matchMedia',
190
201
  'moveBy',
191
202
  'moveTo',
192
203
  'name',
@@ -201,6 +212,7 @@ const OTHER_KEYS = [
201
212
  'print',
202
213
  'prompt',
203
214
  'removeEventListener',
215
+ 'requestAnimationFrame',
204
216
  'resizeBy',
205
217
  'resizeTo',
206
218
  'screen',
@@ -221,6 +233,7 @@ const OTHER_KEYS = [
221
233
  'stop',
222
234
  /* 'toString', */
223
235
  'top',
236
+ 'Window',
224
237
  'window',
225
238
  ]
226
239
 
@@ -1,22 +1,29 @@
1
- import { Window } from 'happy-dom'
2
- import { KEYS } from './dom-keys.js'
1
+ import {
2
+ JSDOM,
3
+ VirtualConsole,
4
+ } from 'jsdom'
5
+ import { populateGlobal } from './util.js'
3
6
 
4
7
  export function createDomEnv () {
5
- // @ts-ignore
6
- const window = global.window = new Window()
7
- const globalKeys = KEYS.concat(Object.getOwnPropertyNames(window))
8
- .filter(k => !k.startsWith('_'))
9
- .filter(k => !(k in global))
8
+ const dom = new JSDOM(
9
+ '<!DOCTYPE html>',
10
+ {
11
+ pretendToBeVisual: true,
12
+ runScripts: 'dangerously',
13
+ url: 'http://localhost:3000',
14
+ virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : undefined,
15
+ includeNodeLocations: false,
16
+ contentType: 'text/html',
17
+ },
18
+ )
10
19
 
11
- for (const key of globalKeys) {
12
- global[key] = window[key]
13
- }
20
+ const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true })
14
21
 
15
22
  function destroy () {
16
- globalKeys.forEach(key => delete global[key])
17
- globalKeys.length = 0
18
- window.happyDOM.cancelAsync()
19
- delete global.window
23
+ keys.forEach(key => delete global[key])
24
+ originals.forEach((v, k) => {
25
+ global[k] = v
26
+ })
20
27
  }
21
28
 
22
29
  return {
@@ -0,0 +1,83 @@
1
+ /*
2
+ * Code from vitest https://github.com/vitest-dev/vitest/blob/98974ba4a5b95a57a98bc2077b74bc5609d6bb3a/packages/vitest/src/integrations/env/utils.ts#L1 by @antfu and @patak
3
+ */
4
+
5
+ import { KEYS } from './dom-keys.js'
6
+
7
+ const skipKeys = [
8
+ 'window',
9
+ 'self',
10
+ 'top',
11
+ 'parent',
12
+ ]
13
+
14
+ export function getWindowKeys (global: any, win: any) {
15
+ const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win))
16
+ .filter((k) => {
17
+ if (skipKeys.includes(k)) {
18
+ return false
19
+ }
20
+ if (k in global) {
21
+ return KEYS.includes(k)
22
+ }
23
+ return true
24
+ }))
25
+
26
+ return keys
27
+ }
28
+
29
+ function isClassLikeName (name: string) {
30
+ return name[0] === name[0].toUpperCase()
31
+ }
32
+
33
+ interface PopulateOptions {
34
+ // we bind functions such as addEventListener and others
35
+ // because they rely on `this` in happy-dom, and in jsdom it
36
+ // has a priority for getting implementation from symbols
37
+ // (global doesn't have these symbols, but window - does)
38
+ bindFunctions?: boolean
39
+ }
40
+
41
+ export function populateGlobal (global: any, win: any, options: PopulateOptions = {}) {
42
+ const { bindFunctions = false } = options
43
+ const keys = getWindowKeys(global, win)
44
+
45
+ const originals = new Map<string | symbol, any>()
46
+
47
+ const overrideObject = new Map<string | symbol, any>()
48
+ for (const key of keys) {
49
+ const boundFunction = bindFunctions &&
50
+ typeof win[key] === 'function' &&
51
+ !isClassLikeName(key) &&
52
+ win[key].bind(win)
53
+
54
+ if (KEYS.includes(key) && key in global) { originals.set(key, global[key]) }
55
+
56
+ Object.defineProperty(global, key, {
57
+ get () {
58
+ if (overrideObject.has(key)) { return overrideObject.get(key) }
59
+ if (boundFunction) { return boundFunction }
60
+ return win[key]
61
+ },
62
+ set (v) {
63
+ overrideObject.set(key, v)
64
+ },
65
+ configurable: true,
66
+ })
67
+ }
68
+
69
+ global.window = global
70
+ global.self = global
71
+ global.top = global
72
+ global.parent = global
73
+
74
+ if (global.global) { global.global = global }
75
+
76
+ skipKeys.forEach(k => keys.add(k))
77
+
78
+ return {
79
+ keys,
80
+ skipKeys,
81
+ originals,
82
+ }
83
+ }