MCPcopy
hub / github.com/FredKSchott/snowpack / loadConfiguration

Function loadConfiguration

snowpack/src/config.ts:789–872  ·  view source on GitHub ↗
(
  overrides: SnowpackUserConfig = {},
  configPath?: string,
)

Source from the content-addressed store, hash-verified

787}
788
789export async function loadConfiguration(
790 overrides: SnowpackUserConfig = {},
791 configPath?: string,
792): Promise<SnowpackConfig> {
793 let result: Awaited<ReturnType<typeof loadConfigurationFile>> = null;
794 // if user specified --config path, load that
795 if (configPath) {
796 result = await loadConfigurationFile(configPath, overrides);
797 if (!result) {
798 throw new Error(`Snowpack config file could not be found: ${configPath}`);
799 }
800 }
801
802 const configs = [
803 'snowpack.config.mjs',
804 'snowpack.config.cjs',
805 'snowpack.config.js',
806 'snowpack.config.json',
807 ];
808
809 // If no config was found above, search for one.
810 if (!result) {
811 for (const potentialConfigurationFile of configs) {
812 if (result) break;
813 result = await loadConfigurationFile(potentialConfigurationFile, overrides);
814 }
815 }
816
817 // Support package.json "snowpack" config
818 if (!result) {
819 const potentialPackageJsonConfig = await loadConfigurationFile('package.json', overrides);
820 if (potentialPackageJsonConfig && (potentialPackageJsonConfig.config as any).snowpack) {
821 result = {
822 filepath: potentialPackageJsonConfig.filepath,
823 config: (potentialPackageJsonConfig.config as any).snowpack,
824 };
825 }
826 }
827
828 if (!result) {
829 logger.warn('Hint: run "snowpack init" to create a project config file. Using defaults...');
830 result = {filepath: undefined, config: {}};
831 }
832
833 const {config, filepath} = result;
834 const configBase = getConfigBasePath(filepath, config.root);
835 valdiateDeprecatedConfig(config);
836 valdiateDeprecatedConfig(overrides);
837 resolveRelativeConfig(config, configBase);
838
839 let extendConfig: SnowpackUserConfig = {} as SnowpackUserConfig;
840 if (config.extends) {
841 const extendConfigLoc = require.resolve(config.extends, {paths: [configBase]});
842 const extendResult = await loadConfigurationFile(extendConfigLoc, {});
843 if (!extendResult) {
844 handleConfigError(`Could not locate "extends" config at ${extendConfigLoc}`);
845 process.exit(1);
846 }

Callers 1

cliFunction · 0.90

Calls 8

loadConfigurationFileFunction · 0.85
getConfigBasePathFunction · 0.85
valdiateDeprecatedConfigFunction · 0.85
resolveRelativeConfigFunction · 0.85
handleConfigErrorFunction · 0.85
handleValidationErrorsFunction · 0.85
createConfigurationFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected