@@ -50,30 +50,34 @@ async function buildDenoLambda(
50
50
const extname = path . extname ( entrypointPath ) ;
51
51
const binName = path . basename ( entrypointPath ) . replace ( extname , '' ) ;
52
52
const binPath = path . join ( workPath , binName ) + '.bundle.js' ;
53
+ const denoDir = path . join ( workPath , 'layer' , '.deno_dir' ) ;
53
54
54
55
const { debug } = config ;
55
56
console . log ( 'running `deno bundle`...' ) ;
56
57
try {
57
58
await execa (
58
- path . join ( workPath , 'layer' , 'amz- deno' ) ,
59
+ path . join ( workPath , 'layer' , 'bin' , ' deno') ,
59
60
[ 'bundle' , entrypointPath , binPath ] . concat ( debug ? [ '-L debug' ] : [ ] ) ,
60
61
{
61
62
env : {
62
- DENO_DIR : path . join ( workPath , 'layer' , '.deno_dir' ) ,
63
+ DENO_DIR : denoDir ,
63
64
} ,
64
65
cwd : entrypointDirname ,
65
66
stdio : 'inherit' ,
66
67
}
67
68
) ;
68
69
} catch ( err ) {
69
- console . error ( 'failed to `deno bundle`' ) ;
70
+ console . error ( 'failed to `deno bundle`:' + err ) ;
70
71
throw err ;
71
72
}
72
73
74
+ const denoDirFiles = await getDenoDirFiles ( denoDir ) ;
75
+
73
76
const lambda = await createLambda ( {
74
77
files : {
75
78
...extraFiles ,
76
79
...layerFiles ,
80
+ ...denoDirFiles ,
77
81
[ binName + '.bundle.js' ] : new FileFsRef ( {
78
82
mode : 0o755 ,
79
83
fsPath : binPath ,
@@ -83,6 +87,7 @@ async function buildDenoLambda(
83
87
runtime : 'provided' ,
84
88
environment : {
85
89
HANDLER_EXT : 'bundle.js' ,
90
+ PATH : process . env . PATH + ':./bin' ,
86
91
} ,
87
92
} ) ;
88
93
@@ -95,6 +100,34 @@ async function buildDenoLambda(
95
100
} ;
96
101
}
97
102
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
+
98
131
async function getDenoLambdaLayer ( { workPath } : BuildOptions ) : Promise < Files > {
99
132
const zipPath = path . join ( workPath , 'deno-lambda-layer.zip' ) ;
100
133
try {
@@ -130,9 +163,9 @@ async function getDenoLambdaLayer({ workPath }: BuildOptions): Promise<Files> {
130
163
mode : 0o755 ,
131
164
fsPath : path . join ( layerDir , 'bootstrap' ) ,
132
165
} ) ,
133
- 'amz- deno' : new FileFsRef ( {
166
+ 'bin/ deno' : new FileFsRef ( {
134
167
mode : 0o755 ,
135
- fsPath : path . join ( layerDir , 'amz- deno' ) ,
168
+ fsPath : path . join ( layerDir , 'bin/ deno' ) ,
136
169
} ) ,
137
170
} ;
138
171
}
0 commit comments