@@ -22,6 +22,7 @@ import { writeManifest } from './manifest.js'
2222import { vendorNPMSpecifiers } from './npm_dependencies.js'
2323import { ensureLatestTypes } from './types.js'
2424import { nonNullable } from './utils/non_nullable.js'
25+ import { BundleError } from './bundle_error.js'
2526
2627export interface BundleOptions {
2728 basePath ?: string
@@ -249,26 +250,35 @@ const getFunctionConfigs = async ({
249250 throw err
250251 }
251252
252- // We failed to extract the configuration because there is an import assert
253- // in the function code, a deprecated feature that we used to support with
254- // Deno 1.x. To avoid a breaking change, we treat this error as a special
255- // case, using the generated ESZIP to extract the configuration. This works
256- // because import asserts are transpiled to import attributes.
257- const extractedESZIP = await extractESZIP ( deno , eszipPath )
258- const configs = await Promise . all (
259- [ ...internalFunctions , ...userFunctions ] . map ( async ( func ) => {
260- const relativePath = relative ( basePath , func . path )
261- const functionPath = join ( extractedESZIP . path , relativePath )
262-
263- return [ func . name , await getFunctionConfig ( { functionPath, importMap, deno, log } ) ] as const
264- } ) ,
265- )
253+ try {
254+ // We failed to extract the configuration because there is an import assert
255+ // in the function code, a deprecated feature that we used to support with
256+ // Deno 1.x. To avoid a breaking change, we treat this error as a special
257+ // case, using the generated ESZIP to extract the configuration. This works
258+ // because import asserts are transpiled to import attributes.
259+ const extractedESZIP = await extractESZIP ( deno , eszipPath )
260+ const configs = await Promise . all (
261+ [ ...internalFunctions , ...userFunctions ] . map ( async ( func ) => {
262+ const relativePath = relative ( basePath , func . path )
263+ const functionPath = join ( extractedESZIP . path , relativePath )
266264
267- await extractedESZIP . cleanup ( )
265+ return [ func . name , await getFunctionConfig ( { functionPath, importMap, deno, log } ) ] as const
266+ } ) ,
267+ )
268268
269- return {
270- internalFunctions : Object . fromEntries ( configs . slice ( 0 , internalFunctions . length ) ) ,
271- userFunctions : Object . fromEntries ( configs . slice ( internalFunctions . length ) ) ,
269+ await extractedESZIP . cleanup ( )
270+
271+ return {
272+ internalFunctions : Object . fromEntries ( configs . slice ( 0 , internalFunctions . length ) ) ,
273+ userFunctions : Object . fromEntries ( configs . slice ( internalFunctions . length ) ) ,
274+ }
275+ } catch ( err ) {
276+ throw new BundleError (
277+ new Error (
278+ 'An error occurred while building an edge function that uses an import assertion. Refer to https://ntl.fyi/import-assert for more information.' ,
279+ ) ,
280+ { cause : err } ,
281+ )
272282 }
273283 }
274284}
0 commit comments