From 87e7fedecd698cfa2b9646b98696d3ec54005fcc Mon Sep 17 00:00:00 2001 From: literat Date: Mon, 4 Nov 2024 11:43:51 +0100 Subject: [PATCH] fixup! Refactor(common): Switch package to the ES module --- .../constants/__tests__/servers.test.ts | 4 ++-- packages/common/constants/servers.ts | 20 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/common/constants/__tests__/servers.test.ts b/packages/common/constants/__tests__/servers.test.ts index d5c02cd508..517cb08c43 100644 --- a/packages/common/constants/__tests__/servers.test.ts +++ b/packages/common/constants/__tests__/servers.test.ts @@ -1,4 +1,4 @@ -import { getDevelopmentEndpointUri } from '../servers'; +import { getDevelopmentEndpointUri, PackageName } from '../servers'; describe('servers', () => { describe('getDevelopmentEndpointUri', () => { @@ -7,7 +7,7 @@ describe('servers', () => { ['web', 'http://localhost:3456/packages/web/'], ['web-react', 'http://localhost:3456/packages/web-react/'], ])('should return the correct development endpoint URI for a given package name', (packageName, expectedUri) => { - const result = getDevelopmentEndpointUri(packageName); + const result = getDevelopmentEndpointUri(packageName as PackageName); expect(result).toBe(expectedUri); }); diff --git a/packages/common/constants/servers.ts b/packages/common/constants/servers.ts index 4f81203cbd..ceec38e3c3 100644 --- a/packages/common/constants/servers.ts +++ b/packages/common/constants/servers.ts @@ -1,13 +1,11 @@ -/** - * ⚠️ This file is in CommonJS format only. - * It is mainly used in Vite configuration (`vite.config.ts`). - * Due to use of ESbuild, Vite configuration only supports importing CommonJS modules. - * - * @see https://github.com/vitejs/vite/issues/7981 - */ -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-nocheck -const SERVERS = { +export type PackageName = 'web' | 'web-react' | 'web-twig' | 'form-validations'; +export type ServerOptions = { host: string; https: boolean; port: number; path?: string; strictPort?: boolean }; +export type ServerEnvironments = { + DEVELOPMENT: Record; + TESTING: Partial>; +}; + +const SERVERS: ServerEnvironments = { DEVELOPMENT: { // @see: https://vitejs.dev/config/server-options.html web: { @@ -45,7 +43,7 @@ const SERVERS = { }, }; -const getDevelopmentEndpointUri = (packageName, { isDocker } = { isDocker: false }) => { +const getDevelopmentEndpointUri = (packageName: PackageName, { isDocker } = { isDocker: false }) => { const { https, host, port, path } = SERVERS.DEVELOPMENT[packageName]; return `http${https ? 's' : ''}://${isDocker ? 'host.docker.internal' : host}:${port}${path ? `/${path}` : ''}`;