histoire 0.15.4 → 0.15.6
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/index.d.ts +0 -1
- package/dist/node/collect/index.js +5 -10
- package/dist/node/collect/worker.d.ts +0 -1
- package/dist/node/collect/worker.js +7 -4
- package/dist/node/server.js +1 -2
- package/package.json +6 -6
- package/src/node/collect/index.ts +5 -11
- package/src/node/collect/worker.ts +8 -6
- package/src/node/server.ts +0 -3
|
@@ -2,7 +2,7 @@ import { MessageChannel } from 'node:worker_threads';
|
|
|
2
2
|
import { ViteNodeServer } from 'vite-node/server';
|
|
3
3
|
import { relative } from 'pathe';
|
|
4
4
|
import pc from 'picocolors';
|
|
5
|
-
import Tinypool from 'tinypool';
|
|
5
|
+
import Tinypool from '@akryum/tinypool';
|
|
6
6
|
import { createBirpc } from 'birpc';
|
|
7
7
|
import { cpus } from 'node:os';
|
|
8
8
|
import { createPath } from '../tree.js';
|
|
@@ -58,18 +58,15 @@ export function useCollectStories(options, ctx) {
|
|
|
58
58
|
workerPort,
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
const invalidates = new Set();
|
|
62
61
|
if (mainServer) {
|
|
63
62
|
mainServer.watcher.on('change', (file) => {
|
|
64
63
|
file = slash(file);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
threadPool.broadcastMessage({
|
|
65
|
+
kind: 'hst:invalidate',
|
|
66
|
+
file,
|
|
67
|
+
});
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
-
function clearInvalidates() {
|
|
71
|
-
invalidates.clear();
|
|
72
|
-
}
|
|
73
70
|
async function executeStoryFile(storyFile) {
|
|
74
71
|
try {
|
|
75
72
|
const { workerPort } = createChannel();
|
|
@@ -78,7 +75,6 @@ export function useCollectStories(options, ctx) {
|
|
|
78
75
|
base: server.config.base,
|
|
79
76
|
storyFile,
|
|
80
77
|
port: workerPort,
|
|
81
|
-
invalidates: Array.from(invalidates),
|
|
82
78
|
};
|
|
83
79
|
const { storyData } = await threadPool.run(payload, {
|
|
84
80
|
transferList: [
|
|
@@ -127,6 +123,5 @@ export function useCollectStories(options, ctx) {
|
|
|
127
123
|
clearCache,
|
|
128
124
|
executeStoryFile,
|
|
129
125
|
destroy,
|
|
130
|
-
clearInvalidates,
|
|
131
126
|
};
|
|
132
127
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { parentPort } from 'node:worker_threads';
|
|
2
3
|
import { performance } from 'node:perf_hooks';
|
|
3
4
|
import { ModuleCacheMap, ViteNodeRunner } from 'vite-node/client';
|
|
4
5
|
import { createBirpc } from 'birpc';
|
|
@@ -9,6 +10,12 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
9
10
|
const _moduleCache = new ModuleCacheMap();
|
|
10
11
|
let _runner;
|
|
11
12
|
let _rpc;
|
|
13
|
+
// Cleanup module cache
|
|
14
|
+
parentPort.on('message', message => {
|
|
15
|
+
if (message?.kind === 'hst:invalidate') {
|
|
16
|
+
_moduleCache.delete(message.file);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
12
19
|
export default async (payload) => {
|
|
13
20
|
const startTime = performance.now();
|
|
14
21
|
process.env.HST_COLLECT = 'true';
|
|
@@ -27,10 +34,6 @@ export default async (payload) => {
|
|
|
27
34
|
return _rpc.resolveId(id, importer);
|
|
28
35
|
},
|
|
29
36
|
}));
|
|
30
|
-
// Cleanup cache
|
|
31
|
-
for (const file of payload.invalidates) {
|
|
32
|
-
_moduleCache.delete(file);
|
|
33
|
-
}
|
|
34
37
|
const { destroy: destroyDomEnv } = createDomEnv();
|
|
35
38
|
const el = window.document.createElement('div');
|
|
36
39
|
const beforeExectureTime = performance.now();
|
package/dist/node/server.js
CHANGED
|
@@ -56,7 +56,7 @@ export async function createServer(ctx, options = {}) {
|
|
|
56
56
|
});
|
|
57
57
|
// Wait for pre-bundling (in `listen()`)
|
|
58
58
|
await server.listen(options.port ?? server.config.server?.port);
|
|
59
|
-
const { clearCache, executeStoryFile, destroy: destroyCollectStories,
|
|
59
|
+
const { clearCache, executeStoryFile, destroy: destroyCollectStories, } = useCollectStories({
|
|
60
60
|
server: nodeServer,
|
|
61
61
|
mainServer: server,
|
|
62
62
|
}, ctx);
|
|
@@ -151,7 +151,6 @@ export async function createServer(ctx, options = {}) {
|
|
|
151
151
|
server.ws.send('histoire:all-stories-loaded', {});
|
|
152
152
|
}
|
|
153
153
|
console.log(`Collect stories end ${pc.bold(pc.blue(Math.round(performance.now() - time)))}ms`);
|
|
154
|
-
clearInvalidates();
|
|
155
154
|
invalidateModule(VirtualFiles.RESOLVED_STORIES_ID);
|
|
156
155
|
invalidateModule(VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID);
|
|
157
156
|
collecting = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.6",
|
|
4
4
|
"description": "A fast story book powered by Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -37,10 +37,11 @@
|
|
|
37
37
|
"histoire": "./bin.mjs"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@histoire/
|
|
42
|
-
"@histoire/
|
|
43
|
-
"@histoire/
|
|
40
|
+
"@akryum/tinypool": "^0.3.1",
|
|
41
|
+
"@histoire/app": "^0.15.6",
|
|
42
|
+
"@histoire/controls": "^0.15.6",
|
|
43
|
+
"@histoire/shared": "^0.15.6",
|
|
44
|
+
"@histoire/vendors": "^0.15.6",
|
|
44
45
|
"@types/flexsearch": "^0.7.3",
|
|
45
46
|
"@types/markdown-it": "^12.2.3",
|
|
46
47
|
"birpc": "^0.1.1",
|
|
@@ -66,7 +67,6 @@
|
|
|
66
67
|
"sade": "^1.8.1",
|
|
67
68
|
"shiki-es": "^0.2.0",
|
|
68
69
|
"sirv": "^2.0.2",
|
|
69
|
-
"tinypool": "^0.1.2",
|
|
70
70
|
"vite-node": "0.28.4"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
@@ -4,7 +4,7 @@ import { ViteNodeServer } from 'vite-node/server'
|
|
|
4
4
|
import type { FetchFunction, ResolveIdFunction } from 'vite-node'
|
|
5
5
|
import { relative } from 'pathe'
|
|
6
6
|
import pc from 'picocolors'
|
|
7
|
-
import Tinypool from 'tinypool'
|
|
7
|
+
import Tinypool from '@akryum/tinypool'
|
|
8
8
|
import { createBirpc } from 'birpc'
|
|
9
9
|
import { cpus } from 'node:os'
|
|
10
10
|
import type { ServerStoryFile } from '@histoire/shared'
|
|
@@ -82,20 +82,16 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
const invalidates = new Set<string>()
|
|
86
|
-
|
|
87
85
|
if (mainServer) {
|
|
88
86
|
mainServer.watcher.on('change', (file) => {
|
|
89
87
|
file = slash(file)
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
threadPool.broadcastMessage({
|
|
89
|
+
kind: 'hst:invalidate',
|
|
90
|
+
file,
|
|
91
|
+
})
|
|
92
92
|
})
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
function clearInvalidates () {
|
|
96
|
-
invalidates.clear()
|
|
97
|
-
}
|
|
98
|
-
|
|
99
95
|
async function executeStoryFile (storyFile: ServerStoryFile) {
|
|
100
96
|
try {
|
|
101
97
|
const { workerPort } = createChannel()
|
|
@@ -104,7 +100,6 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
|
|
|
104
100
|
base: server.config.base,
|
|
105
101
|
storyFile,
|
|
106
102
|
port: workerPort,
|
|
107
|
-
invalidates: Array.from(invalidates),
|
|
108
103
|
}
|
|
109
104
|
const { storyData } = await threadPool.run(payload, {
|
|
110
105
|
transferList: [
|
|
@@ -157,6 +152,5 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
|
|
|
157
152
|
clearCache,
|
|
158
153
|
executeStoryFile,
|
|
159
154
|
destroy,
|
|
160
|
-
clearInvalidates,
|
|
161
155
|
}
|
|
162
156
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url'
|
|
2
2
|
import type { MessagePort } from 'node:worker_threads'
|
|
3
|
+
import { parentPort } from 'node:worker_threads'
|
|
3
4
|
import { performance } from 'node:perf_hooks'
|
|
4
5
|
import { ModuleCacheMap, ViteNodeRunner } from 'vite-node/client'
|
|
5
6
|
import { createBirpc } from 'birpc'
|
|
@@ -16,7 +17,6 @@ export interface Payload {
|
|
|
16
17
|
base: string
|
|
17
18
|
port: MessagePort
|
|
18
19
|
storyFile: ServerStoryFile
|
|
19
|
-
invalidates: string[]
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export interface ReturnData {
|
|
@@ -30,6 +30,13 @@ let _rpc: ReturnType<typeof createBirpc<{
|
|
|
30
30
|
resolveId: ResolveIdFunction
|
|
31
31
|
}>>
|
|
32
32
|
|
|
33
|
+
// Cleanup module cache
|
|
34
|
+
parentPort.on('message', message => {
|
|
35
|
+
if (message?.kind === 'hst:invalidate') {
|
|
36
|
+
_moduleCache.delete(message.file)
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
|
|
33
40
|
export default async (payload: Payload): Promise<ReturnData> => {
|
|
34
41
|
const startTime = performance.now()
|
|
35
42
|
process.env.HST_COLLECT = 'true'
|
|
@@ -54,11 +61,6 @@ export default async (payload: Payload): Promise<ReturnData> => {
|
|
|
54
61
|
},
|
|
55
62
|
}))
|
|
56
63
|
|
|
57
|
-
// Cleanup cache
|
|
58
|
-
for (const file of payload.invalidates) {
|
|
59
|
-
_moduleCache.delete(file)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
64
|
const { destroy: destroyDomEnv } = createDomEnv()
|
|
63
65
|
|
|
64
66
|
const el = window.document.createElement('div')
|
package/src/node/server.ts
CHANGED
|
@@ -81,7 +81,6 @@ export async function createServer (ctx: Context, options: CreateServerOptions =
|
|
|
81
81
|
clearCache,
|
|
82
82
|
executeStoryFile,
|
|
83
83
|
destroy: destroyCollectStories,
|
|
84
|
-
clearInvalidates,
|
|
85
84
|
} = useCollectStories({
|
|
86
85
|
server: nodeServer,
|
|
87
86
|
mainServer: server,
|
|
@@ -189,8 +188,6 @@ export async function createServer (ctx: Context, options: CreateServerOptions =
|
|
|
189
188
|
}
|
|
190
189
|
console.log(`Collect stories end ${pc.bold(pc.blue(Math.round(performance.now() - time)))}ms`)
|
|
191
190
|
|
|
192
|
-
clearInvalidates()
|
|
193
|
-
|
|
194
191
|
invalidateModule(VirtualFiles.RESOLVED_STORIES_ID)
|
|
195
192
|
invalidateModule(VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID)
|
|
196
193
|
|