@lomray/vite-ssr-boost 2.3.3 → 2.3.4
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.
|
@@ -250,5 +250,5 @@ type IAsyncRoute = {
|
|
|
250
250
|
/**
|
|
251
251
|
* Import dynamic route
|
|
252
252
|
*/
|
|
253
|
-
declare const importRoute: (route: IDynamicRoute, id?: string) => Promise<IAsyncRoute
|
|
253
|
+
declare const importRoute: (route: IDynamicRoute, id?: string) => (() => Promise<IAsyncRoute>);
|
|
254
254
|
export { importRoute as default, IDynamicRoute, IAsyncRoute };
|
package/helpers/import-route.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"../components/with-suspense.js";import{keys as n}from"../interfaces/fc-route.js";const e=
|
|
1
|
+
import t from"../components/with-suspense.js";import{keys as n}from"../interfaces/fc-route.js";const e=(e,o)=>async()=>{const s=await e();if("Component"in s)return{...s,pathId:o};const p=s.default,r={Component:p,pathId:o};return n.forEach((t=>{p[t]&&(r[t]=p[t])})),p.Suspense&&(r.Component=t(p,p.Suspense)),r};export{e as default};
|
|
2
2
|
//# sourceMappingURL=import-route.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-route.js","sources":["../../src/helpers/import-route.ts"],"sourcesContent":["import type { ImmutableRouteKey } from '@remix-run/router/utils';\nimport type { IndexRouteObject, NonIndexRouteObject } from 'react-router-dom';\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 IAsyncRoute = { pathId?: string } & (\n | Omit<IndexRouteObject, ImmutableRouteKey>\n | Omit<NonIndexRouteObject, ImmutableRouteKey>\n);\n\n/**\n * Import dynamic route\n */\nconst importRoute =
|
|
1
|
+
{"version":3,"file":"import-route.js","sources":["../../src/helpers/import-route.ts"],"sourcesContent":["import type { ImmutableRouteKey } from '@remix-run/router/utils';\nimport type { IndexRouteObject, NonIndexRouteObject } from 'react-router-dom';\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 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":"+FAgBA,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,GACzB,IAGCL,EAAUM,WACZJ,EAAOF,UAAYO,EAAaP,EAAWA,EAAUM,WAGhDJ,CAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lomray/vite-ssr-boost",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4",
|
|
4
4
|
"description": "Vite plugin for create awesome SSR or SPA applications on React.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -36,24 +36,24 @@
|
|
|
36
36
|
"chalk": "^5.3.0",
|
|
37
37
|
"commander": "^12.0.0",
|
|
38
38
|
"compression": "^1.7.4",
|
|
39
|
-
"express": "^4.18.
|
|
39
|
+
"express": "^4.18.3",
|
|
40
40
|
"hoist-non-react-statics": "^3.3.2",
|
|
41
41
|
"json5": "^2.2.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@commitlint/cli": "^19.
|
|
45
|
-
"@commitlint/config-conventional": "^19.0
|
|
44
|
+
"@commitlint/cli": "^19.2.1",
|
|
45
|
+
"@commitlint/config-conventional": "^19.1.0",
|
|
46
46
|
"@lomray/eslint-config-react": "^5.0.6",
|
|
47
47
|
"@lomray/prettier-config": "^2.0.1",
|
|
48
48
|
"@rollup/plugin-terser": "^0.4.4",
|
|
49
49
|
"@testing-library/react": "^14.2.1",
|
|
50
|
-
"@types/chai": "^4.3.
|
|
50
|
+
"@types/chai": "^4.3.13",
|
|
51
51
|
"@types/compression": "^1.7.5",
|
|
52
52
|
"@types/hoist-non-react-statics": "^3.3.5",
|
|
53
53
|
"@types/react-dom": "^18.2.19",
|
|
54
54
|
"@types/sinon": "^17.0.3",
|
|
55
55
|
"@types/sinon-chai": "^3.2.12",
|
|
56
|
-
"@vitest/coverage-v8": "^1.
|
|
56
|
+
"@vitest/coverage-v8": "^1.4.0",
|
|
57
57
|
"@zerollup/ts-transform-paths": "^1.7.18",
|
|
58
58
|
"chai": "^4.4.1",
|
|
59
59
|
"eslint": "^8.57.0",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"jsdom": "^24.0.0",
|
|
62
62
|
"lint-staged": "^15.2.2",
|
|
63
63
|
"prettier": "^3.2.5",
|
|
64
|
-
"rollup": "^4.
|
|
64
|
+
"rollup": "^4.13.0",
|
|
65
65
|
"rollup-plugin-copy": "^3.5.0",
|
|
66
66
|
"rollup-plugin-folder-input": "^1.0.1",
|
|
67
67
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"sinon": "^17.0.1",
|
|
72
72
|
"sinon-chai": "^3.7.0",
|
|
73
73
|
"typescript": "^5.3.3",
|
|
74
|
-
"vitest": "^1.
|
|
74
|
+
"vitest": "^1.4.0"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"@types/express": ">=4.17.21",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{extname as e}from"node:path";import r from"../constants/plugin-name.js";import t from"../helpers/is-route-file.js";const s=(e,r=!1)=>{if(r)return e;const t=[...e.matchAll(/import\s+(\w+)\sfrom\s+['"]([^'"]+)['"]/g)].reduce(((e,[,r,t])=>({[r]:t,...e})),{});return e.replace(/(.*?(?:Component|element):[\s<]*(\w+)[^,}]*),*/gs,((e,r,s)=>{const n=t?.[s];return n?`${r},pathId: '${n}',`:e}))},n=(e,t)=>{const s=e.replace(/(lazy)(:\s*)(\(\)\s*=>\s*import\(([^)]+)\))/gs,t?"lazy$
|
|
1
|
+
import{extname as e}from"node:path";import r from"../constants/plugin-name.js";import t from"../helpers/is-route-file.js";const s=(e,r=!1)=>{if(r)return e;const t=[...e.matchAll(/import\s+(\w+)\sfrom\s+['"]([^'"]+)['"]/g)].reduce(((e,[,r,t])=>({[r]:t,...e})),{});return e.replace(/(.*?(?:Component|element):[\s<]*(\w+)[^,}]*),*/gs,((e,r,s)=>{const n=t?.[s];return n?`${r},pathId: '${n}',`:e}))},n=(e,t)=>{const s=e.replace(/(lazy)(:\s*)(\(\)\s*=>\s*import\(([^)]+)\))/gs,t?"lazy$2n($3,$4)":"lazy$2n($3)");return e!==s?`import n from '${r}/helpers/import-route';${s}`:e};function o(o={}){const{isSSR:m=!1,isBuild:i=!1,routesPath:p}=o;return{name:`${r}-normalize-route`,enforce:"pre",transform(r,o){const[l]=e(o).split("?"),u=!p||o.includes(p);if(!o.includes("node_modules")&&[".js",".mjs",".ts",".tsx"].includes(l)&&u&&t(r))return{code:n(s(r,i),m),map:{mappings:""}}}}}export{o as default};
|
|
2
2
|
//# sourceMappingURL=normalize-route.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-route.js","sources":["../../src/plugins/normalize-route.ts"],"sourcesContent":["import { extname } from 'node:path';\nimport type { Plugin } from 'vite';\nimport PLUGIN_NAME from '@constants/plugin-name';\nimport isRoutesFile from '@helpers/is-route-file';\n\nexport interface IPluginOptions {\n isSSR?: boolean;\n isBuild?: boolean;\n routesPath?: string;\n}\n\n/**\n * Add pathId to route (where pathId - import string)\n * NOTE: only for dev mode\n */\nconst normalizeSyncRoutes = (code: string, isBuild = false): string => {\n if (isBuild) {\n return code;\n }\n\n const imports: Record<string, string> = [\n ...code.matchAll(/import\\s+(\\w+)\\sfrom\\s+['\"]([^'\"]+)['\"]/g),\n ].reduce(\n (res, [, key, value]) => ({\n [key]: value,\n ...res,\n }),\n {},\n );\n\n return code.replace(\n /(.*?(?:Component|element):[\\s<]*(\\w+)[^,}]*),*/gs,\n (fullMatch, before: string, routeName: string) => {\n const importPath = imports?.[routeName];\n\n if (!importPath) {\n return fullMatch;\n }\n\n return `${before},pathId: '${importPath}',`;\n },\n );\n};\n\n/**\n * Add normalize wrapper to lazy imports for client build\n */\nconst normalizeAsyncRoutes = (code: string, isSSR: boolean): string => {\n const modifiedCode = code.replace(\n /(lazy)(:\\s*)(\\(\\)\\s*=>\\s*import\\(([^)]+)\\))/gs,\n isSSR ? 'lazy$
|
|
1
|
+
{"version":3,"file":"normalize-route.js","sources":["../../src/plugins/normalize-route.ts"],"sourcesContent":["import { extname } from 'node:path';\nimport type { Plugin } from 'vite';\nimport PLUGIN_NAME from '@constants/plugin-name';\nimport isRoutesFile from '@helpers/is-route-file';\n\nexport interface IPluginOptions {\n isSSR?: boolean;\n isBuild?: boolean;\n routesPath?: string;\n}\n\n/**\n * Add pathId to route (where pathId - import string)\n * NOTE: only for dev mode\n */\nconst normalizeSyncRoutes = (code: string, isBuild = false): string => {\n if (isBuild) {\n return code;\n }\n\n const imports: Record<string, string> = [\n ...code.matchAll(/import\\s+(\\w+)\\sfrom\\s+['\"]([^'\"]+)['\"]/g),\n ].reduce(\n (res, [, key, value]) => ({\n [key]: value,\n ...res,\n }),\n {},\n );\n\n return code.replace(\n /(.*?(?:Component|element):[\\s<]*(\\w+)[^,}]*),*/gs,\n (fullMatch, before: string, routeName: string) => {\n const importPath = imports?.[routeName];\n\n if (!importPath) {\n return fullMatch;\n }\n\n return `${before},pathId: '${importPath}',`;\n },\n );\n};\n\n/**\n * Add normalize wrapper to lazy imports for client build\n */\nconst normalizeAsyncRoutes = (code: string, isSSR: boolean): string => {\n const modifiedCode = code.replace(\n /(lazy)(:\\s*)(\\(\\)\\s*=>\\s*import\\(([^)]+)\\))/gs,\n isSSR ? 'lazy$2n($3,$4)' : 'lazy$2n($3)',\n );\n\n if (code !== modifiedCode) {\n return `import n from '${PLUGIN_NAME}/helpers/import-route';${modifiedCode}`;\n }\n\n return code;\n};\n\n/**\n * Add possibility to export route components like FCRoute or FCCRoute\n * Add route path for generating manifest\n * USAGE: { path: '/', lazy: () => import('./pages/home') }\n * @see FCRoute\n * @see FCCRoute\n * @see SsrManifest.getRoutesIds\n * @see importRoute\n * @constructor\n */\nfunction ViteNormalizeRouterPlugin(options: IPluginOptions = {}): Plugin {\n const { isSSR = false, isBuild = false, routesPath } = options;\n\n return {\n name: `${PLUGIN_NAME}-normalize-route`,\n enforce: 'pre',\n transform(code, id) {\n const [extName] = extname(id).split('?');\n const isRoutesPath = !routesPath || id.includes(routesPath);\n\n if (\n id.includes('node_modules') ||\n !['.js', '.mjs', '.ts', '.tsx'].includes(extName) ||\n !isRoutesPath ||\n !isRoutesFile(code)\n ) {\n return;\n }\n\n return {\n code: normalizeAsyncRoutes(normalizeSyncRoutes(code, isBuild), isSSR),\n map: { mappings: '' },\n };\n },\n };\n}\n\nexport default ViteNormalizeRouterPlugin;\n"],"names":["normalizeSyncRoutes","code","isBuild","imports","matchAll","reduce","res","key","value","replace","fullMatch","before","routeName","importPath","normalizeAsyncRoutes","isSSR","modifiedCode","PLUGIN_NAME","ViteNormalizeRouterPlugin","options","routesPath","name","enforce","transform","id","extName","extname","split","isRoutesPath","includes","isRoutesFile","map","mappings"],"mappings":"0HAeA,MAAMA,EAAsB,CAACC,EAAcC,GAAU,KACnD,GAAIA,EACF,OAAOD,EAGT,MAAME,EAAkC,IACnCF,EAAKG,SAAS,6CACjBC,QACA,CAACC,GAAK,CAAGC,EAAKC,MAAY,CACxBD,CAACA,GAAMC,KACJF,KAEL,CAAE,GAGJ,OAAOL,EAAKQ,QACV,oDACA,CAACC,EAAWC,EAAgBC,KAC1B,MAAMC,EAAaV,IAAUS,GAE7B,OAAKC,EAIE,GAAGF,cAAmBE,MAHpBH,CAGkC,GAE9C,EAMGI,EAAuB,CAACb,EAAcc,KAC1C,MAAMC,EAAef,EAAKQ,QACxB,gDACAM,EAAQ,iBAAmB,eAG7B,OAAId,IAASe,EACJ,kBAAkBC,2BAAqCD,IAGzDf,CAAI,EAab,SAASiB,EAA0BC,EAA0B,IAC3D,MAAMJ,MAAEA,GAAQ,EAAKb,QAAEA,GAAU,EAAKkB,WAAEA,GAAeD,EAEvD,MAAO,CACLE,KAAM,GAAGJ,oBACTK,QAAS,MACTC,UAAUtB,EAAMuB,GACd,MAAOC,GAAWC,EAAQF,GAAIG,MAAM,KAC9BC,GAAgBR,GAAcI,EAAGK,SAAST,GAEhD,IACEI,EAAGK,SAAS,iBACX,CAAC,MAAO,OAAQ,MAAO,QAAQA,SAASJ,IACxCG,GACAE,EAAa7B,GAKhB,MAAO,CACLA,KAAMa,EAAqBd,EAAoBC,EAAMC,GAAUa,GAC/DgB,IAAK,CAAEC,SAAU,IAEpB,EAEL"}
|