@@ -21,7 +21,7 @@ const {
21
21
* @return {string[][] } a list of valid commands.
22
22
*/
23
23
function filterCommands ( commands ) {
24
- return commands . filter ( ( cmd ) => Boolean ( cmd ) && cmd . length > 0 ) ;
24
+ return commands . filter ( cmd => Boolean ( cmd ) && cmd . length > 0 ) ;
25
25
}
26
26
27
27
/**
@@ -34,13 +34,13 @@ function filterCommands(commands) {
34
34
function mergeCommands ( commands ) {
35
35
const cmds = filterCommands ( commands ) ;
36
36
if ( cmds . length === 0 ) {
37
- throw new Error ( 'Expected at least one non-empty command' )
37
+ throw new Error ( 'Expected at least one non-empty command' ) ;
38
38
} else if ( cmds . length === 1 ) {
39
39
return cmds [ 0 ] ;
40
40
} else {
41
41
// Quote the arguments in each command and join them all using &&.
42
42
const script = cmds . map ( quote ) . join ( ' && ' ) ;
43
- return [ " /bin/sh" , "-c" , script ] ;
43
+ return [ ' /bin/sh' , '-c' , script ] ;
44
44
}
45
45
}
46
46
@@ -79,17 +79,10 @@ function installRequirementsFile(
79
79
80
80
function pipAcceptsSystem ( pythonBin ) {
81
81
// Check if pip has Debian's --system option and set it if so
82
- const pipTestRes = spawnSync ( pythonBin , [
83
- '-m' ,
84
- 'pip' ,
85
- 'help' ,
86
- 'install'
87
- ] ) ;
82
+ const pipTestRes = spawnSync ( pythonBin , [ '-m' , 'pip' , 'help' , 'install' ] ) ;
88
83
if ( pipTestRes . error ) {
89
84
if ( pipTestRes . error . code === 'ENOENT' ) {
90
- throw new Error (
91
- `${ pythonBin } not found! Try the pythonBin option.`
92
- ) ;
85
+ throw new Error ( `${ pythonBin } not found! Try the pythonBin option.` ) ;
93
86
}
94
87
throw pipTestRes . error ;
95
88
}
@@ -140,8 +133,12 @@ function installRequirements(targetFolder, serverless, options) {
140
133
141
134
if ( ! options . dockerizePip ) {
142
135
// Push our local OS-specific paths for requirements and target directory
143
- pipCmd . push ( '-t' , dockerPathForWin ( targetFolder ) ,
144
- '-r' , dockerPathForWin ( targetRequirementsTxt ) ) ;
136
+ pipCmd . push (
137
+ '-t' ,
138
+ dockerPathForWin ( targetFolder ) ,
139
+ '-r' ,
140
+ dockerPathForWin ( targetRequirementsTxt )
141
+ ) ;
145
142
// If we want a download cache...
146
143
if ( options . useDownloadCache ) {
147
144
const downloadCacheDir = path . join (
@@ -175,18 +172,20 @@ function installRequirements(targetFolder, serverless, options) {
175
172
serverless . cli . log ( `Docker Image: ${ dockerImage } ` ) ;
176
173
177
174
// Prepare bind path depending on os platform
178
- const bindPath = dockerPathForWin (
179
- getBindPath ( serverless , targetFolder )
180
- ) ;
175
+ const bindPath = dockerPathForWin ( getBindPath ( serverless , targetFolder ) ) ;
181
176
182
177
dockerCmd . push ( 'docker' , 'run' , '--rm' , '-v' , `${ bindPath } :/var/task:z` ) ;
183
178
if ( options . dockerSsh ) {
184
179
// Mount necessary ssh files to work with private repos
185
180
dockerCmd . push (
186
- '-v' , `${ process . env . HOME } /.ssh/id_rsa:/root/.ssh/id_rsa:z` ,
187
- '-v' , `${ process . env . HOME } /.ssh/known_hosts:/root/.ssh/known_hosts:z` ,
188
- '-v' , `${ process . env . SSH_AUTH_SOCK } :/tmp/ssh_sock:z` ,
189
- '-e' , 'SSH_AUTH_SOCK=/tmp/ssh_sock'
181
+ '-v' ,
182
+ `${ process . env . HOME } /.ssh/id_rsa:/root/.ssh/id_rsa:z` ,
183
+ '-v' ,
184
+ `${ process . env . HOME } /.ssh/known_hosts:/root/.ssh/known_hosts:z` ,
185
+ '-v' ,
186
+ `${ process . env . SSH_AUTH_SOCK } :/tmp/ssh_sock:z` ,
187
+ '-e' ,
188
+ 'SSH_AUTH_SOCK=/tmp/ssh_sock'
190
189
) ;
191
190
}
192
191
@@ -207,10 +206,7 @@ function installRequirements(targetFolder, serverless, options) {
207
206
) ;
208
207
const windowsized = getBindPath ( serverless , downloadCacheDir ) ;
209
208
// And now push it to a volume mount and to pip...
210
- dockerCmd . push (
211
- '-v' ,
212
- `${ windowsized } :${ dockerDownloadCacheDir } :z`
213
- ) ;
209
+ dockerCmd . push ( '-v' , `${ windowsized } :${ dockerDownloadCacheDir } :z` ) ;
214
210
pipCmd . push ( '--cache-dir' , dockerDownloadCacheDir ) ;
215
211
}
216
212
@@ -229,17 +225,20 @@ function installRequirements(targetFolder, serverless, options) {
229
225
}
230
226
// Install requirements with pip
231
227
// Set the ownership of the current folder to user
232
- pipCmds . push ( [ 'chown' , '-R' , `${ process . getuid ( ) } :${ process . getgid ( ) } ` , '/var/task' ] ) ;
228
+ pipCmds . push ( [
229
+ 'chown' ,
230
+ '-R' ,
231
+ `${ process . getuid ( ) } :${ process . getgid ( ) } ` ,
232
+ '/var/task'
233
+ ] ) ;
233
234
if ( options . useDownloadCache ) {
234
235
// Set the ownership of the download cache dir back to user
235
- pipCmds . push (
236
- [
237
- 'chown' ,
238
- '-R' ,
239
- `${ process . getuid ( ) } :${ process . getgid ( ) } ` ,
240
- dockerDownloadCacheDir
241
- ]
242
- ) ;
236
+ pipCmds . push ( [
237
+ 'chown' ,
238
+ '-R' ,
239
+ `${ process . getuid ( ) } :${ process . getgid ( ) } ` ,
240
+ dockerDownloadCacheDir
241
+ ] ) ;
243
242
}
244
243
} else {
245
244
// Use same user so --cache-dir works
@@ -252,8 +251,10 @@ function installRequirements(targetFolder, serverless, options) {
252
251
switch ( getStripMode ( options ) ) {
253
252
case 'docker' :
254
253
pipCmds . push ( getStripCommand ( options , '/var/task' ) ) ;
254
+ break ;
255
255
case 'direct' :
256
256
postCmds . push ( getStripCommand ( options , dockerPathForWin ( targetFolder ) ) ) ;
257
+ break ;
257
258
}
258
259
259
260
let spawnArgs = { shell : true } ;
@@ -272,17 +273,20 @@ function installRequirements(targetFolder, serverless, options) {
272
273
serverless . cli . log ( `Running ${ quote ( dockerCmd ) } ...` ) ;
273
274
274
275
filterCommands ( mainCmds ) . forEach ( ( [ cmd , ...args ] ) => {
275
- const res = spawnSync ( cmd , args ) ;
276
- if ( res . error ) {
277
- if ( res . error . code === 'ENOENT' ) {
278
- const advice = cmd . indexOf ( 'python' ) > - 1 ? 'Try the pythonBin option' : 'Please install it' ;
279
- throw new Error ( `${ cmd } not found! ${ advice } ` ) ;
280
- }
281
- throw res . error ;
282
- }
283
- if ( res . status !== 0 ) {
284
- throw new Error ( res . stderr ) ;
276
+ const res = spawnSync ( cmd , args ) ;
277
+ if ( res . error ) {
278
+ if ( res . error . code === 'ENOENT' ) {
279
+ const advice =
280
+ cmd . indexOf ( 'python' ) > - 1
281
+ ? 'Try the pythonBin option'
282
+ : 'Please install it' ;
283
+ throw new Error ( `${ cmd } not found! ${ advice } ` ) ;
285
284
}
285
+ throw res . error ;
286
+ }
287
+ if ( res . status !== 0 ) {
288
+ throw new Error ( res . stderr ) ;
289
+ }
286
290
} ) ;
287
291
// If enabled slimming, delete files in slimPatterns
288
292
if ( options . slim === true || options . slim === 'true' ) {
0 commit comments