Skip to content

Commit

Permalink
Chore/improve devx (#8)
Browse files Browse the repository at this point in the history
* chore: update test tsconfigs to be selfcontained

* chore: simplify iql

* chore: sort package.jsons

* chore: add gitignore

* chore: update eslintrc

* refactor: allow tsc watch using composite references

* chore: update runtime tsconfig

* fix: correct path

* chore: remove misleading script

* chore: add tasks

* chore: bump package versions

* chore: add guide for upgrading packages

* chore: prettierignore generated files

* chore: make pipelines faster

* chore: remove old lint scripts

* fix: use moved tsconfig

* chore: simplify build:watch

* fix: remove overly permissive regex

* chore: update dev config

* chore: PR comments

* chore: add another lint

* fix: use declaration maps

* chore: reformat

* chore: add more references
  • Loading branch information
jkoenig134 authored Feb 1, 2024
1 parent 7159bd4 commit d0645cc
Show file tree
Hide file tree
Showing 36 changed files with 1,633 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .ci/runChecks.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set -e

npm ci
npm run build --workspaces
npm run build:node
npm run lint:eslint
npm run lint:prettier
npx -ws license-check
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"parserOptions": {
"project": ["./packages/*/tsconfig.json", "./packages/*/test/tsconfig.json"]
},
"ignorePatterns": ["jest.config.js", "Schemas.ts", "dist", "node_modules", "lib-web", "generated", "demo"],
"ignorePatterns": ["jest.config.js", "Schemas.ts", "dist", "node_modules", "lib-web", "*.gen.js", "demo"],
"rules": {
"jest/expect-expect": [
"error",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
node-version: 20
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run build:ci --workspaces
- run: npm run build:ci -ws
env:
BUILD_NUMBER: ${{ github.run_number }}
COMMIT_HASH: ${{ github.sha }}
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
node-version: 18
- run: npm ci
- run: npm run build:node --workspaces
- run: npm run build:node
- run: npm run test:ci --workspace=@nmshd/app-runtime
env:
NMSHD_TEST_BASEURL: http://localhost:5000
Expand All @@ -44,7 +44,7 @@ jobs:
- run: npm ci
- name: Start MongoDB
uses: supercharge/mongodb-github-action@v1
- run: npm run build:node --workspaces
- run: npm run build:node
- run: npm run test:ci:mongodb --workspace=@nmshd/consumption
env:
CONNECTION_STRING: mongodb://127.0.0.1:27017
Expand All @@ -67,7 +67,7 @@ jobs:
- uses: js-soft/ferretdb-github-action@1.1.0
with:
ferretdb-telemetry: "enabled"
- run: npm run build:node --workspaces
- run: npm run build:node
- run: npm run test:ci:mongodb --workspace=@nmshd/consumption
env:
CONNECTION_STRING: mongodb://127.0.0.1:27017
Expand All @@ -87,7 +87,7 @@ jobs:
with:
node-version: 20
- run: npm ci
- run: npm run build:node --workspaces
- run: npm run build:node
- run: npm run test:ci:lokijs --workspace=@nmshd/consumption
env:
NMSHD_TEST_BASEURL: http://localhost:5000
Expand All @@ -105,7 +105,7 @@ jobs:
env:
BUILD_NUMBER: ${{ github.run_number }}
COMMIT_HASH: ${{ github.sha }}
- run: npm run build:node --workspaces
- run: npm run build:node
- run: npm run test:ci --workspace=@nmshd/content

test-runtime-mongodb:
Expand All @@ -121,7 +121,7 @@ jobs:
node-version: 20
- uses: supercharge/mongodb-github-action@v1
- run: npm ci
- run: npm run build:node --workspaces
- run: npm run build:node
- run: npm run build:schemas --workspace=@nmshd/runtime
- run: npm run test:ci:mongodb --workspace=@nmshd/runtime
env:
Expand All @@ -146,7 +146,7 @@ jobs:
ferretdb-telemetry: "enabled"
ferretdb-version: latest
- run: npm ci
- run: npm run build:node --workspaces
- run: npm run build:node
- run: npm run build:schemas --workspace=@nmshd/runtime
- run: npm run test:ci:mongodb --workspace=@nmshd/runtime
env:
Expand All @@ -167,7 +167,7 @@ jobs:
with:
node-version: 20
- run: npm ci
- run: npm run build:node --workspaces
- run: npm run build:node
- run: npm run build:schemas --workspace=@nmshd/runtime
- run: npm run test:ci:lokijs --workspace=@nmshd/runtime
env:
Expand All @@ -187,7 +187,7 @@ jobs:
with:
node-version: 20
- run: npm ci
- run: npm run build:node --workspaces
- run: npm run build:node
- name: Start MongoDB
uses: supercharge/mongodb-github-action@v1
- run: npm run test:ci:mongodb --workspace=@nmshd/transport
Expand All @@ -209,7 +209,7 @@ jobs:
with:
node-version: 20
- run: npm ci
- run: npm run build:node --workspaces
- run: npm run build:node
- uses: js-soft/ferretdb-github-action@1.1.0
with:
ferretdb-telemetry: "enabled"
Expand All @@ -232,7 +232,7 @@ jobs:
with:
node-version: 20
- run: npm ci
- run: npm run build:node --workspaces
- run: npm run build:node
env:
BUILD_NUMBER: ${{ github.run_number }}
COMMIT_HASH: ${{ github.sha }}
Expand All @@ -250,7 +250,7 @@ jobs:
with:
node-version: 20
- run: npm ci
- run: npm run build:node --workspaces
- run: npm run build:node
env:
BUILD_NUMBER: ${{ github.run_number }}
COMMIT_HASH: ${{ github.sha }}
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

node_modules
tsconfig.tsbuildinfo
node_modules
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ lib-web
dist-test
Schemas.ts
generated
*.gen.js
27 changes: 27 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile",
"command": "npm run build:watch",
"type": "shell",
"isBackground": true,
"presentation": {
"reveal": "never",
"focus": false
},
"runOptions": {
"runOn": "folderOpen"
}
},
{
"label": "Clear",
"command": "npm run test:teardown",
"type": "shell",
"isBackground": true,
"presentation": {
"reveal": "always"
}
}
]
}
21 changes: 21 additions & 0 deletions README_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

