Skip to content

Commit c7774c9

Browse files
upgrade packages and dependencies
1 parent f88a162 commit c7774c9

20 files changed

+818
-819
lines changed

.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
APP_NAME="Starter Project"
1+
NEXT_PUBLIC_APP_NAME="Starter Project"

.env.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
APP_NAME="Starter Project"
1+
NEXT_PUBLIC_APP_NAME="Starter Project"

.eslintrc

+37-13
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,28 @@
22
"parser": "@typescript-eslint/parser",
33
"extends": [
44
"next",
5-
"plugin:react/recommended",
5+
"next/core-web-vitals",
66
"airbnb",
77
"airbnb-typescript",
8-
"plugin:jsx-a11y/recommended",
98
"plugin:sonarjs/recommended",
10-
"plugin:react-hooks/recommended",
11-
"plugin:prettier/recommended"
9+
"prettier"
1210
],
1311
"plugins": [
1412
"@typescript-eslint",
1513
"jest",
16-
"react"
14+
"simple-import-sort",
15+
"unused-imports"
1716
],
1817
"env": {
19-
"es6": true,
18+
"es2021": true,
2019
"browser": true,
21-
"jest": true
20+
"jest": true,
21+
"node": true
2222
},
2323
"rules": {
2424
"react/require-default-props": "off",
2525
"import/prefer-default-export": "off",
2626
"react/prop-types": "off",
27-
"import/no-cycle": "off",
2827
"no-multi-assign": "off",
2928
"import/imports-first": [
3029
"error",
@@ -48,6 +47,10 @@
4847
]
4948
}
5049
],
50+
// Multiline indentation: https://stackoverflow.com/a/48906878
51+
"indent": ["error", 2],
52+
"react/jsx-indent": ["error", 2],
53+
"react/jsx-indent-props": ["error", 2],
5154
"quotes": [
5255
2,
5356
"single",
@@ -66,16 +69,37 @@
6669
"ForInStatement"
6770
],
6871
"use-isnan": "error",
69-
"@typescript-eslint/no-unused-vars": [
70-
"error",
72+
"@typescript-eslint/no-unused-vars": "off",
73+
"unused-imports/no-unused-imports": "warn",
74+
"unused-imports/no-unused-vars": [
75+
"warn",
7176
{
72-
"args": "after-used",
73-
"ignoreRestSiblings": true,
7477
"vars": "all",
7578
"varsIgnorePattern": "^_",
79+
"args": "after-used",
7680
"argsIgnorePattern": "^_"
7781
}
7882
],
83+
"simple-import-sort/exports": "warn",
84+
"simple-import-sort/imports": [
85+
"warn",
86+
{
87+
"groups": [
88+
["^node:"],
89+
["^react", "^next"],
90+
// Things that start with a letter (or digit or underscore), or `@` followed by a letter.
91+
// & side effect imports
92+
["^@?\\w", "^\\u0000"],
93+
["^.+\\.s?css$"],
94+
// Other imports
95+
["^@/", "^~/"],
96+
// anything not matched in other groups
97+
["^"],
98+
// relative imports - anything that starts with a dot
99+
["^\\."]
100+
]
101+
}
102+
],
79103
"@typescript-eslint/await-thenable": "error",
80104
"@typescript-eslint/no-floating-promises": "error",
81105
"@typescript-eslint/no-misused-new": "error",
@@ -106,7 +130,7 @@
106130
},
107131
"parserOptions": {
108132
// Allows for the parsing of modern ECMAScript features
109-
"ecmaVersion": 2018,
133+
"ecmaVersion": 2021,
110134
// Allows for the use of imports
111135
"sourceType": "module",
112136
// https://blog.geographer.fr/eslint-parser-services, https://www.robertcooper.me/using-eslint-and-prettier-in-a-typescript-project

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ yarn-error.log*
2727

2828
# Environment Variables
2929
.env
30+
.env.local
3031

3132
# Typescript
3233
tsconfig.tsbuildinfo

.lintstagedrc.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
const path = require('path')
2+
3+
// With `next lint`: https://nextjs.org/docs/basic-features/eslint#lint-staged
4+
const buildEslintCommand = (filenames) =>
5+
`yarn lint:fix --file ${filenames.map((f) => path.relative(process.cwd(), f)).join(' --file ')}`
6+
17
module.exports = {
2-
'*.{js,jsx,ts,tsx}': 'npm run format',
8+
'*.{js,jsx,ts,tsx}': [buildEslintCommand],
39
'*.{ts,tsx}': "bash -c 'npm run typecheck'", // running this via bash https://github.com/okonet/lint-staged/issues/825#issuecomment-727185296
410
}

.prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"singleQuote": true,
3+
"jsxSingleQuote": true,
4+
"arrowParens": "always",
35
"noSemi": true,
46
"semi": false,
57
"trailingComma": "all",
8+
"tabWidth": 2,
69
"printWidth": 120
710
}

