Skip to content

Commit

Permalink
esm + vitest + eslint upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikzogg committed Jun 25, 2024
1 parent 4d9e1e9 commit 2764a58
Show file tree
Hide file tree
Showing 30 changed files with 4,261 additions and 4,411 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const config = require('@chubbyts/chubbyts-eslint/dist/eslintrc').default;

module.exports = {
...config,
parserOptions: {
...config.parserOptions,
project: './tsconfig.eslint.json',
},
};
1 change: 0 additions & 1 deletion .eslintrc.js

This file was deleted.

16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ jobs:
- name: checkout
uses: actions/checkout@v4
- name: docker build
run: docker build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) -f docker/development/node/Dockerfile . -t node
run: docker build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -u) -f docker/development/node/Dockerfile . -t node
- name: pnpm install
run: docker container run -v ${GITHUB_WORKSPACE}:/app node /bin/bash -c 'source ~/.bashrc && pnpm install'
- name: pnpm run cs
run: docker container run -v ${GITHUB_WORKSPACE}:/app node /bin/bash -c 'source ~/.bashrc && pnpm run cs'
- name: pnpm run lint
run: docker container run -v ${GITHUB_WORKSPACE}:/app node /bin/bash -c 'source ~/.bashrc && pnpm run lint'
- name: pnpm run test --coverage --no-cache
run: docker container run -v ${GITHUB_WORKSPACE}:/app node /bin/bash -c 'source ~/.bashrc && pnpm run test --coverage --no-cache'
- name: pnpm run test:integration --no-cache
run: docker container run -v ${GITHUB_WORKSPACE}:/app node /bin/bash -c 'source ~/.bashrc && pnpm run test:integration --no-cache'
- name: pnpm run test --run --coverage --no-cache
run: docker container run -v ${GITHUB_WORKSPACE}:/app node /bin/bash -c 'source ~/.bashrc && pnpm run test --run --coverage --no-cache'
- name: pnpm run test:integration --run --no-cache
run: docker container run -v ${GITHUB_WORKSPACE}:/app node /bin/bash -c 'source ~/.bashrc && pnpm run test:integration --run --no-cache'
- name: pnpm run infection
run: docker container run -v ${GITHUB_WORKSPACE}:/app node /bin/bash -c 'source ~/.bashrc && pnpm run infection'
- name: pnpm run build
Expand All @@ -55,7 +55,7 @@ jobs:
node-version: '18'
- run: corepack enable pnpm
- run: pnpm install
- run: pnpm run test
- run: pnpm run test --run
node20:
name: Node 20
runs-on: ubuntu-22.04
Expand All @@ -70,8 +70,8 @@ jobs:
- run: pnpm install
- run: pnpm run cs
- run: pnpm run lint
- run: pnpm run test --coverage --no-cache
- run: pnpm run test:integration --no-cache
- run: pnpm run test --run --coverage --no-cache
- run: pnpm run test:integration --run --no-cache
- run: pnpm run infection
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ A minimal skeleton for [chubbyts-framework][5].
* [@chubbyts/chubbyts-http-node-bridge][8]: ^1.2.0
* [@chubbyts/chubbyts-http-types][9]: ^1.2.3
* [@chubbyts/chubbyts-log-types][10]: ^1.3.2
* [@chubbyts/chubbyts-pino-adapter][11]: ^1.3.1
* [commander][12]: ^12.0.0
* [pino][13]: ^8.19.0
* [@chubbyts/chubbyts-pino-adapter][11]: ^1.3.2
* [commander][12]: ^12.1.0
* [pino][13]: ^9.2.0

## Environment

Expand Down
30 changes: 11 additions & 19 deletions bin/console.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { createServer } from 'http';
import { Command } from 'commander';
import { containerFactory } from '../bootstrap/container';
import type { CleanDirectoriesCommand } from '../src/command';
import { containerFactory } from '../bootstrap/container.js';
import type { CleanDirectoriesCommand } from '../src/command.js';

const program = new Command();

const container = containerFactory(process.env.NODE_ENV as string);

type Action = (...args: Array<string>) => Promise<number> | number;

