lint-staged 12.1.2 → 12.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,10 +44,13 @@ cmdline
44
44
  )
45
45
  .parse(process.argv)
46
46
 
47
- const debugLog = debug('lint-staged:bin')
48
- if (cmdline.debug) {
47
+ const cmdlineOptions = cmdline.opts()
48
+
49
+ if (cmdlineOptions.debug) {
49
50
  debug.enable('lint-staged*')
50
51
  }
52
+
53
+ const debugLog = debug('lint-staged:bin')
51
54
  debugLog('Running `lint-staged@%s`', version)
52
55
 
53
56
  /**
@@ -68,8 +71,6 @@ const getMaxArgLength = () => {
68
71
  }
69
72
  }
70
73
 
71
- const cmdlineOptions = cmdline.opts()
72
-
73
74
  const options = {
74
75
  allowEmpty: !!cmdlineOptions.allowEmpty,
75
76
  concurrent: JSON.parse(cmdlineOptions.concurrent),
package/lib/index.js CHANGED
@@ -58,7 +58,7 @@ const lintStaged = async (
58
58
  ) => {
59
59
  await validateOptions({ shell }, logger)
60
60
 
61
- const inputConfig = configObject || (await loadConfig(configPath, logger))
61
+ const inputConfig = configObject || (await loadConfig({ configPath, cwd }, logger))
62
62
 
63
63
  if (!inputConfig) {
64
64
  logger.error(`${ConfigNotFoundError.message}.`)
package/lib/loadConfig.js CHANGED
@@ -1,3 +1,5 @@
1
+ /** @typedef {import('./index').Logger} Logger */
2
+
1
3
  import { pathToFileURL } from 'url'
2
4
 
3
5
  import debug from 'debug'
@@ -56,20 +58,23 @@ const resolveConfig = (configPath) => {
56
58
  }
57
59
 
58
60
  /**
59
- * @param {string} [configPath]
60
- * @param {Logger} [logger]
61
+ * @param {object} options
62
+ * @param {string} [options.configPath] - Explicit path to a config file
63
+ * @param {string} [options.cwd] - Current working directory
61
64
  */
62
- export const loadConfig = async (configPath, logger) => {
65
+ export const loadConfig = async ({ configPath, cwd }, logger) => {
63
66
  try {
64
67
  if (configPath) {
65
68
  debugLog('Loading configuration from `%s`...', configPath)
66
69
  } else {
67
- debugLog('Searching for configuration...')
70
+ debugLog('Searching for configuration from `%s`...', cwd)
68
71
  }
69
72
 
70
73
  const explorer = lilconfig('lint-staged', { searchPlaces, loaders })
71
74
 
72
- const result = await (configPath ? explorer.load(resolveConfig(configPath)) : explorer.search())
75
+ const result = await (configPath
76
+ ? explorer.load(resolveConfig(configPath))
77
+ : explorer.search(cwd))
73
78
  if (!result) return null
74
79
 
75
80
  // config is a promise when using the `dynamicImport` loader
@@ -79,7 +84,7 @@ export const loadConfig = async (configPath, logger) => {
79
84
 
80
85
  return config
81
86
  } catch (error) {
82
- debugLog('Failed to load configuration from `%s`', configPath)
87
+ debugLog('Failed to load configuration!')
83
88
  logger.error(error)
84
89
  return null
85
90
  }
@@ -28,13 +28,14 @@ const getTitleLength = (renderer, columns = process.stdout.columns) => {
28
28
  *
29
29
  * @param {object} options
30
30
  * @param {Array<string|Function>|string|Function} options.commands
31
+ * @param {string} options.cwd
31
32
  * @param {Array<string>} options.files
32
33
  * @param {string} options.gitDir
33
34
  * @param {string} options.renderer
34
35
  * @param {Boolean} shell
35
36
  * @param {Boolean} verbose
36
37
  */
37
- export const makeCmdTasks = async ({ commands, files, gitDir, renderer, shell, verbose }) => {
38
+ export const makeCmdTasks = async ({ commands, cwd, files, gitDir, renderer, shell, verbose }) => {
38
39
  debugLog('Creating listr tasks for commands %o', commands)
39
40
  const commandArray = Array.isArray(commands) ? commands : [commands]
40
41
  const cmdTasks = []
@@ -61,7 +62,7 @@ export const makeCmdTasks = async ({ commands, files, gitDir, renderer, shell, v
61
62
 
62
63
  // Truncate title to single line based on renderer
63
64
  const title = cliTruncate(command, getTitleLength(renderer))
64
- const task = resolveTaskFn({ command, files, gitDir, isFn, shell, verbose })
65
+ const task = resolveTaskFn({ command, cwd, files, gitDir, isFn, shell, verbose })
65
66
  cmdTasks.push({ title, command, task })
66
67
  }
67
68
  }
@@ -54,7 +54,7 @@ export const resolveGitRepo = async (cwd = process.cwd()) => {
54
54
 
55
55
  // read the path of the current directory relative to the top-level directory
56
56
  // don't read the toplevel directly, it will lead to an posix conform path on non posix systems (cygwin)
57
- const gitRel = normalize(await execGit(['rev-parse', '--show-prefix']))
57
+ const gitRel = normalize(await execGit(['rev-parse', '--show-prefix'], { cwd }))
58
58
  const gitDir = determineGitDir(normalize(cwd), gitRel)
59
59
  const gitConfigDir = normalize(await resolveGitConfigDir(gitDir))
60
60
 
@@ -68,20 +68,20 @@ const makeErr = (command, result, ctx) => {
68
68
  *
69
69
  * @param {Object} options
70
70
  * @param {string} options.command — Linter task
71
+ * @param {string} [options.cwd]
71
72
  * @param {String} options.gitDir - Current git repo path
72
73
  * @param {Boolean} options.isFn - Whether the linter task is a function
73
74
  * @param {Array<string>} options.files — Filepaths to run the linter task against
74
- * @param {Boolean} [options.relative] — Whether the filepaths should be relative
75
75
  * @param {Boolean} [options.shell] — Whether to skip parsing linter task for better shell support
76
76
  * @param {Boolean} [options.verbose] — Always show task verbose
77
77
  * @returns {function(): Promise<Array<string>>}
78
78
  */
79
79
  export const resolveTaskFn = ({
80
80
  command,
81
+ cwd = process.cwd(),
81
82
  files,
82
83
  gitDir,
83
84
  isFn,
84
- relative,
85
85
  shell = false,
86
86
  verbose = false,
87
87
  }) => {
@@ -89,14 +89,15 @@ export const resolveTaskFn = ({
89
89
  debugLog('cmd:', cmd)
90
90
  debugLog('args:', args)
91
91
 
92
- const execaOptions = { preferLocal: true, reject: false, shell }
93
- if (relative) {
94
- execaOptions.cwd = process.cwd()
95
- } else if (/^git(\.exe)?/i.test(cmd) && gitDir !== process.cwd()) {
92
+ const execaOptions = {
96
93
  // Only use gitDir as CWD if we are using the git binary
97
94
  // e.g `npm` should run tasks in the actual CWD
98
- execaOptions.cwd = gitDir
95
+ cwd: /^git(\.exe)?/i.test(cmd) ? gitDir : cwd,
96
+ preferLocal: true,
97
+ reject: false,
98
+ shell,
99
99
  }
100
+
100
101
  debugLog('execaOptions:', execaOptions)
101
102
 
102
103
  return async (ctx = getInitialState()) => {
package/lib/runAll.js CHANGED
@@ -135,6 +135,7 @@ export const runAll = async (
135
135
  for (const task of chunkTasks) {
136
136
  const subTasks = await makeCmdTasks({
137
137
  commands: task.commands,
138
+ cwd,
138
139
  files: task.fileList,
139
140
  gitDir,
140
141
  renderer: listrOptions.renderer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "12.1.2",
3
+ "version": "12.1.6",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/okonet/lint-staged",
@@ -32,34 +32,33 @@
32
32
  "cli-truncate": "^3.1.0",
33
33
  "colorette": "^2.0.16",
34
34
  "commander": "^8.3.0",
35
- "debug": "^4.3.2",
36
- "enquirer": "^2.3.6",
35
+ "debug": "^4.3.3",
37
36
  "execa": "^5.1.1",
38
37
  "lilconfig": "2.0.4",
39
- "listr2": "^3.13.3",
38
+ "listr2": "^3.13.5",
40
39
  "micromatch": "^4.0.4",
41
40
  "normalize-path": "^3.0.0",
42
- "object-inspect": "^1.11.0",
41
+ "object-inspect": "^1.11.1",
43
42
  "string-argv": "^0.3.1",
44
- "supports-color": "^9.0.2",
43
+ "supports-color": "^9.2.1",
45
44
  "yaml": "^1.10.2"
46
45
  },
47
46
  "devDependencies": {
48
- "@babel/core": "^7.16.0",
49
- "@babel/eslint-parser": "^7.16.3",
50
- "@babel/preset-env": "^7.16.0",
51
- "babel-jest": "^27.3.1",
47
+ "@babel/core": "^7.16.5",
48
+ "@babel/eslint-parser": "^7.16.5",
49
+ "@babel/preset-env": "^7.16.5",
50
+ "babel-jest": "^27.4.5",
52
51
  "consolemock": "^1.1.0",
53
- "eslint": "^8.2.0",
52
+ "eslint": "^8.4.1",
54
53
  "eslint-config-prettier": "^8.3.0",
55
54
  "eslint-plugin-import": "^2.25.3",
56
55
  "eslint-plugin-node": "^11.1.0",
57
56
  "eslint-plugin-prettier": "^4.0.0",
58
57
  "fs-extra": "^10.0.0",
59
58
  "husky": "^7.0.4",
60
- "jest": "^27.3.1",
59
+ "jest": "^27.4.5",
61
60
  "jest-snapshot-serializer-ansi": "^1.0.0",
62
- "prettier": "^2.4.1"
61
+ "prettier": "^2.5.1"
63
62
  },
64
63
  "keywords": [
65
64
  "lint",