@netlify/edge-bundler
Advanced tools
Comparing version 8.11.1 to 8.12.0
@@ -9,3 +9,3 @@ import { promises as fs } from 'fs'; | ||
import { getFunctionConfig } from './config.js'; | ||
import { getDeclarationsFromConfig } from './declaration.js'; | ||
import { mergeDeclarations } from './declaration.js'; | ||
import { load as loadDeployConfig } from './deploy_config.js'; | ||
@@ -70,3 +70,3 @@ import { getFlags } from './feature_flags.js'; | ||
// deploy configuration API and the in-source configuration. | ||
const declarationsFromConfig = getDeclarationsFromConfig(tomlDeclarations, functionsWithConfig, deployConfig); | ||
const declarationsFromConfig = mergeDeclarations(tomlDeclarations, functionsWithConfig, deployConfig.declarations); | ||
// If any declarations are autogenerated and are missing the generator field | ||
@@ -73,0 +73,0 @@ // add a default string. |
import { FunctionConfig } from './config.js'; | ||
import type { DeployConfig } from './deploy_config.js'; | ||
interface BaseDeclaration { | ||
@@ -17,5 +16,5 @@ cache?: string; | ||
}; | ||
type Declaration = DeclarationWithPath | DeclarationWithPattern; | ||
export declare const getDeclarationsFromConfig: (tomlDeclarations: Declaration[], functionsConfig: Record<string, FunctionConfig>, deployConfig: DeployConfig) => Declaration[]; | ||
export type Declaration = DeclarationWithPath | DeclarationWithPattern; | ||
export declare const mergeDeclarations: (tomlDeclarations: Declaration[], functionsConfig: Record<string, FunctionConfig>, deployConfigDeclarations: Declaration[]) => Declaration[]; | ||
export declare const parsePattern: (pattern: string) => string; | ||
export { Declaration, DeclarationWithPath, DeclarationWithPattern }; | ||
export {}; |
import regexpAST from 'regexp-tree'; | ||
export const getDeclarationsFromConfig = (tomlDeclarations, functionsConfig, deployConfig) => { | ||
export const mergeDeclarations = (tomlDeclarations, functionsConfig, deployConfigDeclarations) => { | ||
var _a; | ||
@@ -10,11 +10,11 @@ const declarations = []; | ||
// takes precedence. | ||
for (const declaration of [...tomlDeclarations, ...deployConfig.declarations]) { | ||
for (const declaration of [...tomlDeclarations, ...deployConfigDeclarations]) { | ||
const config = functionsConfig[declaration.function]; | ||
// If no config is found, add the declaration as is | ||
if (!config) { | ||
// If no config is found, add the declaration as is. | ||
declarations.push(declaration); | ||
// If we have a path specified as either a string or non-empty array | ||
// create a declaration for each path | ||
} | ||
else if ((_a = config.path) === null || _a === void 0 ? void 0 : _a.length) { | ||
// If we have a path specified as either a string or non-empty array, | ||
// create a declaration for each path. | ||
const paths = Array.isArray(config.path) ? config.path : [config.path]; | ||
@@ -24,6 +24,5 @@ paths.forEach((path) => { | ||
}); | ||
// With an in-source config without a path, add the config to the declaration | ||
} | ||
else { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
// With an in-source config without a path, add the config to the declaration. | ||
const { path, excludedPath, ...rest } = config; | ||
@@ -38,3 +37,3 @@ declarations.push({ ...declaration, ...rest }); | ||
const { cache, path } = functionsConfig[name]; | ||
// If we have path specified create a declaration for each path | ||
// If we have a path specified, create a declaration for each path. | ||
if (!functionsVisited.has(name) && path) { | ||
@@ -41,0 +40,0 @@ const paths = Array.isArray(path) ? path : [path]; |
import { test, expect } from 'vitest'; | ||
import { getDeclarationsFromConfig } from './declaration.js'; | ||
import { mergeDeclarations } from './declaration.js'; | ||
// TODO: Add tests with the deploy config. | ||
const deployConfig = { | ||
declarations: [], | ||
layers: [], | ||
}; | ||
const deployConfigDeclarations = []; | ||
test('In-source config takes precedence over netlify.toml config', () => { | ||
@@ -22,3 +19,3 @@ const tomlConfig = [ | ||
]; | ||
const declarations = getDeclarationsFromConfig(tomlConfig, funcConfig, deployConfig); | ||
const declarations = mergeDeclarations(tomlConfig, funcConfig, deployConfigDeclarations); | ||
expect(declarations).toEqual(expectedDeclarations); | ||
@@ -39,3 +36,3 @@ }); | ||
]; | ||
const declarations = getDeclarationsFromConfig(tomlConfig, funcConfig, deployConfig); | ||
const declarations = mergeDeclarations(tomlConfig, funcConfig, deployConfigDeclarations); | ||
expect(declarations).toEqual(expectedDeclarations); | ||
@@ -57,5 +54,5 @@ }); | ||
const expectedDeclarationsWithoutISCPath = [{ function: 'geolocation', path: '/geo', cache: 'off' }]; | ||
const declarationsWithISCPath = getDeclarationsFromConfig(tomlConfig, funcConfigWithPath, deployConfig); | ||
const declarationsWithISCPath = mergeDeclarations(tomlConfig, funcConfigWithPath, deployConfigDeclarations); | ||
expect(declarationsWithISCPath).toEqual(expectedDeclarationsWithISCPath); | ||
const declarationsWithoutISCPath = getDeclarationsFromConfig(tomlConfig, funcConfigWithoutPath, deployConfig); | ||
const declarationsWithoutISCPath = mergeDeclarations(tomlConfig, funcConfigWithoutPath, deployConfigDeclarations); | ||
expect(declarationsWithoutISCPath).toEqual(expectedDeclarationsWithoutISCPath); | ||
@@ -69,3 +66,3 @@ }); | ||
const expectedDeclarations = [{ function: 'geolocation', path: '/geo', cache: 'manual' }]; | ||
expect(getDeclarationsFromConfig(tomlConfig, funcConfig, deployConfig)).toEqual(expectedDeclarations); | ||
expect(mergeDeclarations(tomlConfig, funcConfig, deployConfigDeclarations)).toEqual(expectedDeclarations); | ||
}); | ||
@@ -78,3 +75,3 @@ test("In-source config path property works if it's not an array", () => { | ||
const expectedDeclarations = [{ function: 'json', path: '/json', cache: 'manual' }]; | ||
expect(getDeclarationsFromConfig(tomlConfig, funcConfig, deployConfig)).toEqual(expectedDeclarations); | ||
expect(mergeDeclarations(tomlConfig, funcConfig, deployConfigDeclarations)).toEqual(expectedDeclarations); | ||
}); | ||
@@ -90,3 +87,3 @@ test("In-source config path property works if it's not an array and it's not present in toml or deploy config", () => { | ||
]; | ||
expect(getDeclarationsFromConfig(tomlConfig, funcConfig, deployConfig)).toEqual(expectedDeclarations); | ||
expect(mergeDeclarations(tomlConfig, funcConfig, deployConfigDeclarations)).toEqual(expectedDeclarations); | ||
}); | ||
@@ -99,3 +96,3 @@ test('In-source config works if path property is an empty array with cache value specified', () => { | ||
const expectedDeclarations = [{ function: 'json', path: '/json-toml', cache: 'manual' }]; | ||
expect(getDeclarationsFromConfig(tomlConfig, funcConfig, deployConfig)).toEqual(expectedDeclarations); | ||
expect(mergeDeclarations(tomlConfig, funcConfig, deployConfigDeclarations)).toEqual(expectedDeclarations); | ||
}); | ||
@@ -106,4 +103,4 @@ test('netlify.toml-defined excludedPath are respected', () => { | ||
const expectedDeclarations = [{ function: 'geolocation', path: '/geo/*', excludedPath: '/geo/exclude' }]; | ||
const declarations = getDeclarationsFromConfig(tomlConfig, funcConfig, deployConfig); | ||
const declarations = mergeDeclarations(tomlConfig, funcConfig, deployConfigDeclarations); | ||
expect(declarations).toEqual(expectedDeclarations); | ||
}); |
import { EdgeFunction } from '../edge_function.js'; | ||
import type { FormatFunction } from '../server/server.js'; | ||
interface GenerateStage2Options { | ||
bootstrapURL: string; | ||
distDirectory: string; | ||
@@ -10,9 +11,9 @@ fileName: string; | ||
} | ||
declare const generateStage2: ({ distDirectory, fileName, formatExportTypeError, formatImportError, functions, }: GenerateStage2Options) => Promise<string>; | ||
declare const getBootstrapURL: () => string; | ||
declare const generateStage2: ({ bootstrapURL, distDirectory, fileName, formatExportTypeError, formatImportError, functions, }: GenerateStage2Options) => Promise<string>; | ||
interface GetLocalEntryPointOptions { | ||
bootstrapURL: string; | ||
formatExportTypeError?: FormatFunction; | ||
formatImportError?: FormatFunction; | ||
} | ||
declare const getLocalEntryPoint: (functions: EdgeFunction[], { formatExportTypeError, formatImportError, }: GetLocalEntryPointOptions) => string; | ||
export { generateStage2, getBootstrapURL, getLocalEntryPoint }; | ||
declare const getLocalEntryPoint: (functions: EdgeFunction[], { bootstrapURL, formatExportTypeError, formatImportError, }: GetLocalEntryPointOptions) => string; | ||
export { generateStage2, getLocalEntryPoint }; |
import { promises as fs } from 'fs'; | ||
import { join } from 'path'; | ||
import { env } from 'process'; | ||
import { pathToFileURL } from 'url'; | ||
import { deleteAsync } from 'del'; | ||
const BOOTSTRAP_LATEST = 'https://640b5b066a2b9b0008e88cb0--edge.netlify.com/bootstrap/index-combined.ts'; | ||
const defaultFormatExportTypeError = (name) => `The Edge Function "${name}" has failed to load. Does it have a function as the default export?`; | ||
const defaultFormatImpoortError = (name) => `There was an error with Edge Function "${name}".`; | ||
const generateStage2 = async ({ distDirectory, fileName, formatExportTypeError, formatImportError, functions, }) => { | ||
const generateStage2 = async ({ bootstrapURL, distDirectory, fileName, formatExportTypeError, formatImportError, functions, }) => { | ||
await deleteAsync(distDirectory, { force: true }); | ||
await fs.mkdir(distDirectory, { recursive: true }); | ||
const entryPoint = getLocalEntryPoint(functions, { formatExportTypeError, formatImportError }); | ||
const entryPoint = getLocalEntryPoint(functions, { bootstrapURL, formatExportTypeError, formatImportError }); | ||
const stage2Path = join(distDirectory, fileName); | ||
@@ -17,8 +15,7 @@ await fs.writeFile(stage2Path, entryPoint); | ||
}; | ||
const getBootstrapURL = () => { var _a; return (_a = env.NETLIFY_EDGE_BOOTSTRAP) !== null && _a !== void 0 ? _a : BOOTSTRAP_LATEST; }; | ||
// For the local development environment, we import the user functions with | ||
// dynamic imports to gracefully handle the case where the file doesn't have | ||
// a valid default export. | ||
const getLocalEntryPoint = (functions, { formatExportTypeError = defaultFormatExportTypeError, formatImportError = defaultFormatImpoortError, }) => { | ||
const bootImport = `import { boot } from "${getBootstrapURL()}";`; | ||
const getLocalEntryPoint = (functions, { bootstrapURL, formatExportTypeError = defaultFormatExportTypeError, formatImportError = defaultFormatImpoortError, }) => { | ||
const bootImport = `import { boot } from "${bootstrapURL}";`; | ||
const declaration = `const functions = {}; const metadata = { functions: {} };`; | ||
@@ -49,2 +46,2 @@ const imports = functions.map((func) => { | ||
}; | ||
export { generateStage2, getBootstrapURL, getLocalEntryPoint }; | ||
export { generateStage2, getLocalEntryPoint }; |
export { bundle } from './bundler.js'; | ||
export { DenoBridge } from './bridge.js'; | ||
export type { FunctionConfig } from './config.js'; | ||
export { Declaration, mergeDeclarations } from './declaration.js'; | ||
export type { EdgeFunction } from './edge_function.js'; | ||
export { findFunctions as find } from './finder.js'; | ||
@@ -4,0 +7,0 @@ export { generateManifest } from './manifest.js'; |
export { bundle } from './bundler.js'; | ||
export { DenoBridge } from './bridge.js'; | ||
export { mergeDeclarations } from './declaration.js'; | ||
export { findFunctions as find } from './finder.js'; | ||
@@ -4,0 +5,0 @@ export { generateManifest } from './manifest.js'; |
@@ -20,2 +20,3 @@ /// <reference types="node" /> | ||
interface ServeOptions { | ||
bootstrapURL: string; | ||
certificatePath?: string; | ||
@@ -33,3 +34,3 @@ debug?: boolean; | ||
} | ||
declare const serve: ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMapPaths, onAfterDownload, onBeforeDownload, port, systemLogger, }: ServeOptions) => Promise<(functions: EdgeFunction[], env?: NodeJS.ProcessEnv, options?: StartServerOptions) => Promise<{ | ||
declare const serve: ({ bootstrapURL, certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMapPaths, onAfterDownload, onBeforeDownload, port, systemLogger, }: ServeOptions) => Promise<(functions: EdgeFunction[], env?: NodeJS.ProcessEnv, options?: StartServerOptions) => Promise<{ | ||
functionsConfig: FunctionConfig[]; | ||
@@ -36,0 +37,0 @@ graph: any; |
@@ -9,3 +9,3 @@ import { tmpName } from 'tmp-promise'; | ||
import { killProcess, waitForServer } from './util.js'; | ||
const prepareServer = ({ deno, distDirectory, flags: denoFlags, formatExportTypeError, formatImportError, importMap, logger, port, }) => { | ||
const prepareServer = ({ bootstrapURL, deno, distDirectory, flags: denoFlags, formatExportTypeError, formatImportError, importMap, logger, port, }) => { | ||
const processRef = {}; | ||
@@ -18,2 +18,3 @@ const startServer = async (functions, env = {}, options = {}) => { | ||
const stage2Path = await generateStage2({ | ||
bootstrapURL, | ||
distDirectory, | ||
@@ -58,3 +59,3 @@ fileName: 'dev.js', | ||
}; | ||
const serve = async ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMapPaths = [], onAfterDownload, onBeforeDownload, port, systemLogger, }) => { | ||
const serve = async ({ bootstrapURL, certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMapPaths = [], onAfterDownload, onBeforeDownload, port, systemLogger, }) => { | ||
const logger = getLogger(systemLogger, debug); | ||
@@ -95,2 +96,3 @@ const deno = new DenoBridge({ | ||
const server = prepareServer({ | ||
bootstrapURL, | ||
deno, | ||
@@ -97,0 +99,0 @@ distDirectory, |
@@ -17,2 +17,3 @@ import { join } from 'path'; | ||
const server = await serve({ | ||
bootstrapURL: 'https://edge.netlify.com/bootstrap/index-combined.ts', | ||
importMapPaths, | ||
@@ -19,0 +20,0 @@ port, |
import { promises as fs } from 'fs'; | ||
import { join } from 'path'; | ||
import process from 'process'; | ||
import { pathToFileURL } from 'url'; | ||
@@ -26,4 +25,4 @@ import { deleteAsync } from 'del'; | ||
const printerPath = join(tmpDir, 'printer.mjs'); | ||
const bootstrapURL = pathToFileURL(printerPath).toString(); | ||
await fs.writeFile(printerPath, printer); | ||
process.env.NETLIFY_EDGE_BOOTSTRAP = pathToFileURL(printerPath).toString(); | ||
const functions = [ | ||
@@ -37,3 +36,3 @@ { name: 'func1', path: join(tmpDir, 'func1.mjs'), response: 'Hello from function 1' }, | ||
} | ||
const stage2 = getLocalEntryPoint(functions.map(({ name, path }) => ({ name, path })), {}); | ||
const stage2 = getLocalEntryPoint(functions.map(({ name, path }) => ({ name, path })), { bootstrapURL }); | ||
const stage2Path = join(tmpDir, 'stage2.mjs'); | ||
@@ -49,3 +48,2 @@ await fs.writeFile(stage2Path, stage2); | ||
await deleteAsync(tmpDir, { force: true }); | ||
delete process.env.NETLIFY_EDGE_BOOTSTRAP; | ||
}); |
{ | ||
"name": "@netlify/edge-bundler", | ||
"version": "8.11.1", | ||
"version": "8.12.0", | ||
"description": "Intelligently prepare Netlify Edge Functions for deployment", | ||
@@ -5,0 +5,0 @@ "type": "module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
26
8
3067665
149
7583