@lomray/vite-ssr-boost 1.0.0-beta.1
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/browser/entry.d.ts +20 -0
- package/browser/entry.js +2 -0
- package/browser/entry.js.map +1 -0
- package/cli/build.d.ts +11 -0
- package/cli/build.js +2 -0
- package/cli/build.js.map +1 -0
- package/cli/keyboard-input.d.ts +5 -0
- package/cli/keyboard-input.js +2 -0
- package/cli/keyboard-input.js.map +1 -0
- package/cli/run-dev.d.ts +17 -0
- package/cli/run-dev.js +2 -0
- package/cli/run-dev.js.map +1 -0
- package/cli/run-prod.d.ts +19 -0
- package/cli/run-prod.js +2 -0
- package/cli/run-prod.js.map +1 -0
- package/cli/vite-reset-cache.d.ts +5 -0
- package/cli/vite-reset-cache.js +2 -0
- package/cli/vite-reset-cache.js.map +1 -0
- package/cli.d.ts +2 -0
- package/cli.js +3 -0
- package/cli.js.map +1 -0
- package/components/navigate.d.ts +12 -0
- package/components/navigate.js +2 -0
- package/components/navigate.js.map +1 -0
- package/components/response-status.d.ts +11 -0
- package/components/response-status.js +2 -0
- package/components/response-status.js.map +1 -0
- package/constants/cli-actions.d.ts +7 -0
- package/constants/cli-actions.js +2 -0
- package/constants/cli-actions.js.map +1 -0
- package/constants/cli-context.d.ts +14 -0
- package/constants/cli-context.js +2 -0
- package/constants/cli-context.js.map +1 -0
- package/constants/cli-name.d.ts +2 -0
- package/constants/cli-name.js +2 -0
- package/constants/cli-name.js.map +1 -0
- package/constants/cli-shortcuts.d.ts +6 -0
- package/constants/cli-shortcuts.js +2 -0
- package/constants/cli-shortcuts.js.map +1 -0
- package/constants/common.d.ts +2 -0
- package/constants/common.js +2 -0
- package/constants/common.js.map +1 -0
- package/constants/plugin-name.d.ts +2 -0
- package/constants/plugin-name.js +2 -0
- package/constants/plugin-name.js.map +1 -0
- package/constants/stream-error.d.ts +10 -0
- package/constants/stream-error.js +2 -0
- package/constants/stream-error.js.map +1 -0
- package/context/server.d.ts +21 -0
- package/context/server.js +2 -0
- package/context/server.js.map +1 -0
- package/helpers/build-custom-state.d.ts +6 -0
- package/helpers/build-custom-state.js +2 -0
- package/helpers/build-custom-state.js.map +1 -0
- package/helpers/build-router-state.d.ts +6 -0
- package/helpers/build-router-state.js +2 -0
- package/helpers/build-router-state.js.map +1 -0
- package/helpers/handle-response.d.ts +7 -0
- package/helpers/handle-response.js +2 -0
- package/helpers/handle-response.js.map +1 -0
- package/helpers/obtain-stream-error.d.ts +11 -0
- package/helpers/obtain-stream-error.js +2 -0
- package/helpers/obtain-stream-error.js.map +1 -0
- package/helpers/plugin-config.d.ts +13 -0
- package/helpers/plugin-config.js +2 -0
- package/helpers/plugin-config.js.map +1 -0
- package/helpers/print-server-info.d.ts +11 -0
- package/helpers/print-server-info.js +2 -0
- package/helpers/print-server-info.js.map +1 -0
- package/helpers/print-server-urls.d.ts +8 -0
- package/helpers/print-server-urls.js +2 -0
- package/helpers/print-server-urls.js.map +1 -0
- package/helpers/process-stop.d.ts +5 -0
- package/helpers/process-stop.js +2 -0
- package/helpers/process-stop.js.map +1 -0
- package/helpers/resolve-server-urls.d.ts +15 -0
- package/helpers/resolve-server-urls.js +2 -0
- package/helpers/resolve-server-urls.js.map +1 -0
- package/helpers/serialize-errors.d.ts +7 -0
- package/helpers/serialize-errors.js +2 -0
- package/helpers/serialize-errors.js.map +1 -0
- package/node/create-fetch-request.d.ts +7 -0
- package/node/create-fetch-request.js +2 -0
- package/node/create-fetch-request.js.map +1 -0
- package/node/entry.d.ts +40 -0
- package/node/entry.js +2 -0
- package/node/entry.js.map +1 -0
- package/node/render.d.ts +64 -0
- package/node/render.js +2 -0
- package/node/render.js.map +1 -0
- package/node/server.d.ts +14 -0
- package/node/server.js +2 -0
- package/node/server.js.map +1 -0
- package/node/write-response.d.ts +14 -0
- package/node/write-response.js +2 -0
- package/node/write-response.js.map +1 -0
- package/package.json +76 -0
- package/plugin.d.ts +19 -0
- package/plugin.js +2 -0
- package/plugin.js.map +1 -0
- package/services/logger.d.ts +53 -0
- package/services/logger.js +2 -0
- package/services/logger.js.map +1 -0
- package/services/prepare-server.d.ts +74 -0
- package/services/prepare-server.js +2 -0
- package/services/prepare-server.js.map +1 -0
- package/services/server-config.d.ts +140 -0
- package/services/server-config.js +2 -0
- package/services/server-config.js.map +1 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="react-dom" />
|
|
2
|
+
import { FC, PropsWithChildren } from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom/client';
|
|
4
|
+
import { RouteObject } from 'react-router-dom';
|
|
5
|
+
interface IEntryClientOptions {
|
|
6
|
+
routes: RouteObject[];
|
|
7
|
+
}
|
|
8
|
+
interface IAppClientProps<T = undefined> {
|
|
9
|
+
client: T;
|
|
10
|
+
}
|
|
11
|
+
interface IInitPropsParams {
|
|
12
|
+
isSSRMode: boolean;
|
|
13
|
+
}
|
|
14
|
+
type TApp<T> = FC<PropsWithChildren<IAppClientProps<T>>>;
|
|
15
|
+
type TAppGetProps<T> = (params: IInitPropsParams) => Promise<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Render client side application
|
|
18
|
+
*/
|
|
19
|
+
declare function entry<TAppProps>({ routes }: IEntryClientOptions, App: TApp<TAppProps>, initProps?: TAppGetProps<TAppProps>): Promise<ReactDOM.Root | void>;
|
|
20
|
+
export { entry as default, IEntryClientOptions, IAppClientProps, IInitPropsParams, TApp, TAppGetProps };
|
package/browser/entry.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import t from"react";import e from"react-dom/client";import{matchRoutes as o,createBrowserRouter as r,RouterProvider as a}from"react-router-dom";import{IS_SSR_MODE as n}from"../constants/common.js";async function c({routes:c},l,m){const i=o(c,window.location)?.filter((t=>t.route.lazy));i&&i?.length>0&&await Promise.all(i.map((async t=>{const e=await(t.route.lazy?.());Object.assign(t.route,{...e,lazy:void 0})})));const s=await(m?.({isSSRMode:n})),u=r(c),d=document.getElementById("root"),f=()=>t.createElement(l,{client:s},t.createElement(a,{router:u}));return n?e.hydrateRoot(d,t.createElement(f,null)):e.createRoot(d).render(t.createElement(f,null))}export{c as default};
|
|
2
|
+
//# sourceMappingURL=entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.js","sources":["../../src/browser/entry.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from 'react';\nimport React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport type { RouteObject } from 'react-router-dom';\nimport { createBrowserRouter, matchRoutes, RouterProvider } from 'react-router-dom';\nimport { IS_SSR_MODE } from '@constants/common';\n\nexport interface IEntryClientOptions {\n routes: RouteObject[];\n}\n\nexport interface IAppClientProps<T = undefined> {\n client: T;\n}\n\nexport interface IInitPropsParams {\n isSSRMode: boolean;\n}\n\nexport type TApp<T> = FC<PropsWithChildren<IAppClientProps<T>>>;\n\nexport type TAppGetProps<T> = (params: IInitPropsParams) => Promise<T>;\n\n/**\n * Render client side application\n */\nasync function entry<TAppProps>(\n { routes }: IEntryClientOptions,\n App: TApp<TAppProps>,\n initProps?: TAppGetProps<TAppProps>,\n): Promise<ReactDOM.Root | void> {\n const lazyMatches = matchRoutes(routes, window.location)?.filter((m) => m.route.lazy);\n\n // Load the lazy matches and update the routes before creating router,\n // so we can hydrate the SSR-rendered content synchronously\n if (lazyMatches && lazyMatches?.length > 0) {\n await Promise.all(\n lazyMatches.map(async (m) => {\n const routeModule = await m.route.lazy?.();\n\n Object.assign(m.route, {\n ...routeModule,\n lazy: undefined,\n });\n }),\n );\n }\n\n const appProps = (await initProps?.({ isSSRMode: IS_SSR_MODE })) as TAppProps;\n const router = createBrowserRouter(routes);\n const root = document.getElementById('root') as HTMLElement;\n\n const AppComponent: FC = () => (\n <App client={appProps}>\n <RouterProvider router={router} />\n </App>\n );\n\n if (!IS_SSR_MODE) {\n return ReactDOM.createRoot(root).render(<AppComponent />);\n }\n\n return ReactDOM.hydrateRoot(root, <AppComponent />);\n}\n\nexport default entry;\n"],"names":["async","entry","routes","App","initProps","lazyMatches","matchRoutes","window","location","filter","m","route","lazy","length","Promise","all","map","routeModule","Object","assign","undefined","appProps","isSSRMode","IS_SSR_MODE","router","createBrowserRouter","root","document","getElementById","AppComponent","React","createElement","client","RouterProvider","ReactDOM","hydrateRoot","createRoot","render"],"mappings":"sMA0BAA,eAAeC,GACbC,OAAEA,GACFC,EACAC,GAEA,MAAMC,EAAcC,EAAYJ,EAAQK,OAAOC,WAAWC,QAAQC,GAAMA,EAAEC,MAAMC,OAI5EP,GAAeA,GAAaQ,OAAS,SACjCC,QAAQC,IACZV,EAAYW,KAAIhB,MAAOU,IACrB,MAAMO,QAAoBP,EAAEC,MAAMC,UAElCM,OAAOC,OAAOT,EAAEC,MAAO,IAClBM,EACHL,UAAMQ,GACN,KAKR,MAAMC,QAAkBjB,IAAY,CAAEkB,UAAWC,KAC3CC,EAASC,EAAoBvB,GAC7BwB,EAAOC,SAASC,eAAe,QAE/BC,EAAmB,IACvBC,EAAAC,cAAC5B,EAAG,CAAC6B,OAAQX,GACXS,EAACC,cAAAE,GAAeT,OAAQA,KAI5B,OAAKD,EAIEW,EAASC,YAAYT,EAAMI,EAACC,cAAAF,EAAe,OAHzCK,EAASE,WAAWV,GAAMW,OAAOP,EAAAC,cAACF,EAAY,MAIzD"}
|
package/cli/build.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface IBuildParams {
|
|
2
|
+
isOnlyClient?: boolean;
|
|
3
|
+
isWatch?: boolean;
|
|
4
|
+
clientOptions?: string;
|
|
5
|
+
serverOptions?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Build production application
|
|
9
|
+
*/
|
|
10
|
+
declare function build({ isOnlyClient, isWatch, clientOptions, serverOptions, }: IBuildParams): Promise<void | [unknown, unknown]>;
|
|
11
|
+
export { build as default };
|
package/cli/build.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"node:child_process";import{performance as o}from"node:perf_hooks";import i from"chalk";import{resolveConfig as r}from"vite";import t from"../constants/cli-name.js";import n from"../helpers/plugin-config.js";const s=e=>new Promise(((o,i)=>{e.on("exit",(e=>{o(e)})),e.on("close",(e=>{o(e)})),e.on("error",(e=>{i(e)}))}));async function l({isOnlyClient:l=!1,isWatch:a=!1,clientOptions:c="",serverOptions:p=""}){const m=o.now(),u=await r({},"build"),d=n(u),{outDir:f}=u.build,h=["client"],S=new AbortController,v=s(e.spawn(`vite build ${c} --emptyOutDir --outDir ${f}/client`,{signal:S.signal,stdio:"inherit",shell:!0,env:{...process.env,SSR_BOOST_IS_SSR:l?"0":"1"}}));let w;if(a||await v,l||(w=s(e.spawn(`vite build ${p} --emptyOutDir --outDir ${f}/server --ssr ${d.serverFile}`,{signal:S.signal,stdio:"inherit",shell:!0,env:{...process.env,SSR_BOOST_IS_SSR:l?"0":"1"}})),a||await w,h.push("server")),a){process.on("exit",(()=>{S.abort()}));const e=Promise.all([v,w]);return e.controller=S,e}const $=i.dim(`${i.yellowBright(h.join(","))} built in ${i.reset(i.bold(Math.ceil(o.now()-m)))} ms`);console.info(`\n ${i.green(`${i.bold(t.toUpperCase())}`)} ${$}\n`)}export{l as default};
|
|
2
|
+
//# sourceMappingURL=build.js.map
|
package/cli/build.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sources":["../../src/cli/build.ts"],"sourcesContent":["import childProcess from 'node:child_process';\nimport { performance } from 'node:perf_hooks';\nimport chalk from 'chalk';\nimport { resolveConfig } from 'vite';\nimport cliName from '@constants/cli-name';\nimport getPluginConfig from '@helpers/plugin-config';\n\ninterface IBuildParams {\n isOnlyClient?: boolean;\n isWatch?: boolean;\n clientOptions?: string;\n serverOptions?: string;\n}\n\n/**\n * Promisify spawn process\n */\nconst promisify = (command: childProcess.ChildProcess) =>\n new Promise((resolve, reject) => {\n command.on('exit', (code) => {\n resolve(code);\n });\n\n command.on('close', (code) => {\n resolve(code);\n });\n\n command.on('error', (message) => {\n reject(message);\n });\n });\n\n/**\n * Build production application\n */\nasync function build({\n isOnlyClient = false,\n isWatch = false,\n clientOptions = '',\n serverOptions = '',\n}: IBuildParams): Promise<void | [unknown, unknown]> {\n const perfStart = performance.now();\n const config = await resolveConfig({}, 'build');\n const pluginConfig = getPluginConfig(config);\n const { outDir } = config.build;\n const types = ['client'];\n const controller = new AbortController();\n\n // build client\n const clientProcess = promisify(\n childProcess.spawn(`vite build ${clientOptions} --emptyOutDir --outDir ${outDir}/client`, {\n signal: controller.signal,\n stdio: 'inherit',\n shell: true,\n env: {\n ...process.env,\n SSR_BOOST_IS_SSR: isOnlyClient ? '0' : '1',\n },\n }),\n );\n\n if (!isWatch) {\n await clientProcess;\n }\n\n let serverProcess;\n\n if (!isOnlyClient) {\n // build server\n serverProcess = promisify(\n childProcess.spawn(\n `vite build ${serverOptions} --emptyOutDir --outDir ${outDir}/server --ssr ${pluginConfig.serverFile}`,\n {\n signal: controller.signal,\n stdio: 'inherit',\n shell: true,\n env: {\n ...process.env,\n SSR_BOOST_IS_SSR: isOnlyClient ? '0' : '1',\n },\n },\n ),\n );\n\n if (!isWatch) {\n await serverProcess;\n }\n\n types.push('server');\n }\n\n if (isWatch) {\n process.on('exit', () => {\n controller.abort();\n });\n\n const buildPromise = Promise.all([clientProcess, serverProcess]);\n\n buildPromise['controller'] = controller;\n\n return buildPromise;\n }\n\n const buildDurationString = chalk.dim(\n `${chalk.yellowBright(types.join(','))} built in ${chalk.reset(\n chalk.bold(Math.ceil(performance.now() - perfStart)),\n )} ms`,\n );\n\n console.info(\n `\\n ${chalk.green(`${chalk.bold(cliName.toUpperCase())}`)} ${buildDurationString}\\n`,\n );\n}\n\nexport default build;\n"],"names":["promisify","command","Promise","resolve","reject","on","code","message","async","build","isOnlyClient","isWatch","clientOptions","serverOptions","perfStart","performance","now","config","resolveConfig","pluginConfig","getPluginConfig","outDir","types","controller","AbortController","clientProcess","childProcess","spawn","signal","stdio","shell","env","process","SSR_BOOST_IS_SSR","serverProcess","serverFile","push","abort","buildPromise","all","buildDurationString","chalk","dim","yellowBright","join","reset","bold","Math","ceil","console","info","green","cliName","toUpperCase"],"mappings":"6NAiBA,MAAMA,EAAaC,GACjB,IAAIC,SAAQ,CAACC,EAASC,KACpBH,EAAQI,GAAG,QAASC,IAClBH,EAAQG,EAAK,IAGfL,EAAQI,GAAG,SAAUC,IACnBH,EAAQG,EAAK,IAGfL,EAAQI,GAAG,SAAUE,IACnBH,EAAOG,EAAQ,GACf,IAMNC,eAAeC,GAAMC,aACnBA,GAAe,EAAKC,QACpBA,GAAU,EAAKC,cACfA,EAAgB,GAAEC,cAClBA,EAAgB,KAEhB,MAAMC,EAAYC,EAAYC,MACxBC,QAAeC,EAAc,CAAE,EAAE,SACjCC,EAAeC,EAAgBH,IAC/BI,OAAEA,GAAWJ,EAAOR,MACpBa,EAAQ,CAAC,UACTC,EAAa,IAAIC,gBAGjBC,EAAgBzB,EACpB0B,EAAaC,MAAM,cAAcf,4BAAwCS,WAAiB,CACxFO,OAAQL,EAAWK,OACnBC,MAAO,UACPC,OAAO,EACPC,IAAK,IACAC,QAAQD,IACXE,iBAAkBvB,EAAe,IAAM,QAS7C,IAAIwB,EA0BJ,GA9BKvB,SACGc,EAKHf,IAEHwB,EAAgBlC,EACd0B,EAAaC,MACX,cAAcd,4BAAwCQ,kBAAuBF,EAAagB,aAC1F,CACEP,OAAQL,EAAWK,OACnBC,MAAO,UACPC,OAAO,EACPC,IAAK,IACAC,QAAQD,IACXE,iBAAkBvB,EAAe,IAAM,QAM1CC,SACGuB,EAGRZ,EAAMc,KAAK,WAGTzB,EAAS,CACXqB,QAAQ3B,GAAG,QAAQ,KACjBkB,EAAWc,OAAO,IAGpB,MAAMC,EAAepC,QAAQqC,IAAI,CAACd,EAAeS,IAIjD,OAFAI,EAAyB,WAAIf,EAEtBe,CACR,CAED,MAAME,EAAsBC,EAAMC,IAChC,GAAGD,EAAME,aAAarB,EAAMsB,KAAK,kBAAkBH,EAAMI,MACvDJ,EAAMK,KAAKC,KAAKC,KAAKjC,EAAYC,MAAQF,WAI7CmC,QAAQC,KACN,OAAOT,EAAMU,MAAM,GAAGV,EAAMK,KAAKM,EAAQC,sBAAsBb,MAEnE"}
|
|
@@ -0,0 +1,2 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/cli/run-dev.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Server } from 'node:net';
|
|
3
|
+
import ServerConfig from "../services/server-config.js";
|
|
4
|
+
interface IRunDevParams {
|
|
5
|
+
version: string;
|
|
6
|
+
isHost?: boolean;
|
|
7
|
+
isPrintInfo?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface IRunDevOut {
|
|
10
|
+
server: Server;
|
|
11
|
+
config: ServerConfig;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Run development server
|
|
15
|
+
*/
|
|
16
|
+
declare function runDev({ version, isHost, isPrintInfo }: IRunDevParams): Promise<IRunDevOut>;
|
|
17
|
+
export { runDev as default };
|
package/cli/run-dev.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{performance as o}from"node:perf_hooks";import r from"../node/server.js";import i from"../services/server-config.js";async function s({version:s,isHost:e,isPrintInfo:n}){global.viteBoostStartTime=o.now();const t=i.init({isHost:e}),{run:f}=await r(t);return{server:f({version:s,isPrintInfo:n}),config:t}}export{s as default};
|
|
2
|
+
//# sourceMappingURL=run-dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-dev.js","sources":["../../src/cli/run-dev.ts"],"sourcesContent":["import type { Server } from 'node:net';\nimport { performance } from 'node:perf_hooks';\nimport createServer from '@node/server';\nimport ServerConfig from '@services/server-config';\n\ninterface IRunDevParams {\n version: string;\n isHost?: boolean;\n isPrintInfo?: boolean;\n}\n\ninterface IRunDevOut {\n server: Server;\n config: ServerConfig;\n}\n\n/**\n * Run development server\n */\nasync function runDev({ version, isHost, isPrintInfo }: IRunDevParams): Promise<IRunDevOut> {\n global.viteBoostStartTime = performance.now();\n\n const config = ServerConfig.init({ isHost });\n const { run } = await createServer(config);\n\n return {\n server: run({ version, isPrintInfo }),\n config,\n };\n}\n\nexport default runDev;\n"],"names":["async","runDev","version","isHost","isPrintInfo","global","viteBoostStartTime","performance","now","config","ServerConfig","init","run","createServer","server"],"mappings":"2HAmBAA,eAAeC,GAAOC,QAAEA,EAAOC,OAAEA,EAAMC,YAAEA,IACvCC,OAAOC,mBAAqBC,EAAYC,MAExC,MAAMC,EAASC,EAAaC,KAAK,CAAER,YAC7BS,IAAEA,SAAcC,EAAaJ,GAEnC,MAAO,CACLK,OAAQF,EAAI,CAAEV,UAASE,gBACvBK,SAEJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Server } from 'node:net';
|
|
3
|
+
import ServerConfig from "../services/server-config.js";
|
|
4
|
+
interface IRunProdParams {
|
|
5
|
+
version: string;
|
|
6
|
+
port?: number;
|
|
7
|
+
isHost?: boolean;
|
|
8
|
+
isPrintInfo?: boolean;
|
|
9
|
+
onlyClient?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface IRunProdOut {
|
|
12
|
+
server: Server;
|
|
13
|
+
config: ServerConfig;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Run production server
|
|
17
|
+
*/
|
|
18
|
+
declare function runProd({ version, isHost, isPrintInfo, port, onlyClient, }: IRunProdParams): Promise<IRunProdOut>;
|
|
19
|
+
export { runProd as default };
|
package/cli/run-prod.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{performance as o}from"node:perf_hooks";import r from"../node/server.js";import i from"../services/server-config.js";async function n({version:n,isHost:s,isPrintInfo:t,port:e,onlyClient:f=!1}){global.viteBoostStartTime=o.now();const a=i.init({isHost:s,isProd:!0,isOnlyClient:f},{port:e}),{run:l}=await r(a);return{server:l({version:n,isPrintInfo:t}),config:a}}export{n as default};
|
|
2
|
+
//# sourceMappingURL=run-prod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-prod.js","sources":["../../src/cli/run-prod.ts"],"sourcesContent":["import type { Server } from 'node:net';\nimport { performance } from 'node:perf_hooks';\nimport createServer from '@node/server';\nimport ServerConfig from '@services/server-config';\n\ninterface IRunProdParams {\n version: string;\n port?: number;\n isHost?: boolean;\n isPrintInfo?: boolean;\n onlyClient?: boolean; // SPA mode\n}\n\ninterface IRunProdOut {\n server: Server;\n config: ServerConfig;\n}\n\n/**\n * Run production server\n */\nasync function runProd({\n version,\n isHost,\n isPrintInfo,\n port,\n onlyClient = false,\n}: IRunProdParams): Promise<IRunProdOut> {\n global.viteBoostStartTime = performance.now();\n\n const config = ServerConfig.init({ isHost, isProd: true, isOnlyClient: onlyClient }, { port });\n const { run } = await createServer(config);\n\n return {\n server: run({ version, isPrintInfo }),\n config,\n };\n}\n\nexport default runProd;\n"],"names":["async","runProd","version","isHost","isPrintInfo","port","onlyClient","global","viteBoostStartTime","performance","now","config","ServerConfig","init","isProd","isOnlyClient","run","createServer","server"],"mappings":"2HAqBAA,eAAeC,GAAQC,QACrBA,EAAOC,OACPA,EAAMC,YACNA,EAAWC,KACXA,EAAIC,WACJA,GAAa,IAEbC,OAAOC,mBAAqBC,EAAYC,MAExC,MAAMC,EAASC,EAAaC,KAAK,CAAEV,SAAQW,QAAQ,EAAMC,aAAcT,GAAc,CAAED,UACjFW,IAAEA,SAAcC,EAAaN,GAEnC,MAAO,CACLO,OAAQF,EAAI,CAAEd,UAASE,gBACvBO,SAEJ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"node:fs";import o from"chalk";import{resolveConfig as c}from"vite";async function i(){const i=await c({},"build"),{cacheDir:r}=i;e.existsSync(r)&&e.rmSync(r,{recursive:!0,force:!0}),console.info(o.dim(o.yellowBright("vite cache cleared.")))}export{i as default};
|
|
2
|
+
//# sourceMappingURL=vite-reset-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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/cli.d.ts
ADDED
package/cli.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{readFileSync as o}from"fs";import t from"chalk";import{Command as n,Option as e}from"commander";import i from"./cli/build.js";import s from"./cli/keyboard-input.js";import r from"./cli/run-dev.js";import c from"./cli/run-prod.js";import a from"./cli/vite-reset-cache.js";import p from"./constants/cli-actions.js";import d from"./constants/cli-context.js";import l from"./constants/cli-name.js";const{description:m,version:f}=JSON.parse(o(new URL("./package.json",import.meta.url),"utf8")),v=()=>{process.stdin.isTTY&&(process.stdin.setRawMode(!0),process.stdin.on("data",s).setEncoding("utf8").resume())},u=new n;u.name(l).description(m).version(f).hook("preAction",((o,t)=>{global.viteBoostAction=t.name()}));const O=new e("--host","Ability to access the local instance on other devices under the same network.").default(!1),w=new e("--only-client","Build/run only client side part.").default(!1),y=new e("--port [port]","Server port.").default(3e3);u.command(p.dev).description("Run development server.").addOption(O).addOption(new e("--reset-cache","Clear vite cache before run.").default(!1)).action((async({host:o,resetCache:t})=>{t&&await a();const n=async t=>{const{server:n,config:e}=await r({version:f,isHost:o,isPrintInfo:t});d.server=n,d.config=e};return d.reboot=n,v(),n()})),u.command(p.build).description("Create production build.").addOption(w).addOption(new e("--client-options [client-options]",'Pass vite build options for client. Example: --client-options="--ssrManifest"').env("VITE_BUILD_CLIENT_OPTIONS").default("")).addOption(new e("--server-options [server-options]","Pass vite build options for server.").env("VITE_BUILD_SERVER_OPTIONS").default("")).action((async({onlyClient:o,clientOptions:t,serverOptions:n})=>{await i({isOnlyClient:o,clientOptions:t,serverOptions:n})})),u.command(p.start).description("Run production server.").addOption(O).addOption(y).addOption(w).action((({host:o,port:t,onlyClient:n})=>{const e=async e=>{const{server:i,config:s}=await c({version:f,isHost:o,isPrintInfo:e,port:t,onlyClient:n});d.server=i,d.config=s};return d.reboot=e,v(),e()})),u.command(p.preview).description("Build and preview production.").addOption(w).addOption(O).addOption(y).action((async({host:o,port:n,onlyClient:e})=>{const s=async i=>{const{server:s,config:r}=await c({version:f,isHost:o,isPrintInfo:i,port:n,onlyClient:e});s.on("listening",(()=>{setTimeout((()=>{r.getLogger().info(t.yellow("\n Running preview mode... \n"))}),0)})),d.server=s,d.config=r};d.reboot=s,v();const r=i({isWatch:!0,isOnlyClient:e,clientOptions:"-w",serverOptions:"-w"});await Promise.all([s(),r])})),u.parse();
|
|
3
|
+
//# sourceMappingURL=cli.js.map
|
package/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readFileSync } from 'fs';\nimport chalk from 'chalk';\nimport { Command, Option } from 'commander';\nimport runBuild from '@cli/build';\nimport onKeyPress from '@cli/keyboard-input';\nimport runDev from '@cli/run-dev';\nimport runProd from '@cli/run-prod';\nimport viteResetCache from '@cli/vite-reset-cache';\nimport CliActions from '@constants/cli-actions';\nimport cliContext from '@constants/cli-context';\nimport cliName from '@constants/cli-name';\n\n/**\n * Parse package meta\n */\nconst { description, version } = JSON.parse(\n readFileSync(new URL('./package.json', import.meta.url), 'utf8'),\n) as { name: string; description: string; version: string };\n\n/**\n * Enable shortcuts\n * listen keyboard command\n */\nconst enableShortcuts = (): void => {\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(true);\n process.stdin.on('data', onKeyPress).setEncoding('utf8').resume();\n }\n};\n\nconst program = new Command();\n\nprogram\n .name(cliName)\n .description(description)\n .version(version)\n .hook('preAction', (_, actionCommand) => {\n // pass cli action to plugin config\n global.viteBoostAction = actionCommand.name();\n });\n\n/**\n * Common options\n */\nconst hostOption = new Option(\n '--host',\n 'Ability to access the local instance on other devices under the same network.',\n).default(false);\nconst onlyClientOption = new Option('--only-client', 'Build/run only client side part.').default(\n false,\n);\nconst portOption = new Option('--port [port]', 'Server port.').default(3000);\n\n/**\n * Cli commands\n */\n\nprogram\n .command(CliActions.dev)\n .description('Run development server.')\n .addOption(hostOption)\n .addOption(new Option('--reset-cache', 'Clear vite cache before run.').default(false))\n .action(async ({ host, resetCache }) => {\n if (resetCache) {\n await viteResetCache();\n }\n\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runDev({ version, isHost: host, isPrintInfo });\n\n cliContext.server = server;\n cliContext.config = config;\n };\n\n cliContext.reboot = command;\n\n enableShortcuts();\n\n return command();\n });\n\nprogram\n .command(CliActions.build)\n .description('Create production build.')\n .addOption(onlyClientOption)\n .addOption(\n new Option(\n '--client-options [client-options]',\n 'Pass vite build options for client. Example: --client-options=\"--ssrManifest\"',\n )\n .env('VITE_BUILD_CLIENT_OPTIONS')\n .default(''),\n )\n .addOption(\n new Option('--server-options [server-options]', 'Pass vite build options for server.')\n .env('VITE_BUILD_SERVER_OPTIONS')\n .default(''),\n )\n .action(async ({ onlyClient, clientOptions, serverOptions }) => {\n await runBuild({ isOnlyClient: onlyClient, clientOptions, serverOptions });\n });\n\nprogram\n .command(CliActions.start)\n .description('Run production server.')\n .addOption(hostOption)\n .addOption(portOption)\n .addOption(onlyClientOption)\n .action(({ host, port, onlyClient }) => {\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runProd({\n version,\n isHost: host,\n isPrintInfo,\n port,\n onlyClient,\n });\n\n cliContext.server = server;\n cliContext.config = config;\n };\n\n cliContext.reboot = command;\n\n enableShortcuts();\n\n return command();\n });\n\nprogram\n .command(CliActions.preview)\n .description('Build and preview production.')\n .addOption(onlyClientOption)\n .addOption(hostOption)\n .addOption(portOption)\n .action(async ({ host, port, onlyClient }) => {\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runProd({\n version,\n isHost: host,\n isPrintInfo,\n port,\n onlyClient,\n });\n\n server.on('listening', () => {\n setTimeout(() => {\n config.getLogger().info(chalk.yellow('\\n Running preview mode... \\n'));\n }, 0);\n });\n\n cliContext.server = server;\n cliContext.config = config;\n };\n\n cliContext.reboot = command;\n\n enableShortcuts();\n\n const buildOptions = '-w';\n const build = runBuild({\n isWatch: true,\n isOnlyClient: onlyClient,\n clientOptions: buildOptions,\n serverOptions: buildOptions,\n });\n\n await Promise.all([command(), build]);\n });\n\nprogram.parse();\n"],"names":["description","version","JSON","parse","readFileSync","URL","url","enableShortcuts","process","stdin","isTTY","setRawMode","on","onKeyPress","setEncoding","resume","program","Command","name","cliName","hook","_","actionCommand","global","viteBoostAction","hostOption","Option","default","onlyClientOption","portOption","command","CliActions","dev","addOption","action","async","host","resetCache","viteResetCache","isPrintInfo","server","config","runDev","isHost","cliContext","reboot","build","env","onlyClient","clientOptions","serverOptions","runBuild","isOnlyClient","start","port","runProd","preview","setTimeout","getLogger","info","chalk","yellow","isWatch","Promise","all"],"mappings":";iZAiBA,MAAMA,YAAEA,EAAWC,QAAEA,GAAYC,KAAKC,MACpCC,EAAa,IAAIC,IAAI,6BAA8BC,KAAM,SAOrDC,EAAkB,KAClBC,QAAQC,MAAMC,QAChBF,QAAQC,MAAME,YAAW,GACzBH,QAAQC,MAAMG,GAAG,OAAQC,GAAYC,YAAY,QAAQC,SAC1D,EAGGC,EAAU,IAAIC,EAEpBD,EACGE,KAAKC,GACLnB,YAAYA,GACZC,QAAQA,GACRmB,KAAK,aAAa,CAACC,EAAGC,KAErBC,OAAOC,gBAAkBF,EAAcJ,MAAM,IAMjD,MAAMO,EAAa,IAAIC,EACrB,SACA,iFACAC,SAAQ,GACJC,EAAmB,IAAIF,EAAO,gBAAiB,oCAAoCC,SACvF,GAEIE,EAAa,IAAIH,EAAO,gBAAiB,gBAAgBC,QAAQ,KAMvEX,EACGc,QAAQC,EAAWC,KACnBhC,YAAY,2BACZiC,UAAUR,GACVQ,UAAU,IAAIP,EAAO,gBAAiB,gCAAgCC,SAAQ,IAC9EO,QAAOC,OAASC,OAAMC,iBACjBA,SACIC,IAGR,MAAMR,EAAUK,MAAOI,IACrB,MAAMC,OAAEA,EAAMC,OAAEA,SAAiBC,EAAO,CAAEzC,UAAS0C,OAAQP,EAAMG,gBAEjEK,EAAWJ,OAASA,EACpBI,EAAWH,OAASA,CAAM,EAO5B,OAJAG,EAAWC,OAASf,EAEpBvB,IAEOuB,GAAS,IAGpBd,EACGc,QAAQC,EAAWe,OACnB9C,YAAY,4BACZiC,UAAUL,GACVK,UACC,IAAIP,EACF,oCACA,iFAECqB,IAAI,6BACJpB,QAAQ,KAEZM,UACC,IAAIP,EAAO,oCAAqC,uCAC7CqB,IAAI,6BACJpB,QAAQ,KAEZO,QAAOC,OAASa,aAAYC,gBAAeC,0BACpCC,EAAS,CAAEC,aAAcJ,EAAYC,gBAAeC,iBAAgB,IAG9ElC,EACGc,QAAQC,EAAWsB,OACnBrD,YAAY,0BACZiC,UAAUR,GACVQ,UAAUJ,GACVI,UAAUL,GACVM,QAAO,EAAGE,OAAMkB,OAAMN,iBACrB,MAAMlB,EAAUK,MAAOI,IACrB,MAAMC,OAAEA,EAAMC,OAAEA,SAAiBc,EAAQ,CACvCtD,UACA0C,OAAQP,EACRG,cACAe,OACAN,eAGFJ,EAAWJ,OAASA,EACpBI,EAAWH,OAASA,CAAM,EAO5B,OAJAG,EAAWC,OAASf,EAEpBvB,IAEOuB,GAAS,IAGpBd,EACGc,QAAQC,EAAWyB,SACnBxD,YAAY,iCACZiC,UAAUL,GACVK,UAAUR,GACVQ,UAAUJ,GACVK,QAAOC,OAASC,OAAMkB,OAAMN,iBAC3B,MAAMlB,EAAUK,MAAOI,IACrB,MAAMC,OAAEA,EAAMC,OAAEA,SAAiBc,EAAQ,CACvCtD,UACA0C,OAAQP,EACRG,cACAe,OACAN,eAGFR,EAAO5B,GAAG,aAAa,KACrB6C,YAAW,KACThB,EAAOiB,YAAYC,KAAKC,EAAMC,OAAO,kCAAkC,GACtE,EAAE,IAGPjB,EAAWJ,OAASA,EACpBI,EAAWH,OAASA,CAAM,EAG5BG,EAAWC,OAASf,EAEpBvB,IAEA,MACMuC,EAAQK,EAAS,CACrBW,SAAS,EACTV,aAAcJ,EACdC,cAJmB,KAKnBC,cALmB,aAQfa,QAAQC,IAAI,CAAClC,IAAWgB,GAAO,IAGzC9B,EAAQb"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { NavigateProps } from 'react-router-dom';
|
|
3
|
+
interface INavigate {
|
|
4
|
+
status?: number;
|
|
5
|
+
}
|
|
6
|
+
type TProps = INavigate & NavigateProps;
|
|
7
|
+
/**
|
|
8
|
+
* React router navigate with server support
|
|
9
|
+
* @constructor
|
|
10
|
+
*/
|
|
11
|
+
declare const Navigate: FC<TProps>;
|
|
12
|
+
export { Navigate as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"react";import{Navigate as t}from"react-router-dom";import{useServerContext as r}from"../context/server.js";const o=({to:o,status:s=301,...a})=>{const n=r();if(!n.isServer)return e.createElement(t,{to:o,...a});if(n){const e="string"==typeof o?o:[o.pathname,o.search,o.hash].filter(Boolean).join("");n.response=new Response("",{status:s,headers:new Headers({Location:e})})}return null};export{o as default};
|
|
2
|
+
//# sourceMappingURL=navigate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigate.js","sources":["../../src/components/navigate.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport React from 'react';\nimport type { NavigateProps } from 'react-router-dom';\nimport { Navigate as DefaultNavigate } from 'react-router-dom';\nimport { useServerContext } from '@context/server';\n\ninterface INavigate {\n status?: number;\n}\n\ntype TProps = INavigate & NavigateProps;\n\n/**\n * React router navigate with server support\n * @constructor\n */\nconst Navigate: FC<TProps> = ({ to, status = 301, ...rest }) => {\n const context = useServerContext();\n\n if (!context.isServer) {\n return <DefaultNavigate to={to} {...rest} />;\n }\n\n if (context) {\n const location =\n typeof to === 'string' ? to : [to.pathname, to.search, to.hash].filter(Boolean).join('');\n\n context.response = new Response('', { status, headers: new Headers({ Location: location }) });\n }\n\n return null;\n};\n\nexport default Navigate;\n"],"names":["Navigate","to","status","rest","context","useServerContext","isServer","React","createElement","DefaultNavigate","location","pathname","search","hash","filter","Boolean","join","response","Response","headers","Headers","Location"],"mappings":"yHAgBA,MAAMA,EAAuB,EAAGC,KAAIC,SAAS,OAAQC,MACnD,MAAMC,EAAUC,IAEhB,IAAKD,EAAQE,SACX,OAAOC,EAAAC,cAACC,EAAgB,CAAAR,GAAIA,KAAQE,IAGtC,GAAIC,EAAS,CACX,MAAMM,EACU,iBAAPT,EAAkBA,EAAK,CAACA,EAAGU,SAAUV,EAAGW,OAAQX,EAAGY,MAAMC,OAAOC,SAASC,KAAK,IAEvFZ,EAAQa,SAAW,IAAIC,SAAS,GAAI,CAAEhB,SAAQiB,QAAS,IAAIC,QAAQ,CAAEC,SAAUX,KAChF,CAED,OAAO,IAAI"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
interface IStatusGate {
|
|
3
|
+
status: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Change server response status
|
|
7
|
+
* Example: <ResponseStatus status={400} />
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
10
|
+
declare const ResponseStatus: FC<IStatusGate>;
|
|
11
|
+
export { ResponseStatus as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-status.js","sources":["../../src/components/response-status.ts"],"sourcesContent":["import type { FC } from 'react';\nimport { useServerContext } from '@context/server';\n\ninterface IStatusGate {\n status: number;\n}\n\n/**\n * Change server response status\n * Example: <ResponseStatus status={400} />\n * @constructor\n */\nconst ResponseStatus: FC<IStatusGate> = ({ status }) => {\n const context = useServerContext();\n\n if (context.isServer) {\n context.response = new Response('', { status });\n }\n\n return null;\n};\n\nexport default ResponseStatus;\n"],"names":["ResponseStatus","status","context","useServerContext","isServer","response","Response"],"mappings":"wDAYA,MAAMA,EAAkC,EAAGC,aACzC,MAAMC,EAAUC,IAMhB,OAJID,EAAQE,WACVF,EAAQG,SAAW,IAAIC,SAAS,GAAI,CAAEL,YAGjC,IAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-actions.js","sources":["../../src/constants/cli-actions.ts"],"sourcesContent":["enum CliActions {\n dev = 'dev',\n build = 'build',\n start = 'start',\n preview = 'preview',\n}\n\nexport default CliActions;\n"],"names":["CliActions","CliActions$1"],"mappings":"AAAA,IAAKA,GAAL,SAAKA,GACHA,EAAA,IAAA,MACAA,EAAA,MAAA,QACAA,EAAA,MAAA,QACAA,EAAA,QAAA,SACD,CALD,CAAKA,IAAAA,EAKJ,CAAA,IAED,IAAAC,EAAeD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Server } from 'node:net';
|
|
3
|
+
import ServerConfig from "../services/server-config.js";
|
|
4
|
+
interface ICliContext {
|
|
5
|
+
isProd?: boolean;
|
|
6
|
+
server?: Server;
|
|
7
|
+
config?: ServerConfig;
|
|
8
|
+
reboot?: (isPrintInfo?: boolean) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Share CLI context
|
|
12
|
+
*/
|
|
13
|
+
declare const cliContext: ICliContext;
|
|
14
|
+
export { cliContext as default, ICliContext };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-context.js","sources":["../../src/constants/cli-context.ts"],"sourcesContent":["import type { Server } from 'node:net';\nimport type ServerConfig from '@services/server-config';\n\nexport interface ICliContext {\n isProd?: boolean;\n server?: Server;\n config?: ServerConfig;\n reboot?: (isPrintInfo?: boolean) => Promise<void>; // reboot dev server\n}\n\n/**\n * Share CLI context\n */\nconst cliContext: ICliContext = {\n isProd: false,\n};\n\nexport default cliContext;\n"],"names":["cliContext","isProd"],"mappings":"AAaA,MAAMA,EAA0B,CAC9BC,QAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-name.js","sources":["../../src/constants/cli-name.ts"],"sourcesContent":["export default 'ssr-boost';\n"],"names":["cliName"],"mappings":"AAAA,IAAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"chalk";import r from"../helpers/process-stop.js";const o=async({server:r,config:o})=>{const t=o?.getLogger(),i=await new Promise((e=>{r?.close(e)}));return await(o?.getVite()?.close()),!i||(t?.info(e.red(`failed to stop dev server: ${i}`)),!1)},t=[{key:"r",description:"restart server",action:async r=>{const{reboot:t,config:i}=r,s=i?.getLogger();s?.info(e.yellow("\nrestarting server...")),await o(r)&&(await(t?.(!1)),s?.info(e.green("server restarted successful.")))}},{key:"u",description:"show server url",action({config:e}){e?.getLogger()?.info(""),e?.getVite()?.printUrls()}},{key:"c",description:"clear console",isOnlyDev:!0,action({config:e}){e?.getLogger()?.clearScreen("error")}},{key:"o",description:"open in browser",isOnlyDev:!0,action({config:e}){e?.getVite()?.openBrowser()}},{key:"q",description:"quit",async action(e){await o(e),r()}}];export{t as default};
|
|
2
|
+
//# sourceMappingURL=cli-shortcuts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-shortcuts.js","sources":["../../src/constants/cli-shortcuts.ts"],"sourcesContent":["import chalk from 'chalk';\nimport type { ICliContext } from '@constants/cli-context';\nimport processStop from '@helpers/process-stop';\nimport type { IPluginOptions } from '../plugin';\n\n/**\n * Stop server\n */\nconst stopServer = async ({ server, config }: ICliContext): Promise<boolean> => {\n const Logger = config?.getLogger();\n\n // stop express server\n const err = await new Promise((resolve) => {\n server?.close(resolve);\n });\n\n // stop vite server\n await config?.getVite()?.close();\n\n if (err) {\n Logger?.info(chalk.red(`failed to stop dev server: ${err as string}`));\n\n return false;\n }\n\n return true;\n};\n\n/**\n * Default plugin shortcuts\n */\nconst shortcuts: NonNullable<IPluginOptions['customShortcuts']> = [\n {\n key: 'r',\n description: 'restart server',\n action: async (cliContext) => {\n const { reboot, config } = cliContext;\n const Logger = config?.getLogger();\n\n Logger?.info(chalk.yellow('\\nrestarting server...'));\n\n if (!(await stopServer(cliContext))) {\n return;\n }\n\n await reboot?.(false);\n Logger?.info(chalk.green('server restarted successful.'));\n },\n },\n {\n key: 'u',\n description: 'show server url',\n action({ config }) {\n config?.getLogger()?.info('');\n config?.getVite()?.printUrls();\n },\n },\n {\n key: 'c',\n description: 'clear console',\n isOnlyDev: true,\n action({ config }) {\n config?.getLogger()?.clearScreen('error');\n },\n },\n {\n key: 'o',\n description: 'open in browser',\n isOnlyDev: true,\n action({ config }) {\n config?.getVite()?.openBrowser();\n },\n },\n {\n key: 'q',\n description: 'quit',\n async action(cliContext) {\n await stopServer(cliContext);\n processStop();\n },\n },\n];\n\nexport default shortcuts;\n"],"names":["stopServer","async","server","config","Logger","getLogger","err","Promise","resolve","close","getVite","info","chalk","red","shortcuts","key","description","action","cliContext","reboot","yellow","green","printUrls","isOnlyDev","clearScreen","openBrowser","processStop"],"mappings":"+DAQA,MAAMA,EAAaC,OAASC,SAAQC,aAClC,MAAMC,EAASD,GAAQE,YAGjBC,QAAY,IAAIC,SAASC,IAC7BN,GAAQO,MAAMD,EAAQ,IAMxB,aAFML,GAAQO,WAAWD,UAErBH,IACFF,GAAQO,KAAKC,EAAMC,IAAI,8BAA8BP,OAE9C,EAGE,EAMPQ,EAA4D,CAChE,CACEC,IAAK,IACLC,YAAa,iBACbC,OAAQhB,MAAOiB,IACb,MAAMC,OAAEA,EAAMhB,OAAEA,GAAWe,EACrBd,EAASD,GAAQE,YAEvBD,GAAQO,KAAKC,EAAMQ,OAAO,iCAEdpB,EAAWkB,WAIjBC,KAAS,IACff,GAAQO,KAAKC,EAAMS,MAAM,iCAAgC,GAG7D,CACEN,IAAK,IACLC,YAAa,kBACbC,QAAOd,OAAEA,IACPA,GAAQE,aAAaM,KAAK,IAC1BR,GAAQO,WAAWY,WACpB,GAEH,CACEP,IAAK,IACLC,YAAa,gBACbO,WAAW,EACXN,QAAOd,OAAEA,IACPA,GAAQE,aAAamB,YAAY,QAClC,GAEH,CACET,IAAK,IACLC,YAAa,kBACbO,WAAW,EACXN,QAAOd,OAAEA,IACPA,GAAQO,WAAWe,aACpB,GAEH,CACEV,IAAK,IACLC,YAAa,OACbf,aAAaiB,SACLlB,EAAWkB,GACjBQ,GACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sources":["../../src/constants/common.ts"],"sourcesContent":["/* eslint-disable no-undef */\n// @ts-ignore\nconst IS_SSR_MODE = typeof __IS_SSR__ === 'undefined' ? true : __IS_SSR__; // build in SSR mode?\n\n// eslint-disable-next-line import/prefer-default-export\nexport { IS_SSR_MODE };\n"],"names":["IS_SSR_MODE","__IS_SSR__"],"mappings":"AAEA,MAAMA,EAAoC,oBAAfC,YAAoCA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-name.js","sources":["../../src/constants/plugin-name.ts"],"sourcesContent":["export default '@lomray/vite-ssr-boost';\n"],"names":["PLUGIN_NAME"],"mappings":"AAAA,IAAAA,EAAe"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-error.js","sources":["../../src/constants/stream-error.ts"],"sourcesContent":["/**\n * React stream errors\n */\nenum StreamError {\n RenderAborted = 'aborted',\n RenderTimeout = 'timeout',\n RenderCancel = 'cancel',\n Unknown = 'unknown',\n}\n\nexport default StreamError;\n"],"names":["StreamError","StreamError$1"],"mappings":"AAGA,IAAKA,GAAL,SAAKA,GACHA,EAAA,cAAA,UACAA,EAAA,cAAA,UACAA,EAAA,aAAA,SACAA,EAAA,QAAA,SACD,CALD,CAAKA,IAAAA,EAKJ,CAAA,IAED,IAAAC,EAAeD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { FC, PropsWithChildren } from "react";
|
|
4
|
+
interface IServerContext {
|
|
5
|
+
response: Response | null;
|
|
6
|
+
isServer: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Server application context
|
|
10
|
+
*/
|
|
11
|
+
declare const ServerContext: React.Context<IServerContext>;
|
|
12
|
+
interface IServerProvider {
|
|
13
|
+
context: Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Server application context provider
|
|
17
|
+
* @constructor
|
|
18
|
+
*/
|
|
19
|
+
declare const ServerProvider: FC<PropsWithChildren<IServerProvider>>;
|
|
20
|
+
declare const useServerContext: () => IServerContext;
|
|
21
|
+
export { IServerContext, IServerProvider, ServerContext, ServerProvider, useServerContext };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e,{useContext as r}from"react";const t=e.createContext({response:null,isServer:!1}),n=({children:r,context:n})=>e.createElement(t.Provider,{value:n,children:r}),o=()=>r(t);export{t as ServerContext,n as ServerProvider,o as useServerContext};
|
|
2
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sources":["../../src/context/server.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from 'react';\nimport React, { useContext } from 'react';\n\nexport interface IServerContext {\n response: Response | null;\n isServer: boolean;\n}\n\nconst initState = {\n response: null,\n isServer: false,\n};\n\n/**\n * Server application context\n */\nconst ServerContext = React.createContext<IServerContext>(initState);\n\nexport interface IServerProvider {\n context: Record<string, any>;\n}\n\n/**\n * Server application context provider\n * @constructor\n */\nconst ServerProvider: FC<PropsWithChildren<IServerProvider>> = ({ children, context }) => (\n <ServerContext.Provider value={context as IServerContext} children={children} />\n);\n\nconst useServerContext = (): IServerContext => useContext(ServerContext);\n\nexport { ServerContext, ServerProvider, useServerContext };\n"],"names":["ServerContext","React","createContext","response","isServer","ServerProvider","children","context","createElement","Provider","value","useServerContext","useContext"],"mappings":"sCAQA,MAQMA,EAAgBC,EAAMC,cARV,CAChBC,SAAU,KACVC,UAAU,IAgBNC,EAAyD,EAAGC,WAAUC,aAC1EN,EAAAO,cAACR,EAAcS,SAAS,CAAAC,MAAOH,EAA2BD,SAAUA,IAGhEK,EAAmB,IAAsBC,EAAWZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-custom-state.js","sources":["../../src/helpers/build-custom-state.ts"],"sourcesContent":["import type { IRenderOptions } from '@node/render';\n\n/**\n * Build custom state\n */\nfunction buildCustomState(initState?: ReturnType<NonNullable<IRenderOptions['getState']>>): string {\n const stateScripts = Object.entries(initState ?? {}).map(([key, state]) => {\n if (!key || !state || !Object.keys(state || {}).length) {\n return '';\n }\n\n return `<script async>window.${key} = ${JSON.stringify(state)}</script>`;\n });\n\n return stateScripts.join('').trim();\n}\n\nexport default buildCustomState;\n"],"names":["buildCustomState","initState","Object","entries","map","key","state","keys","length","JSON","stringify","join","trim"],"mappings":"AAKA,SAASA,EAAiBC,GASxB,OARqBC,OAAOC,QAAQF,GAAa,CAAA,GAAIG,KAAI,EAAEC,EAAKC,KACzDD,GAAQC,GAAUJ,OAAOK,KAAKD,GAAS,IAAIE,OAIzC,wBAAwBH,OAASI,KAAKC,UAAUJ,eAH9C,KAMSK,KAAK,IAAIC,MAC/B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import r from"./serialize-errors.js";function a(a){const{loaderData:t,actionData:o,errors:i}=a,s={loaderData:t,actionData:o,errors:r(i)};return`<script async>window.__staticRouterHydrationData = ${JSON.stringify(s)};<\/script>`}export{a as default};
|
|
2
|
+
//# sourceMappingURL=build-router-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-router-state.js","sources":["../../src/helpers/build-router-state.ts"],"sourcesContent":["import type { StaticHandlerContext } from 'react-router-dom/server';\nimport serializeErrors from '@helpers/serialize-errors';\n\n/**\n * Build router state\n */\nfunction buildRouterState(context: StaticHandlerContext): string {\n const { loaderData, actionData, errors } = context as StaticHandlerContext;\n const routerState = {\n loaderData,\n actionData,\n errors: serializeErrors(errors),\n };\n const json = JSON.stringify(routerState);\n\n return `<script async>window.__staticRouterHydrationData = ${json};</script>`;\n}\n\nexport default buildRouterState;\n"],"names":["buildRouterState","context","loaderData","actionData","errors","routerState","serializeErrors","JSON","stringify"],"mappings":"qCAMA,SAASA,EAAiBC,GACxB,MAAMC,WAAEA,EAAUC,WAAEA,EAAUC,OAAEA,GAAWH,EACrCI,EAAc,CAClBH,aACAC,aACAC,OAAQE,EAAgBF,IAI1B,MAAO,sDAFMG,KAAKC,UAAUH,eAG9B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Response as ExpressResponse } from 'express';
|
|
2
|
+
import { StaticHandlerContext } from 'react-router-dom/server';
|
|
3
|
+
/**
|
|
4
|
+
* Handle router or server context response
|
|
5
|
+
*/
|
|
6
|
+
declare const handleResponse: (res: ExpressResponse, response: Response | StaticHandlerContext | null, defaultStatus?: number) => number | undefined;
|
|
7
|
+
export { handleResponse as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-response.js","sources":["../../src/helpers/handle-response.ts"],"sourcesContent":["import type { Response as ExpressResponse } from 'express';\nimport type { StaticHandlerContext } from 'react-router-dom/server';\n\n/**\n * Handle router or server context response\n */\nconst handleResponse = (\n res: ExpressResponse,\n response: Response | StaticHandlerContext | null,\n defaultStatus = 200,\n): number | undefined => {\n if (!(response instanceof Response)) {\n return defaultStatus;\n }\n\n // redirect\n if (response.status >= 300 && response.status < 400) {\n res.redirect(response.status, response.headers.get('Location')!);\n\n return;\n }\n\n return response.status ?? defaultStatus;\n};\n\nexport default handleResponse;\n"],"names":["handleResponse","res","response","defaultStatus","Response","status","redirect","headers","get"],"mappings":"AAMM,MAAAA,EAAiB,CACrBC,EACAC,EACAC,EAAgB,MAEVD,aAAoBE,SAKtBF,EAASG,QAAU,KAAOH,EAASG,OAAS,SAC9CJ,EAAIK,SAASJ,EAASG,OAAQH,EAASK,QAAQC,IAAI,aAK9CN,EAASG,QAAUF,EAVjBA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import StreamError from "../constants/stream-error.js";
|
|
2
|
+
interface IObtainStreamErrorOut {
|
|
3
|
+
code: StreamError;
|
|
4
|
+
message: string;
|
|
5
|
+
original: unknown;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Get react stream error
|
|
9
|
+
*/
|
|
10
|
+
declare const obtainStreamError: (err: unknown) => IObtainStreamErrorOut;
|
|
11
|
+
export { obtainStreamError as default, IObtainStreamErrorOut };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"../constants/stream-error.js";const r=r=>{const o=(r?.message??"Unknown.").replace("Error: ","");return"The render was aborted by the server without a reason."===o?{code:e.RenderAborted,message:o,original:r}:{code:e.Unknown,message:o||"Unknown error",original:r}};export{r as default};
|
|
2
|
+
//# sourceMappingURL=obtain-stream-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"obtain-stream-error.js","sources":["../../src/helpers/obtain-stream-error.ts"],"sourcesContent":["import StreamError from '@constants/stream-error';\n\nexport interface IObtainStreamErrorOut {\n code: StreamError;\n message: string;\n original: unknown;\n}\n\n/**\n * Get react stream error\n */\nconst obtainStreamError = (err: unknown): IObtainStreamErrorOut => {\n const message = (err?.['message'] ?? 'Unknown.').replace('Error: ', '');\n\n if (message === 'The render was aborted by the server without a reason.') {\n return {\n code: StreamError.RenderAborted,\n message,\n original: err,\n };\n }\n\n return {\n code: StreamError.Unknown,\n message: message || 'Unknown error',\n original: err,\n };\n};\n\nexport default obtainStreamError;\n"],"names":["obtainStreamError","err","message","replace","code","StreamError","RenderAborted","original","Unknown"],"mappings":"4CAWA,MAAMA,EAAqBC,IACzB,MAAMC,GAAWD,GAAe,SAAK,YAAYE,QAAQ,UAAW,IAEpE,MAAgB,2DAAZD,EACK,CACLE,KAAMC,EAAYC,cAClBJ,UACAK,SAAUN,GAIP,CACLG,KAAMC,EAAYG,QAClBN,QAASA,GAAW,gBACpBK,SAAUN,EACX"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ResolvedConfig } from 'vite';
|
|
2
|
+
import CliActions from "../constants/cli-actions.js";
|
|
3
|
+
import { IPluginOptions } from "../plugin.js";
|
|
4
|
+
interface IPluginConfig extends Required<IPluginOptions> {
|
|
5
|
+
pluginPath: string;
|
|
6
|
+
action: CliActions;
|
|
7
|
+
isDev: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get plugin config from vite config
|
|
11
|
+
*/
|
|
12
|
+
declare function getPluginConfig(viteConfig: ResolvedConfig): IPluginConfig;
|
|
13
|
+
export { getPluginConfig as default, IPluginConfig };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import n from"../constants/plugin-name.js";function t(t){const o=t.plugins.find((t=>t.name===n))?.pluginOptions;if(!o)throw new Error(`Failed to get to plugin config. Make sure you add the plugin '${n}' to the VITE config.`);return o}export{t as default};
|
|
2
|
+
//# sourceMappingURL=plugin-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-config.js","sources":["../../src/helpers/plugin-config.ts"],"sourcesContent":["import type { ResolvedConfig } from 'vite';\nimport type CliActions from '@constants/cli-actions';\nimport PLUGIN_NAME from '@constants/plugin-name';\nimport type { IPluginOptions } from '../plugin';\n\nexport interface IPluginConfig extends Required<IPluginOptions> {\n pluginPath: string;\n action: CliActions;\n isDev: boolean;\n}\n\n/**\n * Get plugin config from vite config\n */\nfunction getPluginConfig(viteConfig: ResolvedConfig): IPluginConfig {\n const pluginOptions = viteConfig.plugins.find((plugin) => plugin.name === PLUGIN_NAME)?.[\n 'pluginOptions'\n ] as unknown as IPluginConfig;\n\n if (!pluginOptions) {\n throw new Error(\n `Failed to get to plugin config. Make sure you add the plugin '${PLUGIN_NAME}' to the VITE config.`,\n );\n }\n\n return pluginOptions;\n}\n\nexport default getPluginConfig;\n"],"names":["getPluginConfig","viteConfig","pluginOptions","plugins","find","plugin","name","PLUGIN_NAME","Error"],"mappings":"2CAcA,SAASA,EAAgBC,GACvB,MAAMC,EAAgBD,EAAWE,QAAQC,MAAMC,GAAWA,EAAOC,OAASC,KACzD,cAGjB,IAAKL,EACH,MAAM,IAAIM,MACR,iEAAiED,0BAIrE,OAAOL,CACT"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Server } from 'node:net';
|
|
3
|
+
import ServerConfig from "../services/server-config.js";
|
|
4
|
+
interface IPrintServerInfoParams {
|
|
5
|
+
version?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Print server info
|
|
9
|
+
*/
|
|
10
|
+
declare function printServerInfo(server: Server, config: ServerConfig, { version }: IPrintServerInfoParams): Promise<void>;
|
|
11
|
+
export { printServerInfo as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{performance as o}from"node:perf_hooks";import e from"chalk";import r from"../constants/cli-actions.js";import s from"../constants/cli-name.js";import t from"./print-server-urls.js";import n from"./resolve-server-urls.js";async function i(i,a,{version:l="unknown"}){const{action:m}=a.getPluginConfig()??{},{isProd:p,host:f}=a.getParams(),c=a.getLogger(),d=global.viteBoostStartTime??o.now(),g=e.dim(`ready in ${e.reset(e.bold(Math.ceil(o.now()-d)))} ms`);c.info(`\n ${e.green(`${e.bold(s.toUpperCase())} v${l}${p?e.blue(" PRODUCTION"):""}`)} ${g}\n`,{clear:!c.hasWarned});const h=a.getVite()?.config,v=await n(i,{host:f,isHttps:"boolean"==typeof h?.server.https&&h?.server.https,rawBase:h?.rawBase});if(p)t(v,(o=>c.info(o)));else{const o=a.getVite();o.resolvedUrls=v,o.printUrls()}m===r.dev&&c.info(e.dim(e.green(" ➜"))+e.dim(" press ")+e.bold("h")+e.dim(" to show help"))}export{i as default};
|
|
2
|
+
//# sourceMappingURL=print-server-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print-server-info.js","sources":["../../src/helpers/print-server-info.ts"],"sourcesContent":["import type { Server } from 'node:net';\nimport { performance } from 'node:perf_hooks';\nimport chalk from 'chalk';\nimport CliActions from '@constants/cli-actions';\nimport cliName from '@constants/cli-name';\nimport printServerUrls from '@helpers/print-server-urls';\nimport resolveServerUrls from '@helpers/resolve-server-urls';\nimport type ServerConfig from '@services/server-config';\n\ninterface IPrintServerInfoParams {\n version?: string;\n}\n\n/**\n * Print server info\n */\nasync function printServerInfo(\n server: Server,\n config: ServerConfig,\n { version = 'unknown' }: IPrintServerInfoParams,\n): Promise<void> {\n const { action } = config.getPluginConfig() ?? {};\n const { isProd, host } = config.getParams();\n\n const Logger = config.getLogger();\n const perfStart = global.viteBoostStartTime ?? performance.now();\n const startupDurationString = chalk.dim(\n `ready in ${chalk.reset(chalk.bold(Math.ceil(performance.now() - perfStart)))} ms`,\n );\n\n Logger.info(\n `\\n ${chalk.green(\n `${chalk.bold(cliName.toUpperCase())} v${version}${isProd ? chalk.blue(' PRODUCTION') : ''}`,\n )} ${startupDurationString}\\n`,\n { clear: !Logger.hasWarned },\n );\n\n const viteConfig = config.getVite()?.config;\n const resolvedUrls = await resolveServerUrls(server, {\n host,\n isHttps: typeof viteConfig?.server.https === 'boolean' ? viteConfig?.server.https : false,\n rawBase: viteConfig?.['rawBase'],\n });\n\n if (!isProd) {\n const vite = config.getVite()!;\n\n vite.resolvedUrls = resolvedUrls;\n vite.printUrls();\n } else {\n printServerUrls(resolvedUrls, (msg) => Logger.info(msg));\n }\n\n if (action === CliActions.dev) {\n Logger.info(\n chalk.dim(chalk.green(' ➜')) +\n chalk.dim(' press ') +\n chalk.bold('h') +\n chalk.dim(' to show help'),\n );\n }\n}\n\nexport default printServerInfo;\n"],"names":["async","printServerInfo","server","config","version","action","getPluginConfig","isProd","host","getParams","Logger","getLogger","perfStart","global","viteBoostStartTime","performance","now","startupDurationString","chalk","dim","reset","bold","Math","ceil","info","green","cliName","toUpperCase","blue","clear","hasWarned","viteConfig","getVite","resolvedUrls","resolveServerUrls","isHttps","https","rawBase","printServerUrls","msg","vite","printUrls","CliActions","dev"],"mappings":"oOAgBAA,eAAeC,EACbC,EACAC,GACAC,QAAEA,EAAU,YAEZ,MAAMC,OAAEA,GAAWF,EAAOG,mBAAqB,CAAA,GACzCC,OAAEA,EAAMC,KAAEA,GAASL,EAAOM,YAE1BC,EAASP,EAAOQ,YAChBC,EAAYC,OAAOC,oBAAsBC,EAAYC,MACrDC,EAAwBC,EAAMC,IAClC,YAAYD,EAAME,MAAMF,EAAMG,KAAKC,KAAKC,KAAKR,EAAYC,MAAQJ,WAGnEF,EAAOc,KACL,OAAON,EAAMO,MACX,GAAGP,EAAMG,KAAKK,EAAQC,mBAAmBvB,IAAUG,EAASW,EAAMU,KAAK,eAAiB,UACpFX,MACN,CAAEY,OAAQnB,EAAOoB,YAGnB,MAAMC,EAAa5B,EAAO6B,WAAW7B,OAC/B8B,QAAqBC,EAAkBhC,EAAQ,CACnDM,OACA2B,QAA6C,kBAA7BJ,GAAY7B,OAAOkC,OAAsBL,GAAY7B,OAAOkC,MAC5EC,QAASN,GAAsB,UAGjC,GAAKxB,EAMH+B,EAAgBL,GAAeM,GAAQ7B,EAAOc,KAAKe,SANxC,CACX,MAAMC,EAAOrC,EAAO6B,UAEpBQ,EAAKP,aAAeA,EACpBO,EAAKC,WACN,CAIGpC,IAAWqC,EAAWC,KACxBjC,EAAOc,KACLN,EAAMC,IAAID,EAAMO,MAAM,QACpBP,EAAMC,IAAI,YACVD,EAAMG,KAAK,KACXH,EAAMC,IAAI,iBAGlB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Logger, ResolvedServerUrls } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Print server urls
|
|
4
|
+
* @see https://github.com/vitejs/vite/blob/711dd807610b39538e9955970145d52e4ca1d8c0/packages/vite/src/node/logger.ts#LL142C1-L162C2
|
|
5
|
+
* vite not export this function
|
|
6
|
+
*/
|
|
7
|
+
declare function printServerUrls(urls: ResolvedServerUrls, info: Logger['info']): void;
|
|
8
|
+
export { printServerUrls as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import o from"chalk";function e(e,r){const c=e=>o.cyan(e.replace(/:(\d+)\//,((e,r)=>`:${o.bold(r)}/`)));for(const l of e.local)r(` ${o.green("➜")} ${o.bold("Local")}: ${c(l)}`);for(const l of e.network)r(` ${o.green("➜")} ${o.bold("Network")}: ${c(l)}`)}export{e as default};
|
|
2
|
+
//# sourceMappingURL=print-server-urls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print-server-urls.js","sources":["../../src/helpers/print-server-urls.ts"],"sourcesContent":["import chalk from 'chalk';\nimport type { Logger, ResolvedServerUrls } from 'vite';\n\n/**\n * Print server urls\n * @see https://github.com/vitejs/vite/blob/711dd807610b39538e9955970145d52e4ca1d8c0/packages/vite/src/node/logger.ts#LL142C1-L162C2\n * vite not export this function\n */\nfunction printServerUrls(urls: ResolvedServerUrls, info: Logger['info']): void {\n const colorUrl = (url: string) =>\n chalk.cyan(url.replace(/:(\\d+)\\//, (_, port) => `:${chalk.bold(port)}/`));\n for (const url of urls.local) {\n info(` ${chalk.green('➜')} ${chalk.bold('Local')}: ${colorUrl(url)}`);\n }\n for (const url of urls.network) {\n info(` ${chalk.green('➜')} ${chalk.bold('Network')}: ${colorUrl(url)}`);\n }\n}\n\nexport default printServerUrls;\n"],"names":["printServerUrls","urls","info","colorUrl","url","chalk","cyan","replace","_","port","bold","local","green","network"],"mappings":"qBAQA,SAASA,EAAgBC,EAA0BC,GACjD,MAAMC,EAAYC,GAChBC,EAAMC,KAAKF,EAAIG,QAAQ,YAAY,CAACC,EAAGC,IAAS,IAAIJ,EAAMK,KAAKD,SACjE,IAAK,MAAML,KAAOH,EAAKU,MACrBT,EAAK,KAAKG,EAAMO,MAAM,SAASP,EAAMK,KAAK,eAAeP,EAASC,MAEpE,IAAK,MAAMA,KAAOH,EAAKY,QACrBX,EAAK,KAAKG,EAAMO,MAAM,SAASP,EAAMK,KAAK,eAAeP,EAASC,KAEtE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-stop.js","sources":["../../src/helpers/process-stop.ts"],"sourcesContent":["import process from 'node:process';\n\n/**\n * Stop node process\n */\nconst processStop = (code = 0) => process.exit(code);\n\nexport default processStop;\n"],"names":["processStop","code","process","exit"],"mappings":"4BAKA,MAAMA,EAAc,CAACC,EAAO,IAAMC,EAAQC,KAAKF"}
|