@netlify/edge-bundler 14.3.0 → 14.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.
@@ -1,14 +1,13 @@
1
1
  import { Buffer } from 'buffer';
2
- import { execSync } from 'node:child_process';
3
2
  import { access, readdir, readFile, rm, writeFile } from 'fs/promises';
4
3
  import { join, resolve } from 'path';
5
4
  import process from 'process';
6
5
  import { pathToFileURL } from 'url';
7
- import { lt } from 'semver';
6
+ import { gte, lt } from 'semver';
8
7
  import tmp from 'tmp-promise';
9
8
  import { test, expect, vi, describe } from 'vitest';
10
9
  import { importMapSpecifier } from '../shared/consts.js';
11
- import { runESZIP, runTarball, useFixture } from '../test/util.js';
10
+ import { denoVersion, runESZIP, runTarball, useFixture } from '../test/util.js';
12
11
  import { BundleError } from './bundle_error.js';
13
12
  import { bundle } from './bundler.js';
14
13
  import { isFileNotFoundError } from './utils/error.js';
@@ -476,7 +475,7 @@ test('Loads npm modules in a monorepo setup', async () => {
476
475
  await cleanup();
477
476
  await rm(vendorDirectory.path, { force: true, recursive: true });
478
477
  });
479
- test('Loads JSON modules', async () => {
478
+ test('Loads JSON modules with `with` attribute', async () => {
480
479
  const { basePath, cleanup, distPath } = await useFixture('imports_json');
481
480
  const sourceDirectory = join(basePath, 'functions');
482
481
  const declarations = [
@@ -498,6 +497,35 @@ test('Loads JSON modules', async () => {
498
497
  await cleanup();
499
498
  await rm(vendorDirectory.path, { force: true, recursive: true });
500
499
  });
500
+ // We can't run this on versions above 2.0.0 because the bundling will fail
501
+ // entirely, and what we're asserting here is that we emit a system log when
502
+ // import assertions are detected on successful builds. Also, running it on
503
+ // earlier versions won't work either, since those won't even show a warning.
504
+ test.skipIf(lt(denoVersion, '1.46.3') || gte(denoVersion, '2.0.0'))('Emits a system log when import assertions are used', async () => {
505
+ const { basePath, cleanup, distPath } = await useFixture('with_import_assert');
506
+ const sourceDirectory = join(basePath, 'functions');
507
+ const declarations = [
508
+ {
509
+ function: 'func1',
510
+ path: '/func1',
511
+ },
512
+ ];
513
+ const vendorDirectory = await tmp.dir();
514
+ const systemLogger = vi.fn();
515
+ await bundle([sourceDirectory], distPath, declarations, {
516
+ basePath,
517
+ systemLogger,
518
+ vendorDirectory: vendorDirectory.path,
519
+ });
520
+ const manifestFile = await readFile(resolve(distPath, 'manifest.json'), 'utf8');
521
+ const manifest = JSON.parse(manifestFile);
522
+ const bundlePath = join(distPath, manifest.bundles[0].asset);
523
+ const { func1 } = await runESZIP(bundlePath, vendorDirectory.path);
524
+ expect(func1).toBe(`{"foo":"bar"}`);
525
+ expect(systemLogger).toHaveBeenCalledWith(`Edge function uses import assertions: ${join(sourceDirectory, 'func1.ts')}`);
526
+ await cleanup();
527
+ await rm(vendorDirectory.path, { force: true, recursive: true });
528
+ });
501
529
  test('Supports TSX and process.env', async () => {
502
530
  const { basePath, cleanup, distPath } = await useFixture('tsx');
503
531
  const sourceDirectory = join(basePath, 'functions');
@@ -552,7 +580,6 @@ test('Loads edge functions from the Frameworks API', async () => {
552
580
  });
553
581
  await cleanup();
554
582
  });
555
- const denoVersion = execSync('deno eval --no-lock "console.log(Deno.version.deno)"').toString();
556
583
  describe.skipIf(lt(denoVersion, '2.4.2'))('Produces a tarball bundle', () => {
557
584
  test('With only local imports', async () => {
558
585
  const systemLogger = vi.fn();
@@ -37,10 +37,11 @@ export const getFunctionConfig = async ({ func, importMap, deno, log, }) => {
37
37
  // the config function to write to stdout and stderr without that interfering
38
38
  // with the extractor.
39
39
  const collector = await tmp.file();
40
+ // Retrieving the version of Deno.
41
+ const version = new SemVer((await deno.getBinaryVersion((await deno.getBinaryPath({ silent: true })).path)) || '');
40
42
  // The extractor will use its exit code to signal different error scenarios,
41
43
  // based on the list of exit codes we send as an argument. We then capture
42
44
  // 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)) || '');
44
45
  const { exitCode, stderr, stdout } = await deno.run([
45
46
  'run',
46
47
  '--allow-env',
@@ -57,6 +58,9 @@ export const getFunctionConfig = async ({ func, importMap, deno, log, }) => {
57
58
  pathToFileURL(collector.path).href,
58
59
  JSON.stringify(ConfigExitCode),
59
60
  ].filter(Boolean), { rejectOnExitCode: false });
61
+ if (stderr.includes('Import assertions are deprecated')) {
62
+ log.system(`Edge function uses import assertions: ${func.path}`);
63
+ }
60
64
  if (exitCode !== ConfigExitCode.Success) {
61
65
  handleConfigError(func, exitCode, stderr, log);
62
66
  return {};
@@ -166,7 +166,7 @@ describe('route headers', () => {
166
166
  manifest.routes[0].headers = {
167
167
  'x-custom-header': {
168
168
  matcher: 'regex',
169
- pattern: '^Bearer .+$',
169
+ pattern: 'Bearer .+',
170
170
  },
171
171
  };
172
172
  expect(() => validateManifest(manifest)).not.toThrowError();
@@ -203,7 +203,7 @@ describe('route headers', () => {
203
203
  manifest.routes[0].headers = {
204
204
  'x-custom-header': {
205
205
  matcher: 'regex',
206
- pattern: '/^Bearer .+/',
206
+ pattern: /^Bearer .+/,
207
207
  },
208
208
  };
209
209
  expect(() => validateManifest(manifest)).toThrowErrorMatchingSnapshot();
@@ -66,7 +66,6 @@ declare const edgeManifestSchema: {
66
66
  properties: {
67
67
  pattern: {
68
68
  type: string;
69
- format: string;
70
69
  };
71
70
  matcher: {
72
71
  type: string;
@@ -139,7 +138,6 @@ declare const edgeManifestSchema: {
139
138
  properties: {
140
139
  pattern: {
141
140
  type: string;
142
- format: string;
143
141
  };
144
142
  matcher: {
145
143
  type: string;
@@ -24,7 +24,6 @@ const headersSchema = {
24
24
  properties: {
25
25
  pattern: {
26
26
  type: 'string',
27
- format: 'regexPattern',
28
27
  },
29
28
  matcher: {
30
29
  type: 'string',
@@ -16,4 +16,5 @@ export declare const useFixture: (fixtureName: string, { copyDirectory }?: UseFi
16
16
  export declare const getRouteMatcher: (manifest: Manifest) => (candidate: string) => import("../node/manifest.js").Route | undefined;
17
17
  export declare const runESZIP: (eszipPath: string, vendorDirectory?: string) => Promise<any>;
18
18
  export declare const runTarball: (tarballPath: string) => Promise<any>;
19
+ export declare const denoVersion: string;
19
20
  export {};
package/dist/test/util.js CHANGED
@@ -1,7 +1,8 @@
1
- import { promises as fs } from 'fs';
2
- import { join, resolve } from 'path';
3
- import { stderr, stdout } from 'process';
4
- import { fileURLToPath, pathToFileURL } from 'url';
1
+ import { execSync } from 'node:child_process';
2
+ import { promises as fs } from 'node:fs';
3
+ import { join, resolve } from 'node:path';
4
+ import { stderr, stdout } from 'node:process';
5
+ import { fileURLToPath, pathToFileURL } from 'node:url';
5
6
  import cpy from 'cpy';
6
7
  import { execa } from 'execa';
7
8
  import * as tar from 'tar';
@@ -128,3 +129,4 @@ export const runTarball = async (tarballPath) => {
128
129
  await tmpDir.cleanup();
129
130
  return JSON.parse(result.stdout);
130
131
  };
132
+ export const denoVersion = execSync('deno eval --no-lock "console.log(Deno.version.deno)"').toString();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "14.3.0",
3
+ "version": "14.4.1",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.js",
@@ -68,9 +68,7 @@
68
68
  "esbuild": "0.25.6",
69
69
  "execa": "^8.0.0",
70
70
  "find-up": "^7.0.0",
71
- "get-package-name": "^2.2.0",
72
71
  "get-port": "^7.0.0",
73
- "is-path-inside": "^4.0.0",
74
72
  "node-stream-zip": "^1.15.0",
75
73
  "p-retry": "^6.0.0",
76
74
  "p-wait-for": "^5.0.0",
@@ -82,5 +80,5 @@
82
80
  "urlpattern-polyfill": "8.0.2",
83
81
  "uuid": "^11.0.0"
84
82
  },
85
- "gitHead": "f65a08178a04db0ad274aa62f7d46319f2ef661a"
83
+ "gitHead": "2b427686f1d4cfc2d28b79d4ce18ad691f270d2e"
86
84
  }