Skip to content

Commit

Permalink
Latest experimental changes (#394)
Browse files Browse the repository at this point in the history
* refactor: inject io only (#391)

Currently we inject all sorts of functions into all sorts of functions. After reading a few articles about dependency injection, I have come to the conclusion that it would be better if we only inject IO function and build all other services in-place or just inline them.

We now have four layers in the app (which I will also document in a dev guide soon)

- Domain: Pure logic related to the problem domain
- IO: Functions for interacting with external systems, like the network or the fs.
- App: Utility functions which combine IO functions into reusable compositions.
- CLI: CLI specific code.

Sources for this decision were the great articles by Mark Seemann:
- https://blog.ploeh.dk/2017/02/02/dependency-rejection/
- https://blog.ploeh.dk/2017/01/30/partial-application-is-dependency-injection/
- https://blog.ploeh.dk/2017/01/27/dependency-injection-is-passing-an-argument/
- https://blog.ploeh.dk/2017/01/27/from-dependency-injection-to-dependency-rejection/
- https://blog.ploeh.dk/2017/01/03/decoupling-application-errors-from-domain-models/
- https://blog.ploeh.dk/2023/10/02/dependency-whac-a-mole/

* refactor: dependency add logic

Extract imperative non-cli logic to own function. This way it can be tested in integration tests without the cli. Actual functionality was only changed minimally.

* refactor: rename files

Rename files to better be in line with other file names

* fix: missing log

* fix: incorrect log level

* fix: incorrect log message

* conf: eslint

Specify project tsconfig

* conf: eslint

Unawaited promises are errors

* refactor: debug-loggin

Make debug loggin async. This will make it easier to write to a file if we want to and also makes it clear that logging is an IO operation.

* conf: jsdoc eslint

require jsdoc for public constants and variables

* docs: add missing jsdoc

* refactor: simplify project structure

Fewer directories and files. Move things closer together and delete unused things

* deps: bump typescript

Hopefully get some performance and refactor improvements without any breaking changes

* refactor: cleanup io

Make io modules only contain abstractions of external io logic. Move all other code either into domain (if it is pure) or app (if it is impure)
  • Loading branch information
ComradeVanti authored Sep 8, 2024
1 parent 4c421fe commit 823ead7
Show file tree
Hide file tree
Showing 155 changed files with 3,545 additions and 4,253 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/node_modules
/lib
.eslintrc.js
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,27 @@ module.exports = {
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
"jsdoc/require-returns": 0,
"jsdoc/require-jsdoc": [
1,
"warn",
{
publicOnly: true,
contexts: [
"TSTypeAliasDeclaration",
"TSInterfaceDeclaration",
"TSPropertySignature",
"TSMethodSignature",
"ExportNamedDeclaration > VariableDeclaration",
],
},
],
"jsdoc/require-param": 0,
"jsdoc/require-throws": 1,
"jsdoc/require-description-complete-sentence": 1,
"jsdoc/check-param-names": [1, { checkDestructured: false }],
"@typescript-eslint/no-floating-promises": "error",
},
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json",
},
plugins: ["@typescript-eslint", "jsdoc"],
};
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ jobs:
- name: Unit tests
run: npm run test:unit

integration-test:
runs-on: ubuntu-latest
name: Integration Tests
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "22.x"
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run test:integration

e2e-test:
runs-on: ${{ matrix.os }}-latest
strategy:
Expand Down Expand Up @@ -46,6 +61,7 @@ jobs:
runs-on: ubuntu-latest
needs:
- unit-test
- integration-test
- e2e-test
if: github.ref == 'refs/heads/master'
steps:
Expand Down
4 changes: 0 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ module.exports = {
testEnvironment: "node",
verbose: true,
clearMocks: true,
setupFilesAfterEnv: [
"./test/project-manifest-assertions.ts",
"./test/result-assertions.ts",
],
};
52 changes: 48 additions & 4 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"scripts": {
"test:e2e": "jest --testMatch \"**/e2e/**/*.test.ts\" --runInBand",
"test:unit": "cross-env NODE_ENV=test jest --testMatch \"**/unit/**/*.test.ts\"",
"test:integration": "jest --testMatch \"**/integration/**/*.test.ts\" --runInBand",
"test:unit": "jest --testMatch \"**/unit/**/*.test.ts\"",
"clean": "rimraf lib",
"build": "npm run clean && tsc -p tsconfig.build.json",
"build:watch": "tsc -w -p tsconfig.build.json",
Expand Down Expand Up @@ -56,11 +57,12 @@
"eslint-plugin-jsdoc": "^48.8.3",
"fast-check": "^3.16.0",
"jest": "^29.7.0",
"nock": "^13.5.5",
"prettier": "^2.8.8",
"rimraf": "^5.0.5",
"semantic-release": "^19.0.3",
"ts-jest": "^29.1.2",
"typescript": "^5.2.2"
"typescript": "^5.5.4"
},
"dependencies": {
"@commander-js/extra-typings": "^9.5.0",
Expand Down
Loading

0 comments on commit 823ead7

Please sign in to comment.