[FIX] Out of memory while running app localy (#11341)
# Introduction
Lately encountering a lot of out of memory error when running
twenty-front in watch mode with both TypeScript and lint checkers
```ts
Error: Worker terminated due to reaching memory limit: JS heap out of memory
at new NodeError (node:internal/errors:405:5)
at [kOnExit] (node:internal/worker:287:26)
at Worker.<computed>.onexit (node:internal/worker:209:20)
```
The existing configuration looks like this:
```ts
// packages/twenty-front/vite.config.ts
'cd ../.. && eslint packages/twenty-front --report-unused-disable-directives --max-warnings 0 --config .eslintrc.cjs',
```
This is wrong as computing the root eslintrc completely omitting
twenty-front's one ***and its ignorePattern*** so will be checking in
`node_modules` etc checking for project-structure :).
For example this a
[snippet](https://gist.github.com/prastoin/d7f8ad4ef5eb2f7732209b756a38094c)
of the above commands errors. We can see rule that should be disabled by
`eslintrc.react.cjs` extension made from twenty-front `eslintrc` :
```ts
/Users/paulrastoin/ws/twenty-two/packages/twenty-front/src/modules/settings/data-model/fields/forms/components/__stories__/SettingsDataModelFieldSettingsFormCard.stories.tsx
23:27 warning Forbidden non-null assertion @typescript-eslint/no-non-null-assertion
```
## Fixes
- consume the `twenty-front` package eslint configuration within the
vite lint checker
- eslint overrides extends are getting merged based on glob inclusion of
their files declarations
- any linted files should be included in one of our `tsconfig`
- removed redundant and counter-productive negative `ignorePatterns`, as
eslint will naturally only lint files within configuration file
directory by default which will result making it go through local
`node_modules` project structure
## Now
Less cpu usage <3.5 gb and faster
```ts
// from packages/twenty-front
TIMING=1 npx eslint . --report-unused-disable-directives --max-warnings 0 --config .eslintrc.cjs --debug
#...
Rule | Time (ms) | Relative
:-----------------------------------------------|----------:|--------:
project-structure/folder-structure | 19578.927 | 20.2%
prettier/prettier | 13746.156 | 14.2%
no-redeclare | 9546.570 | 9.9%
@nx/workspace-explicit-boolean-predicates-in-if | 8167.805 | 8.4%
@typescript-eslint/no-unused-vars | 6872.803 | 7.1%
import/no-relative-packages | 6577.273 | 6.8%
@nx/enforce-module-boundaries | 6520.945 | 6.7%
import/no-duplicates | 4987.476 | 5.2%
react/no-direct-mutation-state | 2323.082 | 2.4%
react/require-render-return | 1155.261 | 1.2%
```
## Conclusion
Please note that `nx linter` might not be as strict as vite config
eslint runner
---------
Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: ['plugin:prettier/recommended', 'plugin:lingui/recommended'],
|
||||
ignorePatterns: ['node_modules'],
|
||||
plugins: [
|
||||
'@nx',
|
||||
'prefer-arrow',
|
||||
@ -10,10 +10,7 @@ module.exports = {
|
||||
plugins: ['react-hooks', 'react-refresh'],
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.base.{json,*.json}'],
|
||||
},
|
||||
files: ['**/*.ts', '**/*.tsx'],
|
||||
rules: {
|
||||
'no-restricted-imports': [
|
||||
'error',
|
||||
|
||||
@ -1,11 +1,16 @@
|
||||
module.exports = {
|
||||
extends: ['../../.eslintrc.cjs', '../../.eslintrc.react.cjs'],
|
||||
ignorePatterns: ['!**/*', 'node_modules', 'dist', '**/generated/*'],
|
||||
root: true,
|
||||
extends: ['../../.eslintrc.global.cjs', '../../.eslintrc.react.cjs'],
|
||||
ignorePatterns: [
|
||||
'node_modules',
|
||||
'dist',
|
||||
'**/generated/*',
|
||||
],
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
files: ['**/*.ts', '**/*.tsx'],
|
||||
parserOptions: {
|
||||
project: ['packages/twenty-chrome-extension/tsconfig.{json,*.json}'],
|
||||
project: ['packages/twenty-chrome-extension/tsconfig.*.json'],
|
||||
},
|
||||
rules: {
|
||||
'@nx/workspace-explicit-boolean-predicates-in-if': 'warn',
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
module.exports = {
|
||||
extends: ['../../.eslintrc.cjs', '../../.eslintrc.react.cjs'],
|
||||
ignorePatterns: ['!**/*'],
|
||||
extends: ['../../.eslintrc.global.cjs', '../../.eslintrc.react.cjs'],
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
files: ['**/*.ts', '**/*.tsx'],
|
||||
parserOptions: {
|
||||
project: ['packages/twenty-emails/tsconfig.{json,*.json}'],
|
||||
project: ['packages/twenty-emails/tsconfig.*.json'],
|
||||
},
|
||||
rules: {
|
||||
'@nx/dependency-checks': 'error',
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
extends: ['../../.eslintrc.cjs', '../../.eslintrc.react.cjs'],
|
||||
extends: ['../../.eslintrc.global.cjs', '../../.eslintrc.react.cjs'],
|
||||
ignorePatterns: [
|
||||
'!**/*',
|
||||
'node_modules',
|
||||
'mockServiceWorker.js',
|
||||
'**/generated*/*',
|
||||
@ -19,9 +18,9 @@ module.exports = {
|
||||
],
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
files: ['**/*.ts', '**/*.tsx'],
|
||||
parserOptions: {
|
||||
project: ['packages/twenty-front/tsconfig.{json,*.json}'],
|
||||
project: ['packages/twenty-front/tsconfig.*.json'],
|
||||
},
|
||||
plugins: ['project-structure'],
|
||||
settings: {
|
||||
|
||||
@ -62,6 +62,27 @@
|
||||
"@lingui/cli": "^5.1.2",
|
||||
"@lingui/swc-plugin": "^5.1.0",
|
||||
"@lingui/vite-plugin": "^5.1.2",
|
||||
"@types/file-saver": "^2"
|
||||
"@types/file-saver": "^2",
|
||||
"@typescript-eslint/eslint-plugin": "6.21.0",
|
||||
"@typescript-eslint/experimental-utils": "^5.62.0",
|
||||
"@typescript-eslint/parser": "6.21.0",
|
||||
"@typescript-eslint/utils": "6.21.0",
|
||||
"eslint": "^8.53.0",
|
||||
"eslint-config-next": "14.0.4",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-import": "2.29.1",
|
||||
"eslint-plugin-jsx-a11y": "^6.8.0",
|
||||
"eslint-plugin-lingui": "^0.9.0",
|
||||
"eslint-plugin-prefer-arrow": "^1.2.3",
|
||||
"eslint-plugin-prettier": "^5.1.2",
|
||||
"eslint-plugin-project-structure": "^3.9.1",
|
||||
"eslint-plugin-react": "^7.33.2",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.4",
|
||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||
"eslint-plugin-storybook": "^0.6.15",
|
||||
"eslint-plugin-unicorn": "^51.0.1",
|
||||
"eslint-plugin-unused-imports": "^3.0.0",
|
||||
"optionator": "^0.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,10 +52,6 @@
|
||||
"typecheck": {},
|
||||
"lint": {
|
||||
"options": {
|
||||
"lintFilePatterns": [
|
||||
"{projectRoot}/src/**/*.{ts,tsx,json}",
|
||||
"{projectRoot}/package.json"
|
||||
],
|
||||
"maxWarnings": 0,
|
||||
"reportUnusedDisableDirectives": "error"
|
||||
},
|
||||
|
||||
@ -63,7 +63,8 @@ export default defineConfig(({ command, mode }) => {
|
||||
if (VITE_DISABLE_ESLINT_CHECKER !== 'true') {
|
||||
checkers['eslint'] = {
|
||||
lintCommand:
|
||||
'cd ../.. && eslint packages/twenty-front --report-unused-disable-directives --max-warnings 0 --config .eslintrc.cjs',
|
||||
// Appended to packages/twenty-front/.eslintrc.cjs
|
||||
'eslint ../../packages/twenty-front --report-unused-disable-directives --max-warnings 0 --config .eslintrc.cjs',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['@stylistic'],
|
||||
extends: ['../../.eslintrc.cjs'],
|
||||
extends: ['../../.eslintrc.global.cjs'],
|
||||
ignorePatterns: [
|
||||
'src/engine/workspace-manager/demo-objects-prefill-data/**',
|
||||
'src/engine/seeder/data-seeds/**',
|
||||
@ -9,7 +9,7 @@ module.exports = {
|
||||
],
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts'],
|
||||
files: ['**/*.ts'],
|
||||
parserOptions: {
|
||||
project: ['packages/twenty-server/tsconfig.json'],
|
||||
},
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
module.exports = {
|
||||
extends: ['../../.eslintrc.cjs'],
|
||||
ignorePatterns: ['!**/*'],
|
||||
extends: ['../../.eslintrc.global.cjs'],
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
files: ['**/*.ts'],
|
||||
parserOptions: {
|
||||
project: ['packages/twenty-shared/tsconfig.{json,*.json}'],
|
||||
project: ['packages/twenty-shared/tsconfig.*.json'],
|
||||
},
|
||||
rules: {
|
||||
'@nx/dependency-checks': 'error',
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
module.exports = {
|
||||
extends: ['../../.eslintrc.cjs', '../../.eslintrc.react.cjs'],
|
||||
ignorePatterns: ['!**/*'],
|
||||
extends: ['../../.eslintrc.global.cjs', '../../.eslintrc.react.cjs'],
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
files: ['**/*.ts', '**/*.tsx'],
|
||||
parserOptions: {
|
||||
project: ['packages/twenty-ui/tsconfig.{json,*.json}'],
|
||||
project: ['packages/twenty-ui/tsconfig.*.json'],
|
||||
},
|
||||
rules: {
|
||||
'no-restricted-imports': [
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
extends: ['../../.eslintrc.cjs', 'plugin:@next/next/recommended'],
|
||||
extends: ['../../.eslintrc.global.cjs', 'plugin:@next/next/recommended'],
|
||||
rules: {
|
||||
'no-console': 'off',
|
||||
'prefer-arrow/prefer-arrow-functions': 'off',
|
||||
|
||||
23
yarn.lock
23
yarn.lock
@ -44955,7 +44955,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"optionator@npm:^0.9.3":
|
||||
"optionator@npm:^0.9.1, optionator@npm:^0.9.3":
|
||||
version: 0.9.4
|
||||
resolution: "optionator@npm:0.9.4"
|
||||
dependencies:
|
||||
@ -53144,10 +53144,31 @@ __metadata:
|
||||
"@tiptap/extension-text-style": "npm:^2.10.4"
|
||||
"@tiptap/react": "npm:^2.10.4"
|
||||
"@types/file-saver": "npm:^2"
|
||||
"@typescript-eslint/eslint-plugin": "npm:6.21.0"
|
||||
"@typescript-eslint/experimental-utils": "npm:^5.62.0"
|
||||
"@typescript-eslint/parser": "npm:6.21.0"
|
||||
"@typescript-eslint/utils": "npm:6.21.0"
|
||||
"@xyflow/react": "npm:^12.4.2"
|
||||
buffer: "npm:^6.0.3"
|
||||
docx: "npm:^9.1.0"
|
||||
eslint: "npm:^8.53.0"
|
||||
eslint-config-next: "npm:14.0.4"
|
||||
eslint-config-prettier: "npm:^9.1.0"
|
||||
eslint-plugin-import: "npm:2.29.1"
|
||||
eslint-plugin-jsx-a11y: "npm:^6.8.0"
|
||||
eslint-plugin-lingui: "npm:^0.9.0"
|
||||
eslint-plugin-prefer-arrow: "npm:^1.2.3"
|
||||
eslint-plugin-prettier: "npm:^5.1.2"
|
||||
eslint-plugin-project-structure: "npm:^3.9.1"
|
||||
eslint-plugin-react: "npm:^7.33.2"
|
||||
eslint-plugin-react-hooks: "npm:^4.6.0"
|
||||
eslint-plugin-react-refresh: "npm:^0.4.4"
|
||||
eslint-plugin-simple-import-sort: "npm:^10.0.0"
|
||||
eslint-plugin-storybook: "npm:^0.6.15"
|
||||
eslint-plugin-unicorn: "npm:^51.0.1"
|
||||
eslint-plugin-unused-imports: "npm:^3.0.0"
|
||||
file-saver: "npm:^2.0.5"
|
||||
optionator: "npm:^0.9.1"
|
||||
recoil-sync: "npm:^0.2.0"
|
||||
transliteration: "npm:^2.3.5"
|
||||
twenty-shared: "workspace:*"
|
||||
|
||||
Reference in New Issue
Block a user