Skip to content

Commit 34195f0

Browse files
authored
Merge pull request #18 from spuxx1701/feat/nest
chore: Introduced react and nestjs test applications
2 parents a4818fb + 27a359d commit 34195f0

Some content is hidden

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

53 files changed

+3892
-153
lines changed

.eslintrc.cjs

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ module.exports = {
44
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
55
ignorePatterns: ['dist', '.eslintrc.cjs'],
66
parser: '@typescript-eslint/parser',
7+
parserOptions: {
8+
project: 'tsconfig.json',
9+
tsconfigRootDir: __dirname,
10+
sourceType: 'module',
11+
},
712
plugins: ['prettier', '@typescript-eslint'],
813
rules: {
914
// Miscellanous

.github/workflows/main.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ jobs:
1010
run_checks:
1111
name: Run code checks
1212
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_checks.yml@v4.0.0
13+
with:
14+
PNPM_BUILD: true
1315

1416
run_unit_tests:
15-
name: Run unit tests
16-
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_unit_tests.yml@v4.0.0
17+
name: Run tests (vitest)
18+
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_tests_vitest.yml@v4.0.0
1719
with:
20+
PNPM_BUILD: true
1821
COVERAGE_FILENAME: reports/vitest/coverage/cobertura-coverage.xml
1922
COVERAGE_FAIL_BELOW_MIN: 100
2023

.github/workflows/prerelease.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ jobs:
77
run_checks:
88
name: Run code checks
99
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_checks.yml@v4.0.0
10+
with:
11+
PNPM_BUILD: true
1012

1113
run_unit_tests:
12-
name: Run unit tests
13-
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_unit_tests.yml@v4.0.0
14+
name: Run tests (vitest)
15+
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_tests_vitest.yml@v4.0.0
1416
with:
17+
PNPM_BUILD: true
1518
COVERAGE_FILENAME: reports/vitest/coverage/cobertura-coverage.xml
1619
COVERAGE_FAIL_BELOW_MIN: 100
1720

.github/workflows/pull_request.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ jobs:
99
run_checks:
1010
name: Run code checks
1111
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_checks.yml@v4.0.0
12+
with:
13+
PNPM_BUILD: true
1214

1315
run_unit_tests:
14-
name: Run unit tests
15-
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_unit_tests.yml@v4.0.0
16+
name: Run tests (vitest)
17+
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_tests_vitest.yml@v4.0.0
1618
with:
19+
PNPM_BUILD: true
1720
COVERAGE_FILENAME: reports/vitest/coverage/cobertura-coverage.xml
1821
COVERAGE_FAIL_BELOW_MIN: 100

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_checks.yml@v4.0.0
1313

1414
run_unit_tests:
15-
name: Run unit tests
16-
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_unit_tests.yml@v4.0.0
15+
name: Run tests (vitest)
16+
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_tests_vitest.yml@v4.0.0
1717
with:
1818
COVERAGE_FILENAME: reports/vitest/coverage/cobertura-coverage.xml
1919
COVERAGE_FAIL_BELOW_MIN: 100

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pnpm-lock.yaml
2+
pnpm-workspace.yaml
23
reports/
34
dist/
45
.github/

.release-please/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{ "type": "style", "section": "Styles", "hidden": true },
1414
{ "type": "chore", "section": "Miscellaneous Chores", "hidden": true },
1515
{ "type": "refactor", "section": "Code Refactoring" },
16-
{ "type": "test", "section": "Tests" },
16+
{ "type": "test", "section": "Tests", "hidden": true },
1717
{ "type": "build", "section": "Build System" },
1818
{ "type": "ci", "section": "Continuous Integration", "hidden": true }
1919
]

apps/nest/nest-cli.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://json.schemastore.org/nest-cli",
3+
"collection": "@nestjs/schematics",
4+
"sourceRoot": "src",
5+
"compilerOptions": {
6+
"builder": "swc",
7+
"deleteOutDir": true
8+
}
9+
}

apps/nest/package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "nest",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "vite dev",
7+
"debug": "nest start --debug --watch",
8+
"preview": "node dist/main.mjs",
9+
"build": "vite build",
10+
"types": "tsc --noEmit"
11+
},
12+
"dependencies": {
13+
"@nestjs/common": "^10.0.0",
14+
"@nestjs/core": "^10.0.0",
15+
"@nestjs/platform-express": "^10.0.0",
16+
"reflect-metadata": "^0.2.0",
17+
"rxjs": "^7.8.1",
18+
"@spuxx/nest-utils": "workspace:@spuxx/nest-utils@*"
19+
},
20+
"devDependencies": {
21+
"source-map-support": "^0.5.21",
22+
"ts-loader": "^9.4.3",
23+
"ts-node": "^10.9.1"
24+
}
25+
}

