Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@netlify/edge-bundler

Package Overview
Dependencies
Maintainers
18
Versions
134
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@netlify/edge-bundler - npm Package Compare versions

Comparing version 5.5.0 to 6.0.0

dist/node/deno_config.d.ts

13

dist/node/bundler.js

@@ -9,2 +9,3 @@ import { promises as fs } from 'fs';

import { getDeclarationsFromConfig } from './declaration.js';
import { getConfig as getDenoConfig } from './deno_config.js';
import { load as loadDeployConfig } from './deploy_config.js';

@@ -14,3 +15,3 @@ import { getFlags } from './feature_flags.js';

import { bundle as bundleESZIP } from './formats/eszip.js';
import { ImportMap } from './import_map.js';
import { ImportMap, readFile as readImportMapFile } from './import_map.js';
import { getLogger } from './logger.js';

@@ -49,2 +50,12 @@ import { writeManifest } from './manifest.js';

}
if (featureFlags.edge_functions_read_deno_config) {
// Look for a Deno config file and read it if one exists.
const denoConfig = await getDenoConfig(basePath);
// If the Deno config file defines an import map, read the file and add the
// imports to the global import map.
if (denoConfig === null || denoConfig === void 0 ? void 0 : denoConfig.importMap) {
const importMapFile = await readImportMapFile(denoConfig.importMap);
importMap.add(importMapFile);
}
}
const functions = await findFunctions(sourceDirectories);

