@lomray/vite-ssr-boost 2.0.3 → 2.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/package.json +11 -15
- package/plugin.d.ts +2 -2
- package/plugin.js +1 -1
- package/plugin.js.map +1 -1
- package/plugins/make-aliases.d.ts +0 -11
- package/plugins/make-aliases.js +0 -2
- package/plugins/make-aliases.js.map +0 -1
package/README.md
CHANGED
|
@@ -22,9 +22,8 @@
|
|
|
22
22
|
<img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=vulnerabilities" alt="Vulnerabilities">
|
|
23
23
|
<img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=bugs" alt="Bugs">
|
|
24
24
|
<img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=ncloc" alt="Lines of Code">
|
|
25
|
-
<img src="https://img.shields.io/npm/l/@lomray/vite-ssr-boost" alt="size">
|
|
26
|
-
<img src="https://img.shields.io/npm/v/@lomray/vite-ssr-boost?label=semantic%20release&logo=semantic-release" alt="semantic version">
|
|
27
25
|
<img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=coverage" alt="code coverage">
|
|
26
|
+
<img src="https://img.shields.io/npm/v/@lomray/vite-ssr-boost?label=semantic%20release&logo=semantic-release" alt="semantic version">
|
|
28
27
|
</p>
|
|
29
28
|
|
|
30
29
|
## Table of contents
|
|
@@ -265,4 +264,4 @@ Bug or a feature request, [please open a new issue](https://github.com/Lomray-So
|
|
|
265
264
|
## License
|
|
266
265
|
Made with 💚
|
|
267
266
|
|
|
268
|
-
Published under [
|
|
267
|
+
Published under [MIT License](./LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lomray/vite-ssr-boost",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-beta.1",
|
|
4
4
|
"description": "Vite plugin for create awesome SSR or SPA applications on React.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -30,33 +30,30 @@
|
|
|
30
30
|
"lint:check": "eslint --ext \".ts,.tsx\" \"src/**/*.{ts,tsx,*.ts,*tsx}\"",
|
|
31
31
|
"lint:format": "eslint --fix --ext \".ts,.tsx\" \"src/**/*.{ts,tsx,*.ts,*tsx}\"",
|
|
32
32
|
"ts:check": "tsc --project ./tsconfig.json --skipLibCheck --noemit",
|
|
33
|
-
"test": "
|
|
33
|
+
"test": "vitest run"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"chalk": "^5.3.0",
|
|
37
37
|
"commander": "^11.1.0",
|
|
38
38
|
"compression": "^1.7.4",
|
|
39
39
|
"express": "^4.18.2",
|
|
40
|
-
"hjson": "^3.2.2",
|
|
41
40
|
"hoist-non-react-statics": "^3.3.2"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
|
-
"@commitlint/cli": "^18.
|
|
45
|
-
"@commitlint/config-conventional": "^18.
|
|
43
|
+
"@commitlint/cli": "^18.5.0",
|
|
44
|
+
"@commitlint/config-conventional": "^18.5.0",
|
|
46
45
|
"@lomray/eslint-config": "^4.0.1",
|
|
47
46
|
"@lomray/prettier-config": "^2.0.1",
|
|
48
47
|
"@rollup/plugin-terser": "^0.4.4",
|
|
49
48
|
"@types/chai": "^4.3.11",
|
|
50
49
|
"@types/compression": "^1.7.5",
|
|
51
|
-
"@types/hjson": "^2.4.6",
|
|
52
50
|
"@types/hoist-non-react-statics": "^3.3.5",
|
|
53
|
-
"@types/mocha": "^10.0.6",
|
|
54
51
|
"@types/react-dom": "^18.2.17",
|
|
55
|
-
"@types/sinon": "^17.0.
|
|
52
|
+
"@types/sinon": "^17.0.3",
|
|
56
53
|
"@types/sinon-chai": "^3.2.12",
|
|
57
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
55
|
+
"@vitest/coverage-v8": "^1.2.1",
|
|
58
56
|
"@zerollup/ts-transform-paths": "^1.7.18",
|
|
59
|
-
"c8": "^8.0.1",
|
|
60
57
|
"chai": "^4.3.10",
|
|
61
58
|
"eslint": "^8.55.0",
|
|
62
59
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -65,7 +62,6 @@
|
|
|
65
62
|
"eslint-plugin-prettier": "^5.0.1",
|
|
66
63
|
"husky": "^8.0.3",
|
|
67
64
|
"lint-staged": "^15.2.0",
|
|
68
|
-
"mocha": "^10.2.0",
|
|
69
65
|
"prettier": "^3.1.1",
|
|
70
66
|
"rollup": "^4.9.0",
|
|
71
67
|
"rollup-plugin-copy": "^3.5.0",
|
|
@@ -76,15 +72,15 @@
|
|
|
76
72
|
"semantic-release": "^21.1.2",
|
|
77
73
|
"sinon": "^17.0.1",
|
|
78
74
|
"sinon-chai": "^3.7.0",
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"typescript": "^5.3.3"
|
|
75
|
+
"typescript": "^5.3.3",
|
|
76
|
+
"vitest": "^1.2.1"
|
|
82
77
|
},
|
|
83
78
|
"peerDependencies": {
|
|
84
79
|
"@types/express": ">=4.17.21",
|
|
85
80
|
"react-dom": ">=18.2.0",
|
|
86
81
|
"react-router-dom": ">=6.12.1",
|
|
87
|
-
"vite": ">=5"
|
|
82
|
+
"vite": ">=5",
|
|
83
|
+
"vite-tsconfig-paths": ">=4"
|
|
88
84
|
},
|
|
89
85
|
"bin": {
|
|
90
86
|
"ssr-boost": "cli.js"
|
package/plugin.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
+
import { PluginOptions as ITsconfigPathsOptions } from 'vite-tsconfig-paths';
|
|
2
3
|
import { ICliContext } from "./constants/cli-context.js";
|
|
3
|
-
import { IPluginOptions as IMakeAliasesPluginOptions } from "./plugins/make-aliases.js";
|
|
4
4
|
interface IPluginOptions {
|
|
5
5
|
indexFile?: string;
|
|
6
6
|
serverFile?: string;
|
|
7
7
|
clientFile?: string;
|
|
8
8
|
routesPath?: string;
|
|
9
|
-
|
|
9
|
+
tsconfigPaths?: boolean | ITsconfigPathsOptions;
|
|
10
10
|
customShortcuts?: {
|
|
11
11
|
key: string;
|
|
12
12
|
description: string;
|
package/plugin.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import i from"node:path";import
|
|
1
|
+
import i from"node:path";import t from"vite-tsconfig-paths";import e from"./constants/cli-actions.js";import o from"./constants/plugin-name.js";import n from"./plugins/normalize-route.js";const s={indexFile:"index.html",serverFile:"server.ts",clientFile:"client.ts",tsconfigPaths:!0};function r(r={}){const p=new URL(import.meta.url),a=global.viteBoostAction||process.env.SSR_BOOST_ACTION,l={...s,...r},u="1"===process.env.SSR_BOOST_IS_SSR||a===e.dev,c=a===e.build,m=[{name:o,enforce:"pre",pluginOptions:{...l,pluginPath:i.dirname(p.pathname),action:a,isDev:a===e.dev},config:(i,{isSsrBuild:t})=>(i.define={...i.define??{},__IS_SSR__:u},i.build={...i.build??{}},t?{...i,...c?{appType:"custom"}:{},publicDir:!1}:(u&&c&&(i.build.manifest=!0),i))}],{tsconfigPaths:d,routesPath:f}=l;return d&&m.push(t("boolean"==typeof d?void 0:d)),m.push(n({isSSR:u,isBuild:c,routesPath:f})),m}export{r as default};
|
|
2
2
|
//# sourceMappingURL=plugin.js.map
|
package/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path';\nimport type { Plugin } from 'vite';\nimport
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path';\nimport type { Plugin } from 'vite';\nimport type { PluginOptions as ITsconfigPathsOptions } from 'vite-tsconfig-paths';\nimport tsconfigPathsPlugin from 'vite-tsconfig-paths';\nimport CliActions from '@constants/cli-actions';\nimport type { ICliContext } from '@constants/cli-context';\nimport PLUGIN_NAME from '@constants/plugin-name';\nimport ViteNormalizeRouterPlugin from '@plugins/normalize-route';\n\nexport interface IPluginOptions {\n // default: index.html\n indexFile?: string;\n // default: server.ts\n serverFile?: string;\n // default: client.ts\n clientFile?: string;\n // Path contains routes declaration files (need to detect route files). default: undefined, e.g.: /routes/\n routesPath?: string;\n // Enable and configure tsconfig path plugin\n tsconfigPaths?: boolean | ITsconfigPathsOptions;\n customShortcuts?: {\n key: string;\n description: string;\n action: (cliContext: ICliContext) => Promise<void> | void;\n isOnlyDev?: boolean;\n }[];\n}\n\nconst defaultOptions: IPluginOptions = {\n indexFile: 'index.html',\n serverFile: 'server.ts',\n clientFile: 'client.ts',\n tsconfigPaths: true,\n};\n\n/**\n * Init plugin\n * @constructor\n */\nfunction ViteSsrBoostPlugin(options: IPluginOptions = {}): Plugin[] {\n const dirInfo = new URL(import.meta.url);\n const action = (global.viteBoostAction || process.env.SSR_BOOST_ACTION) as CliActions;\n const mergedOptions: IPluginOptions = { ...defaultOptions, ...options };\n const isSSR = process.env.SSR_BOOST_IS_SSR === '1' || action === CliActions.dev;\n const isBuild = action === CliActions.build;\n\n const plugins: Plugin[] = [\n {\n name: PLUGIN_NAME,\n enforce: 'pre',\n // @ts-ignore save custom options\n pluginOptions: {\n ...mergedOptions,\n pluginPath: path.dirname(dirInfo.pathname),\n action,\n isDev: action === CliActions.dev,\n },\n\n config(config, { isSsrBuild }) {\n config.define = {\n ...(config.define ?? {}),\n __IS_SSR__: isSSR,\n };\n\n config.build = {\n ...(config.build ?? {}),\n };\n\n if (!isSsrBuild) {\n if (isSSR && isBuild) {\n config.build!.manifest = true;\n }\n\n return config;\n }\n\n return {\n ...config,\n ...(isBuild ? { appType: 'custom' } : {}),\n publicDir: false,\n };\n },\n },\n ];\n\n const { tsconfigPaths, routesPath } = mergedOptions;\n\n if (tsconfigPaths) {\n plugins.push(\n tsconfigPathsPlugin(typeof tsconfigPaths === 'boolean' ? undefined : tsconfigPaths),\n );\n }\n\n plugins.push(ViteNormalizeRouterPlugin({ isSSR, isBuild, routesPath }));\n\n return plugins;\n}\n\nexport default ViteSsrBoostPlugin;\n"],"names":["defaultOptions","indexFile","serverFile","clientFile","tsconfigPaths","ViteSsrBoostPlugin","options","dirInfo","URL","url","action","global","viteBoostAction","process","env","SSR_BOOST_ACTION","mergedOptions","isSSR","SSR_BOOST_IS_SSR","CliActions","dev","isBuild","build","plugins","name","PLUGIN_NAME","enforce","pluginOptions","pluginPath","path","dirname","pathname","isDev","config","isSsrBuild","define","__IS_SSR__","appType","publicDir","manifest","routesPath","push","tsconfigPathsPlugin","undefined","ViteNormalizeRouterPlugin"],"mappings":"4LA4BA,MAAMA,EAAiC,CACrCC,UAAW,aACXC,WAAY,YACZC,WAAY,YACZC,eAAe,GAOjB,SAASC,EAAmBC,EAA0B,IACpD,MAAMC,EAAU,IAAIC,gBAAgBC,KAC9BC,EAAUC,OAAOC,iBAAmBC,QAAQC,IAAIC,iBAChDC,EAAgC,IAAKhB,KAAmBM,GACxDW,EAAyC,MAAjCJ,QAAQC,IAAII,kBAA4BR,IAAWS,EAAWC,IACtEC,EAAUX,IAAWS,EAAWG,MAEhCC,EAAoB,CACxB,CACEC,KAAMC,EACNC,QAAS,MAETC,cAAe,IACVX,EACHY,WAAYC,EAAKC,QAAQvB,EAAQwB,UACjCrB,SACAsB,MAAOtB,IAAWS,EAAWC,KAG/Ba,OAAM,CAACA,GAAQC,WAAEA,MACfD,EAAOE,OAAS,IACVF,EAAOE,QAAU,CAAE,EACvBC,WAAYnB,GAGdgB,EAAOX,MAAQ,IACTW,EAAOX,OAAS,CAAE,GAGnBY,EAQE,IACFD,KACCZ,EAAU,CAAEgB,QAAS,UAAa,CAAE,EACxCC,WAAW,IAVPrB,GAASI,IACXY,EAAOX,MAAOiB,UAAW,GAGpBN,OAYT7B,cAAEA,EAAaoC,WAAEA,GAAexB,EAUtC,OARIZ,GACFmB,EAAQkB,KACNC,EAA6C,kBAAlBtC,OAA8BuC,EAAYvC,IAIzEmB,EAAQkB,KAAKG,EAA0B,CAAE3B,QAAOI,UAASmB,gBAElDjB,CACT"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
interface IPluginOptions {
|
|
3
|
-
root?: string;
|
|
4
|
-
tsconfig?: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Read tsconfig file and set vite aliases
|
|
8
|
-
* @constructor
|
|
9
|
-
*/
|
|
10
|
-
declare function ViteMakeAliasesPlugin(options?: IPluginOptions): Plugin;
|
|
11
|
-
export { ViteMakeAliasesPlugin as default, IPluginOptions };
|
package/plugins/make-aliases.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import e from"node:fs";import o from"node:path";import s from"node:process";import r from"hjson";import t from"../constants/plugin-name.js";import n from"../helpers/vite-aliases.js";const i=`${t}-make-aliases`,a=e=>e.replace("/*","");function c(t={}){const{root:c,tsconfig:p}=t,f=c??s.cwd(),m=o.resolve(f,p??"tsconfig.json"),l=[];if(e.existsSync(m)){const o=r.parse(e.readFileSync(m,{encoding:"utf-8"})),s=o?.compilerOptions?.paths??{};Object.entries(s).forEach((([e,o])=>{l.push([a(e),a(o[0])])}))}else console.error(`${i}: tsconfig not exist in "${m}"`);return{name:i,config(e){if(l.length){const o=e.resolve??{},s=o.alias??[],r=Array.isArray(s)?s:Object.entries(s).map((([e,o])=>({find:e,replacement:o})));r.push(...n(l,`${f}/${e?.root??""}`)),e.resolve={...o,alias:r}}return e}}}export{c as default};
|
|
2
|
-
//# sourceMappingURL=make-aliases.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"make-aliases.js","sources":["../../src/plugins/make-aliases.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport process from 'node:process';\nimport Hjson from 'hjson';\nimport type { Plugin } from 'vite';\nimport PLUGIN_NAME from '@constants/plugin-name';\nimport ViteAliases from '@helpers/vite-aliases';\n\nexport interface IPluginOptions {\n root?: string; // default: cwd()\n tsconfig?: string; // default: tsconfig.json\n}\n\nconst pluginName = `${PLUGIN_NAME}-make-aliases`;\nconst cleanupAlias = (str: string): string => str.replace('/*', '');\n\n/**\n * Read tsconfig file and set vite aliases\n * @constructor\n */\nfunction ViteMakeAliasesPlugin(options: IPluginOptions = {}): Plugin {\n const { root, tsconfig } = options;\n const projectRoot = root ?? process.cwd();\n const tsconfigPath = path.resolve(projectRoot, tsconfig ?? 'tsconfig.json');\n const aliases: [string, string][] = [];\n\n if (!fs.existsSync(tsconfigPath)) {\n console.error(`${pluginName}: tsconfig not exist in \"${tsconfigPath}\"`);\n } else {\n const tsJson = Hjson.parse(fs.readFileSync(tsconfigPath, { encoding: 'utf-8' }));\n const paths: Record<string, string[]> = tsJson?.compilerOptions?.paths ?? {};\n\n Object.entries(paths).forEach(([alias, aliasPaths]) => {\n aliases.push([cleanupAlias(alias), cleanupAlias(aliasPaths[0])]);\n });\n }\n\n return {\n name: pluginName,\n config(config) {\n if (aliases.length) {\n const resolveConfig = config.resolve ?? {};\n const defaultAliases = resolveConfig.alias ?? [];\n const normalizedAliases = Array.isArray(defaultAliases)\n ? defaultAliases\n : Object.entries(defaultAliases).map(([find, val]) => ({ find, replacement: val }));\n\n normalizedAliases.push(...ViteAliases(aliases, `${projectRoot}/${config?.root ?? ''}`));\n\n config.resolve = {\n ...resolveConfig,\n alias: normalizedAliases,\n };\n }\n\n return config;\n },\n };\n}\n\nexport default ViteMakeAliasesPlugin;\n"],"names":["pluginName","PLUGIN_NAME","cleanupAlias","str","replace","ViteMakeAliasesPlugin","options","root","tsconfig","projectRoot","process","cwd","tsconfigPath","path","resolve","aliases","fs","existsSync","tsJson","Hjson","parse","readFileSync","encoding","paths","compilerOptions","Object","entries","forEach","alias","aliasPaths","push","console","error","name","config","length","resolveConfig","defaultAliases","normalizedAliases","Array","isArray","map","find","val","replacement","ViteAliases"],"mappings":"sLAaA,MAAMA,EAAa,GAAGC,iBAChBC,EAAgBC,GAAwBA,EAAIC,QAAQ,KAAM,IAMhE,SAASC,EAAsBC,EAA0B,IACvD,MAAMC,KAAEA,EAAIC,SAAEA,GAAaF,EACrBG,EAAcF,GAAQG,EAAQC,MAC9BC,EAAeC,EAAKC,QAAQL,EAAaD,GAAY,iBACrDO,EAA8B,GAEpC,GAAKC,EAAGC,WAAWL,GAEZ,CACL,MAAMM,EAASC,EAAMC,MAAMJ,EAAGK,aAAaT,EAAc,CAAEU,SAAU,WAC/DC,EAAkCL,GAAQM,iBAAiBD,OAAS,CAAA,EAE1EE,OAAOC,QAAQH,GAAOI,SAAQ,EAAEC,EAAOC,MACrCd,EAAQe,KAAK,CAAC5B,EAAa0B,GAAQ1B,EAAa2B,EAAW,KAAK,GAEnE,MARCE,QAAQC,MAAM,GAAGhC,6BAAsCY,MAUzD,MAAO,CACLqB,KAAMjC,EACNkC,OAAOA,GACL,GAAInB,EAAQoB,OAAQ,CAClB,MAAMC,EAAgBF,EAAOpB,SAAW,GAClCuB,EAAiBD,EAAcR,OAAS,GACxCU,EAAoBC,MAAMC,QAAQH,GACpCA,EACAZ,OAAOC,QAAQW,GAAgBI,KAAI,EAAEC,EAAMC,MAAU,CAAED,OAAME,YAAaD,MAE9EL,EAAkBR,QAAQe,EAAY9B,EAAS,GAAGN,KAAeyB,GAAQ3B,MAAQ,OAEjF2B,EAAOpB,QAAU,IACZsB,EACHR,MAAOU,EAEV,CAED,OAAOJ,CACR,EAEL"}
|