Skip to content

Commit

Permalink
fixup! Refactor(common): Switch package to the ES module
Browse files Browse the repository at this point in the history
  • Loading branch information
literat committed Nov 4, 2024
1 parent ac70f4c commit 87e7fed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/common/constants/__tests__/servers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getDevelopmentEndpointUri } from '../servers';
import { getDevelopmentEndpointUri, PackageName } from '../servers';

describe('servers', () => {
describe('getDevelopmentEndpointUri', () => {
Expand All @@ -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);
});
Expand Down
20 changes: 9 additions & 11 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,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}` : ''}`;
Expand Down

0 comments on commit 87e7fed

Please sign in to comment.