UNPKG

2.74 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3'use strict'
4
5// Force colors for packages that depend on https://www.npmjs.com/package/supports-color
6const { supportsColor } = require('chalk')
7if (supportsColor) {
8 process.env.FORCE_COLOR = supportsColor.level.toString()
9}
10
11// Do not terminate main Listr process on SIGINT
12process.on('SIGINT', () => {})
13
14const pkg = require('../package.json')
15require('please-upgrade-node')(
16 Object.assign({}, pkg, {
17 engines: {
18 node: '>=10.13.0', // First LTS release of 'Dubnium'
19 },
20 })
21)
22
23const cmdline = require('commander')
24const debugLib = require('debug')
25const lintStaged = require('../lib')
26
27const debug = debugLib('lint-staged:bin')
28
29cmdline
30 .version(pkg.version)
31 .option('--allow-empty', 'allow empty commits when tasks revert all staged changes', false)
32 .option('-c, --config [path]', 'path to configuration file')
33 .option('-d, --debug', 'print additional debug information', false)
34 .option('--no-stash', 'disable the backup stash, and do not revert in case of errors', false)
35 .option(
36 '-p, --concurrent <parallel tasks>',
37 'the number of tasks to run concurrently, or false to run tasks serially',
38 true
39 )
40 .option('-q, --quiet', 'disable lint-staged’s own console output', false)
41 .option('-r, --relative', 'pass relative filepaths to tasks', false)
42 .option('-x, --shell', 'skip parsing of tasks for better shell support', false)
43 .option(
44 '-v, --verbose',
45 'show task output even when tasks succeed; by default only failed output is shown',
46 false
47 )
48 .parse(process.argv)
49
50if (cmdline.debug) {
51 debugLib.enable('lint-staged*')
52}
53
54debug('Running `lint-staged@%s`', pkg.version)
55
56/**
57 * Get the maximum length of a command-line argument string based on current platform
58 *
59 * https://serverfault.com/questions/69430/what-is-the-maximum-length-of-a-command-line-in-mac-os-x
60 * https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitation
61 * https://unix.stackexchange.com/a/120652
62 */
63const getMaxArgLength = () => {
64 switch (process.platform) {
65 case 'darwin':
66 return 262144
67 case 'win32':
68 return 8191
69 default:
70 return 131072
71 }
72}
73
74const options = {
75 allowEmpty: !!cmdline.allowEmpty,
76 concurrent: cmdline.concurrent,
77 configPath: cmdline.config,
78 debug: !!cmdline.debug,
79 maxArgLength: getMaxArgLength() / 2,
80 stash: !!cmdline.stash, // commander inverts `no-<x>` flags to `!x`
81 quiet: !!cmdline.quiet,
82 relative: !!cmdline.relative,
83 shell: !!cmdline.shell,
84 verbose: !!cmdline.verbose,
85}
86
87debug('Options parsed from command-line:', options)
88
89lintStaged(options)
90 .then((passed) => {
91 process.exitCode = passed ? 0 : 1
92 })
93 .catch(() => {
94 process.exitCode = 1
95 })