@netlify/config 23.0.8 → 23.0.10

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.
package/lib/main.js CHANGED
@@ -108,11 +108,12 @@ export const resolveConfig = async function (opts) {
108
108
  siteId,
109
109
  accountId,
110
110
  token,
111
- cwd,
111
+ buildDir,
112
112
  extensionApiBaseUrl,
113
113
  testOpts,
114
114
  offline,
115
115
  mode,
116
+ debug,
116
117
  });
117
118
  const mergedIntegrations = await mergeIntegrations({
118
119
  apiIntegrations: updatedIntegrations,
@@ -5,12 +5,13 @@ interface AutoInstallOptions {
5
5
  siteId: string;
6
6
  accountId: string;
7
7
  token: string;
8
- cwd: string;
8
+ buildDir: string;
9
9
  integrations: IntegrationResponse[];
10
10
  offline: boolean;
11
11
  testOpts: any;
12
12
  mode: ModeOption;
13
13
  extensionApiBaseUrl: string;
14
+ debug?: boolean;
14
15
  }
15
- export declare function handleAutoInstallExtensions({ featureFlags, siteId, accountId, token, cwd, integrations, offline, testOpts, mode, extensionApiBaseUrl, }: AutoInstallOptions): Promise<IntegrationResponse[]>;
16
+ export declare function handleAutoInstallExtensions({ featureFlags, siteId, accountId, token, buildDir, integrations, offline, testOpts, mode, extensionApiBaseUrl, debug, }: AutoInstallOptions): Promise<IntegrationResponse[]>;
16
17
  export {};
@@ -3,73 +3,57 @@ import { join } from 'path';
3
3
  import { getIntegrations } from '../../api/site_info.js';
4
4
  import { fetchAutoInstallableExtensionsMeta, installExtension } from './utils.js';
5
5
  function getPackageJSON(directory) {
6
- const require = createRequire(join(directory, 'package.json'));
7
- return require('./package.json');
8
- }
9
- export async function handleAutoInstallExtensions({ featureFlags, siteId, accountId, token, cwd, integrations, offline, testOpts = {}, mode, extensionApiBaseUrl, }) {
10
- if (!featureFlags?.auto_install_required_extensions) {
11
- return integrations;
12
- }
13
- if (!accountId) {
14
- console.error("Failed to auto install extension(s): Missing 'accountId'", {
15
- accountId,
16
- siteId,
17
- cwd,
18
- offline,
19
- mode,
20
- });
21
- return integrations;
22
- }
23
- if (!siteId) {
24
- console.error("Failed to auto install extension(s): Missing 'siteId'", {
25
- accountId,
26
- siteId,
27
- cwd,
28
- offline,
29
- mode,
30
- });
31
- return integrations;
6
+ try {
7
+ const require = createRequire(join(directory, 'package.json'));
8
+ return require('./package.json');
32
9
  }
33
- if (!token) {
34
- console.error("Failed to auto install extension(s): Missing 'token'", {
35
- accountId,
36
- siteId,
37
- cwd,
38
- offline,
39
- mode,
40
- });
41
- return integrations;
10
+ catch {
11
+ // Gracefully fail if no package.json found in buildDir
12
+ return {};
42
13
  }
43
- if (!cwd) {
44
- console.error("Failed to auto install extension(s): Missing 'cwd'", {
45
- accountId,
46
- siteId,
47
- cwd,
48
- offline,
49
- mode,
50
- });
14
+ }
15
+ export async function handleAutoInstallExtensions({ featureFlags, siteId, accountId, token, buildDir, integrations, offline, testOpts = {}, mode, extensionApiBaseUrl, debug = false, }) {
16
+ if (!featureFlags?.auto_install_required_extensions) {
51
17
  return integrations;
52
18
  }
53
- if (offline) {
54
- console.error("Failed to auto install extension(s): Running as 'offline'", {
55
- accountId,
56
- siteId,
57
- cwd,
58
- offline,
59
- mode,
60
- });
19
+ if (!accountId || !siteId || !token || !buildDir || offline) {
20
+ const reason = !accountId
21
+ ? 'Missing accountId'
22
+ : !siteId
23
+ ? 'Missing siteId'
24
+ : !token
25
+ ? 'Missing token'
26
+ : !buildDir
27
+ ? 'Missing buildDir'
28
+ : 'Running as offline';
29
+ if (debug) {
30
+ console.error(`Failed to auto install extension(s): ${reason}`, {
31
+ accountId,
32
+ siteId,
33
+ buildDir,
34
+ offline,
35
+ mode,
36
+ });
37
+ }
61
38
  return integrations;
62
39
  }
63
40
  try {
64
- const packageJson = getPackageJSON(cwd);
41
+ const packageJson = getPackageJSON(buildDir);
65
42
  if (!packageJson?.dependencies ||
66
43
  typeof packageJson?.dependencies !== 'object' ||
67
44
  Object.keys(packageJson?.dependencies)?.length === 0) {
68
45
  return integrations;
69
46
  }
70
47
  const autoInstallableExtensions = await fetchAutoInstallableExtensionsMeta();
71
- const extensionsToInstall = autoInstallableExtensions.filter((ext) => {
72
- return !integrations?.some((integration) => integration.slug === ext.slug);
48
+ const enabledExtensionSlugs = new Set((integrations ?? []).map(({ slug }) => slug));
49
+ const extensionsToInstallCandidates = autoInstallableExtensions.filter(({ slug }) => !enabledExtensionSlugs.has(slug));
50
+ const extensionsToInstall = extensionsToInstallCandidates.filter(({ packages }) => {
51
+ for (const pkg of packages) {
52
+ if (packageJson?.dependencies && Object.hasOwn(packageJson.dependencies, pkg)) {
53
+ return true;
54
+ }
55
+ }
56
+ return false;
73
57
  });
74
58
  if (extensionsToInstall.length === 0) {
75
59
  return integrations;
@@ -34,11 +34,17 @@ export const installExtension = async ({ netlifyToken, accountId, slug, hostSite
34
34
  * @returns Array of extensions with their associated packages
35
35
  */
36
36
  export async function fetchAutoInstallableExtensionsMeta() {
37
- const url = new URL(`/meta/auto-installable`, process.env.EXTENSION_API_BASE_URL ?? EXTENSION_API_BASE_URL);
38
- const response = await fetch(url.toString());
39
- if (!response.ok) {
40
- throw new Error(`Failed to fetch extensions meta`);
37
+ try {
38
+ const url = new URL(`/meta/auto-installable`, process.env.EXTENSION_API_BASE_URL ?? EXTENSION_API_BASE_URL);
39
+ const response = await fetch(url.toString());
40
+ if (!response.ok) {
41
+ throw new Error(`Failed to fetch extensions meta`);
42
+ }
43
+ const data = await response.json();
44
+ return data;
45
+ }
46
+ catch (error) {
47
+ console.error(`Failed to fetch auto-installable extensions meta: ${error.message}`, error);
48
+ return [];
41
49
  }
42
- const data = await response.json();
43
- return data;
44
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/config",
3
- "version": "23.0.8",
3
+ "version": "23.0.10",
4
4
  "description": "Netlify config module",
5
5
  "type": "module",
6
6
  "exports": "./lib/index.js",
@@ -94,5 +94,5 @@
94
94
  "engines": {
95
95
  "node": ">=18.14.0"
96
96
  },
97
- "gitHead": "df148594017a78f0f419591da402311ed08e4d64"
97
+ "gitHead": "4a0f587ae4efe1c2e62c25c11374e3fbaa9aebce"
98
98
  }