@netlify/edge-bundler 14.5.0 → 14.5.2

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.
@@ -4,6 +4,7 @@ import { join, resolve } from 'path';
4
4
  import process from 'process';
5
5
  import { pathToFileURL } from 'url';
6
6
  import { gte, lt } from 'semver';
7
+ import * as tar from 'tar';
7
8
  import tmp from 'tmp-promise';
8
9
  import { test, expect, vi, describe } from 'vitest';
9
10
  import { importMapSpecifier } from '../shared/consts.js';
@@ -608,6 +609,14 @@ describe.skipIf(lt(denoVersion, '2.4.2'))('Produces a tarball bundle', () => {
608
609
  const tarballPath = join(distPath, manifest.bundles[0].asset);
609
610
  const tarballResult = await runTarball(tarballPath);
610
611
  expect(tarballResult).toStrictEqual(expectedOutput);
612
+ const entries = [];
613
+ await tar.list({
614
+ file: tarballPath,
615
+ onReadEntry: (entry) => {
616
+ entries.push(entry.path);
617
+ },
618
+ });
619
+ expect(entries).toStrictEqual(['___netlify-edge-functions.json', 'deno.json', 'func1.js']);
611
620
  const eszipPath = join(distPath, manifest.bundles[1].asset);
612
621
  const eszipResult = await runESZIP(eszipPath);
613
622
  expect(eszipResult).toStrictEqual(expectedOutput);
@@ -4,12 +4,13 @@ import commonPathPrefix from 'common-path-prefix';
4
4
  import * as tar from 'tar';
5
5
  import tmp from 'tmp-promise';
6
6
  import { BundleFormat } from '../bundle.js';
7
- import { getDirectoryHash, getStringHash } from '../utils/sha256.js';
8
- const TARBALL_EXTENSION = '.tar';
7
+ import { listRecursively } from '../utils/fs.js';
8
+ import { getFileHash } from '../utils/sha256.js';
9
+ const TARBALL_EXTENSION = '.tar.gz';
9
10
  const getUnixPath = (input) => input.split(path.sep).join('/');
10
11
  export const bundle = async ({ basePath, buildID, deno, distDirectory, functions, importMap, vendorDirectory, }) => {
11
- const sideFilesDir = await tmp.dir({ unsafeCleanup: true });
12
- const cleanup = [sideFilesDir.cleanup];
12
+ const bundleDir = await tmp.dir({ unsafeCleanup: true });
13
+ const cleanup = [bundleDir.cleanup];
13
14
  let denoDir = vendorDirectory ? path.join(vendorDirectory, 'deno_dir') : undefined;
14
15
  if (!denoDir) {
15
16
  const tmpDir = await tmp.dir({ unsafeCleanup: true });
@@ -43,50 +44,35 @@ export const bundle = async ({ basePath, buildID, deno, distDirectory, functions
43
44
  '--quiet',
44
45
  '--code-splitting',
45
46
  '--outdir',
46
- distDirectory,
47
+ bundleDir.path,
47
48
  ...functions.map((func) => func.path),
48
49
  ], {
49
50
  cwd: basePath,
50
51
  });
51
- const manifestPath = path.join(sideFilesDir.path, 'manifest.json');
52
+ const manifestPath = path.join(bundleDir.path, '___netlify-edge-functions.json');
52
53
  const manifestContents = JSON.stringify(manifest);
53
54
  await fs.writeFile(manifestPath, manifestContents);
54
- const denoConfigPath = path.join(sideFilesDir.path, 'deno.json');
55
+ const denoConfigPath = path.join(bundleDir.path, 'deno.json');
55
56
  const denoConfigContents = JSON.stringify(importMap.getContentsWithRelativePaths());
56
57
  await fs.writeFile(denoConfigPath, denoConfigContents);
57
- const rootLevel = await fs.readdir(distDirectory);
58
- const hash = await getDirectoryHash(distDirectory);
59
58
  const tarballPath = path.join(distDirectory, buildID + TARBALL_EXTENSION);
60
59
  await fs.mkdir(path.dirname(tarballPath), { recursive: true });
61
- // Adding all the bundled files.
62
60
  await tar.create({
63
- cwd: distDirectory,
61
+ cwd: bundleDir.path,
64
62
  file: tarballPath,
63
+ gzip: true,
64
+ noDirRecurse: true,
65
65
  onWriteEntry(entry) {
66
- entry.path = getUnixPath(`./${entry.path}`);
66
+ const relativePath = path.relative(bundleDir.path, path.join('/', entry.path));
67
+ const normalizedPath = getUnixPath(relativePath);
68
+ entry.path = normalizedPath;
67
69
  },
68
- }, rootLevel);
69
- // Adding `deno.json`.
70
- await tar.update({
71
- cwd: distDirectory,
72
- file: tarballPath,
73
- onWriteEntry(entry) {
74
- entry.path = './deno.json';
75
- },
76
- }, [denoConfigPath]);
77
- // Adding the manifest file.
78
- await tar.update({
79
- cwd: distDirectory,
80
- file: tarballPath,
81
- onWriteEntry(entry) {
82
- entry.path = './___netlify-edge-functions.json';
83
- },
84
- }, [manifestPath]);
85
- await Promise.all(cleanup);
86
- const finalHash = [hash, getStringHash(manifestContents), getStringHash(denoConfigContents)].join('');
70
+ }, await listRecursively(bundleDir.path));
71
+ const hash = await getFileHash(tarballPath);
72
+ await Promise.allSettled(cleanup);
87
73
  return {
88
74
  extension: TARBALL_EXTENSION,
89
75
  format: BundleFormat.TARBALL,
90
- hash: finalHash,
76
+ hash,
91
77
  };
92
78
  };
@@ -1,3 +1,4 @@
1
+ export declare const listRecursively: (dirPath: string) => Promise<string[]>;
1
2
  /**
2
3
  * Returns all the directories obtained by traversing `inner` and its parents
3
4
  * all the way to `outer`, inclusive.
@@ -1,4 +1,22 @@
1
- import path from 'path';
1
+ import { promises as fs } from 'node:fs';
2
+ import path from 'node:path';
3
+ export const listRecursively = async (dirPath) => {
4
+ const entries = [];
5
+ async function walk(currentPath) {
6
+ const dirents = await fs.readdir(currentPath, { withFileTypes: true });
7
+ for (const dirent of dirents) {
8
+ const fullPath = path.join(currentPath, dirent.name);
9
+ if (dirent.isDirectory()) {
10
+ await walk(fullPath);
11
+ }
12
+ else if (dirent.isFile() || dirent.isSymbolicLink()) {
13
+ entries.push(fullPath);
14
+ }
15
+ }
16
+ }
17
+ await walk(dirPath);
18
+ return entries.sort((a, b) => a.localeCompare(b));
19
+ };
2
20
  /**
3
21
  * Returns all the directories obtained by traversing `inner` and its parents
4
22
  * all the way to `outer`, inclusive.
@@ -1,3 +1,2 @@
1
- export declare const getDirectoryHash: (dirPath: string) => Promise<string>;
2
1
  export declare const getFileHash: (path: string) => Promise<string>;
3
2
  export declare const getStringHash: (input: string) => string;
@@ -1,25 +1,5 @@
1
1
  import crypto from 'node:crypto';
2
- import { createReadStream, promises as fs } from 'node:fs';
3
- import path from 'node:path';
4
- export const getDirectoryHash = async (dirPath) => {
5
- const entries = [];
6
- async function walk(currentPath) {
7
- const dirents = await fs.readdir(currentPath, { withFileTypes: true });
8
- for (const dirent of dirents) {
9
- const fullPath = path.join(currentPath, dirent.name);
10
- const relativePath = path.relative(dirPath, fullPath);
11
- if (dirent.isDirectory()) {
12
- await walk(fullPath);
13
- }
14
- else if (dirent.isFile() || dirent.isSymbolicLink()) {
15
- const fileHash = await getFileHash(fullPath);
16
- entries.push(`${relativePath}:${fileHash}`);
17
- }
18
- }
19
- }
20
- await walk(dirPath);
21
- return getStringHash(entries.sort((a, b) => a.localeCompare(b)).join('\n'));
22
- };
2
+ import { createReadStream } from 'node:fs';
23
3
  export const getFileHash = (path) => {
24
4
  const hash = crypto.createHash('sha256');
25
5
  hash.setEncoding('hex');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "14.5.0",
3
+ "version": "14.5.2",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.js",
@@ -80,5 +80,5 @@
80
80
  "urlpattern-polyfill": "8.0.2",
81
81
  "uuid": "^11.0.0"
82
82
  },
83
- "gitHead": "6c0a42f34965ccca2564cf7b3c5a4d458debbe50"
83
+ "gitHead": "e1251f7e7c36b6de4cf0d88777b9f362817520f3"
84
84
  }