@netlify/edge-bundler 1.2.1 → 1.4.1

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/deno/bundle.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { writeStage2 } from 'https://62a718350450bd00093e1841--edge-bootstrap.netlify.app/bundler/mod.ts'
1
+ import { writeStage2 } from 'https://62ac9c589c16c50008b6ef55--edge-bootstrap.netlify.app/bundler/mod.ts'
2
2
 
3
3
  const [payload] = Deno.args
4
4
  const { basePath, destPath, functions } = JSON.parse(payload)
package/dist/bridge.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { ExecaChildProcess } from 'execa';
2
- declare type LifecycleHook = () => void | Promise<void>;
2
+ declare type OnBeforeDownloadHook = () => void | Promise<void>;
3
+ declare type OnAfterDownloadHook = (error?: Error) => void | Promise<void>;
3
4
  interface DenoOptions {
4
5
  cacheDirectory?: string;
5
6
  debug?: boolean;
6
- onAfterDownload?: LifecycleHook;
7
- onBeforeDownload?: LifecycleHook;
7
+ onAfterDownload?: OnAfterDownloadHook;
8
+ onBeforeDownload?: OnBeforeDownloadHook;
8
9
  useGlobal?: boolean;
9
10
  versionRange?: string;
10
11
  }
@@ -18,8 +19,8 @@ declare class DenoBridge {
18
19
  cacheDirectory: string;
19
20
  currentDownload?: ReturnType<DenoBridge['downloadBinary']>;
20
21
  debug: boolean;
21
- onAfterDownload?: LifecycleHook;
22
- onBeforeDownload?: LifecycleHook;
22
+ onAfterDownload?: OnAfterDownloadHook;
23
+ onBeforeDownload?: OnBeforeDownloadHook;
23
24
  useGlobal: boolean;
24
25
  versionRange: string;
25
26
  constructor(options?: DenoOptions);
@@ -39,4 +40,4 @@ declare class DenoBridge {
39
40
  runInBackground(args: string[], pipeOutput?: boolean, ref?: ProcessRef): Promise<void>;
40
41
  }
41
42
  export { DenoBridge };
42
- export type { LifecycleHook, ProcessRef };
43
+ export type { OnAfterDownloadHook, OnBeforeDownloadHook, ProcessRef };
package/dist/bridge.js CHANGED
@@ -19,9 +19,8 @@ class DenoBridge {
19
19
  this.versionRange = (_d = options.versionRange) !== null && _d !== void 0 ? _d : DENO_VERSION_RANGE;
20
20
  }
21
21
  async downloadBinary() {
22
- if (this.onBeforeDownload) {
23
- this.onBeforeDownload();
24
- }
22
+ var _a, _b, _c;
23
+ (_a = this.onBeforeDownload) === null || _a === void 0 ? void 0 : _a.call(this);
25
24
  await fs.mkdir(this.cacheDirectory, { recursive: true });
26
25
  this.log(`Downloading Deno CLI to ${this.cacheDirectory}...`);
27
26
  const binaryPath = await download(this.cacheDirectory, this.versionRange);
@@ -30,12 +29,12 @@ class DenoBridge {
30
29
  // a malformed semver range. If this does happen, let's throw an error so
31
30
  // that the tests catch it.
32
31
  if (downloadedVersion === undefined) {
33
- throw new Error('Could not read downloaded binary');
32
+ const error = new Error('There was a problem setting up the Edge Functions environment. To try a manual installation, visit https://ntl.fyi/install-deno.');
33
+ (_b = this.onAfterDownload) === null || _b === void 0 ? void 0 : _b.call(this, error);
34
+ throw error;
34
35
  }
35
36
  await this.writeVersionFile(downloadedVersion);
36
- if (this.onAfterDownload) {
37
- this.onAfterDownload();
38
- }
37
+ (_c = this.onAfterDownload) === null || _c === void 0 ? void 0 : _c.call(this);
39
38
  return binaryPath;
40
39
  }
41
40
  static async getBinaryVersion(binaryPath) {
package/dist/bundler.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { LifecycleHook } from './bridge.js';
1
+ import { OnAfterDownloadHook, OnBeforeDownloadHook } 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 {
@@ -8,10 +9,11 @@ interface BundleOptions {
8
9
  distImportMapPath?: string;
9
10
  featureFlags?: FeatureFlags;
10
11
  importMaps?: ImportMapFile[];
11
- onAfterDownload?: LifecycleHook;
12
- onBeforeDownload?: LifecycleHook;
12
+ onAfterDownload?: OnAfterDownloadHook;
13
+ onBeforeDownload?: OnBeforeDownloadHook;
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,6 +9,30 @@ 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
+ const createBundleOps = ({ basePath, buildID, debug, deno, distDirectory, functions, importMap, featureFlags, }) => {
13
+ const bundleOps = [];
14
+ if (featureFlags.edge_functions_produce_eszip) {
15
+ bundleOps.push(bundleESZIP({
16
+ basePath,
17
+ buildID,
18
+ debug,
19
+ deno,
20
+ distDirectory,
21
+ functions,
22
+ }));
23
+ }
24
+ else {
25
+ bundleOps.push(bundleJS({
26
+ buildID,
27
+ debug,
28
+ deno,
29
+ distDirectory,
30
+ functions,
31
+ importMap,
32
+ }));
33
+ }
34
+ return bundleOps;
35
+ };
12
36
  const bundle = async (sourceDirectories, distDirectory, declarations = [], { cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, } = {}) => {
13
37
  const featureFlags = getFlags(inputFeatureFlags);
14
38
  const deno = new DenoBridge({
@@ -26,32 +50,22 @@ const bundle = async (sourceDirectories, distDirectory, declarations = [], { cac
26
50
  // if any.
27
51
  const importMap = new ImportMap(importMaps);
28
52
  const functions = await findFunctions(sourceDirectories);
29
- const bundleOps = [
30
- bundleJS({
31
- buildID,
32
- debug,
33
- deno,
34
- distDirectory,
35
- functions,
36
- importMap,
37
- }),
38
- ];
39
- if (featureFlags.edge_functions_produce_eszip) {
40
- bundleOps.push(bundleESZIP({
41
- basePath,
42
- buildID,
43
- debug,
44
- deno,
45
- distDirectory,
46
- functions,
47
- }));
48
- }
53
+ const bundleOps = createBundleOps({
54
+ basePath,
55
+ buildID,
56
+ debug,
57
+ deno,
58
+ distDirectory,
59
+ functions,
60
+ importMap,
61
+ featureFlags,
62
+ });
49
63
  const bundles = await Promise.all(bundleOps);
50
64
  // The final file name of the bundles contains a SHA256 hash of the contents,
51
65
  // which we can only compute now that the files have been generated. So let's
52
66
  // rename the bundles to their permanent names.
53
67
  await createFinalBundles(bundles, distDirectory, buildID);
54
- await writeManifest({
68
+ const manifest = await writeManifest({
55
69
  bundles,
56
70
  declarations,
57
71
  distDirectory,
@@ -60,7 +74,7 @@ const bundle = async (sourceDirectories, distDirectory, declarations = [], { cac
60
74
  if (distImportMapPath) {
61
75
  await importMap.writeToFile(distImportMapPath);
62
76
  }
63
- return { functions };
77
+ return { functions, manifest };
64
78
  };
65
79
  const createFinalBundles = async (bundles, distDirectory, buildID) => {
66
80
  const renamingOps = bundles.map(async ({ extension, hash }) => {
@@ -5,7 +5,7 @@ import { pathToFileURL } from 'url';
5
5
  import del from 'del';
6
6
  import { wrapBundleError } from '../bundle_error.js';
7
7
  import { getFileHash } from '../utils/sha256.js';
8
- const BOOTSTRAP_LATEST = 'https://62a718350450bd00093e1841--edge-bootstrap.netlify.app/bootstrap/index-combined.ts';
8
+ const BOOTSTRAP_LATEST = 'https://62ac9c589c16c50008b6ef55--edge-bootstrap.netlify.app/bootstrap/index-combined.ts';
9
9
  const bundle = async (options) => {
10
10
  try {
11
11
  return await bundleJS(options);
@@ -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 };
@@ -1,4 +1,4 @@
1
- import { LifecycleHook } from '../bridge.js';
1
+ import { OnAfterDownloadHook, OnBeforeDownloadHook } from '../bridge.js';
2
2
  import type { EdgeFunction } from '../edge_function.js';
3
3
  import { ImportMapFile } from '../import_map.js';
4
4
  declare type FormatFunction = (name: string) => string;
@@ -13,8 +13,8 @@ interface ServeOptions {
13
13
  distImportMapPath?: string;
14
14
  inspectSettings?: InspectSettings;
15
15
  importMaps?: ImportMapFile[];
16
- onAfterDownload?: LifecycleHook;
17
- onBeforeDownload?: LifecycleHook;
16
+ onAfterDownload?: OnAfterDownloadHook;
17
+ onBeforeDownload?: OnBeforeDownloadHook;
18
18
  formatExportTypeError?: FormatFunction;
19
19
  formatImportError?: FormatFunction;
20
20
  port: number;
@@ -1,4 +1,4 @@
1
1
  import { ExecaChildProcess } from 'execa';
2
2
  declare const killProcess: (ps: ExecaChildProcess<string>) => Promise<unknown> | undefined;
3
- declare const waitForServer: (port: number, ps?: ExecaChildProcess<string> | undefined) => Promise<boolean>;
3
+ declare const waitForServer: (port: number, ps?: ExecaChildProcess<string>) => Promise<boolean>;
4
4
  export { killProcess, waitForServer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "1.2.1",
3
+ "version": "1.4.1",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",