From fe49723139782df8f35d163a21a048c86a680288 Mon Sep 17 00:00:00 2001 From: Perreal Guillaume <guillaume.perreal@irstea.fr> Date: Mon, 14 Oct 2019 13:24:43 +0200 Subject: [PATCH] Tentative de configuration DebugModule.forRoot(). --- package-lock.json | 15 ++++++++------- package.json | 3 +++ src/index.ts | 8 ++++++-- src/lib/api/api-debug.component.ts | 18 +++++++++++++----- src/lib/api/index.ts | 2 -- src/lib/debug.module.ts | 29 +++++++++++++++++++++++++---- tsconfig.lib.json | 2 +- tsconfig.spec.json | 1 - 8 files changed, 56 insertions(+), 22 deletions(-) delete mode 100644 src/lib/api/index.ts diff --git a/package-lock.json b/package-lock.json index 18fa0d8..99351af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2003,6 +2003,7 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/@devatscience/ngx-rxtools/-/ngx-rxtools-1.1.0.tgz", "integrity": "sha512-UCIavkf2dYoeScSiYk3iBRkXPnqL2FJ5WlVZepOehaUgy7RPLIomWMh0wLGLYHTFLlvy1v3V1FLyDmS8GDOz2w==", + "dev": true, "requires": { "tslib": "^1.9.0" } @@ -6001,9 +6002,9 @@ "dev": true }, "handlebars": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.2.0.tgz", - "integrity": "sha512-Kb4xn5Qh1cxAKvQnzNWZ512DhABzyFNmsaJf3OAkWNa4NkaqWcNI8Tao8Tasi0/F4JD9oyG0YxuFyvyR57d+Gw==", + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.3.tgz", + "integrity": "sha512-B0W4A2U1ww3q7VVthTKfh+epHx+q4mCt6iK+zEAzbMBpWQAwxCeKxEGpj/1oQTpzPXDNSOG7hmG14TsISH50yw==", "dev": true, "requires": { "neo-async": "^2.6.0", @@ -12204,13 +12205,13 @@ "dev": true }, "uglify-js": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", - "integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==", + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.1.tgz", + "integrity": "sha512-+dSJLJpXBb6oMHP+Yvw8hUgElz4gLTh82XuX68QiJVTXaE5ibl6buzhNkQdYhBlIhozWOC9ge16wyRmjG4TwVQ==", "dev": true, "optional": true, "requires": { - "commander": "~2.20.0", + "commander": "2.20.0", "source-map": "~0.6.1" }, "dependencies": { diff --git a/package.json b/package.json index a58340e..3984463 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,9 @@ "type": "git", "url": "https://gitlab.irstea.fr/pole-is/packages/ngx-debug.git" }, + "dependencies": { + "tslib": "^1.10.0" + }, "peerDependencies": { "@angular/common": "^8", "@angular/core": "^8", diff --git a/src/index.ts b/src/index.ts index ab1fe3e..b120d08 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,8 +2,12 @@ * Public API Surface of ngx-debug */ -export * from './lib/debug.module'; -export * from './lib/spy/spy.operator'; export * from './lib/api/api-debug.interceptor'; export * from './lib/api/api-debug.component'; +export * from './lib/debug.module'; +export * from './lib/dump-value.component'; +export * from './lib/watch/watch.component'; export * from './lib/watch/watch.service'; +export * from './lib/debug-toggle.component'; +export * from './lib/debug-state.service'; +export * from './lib/spy/spy.operator'; diff --git a/src/lib/api/api-debug.component.ts b/src/lib/api/api-debug.component.ts index 0235686..39ae66c 100644 --- a/src/lib/api/api-debug.component.ts +++ b/src/lib/api/api-debug.component.ts @@ -1,5 +1,13 @@ import { HttpRequest, HttpResponseBase } from '@angular/common/http'; -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Inject, InjectionToken, Output } from '@angular/core'; +import { + ChangeDetectionStrategy, + ChangeDetectorRef, + Component, + EventEmitter, + Inject, + InjectionToken, + Output, +} from '@angular/core'; import { DebugStateService } from '../debug-state.service'; @@ -38,7 +46,7 @@ export class ApiDebugComponent { interceptor: ApiDebugInterceptor, public readonly debug: DebugStateService, private readonly cd: ChangeDetectorRef, - @Inject(ApiBaseUrlToken) private readonly apiPrefix: string, + @Inject(ApiBaseUrlToken) private readonly apiPrefix: string ) { interceptor.events$.subscribe(ev => { this.handle(ev); @@ -78,7 +86,7 @@ export class ApiDebugComponent { private addRequest( id: string, - { urlWithParams, method }: HttpRequest<any>, + { urlWithParams, method }: HttpRequest<any> ): void { if (urlWithParams.startsWith(this.apiPrefix)) { urlWithParams = new URL(urlWithParams).pathname; @@ -96,7 +104,7 @@ export class ApiDebugComponent { private setResponse( request: RequestInfo, - { status, statusText, headers }: HttpResponseBase, + { status, statusText, headers }: HttpResponseBase ): void { request.response = { status, @@ -124,7 +132,7 @@ export class ApiDebugComponent { } public get last(): RequestInfo | null { - return this.ids.length ? this.requests.get(this.ids[ 0 ]) : null; + return this.ids.length ? this.requests.get(this.ids[0]) : null; } public get previous(): RequestInfo[] { diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts deleted file mode 100644 index 7d7e04e..0000000 --- a/src/lib/api/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './api-debug.component'; -export * from './api-debug.interceptor'; diff --git a/src/lib/debug.module.ts b/src/lib/debug.module.ts index dc36df6..8a837f1 100644 --- a/src/lib/debug.module.ts +++ b/src/lib/debug.module.ts @@ -1,5 +1,6 @@ import { CommonModule } from '@angular/common'; -import { LOCALE_ID, NgModule } from '@angular/core'; +import { HTTP_INTERCEPTORS } from '@angular/common/http'; +import { LOCALE_ID, ModuleWithProviders, NgModule } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { ButtonModule, @@ -14,8 +15,9 @@ import { import { TreeModule } from 'primeng/tree'; import { TreeTableModule } from 'primeng/treetable'; -import { ApiDebugComponent } from './api'; -import { DebugStateService } from './debug-state.service'; +import { ApiBaseUrlToken, ApiDebugComponent } from './api/api-debug.component'; +import { ApiDebugInterceptor } from './api/api-debug.interceptor'; +import { DebugStateService, ProductionToken } from './debug-state.service'; import { DebugToggleComponent } from './debug-toggle.component'; import { DumpPanelComponent } from './dump-panel.component'; import { DumpValueComponent } from './dump-value.component'; @@ -61,4 +63,23 @@ const EXPORTED_COMPONENTS = [ ], exports: [...EXPORTED_COMPONENTS], }) -export class DebugModule {} +export class DebugModule { + public static forRoot( + apiBaseUrl: string, + production: boolean + ): ModuleWithProviders { + // TODO: fournir un module différent en prod (+ léger) et en dev (complet) + return { + ngModule: DebugModule, + providers: [ + { provide: ProductionToken, useValue: production }, + { provide: ApiBaseUrlToken, useValue: apiBaseUrl }, + { + provide: HTTP_INTERCEPTORS, + useClass: ApiDebugInterceptor, + multi: true, + }, + ], + }; + } +} diff --git a/tsconfig.lib.json b/tsconfig.lib.json index a8af426..6452321 100644 --- a/tsconfig.lib.json +++ b/tsconfig.lib.json @@ -20,6 +20,6 @@ "strictInjectionParameters": true, "enableResourceInlining": true }, - "files": ["src/**/*.ts"], + "include": ["src/**/*.ts"], "exclude": ["src/test.ts", "**/*.spec.ts"] } diff --git a/tsconfig.spec.json b/tsconfig.spec.json index 17bfe7b..b830c26 100644 --- a/tsconfig.spec.json +++ b/tsconfig.spec.json @@ -4,6 +4,5 @@ "outDir": "out-tsc/spec", "types": ["jasmine", "node"] }, - "files": ["src/test.ts"], "exclude": [] } -- GitLab