const runAction = async (action: Action, args: Array<string>): Promise<number> => {
Expand All @@ -20,31 +17,26 @@ const runAction = async (action: Action, args: Array<string>): Promise<number> =

const run = (action: Action) => {
return async (...args: Array<string>): Promise<void> => {
const server = createServer((_, res) => {
res.writeHead(200);
res.end();
});

server.listen(9999);

console.log(`command start: ${new Date().toJSON()}`);
const exitCode = await runAction(action, args);

setTimeout(() => {
server.close();
process.exit(exitCode);
}, 1000);
console.log(`command end: ${new Date().toJSON()}, exitCode: ${exitCode}`);
process.exit(exitCode);
};
};

(async () => {
const container = await containerFactory(process.env.NODE_ENV as string);

program
.command('clean-directories')
.argument('[directoryNames]')
.description('Delete everything within a given directory.')
.action(
run((directoryNamesAsString: string): number => {
run((directoryNamesAsString?: string): number => {
const command = container.get<CleanDirectoriesCommand>('cleanDirectoriesCommand');
return command(directoryNamesAsString.split(',').map((directoryName) => directoryName.trim()));
return command(
directoryNamesAsString ? directoryNamesAsString.split(',').map((directoryName) => directoryName.trim()) : [],
);
}),
);

Expand Down
6 changes: 3 additions & 3 deletions bootstrap/container.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { existsSync, mkdirSync } from 'fs';
import type { Container } from '@chubbyts/chubbyts-dic-types/dist/container';
import { createContainerByConfigFactory } from '@chubbyts/chubbyts-dic-config/dist/dic-config';
import type { Config } from '../config/production';
import type { Config } from '../config/production.js';

export const containerFactory = (env: string): Container => {
export const containerFactory = async (env: string): Promise<Container> => {
/* eslint-disable @typescript-eslint/no-var-requires */
const config: Config = require(`../config/${env}`).configFactory(env);
const config: Config = (await import(`../config/${env}.js`)).configFactory(env);

config.directories.forEach((directory) => {
if (!existsSync(directory)) {
Expand Down
6 changes: 3 additions & 3 deletions bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import type {
StreamFromResourceFactory,
UriFactory,
} from '@chubbyts/chubbyts-http-types/dist/message-factory';
import type { Config } from '../config/production';
import { containerFactory } from '../bootstrap/container';
import type { Config } from '../config/production.js';
import { containerFactory } from '../bootstrap/container.js';

(async () => {
const container = containerFactory(process.env.NODE_ENV as string);
const container = await containerFactory(process.env.NODE_ENV as string);

const app = createApplication(container.get<Array<Middleware>>('middlewares'));

Expand Down
4 changes: 2 additions & 2 deletions config/development.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Config } from './production';
import { configFactory as productionConfigFactory } from './production';
import type { Config } from './production.js';
import { configFactory as productionConfigFactory } from './production.js';

export const configFactory = (env: string): Config => {
const config = productionConfigFactory(env);
Expand Down
6 changes: 0 additions & 6 deletions config/jest.ts

This file was deleted.

4 changes: 2 additions & 2 deletions config/production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
streamFactoryServiceFactory,
streamFromResourceFactoryServiceFactory,
uriFactoryServiceFactory,
} from '../src/service-factory';
} from '../src/service-factory.js';

export type Config = {
debug: boolean;
Expand All @@ -35,7 +35,7 @@ export type Config = {
};
};

const rootDir = realpathSync(__dirname + '/..');
const rootDir = realpathSync(new URL('..', import.meta.url));

export const configFactory = (env: string): Config => {
console.log(`Loading "${env}" config`);
Expand Down
3 changes: 3 additions & 0 deletions config/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { configFactory as developmentConfigFactory } from './development.js';

export const configFactory = developmentConfigFactory;
4 changes: 2 additions & 2 deletions docker/production/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ WORKDIR /app-build
RUN source ~/.bashrc && pnpm install
RUN source ~/.bashrc && pnpm run cs
RUN source ~/.bashrc && pnpm run lint
RUN source ~/.bashrc && pnpm run test --coverage --no-cache
RUN source ~/.bashrc && pnpm run test:integration --no-cache
RUN source ~/.bashrc && pnpm run test --run --coverage --no-cache
RUN source ~/.bashrc && pnpm run test:integration --run --no-cache
RUN source ~/.bashrc && pnpm run build

# prod
Expand Down
17 changes: 0 additions & 17 deletions jest.config.js

This file was deleted.

12 changes: 0 additions & 12 deletions jest.integration.config.js

This file was deleted.

7 changes: 0 additions & 7 deletions jest.integration.global-teardown.js

This file was deleted.

2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"ext": "json,ts,tsx",
"exec": "node ${CHUBBYTS_NODE_OPTIONS} -r ts-node/register bootstrap/index.ts"
"exec": "node ${CHUBBYTS_NODE_OPTIONS} --loader ts-node/esm bootstrap/index.ts"
}
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@chubbyts/chubbyts-framework-skeleton",
"version": "1.0.0",
"description": "A minimal skeleton for chubbyts-framework.",
"type": "module",
"keywords": [
"chubbyts",
"framework",
Expand All @@ -13,17 +14,17 @@
"scripts": {
"build": "rm -Rf dist && tsc",
"command": "ts-node bin/console.ts",
"cs-fix": "./node_modules/prettier/bin/prettier.cjs --write bin bootstrap config src tests *.js",
"cs": "./node_modules/prettier/bin/prettier.cjs --check bin bootstrap config src tests *.js",
"cs-fix": "prettier --write bin bootstrap config src tests *.cjs *.ts",
"cs": "prettier --check bin bootstrap config src tests *.cjs *.ts",
"develop:debug": "CHUBBYTS_NODE_OPTIONS='--inspect=0.0.0.0:8888' nodemon",
"develop": "nodemon",
"infection": "stryker run",
"lint-fix": "eslint bin bootstrap config src tests --fix",
"lint": "eslint bin bootstrap config src tests",
"start:debug": "pnpm install && pnpm run lint-fix && pnpm run cs-fix && pnpm run develop:debug",
"start": "pnpm install && pnpm run lint-fix && pnpm run cs-fix && pnpm run develop",
"test:integration": "jest --config jest.integration.config.js",
"test": "jest"
"test:integration": "vitest --config vitest.integration.config.js",
"test": "vitest --config vitest.config.js"
},
"prettier": {
"printWidth": 120,
Expand All @@ -47,28 +48,27 @@
"@chubbyts/chubbyts-http-node-bridge": "^1.2.0",
"@chubbyts/chubbyts-http-types": "^1.2.3",
"@chubbyts/chubbyts-log-types": "^1.3.2",
"@chubbyts/chubbyts-pino-adapter": "^1.3.1",
"commander": "^12.0.0",
"pino": "^8.19.0"
"@chubbyts/chubbyts-pino-adapter": "^1.3.2",
"commander": "^12.1.0",
"pino": "^9.2.0"
},
"devDependencies": {
"@chubbyts/chubbyts-eslint": "^2.0.3",
"@chubbyts/chubbyts-function-mock": "^1.4.1",
"@jest/globals": "^29.7.0",
"@chubbyts/chubbyts-eslint": "^2.0.7",
"@chubbyts/chubbyts-function-mock": "^1.4.2",
"@stryker-mutator/core": "^8.2.6",
"@stryker-mutator/jest-runner": "^8.2.6",
"@stryker-mutator/typescript-checker": "^8.2.6",
"@swc/cli": "^0.3.10",
"@swc/core": "^1.4.8",
"@swc/jest": "^0.2.36",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.30",
"@stryker-mutator/vitest-runner": "^8.2.6",
"@swc/cli": "^0.3.12",
"@swc/core": "^1.6.1",
"@types/node": "^20.14.2",
"@vitest/coverage-v8": "^1.6.0",
"cross-fetch": "^4.0.0",
"jest": "^29.7.0",
"nodemon": "^3.1.0",
"prettier": "^3.2.5",
"prettier-2": "npm:prettier@^2.8.8",
"ts-node": "^10.9.2",
"typescript": "^5.4.3"
}
"typescript": "^5.4.3",
"vitest": "^1.6.0"
},
"packageManager": "pnpm@9.4.0+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a"
}
Loading

0 comments on commit 2764a58

Please sign in to comment.