@netlify/config 20.8.1 → 20.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ import fetch from 'node-fetch';
2
+ export const getAvailableIntegrations = async function ({ testOpts, offline, }) {
3
+ if (offline) {
4
+ return [];
5
+ }
6
+ const { host } = testOpts;
7
+ const baseUrl = new URL(host ? `http://${host}/` : `https://api.netlifysdk.com/`);
8
+ try {
9
+ const response = await fetch(`${baseUrl}integrations`);
10
+ if (response.ok) {
11
+ const integrations = (await response.json());
12
+ return Array.isArray(integrations) ? integrations : [];
13
+ }
14
+ return [];
15
+ }
16
+ catch {
17
+ return [];
18
+ }
19
+ };
@@ -11,19 +11,20 @@ import { ERROR_CALL_TO_ACTION } from '../log/messages.js';
11
11
  * Silently ignore API errors. For example the network connection might be down,
12
12
  * but local builds should still work regardless.
13
13
  */
14
- export const getSiteInfo = async function ({ api, siteId, mode, siteFeatureFlagPrefix, offline = false, featureFlags = {}, testOpts = {}, }) {
14
+ export const getSiteInfo = async function ({ api, siteId, mode, siteFeatureFlagPrefix, offline = false, testOpts = {}, }) {
15
15
  const { env: testEnv = false } = testOpts;
16
- const fetchIntegrations = featureFlags.buildbot_fetch_integrations;
17
16
  if (api === undefined || mode === 'buildbot' || testEnv) {
18
17
  const siteInfo = siteId === undefined ? {} : { id: siteId };
19
- const integrations = fetchIntegrations && mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts }) : [];
18
+ const integrations = mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts, offline }) : [];
20
19
  return { siteInfo, accounts: [], addons: [], integrations };
21
20
  }
22
- const promises = [getSite(api, siteId, siteFeatureFlagPrefix), getAccounts(api), getAddons(api, siteId)];
23
- if (fetchIntegrations) {
24
- promises.push(getIntegrations({ siteId, testOpts }));
25
- }
26
- const [siteInfo, accounts, addons, integrations = []] = await Promise.all(promises);
21
+ const promises = [
22
+ getSite(api, siteId, siteFeatureFlagPrefix),
23
+ getAccounts(api),
24
+ getAddons(api, siteId),
25
+ getIntegrations({ siteId, testOpts, offline }),
26
+ ];
27
+ const [siteInfo, accounts, addons, integrations] = await Promise.all(promises);
27
28
  if (siteInfo.use_envelope) {
28
29
  const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId });
29
30
  siteInfo.build_settings.env = envelope;
@@ -63,8 +64,8 @@ const getAddons = async function (api, siteId) {
63
64
  throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
64
65
  }
65
66
  };
66
- const getIntegrations = async function ({ siteId, testOpts }) {
67
- if (!siteId) {
67
+ const getIntegrations = async function ({ siteId, testOpts, offline, }) {
68
+ if (!siteId || offline) {
68
69
  return [];
69
70
  }
70
71
  const { host } = testOpts;
@@ -0,0 +1,34 @@
1
+ import { getAvailableIntegrations } from './api/integrations.js';
2
+ export const mergeIntegrations = async function ({ configIntegrations = [], apiIntegrations, context, testOpts = {}, offline, }) {
3
+ const availableIntegrations = await getAvailableIntegrations({ testOpts, offline });
4
+ // Include all API integrations, unless they have a `dev` property and we are in the `dev` context
5
+ const resolvedApiIntegrations = apiIntegrations.filter((integration) => !configIntegrations.some((configIntegration) => configIntegration.name === integration.slug &&
6
+ typeof configIntegration.dev !== 'undefined' &&
7
+ context === 'dev'));
8
+ // For integrations loaded from the TOML, we will use the local reference in the `dev` context,
9
+ // otherwise we will fetch from the API and match the slug
10
+ const resolvedConfigIntegrations = configIntegrations
11
+ .filter((configIntegration) => apiIntegrations.every((apiIntegration) => apiIntegration.slug !== configIntegration.name) ||
12
+ ('dev' in configIntegration && context === 'dev'))
13
+ .map((configIntegration) => {
14
+ if (configIntegration.dev && context === 'dev') {
15
+ const integrationInstance = apiIntegrations.find((apiIntegration) => apiIntegration.slug === configIntegration.name);
16
+ return {
17
+ slug: configIntegration.name,
18
+ dev: configIntegration.dev,
19
+ has_build: integrationInstance?.has_build ?? configIntegration.dev?.force_run_in_build ?? false,
20
+ };
21
+ }
22
+ const integration = availableIntegrations.find((availableIntegration) => availableIntegration.slug === configIntegration.name);
23
+ if (!integration) {
24
+ return undefined;
25
+ }
26
+ return {
27
+ slug: integration.slug,
28
+ version: integration.hostSiteUrl,
29
+ has_build: !!integration.hasBuild,
30
+ };
31
+ })
32
+ .filter((i) => typeof i !== 'undefined');
33
+ return [...resolvedApiIntegrations, ...resolvedConfigIntegrations];
34
+ };
package/lib/main.js CHANGED
@@ -9,6 +9,7 @@ import { getEnv } from './env/main.js';
9
9
  import { resolveConfigPaths } from './files.js';
10
10
  import { getHeadersPath, addHeaders } from './headers.js';
11
11
  import { getInlineConfig } from './inline_config.js';
12
+ import { mergeIntegrations } from './integrations.js';
12
13
  import { logResult } from './log/main.js';
13
14
  import { mergeConfigs } from './merge.js';
14
15
  import { normalizeBeforeConfigMerge, normalizeAfterConfigMerge } from './merge_normalize.js';
@@ -77,9 +78,16 @@ export const resolveConfig = async function (opts) {
77
78
  });
78
79
  // @todo Remove in the next major version.
79
80
  const configA = addLegacyFunctionsDirectory(config);
81
+ const mergedIntegrations = await mergeIntegrations({
82
+ apiIntegrations: integrations,
83
+ configIntegrations: configA.integrations,
84
+ context: context,
85
+ testOpts,
86
+ offline,
87
+ });
80
88
  const result = {
81
89
  siteInfo,
82
- integrations,
90
+ integrations: mergedIntegrations,
83
91
  accounts,
84
92
  addons,
85
93
  env,
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/config",
3
- "version": "20.8.1",
3
+ "version": "20.10.0",
4
4
  "description": "Netlify config module",
5
5
  "type": "module",
6
6
  "exports": "./lib/index.js",
@@ -70,7 +70,7 @@
70
70
  "is-plain-obj": "^4.0.0",
71
71
  "js-yaml": "^4.0.0",
72
72
  "map-obj": "^5.0.0",
73
- "netlify": "^13.1.10",
73
+ "netlify": "^13.1.11",
74
74
  "netlify-headers-parser": "^7.1.2",
75
75
  "netlify-redirect-parser": "^14.2.0",
76
76
  "node-fetch": "^3.3.1",
@@ -94,5 +94,5 @@
94
94
  "engines": {
95
95
  "node": "^14.16.0 || >=16.0.0"
96
96
  },
97
- "gitHead": "0eb6dbbfd00ba11941b1ef638811eded8a030a17"
97
+ "gitHead": "01ca6c705c4b568b7552a7d90a9801ebdc747594"
98
98
  }