packages/cli-config/src/load.js
function loadPreset(descriptor, loader) {
  const config = Array.isArray(descriptor) ? descriptor : [descriptor];
  const [name, options = {}] = config;
  const { error: loaderError, module: getPreset } = loader(name);

  if (loaderError) {
    return {
      error: loaderError,
      name,
    };
  }

  if (typeof getPreset !== 'function') {
    return {
      error: new Error(
        `Expected the preset \`${name}\` to export a function, instead ` +
          `recieved: ${typeof getPreset}`
      ),
      name,
    };
  }

  let preset;
  try {
    preset = getPreset(options);
  } catch (error) {
    return {
      error,
      name,
      options,
    };
  }

  const { presets = [], plugins = [] } = preset;

  return {
    name,
    options,
    presets: presets.map(descriptor => loadPreset(descriptor, loader)),
    plugins: plugins.map(descriptor => loadPlugin(descriptor, loader)),
  };
}
function loadPreset(descriptor, loader) {
  const config = Array.isArray(descriptor) ? descriptor : [descriptor];
  const [name, options = {}] = config;
  const { error: loaderError, module: getPreset } = loader(name);

  if (loaderError) {
    return {
      error: loaderError,
      name,
    };
  }

  if (typeof getPreset !== 'function') {
    return {
      error: new Error(
        `Expected the preset \`${name}\` to export a function, instead ` +
          `recieved: ${typeof getPreset}`
      ),
      name,
    };
  }

  let preset;
  try {
    preset = getPreset(options);
  } catch (error) {
    return {
      error,
      name,
      options,
    };
  }

  const { presets = [], plugins = [] } = preset;

  return {
    name,
    options,
    presets: presets.map(descriptor => loadPreset(descriptor, loader)),
    plugins: plugins.map(descriptor => loadPlugin(descriptor, loader)),
  };
}
function loadPreset ( descriptor , loader ) { const config = Array . isArray ( descriptor ) ? descriptor : [ descriptor ] ; const [ name , options = { } ] = config ; const { error : loaderError , module : getPreset } = loader ( name ) ; if ( loaderError ) { return { error : loaderError , name , } ; } if ( typeof getPreset !== 'function' ) { return { error : new Error ( ` \` ${ name } \` ` + ` ${ typeof getPreset } ` ) , name , } ; } let preset ; try { preset = getPreset ( options ) ; } catch ( error ) { return { error , name , options , } ; } const { presets = [ ] , plugins = [ ] } = preset ; return { name , options , presets : presets . map ( descriptor => loadPreset ( descriptor , loader ) ) , plugins : plugins . map ( descriptor => loadPlugin ( descriptor , loader ) ) , } ; }
Load the preset with the given loader
@param {Descriptor} descriptor
@param {Loader} loader
Load the preset with the given loader