Skip to content

Commit 0362dee

Browse files
committed
Linting and such.
1 parent 937fa56 commit 0362dee

File tree

3 files changed

+68
-50
lines changed

3 files changed

+68
-50
lines changed

lib/pip.js

+48-44
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const {
2121
* @return {string[][]} a list of valid commands.
2222
*/
2323
function filterCommands(commands) {
24-
return commands.filter((cmd) => Boolean(cmd) && cmd.length > 0);
24+
return commands.filter(cmd => Boolean(cmd) && cmd.length > 0);
2525
}
2626

2727
/**
@@ -34,13 +34,13 @@ function filterCommands(commands) {
3434
function mergeCommands(commands) {
3535
const cmds = filterCommands(commands);
3636
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');
3838
} else if (cmds.length === 1) {
3939
return cmds[0];
4040
} else {
4141
// Quote the arguments in each command and join them all using &&.
4242
const script = cmds.map(quote).join(' && ');
43-
return ["/bin/sh", "-c", script];
43+
return ['/bin/sh', '-c', script];
4444
}
4545
}
4646

@@ -79,17 +79,10 @@ function installRequirementsFile(
7979

8080
function pipAcceptsSystem(pythonBin) {
8181
// 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']);
8883
if (pipTestRes.error) {
8984
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.`);
9386
}
9487
throw pipTestRes.error;
9588
}
@@ -140,8 +133,12 @@ function installRequirements(targetFolder, serverless, options) {
140133

141134
if (!options.dockerizePip) {
142135
// 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+
);
145142
// If we want a download cache...
146143
if (options.useDownloadCache) {
147144
const downloadCacheDir = path.join(
@@ -175,18 +172,20 @@ function installRequirements(targetFolder, serverless, options) {
175172
serverless.cli.log(`Docker Image: ${dockerImage}`);
176173

177174
// Prepare bind path depending on os platform
178-
const bindPath = dockerPathForWin(
179-
getBindPath(serverless, targetFolder)
180-
);
175+
const bindPath = dockerPathForWin(getBindPath(serverless, targetFolder));
181176

182177
dockerCmd.push('docker', 'run', '--rm', '-v', `${bindPath}:/var/task:z`);
183178
if (options.dockerSsh) {
184179
// Mount necessary ssh files to work with private repos
185180
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'
190189
);
191190
}
192191

@@ -207,10 +206,7 @@ function installRequirements(targetFolder, serverless, options) {
207206
);
208207
const windowsized = getBindPath(serverless, downloadCacheDir);
209208
// 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`);
214210
pipCmd.push('--cache-dir', dockerDownloadCacheDir);
215211
}
216212

@@ -229,17 +225,20 @@ function installRequirements(targetFolder, serverless, options) {
229225
}
230226
// Install requirements with pip
231227
// 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+
]);
233234
if (options.useDownloadCache) {
234235
// 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+
]);
243242
}
244243
} else {
245244
// Use same user so --cache-dir works
@@ -252,8 +251,10 @@ function installRequirements(targetFolder, serverless, options) {
252251
switch (getStripMode(options)) {
253252
case 'docker':
254253
pipCmds.push(getStripCommand(options, '/var/task'));
254+
break;
255255
case 'direct':
256256
postCmds.push(getStripCommand(options, dockerPathForWin(targetFolder)));
257+
break;
257258
}
258259

259260
let spawnArgs = { shell: true };
@@ -272,17 +273,20 @@ function installRequirements(targetFolder, serverless, options) {
272273
serverless.cli.log(`Running ${quote(dockerCmd)}...`);
273274

274275
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}`);
285284
}
285+
throw res.error;
286+
}
287+
if (res.status !== 0) {
288+
throw new Error(res.stderr);
289+
}
286290
});
287291
// If enabled slimming, delete files in slimPatterns
288292
if (options.slim === true || options.slim === 'true') {

lib/slim.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,31 @@ const isWsl = require('is-wsl');
22
const glob = require('glob-all');
33
const fse = require('fs-extra');
44

5-
const getStripMode = (options) => {
5+
const getStripMode = options => {
66
if (options.slim === false || options.slim === 'false') {
77
return 'skip';
88
} else if (options.dockerizePip) {
99
return 'docker';
10-
} else if (!isWsl && process.platform === 'win32' || process.platform === 'darwin') {
10+
} else if (
11+
(!isWsl && process.platform === 'win32') ||
12+
process.platform === 'darwin'
13+
) {
1114
return 'skip';
1215
} else {
1316
return 'direct';
1417
}
15-
}
18+
};
1619

17-
const getStripCommand = (options, folderPath) => (['find', folderPath, '-name', '*.so', '-exec', 'strip', '{}', '+']);
20+
const getStripCommand = (options, folderPath) => [
21+
'find',
22+
folderPath,
23+
'-name',
24+
'*.so',
25+
'-exec',
26+
'strip',
27+
'{}',
28+
';'
29+
];
1830

1931
const deleteFiles = (options, folderPath) => {
2032
let patterns = ['**/*.py[c|o]', '**/__pycache__*', '**/*.dist-info*'];

test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ const mkCommand = cmd => (args, options = {}) => {
2727
)
2828
);
2929
if (error) {
30-
console.error(`Error running: ${quote([cmd, ...args])}`);
30+
console.error(`Error running: ${quote([cmd, ...args])}`); // eslint-disable-line no-console
3131
throw error;
3232
}
3333
if (status) {
3434
console.error('STDOUT: ', stdout.toString()); // eslint-disable-line no-console
3535
console.error('STDERR: ', stderr.toString()); // eslint-disable-line no-console
36-
throw new Error(`${quote([cmd, ...args])} failed with status code ${status}`);
36+
throw new Error(
37+
`${quote([cmd, ...args])} failed with status code ${status}`
38+
);
3739
}
3840
return stdout && stdout.toString().trim();
3941
};

0 commit comments

Comments
 (0)