执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict'
 
const path = require('path')
const micromatch = require('micromatch')
const pathIsInside = require('path-is-inside')
const { getConfig } = require('./getConfig')
const resolveGitDir = require('./resolveGitDir')
 
const debug = require('debug')('lint-staged:gen-tasks')
 
module.exports = function generateTasks(config, stagedRelFiles) {
  debug('Generating linter tasks')
 
  const normalizedConfig = getConfig(config) // Ensure we have a normalized config
  const { linters, globOptions, ignore } = normalizedConfig
 
  const gitDir = resolveGitDir()
  const cwd = process.cwd()
  const stagedFiles = stagedRelFiles.map(file => path.resolve(gitDir, file))
 
  return Object.keys(linters).map(pattern => {
    const isParentDirPattern = pattern.startsWith('../')
    const commands = linters[pattern]
 
    const fileList = micromatch(
      stagedFiles
        // Only worry about children of the CWD unless the pattern explicitly
        // specifies that it concerns a parent directory.
        .filter(file => isParentDirPattern || pathIsInside(file, cwd))
        // Make the paths relative to CWD for filtering
        .map(file => path.relative(cwd, file)),
      pattern,
      {
        ...globOptions,
        ignore
      }
    ).map(file => {
      // if you set relative option, then the file path will be relative to your package.json
      if (config.relative) {
        return path.normalize(file)
      }
      // Return absolute path after the filter is run
      return path.resolve(cwd, file)
    })
 
    const task = { pattern, commands, fileList }
    debug('Generated task: \n%O', task)
 
    return task
  })
}