diff --git a/package-lock.json b/package-lock.json index 18fa0d801cdfcace8b9964d79beaedeec00b9e80..99351af606c3818005445dc42f9b0f19491f483b 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 a58340e32809a97496192d2d8537c57b323dae47..3984463d5b0f0f2166b48c5b3235959b56563dd5 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 ab1fe3e4a633d9e2462e11fc30e7cd251fc5aba0..b120d0840530a30fd19cde008fc1cdefdcb01df1 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 0235686b3a1034cc7c2bcbb24261957b11f9d275..39ae66c9a36e39c235c18f5a3e6f607d681a5da5 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 7d7e04e1498149c8cb8f010fad950b5a3630d970..0000000000000000000000000000000000000000 --- 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 dc36df69e05de3111e85edd963b587feea8d51bf..8a837f160e4af6a5ff21e7c462fed0fc0cfe86ff 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 a8af42690250cdd89b9f41e4de5e8c90b6583a94..645232154e9bb3566366d9aa4f40e684287fe627 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 17bfe7b2f32b15227686f4782d082ab097910203..b830c266327f6d38aeb16de3292704d8d057d966 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": [] }