diff --git a/package.json b/package.json index e82062ae8eb..5422b022ee1 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "changelog": "lerna-changelog", "prebuild:prod": "npm run clean", "build:prod": "gulp build", + "build:multi": "npx tsup --dts --sourcemap --format esm,cjs", "build:samples": "gulp install:samples && npm run build && gulp build:samples && gulp test:samples && gulp test:e2e:samples", "clean": "gulp clean:bundle", "codechecks:benchmarks": "codechecks ./tools/benchmarks/check-benchmarks.ts", @@ -162,6 +163,7 @@ "supertest": "6.2.2", "ts-morph": "13.0.3", "ts-node": "10.4.0", + "tsup": "^5.10.0", "typeorm": "0.2.41", "typescript": "4.3.5", "wrk": "1.2.1", diff --git a/packages/core/injector/module-token-factory.ts b/packages/core/injector/module-token-factory.ts index 65409ad0929..2bc284b0efb 100644 --- a/packages/core/injector/module-token-factory.ts +++ b/packages/core/injector/module-token-factory.ts @@ -3,7 +3,7 @@ import { Type } from '@nestjs/common/interfaces/type.interface'; import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util'; import { isFunction, isSymbol } from '@nestjs/common/utils/shared.utils'; import stringify from 'fast-safe-stringify'; -import * as hash from 'object-hash'; +import hash from 'object-hash'; export class ModuleTokenFactory { private readonly moduleIdsCache = new WeakMap, string>(); diff --git a/packages/core/middleware/utils.ts b/packages/core/middleware/utils.ts index 19418afc892..3016cd3c4b7 100644 --- a/packages/core/middleware/utils.ts +++ b/packages/core/middleware/utils.ts @@ -2,7 +2,7 @@ import { RequestMethod } from '@nestjs/common'; import { HttpServer, RouteInfo, Type } from '@nestjs/common/interfaces'; import { isFunction } from '@nestjs/common/utils/shared.utils'; import { iterate } from 'iterare'; -import * as pathToRegexp from 'path-to-regexp'; +import pathToRegexp from 'path-to-regexp'; import { v4 as uuid } from 'uuid'; import { ExcludeRouteMetadata } from '../router/interfaces/exclude-route-metadata.interface'; import { isRouteExcluded } from '../router/utils'; diff --git a/packages/core/nest-application.ts b/packages/core/nest-application.ts index 0ecc357cdb4..cf3b767e849 100644 --- a/packages/core/nest-application.ts +++ b/packages/core/nest-application.ts @@ -29,7 +29,7 @@ import { } from '@nestjs/common/utils/shared.utils'; import { iterate } from 'iterare'; import { platform } from 'os'; -import * as pathToRegexp from 'path-to-regexp'; +import pathToRegexp from 'path-to-regexp'; import { AbstractHttpAdapter } from './adapters'; import { ApplicationConfig } from './application-config'; import { MESSAGES } from './constants'; diff --git a/packages/core/router/router-explorer.ts b/packages/core/router/router-explorer.ts index 153bf29b40a..ea967eea422 100644 --- a/packages/core/router/router-explorer.ts +++ b/packages/core/router/router-explorer.ts @@ -19,7 +19,7 @@ import { isString, isUndefined, } from '@nestjs/common/utils/shared.utils'; -import * as pathToRegexp from 'path-to-regexp'; +import pathToRegexp from 'path-to-regexp'; import { ApplicationConfig } from '../application-config'; import { UnknownRequestMappingException } from '../errors/exceptions/unknown-request-mapping.exception'; import { GuardsConsumer } from '../guards/guards-consumer'; diff --git a/packages/microservices/client/client-tcp.ts b/packages/microservices/client/client-tcp.ts index f16c6407c2c..5c0f44ae7eb 100644 --- a/packages/microservices/client/client-tcp.ts +++ b/packages/microservices/client/client-tcp.ts @@ -1,5 +1,5 @@ import { Logger } from '@nestjs/common'; -import * as net from 'net'; +import net from 'net'; import { EmptyError, lastValueFrom } from 'rxjs'; import { share, tap } from 'rxjs/operators'; import { diff --git a/packages/microservices/external/kafka.interface.ts b/packages/microservices/external/kafka.interface.ts index ea7a29a4c56..4ac8bee868a 100644 --- a/packages/microservices/external/kafka.interface.ts +++ b/packages/microservices/external/kafka.interface.ts @@ -6,8 +6,8 @@ /// -import * as net from 'net'; -import * as tls from 'tls'; +import net from 'net'; +import tls from 'tls'; type Without = { [P in Exclude]?: never }; type XOR = T | U extends object diff --git a/packages/microservices/server/server-tcp.ts b/packages/microservices/server/server-tcp.ts index 067a3b19afa..5c4adbce175 100644 --- a/packages/microservices/server/server-tcp.ts +++ b/packages/microservices/server/server-tcp.ts @@ -1,6 +1,5 @@ import { isString, isUndefined } from '@nestjs/common/utils/shared.utils'; -import * as net from 'net'; -import { Server as NetSocket, Socket } from 'net'; +import net, { Server as NetSocket, Socket } from 'net'; import { Observable } from 'rxjs'; import { CLOSE_EVENT, diff --git a/packages/platform-express/adapters/express-adapter.ts b/packages/platform-express/adapters/express-adapter.ts index afe1b782e0e..92491b123f4 100644 --- a/packages/platform-express/adapters/express-adapter.ts +++ b/packages/platform-express/adapters/express-adapter.ts @@ -2,34 +2,34 @@ import { InternalServerErrorException, RequestMethod, StreamableFile, - VersioningType, + VersioningType } from '@nestjs/common'; import { VersioningOptions, VersionValue, - VERSION_NEUTRAL, + VERSION_NEUTRAL } from '@nestjs/common/interfaces'; import { CorsOptions, - CorsOptionsDelegate, + CorsOptionsDelegate } from '@nestjs/common/interfaces/external/cors-options.interface'; import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface'; import { isFunction, isNil, isObject, - isString, + isString } from '@nestjs/common/utils/shared.utils'; import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter'; import { RouterMethodFactory } from '@nestjs/core/helpers/router-method-factory'; import { json as bodyParserJson, - urlencoded as bodyParserUrlencoded, + urlencoded as bodyParserUrlencoded } from 'body-parser'; -import * as cors from 'cors'; -import * as express from 'express'; -import * as http from 'http'; -import * as https from 'https'; +import cors from 'cors'; +import express from 'express'; +import http from 'http'; +import https from 'https'; import { ServeStaticOptions } from '../interfaces/serve-static-options.interface'; export class ExpressAdapter extends AbstractHttpAdapter { diff --git a/packages/platform-express/multer/interceptors/any-files.interceptor.ts b/packages/platform-express/multer/interceptors/any-files.interceptor.ts index afa8a000373..93baa163fb9 100644 --- a/packages/platform-express/multer/interceptors/any-files.interceptor.ts +++ b/packages/platform-express/multer/interceptors/any-files.interceptor.ts @@ -7,7 +7,7 @@ import { Optional, Type, } from '@nestjs/common'; -import * as multer from 'multer'; +import multer from 'multer'; import { Observable } from 'rxjs'; import { MULTER_MODULE_OPTIONS } from '../files.constants'; import { MulterModuleOptions } from '../interfaces'; diff --git a/packages/platform-express/multer/interceptors/file-fields.interceptor.ts b/packages/platform-express/multer/interceptors/file-fields.interceptor.ts index 154981a9b0e..22891620fb6 100644 --- a/packages/platform-express/multer/interceptors/file-fields.interceptor.ts +++ b/packages/platform-express/multer/interceptors/file-fields.interceptor.ts @@ -7,7 +7,7 @@ import { Optional, Type, } from '@nestjs/common'; -import * as multer from 'multer'; +import multer from 'multer'; import { Observable } from 'rxjs'; import { MULTER_MODULE_OPTIONS } from '../files.constants'; import { MulterModuleOptions } from '../interfaces'; diff --git a/packages/platform-express/multer/interceptors/file.interceptor.ts b/packages/platform-express/multer/interceptors/file.interceptor.ts index a1fd82b6ac8..8eb731ac10a 100644 --- a/packages/platform-express/multer/interceptors/file.interceptor.ts +++ b/packages/platform-express/multer/interceptors/file.interceptor.ts @@ -7,7 +7,7 @@ import { Optional, Type, } from '@nestjs/common'; -import * as multer from 'multer'; +import multer from 'multer'; import { Observable } from 'rxjs'; import { MULTER_MODULE_OPTIONS } from '../files.constants'; import { MulterModuleOptions } from '../interfaces'; diff --git a/packages/platform-express/multer/interceptors/files.interceptor.ts b/packages/platform-express/multer/interceptors/files.interceptor.ts index 83705333dc7..7f205cacd31 100644 --- a/packages/platform-express/multer/interceptors/files.interceptor.ts +++ b/packages/platform-express/multer/interceptors/files.interceptor.ts @@ -7,7 +7,7 @@ import { Optional, Type, } from '@nestjs/common'; -import * as multer from 'multer'; +import multer from 'multer'; import { Observable } from 'rxjs'; import { MULTER_MODULE_OPTIONS } from '../files.constants'; import { MulterModuleOptions } from '../interfaces'; diff --git a/packages/platform-fastify/adapters/fastify-adapter.ts b/packages/platform-fastify/adapters/fastify-adapter.ts index 6c15826ea66..5137c9c394b 100644 --- a/packages/platform-fastify/adapters/fastify-adapter.ts +++ b/packages/platform-fastify/adapters/fastify-adapter.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ import { HttpStatus, Logger, @@ -29,10 +30,10 @@ import { RawServerDefault, RequestGenericInterface, } from 'fastify'; -import * as Reply from 'fastify/lib/reply'; +import Reply from 'fastify/lib/reply'; import { RouteShorthandMethod } from 'fastify/types/route'; -import * as http2 from 'http2'; -import * as https from 'https'; +import http2 from 'http2'; +import https from 'https'; import { Chain as LightMyRequestChain, InjectOptions, @@ -100,6 +101,7 @@ export class FastifyAdapter< TRawResponse > = FastifyInstance, > extends AbstractHttpAdapter { + // @ts-ignore protected readonly instance: TInstance; private _isParserRegistered: boolean; @@ -195,6 +197,7 @@ export class FastifyAdapter< }, ...(instanceOrOptions as FastifyServerOptions), }); + // @ts-ignore this.setInstance(instance); } @@ -350,6 +353,7 @@ export class FastifyAdapter< return await this.instance.close(); } catch (err) { // Check if server is still running + // @ts-ignore if (err.code !== 'ERR_SERVER_NOT_RUNNING') { throw err; } @@ -358,6 +362,7 @@ export class FastifyAdapter< } public initHttpServer() { + // @ts-ignore this.httpServer = this.instance.server; } diff --git a/packages/platform-ws/adapters/ws-adapter.ts b/packages/platform-ws/adapters/ws-adapter.ts index 973bce7b90d..cccc9772df6 100644 --- a/packages/platform-ws/adapters/ws-adapter.ts +++ b/packages/platform-ws/adapters/ws-adapter.ts @@ -4,12 +4,13 @@ import { AbstractWsAdapter } from '@nestjs/websockets'; import { CLOSE_EVENT, CONNECTION_EVENT, - ERROR_EVENT, + ERROR_EVENT } from '@nestjs/websockets/constants'; import { MessageMappingProperties } from '@nestjs/websockets/gateway-metadata-explorer'; -import * as http from 'http'; -import { EMPTY, fromEvent, Observable } from 'rxjs'; +import http from 'http'; +import { fromEvent, Observable } from 'rxjs'; import { filter, first, mergeMap, share, takeUntil } from 'rxjs/operators'; +import { URL } from 'url'; let wsPackage: any = {}; diff --git a/packages/tsconfig.base.json b/packages/tsconfig.base.json index ff837eb4f25..94461c9c315 100644 --- a/packages/tsconfig.base.json +++ b/packages/tsconfig.base.json @@ -16,6 +16,7 @@ "allowJs": false, "strict": true, "strictNullChecks": false, + "esModuleInterop": true, "types": ["node"] }, "exclude": ["../node_modules", "./**/*.spec.ts"] diff --git a/packages/websockets/sockets-container.ts b/packages/websockets/sockets-container.ts index 1090150e823..be38009dd94 100644 --- a/packages/websockets/sockets-container.ts +++ b/packages/websockets/sockets-container.ts @@ -1,4 +1,4 @@ -import * as hash from 'object-hash'; +import hash from 'object-hash'; import { GatewayMetadata, ServerAndEventStreamsHost } from './interfaces'; export class SocketsContainer { diff --git a/tsconfig.json b/tsconfig.json index 036b1a81438..0857dd2d1ee 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,7 @@ "allowJs": true, "outDir": "dist", "lib": ["es7"], + "esModuleInterop": true, "paths": { "@nestjs/common": ["./packages/common"], "@nestjs/common/*": ["./packages/common/*"], diff --git a/tsup.config.ts b/tsup.config.ts new file mode 100644 index 00000000000..fee472b87f2 --- /dev/null +++ b/tsup.config.ts @@ -0,0 +1,19 @@ +import { defineConfig } from 'tsup'; + +export default defineConfig({ + splitting: false, + sourcemap: true, + outDir: 'node_modules/@nestjs', + clean: true, + entryPoints: [ + 'packages/common/index.ts', + 'packages/core/index.ts', + 'packages/microservices/index.ts', + 'packages/platform-express/index.ts', + 'packages/platform-fastify/index.ts', + 'packages/platform-socket.io/index.ts', + 'packages/platform-ws/index.ts', + 'packages/testing/index.ts', + 'packages/websockets/index.ts' + ], +});