1. Download and install [Node JS](https://nodejs.org/en/download/)
2. run `npm i`
3. run `npm run build:watch` (this is also added as a VSCode task that is configured to [run on folder open](https://code.visualstudio.com/updates/v1_30#_run-on-folder-open))

## Running scripts

Expand All @@ -17,6 +18,14 @@ This workspace provide two types of scripts:

additionally you can run a script in all workspaces by `npm run -ws --if-present <scriptname>`

## Linting

- Typescript
- each package provides its own typescript linting script. You can run it by `npm run lint:tsc` from the package directory or by `npm run -w packages/<package> lint:tsc` from the root of the project
- the root project also provides a script that lints all packages. You can run it by `npm run lint:tsc` from the root of the project
- Prettier: simply run `npm run lint:prettier` from the root of the project
- ESLint: simply run `npm run lint:eslint` from the root of the project

## Check for outdated dependencies

To check for outdated dependencies run `npm run outdated`. This will check the root folder and all packages using [npm-check-updates](https://www.npmjs.com/package/npm-check-updates).
Expand Down Expand Up @@ -68,3 +77,15 @@ Or deserialize-/fromUnknown won't find your class.

- Check if all (parent) classes up to Serializable(-Async) inclulde a @schema declaration with a type
- You might have several different Serializable(-Async) instances up- and running. This usually happens if ts-serval/crypto/transport are not correctly imported.

### Upgrading package versions

When bumping the packages pinned directly in the runtime (transport, content and consumption) you always have to update the packages in the runtime. If you don't do this, you will get errors like:

```
Error: src/AppRuntime.ts(106,30): error TS2416: Property 'login' in type 'AppRuntime' is not assignable to the same property in base type 'Runtime<AppConfig>'.
Type '(accountController: AccountController, consumptionController: ConsumptionController) => Promise<AppRuntimeServices>' is not assignable to type '(accountController: AccountController, consumptionController: ConsumptionController) => Promise<RuntimeServices>'.
Error: src/AppRuntime.ts(107,63): error TS2345: Argument of type 'import("/home/runner/work/runtime/runtime/packages/consumption/dist/consumption/ConsumptionController").ConsumptionController' is not assignable to parameter of type 'import("/home/runner/work/runtime/runtime/packages/runtime/node_modules/@nmshd/consumption/dist/consumption/ConsumptionController").ConsumptionController'.
```

This is caused by the runtime using different (npm insalled) versions of the bumped packages.
37 changes: 29 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
"packages/app-runtime"
],
"scripts": {
"build:node": "tsc --build",
"build:watch": "tsc --build -w",
"lint": "npm run lint:eslint && npm run lint:prettier && npm run lint:tsc",
"lint:eslint": "eslint --ext .ts ./packages/*/src ./packages/*/test",
"lint:prettier": "prettier --check .",
"lint:tsc": "npm run -ws lint:tsc",
"outdated": "ncu -i && ncu -i -ws"
"outdated": "ncu -i && ncu -i -ws",
"test:teardown": "docker compose -f .dev/compose.yml down -fsv"
},
"devDependencies": {
"@js-soft/eslint-config-ts": "^1.6.6",
Expand Down
5 changes: 1 addition & 4 deletions packages/app-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
"bundle:min": "webpack --stats-all --config webpack.min.config.js",
"bundle:notest": "npm run bundle:lib && npm run bundle:min",
"cdep": "tsc && madge --circular dist",
"lint": "npm run lint:prettier && npm run lint:eslint && npm run lint:tsc",
"lint:eslint": "eslint --ext .ts ./src ./test",
"lint:prettier": "prettier --check .",
"lint:tsc": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit",
"test": "jest",
"test:ci": "jest -i"
Expand Down Expand Up @@ -64,7 +61,7 @@
"@types/luxon": "^3.4.2"
},
"peerDependencies": {
"@nmshd/runtime": "^3.4.3"
"@nmshd/runtime": "^3.4.4"
},
"publishConfig": {
"access": "public",
Expand Down
4 changes: 2 additions & 2 deletions packages/app-runtime/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"extends": "../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "../",
"noEmit": true
},
"files": ["../../../node_modules/jest-expect-message/types/index.d.ts"],
"include": ["**/*.ts"],
"include": ["**/*.ts", "../src/**/*.ts"],
"exclude": []
}
5 changes: 3 additions & 2 deletions packages/app-runtime/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"extends": "../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"baseUrl": "."
"rootDir": "src"
},
"include": ["src/**/*.ts"],
"exclude": []
"exclude": [],
"references": [{ "path": "../runtime" }]
}
Loading

0 comments on commit d0645cc

Please sign in to comment.