lint-staged 15.2.4 → 15.2.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.
package/lib/loadConfig.js CHANGED
@@ -7,6 +7,7 @@ import debug from 'debug'
7
7
  import YAML from 'yaml'
8
8
 
9
9
  import { dynamicImport } from './dynamicImport.js'
10
+ import { failedToLoadConfig } from './messages.js'
10
11
  import { resolveConfig } from './resolveConfig.js'
11
12
  import {
12
13
  CONFIG_FILE_NAMES,
@@ -117,8 +118,8 @@ export const loadConfig = async ({ configPath, cwd }, logger) => {
117
118
 
118
119
  return { config, filepath }
119
120
  } catch (error) {
120
- debugLog('Failed to load configuration!')
121
- logger.error(error)
121
+ debugLog('Failed to load configuration from `%s` with error:\n', configPath, error)
122
+ logger.error(failedToLoadConfig(configPath))
122
123
  return {}
123
124
  }
124
125
  }
package/lib/messages.js CHANGED
@@ -85,3 +85,15 @@ export const RESTORE_STASH_EXAMPLE = ` Any lost modifications can be restored f
85
85
  `
86
86
 
87
87
  export const CONFIG_STDIN_ERROR = chalk.redBright(`${error} Failed to read config from stdin.`)
88
+
89
+ export const failedToLoadConfig = (filepath) =>
90
+ chalk.redBright(`${error} Failed to read config from file "${filepath}".`)
91
+
92
+ export const failedToParseConfig = (
93
+ filepath,
94
+ error
95
+ ) => `${chalk.redBright(`${error} Failed to parse config from file "${filepath}".`)}
96
+
97
+ ${error}
98
+
99
+ See https://github.com/okonet/lint-staged#configuration.`
@@ -1,54 +1,10 @@
1
- import fs from 'node:fs/promises'
2
- import path from 'node:path'
3
-
4
1
  import debug from 'debug'
5
2
 
6
3
  import { execGit } from './execGit.js'
7
- import { readFile } from './file.js'
8
4
  import { normalizePath } from './normalizePath.js'
9
5
 
10
6
  const debugLog = debug('lint-staged:resolveGitRepo')
11
7
 
12
- /**
13
- * Resolve path to the .git directory, with special handling for
14
- * submodules and worktrees
15
- */
16
- const resolveGitConfigDir = async (gitDir) => {
17
- // Get the real path in case it's a symlink
18
- const defaultDir = path.join(gitDir, '.git')
19
- const stats = await fs.lstat(defaultDir)
20
-
21
- // If .git is a directory, use it
22
- if (stats.isDirectory()) {
23
- return defaultDir
24
- }
25
-
26
- // If .git is a symlink, return the real location
27
- if (stats.isSymbolicLink()) {
28
- return await fs.realpath(gitDir)
29
- }
30
-
31
- // Otherwise .git is a file containing path to real location
32
- const file = (await readFile(defaultDir)).toString()
33
- return path.resolve(gitDir, file.replace(/^gitdir: /, '')).trim()
34
- }
35
-
36
- // exported for test
37
- export const determineGitDir = (cwd, relativeDir) => {
38
- // if relative dir and cwd have different endings normalize it
39
- // this happens under windows, where normalize is unable to normalize git's output
40
- if (relativeDir && relativeDir.endsWith(path.sep)) {
41
- relativeDir = relativeDir.slice(0, -1)
42
- }
43
- if (relativeDir) {
44
- // the current working dir is inside the git top-level directory
45
- return cwd.substring(0, cwd.lastIndexOf(relativeDir))
46
- } else {
47
- // the current working dir is the top-level git directory
48
- return cwd
49
- }
50
- }
51
-
52
8
  /**
53
9
  * Resolve git directory and possible submodule paths
54
10
  */
