jinrai 1.1.4 → 1.1.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/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ export { JinraiContext } from "./src/front/url/JinraiContext"
2
+
3
+ export { JinraiDebug } from "./src/front/url/JinraiDebug"
4
+
1
5
  export type { ServerKey } from "./src/front/server-state/useServerState"
2
6
 
3
7
  export { useServerState } from "./src/front/server-state/useServerState"
package/lib/bin/bin.js CHANGED
@@ -9,7 +9,7 @@ import ora, { spinners } from 'ora';
9
9
  import { stdout, stdin } from 'node:process';
10
10
  import readline from 'node:readline/promises';
11
11
  import path from 'node:path';
12
- import { preview } from 'vite';
12
+ import { createServer } from 'vite';
13
13
 
14
14
  const getUserConfig = async (configName) => {
15
15
  const jiti = createJiti(import.meta.url, {
@@ -271,7 +271,7 @@ const getRawPageData = async (url, pages, test = false, debug = false) => {
271
271
  const path = mask.replaceAll("{", "").replaceAll("}", "").replace("\/*", "");
272
272
  await page.goto(url + path);
273
273
  await page.waitForLoadState("networkidle");
274
- await page.waitForTimeout(1000);
274
+ await page.waitForTimeout(2000);
275
275
  const { state, root, lang } = await pageCollector(page);
276
276
  if (defaultLang == undefined) {
277
277
  defaultLang = lang;
@@ -304,11 +304,17 @@ const getRawPageData = async (url, pages, test = false, debug = false) => {
304
304
  };
305
305
 
306
306
  const vitePreview = async () => {
307
- const previewServer = await preview({
308
- preview: {
309
- port: 8084,
310
- },
307
+ // const previewServer = await preview({
308
+ // preview: {
309
+ // port: 8084,
310
+ // },
311
+ // })
312
+ const previewServer = await createServer({
313
+ server: {
314
+ port: 8084
315
+ }
311
316
  });
317
+ await previewServer.listen();
312
318
  if (!previewServer.resolvedUrls?.local?.length)
313
319
  throw new Error("vite is not defined");
314
320
  return [previewServer.resolvedUrls?.local[0].slice(0, -1), () => previewServer.close()];
@@ -322,7 +328,7 @@ const runBuild = async (options) => {
322
328
  task.success();
323
329
  const [serverUrl, close] = await vitePreview();
324
330
  const { pages, lang } = await getRawPageData(serverUrl, config.pages, config.test, options.debug);
325
- console.log({ lang });
331
+ // console.log({ lang })
326
332
  close();
327
333
  const outputcashe = path.join(config.dist ?? "dist", ".cached");
328
334
  task.do("Format");
@@ -330,7 +336,7 @@ const runBuild = async (options) => {
330
336
  task.next(`Export: (${templates.length})`);
331
337
  await mkdir(outputcashe, { recursive: true });
332
338
  console.log("dev");
333
- const exportConfig = { routes, proxy: config.proxy, meta: config.meta, lang };
339
+ const exportConfig = { routes, proxy: config.proxy, meta: config.meta, lang, cacheablePaths: config.cacheablePaths };
334
340
  await writeFile(path.join(outputcashe, "config.json"), JSON.stringify(exportConfig, null, 2));
335
341
  // await writeFile(
336
342
  // path.join(outputcashe, "index.html"),
package/lib/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { JinraiContext } from "./src/front/url/JinraiContext";
2
+ export { JinraiDebug } from "./src/front/url/JinraiDebug";
1
3
  export type { ServerKey } from "./src/front/server-state/useServerState";
2
4
  export { useServerState } from "./src/front/server-state/useServerState";
3
5
  export { orig, original } from "./src/front/server-state/orig";
package/lib/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ export { JinraiContext } from './src/front/url/JinraiContext.js';
2
+ export { JinraiDebug } from './src/front/url/JinraiDebug.js';
1
3
  export { useServerState } from './src/front/server-state/useServerState.js';
2
4
  export { orig, original } from './src/front/server-state/orig.js';
3
5
  export { useParamsIndex } from './src/front/url/params/useParamsIndex.js';
@@ -10,5 +10,6 @@ export interface Config {
10
10
  dist?: string;
11
11
  proxy?: Record<string, string>;
12
12
  meta?: string;
13
+ cacheablePaths?: string[];
13
14
  }
14
15
  export declare const getUserConfig: (configName: string) => Promise<Config>;
@@ -19,8 +19,10 @@ const getTarget = (data, path) => {
19
19
  }
20
20
  };
21
21
  function createDataProxy(data, path = "") {
22
- if (path.endsWith("@"))
22
+ if (path.endsWith("@")) {
23
+ console.log("set to source >>>> ", path);
23
24
  sources.set(path.slice(0, -1), data);
25
+ }
24
26
  return new Proxy(getTarget(data, path), {
25
27
  get: (_target, prop) => {
26
28
  if (ssr.exportToJV) {
@@ -37,6 +37,9 @@ const getArrayByPath = (path) => {
37
37
  const keys = requestPath.split("/");
38
38
  keys.shift();
39
39
  let link = sources.get(sourceIndex);
40
+ if (!link) {
41
+ return link;
42
+ }
40
43
  for (let key of keys) {
41
44
  if (key.startsWith("[ITEM="))
42
45
  key = key.slice(6, -1);
@@ -21,17 +21,18 @@ const getIdent = (key) => {
21
21
  return Array.isArray(key) ? key.join("-") : key;
22
22
  };
23
23
  const getServerValue = (key, def, options) => {
24
+ console.log("KKKey", key);
24
25
  if (key == undefined) {
25
26
  return [def, false];
26
27
  }
27
28
  const ident = getIdent(key);
28
29
  serverStates.set(ident, { options, value: !options?.source ? def : undefined, key });
29
- console.log("CHECK", ident);
30
+ // console.log("CHECK", ident)
30
31
  if (ident in initialState) {
31
32
  const result = initialState[ident];
32
33
  // delete initialState[ident]
33
- console.log("HAS", ident, result);
34
- if (result != null && typeof result == 'object' && "data" in result) {
34
+ // console.log("HAS", ident, result)
35
+ if (result != null && typeof result == "object" && "data" in result) {
35
36
  return [result.data, true];
36
37
  }
37
38
  return [result, true];
@@ -39,6 +40,7 @@ const getServerValue = (key, def, options) => {
39
40
  return [def, false];
40
41
  };
41
42
  const setServerValue = (key, value, options) => {
43
+ console.log("KKK>>", key);
42
44
  const ident = getIdent(key);
43
45
  serverStates.set(ident, { options, value: !options?.source ? value : undefined, key });
44
46
  return createDataProxy(value, `${ident}@`);
@@ -2,6 +2,7 @@ import { DependencyList, ReactNode } from "react";
2
2
  export interface JinraiProps {
3
3
  deps?: DependencyList;
4
4
  children?: ReactNode;
5
- search: string;
5
+ search?: string;
6
+ debug?: string;
6
7
  }
7
8
  export declare const JinraiContext: import("react").Context<JinraiProps>;
@@ -3,7 +3,6 @@ import { createContext } from 'react';
3
3
  const JinraiContext = createContext({
4
4
  deps: [],
5
5
  children: undefined,
6
- search: ""
7
6
  });
8
7
 
9
8
  export { JinraiContext };
@@ -0,0 +1,6 @@
1
+ import { ReactNode } from "react";
2
+ interface props {
3
+ children: ReactNode;
4
+ }
5
+ export declare const JinraiDebug: (props: props) => ReactNode;
6
+ export {};
@@ -0,0 +1,8 @@
1
+ import { ssr } from '../server-state/SSR.js';
2
+
3
+ const JinraiDebug = (props) => {
4
+ ssr.current = true;
5
+ return props.children;
6
+ };
7
+
8
+ export { JinraiDebug };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jinrai",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "A powerful library that analyzes your modern web application and automatically generates a perfectly rendered, static snapshot of its pages. Experience unparalleled loading speed and SEO clarity without the complexity of traditional SSR setups. Simply point Jinrai at your SPA and witness divine speed.",
5
5
  "main": "lib/index.ts",
6
6
  "scripts": {
@@ -64,7 +64,7 @@
64
64
  "import": "./lib/src/front/url/adapter/rrd7.js"
65
65
  },
66
66
  "./config": {
67
- "types": "./lib/config/config.d.ts",
67
+ "types": "./lib/config.d.ts",
68
68
  "import": "./lib/config/config.js"
69
69
  },
70
70
  "./vite": {
package/src/bin/bin.ts CHANGED
@@ -2,6 +2,7 @@ import { runBuild } from "./build/build"
2
2
 
3
3
  const args = process.argv.slice(2)
4
4
 
5
+
5
6
  const debug = args.includes("--debug")
6
7
  const customConfig = args.find(itm => itm.startsWith("--config="))?.substring(9)
7
8
 
@@ -30,7 +30,7 @@ export const runBuild = async (options: buildArgs) => {
30
30
 
31
31
  const { pages, lang } = await getRawPageData(serverUrl, config.pages, config.test, options.debug)
32
32
 
33
- console.log({ lang })
33
+ // console.log({ lang })
34
34
 
35
35
  close()
36
36
 
@@ -44,7 +44,7 @@ export const runBuild = async (options: buildArgs) => {
44
44
 
45
45
  console.log("dev")
46
46
 
47
- const exportConfig = { routes, proxy: config.proxy, meta: config.meta, lang }
47
+ const exportConfig = { routes, proxy: config.proxy, meta: config.meta, lang, cacheablePaths: config.cacheablePaths }
48
48
 
49
49
  await writeFile(path.join(outputcashe, "config.json"), JSON.stringify(exportConfig, null, 2))
50
50
  // await writeFile(
@@ -1,7 +1,5 @@
1
1
  import type { Config } from "./userConfig"
2
2
 
3
- export const defineConfig = (config: Config) => {
3
+ export const defineConfig = (config: Config): Config => {
4
4
  return config
5
5
  }
6
-
7
-
@@ -15,6 +15,7 @@ export interface Config {
15
15
  dist?: string
16
16
  proxy?: Record<string, string>
17
17
  meta?: string
18
+ cacheablePaths?: string[]
18
19
  }
19
20
 
20
21
  export const getUserConfig = async (configName: string): Promise<Config> => {
@@ -49,7 +49,7 @@ export const getRawPageData = async (
49
49
 
50
50
  await page.waitForLoadState("networkidle")
51
51
 
52
- await page.waitForTimeout(1000)
52
+ await page.waitForTimeout(2000)
53
53
 
54
54
  const { state, root, lang } = await pageCollector(page)
55
55
  if (defaultLang == undefined) {
@@ -1,12 +1,21 @@
1
- import { preview } from "vite"
1
+ import { createServer, preview } from "vite"
2
2
 
3
3
  export const vitePreview = async () => {
4
- const previewServer = await preview({
5
- preview: {
6
- port: 8084,
7
- },
4
+ // const previewServer = await preview({
5
+ // preview: {
6
+ // port: 8084,
7
+ // },
8
+ // })
9
+
10
+ const previewServer = await createServer({
11
+ server: {
12
+ port: 8084
13
+ }
8
14
  })
9
15
 
16
+ await previewServer.listen()
17
+
18
+
10
19
  if (!previewServer.resolvedUrls?.local?.length) throw new Error("vite is not defined")
11
20
 
12
21
  return [previewServer.resolvedUrls?.local[0].slice(0, -1), () => previewServer.close()] as [string, () => void]
@@ -31,8 +31,10 @@ const getTarget = (data: any, path: string) => {
31
31
 
32
32
  type WithDataProxy<T> = T & DataProxy
33
33
  function createDataProxy<T>(data: T, path: string = ""): WithDataProxy<T> {
34
- if (path.endsWith("@")) sources.set(path.slice(0, -1), data)
35
-
34
+ if (path.endsWith("@")) {
35
+ console.log("set to source >>>> ", path)
36
+ sources.set(path.slice(0, -1), data)
37
+ }
36
38
  return new Proxy(getTarget(data, path), {
37
39
  get: (_target: any, prop: PropertyKey) => {
38
40
  if (ssr.exportToJV) {
@@ -47,6 +47,9 @@ const getArrayByPath = (path: string) => {
47
47
  const requestId = keys.shift()
48
48
 
49
49
  let link = sources.get(sourceIndex)
50
+ if (!link) {
51
+ return link
52
+ }
50
53
 
51
54
  for (let key of keys) {
52
55
  if (key.startsWith("[ITEM=")) key = key.slice(6, -1)
@@ -45,21 +45,22 @@ export const getIdent = (key: ServerKey): string => {
45
45
  }
46
46
 
47
47
  export const getServerValue = (key?: ServerKey, def?: ServerValue["value"], options?: ServerValue["options"]) => {
48
+ // console.log("KKKey", key)
48
49
  if (key == undefined) {
49
50
  return [def, false]
50
51
  }
51
52
  const ident = getIdent(key)
52
53
  serverStates.set(ident, { options, value: !options?.source ? def : undefined, key })
53
54
 
54
- console.log("CHECK", ident)
55
+ // console.log("CHECK", ident)
55
56
 
56
57
  if (ident in initialState) {
57
58
  const result = initialState[ident]
58
59
  // delete initialState[ident]
59
60
 
60
- console.log("HAS", ident, result)
61
+ // console.log("HAS", ident, result)
61
62
 
62
- if (result != null && typeof result == 'object' && "data" in result) {
63
+ if (result != null && typeof result == "object" && "data" in result) {
63
64
  return [result.data, true]
64
65
  }
65
66
 
@@ -70,6 +71,7 @@ export const getServerValue = (key?: ServerKey, def?: ServerValue["value"], opti
70
71
  }
71
72
 
72
73
  export const setServerValue = (key: ServerKey, value: ServerValue["value"], options?: ServerValue["options"]) => {
74
+ // console.log("KKK>>", key)
73
75
  const ident = getIdent(key)
74
76
  serverStates.set(ident, { options, value: !options?.source ? value : undefined, key })
75
77
  return createDataProxy(value, `${ident}@`)
@@ -3,10 +3,10 @@ import { createContext, DependencyList, ReactNode } from "react"
3
3
  export interface JinraiProps {
4
4
  deps?: DependencyList
5
5
  children?: ReactNode
6
- search: string
6
+ search?: string
7
+ debug?: string
7
8
  }
8
9
  export const JinraiContext = createContext<JinraiProps>({
9
10
  deps: [],
10
11
  children: undefined,
11
- search: ""
12
12
  })
@@ -0,0 +1,12 @@
1
+ import { ReactNode } from "react"
2
+ import { ssr } from "../server-state/SSR"
3
+
4
+ interface props {
5
+ children: ReactNode,
6
+ }
7
+
8
+ export const JinraiDebug = (props: props) => {
9
+ ssr.current = true
10
+
11
+ return props.children
12
+ }
@@ -9,7 +9,8 @@ describe("test custom component", async () => {
9
9
 
10
10
  it("parse custom.html", async () => {
11
11
  const html = await readFile("./tests/parse/content/custom.html", "utf-8")
12
- // expect(JSON.stringify(parsr.parse(html))).toEqual("")
12
+ const result = parsr.parse(html)
13
+ // expect(JSON.stringify(result)).toEqual("")
13
14
 
14
15
  expect(parsr.parse(html)).toEqual(custom)
15
16
  })