UNPKG

@equinor/fusion-framework-cli

Version:

[![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](./LICENSE)

47 lines 2.3 kB
import { importConfig } from '@equinor/fusion-imports'; import { mergeDevServerConfig } from './merge-dev-server-config.js'; /** * Helper to define a dev server config function with proper typing. * @param fn - The configuration function to be used as the dev server config. * @returns The same function, typed as DevServerConfigFn. */ export const defineDevServerConfig = (fn) => fn; /** * Loads the dev server configuration from a file or function. * * @param env - The runtime environment configuration. * @param base - The base DevServerOptions to use as defaults. * @param options - Optional settings for file name and extensions. * @returns A promise resolving to the imported config result. * * This function uses importConfig to dynamically load the configuration file. * If the config export is a function, it is invoked with the environment and a cloned base config. * If the config export is an object, it is merged with the base config. * * Inline comments are provided for maintainability and clarity. */ export const loadDevServerConfig = async (env, base, options) => { // Use importConfig to load the config file, defaulting to 'dev-server.config' if not specified return importConfig(options?.file ?? 'dev-server.config', { baseDir: env.root, // Set the base directory for config resolution extensions: options?.extensions, // Allow custom file extensions script: { // Custom resolver for the config module resolve: async (module) => { // If the default export is a function, call it with env and a cloned base config let overrides; if (typeof module.default === 'function') { const baseClone = { ...base }; // Clone base to avoid mutation overrides = await module.default(env, { base: baseClone }); // TODO: Add zod validation of the config for type safety } else { overrides = module.default; } // If the default export is an object, return it or fallback to base return mergeDevServerConfig(base, overrides ?? {}); }, }, }); }; //# sourceMappingURL=load-dev-server-config.js.map