.swcrc

-10
This file was deleted.

jest.config.js

+27-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
module.exports = {
2-
preset: 'ts-jest/presets/js-with-ts',
3-
setupFiles: ['<rootDir>/jest.setup.ts'],
4-
moduleNameMapper: {
5-
'^@src/(.*)$': '<rootDir>/src/$1',
6-
},
7-
coveragePathIgnorePatterns: ['/node_modules/'],
8-
transform: {
9-
'^.+\\.[tj]sx?$': [
10-
'ts-jest',
11-
{
12-
tsconfig: '<rootDir>/tsconfig.jest.json',
13-
diagnostics: false,
14-
},
15-
],
16-
},
1+
const nextJest = require('next/jest')
2+
3+
const createJestConfig = nextJest({
4+
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
5+
dir: './',
6+
})
7+
8+
// Add any custom config to be passed to Jest
9+
/** @type {import('jest').Config} */
10+
const customJestConfig = {
11+
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
1712
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
13+
14+
// if using TypeScript with a baseUrl set to the root directory then you need the snippet below for alias' to work
15+
moduleDirectories: ['node_modules', '<rootDir>/'],
16+
17+
testEnvironment: 'jest-environment-jsdom',
1818
testMatch: ['**/*.(test|spec).(js|jsx|ts|tsx)'],
19-
testEnvironment: 'jsdom',
19+
coveragePathIgnorePatterns: ['/node_modules/'],
20+
/**
21+
* Absolute imports and module path aliases
22+
*/
23+
moduleNameMapper: {
24+
'^@/(.*)$': '<rootDir>/src/$1',
25+
'^~/(.*)$': '<rootDir>/public/$1',
26+
},
2027
}
28+
29+
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
30+
module.exports = createJestConfig(customJestConfig)

jest.setup.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Loading `.env.test`: https://github.com/vercel/next.js/discussions/16270#discussioncomment-54198
2-
import next from 'next'
1+
import '@testing-library/jest-dom/extend-expect'
32

4-
next({})
3+
// Allow router mocks.
4+
// eslint-disable-next-line no-undef, global-require
5+
jest.mock('next/router', () => require('next-router-mock'))

next.config.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1+
/** @type {import('next').NextConfig} */
12
module.exports = {
23
poweredByHeader: false,
34
generateEtags: false,
4-
/**
5-
* Environment Variables.
6-
*/
7-
publicRuntimeConfig: {
8-
APP_NAME: process.env.APP_NAME,
9-
},
10-
serverRuntimeConfig: {},
5+
reactStrictMode: true,
6+
swcMinify: true,
117
}

package.json

+21-20
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,39 @@
55
"dev": "next",
66
"build": "next build",
77
"start": "next start",
8+
"export": "yarn-or-npm build && next export",
9+
"lint": "next lint",
10+
"lint:fix": "next lint --fix",
811
"test:coverage": "yarn-or-npm test --coverage",
912
"test:debug": "yarn-or-npm test --debug --detectOpenHandles",
1013
"test:ci": "yarn-or-npm test --runInBand --no-cache --ci",
1114
"test": "NODE_ENV=test jest",
12-
"lint": "eslint './{src,pages}/**/*' --ext .js,.jsx,.tsx,.ts",
13-
"format": "eslint './{src,pages}/**/*' --ext .js,.jsx,.tsx,.ts --fix",
1415
"typecheck": "tsc --noEmit",
1516
"clean": "rimraf out/",
1617
"prepare": "husky install"
1718
},
1819
"dependencies": {
19-
"@chakra-ui/react": "^2.4.1",
20+
"@chakra-ui/react": "^2.4.3",
2021
"@emotion/react": "^11.10.5",
2122
"@emotion/styled": "^11.10.5",
22-
"framer-motion": "^7.6.12",
23-
"next": "^13.0.5",
23+
"framer-motion": "^7.6.19",
24+
"next": "^13.0.6",
2425
"react": "^18.2.0",
2526
"react-dom": "^18.2.0"
2627
},
2728
"devDependencies": {
29+
"@testing-library/jest-dom": "^5.16.5",
2830
"@testing-library/react": "^13.4.0",
29-
"@types/jest": "^29.2.3",
30-
"@types/node": "^18.11.9",
31-
"@types/react": "^18.0.25",
32-
"@types/react-addons-test-utils": "^15.6.0",
31+
"@types/jest": "^29.2.4",
32+
"@types/node": "^18.11.12",
33+
"@types/react": "^18.0.26",
3334
"@types/react-dom": "^18.0.9",
34-
"@types/react-test-renderer": "^18.0.0",
35-
"@typescript-eslint/eslint-plugin": "^5.44.0",
36-
"@typescript-eslint/parser": "^5.44.0",
37-
"cross-env": "^7.0.3",
38-
"eslint": "^8.28.0",
35+
"@typescript-eslint/eslint-plugin": "^5.46.0",
36+
"@typescript-eslint/parser": "^5.46.0",
37+
"eslint": "^8.29.0",
3938
"eslint-config-airbnb": "19.0.4",
4039
"eslint-config-airbnb-typescript": "^17.0.0",
41-
"eslint-config-next": "^13.0.5",
40+
"eslint-config-next": "^13.0.6",
4241
"eslint-config-prettier": "^8.5.0",
4342
"eslint-config-react-app": "^7.0.1",
4443
"eslint-import-resolver-typescript": "^3.5.2",
@@ -48,16 +47,18 @@
4847
"eslint-plugin-prettier": "^4.2.1",
4948
"eslint-plugin-react": "^7.31.11",
5049
"eslint-plugin-react-hooks": "^4.6.0",
51-
"eslint-plugin-sonarjs": "^0.16.0",
50+
"eslint-plugin-simple-import-sort": "^8.0.0",
51+
"eslint-plugin-sonarjs": "^0.17.0",
52+
"eslint-plugin-unused-imports": "^2.0.0",
5253
"husky": "^8.0.2",
5354
"jest": "^29.3.1",
5455
"jest-environment-jsdom": "^29.3.1",
55-
"lint-staged": "^13.0.3",
56+
"lint-staged": "^13.1.0",
57+
"next-router-mock": "^0.8.0",
5658
"npm-run-all": "^4.1.5",
57-
"prettier": "^2.8.0",
59+
"prettier": "^2.8.1",
5860
"rimraf": "^3.0.2",
59-
"ts-jest": "^29.0.3",
60-
"typescript": "^4.9.3",
61+
"typescript": "^4.9.4",
6162
"yarn-or-npm": "^3.0.1"
6263
}
6364
}

