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

@netlify/edge-bundler

Package Overview
Dependencies
Maintainers
19
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 7.0.1 to 7.1.0

4

dist/node/bundler.test.js

@@ -281,6 +281,8 @@ import { promises as fs } from 'fs';

const manifest = JSON.parse(manifestFile);
const { bundles } = manifest;
const { bundles, routes } = manifest;
expect(bundles.length).toBe(1);
expect(bundles[0].format).toBe('eszip2');
expect(generatedFiles.includes(bundles[0].asset)).toBe(true);
// respects excludedPath from deploy config
expect(routes[1].excluded_pattern).toEqual('^/func2/skip/?$');
await cleanup();

@@ -287,0 +289,0 @@ });

@@ -10,5 +10,7 @@ import { FunctionConfig } from './config.js';

path: string;
excludedPath?: string;
};
type DeclarationWithPattern = BaseDeclaration & {
pattern: string;
excludedPattern?: string;
};

@@ -15,0 +17,0 @@ type Declaration = DeclarationWithPath | DeclarationWithPattern;

@@ -95,1 +95,8 @@ import { test, expect } from 'vitest';

});
test('netlify.toml-defined excludedPath are respected', () => {
const tomlConfig = [{ function: 'geolocation', path: '/geo/*', excludedPath: '/geo/exclude' }];
const funcConfig = {};
const expectedDeclarations = [{ function: 'geolocation', path: '/geo/*', excludedPath: '/geo/exclude' }];
const declarations = getDeclarationsFromConfig(tomlConfig, funcConfig, deployConfig);
expect(declarations).toEqual(expectedDeclarations);
});

@@ -12,2 +12,8 @@ import type { Bundle } from './bundle.js';

}
interface Route {
function: string;
name?: string;
pattern: string;
excluded_pattern?: string;
}
interface Manifest {

@@ -24,13 +30,10 @@ bundler_version: string;

}[];
routes: {
function: string;
name?: string;
pattern: string;
}[];
post_cache_routes: {
function: string;
name?: string;
pattern: string;
}[];
routes: Route[];
post_cache_routes: Route[];
}
interface Route {
function: string;
name?: string;
pattern: string;
}
declare const generateManifest: ({ bundles, declarations, functions, importMap, layers, }: GenerateManifestOptions) => Manifest;

@@ -37,0 +40,0 @@ interface WriteManifestOptions {

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

import { nonNullable } from './utils/non_nullable.js';
const serializePattern = (regex) => regex.source.replace(/\\\//g, '/');
const generateManifest = ({ bundles = [], declarations = [], functions, importMap, layers = [], }) => {

@@ -16,8 +17,11 @@ const preCacheRoutes = [];

const pattern = getRegularExpression(declaration);
const serializablePattern = pattern.source.replace(/\\\//g, '/');
const route = {
function: func.name,
name: declaration.name,
pattern: serializablePattern,
pattern: serializePattern(pattern),
};
const excludedPattern = getExcludedRegularExpression(declaration);
if (excludedPattern) {
route.excluded_pattern = serializePattern(excludedPattern);
}
if (declaration.cache === "manual" /* Cache.Manual */) {

@@ -44,9 +48,6 @@ postCacheRoutes.push(route);

};
const getRegularExpression = (declaration) => {
if ('pattern' in declaration) {
return new RegExp(declaration.pattern);
}
const pathToRegularExpression = (path) => {
// We use the global flag so that `globToRegExp` will not wrap the expression
// with `^` and `$`. We'll do that ourselves.
const regularExpression = globToRegExp(declaration.path, { flags: 'g' });
const regularExpression = globToRegExp(path, { flags: 'g' });
// Wrapping the expression source with `^` and `$`. Also, adding an optional

@@ -58,2 +59,16 @@ // trailing slash, so that a declaration of `path: "/foo"` matches requests

};
const getRegularExpression = (declaration) => {
if ('pattern' in declaration) {
return new RegExp(declaration.pattern);
}
return pathToRegularExpression(declaration.path);
};
const getExcludedRegularExpression = (declaration) => {
if ('pattern' in declaration && declaration.excludedPattern) {
return new RegExp(declaration.excludedPattern);
}
if ('path' in declaration && declaration.excludedPath) {
return pathToRegularExpression(declaration.excludedPath);
}
};
const writeManifest = async ({ bundles, declarations = [], distDirectory, functions, importMap, layers, }) => {

@@ -60,0 +75,0 @@ const manifest = generateManifest({ bundles, declarations, functions, importMap, layers });

@@ -45,2 +45,19 @@ import { env } from 'process';

});
test('Generates a manifest with excluded paths and patterns', () => {
const functions = [
{ name: 'func-1', path: '/path/to/func-1.ts' },
{ name: 'func-2', path: '/path/to/func-2.ts' },
];
const declarations = [
{ function: 'func-1', name: 'Display Name', path: '/f1/*', excludedPath: '/f1/exclude' },
{ function: 'func-2', pattern: '^/f2/.*/?$', excludedPattern: '^/f2/exclude$' },
];
const manifest = generateManifest({ bundles: [], declarations, functions });
const expectedRoutes = [
{ function: 'func-1', name: 'Display Name', pattern: '^/f1/.*/?$', excluded_pattern: '^/f1/exclude/?$' },
{ function: 'func-2', pattern: '^/f2/.*/?$', excluded_pattern: '^/f2/exclude$' },
];
expect(manifest.routes).toEqual(expectedRoutes);
expect(manifest.bundler_version).toBe(env.npm_package_version);
});
test('Excludes functions for which there are function files but no matching config declarations', () => {

@@ -47,0 +64,0 @@ const bundle1 = {

{
"name": "@netlify/edge-bundler",
"version": "7.0.1",
"version": "7.1.0",
"description": "Intelligently prepare Netlify Edge Functions for deployment",

@@ -5,0 +5,0 @@ "type": "module",

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