Kaynağa Gözat

feat(core): Expose additional bootstrap options (#2568)

This allows eg support for NestJS devtools
Alexis Vigoureux 2 yıl önce
ebeveyn
işleme
3b6d6abc73

+ 1 - 0
packages/core/package.json

@@ -44,6 +44,7 @@
         "@nestjs/apollo": "^12.0.7",
         "@nestjs/common": "10.2.1",
         "@nestjs/core": "10.2.1",
+        "@nestjs/devtools-integration": "0.1.5",
         "@nestjs/graphql": "12.0.8",
         "@nestjs/platform-express": "10.2.1",
         "@nestjs/terminus": "10.0.1",

+ 5 - 0
packages/core/src/app.module.ts

@@ -12,6 +12,7 @@ import { I18nService } from './i18n/i18n.service';
 import { PluginModule } from './plugin/plugin.module';
 import { ProcessContextModule } from './process-context/process-context.module';
 import { ServiceModule } from './service/service.module';
+import { DevtoolsModule } from "@nestjs/devtools-integration";
 
 @Module({
     imports: [
@@ -23,6 +24,10 @@ import { ServiceModule } from './service/service.module';
         HealthCheckModule,
         ServiceModule,
         ConnectionModule,
+        DevtoolsModule.register({
+            port: process.env.DEVTOOLS_PORT ? +process.env.DEVTOOLS_PORT : 8000,
+            http: process.env.NODE_ENV !== 'production' && process.env.ENABLE_DEVTOOLS === 'true',
+        }),
     ],
 })
 export class AppModule implements NestModule, OnApplicationShutdown {

+ 14 - 2
packages/core/src/bootstrap.ts

@@ -24,9 +24,19 @@ import { getPluginStartupMessages } from './plugin/plugin-utils';
 import { setProcessContext } from './process-context/process-context';
 import { VENDURE_VERSION } from './version';
 import { VendureWorker } from './worker/vendure-worker';
+import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
+import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
 
 export type VendureBootstrapFunction = (config: VendureConfig) => Promise<INestApplication>;
 
+export interface BootstrapOptions {
+    nestApplicationOptions: NestApplicationOptions;
+}
+
+export interface BootstrapWorkerOptions {
+    nestApplicationContextOptions: NestApplicationContextOptions
+}
+
 /**
  * @description
  * Bootstraps the Vendure server. This is the entry point to the application.
@@ -42,7 +52,7 @@ export type VendureBootstrapFunction = (config: VendureConfig) => Promise<INestA
  * ```
  * @docsCategory common
  * */
-export async function bootstrap(userConfig: Partial<VendureConfig>): Promise<INestApplication> {
+export async function bootstrap(userConfig: Partial<VendureConfig>, options?: BootstrapOptions): Promise<INestApplication> {
     const config = await preBootstrapConfig(userConfig);
     Logger.useLogger(config.logger);
     Logger.info(`Bootstrapping Vendure Server (pid: ${process.pid})...`);
@@ -58,6 +68,7 @@ export async function bootstrap(userConfig: Partial<VendureConfig>): Promise<INe
     const app = await NestFactory.create(appModule.AppModule, {
         cors,
         logger: new Logger(),
+        ...options?.nestApplicationOptions
     });
     DefaultLogger.restoreOriginalLogLevel();
     app.useLogger(new Logger());
@@ -99,7 +110,7 @@ export async function bootstrap(userConfig: Partial<VendureConfig>): Promise<INe
  * ```
  * @docsCategory worker
  * */
-export async function bootstrapWorker(userConfig: Partial<VendureConfig>): Promise<VendureWorker> {
+export async function bootstrapWorker(userConfig: Partial<VendureConfig>, options?: BootstrapWorkerOptions): Promise<VendureWorker> {
     const vendureConfig = await preBootstrapConfig(userConfig);
     const config = disableSynchronize(vendureConfig);
     config.logger.setDefaultContext?.('Vendure Worker');
@@ -113,6 +124,7 @@ export async function bootstrapWorker(userConfig: Partial<VendureConfig>): Promi
     const WorkerModule = await import('./worker/worker.module.js').then(m => m.WorkerModule);
     const workerApp = await NestFactory.createApplicationContext(WorkerModule, {
         logger: new Logger(),
+        ...options?.nestApplicationContextOptions
     });
     DefaultLogger.restoreOriginalLogLevel();
     workerApp.useLogger(new Logger());

+ 9 - 1
yarn.lock

@@ -3708,6 +3708,14 @@
     path-to-regexp "3.2.0"
     tslib "2.6.1"
 
+"@nestjs/devtools-integration@0.1.5":
+  version "0.1.5"
+  resolved "https://registry.yarnpkg.com/@nestjs/devtools-integration/-/devtools-integration-0.1.5.tgz#373aebe93632dd0f1bc46b714c6720951f35f87b"
+  integrity sha512-iwxvfxa3kzOulG/Fje82Ww80OVsA8rzYR+UAEKrdGExRRGQRGQ0+bHfG0XLlPG3XIuM5J2MRMo7x1bN8ZIs9Gg==
+  dependencies:
+    chalk "^4.1.2"
+    node-fetch "^2.6.9"
+
 "@nestjs/graphql@12.0.8":
   version "12.0.8"
   resolved "https://registry.yarnpkg.com/@nestjs/graphql/-/graphql-12.0.8.tgz#15143b76dfb5fa4dc880d68a1bf2f7159ea077b6"
@@ -14102,7 +14110,7 @@ node-fetch@2.6.7:
   dependencies:
     whatwg-url "^5.0.0"
 
-node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.12, node-fetch@^2.6.7, node-fetch@^2.7.0:
+node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.12, node-fetch@^2.6.7, node-fetch@^2.6.9, node-fetch@^2.7.0:
   version "2.7.0"
   resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
   integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==