@netlify/edge-bundler
Advanced tools
Comparing version 8.19.0 to 8.19.1
@@ -6,2 +6,10 @@ import { writeStage2 } from './lib/stage2.ts' | ||
await writeStage2({ basePath, destPath, externals, functions, importMapData }) | ||
try { | ||
await writeStage2({ basePath, destPath, externals, functions, importMapData }) | ||
} catch (error) { | ||
if (error instanceof Error && error.message.includes("The module's source code could not be parsed")) { | ||
delete error.stack | ||
} | ||
throw error | ||
} |
@@ -1,5 +0,7 @@ | ||
const [functionURL, collectorURL, bootstrapURL, rawExitCodes] = Deno.args | ||
// this needs to be updated whenever there's a change to globalThis.Netlify in bootstrap | ||
import { Netlify } from "https://64e8753eae24930008fac6d9--edge.netlify.app/bootstrap/index-combined.ts" | ||
const [functionURL, collectorURL, rawExitCodes] = Deno.args | ||
const exitCodes = JSON.parse(rawExitCodes) | ||
const { Netlify } = await import(bootstrapURL) | ||
globalThis.Netlify = Netlify | ||
@@ -6,0 +8,0 @@ |
@@ -23,2 +23,6 @@ const getCustomErrorInfo = (options) => ({ | ||
if (input instanceof Error) { | ||
if (input.message.includes("The module's source code could not be parsed")) { | ||
// eslint-disable-next-line no-param-reassign | ||
input.message = input.stderr; | ||
} | ||
return new BundleError(input, options); | ||
@@ -25,0 +29,0 @@ } |
@@ -19,3 +19,3 @@ import { OnAfterDownloadHook, OnBeforeDownloadHook } from './bridge.js'; | ||
} | ||
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<{ | ||
declare const bundle: (sourceDirectories: string[], distDirectory: string, tomlDeclarations?: Declaration[], { basePath: inputBasePath, cacheDirectory, configPath, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMapPaths, onAfterDownload, onBeforeDownload, systemLogger, internalSrcFolder, }?: BundleOptions) => Promise<{ | ||
functions: import("./edge_function.js").EdgeFunction[]; | ||
@@ -22,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, bootstrapURL = 'https://edge.netlify.com/bootstrap/index-combined.ts', } = {}) => { | ||
const bundle = async (sourceDirectories, distDirectory, tomlDeclarations = [], { basePath: inputBasePath, cacheDirectory, configPath, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMapPaths = [], onAfterDownload, onBeforeDownload, systemLogger, internalSrcFolder, } = {}) => { | ||
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, log: logger, bootstrapURL })]); | ||
const userConfigPromises = userFunctions.map(async (func) => [func.name, await getFunctionConfig({ func, importMap, deno, log: logger, bootstrapURL })]); | ||
const internalConfigPromises = internalFunctions.map(async (func) => [func.name, await getFunctionConfig({ func, importMap, deno, log: logger })]); | ||
const userConfigPromises = userFunctions.map(async (func) => [func.name, await getFunctionConfig({ func, importMap, deno, log: logger })]); | ||
// Creating a hash of function names to configuration objects. | ||
@@ -71,0 +71,0 @@ const internalFunctionsWithConfig = Object.fromEntries(await Promise.all(internalConfigPromises)); |
@@ -71,3 +71,4 @@ import { access, readdir, readFile, rm, writeFile } from 'fs/promises'; | ||
test('Adds a custom error property to user errors during bundling', async () => { | ||
expect.assertions(2); | ||
process.env.NO_COLOR = 'true'; | ||
expect.assertions(3); | ||
const { basePath, cleanup, distPath } = await useFixture('invalid_functions'); | ||
@@ -86,2 +87,12 @@ const sourceDirectory = join(basePath, 'functions'); | ||
expect(error).toBeInstanceOf(BundleError); | ||
const [messageBeforeStack] = error.message.split('at <anonymous> (file://'); | ||
expect(messageBeforeStack).toMatchInlineSnapshot(` | ||
"error: Uncaught (in promise) Error: The module's source code could not be parsed: Unexpected eof at file:///root/functions/func1.ts:1:27 | ||
export default async () => | ||
~ | ||
const ret = new Error(getStringFromWasm0(arg0, arg1)); | ||
^ | ||
" | ||
`); | ||
expect(error.customErrorInfo).toEqual({ | ||
@@ -88,0 +99,0 @@ location: { |
@@ -22,8 +22,7 @@ import { DenoBridge } from './bridge.js'; | ||
} | ||
export declare const getFunctionConfig: ({ func, importMap, deno, bootstrapURL, log, }: { | ||
export declare const getFunctionConfig: ({ func, importMap, deno, 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, bootstrapURL, log, }) => { | ||
export const getFunctionConfig = async ({ func, importMap, deno, log, }) => { | ||
// The extractor is a Deno script that will import the function and run its | ||
@@ -54,3 +54,2 @@ // `config` export, if one exists. | ||
pathToFileURL(collector.path).href, | ||
bootstrapURL, | ||
JSON.stringify(ConfigExitCode), | ||
@@ -57,0 +56,0 @@ ], { rejectOnExitCode: false }); |
@@ -12,3 +12,2 @@ import { promises as fs } from 'fs'; | ||
import { ImportMap } from './import_map.js'; | ||
const bootstrapURL = 'https://edge.netlify.com/bootstrap/index-combined.ts'; | ||
const importMapFile = { | ||
@@ -126,3 +125,2 @@ baseURL: new URL('file:///some/path/import-map.json'), | ||
log: logger, | ||
bootstrapURL, | ||
}); | ||
@@ -251,3 +249,2 @@ if (func.error) { | ||
log: logger, | ||
bootstrapURL, | ||
})).resolves.not.toThrow(); | ||
@@ -282,3 +279,2 @@ await rm(tmpDir, { force: true, recursive: true, maxRetries: 10 }); | ||
log: logger, | ||
bootstrapURL, | ||
}); | ||
@@ -313,3 +309,2 @@ await expect(config).rejects.toThrowError(invalidDefaultExportErr(path)); | ||
log: logger, | ||
bootstrapURL, | ||
}); | ||
@@ -316,0 +311,0 @@ await expect(config).rejects.toThrowError(invalidDefaultExportErr(path)); |
@@ -9,3 +9,3 @@ import { Buffer } from 'buffer'; | ||
'@netlify/edge-functions': 'https://edge.netlify.com/v1/index.ts', | ||
'netlify:edge': 'https://edge.netlify.com/v1/index.ts', | ||
'netlify:edge': 'https://edge.netlify.com/v1/index.ts?v=legacy', | ||
}; | ||
@@ -12,0 +12,0 @@ // ImportMap can take several import map files and merge them into a final |
@@ -24,3 +24,4 @@ import { promises as fs } from 'fs'; | ||
const { imports } = map.getContents(); | ||
expect(imports['netlify:edge']).toBe('https://edge.netlify.com/v1/index.ts'); | ||
expect(imports['netlify:edge']).toBe('https://edge.netlify.com/v1/index.ts?v=legacy'); | ||
expect(imports['@netlify/edge-functions']).toBe('https://edge.netlify.com/v1/index.ts'); | ||
expect(imports['alias:jamstack']).toBe('https://jamstack.org/'); | ||
@@ -40,3 +41,4 @@ expect(imports['alias:pets']).toBe('https://petsofnetlify.com/'); | ||
const expectedPath = join(cwd(), 'my-cool-site', 'heart', 'pets'); | ||
expect(imports['netlify:edge']).toBe('https://edge.netlify.com/v1/index.ts'); | ||
expect(imports['netlify:edge']).toBe('https://edge.netlify.com/v1/index.ts?v=legacy'); | ||
expect(imports['@netlify/edge-functions']).toBe('https://edge.netlify.com/v1/index.ts'); | ||
expect(imports['alias:pets']).toBe(`${pathToFileURL(expectedPath).toString()}/`); | ||
@@ -75,3 +77,3 @@ }); | ||
'@netlify/edge-functions': 'https://edge.netlify.com/v1/index.ts', | ||
'netlify:edge': 'https://edge.netlify.com/v1/index.ts', | ||
'netlify:edge': 'https://edge.netlify.com/v1/index.ts?v=legacy', | ||
}); | ||
@@ -98,3 +100,3 @@ expect(scopes).toStrictEqual({ | ||
'@netlify/edge-functions': 'https://edge.netlify.com/v1/index.ts', | ||
'netlify:edge': 'https://edge.netlify.com/v1/index.ts', | ||
'netlify:edge': 'https://edge.netlify.com/v1/index.ts?v=legacy', | ||
}); | ||
@@ -135,4 +137,5 @@ expect(scopes).toStrictEqual({ | ||
await file.cleanup(); | ||
expect(imports['netlify:edge']).toBe('https://edge.netlify.com/v1/index.ts'); | ||
expect(imports['netlify:edge']).toBe('https://edge.netlify.com/v1/index.ts?v=legacy'); | ||
expect(imports['@netlify/edge-functions']).toBe('https://edge.netlify.com/v1/index.ts'); | ||
expect(imports['alias:pets']).toBe(pathToFileURL(expectedPath).toString()); | ||
}); |
@@ -46,3 +46,3 @@ import { tmpName } from 'tmp-promise'; | ||
if (options.getFunctionsConfig) { | ||
functionsConfig = await Promise.all(functions.map((func) => getFunctionConfig({ func, importMap, deno, bootstrapURL, log: logger }))); | ||
functionsConfig = await Promise.all(functions.map((func) => getFunctionConfig({ func, importMap, deno, log: logger }))); | ||
} | ||
@@ -49,0 +49,0 @@ const success = await waitForServer(port, processRef.ps); |
{ | ||
"name": "@netlify/edge-bundler", | ||
"version": "8.19.0", | ||
"version": "8.19.1", | ||
"description": "Intelligently prepare Netlify Edge Functions for deployment", | ||
@@ -5,0 +5,0 @@ "type": "module", |
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
3112826
8204
28