Skip to content

Commit

Permalink
Refactor(common): Switch package to the ES module
Browse files Browse the repository at this point in the history
refs #DS-1506
  • Loading branch information
literat committed Nov 4, 2024
1 parent ebc0414 commit edf2ac6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
File renamed without changes.
5 changes: 2 additions & 3 deletions packages/common/constants/__tests__/servers.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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);
});
Expand Down
22 changes: 10 additions & 12 deletions packages/common/constants/servers.ts
Original file line number Diff line number Diff line change
@@ -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<PackageName, ServerOptions>;
TESTING: Partial<Record<PackageName, string>>;
};

const SERVERS: ServerEnvironments = {
DEVELOPMENT: {
// @see: https://vitejs.dev/config/server-options.html
web: {
Expand Down Expand Up @@ -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 };
1 change: 1 addition & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Common code and scripts for Spirit Design System",
"license": "MIT",
"private": true,
"type": "module",
"keywords": [
"spirit",
"common",
Expand Down

0 comments on commit edf2ac6

Please sign in to comment.