components/node_modules/es-dev-server/dist/config.js
/**
 * Creates dev server config with default settings
 * @param {Partial<Config>} config
 * @returns {InternalConfig}
 */
Creates dev server config with default settings
@param {Partial} config
@returns {InternalConfig}
Creates dev server config with default settings @param { Partial } config @returns { InternalConfig }
function createConfig(config) {
  const {
    babel = false,
    babelConfig,
    babelExclude = [],
    babelModernExclude = [],
    babelModuleExclude = [],
    basePath,
    compress = true,
    fileExtensions: fileExtensionsArg,
    hostname,
    http2 = false,
    logStartup,
    open = false,
    port,
    sslCert,
    sslKey,
    watch = false,
    logErrorsToBrowser = false,
    polyfills = _constants.polyfillsModes.AUTO,
    responseTransformers,
    debug = false,
    nodeResolve: nodeResolveArg = false,
    dedupeModules,
    moduleDirs,
    preserveSymlinks = false
  } = config;
  if (debug) {
    (0, _utils.setDebug)(true);
  }
  let {
    compatibility = _constants.compatibilityModes.AUTO
  } = config;
  if (compatibility === 'modern' || compatibility === 'all') {
    console.warn('[es-dev-server] Compatibility mode "modern" and "all" are deprecated, and combined into "auto".' + '"auto" mode is turned on by default.');
    compatibility = _constants.compatibilityModes.AUTO;
  }
  if (!Object.values(_constants.compatibilityModes).includes(compatibility)) {
    throw new Error(`Unknown compatibility mode: ${compatibility}`);
  }
  if (!Object.values(_constants.polyfillsModes).includes(polyfills)) {
    throw new Error(`Unknown polyfills mode: ${polyfills}`);
  } 
  const middlewares = config.middlewares || config.customMiddlewares;
  let {
    appIndex,
    rootDir = process.cwd()
  } = config;
  let appIndexDir; 
  rootDir = _path.default.resolve(rootDir); 
  if (appIndex) {
    if (_path.default.isAbsolute(appIndex)) {
      appIndex = `/${(0, _utils.toBrowserPath)(_path.default.relative(rootDir, appIndex))}`;
    } else if (!appIndex.startsWith('/')) {
      appIndex = `/${(0, _utils.toBrowserPath)(appIndex)}`;
    } else {
      appIndex = (0, _utils.toBrowserPath)(appIndex);
    }
    appIndexDir = `${appIndex.substring(0, appIndex.lastIndexOf('/'))}`;
  } 
  let openPath;
  if (typeof open === 'string' && open !== '') {
    openPath = open;
  } else if (appIndex) {
    openPath = `${basePath || ''}${appIndexDir}/`;
  } else {
    openPath = basePath ? `${basePath}/` : '/';
  }
  const fileExtensions = [...(fileExtensionsArg || []), ..._buildingUtils.defaultFileExtensions];
  let nodeResolve = nodeResolveArg; 
  if (nodeResolveArg != null && nodeResolveArg !== false && (moduleDirs != null || preserveSymlinks != null || dedupeModules != null)) {
    nodeResolve = { 
      ...(typeof nodeResolveArg === 'object' ? nodeResolveArg : {}),
      customResolveOptions: {
        moduleDirectory: moduleDirs,
        preserveSymlinks
      }
    };
    if (dedupeModules) {
      nodeResolve.dedupe = dedupeModules === true ? importee => !['.', '/'].includes(importee[0]) : dedupeModules;
    }
  }
  return {
    appIndex,
    appIndexDir,
    babelExclude,
    babelModernExclude,
    babelModuleExclude,
    basePath,
    compatibilityMode: compatibility,
    polyfillsMode: polyfills,
    compress,
    customBabelConfig: babelConfig,
    customMiddlewares: middlewares,
    responseTransformers,
    fileExtensions,
    hostname,
    http2,
    logStartup,
    nodeResolve,
    openBrowser: open === true || typeof open === 'string',
    openPath,
    port,
    readUserBabelConfig: babel,
    rootDir,
    sslCert,
    sslKey,
    watch,
    logErrorsToBrowser,
    watchDebounce: 100
  };
}
function createConfig ( config ) { const { babel = false , babelConfig , babelExclude = [ ] , babelModernExclude = [ ] , babelModuleExclude = [ ] , basePath , compress = true , fileExtensions : fileExtensionsArg , hostname , http2 = false , logStartup , open = false , port , sslCert , sslKey , watch = false , logErrorsToBrowser = false , polyfills = _constants . polyfillsModes . AUTO , responseTransformers , debug = false , nodeResolve : nodeResolveArg = false , dedupeModules , moduleDirs , preserveSymlinks = false } = config ; if ( debug ) { ( 0 , _utils . setDebug ) ( true ) ; } let { compatibility = _constants . compatibilityModes . AUTO } = config ; if ( compatibility === 'modern' || compatibility === 'all' ) { console . warn ( '[es-dev-server] Compatibility mode "modern" and "all" are deprecated, and combined into "auto".' + '"auto" mode is turned on by default.' ) ; compatibility = _constants . compatibilityModes . AUTO ; } if ( ! Object . values ( _constants . compatibilityModes ) . includes ( compatibility ) ) { throw new Error ( ` ${ compatibility } ` ) ; } if ( ! Object . values ( _constants . polyfillsModes ) . includes ( polyfills ) ) { throw new Error ( ` ${ polyfills } ` ) ; } const middlewares = config . middlewares || config . customMiddlewares ; let { appIndex , rootDir = process . cwd ( ) } = config ; let appIndexDir ; rootDir = _path . default . resolve ( rootDir ) ; if ( appIndex ) { if ( _path . default . isAbsolute ( appIndex ) ) { appIndex = ` ${ ( 0 , _utils . toBrowserPath ) ( _path . default . relative ( rootDir , appIndex ) ) } ` ; } else if ( ! appIndex . startsWith ( '/' ) ) { appIndex = ` ${ ( 0 , _utils . toBrowserPath ) ( appIndex ) } ` ; } else { appIndex = ( 0 , _utils . toBrowserPath ) ( appIndex ) ; } appIndexDir = ` ${ appIndex . substring ( 0 , appIndex . lastIndexOf ( '/' ) ) } ` ; } let openPath ; if ( typeof open === 'string' && open !== '' ) { openPath = open ; } else if ( appIndex ) { openPath = ` ${ basePath || '' } ${ appIndexDir } ` ; } else { openPath = basePath ? ` ${ basePath } ` : '/' ; } const fileExtensions = [ ... ( fileExtensionsArg || [ ] ) , ... _buildingUtils . defaultFileExtensions ] ; let nodeResolve = nodeResolveArg ; if ( nodeResolveArg != null && nodeResolveArg !== false && ( moduleDirs != null || preserveSymlinks != null || dedupeModules != null ) ) { nodeResolve = { ... ( typeof nodeResolveArg === 'object' ? nodeResolveArg : { } ) , customResolveOptions : { moduleDirectory : moduleDirs , preserveSymlinks } } ; if ( dedupeModules ) { nodeResolve . dedupe = dedupeModules === true ? importee => ! [ '.' , '/' ] . includes ( importee [ 0 ] ) : dedupeModules ; } } return { appIndex , appIndexDir , babelExclude , babelModernExclude , babelModuleExclude , basePath , compatibilityMode : compatibility , polyfillsMode : polyfills , compress , customBabelConfig : babelConfig , customMiddlewares : middlewares , responseTransformers , fileExtensions , hostname , http2 , logStartup , nodeResolve , openBrowser : open === true || typeof open === 'string' , openPath , port , readUserBabelConfig : babel , rootDir , sslCert , sslKey , watch , logErrorsToBrowser , watchDebounce : 100 } ; }
Creates dev server config with default settings
 @param {Partial<Config>} config
 @returns {InternalConfig}
Creates dev server config with default settings @param { Partial<Config > } config @returns { InternalConfig }
/* eslint-disable-next-line no-console */ // middlewares used to be called customMiddlewares // @ts-ignore // ensure rootDir is a fully resolved path, for example if you set ../../ // in the config or cli, it's resolved relative to the current working directory // resolve appIndex relative to rootDir and transform it to a browser path // parse `open` option, based on whether it's a boolean or a string // user-provided open path // if an appIndex was provided, use it's directory as open path /** @type {boolean | NodeResolveOptions} */ // some node resolve options can be set separately for convenience, primarily // for the command line args. we merge them into a node resolve options object // user provided options, if any