1 | import { constants, promises as fs } from 'fs'
|
2 | import path from 'path'
|
3 |
|
4 | import debug from 'debug'
|
5 |
|
6 | import { invalidOption } from './messages.js'
|
7 | import { InvalidOptionsError } from './symbols.js'
|
8 |
|
9 | const debugLog = debug('lint-staged:validateOptions')
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export const validateOptions = async (options = {}, logger) => {
|
20 | debugLog('Validating options...')
|
21 |
|
22 |
|
23 | if (typeof options.cwd === 'string') {
|
24 | try {
|
25 | const resolved = path.resolve(options.cwd)
|
26 | await fs.access(resolved, constants.F_OK)
|
27 | } catch (error) {
|
28 | logger.error(invalidOption('cwd', options.cwd, error.message))
|
29 | throw InvalidOptionsError
|
30 | }
|
31 | }
|
32 |
|
33 |
|
34 | if (typeof options.shell === 'string') {
|
35 | try {
|
36 | await fs.access(options.shell, constants.X_OK)
|
37 | } catch (error) {
|
38 | logger.error(invalidOption('shell', options.shell, error.message))
|
39 | throw InvalidOptionsError
|
40 | }
|
41 | }
|
42 |
|
43 | debugLog('Validated options!')
|
44 | }
|