Skip to content

Commit a98e520

Browse files
committed
chore: More work on introducing nest into the monorepo
1 parent c58641a commit a98e520

22 files changed

+250
-14
lines changed

apps/nest/package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"dev": "nest start --watch",
6+
"dev": "vite dev",
77
"debug": "nest start --debug --watch",
8-
"build": "nest build",
8+
"preview": "node dist/main.mjs",
9+
"build": "vite build",
910
"types": "tsc --noEmit"
1011
},
1112
"dependencies": {
1213
"@nestjs/common": "^10.0.0",
1314
"@nestjs/core": "^10.0.0",
1415
"@nestjs/platform-express": "^10.0.0",
1516
"reflect-metadata": "^0.2.0",
16-
"rxjs": "^7.8.1"
17+
"rxjs": "^7.8.1",
18+
"@spuxx/js-utils": "workspace:@spuxx/nest-utils@*"
1719
},
1820
"devDependencies": {
1921
"source-map-support": "^0.5.21",
2022
"ts-loader": "^9.4.3",
21-
"ts-node": "^10.9.1",
22-
"vite-plugin-node": "^3.1.0"
23+
"ts-node": "^10.9.1"
2324
}
2425
}

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

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ describe('AppController', () => {
1212
}).compile();
1313

1414
controller = app.get<AppController>(AppController);
15-
const service = app.get<AppService>(AppService);
16-
console.log(service);
1715
});
1816

1917
describe('root', () => {

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

Whitespace-only changes.

apps/nest/src/main.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import { Logger } from '@nestjs/common';
44

55
async function bootstrap() {
66
const app = await NestFactory.create(AppModule);
7-
await app.listen(3000);
8-
const url = await app.getUrl();
9-
Logger.log(`Application is running on: ${url}`, 'Bootstrap');
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;
1013
}
11-
bootstrap();
14+
15+
export const app = bootstrap();

apps/nest/vite.config.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
/// <reference types="vitest" />
22
import baseConfig from '../../vite.config';
33
import { mergeConfig, defineConfig } from 'vite';
4+
import { VitePluginNode } from 'vite-plugin-node';
45

5-
export default mergeConfig(baseConfig, defineConfig({}));
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+
);

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"unplugin-swc": "^1.5.1",
5454
"vite": "5.3.5",
5555
"vite-plugin-dts": "3.9.1",
56+
"vite-plugin-node": "^3.1.0",
5657
"vite-tsconfig-paths": "4.3.2",
5758
"vitest": "2.0.5"
5859
}

packages/nest-utils/.npmignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*
2+
!/dist
3+
!package.json
4+
!LICENSE.md
5+
!README.md

packages/nest-utils/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Changelog

