histoire 0.11.7 → 0.11.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.
- package/dist/node/collect/worker.js +0 -3
- package/dist/node/config.js +0 -9
- package/dist/node/dom/dom-keys.js +12 -0
- package/dist/node/dom/env.d.ts +1 -2
- package/dist/node/dom/env.js +15 -14
- package/dist/node/dom/util.d.ts +10 -0
- package/dist/node/dom/util.js +69 -0
- package/package.json +6 -6
- package/src/node/collect/worker.ts +0 -3
- package/src/node/config.ts +0 -10
- package/src/node/dom/dom-keys.ts +13 -0
- package/src/node/dom/env.ts +21 -14
- package/src/node/dom/util.ts +83 -0
|
@@ -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
|
package/dist/node/config.js
CHANGED
|
@@ -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);
|
package/dist/node/dom/env.d.ts
CHANGED
package/dist/node/dom/env.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { JSDOM, VirtualConsole, } from 'jsdom';
|
|
2
|
+
import { populateGlobal } from './util.js';
|
|
3
3
|
export function createDomEnv() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
.
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.8",
|
|
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.
|
|
37
|
-
"@histoire/controls": "^0.11.
|
|
38
|
-
"@histoire/shared": "^0.11.
|
|
39
|
-
"@histoire/vendors": "^0.11.
|
|
36
|
+
"@histoire/app": "^0.11.8",
|
|
37
|
+
"@histoire/controls": "^0.11.8",
|
|
38
|
+
"@histoire/shared": "^0.11.8",
|
|
39
|
+
"@histoire/vendors": "^0.11.8",
|
|
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",
|
package/src/node/config.ts
CHANGED
|
@@ -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) {
|
package/src/node/dom/dom-keys.ts
CHANGED
|
@@ -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
|
|
package/src/node/dom/env.ts
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
JSDOM,
|
|
3
|
+
VirtualConsole,
|
|
4
|
+
} from 'jsdom'
|
|
5
|
+
import { populateGlobal } from './util.js'
|
|
3
6
|
|
|
4
7
|
export function createDomEnv () {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
12
|
-
global[key] = window[key]
|
|
13
|
-
}
|
|
20
|
+
const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true })
|
|
14
21
|
|
|
15
22
|
function destroy () {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
}
|