@@ -51,0 +62,0 @@ const functionBundle = await bundleESZIP({

12

dist/node/bundler.test.js

@@ -21,9 +21,13 @@ import { promises as fs } from 'fs';

];
const sourceDirectory = join(basePath, 'functions');
const result = await bundle([sourceDirectory], distPath, declarations, {
const userDirectory = join(basePath, 'user-functions');
const internalDirectory = join(basePath, 'functions');
const result = await bundle([userDirectory, internalDirectory], distPath, declarations, {
basePath,
configPath: join(sourceDirectory, 'config.json'),
configPath: join(internalDirectory, 'config.json'),
featureFlags: {
edge_functions_read_deno_config: true,
},
});
const generatedFiles = await fs.readdir(distPath);
expect(result.functions.length).toBe(1);
expect(result.functions.length).toBe(2);
expect(generatedFiles.length).toBe(2);

@@ -30,0 +34,0 @@ const manifestFile = await fs.readFile(resolve(distPath, 'manifest.json'), 'utf8');

const defaultFlags = {
edge_functions_cache_deno_dir: false,
edge_functions_config_export: false,
edge_functions_read_deno_config: false,
};

@@ -5,0 +6,0 @@ const getFlags = (input = {}, flags = defaultFlags) => Object.entries(flags).reduce((result, [key, defaultValue]) => ({

@@ -21,2 +21,3 @@ /// <reference types="node" />

interface ServeOptions {
basePath: string;
certificatePath?: string;

@@ -34,3 +35,3 @@ debug?: boolean;

}
declare const serve: ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, systemLogger, }: ServeOptions) => Promise<(functions: EdgeFunction[], env?: NodeJS.ProcessEnv, options?: StartServerOptions) => Promise<{
declare const serve: ({ basePath, certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, systemLogger, }: ServeOptions) => Promise<(functions: EdgeFunction[], env?: NodeJS.ProcessEnv, options?: StartServerOptions) => Promise<{
functionsConfig: FunctionConfig[];

@@ -37,0 +38,0 @@ graph: any;

import { tmpName } from 'tmp-promise';
import { DenoBridge } from '../bridge.js';
import { getFunctionConfig } from '../config.js';
import { getConfig as getDenoConfig } from '../deno_config.js';
import { generateStage2 } from '../formats/javascript.js';
import { ImportMap } from '../import_map.js';
import { ImportMap, readFile as readImportMapFile } from '../import_map.js';
import { getLogger } from '../logger.js';

@@ -56,3 +57,3 @@ import { ensureLatestTypes } from '../types.js';

};
const serve = async ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, systemLogger, }) => {
const serve = async ({ basePath, certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, systemLogger, }) => {
const logger = getLogger(systemLogger, debug);

@@ -75,2 +76,10 @@ const deno = new DenoBridge({

const importMap = new ImportMap(importMaps);
// Look for a Deno config file and read it if one exists.
const denoConfig = await getDenoConfig(basePath);
// If the Deno config file defines an import map, read the file and add the
// imports to the global import map.
if (denoConfig === null || denoConfig === void 0 ? void 0 : denoConfig.importMap) {
const importMapFile = await readImportMapFile(denoConfig.importMap);
importMap.add(importMapFile);
}
const flags = ['--allow-all', '--unstable', `--import-map=${importMap.toDataURL()}`, '--no-config'];

@@ -77,0 +86,0 @@ if (certificatePath) {

import { join } from 'path';
import { pathToFileURL } from 'url';
import getPort from 'get-port';
import fetch from 'node-fetch';
import { v4 as uuidv4 } from 'uuid';
import { test, expect } from 'vitest';

@@ -8,12 +10,28 @@ import { fixturesDir } from '../../test/util.js';

test('Starts a server and serves requests for edge functions', async () => {
const basePath = join(fixturesDir, 'serve_test');
const functionPaths = {
internal: join(basePath, '.netlify', 'edge-functions', 'greet.ts'),
user: join(basePath, 'netlify', 'edge-functions', 'echo_env.ts'),
};
const port = await getPort();
const internalImportMap = {
baseURL: pathToFileURL(functionPaths.internal),
imports: {
'internal-helper': '../../helper.ts',
},
};
const server = await serve({
basePath,
importMaps: [internalImportMap],
port,
});
const functionPath = join(fixturesDir, 'serve_test', 'echo_env.ts');
const functions = [
{
name: 'echo_env',
path: functionPath,
path: functionPaths.user,
},
{
name: 'greet',
path: functionPaths.internal,
},
];

@@ -27,17 +45,27 @@ const options = {

expect(success).toBe(true);
expect(functionsConfig).toEqual([{ path: '/my-function' }]);
const graphEntry = graph === null || graph === void 0 ? void 0 : graph.modules.some(
// @ts-expect-error TODO: Module graph is currently not typed
({ kind, mediaType, local }) => kind === 'esm' && mediaType === 'TypeScript' && local === functionPath);
expect(graphEntry).toBe(true);
const response = await fetch(`http://0.0.0.0:${port}/foo`, {
expect(functionsConfig).toEqual([{ path: '/my-function' }, {}]);
for (const key in functionPaths) {
const graphEntry = graph === null || graph === void 0 ? void 0 : graph.modules.some(
// @ts-expect-error TODO: Module graph is currently not typed
({ kind, mediaType, local }) => kind === 'esm' && mediaType === 'TypeScript' && local === functionPaths[key]);
expect(graphEntry).toBe(true);
}
const response1 = await fetch(`http://0.0.0.0:${port}/foo`, {
headers: {
'x-deno-functions': 'echo_env',
'x-deno-pass': 'passthrough',
'X-NF-Request-ID': 'foo',
'X-NF-Request-ID': uuidv4(),
},
});
expect(response.status).toBe(200);
const body = (await response.json());
expect(body.very_secret_secret).toBe('i love netlify');
expect(response1.status).toBe(200);
expect(await response1.text()).toBe('I LOVE NETLIFY');
const response2 = await fetch(`http://0.0.0.0:${port}/greet`, {
headers: {
'x-deno-functions': 'greet',
'x-deno-pass': 'passthrough',
'X-NF-Request-ID': uuidv4(),
},
});
expect(response2.status).toBe(200);
expect(await response2.text()).toBe('HELLO!');
});
{
"name": "@netlify/edge-bundler",
"version": "5.5.0",
"version": "6.0.0",
"description": "Intelligently prepare Netlify Edge Functions for deployment",

@@ -87,2 +87,3 @@ "type": "module",

"glob-to-regexp": "^0.4.1",
"jsonc-parser": "^3.2.0",
"node-fetch": "^3.1.1",

@@ -89,0 +90,0 @@ "node-stream-zip": "^1.15.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc