@netlify/edge-bundler 1.4.3 → 1.5.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/bridge.d.ts CHANGED
@@ -29,13 +29,13 @@ declare class DenoBridge {
29
29
  private getCachedBinary;
30
30
  private getGlobalBinary;
31
31
  private getRemoteBinary;
32
- private log;
33
32
  private static runWithBinary;
34
33
  private writeVersionFile;
35
34
  getBinaryPath(): Promise<{
36
35
  global: boolean;
37
36
  path: string;
38
37
  }>;
38
+ log(...data: unknown[]): void;
39
39
  run(args: string[], { pipeOutput }?: RunOptions): Promise<import("execa").ExecaReturnValue<string>>;
40
40
  runInBackground(args: string[], pipeOutput?: boolean, ref?: ProcessRef): Promise<void>;
41
41
  }
package/dist/bridge.js CHANGED
@@ -82,12 +82,6 @@ class DenoBridge {
82
82
  }
83
83
  return this.currentDownload;
84
84
  }
85
- log(...data) {
86
- if (!this.debug) {
87
- return;
88
- }
89
- console.log(...data);
90
- }
91
85
  static runWithBinary(binaryPath, args, pipeOutput) {
92
86
  var _a, _b;
93
87
  const runDeno = execa(binaryPath, args);
@@ -115,6 +109,12 @@ class DenoBridge {
115
109
  const downloadedPath = await this.getRemoteBinary();
116
110
  return { global: false, path: downloadedPath };
117
111
  }
112
+ log(...data) {
113
+ if (!this.debug) {
114
+ return;
115
+ }
116
+ console.log(...data);
117
+ }
118
118
  // Runs the Deno CLI in the background and returns a reference to the child
119
119
  // process, awaiting its execution.
120
120
  async run(args, { pipeOutput } = {}) {
package/dist/bundler.js CHANGED
@@ -9,6 +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
+ import { ensureLatestTypes } from './types.js';
12
13
  const createBundleOps = ({ basePath, buildID, debug, deno, distDirectory, functions, importMap, featureFlags, }) => {
13
14
  const bundleOps = [];
14
15
  if (featureFlags.edge_functions_produce_eszip) {
@@ -42,6 +43,7 @@ const bundle = async (sourceDirectories, distDirectory, declarations = [], { cac
42
43
  onBeforeDownload,
43
44
  });
44
45
  const basePath = getBasePath(sourceDirectories);
46
+ await ensureLatestTypes(deno);
45
47
  // The name of the bundle will be the hash of its contents, which we can't
46
48
  // compute until we run the bundle process. For now, we'll use a random ID
47
49
  // to create the bundle artifacts and rename them later.
@@ -2,6 +2,7 @@ import { tmpName } from 'tmp-promise';
2
2
  import { DenoBridge } from '../bridge.js';
3
3
  import { generateStage2 } from '../formats/javascript.js';
4
4
  import { ImportMap } from '../import_map.js';
5
+ import { ensureLatestTypes } from '../types.js';
5
6
  import { killProcess, waitForServer } from './util.js';
6
7
  const prepareServer = ({ deno, distDirectory, flags: denoFlags, formatExportTypeError, formatImportError, port, }) => {
7
8
  const processRef = {};
@@ -39,7 +40,6 @@ const prepareServer = ({ deno, distDirectory, flags: denoFlags, formatExportType
39
40
  };
40
41
  return startIsolate;
41
42
  };
42
- // eslint-disable-next-line complexity, max-statements
43
43
  const serve = async ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, }) => {
44
44
  const deno = new DenoBridge({
45
45
  debug,
@@ -51,6 +51,8 @@ const serve = async ({ certificatePath, debug, distImportMapPath, inspectSetting
51
51
  const distDirectory = await tmpName();
52
52
  // Wait for the binary to be downloaded if needed.
53
53
  await deno.getBinaryPath();
54
+ // Downloading latest types if needed.
55
+ await ensureLatestTypes(deno);
54
56
  // Creating an ImportMap instance with any import maps supplied by the user,
55
57
  // if any.
56
58
  const importMap = new ImportMap(importMaps);
@@ -0,0 +1,3 @@
1
+ import type { DenoBridge } from './bridge.js';
2
+ declare const ensureLatestTypes: (deno: DenoBridge, customTypesURL?: string) => Promise<void>;
3
+ export { ensureLatestTypes };
package/dist/types.js ADDED
@@ -0,0 +1,57 @@
1
+ import { promises as fs } from 'fs';
2
+ import { join } from 'path';
3
+ import fetch from 'node-fetch';
4
+ const TYPES_URL = 'https://edge.netlify.com';
5
+ const ensureLatestTypes = async (deno, customTypesURL) => {
6
+ const typesURL = customTypesURL !== null && customTypesURL !== void 0 ? customTypesURL : TYPES_URL;
7
+ let [localVersion, remoteVersion] = [await getLocalVersion(deno), ''];
8
+ try {
9
+ remoteVersion = await getRemoteVersion(typesURL);
10
+ }
11
+ catch (error) {
12
+ deno.log('Could not check latest version of types:', error);
13
+ return;
14
+ }
15
+ if (localVersion === remoteVersion) {
16
+ deno.log('Local version of types is up-to-date:', localVersion);
17
+ return;
18
+ }
19
+ deno.log('Local version of types is outdated, updating:', localVersion);
20
+ try {
21
+ await deno.run(['cache', '-r', typesURL]);
22
+ }
23
+ catch (error) {
24
+ deno.log('Could not download latest types:', error);
25
+ return;
26
+ }
27
+ try {
28
+ await writeVersionFile(deno, remoteVersion);
29
+ }
30
+ catch {
31
+ // no-op
32
+ }
33
+ };
34
+ const getLocalVersion = async (deno) => {
35
+ const versionFilePath = join(deno.cacheDirectory, 'types-version.txt');
36
+ try {
37
+ const version = await fs.readFile(versionFilePath, 'utf8');
38
+ return version;
39
+ }
40
+ catch {
41
+ // no-op
42
+ }
43
+ };
44
+ const getRemoteVersion = async (typesURL) => {
45
+ const versionURL = new URL('/version.txt', typesURL);
46
+ const res = await fetch(versionURL.toString());
47
+ if (res.status !== 200) {
48
+ throw new Error('Unexpected status code from version endpoint');
49
+ }
50
+ const version = await res.text();
51
+ return version;
52
+ };
53
+ const writeVersionFile = async (deno, version) => {
54
+ const versionFilePath = join(deno.cacheDirectory, 'types-version.txt');
55
+ await fs.writeFile(versionFilePath, version);
56
+ };
57
+ export { ensureLatestTypes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "1.4.3",
3
+ "version": "1.5.0",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",