Skip to content

Commit 346cfba

Browse files
committed
Node version 22
- Packages frontend, backend, and interface - jest working in backend! - simplify eslint to use projectService always - Make multi-root better
1 parent d362d01 commit 346cfba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2545
-273
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22.9.0

.vscode/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"simonsiefke.svg-preview",
1111
"yoavbls.pretty-ts-errors",
1212
"csstools.postcss",
13+
"antfu.vite",
1314
],
1415
}

.vscode/settings.json

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
"editor.formatOnSave": true,
44
"editor.defaultFormatter": "esbenp.prettier-vscode",
55
"editor.codeActionsOnSave": {
6-
"source.organizeImports": "never",
6+
"source.fixAll": "always",
7+
"source.fixAll.eslint": "always",
8+
"source.sortImports": "always",
9+
"source.addMissingImports.ts": "never",
10+
"source.fixAll.ts": "always",
11+
"source.organizeImports": "always",
12+
"source.removeUnused.ts": "never",
13+
"source.removeUnusedImports": "never",
714
},
815
"editor.formatOnSaveMode": "modificationsIfAvailable",
916
"[javascript,typescript,jsonc,json]": {
@@ -12,9 +19,11 @@
1219
"editor.defaultFormatter": "esbenp.prettier-vscode",
1320
"editor.formatOnSaveMode": "modificationsIfAvailable",
1421
},
15-
"eslint.useFlatConfig": true,
16-
"jest.jestCommandLine": "npm test -- ",
17-
"jest.runMode": {
18-
"type": "on-demand",
22+
"[json]": {
23+
"editor.tabSize": 4,
1924
},
25+
"eslint.useFlatConfig": true,
26+
"jest.enable": true,
27+
"jest.rootPath": "packages/",
28+
"vite.autoStart": false,
2029
}

.vscode/tasks.json

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,56 @@
44
"version": "2.0.0",
55
"tasks": [
66
{
7-
"type": "npm",
8-
"script": "build",
9-
"group": "build",
10-
"problemMatcher": [],
7+
"label": "dev",
8+
"isBackground": true,
9+
"dependsOn": [
10+
"npm: dev - packages/frontend",
11+
"npm: dev - packages/backend",
12+
],
1113
},
1214
{
1315
"type": "npm",
14-
"script": "lint",
15-
"problemMatcher": [],
16+
"script": "dev",
17+
"isBackground": true,
18+
"path": "packages/frontend",
19+
// See here https://stackoverflow.com/a/72655542/7346915
20+
"problemMatcher": [
21+
{
22+
"owner": "typescript",
23+
"source": "Typescript",
24+
"fileLocation": "absolute",
25+
"applyTo": "allDocuments",
26+
"background": {
27+
"activeOnStart": true,
28+
// "beginsPattern": "sd",
29+
// "endsPattern": " > "
30+
},
31+
"pattern": [
32+
{
33+
"regexp": "(ERROR|WARNING)\\(TypeScript\\) (.*)",
34+
"severity": 1,
35+
"message": 2,
36+
},
37+
{
38+
"regexp": "^ FILE (.*):(\\d*):(\\d*)$",
39+
"file": 1,
40+
"line": 2,
41+
"column": 3,
42+
},
43+
],
44+
},
45+
],
46+
"label": "npm: dev - packages/frontend",
47+
"detail": "vite",
1648
},
1749
{
1850
"type": "npm",
19-
"script": "start",
20-
"problemMatcher": [],
21-
},
22-
{
23-
"type": "typescript",
24-
"tsconfig": "tsconfig.json",
25-
"problemMatcher": ["$tsc"],
26-
"group": "build",
27-
},
28-
{
29-
"label": "tsc: watch",
30-
"type": "typescript",
31-
"tsconfig": "tsconfig.json",
32-
"option": "watch",
51+
"script": "dev",
52+
"isBackground": true,
53+
"path": "packages/backend",
3354
"problemMatcher": ["$tsc-watch"],
34-
"group": "build",
55+
"label": "npm: dev - packages/backend",
56+
"detail": "tsc-watch --onSuccess 'node .'",
3557
},
3658
],
3759
}

README.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
# Example
22

3-
Example of typescript, eslint, and jest with property based testing.
3+
## Using workspaces
44

5-
Possibly, you might want to delete the `.pre-commit-config.yaml` file if you are
6-
not using python anywhere.
7-
8-
This is only tested with certain versions of node and npm, it might work with
9-
others, disable the `engine-strict=true` in the `.npmrc` file at your
10-
discretion.
11-
12-
## Check upgrades
5+
Most commands can be launched for each workspace by using `--workspaces|-ws`
136

147
```bash
15-
npx npm-check -u
8+
npm i -ws
9+
npm install --workspaces
1610
```

