Skip to content

Commit

Permalink
fix: support dynamic version in url
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-pribilinskiy committed Jun 15, 2023
1 parent 56c4549 commit cbd0cd7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ export const DEFAULT_DIR_DOWNLOADED_TYPES = `src/@types/remotes`;

export const DEFAULT_DOWNLOAD_TYPES_INTERVAL_IN_SECONDS = 60;

export const CLOUDBEDS_DEV_FRONTEND_ASSETS_DOMAIN = 'https://cb-front.cloudbeds-dev.com';
export enum CloudbedsCloudfrontDomain {
Dev = 'https://cb-front.cloudbeds-dev.com',
Stage = 'https://cb-front.stage-ga.cloudbeds-dev.com',
Prod = 'https://front.cloudbeds.com',
}

/** @deprecated */
export const CLOUDBEDS_MFD_COMMON_MANIFEST_FILE_NAME = 'mfd-common-remote-entry.json';
export const CLOUDBEDS_REMOTES_MANIFEST_FILE_NAME = 'remote-entries.json';
Expand Down
11 changes: 8 additions & 3 deletions src/helpers/cloudbedsRemoteManifests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
CLOUDBEDS_DEV_FRONTEND_ASSETS_DOMAIN,
CloudbedsCloudfrontDomain,
CLOUDBEDS_MFD_COMMON_MANIFEST_FILE_NAME,
CLOUDBEDS_REMOTES_MANIFEST_FILE_NAME,
CloudbedsMicrofrontend,
Expand All @@ -9,9 +9,14 @@ import { ModuleFederationTypesPluginOptions, RemoteManifestUrls } from '../types
export function getRemoteManifestUrls(options?: ModuleFederationTypesPluginOptions): RemoteManifestUrls | undefined {
if (options?.cloudbedsRemoteManifestsBaseUrl !== undefined) {
let baseUrl = options?.cloudbedsRemoteManifestsBaseUrl;
if (!baseUrl || baseUrl === 'use-domain-name' || baseUrl === 'dev-ga') {
baseUrl = `${CLOUDBEDS_DEV_FRONTEND_ASSETS_DOMAIN}/remotes/dev-ga`;
if (!baseUrl || ['use-domain-name', 'dev', 'dev-ga'].includes(baseUrl)) {
baseUrl = `${CloudbedsCloudfrontDomain.Dev}/remotes/dev-ga`;
} else if (['stage', 'stage-ga'].includes(baseUrl)) {
baseUrl = `${CloudbedsCloudfrontDomain.Stage}/remotes/stage-ga/{version}`;
} else if (['prod', 'prod-ga'].includes(baseUrl)) {
baseUrl = `${CloudbedsCloudfrontDomain.Prod}/remotes/prod-ga/{version}`;
}

return {
/** @deprecated */
[CloudbedsMicrofrontend.Common]: `${baseUrl}/${CLOUDBEDS_MFD_COMMON_MANIFEST_FILE_NAME}`,
Expand Down
11 changes: 10 additions & 1 deletion src/helpers/downloadTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { toCamelCase } from './toCamelCase';
const downloadOptions: download.DownloadOptions = { rejectUnauthorized: false };

async function downloadRemoteEntryManifest(url: string): Promise<unknown> {
if (url.includes('{version}')) {
const versionJsonUrl = `${url.match(/^https:\/\/[^/]+/)}/version.json`;
const { version } = JSON.parse((await download(versionJsonUrl, downloadOptions)).toString());
url.replace('{version}', version);
}
const json = (await download(url, downloadOptions)).toString();
return JSON.parse(json);
}
Expand Down Expand Up @@ -121,7 +126,11 @@ export async function downloadTypes(
Object.entries(remotesFromFederationConfig).forEach(([remoteName, remoteLocation]) => {
try {
const remoteEntryUrl = remoteEntryUrlsResolved[remoteName] || remoteLocation.split('@')[1];
const remoteEntryBaseUrl = remoteEntryUrl.split('/').slice(0, -1).join('/');

const remoteEntryBaseUrl = remoteEntryUrl.endsWith('.js')
? remoteEntryUrl.split('/').slice(0, -1).join('/')
: remoteEntryUrl;

const promiseDownload = downloadRemoteEntryTypes(
remoteName,
remoteLocation,
Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ export type ModuleFederationTypesPluginOptions = {
remoteManifestUrls?: RemoteManifestUrls,
remoteManifestUrl?: string,

cloudbedsRemoteManifestsBaseUrl?: string | /** @deprecated */ 'use-domain-name' | 'dev-ga',
cloudbedsRemoteManifestsBaseUrl?: string | /** @deprecated */ 'use-domain-name'
| 'dev' | 'dev-ga'
| 'stage' | 'stage-ga'
| 'prod' | 'prod-ga',
}

0 comments on commit cbd0cd7

Please sign in to comment.