lint-staged 12.1.0 → 12.1.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/lib/index.js CHANGED
@@ -58,20 +58,14 @@ const lintStaged = async (
58
58
  ) => {
59
59
  await validateOptions({ shell }, logger)
60
60
 
61
- debugLog('Loading config using `lilconfig`')
61
+ const inputConfig = configObject || (await loadConfig(configPath, logger))
62
62
 
63
- const resolved = configObject
64
- ? { config: configObject, filepath: '(input)' }
65
- : await loadConfig(configPath)
66
-
67
- if (!resolved) {
63
+ if (!inputConfig) {
68
64
  logger.error(`${ConfigNotFoundError.message}.`)
69
65
  throw ConfigNotFoundError
70
66
  }
71
67
 
72
- debugLog('Successfully loaded config from `%s`:\n%O', resolved.filepath, resolved.config)
73
-
74
- const config = validateConfig(resolved.config, logger)
68
+ const config = validateConfig(inputConfig, logger)
75
69
 
76
70
  if (debug) {
77
71
  // Log using logger to be able to test through `consolemock`.
package/lib/loadConfig.js CHANGED
@@ -1,6 +1,11 @@
1
+ import { pathToFileURL } from 'url'
2
+
3
+ import debug from 'debug'
1
4
  import { lilconfig } from 'lilconfig'
2
5
  import YAML from 'yaml'
3
6
 
7
+ const debugLog = debug('lint-staged:loadConfig')
8
+
4
9
  /**
5
10
  * The list of files `lint-staged` will read configuration
6
11
  * from, in the declared order.
@@ -20,16 +25,12 @@ const searchPlaces = [
20
25
  ]
21
26
 
22
27
  /** exported for tests */
23
- export const dynamicImport = (path) =>
24
- import(path)
25
- .then((module) => module.default)
26
- .catch((error) => {
27
- console.error(error)
28
- throw error
29
- })
28
+ export const dynamicImport = (path) => import(pathToFileURL(path)).then((module) => module.default)
30
29
 
31
30
  const jsonParse = (path, content) => JSON.parse(content)
32
31
 
32
+ const yamlParse = (path, content) => YAML.parse(content)
33
+
33
34
  /**
34
35
  * `lilconfig` doesn't support yaml files by default,
35
36
  * so we add custom loaders for those. Files without
@@ -41,9 +42,9 @@ const loaders = {
41
42
  '.json': jsonParse,
42
43
  '.mjs': dynamicImport,
43
44
  '.cjs': dynamicImport,
44
- '.yaml': YAML.parse,
45
- '.yml': YAML.parse,
46
- noExt: YAML.parse,
45
+ '.yaml': yamlParse,
46
+ '.yml': yamlParse,
47
+ noExt: yamlParse,
47
48
  }
48
49
 
49
50
  const resolveConfig = (configPath) => {
@@ -56,8 +57,30 @@ const resolveConfig = (configPath) => {
56
57
 
57
58
  /**
58
59
  * @param {string} [configPath]
60
+ * @param {Logger} [logger]
59
61
  */
60
- export const loadConfig = (configPath) => {
61
- const explorer = lilconfig('lint-staged', { searchPlaces, loaders })
62
- return configPath ? explorer.load(resolveConfig(configPath)) : explorer.search()
62
+ export const loadConfig = async (configPath, logger) => {
63
+ try {
64
+ if (configPath) {
65
+ debugLog('Loading configuration from `%s`...', configPath)
66
+ } else {
67
+ debugLog('Searching for configuration...')
68
+ }
69
+
70
+ const explorer = lilconfig('lint-staged', { searchPlaces, loaders })
71
+
72
+ const result = await (configPath ? explorer.load(resolveConfig(configPath)) : explorer.search())
73
+ if (!result) return null
74
+
75
+ // config is a promise when using the `dynamicImport` loader
76
+ const config = await result.config
77
+
78
+ debugLog('Successfully loaded config from `%s`:\n%O', result.filepath, config)
79
+
80
+ return config
81
+ } catch (error) {
82
+ debugLog('Failed to load configuration from `%s`', configPath)
83
+ logger.error(error)
84
+ return null
85
+ }
63
86
  }
@@ -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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "12.1.0",
3
+ "version": "12.1.4",
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",