@lomray/vite-ssr-boost 1.0.0-beta.8 → 1.0.0
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/README.md +72 -12
- package/cli/build.d.ts +7 -5
- package/cli/build.js +1 -1
- package/cli/build.js.map +1 -1
- package/cli/helpers/keyboard-input.js +2 -0
- package/cli/helpers/keyboard-input.js.map +1 -0
- package/cli/helpers/vite-reset-cache.js.map +1 -0
- package/cli/run-docker-build.js +1 -1
- package/cli/run-docker-build.js.map +1 -1
- package/cli/run-prod.d.ts +2 -1
- package/cli/run-prod.js +1 -1
- package/cli/run-prod.js.map +1 -1
- package/cli.js +1 -1
- package/cli.js.map +1 -1
- package/components/scroll-to-top.d.ts +10 -0
- package/components/scroll-to-top.js +2 -0
- package/components/scroll-to-top.js.map +1 -0
- package/helpers/get-server-state.d.ts +5 -0
- package/helpers/get-server-state.js +2 -0
- package/helpers/get-server-state.js.map +1 -0
- package/helpers/import-route.d.ts +1 -1
- package/helpers/import-route.js +1 -1
- package/helpers/import-route.js.map +1 -1
- package/helpers/is-route-file.d.ts +5 -0
- package/helpers/is-route-file.js +2 -0
- package/helpers/is-route-file.js.map +1 -0
- package/helpers/process-stop.d.ts +1 -1
- package/helpers/process-stop.js +1 -1
- package/helpers/process-stop.js.map +1 -1
- package/helpers/vite-aliases.js +1 -1
- package/helpers/vite-aliases.js.map +1 -1
- package/interfaces/fc-route.d.ts +9 -0
- package/interfaces/fc-route.js.map +1 -1
- package/interfaces/route-object.d.ts +1 -1
- package/node/entry.d.ts +6 -1
- package/node/entry.js +1 -1
- package/node/entry.js.map +1 -1
- package/node/render.d.ts +3 -2
- package/node/render.js +1 -1
- package/node/render.js.map +1 -1
- package/node/server.js +1 -1
- package/node/server.js.map +1 -1
- package/package.json +3 -3
- package/plugin.d.ts +1 -2
- package/plugin.js +1 -1
- package/plugin.js.map +1 -1
- package/plugins/normalize-route.d.ts +9 -3
- package/plugins/normalize-route.js +1 -1
- package/plugins/normalize-route.js.map +1 -1
- package/services/build.d.ts +94 -0
- package/services/build.js +2 -0
- package/services/build.js.map +1 -0
- package/services/prepare-server.d.ts +4 -3
- package/services/prepare-server.js +1 -1
- package/services/prepare-server.js.map +1 -1
- package/services/server-config.d.ts +6 -10
- package/services/server-config.js +1 -1
- package/services/server-config.js.map +1 -1
- package/services/ssr-manifest.d.ts +207 -0
- package/services/ssr-manifest.js +2 -0
- package/services/ssr-manifest.js.map +1 -0
- package/workflow/Dockerfile +0 -1
- package/cli/keyboard-input.js +0 -2
- package/cli/keyboard-input.js.map +0 -1
- package/cli/vite-reset-cache.js.map +0 -1
- package/helpers/unlock-robots.d.ts +0 -5
- package/helpers/unlock-robots.js +0 -2
- package/helpers/unlock-robots.js.map +0 -1
- /package/cli/{keyboard-input.d.ts → helpers/keyboard-input.d.ts} +0 -0
- /package/cli/{vite-reset-cache.d.ts → helpers/vite-reset-cache.d.ts} +0 -0
- /package/cli/{vite-reset-cache.js → helpers/vite-reset-cache.js} +0 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Socket } from 'node:net';
|
|
3
|
+
import { AgnosticDataRouteMatch } from '@remix-run/router/dist/utils';
|
|
4
|
+
import { RouteObject } from 'react-router-dom';
|
|
5
|
+
import { Alias, ModuleNode } from 'vite';
|
|
6
|
+
import { IRequestContext } from "../node/render.js";
|
|
7
|
+
import ServerConfig from "./server-config.js";
|
|
8
|
+
interface ISsrManifestParams {
|
|
9
|
+
buildDir?: string;
|
|
10
|
+
viteAliases?: Alias[];
|
|
11
|
+
}
|
|
12
|
+
interface IManifest {
|
|
13
|
+
[path: string]: {
|
|
14
|
+
assets: string[];
|
|
15
|
+
css: string[];
|
|
16
|
+
file: string;
|
|
17
|
+
isEntry?: boolean;
|
|
18
|
+
imports: string[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
declare enum AssetType {
|
|
22
|
+
style = "style",
|
|
23
|
+
script = "script",
|
|
24
|
+
image = "image",
|
|
25
|
+
font = "font"
|
|
26
|
+
}
|
|
27
|
+
interface IAsset {
|
|
28
|
+
type: AssetType;
|
|
29
|
+
url: string;
|
|
30
|
+
weight: number;
|
|
31
|
+
isNested: boolean;
|
|
32
|
+
isPreload: boolean;
|
|
33
|
+
content?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Working with SSR Manifest file
|
|
37
|
+
*/
|
|
38
|
+
declare class SsrManifest {
|
|
39
|
+
/**
|
|
40
|
+
* Singleton
|
|
41
|
+
*/
|
|
42
|
+
protected static instance: SsrManifest | null;
|
|
43
|
+
/**
|
|
44
|
+
* Server config
|
|
45
|
+
*/
|
|
46
|
+
protected readonly config: ServerConfig;
|
|
47
|
+
/**
|
|
48
|
+
* Project root path
|
|
49
|
+
*/
|
|
50
|
+
protected readonly root: string;
|
|
51
|
+
/**
|
|
52
|
+
* Build dir
|
|
53
|
+
*/
|
|
54
|
+
protected readonly buildDir?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Client manifest file name
|
|
57
|
+
*/
|
|
58
|
+
protected readonly manifestName = "manifest.json";
|
|
59
|
+
/**
|
|
60
|
+
* Assets manifest file name
|
|
61
|
+
*/
|
|
62
|
+
protected readonly assetsManifest = "assets-manifest.json";
|
|
63
|
+
/**
|
|
64
|
+
* Vite resolve aliases
|
|
65
|
+
*/
|
|
66
|
+
protected readonly viteAliases?: Alias[];
|
|
67
|
+
/**
|
|
68
|
+
* Loaded assets manifest file
|
|
69
|
+
*/
|
|
70
|
+
protected routesAssets: Record<string, IAsset[]> | null;
|
|
71
|
+
/**
|
|
72
|
+
* @constructor
|
|
73
|
+
*/
|
|
74
|
+
/**
|
|
75
|
+
* @constructor
|
|
76
|
+
*/
|
|
77
|
+
protected constructor(config: ServerConfig, { buildDir, viteAliases }?: ISsrManifestParams);
|
|
78
|
+
/**
|
|
79
|
+
* Get singleton instance
|
|
80
|
+
*/
|
|
81
|
+
/**
|
|
82
|
+
* Get singleton instance
|
|
83
|
+
*/
|
|
84
|
+
static get(config: ServerConfig, params?: ISsrManifestParams): SsrManifest;
|
|
85
|
+
/**
|
|
86
|
+
* Get assets manifest file name
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* Get assets manifest file name
|
|
90
|
+
*/
|
|
91
|
+
protected getAssetsManifestFile(): string;
|
|
92
|
+
/**
|
|
93
|
+
* Load client ssr manifest
|
|
94
|
+
*/
|
|
95
|
+
/**
|
|
96
|
+
* Load client ssr manifest
|
|
97
|
+
*/
|
|
98
|
+
protected loadClientManifest(): IManifest;
|
|
99
|
+
/**
|
|
100
|
+
* Load assets manifest
|
|
101
|
+
*/
|
|
102
|
+
/**
|
|
103
|
+
* Load assets manifest
|
|
104
|
+
*/
|
|
105
|
+
protected loadAssetsManifest(): Record<string, IAsset[]>;
|
|
106
|
+
/**
|
|
107
|
+
* Recursive walk routes and return id's with route import path
|
|
108
|
+
*/
|
|
109
|
+
/**
|
|
110
|
+
* Recursive walk routes and return id's with route import path
|
|
111
|
+
*/
|
|
112
|
+
protected getRoutesIds(routes: RouteObject[], index?: string): Promise<Record<string, string>>;
|
|
113
|
+
/**
|
|
114
|
+
* Sort assets
|
|
115
|
+
*/
|
|
116
|
+
/**
|
|
117
|
+
* Sort assets
|
|
118
|
+
*/
|
|
119
|
+
protected sortAssets(assets: IAsset[]): IAsset[];
|
|
120
|
+
/**
|
|
121
|
+
* Get recursive module assets
|
|
122
|
+
*/
|
|
123
|
+
/**
|
|
124
|
+
* Get recursive module assets
|
|
125
|
+
*/
|
|
126
|
+
protected getRouteAssets(manifest: IManifest, module: IManifest[string], isNested?: boolean): Record<string, IAsset>;
|
|
127
|
+
/**
|
|
128
|
+
* Build routes manifest file
|
|
129
|
+
*/
|
|
130
|
+
/**
|
|
131
|
+
* Build routes manifest file
|
|
132
|
+
*/
|
|
133
|
+
buildRoutesManifest(): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Get vite aliases
|
|
136
|
+
*/
|
|
137
|
+
/**
|
|
138
|
+
* Get vite aliases
|
|
139
|
+
*/
|
|
140
|
+
protected getAliases(): Record<string, string>;
|
|
141
|
+
/**
|
|
142
|
+
* Return route postfix
|
|
143
|
+
*/
|
|
144
|
+
/**
|
|
145
|
+
* Return route postfix
|
|
146
|
+
*/
|
|
147
|
+
protected getRouteImportPostfix(): string[];
|
|
148
|
+
/**
|
|
149
|
+
* Normalized route path
|
|
150
|
+
*/
|
|
151
|
+
/**
|
|
152
|
+
* Normalized route path
|
|
153
|
+
*/
|
|
154
|
+
protected normalizeRoutePath(routePath?: string, withRoot?: boolean): string | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Get route assets
|
|
157
|
+
*/
|
|
158
|
+
/**
|
|
159
|
+
* Get route assets
|
|
160
|
+
*/
|
|
161
|
+
protected getAssets(routes?: AgnosticDataRouteMatch[]): IAsset[];
|
|
162
|
+
/**
|
|
163
|
+
* Get development route assets
|
|
164
|
+
*/
|
|
165
|
+
/**
|
|
166
|
+
* Get development route assets
|
|
167
|
+
*/
|
|
168
|
+
protected getAssetsDev(routes?: AgnosticDataRouteMatch[]): IAsset[];
|
|
169
|
+
/**
|
|
170
|
+
* Get module assets
|
|
171
|
+
*/
|
|
172
|
+
/**
|
|
173
|
+
* Get module assets
|
|
174
|
+
*/
|
|
175
|
+
protected getModuleAssets(module?: ModuleNode, isNested?: boolean): {
|
|
176
|
+
[id: string]: IAsset;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Get asset weight
|
|
180
|
+
*/
|
|
181
|
+
/**
|
|
182
|
+
* Get asset weight
|
|
183
|
+
*/
|
|
184
|
+
protected getAssetWeight(asset: string): number;
|
|
185
|
+
/**
|
|
186
|
+
* Get asset type
|
|
187
|
+
*/
|
|
188
|
+
/**
|
|
189
|
+
* Get asset type
|
|
190
|
+
*/
|
|
191
|
+
protected getAssetType(asset: string): AssetType | null;
|
|
192
|
+
/**
|
|
193
|
+
* Write 103 Early Hits header
|
|
194
|
+
*/
|
|
195
|
+
/**
|
|
196
|
+
* Write 103 Early Hits header
|
|
197
|
+
*/
|
|
198
|
+
writeEarlyHits(assets: IAsset[], socket: Socket): void;
|
|
199
|
+
/**
|
|
200
|
+
* Inject route assets to head html
|
|
201
|
+
*/
|
|
202
|
+
/**
|
|
203
|
+
* Inject route assets to head html
|
|
204
|
+
*/
|
|
205
|
+
injectAssets({ routerContext, html, res, hasEarlyHints }: IRequestContext): void;
|
|
206
|
+
}
|
|
207
|
+
export { SsrManifest as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import t from"node:fs";import e from"node:path";import s from"chalk";import i from"./prepare-server.js";import r from"./server-config.js";var o;!function(t){t.style="style",t.script="script",t.image="image",t.font="font"}(o||(o={}));const n="\r\n";class a{static instance=null;config;root;buildDir;manifestName="manifest.json";assetsManifest="assets-manifest.json";viteAliases;routesAssets=null;constructor(t,{buildDir:e,viteAliases:s}={}){this.config=t,this.root=t.getParams().root,this.buildDir=e,this.viteAliases=s??t.getVite()?.config?.resolve.alias}static get(t,e={}){return null===a.instance&&(a.instance=new a(t,e)),a.instance}getAssetsManifestFile(){return`${e.resolve(this.root,this.buildDir||"")}/server/${this.assetsManifest}`}loadClientManifest(){const s=e.resolve(this.root,`${this.buildDir||""}/client/${this.manifestName}`);if(!t.existsSync(s))return{};const i=JSON.parse(t.readFileSync(s,{encoding:"utf-8"}));return t.rmSync(s),i}loadAssetsManifest(){if(null!==this.routesAssets)return this.routesAssets;const e=this.getAssetsManifestFile();return t.existsSync(e)?(this.routesAssets=JSON.parse(t.readFileSync(e,{encoding:"utf-8"})),this.routesAssets):{}}async getRoutesIds(t,e){const i={};for(const r in t){const o=t[r],n=[e,r].filter(Boolean).join("-");if(o.lazy)try{const t=await o.lazy();i[n]=this.normalizeRoutePath(t?.pathId)}catch(t){console.error(s.red("Failed to load route:"),o.path,t)}else o.children&&Object.assign(i,await this.getRoutesIds(o.children,n))}return i}sortAssets(t){return t.sort(((t,e)=>t.weight===e.weight?Number(t.isNested)-Number(e.isNested):t.weight-e.weight))}getRouteAssets(t,e,s=!1){const i=[...e?.assets??[],...e?.css??[],e?.file].reduce(((t,i)=>{if(i){const r=this.getAssetType(i),o=e.isEntry&&e.file===i;r&&(t[i]={url:`/${i}`,weight:o?1.9:this.getAssetWeight(i),type:r,isNested:s,isPreload:!o})}return t}),{});return e?.imports?.length&&e.imports.forEach((e=>{const s=t[e];s&&Object.assign(i,this.getRouteAssets(t,s,!0))})),i}async buildRoutesManifest(){const e=i.init(r.init({isProd:!0})),s=this.loadClientManifest(),{routes:o}=await e.loadEntrypoint(!1),n=await this.getRoutesIds(o),a=this.getRouteImportPostfix(),l={};Object.entries(n).forEach((([t,e])=>{const i=a.find((t=>void 0!==s[`${e}${t}`])),r=s[`${e}${i||""}`];l[t]=this.sortAssets(Object.values(this.getRouteAssets(s,r)))})),t.writeFileSync(this.getAssetsManifestFile(),JSON.stringify(l,null,2),{encoding:"utf-8"})}getAliases(){const t={};return this.viteAliases?.forEach((({find:e,replacement:s})=>{"string"==typeof e&&(t[e]=s)})),t}getRouteImportPostfix(){return["","/index"].map((t=>["",".js",".ts",".tsx"].map((e=>`${t}${e}`)))).flat()}normalizeRoutePath(t,s=!1){if(!t)return;let i="";if(t.startsWith("./")||t.startsWith("../"))i=e.resolve(this.root,t);else{const e=this.getAliases(),[s]=t.split("/");e[s]&&(i=t.replace(s,e[s]))}return i=i.split(e.win32.sep).join(e.posix.sep),s?i:i.replace(this.root,"").replace(/^\/|\/$/g,"")}getAssets(t){if(this.config.getVite())return this.getAssetsDev(t);const e=t?.map((({route:t})=>t.id)).filter(Boolean)??[];if(!e.length)return[];const s=this.loadAssetsManifest();return this.sortAssets(e.map((t=>s[t])).flat().filter(Boolean))}getAssetsDev(t){const e=t?.map((({route:t})=>this.normalizeRoutePath(t?.pathId,!0))).filter(Boolean)??[];if(!e.length)return[];let s={};const i=this.getRouteImportPostfix();return[`${this.root}/${this.config.getPluginConfig()?.clientFile??"client.ts"}`,...e].forEach((t=>{for(const e of i){const i=this.config.getVite()?.moduleGraph.getModuleById(`${t}${e}`);if(i){s={...s,...this.getModuleAssets(i)};break}}})),Object.values(s)}getModuleAssets(t,e=!1){if(!t?.clientImportedModules.size)return{};let i={};return t.clientImportedModules.forEach((t=>{const{file:r,clientImportedModules:n,transformResult:a}=t,l=r?.split(".").at(-1);if(r&&l&&["css","scss"].includes(l)){const t=a?.code.match(/__vite__css\s+=\s+"(?<css>.+)"/)?.groups?.css;if(t)try{i[r]={type:o.style,url:r,weight:this.getAssetWeight(r),content:JSON.parse(`{"style": "${t}"}`).style,isNested:e,isPreload:!1}}catch(t){console.warn(s.yellowBright("Failed to parse style: ",r))}}else n.size&&(i={...i,...this.getModuleAssets(t,!0)})})),i}getAssetWeight(t){switch(this.getAssetType(t)){case"style":return 1;case"script":return 2;default:return 3}}getAssetType(t){const e=t.split(".").at(-1)?.toLowerCase();switch(e){case"css":case"scss":return o.style;case"js":return o.script;case"svg":case"jpg":case"jpeg":case"png":case"webp":case"gif":case"ico":return o.image;case"ttf":case"otf":case"woff":case"woff2":return o.font;default:return null}}writeEarlyHits(t,e){e.write(`HTTP/1.1 103 Early Hints${n}`),t.forEach((({type:t,url:s})=>{t&&["style","script"].includes(t)&&e.write(`Link: <${s}>; rel=preload; as=${t}${n}`)})),e.write(n)}injectAssets({routerContext:t,html:e,res:s,hasEarlyHints:i=!1}){const r=this.getAssets(t?.matches),o=r.map((({type:t,url:e,isPreload:s,content:i=""})=>{switch(t){case"style":return this.config.getVite()?`<style data-vite-dev-id="${e}">${i}</style>`:`<link rel="stylesheet" href="${e}">`;case"script":return s?this.config.isModulePreload?`<link rel="modulepreload" as="script" crossorigin href="${e}">`:null:`<script async type="module" crossorigin src="${e}"><\/script>`}return null})).filter(Boolean);e.header=e.header.replace("</head>",`${o.join("\n")}</head>`),i&&o.length&&s.socket&&this.writeEarlyHits(r,s.socket)}}export{a as default};
|
|
2
|
+
//# sourceMappingURL=ssr-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssr-manifest.js","sources":["../../src/services/ssr-manifest.ts"],"sourcesContent":["import fs from 'node:fs';\nimport type { Socket } from 'node:net';\nimport path from 'node:path';\nimport type { AgnosticDataRouteMatch } from '@remix-run/router/dist/utils';\nimport chalk from 'chalk';\nimport type { RouteObject } from 'react-router-dom';\nimport type { Alias, ModuleNode } from 'vite';\nimport type { IRequestContext } from '@node/render';\nimport PrepareServer from '@services/prepare-server';\nimport ServerConfig from '@services/server-config';\n\ninterface ISsrManifestParams {\n buildDir?: string;\n viteAliases?: Alias[];\n}\n\ninterface IManifest {\n [path: string]: {\n assets: string[];\n css: string[];\n file: string;\n isEntry?: boolean;\n imports: string[];\n };\n}\n\nenum AssetType {\n style = 'style',\n script = 'script',\n image = 'image',\n font = 'font',\n}\n\ninterface IAsset {\n type: AssetType;\n url: string;\n weight: number;\n isNested: boolean;\n isPreload: boolean;\n content?: string;\n}\n\nconst CRLF = '\\r\\n';\n\n/**\n * Working with SSR Manifest file\n */\nclass SsrManifest {\n /**\n * Singleton\n */\n protected static instance: SsrManifest | null = null;\n\n /**\n * Server config\n */\n protected readonly config: ServerConfig;\n\n /**\n * Project root path\n */\n protected readonly root: string;\n\n /**\n * Build dir\n */\n protected readonly buildDir?: string;\n\n /**\n * Client manifest file name\n */\n protected readonly manifestName = 'manifest.json';\n\n /**\n * Assets manifest file name\n */\n protected readonly assetsManifest = 'assets-manifest.json';\n\n /**\n * Vite resolve aliases\n */\n protected readonly viteAliases?: Alias[];\n\n /**\n * Loaded assets manifest file\n */\n protected routesAssets: Record<string, IAsset[]> | null = null;\n\n /**\n * @constructor\n */\n protected constructor(config: ServerConfig, { buildDir, viteAliases }: ISsrManifestParams = {}) {\n this.config = config;\n this.root = config.getParams().root;\n this.buildDir = buildDir;\n this.viteAliases = viteAliases ?? config.getVite()?.config?.resolve.alias;\n }\n\n /**\n * Get singleton instance\n */\n public static get(config: ServerConfig, params: ISsrManifestParams = {}): SsrManifest {\n if (SsrManifest.instance === null) {\n SsrManifest.instance = new SsrManifest(config, params);\n }\n\n return SsrManifest.instance;\n }\n\n /**\n * Get assets manifest file name\n */\n protected getAssetsManifestFile(): string {\n const outDir = path.resolve(this.root, this.buildDir || '');\n\n return `${outDir}/server/${this.assetsManifest}`;\n }\n\n /**\n * Load client ssr manifest\n */\n protected loadClientManifest(): IManifest {\n const clientSsrManifest = path.resolve(\n this.root,\n `${this.buildDir || ''}/client/${this.manifestName}`,\n );\n\n if (!fs.existsSync(clientSsrManifest)) {\n return {};\n }\n\n const result = JSON.parse(\n fs.readFileSync(clientSsrManifest, { encoding: 'utf-8' }),\n ) as IManifest;\n\n fs.rmSync(clientSsrManifest);\n\n return result;\n }\n\n /**\n * Load assets manifest\n */\n protected loadAssetsManifest(): Record<string, IAsset[]> {\n if (this.routesAssets !== null) {\n return this.routesAssets;\n }\n\n const manifestFile = this.getAssetsManifestFile();\n\n if (!fs.existsSync(manifestFile)) {\n return {};\n }\n\n this.routesAssets = JSON.parse(fs.readFileSync(manifestFile, { encoding: 'utf-8' })) as Record<\n string,\n IAsset[]\n >;\n\n return this.routesAssets;\n }\n\n /**\n * Recursive walk routes and return id's with route import path\n */\n protected async getRoutesIds(\n routes: RouteObject[],\n index?: string,\n ): Promise<Record<string, string>> {\n const result = {};\n\n for (const routeIndex in routes) {\n const route = routes[routeIndex];\n const routeId = [index, routeIndex].filter(Boolean).join('-');\n\n if (route.lazy) {\n try {\n const resolvedRoute = await route.lazy();\n\n result[routeId] = this.normalizeRoutePath(resolvedRoute?.['pathId'] as string);\n } catch (e) {\n console.error(chalk.red('Failed to load route:'), route.path, e);\n }\n } else if (route.children) {\n Object.assign(result, await this.getRoutesIds(route.children, routeId));\n }\n }\n\n return result;\n }\n\n /**\n * Sort assets\n */\n protected sortAssets(assets: IAsset[]): IAsset[] {\n return assets.sort((a, b) =>\n a.weight === b.weight ? Number(a.isNested) - Number(b.isNested) : a.weight - b.weight,\n );\n }\n\n /**\n * Get recursive module assets\n */\n protected getRouteAssets(\n manifest: IManifest,\n module: IManifest[string],\n isNested = false,\n ): Record<string, IAsset> {\n const rootAssets = [...(module?.assets ?? []), ...(module?.css ?? []), module?.file];\n\n const assets = rootAssets.reduce((res, asset) => {\n if (asset) {\n const type = this.getAssetType(asset);\n const isEntry = module.isEntry && module.file === asset;\n\n // keep only js,css,image,fonts files\n if (type) {\n res[asset] = {\n url: `/${asset}`,\n weight: isEntry ? 1.9 : this.getAssetWeight(asset),\n type,\n isNested,\n isPreload: !isEntry,\n };\n }\n }\n\n return res;\n }, {} as Record<string, IAsset>);\n\n // nested assets\n if (module?.imports?.length) {\n module.imports.forEach((nestedAsset) => {\n const nestedModule = manifest[nestedAsset];\n\n if (nestedModule) {\n Object.assign(assets, this.getRouteAssets(manifest, nestedModule, true));\n }\n });\n }\n\n return assets;\n }\n\n /**\n * Build routes manifest file\n */\n public async buildRoutesManifest(): Promise<void> {\n const prepareServer = PrepareServer.init(ServerConfig.init({ isProd: true }));\n const manifest = this.loadClientManifest();\n const { routes } = await prepareServer.loadEntrypoint(false);\n const routesPaths = await this.getRoutesIds(routes as RouteObject[]);\n const postfixes = this.getRouteImportPostfix();\n\n const result = {};\n\n // find route assets\n Object.entries(routesPaths).forEach(([routeId, routePath]) => {\n const routePostfix = postfixes.find((postfix) => {\n const filePath = `${routePath}${postfix}`;\n\n return manifest[filePath] !== undefined;\n });\n const routeFile = `${routePath}${routePostfix || ''}`;\n const routeMeta = manifest[routeFile];\n\n result[routeId] = this.sortAssets(Object.values(this.getRouteAssets(manifest, routeMeta)));\n });\n\n fs.writeFileSync(this.getAssetsManifestFile(), JSON.stringify(result, null, 2), {\n encoding: 'utf-8',\n });\n }\n\n /**\n * Get vite aliases\n */\n protected getAliases(): Record<string, string> {\n const aliases = {};\n\n this.viteAliases?.forEach(({ find, replacement }) => {\n if (typeof find !== 'string') {\n return;\n }\n\n aliases[find] = replacement;\n });\n\n return aliases;\n }\n\n /**\n * Return route postfix\n */\n protected getRouteImportPostfix(): string[] {\n return ['', '/index']\n .map((prefix) => ['', '.js', '.ts', '.tsx'].map((ext) => `${prefix}${ext}`))\n .flat();\n }\n\n /**\n * Normalized route path\n */\n protected normalizeRoutePath(routePath?: string, withRoot = false): string | undefined {\n if (!routePath) {\n return;\n }\n\n let fullPath = '';\n\n // relative import\n if (routePath.startsWith('./') || routePath.startsWith('../')) {\n fullPath = path.resolve(this.root, routePath);\n } else {\n // alias import\n const aliases = this.getAliases();\n // get alias\n const [routeAlias] = routePath.split('/');\n\n if (aliases[routeAlias]) {\n fullPath = routePath.replace(routeAlias, aliases[routeAlias]);\n }\n }\n\n // normalize slashes\n fullPath = fullPath.split(path.win32.sep).join(path.posix.sep);\n\n if (withRoot) {\n return fullPath;\n }\n\n return fullPath.replace(this.root, '').replace(/^\\/|\\/$/g, '');\n }\n\n /**\n * Get route assets\n */\n protected getAssets(routes?: AgnosticDataRouteMatch[]): IAsset[] {\n if (this.config.getVite()) {\n return this.getAssetsDev(routes);\n }\n\n const routeIds = routes?.map(({ route }) => route.id).filter(Boolean) ?? [];\n\n if (!routeIds.length) {\n return [];\n }\n\n const routesAssets = this.loadAssetsManifest();\n\n return this.sortAssets(\n routeIds\n .map((routeId) => routesAssets[routeId])\n .flat()\n .filter(Boolean),\n );\n }\n\n /**\n * Get development route assets\n */\n protected getAssetsDev(routes?: AgnosticDataRouteMatch[]): IAsset[] {\n const routeIds =\n (routes\n ?.map(({ route }) => this.normalizeRoutePath(route?.['pathId'] as string, true))\n .filter(Boolean) as string[]) ?? [];\n\n if (!routeIds.length) {\n return [];\n }\n\n let assets: { [id: string]: IAsset } = {};\n const postfixes = this.getRouteImportPostfix();\n const rootId = `${this.root}/${this.config.getPluginConfig()?.clientFile ?? 'client.ts'}`;\n\n [rootId, ...routeIds].forEach((moduleId) => {\n for (const ext of postfixes) {\n const module = this.config.getVite()?.moduleGraph.getModuleById(`${moduleId}${ext}`);\n\n if (module) {\n assets = { ...assets, ...this.getModuleAssets(module) };\n break;\n }\n }\n });\n\n return Object.values(assets);\n }\n\n /**\n * Get module assets\n */\n protected getModuleAssets(module?: ModuleNode, isNested = false): { [id: string]: IAsset } {\n if (!module?.clientImportedModules.size) {\n return {};\n }\n\n let assets: { [id: string]: IAsset } = {};\n\n module.clientImportedModules.forEach((subModule) => {\n const { file, clientImportedModules, transformResult } = subModule;\n const ext = file?.split('.').at(-1);\n\n if (file && ext && ['css', 'scss'].includes(ext)) {\n // @TODO investigate better method?\n const code = transformResult?.code.match(/__vite__css\\s+=\\s+\"(?<css>.+)\"/)?.groups?.css;\n\n if (code) {\n try {\n assets[file] = {\n type: AssetType.style,\n url: file,\n weight: this.getAssetWeight(file),\n content: JSON.parse(`{\"style\": \"${code}\"}`).style,\n isNested,\n isPreload: false,\n };\n } catch (e) {\n console.warn(chalk.yellowBright('Failed to parse style: ', file));\n }\n }\n } else if (clientImportedModules.size) {\n assets = {\n ...assets,\n ...this.getModuleAssets(subModule, true),\n };\n }\n });\n\n return assets;\n }\n\n /**\n * Get asset weight\n */\n protected getAssetWeight(asset: string): number {\n const type = this.getAssetType(asset);\n\n switch (type) {\n case 'style':\n return 1;\n\n case 'script':\n return 2;\n\n default:\n return 3;\n }\n }\n\n /**\n * Get asset type\n */\n protected getAssetType(asset: string): AssetType | null {\n const ext = asset.split('.').at(-1)?.toLowerCase();\n\n switch (ext) {\n case 'css':\n case 'scss':\n return AssetType.style;\n\n case 'js':\n return AssetType.script;\n\n case 'svg':\n case 'jpg':\n case 'jpeg':\n case 'png':\n case 'webp':\n case 'gif':\n case 'ico':\n return AssetType.image;\n\n case 'ttf':\n case 'otf':\n case 'woff':\n case 'woff2':\n return AssetType.font;\n\n default:\n return null;\n }\n }\n\n /**\n * Write 103 Early Hits header\n */\n public writeEarlyHits(assets: IAsset[], socket: Socket): void {\n socket.write(`HTTP/1.1 103 Early Hints${CRLF}`);\n assets.forEach(({ type, url }) => {\n if (!type || !['style', 'script'].includes(type)) {\n return;\n }\n\n socket.write(`Link: <${url}>; rel=preload; as=${type}${CRLF}`);\n });\n socket.write(CRLF);\n }\n\n /**\n * Inject route assets to head html\n */\n public injectAssets({ routerContext, html, res, hasEarlyHints = false }: IRequestContext): void {\n const assets = this.getAssets(routerContext?.matches);\n const htmlAssets = assets\n .map(({ type, url, isPreload, content = '' }) => {\n switch (type) {\n case 'style':\n return this.config.getVite()\n ? `<style data-vite-dev-id=\"${url}\">${content}</style>`\n : `<link rel=\"stylesheet\" href=\"${url}\">`;\n\n case 'script':\n return isPreload\n ? this.config.isModulePreload\n ? // can reduce lighthouse performance\n `<link rel=\"modulepreload\" as=\"script\" crossorigin href=\"${url}\">`\n : null\n : `<script async type=\"module\" crossorigin src=\"${url}\"></script>`;\n }\n\n return null;\n })\n .filter(Boolean);\n\n html.header = html.header.replace('</head>', `${htmlAssets.join('\\n')}</head>`);\n\n if (hasEarlyHints && htmlAssets.length && res.socket) {\n this.writeEarlyHits(assets, res.socket);\n }\n }\n}\n\nexport default SsrManifest;\n"],"names":["AssetType","CRLF","SsrManifest","static","config","root","buildDir","manifestName","assetsManifest","viteAliases","routesAssets","constructor","this","getParams","getVite","resolve","alias","params","instance","getAssetsManifestFile","path","loadClientManifest","clientSsrManifest","fs","existsSync","result","JSON","parse","readFileSync","encoding","rmSync","loadAssetsManifest","manifestFile","async","routes","index","routeIndex","route","routeId","filter","Boolean","join","lazy","resolvedRoute","normalizeRoutePath","e","console","error","chalk","red","children","Object","assign","getRoutesIds","sortAssets","assets","sort","a","b","weight","Number","isNested","getRouteAssets","manifest","module","css","file","reduce","res","asset","type","getAssetType","isEntry","url","getAssetWeight","isPreload","imports","length","forEach","nestedAsset","nestedModule","prepareServer","PrepareServer","init","ServerConfig","isProd","loadEntrypoint","routesPaths","postfixes","getRouteImportPostfix","entries","routePath","routePostfix","find","postfix","undefined","routeMeta","values","writeFileSync","stringify","getAliases","aliases","replacement","map","prefix","ext","flat","withRoot","fullPath","startsWith","routeAlias","split","replace","win32","sep","posix","getAssets","getAssetsDev","routeIds","id","getPluginConfig","clientFile","moduleId","moduleGraph","getModuleById","getModuleAssets","clientImportedModules","size","subModule","transformResult","at","includes","code","match","groups","style","content","warn","yellowBright","toLowerCase","script","image","font","writeEarlyHits","socket","write","injectAssets","routerContext","html","hasEarlyHints","matches","htmlAssets","isModulePreload","header"],"mappings":"0IA0BA,IAAKA,GAAL,SAAKA,GACHA,EAAA,MAAA,QACAA,EAAA,OAAA,SACAA,EAAA,MAAA,QACAA,EAAA,KAAA,MACD,CALD,CAAKA,IAAAA,EAKJ,CAAA,IAWD,MAAMC,EAAO,OAKb,MAAMC,EAIMC,gBAAsC,KAK7BC,OAKAC,KAKAC,SAKAC,aAAe,gBAKfC,eAAiB,uBAKjBC,YAKTC,aAAgD,KAK1DC,YAAsBP,GAAsBE,SAAEA,EAAQG,YAAEA,GAAoC,CAAA,GAC1FG,KAAKR,OAASA,EACdQ,KAAKP,KAAOD,EAAOS,YAAYR,KAC/BO,KAAKN,SAAWA,EAChBM,KAAKH,YAAcA,GAAeL,EAAOU,WAAWV,QAAQW,QAAQC,KACrE,CAKMb,WAAWC,EAAsBa,EAA6B,IAKnE,OAJ6B,OAAzBf,EAAYgB,WACdhB,EAAYgB,SAAW,IAAIhB,EAAYE,EAAQa,IAG1Cf,EAAYgB,QACpB,CAKSC,wBAGR,MAAO,GAFQC,EAAKL,QAAQH,KAAKP,KAAMO,KAAKN,UAAY,cAE7BM,KAAKJ,gBACjC,CAKSa,qBACR,MAAMC,EAAoBF,EAAKL,QAC7BH,KAAKP,KACL,GAAGO,KAAKN,UAAY,aAAaM,KAAKL,gBAGxC,IAAKgB,EAAGC,WAAWF,GACjB,MAAO,GAGT,MAAMG,EAASC,KAAKC,MAClBJ,EAAGK,aAAaN,EAAmB,CAAEO,SAAU,WAKjD,OAFAN,EAAGO,OAAOR,GAEHG,CACR,CAKSM,qBACR,GAA0B,OAAtBnB,KAAKF,aACP,OAAOE,KAAKF,aAGd,MAAMs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,cAAaC,cAAEA,EAAaC,KAAEA,EAAIhF,IAAEA,EAAGiF,cAAEA,GAAgB,IAC9D,MAAM9F,EAAS3C,KAAKwG,UAAU+B,GAAeG,SACvCC,EAAahG,EAChBgD,KAAI,EAAGjC,OAAMG,MAAKE,YAAW6D,UAAU,OACtC,OAAQlE,GACN,IAAK,QACH,OAAO1D,KAAKR,OAAOU,UACf,4BAA4B2D,MAAQ+D,YACpC,gCAAgC/D,MAEtC,IAAK,SACH,OAAOE,EACH/D,KAAKR,OAAOoJ,gBAEV,2DAA2D/E,MAC3D,KACF,gDAAgDA,gBAGxD,OAAO,IAAI,IAEZlC,OAAOC,SAEV4G,EAAKK,OAASL,EAAKK,OAAOzC,QAAQ,UAAW,GAAGuC,EAAW9G,KAAK,gBAE5D4G,GAAiBE,EAAW1E,QAAUT,EAAI4E,QAC5CpI,KAAKmI,eAAexF,EAAQa,EAAI4E,OAEnC"}
|
package/workflow/Dockerfile
CHANGED
package/cli/keyboard-input.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import o from"chalk";import t from"../constants/cli-context.js";import i from"../constants/cli-shortcuts.js";import r from"../helpers/plugin-config.js";import e from"../helpers/process-stop.js";let n=!1;function s(s){!async function(s){if(""===s||""===s)return void(t.server?.close((o=>e(o?1:0)))||e());if(n)return;const{config:c}=t,f=c?.getLogger(),{customShortcuts:l=[]}="object"==typeof c?.getVite()?.config?r(c.getVite().config):{},p=l.filter(Boolean).concat(i).filter((({isOnlyDev:o=!1})=>!o||o&&!c?.isProd));if("\r"===s)return f?.info("\r");"h"===s&&f?.info(["",o.bold(" Shortcuts"),...p.map((t=>o.dim(" press ")+o.bold(t.key)+o.dim(` to ${t.description}`)))].join("\n"));const m=p.find((({key:o})=>o===s));if(!m)return;n=!0,await m.action(t),n=!1}(s)}export{s as default};
|
|
2
|
-
//# sourceMappingURL=keyboard-input.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard-input.js","sources":["../../src/cli/keyboard-input.ts"],"sourcesContent":["import chalk from 'chalk';\nimport cliContext from '@constants/cli-context';\nimport defaultShortcuts from '@constants/cli-shortcuts';\nimport getPluginConfig from '@helpers/plugin-config';\nimport processStop from '@helpers/process-stop';\n\nlet isActionRunning = false;\n\n/**\n * Handle keyboard press buttons\n */\nfunction onKeyPress(input: string): void {\n void runAction(input);\n}\n\n/**\n * Run shortcut\n */\nasync function runAction(input: string): Promise<void> {\n // ctrl+c or ctrl+d\n if (input === '\\x03' || input === '\\x04') {\n if (!cliContext.server?.close((e) => processStop(e ? 1 : 0))) {\n processStop();\n }\n\n return;\n }\n\n if (isActionRunning) {\n return;\n }\n\n const { config } = cliContext;\n const Logger = config?.getLogger();\n const { customShortcuts = [] } =\n typeof config?.getVite()?.config === 'object' ? getPluginConfig(config.getVite()!.config) : {};\n\n const shortcuts = customShortcuts\n .filter(Boolean)\n .concat(defaultShortcuts)\n .filter(({ isOnlyDev = false }) => !isOnlyDev || (isOnlyDev && !config?.isProd));\n\n // print empty line\n if (input === '\\r') {\n return Logger?.info('\\r');\n }\n\n // print help\n if (input === 'h') {\n Logger?.info(\n [\n '',\n chalk.bold(' Shortcuts'),\n ...shortcuts.map(\n (shortcut) =>\n chalk.dim(' press ') +\n chalk.bold(shortcut.key) +\n chalk.dim(` to ${shortcut.description}`),\n ),\n ].join('\\n'),\n );\n }\n\n // execute shortcut command\n const shortcut = shortcuts.find(({ key }) => key === input);\n\n if (!shortcut) {\n return;\n }\n\n isActionRunning = true;\n await shortcut.action(cliContext);\n isActionRunning = false;\n}\n\nexport default onKeyPress;\n"],"names":["isActionRunning","onKeyPress","input","async","cliContext","server","close","e","processStop","config","Logger","getLogger","customShortcuts","getVite","getPluginConfig","shortcuts","filter","Boolean","concat","defaultShortcuts","isOnlyDev","isProd","info","chalk","bold","map","shortcut","dim","key","description","join","find","action","runAction"],"mappings":"kMAMA,IAAIA,GAAkB,EAKtB,SAASC,EAAWC,IAOpBC,eAAyBD,GAEvB,GAAc,MAAVA,GAA8B,MAAVA,EAKtB,YAJKE,EAAWC,QAAQC,OAAOC,GAAMC,EAAYD,EAAI,EAAI,MACvDC,KAMJ,GAAIR,EACF,OAGF,MAAMS,OAAEA,GAAWL,EACbM,EAASD,GAAQE,aACjBC,gBAAEA,EAAkB,IACa,iBAA9BH,GAAQI,WAAWJ,OAAsBK,EAAgBL,EAAOI,UAAWJ,QAAU,CAAA,EAExFM,EAAYH,EACfI,OAAOC,SACPC,OAAOC,GACPH,QAAO,EAAGI,aAAY,MAAaA,GAAcA,IAAcX,GAAQY,SAG1E,GAAc,OAAVnB,EACF,OAAOQ,GAAQY,KAAK,MAIR,MAAVpB,GACFQ,GAAQY,KACN,CACE,GACAC,EAAMC,KAAK,kBACRT,EAAUU,KACVC,GACCH,EAAMI,IAAI,YACVJ,EAAMC,KAAKE,EAASE,KACpBL,EAAMI,IAAI,OAAOD,EAASG,kBAE9BC,KAAK,OAKX,MAAMJ,EAAWX,EAAUgB,MAAK,EAAGH,SAAUA,IAAQ1B,IAErD,IAAKwB,EACH,OAGF1B,GAAkB,QACZ0B,EAASM,OAAO5B,GACtBJ,GAAkB,CACpB,CA7DOiC,CAAU/B,EACjB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-reset-cache.js","sources":["../../src/cli/vite-reset-cache.ts"],"sourcesContent":["import fs from 'node:fs';\nimport chalk from 'chalk';\nimport { resolveConfig } from 'vite';\n\n/**\n * Reset vite cache\n */\nasync function viteResetCache(): Promise<void> {\n const config = await resolveConfig({}, 'build');\n const { cacheDir } = config;\n\n if (fs.existsSync(cacheDir)) {\n fs.rmSync(cacheDir, { recursive: true, force: true });\n }\n\n console.info(chalk.dim(chalk.yellowBright('vite cache cleared.')));\n}\n\nexport default viteResetCache;\n"],"names":["async","viteResetCache","config","resolveConfig","cacheDir","fs","existsSync","rmSync","recursive","force","console","info","chalk","dim","yellowBright"],"mappings":"iFAOAA,eAAeC,IACb,MAAMC,QAAeC,EAAc,CAAE,EAAE,UACjCC,SAAEA,GAAaF,EAEjBG,EAAGC,WAAWF,IAChBC,EAAGE,OAAOH,EAAU,CAAEI,WAAW,EAAMC,OAAO,IAGhDC,QAAQC,KAAKC,EAAMC,IAAID,EAAME,aAAa,wBAC5C"}
|
package/helpers/unlock-robots.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import o from"node:fs";import t from"node:path";import e from"chalk";const n=(n,l)=>{const i=`${t.resolve(n,l)}/client/robots.txt`;if(!o.existsSync(i))return void console.warn(`Failed to unlock robots.txt, file not exist: ${i}`);const r=o.readFileSync(i,{encoding:"utf-8"}).replace(/Disallow: \/$/m,"Allow: /");o.writeFileSync(i,r,{encoding:"utf-8"}),console.info(e.blue("\nrobots.txt unlocked."))};export{n as default};
|
|
2
|
-
//# sourceMappingURL=unlock-robots.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unlock-robots.js","sources":["../../src/helpers/unlock-robots.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport chalk from 'chalk';\n\n/**\n * Change general directive Disallow to Allow in robots.txt.\n */\nconst unlockRobots = (root: string, buildFolder: string): void => {\n const buildPath = path.resolve(root, buildFolder);\n const robotsFile = `${buildPath}/client/robots.txt`;\n\n if (!fs.existsSync(robotsFile)) {\n console.warn(`Failed to unlock robots.txt, file not exist: ${robotsFile}`);\n\n return;\n }\n\n const data = fs\n .readFileSync(robotsFile, { encoding: 'utf-8' })\n .replace(/Disallow: \\/$/m, 'Allow: /');\n\n fs.writeFileSync(robotsFile, data, { encoding: 'utf-8' });\n\n console.info(chalk.blue('\\nrobots.txt unlocked.'));\n};\n\nexport default unlockRobots;\n"],"names":["unlockRobots","root","buildFolder","robotsFile","path","resolve","fs","existsSync","console","warn","data","readFileSync","encoding","replace","writeFileSync","info","chalk","blue"],"mappings":"qEAOA,MAAMA,EAAe,CAACC,EAAcC,KAClC,MACMC,EAAa,GADDC,EAAKC,QAAQJ,EAAMC,uBAGrC,IAAKI,EAAGC,WAAWJ,GAGjB,YAFAK,QAAQC,KAAK,gDAAgDN,KAK/D,MAAMO,EAAOJ,EACVK,aAAaR,EAAY,CAAES,SAAU,UACrCC,QAAQ,iBAAkB,YAE7BP,EAAGQ,cAAcX,EAAYO,EAAM,CAAEE,SAAU,UAE/CJ,QAAQO,KAAKC,EAAMC,KAAK,0BAA0B"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|