Skip to content

Commit

Permalink
fix: build apps return an unexpected type error (#397)
Browse files Browse the repository at this point in the history
* perf: declare global vars in `shared/global`

* revert: remove `@ts-ignore` keyword
  • Loading branch information
wibus-wee authored Oct 1, 2022
1 parent 9d59cac commit 3607a0c
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 49 deletions.
17 changes: 8 additions & 9 deletions apps/core/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import PKG from "../../../package.json";
import PKG from '../../../package.json';
import { ApiOperation } from '@nestjs/swagger';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get(["/", "/info"])
@ApiOperation({ summary: "获取服务端版本等信息" })
@Get(['/', '/info'])
@ApiOperation({ summary: '获取服务端版本等信息' })
async appInfo() {
return {
name: PKG.name,
author: PKG.author,
// @ts-ignore
version: isDev ? "dev" : PKG.version,
version: isDev ? 'dev' : PKG.version,
homepage: PKG.homepage,
issues: PKG.issues,
};
}

@Get(["/ping"])
@ApiOperation({ summary: "测试接口是否存活" })
ping(): "pong" {
return "pong";
@Get(['/ping'])
@ApiOperation({ summary: '测试接口是否存活' })
ping(): 'pong' {
return 'pong';
}
}
14 changes: 5 additions & 9 deletions apps/core/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author: Wibus
* @Date: 2022-09-03 14:19:53
* @LastEditors: Wibus
* @LastEditTime: 2022-09-25 15:33:26
* @LastEditTime: 2022-10-01 20:02:53
* Coding With IU
*/

Expand Down Expand Up @@ -43,21 +43,18 @@ export async function bootstrap() {
whitelist: true, // 允许所有参数
errorHttpStatusCode: 422, // 返回422错误
forbidUnknownValues: true, // 禁止未知参数
// @ts-ignore

enableDebugMessages: isDev, // 开启调试模式
stopAtFirstError: true, // 在第一个错误后立即停止
}),
);

// @ts-ignore
!isDev && app.setGlobalPrefix(`api`);

// @ts-ignore
if (isDev) {
app.useGlobalInterceptors(new LoggingInterceptor());
}

// @ts-ignore
if (isDev) {
const { DocumentBuilder, SwaggerModule } = await import('@nestjs/swagger');
const options = new DocumentBuilder()
Expand All @@ -79,18 +76,17 @@ export async function bootstrap() {
Logger.error(err);
process.exit(1);
}
// @ts-ignore

consola.info('ENV:', process.env.NODE_ENV);
const url = await app.getUrl();
const pid = process.pid;

const prefix = 'P';
// @ts-ignore

if (isDev || argv.dev_online == 'true') {
// @ts-ignore
consola.debug(`[${prefix + pid}] OpenApi: ${url}/api-docs`);
}
// @ts-ignore

consola.success(`[${prefix + pid}] 服务器正在监听: ${url}`);
Logger.log(
`NxServer 已启动. ${chalk.yellow(`+${performance.now() | 0}ms`)}`,
Expand Down
22 changes: 0 additions & 22 deletions global.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions libs/database/src/database.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ export const databaseProvider = {
return str.map((s) => chalk.green(s)).join('');
};
mongoose.connection.on('connecting', () => {
// @ts-ignore
consola.info(Badge, color`connecting...`);
});

mongoose.connection.on('open', () => {
// @ts-ignore
consola.info(Badge, color`readied!`);
if (reconnectionTask) {
clearTimeout(reconnectionTask);
Expand All @@ -35,7 +33,6 @@ export const databaseProvider = {
});

mongoose.connection.on('disconnected', () => {
// @ts-ignore
consola.error(
Badge,
chalk.red(
Expand All @@ -46,7 +43,6 @@ export const databaseProvider = {
});

mongoose.connection.on('error', (error) => {
// @ts-ignore
consola.error(Badge, 'error!', error);
mongoose.disconnect();
});
Expand Down
2 changes: 0 additions & 2 deletions libs/helper/src/helper.jwt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class JWTService {
const getMachineId = () => {
const id = machineIdSync();

// @ts-ignore
if (isDev && cluster.isPrimary) {
console.log(id);
}
Expand All @@ -42,7 +41,6 @@ export class JWTService {
Buffer.from(getMachineId()).toString('base64').slice(0, 15) ||
'asjhczxiucipoiopiqm2376';

// @ts-ignore
if (isDev && cluster.isPrimary) {
console.log(secret);
}
Expand Down
1 change: 0 additions & 1 deletion shared/common/decorator/api-controller.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Controller, ControllerOptions } from '@nestjs/common';

// @ts-ignore
export const apiRoutePrefix = isDev ? '' : `/api`;
export const ApiController: (
optionOrString?: string | string[] | undefined | ControllerOptions,
Expand Down
1 change: 0 additions & 1 deletion shared/common/decorator/openapi.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ApiTags } from '@nestjs/swagger';

export const ApiName: ClassDecorator = (target) => {
// @ts-ignore
if (!isDev) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion shared/common/filters/any-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class AllExceptionsFilter implements ExceptionFilter {
`IP: ${ip} 错误信息: (${status}) ${message} Path: ${decodeURI(url)}`,
);
}
// @ts-ignore

const prevRequestTs = this.reflector.get(HTTP_REQUEST_TIME, request as any);

if (prevRequestTs) {
Expand Down
11 changes: 11 additions & 0 deletions shared/global/index.global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ import { consola, registerStdLogger } from './consola.global';
import './dayjs.global';
import { isDev } from './env.global';
import { join } from 'path';
import { Consola } from 'consola';
import { ModelType } from '@typegoose/typegoose/lib/types';
import { Document, PaginateModel } from 'mongoose';

declare global {
export const isDev: boolean;

export const consola: Consola;

export type MongooseModel<T> = ModelType<T> & PaginateModel<T & Document>;
}

function consoleMog() {
console.log(`
Expand Down

0 comments on commit 3607a0c

Please sign in to comment.