From c4b0ab6258db1cd73047cabf29b7cc53dbee0d14 Mon Sep 17 00:00:00 2001 From: sobird Date: Mon, 18 Nov 2024 18:35:12 +0800 Subject: [PATCH] chore: update --- .eslintrc.cjs | 37 ++-------- .../role/components/role-form/index.tsx | 5 +- app/dashboard/role/page.tsx | 11 +-- app/page.tsx | 9 ++- models/index.ts | 12 ++-- next.config.js | 2 +- package.json | 4 +- tsconfig.json | 71 ++++++++----------- 8 files changed, 59 insertions(+), 92 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index f3a5119..0fd8ac8 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,41 +1,18 @@ module.exports = { root: true, extends: [ - 'sobird/react.cjs', + 'sobird/typescript-react.cjs', + 'sobird/typescript.cjs', 'plugin:@next/next/recommended', + 'plugin:@next/next/core-web-vitals', ], plugins: [ '@next/next', ], - overrides: [ - { - files: ['**/*.ts?(x)'], - extends: [ - 'sobird/typescript-react.cjs', - ], - rules: { - 'import/prefer-default-export': 'off', - 'import/no-extraneous-dependencies': 'off', - 'no-param-reassign': [ - 'error', - { - props: true, - ignorePropertyModificationsFor: [ - 'ctx', // for Koa routing - 'req', // for Express requests - 'request', // for Express requests - 'res', // for Express responses - 'response', // for Express responses - 'state', // for store state - 'model', // for store state - ], - }, - ], - 'prefer-promise-reject-errors': 'off', - }, - }, - ], + overrides: [], rules: { - + 'import/no-extraneous-dependencies': 'off', + 'import/no-unresolved': 'off', + 'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'], }, }; diff --git a/app/dashboard/role/components/role-form/index.tsx b/app/dashboard/role/components/role-form/index.tsx index 4c792e1..076fdc1 100644 --- a/app/dashboard/role/components/role-form/index.tsx +++ b/app/dashboard/role/components/role-form/index.tsx @@ -8,10 +8,11 @@ 'use client'; -import React, { PropsWithChildren } from 'react'; import { Form, Input } from 'antd'; -import { RoleFormRule } from '@/zod/role'; +import React, { PropsWithChildren } from 'react'; + import withActionForm from '@/components/with-action-form'; +import { RoleFormRule } from '@/zod/role'; const RoleForm: React.FC = ({ children }) => { return ( diff --git a/app/dashboard/role/page.tsx b/app/dashboard/role/page.tsx index 6b96055..e72b62e 100644 --- a/app/dashboard/role/page.tsx +++ b/app/dashboard/role/page.tsx @@ -4,16 +4,17 @@ * sobird at 2023/12/05 15:10:21 created. */ -import React from 'react'; +import { Button } from 'antd'; import { Metadata } from 'next'; import Link from 'next/link'; -import { Button } from 'antd'; -import RoleTable from './table'; -import { RoleModel } from '@/models'; +import React from 'react'; -import RoleForm from './components/role-form'; import { createRoleAction } from '@/actions/role'; import withActionFormModal from '@/components/with-action-form-modal'; +import { RoleModel } from '@/models'; + +import RoleForm from './components/role-form'; +import RoleTable from './table'; export const metadata: Metadata = { title: '角色管理', diff --git a/app/page.tsx b/app/page.tsx index 27d2cb7..f5c4347 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,21 +1,20 @@ import { subject } from '@casl/ability'; -import { getToken } from 'next-auth/jwt'; import { cookies, headers } from 'next/headers'; +import { getToken } from 'next-auth/jwt'; import { getCsrfToken } from 'next-auth/react'; + import { LoginButton, LogoutButton, ProfileButton, RegisterButton, } from '@/components/buttons'; - +import { defineAbilityFor } from '@/lib/ability'; +import { getServerAuthToken } from '@/lib/auth'; import { UserModel, SessionModel, AccountModel, sequelize, } from '@/models'; -import { defineAbilityFor } from '@/lib/ability'; -import { getServerAuthToken } from '@/lib/auth'; - const HomePage: IAppPage<{ id: string }> = async () => { const token = await getServerAuthToken(); console.log('getServerAuthToken', token); diff --git a/models/index.ts b/models/index.ts index b687a30..351a868 100644 --- a/models/index.ts +++ b/models/index.ts @@ -10,17 +10,17 @@ import { sequelize } from '@/lib/sequelize'; -import User from './user'; -import Role from './role'; -import Permission from './permission'; import Account from './account'; -import Session from './session'; -import VerificationToken from './verificationToken'; -import Menu from './menu'; import Group from './group'; +import Menu from './menu'; +import Permission from './permission'; +import Role from './role'; // Associations Model import RolePermission from './role-permission'; +import Session from './session'; +import User from './user'; import UserRole from './user-role'; +import VerificationToken from './verificationToken'; export type { UserAttributes, UserCreationAttributes } from './user'; export type { RoleAttributes, RoleCreationAttributes } from './role'; diff --git a/next.config.js b/next.config.js index 04d1d68..8755a2b 100644 --- a/next.config.js +++ b/next.config.js @@ -1,6 +1,6 @@ /** @type {import('next').NextConfig} */ const nextConfig = { - // output: 'standalone', + output: 'standalone', experimental: { // typedRoutes: true, esmExternals: false, diff --git a/package.json b/package.json index 822e935..9371d44 100644 --- a/package.json +++ b/package.json @@ -46,10 +46,10 @@ "@types/react": "18.2.38", "@types/react-dom": "^18.2.17", "@types/uuid": "^9.0.7", - "eslint-config-sobird": "^0.1.18", + "eslint-config-sobird": "^0.2.14", "raw-loader": "^4.0.2", "sass": "^1.69.5", - "typescript": "^5.3.2", + "typescript": "^5.6.3", "zod-prisma": "^0.5.4" }, "keywords": [ diff --git a/tsconfig.json b/tsconfig.json index 78aea06..08a2bbd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,20 +1,20 @@ { "compilerOptions": { /* Visit https://aka.ms/tsconfig to read more about this file */ - /* Projects */ - "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - /* Language and Environment */ - "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - "lib": ["dom", "dom.iterable", "esnext"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - "jsx": "preserve", /* Specify what JSX code is generated. */ - // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ + "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + "jsx": "preserve", /* Specify what JSX code is generated. */// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ @@ -23,35 +23,27 @@ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ - /* Modules */ - "module": "ESNext", /* Specify what module code is generated. */ - // "rootDir": "./", /* Specify the root folder within your source files. */ - "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + "module": "ESNext", /* Specify what module code is generated. */// "rootDir": "./", /* Specify the root folder within your source files. */ + "moduleResolution": "bundler", /* Specify how TypeScript looks up a file from a given module specifier. */ + "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ "paths": { "@/*": [ "./*" ] - }, /* Specify a set of entries that re-map imports to additional lookup locations. */ - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + }, /* Specify a set of entries that re-map imports to additional lookup locations. */// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ - // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ + "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ - "resolveJsonModule": true, /* Enable importing .json files. */ - // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ + "resolveJsonModule": true, /* Enable importing .json files. */// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ - /* JavaScript Support */ - "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ - /* Emit */ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ // "declarationMap": true, /* Create sourcemaps for d.ts files. */ @@ -61,8 +53,7 @@ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ // "outDir": "./", /* Specify an output folder for all emitted files. */ // "removeComments": true, /* Disable emitting comments. */ - "noEmit": true, /* Disable emitting files from a compilation. */ - // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + "noEmit": true, /* Disable emitting files from a compilation. */// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ @@ -76,19 +67,13 @@ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ - /* Interop Constraints */ - "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - - /* Type Checking */ - "strict": false, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ - "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. *//* Type Checking */ + "strict": false, /* Enable all strict type-checking options. */// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ @@ -105,15 +90,15 @@ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ "plugins": [ { "name": "next" } - ] + ], + "strictNullChecks": true }, "include": [ "app.d.ts", @@ -121,9 +106,13 @@ ".next/types/**/*.ts", "**/*.ts", "**/*.tsx", + ".eslintrc.cjs" ], "exclude": [ - "node_modules" + "node_modules", + "dist" ], - "ts-node": { "esm": true } + "ts-node": { + "esm": true + } }