@netlify/edge-bundler 14.3.0 → 14.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.
- package/dist/node/bundler.test.js +32 -5
- package/dist/node/config.js +5 -1
- package/dist/test/util.d.ts +1 -0
- package/dist/test/util.js +6 -4
- package/package.json +2 -2
|
@@ -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();
|
package/dist/node/config.js
CHANGED
|
@@ -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 {};
|
package/dist/test/util.d.ts
CHANGED
|
@@ -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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
+
"version": "14.4.0",
|
|
4
4
|
"description": "Intelligently prepare Netlify Edge Functions for deployment",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/node/index.js",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"urlpattern-polyfill": "8.0.2",
|
|
83
83
|
"uuid": "^11.0.0"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "1f098009f518b66b0d6604910aff38824d7f9a69"
|
|
86
86
|
}
|