Skip to content

Commit

Permalink
dynamic import of platformsh-client plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
zeshanziya committed Sep 24, 2024
1 parent 0f273dc commit 56f562c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions plugins/platformsh-backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion plugins/platformsh-backend/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -67,6 +67,9 @@
"msw": "^2.3.1",
"supertest": "^6.2.4"
},
"bundleDependencies": [
"platformsh-client"
],
"files": [
"dist",
"config.d.ts"
Expand Down
8 changes: 7 additions & 1 deletion plugins/platformsh-backend/src/PlatformshHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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',
Expand Down

0 comments on commit 56f562c

Please sign in to comment.