apps/nest/src/app.controller.spec.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { AppController } from './app.controller';
3+
import { AppService } from './app.service';
4+
import { NestUtilsModule } from '@spuxx/nest-utils';
5+
6+
describe('AppController', () => {
7+
let controller: AppController;
8+
9+
beforeEach(async () => {
10+
const app: TestingModule = await Test.createTestingModule({
11+
imports: [NestUtilsModule],
12+
controllers: [AppController],
13+
providers: [AppService],
14+
}).compile();
15+
16+
controller = app.get<AppController>(AppController);
17+
});
18+
19+
describe('root', () => {
20+
it('should return "Hello World!"', () => {
21+
expect(controller.getHello()).toBe('Hello World!');
22+
});
23+
});
24+
});

apps/nest/src/app.controller.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Controller, Get } from '@nestjs/common';
2+
import { AppService } from './app.service';
3+
4+
@Controller()
5+
export class AppController {
6+
constructor(private readonly service: AppService) {}
7+
8+
@Get()
9+
getHello(): string {
10+
return this.service.getHello();
11+
}
12+
}

apps/nest/src/app.module.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Module } from '@nestjs/common';
2+
import { AppController } from './app.controller';
3+
import { AppService } from './app.service';
4+
import { NestUtilsModule } from '@spuxx/nest-utils';
5+
6+
@Module({
7+
imports: [NestUtilsModule],
8+
controllers: [AppController],
9+
providers: [AppService],
10+
})
11+
export class AppModule {}

apps/nest/src/app.service.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { NestUtilsService } from '@spuxx/nest-utils';
3+
4+
@Injectable()
5+
export class AppService {
6+
constructor(private readonly utils: NestUtilsService) {}
7+
8+
getHello(): string {
9+
return this.utils.getHello();
10+
}
11+
}

apps/nest/src/auth/config/auth.config.ts

Whitespace-only changes.

apps/nest/src/main.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { NestFactory } from '@nestjs/core';
2+
import { AppModule } from './app.module';
3+
import { Logger } from '@nestjs/common';
4+
5+
async function bootstrap() {
6+
const app = await NestFactory.create(AppModule);
7+
Logger.log(`Application is running on: http://localhost:3000`, 'Bootstrap');
8+
// Required, see: https://www.npmjs.com/package/vite-plugin-node#get-started
9+
if (import.meta.env.PROD) {
10+
await app.listen(3000);
11+
}
12+
return app;
13+
}
14+
15+
export const app = bootstrap();

apps/nest/tsconfig.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.nest.json",
3+
"include": ["./src/**/*"],
4+
"compilerOptions": {
5+
"outDir": "./dist"
6+
}
7+
}

apps/nest/vite.config.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference types="vitest" />
2+
import baseConfig from '../../vite.config';
3+
import { mergeConfig, defineConfig } from 'vite';
4+
import { VitePluginNode } from 'vite-plugin-node';
5+
6+
export default mergeConfig(
7+
baseConfig,
8+
defineConfig({
9+
server: {
10+
port: 3000,
11+
},
12+
plugins: [
13+
...baseConfig.plugins!,
14+
// https://www.npmjs.com/package/vite-plugin-node#get-started
15+
VitePluginNode({
16+
adapter: 'nest',
17+
tsCompiler: 'swc',
18+
appPath: 'src/main.ts',
19+
exportName: 'app',
20+
initAppOnBoot: true,
21+
}),
22+
],
23+
}),
24+
);

test-apps/react/index.html apps/react/index.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
65
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>@spuxx/browser-utils</title>
6+
<title>@spuxx/jslibs</title>
87
</head>
98
<body>
109
<div id="root"></div>

test-apps/react/main.tsx apps/react/main.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom/client';
33
import App from './src/App.tsx';
4+
// @ts-expect-error TypeScript config is f***ed in this app for some reason
45
import de from './translations/de.yaml';
56
import { Intl, Logger } from '@spuxx/js-utils';
67

