From 56f562ce26b4f725a168e2ac5e50b48e5ceef8c6 Mon Sep 17 00:00:00 2001 From: zeshanziya Date: Tue, 24 Sep 2024 10:54:19 +0000 Subject: [PATCH] dynamic import of platformsh-client plugin --- packages/backend/package.json | 2 +- plugins/platformsh-backend/CHANGELOG.md | 12 ++++++++++++ plugins/platformsh-backend/package.json | 5 ++++- plugins/platformsh-backend/src/PlatformshHelper.ts | 8 +++++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/backend/package.json b/packages/backend/package.json index 65730d4..cc152fe 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -43,7 +43,7 @@ "@backstage/plugin-search-backend-module-techdocs": "^0.2.0", "@backstage/plugin-search-backend-node": "^1.3.0", "@backstage/plugin-techdocs-backend": "^1.10.10", - "@axelerant/backstage-plugin-platformsh-backend": "^0.1.1", + "@axelerant/backstage-plugin-platformsh-backend": "^0.1.3", "@axelerant/backstage-plugin-platformsh-common": "^0.1.0", "app": "link:../app", "better-sqlite3": "^9.0.0", diff --git a/plugins/platformsh-backend/CHANGELOG.md b/plugins/platformsh-backend/CHANGELOG.md index 3675c23..584d645 100644 --- a/plugins/platformsh-backend/CHANGELOG.md +++ b/plugins/platformsh-backend/CHANGELOG.md @@ -1,5 +1,17 @@ # @axelerant/backstage-plugin-platformsh-backend +## 0.1.3 + +### Patch Changes + +- dynamic import of platformsh-client + +## 0.1.2 + +### Patch Changes + +- bundle platformsh-client package + ## 0.1.1 ### Patch Changes diff --git a/plugins/platformsh-backend/package.json b/plugins/platformsh-backend/package.json index 628f8eb..99cb7dd 100644 --- a/plugins/platformsh-backend/package.json +++ b/plugins/platformsh-backend/package.json @@ -1,6 +1,6 @@ { "name": "@axelerant/backstage-plugin-platformsh-backend", - "version": "0.1.1", + "version": "0.1.3", "description": "Backstage backend plugin for Platform.sh integration!", "main": "src/index.ts", "types": "src/index.ts", @@ -67,6 +67,9 @@ "msw": "^2.3.1", "supertest": "^6.2.4" }, + "bundleDependencies": [ + "platformsh-client" + ], "files": [ "dist", "config.d.ts" diff --git a/plugins/platformsh-backend/src/PlatformshHelper.ts b/plugins/platformsh-backend/src/PlatformshHelper.ts index bdd40b2..7be9453 100644 --- a/plugins/platformsh-backend/src/PlatformshHelper.ts +++ b/plugins/platformsh-backend/src/PlatformshHelper.ts @@ -2,7 +2,7 @@ import { LoggerService, RootConfigService, } from '@backstage/backend-plugin-api'; -import Client from 'platformsh-client'; +// import Client from 'platformsh-client'; import Activity from 'platformsh-client/types/model/Activity'; import Environment from 'platformsh-client/types/model/Environment'; import { @@ -31,6 +31,11 @@ export class PlatformshHelper { return currentTime >= this.tokenExpireTime; } + async loadPlatformshClient() { + const { default: Client } = await import('platformsh-client'); + return Client; + } + async getClient() { try { if (this.isTokenExpired()) { @@ -44,6 +49,7 @@ export class PlatformshHelper { } catch (error) { this.logger.error('Unable to get platformsh access token'); } + const Client = await this.loadPlatformshClient(); return new Client({ access_token: this.lastAccessToken.access_token, api_url: 'https://api.platform.sh/api',