@lomray/vite-ssr-boost 3.3.5 → 4.0.0-beta.2
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 +2 -3
- package/browser/entry.js +1 -1
- package/browser/entry.js.map +1 -1
- package/cli/helpers/keyboard-input.js.map +1 -1
- package/cli/helpers/vite-reset-cache.js.map +1 -1
- package/cli/run-amplify-build.js.map +1 -1
- package/cli/run-docker-build.js.map +1 -1
- package/cli/run-vercel-build.js.map +1 -1
- package/cli.js.map +1 -1
- package/components/navigate.d.ts +1 -1
- package/components/navigate.js +1 -1
- package/components/navigate.js.map +1 -1
- package/components/scroll-to-top.js +1 -1
- package/components/scroll-to-top.js.map +1 -1
- package/helpers/build-router-state.d.ts +1 -1
- package/helpers/build-router-state.js.map +1 -1
- package/helpers/dev-marker.js.map +1 -1
- package/helpers/get-server-state.js.map +1 -1
- package/helpers/handle-response.d.ts +1 -1
- package/helpers/handle-response.js.map +1 -1
- package/helpers/import-route.d.ts +3 -243
- package/helpers/import-route.js.map +1 -1
- package/helpers/print-server-info.js.map +1 -1
- package/helpers/resolve-server-urls.js.map +1 -1
- package/helpers/serialize-errors.d.ts +1 -1
- package/helpers/serialize-errors.js +1 -1
- package/helpers/serialize-errors.js.map +1 -1
- package/helpers/ssr-meta.js.map +1 -1
- package/interfaces/fc-route.d.ts +2 -2
- package/interfaces/fc-route.js.map +1 -1
- package/interfaces/route-object.d.ts +1 -1
- package/node/entry.d.ts +1 -1
- package/node/entry.js +1 -1
- package/node/entry.js.map +1 -1
- package/node/render.d.ts +1 -2
- package/node/render.js +1 -1
- package/node/render.js.map +1 -1
- package/node/server.js.map +1 -1
- package/node/write-response.js.map +1 -1
- package/package.json +19 -19
- package/plugins/handle-custom-entrypoint.js.map +1 -1
- package/plugins/make-aliases.js.map +1 -1
- package/plugins/normalize-route.js.map +1 -1
- package/services/build.js.map +1 -1
- package/services/logger.js.map +1 -1
- package/services/parse-routes.js.map +1 -1
- package/services/path-normalize.js.map +1 -1
- package/services/prepare-server.js.map +1 -1
- package/services/server-api.js.map +1 -1
- package/services/server-config.js.map +1 -1
- package/services/ssr-manifest.d.ts +3 -4
- package/services/ssr-manifest.js.map +1 -1
package/browser/entry.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/// <reference types="react-dom" />
|
|
2
|
-
import { Router as RemixRouter } from '@remix-run/router/dist/router';
|
|
3
2
|
import { FC, PropsWithChildren } from 'react';
|
|
4
3
|
import ReactDOM from 'react-dom/client';
|
|
5
|
-
import { createBrowserRouter } from 'react-router
|
|
4
|
+
import { DataRouter, createBrowserRouter } from 'react-router';
|
|
6
5
|
import { TRouteObject } from "../interfaces/route-object.js";
|
|
7
6
|
interface IAppClientProps<T = undefined> {
|
|
8
7
|
client: T;
|
|
9
8
|
}
|
|
10
9
|
interface IInitPropsParams {
|
|
11
10
|
isSSRMode: boolean;
|
|
12
|
-
router:
|
|
11
|
+
router: DataRouter;
|
|
13
12
|
}
|
|
14
13
|
type TApp<T> = FC<PropsWithChildren<IAppClientProps<T>>>;
|
|
15
14
|
interface IEntryClientOptions<T> {
|
package/browser/entry.js
CHANGED
|
@@ -1,2 +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
|
|
1
|
+
import t from"react";import e from"react-dom/client";import{matchRoutes as o,createBrowserRouter as r,RouterProvider as a}from"react-router";import{IS_SSR_MODE as n}from"../constants/common.js";async function c(c,i,{init:l,routerOptions:m,createRouter:s=r,rootId:u="root"}={}){const d=o(i,window.location,m?.basename)?.filter((t=>t.route.lazy));d&&d?.length>0&&await Promise.all(d.map((async t=>{const e=await(t.route.lazy?.());Object.assign(t.route,{...e,lazy:void 0})})));const f=s(i,m),p=document.getElementById(u),y=await(l?.({isSSRMode:n,router:f})),w=()=>t.createElement(c,{client:y},t.createElement(a,{router:f}));return n&&"1"!==p.dataset.forceSpa?e.hydrateRoot(p,t.createElement(w,null)):e.createRoot(p).render(t.createElement(w,null))}export{c as default};
|
|
2
2
|
//# sourceMappingURL=entry.js.map
|
package/browser/entry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","sources":["../../src/browser/entry.tsx"],"sourcesContent":["import type {
|
|
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 { DataRouter, RouteObject } from 'react-router';\nimport { createBrowserRouter, matchRoutes, RouterProvider } from 'react-router';\nimport { IS_SSR_MODE } from '@constants/common';\nimport type { TRouteObject } from '@interfaces/route-object';\n\nexport interface IAppClientProps<T = undefined> {\n client: T;\n}\n\nexport interface IInitPropsParams {\n isSSRMode: boolean;\n router: DataRouter;\n}\n\nexport type TApp<T> = FC<PropsWithChildren<IAppClientProps<T>>>;\n\nexport interface IEntryClientOptions<T> {\n init?: (params: IInitPropsParams) => Promise<T>;\n routerOptions?: Parameters<typeof createBrowserRouter>[1];\n createRouter?: typeof createBrowserRouter;\n rootId?: string;\n}\n\n/**\n * Render client side application\n */\nasync function entry<TAppProps>(\n App: TApp<TAppProps>,\n routes: TRouteObject[],\n {\n init,\n routerOptions,\n createRouter = createBrowserRouter,\n rootId = 'root',\n }: IEntryClientOptions<TAppProps> = {},\n): Promise<ReactDOM.Root | void> {\n const lazyMatches = matchRoutes(\n routes as RouteObject[],\n window.location,\n routerOptions?.basename,\n )?.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 router = createRouter(routes as RouteObject[], routerOptions);\n const root = document.getElementById(rootId) as HTMLElement;\n const appProps = (await init?.({ isSSRMode: IS_SSR_MODE, router })) as TAppProps;\n\n const AppComponent: FC = () => (\n <App client={appProps}>\n <RouterProvider router={router} />\n </App>\n );\n\n if (!IS_SSR_MODE || root.dataset['forceSpa'] === '1') {\n return ReactDOM.createRoot(root).render(<AppComponent />);\n }\n\n return ReactDOM.hydrateRoot(root, <AppComponent />);\n}\n\nexport default entry;\n"],"names":["async","entry","App","routes","init","routerOptions","createRouter","createBrowserRouter","rootId","lazyMatches","matchRoutes","window","location","basename","filter","m","route","lazy","length","Promise","all","map","routeModule","Object","assign","undefined","router","root","document","getElementById","appProps","isSSRMode","IS_SSR_MODE","AppComponent","React","createElement","client","RouterProvider","dataset","ReactDOM","hydrateRoot","createRoot","render"],"mappings":"kMA6BAA,eAAeC,EACbC,EACAC,GACAC,KACEA,EAAIC,cACJA,EAAaC,aACbA,EAAeC,EAAmBC,OAClCA,EAAS,QACyB,CAAA,GAEpC,MAAMC,EAAcC,EAClBP,EACAQ,OAAOC,SACPP,GAAeQ,WACdC,QAAQC,GAAMA,EAAEC,MAAMC,OAIrBR,GAAeA,GAAaS,OAAS,SACjCC,QAAQC,IACZX,EAAYY,KAAIrB,MAAOe,IACrB,MAAMO,QAAoBP,EAAEC,MAAMC,UAElCM,OAAOC,OAAOT,EAAEC,MAAO,IAClBM,EACHL,UAAMQ,GACN,KAKR,MAAMC,EAASpB,EAAaH,EAAyBE,GAC/CsB,EAAOC,SAASC,eAAerB,GAC/BsB,QAAkB1B,IAAO,CAAE2B,UAAWC,EAAaN,YAEnDO,EAAmB,IACvBC,EAAAC,cAACjC,EAAG,CAACkC,OAAQN,GACXI,EAACC,cAAAE,GAAeX,OAAQA,KAI5B,OAAKM,GAA4C,MAA7BL,EAAKW,QAAkB,SAIpCC,EAASC,YAAYb,EAAMO,EAACC,cAAAF,EAAe,OAHzCM,EAASE,WAAWd,GAAMe,OAAOR,EAAAC,cAACF,EAAY,MAIzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard-input.js","sources":["../../../src/cli/helpers/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":"8MAMA,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,
|
|
1
|
+
{"version":3,"file":"keyboard-input.js","sources":["../../../src/cli/helpers/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":"8MAMA,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,CAAE,EAE1FM,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-reset-cache.js","sources":["../../../src/cli/helpers/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,
|
|
1
|
+
{"version":3,"file":"vite-reset-cache.js","sources":["../../../src/cli/helpers/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,CAAA,EAAI,UACjCC,SAAEA,GAAaF,EAEjBG,EAAGC,WAAWF,IAChBC,EAAGE,OAAOH,EAAU,CAAEI,WAAW,EAAMC,OAAO,IAGhDC,QAAQC,KAAKC,EAAMC,IAAID,EAAME,aAAa,wBAC5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-amplify-build.js","sources":["../../src/cli/run-amplify-build.ts"],"sourcesContent":["import type { ExecSyncOptions } from 'child_process';\nimport childProcess from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { cwd } from 'node:process';\nimport chalk from 'chalk';\nimport { resolveConfig } from 'vite';\nimport getPluginConfig from '@helpers/plugin-config';\n\ninterface IRunAmplifyBuildParams {\n manifestFile?: string;\n mode?: string;\n isOptimize?: boolean;\n}\n\n/**\n * Create AWS Amplify SSR build\n */\nasync function runAmplifyBuild({\n manifestFile,\n mode = '',\n isOptimize = false,\n}: IRunAmplifyBuildParams): Promise<void> {\n const config = await resolveConfig({}, 'build', mode);\n const pluginConfig = getPluginConfig(config);\n const {\n root,\n build: { outDir },\n } = config;\n const projectRoot = cwd();\n const buildDir = `.${path.resolve(root, outDir).replace(projectRoot, '')}`; // relative path\n const manFile = manifestFile || `${pluginConfig.pluginPath}/workflow/amplify-manifest.json`;\n const amplifyDir = `${projectRoot}/.amplify-hosting`;\n const computeDir = `${amplifyDir}/compute/default`;\n const stdOpts: ExecSyncOptions = {\n stdio: 'inherit',\n };\n\n // Check build server\n if (!fs.existsSync(`${buildDir}/server/start.js`)) {\n console.error(\n chalk.red(\n 'Failed create Amplify build: Before, you should create standard build with `eject` option.',\n ),\n );\n\n return;\n }\n\n if (fs.existsSync(amplifyDir)) {\n childProcess.execSync(`rm -rf ${amplifyDir}`, stdOpts);\n }\n\n fs.mkdirSync(computeDir, { recursive: true });\n childProcess.execSync(`cp -r ${buildDir} ${computeDir}/build`, stdOpts);\n childProcess.execSync(`cp ${projectRoot}/package.json ${computeDir}/package.json`, stdOpts);\n childProcess.execSync(\n `cp ${projectRoot}/package-lock.json ${computeDir}/package-lock.json`,\n stdOpts,\n );\n childProcess.execSync(`cp -r ${buildDir}/client ${amplifyDir}/static`, stdOpts);\n childProcess.execSync(`cp ${manFile} ${amplifyDir}/deploy-manifest.json`, stdOpts);\n childProcess.execSync(`cp -r ${projectRoot}/node_modules ${computeDir}/node_modules`);\n\n if (isOptimize) {\n childProcess.execSync(`cd ${computeDir} && npm ci --omit=dev`, stdOpts);\n }\n\n // cleanup\n childProcess.execSync(`rm -rf ${computeDir}/build/client/assets`, stdOpts);\n\n console.info(`\\n${chalk.cyan('AWS Amplify build success created.')}`);\n}\n\nexport default runAmplifyBuild;\n"],"names":["async","runAmplifyBuild","manifestFile","mode","isOptimize","config","resolveConfig","pluginConfig","getPluginConfig","root","build","outDir","projectRoot","cwd","buildDir","path","resolve","replace","manFile","pluginPath","amplifyDir","computeDir","stdOpts","stdio","fs","existsSync","childProcess","execSync","mkdirSync","recursive","console","info","chalk","cyan","error","red"],"mappings":"0NAkBAA,eAAeC,GAAgBC,aAC7BA,EAAYC,KACZA,EAAO,GAAEC,WACTA,GAAa,IAEb,MAAMC,QAAeC,EAAc,
|
|
1
|
+
{"version":3,"file":"run-amplify-build.js","sources":["../../src/cli/run-amplify-build.ts"],"sourcesContent":["import type { ExecSyncOptions } from 'child_process';\nimport childProcess from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { cwd } from 'node:process';\nimport chalk from 'chalk';\nimport { resolveConfig } from 'vite';\nimport getPluginConfig from '@helpers/plugin-config';\n\ninterface IRunAmplifyBuildParams {\n manifestFile?: string;\n mode?: string;\n isOptimize?: boolean;\n}\n\n/**\n * Create AWS Amplify SSR build\n */\nasync function runAmplifyBuild({\n manifestFile,\n mode = '',\n isOptimize = false,\n}: IRunAmplifyBuildParams): Promise<void> {\n const config = await resolveConfig({}, 'build', mode);\n const pluginConfig = getPluginConfig(config);\n const {\n root,\n build: { outDir },\n } = config;\n const projectRoot = cwd();\n const buildDir = `.${path.resolve(root, outDir).replace(projectRoot, '')}`; // relative path\n const manFile = manifestFile || `${pluginConfig.pluginPath}/workflow/amplify-manifest.json`;\n const amplifyDir = `${projectRoot}/.amplify-hosting`;\n const computeDir = `${amplifyDir}/compute/default`;\n const stdOpts: ExecSyncOptions = {\n stdio: 'inherit',\n };\n\n // Check build server\n if (!fs.existsSync(`${buildDir}/server/start.js`)) {\n console.error(\n chalk.red(\n 'Failed create Amplify build: Before, you should create standard build with `eject` option.',\n ),\n );\n\n return;\n }\n\n if (fs.existsSync(amplifyDir)) {\n childProcess.execSync(`rm -rf ${amplifyDir}`, stdOpts);\n }\n\n fs.mkdirSync(computeDir, { recursive: true });\n childProcess.execSync(`cp -r ${buildDir} ${computeDir}/build`, stdOpts);\n childProcess.execSync(`cp ${projectRoot}/package.json ${computeDir}/package.json`, stdOpts);\n childProcess.execSync(\n `cp ${projectRoot}/package-lock.json ${computeDir}/package-lock.json`,\n stdOpts,\n );\n childProcess.execSync(`cp -r ${buildDir}/client ${amplifyDir}/static`, stdOpts);\n childProcess.execSync(`cp ${manFile} ${amplifyDir}/deploy-manifest.json`, stdOpts);\n childProcess.execSync(`cp -r ${projectRoot}/node_modules ${computeDir}/node_modules`);\n\n if (isOptimize) {\n childProcess.execSync(`cd ${computeDir} && npm ci --omit=dev`, stdOpts);\n }\n\n // cleanup\n childProcess.execSync(`rm -rf ${computeDir}/build/client/assets`, stdOpts);\n\n console.info(`\\n${chalk.cyan('AWS Amplify build success created.')}`);\n}\n\nexport default runAmplifyBuild;\n"],"names":["async","runAmplifyBuild","manifestFile","mode","isOptimize","config","resolveConfig","pluginConfig","getPluginConfig","root","build","outDir","projectRoot","cwd","buildDir","path","resolve","replace","manFile","pluginPath","amplifyDir","computeDir","stdOpts","stdio","fs","existsSync","childProcess","execSync","mkdirSync","recursive","console","info","chalk","cyan","error","red"],"mappings":"0NAkBAA,eAAeC,GAAgBC,aAC7BA,EAAYC,KACZA,EAAO,GAAEC,WACTA,GAAa,IAEb,MAAMC,QAAeC,EAAc,CAAA,EAAI,QAASH,GAC1CI,EAAeC,EAAgBH,IAC/BI,KACJA,EACAC,OAAOC,OAAEA,IACPN,EACEO,EAAcC,IACdC,EAAW,IAAIC,EAAKC,QAAQP,EAAME,GAAQM,QAAQL,EAAa,MAC/DM,EAAUhB,GAAgB,GAAGK,EAAaY,4CAC1CC,EAAa,GAAGR,qBAChBS,EAAa,GAAGD,oBAChBE,EAA2B,CAC/BC,MAAO,WAIJC,EAAGC,WAAW,GAAGX,sBAUlBU,EAAGC,WAAWL,IAChBM,EAAaC,SAAS,UAAUP,IAAcE,GAGhDE,EAAGI,UAAUP,EAAY,CAAEQ,WAAW,IACtCH,EAAaC,SAAS,SAASb,KAAYO,UAAoBC,GAC/DI,EAAaC,SAAS,MAAMf,kBAA4BS,iBAA2BC,GACnFI,EAAaC,SACX,MAAMf,uBAAiCS,sBACvCC,GAEFI,EAAaC,SAAS,SAASb,YAAmBM,WAAqBE,GACvEI,EAAaC,SAAS,MAAMT,KAAWE,yBAAmCE,GAC1EI,EAAaC,SAAS,SAASf,kBAA4BS,kBAEvDjB,GACFsB,EAAaC,SAAS,MAAMN,yBAAmCC,GAIjEI,EAAaC,SAAS,UAAUN,wBAAkCC,GAElEQ,QAAQC,KAAK,KAAKC,EAAMC,KAAK,0CA/B3BH,QAAQI,MACNF,EAAMG,IACJ,8FA8BR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-docker-build.js","sources":["../../src/cli/run-docker-build.ts"],"sourcesContent":["import childProcess from 'node:child_process';\nimport path from 'node:path';\nimport { cwd } from 'node:process';\nimport { resolveConfig } from 'vite';\nimport createFocusOnly from '@helpers/create-focus-only';\nimport getPluginConfig from '@helpers/plugin-config';\nimport type { IBuildParams } from '@services/build';\n\ninterface IRunDockerBuildParams {\n imageName: string;\n dockerOptions?: string;\n dockerFile?: string;\n focusOnly?: IBuildParams['focusOnly'];\n mode?: string;\n}\n\n/**\n * Build docker image\n */\nasync function runDockerBuild({\n imageName,\n dockerFile,\n focusOnly,\n dockerOptions = '',\n mode = '',\n}: IRunDockerBuildParams): Promise<void> {\n const nodeEnv = mode === 'production' ? 'production' : 'development';\n const config = await resolveConfig({}, 'build', mode);\n const pluginConfig = getPluginConfig(config);\n const {\n root,\n build: { outDir },\n } = config;\n const projectRoot = cwd();\n const buildDir = `.${path.resolve(root, outDir).replace(projectRoot, '')}`; // relative path\n const runType = createFocusOnly(focusOnly).isOnlyClient() ? 'spa' : 'ssr';\n const docFile = dockerFile || `${pluginConfig.pluginPath}/workflow/Dockerfile`;\n\n childProcess.execSync(\n `docker build -f ${docFile}` +\n ` --build-arg BUILD_PATH=${buildDir}` +\n ` --build-arg RUN_TYPE=${runType} --build-arg ENV_MODE=${nodeEnv}` +\n ` ${dockerOptions} -t ${imageName} ${projectRoot}`,\n {\n stdio: 'inherit',\n env: {\n ...process.env,\n },\n },\n );\n}\n\nexport default runDockerBuild;\n"],"names":["async","runDockerBuild","imageName","dockerFile","focusOnly","dockerOptions","mode","nodeEnv","config","resolveConfig","pluginConfig","getPluginConfig","root","build","outDir","projectRoot","cwd","buildDir","path","resolve","replace","runType","createFocusOnly","isOnlyClient","docFile","pluginPath","childProcess","execSync","stdio","env","process"],"mappings":"6NAmBAA,eAAeC,GAAeC,UAC5BA,EAASC,WACTA,EAAUC,UACVA,EAASC,cACTA,EAAgB,GAAEC,KAClBA,EAAO,KAEP,MAAMC,EAAmB,eAATD,EAAwB,aAAe,cACjDE,QAAeC,EAAc,
|
|
1
|
+
{"version":3,"file":"run-docker-build.js","sources":["../../src/cli/run-docker-build.ts"],"sourcesContent":["import childProcess from 'node:child_process';\nimport path from 'node:path';\nimport { cwd } from 'node:process';\nimport { resolveConfig } from 'vite';\nimport createFocusOnly from '@helpers/create-focus-only';\nimport getPluginConfig from '@helpers/plugin-config';\nimport type { IBuildParams } from '@services/build';\n\ninterface IRunDockerBuildParams {\n imageName: string;\n dockerOptions?: string;\n dockerFile?: string;\n focusOnly?: IBuildParams['focusOnly'];\n mode?: string;\n}\n\n/**\n * Build docker image\n */\nasync function runDockerBuild({\n imageName,\n dockerFile,\n focusOnly,\n dockerOptions = '',\n mode = '',\n}: IRunDockerBuildParams): Promise<void> {\n const nodeEnv = mode === 'production' ? 'production' : 'development';\n const config = await resolveConfig({}, 'build', mode);\n const pluginConfig = getPluginConfig(config);\n const {\n root,\n build: { outDir },\n } = config;\n const projectRoot = cwd();\n const buildDir = `.${path.resolve(root, outDir).replace(projectRoot, '')}`; // relative path\n const runType = createFocusOnly(focusOnly).isOnlyClient() ? 'spa' : 'ssr';\n const docFile = dockerFile || `${pluginConfig.pluginPath}/workflow/Dockerfile`;\n\n childProcess.execSync(\n `docker build -f ${docFile}` +\n ` --build-arg BUILD_PATH=${buildDir}` +\n ` --build-arg RUN_TYPE=${runType} --build-arg ENV_MODE=${nodeEnv}` +\n ` ${dockerOptions} -t ${imageName} ${projectRoot}`,\n {\n stdio: 'inherit',\n env: {\n ...process.env,\n },\n },\n );\n}\n\nexport default runDockerBuild;\n"],"names":["async","runDockerBuild","imageName","dockerFile","focusOnly","dockerOptions","mode","nodeEnv","config","resolveConfig","pluginConfig","getPluginConfig","root","build","outDir","projectRoot","cwd","buildDir","path","resolve","replace","runType","createFocusOnly","isOnlyClient","docFile","pluginPath","childProcess","execSync","stdio","env","process"],"mappings":"6NAmBAA,eAAeC,GAAeC,UAC5BA,EAASC,WACTA,EAAUC,UACVA,EAASC,cACTA,EAAgB,GAAEC,KAClBA,EAAO,KAEP,MAAMC,EAAmB,eAATD,EAAwB,aAAe,cACjDE,QAAeC,EAAc,CAAA,EAAI,QAASH,GAC1CI,EAAeC,EAAgBH,IAC/BI,KACJA,EACAC,OAAOC,OAAEA,IACPN,EACEO,EAAcC,IACdC,EAAW,IAAIC,EAAKC,QAAQP,EAAME,GAAQM,QAAQL,EAAa,MAC/DM,EAAUC,EAAgBlB,GAAWmB,eAAiB,MAAQ,MAC9DC,EAAUrB,GAAc,GAAGO,EAAae,iCAE9CC,EAAaC,SACX,mBAAmBH,4BACUP,0BACFI,0BAAgCd,KACrDF,QAAoBH,KAAaa,IACvC,CACEa,MAAO,UACPC,IAAK,IACAC,QAAQD,MAInB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-vercel-build.js","sources":["../../src/cli/run-vercel-build.ts"],"sourcesContent":["import type { ExecSyncOptions } from 'child_process';\nimport childProcess from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { cwd } from 'node:process';\nimport chalk from 'chalk';\nimport { resolveConfig } from 'vite';\nimport getPluginConfig from '@helpers/plugin-config';\n\ninterface IRunVercelBuildParams {\n configFile?: string;\n configVcFile?: string;\n mode?: string;\n isOptimize?: boolean;\n}\n\n/**\n * Create Vercel SSR build\n */\nasync function runVercelBuild({\n configFile,\n configVcFile,\n mode = '',\n isOptimize = false,\n}: IRunVercelBuildParams): Promise<void> {\n const config = await resolveConfig({}, 'build', mode);\n const pluginConfig = getPluginConfig(config);\n const {\n root,\n build: { outDir },\n } = config;\n const projectRoot = cwd();\n const buildDir = `.${path.resolve(root, outDir).replace(projectRoot, '')}`; // relative path\n const manFile = configFile || `${pluginConfig.pluginPath}/workflow/vercel.config.json`;\n const manVcFile = configVcFile || `${pluginConfig.pluginPath}/workflow/vercel.vc-config.json`;\n const outputDir = `${projectRoot}/.vercel/output`;\n const stdOpts: ExecSyncOptions = {\n stdio: 'inherit',\n };\n\n // Check build serverless\n if (!fs.existsSync(`${buildDir}/server/serverless.js`)) {\n console.error(\n chalk.red(\n 'Failed create Vercel build: Before, you should create standard build with `serverless` option.',\n ),\n );\n\n return;\n }\n\n if (fs.existsSync(outputDir)) {\n childProcess.execSync(`rm -rf ${outputDir}`, stdOpts);\n }\n\n fs.mkdirSync(outputDir, { recursive: true });\n fs.mkdirSync(`${outputDir}/functions/index.func`, { recursive: true });\n childProcess.execSync(`cp ${manFile} ${outputDir}/config.json`, stdOpts);\n childProcess.execSync(\n `cp ${manVcFile} ${outputDir}/functions/index.func/.vc-config.json`,\n stdOpts,\n );\n childProcess.execSync(\n `cp ${buildDir}/server/serverless.js ${outputDir}/functions/index.func/index.js`,\n stdOpts,\n );\n childProcess.execSync(\n `cp -r ${projectRoot}/node_modules ${outputDir}/functions/index.func/node_modules`,\n stdOpts,\n );\n childProcess.execSync(`cp -r ${buildDir} ${outputDir}/functions/index.func/build`, stdOpts);\n childProcess.execSync(\n `cp -r ${projectRoot}/package.json ${outputDir}/functions/index.func/package.json`,\n stdOpts,\n );\n childProcess.execSync(\n `cp -r ${projectRoot}/package-lock.json ${outputDir}/functions/index.func/package-lock.json`,\n stdOpts,\n );\n childProcess.execSync(`cp -r ${buildDir}/client ${outputDir}/static`, stdOpts);\n\n if (isOptimize) {\n childProcess.execSync(`cd ${outputDir}/functions/index.func && npm ci --omit=dev`, stdOpts);\n }\n\n console.info(`\\n${chalk.cyan('Vercel build success created.')}`);\n}\n\nexport default runVercelBuild;\n"],"names":["async","runVercelBuild","configFile","configVcFile","mode","isOptimize","config","resolveConfig","pluginConfig","getPluginConfig","root","build","outDir","projectRoot","cwd","buildDir","path","resolve","replace","manFile","pluginPath","manVcFile","outputDir","stdOpts","stdio","fs","existsSync","childProcess","execSync","mkdirSync","recursive","console","info","chalk","cyan","error","red"],"mappings":"0NAmBAA,eAAeC,GAAeC,WAC5BA,EAAUC,aACVA,EAAYC,KACZA,EAAO,GAAEC,WACTA,GAAa,IAEb,MAAMC,QAAeC,EAAc,
|
|
1
|
+
{"version":3,"file":"run-vercel-build.js","sources":["../../src/cli/run-vercel-build.ts"],"sourcesContent":["import type { ExecSyncOptions } from 'child_process';\nimport childProcess from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { cwd } from 'node:process';\nimport chalk from 'chalk';\nimport { resolveConfig } from 'vite';\nimport getPluginConfig from '@helpers/plugin-config';\n\ninterface IRunVercelBuildParams {\n configFile?: string;\n configVcFile?: string;\n mode?: string;\n isOptimize?: boolean;\n}\n\n/**\n * Create Vercel SSR build\n */\nasync function runVercelBuild({\n configFile,\n configVcFile,\n mode = '',\n isOptimize = false,\n}: IRunVercelBuildParams): Promise<void> {\n const config = await resolveConfig({}, 'build', mode);\n const pluginConfig = getPluginConfig(config);\n const {\n root,\n build: { outDir },\n } = config;\n const projectRoot = cwd();\n const buildDir = `.${path.resolve(root, outDir).replace(projectRoot, '')}`; // relative path\n const manFile = configFile || `${pluginConfig.pluginPath}/workflow/vercel.config.json`;\n const manVcFile = configVcFile || `${pluginConfig.pluginPath}/workflow/vercel.vc-config.json`;\n const outputDir = `${projectRoot}/.vercel/output`;\n const stdOpts: ExecSyncOptions = {\n stdio: 'inherit',\n };\n\n // Check build serverless\n if (!fs.existsSync(`${buildDir}/server/serverless.js`)) {\n console.error(\n chalk.red(\n 'Failed create Vercel build: Before, you should create standard build with `serverless` option.',\n ),\n );\n\n return;\n }\n\n if (fs.existsSync(outputDir)) {\n childProcess.execSync(`rm -rf ${outputDir}`, stdOpts);\n }\n\n fs.mkdirSync(outputDir, { recursive: true });\n fs.mkdirSync(`${outputDir}/functions/index.func`, { recursive: true });\n childProcess.execSync(`cp ${manFile} ${outputDir}/config.json`, stdOpts);\n childProcess.execSync(\n `cp ${manVcFile} ${outputDir}/functions/index.func/.vc-config.json`,\n stdOpts,\n );\n childProcess.execSync(\n `cp ${buildDir}/server/serverless.js ${outputDir}/functions/index.func/index.js`,\n stdOpts,\n );\n childProcess.execSync(\n `cp -r ${projectRoot}/node_modules ${outputDir}/functions/index.func/node_modules`,\n stdOpts,\n );\n childProcess.execSync(`cp -r ${buildDir} ${outputDir}/functions/index.func/build`, stdOpts);\n childProcess.execSync(\n `cp -r ${projectRoot}/package.json ${outputDir}/functions/index.func/package.json`,\n stdOpts,\n );\n childProcess.execSync(\n `cp -r ${projectRoot}/package-lock.json ${outputDir}/functions/index.func/package-lock.json`,\n stdOpts,\n );\n childProcess.execSync(`cp -r ${buildDir}/client ${outputDir}/static`, stdOpts);\n\n if (isOptimize) {\n childProcess.execSync(`cd ${outputDir}/functions/index.func && npm ci --omit=dev`, stdOpts);\n }\n\n console.info(`\\n${chalk.cyan('Vercel build success created.')}`);\n}\n\nexport default runVercelBuild;\n"],"names":["async","runVercelBuild","configFile","configVcFile","mode","isOptimize","config","resolveConfig","pluginConfig","getPluginConfig","root","build","outDir","projectRoot","cwd","buildDir","path","resolve","replace","manFile","pluginPath","manVcFile","outputDir","stdOpts","stdio","fs","existsSync","childProcess","execSync","mkdirSync","recursive","console","info","chalk","cyan","error","red"],"mappings":"0NAmBAA,eAAeC,GAAeC,WAC5BA,EAAUC,aACVA,EAAYC,KACZA,EAAO,GAAEC,WACTA,GAAa,IAEb,MAAMC,QAAeC,EAAc,CAAA,EAAI,QAASH,GAC1CI,EAAeC,EAAgBH,IAC/BI,KACJA,EACAC,OAAOC,OAAEA,IACPN,EACEO,EAAcC,IACdC,EAAW,IAAIC,EAAKC,QAAQP,EAAME,GAAQM,QAAQL,EAAa,MAC/DM,EAAUjB,GAAc,GAAGM,EAAaY,yCACxCC,EAAYlB,GAAgB,GAAGK,EAAaY,4CAC5CE,EAAY,GAAGT,mBACfU,EAA2B,CAC/BC,MAAO,WAIJC,EAAGC,WAAW,GAAGX,2BAUlBU,EAAGC,WAAWJ,IAChBK,EAAaC,SAAS,UAAUN,IAAaC,GAG/CE,EAAGI,UAAUP,EAAW,CAAEQ,WAAW,IACrCL,EAAGI,UAAU,GAAGP,yBAAkC,CAAEQ,WAAW,IAC/DH,EAAaC,SAAS,MAAMT,KAAWG,gBAAyBC,GAChEI,EAAaC,SACX,MAAMP,KAAaC,yCACnBC,GAEFI,EAAaC,SACX,MAAMb,0BAAiCO,kCACvCC,GAEFI,EAAaC,SACX,SAASf,kBAA4BS,sCACrCC,GAEFI,EAAaC,SAAS,SAASb,KAAYO,+BAAwCC,GACnFI,EAAaC,SACX,SAASf,kBAA4BS,sCACrCC,GAEFI,EAAaC,SACX,SAASf,uBAAiCS,2CAC1CC,GAEFI,EAAaC,SAAS,SAASb,YAAmBO,WAAoBC,GAElElB,GACFsB,EAAaC,SAAS,MAAMN,8CAAuDC,GAGrFQ,QAAQC,KAAK,KAAKC,EAAMC,KAAK,qCA3C3BH,QAAQI,MACNF,EAAMG,IACJ,kGA0CR"}
|
package/cli.js.map
CHANGED
|
@@ -1 +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/helpers/keyboard-input';\nimport viteResetCache from '@cli/helpers/vite-reset-cache';\nimport type {\n IBuildActionParams,\n IBuildAmplifyActionParams,\n IBuildDockerActionParams,\n IBuildVercelActionParams,\n IDevActionParams,\n IPreviewActionParams,\n IStartActionParams,\n} from '@cli/interfaces/actions';\nimport runAmplifyBuild from '@cli/run-amplify-build';\nimport runDev from '@cli/run-dev';\nimport runDockerBuild from '@cli/run-docker-build';\nimport runProd from '@cli/run-prod';\nimport runVercelBuild from '@cli/run-vercel-build';\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 focusOnlyOption = new Option(\n '--focus-only [focusOnly]',\n 'Build or Start only specified part of app.',\n)\n .default('app')\n .choices(['all', 'app', 'client', 'server', 'entrypoint']);\nconst portOption = new Option('--port [port]', 'Server port.').default(3000);\nconst envModeOption = new Option('--mode [mode]', 'Env mode.')\n .env('VITE_ENV_MODE')\n .default('production');\nconst buildDirOption = new Option('--build-dir [buildDir]', 'Build directory output.');\n\n/**\n * Cli commands\n */\n\nprogram\n .command(CliActions.dev)\n .description('Run development server.')\n .addOption(hostOption)\n .addOption(portOption)\n .addOption(new Option('--reset-cache', 'Clear vite cache before run.').default(false))\n .addOption(new Option('--mode [mode]', 'Env mode.').env('VITE_ENV_MODE').default('development'))\n .addOption(new Option('--entrypoint [entrypoint]', 'Run only entrypoint by name.'))\n .action(async ({ host, port, resetCache, mode, entrypoint }: IDevActionParams) => {\n if (resetCache) {\n await viteResetCache();\n }\n\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n console.info(chalk.cyan('Starting the development server...'));\n\n const { server, config } = await runDev({\n version,\n isHost: host,\n isPrintInfo,\n port,\n mode,\n entrypointName: entrypoint,\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.build)\n .description('Create production build.')\n .addOption(focusOnlyOption)\n .addOption(envModeOption)\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 .addOption(\n new Option(\n '--unlock-robots',\n 'Change general directive Disallow to Allow in robots.txt',\n ).default(false),\n )\n .addOption(\n new Option('--eject', 'Produces entrypoint file to run app without cli').default(false),\n )\n .addOption(\n new Option(\n '--serverless',\n 'Produces entrypoint file to run app like serverless function',\n ).default(false),\n )\n .addOption(\n new Option(\n '--throw-warnings',\n 'The build will abort with an error if warnings occur in the process.',\n ).default(false),\n )\n .action(\n async ({\n focusOnly,\n clientOptions,\n serverOptions,\n mode,\n unlockRobots,\n eject,\n serverless,\n throwWarnings,\n }: IBuildActionParams) => {\n await runBuild({\n focusOnly,\n isUnlockRobots: unlockRobots,\n isNoWarnings: throwWarnings,\n isEject: eject,\n isServerless: serverless,\n clientOptions,\n serverOptions,\n mode: mode!,\n });\n },\n );\n\nprogram\n .command(CliActions.start)\n .description('Run production server.')\n .addOption(hostOption)\n .addOption(portOption)\n .addOption(focusOnlyOption)\n .addOption(buildDirOption)\n .addOption(\n new Option('--module-preload', 'Add module preload scripts to server output.').default(false),\n )\n .action(({ host, port, focusOnly, modulePreload, buildDir }: IStartActionParams) => {\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runProd({\n version,\n isHost: host,\n isPrintInfo,\n port,\n focusOnly,\n modulePreload,\n buildDir,\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(focusOnlyOption)\n .addOption(hostOption)\n .addOption(portOption)\n .addOption(envModeOption)\n .addOption(buildDirOption)\n .action(async ({ host, port, focusOnly, mode, buildDir }: IPreviewActionParams) => {\n global.viteBoostStartTime = performance.now();\n\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runProd({\n version,\n isHost: host,\n isPrintInfo,\n port,\n focusOnly,\n buildDir,\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\n await runBuild({\n mode: mode!,\n isWatch: true,\n focusOnly,\n clientOptions: buildOptions,\n serverOptions: buildOptions,\n onFinish: () => {\n void command();\n },\n });\n });\n\nprogram\n .command(CliActions.buildDocker)\n .description('Create docker image with production build.')\n .requiredOption('--image-name <image-name>', 'Docker image name.')\n .addOption(\n new Option(\n '--docker-options [docker-options]',\n 'Extra docker options which pass to docker build command.',\n ),\n )\n .addOption(\n new Option(\n '--docker-file [docker-file]',\n 'Name of the Dockerfile (Default is PLUGIN_PATH/workflow/Dockerfile).',\n ),\n )\n .addOption(focusOnlyOption)\n .addOption(envModeOption)\n .action(\n async ({ imageName, dockerOptions, dockerFile, focusOnly, mode }: IBuildDockerActionParams) => {\n await runDockerBuild({\n imageName,\n dockerOptions,\n dockerFile,\n focusOnly,\n mode,\n });\n },\n );\n\nprogram\n .command(CliActions.buildAmplify)\n .description('Create AWS Amplify production build.')\n .addOption(\n new Option(\n '--manifest-file [manifest-file]',\n 'Path to the Amplify manifest file (Default is PLUGIN_PATH/workflow/amplify-manifest.json).',\n ),\n )\n .addOption(new Option('--is-optimize', 'Optimize node_modules folder.').default(false))\n .addOption(envModeOption)\n .action(async ({ manifestFile, mode, isOptimize }: IBuildAmplifyActionParams) => {\n await runAmplifyBuild({\n manifestFile,\n mode,\n isOptimize,\n });\n });\n\nprogram\n .command(CliActions.buildVercel)\n .description('Create Vercel serverless production build.')\n .addOption(\n new Option(\n '--config-file [config-file]',\n 'Path to the Vercel config.json file (Default is PLUGIN_PATH/workflow/vercel.config.json).',\n ),\n )\n .addOption(\n new Option(\n '--config-vc-file [config-vc-file]',\n 'Path to the Vercel vc-config.json file (Default is PLUGIN_PATH/workflow/vercel.vc-config.json).',\n ),\n )\n .addOption(new Option('--is-optimize', 'Optimize node_modules folder.').default(false))\n .addOption(envModeOption)\n .action(async ({ configFile, configVcFile, mode, isOptimize }: IBuildVercelActionParams) => {\n await runVercelBuild({\n configFile,\n configVcFile,\n mode,\n isOptimize,\n });\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","focusOnlyOption","choices","portOption","envModeOption","env","buildDirOption","command","CliActions","dev","addOption","action","async","host","port","resetCache","mode","entrypoint","viteResetCache","isPrintInfo","console","info","chalk","cyan","server","config","runDev","isHost","entrypointName","cliContext","reboot","build","focusOnly","clientOptions","serverOptions","unlockRobots","eject","serverless","throwWarnings","runBuild","isUnlockRobots","isNoWarnings","isEject","isServerless","start","modulePreload","buildDir","runProd","preview","viteBoostStartTime","performance","now","setTimeout","getLogger","yellow","isWatch","onFinish","buildDocker","requiredOption","imageName","dockerOptions","dockerFile","runDockerBuild","buildAmplify","manifestFile","isOptimize","runAmplifyBuild","buildVercel","configFile","configVcFile","runVercelBuild"],"mappings":";6hBA6BA,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,EAAkB,IAAIF,EAC1B,2BACA,8CAECC,QAAQ,OACRE,QAAQ,CAAC,MAAO,MAAO,SAAU,SAAU,eACxCC,EAAa,IAAIJ,EAAO,gBAAiB,gBAAgBC,QAAQ,KACjEI,EAAgB,IAAIL,EAAO,gBAAiB,aAC/CM,IAAI,iBACJL,QAAQ,cACLM,EAAiB,IAAIP,EAAO,yBAA0B,2BAM5DV,EACGkB,QAAQC,EAAWC,KACnBpC,YAAY,2BACZqC,UAAUZ,GACVY,UAAUP,GACVO,UAAU,IAAIX,EAAO,gBAAiB,gCAAgCC,SAAQ,IAC9EU,UAAU,IAAIX,EAAO,gBAAiB,aAAaM,IAAI,iBAAiBL,QAAQ,gBAChFU,UAAU,IAAIX,EAAO,4BAA6B,iCAClDY,QAAOC,OAASC,OAAMC,OAAMC,aAAYC,OAAMC,iBACzCF,SACIG,IAGR,MAAMX,EAAUK,MAAOO,IACrBC,QAAQC,KAAKC,EAAMC,KAAK,uCAExB,MAAMC,OAAEA,EAAMC,OAAEA,SAAiBC,EAAO,CACtCpD,UACAqD,OAAQd,EACRM,cACAL,OACAE,OACAY,eAAgBX,IAGlBY,EAAWL,OAASA,EAC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,OACAiD,cACA,IAGN5E,EAAQb"}
|
|
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/helpers/keyboard-input';\nimport viteResetCache from '@cli/helpers/vite-reset-cache';\nimport type {\n IBuildActionParams,\n IBuildAmplifyActionParams,\n IBuildDockerActionParams,\n IBuildVercelActionParams,\n IDevActionParams,\n IPreviewActionParams,\n IStartActionParams,\n} from '@cli/interfaces/actions';\nimport runAmplifyBuild from '@cli/run-amplify-build';\nimport runDev from '@cli/run-dev';\nimport runDockerBuild from '@cli/run-docker-build';\nimport runProd from '@cli/run-prod';\nimport runVercelBuild from '@cli/run-vercel-build';\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 focusOnlyOption = new Option(\n '--focus-only [focusOnly]',\n 'Build or Start only specified part of app.',\n)\n .default('app')\n .choices(['all', 'app', 'client', 'server', 'entrypoint']);\nconst portOption = new Option('--port [port]', 'Server port.').default(3000);\nconst envModeOption = new Option('--mode [mode]', 'Env mode.')\n .env('VITE_ENV_MODE')\n .default('production');\nconst buildDirOption = new Option('--build-dir [buildDir]', 'Build directory output.');\n\n/**\n * Cli commands\n */\n\nprogram\n .command(CliActions.dev)\n .description('Run development server.')\n .addOption(hostOption)\n .addOption(portOption)\n .addOption(new Option('--reset-cache', 'Clear vite cache before run.').default(false))\n .addOption(new Option('--mode [mode]', 'Env mode.').env('VITE_ENV_MODE').default('development'))\n .addOption(new Option('--entrypoint [entrypoint]', 'Run only entrypoint by name.'))\n .action(async ({ host, port, resetCache, mode, entrypoint }: IDevActionParams) => {\n if (resetCache) {\n await viteResetCache();\n }\n\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n console.info(chalk.cyan('Starting the development server...'));\n\n const { server, config } = await runDev({\n version,\n isHost: host,\n isPrintInfo,\n port,\n mode,\n entrypointName: entrypoint,\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.build)\n .description('Create production build.')\n .addOption(focusOnlyOption)\n .addOption(envModeOption)\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 .addOption(\n new Option(\n '--unlock-robots',\n 'Change general directive Disallow to Allow in robots.txt',\n ).default(false),\n )\n .addOption(\n new Option('--eject', 'Produces entrypoint file to run app without cli').default(false),\n )\n .addOption(\n new Option(\n '--serverless',\n 'Produces entrypoint file to run app like serverless function',\n ).default(false),\n )\n .addOption(\n new Option(\n '--throw-warnings',\n 'The build will abort with an error if warnings occur in the process.',\n ).default(false),\n )\n .action(\n async ({\n focusOnly,\n clientOptions,\n serverOptions,\n mode,\n unlockRobots,\n eject,\n serverless,\n throwWarnings,\n }: IBuildActionParams) => {\n await runBuild({\n focusOnly,\n isUnlockRobots: unlockRobots,\n isNoWarnings: throwWarnings,\n isEject: eject,\n isServerless: serverless,\n clientOptions,\n serverOptions,\n mode: mode!,\n });\n },\n );\n\nprogram\n .command(CliActions.start)\n .description('Run production server.')\n .addOption(hostOption)\n .addOption(portOption)\n .addOption(focusOnlyOption)\n .addOption(buildDirOption)\n .addOption(\n new Option('--module-preload', 'Add module preload scripts to server output.').default(false),\n )\n .action(({ host, port, focusOnly, modulePreload, buildDir }: IStartActionParams) => {\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runProd({\n version,\n isHost: host,\n isPrintInfo,\n port,\n focusOnly,\n modulePreload,\n buildDir,\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(focusOnlyOption)\n .addOption(hostOption)\n .addOption(portOption)\n .addOption(envModeOption)\n .addOption(buildDirOption)\n .action(async ({ host, port, focusOnly, mode, buildDir }: IPreviewActionParams) => {\n global.viteBoostStartTime = performance.now();\n\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runProd({\n version,\n isHost: host,\n isPrintInfo,\n port,\n focusOnly,\n buildDir,\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\n await runBuild({\n mode: mode!,\n isWatch: true,\n focusOnly,\n clientOptions: buildOptions,\n serverOptions: buildOptions,\n onFinish: () => {\n void command();\n },\n });\n });\n\nprogram\n .command(CliActions.buildDocker)\n .description('Create docker image with production build.')\n .requiredOption('--image-name <image-name>', 'Docker image name.')\n .addOption(\n new Option(\n '--docker-options [docker-options]',\n 'Extra docker options which pass to docker build command.',\n ),\n )\n .addOption(\n new Option(\n '--docker-file [docker-file]',\n 'Name of the Dockerfile (Default is PLUGIN_PATH/workflow/Dockerfile).',\n ),\n )\n .addOption(focusOnlyOption)\n .addOption(envModeOption)\n .action(\n async ({ imageName, dockerOptions, dockerFile, focusOnly, mode }: IBuildDockerActionParams) => {\n await runDockerBuild({\n imageName,\n dockerOptions,\n dockerFile,\n focusOnly,\n mode,\n });\n },\n );\n\nprogram\n .command(CliActions.buildAmplify)\n .description('Create AWS Amplify production build.')\n .addOption(\n new Option(\n '--manifest-file [manifest-file]',\n 'Path to the Amplify manifest file (Default is PLUGIN_PATH/workflow/amplify-manifest.json).',\n ),\n )\n .addOption(new Option('--is-optimize', 'Optimize node_modules folder.').default(false))\n .addOption(envModeOption)\n .action(async ({ manifestFile, mode, isOptimize }: IBuildAmplifyActionParams) => {\n await runAmplifyBuild({\n manifestFile,\n mode,\n isOptimize,\n });\n });\n\nprogram\n .command(CliActions.buildVercel)\n .description('Create Vercel serverless production build.')\n .addOption(\n new Option(\n '--config-file [config-file]',\n 'Path to the Vercel config.json file (Default is PLUGIN_PATH/workflow/vercel.config.json).',\n ),\n )\n .addOption(\n new Option(\n '--config-vc-file [config-vc-file]',\n 'Path to the Vercel vc-config.json file (Default is PLUGIN_PATH/workflow/vercel.vc-config.json).',\n ),\n )\n .addOption(new Option('--is-optimize', 'Optimize node_modules folder.').default(false))\n .addOption(envModeOption)\n .action(async ({ configFile, configVcFile, mode, isOptimize }: IBuildVercelActionParams) => {\n await runVercelBuild({\n configFile,\n configVcFile,\n mode,\n isOptimize,\n });\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","focusOnlyOption","choices","portOption","envModeOption","env","buildDirOption","command","CliActions","dev","addOption","action","async","host","port","resetCache","mode","entrypoint","viteResetCache","isPrintInfo","console","info","chalk","cyan","server","config","runDev","isHost","entrypointName","cliContext","reboot","build","focusOnly","clientOptions","serverOptions","unlockRobots","eject","serverless","throwWarnings","runBuild","isUnlockRobots","isNoWarnings","isEject","isServerless","start","modulePreload","buildDir","runProd","preview","viteBoostStartTime","performance","now","setTimeout","getLogger","yellow","isWatch","onFinish","buildDocker","requiredOption","imageName","dockerOptions","dockerFile","runDockerBuild","buildAmplify","manifestFile","isOptimize","runAmplifyBuild","buildVercel","configFile","configVcFile","runVercelBuild"],"mappings":";6hBA6BA,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,WAIvDC,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,EAAkB,IAAIF,EAC1B,2BACA,8CAECC,QAAQ,OACRE,QAAQ,CAAC,MAAO,MAAO,SAAU,SAAU,eACxCC,EAAa,IAAIJ,EAAO,gBAAiB,gBAAgBC,QAAQ,KACjEI,EAAgB,IAAIL,EAAO,gBAAiB,aAC/CM,IAAI,iBACJL,QAAQ,cACLM,EAAiB,IAAIP,EAAO,yBAA0B,2BAM5DV,EACGkB,QAAQC,EAAWC,KACnBpC,YAAY,2BACZqC,UAAUZ,GACVY,UAAUP,GACVO,UAAU,IAAIX,EAAO,gBAAiB,gCAAgCC,SAAQ,IAC9EU,UAAU,IAAIX,EAAO,gBAAiB,aAAaM,IAAI,iBAAiBL,QAAQ,gBAChFU,UAAU,IAAIX,EAAO,4BAA6B,iCAClDY,QAAOC,OAASC,OAAMC,OAAMC,aAAYC,OAAMC,iBACzCF,SACIG,IAGR,MA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,8BACA,8FAGHW,UACC,IAAIX,EACF,oCACA,oGAGHW,UAAU,IAAIX,EAAO,gBAAiB,iCAAiCC,SAAQ,IAC/EU,UAAUN,GACVO,QAAOC,OAASwD,aAAYC,eAAcrD,OAAMiD,uBACzCK,EAAe,CACnBF,aACAC,eACArD,OACAiD,cACA,IAGN5E,EAAQb"}
|
package/components/navigate.d.ts
CHANGED
package/components/navigate.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"react";import{Navigate as t}from"react-router
|
|
1
|
+
import e from"react";import{Navigate as t}from"react-router";import{useServerContext as r}from"../context/server.js";const a=({to:a,status:o=301,...s})=>{const n=r();if(!n.isServer)return e.createElement(t,{to:a,...s});if(n){const{basename:e}=n,t=[e,"string"==typeof a?a:[a.pathname,a.search,a.hash]].flat().filter(Boolean).join("").replace(/\/+/g,"/");n.response=new Response("",{status:o,headers:new Headers({Location:t})})}return null};export{a as default};
|
|
2
2
|
//# sourceMappingURL=navigate.js.map
|
|
@@ -1 +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
|
|
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';\nimport { Navigate as DefaultNavigate } from 'react-router';\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 { basename } = context;\n const location = [basename, typeof to === 'string' ? to : [to.pathname, to.search, to.hash]]\n .flat()\n .filter(Boolean)\n .join('')\n .replace(/\\/+/g, '/');\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","basename","location","pathname","search","hash","flat","filter","Boolean","join","replace","response","Response","headers","Headers","Location"],"mappings":"qHAgBA,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,SAAEA,GAAaN,EACfO,EAAW,CAACD,EAAwB,iBAAPT,EAAkBA,EAAK,CAACA,EAAGW,SAAUX,EAAGY,OAAQZ,EAAGa,OACnFC,OACAC,OAAOC,SACPC,KAAK,IACLC,QAAQ,OAAQ,KAEnBf,EAAQgB,SAAW,IAAIC,SAAS,GAAI,CAAEnB,SAAQoB,QAAS,IAAIC,QAAQ,CAAEC,SAAUb,MAGjF,OAAO,IAAI"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useRef as r,useEffect as
|
|
1
|
+
import{useRef as r,useEffect as t}from"react";import{useLocation as o}from"react-router";const e=({shouldReloadReset:e=!1})=>{const{pathname:n}=o(),a=r(n);return t((()=>{(e||a.current!==n)&&(a.current=n,window.scrollTo(0,0))}),[n]),null};export{e as default};
|
|
2
2
|
//# sourceMappingURL=scroll-to-top.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-to-top.js","sources":["../../src/components/scroll-to-top.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { useEffect, useRef } from 'react';\nimport { useLocation } from 'react-router
|
|
1
|
+
{"version":3,"file":"scroll-to-top.js","sources":["../../src/components/scroll-to-top.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { useEffect, useRef } from 'react';\nimport { useLocation } from 'react-router';\n\ninterface IScrollToTop {\n shouldReloadReset?: boolean;\n}\n\n/**\n * Scroll page to top on every pathname (url) change\n * @constructor\n */\nconst ScrollToTop: FC<IScrollToTop> = ({ shouldReloadReset = false }) => {\n const { pathname } = useLocation();\n const prev = useRef(pathname);\n\n useEffect(() => {\n if (!shouldReloadReset && prev.current === pathname) {\n return;\n }\n\n prev.current = pathname;\n window.scrollTo(0, 0);\n }, [pathname]);\n\n return null;\n};\n\nexport default ScrollToTop;\n"],"names":["ScrollToTop","shouldReloadReset","pathname","useLocation","prev","useRef","useEffect","current","window","scrollTo"],"mappings":"yFAYM,MAAAA,EAAgC,EAAGC,qBAAoB,MAC3D,MAAMC,SAAEA,GAAaC,IACfC,EAAOC,EAAOH,GAWpB,OATAI,GAAU,MACHL,GAAqBG,EAAKG,UAAYL,KAI3CE,EAAKG,QAAUL,EACfM,OAAOC,SAAS,EAAG,GAAE,GACpB,CAACP,IAEG,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-router-state.js","sources":["../../src/helpers/build-router-state.ts"],"sourcesContent":["import type { StaticHandlerContext } from 'react-router
|
|
1
|
+
{"version":3,"file":"build-router-state.js","sources":["../../src/helpers/build-router-state.ts"],"sourcesContent":["import type { StaticHandlerContext } from 'react-router';\nimport htmlEscape from '@helpers/html-escape';\nimport serializeErrors from '@helpers/serialize-errors';\n\n/**\n * Build router state\n */\nfunction buildRouterState(context: StaticHandlerContext): string {\n const { loaderData, actionData, errors } = context;\n const routerState = {\n loaderData,\n actionData,\n errors: serializeErrors(errors),\n };\n const json = htmlEscape(JSON.stringify(JSON.stringify(routerState)));\n\n return `<script async>window.__staticRouterHydrationData = JSON.parse(${json});</script>`;\n}\n\nexport default buildRouterState;\n"],"names":["buildRouterState","context","loaderData","actionData","errors","routerState","serializeErrors","htmlEscape","JSON","stringify"],"mappings":"qEAOA,SAASA,EAAiBC,GACxB,MAAMC,WAAEA,EAAUC,WAAEA,EAAUC,OAAEA,GAAWH,EACrCI,EAAc,CAClBH,aACAC,aACAC,OAAQE,EAAgBF,IAI1B,MAAO,iEAFMG,EAAWC,KAAKC,UAAUD,KAAKC,UAAUJ,kBAGxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-marker.js","sources":["../../src/helpers/dev-marker.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport type { ResolvedConfig } from 'vite';\n\nconst getMarkerFile = (root: string, withFile = true): string =>\n [root, 'server', withFile && '.dev'].filter(Boolean).join('/');\n\n/**\n * Create dev marker\n *\n * @see printServerInfo\n */\nconst createDevMarker = (isProd: boolean, { root, build: buildConf }: ResolvedConfig): void => {\n const buildRoot = path.resolve(root, buildConf.outDir);\n const devMarkerPath = getMarkerFile(buildRoot, false);\n const devMarker = getMarkerFile(buildRoot);\n\n if (!isProd) {\n if (!fs.existsSync(devMarkerPath)) {\n fs.mkdirSync(devMarkerPath, { recursive: true });\n }\n\n fs.writeFileSync(devMarker, '');\n } else if (fs.existsSync(devMarker)) {\n fs.rmSync(devMarker);\n }\n};\n\nexport { createDevMarker, getMarkerFile };\n"],"names":["getMarkerFile","root","withFile","filter","Boolean","join","createDevMarker","isProd","build","buildConf","buildRoot","path","resolve","outDir","devMarkerPath","devMarker","fs","existsSync","rmSync","mkdirSync","recursive","writeFileSync"],"mappings":"gDAIA,MAAMA,EAAgB,CAACC,EAAcC,GAAW,IAC9C,CAACD,EAAM,SAAUC,GAAY,QAAQC,OAAOC,SAASC,KAAK,KAOtDC,EAAkB,CAACC,GAAmBN,OAAMO,MAAOC,MACvD,MAAMC,EAAYC,EAAKC,QAAQX,EAAMQ,EAAUI,QACzCC,EAAgBd,EAAcU,GAAW,GACzCK,EAAYf,EAAcU,GAE3BH,EAMMS,EAAGC,WAAWF,IACvBC,EAAGE,OAAOH,IANLC,EAAGC,WAAWH,IACjBE,EAAGG,UAAUL,EAAe,CAAEM,WAAW,IAG3CJ,EAAGK,cAAcN,EAAW
|
|
1
|
+
{"version":3,"file":"dev-marker.js","sources":["../../src/helpers/dev-marker.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport type { ResolvedConfig } from 'vite';\n\nconst getMarkerFile = (root: string, withFile = true): string =>\n [root, 'server', withFile && '.dev'].filter(Boolean).join('/');\n\n/**\n * Create dev marker\n *\n * @see printServerInfo\n */\nconst createDevMarker = (isProd: boolean, { root, build: buildConf }: ResolvedConfig): void => {\n const buildRoot = path.resolve(root, buildConf.outDir);\n const devMarkerPath = getMarkerFile(buildRoot, false);\n const devMarker = getMarkerFile(buildRoot);\n\n if (!isProd) {\n if (!fs.existsSync(devMarkerPath)) {\n fs.mkdirSync(devMarkerPath, { recursive: true });\n }\n\n fs.writeFileSync(devMarker, '');\n } else if (fs.existsSync(devMarker)) {\n fs.rmSync(devMarker);\n }\n};\n\nexport { createDevMarker, getMarkerFile };\n"],"names":["getMarkerFile","root","withFile","filter","Boolean","join","createDevMarker","isProd","build","buildConf","buildRoot","path","resolve","outDir","devMarkerPath","devMarker","fs","existsSync","rmSync","mkdirSync","recursive","writeFileSync"],"mappings":"gDAIA,MAAMA,EAAgB,CAACC,EAAcC,GAAW,IAC9C,CAACD,EAAM,SAAUC,GAAY,QAAQC,OAAOC,SAASC,KAAK,KAOtDC,EAAkB,CAACC,GAAmBN,OAAMO,MAAOC,MACvD,MAAMC,EAAYC,EAAKC,QAAQX,EAAMQ,EAAUI,QACzCC,EAAgBd,EAAcU,GAAW,GACzCK,EAAYf,EAAcU,GAE3BH,EAMMS,EAAGC,WAAWF,IACvBC,EAAGE,OAAOH,IANLC,EAAGC,WAAWH,IACjBE,EAAGG,UAAUL,EAAe,CAAEM,WAAW,IAG3CJ,EAAGK,cAAcN,EAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-server-state.js","sources":["../../src/helpers/get-server-state.ts"],"sourcesContent":["/**\n * Get server state on the client side\n */\nconst getServerState = <TP = Record<string, any>>(name: string, shouldRemove = true): TP => {\n const data = (window as Record<any, any>)[name] as TP;\n\n if (shouldRemove && data) {\n delete (window as Record<any, any>)[name];\n }\n\n return (data ?? {}) as TP;\n};\n\nexport default getServerState;\n"],"names":["getServerState","name","shouldRemove","data","window"],"mappings":"AAGM,MAAAA,EAAiB,CAA2BC,EAAcC,GAAe,KAC7E,MAAMC,EAAQC,OAA4BH,GAM1C,OAJIC,GAAgBC,UACVC,OAA4BH,GAG9BE,GAAQ,CAAA
|
|
1
|
+
{"version":3,"file":"get-server-state.js","sources":["../../src/helpers/get-server-state.ts"],"sourcesContent":["/**\n * Get server state on the client side\n */\nconst getServerState = <TP = Record<string, any>>(name: string, shouldRemove = true): TP => {\n const data = (window as Record<any, any>)[name] as TP;\n\n if (shouldRemove && data) {\n delete (window as Record<any, any>)[name];\n }\n\n return (data ?? {}) as TP;\n};\n\nexport default getServerState;\n"],"names":["getServerState","name","shouldRemove","data","window"],"mappings":"AAGM,MAAAA,EAAiB,CAA2BC,EAAcC,GAAe,KAC7E,MAAMC,EAAQC,OAA4BH,GAM1C,OAJIC,GAAgBC,UACVC,OAA4BH,GAG9BE,GAAQ,CAAE,CAAA"}
|
|
@@ -1 +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
|
|
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';\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"}
|
|
@@ -1,249 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import { IndexRouteObject, NonIndexRouteObject } from 'react-router-dom';
|
|
1
|
+
import { IndexRouteObject, NonIndexRouteObject } from 'react-router';
|
|
3
2
|
import { FCCRoute, FCRoute } from "../interfaces/fc-route.js";
|
|
4
|
-
declare enum ResultType {
|
|
5
|
-
data = "data",
|
|
6
|
-
deferred = "deferred",
|
|
7
|
-
redirect = "redirect",
|
|
8
|
-
error = "error"
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Successful result from a loader or action
|
|
12
|
-
*/
|
|
13
|
-
interface SuccessResult {
|
|
14
|
-
type: ResultType.data;
|
|
15
|
-
data: any;
|
|
16
|
-
statusCode?: number;
|
|
17
|
-
headers?: Headers;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Successful defer() result from a loader or action
|
|
21
|
-
*/
|
|
22
|
-
interface DeferredResult {
|
|
23
|
-
type: ResultType.deferred;
|
|
24
|
-
deferredData: DeferredData;
|
|
25
|
-
statusCode?: number;
|
|
26
|
-
headers?: Headers;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Redirect result from a loader or action
|
|
30
|
-
*/
|
|
31
|
-
interface RedirectResult {
|
|
32
|
-
type: ResultType.redirect;
|
|
33
|
-
status: number;
|
|
34
|
-
location: string;
|
|
35
|
-
revalidate: boolean;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Unsuccessful result from a loader or action
|
|
39
|
-
*/
|
|
40
|
-
interface ErrorResult {
|
|
41
|
-
type: ResultType.error;
|
|
42
|
-
error: any;
|
|
43
|
-
headers?: Headers;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Result from a loader or action - potentially successful or unsuccessful
|
|
47
|
-
*/
|
|
48
|
-
type DataResult = SuccessResult | DeferredResult | RedirectResult | ErrorResult;
|
|
49
|
-
type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
|
|
50
|
-
type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
|
|
51
|
-
/**
|
|
52
|
-
* Active navigation/fetcher form methods are exposed in lowercase on the
|
|
53
|
-
* RouterState
|
|
54
|
-
*/
|
|
55
|
-
type FormMethod = LowerCaseFormMethod;
|
|
56
|
-
/**
|
|
57
|
-
* In v7, active navigation/fetcher form methods are exposed in uppercase on the
|
|
58
|
-
* RouterState. This is to align with the normalization done via fetch().
|
|
59
|
-
*/
|
|
60
|
-
type V7_FormMethod = UpperCaseFormMethod;
|
|
61
|
-
type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data";
|
|
62
|
-
/**
|
|
63
|
-
* @private
|
|
64
|
-
* Internal interface to pass around for action submissions, not intended for
|
|
65
|
-
* external consumption
|
|
66
|
-
*/
|
|
67
|
-
interface Submission {
|
|
68
|
-
formMethod: FormMethod | V7_FormMethod;
|
|
69
|
-
formAction: string;
|
|
70
|
-
formEncType: FormEncType;
|
|
71
|
-
formData: FormData;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @private
|
|
75
|
-
* Arguments passed to route loader/action functions. Same for now but we keep
|
|
76
|
-
* this as a private implementation detail in case they diverge in the future.
|
|
77
|
-
*/
|
|
78
|
-
interface DataFunctionArgs {
|
|
79
|
-
request: Request;
|
|
80
|
-
params: Params;
|
|
81
|
-
context?: any;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Arguments passed to loader functions
|
|
85
|
-
*/
|
|
86
|
-
interface LoaderFunctionArgs extends DataFunctionArgs {
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Arguments passed to action functions
|
|
90
|
-
*/
|
|
91
|
-
interface ActionFunctionArgs extends DataFunctionArgs {
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Loaders and actions can return anything except `undefined` (`null` is a
|
|
95
|
-
* valid return value if there is no data to return). Responses are preferred
|
|
96
|
-
* and will ease any future migration to Remix
|
|
97
|
-
*/
|
|
98
|
-
type DataFunctionValue = Response | NonNullable<unknown> | null;
|
|
99
|
-
/**
|
|
100
|
-
* Route loader function signature
|
|
101
|
-
*/
|
|
102
|
-
interface LoaderFunction {
|
|
103
|
-
(args: LoaderFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Route action function signature
|
|
107
|
-
*/
|
|
108
|
-
interface ActionFunction {
|
|
109
|
-
(args: ActionFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Route shouldRevalidate function signature. This runs after any submission
|
|
113
|
-
* (navigation or fetcher), so we flatten the navigation/fetcher submission
|
|
114
|
-
* onto the arguments. It shouldn't matter whether it came from a navigation
|
|
115
|
-
* or a fetcher, what really matters is the URLs and the formData since loaders
|
|
116
|
-
* have to re-run based on the data models that were potentially mutated.
|
|
117
|
-
*/
|
|
118
|
-
interface ShouldRevalidateFunction {
|
|
119
|
-
(args: {
|
|
120
|
-
currentUrl: URL;
|
|
121
|
-
currentParams: AgnosticDataRouteMatch["params"];
|
|
122
|
-
nextUrl: URL;
|
|
123
|
-
nextParams: AgnosticDataRouteMatch["params"];
|
|
124
|
-
formMethod?: Submission["formMethod"];
|
|
125
|
-
formAction?: Submission["formAction"];
|
|
126
|
-
formEncType?: Submission["formEncType"];
|
|
127
|
-
formData?: Submission["formData"];
|
|
128
|
-
actionResult?: DataResult;
|
|
129
|
-
defaultShouldRevalidate: boolean;
|
|
130
|
-
}): boolean;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Keys we cannot change from within a lazy() function. We spread all other keys
|
|
134
|
-
* onto the route. Either they're meaningful to the router, or they'll get
|
|
135
|
-
* ignored.
|
|
136
|
-
*/
|
|
137
|
-
type ImmutableRouteKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
|
|
138
|
-
/**
|
|
139
|
-
* lazy() function to load a route definition, which can add non-matching
|
|
140
|
-
* related properties to a route
|
|
141
|
-
*/
|
|
142
|
-
interface LazyRouteFunction<R extends AgnosticRouteObject> {
|
|
143
|
-
(): Promise<Omit<R, ImmutableRouteKey>>;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Base RouteObject with common props shared by all types of routes
|
|
147
|
-
*/
|
|
148
|
-
type AgnosticBaseRouteObject = {
|
|
149
|
-
caseSensitive?: boolean;
|
|
150
|
-
path?: string;
|
|
151
|
-
id?: string;
|
|
152
|
-
loader?: LoaderFunction;
|
|
153
|
-
action?: ActionFunction;
|
|
154
|
-
hasErrorBoundary?: boolean;
|
|
155
|
-
shouldRevalidate?: ShouldRevalidateFunction;
|
|
156
|
-
handle?: any;
|
|
157
|
-
lazy?: LazyRouteFunction<AgnosticBaseRouteObject>;
|
|
158
|
-
};
|
|
159
|
-
/**
|
|
160
|
-
* Index routes must not have children
|
|
161
|
-
*/
|
|
162
|
-
type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
|
|
163
|
-
children?: undefined;
|
|
164
|
-
index: true;
|
|
165
|
-
};
|
|
166
|
-
/**
|
|
167
|
-
* Non-index routes may have children, but cannot have index
|
|
168
|
-
*/
|
|
169
|
-
type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
|
|
170
|
-
children?: AgnosticRouteObject[];
|
|
171
|
-
index?: false;
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* A route object represents a logical route, with (optionally) its child
|
|
175
|
-
* routes organized in a tree-like structure.
|
|
176
|
-
*/
|
|
177
|
-
type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
|
|
178
|
-
type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
|
|
179
|
-
id: string;
|
|
180
|
-
};
|
|
181
|
-
type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
|
|
182
|
-
children?: AgnosticDataRouteObject[];
|
|
183
|
-
id: string;
|
|
184
|
-
};
|
|
185
|
-
/**
|
|
186
|
-
* A data route object, which is just a RouteObject with a required unique ID
|
|
187
|
-
*/
|
|
188
|
-
type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
|
|
189
|
-
/**
|
|
190
|
-
* The parameters that were parsed from the URL path.
|
|
191
|
-
*/
|
|
192
|
-
type Params<Key extends string = string> = {
|
|
193
|
-
readonly [key in Key]: string | undefined;
|
|
194
|
-
};
|
|
195
|
-
/**
|
|
196
|
-
* A RouteMatch contains info about how a route matched a URL.
|
|
197
|
-
*/
|
|
198
|
-
interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
|
|
199
|
-
/**
|
|
200
|
-
* The names and values of dynamic parameters in the URL.
|
|
201
|
-
*/
|
|
202
|
-
params: Params<ParamKey>;
|
|
203
|
-
/**
|
|
204
|
-
* The portion of the URL pathname that was matched.
|
|
205
|
-
*/
|
|
206
|
-
pathname: string;
|
|
207
|
-
/**
|
|
208
|
-
* The portion of the URL pathname that was matched before child routes.
|
|
209
|
-
*/
|
|
210
|
-
pathnameBase: string;
|
|
211
|
-
/**
|
|
212
|
-
* The route object that was used to match.
|
|
213
|
-
*/
|
|
214
|
-
route: RouteObjectType;
|
|
215
|
-
}
|
|
216
|
-
interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
|
|
217
|
-
}
|
|
218
|
-
declare class DeferredData {
|
|
219
|
-
private pendingKeysSet;
|
|
220
|
-
private controller;
|
|
221
|
-
private abortPromise;
|
|
222
|
-
private unlistenAbortSignal;
|
|
223
|
-
private subscribers;
|
|
224
|
-
data: Record<string, unknown>;
|
|
225
|
-
init?: ResponseInit;
|
|
226
|
-
deferredKeys: string[];
|
|
227
|
-
constructor(data: Record<string, unknown>, responseInit?: ResponseInit);
|
|
228
|
-
private trackPromise;
|
|
229
|
-
private onSettle;
|
|
230
|
-
private emit;
|
|
231
|
-
subscribe(fn: (aborted: boolean, settledKey?: string) => void): () => boolean;
|
|
232
|
-
cancel(): void;
|
|
233
|
-
resolveData(signal: AbortSignal): Promise<boolean>;
|
|
234
|
-
get done(): boolean;
|
|
235
|
-
get unwrappedData(): {};
|
|
236
|
-
get pendingKeys(): string[];
|
|
237
|
-
}
|
|
238
|
-
type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
|
|
239
|
-
/**
|
|
240
|
-
* A redirect response. Sets the status code and the `Location` header.
|
|
241
|
-
* Defaults to "302 Found".
|
|
242
|
-
*/
|
|
243
|
-
declare const redirect: RedirectFunction;
|
|
244
3
|
type IDynamicRoute = () => Promise<{
|
|
245
4
|
default: FCRoute | FCCRoute<any>;
|
|
246
5
|
}>;
|
|
6
|
+
type ImmutableRouteKey = 'lazy' | 'caseSensitive' | 'path' | 'id' | 'index' | 'children';
|
|
247
7
|
type IAsyncRoute = {
|
|
248
8
|
pathId?: string;
|
|
249
9
|
} & (Omit<IndexRouteObject, ImmutableRouteKey> | Omit<NonIndexRouteObject, ImmutableRouteKey>);
|
|
@@ -251,4 +11,4 @@ type IAsyncRoute = {
|
|
|
251
11
|
* Import dynamic route
|
|
252
12
|
*/
|
|
253
13
|
declare const importRoute: (route: IDynamicRoute, id?: string) => (() => Promise<IAsyncRoute>);
|
|
254
|
-
export { importRoute as default, IDynamicRoute, IAsyncRoute };
|
|
14
|
+
export { importRoute as default, IDynamicRoute, ImmutableRouteKey, IAsyncRoute };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-route.js","sources":["../../src/helpers/import-route.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"import-route.js","sources":["../../src/helpers/import-route.ts"],"sourcesContent":["import type { IndexRouteObject, NonIndexRouteObject } from 'react-router';\nimport withSuspense from '@components/with-suspense';\nimport type { FCCRoute, FCRoute } from '@interfaces/fc-route';\nimport { keys } from '@interfaces/fc-route';\n\nexport type IDynamicRoute = () => Promise<{ default: FCRoute | FCCRoute<any> }>;\n\nexport type ImmutableRouteKey = 'lazy' | 'caseSensitive' | 'path' | 'id' | 'index' | 'children';\n\nexport type IAsyncRoute = { pathId?: string } & (\n | Omit<IndexRouteObject, ImmutableRouteKey>\n | Omit<NonIndexRouteObject, ImmutableRouteKey>\n);\n\n/**\n * Import dynamic route\n */\nconst importRoute = (route: IDynamicRoute, id?: string): (() => Promise<IAsyncRoute>) => {\n return async (): Promise<IAsyncRoute> => {\n const resolved = await route();\n\n // fallback to react router export style\n if ('Component' in resolved) {\n return { ...resolved, pathId: id } as IAsyncRoute;\n }\n\n const Component = resolved.default;\n const result: IAsyncRoute = { Component, pathId: id };\n\n keys.forEach((key) => {\n if (Component[key]) {\n // @ts-ignore\n result[key] = Component[key] as NonNullable<IAsyncRoute[typeof key]>;\n }\n });\n\n if (Component.Suspense) {\n result.Component = withSuspense(Component, Component.Suspense);\n }\n\n return result;\n };\n};\n\nexport default importRoute;\n"],"names":["importRoute","route","id","async","resolved","pathId","Component","default","result","keys","forEach","key","Suspense","withSuspense"],"mappings":"+FAiBA,MAAMA,EAAc,CAACC,EAAsBC,IAClCC,UACL,MAAMC,QAAiBH,IAGvB,GAAI,cAAeG,EACjB,MAAO,IAAKA,EAAUC,OAAQH,GAGhC,MAAMI,EAAYF,EAASG,QACrBC,EAAsB,CAAEF,YAAWD,OAAQH,GAajD,OAXAO,EAAKC,SAASC,IACRL,EAAUK,KAEZH,EAAOG,GAAOL,EAAUK,OAIxBL,EAAUM,WACZJ,EAAOF,UAAYO,EAAaP,EAAWA,EAAUM,WAGhDJ,CAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print-server-info.js","sources":["../../src/helpers/print-server-info.ts"],"sourcesContent":["import fs from 'node:fs';\nimport type { Server } from 'node:net';\nimport { performance } from 'node:perf_hooks';\nimport chalk from 'chalk';\nimport type { ResolvedConfig } from 'vite';\nimport CliActions from '@constants/cli-actions';\nimport cliName from '@constants/cli-name';\nimport { getMarkerFile } from '@helpers/dev-marker';\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 server?: Server;\n}\n\n/**\n * Print server info\n */\nasync function printServerInfo(\n config: ServerConfig,\n { server, version = 'unknown' }: IPrintServerInfoParams = {},\n): Promise<void> {\n const { action } = config.getPluginConfig() ?? {};\n const { isProd, host, root, isSPA } = config.getParams();\n const devMarker = getMarkerFile(root);\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}`,\n )} ${startupDurationString}\\n`,\n { clear: !Logger.hasWarned },\n );\n\n const viteConfig = config.getVite()?.config as\n | (ResolvedConfig & { rawBase?: string })\n | undefined;\n const isProdBuild = !viteConfig?.mode && !fs.existsSync(devMarker);\n const resolvedUrls = server\n ? await resolveServerUrls(server, {\n host,\n isHttps: Boolean(viteConfig?.server.https),\n rawBase: viteConfig?.rawBase,\n })\n : null;\n const mode =\n viteConfig?.mode || isProdBuild\n ? config.mode\n : `production ${chalk.red('NODE_ENV=development')}`;\n const type = isSPA ? 'SPA' : 'SSR';\n\n Logger.info(chalk.dim(chalk.green(' ➜')) + chalk.dim(' Mode: ') + chalk.blue(mode));\n Logger.info(chalk.dim(chalk.green(' ➜')) + chalk.dim(' Type: ') + chalk.blue(type));\n\n if (!isProd) {\n const vite = config.getVite()!;\n\n vite.resolvedUrls = resolvedUrls;\n vite.printUrls();\n } else if (resolvedUrls) {\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","config","server","version","action","getPluginConfig","isProd","host","root","isSPA","getParams","devMarker","getMarkerFile","Logger","getLogger","perfStart","global","viteBoostStartTime","performance","now","startupDurationString","chalk","dim","reset","bold","Math","ceil","info","green","cliName","toUpperCase","clear","hasWarned","viteConfig","getVite","isProdBuild","mode","fs","existsSync","resolvedUrls","resolveServerUrls","isHttps","Boolean","https","rawBase","red","type","blue","printServerUrls","msg","vite","printUrls","CliActions","dev"],"mappings":"2SAoBAA,eAAeC,EACbC,GACAC,OAAEA,EAAMC,QAAEA,EAAU,WAAsC,IAE1D,MAAMC,OAAEA,GAAWH,EAAOI,mBAAqB,
|
|
1
|
+
{"version":3,"file":"print-server-info.js","sources":["../../src/helpers/print-server-info.ts"],"sourcesContent":["import fs from 'node:fs';\nimport type { Server } from 'node:net';\nimport { performance } from 'node:perf_hooks';\nimport chalk from 'chalk';\nimport type { ResolvedConfig } from 'vite';\nimport CliActions from '@constants/cli-actions';\nimport cliName from '@constants/cli-name';\nimport { getMarkerFile } from '@helpers/dev-marker';\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 server?: Server;\n}\n\n/**\n * Print server info\n */\nasync function printServerInfo(\n config: ServerConfig,\n { server, version = 'unknown' }: IPrintServerInfoParams = {},\n): Promise<void> {\n const { action } = config.getPluginConfig() ?? {};\n const { isProd, host, root, isSPA } = config.getParams();\n const devMarker = getMarkerFile(root);\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}`,\n )} ${startupDurationString}\\n`,\n { clear: !Logger.hasWarned },\n );\n\n const viteConfig = config.getVite()?.config as\n | (ResolvedConfig & { rawBase?: string })\n | undefined;\n const isProdBuild = !viteConfig?.mode && !fs.existsSync(devMarker);\n const resolvedUrls = server\n ? await resolveServerUrls(server, {\n host,\n isHttps: Boolean(viteConfig?.server.https),\n rawBase: viteConfig?.rawBase,\n })\n : null;\n const mode =\n viteConfig?.mode || isProdBuild\n ? config.mode\n : `production ${chalk.red('NODE_ENV=development')}`;\n const type = isSPA ? 'SPA' : 'SSR';\n\n Logger.info(chalk.dim(chalk.green(' ➜')) + chalk.dim(' Mode: ') + chalk.blue(mode));\n Logger.info(chalk.dim(chalk.green(' ➜')) + chalk.dim(' Type: ') + chalk.blue(type));\n\n if (!isProd) {\n const vite = config.getVite()!;\n\n vite.resolvedUrls = resolvedUrls;\n vite.printUrls();\n } else if (resolvedUrls) {\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","config","server","version","action","getPluginConfig","isProd","host","root","isSPA","getParams","devMarker","getMarkerFile","Logger","getLogger","perfStart","global","viteBoostStartTime","performance","now","startupDurationString","chalk","dim","reset","bold","Math","ceil","info","green","cliName","toUpperCase","clear","hasWarned","viteConfig","getVite","isProdBuild","mode","fs","existsSync","resolvedUrls","resolveServerUrls","isHttps","Boolean","https","rawBase","red","type","blue","printServerUrls","msg","vite","printUrls","CliActions","dev"],"mappings":"2SAoBAA,eAAeC,EACbC,GACAC,OAAEA,EAAMC,QAAEA,EAAU,WAAsC,IAE1D,MAAMC,OAAEA,GAAWH,EAAOI,m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