@@ -50,30 +50,34 @@ async function buildDenoLambda(
5050 const extname = path . extname ( entrypointPath ) ;
5151 const binName = path . basename ( entrypointPath ) . replace ( extname , '' ) ;
5252 const binPath = path . join ( workPath , binName ) + '.bundle.js' ;
53+ const denoDir = path . join ( workPath , 'layer' , '.deno_dir' ) ;
5354
5455 const { debug } = config ;
5556 console . log ( 'running `deno bundle`...' ) ;
5657 try {
5758 await execa (
58- path . join ( workPath , 'layer' , 'amz- deno' ) ,
59+ path . join ( workPath , 'layer' , 'bin' , ' deno') ,
5960 [ 'bundle' , entrypointPath , binPath ] . concat ( debug ? [ '-L debug' ] : [ ] ) ,
6061 {
6162 env : {
62- DENO_DIR : path . join ( workPath , 'layer' , '.deno_dir' ) ,
63+ DENO_DIR : denoDir ,
6364 } ,
6465 cwd : entrypointDirname ,
6566 stdio : 'inherit' ,
6667 }
6768 ) ;
6869 } catch ( err ) {
69- console . error ( 'failed to `deno bundle`' ) ;
70+ console . error ( 'failed to `deno bundle`:' + err ) ;
7071 throw err ;
7172 }
7273
74+ const denoDirFiles = await getDenoDirFiles ( denoDir ) ;
75+
7376 const lambda = await createLambda ( {
7477 files : {
7578 ...extraFiles ,
7679 ...layerFiles ,
80+ ...denoDirFiles ,
7781 [ binName + '.bundle.js' ] : new FileFsRef ( {
7882 mode : 0o755 ,
7983 fsPath : binPath ,
@@ -83,6 +87,7 @@ async function buildDenoLambda(
8387 runtime : 'provided' ,
8488 environment : {
8589 HANDLER_EXT : 'bundle.js' ,
90+ PATH : process . env . PATH + ':./bin' ,
8691 } ,
8792 } ) ;
8893
@@ -95,6 +100,34 @@ async function buildDenoLambda(
95100 } ;
96101}
97102
103+ async function walk ( dir : string ) : Promise < string [ ] > {
104+ const f = await fs . readdir ( dir ) ;
105+ const files = await Promise . all (
106+ f . map ( async file => {
107+ const filePath = path . join ( dir , file ) ;
108+ const stats = await fs . stat ( filePath ) ;
109+ if ( stats . isDirectory ( ) ) return walk ( filePath ) ;
110+ else if ( stats . isFile ( ) ) return filePath ;
111+ throw 'File not dir or file: ' + filePath ;
112+ } )
113+ ) ;
114+
115+ return files . flat ( ) ;
116+ }
117+
118+ async function getDenoDirFiles ( denoDirPath : string ) : Promise < Files > {
119+ const files : Files = { } ;
120+
121+ const dir = await walk ( denoDirPath ) ;
122+
123+ dir . forEach ( file => {
124+ const f = path . join ( '.deno_dir' , file . replace ( denoDirPath + '/' , '' ) ) ;
125+ files [ f ] = new FileFsRef ( { fsPath : file , mode : 0o755 } ) ;
126+ } ) ;
127+
128+ return files ;
129+ }
130+
98131async function getDenoLambdaLayer ( { workPath } : BuildOptions ) : Promise < Files > {
99132 const zipPath = path . join ( workPath , 'deno-lambda-layer.zip' ) ;
100133 try {
@@ -130,9 +163,9 @@ async function getDenoLambdaLayer({ workPath }: BuildOptions): Promise<Files> {
130163 mode : 0o755 ,
131164 fsPath : path . join ( layerDir , 'bootstrap' ) ,
132165 } ) ,
133- 'amz- deno' : new FileFsRef ( {
166+ 'bin/ deno' : new FileFsRef ( {
134167 mode : 0o755 ,
135- fsPath : path . join ( layerDir , 'amz- deno' ) ,
168+ fsPath : path . join ( layerDir , 'bin/ deno' ) ,
136169 } ) ,
137170 } ;
138171}
0 commit comments