eslint.config.mjs

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
import js from '@eslint/js';
2-
import tseslint from 'typescript-eslint';
32
import eslintConfigPrettier from 'eslint-config-prettier';
3+
import tseslint from 'typescript-eslint';
44
// When it works again do `npm install --save-dev eslint-plugin-import`
55
// import imprt from 'eslint-plugin-import';
66
// https://github.com/eslint/eslint/issues/18087
77
// https://github.com/import-js/eslint-plugin-import/pull/2829
8-
import globals from 'globals';
98
import jest from 'eslint-plugin-jest';
9+
import reactHooks from 'eslint-plugin-react-hooks';
10+
import reactRefresh from 'eslint-plugin-react-refresh';
11+
import { readFileSync } from 'fs';
12+
import { globSync } from 'glob';
13+
import globals from 'globals';
14+
import { join } from 'path';
15+
// still experimental -->> import { globSync } from 'fs';
16+
// sitll experimental -->> import packageJSON from './package.json' with { type: 'json' };
17+
18+
const packageJSON = JSON.parse(readFileSync('./package.json'));
19+
const packageFolders = globSync(packageJSON.workspaces);
20+
const multiRootConfigFileGlobs = [
21+
'.*.js',
22+
'.*.mjs',
23+
'.*.cjs',
24+
'*.config.mjs',
25+
'*.config.cjs',
26+
'*.config.js',
27+
'*.config.ts',
28+
];
29+
30+
const configFiles = ['.', ...packageFolders].flatMap((p) =>
31+
multiRootConfigFileGlobs.flatMap((c) => join(p, c)),
32+
);
1033

1134
const off = 'off';
1235
const warn = 'warn';
@@ -35,27 +58,22 @@ const any_rules = (level) => {
3558
export default [
3659
{
3760
ignores: [
38-
'lib/',
39-
'build/',
40-
'build-*/',
41-
'dist/',
61+
'**/lib/',
62+
'**/build/',
63+
'**/build-*/',
64+
'**/dist/',
4265
'.vscode/',
43-
'node_modules/',
44-
'coverage/',
45-
'report/',
66+
'**/node_modules/',
67+
'**/mocks',
68+
'**/coverage/',
69+
'**/report/',
70+
'**/__snapshots__',
4671
'!*.js',
4772
'!*.mjs',
4873
'!*.cjs',
4974
'!*.ts',
5075
'!.vscode/*.json',
51-
'package-lock.json',
52-
'**/node_modules',
53-
'**/dist',
54-
'**/build',
55-
'**/__snapshots__',
56-
'**/mocks',
57-
'**/coverage',
58-
'**/report',
76+
'**/package-lock.json',
5977
],
6078
},
6179
js.configs.recommended,
@@ -67,14 +85,9 @@ export default [
6785
globals: globals.node,
6886
parser: tseslint.parser,
6987
parserOptions: {
70-
ecmaVersion: 2022,
7188
sourceType: 'module',
7289
tsconfigRootDir: import.meta.dirname,
73-
project: [
74-
'./tsconfig.eslint.json',
75-
'./tsconfig.json',
76-
'./tsconfig.node.json',
77-
],
90+
projectService: true,
7891
},
7992
},
8093
},
@@ -133,15 +146,7 @@ export default [
133146
},
134147
{
135148
name: 'linting for configuration files',
136-
files: [
137-
'.*.js',
138-
'.*.mjs',
139-
'.*.cjs',
140-
'*.config.mjs',
141-
'*.config.cjs',
142-
'*.config.js',
143-
'*.config.ts',
144-
],
149+
files: configFiles,
145150
rules: {
146151
'no-restricted-imports': off,
147152
// Consider if this is too leanient for tests
@@ -166,9 +171,6 @@ export default [
166171
// https://eslint.org/docs/user-guide/configuring#specifying-environments
167172
languageOptions: {
168173
globals: { ...globals.jest, ...globals.node },
169-
parserOptions: {
170-
project: ['./tests/tsconfig.json'],
171-
},
172174
},
173175
plugins: { jest },
174176
rules: {
@@ -183,4 +185,37 @@ export default [
183185
...any_rules('off'),
184186
},
185187
},
188+
{
189+
files: [join('packages', 'backend', '**', '*.{ts,tsx,mtsx,mts}')],
190+
languageOptions: {
191+
parserOptions: {
192+
sourceType: 'module',
193+
tsconfigRootDir: join(import.meta.dirname, 'packages', 'backend'),
194+
projectService: true,
195+
},
196+
},
197+
},
198+
{
199+
files: [join('packages', 'frontend', '**', '*.{ts,tsx,mtsx,mts}')],
200+
plugins: {
201+
'react-hooks': reactHooks,
202+
'react-refresh': reactRefresh,
203+
},
204+
languageOptions: {
205+
ecmaVersion: 2022,
206+
globals: globals.browser,
207+
parserOptions: {
208+
sourceType: 'module',
209+
tsconfigRootDir: join(import.meta.dirname, 'packages', 'frontend'),
210+
projectService: true,
211+
},
212+
},
213+
rules: {
214+
...reactHooks.configs.recommended.rules,
215+
'react-refresh/only-export-components': [
216+
'warn',
217+
{ allowConstantExport: true },
218+
],
219+
},
220+
},
186221
];

0 commit comments

Comments
 (0)