apps/react/package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "react-test-app",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"private": true,
6+
"scripts": {
7+
"dev": "vite dev",
8+
"types": "tsc --noEmit"
9+
},
10+
"dependencies": {
11+
"@spuxx/browser-utils": "workspace:@spuxx/browser-utils@*",
12+
"@spuxx/js-utils": "workspace:@spuxx/js-utils@*",
13+
"react": "18.2.0",
14+
"react-dom": "18.2.0"
15+
},
16+
"devDependencies": {
17+
"@types/react": "18.3.3",
18+
"@types/react-dom": "18.3.0",
19+
"@vitejs/plugin-react": "^4.3.1"
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
import React from 'react';
12
import { intl } from '@spuxx/js-utils';
23

3-
function App() {
4+
export default function App(): React.ReactElement {
45
return (
56
<>
67
<h1>{intl('app.title')}</h1>
78
</>
89
);
910
}
10-
11-
export default App;

apps/react/translations/de.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
app:
2+
title: 'spuxx/jslibs'

apps/react/tsconfig.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.bundler.json",
3+
"include": ["./src"],
4+
"compilerOptions": {
5+
"jsx": "react-jsx"
6+
}
7+
}

apps/react/vite.config.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import baseConfig from '../../vite.config';
2+
import { mergeConfig, defineConfig } from 'vite';
3+
import react from '@vitejs/plugin-react';
4+
import ViteYaml from '@modyfi/vite-plugin-yaml';
5+
6+
export default mergeConfig(
7+
baseConfig,
8+
defineConfig({
9+
plugins: [...baseConfig.plugins!, ViteYaml(), react()],
10+
}),
11+
);

nest-cli.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"$schema": "https://json.schemastore.org/nest-cli",
3+
"collection": "@nestjs/schematics",
4+
"monorepo": true,
5+
"sourceRoot": "apps/nest/src",
6+
"compilerOptions": {
7+
"builder": "swc",
8+
"typeCheck": true,
9+
"deleteOutDir": true
10+
},
11+
"projects": {
12+
"test-app": {
13+
"type": "application",
14+
"root": "apps/nest",
15+
"sourceRoot": "apps/nest/src",
16+
"compilerOptions": {
17+
"tsConfigPath": "apps/nest/tsconfig.json"
18+
}
19+
},
20+
"nest-utils": {
21+
"type": "library",
22+
"root": "packages/nest-utils",
23+
"entryFile": "index",
24+
"sourceRoot": "packages/nest-utils/src",
25+
"compilerOptions": {
26+
"tsConfigPath": "packages/nest-utils/tsconfig.json"
27+
}
28+
}
29+
}
30+
}

package.json

+19-6
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,44 @@
2222
"packageManager": "pnpm@9.6.0",
2323
"private": "true",
2424
"scripts": {
25+
"dev": "concurrently \"pnpm dev:js-utils\" \"pnpm dev:browser-utils\" \"pnpm dev:nest-utils\" \"pnpm dev:app:react\" \"pnpm dev:app:nest\"",
26+
"dev:js-utils": "cd packages/js-utils && pnpm dev",
27+
"dev:browser-utils": "cd packages/browser-utils && pnpm dev",
28+
"dev:nest-utils": "cd packages/nest-utils && pnpm dev",
29+
"dev:app:react": "cd apps/react && pnpm dev",
30+
"dev:app:nest": "cd apps/nest && pnpm dev",
2531
"publish:test": "pnpm -r publish --dry-run --no-git-checks",
26-
"test": "pnpm run test:unit",
27-
"test:unit": "vitest run --coverage",
32+
"test": "pnpm test:vitest",
33+
"test:vitest": "vitest run --coverage",
2834
"check": "pnpm types && pnpm run lint && pnpm run prettier-check",
29-
"types": "tsc --noEmit",
35+
"types": "pnpm -r types",
3036
"lint": "eslint . --ext ts,tsx",
3137
"prettier-check": "prettier --check .",
3238
"format": "prettier --write ."
3339
},
3440
"devDependencies": {
3541
"@modyfi/vite-plugin-yaml": "1.1.0",
42+
"@nestjs/cli": "10.4.2",
43+
"@nestjs/testing": "10.3.10",
44+
"@swc/cli": "^0.4.0",
45+
"@swc/core": "^1.7.6",
46+
"@types/express": "^4.17.21",
3647
"@types/node": "22.1.0",
3748
"@typescript-eslint/eslint-plugin": "7.18.0",
3849
"@typescript-eslint/parser": "7.18.0",
3950
"@vitest/coverage-v8": "2.0.5",
51+
"concurrently": "^8.2.2",
4052
"eslint": "8.57.0",
4153
"eslint-config-prettier": "9.1.0",
4254
"eslint-plugin-prettier": "5.2.1",
4355
"prettier": "3.3.3",
44-
"release-please": "^16.12.0",
56+
"release-please": "16.12.0",
4557
"typescript": "5.5.4",
58+
"unplugin-swc": "^1.5.1",
4659
"vite": "5.3.5",
4760
"vite-plugin-dts": "3.9.1",
61+
"vite-plugin-node": "^3.1.0",
4862
"vite-tsconfig-paths": "4.3.2",
4963
"vitest": "2.0.5"
50-
},
51-
"dependencies": {}
64+
}
5265
}

0 commit comments

Comments
 (0)