lint-staged 11.2.0 → 11.2.4

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/README.md CHANGED
@@ -105,7 +105,7 @@ Starting with v3.1 you can now use different ways of configuring lint-staged:
105
105
  - `lint-staged.config.js`, `.lintstagedrc.js`, or `.lintstagedrc.cjs` file in JS format
106
106
  - Pass a configuration file using the `--config` or `-c` flag
107
107
 
108
- See [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for more details on what formats are supported.
108
+ See [lilconfig](https://github.com/antonk52/lilconfig) for more details on what formats are supported.
109
109
 
110
110
  Configuration should be an object where each value is a command to run and its key is a glob pattern to use for this command. This package uses [micromatch](https://github.com/micromatch/micromatch) for glob patterns.
111
111
 
package/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const { cosmiconfig } = require('cosmiconfig')
3
+ const { lilconfig } = require('lilconfig')
4
+ const { yaml } = require('js-yaml')
4
5
  const debugLog = require('debug')('lint-staged')
5
6
  const stringifyObject = require('stringify-object')
6
7
 
@@ -24,8 +25,10 @@ const resolveConfig = (configPath) => {
24
25
  }
25
26
  }
26
27
 
28
+ const jsYamlLoad = (filepath, content) => yaml.load(content)
29
+
27
30
  const loadConfig = (configPath) => {
28
- const explorer = cosmiconfig('lint-staged', {
31
+ const explorer = lilconfig('lint-staged', {
29
32
  searchPlaces: [
30
33
  'package.json',
31
34
  '.lintstagedrc',
@@ -37,6 +40,11 @@ const loadConfig = (configPath) => {
37
40
  'lint-staged.config.js',
38
41
  'lint-staged.config.cjs',
39
42
  ],
43
+ loaders: {
44
+ '.yml': jsYamlLoad,
45
+ '.yaml': jsYamlLoad,
46
+ noExt: jsYamlLoad,
47
+ },
40
48
  })
41
49
 
42
50
  return configPath ? explorer.load(resolveConfig(configPath)) : explorer.search()
@@ -84,7 +92,7 @@ const lintStaged = async (
84
92
  ) => {
85
93
  await validateOptions({ shell }, logger)
86
94
 
87
- debugLog('Loading config using `cosmiconfig`')
95
+ debugLog('Loading config using `lilconfig`')
88
96
 
89
97
  const resolved = configObject
90
98
  ? { config: configObject, filepath: '(input)' }
@@ -25,10 +25,25 @@ const resolveGitConfigDir = async (gitDir) => {
25
25
  return path.resolve(gitDir, file.replace(/^gitdir: /, '')).trim()
26
26
  }
27
27
 
28
+ const determineGitDir = (cwd, relativeDir) => {
29
+ // if relative dir and cwd have different endings normalize it
30
+ // this happens under windows, where normalize is unable to normalize git's output
31
+ if (relativeDir && relativeDir.endsWith(path.sep)) {
32
+ relativeDir = relativeDir.slice(0, -1)
33
+ }
34
+ if (relativeDir) {
35
+ // the current working dir is inside the git top-level directory
36
+ return normalize(cwd.substring(0, cwd.lastIndexOf(relativeDir)))
37
+ } else {
38
+ // the current working dir is the top-level git directory
39
+ return normalize(cwd)
40
+ }
41
+ }
42
+
28
43
  /**
29
44
  * Resolve git directory and possible submodule paths
30
45
  */
31
- const resolveGitRepo = async (cwd) => {
46
+ const resolveGitRepo = async (cwd = process.cwd()) => {
32
47
  try {
33
48
  debugLog('Resolving git repo from `%s`', cwd)
34
49
 
@@ -38,7 +53,10 @@ const resolveGitRepo = async (cwd) => {
38
53
  debugLog('Unset GIT_WORK_TREE (was `%s`)', process.env.GIT_WORK_TREE)
39
54
  delete process.env.GIT_WORK_TREE
40
55
 
41
- const gitDir = normalize(await execGit(['rev-parse', '--show-toplevel'], { cwd }))
56
+ // read the path of the current directory relative to the top-level directory
57
+ // don't read the toplevel directly, it will lead to an posix conform path on non posix systems (cygwin)
58
+ const gitRel = normalize(await execGit(['rev-parse', '--show-prefix']))
59
+ const gitDir = determineGitDir(normalize(cwd), gitRel)
42
60
  const gitConfigDir = normalize(await resolveGitConfigDir(gitDir))
43
61
 
44
62
  debugLog('Resolved git directory to be `%s`', gitDir)
@@ -52,3 +70,6 @@ const resolveGitRepo = async (cwd) => {
52
70
  }
53
71
 
54
72
  module.exports = resolveGitRepo
73
+
74
+ // exported for test
75
+ module.exports.determineGitDir = determineGitDir
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "11.2.0",
3
+ "version": "11.2.4",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/okonet/lint-staged",
@@ -30,10 +30,11 @@
30
30
  "cli-truncate": "2.1.0",
31
31
  "colorette": "^1.4.0",
32
32
  "commander": "^8.2.0",
33
- "cosmiconfig": "^7.0.1",
34
33
  "debug": "^4.3.2",
35
34
  "enquirer": "^2.3.6",
36
35
  "execa": "^5.1.1",
36
+ "js-yaml": "^4.1.0",
37
+ "lilconfig": "^2.0.3",
37
38
  "listr2": "^3.12.2",
38
39
  "micromatch": "^4.0.4",
39
40
  "normalize-path": "^3.0.0",