@netlify/build 29.37.2 → 29.38.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.
@@ -3,7 +3,7 @@ import { getDeployStore } from '@netlify/blobs';
3
3
  import pMap from 'p-map';
4
4
  import semver from 'semver';
5
5
  import { log, logError } from '../../log/logger.js';
6
- import { anyBlobsToUpload, getBlobsDir } from '../../utils/blobs.js';
6
+ import { scanForBlobs } from '../../utils/blobs.js';
7
7
  import { getKeysToUpload, getFileWithMetadata } from './utils.js';
8
8
  const coreStep = async function ({ debug, logs, deployId, buildDir, quiet, packagePath, constants: { SITE_ID, NETLIFY_API_TOKEN, NETLIFY_API_HOST }, }) {
9
9
  // This should never happen due to the condition check
@@ -18,14 +18,28 @@ const coreStep = async function ({ debug, logs, deployId, buildDir, quiet, packa
18
18
  token: NETLIFY_API_TOKEN,
19
19
  apiURL: `https://${apiHost}`,
20
20
  };
21
+ // If we don't have native `fetch` in the global scope, add a polyfill.
21
22
  if (semver.lt(nodeVersion, '18.0.0')) {
22
23
  const nodeFetch = await import('node-fetch');
24
+ // @ts-expect-error The types between `node-fetch` and the native `fetch`
25
+ // are not a 100% match, even though the APIs are mostly compatible.
23
26
  storeOpts.fetch = nodeFetch.default;
24
27
  }
25
- const blobStore = getDeployStore(storeOpts);
26
- const blobsDir = getBlobsDir(buildDir, packagePath);
27
- const keys = await getKeysToUpload(blobsDir);
28
+ const blobs = await scanForBlobs(buildDir, packagePath);
28
29
  // We checked earlier, but let's be extra safe
30
+ if (blobs === null) {
31
+ if (!quiet) {
32
+ log(logs, 'No blobs to upload to deploy store.');
33
+ }
34
+ return {};
35
+ }
36
+ // If using the deploy config API, configure the store to use the region that
37
+ // was configured for the deploy.
38
+ if (!blobs.isLegacyDirectory) {
39
+ storeOpts.experimentalRegion = 'auto';
40
+ }
41
+ const blobStore = getDeployStore(storeOpts);
42
+ const keys = await getKeysToUpload(blobs.directory);
29
43
  if (keys.length === 0) {
30
44
  if (!quiet) {
31
45
  log(logs, 'No blobs to upload to deploy store.');
@@ -39,7 +53,7 @@ const coreStep = async function ({ debug, logs, deployId, buildDir, quiet, packa
39
53
  if (debug && !quiet) {
40
54
  log(logs, `- Uploading blob ${key}`, { indent: true });
41
55
  }
42
- const { data, metadata } = await getFileWithMetadata(blobsDir, key);
56
+ const { data, metadata } = await getFileWithMetadata(blobs.directory, key);
43
57
  await blobStore.set(key, data, { metadata });
44
58
  };
45
59
  try {
@@ -54,7 +68,7 @@ const coreStep = async function ({ debug, logs, deployId, buildDir, quiet, packa
54
68
  }
55
69
  return {};
56
70
  };
57
- const deployAndBlobsPresent = async ({ deployId, buildDir, packagePath, constants: { NETLIFY_API_TOKEN }, }) => Boolean(NETLIFY_API_TOKEN && deployId && (await anyBlobsToUpload(buildDir, packagePath)));
71
+ const deployAndBlobsPresent = async ({ deployId, buildDir, packagePath, constants: { NETLIFY_API_TOKEN }, }) => Boolean(NETLIFY_API_TOKEN && deployId && (await scanForBlobs(buildDir, packagePath)));
58
72
  export const uploadBlobs = {
59
73
  event: 'onPostBuild',
60
74
  coreStep,
@@ -1,16 +1,16 @@
1
1
  import { rm } from 'node:fs/promises';
2
- import { anyBlobsToUpload, getBlobsDir } from '../../utils/blobs.js';
2
+ import { scanForBlobs, getBlobsDirs } from '../../utils/blobs.js';
3
3
  const coreStep = async ({ buildDir, packagePath }) => {
4
- const blobsDir = getBlobsDir(buildDir, packagePath);
4
+ const blobsDirs = getBlobsDirs(buildDir, packagePath);
5
5
  try {
6
- await rm(blobsDir, { recursive: true, force: true });
6
+ await Promise.all(blobsDirs.map((dir) => rm(dir, { recursive: true, force: true })));
7
7
  }
8
8
  catch {
9
9
  // Ignore errors if it fails, we can continue anyway.
10
10
  }
11
11
  return {};
12
12
  };
13
- const blobsPresent = ({ buildDir, packagePath }) => anyBlobsToUpload(buildDir, packagePath);
13
+ const blobsPresent = async ({ buildDir, packagePath }) => Boolean(await scanForBlobs(buildDir, packagePath));
14
14
  export const preCleanup = {
15
15
  event: 'onPreBuild',
16
16
  coreStep,
@@ -1,9 +1,15 @@
1
- /** Retrieve the absolute path of the deploy scoped internal blob directory */
2
- export declare const getBlobsDir: (buildDir: string, packagePath?: string) => string;
1
+ /** Retrieve the absolute path of the deploy scoped internal blob directories */
2
+ export declare const getBlobsDirs: (buildDir: string, packagePath?: string) => string[];
3
3
  /**
4
- * Detect if there are any blobs to upload
4
+ * Detect if there are any blobs to upload, and if so, what directory they're
5
+ * in and whether that directory is the legacy `.netlify/blobs` path or the
6
+ * newer deploy config API endpoint.
7
+ *
5
8
  * @param buildDir The build directory. (current working directory where the build is executed)
6
9
  * @param packagePath An optional package path for mono repositories
7
10
  * @returns
8
11
  */
9
- export declare const anyBlobsToUpload: (buildDir: string, packagePath?: string) => Promise<boolean>;
12
+ export declare const scanForBlobs: (buildDir: string, packagePath?: string) => Promise<{
13
+ directory: string;
14
+ isLegacyDirectory: boolean;
15
+ } | null>;
@@ -1,16 +1,37 @@
1
1
  import { resolve } from 'node:path';
2
2
  import { fdir } from 'fdir';
3
- const BLOBS_PATH = '.netlify/blobs/deploy';
4
- /** Retrieve the absolute path of the deploy scoped internal blob directory */
5
- export const getBlobsDir = (buildDir, packagePath) => resolve(buildDir, packagePath || '', BLOBS_PATH);
3
+ const LEGACY_BLOBS_PATH = '.netlify/blobs/deploy';
4
+ const DEPLOY_CONFIG_BLOBS_PATH = '.netlify/deploy/v1/blobs/deploy';
5
+ /** Retrieve the absolute path of the deploy scoped internal blob directories */
6
+ export const getBlobsDirs = (buildDir, packagePath) => [
7
+ resolve(buildDir, packagePath || '', DEPLOY_CONFIG_BLOBS_PATH),
8
+ resolve(buildDir, packagePath || '', LEGACY_BLOBS_PATH),
9
+ ];
6
10
  /**
7
- * Detect if there are any blobs to upload
11
+ * Detect if there are any blobs to upload, and if so, what directory they're
12
+ * in and whether that directory is the legacy `.netlify/blobs` path or the
13
+ * newer deploy config API endpoint.
14
+ *
8
15
  * @param buildDir The build directory. (current working directory where the build is executed)
9
16
  * @param packagePath An optional package path for mono repositories
10
17
  * @returns
11
18
  */
12
- export const anyBlobsToUpload = async function (buildDir, packagePath) {
13
- const blobsDir = getBlobsDir(buildDir, packagePath);
14
- const { files } = await new fdir().onlyCounts().crawl(blobsDir).withPromise();
15
- return files > 0;
19
+ export const scanForBlobs = async function (buildDir, packagePath) {
20
+ const blobsDir = resolve(buildDir, packagePath || '', DEPLOY_CONFIG_BLOBS_PATH);
21
+ const blobsDirScan = await new fdir().onlyCounts().crawl(blobsDir).withPromise();
22
+ if (blobsDirScan.files > 0) {
23
+ return {
24
+ directory: blobsDir,
25
+ isLegacyDirectory: false,
26
+ };
27
+ }
28
+ const legacyBlobsDir = resolve(buildDir, packagePath || '', LEGACY_BLOBS_PATH);
29
+ const legacyBlobsDirScan = await new fdir().onlyCounts().crawl(legacyBlobsDir).withPromise();
30
+ if (legacyBlobsDirScan.files > 0) {
31
+ return {
32
+ directory: legacyBlobsDir,
33
+ isLegacyDirectory: true,
34
+ };
35
+ }
36
+ return null;
16
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "29.37.2",
3
+ "version": "29.38.0",
4
4
  "description": "Netlify build module",
5
5
  "type": "module",
6
6
  "exports": "./lib/index.js",
@@ -68,7 +68,7 @@
68
68
  "license": "MIT",
69
69
  "dependencies": {
70
70
  "@bugsnag/js": "^7.0.0",
71
- "@netlify/blobs": "^6.5.0",
71
+ "@netlify/blobs": "^7.2.0",
72
72
  "@netlify/cache-utils": "^5.1.5",
73
73
  "@netlify/config": "^20.12.1",
74
74
  "@netlify/edge-bundler": "11.3.0",
@@ -164,5 +164,5 @@
164
164
  "engines": {
165
165
  "node": "^14.16.0 || >=16.0.0"
166
166
  },
167
- "gitHead": "5532a6654b3b644da7b7f348a7b71ed2f7285494"
167
+ "gitHead": "48dfa17701f997ce0c52995ab501d652fb113c5a"
168
168
  }