@@ -62,13 +18,14 @@ export const resolveGitRepo = async (cwd = process.cwd()) => {
62
18
  debugLog('Unset GIT_WORK_TREE (was `%s`)', process.env.GIT_WORK_TREE)
63
19
  delete process.env.GIT_WORK_TREE
64
20
 
65
- // read the path of the current directory relative to the top-level directory
66
- // don't read the toplevel directly, it will lead to an posix conform path on non posix systems (cygwin)
67
- const gitRel = normalizePath(await execGit(['rev-parse', '--show-prefix'], { cwd }))
68
- const gitDir = normalizePath(determineGitDir(normalizePath(cwd), gitRel))
69
- const gitConfigDir = normalizePath(await resolveGitConfigDir(gitDir))
70
-
21
+ const gitDir = normalizePath(
22
+ await execGit(['rev-parse', '--path-format=absolute', '--show-toplevel'], { cwd })
23
+ )
71
24
  debugLog('Resolved git directory to be `%s`', gitDir)
25
+
26
+ const gitConfigDir = normalizePath(
27
+ await execGit(['rev-parse', '--path-format=absolute', '--absolute-git-dir'], { cwd })
28
+ )
72
29
  debugLog('Resolved git config directory to be `%s`', gitConfigDir)
73
30
 
74
31
  return { gitDir, gitConfigDir }
@@ -4,7 +4,7 @@ import { inspect } from 'node:util'
4
4
 
5
5
  import debug from 'debug'
6
6
 
7
- import { configurationError } from './messages.js'
7
+ import { configurationError, failedToParseConfig } from './messages.js'
8
8
  import { ConfigEmptyError, ConfigFormatError } from './symbols.js'
9
9
  import { validateBraces } from './validateBraces.js'
10
10
 
@@ -23,14 +23,7 @@ const TEST_DEPRECATED_KEYS = new Map([
23
23
  ['relative', (key) => typeof key === 'boolean'],
24
24
  ])
25
25
 
26
- /**
27
- * Runs config validation. Throws error if the config is not valid.
28
- * @param {Object} config
29
- * @param {string} configPath
30
- * @param {Logger} logger
31
- * @returns {Object} config
32
- */
33
- export const validateConfig = (config, configPath, logger) => {
26
+ export const validateConfigLogic = (config, configPath, logger) => {
34
27
  debugLog('Validating config from `%s`...', configPath)
35
28
 
36
29
  if (!config || (typeof config !== 'object' && typeof config !== 'function')) {
@@ -100,11 +93,7 @@ export const validateConfig = (config, configPath, logger) => {
100
93
  if (errors.length) {
101
94
  const message = errors.join('\n\n')
102
95
 
103
- logger.error(`Could not parse lint-staged config.
104
-
105
- ${message}
106
-
107
- See https://github.com/okonet/lint-staged#configuration.`)
96
+ logger.error(failedToParseConfig(configPath, message))
108
97
 
109
98
  throw new Error(message)
110
99
  }
@@ -114,3 +103,19 @@ See https://github.com/okonet/lint-staged#configuration.`)
114
103
 
115
104
  return validatedConfig
116
105
  }
106
+
107
+ /**
108
+ * Runs config validation. Throws error if the config is not valid.
109
+ * @param {Object} config
110
+ * @param {string} configPath
111
+ * @param {Logger} logger
112
+ * @returns {Object} config
113
+ */
114
+ export const validateConfig = (config, configPath, logger) => {
115
+ try {
116
+ return validateConfigLogic(config, configPath, logger)
117
+ } catch (error) {
118
+ logger.error(failedToParseConfig(configPath, error))
119
+ throw error
120
+ }
121
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "15.2.4",
3
+ "version": "15.2.6",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/okonet/lint-staged",
@@ -36,16 +36,16 @@
36
36
  "tag": "npx changeset tag"
37
37
  },
38
38
  "dependencies": {
39
- "chalk": "5.3.0",
40
- "commander": "12.1.0",
41
- "debug": "4.3.4",
42
- "execa": "8.0.1",
43
- "lilconfig": "3.1.1",
44
- "listr2": "8.2.1",
45
- "micromatch": "4.0.6",
46
- "pidtree": "0.6.0",
47
- "string-argv": "0.3.2",
48
- "yaml": "2.4.2"
39
+ "chalk": "~5.3.0",
40
+ "commander": "~12.1.0",
41
+ "debug": "~4.3.4",
42
+ "execa": "~8.0.1",
43
+ "lilconfig": "~3.1.1",
44
+ "listr2": "~8.2.1",
45
+ "micromatch": "~4.0.7",
46
+ "pidtree": "~0.6.0",
47
+ "string-argv": "~0.3.2",
48
+ "yaml": "~2.4.2"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@changesets/changelog-github": "0.5.0",