@netlify/edge-bundler 1.4.0 → 1.4.3

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://62ac9c589c16c50008b6ef55--edge-bootstrap.netlify.app/bundler/mod.ts'
1
+ import { writeStage2 } from 'https://62bae4994570970008142f1e--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
+ await ((_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
+ await ((_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
+ await ((_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,4 +1,4 @@
1
- import { LifecycleHook } from './bridge.js';
1
+ import { OnAfterDownloadHook, OnBeforeDownloadHook } from './bridge.js';
2
2
  import type { Declaration } from './declaration.js';
3
3
  import { EdgeFunction } from './edge_function.js';
4
4
  import { FeatureFlags } from './feature_flags.js';
@@ -9,8 +9,8 @@ interface BundleOptions {
9
9
  distImportMapPath?: string;
10
10
  featureFlags?: FeatureFlags;
11
11
  importMaps?: ImportMapFile[];
12
- onAfterDownload?: LifecycleHook;
13
- onBeforeDownload?: LifecycleHook;
12
+ onAfterDownload?: OnAfterDownloadHook;
13
+ onBeforeDownload?: OnBeforeDownloadHook;
14
14
  }
15
15
  declare const bundle: (sourceDirectories: string[], distDirectory: string, declarations?: Declaration[], { cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, }?: BundleOptions) => Promise<{
16
16
  functions: EdgeFunction[];
@@ -9,5 +9,5 @@ interface BundleESZIPOptions {
9
9
  distDirectory: string;
10
10
  functions: EdgeFunction[];
11
11
  }
12
- declare const bundle: (options: BundleESZIPOptions) => Promise<Bundle>;
13
- export { bundle };
12
+ declare const bundleESZIP: ({ basePath, buildID, debug, deno, distDirectory, functions, }: BundleESZIPOptions) => Promise<Bundle>;
13
+ export { bundleESZIP as bundle };
@@ -2,14 +2,6 @@ import { join, resolve } from 'path';
2
2
  import { fileURLToPath } from 'url';
3
3
  import { wrapBundleError } from '../bundle_error.js';
4
4
  import { getFileHash } from '../utils/sha256.js';
5
- const bundle = async (options) => {
6
- try {
7
- return await bundleESZIP(options);
8
- }
9
- catch (error) {
10
- throw wrapBundleError(error, { format: 'eszip' });
11
- }
12
- };
13
5
  const bundleESZIP = async ({ basePath, buildID, debug, deno, distDirectory, functions, }) => {
14
6
  const extension = '.eszip';
15
7
  const destPath = join(distDirectory, `${buildID}${extension}`);
@@ -23,7 +15,12 @@ const bundleESZIP = async ({ basePath, buildID, debug, deno, distDirectory, func
23
15
  if (!debug) {
24
16
  flags.push('--quiet');
25
17
  }
26
- await deno.run(['run', ...flags, bundler, JSON.stringify(payload)], { pipeOutput: true });
18
+ try {
19
+ await deno.run(['run', ...flags, bundler, JSON.stringify(payload)], { pipeOutput: true });
20
+ }
21
+ catch (error) {
22
+ throw wrapBundleError(error, { format: 'eszip' });
23
+ }
27
24
  const hash = await getFileHash(destPath);
28
25
  return { extension, format: 'eszip2', hash };
29
26
  };
@@ -33,4 +30,4 @@ const getESZIPBundler = () => {
33
30
  const bundlerPath = resolve(pathname, '../../../deno/bundle.ts');
34
31
  return bundlerPath;
35
32
  };
36
- export { bundle };
33
+ export { bundleESZIP as bundle };
@@ -11,7 +11,7 @@ interface BundleJSOptions {
11
11
  functions: EdgeFunction[];
12
12
  importMap: ImportMap;
13
13
  }
14
- declare const bundle: (options: BundleJSOptions) => Promise<Bundle>;
14
+ declare const bundleJS: ({ buildID, debug, deno, distDirectory, functions, importMap, }: BundleJSOptions) => Promise<Bundle>;
15
15
  interface GenerateStage2Options {
16
16
  distDirectory: string;
17
17
  fileName: string;
@@ -22,4 +22,4 @@ interface GenerateStage2Options {
22
22
  }
23
23
  declare const generateStage2: ({ distDirectory, fileName, formatExportTypeError, formatImportError, functions, type, }: GenerateStage2Options) => Promise<string>;
24
24
  declare const getBootstrapURL: () => string;
25
- export { bundle, generateStage2, getBootstrapURL };
25
+ export { bundleJS as bundle, generateStage2, getBootstrapURL };
@@ -5,15 +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://62ac9c589c16c50008b6ef55--edge-bootstrap.netlify.app/bootstrap/index-combined.ts';
9
- const bundle = async (options) => {
10
- try {
11
- return await bundleJS(options);
12
- }
13
- catch (error) {
14
- throw wrapBundleError(error, { format: 'javascript' });
15
- }
16
- };
8
+ const BOOTSTRAP_LATEST = 'https://62bae4994570970008142f1e--edge-bootstrap.netlify.app/bootstrap/index-combined.ts';
17
9
  const bundleJS = async ({ buildID, debug, deno, distDirectory, functions, importMap, }) => {
18
10
  const stage2Path = await generateStage2({ distDirectory, functions, fileName: `${buildID}-pre.js` });
19
11
  const extension = '.js';
@@ -22,7 +14,12 @@ const bundleJS = async ({ buildID, debug, deno, distDirectory, functions, import
22
14
  if (!debug) {
23
15
  flags.push('--quiet');
24
16
  }
25
- await deno.run(['bundle', ...flags, stage2Path, jsBundlePath], { pipeOutput: true });
17
+ try {
18
+ await deno.run(['bundle', ...flags, stage2Path, jsBundlePath], { pipeOutput: true });
19
+ }
20
+ catch (error) {
21
+ throw wrapBundleError(error, { format: 'javascript' });
22
+ }
26
23
  await fs.unlink(stage2Path);
27
24
  const hash = await getFileHash(jsBundlePath);
28
25
  return { extension, format: 'js', hash };
@@ -80,4 +77,4 @@ const getProductionEntryPoint = (functions) => {
80
77
  const defaultExport = 'boot(functions);';
81
78
  return [bootImport, importLines, exportDeclaration, defaultExport].join('\n\n');
82
79
  };
83
- export { bundle, generateStage2, getBootstrapURL };
80
+ export { bundleJS as bundle, generateStage2, getBootstrapURL };
@@ -1,15 +1,15 @@
1
1
  import { Buffer } from 'buffer';
2
2
  import { promises as fs } from 'fs';
3
3
  import { dirname } from 'path';
4
- const DEFAULT_IMPORTS = {
4
+ const INTERNAL_IMPORTS = {
5
5
  'netlify:edge': 'https://edge-bootstrap.netlify.app/v1/index.ts',
6
6
  };
7
7
  class ImportMap {
8
8
  constructor(input = []) {
9
9
  const inputImports = input.reduce((acc, { imports }) => ({ ...acc, ...imports }), {});
10
- // `DEFAULT_IMPORTS` must come last because we want our internal imports to
11
- // take precedence.
12
- this.imports = { ...inputImports, ...DEFAULT_IMPORTS };
10
+ // `INTERNAL_IMPORTS` must come last,
11
+ // because we need to guarantee `netlify:edge` isn't user-defined.
12
+ this.imports = { ...inputImports, ...INTERNAL_IMPORTS };
13
13
  }
14
14
  getContents() {
15
15
  const contents = {
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "1.4.0",
3
+ "version": "1.4.3",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",