packages/nest-utils/LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) [2024] [spuxx]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/nest-utils/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# @spuxx/js-utils
2+
3+
![Release pipeline](https://github.com/spuxx1701/jslibs/actions/workflows/release.yml/badge.svg)
4+
![Main pipeline](https://github.com/spuxx1701/jslibs/actions/workflows/main.yml/badge.svg)
5+
![NPM Version](https://img.shields.io/npm/v/%40spuxx%2Fnest-utils)
6+
![License](https://img.shields.io/github/license/spuxx1701/jslibs)
7+
8+
## Description
9+
10+
`@spuxx/nest-utils` contains a selection of core utilities that I keep reusing in my NestJS applications.

packages/nest-utils/package.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "@spuxx/nest-utils",
3+
"version": "0.0.0",
4+
"description": "A package containing various utilities for NestJS applications.",
5+
"license": "MIT",
6+
"author": {
7+
"name": "spuxx",
8+
"email": "hi@spuxx.dev",
9+
"url": "https://spuxx.dev"
10+
},
11+
"keywords": [
12+
"spuxx"
13+
],
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/spuxx1701/jslibs"
17+
},
18+
"homepage": "https://github.com/spuxx1701/jslibs/blob/main/packages/nest-utils/README.md",
19+
"bugs": {
20+
"url": "https://github.com/spuxx1701/jslibs/issues"
21+
},
22+
"type": "commonjs",
23+
"main": "dist/main.js",
24+
"module": "dist/main.js",
25+
"types": "dist/main.d.ts",
26+
"exports": {
27+
".": {
28+
"types": "./dist/main.d.ts",
29+
"import": "./dist/main.js"
30+
}
31+
},
32+
"files": [
33+
"dist",
34+
"README.md",
35+
"LICENSE",
36+
"package.json"
37+
],
38+
"scripts": {
39+
"build": "nest build",
40+
"types": "tsc --noEmit"
41+
},
42+
"peerDependencies": {
43+
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
44+
"@nestjs/core": "^8.0.0 || ^9.0.0 || ^10.0.0",
45+
"reflect-metadata": "^0.1.13 || ^0.2.0"
46+
},
47+
"dependencies": {
48+
"@spuxx/js-utils": "workspace:@spuxx/js-utils@*"
49+
}
50+
}

packages/nest-utils/src/main.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './nest-utils.module';
2+
export * from './nest-utils.service';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Module } from '@nestjs/common';
2+
import { NestUtilsService } from './nest-utils.service';
3+
4+
@Module({
5+
providers: [NestUtilsService],
6+
exports: [NestUtilsService],
7+
})
8+
export class NestUtilsModule {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { NestUtilsService } from './nest-utils.service';
3+
4+
describe('NestUtilsService', () => {
5+
let service: NestUtilsService;
6+
7+
beforeEach(async () => {
8+
const module: TestingModule = await Test.createTestingModule({
9+
providers: [NestUtilsService],
10+
}).compile();
11+
12+
service = module.get<NestUtilsService>(NestUtilsService);
13+
});
14+
15+
it('should be defined', () => {
16+
expect(service).toBeDefined();
17+
});
18+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Injectable } from '@nestjs/common';
2+
3+
@Injectable()
4+
export class NestUtilsService {
5+
getHello(): string {
6+
return 'Hello World!';
7+
}
8+
}

packages/nest-utils/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+
}

packages/nest-utils/vite.config.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// <reference types="vitest" />
2+
import baseConfig from '../../vite.config';
3+
import { mergeConfig, defineConfig } from 'vite';
4+
import { resolve } from 'path';
5+
import { VitePluginNode } from 'vite-plugin-node';
6+
import { peerDependencies } from './package.json';
7+
8+
export default mergeConfig(
9+
baseConfig,
10+
defineConfig({
11+
plugins: [
12+
...baseConfig.plugins!,
13+
VitePluginNode({
14+
adapter: 'nest',
15+
tsCompiler: 'swc',
16+
appPath: 'src/main.ts',
17+
exportName: 'app',
18+
}),
19+
],
20+
build: {
21+
lib: {
22+
entry: {
23+
main: resolve(__dirname, 'src/main.ts'),
24+
},
25+
name: '@spuxx/nest-utils',
26+
formats: ['cjs', 'es'],
27+
},
28+
rollupOptions: {
29+
external: [...Object.keys(peerDependencies)],
30+
},
31+
},
32+
}),
33+
);

pnpm-lock.yaml

+44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"useDefineForClassFields": true,
66
"removeComments": true,
77
/* Resolution */
8+
"resolveJsonModule": true,
89
"types": ["vite/client", "vitest/globals", "@modyfi/vite-plugin-yaml/modules"],
910
"baseUrl": ".",
1011
"paths": {

tsconfig.nest.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"module": "CommonJS",
4+
"module": "es2022",
5+
"moduleResolution": "Node",
56
"emitDecoratorMetadata": true,
67
"experimentalDecorators": true,
78
"sourceMap": true,

vite.config.nest.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="vitest" />
2+
import baseConfig from './vite.config';
3+
import { mergeConfig, defineConfig } from 'vite';
4+
5+
export default mergeConfig(baseConfig, defineConfig({}));

vite.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import swc from 'unplugin-swc';
55

66
// https://vitejs.dev/config/
77
export default defineConfig({
8-
publicDir: 'app/public',
98
plugins: [
109
dts({
1110
include: ['src/**/*'],

0 commit comments

Comments
 (0)