readme.md

+2-52
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Starter template for building a project using React, Typescript, Next.js, Jest,
1616
- `yarn test`: To run the entire unit test suite using `jest`.
1717
- `yarn test:ci`: To run tests on CI.
1818
- `yarn lint`: To run the ESLint based linter to find out the issues in the project.
19-
- `yarn format`: To autoformat all the issues.
19+
- `yarn lint:fix`: To autoformat all the issues.
2020
- `yarn export`: Run this after running `yarn analyze` to export a build copy.
2121
- `yarn production`: To export a production build. Use `yarn start` to serve that.
2222

@@ -47,56 +47,6 @@ All source code is located in the `src/` directory:
4747

4848
If you feel like changing the directory structure, please change the appropriate settings in the following files:
4949

50-
- `.swcrc`
5150
- `jest.config.js`
5251
- `tsconfig.json`
53-
- The `lint` and the `format` scripts in `package.json`
54-
55-
## Note
56-
57-
1. This project removes the `x-powered-by` response header via `next.config.js` by marking the `poweredByHeader` property as `false`.
58-
59-
2. If you wish to use Babel instead of SWC (introduced with the Next.js v12 upgrade), please remove the `.swcrc` file and add a `.babelrc` file at the root with the following:
60-
61-
```
62-
{
63-
"presets": [
64-
"next/babel"
65-
],
66-
"plugins": [
67-
[
68-
"module-resolver",
69-
{
70-
"root": [
71-
"./"
72-
],
73-
"alias": {
74-
"@src": "./src"
75-
},
76-
"extensions": [
77-
".js",
78-
".jsx",
79-
".ts",
80-
".tsx"
81-
]
82-
}
83-
]
84-
]
85-
}
86-
```
87-
88-
Then, open `./jest.config.js` and find the `globals` config. Add `babelConfig` to it, like so:
89-
90-
```
91-
{
92-
globals: {
93-
'ts-jest': {
94-
tsconfig: '<rootDir>/tsconfig.jest.json',
95-
babelConfig: true,
96-
diagnostics: false,
97-
},
98-
},
99-
}
100-
```
101-
102-
Also, run `yarn add -D @babel/core babel-plugin-module-resolver eslint-import-resolver-babel-module` to install Babel's dependencies.
52+
- The `lint` and the `lint:fix` scripts in `package.json`
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Index Page renders correctly 1`] = `
4-
<DocumentFragment>
4+
<div>
55
<h1
66
class="chakra-heading css-0"
7-
data-testid="main-heading"
87
/>
9-
</DocumentFragment>
8+
</div>
109
`;

0 commit comments

Comments
 (0)