@dooboostore/simple-boot-http-server-ssr 1.0.12 → 1.0.13
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/cjs/filters/SSRFilter.js +1 -1
- package/dist/cjs/filters/SSRFilter.js.map +2 -2
- package/dist/cjs/filters/SSRLinkDomDomFilter.js +183 -0
- package/dist/cjs/filters/SSRLinkDomDomFilter.js.map +7 -0
- package/dist/cjs/initializers/LinkedomInitializer.js +81 -0
- package/dist/cjs/initializers/LinkedomInitializer.js.map +7 -0
- package/dist/esm/filters/SSRFilter.js +1 -1
- package/dist/esm/filters/SSRFilter.js.map +2 -2
- package/dist/esm/filters/SSRLinkDomDomFilter.js +160 -0
- package/dist/esm/filters/SSRLinkDomDomFilter.js.map +7 -0
- package/dist/esm/initializers/LinkedomInitializer.js +48 -0
- package/dist/esm/initializers/LinkedomInitializer.js.map +7 -0
- package/dist/esm-bundle/dooboostore-simple-boot-http-server-ssr.esm.js +681 -242
- package/dist/esm-bundle/dooboostore-simple-boot-http-server-ssr.esm.js.map +4 -4
- package/dist/types/filters/SSRLinkDomDomFilter.d.ts +57 -0
- package/dist/types/filters/SSRLinkDomDomFilter.d.ts.map +1 -0
- package/dist/types/index.d.ts +0 -19
- package/dist/types/initializers/LinkedomInitializer.d.ts +11 -0
- package/dist/types/initializers/LinkedomInitializer.d.ts.map +1 -0
- package/dist/umd-bundle/dooboostore-simple-boot-http-server-ssr.umd.js +681 -242
- package/dist/umd-bundle/dooboostore-simple-boot-http-server-ssr.umd.js.map +4 -4
- package/package.json +15 -14
- package/src/filters/SSRFilter.ts +2 -2
- package/src/filters/SSRLinkDomDomFilter.ts +227 -0
- package/src/initializers/LinkedomInitializer.ts +69 -0
- package/src/node_modules/.bin/acorn +17 -0
- package/src/node_modules/.bin/browserslist +17 -0
- package/src/node_modules/.bin/eslint +17 -0
- package/src/node_modules/.bin/jest +17 -0
- package/src/node_modules/.bin/ts-jest +17 -0
- package/src/node_modules/.bin/ts-node +17 -0
- package/src/node_modules/.bin/ts-node-cwd +17 -0
- package/src/node_modules/.bin/ts-node-esm +17 -0
- package/src/node_modules/.bin/ts-node-script +17 -0
- package/src/node_modules/.bin/ts-node-transpile-only +17 -0
- package/src/node_modules/.bin/ts-script +17 -0
- package/src/node_modules/.bin/tsc +17 -0
- package/src/node_modules/.bin/tsserver +17 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { HttpHeaders } from "@dooboostore/simple-boot-http-server/codes/HttpHeaders";
|
|
2
|
+
import { Mimes } from "@dooboostore/simple-boot-http-server/codes/Mimes";
|
|
3
|
+
import { HttpStatus } from "@dooboostore/simple-boot-http-server/codes/HttpStatus";
|
|
4
|
+
import { AsyncBlockingQueue } from "@dooboostore/core/queues/AsyncBlockingQueue";
|
|
5
|
+
import { RandomUtils } from "@dooboostore/core/random/RandomUtils";
|
|
6
|
+
import { NotFoundError } from "@dooboostore/simple-boot-http-server/errors/NotFoundError";
|
|
7
|
+
import { DomRenderProxy } from "@dooboostore/dom-render/DomRenderProxy";
|
|
8
|
+
import { filter } from "@dooboostore/core/message/operators/filter";
|
|
9
|
+
import { first } from "@dooboostore/core/message/operators/first";
|
|
10
|
+
import { firstValueFrom } from "@dooboostore/core/message/internal/firstValueFrom";
|
|
11
|
+
import { LinkedomInitializer } from "../initializers/LinkedomInitializer.js";
|
|
12
|
+
class SSRLinkDomDomFilter {
|
|
13
|
+
constructor(config, otherInstanceSim) {
|
|
14
|
+
this.config = config;
|
|
15
|
+
this.otherInstanceSim = otherInstanceSim;
|
|
16
|
+
this.simpleBootFrontPool = [];
|
|
17
|
+
this.simpleBootFrontQueue = new AsyncBlockingQueue();
|
|
18
|
+
// private indexHTML: string;
|
|
19
|
+
this.welcomUrl = "http://localhost";
|
|
20
|
+
this.poolGeneration = 0;
|
|
21
|
+
config.frontDistIndexFileName = config.frontDistIndexFileName || "index.html";
|
|
22
|
+
}
|
|
23
|
+
async onInit(app) {
|
|
24
|
+
for (let i = 0; i < this.config.poolOption.min; i++) {
|
|
25
|
+
await this.pushQueue();
|
|
26
|
+
}
|
|
27
|
+
if (this.config.poolOption.clearIntervalTime && this.config.poolOption.clearIntervalTime > 0) {
|
|
28
|
+
this.intervalId = setInterval(() => {
|
|
29
|
+
this.poolGeneration++;
|
|
30
|
+
}, this.config.poolOption.clearIntervalTime);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async onDestroy() {
|
|
34
|
+
if (this.intervalId) {
|
|
35
|
+
clearInterval(this.intervalId);
|
|
36
|
+
}
|
|
37
|
+
this.simpleBootFrontPool.forEach((front) => {
|
|
38
|
+
front.jsdom?.window.close();
|
|
39
|
+
});
|
|
40
|
+
this.simpleBootFrontPool = [];
|
|
41
|
+
}
|
|
42
|
+
async makePage() {
|
|
43
|
+
return new LinkedomInitializer(
|
|
44
|
+
this.config.frontDistPath,
|
|
45
|
+
this.config.frontDistIndexFileName || "index.html",
|
|
46
|
+
{ url: this.welcomUrl }
|
|
47
|
+
).run();
|
|
48
|
+
}
|
|
49
|
+
async makeFront(window) {
|
|
50
|
+
const name = RandomUtils.uuid();
|
|
51
|
+
window.ssrUse = false;
|
|
52
|
+
const option = this.config.factorySimFrontOption(DomRenderProxy.final(window));
|
|
53
|
+
const simpleBootFront = await this.config.factory.create(option, this.config.using, this.config.domExcludes);
|
|
54
|
+
simpleBootFront.run(this.otherInstanceSim);
|
|
55
|
+
simpleBootFront.generation = this.poolGeneration;
|
|
56
|
+
return simpleBootFront;
|
|
57
|
+
}
|
|
58
|
+
enqueueFrontApp(simpleBootFront) {
|
|
59
|
+
this.simpleBootFrontPool.push(simpleBootFront);
|
|
60
|
+
this.simpleBootFrontQueue.enqueue(simpleBootFront);
|
|
61
|
+
}
|
|
62
|
+
async pushQueue() {
|
|
63
|
+
if (this.simpleBootFrontPool.length < this.config.poolOption.max) {
|
|
64
|
+
this.enqueueFrontApp(await this.makeFront(await this.makePage()));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async proceedBefore({ rr, app }) {
|
|
68
|
+
if (this.config.ssrExcludeFilter?.(rr)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {
|
|
72
|
+
if (this.simpleBootFrontQueue.isEmpty()) {
|
|
73
|
+
await this.pushQueue();
|
|
74
|
+
}
|
|
75
|
+
const simpleBootFront = await this.simpleBootFrontQueue.dequeue();
|
|
76
|
+
try {
|
|
77
|
+
simpleBootFront.option.window.ssrUse = true;
|
|
78
|
+
delete simpleBootFront.option.window.server_side_data;
|
|
79
|
+
const url = rr.reqUrlObj({ host: "localhost" });
|
|
80
|
+
if (this.config.simpleBootFront?.notFoundError) {
|
|
81
|
+
const intent = await simpleBootFront.getIntent(url.pathname);
|
|
82
|
+
if (intent.module === void 0 && !intent.getRouterPathData(rr.reqUrlPathName)) {
|
|
83
|
+
throw new NotFoundError({ message: `Not Found: ${rr.reqUrlPathName}` });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const targetUrl = url.toString();
|
|
87
|
+
await simpleBootFront.goRouting(targetUrl);
|
|
88
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
89
|
+
const data = await firstValueFrom(
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
simpleBootFront.routingSubjectObservable.pipe(
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
filter(
|
|
94
|
+
(it) => it.triggerPoint === "end" && typeof it.routerModule.intent.uri === "string" && targetUrl.endsWith(it.routerModule.intent.uri)
|
|
95
|
+
),
|
|
96
|
+
// delay(1000),
|
|
97
|
+
first()
|
|
98
|
+
)
|
|
99
|
+
);
|
|
100
|
+
const html = this.makeHTML(simpleBootFront);
|
|
101
|
+
await this.writeOkHtmlAndEnd({ rr }, html);
|
|
102
|
+
} finally {
|
|
103
|
+
simpleBootFront.option.window.ssrUse = false;
|
|
104
|
+
delete simpleBootFront.option.window.server_side_data;
|
|
105
|
+
if (simpleBootFront.generation < this.poolGeneration) {
|
|
106
|
+
const jsdom = simpleBootFront.jsdom;
|
|
107
|
+
jsdom?.window.close();
|
|
108
|
+
const index = this.simpleBootFrontPool.indexOf(simpleBootFront);
|
|
109
|
+
if (index > -1) {
|
|
110
|
+
this.simpleBootFrontPool.splice(index, 1);
|
|
111
|
+
}
|
|
112
|
+
this.pushQueue();
|
|
113
|
+
} else {
|
|
114
|
+
this.simpleBootFrontQueue.enqueue(simpleBootFront);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
} else {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
makeHTML(simpleBootFront) {
|
|
123
|
+
simpleBootFront.option.window.document.querySelectorAll("*").forEach((el) => {
|
|
124
|
+
Array.from(el.attributes).forEach((attr) => {
|
|
125
|
+
if (/^dr-/.test(attr.name) || /^domstyle/.test(attr.name) || /this-path/.test(attr.name)) {
|
|
126
|
+
el.removeAttribute(attr.name);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
let html = simpleBootFront.option.window.document.documentElement.outerHTML;
|
|
131
|
+
html = "<!DOCTYPE html>" + html;
|
|
132
|
+
html = html.replace(/\$\{[\s\S]*?\}\$/g, "");
|
|
133
|
+
const serverSideData = simpleBootFront.option.window.server_side_data;
|
|
134
|
+
if (serverSideData) {
|
|
135
|
+
const data = Object.entries(serverSideData).map(([k, v]) => {
|
|
136
|
+
if (typeof v === "string") {
|
|
137
|
+
return `window.server_side_data.${k} = ${v}`;
|
|
138
|
+
} else {
|
|
139
|
+
return `window.server_side_data.${k} = ${JSON.stringify(v)}`;
|
|
140
|
+
}
|
|
141
|
+
}).join(";");
|
|
142
|
+
if (data) {
|
|
143
|
+
html = html.replace("</head>", `<script> window.server_side_data={}; ${data}; </script></head>`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return html;
|
|
147
|
+
}
|
|
148
|
+
async writeOkHtmlAndEnd({ rr, status = HttpStatus.Ok }, html) {
|
|
149
|
+
rr.resStatusCode(status);
|
|
150
|
+
rr.resSetHeader(HttpHeaders.ContentType, Mimes.TextHtml);
|
|
151
|
+
await rr.resEnd(html);
|
|
152
|
+
}
|
|
153
|
+
async proceedAfter({ rr, app }) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export {
|
|
158
|
+
SSRLinkDomDomFilter
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=SSRLinkDomDomFilter.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/filters/SSRLinkDomDomFilter.ts"],
|
|
4
|
+
"sourcesContent": ["import { RequestResponse } from '@dooboostore/simple-boot-http-server/models/RequestResponse';\nimport { HttpHeaders } from '@dooboostore/simple-boot-http-server/codes/HttpHeaders';\nimport { SimpleBootHttpSSRFactory } from '../SimpleBootHttpSSRFactory';\nimport { ConstructorType } from '@dooboostore/core/types';\nimport { JsdomInitializer } from '../initializers/JsdomInitializer';\nimport { Filter } from '@dooboostore/simple-boot-http-server/filters/Filter';\nimport { Mimes } from '@dooboostore/simple-boot-http-server/codes/Mimes';\nimport { HttpStatus } from '@dooboostore/simple-boot-http-server/codes/HttpStatus';\nimport { SimpleBootHttpServer } from '@dooboostore/simple-boot-http-server/SimpleBootHttpServer';\nimport { SimFrontOption } from '@dooboostore/simple-boot-front/option/SimFrontOption';\nimport { SimpleBootFront } from '@dooboostore/simple-boot-front/SimpleBootFront';\nimport { AsyncBlockingQueue } from '@dooboostore/core/queues/AsyncBlockingQueue';\nimport { RandomUtils } from '@dooboostore/core/random/RandomUtils';\nimport * as JSDOM from 'jsdom';\nimport { NotFoundError } from '@dooboostore/simple-boot-http-server/errors/NotFoundError';\nimport { DomRenderProxy } from '@dooboostore/dom-render/DomRenderProxy';\nimport { filter } from '@dooboostore/core/message/operators/filter';\nimport { first } from '@dooboostore/core/message/operators/first';\nimport { firstValueFrom } from '@dooboostore/core/message/internal/firstValueFrom';\nimport { parseHTML } from 'linkedom';\nimport { LinkedomInitializer } from '../initializers/LinkedomInitializer';\n\nexport type FactoryAndParams = {\n frontDistPath: string;\n frontDistIndexFileName?: string;\n factorySimFrontOption: (window: any) => SimFrontOption;\n factory: SimpleBootHttpSSRFactory;\n poolOption: {\n max: number;\n min: number;\n clearIntervalTime?: number;\n };\n using: ConstructorType<any>[];\n domExcludes?: ConstructorType<any>[];\n ssrExcludeFilter?: (rr: RequestResponse) => boolean;\n simpleBootFront?: {\n notFoundError?: boolean;\n };\n};\n\nexport class SSRLinkDomDomFilter implements Filter {\n private simpleBootFrontPool: SimpleBootFront[] = [];\n private simpleBootFrontQueue = new AsyncBlockingQueue<SimpleBootFront>();\n // private indexHTML: string;\n private welcomUrl = 'http://localhost';\n private poolGeneration = 0;\n private intervalId?: NodeJS.Timeout;\n\n constructor(\n public config: FactoryAndParams,\n public otherInstanceSim?: Map<ConstructorType<any>, any>\n ) {\n config.frontDistIndexFileName = config.frontDistIndexFileName || 'index.html';\n // this.indexHTML = JsdomInitializer.loadFile(this.config.frontDistPath, config.frontDistIndexFileName);\n }\n\n async onInit(app: SimpleBootHttpServer) {\n for (let i = 0; i < this.config.poolOption.min; i++) {\n await this.pushQueue();\n }\n\n if (this.config.poolOption.clearIntervalTime && this.config.poolOption.clearIntervalTime > 0) {\n this.intervalId = setInterval(() => {\n this.poolGeneration++;\n }, this.config.poolOption.clearIntervalTime);\n }\n }\n\n async onDestroy() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n // this.simpleBootFrontQueue.clear();\n this.simpleBootFrontPool.forEach(front => {\n (front as any).jsdom?.window.close();\n });\n this.simpleBootFrontPool = [];\n }\n\n async makePage() {\n return new LinkedomInitializer(\n this.config.frontDistPath,\n this.config.frontDistIndexFileName || 'index.html',\n { url: this.welcomUrl }\n ).run();\n // const jsdom = await new JsdomInitializer(\n // this.config.frontDistPath,\n // this.config.frontDistIndexFileName || 'index.html',\n // { url: this.welcomUrl }\n // ).run();\n // return jsdom;\n }\n\n async makeFront(window: Window) {\n const name = RandomUtils.uuid();\n (window as any).ssrUse = false;\n const option = this.config.factorySimFrontOption(DomRenderProxy.final(window));\n const simpleBootFront = await this.config.factory.create(option, this.config.using, this.config.domExcludes);\n simpleBootFront.run(this.otherInstanceSim);\n (simpleBootFront as any).generation = this.poolGeneration;\n return simpleBootFront;\n }\n\n enqueueFrontApp(simpleBootFront: SimpleBootFront) {\n // this.simpleBootFrontPool.set(simpleBootFront.option.name!, simpleBootFront);\n this.simpleBootFrontPool.push(simpleBootFront);\n this.simpleBootFrontQueue.enqueue(simpleBootFront);\n }\n async pushQueue() {\n if (this.simpleBootFrontPool.length < this.config.poolOption.max) {\n this.enqueueFrontApp(await this.makeFront(await this.makePage()));\n }\n }\n\n async proceedBefore({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n if (this.config.ssrExcludeFilter?.(rr)) {\n return false;\n }\n if (rr.reqHasAcceptHeader(Mimes.TextHtml) || rr.reqHasAcceptHeader(Mimes.All)) {\n if (this.simpleBootFrontQueue.isEmpty()) {\n await this.pushQueue();\n }\n const simpleBootFront = await this.simpleBootFrontQueue.dequeue();\n try {\n (simpleBootFront.option.window as any).ssrUse = true;\n delete (simpleBootFront.option.window as any).server_side_data;\n const url = rr.reqUrlObj({ host: 'localhost' });\n if (this.config.simpleBootFront?.notFoundError) {\n // intent router check first\n const intent = await simpleBootFront.getIntent(url.pathname);\n // route\uB97C \uBABB\uCC3E\uC740\uC0C1\uD0DC\uC5D0\uC11C router path\uAE4C\uC9C0 \uC548\uB9DE\uC73C\uBA74 404 \uCC98\uB9AC\uD55C\uB2E4. route\uB791 router\uB791 \uB2E4\uB974\uB2C8\uAE50 \uD5DB\uAC08\uB9AC\uC9C0\uB9D0\uB3C4\uB85D\n if (intent.module === undefined && !intent.getRouterPathData(rr.reqUrlPathName)) {\n throw new NotFoundError({ message: `Not Found: ${rr.reqUrlPathName}` });\n }\n }\n\n // runRouting!!\n const targetUrl = url.toString();\n await simpleBootFront.goRouting(targetUrl);\n await new Promise(r => setTimeout(r, 0)); // <--\uC911\uC694: \uC774\uAC70 \uB123\uC5B4\uC57C\uC9C0 \uB450\uBC88\uBD88\uB7EC\uC9C0\uB294\uAC8C \uC5C6\uC5B4\uC9C0\uB294\uB4EF? \uBB50\uC9C0 event loop \uBCC0\uACBD\uB41C\uAC74\uAC00?\n\n\n // simpleBootFront.routingSubjectObservable.subscribe(it=>{\n // console.log('zzzzzzzzzzzzzzzzzzz', it);\n // if (it.triggerPoint==='end') {\n // console.log('zzz@@', it.routerModule.intent);\n // }\n // })\n\n const data = await firstValueFrom(\n // @ts-ignore\n simpleBootFront.routingSubjectObservable.pipe(\n // @ts-ignore\n filter(\n (it) =>\n it.triggerPoint === 'end' &&\n typeof it.routerModule.intent.uri === 'string' &&\n targetUrl.endsWith(it.routerModule.intent.uri)\n ),\n // delay(1000),\n first()\n )\n );\n // console.log('???????done');\n const html = this.makeHTML(simpleBootFront);\n await this.writeOkHtmlAndEnd({ rr }, html);\n } finally {\n (simpleBootFront.option.window as any).ssrUse = false;\n delete (simpleBootFront.option.window as any).server_side_data;\n if ((simpleBootFront as any).generation < this.poolGeneration) {\n // Stale instance, destroy it\n const jsdom = (simpleBootFront as any).jsdom as JSDOM.JSDOM | undefined;\n jsdom?.window.close();\n const index = this.simpleBootFrontPool.indexOf(simpleBootFront);\n if (index > -1) {\n this.simpleBootFrontPool.splice(index, 1);\n }\n this.pushQueue();\n } else {\n // Current instance, return to queue\n this.simpleBootFrontQueue.enqueue(simpleBootFront);\n }\n }\n return false;\n } else {\n return true;\n }\n }\n\n makeHTML(simpleBootFront: SimpleBootFront) {\n (simpleBootFront.option.window as any).document.querySelectorAll('*').forEach((el:HTMLElement )=> {\n Array.from(el.attributes).forEach(attr => {\n if (/^dr-/.test(attr.name) || /^domstyle/.test(attr.name) || /this-path/.test(attr.name)) {\n el.removeAttribute(attr.name);\n }\n });\n });\n let html = simpleBootFront.option.window.document.documentElement.outerHTML;\n html = '<!DOCTYPE html>' + html;\n html = html.replace(/\\$\\{[\\s\\S]*?\\}\\$/g, '');\n const serverSideData = (simpleBootFront.option.window as any).server_side_data;\n if (serverSideData) {\n const data = Object.entries(serverSideData)\n .map(([k, v]) => {\n if (typeof v === 'string') {\n return `window.server_side_data.${k} = ${v}`;\n } else {\n return `window.server_side_data.${k} = ${JSON.stringify(v)}`;\n }\n })\n .join(';');\n if (data) {\n html = html.replace('</head>', `<script> window.server_side_data={}; ${data}; </script></head>`);\n }\n }\n return html;\n }\n async writeOkHtmlAndEnd({ rr, status = HttpStatus.Ok }: { rr: RequestResponse; status?: HttpStatus }, html: string) {\n rr.resStatusCode(status);\n rr.resSetHeader(HttpHeaders.ContentType, Mimes.TextHtml);\n await rr.resEnd(html);\n }\n\n async proceedAfter({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n return true;\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,mBAAmB;AAK5B,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAI3B,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAE5B,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,aAAa;AACtB,SAAS,sBAAsB;AAE/B,SAAS,2BAA2B;AAoB7B,MAAM,oBAAsC;AAAA,EAQjD,YACS,QACA,kBACP;AAFO;AACA;AATT,SAAQ,sBAAyC,CAAC;AAClD,SAAQ,uBAAuB,IAAI,mBAAoC;AAEvE;AAAA,SAAQ,YAAY;AACpB,SAAQ,iBAAiB;AAOvB,WAAO,yBAAyB,OAAO,0BAA0B;AAAA,EAEnE;AAAA,EAEA,MAAM,OAAO,KAA2B;AACtC,aAAS,IAAI,GAAG,IAAI,KAAK,OAAO,WAAW,KAAK,KAA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wC,IAAI,oBAAoB;AAAA,MACjG;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EACA,MAAM,kBAAkB,EAAE,IAAI,SAAS,WAAW,GAAG,GAAiD,MAAc;AAClH,OAAG,cAAc,MAAM;AACvB,OAAG,aAAa,YAAY,aAAa,MAAM,QAAQ;AACvD,UAAM,GAAG,OAAO,IAAI;AAAA,EACtB;AAAA,EAEA,MAAM,aAAa,EAAE,IAAI,IAAI,GAAkF;AAC7G,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { parseHTML } from "linkedom";
|
|
4
|
+
class LinkedomInitializer {
|
|
5
|
+
constructor(frontDistPath, frontDistIndexFileName, reconfigureSettings) {
|
|
6
|
+
this.frontDistPath = frontDistPath;
|
|
7
|
+
this.frontDistIndexFileName = frontDistIndexFileName;
|
|
8
|
+
this.reconfigureSettings = reconfigureSettings;
|
|
9
|
+
}
|
|
10
|
+
static loadFile(distPath, filePath) {
|
|
11
|
+
return fs.readFileSync(path.join(distPath, filePath), "utf8");
|
|
12
|
+
}
|
|
13
|
+
async run() {
|
|
14
|
+
const pathStr = path.join(this.frontDistPath, this.frontDistIndexFileName);
|
|
15
|
+
const html = fs.readFileSync(pathStr, "utf8");
|
|
16
|
+
const w = parseHTML(html);
|
|
17
|
+
global.document = w.document;
|
|
18
|
+
global.window = w;
|
|
19
|
+
global.window.requestAnimationFrame = () => {
|
|
20
|
+
};
|
|
21
|
+
global.window.scrollTo = () => {
|
|
22
|
+
};
|
|
23
|
+
global.history = w.history;
|
|
24
|
+
global.Event = w.Event;
|
|
25
|
+
global.PopStateEvent = w.Event;
|
|
26
|
+
global.IntersectionObserver = w.IntersectionObserver;
|
|
27
|
+
global.NodeFilter = w.NodeFilter;
|
|
28
|
+
global.Node = w.Node;
|
|
29
|
+
global.DocumentFragment = w.DocumentFragment;
|
|
30
|
+
global.HTMLElement = w.HTMLElement;
|
|
31
|
+
global.HTMLMetaElement = w.HTMLMetaElement;
|
|
32
|
+
global.Element = w.Element;
|
|
33
|
+
global.HTMLCanvasElement = w.HTMLCanvasElement;
|
|
34
|
+
global.HTMLCanvasElement.prototype.getContext = () => {
|
|
35
|
+
return null;
|
|
36
|
+
};
|
|
37
|
+
global.CanvasRenderingContext2D = w.CanvasRenderingContext2D;
|
|
38
|
+
global.CanvasPattern = w.CanvasPattern;
|
|
39
|
+
global.CanvasGradient = w.CanvasGradient;
|
|
40
|
+
global.Path2D = w.Path2D;
|
|
41
|
+
global.ImageData = w.ImageData;
|
|
42
|
+
return w;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
LinkedomInitializer
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=LinkedomInitializer.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/initializers/LinkedomInitializer.ts"],
|
|
4
|
+
"sourcesContent": ["import fs from 'fs';\nimport path from 'path';\nimport { parseHTML } from 'linkedom';\n\nexport class LinkedomInitializer {\n constructor(\n private frontDistPath: string,\n private frontDistIndexFileName: string,\n private reconfigureSettings?: {url: string}\n ) {}\n\n public static loadFile(distPath: string, filePath: string): string {\n return fs.readFileSync(path.join(distPath, filePath), 'utf8');\n }\n\n async run(): Promise<Window> {\n // const indexHTML = fs.readFileSync(path.join(this.frontDistPath, 'index.html'), 'utf8');\n // const indexHTML = JsdomInitializer.loadFile(this.frontDistPath, this.frontDistIndexFileName);\n const pathStr = path.join(this.frontDistPath, this.frontDistIndexFileName);\n\n const html = fs.readFileSync(pathStr,'utf8');\n\n const w = parseHTML(html);\n // @ts-ignore\n // w.location ??= { href: 'about:blank'};\n // if(this.reconfigureSettings?.url){\n // console.log('--',w,w.location);\n // @ts-ignore\n // w.location.href = this.reconfigureSettings.url;\n // }\n // console.log('!!!!!!!!!!!', html, w.document);\n // @ts-ignore\n global.document = w.document;\n // @ts-ignore\n global.window = w as unknown as Window & typeof globalThis;\n // @ts-ignore\n global.window.requestAnimationFrame = () => {};\n global.window.scrollTo = () => {};\n // @ts-ignore\n global.history = w.history;\n global.Event = w.Event;\n // @ts-ignore\n global.PopStateEvent = w.Event;\n global.IntersectionObserver = w.IntersectionObserver;\n // @ts-ignore\n // global.Error = ErrorBase;\n // @ts-ignore\n // global.navigator = w.navigator;\n global.NodeFilter = w.NodeFilter;\n global.Node = w.Node;\n global.DocumentFragment = w.DocumentFragment;\n global.HTMLElement = w.HTMLElement;\n global.HTMLMetaElement = w.HTMLMetaElement;\n global.Element = w.Element;\n global.HTMLCanvasElement = w.HTMLCanvasElement;\n global.HTMLCanvasElement.prototype.getContext = () => {\n return null;\n };\n global.CanvasRenderingContext2D = w.CanvasRenderingContext2D;\n global.CanvasPattern = w.CanvasPattern;\n global.CanvasGradient = w.CanvasGradient;\n global.Path2D = w.Path2D;\n global.ImageData = w.ImageData;\n // console.log('cvvvvvvvvvvvvvv', w.Node.DOCUMENT_FRAGMENT_NODE);\n return w;\n }\n}\n//\n// export default new JsdomInitializer();\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,iBAAiB;AAEnB,MAAM,oBAAoB;AAAA,EAC/B,YACU,eACA,wBACA,qBACR;AAHQ;AACA;AACA;AAAA,EACP;AAAA,EAEH,OAAc,SAAS,UAAkB,UAA0B;AACjE,WAAO,GAAG,aAAa,KAAK,KAAK,UAAU,QAAQ,GAAG,MAAM;AAAA,EAC9D;AAAA,EAEA,MAAM,MAAuB;AAG3B,UAAM,UAAU,KAAK,KAAK,KAAK,eAAe,KAAK,sBAAsB;AAEzE,UAAM,OAAO,GAAG,aAAa,SAAQ,MAAM;AAE3C,UAAM,IAAI,UAAU,IAAI;AAUxB,WAAO,WAAW,EAAE;AAEpB,WAAO,SAAS;AAEhB,WAAO,OAAO,wBAAwB,MAAM;AAAA,IAAC;AAC7C,WAAO,OAAO,WAAW,MAAM;AAAA,IAAC;AAEhC,WAAO,UAAU,EAAE;AACnB,WAAO,QAAQ,EAAE;AAEjB,WAAO,gBAAgB,EAAE;AACzB,WAAO,uBAAuB,EAAE;AAKhC,WAAO,aAAa,EAAE;AACtB,WAAO,OAAO,EAAE;AAChB,WAAO,mBAAmB,EAAE;AAC5B,WAAO,cAAc,EAAE;AACvB,WAAO,kBAAkB,EAAE;AAC3B,WAAO,UAAU,EAAE;AACnB,WAAO,oBAAoB,EAAE;AAC7B,WAAO,kBAAkB,UAAU,aAAa,MAAM;AACpD,aAAO;AAAA,IACT;AACA,WAAO,2BAA2B,EAAE;AACpC,WAAO,gBAAgB,EAAE;AACzB,WAAO,iBAAiB,EAAE;AAC1B,WAAO,SAAS,EAAE;AAClB,WAAO,YAAY,EAAE;AAErB,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|