@netlify/edge-bundler 12.3.2 → 12.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.
@@ -42,7 +42,7 @@ const loadWithRetry = (specifier: string, delay = 1000, maxTry = 3) => {
42
42
  maxTry,
43
43
  });
44
44
  } catch (error) {
45
- if (isTooManyTries(error)) {
45
+ if (isTooManyTries(error as Error)) {
46
46
  console.error(`Loading ${specifier} failed after ${maxTry} tries.`);
47
47
  }
48
48
  throw error;
@@ -1,7 +1,7 @@
1
1
  import { type WriteStream } from 'fs';
2
2
  import { ExecaChildProcess } from 'execa';
3
3
  import { Logger } from './logger.js';
4
- declare const DENO_VERSION_RANGE = "1.39.0 - 1.46.3";
4
+ declare const DENO_VERSION_RANGE = "1.39.0 - 2.2.4";
5
5
  type OnBeforeDownloadHook = () => void | Promise<void>;
6
6
  type OnAfterDownloadHook = (error?: Error) => void | Promise<void>;
7
7
  interface DenoOptions {
@@ -37,14 +37,16 @@ declare class DenoBridge {
37
37
  versionRange: string;
38
38
  constructor(options: DenoOptions);
39
39
  private downloadBinary;
40
- private getBinaryVersion;
40
+ getBinaryVersion(binaryPath: string): Promise<string | undefined>;
41
41
  private getCachedBinary;
42
42
  private getGlobalBinary;
43
43
  private getRemoteBinary;
44
44
  private static runWithBinary;
45
45
  private writeVersionFile;
46
46
  ensureCacheDirectory(): Promise<void>;
47
- getBinaryPath(): Promise<{
47
+ getBinaryPath(options?: {
48
+ silent?: boolean;
49
+ }): Promise<{
48
50
  global: boolean;
49
51
  path: string;
50
52
  }>;
@@ -12,7 +12,7 @@ const DENO_VERSION_FILE = 'version.txt';
12
12
  // When updating DENO_VERSION_RANGE, ensure that the deno version
13
13
  // on the netlify/buildbot build image satisfies this range!
14
14
  // https://github.com/netlify/buildbot/blob/f9c03c9dcb091d6570e9d0778381560d469e78ad/build-image/noble/Dockerfile#L410
15
- const DENO_VERSION_RANGE = '1.39.0 - 1.46.3';
15
+ const DENO_VERSION_RANGE = '1.39.0 - 2.2.4';
16
16
  class DenoBridge {
17
17
  constructor(options) {
18
18
  var _a, _b, _c, _d, _e;
@@ -119,15 +119,19 @@ class DenoBridge {
119
119
  async ensureCacheDirectory() {
120
120
  await fs.mkdir(this.cacheDirectory, { recursive: true });
121
121
  }
122
- async getBinaryPath() {
122
+ async getBinaryPath(options) {
123
123
  const globalPath = await this.getGlobalBinary();
124
124
  if (globalPath !== undefined) {
125
- this.logger.system('Using global installation of Deno CLI');
125
+ if (!(options === null || options === void 0 ? void 0 : options.silent)) {
126
+ this.logger.system('Using global installation of Deno CLI');
127
+ }
126
128
  return { global: true, path: globalPath };
127
129
  }
128
130
  const cachedPath = await this.getCachedBinary();
129
131
  if (cachedPath !== undefined) {
130
- this.logger.system('Using cached Deno CLI from', cachedPath);
132
+ if (!(options === null || options === void 0 ? void 0 : options.silent)) {
133
+ this.logger.system('Using cached Deno CLI from', cachedPath);
134
+ }
131
135
  return { global: false, path: cachedPath };
132
136
  }
133
137
  const downloadedPath = await this.getRemoteBinary();
@@ -84,16 +84,11 @@ test('Adds a custom error property to user errors during bundling', async () =>
84
84
  }
85
85
  catch (error) {
86
86
  expect(error).toBeInstanceOf(BundleError);
87
- const [messageBeforeStack] = error.message.split('at <anonymous> (file://');
88
- expect(messageBeforeStack).toMatchInlineSnapshot(`
89
- "error: Uncaught (in promise) Error: The module's source code could not be parsed: Unexpected eof at file:///root/functions/func1.ts:1:27
90
-
91
- export default async () =>
92
- ~
93
- const ret = new Error(getStringFromWasm0(arg0, arg1));
94
- ^
95
- "
96
- `);
87
+ const messageBeforeStack = error.message;
88
+ expect(messageBeforeStack
89
+ .replace(/file:\/\/\/(.*?\/)(build\/packages\/edge-bundler\/deno\/vendor\/deno\.land\/x\/eszip.*)/, 'file://$2')
90
+ // eslint-disable-next-line no-control-regex
91
+ .replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '')).toMatchSnapshot();
97
92
  expect(error.customErrorInfo).toEqual({
98
93
  location: {
99
94
  format: 'eszip',
@@ -1,6 +1,7 @@
1
1
  import { promises as fs } from 'fs';
2
2
  import { join } from 'path';
3
3
  import { pathToFileURL } from 'url';
4
+ import { SemVer } from 'semver';
4
5
  import tmp from 'tmp-promise';
5
6
  import { BundleError } from './bundle_error.js';
6
7
  import { getPackagePath } from './package_json.js';
@@ -39,21 +40,23 @@ export const getFunctionConfig = async ({ func, importMap, deno, log, }) => {
39
40
  // The extractor will use its exit code to signal different error scenarios,
40
41
  // based on the list of exit codes we send as an argument. We then capture
41
42
  // the exit code to know exactly what happened and guide people accordingly.
43
+ const version = new SemVer((await deno.getBinaryVersion((await deno.getBinaryPath({ silent: true })).path)) || '');
42
44
  const { exitCode, stderr, stdout } = await deno.run([
43
45
  'run',
44
46
  '--allow-env',
47
+ version.major >= 2 ? '--allow-import' : '',
45
48
  '--allow-net',
46
49
  '--allow-read',
47
50
  `--allow-write=${collector.path}`,
48
- '--quiet',
49
51
  `--import-map=${importMap.toDataURL()}`,
50
52
  '--no-config',
51
53
  '--node-modules-dir=false',
54
+ '--quiet',
52
55
  extractorPath,
53
56
  pathToFileURL(func.path).href,
54
57
  pathToFileURL(collector.path).href,
55
58
  JSON.stringify(ConfigExitCode),
56
- ], { rejectOnExitCode: false });
59
+ ].filter(Boolean), { rejectOnExitCode: false });
57
60
  if (exitCode !== ConfigExitCode.Success) {
58
61
  handleConfigError(func, exitCode, stderr, log);
59
62
  return {};
@@ -1,5 +1,6 @@
1
1
  import { readdir, unlink } from 'fs/promises';
2
2
  import { join } from 'path';
3
+ import { pathToFileURL } from 'url';
3
4
  import { DenoBridge } from '../bridge.js';
4
5
  import { getFunctionConfig } from '../config.js';
5
6
  import { generateStage2 } from '../formats/javascript.js';
@@ -65,7 +66,7 @@ const prepareServer = ({ basePath, bootstrapURL, deno, distDirectory, distImport
65
66
  // the `stage2Path` file as well as all of their dependencies.
66
67
  // Consumers such as the CLI can use this information to watch all the
67
68
  // relevant files and issue an isolate restart when one of them changes.
68
- const { stdout } = await deno.run(['info', '--json', stage2Path]);
69
+ const { stdout } = await deno.run(['info', '--json', pathToFileURL(stage2Path).href]);
69
70
  graph = JSON.parse(stdout);
70
71
  }
71
72
  catch {
@@ -49,8 +49,9 @@ test('Starts a server and serves requests for edge functions', async () => {
49
49
  expect(success).toBe(true);
50
50
  expect(functionsConfig).toEqual([{ path: '/my-function' }, {}, { path: '/global-netlify' }]);
51
51
  expect(npmSpecifiersWithExtraneousFiles).toEqual(['dictionary']);
52
+ const modules = graph === null || graph === void 0 ? void 0 : graph.modules.filter(({ kind, mediaType }) => kind === 'esm' && mediaType === 'TypeScript');
52
53
  for (const key in functions) {
53
- const graphEntry = graph === null || graph === void 0 ? void 0 : graph.modules.some(({ kind, mediaType, local }) => kind === 'esm' && mediaType === 'TypeScript' && local === functions[key].path);
54
+ const graphEntry = modules === null || modules === void 0 ? void 0 : modules.some(({ local }) => local === functions[key].path);
54
55
  expect(graphEntry).toBe(true);
55
56
  }
56
57
  const response1 = await fetch(`http://0.0.0.0:${port}/foo`, {
package/dist/test/util.js CHANGED
@@ -76,7 +76,7 @@ const runESZIP = async (eszipPath, vendorDirectory) => {
76
76
  }
77
77
  await fs.rename(stage2Path, `${stage2Path}.js`);
78
78
  // Run function that imports the extracted stage 2 and invokes each function.
79
- const evalCommand = execa('deno', ['eval', '--no-check', '--import-map', importMapPath, inspectFunction(stage2Path)]);
79
+ const evalCommand = execa('deno', ['eval', '--import-map', importMapPath, inspectFunction(stage2Path)]);
80
80
  (_c = evalCommand.stderr) === null || _c === void 0 ? void 0 : _c.pipe(stderr);
81
81
  const result = await evalCommand;
82
82
  await tmpDir.cleanup();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "12.3.2",
3
+ "version": "12.4.0",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.js",
@@ -42,15 +42,12 @@
42
42
  "test": "test/node"
43
43
  },
44
44
  "devDependencies": {
45
- "@types/glob-to-regexp": "^0.4.1",
46
45
  "@types/node": "^14.18.32",
47
46
  "@types/semver": "^7.3.9",
48
47
  "@types/uuid": "^10.0.0",
49
48
  "@vitest/coverage-v8": "^0.34.0",
50
49
  "archiver": "^5.3.1",
51
50
  "chalk": "^5.4.0",
52
- "cpy": "^9.0.1",
53
- "cross-env": "^7.0.3",
54
51
  "nock": "^13.2.4",
55
52
  "tar": "^6.1.11",
56
53
  "typescript": "^5.0.0",
@@ -73,7 +70,6 @@
73
70
  "get-package-name": "^2.2.0",
74
71
  "get-port": "^6.1.2",
75
72
  "is-path-inside": "^4.0.0",
76
- "jsonc-parser": "^3.2.0",
77
73
  "node-fetch": "^3.1.1",
78
74
  "node-stream-zip": "^1.15.0",
79
75
  "p-retry": "^5.1.1",
@@ -84,5 +80,5 @@
84
80
  "urlpattern-polyfill": "8.0.2",
85
81
  "uuid": "^9.0.0"
86
82
  },
87
- "gitHead": "a6d31ce1991f5fcdbdb275ce2d68fe8a60329120"
83
+ "gitHead": "0e4628f57a0a7d02594b5070074445a4ff69b809"
88
84
  }