Skip to content

Commit

Permalink
[migrate] upgrade to Next.js 15, ESLint 9 & other latest Upstream pac…
Browse files Browse the repository at this point in the history
…kages
  • Loading branch information
TechQuery committed Oct 26, 2024
1 parent eaddf79 commit 30990a6
Show file tree
Hide file tree
Showing 14 changed files with 2,573 additions and 2,206 deletions.
10 changes: 0 additions & 10 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
## Technology stack

- Language: [TypeScript v5][2] + [MDX v3][10]
- Component engine: [Next.js v14][3]
- Component engine: [Next.js v15][3]
- Component suite: [Bootstrap v5][4]
- PWA framework: [Workbox v6][5]
- State management: [MobX v6][11]
Expand Down
1 change: 0 additions & 1 deletion components/BlockEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ const Tools = {
};

export default function Editor(props: Omit<EditorProps, 'tools'>) {
// @ts-ignore
return <Core tools={Tools} {...props} />;
}
2 changes: 1 addition & 1 deletion components/Git/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const GitCard: FC<GitCardProps> = observer(
</nav>
<Row as="ul" className="list-unstyled g-4" xs={4}>
{languages.map(language => (
<Col as="li" key={language}>
<Col key={language} as="li">
<GitLogo name={language} />
</Col>
))}
Expand Down
2 changes: 1 addition & 1 deletion components/NotFoundCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const NotFoundCard: FC<ErrorProps> = ({ title }) =>
i18n.currentLanguage.startsWith('zh') ? (
<script
src="//cdn.dnpw.org/404/v1.min.js"
// @ts-ignore
// @ts-expect-error https://www.dnpw.org/cn/pa-notfound.html
jumptarget="/"
jumptime="-1"
error={title}
Expand Down
77 changes: 77 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// @ts-check
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc';
import eslint from '@eslint/js';
import eslintConfigPrettier from 'eslint-config-prettier';
import reactPlugin from 'eslint-plugin-react';
import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort';
import globals from 'globals';
import tsEslint from 'typescript-eslint';
import { fileURLToPath } from 'url';

const tsconfigRootDir = fileURLToPath(new URL('.', import.meta.url)),
flatCompat = new FlatCompat();

export default tsEslint.config(
// register all of the plugins up-front
{
plugins: {
'@typescript-eslint': tsEslint.plugin,
// @ts-expect-error https://github.com/jsx-eslint/eslint-plugin-react/issues/3699
react: fixupPluginRules(reactPlugin),
'simple-import-sort': simpleImportSortPlugin,
},
},
{
// config with just ignores is the replacement for `.eslintignore`
ignores: ['**/node_modules/**', '**/public/**', '**/.next/**'],
},

// extends ...
eslint.configs.recommended,
...tsEslint.configs.recommended,
...fixupConfigRules(flatCompat.extends('plugin:@next/next/core-web-vitals')),

// base config
{
languageOptions: {
globals: { ...globals.es2020, ...globals.browser, ...globals.node },
parserOptions: {
projectService: true,
tsconfigRootDir,
warnOnUnsupportedTypeScriptVersion: false,
},
},
rules: {
'no-empty-pattern': 'warn',
'simple-import-sort/exports': 'error',
'simple-import-sort/imports': 'error',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'warn',
'react/jsx-no-target-blank': 'warn',
'react/jsx-sort-props': [
'error',
{
reservedFirst: true,
callbacksLast: true,
noSortAlphabetically: true,
},
],
'@next/next/no-sync-scripts': 'warn',
},
},
{
files: ['**/*.js'],
extends: [tsEslint.configs.disableTypeChecked],
rules: {
// turn off other type-aware rules
'@typescript-eslint/internal/no-poorly-typed-ts-props': 'off',

// turn off rules that don't apply to JS code
'@typescript-eslint/explicit-function-return-type': 'off',
},
},
eslintConfigPrettier,
);
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
2 changes: 1 addition & 1 deletion next.config.mjs → next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { withSentryConfig } from '@sentry/nextjs';
import CopyPlugin from 'copy-webpack-plugin';
import { readdirSync, statSync } from 'fs';
import setPWA from 'next-pwa';
// @ts-ignore
// @ts-expect-error no official types
import withLess from 'next-with-less';
import RemarkFrontMatter from 'remark-frontmatter';
import RemarkGfm from 'remark-gfm';
Expand Down
73 changes: 44 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,75 @@
"node": ">=20"
},
"dependencies": {
"@editorjs/code": "^2.9.0",
"@editorjs/editorjs": "^2.30.5",
"@editorjs/header": "^2.8.7",
"@editorjs/code": "^2.9.2",
"@editorjs/editorjs": "^2.30.6",
"@editorjs/header": "^2.8.8",
"@editorjs/image": "^2.9.3",
"@editorjs/link": "^2.6.2",
"@editorjs/list": "^1.10.0",
"@editorjs/paragraph": "^2.11.6",
"@editorjs/quote": "~2.7.2",
"@mdx-js/loader": "^3.0.1",
"@mdx-js/react": "^3.0.1",
"@next/mdx": "^14.2.7",
"@sentry/nextjs": "^8.28.0",
"@mdx-js/loader": "^3.1.0",
"@mdx-js/react": "^3.1.0",
"@next/mdx": "^15.0.1",
"@sentry/nextjs": "^8.35.0",
"copy-webpack-plugin": "^12.0.2",
"editorjs-html": "^3.4.3",
"idea-react": "^2.0.0-rc.2",
"koajax": "^3.0.0",
"idea-react": "^2.0.0-rc.8",
"koajax": "^3.0.2",
"less": "^4.2.0",
"less-loader": "^12.2.0",
"lodash": "^4.17.21",
"mobx": "^6.13.1",
"mobx-github": "^0.3.3",
"mobx-i18n": "^0.5.0",
"mobx": "^6.13.5",
"mobx-github": "^0.3.4",
"mobx-i18n": "^0.6.0",
"mobx-react": "^9.1.1",
"mobx-restful": "^1.0.1",
"mobx-restful-table": "^2.0.0",
"next": "^14.2.7",
"next": "^15.0.1",
"next-pwa": "~5.6.0",
"next-ssr-middleware": "^0.8.7",
"next-ssr-middleware": "^0.8.8",
"next-with-less": "^3.0.1",
"prismjs": "^1.29.0",
"react": "^18.3.1",
"react-bootstrap": "^2.10.4",
"react-bootstrap": "^2.10.5",
"react-bootstrap-editor": "^2.0.4",
"react-dom": "^18.3.1",
"react-editor-js": "^2.1.0",
"remark-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.0",
"remark-mdx-frontmatter": "^5.0.0",
"undici": "^6.19.8",
"web-utility": "^4.4.0",
"webpack": "^5.94.0"
"undici": "^6.20.1",
"web-utility": "^4.4.1",
"webpack": "^5.95.0"
},
"devDependencies": {
"@babel/plugin-proposal-decorators": "^7.24.7",
"@babel/plugin-transform-typescript": "^7.25.2",
"@babel/preset-react": "^7.24.7",
"@types/lodash": "^4.17.7",
"@babel/plugin-proposal-decorators": "^7.25.9",
"@babel/plugin-transform-typescript": "^7.25.9",
"@babel/preset-react": "^7.25.9",
"@eslint/compat": "^1.2.1",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.13.0",
"@softonus/prettier-plugin-duplicate-remover": "^1.0.1",
"@types/eslint-config-prettier": "^6.11.3",
"@types/eslint__eslintrc": "^2.1.2",
"@types/eslint__js": "^8.42.3",
"@types/lodash": "^4.17.12",
"@types/next-pwa": "^5.6.9",
"@types/node": "^20.16.3",
"@types/react": "^18.3.5",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.7",
"@types/node": "^20.17.1",
"@types/react": "^18.3.12",
"eslint": "^9.13.0",
"eslint-config-next": "^15.0.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-simple-import-sort": "^12.1.1",
"husky": "^9.1.5",
"globals": "^15.11.0",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"typescript": "~5.5.4"
"prettier-plugin-css-order": "^2.1.2",
"typescript": "~5.6.3",
"typescript-eslint": "^8.11.0"
},
"resolutions": {
"native-file-system-adapter": "npm:@tech_query/native-file-system-adapter@^3.0.1",
Expand All @@ -73,7 +84,11 @@
"prettier": {
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "avoid"
"arrowParens": "avoid",
"plugins": [
"prettier-plugin-css-order",
"@softonus/prettier-plugin-duplicate-remover"
]
},
"lint-staged": {
"*.{html,md,less,json,yml,js,mjs,ts,tsx}": "prettier --write",
Expand Down
4 changes: 2 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ enableStaticRendering(isServer());
const { t } = i18n;

globalThis.addEventListener?.('unhandledrejection', ({ reason }) => {
var { message, response } = reason as HTTPError;
const { statusText, body } = response || {};
let { message } = reason as HTTPError;
const { statusText, body } = reason.response || {};

message = body?.message || statusText || message;

Expand Down
9 changes: 5 additions & 4 deletions pages/api/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export function safeAPI(handler: NextAPI): NextAPI {
return res.send({ message: (error as Error).message });
}
const { message, response } = error;
let { status, body } = response;
let { body } = response;

res.status(status);
res.status(response.status);
res.statusMessage = message;

if (body instanceof ArrayBuffer)
Expand All @@ -35,8 +35,9 @@ export function safeAPI(handler: NextAPI): NextAPI {

body = JSON.parse(body);
console.error(body);
} catch {}

} catch {
//
}
res.send(body);
}
};
Expand Down
2 changes: 1 addition & 1 deletion pages/article/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const getStaticProps: GetStaticProps<{
const pageListOf = (path: string, prefix = 'pages'): ArticleMeta[] =>
readdirSync(prefix + path, { withFileTypes: true })
.map(node => {
var { name, path } = node;
let { name, path } = node;

if (name.startsWith('.')) return;

Expand Down
2 changes: 1 addition & 1 deletion pages/scroll-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ScrollListPage: FC<{ list: GitRepository[] }> = observer(({ list }) => (
renderList={allItems => (
<Row as="ul" className="list-unstyled g-4" xs={1} sm={2}>
{allItems.map(item => (
<Col as="li" key={item.id}>
<Col key={item.id} as="li">
<GitCard className="h-100 shadow-sm" {...item} />
</Col>
))}
Expand Down
Loading

1 comment on commit 30990a6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for next-bootstrap-ts ready!

✅ Preview
https://next-bootstrap-9vztk2i6t-stevending1sts-projects.vercel.app

Built with commit 30990a6.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.