@netlify/edge-bundler
Advanced tools
Comparing version 8.17.0 to 8.17.1
@@ -1,4 +0,7 @@ | ||
const [functionURL, collectorURL, rawExitCodes] = Deno.args | ||
const [functionURL, collectorURL, bootstrapURL, rawExitCodes] = Deno.args | ||
const exitCodes = JSON.parse(rawExitCodes) | ||
const { Netlify } = await import(bootstrapURL) | ||
globalThis.Netlify = Netlify | ||
let func | ||
@@ -5,0 +8,0 @@ |
@@ -17,4 +17,5 @@ import { OnAfterDownloadHook, OnBeforeDownloadHook } from './bridge.js'; | ||
internalSrcFolder?: string; | ||
bootstrapURL?: string; | ||
} | ||
declare const bundle: (sourceDirectories: string[], distDirectory: string, tomlDeclarations?: Declaration[], { basePath: inputBasePath, cacheDirectory, configPath, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMapPaths, onAfterDownload, onBeforeDownload, systemLogger, internalSrcFolder, }?: BundleOptions) => Promise<{ | ||
declare const bundle: (sourceDirectories: string[], distDirectory: string, tomlDeclarations?: Declaration[], { basePath: inputBasePath, cacheDirectory, configPath, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMapPaths, onAfterDownload, onBeforeDownload, systemLogger, internalSrcFolder, bootstrapURL, }?: BundleOptions) => Promise<{ | ||
functions: import("./edge_function.js").EdgeFunction[]; | ||
@@ -21,0 +22,0 @@ manifest: import("./manifest.js").Manifest; |
@@ -17,3 +17,3 @@ import { promises as fs } from 'fs'; | ||
import { ensureLatestTypes } from './types.js'; | ||
const bundle = async (sourceDirectories, distDirectory, tomlDeclarations = [], { basePath: inputBasePath, cacheDirectory, configPath, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMapPaths = [], onAfterDownload, onBeforeDownload, systemLogger, internalSrcFolder, } = {}) => { | ||
const bundle = async (sourceDirectories, distDirectory, tomlDeclarations = [], { basePath: inputBasePath, cacheDirectory, configPath, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMapPaths = [], onAfterDownload, onBeforeDownload, systemLogger, internalSrcFolder, bootstrapURL = 'https://edge.netlify.com/bootstrap/index-combined.ts', } = {}) => { | ||
const logger = getLogger(systemLogger, debug); | ||
@@ -67,4 +67,4 @@ const featureFlags = getFlags(inputFeatureFlags); | ||
// Run `getFunctionConfig` in parallel as it is a non-trivial operation and spins up deno | ||
const internalConfigPromises = internalFunctions.map(async (func) => [func.name, await getFunctionConfig(func, importMap, deno, logger)]); | ||
const userConfigPromises = userFunctions.map(async (func) => [func.name, await getFunctionConfig(func, importMap, deno, logger)]); | ||
const internalConfigPromises = internalFunctions.map(async (func) => [func.name, await getFunctionConfig({ func, importMap, deno, log: logger, bootstrapURL })]); | ||
const userConfigPromises = userFunctions.map(async (func) => [func.name, await getFunctionConfig({ func, importMap, deno, log: logger, bootstrapURL })]); | ||
// Creating a hash of function names to configuration objects. | ||
@@ -71,0 +71,0 @@ const internalFunctionsWithConfig = Object.fromEntries(await Promise.all(internalConfigPromises)); |
@@ -20,2 +20,8 @@ import { DenoBridge } from './bridge.js'; | ||
} | ||
export declare const getFunctionConfig: (func: EdgeFunction, importMap: ImportMap, deno: DenoBridge, log: Logger) => Promise<FunctionConfig>; | ||
export declare const getFunctionConfig: ({ func, importMap, deno, bootstrapURL, log, }: { | ||
func: EdgeFunction; | ||
importMap: ImportMap; | ||
deno: DenoBridge; | ||
bootstrapURL: string; | ||
log: Logger; | ||
}) => Promise<FunctionConfig>; |
@@ -29,3 +29,3 @@ import { promises as fs } from 'fs'; | ||
}; | ||
export const getFunctionConfig = async (func, importMap, deno, log) => { | ||
export const getFunctionConfig = async ({ func, importMap, deno, bootstrapURL, log, }) => { | ||
// The extractor is a Deno script that will import the function and run its | ||
@@ -54,2 +54,3 @@ // `config` export, if one exists. | ||
pathToFileURL(collector.path).href, | ||
bootstrapURL, | ||
JSON.stringify(ConfigExitCode), | ||
@@ -56,0 +57,0 @@ ], { rejectOnExitCode: false }); |
@@ -12,2 +12,3 @@ import { promises as fs } from 'fs'; | ||
import { ImportMap } from './import_map.js'; | ||
const bootstrapURL = 'https://edge.netlify.com/bootstrap/index-combined.ts'; | ||
const importMapFile = { | ||
@@ -118,5 +119,11 @@ baseURL: new URL('file:///some/path/import-map.json'), | ||
const funcCall = () => getFunctionConfig({ | ||
name: func.name, | ||
path, | ||
}, new ImportMap([importMapFile]), deno, logger); | ||
func: { | ||
name: func.name, | ||
path, | ||
}, | ||
importMap: new ImportMap([importMapFile]), | ||
deno, | ||
log: logger, | ||
bootstrapURL, | ||
}); | ||
if (func.error) { | ||
@@ -199,5 +206,11 @@ await expect(funcCall()).rejects.toThrowError(func.error); | ||
await expect(getFunctionConfig({ | ||
name: func.name, | ||
path, | ||
}, new ImportMap([importMapFile]), deno, logger)).resolves.not.toThrow(); | ||
func: { | ||
name: func.name, | ||
path, | ||
}, | ||
importMap: new ImportMap([importMapFile]), | ||
deno, | ||
log: logger, | ||
bootstrapURL, | ||
})).resolves.not.toThrow(); | ||
await rm(tmpDir, { force: true, recursive: true, maxRetries: 10 }); | ||
@@ -224,5 +237,11 @@ }); | ||
const config = getFunctionConfig({ | ||
name: func.name, | ||
path, | ||
}, new ImportMap([importMapFile]), deno, logger); | ||
func: { | ||
name: func.name, | ||
path, | ||
}, | ||
importMap: new ImportMap([importMapFile]), | ||
deno, | ||
log: logger, | ||
bootstrapURL, | ||
}); | ||
await expect(config).rejects.toThrowError(invalidDefaultExportErr(path)); | ||
@@ -249,7 +268,13 @@ await rm(tmpDir, { force: true, recursive: true, maxRetries: 10 }); | ||
const config = getFunctionConfig({ | ||
name: func.name, | ||
path, | ||
}, new ImportMap([importMapFile]), deno, logger); | ||
func: { | ||
name: func.name, | ||
path, | ||
}, | ||
importMap: new ImportMap([importMapFile]), | ||
deno, | ||
log: logger, | ||
bootstrapURL, | ||
}); | ||
await expect(config).rejects.toThrowError(invalidDefaultExportErr(path)); | ||
await rm(tmpDir, { force: true, recursive: true, maxRetries: 10 }); | ||
}); |
@@ -69,3 +69,8 @@ import regexpAST from 'regexp-tree'; | ||
export const parsePattern = (pattern) => { | ||
const regexp = new RegExp(pattern); | ||
let enclosedPattern = pattern; | ||
if (!pattern.startsWith('^')) | ||
enclosedPattern = `^${enclosedPattern}`; | ||
if (!pattern.endsWith('$')) | ||
enclosedPattern = `${enclosedPattern}$`; | ||
const regexp = new RegExp(enclosedPattern); | ||
const newRegexp = regexpAST.transform(regexp, { | ||
@@ -72,0 +77,0 @@ Assertion(path) { |
@@ -129,1 +129,7 @@ import { test, expect } from 'vitest'; | ||
}); | ||
test('Ensures pattern match on the whole path', () => { | ||
const regexPattern = '/foo/.*/bar'; | ||
const expected = '^\\/foo\\/.*\\/bar$'; | ||
const actual = parsePattern(regexPattern); | ||
expect(actual).toEqual(expected); | ||
}); |
@@ -46,3 +46,3 @@ import { tmpName } from 'tmp-promise'; | ||
if (options.getFunctionsConfig) { | ||
functionsConfig = await Promise.all(functions.map((func) => getFunctionConfig(func, importMap, deno, logger))); | ||
functionsConfig = await Promise.all(functions.map((func) => getFunctionConfig({ func, importMap, deno, bootstrapURL, log: logger }))); | ||
} | ||
@@ -49,0 +49,0 @@ const success = await waitForServer(port, processRef.ps); |
@@ -30,2 +30,6 @@ import { join } from 'path'; | ||
}, | ||
{ | ||
name: 'global_netlify', | ||
path: join(paths.user, 'global_netlify.ts'), | ||
}, | ||
]; | ||
@@ -39,3 +43,3 @@ const options = { | ||
expect(success).toBe(true); | ||
expect(functionsConfig).toEqual([{ path: '/my-function' }, {}]); | ||
expect(functionsConfig).toEqual([{ path: '/my-function' }, {}, { path: '/global-netlify' }]); | ||
for (const key in functions) { | ||
@@ -65,2 +69,13 @@ const graphEntry = graph === null || graph === void 0 ? void 0 : graph.modules.some( | ||
expect(await response2.text()).toBe('HELLO!'); | ||
const response3 = await fetch(`http://0.0.0.0:${port}/global-netlify`, { | ||
headers: { | ||
'x-nf-edge-functions': 'global_netlify', | ||
'x-ef-passthrough': 'passthrough', | ||
'X-NF-Request-ID': uuidv4(), | ||
}, | ||
}); | ||
expect(await response3.json()).toEqual({ | ||
global: 'i love netlify', | ||
local: 'i love netlify', | ||
}); | ||
}); |
{ | ||
"name": "@netlify/edge-bundler", | ||
"version": "8.17.0", | ||
"version": "8.17.1", | ||
"description": "Intelligently prepare Netlify Edge Functions for deployment", | ||
@@ -5,0 +5,0 @@ "type": "module", |
3105680
7985
8