@netlify/edge-bundler 1.3.0 → 1.4.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.
package/dist/bundler.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { LifecycleHook } from './bridge.js';
2
2
  import type { Declaration } from './declaration.js';
3
+ import { EdgeFunction } from './edge_function.js';
3
4
  import { FeatureFlags } from './feature_flags.js';
4
5
  import { ImportMapFile } from './import_map.js';
5
6
  interface BundleOptions {
@@ -12,6 +13,7 @@ interface BundleOptions {
12
13
  onBeforeDownload?: LifecycleHook;
13
14
  }
14
15
  declare const bundle: (sourceDirectories: string[], distDirectory: string, declarations?: Declaration[], { cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, }?: BundleOptions) => Promise<{
15
- functions: import("./edge_function.js").EdgeFunction[];
16
+ functions: EdgeFunction[];
17
+ manifest: import("./manifest.js").Manifest;
16
18
  }>;
17
19
  export { bundle };
package/dist/bundler.js CHANGED
@@ -9,24 +9,7 @@ import { bundle as bundleESZIP } from './formats/eszip.js';
9
9
  import { bundle as bundleJS } from './formats/javascript.js';
10
10
  import { ImportMap } from './import_map.js';
11
11
  import { writeManifest } from './manifest.js';
12
- // eslint-disable-next-line max-statements
13
- const bundle = async (sourceDirectories, distDirectory, declarations = [], { cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, } = {}) => {
14
- const featureFlags = getFlags(inputFeatureFlags);
15
- const deno = new DenoBridge({
16
- debug,
17
- cacheDirectory,
18
- onAfterDownload,
19
- onBeforeDownload,
20
- });
21
- const basePath = getBasePath(sourceDirectories);
22
- // The name of the bundle will be the hash of its contents, which we can't
23
- // compute until we run the bundle process. For now, we'll use a random ID
24
- // to create the bundle artifacts and rename them later.
25
- const buildID = uuidv4();
26
- // Creating an ImportMap instance with any import maps supplied by the user,
27
- // if any.
28
- const importMap = new ImportMap(importMaps);
29
- const functions = await findFunctions(sourceDirectories);
12
+ const createBundleOps = ({ basePath, buildID, debug, deno, distDirectory, functions, importMap, featureFlags, }) => {
30
13
  const bundleOps = [];
31
14
  if (featureFlags.edge_functions_produce_eszip) {
32
15
  bundleOps.push(bundleESZIP({
@@ -48,12 +31,41 @@ const bundle = async (sourceDirectories, distDirectory, declarations = [], { cac
48
31
  importMap,
49
32
  }));
50
33
  }
34
+ return bundleOps;
35
+ };
36
+ const bundle = async (sourceDirectories, distDirectory, declarations = [], { cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, } = {}) => {
37
+ const featureFlags = getFlags(inputFeatureFlags);
38
+ const deno = new DenoBridge({
39
+ debug,
40
+ cacheDirectory,
41
+ onAfterDownload,
42
+ onBeforeDownload,
43
+ });
44
+ const basePath = getBasePath(sourceDirectories);
45
+ // The name of the bundle will be the hash of its contents, which we can't
46
+ // compute until we run the bundle process. For now, we'll use a random ID
47
+ // to create the bundle artifacts and rename them later.
48
+ const buildID = uuidv4();
49
+ // Creating an ImportMap instance with any import maps supplied by the user,
50
+ // if any.
51
+ const importMap = new ImportMap(importMaps);
52
+ const functions = await findFunctions(sourceDirectories);
53
+ const bundleOps = createBundleOps({
54
+ basePath,
55
+ buildID,
56
+ debug,
57
+ deno,
58
+ distDirectory,
59
+ functions,
60
+ importMap,
61
+ featureFlags,
62
+ });
51
63
  const bundles = await Promise.all(bundleOps);
52
64
  // The final file name of the bundles contains a SHA256 hash of the contents,
53
65
  // which we can only compute now that the files have been generated. So let's
54
66
  // rename the bundles to their permanent names.
55
67
  await createFinalBundles(bundles, distDirectory, buildID);
56
- await writeManifest({
68
+ const manifest = await writeManifest({
57
69
  bundles,
58
70
  declarations,
59
71
  distDirectory,
@@ -62,7 +74,7 @@ const bundle = async (sourceDirectories, distDirectory, declarations = [], { cac
62
74
  if (distImportMapPath) {
63
75
  await importMap.writeToFile(distImportMapPath);
64
76
  }
65
- return { functions };
77
+ return { functions, manifest };
66
78
  };
67
79
  const createFinalBundles = async (bundles, distDirectory, buildID) => {
68
80
  const renamingOps = bundles.map(async ({ extension, hash }) => {
@@ -24,5 +24,5 @@ interface WriteManifestOptions {
24
24
  distDirectory: string;
25
25
  functions: EdgeFunction[];
26
26
  }
27
- declare const writeManifest: ({ bundles, declarations, distDirectory, functions }: WriteManifestOptions) => Promise<void>;
27
+ declare const writeManifest: ({ bundles, declarations, distDirectory, functions }: WriteManifestOptions) => Promise<Manifest>;
28
28
  export { generateManifest, Manifest, writeManifest };
package/dist/manifest.js CHANGED
@@ -40,9 +40,10 @@ const getRegularExpression = (declaration) => {
40
40
  const normalizedSource = `^${regularExpression.source}\\/?$`;
41
41
  return new RegExp(normalizedSource);
42
42
  };
43
- const writeManifest = ({ bundles, declarations = [], distDirectory, functions }) => {
43
+ const writeManifest = async ({ bundles, declarations = [], distDirectory, functions }) => {
44
44
  const manifest = generateManifest({ bundles, declarations, functions });
45
45
  const manifestPath = join(distDirectory, 'manifest.json');
46
- return fs.writeFile(manifestPath, JSON.stringify(manifest));
46
+ await fs.writeFile(manifestPath, JSON.stringify(manifest));
47
+ return manifest;
47
48
  };
48
49
  export { generateManifest, writeManifest };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",