jinrai 1.1.3 → 1.1.5
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/front.config.json +2 -1
- package/index.ts +2 -1
- package/lib/bin/bin.js +115 -52
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/src/bin/agent/agent.d.ts +1 -0
- package/lib/src/bin/agent/agent.js +2 -1
- package/lib/src/bin/config/userConfig.d.ts +1 -0
- package/lib/src/bin/playwright/pageCollector.d.ts +2 -0
- package/lib/src/bin/playwright/pageTestCollector.d.ts +6 -0
- package/lib/src/bin/playwright/templates.d.ts +6 -1
- package/lib/src/bin/routes/Parser.d.ts +19 -1
- package/lib/src/bin/routes/getRoutes.d.ts +1 -0
- package/lib/src/front/server/useIsServer.d.ts +1 -0
- package/lib/src/front/server/useIsServer.js +7 -0
- package/lib/src/front/server-state/DataProxy.js +3 -0
- package/lib/src/front/server-state/SSR.d.ts +1 -0
- package/lib/src/front/server-state/SSR.js +3 -1
- package/lib/src/front/server-state/orig.d.ts +2 -0
- package/lib/src/front/server-state/{real.js → orig.js} +3 -2
- package/lib/src/front/server-state/serverStates.d.ts +1 -0
- package/lib/src/front/server-state/serverStates.js +6 -2
- package/lib/src/front/server-state/testState.d.ts +3 -0
- package/lib/src/front/server-state/testState.js +14 -0
- package/lib/src/front/server-state/useServerState.js +5 -9
- package/lib/src/front/translate/TranslateConfig.d.ts +21 -0
- package/lib/src/front/translate/TranslateConfig.js +108 -0
- package/lib/src/front/url/JinraiContext.d.ts +1 -0
- package/lib/src/front/url/JinraiContext.js +1 -0
- package/lib/src/front/url/adapter/def.js +1 -1
- package/lib/src/front/url/adapter/rrd6.js +2 -2
- package/lib/src/front/url/adapter/rrd7.js +2 -2
- package/lib/src/front/url/search/useSearch.js +3 -4
- package/lib/src/front/wrapper/Custom.js +5 -1
- package/lib/vite/plugin.js +20 -14
- package/package.json +6 -2
- package/rollup.config.mjs +2 -1
- package/src/bin/agent/agent.ts +1 -0
- package/src/bin/build/build.ts +23 -10
- package/src/bin/config/define.ts +1 -3
- package/src/bin/config/userConfig.ts +1 -0
- package/src/bin/playwright/pageCollector.ts +8 -4
- package/src/bin/playwright/pageTestCollector.ts +15 -0
- package/src/bin/playwright/templates.ts +14 -4
- package/src/bin/routes/Parser.ts +88 -27
- package/src/bin/routes/getRoutes.ts +5 -1
- package/src/front/server/useIsServer.ts +5 -0
- package/src/front/server-state/DataProxy.ts +4 -0
- package/src/front/server-state/SSR.ts +5 -1
- package/src/front/server-state/{real.ts → orig.ts} +3 -1
- package/src/front/server-state/serverStates.ts +8 -2
- package/src/front/server-state/testState.ts +15 -0
- package/src/front/server-state/useServerState.ts +6 -11
- package/src/front/translate/TranslateConfig.tsx +153 -0
- package/src/front/url/JinraiContext.tsx +2 -0
- package/src/front/url/adapter/def.tsx +1 -1
- package/src/front/url/adapter/rrd6.tsx +2 -3
- package/src/front/url/adapter/rrd7.tsx +2 -2
- package/src/front/url/search/useSearch.ts +3 -4
- package/src/front/wrapper/Custom.tsx +9 -1
- package/tests/parse/custom.test.ts +2 -1
- package/tsconfig.types.json +1 -0
- package/vite/plugin.ts +32 -20
- package/lib/src/front/server-state/real.d.ts +0 -1
package/vite/plugin.ts
CHANGED
|
@@ -2,21 +2,26 @@ import { createServer, type Plugin, type ViteDevServer } from "vite"
|
|
|
2
2
|
|
|
3
3
|
import { AsyncLocalStorage } from "async_hooks"
|
|
4
4
|
import { type BrowserContext, chromium, Page } from "playwright"
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// import { writeFile } from "fs/promises"
|
|
9
|
-
import { JinraiAgent } from "../src/bin/agent/agent"
|
|
5
|
+
import { ViteAgent } from "../src/bin/agent/agent"
|
|
6
|
+
import { pageTestCollector } from "../src/bin/playwright/pageTestCollector"
|
|
10
7
|
|
|
11
8
|
const urlStorage = new AsyncLocalStorage<string>()
|
|
12
9
|
|
|
10
|
+
interface CasheItem {
|
|
11
|
+
state: any,
|
|
12
|
+
root: string,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const cashe = new Map<string, CasheItem>()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
13
19
|
export function hydration(): Plugin {
|
|
14
20
|
if (process.env.CHILD_JINRAI_DEV_SERVER) {
|
|
15
21
|
return { name: "vite-jinrai-dummy" }
|
|
16
22
|
}
|
|
17
23
|
process.env.CHILD_JINRAI_DEV_SERVER = "true"
|
|
18
24
|
|
|
19
|
-
console.log("create mirror")
|
|
20
25
|
let mirrorServer: ViteDevServer | undefined = undefined
|
|
21
26
|
let context: BrowserContext | undefined = undefined
|
|
22
27
|
let page: Page | undefined = undefined
|
|
@@ -33,10 +38,10 @@ export function hydration(): Plugin {
|
|
|
33
38
|
|
|
34
39
|
debugUrl = mirrorServer.resolvedUrls?.local[0].slice(0, -1)
|
|
35
40
|
|
|
36
|
-
chromium.launch({ headless:
|
|
37
|
-
|
|
41
|
+
chromium.launch({ headless: true, devtools: false, channel: "chrome" }).then(async browser => {
|
|
42
|
+
|
|
38
43
|
context = await browser.newContext({
|
|
39
|
-
|
|
44
|
+
userAgent: ViteAgent,
|
|
40
45
|
locale: "ru-RU",
|
|
41
46
|
})
|
|
42
47
|
|
|
@@ -46,7 +51,7 @@ export function hydration(): Plugin {
|
|
|
46
51
|
|
|
47
52
|
return {
|
|
48
53
|
name: "vite-jinrai",
|
|
49
|
-
|
|
54
|
+
|
|
50
55
|
configureServer(server: ViteDevServer) {
|
|
51
56
|
server.middlewares.use((req, _res, next) => {
|
|
52
57
|
if (req.url?.startsWith("/@")) {
|
|
@@ -61,29 +66,36 @@ export function hydration(): Plugin {
|
|
|
61
66
|
async transformIndexHtml(html: string) {
|
|
62
67
|
const currentUrl = urlStorage.getStore()
|
|
63
68
|
if (currentUrl && page) {
|
|
69
|
+
const data = cashe.get(currentUrl)
|
|
70
|
+
if (data) {
|
|
71
|
+
return print(html, data.root, data.state)
|
|
72
|
+
}
|
|
73
|
+
|
|
64
74
|
await page.goto(debugUrl + currentUrl)
|
|
65
75
|
await page.waitForLoadState("networkidle")
|
|
66
76
|
|
|
67
|
-
|
|
68
|
-
// const { routes } = getRoutesAndTemplates([{ id: 1, state: {}, mask: currentUrl, root }], true, false)
|
|
77
|
+
await page.waitForTimeout(2000)
|
|
69
78
|
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
const { root, state } = await pageTestCollector(page)
|
|
80
|
+
cashe.set(currentUrl, { root, state })
|
|
72
81
|
|
|
73
|
-
|
|
74
|
-
html = html.replace("<!--app-head-->", JSON.stringify(state, null, 2))
|
|
75
|
-
|
|
76
|
-
return html
|
|
82
|
+
return print(html, root, state)
|
|
77
83
|
}
|
|
78
84
|
return html
|
|
79
85
|
},
|
|
80
86
|
|
|
81
87
|
closeWatcher() {
|
|
82
|
-
console.log("Stop server")
|
|
83
|
-
|
|
84
88
|
page?.close()
|
|
85
89
|
mirrorServer?.close()
|
|
86
90
|
context?.close()
|
|
87
91
|
},
|
|
88
92
|
}
|
|
89
93
|
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
const print = (html: string, root: string, state: any) => {
|
|
97
|
+
html = html.replace("<!--app-html-->", root)
|
|
98
|
+
html = html.replace("<!--app-head-->", `<script>window.__appc__ = ${JSON.stringify({state})}</script>`)
|
|
99
|
+
|
|
100
|
+
return html
|
|
101
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function real<T>(value: T): T;
|