@@ -6,7 +6,7 @@ import type { Protocol } from "jsr:@slack/protocols@0.0.3/types";
66
77import { cleanManifest , getManifest } from "./get_manifest.ts" ;
88import { validateManifestFunctions } from "./utilities.ts" ;
9- import { DenoBundler , EsbuildBundler } from "./bundler/mods.ts" ;
9+ import { Deno2Bundler , DenoBundler , EsbuildBundler } from "./bundler/mods.ts" ;
1010import { BundleError } from "./errors.ts" ;
1111
1212export const validateAndCreateFunctions = async (
@@ -62,7 +62,7 @@ async function resolveDenoConfigPath(
6262 }
6363 }
6464 throw new Error (
65- ` Could not find a deno.json or deno.jsonc file in the current directory.` ,
65+ " Could not find a deno.json or deno.jsonc file in the current directory." ,
6666 ) ;
6767}
6868
@@ -77,29 +77,48 @@ const createFunctionFile = async (
7777 const fnBundledPath = path . join ( outputDirectory , fnFileRelative ) ;
7878
7979 try {
80+ // TODO: Remove this try/catch block once Deno 1.x is no longer supported
8081 await DenoBundler . bundle ( {
8182 entrypoint : fnFilePath ,
8283 outFile : fnBundledPath ,
8384 } ) ;
85+ return ;
8486 } catch ( denoBundleErr ) {
8587 if ( ! ( denoBundleErr instanceof BundleError ) ) {
86- protocol . error ( `Error bundling function file "${ fnId } " with Deno` ) ;
88+ protocol . error ( `Failed to bundle function "${ fnId } " using Deno bundler ` ) ;
8789 throw denoBundleErr ;
8890 }
91+ // TODO: once Protocol can handle debug add a debug statement for the error
92+ }
8993
90- // TODO: once Protocol can handle debug add a debug statement here
91-
92- try {
93- const bundle = await EsbuildBundler . bundle ( {
94- entrypoint : fnFilePath ,
95- absWorkingDir : workingDirectory ,
96- configPath : await resolveDenoConfigPath ( workingDirectory ) ,
97- } ) ;
98- await Deno . writeFile ( fnBundledPath , bundle ) ;
99- } catch ( esbuildError ) {
100- protocol . error ( `Error bundling function file " ${ fnId } " with esbuild` ) ;
101- throw esbuildError ;
94+ try {
95+ await Deno2Bundler . bundle ( {
96+ entrypoint : fnFilePath ,
97+ outFile : fnBundledPath ,
98+ } ) ;
99+ return ;
100+ } catch ( denoBundleErr ) {
101+ if ( ! ( denoBundleErr instanceof BundleError ) ) {
102+ protocol . error (
103+ `Failed to bundle function " ${ fnId } " using Deno2 bundler` ,
104+ ) ;
105+ throw denoBundleErr ;
102106 }
107+ // TODO: once Protocol can handle debug add a debug statement for the error
108+ }
109+
110+ try {
111+ const bundle = await EsbuildBundler . bundle ( {
112+ entrypoint : fnFilePath ,
113+ absWorkingDir : workingDirectory ,
114+ configPath : await resolveDenoConfigPath ( workingDirectory ) ,
115+ } ) ;
116+ await Deno . writeFile ( fnBundledPath , bundle ) ;
117+ } catch ( esbuildError ) {
118+ protocol . error (
119+ `Failed to bundle function "${ fnId } ": Attempt with Deno bundle and esbuild - all failed` ,
120+ ) ;
121+ throw esbuildError ;
103122 }
104123} ;
105124
0 commit comments