histoire 0.11.6 → 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/build.js +4 -2
- package/dist/node/builtin-plugins/vanilla-support/RenderStory.js +0 -1
- package/dist/node/collect/worker.js +0 -3
- package/dist/node/commands/dev.js +3 -3
- package/dist/node/config.js +1 -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/dist/node/server.d.ts +1 -0
- package/dist/node/server.js +8 -3
- package/dist/node/vite.d.ts +5 -1
- package/dist/node/vite.js +6 -4
- package/package.json +6 -7
- package/src/node/build.ts +4 -2
- package/src/node/builtin-plugins/vanilla-support/RenderStory.ts +0 -1
- package/src/node/collect/worker.ts +0 -3
- package/src/node/commands/dev.ts +3 -3
- package/src/node/config.ts +1 -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
- package/src/node/server.ts +9 -4
- package/src/node/vite.ts +13 -6
package/dist/node/build.js
CHANGED
|
@@ -28,7 +28,8 @@ export async function build(ctx) {
|
|
|
28
28
|
const { stop } = await createMarkdownFilesWatcher(ctx);
|
|
29
29
|
await stop();
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const { viteConfig } = await getViteConfigWithPlugins(true, ctx);
|
|
32
|
+
const server = await createViteServer(viteConfig);
|
|
32
33
|
await server.pluginContainer.buildStart({});
|
|
33
34
|
const moduleLoader = useModuleLoader({
|
|
34
35
|
server,
|
|
@@ -54,7 +55,8 @@ export async function build(ctx) {
|
|
|
54
55
|
const storyCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ? 1 : 0), 0);
|
|
55
56
|
const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0);
|
|
56
57
|
const emptyStoryCount = ctx.storyFiles.length - storyCount;
|
|
57
|
-
const
|
|
58
|
+
const { viteConfig: buildViteConfigRaw } = await getViteConfigWithPlugins(false, ctx);
|
|
59
|
+
const buildViteConfig = mergeViteConfig(buildViteConfigRaw, {
|
|
58
60
|
mode: 'development',
|
|
59
61
|
build: {
|
|
60
62
|
lib: false,
|
|
@@ -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
|
|
@@ -9,12 +9,12 @@ export async function devCommand(options) {
|
|
|
9
9
|
const ctx = await createContext({
|
|
10
10
|
mode: 'dev',
|
|
11
11
|
});
|
|
12
|
-
const { server, close } = await createServer(ctx, { port: options.port });
|
|
12
|
+
const { server, viteConfigFile, close } = await createServer(ctx, { port: options.port });
|
|
13
13
|
server.printUrls();
|
|
14
14
|
// Histoire config watcher
|
|
15
15
|
let watcher;
|
|
16
|
-
if (
|
|
17
|
-
watcher = chokidar.watch(
|
|
16
|
+
if (viteConfigFile) {
|
|
17
|
+
watcher = chokidar.watch(viteConfigFile, {
|
|
18
18
|
ignoreInitial: true,
|
|
19
19
|
});
|
|
20
20
|
watcher.on('change', () => {
|
package/dist/node/config.js
CHANGED
|
@@ -139,6 +139,7 @@ export async function loadConfigFile(configFile) {
|
|
|
139
139
|
try {
|
|
140
140
|
const result = jiti(__filename, {
|
|
141
141
|
esmResolve: true,
|
|
142
|
+
requireCache: false,
|
|
142
143
|
})(configFile);
|
|
143
144
|
if (!result.default) {
|
|
144
145
|
throw new Error(`Expected default export in ${configFile}`);
|
|
@@ -226,15 +227,6 @@ export async function processConfig(config, mode) {
|
|
|
226
227
|
return config;
|
|
227
228
|
}
|
|
228
229
|
export async function processDefaultConfig(defaultConfig, preUserConfig, mode, cwd) {
|
|
229
|
-
// Automatically inline dependencies in vite-node
|
|
230
|
-
const pkgFile = await findUp(cwd, ['package.json']);
|
|
231
|
-
const fs = (await import('fs-extra')).default;
|
|
232
|
-
if (pkgFile) {
|
|
233
|
-
const pkg = await fs.readJSON(pkgFile);
|
|
234
|
-
if (pkg.dependencies) {
|
|
235
|
-
defaultConfig.viteNodeInlineDeps = Object.keys(pkg.dependencies).map(d => new RegExp(d));
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
230
|
// Apply plugins
|
|
239
231
|
for (const plugin of [...defaultConfig.plugins, ...preUserConfig.plugins ?? []]) {
|
|
240
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/dist/node/server.d.ts
CHANGED
package/dist/node/server.js
CHANGED
|
@@ -10,11 +10,15 @@ import { wrapLogError } from './util/log.js';
|
|
|
10
10
|
import { createMarkdownFilesWatcher, onMarkdownListChange } from './markdown.js';
|
|
11
11
|
export async function createServer(ctx, options = {}) {
|
|
12
12
|
const getViteServer = async (collecting) => {
|
|
13
|
-
const
|
|
13
|
+
const { viteConfig, viteConfigFile } = await getViteConfigWithPlugins(collecting, ctx);
|
|
14
|
+
const server = await createViteServer(viteConfig);
|
|
14
15
|
await server.pluginContainer.buildStart({});
|
|
15
|
-
return
|
|
16
|
+
return {
|
|
17
|
+
server,
|
|
18
|
+
viteConfigFile,
|
|
19
|
+
};
|
|
16
20
|
};
|
|
17
|
-
const [server, nodeServer, , { stop: stopMdFileWatcher },] = await Promise.all([
|
|
21
|
+
const [{ server, viteConfigFile }, { server: nodeServer }, , { stop: stopMdFileWatcher },] = await Promise.all([
|
|
18
22
|
getViteServer(false),
|
|
19
23
|
getViteServer(true),
|
|
20
24
|
watchStories(ctx),
|
|
@@ -157,6 +161,7 @@ export async function createServer(ctx, options = {}) {
|
|
|
157
161
|
collect();
|
|
158
162
|
return {
|
|
159
163
|
server,
|
|
164
|
+
viteConfigFile,
|
|
160
165
|
close,
|
|
161
166
|
};
|
|
162
167
|
}
|
package/dist/node/vite.d.ts
CHANGED
|
@@ -23,4 +23,8 @@ export declare const RESOLVED_SUPPORT_PLUGINS_COLLECT: string;
|
|
|
23
23
|
export declare const MARKDOWN_FILES = "virtual:$histoire-markdown-files";
|
|
24
24
|
export declare const RESOLVED_MARKDOWN_FILES: string;
|
|
25
25
|
export declare function mergeHistoireViteConfig(viteConfig: InlineConfig, ctx: Context): Promise<InlineConfig>;
|
|
26
|
-
export
|
|
26
|
+
export interface ViteConfigWithPlugins {
|
|
27
|
+
viteConfig: InlineConfig;
|
|
28
|
+
viteConfigFile: string | null;
|
|
29
|
+
}
|
|
30
|
+
export declare function getViteConfigWithPlugins(isServer: boolean, ctx: Context): Promise<ViteConfigWithPlugins>;
|
package/dist/node/vite.js
CHANGED
|
@@ -3,7 +3,6 @@ import { relative, resolve, join, dirname } from 'pathe';
|
|
|
3
3
|
import { mergeConfig as mergeViteConfig, loadConfigFromFile as loadViteConfigFromFile, } from 'vite';
|
|
4
4
|
import { lookup as lookupMime } from 'mrmime';
|
|
5
5
|
import fs from 'fs-extra';
|
|
6
|
-
import ViteInspect from 'vite-plugin-inspect';
|
|
7
6
|
import { APP_PATH, TEMP_PATH } from './alias.js';
|
|
8
7
|
import { notifyStoryChange } from './stories.js';
|
|
9
8
|
import { makeTree } from './tree.js';
|
|
@@ -99,7 +98,6 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
|
|
|
99
98
|
}
|
|
100
99
|
return result;
|
|
101
100
|
}
|
|
102
|
-
plugins.push(ViteInspect());
|
|
103
101
|
plugins.push({
|
|
104
102
|
name: 'histoire-vite-plugin',
|
|
105
103
|
config() {
|
|
@@ -172,7 +170,7 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
|
|
|
172
170
|
else if (isServer && 'server' in setupFileConfig) {
|
|
173
171
|
file = setupFileConfig.server;
|
|
174
172
|
}
|
|
175
|
-
else if ('browser' in setupFileConfig) {
|
|
173
|
+
else if (!isServer && 'browser' in setupFileConfig) {
|
|
176
174
|
file = setupFileConfig.browser;
|
|
177
175
|
}
|
|
178
176
|
if (file) {
|
|
@@ -532,8 +530,12 @@ if (import.meta.hot) {
|
|
|
532
530
|
},
|
|
533
531
|
});
|
|
534
532
|
}
|
|
535
|
-
|
|
533
|
+
const viteConfig = mergeViteConfig(inlineConfig, {
|
|
536
534
|
configFile: false,
|
|
537
535
|
plugins,
|
|
538
536
|
});
|
|
537
|
+
return {
|
|
538
|
+
viteConfig,
|
|
539
|
+
viteConfigFile: userViteConfigFile?.path ?? null,
|
|
540
|
+
};
|
|
539
541
|
}
|
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",
|
|
@@ -63,7 +63,6 @@
|
|
|
63
63
|
"shiki": "0.10.1",
|
|
64
64
|
"sirv": "^2.0.2",
|
|
65
65
|
"tinypool": "^0.1.2",
|
|
66
|
-
"vite-plugin-inspect": "^0.7.5",
|
|
67
66
|
"vite-node": "0.23.4"
|
|
68
67
|
},
|
|
69
68
|
"peerDependencies": {
|
package/src/node/build.ts
CHANGED
|
@@ -45,7 +45,8 @@ export async function build (ctx: Context) {
|
|
|
45
45
|
await stop()
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const
|
|
48
|
+
const { viteConfig } = await getViteConfigWithPlugins(true, ctx)
|
|
49
|
+
const server = await createViteServer(viteConfig)
|
|
49
50
|
await server.pluginContainer.buildStart({})
|
|
50
51
|
|
|
51
52
|
const moduleLoader = useModuleLoader({
|
|
@@ -75,7 +76,8 @@ export async function build (ctx: Context) {
|
|
|
75
76
|
const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0)
|
|
76
77
|
const emptyStoryCount = ctx.storyFiles.length - storyCount
|
|
77
78
|
|
|
78
|
-
const
|
|
79
|
+
const { viteConfig: buildViteConfigRaw } = await getViteConfigWithPlugins(false, ctx)
|
|
80
|
+
const buildViteConfig: ViteInlineConfig = mergeViteConfig(buildViteConfigRaw, {
|
|
79
81
|
mode: 'development',
|
|
80
82
|
build: {
|
|
81
83
|
lib: false,
|
package/src/node/commands/dev.ts
CHANGED
|
@@ -15,13 +15,13 @@ export async function devCommand (options: DevOptions) {
|
|
|
15
15
|
const ctx = await createContext({
|
|
16
16
|
mode: 'dev',
|
|
17
17
|
})
|
|
18
|
-
const { server, close } = await createServer(ctx, { port: options.port })
|
|
18
|
+
const { server, viteConfigFile, close } = await createServer(ctx, { port: options.port })
|
|
19
19
|
server.printUrls()
|
|
20
20
|
|
|
21
21
|
// Histoire config watcher
|
|
22
22
|
let watcher: chokidar.FSWatcher
|
|
23
|
-
if (
|
|
24
|
-
watcher = chokidar.watch(
|
|
23
|
+
if (viteConfigFile) {
|
|
24
|
+
watcher = chokidar.watch(viteConfigFile, {
|
|
25
25
|
ignoreInitial: true,
|
|
26
26
|
})
|
|
27
27
|
watcher.on('change', () => {
|
package/src/node/config.ts
CHANGED
|
@@ -154,6 +154,7 @@ export async function loadConfigFile (configFile: string): Promise<Partial<Histo
|
|
|
154
154
|
try {
|
|
155
155
|
const result = jiti(__filename, {
|
|
156
156
|
esmResolve: true,
|
|
157
|
+
requireCache: false,
|
|
157
158
|
})(configFile)
|
|
158
159
|
if (!result.default) {
|
|
159
160
|
throw new Error(`Expected default export in ${configFile}`)
|
|
@@ -248,16 +249,6 @@ export async function processConfig (config: HistoireConfig, mode: ConfigMode):
|
|
|
248
249
|
}
|
|
249
250
|
|
|
250
251
|
export async function processDefaultConfig (defaultConfig: HistoireConfig, preUserConfig: HistoireConfig, mode: ConfigMode, cwd: string): Promise<HistoireConfig> {
|
|
251
|
-
// Automatically inline dependencies in vite-node
|
|
252
|
-
const pkgFile = await findUp(cwd, ['package.json'])
|
|
253
|
-
const fs = (await import('fs-extra')).default
|
|
254
|
-
if (pkgFile) {
|
|
255
|
-
const pkg = await fs.readJSON(pkgFile)
|
|
256
|
-
if (pkg.dependencies) {
|
|
257
|
-
defaultConfig.viteNodeInlineDeps = Object.keys(pkg.dependencies).map(d => new RegExp(d))
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
252
|
// Apply plugins
|
|
262
253
|
for (const plugin of [...defaultConfig.plugins, ...preUserConfig.plugins ?? []]) {
|
|
263
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
|
+
}
|
package/src/node/server.ts
CHANGED
|
@@ -17,14 +17,18 @@ export interface CreateServerOptions {
|
|
|
17
17
|
|
|
18
18
|
export async function createServer (ctx: Context, options: CreateServerOptions = {}) {
|
|
19
19
|
const getViteServer = async (collecting: boolean) => {
|
|
20
|
-
const
|
|
20
|
+
const { viteConfig, viteConfigFile } = await getViteConfigWithPlugins(collecting, ctx)
|
|
21
|
+
const server = await createViteServer(viteConfig)
|
|
21
22
|
await server.pluginContainer.buildStart({})
|
|
22
|
-
return
|
|
23
|
+
return {
|
|
24
|
+
server,
|
|
25
|
+
viteConfigFile,
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
const [
|
|
26
|
-
server,
|
|
27
|
-
nodeServer,
|
|
30
|
+
{ server, viteConfigFile },
|
|
31
|
+
{ server: nodeServer },
|
|
28
32
|
,
|
|
29
33
|
{ stop: stopMdFileWatcher },
|
|
30
34
|
] = await Promise.all([
|
|
@@ -199,6 +203,7 @@ export async function createServer (ctx: Context, options: CreateServerOptions =
|
|
|
199
203
|
|
|
200
204
|
return {
|
|
201
205
|
server,
|
|
206
|
+
viteConfigFile,
|
|
202
207
|
close,
|
|
203
208
|
}
|
|
204
209
|
}
|
package/src/node/vite.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
} from 'vite'
|
|
10
10
|
import { lookup as lookupMime } from 'mrmime'
|
|
11
11
|
import fs from 'fs-extra'
|
|
12
|
-
import ViteInspect from 'vite-plugin-inspect'
|
|
13
12
|
import { APP_PATH, TEMP_PATH } from './alias.js'
|
|
14
13
|
import { Context } from './context.js'
|
|
15
14
|
import { notifyStoryChange } from './stories.js'
|
|
@@ -97,7 +96,12 @@ export async function mergeHistoireViteConfig (viteConfig: InlineConfig, ctx: Co
|
|
|
97
96
|
return viteConfig
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
export
|
|
99
|
+
export interface ViteConfigWithPlugins {
|
|
100
|
+
viteConfig: InlineConfig
|
|
101
|
+
viteConfigFile: string | null
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context): Promise<ViteConfigWithPlugins> {
|
|
101
105
|
const userViteConfigFile = await loadViteConfigFromFile({ command: ctx.mode === 'dev' ? 'serve' : 'build', mode: ctx.mode })
|
|
102
106
|
const userViteConfig = mergeViteConfig(userViteConfigFile?.config ?? {}, { server: { port: 6006 } })
|
|
103
107
|
|
|
@@ -117,8 +121,6 @@ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context)
|
|
|
117
121
|
return result
|
|
118
122
|
}
|
|
119
123
|
|
|
120
|
-
plugins.push(ViteInspect())
|
|
121
|
-
|
|
122
124
|
plugins.push({
|
|
123
125
|
name: 'histoire-vite-plugin',
|
|
124
126
|
|
|
@@ -191,7 +193,7 @@ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context)
|
|
|
191
193
|
file = setupFileConfig
|
|
192
194
|
} else if (isServer && 'server' in setupFileConfig) {
|
|
193
195
|
file = setupFileConfig.server
|
|
194
|
-
} else if ('browser' in setupFileConfig) {
|
|
196
|
+
} else if (!isServer && 'browser' in setupFileConfig) {
|
|
195
197
|
file = setupFileConfig.browser
|
|
196
198
|
}
|
|
197
199
|
if (file) {
|
|
@@ -574,8 +576,13 @@ if (import.meta.hot) {
|
|
|
574
576
|
})
|
|
575
577
|
}
|
|
576
578
|
|
|
577
|
-
|
|
579
|
+
const viteConfig = mergeViteConfig(inlineConfig, {
|
|
578
580
|
configFile: false,
|
|
579
581
|
plugins,
|
|
580
582
|
}) as InlineConfig
|
|
583
|
+
|
|
584
|
+
return {
|
|
585
|
+
viteConfig,
|
|
586
|
+
viteConfigFile: userViteConfigFile?.path ?? null,
|
|
587
|
+
}
|
|
581
588
|
}
|