diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 55f0f26fd..000000000 --- a/.eslintignore +++ /dev/null @@ -1,14 +0,0 @@ -**/externals.ts -**/external-utils.ts -**/third-party -**/cjs -**/esm -**/dist -**/build -**/typings -**/*.d.ts -**/minimist.js -**/node_modules -**/prism.js -**/.serverless -docs \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 6a6a72a39..000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,27 +0,0 @@ -module.exports = { - root: true, - extends: [ - 'standard-vue-ts', - 'standard-react-ts' - ], - globals: { - context: true, - beforeEach: true, - afterEach: true, - Cypress: true, - cy: true, - expect: true, - it: true, - describe: true - }, - rules: { - '@typescript-eslint/dot-notation': ['off'], - 'padded-blocks': ['off'], - '@typescript-eslint/no-base-to-string': ['off'], - '@typescript-eslint/restrict-plus-operands': ['off'], - 'react-hooks/rules-of-hooks': ['off'], - '@typescript-eslint/no-var-requires': ['off'], - '@typescript-eslint/no-namespace': ['error', { allowDeclarations: true }], - '@typescript-eslint/promise-function-async': ['off'] - } -} diff --git a/.npmrc b/.npmrc index c5277c1c7..8bb958c79 100644 --- a/.npmrc +++ b/.npmrc @@ -4,7 +4,6 @@ public-hoist-pattern[]=typescript public-hoist-pattern[]=*@babel/runtime* public-hoist-pattern[]=*tsconfig-paths* public-hoist-pattern[]=*ts-node* -public-hoist-pattern[]=*eslint* public-hoist-pattern[]=*babel* public-hoist-pattern[]=*@types/express* public-hoist-pattern[]=*vue-template-compiler* diff --git a/.vscode/settings.json b/.vscode/settings.json index 0dd47daba..1c584ef48 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,9 @@ { - "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit" - }, - "eslint.validate": [ - "javascript", - "javascriptreact", - ] +"[javascript]": { + "editor.defaultFormatter": "biomejs.biome" +}, + "editor.codeActionsOnSave": { + "quickfix.biome": "explicit", + "source.organizeImports.biome": "explicit" + } } \ No newline at end of file diff --git a/biome.json b/biome.json new file mode 100644 index 000000000..0fcc0db31 --- /dev/null +++ b/biome.json @@ -0,0 +1,100 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false }, + "files": { + "ignoreUnknown": false, + "ignore": ["**/*.d.ts", "**/mock", "biome.json"], + "include": ["example/**/*.vue", "example/**/*.ts", "packages/**/*.ts"] + }, + "formatter": { "enabled": true, "indentStyle": "tab", "lineWidth": 320, "attributePosition": "auto" }, + "organizeImports": { "enabled": true }, + "linter": { + "enabled": true, + "rules": { + "recommended": false, + "complexity": { + "noExtraBooleanCast": "error", + "noMultipleSpacesInRegularExpressionLiterals": "error", + "noUselessCatch": "error", + "noUselessConstructor": "error", + "noUselessLoneBlockStatements": "error", + "noUselessRename": "error", + "noUselessTernary": "error", + "noUselessUndefinedInitialization": "error", + "noVoid": "error", + "noWith": "error", + "useLiteralKeys": "off" + }, + "correctness": { + "noConstAssign": "error", + "noConstantCondition": "error", + "noEmptyCharacterClassInRegex": "error", + "noEmptyPattern": "error", + "noGlobalObjectCalls": "error", + "noInnerDeclarations": "error", + "noInvalidConstructorSuper": "error", + "noInvalidUseBeforeDeclaration": "error", + "noNewSymbol": "error", + "noSelfAssign": "error", + "noSwitchDeclarations": "error", + "noUndeclaredVariables": "error", + "noUnreachable": "error", + "noUnreachableSuper": "error", + "noUnsafeFinally": "error", + "noUnusedVariables": "warn", + "useArrayLiterals": "error", + "useExhaustiveDependencies": "warn", + "useHookAtTopLevel": "off", + "useIsNan": "error" + }, + "security": { "noGlobalEval": "error" }, + "style": { + "noCommaOperator": "error", + "noNamespace": "error", + "noNonNullAssertion": "off", + "noYodaExpression": "error", + "useBlockStatements": "error", + "useConsistentBuiltinInstantiation": "error", + "useConst": "error", + "useSingleVarDeclarator": "error" + }, + "suspicious": { + "noAsyncPromiseExecutor": "error", + "noCatchAssign": "error", + "noClassAssign": "error", + "noCompareNegZero": "error", + "noControlCharactersInRegex": "error", + "noDebugger": "error", + "noDoubleEquals": "error", + "noDuplicateCase": "error", + "noDuplicateClassMembers": "error", + "noDuplicateObjectKeys": "error", + "noDuplicateParameters": "error", + "noFallthroughSwitchClause": "error", + "noFunctionAssign": "error", + "noGlobalAssign": "error", + "noMisleadingCharacterClass": "error", + "noPrototypeBuiltins": "error", + "noRedeclare": "error", + "noSelfCompare": "error", + "noShadowRestrictedNames": "error", + "noSparseArray": "error", + "noUnsafeNegation": "error", + "useValidTypeof": "error" + } + } + }, + "javascript": { + "formatter": { + "quoteStyle": "single", + "semicolons": "asNeeded", + "trailingCommas": "none", + "lineWidth": 320, + "attributePosition": "auto" + }, + "parser": { + "unsafeParameterDecoratorsEnabled": true + }, + "globals": ["cy", "expect", "it", "context", "beforeEach", "afterEach", "describe", "Cypress", "navigator", "window", "document", "__isBrowser__", "JSX", "Vue", "React", "__non_webpack_require__"] + } +} diff --git a/docs/.eslintignore b/docs/.eslintignore deleted file mode 100644 index 74de859e7..000000000 --- a/docs/.eslintignore +++ /dev/null @@ -1,5 +0,0 @@ -typings -build -**/prism.js -dist -@types \ No newline at end of file diff --git a/docs/.eslintrc.js b/docs/.eslintrc.js deleted file mode 100644 index 726534c63..000000000 --- a/docs/.eslintrc.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - root: true, - extends: [ - 'standard-vue-ts' - ], - parserOptions: { - project: './tsconfig.lint.json' - } -} diff --git a/docs/package.json b/docs/package.json index ec010e3e6..1a36df72f 100644 --- a/docs/package.json +++ b/docs/package.json @@ -31,7 +31,6 @@ "@vitejs/plugin-vue": "^1.2.1", "cross-env": "^7.0.3", "darkmode-js": "^1.5.7", - "eslint-config-standard-vue-ts": "^1.0.12", "raw-loader": "^4.0.2", "ssr": "^6.0.0", "ssr-plugin-midway": "^6.0.0", diff --git a/example/midway-react-ssr/.eslintignore b/example/midway-react-ssr/.eslintignore deleted file mode 100644 index b38d0963c..000000000 --- a/example/midway-react-ssr/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -build -typings -run \ No newline at end of file diff --git a/example/midway-react-ssr/.eslintrc.js b/example/midway-react-ssr/.eslintrc.js deleted file mode 100644 index 0bd3cb532..000000000 --- a/example/midway-react-ssr/.eslintrc.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - root: true, - extends: [ - 'standard-react-ts' - ], - globals: { - __isBrowser__: 'readonly', - defineProps: 'readonly' - } -} diff --git a/example/midway-react-ssr/config.ts b/example/midway-react-ssr/config.ts index 35da1144c..696b10bb7 100644 --- a/example/midway-react-ssr/config.ts +++ b/example/midway-react-ssr/config.ts @@ -1,7 +1,5 @@ import type { UserConfig } from 'ssr-types' -const userConfig: UserConfig = { - -} +const userConfig: UserConfig = {} export { userConfig } diff --git a/example/midway-react-ssr/package.json b/example/midway-react-ssr/package.json index 078ff53b3..fbaac05b1 100644 --- a/example/midway-react-ssr/package.json +++ b/example/midway-react-ssr/package.json @@ -19,11 +19,11 @@ "valtio": "^1.11.2" }, "devDependencies": { + "@biomejs/biome": "^1.9.4", "@midwayjs/mock": "^3.0.0", "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", "@types/react-router-dom": "^5.1.3", - "eslint-config-standard-react-ts": "^1.0.18", "ssr": "^6.0.0", "ssr-plugin-midway": "^6.0.0", "ssr-plugin-react": "^6.0.0", @@ -40,7 +40,7 @@ "build:o": "ssr build --optimize", "build:vite": "ssr build --vite", "deploy": "ssr build && ssr deploy", - "lint": "eslint . --ext .js,.tsx,.ts --cache", - "lint:fix": "eslint . --ext .js,.tsx,.ts --cache --fix" + "lint": "biome format --diagnostic-level error", + "lint:fix": "biome format --diagnostic-level error --write" } } diff --git a/example/midway-react-ssr/src/config/config.default.ts b/example/midway-react-ssr/src/config/config.default.ts index 20a829788..51b14167c 100644 --- a/example/midway-react-ssr/src/config/config.default.ts +++ b/example/midway-react-ssr/src/config/config.default.ts @@ -1,7 +1,6 @@ import { MidwayConfig } from '@midwayjs/core' export default { - // use for cookie sign key, should change to your own and keep security - keys: '1650192482948_2252' - + // use for cookie sign key, should change to your own and keep security + keys: '1650192482948_2252' } as MidwayConfig diff --git a/example/midway-react-ssr/src/configuration.ts b/example/midway-react-ssr/src/configuration.ts index d323c82e2..0a52fe241 100644 --- a/example/midway-react-ssr/src/configuration.ts +++ b/example/midway-react-ssr/src/configuration.ts @@ -1,26 +1,24 @@ -import { Configuration, App } from '@midwayjs/decorator' -import * as koa from '@midwayjs/koa' import { join } from 'path' -import { initialSSRDevProxy, getCwd } from 'ssr-common-utils' +import { App, Configuration } from '@midwayjs/decorator' +import * as koa from '@midwayjs/koa' +import { getCwd, initialSSRDevProxy } from 'ssr-common-utils' const koaStatic = require('koa-static-cache') const cwd = getCwd() @Configuration({ - imports: [ - koa - ], - importConfigs: [join(__dirname, './config')] + imports: [koa], + importConfigs: [join(__dirname, './config')] }) export class ContainerLifeCycle { - @App() - app: koa.Application + @App() + app: koa.Application - async onReady () { - this.app.use(koaStatic(join(cwd, './build'), { maxAge: 864000 })) - this.app.use(koaStatic(join(cwd, './public'), { maxAge: 864000 })) - this.app.use(koaStatic(join(cwd, './build/client'), { maxAge: 864000 })) + async onReady() { + this.app.use(koaStatic(join(cwd, './build'), { maxAge: 864000 })) + this.app.use(koaStatic(join(cwd, './public'), { maxAge: 864000 })) + this.app.use(koaStatic(join(cwd, './build/client'), { maxAge: 864000 })) - await initialSSRDevProxy(this.app) - } + await initialSSRDevProxy(this.app) + } } diff --git a/example/midway-react-ssr/src/controller/api.ts b/example/midway-react-ssr/src/controller/api.ts index ec6b7ca36..492383925 100644 --- a/example/midway-react-ssr/src/controller/api.ts +++ b/example/midway-react-ssr/src/controller/api.ts @@ -1,30 +1,30 @@ -import { Inject, Controller, Provide, Get } from '@midwayjs/decorator' +import { Controller, Get, Inject, Provide } from '@midwayjs/decorator' import { Context } from '@midwayjs/koa' -import { IApiService, IApiDetailService } from '../interface' +import { IApiDetailService, IApiService } from '../interface' @Provide() @Controller('/api') export class Api { - @Inject() - ctx: Context + @Inject() + ctx: Context - @Inject('ApiService') - service: IApiService + @Inject('ApiService') + service: IApiService - @Inject('ApiDetailService') - detailService: IApiDetailService + @Inject('ApiDetailService') + detailService: IApiDetailService - @Get('/index') - async getIndexData () { - const data = await this.service.index() - return data - } + @Get('/index') + async getIndexData() { + const data = await this.service.index() + return data + } - @Get('/detail/:id') - async getDetailData () { - const { ctx, detailService } = this - const id = ctx.params.id - const data = await detailService.index(id) - return data - } + @Get('/detail/:id') + async getDetailData() { + const { ctx, detailService } = this + const id = ctx.params.id + const data = await detailService.index(id) + return data + } } diff --git a/example/midway-react-ssr/src/controller/index.ts b/example/midway-react-ssr/src/controller/index.ts index 5bc42d7d4..70a2b70ec 100755 --- a/example/midway-react-ssr/src/controller/index.ts +++ b/example/midway-react-ssr/src/controller/index.ts @@ -1,45 +1,45 @@ -import { Controller, Get, Provide, Inject } from '@midwayjs/decorator' +import { Controller, Get, Inject, Provide } from '@midwayjs/decorator' import { Context } from '@midwayjs/koa' import { render } from 'ssr-core' -import { IApiService, IApiDetailService } from '../interface' +import { IApiDetailService, IApiService } from '../interface' interface IKoaContext extends Context { - apiService: IApiService - apiDeatilservice: IApiDetailService + apiService: IApiService + apiDeatilservice: IApiDetailService } @Provide() @Controller('/') export class Index { - @Inject() - ctx: IKoaContext + @Inject() + ctx: IKoaContext - @Inject('ApiService') - apiService: IApiService + @Inject('ApiService') + apiService: IApiService - @Inject('ApiDetailService') - apiDeatilservice: IApiDetailService + @Inject('ApiDetailService') + apiDeatilservice: IApiDetailService - @Get('/') - @Get('/detail/:id') - async handler (): Promise { - // 降级策略参考文档 http://doc.ssr-fc.com/docs/features$csr#%E5%A4%84%E7%90%86%20%E6%B5%81%20%E8%BF%94%E5%9B%9E%E5%BD%A2%E5%BC%8F%E7%9A%84%E9%99%8D%E7%BA%A7 - const { ctx } = this - ctx.apiService = this.apiService - ctx.apiDeatilservice = this.apiDeatilservice - const stream = await render(this.ctx, { - stream: true, - mode: 'ssr' - }) - stream.on('error', async (err) => { - console.log('ssr error', err) - stream.destroy() - const csrStream = await render(ctx, { - stream: false, - mode: 'csr' - }) - ctx.res.end(csrStream) - }) - ctx.body = stream - } + @Get('/') + @Get('/detail/:id') + async handler(): Promise { + // 降级策略参考文档 http://doc.ssr-fc.com/docs/features$csr#%E5%A4%84%E7%90%86%20%E6%B5%81%20%E8%BF%94%E5%9B%9E%E5%BD%A2%E5%BC%8F%E7%9A%84%E9%99%8D%E7%BA%A7 + const { ctx } = this + ctx.apiService = this.apiService + ctx.apiDeatilservice = this.apiDeatilservice + const stream = await render(this.ctx, { + stream: true, + mode: 'ssr' + }) + stream.on('error', async (err) => { + console.log('ssr error', err) + stream.destroy() + const csrStream = await render(ctx, { + stream: false, + mode: 'csr' + }) + ctx.res.end(csrStream) + }) + ctx.body = stream + } } diff --git a/example/midway-react-ssr/src/interface/detail.ts b/example/midway-react-ssr/src/interface/detail.ts index 27639189a..e20bb6e93 100644 --- a/example/midway-react-ssr/src/interface/detail.ts +++ b/example/midway-react-ssr/src/interface/detail.ts @@ -1,4 +1,4 @@ import { DetailData } from '~/typings/data' export interface IApiDetailService { - index: (id: string) => Promise + index: (id: string) => Promise } diff --git a/example/midway-react-ssr/src/interface/index.ts b/example/midway-react-ssr/src/interface/index.ts index 580610521..d47053615 100644 --- a/example/midway-react-ssr/src/interface/index.ts +++ b/example/midway-react-ssr/src/interface/index.ts @@ -1,7 +1,7 @@ import { IndexData } from '~/typings/data' export interface IApiService { - index: () => Promise + index: () => Promise } export * from './detail' diff --git a/example/midway-react-ssr/src/service/detail.ts b/example/midway-react-ssr/src/service/detail.ts index ac2fc62c3..abca552ae 100644 --- a/example/midway-react-ssr/src/service/detail.ts +++ b/example/midway-react-ssr/src/service/detail.ts @@ -4,7 +4,7 @@ import mock from '../mock/detail' @Provide('ApiDetailService') export class ApiDetailService { - async index (id): Promise { - return await Promise.resolve(mock.data[id]) - } + async index(id): Promise { + return await Promise.resolve(mock.data[id]) + } } diff --git a/example/midway-react-ssr/src/service/index.ts b/example/midway-react-ssr/src/service/index.ts index 123c7e455..93d692e7b 100644 --- a/example/midway-react-ssr/src/service/index.ts +++ b/example/midway-react-ssr/src/service/index.ts @@ -4,7 +4,7 @@ import mock from '../mock' @Provide('ApiService') export class ApiIndexService { - async index (): Promise { - return await Promise.resolve(mock) - } + async index(): Promise { + return await Promise.resolve(mock) + } } diff --git a/example/midway-react-ssr/web/components/layout/fetch.ts b/example/midway-react-ssr/web/components/layout/fetch.ts index b5f68940c..dbdec9936 100644 --- a/example/midway-react-ssr/web/components/layout/fetch.ts +++ b/example/midway-react-ssr/web/components/layout/fetch.ts @@ -1,7 +1,5 @@ import { ReactMidwayKoaFetch } from 'ssr-types' -const fetch: ReactMidwayKoaFetch = async ({ ctx, routerProps }) => { - -} +const fetch: ReactMidwayKoaFetch = async ({ ctx, routerProps }) => {} export default fetch diff --git a/example/midway-react-ssr/web/pages/detail/fetch.ts b/example/midway-react-ssr/web/pages/detail/fetch.ts index a431780e7..09ccb4a50 100644 --- a/example/midway-react-ssr/web/pages/detail/fetch.ts +++ b/example/midway-react-ssr/web/pages/detail/fetch.ts @@ -1,14 +1,17 @@ +import { useStore } from 'ssr-common-utils' import { ReactNestFetch } from 'ssr-types' import { Ddata } from '~/typings/data' -import { useStore } from 'ssr-common-utils' -const fetch: ReactNestFetch<{ - apiDeatilservice: { - index: (id: string) => Promise - } -}, {id: string}> = async ({ ctx, routerProps }) => { - const { detailState } = useStore() - const data = __isBrowser__ ? await (await window.fetch(`/api/detail/${routerProps!.match.params.id}`)).json() : await ctx!.apiDeatilservice.index(ctx!.request.params.id) - detailState.detailData = data +const fetch: ReactNestFetch< + { + apiDeatilservice: { + index: (id: string) => Promise + } + }, + { id: string } +> = async ({ ctx, routerProps }) => { + const { detailState } = useStore() + const data = __isBrowser__ ? await (await window.fetch(`/api/detail/${routerProps!.match.params.id}`)).json() : await ctx!.apiDeatilservice.index(ctx!.request.params.id) + detailState.detailData = data } export default fetch diff --git a/example/midway-react-ssr/web/pages/index/fetch.ts b/example/midway-react-ssr/web/pages/index/fetch.ts index 0cd217896..f9aaf5d36 100644 --- a/example/midway-react-ssr/web/pages/index/fetch.ts +++ b/example/midway-react-ssr/web/pages/index/fetch.ts @@ -1,15 +1,15 @@ +import { useStore } from 'ssr-common-utils' import { ReactNestFetch } from 'ssr-types' import { IndexData } from '~/typings/data' -import { useStore } from 'ssr-common-utils' const fetch: ReactNestFetch<{ - apiService: { - index: () => Promise - } + apiService: { + index: () => Promise + } }> = async ({ ctx, routerProps }) => { - const { indexState } = useStore() - const data = __isBrowser__ ? await (await window.fetch('/api/index')).json() : await ctx!.apiService?.index() - indexState.indexData = data + const { indexState } = useStore() + const data = __isBrowser__ ? await (await window.fetch('/api/index')).json() : await ctx!.apiService?.index() + indexState.indexData = data } export default fetch diff --git a/example/midway-react-ssr/web/store/index.ts b/example/midway-react-ssr/web/store/index.ts index c1e9bcaa3..86f922e03 100644 --- a/example/midway-react-ssr/web/store/index.ts +++ b/example/midway-react-ssr/web/store/index.ts @@ -1,9 +1,9 @@ -import { state as indexState } from './modules/index' import { state as detailState } from './modules/detail' +import { state as indexState } from './modules/index' import { state as searchState } from './modules/search' export const store = { - indexState, - detailState, - searchState + indexState, + detailState, + searchState } diff --git a/example/midway-react-ssr/web/store/modules/detail.ts b/example/midway-react-ssr/web/store/modules/detail.ts index 18264e84d..9ff46ca19 100644 --- a/example/midway-react-ssr/web/store/modules/detail.ts +++ b/example/midway-react-ssr/web/store/modules/detail.ts @@ -3,5 +3,5 @@ import { Ddata } from '~/typings/data' import { proxy } from 'valtio' export const state = proxy({ - data: {} as Ddata + data: {} as Ddata }) diff --git a/example/midway-react-ssr/web/store/modules/index.ts b/example/midway-react-ssr/web/store/modules/index.ts index 2dfa804dd..a787db6c8 100644 --- a/example/midway-react-ssr/web/store/modules/index.ts +++ b/example/midway-react-ssr/web/store/modules/index.ts @@ -1,8 +1,7 @@ - import { IndexData } from '~/typings/data' import { proxy } from 'valtio' export const state = proxy({ - data: {} as IndexData + data: {} as IndexData }) diff --git a/example/midway-react-ssr/web/store/modules/search.ts b/example/midway-react-ssr/web/store/modules/search.ts index 756abc32b..e9ab76d2e 100644 --- a/example/midway-react-ssr/web/store/modules/search.ts +++ b/example/midway-react-ssr/web/store/modules/search.ts @@ -1,6 +1,5 @@ - import { proxy } from 'valtio' export const state = proxy({ - searchText: '' + searchText: '' }) diff --git a/example/midway-react18-ssr/.eslintignore b/example/midway-react18-ssr/.eslintignore deleted file mode 100644 index b38d0963c..000000000 --- a/example/midway-react18-ssr/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -build -typings -run \ No newline at end of file diff --git a/example/midway-react18-ssr/.eslintrc.js b/example/midway-react18-ssr/.eslintrc.js deleted file mode 100644 index 0bd3cb532..000000000 --- a/example/midway-react18-ssr/.eslintrc.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - root: true, - extends: [ - 'standard-react-ts' - ], - globals: { - __isBrowser__: 'readonly', - defineProps: 'readonly' - } -} diff --git a/example/midway-react18-ssr/config.ts b/example/midway-react18-ssr/config.ts index 35da1144c..696b10bb7 100644 --- a/example/midway-react18-ssr/config.ts +++ b/example/midway-react18-ssr/config.ts @@ -1,7 +1,5 @@ import type { UserConfig } from 'ssr-types' -const userConfig: UserConfig = { - -} +const userConfig: UserConfig = {} export { userConfig } diff --git a/example/midway-react18-ssr/package.json b/example/midway-react18-ssr/package.json index d0cd7593d..395e8a938 100644 --- a/example/midway-react18-ssr/package.json +++ b/example/midway-react18-ssr/package.json @@ -18,11 +18,11 @@ "valtio": "^1.11.2" }, "devDependencies": { + "@biomejs/biome": "^1.9.4", "@midwayjs/mock": "^3.0.0", "@types/react": "^18.0.0", "@types/react-dom": "^18.0.0", "@types/react-router-dom": "^5.1.3", - "eslint-config-standard-react-ts": "^1.0.18", "ssr": "^6.0.0", "ssr-plugin-midway": "^6.0.0", "ssr-plugin-react18": "^6.0.0", @@ -39,7 +39,7 @@ "build:o": "ssr build --optimize", "build:vite": "ssr build --vite", "deploy": "ssr build && ssr deploy", - "lint": "eslint . --ext .js,.tsx,.ts --cache", - "lint:fix": "eslint . --ext .js,.tsx,.ts --cache --fix" + "lint": "biome format --diagnostic-level error", + "lint:fix": "biome format --diagnostic-level error --write" } } diff --git a/example/midway-react18-ssr/src/config/config.default.ts b/example/midway-react18-ssr/src/config/config.default.ts index 20a829788..51b14167c 100644 --- a/example/midway-react18-ssr/src/config/config.default.ts +++ b/example/midway-react18-ssr/src/config/config.default.ts @@ -1,7 +1,6 @@ import { MidwayConfig } from '@midwayjs/core' export default { - // use for cookie sign key, should change to your own and keep security - keys: '1650192482948_2252' - + // use for cookie sign key, should change to your own and keep security + keys: '1650192482948_2252' } as MidwayConfig diff --git a/example/midway-react18-ssr/src/configuration.ts b/example/midway-react18-ssr/src/configuration.ts index d323c82e2..0a52fe241 100644 --- a/example/midway-react18-ssr/src/configuration.ts +++ b/example/midway-react18-ssr/src/configuration.ts @@ -1,26 +1,24 @@ -import { Configuration, App } from '@midwayjs/decorator' -import * as koa from '@midwayjs/koa' import { join } from 'path' -import { initialSSRDevProxy, getCwd } from 'ssr-common-utils' +import { App, Configuration } from '@midwayjs/decorator' +import * as koa from '@midwayjs/koa' +import { getCwd, initialSSRDevProxy } from 'ssr-common-utils' const koaStatic = require('koa-static-cache') const cwd = getCwd() @Configuration({ - imports: [ - koa - ], - importConfigs: [join(__dirname, './config')] + imports: [koa], + importConfigs: [join(__dirname, './config')] }) export class ContainerLifeCycle { - @App() - app: koa.Application + @App() + app: koa.Application - async onReady () { - this.app.use(koaStatic(join(cwd, './build'), { maxAge: 864000 })) - this.app.use(koaStatic(join(cwd, './public'), { maxAge: 864000 })) - this.app.use(koaStatic(join(cwd, './build/client'), { maxAge: 864000 })) + async onReady() { + this.app.use(koaStatic(join(cwd, './build'), { maxAge: 864000 })) + this.app.use(koaStatic(join(cwd, './public'), { maxAge: 864000 })) + this.app.use(koaStatic(join(cwd, './build/client'), { maxAge: 864000 })) - await initialSSRDevProxy(this.app) - } + await initialSSRDevProxy(this.app) + } } diff --git a/example/midway-react18-ssr/src/controller/api.ts b/example/midway-react18-ssr/src/controller/api.ts index ec6b7ca36..492383925 100644 --- a/example/midway-react18-ssr/src/controller/api.ts +++ b/example/midway-react18-ssr/src/controller/api.ts @@ -1,30 +1,30 @@ -import { Inject, Controller, Provide, Get } from '@midwayjs/decorator' +import { Controller, Get, Inject, Provide } from '@midwayjs/decorator' import { Context } from '@midwayjs/koa' -import { IApiService, IApiDetailService } from '../interface' +import { IApiDetailService, IApiService } from '../interface' @Provide() @Controller('/api') export class Api { - @Inject() - ctx: Context + @Inject() + ctx: Context - @Inject('ApiService') - service: IApiService + @Inject('ApiService') + service: IApiService - @Inject('ApiDetailService') - detailService: IApiDetailService + @Inject('ApiDetailService') + detailService: IApiDetailService - @Get('/index') - async getIndexData () { - const data = await this.service.index() - return data - } + @Get('/index') + async getIndexData() { + const data = await this.service.index() + return data + } - @Get('/detail/:id') - async getDetailData () { - const { ctx, detailService } = this - const id = ctx.params.id - const data = await detailService.index(id) - return data - } + @Get('/detail/:id') + async getDetailData() { + const { ctx, detailService } = this + const id = ctx.params.id + const data = await detailService.index(id) + return data + } } diff --git a/example/midway-react18-ssr/src/controller/index.ts b/example/midway-react18-ssr/src/controller/index.ts index 5fc2ec703..224c1e498 100755 --- a/example/midway-react18-ssr/src/controller/index.ts +++ b/example/midway-react18-ssr/src/controller/index.ts @@ -1,47 +1,46 @@ - -import { Controller, Get, Provide, Inject } from '@midwayjs/decorator' +import { Controller, Get, Inject, Provide } from '@midwayjs/decorator' import { Context } from '@midwayjs/koa' import { render } from 'ssr-core' -import { IApiService, IApiDetailService } from '../interface' +import { IApiDetailService, IApiService } from '../interface' interface IKoaContext extends Context { - apiService: IApiService - apiDeatilservice: IApiDetailService + apiService: IApiService + apiDeatilservice: IApiDetailService } @Provide() @Controller('/') export class Index { - @Inject() - ctx: IKoaContext + @Inject() + ctx: IKoaContext - @Inject('ApiService') - apiService: IApiService + @Inject('ApiService') + apiService: IApiService - @Inject('ApiDetailService') - apiDeatilservice: IApiDetailService + @Inject('ApiDetailService') + apiDeatilservice: IApiDetailService - @Get('/') - @Get('/detail/:id') - async handler (): Promise { - // 降级策略参考文档 http://doc.ssr-fc.com/docs/features$csr#%E5%A4%84%E7%90%86%20%E6%B5%81%20%E8%BF%94%E5%9B%9E%E5%BD%A2%E5%BC%8F%E7%9A%84%E9%99%8D%E7%BA%A7 - const { ctx } = this - ctx.apiService = this.apiService - ctx.apiDeatilservice = this.apiDeatilservice - const stream = await render(ctx, { - stream: true, - onError: (err) => { - console.log('ssr error', err) - stream.destroy() - render(ctx, { - stream: false, - mode: 'csr' - }).then(csrStr => { - ctx.res.end(csrStr) - }) - return null - } - }) - ctx.body = stream - } + @Get('/') + @Get('/detail/:id') + async handler(): Promise { + // 降级策略参考文档 http://doc.ssr-fc.com/docs/features$csr#%E5%A4%84%E7%90%86%20%E6%B5%81%20%E8%BF%94%E5%9B%9E%E5%BD%A2%E5%BC%8F%E7%9A%84%E9%99%8D%E7%BA%A7 + const { ctx } = this + ctx.apiService = this.apiService + ctx.apiDeatilservice = this.apiDeatilservice + const stream = await render(ctx, { + stream: true, + onError: (err) => { + console.log('ssr error', err) + stream.destroy() + render(ctx, { + stream: false, + mode: 'csr' + }).then((csrStr) => { + ctx.res.end(csrStr) + }) + return null + } + }) + ctx.body = stream + } } diff --git a/example/midway-react18-ssr/src/interface/detail.ts b/example/midway-react18-ssr/src/interface/detail.ts index 27639189a..e20bb6e93 100644 --- a/example/midway-react18-ssr/src/interface/detail.ts +++ b/example/midway-react18-ssr/src/interface/detail.ts @@ -1,4 +1,4 @@ import { DetailData } from '~/typings/data' export interface IApiDetailService { - index: (id: string) => Promise + index: (id: string) => Promise } diff --git a/example/midway-react18-ssr/src/interface/index.ts b/example/midway-react18-ssr/src/interface/index.ts index 580610521..d47053615 100644 --- a/example/midway-react18-ssr/src/interface/index.ts +++ b/example/midway-react18-ssr/src/interface/index.ts @@ -1,7 +1,7 @@ import { IndexData } from '~/typings/data' export interface IApiService { - index: () => Promise + index: () => Promise } export * from './detail' diff --git a/example/midway-react18-ssr/src/service/detail.ts b/example/midway-react18-ssr/src/service/detail.ts index ac2fc62c3..abca552ae 100644 --- a/example/midway-react18-ssr/src/service/detail.ts +++ b/example/midway-react18-ssr/src/service/detail.ts @@ -4,7 +4,7 @@ import mock from '../mock/detail' @Provide('ApiDetailService') export class ApiDetailService { - async index (id): Promise { - return await Promise.resolve(mock.data[id]) - } + async index(id): Promise { + return await Promise.resolve(mock.data[id]) + } } diff --git a/example/midway-react18-ssr/src/service/index.ts b/example/midway-react18-ssr/src/service/index.ts index 123c7e455..93d692e7b 100644 --- a/example/midway-react18-ssr/src/service/index.ts +++ b/example/midway-react18-ssr/src/service/index.ts @@ -4,7 +4,7 @@ import mock from '../mock' @Provide('ApiService') export class ApiIndexService { - async index (): Promise { - return await Promise.resolve(mock) - } + async index(): Promise { + return await Promise.resolve(mock) + } } diff --git a/example/midway-react18-ssr/web/components/layout/fetch.ts b/example/midway-react18-ssr/web/components/layout/fetch.ts index b5f68940c..dbdec9936 100644 --- a/example/midway-react18-ssr/web/components/layout/fetch.ts +++ b/example/midway-react18-ssr/web/components/layout/fetch.ts @@ -1,7 +1,5 @@ import { ReactMidwayKoaFetch } from 'ssr-types' -const fetch: ReactMidwayKoaFetch = async ({ ctx, routerProps }) => { - -} +const fetch: ReactMidwayKoaFetch = async ({ ctx, routerProps }) => {} export default fetch diff --git a/example/midway-react18-ssr/web/pages/detail/fetch.ts b/example/midway-react18-ssr/web/pages/detail/fetch.ts index a431780e7..09ccb4a50 100644 --- a/example/midway-react18-ssr/web/pages/detail/fetch.ts +++ b/example/midway-react18-ssr/web/pages/detail/fetch.ts @@ -1,14 +1,17 @@ +import { useStore } from 'ssr-common-utils' import { ReactNestFetch } from 'ssr-types' import { Ddata } from '~/typings/data' -import { useStore } from 'ssr-common-utils' -const fetch: ReactNestFetch<{ - apiDeatilservice: { - index: (id: string) => Promise - } -}, {id: string}> = async ({ ctx, routerProps }) => { - const { detailState } = useStore() - const data = __isBrowser__ ? await (await window.fetch(`/api/detail/${routerProps!.match.params.id}`)).json() : await ctx!.apiDeatilservice.index(ctx!.request.params.id) - detailState.detailData = data +const fetch: ReactNestFetch< + { + apiDeatilservice: { + index: (id: string) => Promise + } + }, + { id: string } +> = async ({ ctx, routerProps }) => { + const { detailState } = useStore() + const data = __isBrowser__ ? await (await window.fetch(`/api/detail/${routerProps!.match.params.id}`)).json() : await ctx!.apiDeatilservice.index(ctx!.request.params.id) + detailState.detailData = data } export default fetch diff --git a/example/midway-react18-ssr/web/pages/index/fetch.ts b/example/midway-react18-ssr/web/pages/index/fetch.ts index 0cd217896..f9aaf5d36 100644 --- a/example/midway-react18-ssr/web/pages/index/fetch.ts +++ b/example/midway-react18-ssr/web/pages/index/fetch.ts @@ -1,15 +1,15 @@ +import { useStore } from 'ssr-common-utils' import { ReactNestFetch } from 'ssr-types' import { IndexData } from '~/typings/data' -import { useStore } from 'ssr-common-utils' const fetch: ReactNestFetch<{ - apiService: { - index: () => Promise - } + apiService: { + index: () => Promise + } }> = async ({ ctx, routerProps }) => { - const { indexState } = useStore() - const data = __isBrowser__ ? await (await window.fetch('/api/index')).json() : await ctx!.apiService?.index() - indexState.indexData = data + const { indexState } = useStore() + const data = __isBrowser__ ? await (await window.fetch('/api/index')).json() : await ctx!.apiService?.index() + indexState.indexData = data } export default fetch diff --git a/example/midway-react18-ssr/web/store/index.ts b/example/midway-react18-ssr/web/store/index.ts index c1e9bcaa3..86f922e03 100644 --- a/example/midway-react18-ssr/web/store/index.ts +++ b/example/midway-react18-ssr/web/store/index.ts @@ -1,9 +1,9 @@ -import { state as indexState } from './modules/index' import { state as detailState } from './modules/detail' +import { state as indexState } from './modules/index' import { state as searchState } from './modules/search' export const store = { - indexState, - detailState, - searchState + indexState, + detailState, + searchState } diff --git a/example/midway-react18-ssr/web/store/modules/detail.ts b/example/midway-react18-ssr/web/store/modules/detail.ts index 18264e84d..9ff46ca19 100644 --- a/example/midway-react18-ssr/web/store/modules/detail.ts +++ b/example/midway-react18-ssr/web/store/modules/detail.ts @@ -3,5 +3,5 @@ import { Ddata } from '~/typings/data' import { proxy } from 'valtio' export const state = proxy({ - data: {} as Ddata + data: {} as Ddata }) diff --git a/example/midway-react18-ssr/web/store/modules/index.ts b/example/midway-react18-ssr/web/store/modules/index.ts index 2dfa804dd..a787db6c8 100644 --- a/example/midway-react18-ssr/web/store/modules/index.ts +++ b/example/midway-react18-ssr/web/store/modules/index.ts @@ -1,8 +1,7 @@ - import { IndexData } from '~/typings/data' import { proxy } from 'valtio' export const state = proxy({ - data: {} as IndexData + data: {} as IndexData }) diff --git a/example/midway-react18-ssr/web/store/modules/search.ts b/example/midway-react18-ssr/web/store/modules/search.ts index 756abc32b..e9ab76d2e 100644 --- a/example/midway-react18-ssr/web/store/modules/search.ts +++ b/example/midway-react18-ssr/web/store/modules/search.ts @@ -1,6 +1,5 @@ - import { proxy } from 'valtio' export const state = proxy({ - searchText: '' + searchText: '' }) diff --git a/example/midway-vue-ssr/.eslintignore b/example/midway-vue-ssr/.eslintignore deleted file mode 100644 index c73b4e132..000000000 --- a/example/midway-vue-ssr/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -build -run -typings \ No newline at end of file diff --git a/example/midway-vue-ssr/.eslintrc.js b/example/midway-vue-ssr/.eslintrc.js deleted file mode 100644 index 7fe035579..000000000 --- a/example/midway-vue-ssr/.eslintrc.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - root: true, - extends: [ - 'standard-vue-ts' - ], - globals: { - __isBrowser__: 'readonly', - defineProps: 'readonly' - } -} diff --git a/example/midway-vue-ssr/config.ts b/example/midway-vue-ssr/config.ts index 35da1144c..696b10bb7 100644 --- a/example/midway-vue-ssr/config.ts +++ b/example/midway-vue-ssr/config.ts @@ -1,7 +1,5 @@ import type { UserConfig } from 'ssr-types' -const userConfig: UserConfig = { - -} +const userConfig: UserConfig = {} export { userConfig } diff --git a/example/midway-vue-ssr/package.json b/example/midway-vue-ssr/package.json index 65b22aa9d..cbf0f5325 100644 --- a/example/midway-vue-ssr/package.json +++ b/example/midway-vue-ssr/package.json @@ -21,9 +21,9 @@ "vuex": "^3.6.2" }, "devDependencies": { + "@biomejs/biome": "^1.9.4", "@midwayjs/mock": "^3.0.0", "cross-env": "^7.0.3", - "eslint-config-standard-vue-ts": "^1.0.5", "ssr": "^6.0.0", "ssr-plugin-midway": "^6.0.0", "ssr-plugin-vue": "^6.0.0", @@ -36,8 +36,8 @@ "start": "ssr start", "build": "ssr build", "deploy": "ssr build && ssr deploy", - "lint": "eslint . --ext .js,.tsx,.ts,.vue --cache", - "lint:fix": "eslint . --ext .js,.tsx,.ts,.vue --cache --fix" + "lint": "biome format --diagnostic-level error", + "lint:fix": "biome format --diagnostic-level error --write" }, "midway-integration": { "tsCodeRoot": "src" diff --git a/example/midway-vue-ssr/src/config/config.default.ts b/example/midway-vue-ssr/src/config/config.default.ts index 3f7c87459..51b14167c 100644 --- a/example/midway-vue-ssr/src/config/config.default.ts +++ b/example/midway-vue-ssr/src/config/config.default.ts @@ -1,6 +1,6 @@ import { MidwayConfig } from '@midwayjs/core' export default { - // use for cookie sign key, should change to your own and keep security - keys: '1650192482948_2252' + // use for cookie sign key, should change to your own and keep security + keys: '1650192482948_2252' } as MidwayConfig diff --git a/example/midway-vue-ssr/src/configuration.ts b/example/midway-vue-ssr/src/configuration.ts index d323c82e2..0a52fe241 100644 --- a/example/midway-vue-ssr/src/configuration.ts +++ b/example/midway-vue-ssr/src/configuration.ts @@ -1,26 +1,24 @@ -import { Configuration, App } from '@midwayjs/decorator' -import * as koa from '@midwayjs/koa' import { join } from 'path' -import { initialSSRDevProxy, getCwd } from 'ssr-common-utils' +import { App, Configuration } from '@midwayjs/decorator' +import * as koa from '@midwayjs/koa' +import { getCwd, initialSSRDevProxy } from 'ssr-common-utils' const koaStatic = require('koa-static-cache') const cwd = getCwd() @Configuration({ - imports: [ - koa - ], - importConfigs: [join(__dirname, './config')] + imports: [koa], + importConfigs: [join(__dirname, './config')] }) export class ContainerLifeCycle { - @App() - app: koa.Application + @App() + app: koa.Application - async onReady () { - this.app.use(koaStatic(join(cwd, './build'), { maxAge: 864000 })) - this.app.use(koaStatic(join(cwd, './public'), { maxAge: 864000 })) - this.app.use(koaStatic(join(cwd, './build/client'), { maxAge: 864000 })) + async onReady() { + this.app.use(koaStatic(join(cwd, './build'), { maxAge: 864000 })) + this.app.use(koaStatic(join(cwd, './public'), { maxAge: 864000 })) + this.app.use(koaStatic(join(cwd, './build/client'), { maxAge: 864000 })) - await initialSSRDevProxy(this.app) - } + await initialSSRDevProxy(this.app) + } } diff --git a/example/midway-vue-ssr/src/controller/api.ts b/example/midway-vue-ssr/src/controller/api.ts index ec6b7ca36..492383925 100644 --- a/example/midway-vue-ssr/src/controller/api.ts +++ b/example/midway-vue-ssr/src/controller/api.ts @@ -1,30 +1,30 @@ -import { Inject, Controller, Provide, Get } from '@midwayjs/decorator' +import { Controller, Get, Inject, Provide } from '@midwayjs/decorator' import { Context } from '@midwayjs/koa' -import { IApiService, IApiDetailService } from '../interface' +import { IApiDetailService, IApiService } from '../interface' @Provide() @Controller('/api') export class Api { - @Inject() - ctx: Context + @Inject() + ctx: Context - @Inject('ApiService') - service: IApiService + @Inject('ApiService') + service: IApiService - @Inject('ApiDetailService') - detailService: IApiDetailService + @Inject('ApiDetailService') + detailService: IApiDetailService - @Get('/index') - async getIndexData () { - const data = await this.service.index() - return data - } + @Get('/index') + async getIndexData() { + const data = await this.service.index() + return data + } - @Get('/detail/:id') - async getDetailData () { - const { ctx, detailService } = this - const id = ctx.params.id - const data = await detailService.index(id) - return data - } + @Get('/detail/:id') + async getDetailData() { + const { ctx, detailService } = this + const id = ctx.params.id + const data = await detailService.index(id) + return data + } } diff --git a/example/midway-vue-ssr/src/controller/index.ts b/example/midway-vue-ssr/src/controller/index.ts index 4679bb780..ec3be9daf 100755 --- a/example/midway-vue-ssr/src/controller/index.ts +++ b/example/midway-vue-ssr/src/controller/index.ts @@ -1,45 +1,45 @@ -import { Controller, Get, Provide, Inject } from '@midwayjs/decorator' +import { Controller, Get, Inject, Provide } from '@midwayjs/decorator' import { Context } from '@midwayjs/koa' import { render } from 'ssr-core' -import { IApiService, IApiDetailService } from '../interface' +import { IApiDetailService, IApiService } from '../interface' interface IKoaContext extends Context { - apiService: IApiService - apiDeatilservice: IApiDetailService + apiService: IApiService + apiDeatilservice: IApiDetailService } @Provide() @Controller('/') export class Index { - @Inject() - ctx: IKoaContext + @Inject() + ctx: IKoaContext - @Inject('ApiService') - apiService: IApiService + @Inject('ApiService') + apiService: IApiService - @Inject('ApiDetailService') - apiDeatilservice: IApiDetailService + @Inject('ApiDetailService') + apiDeatilservice: IApiDetailService - @Get('/') - @Get('/detail/:id') - async handler (): Promise { - // 降级策略参考文档 http://doc.ssr-fc.com/docs/features$csr#%E5%A4%84%E7%90%86%20%E6%B5%81%20%E8%BF%94%E5%9B%9E%E5%BD%A2%E5%BC%8F%E7%9A%84%E9%99%8D%E7%BA%A7 - const { ctx } = this - ctx.apiService = this.apiService - ctx.apiDeatilservice = this.apiDeatilservice - const stream = await render(this.ctx, { - stream: true, - mode: 'ssr' - }) - stream.on('error', async (err) => { - console.log('ssr error', err) - stream.destroy() - const csrStream = await render(ctx, { - stream: false, // 这里只能用 string 形式来渲染 koa 无法二次赋值 stream 给 body - mode: 'csr' - }) - ctx.res.end(csrStream) - }) - ctx.body = stream - } + @Get('/') + @Get('/detail/:id') + async handler(): Promise { + // 降级策略参考文档 http://doc.ssr-fc.com/docs/features$csr#%E5%A4%84%E7%90%86%20%E6%B5%81%20%E8%BF%94%E5%9B%9E%E5%BD%A2%E5%BC%8F%E7%9A%84%E9%99%8D%E7%BA%A7 + const { ctx } = this + ctx.apiService = this.apiService + ctx.apiDeatilservice = this.apiDeatilservice + const stream = await render(this.ctx, { + stream: true, + mode: 'ssr' + }) + stream.on('error', async (err) => { + console.log('ssr error', err) + stream.destroy() + const csrStream = await render(ctx, { + stream: false, // 这里只能用 string 形式来渲染 koa 无法二次赋值 stream 给 body + mode: 'csr' + }) + ctx.res.end(csrStream) + }) + ctx.body = stream + } } diff --git a/example/midway-vue-ssr/src/interface/detail.ts b/example/midway-vue-ssr/src/interface/detail.ts index 27639189a..e20bb6e93 100644 --- a/example/midway-vue-ssr/src/interface/detail.ts +++ b/example/midway-vue-ssr/src/interface/detail.ts @@ -1,4 +1,4 @@ import { DetailData } from '~/typings/data' export interface IApiDetailService { - index: (id: string) => Promise + index: (id: string) => Promise } diff --git a/example/midway-vue-ssr/src/interface/index.ts b/example/midway-vue-ssr/src/interface/index.ts index 580610521..d47053615 100644 --- a/example/midway-vue-ssr/src/interface/index.ts +++ b/example/midway-vue-ssr/src/interface/index.ts @@ -1,7 +1,7 @@ import { IndexData } from '~/typings/data' export interface IApiService { - index: () => Promise + index: () => Promise } export * from './detail' diff --git a/example/midway-vue-ssr/src/service/detail.ts b/example/midway-vue-ssr/src/service/detail.ts index ac2fc62c3..abca552ae 100644 --- a/example/midway-vue-ssr/src/service/detail.ts +++ b/example/midway-vue-ssr/src/service/detail.ts @@ -4,7 +4,7 @@ import mock from '../mock/detail' @Provide('ApiDetailService') export class ApiDetailService { - async index (id): Promise { - return await Promise.resolve(mock.data[id]) - } + async index(id): Promise { + return await Promise.resolve(mock.data[id]) + } } diff --git a/example/midway-vue-ssr/src/service/index.ts b/example/midway-vue-ssr/src/service/index.ts index 123c7e455..93d692e7b 100644 --- a/example/midway-vue-ssr/src/service/index.ts +++ b/example/midway-vue-ssr/src/service/index.ts @@ -4,7 +4,7 @@ import mock from '../mock' @Provide('ApiService') export class ApiIndexService { - async index (): Promise { - return await Promise.resolve(mock) - } + async index(): Promise { + return await Promise.resolve(mock) + } } diff --git a/example/midway-vue-ssr/web/components/brief/index.vue b/example/midway-vue-ssr/web/components/brief/index.vue index d1df38215..0ea286b46 100644 --- a/example/midway-vue-ssr/web/components/brief/index.vue +++ b/example/midway-vue-ssr/web/components/brief/index.vue @@ -16,14 +16,13 @@ diff --git a/example/midway-vue-ssr/web/components/layout/App.vue b/example/midway-vue-ssr/web/components/layout/App.vue index 1c035804b..4161528bc 100644 --- a/example/midway-vue-ssr/web/components/layout/App.vue +++ b/example/midway-vue-ssr/web/components/layout/App.vue @@ -5,7 +5,7 @@ diff --git a/example/midway-vue-ssr/web/components/layout/fetch.ts b/example/midway-vue-ssr/web/components/layout/fetch.ts index b00d15e6f..f623bb241 100644 --- a/example/midway-vue-ssr/web/components/layout/fetch.ts +++ b/example/midway-vue-ssr/web/components/layout/fetch.ts @@ -1,5 +1,3 @@ import { Params } from '~/typings/data' -export default async ({ store, router, ctx }: Params) => { - -} +export default async ({ store, router, ctx }: Params) => {} diff --git a/example/midway-vue-ssr/web/components/player/index.vue b/example/midway-vue-ssr/web/components/player/index.vue index 23ab1ac59..a611efbaf 100644 --- a/example/midway-vue-ssr/web/components/player/index.vue +++ b/example/midway-vue-ssr/web/components/player/index.vue @@ -18,20 +18,19 @@ diff --git a/example/midway-vue-ssr/web/components/recommend/index.vue b/example/midway-vue-ssr/web/components/recommend/index.vue index cf9c72960..d8d984de4 100644 --- a/example/midway-vue-ssr/web/components/recommend/index.vue +++ b/example/midway-vue-ssr/web/components/recommend/index.vue @@ -19,10 +19,8 @@ diff --git a/example/midway-vue-ssr/web/components/rectangle/index.vue b/example/midway-vue-ssr/web/components/rectangle/index.vue index 5b575c3dc..2999db7b8 100644 --- a/example/midway-vue-ssr/web/components/rectangle/index.vue +++ b/example/midway-vue-ssr/web/components/rectangle/index.vue @@ -16,14 +16,13 @@ diff --git a/example/midway-vue-ssr/web/components/search/index.vue b/example/midway-vue-ssr/web/components/search/index.vue index f28d2cd32..2401a6a47 100644 --- a/example/midway-vue-ssr/web/components/search/index.vue +++ b/example/midway-vue-ssr/web/components/search/index.vue @@ -10,24 +10,24 @@ import { mapState } from 'vuex' export default { - computed: { - ...mapState({ - searchText: state => state.searchStore.searchText - }) - }, + computed: { + ...mapState({ + searchText: (state) => state.searchStore.searchText + }) + }, - methods: { - setText (e) { - this.$store.dispatch('searchStore/setText', { - payload: { - text: e.target.value - } - }) - }, - toSearch () { - location.href = `https://search.youku.com/search_video?keyword=${this.searchText}` - } - } + methods: { + setText(e) { + this.$store.dispatch('searchStore/setText', { + payload: { + text: e.target.value + } + }) + }, + toSearch() { + location.href = `https://search.youku.com/search_video?keyword=${this.searchText}` + } + } } diff --git a/example/midway-vue-ssr/web/components/slider/index.vue b/example/midway-vue-ssr/web/components/slider/index.vue index 7177065da..a307bc9da 100644 --- a/example/midway-vue-ssr/web/components/slider/index.vue +++ b/example/midway-vue-ssr/web/components/slider/index.vue @@ -16,43 +16,42 @@ diff --git a/example/midway-vue-ssr/web/pages/detail/fetch.ts b/example/midway-vue-ssr/web/pages/detail/fetch.ts index acae4c570..2167f3876 100644 --- a/example/midway-vue-ssr/web/pages/detail/fetch.ts +++ b/example/midway-vue-ssr/web/pages/detail/fetch.ts @@ -1,7 +1,7 @@ import { Params } from '~/typings/data' export default async ({ store, router, ctx }: Params) => { - // 阅读文档获得更多信息 http://doc.ssr-fc.com/docs/features$fetch#%E5%88%A4%E6%96%AD%E5%BD%93%E5%89%8D%E7%8E%AF%E5%A2%83 - const data = __isBrowser__ ? await (await window.fetch(`/api/detail/${router.params.id}`)).json() : await ctx?.apiDeatilservice?.index(ctx.params.id) - await store.dispatch('detailStore/initialData', { payload: data }) + // 阅读文档获得更多信息 http://doc.ssr-fc.com/docs/features$fetch#%E5%88%A4%E6%96%AD%E5%BD%93%E5%89%8D%E7%8E%AF%E5%A2%83 + const data = __isBrowser__ ? await (await window.fetch(`/api/detail/${router.params.id}`)).json() : await ctx?.apiDeatilservice?.index(ctx.params.id) + await store.dispatch('detailStore/initialData', { payload: data }) } diff --git a/example/midway-vue-ssr/web/pages/detail/render$id.vue b/example/midway-vue-ssr/web/pages/detail/render$id.vue index 2d4f40c76..175929b48 100644 --- a/example/midway-vue-ssr/web/pages/detail/render$id.vue +++ b/example/midway-vue-ssr/web/pages/detail/render$id.vue @@ -21,17 +21,17 @@ import Brief from '@/components/brief/index.vue' import Recommend from '@/components/recommend/index.vue' export default { - components: { - Player, - Search, - Brief, - Recommend - }, - computed: { - ...mapState({ - detailData: state => state.detailStore?.data - }) - } + components: { + Player, + Search, + Brief, + Recommend + }, + computed: { + ...mapState({ + detailData: (state) => state.detailStore?.data + }) + } } diff --git a/example/midway-vue-ssr/web/pages/index/fetch.ts b/example/midway-vue-ssr/web/pages/index/fetch.ts index 84be460a1..369d6134f 100644 --- a/example/midway-vue-ssr/web/pages/index/fetch.ts +++ b/example/midway-vue-ssr/web/pages/index/fetch.ts @@ -1,7 +1,7 @@ import { Params } from '~/typings/data' export default async ({ store, router, ctx }: Params) => { - // 阅读文档获得更多信息 http://doc.ssr-fc.com/docs/features$fetch#%E5%88%A4%E6%96%AD%E5%BD%93%E5%89%8D%E7%8E%AF%E5%A2%83 - const data = __isBrowser__ ? await (await window.fetch('/api/index')).json() : await ctx?.apiService?.index() - await store.dispatch('indexStore/initialData', { payload: data }) + // 阅读文档获得更多信息 http://doc.ssr-fc.com/docs/features$fetch#%E5%88%A4%E6%96%AD%E5%BD%93%E5%89%8D%E7%8E%AF%E5%A2%83 + const data = __isBrowser__ ? await (await window.fetch('/api/index')).json() : await ctx?.apiService?.index() + await store.dispatch('indexStore/initialData', { payload: data }) } diff --git a/example/midway-vue-ssr/web/pages/index/render.vue b/example/midway-vue-ssr/web/pages/index/render.vue index 97b03712a..15e04c2c6 100644 --- a/example/midway-vue-ssr/web/pages/index/render.vue +++ b/example/midway-vue-ssr/web/pages/index/render.vue @@ -19,16 +19,16 @@ import Rectangle from '@/components/rectangle/index.vue' import Search from '@/components/search/index.vue' export default { - components: { - Slider, - Rectangle, - Search - }, - computed: { - ...mapState({ - indexData: state => state.indexStore?.data - }) - } + components: { + Slider, + Rectangle, + Search + }, + computed: { + ...mapState({ + indexData: (state) => state.indexStore?.data + }) + } } diff --git a/example/midway-vue-ssr/web/store/index.ts b/example/midway-vue-ssr/web/store/index.ts index 4afa7b293..f45e45ad6 100644 --- a/example/midway-vue-ssr/web/store/index.ts +++ b/example/midway-vue-ssr/web/store/index.ts @@ -1,12 +1,10 @@ -import { indexStore } from './modules/index' import { detailStore } from './modules/detail' +import { indexStore } from './modules/index' import { searchStore } from './modules/search' const modules = { - indexStore, - detailStore, - searchStore -} -export { - modules + indexStore, + detailStore, + searchStore } +export { modules } diff --git a/example/midway-vue-ssr/web/store/modules/detail.ts b/example/midway-vue-ssr/web/store/modules/detail.ts index a8d62b76b..7db492c14 100644 --- a/example/midway-vue-ssr/web/store/modules/detail.ts +++ b/example/midway-vue-ssr/web/store/modules/detail.ts @@ -1,20 +1,18 @@ const detailStore = { - namespaced: true, - state: { - data: {} - }, - mutations: { - setData (state, payload) { - state.data = payload - } - }, - actions: { - initialData ({ commit }, { payload }) { - commit('setData', payload) - } - } + namespaced: true, + state: { + data: {} + }, + mutations: { + setData(state, payload) { + state.data = payload + } + }, + actions: { + initialData({ commit }, { payload }) { + commit('setData', payload) + } + } } -export { - detailStore -} +export { detailStore } diff --git a/example/midway-vue-ssr/web/store/modules/index.ts b/example/midway-vue-ssr/web/store/modules/index.ts index d795c7f7e..11498c48c 100644 --- a/example/midway-vue-ssr/web/store/modules/index.ts +++ b/example/midway-vue-ssr/web/store/modules/index.ts @@ -1,20 +1,18 @@ const indexStore = { - namespaced: true, - state: { - data: {} - }, - mutations: { - setData (state, payload) { - state.data = payload.data - } - }, - actions: { - initialData ({ commit }, { payload }) { - commit('setData', payload) - } - } + namespaced: true, + state: { + data: {} + }, + mutations: { + setData(state, payload) { + state.data = payload.data + } + }, + actions: { + initialData({ commit }, { payload }) { + commit('setData', payload) + } + } } -export { - indexStore -} +export { indexStore } diff --git a/example/midway-vue-ssr/web/store/modules/search.ts b/example/midway-vue-ssr/web/store/modules/search.ts index 5af01b31e..ad039a29a 100644 --- a/example/midway-vue-ssr/web/store/modules/search.ts +++ b/example/midway-vue-ssr/web/store/modules/search.ts @@ -1,20 +1,18 @@ const searchStore = { - namespaced: true, - state: { - searchText: '' - }, - mutations: { - setText (state, payload) { - state.searchText = payload.text - } - }, - actions: { - setText ({ commit }, { payload }) { - commit('setText', payload) - } - } + namespaced: true, + state: { + searchText: '' + }, + mutations: { + setText(state, payload) { + state.searchText = payload.text + } + }, + actions: { + setText({ commit }, { payload }) { + commit('setText', payload) + } + } } -export { - searchStore -} +export { searchStore } diff --git a/example/midway-vue3-ssr/.eslintignore b/example/midway-vue3-ssr/.eslintignore deleted file mode 100644 index c73b4e132..000000000 --- a/example/midway-vue3-ssr/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -build -run -typings \ No newline at end of file diff --git a/example/midway-vue3-ssr/.eslintrc.js b/example/midway-vue3-ssr/.eslintrc.js deleted file mode 100644 index 7fe035579..000000000 --- a/example/midway-vue3-ssr/.eslintrc.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - root: true, - extends: [ - 'standard-vue-ts' - ], - globals: { - __isBrowser__: 'readonly', - defineProps: 'readonly' - } -} diff --git a/example/midway-vue3-ssr/config.ts b/example/midway-vue3-ssr/config.ts index 35da1144c..696b10bb7 100644 --- a/example/midway-vue3-ssr/config.ts +++ b/example/midway-vue3-ssr/config.ts @@ -1,7 +1,5 @@ import type { UserConfig } from 'ssr-types' -const userConfig: UserConfig = { - -} +const userConfig: UserConfig = {} export { userConfig } diff --git a/example/midway-vue3-ssr/package.json b/example/midway-vue3-ssr/package.json index 5503d3b3c..fb5661aa4 100644 --- a/example/midway-vue3-ssr/package.json +++ b/example/midway-vue3-ssr/package.json @@ -8,6 +8,7 @@ "@midwayjs/decorator": "^3.0.0", "@midwayjs/koa": "^3.0.0", "@midwayjs/logger": "^3.0.0", + "@vue/server-renderer": "^3.0.7", "koa-static-cache": "^5.1.4", "midway-schedule": "^2.0.0", "pinia": "^2.0.13", @@ -18,12 +19,11 @@ "swiper": "6.7.5", "vue": "^3.0.0", "vue-router": "^4.2.4", - "vuex": "^4.0.0", - "@vue/server-renderer": "^3.0.7" + "vuex": "^4.0.0" }, "devDependencies": { + "@biomejs/biome": "^1.9.4", "@midwayjs/mock": "^3.0.0", - "eslint-config-standard-vue-ts": "^1.0.5", "ssr": "^6.0.0", "ssr-plugin-midway": "^6.0.0", "ssr-plugin-vue3": "^6.0.0", @@ -40,7 +40,7 @@ "build:o": "ssr build --optimize", "build:vite": "ssr build --vite", "deploy": "ssr build && ssr deploy", - "lint": "eslint . --ext .js,.tsx,.ts,.vue --cache", - "lint:fix": "eslint . --ext .js,.tsx,.ts,.vue --cache --fix" + "lint": "biome format --diagnostic-level error", + "lint:fix": "biome format --diagnostic-level error --write" } } diff --git a/example/midway-vue3-ssr/src/config/config.default.ts b/example/midway-vue3-ssr/src/config/config.default.ts index 3f7c87459..51b14167c 100644 --- a/example/midway-vue3-ssr/src/config/config.default.ts +++ b/example/midway-vue3-ssr/src/config/config.default.ts @@ -1,6 +1,6 @@ import { MidwayConfig } from '@midwayjs/core' export default { - // use for cookie sign key, should change to your own and keep security - keys: '1650192482948_2252' + // use for cookie sign key, should change to your own and keep security + keys: '1650192482948_2252' } as MidwayConfig diff --git a/example/midway-vue3-ssr/src/configuration.ts b/example/midway-vue3-ssr/src/configuration.ts index d323c82e2..0a52fe241 100644 --- a/example/midway-vue3-ssr/src/configuration.ts +++ b/example/midway-vue3-ssr/src/configuration.ts @@ -1,26 +1,24 @@ -import { Configuration, App } from '@midwayjs/decorator' -import * as koa from '@midwayjs/koa' import { join } from 'path' -import { initialSSRDevProxy, getCwd } from 'ssr-common-utils' +import { App, Configuration } from '@midwayjs/decorator' +import * as koa from '@midwayjs/koa' +import { getCwd, initialSSRDevProxy } from 'ssr-common-utils' const koaStatic = require('koa-static-cache') const cwd = getCwd() @Configuration({ - imports: [ - koa - ], - importConfigs: [join(__dirname, './config')] + imports: [koa], + importConfigs: [join(__dirname, './config')] }) export class ContainerLifeCycle { - @App() - app: koa.Application + @App() + app: koa.Application - async onReady () { - this.app.use(koaStatic(join(cwd, './build'), { maxAge: 864000 })) - this.app.use(koaStatic(join(cwd, './public'), { maxAge: 864000 })) - this.app.use(koaStatic(join(cwd, './build/client'), { maxAge: 864000 })) + async onReady() { + this.app.use(koaStatic(join(cwd, './build'), { maxAge: 864000 })) + this.app.use(koaStatic(join(cwd, './public'), { maxAge: 864000 })) + this.app.use(koaStatic(join(cwd, './build/client'), { maxAge: 864000 })) - await initialSSRDevProxy(this.app) - } + await initialSSRDevProxy(this.app) + } } diff --git a/example/midway-vue3-ssr/src/controller/api.ts b/example/midway-vue3-ssr/src/controller/api.ts index ec6b7ca36..492383925 100644 --- a/example/midway-vue3-ssr/src/controller/api.ts +++ b/example/midway-vue3-ssr/src/controller/api.ts @@ -1,30 +1,30 @@ -import { Inject, Controller, Provide, Get } from '@midwayjs/decorator' +import { Controller, Get, Inject, Provide } from '@midwayjs/decorator' import { Context } from '@midwayjs/koa' -import { IApiService, IApiDetailService } from '../interface' +import { IApiDetailService, IApiService } from '../interface' @Provide() @Controller('/api') export class Api { - @Inject() - ctx: Context + @Inject() + ctx: Context - @Inject('ApiService') - service: IApiService + @Inject('ApiService') + service: IApiService - @Inject('ApiDetailService') - detailService: IApiDetailService + @Inject('ApiDetailService') + detailService: IApiDetailService - @Get('/index') - async getIndexData () { - const data = await this.service.index() - return data - } + @Get('/index') + async getIndexData() { + const data = await this.service.index() + return data + } - @Get('/detail/:id') - async getDetailData () { - const { ctx, detailService } = this - const id = ctx.params.id - const data = await detailService.index(id) - return data - } + @Get('/detail/:id') + async getDetailData() { + const { ctx, detailService } = this + const id = ctx.params.id + const data = await detailService.index(id) + return data + } } diff --git a/example/midway-vue3-ssr/src/controller/index.ts b/example/midway-vue3-ssr/src/controller/index.ts index a10a1b8fa..ce02fd9af 100755 --- a/example/midway-vue3-ssr/src/controller/index.ts +++ b/example/midway-vue3-ssr/src/controller/index.ts @@ -1,44 +1,44 @@ -import { Controller, Get, Provide, Inject } from '@midwayjs/decorator' +import { Controller, Get, Inject, Provide } from '@midwayjs/decorator' import { Context } from '@midwayjs/koa' import { render } from 'ssr-core' -import { IApiService, IApiDetailService } from '../interface' +import { IApiDetailService, IApiService } from '../interface' interface IKoaContext extends Context { - apiService: IApiService - apiDeatilservice: IApiDetailService + apiService: IApiService + apiDeatilservice: IApiDetailService } @Provide() @Controller('/') export class Index { - @Inject() - ctx: IKoaContext + @Inject() + ctx: IKoaContext - @Inject('ApiService') - apiService: IApiService + @Inject('ApiService') + apiService: IApiService - @Inject('ApiDetailService') - apiDeatilservice: IApiDetailService + @Inject('ApiDetailService') + apiDeatilservice: IApiDetailService - @Get('/') - @Get('/detail/:id') - async handler (): Promise { - // 渲染降级参考文档 http://doc.ssr-fc.com/docs/features$csr#%E5%A4%84%E7%90%86%20%E6%B5%81%20%E8%BF%94%E5%9B%9E%E5%BD%A2%E5%BC%8F%E7%9A%84%E9%99%8D%E7%BA%A7 - const { ctx } = this - try { - ctx.apiService = this.apiService - ctx.apiDeatilservice = this.apiDeatilservice - const stream = await render(this.ctx, { - stream: true - }) - ctx.body = stream - } catch (error) { - console.log('ssr error', error) - const stream = await render(ctx, { - stream: true, - mode: 'csr' - }) - ctx.body = stream - } - } + @Get('/') + @Get('/detail/:id') + async handler(): Promise { + // 渲染降级参考文档 http://doc.ssr-fc.com/docs/features$csr#%E5%A4%84%E7%90%86%20%E6%B5%81%20%E8%BF%94%E5%9B%9E%E5%BD%A2%E5%BC%8F%E7%9A%84%E9%99%8D%E7%BA%A7 + const { ctx } = this + try { + ctx.apiService = this.apiService + ctx.apiDeatilservice = this.apiDeatilservice + const stream = await render(this.ctx, { + stream: true + }) + ctx.body = stream + } catch (error) { + console.log('ssr error', error) + const stream = await render(ctx, { + stream: true, + mode: 'csr' + }) + ctx.body = stream + } + } } diff --git a/example/midway-vue3-ssr/src/interface/detail.ts b/example/midway-vue3-ssr/src/interface/detail.ts index 27639189a..e20bb6e93 100644 --- a/example/midway-vue3-ssr/src/interface/detail.ts +++ b/example/midway-vue3-ssr/src/interface/detail.ts @@ -1,4 +1,4 @@ import { DetailData } from '~/typings/data' export interface IApiDetailService { - index: (id: string) => Promise + index: (id: string) => Promise } diff --git a/example/midway-vue3-ssr/src/interface/index.ts b/example/midway-vue3-ssr/src/interface/index.ts index 580610521..d47053615 100644 --- a/example/midway-vue3-ssr/src/interface/index.ts +++ b/example/midway-vue3-ssr/src/interface/index.ts @@ -1,7 +1,7 @@ import { IndexData } from '~/typings/data' export interface IApiService { - index: () => Promise + index: () => Promise } export * from './detail' diff --git a/example/midway-vue3-ssr/src/service/detail.ts b/example/midway-vue3-ssr/src/service/detail.ts index ac2fc62c3..abca552ae 100644 --- a/example/midway-vue3-ssr/src/service/detail.ts +++ b/example/midway-vue3-ssr/src/service/detail.ts @@ -4,7 +4,7 @@ import mock from '../mock/detail' @Provide('ApiDetailService') export class ApiDetailService { - async index (id): Promise { - return await Promise.resolve(mock.data[id]) - } + async index(id): Promise { + return await Promise.resolve(mock.data[id]) + } } diff --git a/example/midway-vue3-ssr/src/service/index.ts b/example/midway-vue3-ssr/src/service/index.ts index 123c7e455..93d692e7b 100644 --- a/example/midway-vue3-ssr/src/service/index.ts +++ b/example/midway-vue3-ssr/src/service/index.ts @@ -4,7 +4,7 @@ import mock from '../mock' @Provide('ApiService') export class ApiIndexService { - async index (): Promise { - return await Promise.resolve(mock) - } + async index(): Promise { + return await Promise.resolve(mock) + } } diff --git a/example/midway-vue3-ssr/web/components/brief/index.vue b/example/midway-vue3-ssr/web/components/brief/index.vue index 30b1d973d..572d40de2 100644 --- a/example/midway-vue3-ssr/web/components/brief/index.vue +++ b/example/midway-vue3-ssr/web/components/brief/index.vue @@ -20,7 +20,7 @@ import { toRefs } from 'vue' import { BriefDataNode } from '~/typings/data' const props = defineProps<{ - data: BriefDataNode[] + data: BriefDataNode[] }>() const briefData = toRefs(props.data[0].data) diff --git a/example/midway-vue3-ssr/web/components/layout/App.vue b/example/midway-vue3-ssr/web/components/layout/App.vue index e065a7417..7c2134936 100644 --- a/example/midway-vue3-ssr/web/components/layout/App.vue +++ b/example/midway-vue3-ssr/web/components/layout/App.vue @@ -8,8 +8,8 @@ import { App } from 'vue' const props = defineProps<{ - ssrApp: App, - asyncData: { value: any } + ssrApp: App + asyncData: { value: any } }>() diff --git a/example/midway-vue3-ssr/web/components/layout/fetch.ts b/example/midway-vue3-ssr/web/components/layout/fetch.ts index b00d15e6f..f623bb241 100644 --- a/example/midway-vue3-ssr/web/components/layout/fetch.ts +++ b/example/midway-vue3-ssr/web/components/layout/fetch.ts @@ -1,5 +1,3 @@ import { Params } from '~/typings/data' -export default async ({ store, router, ctx }: Params) => { - -} +export default async ({ store, router, ctx }: Params) => {} diff --git a/example/midway-vue3-ssr/web/components/player/index.vue b/example/midway-vue3-ssr/web/components/player/index.vue index f8c1f2a9a..31a284cca 100644 --- a/example/midway-vue3-ssr/web/components/player/index.vue +++ b/example/midway-vue3-ssr/web/components/player/index.vue @@ -21,14 +21,13 @@ import { toRefs, ref } from 'vue' import { PlayerDataNode } from '~/typings/data' const props = defineProps<{ - data: PlayerDataNode[] + data: PlayerDataNode[] }>() const playData = toRefs(props.data[0].data) const play = ref(false) const playVideo = () => { - play.value = true + play.value = true } -