From 087727d42ce9f4df81c80dd5676f28b13e46740e Mon Sep 17 00:00:00 2001 From: ashevchuk-ecw Date: Mon, 4 Mar 2024 13:03:13 +0200 Subject: [PATCH] Publish st-client-lib and reuse as dependency --- angular.json | 4 ++++ package-lock.json | 23 +++++++++++++++---- package.json | 4 +++- projects/st-client-lib/package.json | 2 +- .../src/lib/st-client-lib.service.ts | 13 +++++------ projects/st-client-lib/tsconfig.lib.json | 4 +++- src/app/app.component.ts | 3 ++- src/app/statsig.service.ts | 9 ++++---- tsconfig.json | 11 ++++----- 9 files changed, 48 insertions(+), 25 deletions(-) diff --git a/angular.json b/angular.json index 9828b99..6ee323a 100644 --- a/angular.json +++ b/angular.json @@ -23,6 +23,10 @@ "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.app.json", "inlineStyleLanguage": "scss", + "allowedCommonJsDependencies": [ + "statsig", + "statsig-js" + ], "assets": [ "src/favicon.ico", "src/assets" diff --git a/package-lock.json b/package-lock.json index 73ce8cf..ce2d590 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "statsig-client", "version": "0.0.0", + "hasInstallScript": true, "dependencies": { "@angular/animations": "^14.2.0", "@angular/common": "^14.2.0", @@ -17,7 +18,8 @@ "@angular/platform-browser-dynamic": "^14.2.0", "@angular/router": "^14.2.0", "rxjs": "~7.5.0", - "statsig-js": "^4.49.0", + "st-client-lib": "0.0.3", + "statsig-js": "^4.48.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" }, @@ -13301,6 +13303,19 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/st-client-lib": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/st-client-lib/-/st-client-lib-0.0.3.tgz", + "integrity": "sha512-ZDsBO4NizvTmAmSBOPG52iO4VEcXp6uymSBBQU3EveCfO3qC3sZuuVM1yMkxiAas8K7RhhB0RTQsToWnDWviJw==", + "dependencies": { + "tslib": "^2.3.0" + }, + "peerDependencies": { + "@angular/common": "^14.2.0", + "@angular/core": "^14.2.0", + "statsig-js": "4.48.0" + } + }, "node_modules/stack-utils": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.6.tgz", @@ -13323,9 +13338,9 @@ } }, "node_modules/statsig-js": { - "version": "4.49.0", - "resolved": "https://registry.npmjs.org/statsig-js/-/statsig-js-4.49.0.tgz", - "integrity": "sha512-N4drx6fzI168Q4NndFY3IJbSDqpWSBWvS290H/RnT/g3Et58SvtXzG5qqgzmqy4CwcmwH+IL8K15pL7hPnfvUQ==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/statsig-js/-/statsig-js-4.48.0.tgz", + "integrity": "sha512-kh6vZ+0C7yGaBmoxt7T4jzWpW8rq+ut6CxMhxAXLS8tqOLTb9FOxbB+7kiyFhYv+8c8ll1BrLxFiB2hTOBauNw==", "dependencies": { "js-sha256": "^0.11.0", "uuid": "^8.3.2" diff --git a/package.json b/package.json index e031d69..b1abc5f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.0.0", "scripts": { "ng": "ng", + "postinstall": "ngcc --properties es2020 browser module main", "start": "ng serve", "build": "ng build st-client-lib && ng build", "watch": "ng build --watch --configuration development", @@ -19,7 +20,8 @@ "@angular/platform-browser-dynamic": "^14.2.0", "@angular/router": "^14.2.0", "rxjs": "~7.5.0", - "statsig-js": "^4.49.0", + "st-client-lib": "0.0.3", + "statsig-js": "^4.48.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" }, diff --git a/projects/st-client-lib/package.json b/projects/st-client-lib/package.json index 7f7227f..197557f 100644 --- a/projects/st-client-lib/package.json +++ b/projects/st-client-lib/package.json @@ -1,6 +1,6 @@ { "name": "st-client-lib", - "version": "0.0.1", + "version": "0.0.3", "peerDependencies": { "@angular/common": "^14.2.0", "@angular/core": "^14.2.0", diff --git a/projects/st-client-lib/src/lib/st-client-lib.service.ts b/projects/st-client-lib/src/lib/st-client-lib.service.ts index b879b02..f0bbcdf 100644 --- a/projects/st-client-lib/src/lib/st-client-lib.service.ts +++ b/projects/st-client-lib/src/lib/st-client-lib.service.ts @@ -1,15 +1,14 @@ import { Injectable } from '@angular/core'; -import Statsig, { DynamicConfig } from 'statsig-js'; +import { DynamicConfig } from 'statsig-js'; +import * as StatsigRoot from 'statsig-js' @Injectable({ providedIn: 'root' }) export class StClientLibService { - constructor() { } - - public async statsigInit(key: string): Promise { - Statsig.initialize( + public async statsigInit(key: string): Promise { + StatsigRoot.default.initialize( key, { appVersion: '42', @@ -26,10 +25,10 @@ export class StClientLibService { } public isFeatureEnabled(key: string): boolean { - return Statsig.checkGate(key); + return StatsigRoot.default.checkGate(key); } public getExperiment(experimentName: string): DynamicConfig { - return Statsig.getExperiment(experimentName);; + return StatsigRoot.default.getExperiment(experimentName);; } } diff --git a/projects/st-client-lib/tsconfig.lib.json b/projects/st-client-lib/tsconfig.lib.json index b77b13c..ea5b059 100644 --- a/projects/st-client-lib/tsconfig.lib.json +++ b/projects/st-client-lib/tsconfig.lib.json @@ -6,10 +6,12 @@ "declaration": true, "declarationMap": true, "inlineSources": true, + "allowSyntheticDefaultImports": true, "types": [] }, "exclude": [ "src/test.ts", "**/*.spec.ts" - ] + ], + "include": ["**/*.ts"] } diff --git a/src/app/app.component.ts b/src/app/app.component.ts index bf88e55..84bd14a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -2,6 +2,7 @@ import { Component } from '@angular/core'; import { StService } from './statsig.service'; import { StClientLibService } from 'st-client-lib'; + @Component({ selector: 'app-root', templateUrl: './app.component.html', @@ -22,7 +23,7 @@ export class AppComponent { } public async initDepsStatsig() { - await this.depsStatsigService.statsigInit(''); + await this.depsStatsigService.statsigInit('client-C1rOhOyc5O1TqQIpY3MCp5wCtjfxlXMsUvQSTnKqPi4'); } public getDepsExperiment(experimentName: string) { diff --git a/src/app/statsig.service.ts b/src/app/statsig.service.ts index 65653a4..ddea13b 100644 --- a/src/app/statsig.service.ts +++ b/src/app/statsig.service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core'; -import Statsig, { DynamicConfig } from 'statsig-js'; +import * as Statsig from 'statsig-js'; +import { DynamicConfig } from 'statsig-js'; @Injectable({ providedIn: 'root' @@ -9,7 +10,7 @@ export class StService { constructor() { } public async statsigInit(): Promise { - Statsig.initialize( + Statsig.default.initialize( 'client-C1rOhOyc5O1TqQIpY3MCp5wCtjfxlXMsUvQSTnKqPi4', { appVersion: '42', @@ -26,10 +27,10 @@ export class StService { } public isFeatureEnabled(key: string): boolean { - return Statsig.checkGate(key); + return Statsig.default.checkGate(key); } public getExperiment(experimentName: string): DynamicConfig { - return Statsig.getExperiment(experimentName);; + return Statsig.default.getExperiment(experimentName);; } } diff --git a/tsconfig.json b/tsconfig.json index bb6fa23..f4af9a9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,15 +14,14 @@ "declaration": false, "downlevelIteration": true, "experimentalDecorators": true, + "emitDecoratorMetadata": true, "moduleResolution": "node", "importHelpers": true, "target": "es2020", - "paths": { - "st-client-lib": [ - "dist/st-client-lib" - ] - }, - "module": "es2020", + "skipLibCheck": true, + "skipDefaultLibCheck": true, + "allowSyntheticDefaultImports": true, + "module": "esnext", "lib": [ "es2020", "dom"