@netlify/edge-bundler 1.3.0 → 1.4.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.
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,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,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 }) => {
@@ -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://62ac9c589c16c50008b6ef55--edge-bootstrap.netlify.app/bootstrap/index-combined.ts';
8
+ const BOOTSTRAP_LATEST = 'https://62bae4994570970008142f1e--edge-bootstrap.netlify.app/bootstrap/index-combined.ts';
9
9
  const bundle = async (options) => {
10
10
  try {
11
11
  return await bundleJS(options);
@@ -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 = {
@@ -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;
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.2",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",