@netlify/config
Version:
Netlify config module
35 lines (34 loc) • 2.3 kB
JavaScript
import { getAvailableIntegrations } from './api/integrations.js';
export const NETLIFY_API_STAGING_BASE_URL = 'api-staging.netlify.com';
export const NETLIFY_API_BASE_URL = 'api.netlify.com';
export const EXTENSION_API_BASE_URL = 'https://api.netlifysdk.com';
export const EXTENSION_API_STAGING_BASE_URL = 'https://api-staging.netlifysdk.com';
export const mergeIntegrations = async function ({ configIntegrations = [], apiIntegrations, context, testOpts = {}, offline, extensionApiBaseUrl, }) {
const availableIntegrations = await getAvailableIntegrations({ testOpts, offline, extensionApiBaseUrl });
// Include all API integrations, unless they have a `dev` property and we are in the `dev` context
const resolvedApiIntegrations = apiIntegrations.filter((integration) => !configIntegrations.some((configIntegration) => configIntegration.name === integration.slug &&
typeof configIntegration.dev !== 'undefined' &&
context === 'dev'));
// For integrations loaded from the TOML, we will use the local reference in the `dev` context,
// otherwise we will fetch from the API and match the slug
const resolvedConfigIntegrations = configIntegrations
.filter((configIntegration) => apiIntegrations.every((apiIntegration) => apiIntegration.slug !== configIntegration.name) ||
('dev' in configIntegration && context === 'dev'))
.map((configIntegration) => {
if (configIntegration.dev && context === 'dev') {
const integrationInstance = apiIntegrations.find((apiIntegration) => apiIntegration.slug === configIntegration.name);
return {
slug: configIntegration.name,
dev: configIntegration.dev,
has_build: integrationInstance?.has_build ?? configIntegration.dev?.force_run_in_build ?? false,
};
}
const integration = availableIntegrations.find((availableIntegration) => availableIntegration.slug === configIntegration.name);
if (!integration) {
return undefined;
}
return { slug: integration.slug, version: integration.hostSiteUrl, has_build: !!integration.hasBuild };
})
.filter((i) => typeof i !== 'undefined');
return [...resolvedApiIntegrations, ...resolvedConfigIntegrations];
};