From edf2ac670994bc0b36d6556299471b8644116b88 Mon Sep 17 00:00:00 2001 From: literat Date: Wed, 23 Oct 2024 15:35:51 +0200 Subject: [PATCH] Refactor(common): Switch package to the ES module refs #DS-1506 --- .../common/{.eslintrc.js => .eslintrc.cjs} | 0 .../constants/__tests__/servers.test.ts | 5 ++--- packages/common/constants/servers.ts | 22 +++++++++---------- packages/common/package.json | 1 + 4 files changed, 13 insertions(+), 15 deletions(-) rename packages/common/{.eslintrc.js => .eslintrc.cjs} (100%) diff --git a/packages/common/.eslintrc.js b/packages/common/.eslintrc.cjs similarity index 100% rename from packages/common/.eslintrc.js rename to packages/common/.eslintrc.cjs diff --git a/packages/common/constants/__tests__/servers.test.ts b/packages/common/constants/__tests__/servers.test.ts index d8519d965a..517cb08c43 100644 --- a/packages/common/constants/__tests__/servers.test.ts +++ b/packages/common/constants/__tests__/servers.test.ts @@ -1,5 +1,4 @@ -// @ts-expect-error TS2306: File is not a module. -import { getDevelopmentEndpointUri } from '../servers'; +import { getDevelopmentEndpointUri, PackageName } from '../servers'; describe('servers', () => { describe('getDevelopmentEndpointUri', () => { @@ -8,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 d8c1d70fcf..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,10 +43,10 @@ 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}` : ''}`; }; -module.exports = { SERVERS, getDevelopmentEndpointUri }; +export { SERVERS, getDevelopmentEndpointUri }; diff --git a/packages/common/package.json b/packages/common/package.json index 8f188817ec..6024f48542 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -4,6 +4,7 @@ "description": "Common code and scripts for Spirit Design System", "license": "MIT", "private": true, + "type": "module", "keywords": [ "spirit", "common",