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