From 35fcce9040c8de2926a9113d09f13517e6b23a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Sun, 29 May 2022 14:48:32 +0300 Subject: [PATCH 01/11] feat: add `--diff` option for overriding list of (staged) files The `--diff` option can be used to, for example, run _lint-staged_ against the list of files changed between two branches: `--diff branch1...branch2`. --- README.md | 30 +++++++++++++++++++++++++++++- bin/lint-staged.js | 6 ++++++ lib/getStagedFiles.js | 18 ++++++++++-------- lib/index.js | 3 +++ lib/runAll.js | 4 +++- test/getStagedFiles.spec.js | 33 +++++++++++++++++++++++++++++++++ test/integration.test.js | 26 ++++++++++++++++++++++++++ 7 files changed, 110 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 78811a782..d4f12cb4f 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,8 @@ Options: -c, --config [path] path to configuration file, or - to read from stdin --cwd [path] run all tasks in specific directory, instead of the current -d, --debug print additional debug information (default: false) + --diff [string] override the default "--staged" flag of "git diff" to get list of files + --max-arg-length [number] maximum length of the command-line argument string (default: 0) --no-stash disable the backup stash, and do not revert in case of errors -q, --quiet disable lint-staged’s own console output (default: false) -r, --relative pass relative filepaths to tasks (default: false) @@ -111,6 +113,8 @@ Options: - **`--debug`**: Run in debug mode. When set, it does the following: - uses [debug](https://github.com/visionmedia/debug) internally to log additional information about staged files, commands being executed, location of binaries, etc. Debug logs, which are automatically enabled by passing the flag, can also be enabled by setting the environment variable `$DEBUG` to `lint-staged*`. - uses [`verbose` renderer](https://github.com/SamVerschueren/listr-verbose-renderer) for `listr`; this causes serial, uncoloured output to the terminal, instead of the default (beautified, dynamic) output. +- **`--diff`**: By default linters are filtered against all files staged in git, generated from `git diff --staged`. This option allows you to override the `--staged` flag with arbitrary revisions. For example to get a list of changed files between two branches, use `--diff="branch1...branch2"`. You can also read more from about [`git diff`](https://git-scm.com/docs/git-diff) and [`gitrevisions`](https://git-scm.com/docs/gitrevisions). +- **`--max-arg-length`**: long commands (a lot of files) are automatically split into multiple chunks when it detects the current shell cannot handle them. Use this flag to override the maximum length of the generated command string. - **`--no-stash`**: By default a backup stash will be created before running the tasks, and all task modifications will be reverted in case of an error. This option will disable creating the stash, and instead leave all modifications in the index when aborting the commit. - **`--quiet`**: Supress all CLI output, except from tasks. - **`--relative`**: Pass filepaths relative to `process.cwd()` (where `lint-staged` runs) to tasks. Default is `false`. @@ -596,7 +600,7 @@ const success = await lintStaged({ relative: false, shell: false, stash: true, - verbose: false + verbose: false, }) ``` @@ -713,6 +717,30 @@ Example repo: [sudo-suhas/lint-staged-django-react-demo](https://github.com/sudo +### Can I run `lint-staged` in CI, or when there are no staged files? + +
+ Click to expand + +Lint-staged will by default run against files staged in git, and should be run during the git pre-commit hook, for example. It's also possible to override this default behaviour and run against files in a specific diff, for example +all changed files between two different branches. If you want to run _lint-staged_ in the CI, maybe you can set it up to compare the branch in a _Pull Request_/_Merge Request_ to the target branch. + +Try out the `git diff` command until you are satisfied with the result, for example: + +``` +git diff --diff-filter=ACMR --name-only master...my-branch +``` + +This will print a list of _added_, _changed_, _modified_, and _renamed_ files between `master` and `my-branch`. + +You can then run lint-staged against the same files with: + +``` +npx lint-staged --diff="master...my-branch" +``` + +
+ ### Can I use `lint-staged` with `ng lint`
diff --git a/bin/lint-staged.js b/bin/lint-staged.js index a2c3dd508..66fa7fbe6 100755 --- a/bin/lint-staged.js +++ b/bin/lint-staged.js @@ -42,6 +42,11 @@ cli.option('--cwd [path]', 'run all tasks in specific directory, instead of the cli.option('-d, --debug', 'print additional debug information', false) +cli.option( + '--diff [string]', + 'override the default "--staged" flag of "git diff" to get list of files' +) + cli.option('--max-arg-length [number]', 'maximum length of the command-line argument string', 0) /** @@ -86,6 +91,7 @@ const options = { configPath: cliOptions.config, cwd: cliOptions.cwd, debug: !!cliOptions.debug, + diff: cliOptions.diff, maxArgLength: cliOptions.maxArgLength || undefined, quiet: !!cliOptions.quiet, relative: !!cliOptions.relative, diff --git a/lib/getStagedFiles.js b/lib/getStagedFiles.js index 363e07a1d..7ab9c0265 100644 --- a/lib/getStagedFiles.js +++ b/lib/getStagedFiles.js @@ -5,16 +5,18 @@ import normalize from 'normalize-path' import { execGit } from './execGit.js' import { parseGitZOutput } from './parseGitZOutput.js' -export const getStagedFiles = async ({ cwd = process.cwd() } = {}) => { - try { - // Docs for --diff-filter option: https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203 - // Docs for -z option: https://git-scm.com/docs/git-diff#Documentation/git-diff.txt--z - const lines = await execGit(['diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z'], { - cwd, - }) +/** + * Docs for --diff-filter option: @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203 + * Docs for -z option: @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt--z + */ +const ARGS = ['diff', '--diff-filter=ACMR', '--name-only', '-z'] +export const getStagedFiles = async ({ cwd = process.cwd(), diff } = {}) => { + try { + /** Use `--diff branch1...branch2` or `--diff="branch1 branch2", or fall back to default staged files */ + const diffArgs = diff !== undefined ? diff.trim().split(' ') : ['--staged'] + const lines = await execGit([...ARGS, ...diffArgs], { cwd }) if (!lines) return [] - return parseGitZOutput(lines).map((file) => normalize(path.resolve(cwd, file))) } catch { return null diff --git a/lib/index.js b/lib/index.js index e15616d49..f815743db 100644 --- a/lib/index.js +++ b/lib/index.js @@ -49,6 +49,7 @@ const getMaxArgLength = () => { * @param {string} [options.configPath] - Path to configuration file * @param {Object} [options.cwd] - Current working directory * @param {boolean} [options.debug] - Enable debug mode + * @param {string} [options.diff] - Override the default "--staged" flag of "git diff" to get list of files * @param {number} [options.maxArgLength] - Maximum argument string length * @param {boolean} [options.quiet] - Disable lint-staged’s own console output * @param {boolean} [options.relative] - Pass relative filepaths to tasks @@ -67,6 +68,7 @@ const lintStaged = async ( configPath, cwd, debug = false, + diff, maxArgLength = getMaxArgLength() / 2, quiet = false, relative = false, @@ -91,6 +93,7 @@ const lintStaged = async ( configPath, cwd, debug, + diff, maxArgLength, quiet, relative, diff --git a/lib/runAll.js b/lib/runAll.js index b9c54f7da..e2e682bf6 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -52,6 +52,7 @@ const createError = (ctx) => Object.assign(new Error('lint-staged failed'), { ct * @param {string} [options.configPath] - Explicit path to a config file * @param {string} [options.cwd] - Current working directory * @param {boolean} [options.debug] - Enable debug mode + * @param {string} [options.diff] - Override the default "--staged" flag of "git diff" to get list of files * @param {number} [options.maxArgLength] - Maximum argument string length * @param {boolean} [options.quiet] - Disable lint-staged’s own console output * @param {boolean} [options.relative] - Pass relative filepaths to tasks @@ -69,6 +70,7 @@ export const runAll = async ( configPath, cwd, debug = false, + diff, maxArgLength, quiet = false, relative = false, @@ -106,7 +108,7 @@ export const runAll = async ( logger.warn(skippingBackup(hasInitialCommit)) } - const files = await getStagedFiles({ cwd: gitDir }) + const files = await getStagedFiles({ cwd: gitDir, diff }) if (!files) { if (!quiet) ctx.output.push(FAILED_GET_STAGED_FILES) ctx.errors.add(GetStagedFilesError) diff --git a/test/getStagedFiles.spec.js b/test/getStagedFiles.spec.js index 15866460d..285a6d187 100644 --- a/test/getStagedFiles.spec.js +++ b/test/getStagedFiles.spec.js @@ -11,11 +11,20 @@ jest.mock('../lib/execGit') const normalizePath = (input) => normalize(path.resolve('/', input)) describe('getStagedFiles', () => { + afterEach(() => { + jest.clearAllMocks() + }) + it('should return array of file names', async () => { execGit.mockImplementationOnce(async () => 'foo.js\u0000bar.js\u0000') const staged = await getStagedFiles({ cwd: '/' }) // Windows filepaths expect(staged).toEqual([normalizePath('/foo.js'), normalizePath('/bar.js')]) + + expect(execGit).toHaveBeenLastCalledWith( + ['diff', '--diff-filter=ACMR', '--name-only', '-z', '--staged'], + { cwd: '/' } + ) }) it('should return empty array when no staged files', async () => { @@ -31,4 +40,28 @@ describe('getStagedFiles', () => { const staged = await getStagedFiles({}) expect(staged).toEqual(null) }) + + it('should support overriding diff trees with ...', async () => { + execGit.mockImplementationOnce(async () => 'foo.js\u0000bar.js\u0000') + const staged = await getStagedFiles({ cwd: '/', diff: 'master...my-branch' }) + // Windows filepaths + expect(staged).toEqual([normalizePath('/foo.js'), normalizePath('/bar.js')]) + + expect(execGit).toHaveBeenLastCalledWith( + ['diff', '--diff-filter=ACMR', '--name-only', '-z', 'master...my-branch'], + { cwd: '/' } + ) + }) + + it('should support overriding diff trees with multiple args', async () => { + execGit.mockImplementationOnce(async () => 'foo.js\u0000bar.js\u0000') + const staged = await getStagedFiles({ cwd: '/', diff: 'master my-branch' }) + // Windows filepaths + expect(staged).toEqual([normalizePath('/foo.js'), normalizePath('/bar.js')]) + + expect(execGit).toHaveBeenLastCalledWith( + ['diff', '--diff-filter=ACMR', '--name-only', '-z', 'master', 'my-branch'], + { cwd: '/' } + ) + }) }) diff --git a/test/integration.test.js b/test/integration.test.js index b90a35c8e..4fc81abe6 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -1309,6 +1309,32 @@ describe('lint-staged', () => { // File outside deeper/ was not fixed expect(await readFile('file.js')).toEqual(testJsFileUgly) }) + + it('should support overriding file list using --diff', async () => { + // Commit ugly file + await appendFile('test.js', testJsFileUgly) + await execGit(['add', 'test.js']) + await execGit(['commit', '-m', 'ugly'], { cwd }) + + const hashes = (await execGit(['log', '--format=format:%H'])).trim().split('\n') + expect(hashes).toHaveLength(2) + + // Run lint-staged with `--diff` between the two commits. + // Nothing is staged at this point, so don't rung `gitCommit` + const passed = await lintStaged({ + config: { '*.js': 'prettier --list-different' }, + cwd, + debug: true, + diff: `${hashes[1]}...${hashes[0]}`, + stash: false, + }) + + // Lint-staged failed because commit diff contains ugly file + expect(passed).toEqual(false) + + expect(console.printHistory()).toMatch('prettier --list-different:') + expect(console.printHistory()).toMatch('test.js') + }) }) describe('lintStaged', () => { From 753ef7281562e0a25a9fe01400d7108143116b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Sun, 29 May 2022 15:01:30 +0300 Subject: [PATCH 02/11] feat: add `--diff-filter` option for overriding list of (staged) files The `--diff-filter` option can be used to, for example, include deleted files instead of only the defaults: `--diff-filter=ACMRD`. --- README.md | 4 +++- bin/lint-staged.js | 6 ++++++ lib/getStagedFiles.js | 25 +++++++++++++++++-------- lib/index.js | 3 +++ lib/runAll.js | 4 +++- test/getStagedFiles.spec.js | 18 +++++++++++++++--- test/integration.test.js | 19 +++++++++++++++++++ 7 files changed, 66 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d4f12cb4f..cdd994aba 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ Options: --cwd [path] run all tasks in specific directory, instead of the current -d, --debug print additional debug information (default: false) --diff [string] override the default "--staged" flag of "git diff" to get list of files + --diff-filter [string] override the default "--diff-filter=ACMR" flag of "git diff" to get list of files --max-arg-length [number] maximum length of the command-line argument string (default: 0) --no-stash disable the backup stash, and do not revert in case of errors -q, --quiet disable lint-staged’s own console output (default: false) @@ -113,7 +114,8 @@ Options: - **`--debug`**: Run in debug mode. When set, it does the following: - uses [debug](https://github.com/visionmedia/debug) internally to log additional information about staged files, commands being executed, location of binaries, etc. Debug logs, which are automatically enabled by passing the flag, can also be enabled by setting the environment variable `$DEBUG` to `lint-staged*`. - uses [`verbose` renderer](https://github.com/SamVerschueren/listr-verbose-renderer) for `listr`; this causes serial, uncoloured output to the terminal, instead of the default (beautified, dynamic) output. -- **`--diff`**: By default linters are filtered against all files staged in git, generated from `git diff --staged`. This option allows you to override the `--staged` flag with arbitrary revisions. For example to get a list of changed files between two branches, use `--diff="branch1...branch2"`. You can also read more from about [`git diff`](https://git-scm.com/docs/git-diff) and [`gitrevisions`](https://git-scm.com/docs/gitrevisions). +- **`--diff`**: By default linters are filtered against all files staged in git, generated from `git diff --staged`. This option allows you to override the `--staged` flag with arbitrary revisions. For example to get a list of changed files between two branches, use `--diff="branch1...branch2"`. You can also read more from about [git diff](https://git-scm.com/docs/git-diff) and [gitrevisions](https://git-scm.com/docs/gitrevisions). +- **`--diff-filter`**: By default only files that are _added_, _copied_, _modified_, or _renamed_ are included. Use this flag to override the default `ACMR` value with something else: _added_ (`A`), _copied_ (`C`), _deleted_ (`D`), _modified_ (`M`), _renamed_ (`R`), _type changed_ (`T`), _unmerged_ (`U`), _unknown_ (`X`), or _pairing broken_ (`B`). See also the `git diff` docs for [--diff-filter](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203). - **`--max-arg-length`**: long commands (a lot of files) are automatically split into multiple chunks when it detects the current shell cannot handle them. Use this flag to override the maximum length of the generated command string. - **`--no-stash`**: By default a backup stash will be created before running the tasks, and all task modifications will be reverted in case of an error. This option will disable creating the stash, and instead leave all modifications in the index when aborting the commit. - **`--quiet`**: Supress all CLI output, except from tasks. diff --git a/bin/lint-staged.js b/bin/lint-staged.js index 66fa7fbe6..21018ddbe 100755 --- a/bin/lint-staged.js +++ b/bin/lint-staged.js @@ -47,6 +47,11 @@ cli.option( 'override the default "--staged" flag of "git diff" to get list of files' ) +cli.option( + '--diff-filter [string]', + 'override the default "--diff-filter=ACMR" flag of "git diff" to get list of files' +) + cli.option('--max-arg-length [number]', 'maximum length of the command-line argument string', 0) /** @@ -92,6 +97,7 @@ const options = { cwd: cliOptions.cwd, debug: !!cliOptions.debug, diff: cliOptions.diff, + diffFilter: cliOptions.diffFilter, maxArgLength: cliOptions.maxArgLength || undefined, quiet: !!cliOptions.quiet, relative: !!cliOptions.relative, diff --git a/lib/getStagedFiles.js b/lib/getStagedFiles.js index 7ab9c0265..08f7723fd 100644 --- a/lib/getStagedFiles.js +++ b/lib/getStagedFiles.js @@ -5,18 +5,27 @@ import normalize from 'normalize-path' import { execGit } from './execGit.js' import { parseGitZOutput } from './parseGitZOutput.js' -/** - * Docs for --diff-filter option: @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203 - * Docs for -z option: @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt--z - */ -const ARGS = ['diff', '--diff-filter=ACMR', '--name-only', '-z'] - -export const getStagedFiles = async ({ cwd = process.cwd(), diff } = {}) => { +export const getStagedFiles = async ({ cwd = process.cwd(), diff, diffFilter } = {}) => { try { + /** + * Docs for --diff-filter option: + * @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203 + */ + const diffFilterArg = diffFilter !== undefined ? diffFilter.trim() : 'ACMR' + /** Use `--diff branch1...branch2` or `--diff="branch1 branch2", or fall back to default staged files */ const diffArgs = diff !== undefined ? diff.trim().split(' ') : ['--staged'] - const lines = await execGit([...ARGS, ...diffArgs], { cwd }) + + /** + * Docs for -z option: + * @see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt--z + */ + const lines = await execGit( + ['diff', '--name-only', '-z', `--diff-filter=${diffFilterArg}`, ...diffArgs], + { cwd } + ) if (!lines) return [] + return parseGitZOutput(lines).map((file) => normalize(path.resolve(cwd, file))) } catch { return null diff --git a/lib/index.js b/lib/index.js index f815743db..636e3ae59 100644 --- a/lib/index.js +++ b/lib/index.js @@ -50,6 +50,7 @@ const getMaxArgLength = () => { * @param {Object} [options.cwd] - Current working directory * @param {boolean} [options.debug] - Enable debug mode * @param {string} [options.diff] - Override the default "--staged" flag of "git diff" to get list of files + * @param {string} [options.diffFilter] - Override the default "--diff-filter=ACMR" flag of "git diff" to get list of files * @param {number} [options.maxArgLength] - Maximum argument string length * @param {boolean} [options.quiet] - Disable lint-staged’s own console output * @param {boolean} [options.relative] - Pass relative filepaths to tasks @@ -69,6 +70,7 @@ const lintStaged = async ( cwd, debug = false, diff, + diffFilter, maxArgLength = getMaxArgLength() / 2, quiet = false, relative = false, @@ -94,6 +96,7 @@ const lintStaged = async ( cwd, debug, diff, + diffFilter, maxArgLength, quiet, relative, diff --git a/lib/runAll.js b/lib/runAll.js index e2e682bf6..f2cdc0366 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -53,6 +53,7 @@ const createError = (ctx) => Object.assign(new Error('lint-staged failed'), { ct * @param {string} [options.cwd] - Current working directory * @param {boolean} [options.debug] - Enable debug mode * @param {string} [options.diff] - Override the default "--staged" flag of "git diff" to get list of files + * @param {string} [options.diffFilter] - Override the default "--diff-filter=ACMR" flag of "git diff" to get list of files * @param {number} [options.maxArgLength] - Maximum argument string length * @param {boolean} [options.quiet] - Disable lint-staged’s own console output * @param {boolean} [options.relative] - Pass relative filepaths to tasks @@ -71,6 +72,7 @@ export const runAll = async ( cwd, debug = false, diff, + diffFilter, maxArgLength, quiet = false, relative = false, @@ -108,7 +110,7 @@ export const runAll = async ( logger.warn(skippingBackup(hasInitialCommit)) } - const files = await getStagedFiles({ cwd: gitDir, diff }) + const files = await getStagedFiles({ cwd: gitDir, diff, diffFilter }) if (!files) { if (!quiet) ctx.output.push(FAILED_GET_STAGED_FILES) ctx.errors.add(GetStagedFilesError) diff --git a/test/getStagedFiles.spec.js b/test/getStagedFiles.spec.js index 285a6d187..620b8ebd2 100644 --- a/test/getStagedFiles.spec.js +++ b/test/getStagedFiles.spec.js @@ -22,7 +22,7 @@ describe('getStagedFiles', () => { expect(staged).toEqual([normalizePath('/foo.js'), normalizePath('/bar.js')]) expect(execGit).toHaveBeenLastCalledWith( - ['diff', '--diff-filter=ACMR', '--name-only', '-z', '--staged'], + ['diff', '--name-only', '-z', '--diff-filter=ACMR', '--staged'], { cwd: '/' } ) }) @@ -48,7 +48,7 @@ describe('getStagedFiles', () => { expect(staged).toEqual([normalizePath('/foo.js'), normalizePath('/bar.js')]) expect(execGit).toHaveBeenLastCalledWith( - ['diff', '--diff-filter=ACMR', '--name-only', '-z', 'master...my-branch'], + ['diff', '--name-only', '-z', '--diff-filter=ACMR', 'master...my-branch'], { cwd: '/' } ) }) @@ -60,7 +60,19 @@ describe('getStagedFiles', () => { expect(staged).toEqual([normalizePath('/foo.js'), normalizePath('/bar.js')]) expect(execGit).toHaveBeenLastCalledWith( - ['diff', '--diff-filter=ACMR', '--name-only', '-z', 'master', 'my-branch'], + ['diff', '--name-only', '-z', '--diff-filter=ACMR', 'master', 'my-branch'], + { cwd: '/' } + ) + }) + + it('should support overriding diff-filter', async () => { + execGit.mockImplementationOnce(async () => 'foo.js\u0000bar.js\u0000') + const staged = await getStagedFiles({ cwd: '/', diffFilter: 'ACDMRTUXB' }) + // Windows filepaths + expect(staged).toEqual([normalizePath('/foo.js'), normalizePath('/bar.js')]) + + expect(execGit).toHaveBeenLastCalledWith( + ['diff', '--name-only', '-z', '--diff-filter=ACDMRTUXB', '--staged'], { cwd: '/' } ) }) diff --git a/test/integration.test.js b/test/integration.test.js index 4fc81abe6..afc0bda45 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -1335,6 +1335,25 @@ describe('lint-staged', () => { expect(console.printHistory()).toMatch('prettier --list-different:') expect(console.printHistory()).toMatch('test.js') }) + + it('should support overriding default --diff-filter', async () => { + // Stage ugly file + await appendFile('test.js', testJsFileUgly) + await execGit(['add', 'test.js']) + + // Run lint-staged with `--diff-filter=D` to include only deleted files. + const passed = await lintStaged({ + config: { '*.js': 'prettier --list-different' }, + cwd, + diffFilter: 'D', + stash: false, + }) + + // Lint-staged passed because no matching (deleted) files + expect(passed).toEqual(true) + + expect(console.printHistory()).toMatch('No staged files found') + }) }) describe('lintStaged', () => { From 641d1c2fd00992e926ae07defbb98c4d324f3b13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Sun, 29 May 2022 15:53:58 +0300 Subject: [PATCH 03/11] fix: include all files when using `--config ` --- lib/groupFilesByConfig.js | 8 +++----- lib/runAll.js | 6 +++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/groupFilesByConfig.js b/lib/groupFilesByConfig.js index 8d734bad8..10cbb1baf 100644 --- a/lib/groupFilesByConfig.js +++ b/lib/groupFilesByConfig.js @@ -2,11 +2,9 @@ import path from 'path' import debug from 'debug' -import { ConfigObjectSymbol } from './searchConfigs.js' - const debugLog = debug('lint-staged:groupFilesByConfig') -export const groupFilesByConfig = async ({ configs, files }) => { +export const groupFilesByConfig = async ({ configs, files, singleConfigMode }) => { debugLog('Grouping %d files by %d configurations', files.length, Object.keys(configs).length) const filesSet = new Set(files) @@ -16,8 +14,8 @@ export const groupFilesByConfig = async ({ configs, files }) => { for (const filepath of Reflect.ownKeys(configs)) { const config = configs[filepath] - /** When passed an explicit config object via the Node.js API, skip logic */ - if (filepath === ConfigObjectSymbol) { + /** When passed an explicit config object via the Node.js API‚ or an explicit path, skip logic */ + if (singleConfigMode) { filesByConfig[filepath] = { config, files } break } diff --git a/lib/runAll.js b/lib/runAll.js index f2cdc0366..d26187a63 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -133,7 +133,11 @@ export const runAll = async ( throw createError(ctx, ConfigNotFoundError) } - const filesByConfig = await groupFilesByConfig({ configs: foundConfigs, files }) + const filesByConfig = await groupFilesByConfig({ + configs: foundConfigs, + files, + singleConfigMode: configObject || configPath !== undefined, + }) const hasMultipleConfigs = numberOfConfigs > 1 From 1f06dd0a37c64f856180d77763c788753057c92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Mon, 30 May 2022 08:54:23 +0300 Subject: [PATCH 04/11] refactor: do not use Symbol in configuration mapping --- lib/groupFilesByConfig.js | 4 +--- lib/runAll.js | 13 ++++--------- lib/searchConfigs.js | 4 +--- test/searchConfigs.spec.js | 4 ++-- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/lib/groupFilesByConfig.js b/lib/groupFilesByConfig.js index 10cbb1baf..ee5c67a97 100644 --- a/lib/groupFilesByConfig.js +++ b/lib/groupFilesByConfig.js @@ -11,9 +11,7 @@ export const groupFilesByConfig = async ({ configs, files, singleConfigMode }) = const filesByConfig = {} /** Configs are sorted deepest first by `searchConfigs` */ - for (const filepath of Reflect.ownKeys(configs)) { - const config = configs[filepath] - + for (const [filepath, config] of Object.entries(configs)) { /** When passed an explicit config object via the Node.js API‚ or an explicit path, skip logic */ if (singleConfigMode) { filesByConfig[filepath] = { config, files } diff --git a/lib/runAll.js b/lib/runAll.js index d26187a63..7bbd91146 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -36,7 +36,7 @@ import { restoreUnstagedChangesSkipped, } from './state.js' import { GitRepoError, GetStagedFilesError, GitError, ConfigNotFoundError } from './symbols.js' -import { ConfigObjectSymbol, searchConfigs } from './searchConfigs.js' +import { searchConfigs } from './searchConfigs.js' const debugLog = debug('lint-staged:runAll') @@ -125,7 +125,7 @@ export const runAll = async ( } const foundConfigs = await searchConfigs({ configObject, configPath, cwd, gitDir }, logger) - const numberOfConfigs = Reflect.ownKeys(foundConfigs).length + const numberOfConfigs = Object.keys(foundConfigs).length // Throw if no configurations were found if (numberOfConfigs === 0) { @@ -157,13 +157,8 @@ export const runAll = async ( // Set of all staged files that matched a task glob. Values in a set are unique. const matchedFiles = new Set() - for (const configPath of Reflect.ownKeys(filesByConfig)) { - const { config, files } = filesByConfig[configPath] - - const configName = - configPath === ConfigObjectSymbol - ? 'Config object' - : normalize(path.relative(cwd, configPath)) + for (const [configPath, { config, files }] of Object.entries(filesByConfig)) { + const configName = configPath ? normalize(path.relative(cwd, configPath)) : 'Config object' const stagedFileChunks = chunkFiles({ baseDir: gitDir, files, maxArgLength, relative }) diff --git a/lib/searchConfigs.js b/lib/searchConfigs.js index ebadd0144..02fc3a56f 100644 --- a/lib/searchConfigs.js +++ b/lib/searchConfigs.js @@ -23,8 +23,6 @@ const sortDeepestParth = (a, b) => (numberOfLevels(a) > numberOfLevels(b) ? -1 : const isInsideDirectory = (dir) => (file) => file.startsWith(normalize(dir)) -export const ConfigObjectSymbol = Symbol() - /** * Search all config files from the git repository, preferring those inside `cwd`. * @@ -46,7 +44,7 @@ export const searchConfigs = async ( if (configObject) { debugLog('Using single direct configuration object...') - return { [ConfigObjectSymbol]: validateConfig(configObject, 'config object', logger) } + return { '': validateConfig(configObject, 'config object', logger) } } // Use only explicit config path instead of discovering multiple diff --git a/test/searchConfigs.spec.js b/test/searchConfigs.spec.js index e7adcc206..eb229fe6a 100644 --- a/test/searchConfigs.spec.js +++ b/test/searchConfigs.spec.js @@ -4,7 +4,7 @@ import normalize from 'normalize-path' import { execGit } from '../lib/execGit.js' import { loadConfig } from '../lib/loadConfig.js' -import { ConfigObjectSymbol, searchConfigs } from '../lib/searchConfigs.js' +import { searchConfigs } from '../lib/searchConfigs.js' jest.mock('../lib/resolveConfig', () => ({ /** Unfortunately necessary due to non-ESM tests. */ @@ -47,7 +47,7 @@ describe('searchConfigs', () => { it('should return config for valid config object', async () => { await expect(searchConfigs({ configObject: { '*.js': 'eslint' } })).resolves.toEqual({ - [ConfigObjectSymbol]: { '*.js': 'eslint' }, + '': { '*.js': 'eslint' }, }) }) From d4da24d90cfa85ef8589a5f8c6ba5f51c3b45275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Mon, 30 May 2022 15:23:32 +0300 Subject: [PATCH 05/11] fix: skip backup stash when using the `--diff` option --- README.md | 3 ++- bin/lint-staged.js | 2 +- lib/index.js | 37 ++++++++++++++++++------------------- lib/messages.js | 10 ++++++++-- lib/runAll.js | 7 ++++--- test/runAll.spec.js | 11 +++++++++++ 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index cdd994aba..42b6938e2 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,8 @@ Options: -c, --config [path] path to configuration file, or - to read from stdin --cwd [path] run all tasks in specific directory, instead of the current -d, --debug print additional debug information (default: false) - --diff [string] override the default "--staged" flag of "git diff" to get list of files + --diff [string] override the default "--staged" flag of "git diff" to get list of files. Implies + "--no-stash". --diff-filter [string] override the default "--diff-filter=ACMR" flag of "git diff" to get list of files --max-arg-length [number] maximum length of the command-line argument string (default: 0) --no-stash disable the backup stash, and do not revert in case of errors diff --git a/bin/lint-staged.js b/bin/lint-staged.js index 21018ddbe..115ce1a96 100755 --- a/bin/lint-staged.js +++ b/bin/lint-staged.js @@ -44,7 +44,7 @@ cli.option('-d, --debug', 'print additional debug information', false) cli.option( '--diff [string]', - 'override the default "--staged" flag of "git diff" to get list of files' + 'override the default "--staged" flag of "git diff" to get list of files. Implies "--no-stash".' ) cli.option( diff --git a/lib/index.js b/lib/index.js index 636e3ae59..2e250fecf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -86,26 +86,25 @@ const lintStaged = async ( debugLog('Unset GIT_LITERAL_PATHSPECS (was `%s`)', process.env.GIT_LITERAL_PATHSPECS) delete process.env.GIT_LITERAL_PATHSPECS + const options = { + allowEmpty, + concurrent, + configObject, + configPath, + cwd, + debug, + diff, + diffFilter, + maxArgLength, + quiet, + relative, + shell, + stash, + verbose, + } + try { - const ctx = await runAll( - { - allowEmpty, - concurrent, - configObject, - configPath, - cwd, - debug, - diff, - diffFilter, - maxArgLength, - quiet, - relative, - shell, - stash, - verbose, - }, - logger - ) + const ctx = await runAll(options, logger) debugLog('Tasks were executed successfully!') printTaskOutput(ctx, logger) return true diff --git a/lib/messages.js b/lib/messages.js index 6083f77cf..2be1d5b87 100644 --- a/lib/messages.js +++ b/lib/messages.js @@ -28,8 +28,14 @@ export const NO_STAGED_FILES = `${info} No staged files found.` export const NO_TASKS = `${info} No staged files match any configured task.` -export const skippingBackup = (hasInitialCommit) => { - const reason = hasInitialCommit ? '`--no-stash` was used' : 'there’s no initial commit yet' +export const skippingBackup = (hasInitialCommit, diff) => { + const reason = + diff !== undefined + ? '`--diff` was used' + : hasInitialCommit + ? '`--no-stash` was used' + : 'there’s no initial commit yet' + return yellow(`${warning} Skipping backup because ${reason}.\n`) } diff --git a/lib/runAll.js b/lib/runAll.js index 7bbd91146..08f06d190 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -104,10 +104,11 @@ export const runAll = async ( .then(() => true) .catch(() => false) - // Lint-staged should create a backup stash only when there's an initial commit - ctx.shouldBackup = hasInitialCommit && stash + // Lint-staged should create a backup stash only when there's an initial commit, + // and when using the default list of staged files + ctx.shouldBackup = hasInitialCommit && stash && diff === undefined if (!ctx.shouldBackup) { - logger.warn(skippingBackup(hasInitialCommit)) + logger.warn(skippingBackup(hasInitialCommit, diff)) } const files = await getStagedFiles({ cwd: gitDir, diff, diffFilter }) diff --git a/test/runAll.spec.js b/test/runAll.spec.js index f890383aa..58a6cefe0 100644 --- a/test/runAll.spec.js +++ b/test/runAll.spec.js @@ -45,6 +45,7 @@ describe('runAll', () => { beforeAll(() => { console = makeConsoleMock() + jest.clearAllMocks() }) afterEach(() => { @@ -372,4 +373,14 @@ describe('runAll', () => { expect(ctx.errors.has(ConfigNotFoundError)).toBe(true) } }) + + it('should warn when --no-stash was used', async () => { + await runAll({ configObject: { '*.js': ['echo "sample"'] }, stash: false }) + expect(console.printHistory()).toMatch('Skipping backup because `--no-stash` was used') + }) + + it('should warn when --diff was used', async () => { + await runAll({ configObject: { '*.js': ['echo "sample"'] }, diff: 'branch1...branch2' }) + expect(console.printHistory()).toMatch('Skipping backup because `--diff` was used') + }) }) From 5fb6df94ccd6de6f5fdd743474c094ff366cc671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Mon, 30 May 2022 15:26:37 +0300 Subject: [PATCH 06/11] feat: remove support for Node.js 12 BREAKING CHANGE: `lint-staged` will no longer support Node.js 12, which is EOL since 30 April 2022 --- .github/workflows/main.yml | 3 +-- README.md | 4 ++++ package-lock.json | 2 +- package.json | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cc1851bba..abc53b8c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -40,9 +40,8 @@ jobs: test: strategy: matrix: - # Test with Node.js v12 (LTS), v14 (LTS), v16 (LTS), and 18 (Current) + # Test with Node.js v14 (LTS), v16 (LTS), and 18 (Current) node: - - 12 - 14 - 16 - 18 diff --git a/README.md b/README.md index 42b6938e2..9e1435077 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,10 @@ See [Releases](https://github.com/okonet/lint-staged/releases). ### Migration +#### v13 + +- Since `v13.0.0` _lint-staged_ no longer supports Node.js 12. Please upgrade your Node.js version to at least `14.13.1`, or `16.0.0` onward. + #### v12 - Since `v12.0.0` _lint-staged_ is a pure ESM module, so make sure your Node.js version is at least `12.20.0`, `14.13.1`, or `16.0.0`. Read more about ESM modules from the official [Node.js Documentation site here](https://nodejs.org/api/esm.html#introduction). diff --git a/package-lock.json b/package-lock.json index e50e5a289..91619350b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,7 +46,7 @@ "prettier": "^2.6.2" }, "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": "^14.13.1 || >=16.0.0" }, "funding": { "url": "https://opencollective.com/lint-staged" diff --git a/package.json b/package.json index 7483656d1..29fe518ff 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "url": "https://opencollective.com/lint-staged" }, "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": "^14.13.1 || >=16.0.0" }, "type": "module", "bin": "./bin/lint-staged.js", From eae9622e4fa100d6bce658c37146cb4ba0307974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Mon, 30 May 2022 15:31:52 +0300 Subject: [PATCH 07/11] refactor: use `node:` protocol imports --- bin/lint-staged.js | 6 +++--- lib/chunkFiles.js | 2 +- lib/dynamicImport.js | 2 +- lib/file.js | 2 +- lib/generateTasks.js | 2 +- lib/getStagedFiles.js | 2 +- lib/gitWorkflow.js | 2 +- lib/groupFilesByConfig.js | 2 +- lib/resolveConfig.js | 2 +- lib/resolveGitRepo.js | 4 ++-- lib/runAll.js | 2 +- lib/searchConfigs.js | 6 +++--- lib/validateOptions.js | 5 +++-- test/loadConfig.spec.js | 2 +- 14 files changed, 21 insertions(+), 20 deletions(-) diff --git a/bin/lint-staged.js b/bin/lint-staged.js index 115ce1a96..ca18bdf74 100755 --- a/bin/lint-staged.js +++ b/bin/lint-staged.js @@ -1,8 +1,8 @@ #!/usr/bin/env node -import fs from 'fs' -import path from 'path' -import { fileURLToPath } from 'url' +import fs from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' import { Option, program } from 'commander' import debug from 'debug' diff --git a/lib/chunkFiles.js b/lib/chunkFiles.js index f04c25a65..64761a046 100644 --- a/lib/chunkFiles.js +++ b/lib/chunkFiles.js @@ -1,4 +1,4 @@ -import path from 'path' +import path from 'node:path' import debug from 'debug' import normalize from 'normalize-path' diff --git a/lib/dynamicImport.js b/lib/dynamicImport.js index 75e228fc2..fba6409cd 100644 --- a/lib/dynamicImport.js +++ b/lib/dynamicImport.js @@ -1,3 +1,3 @@ -import { pathToFileURL } from 'url' +import { pathToFileURL } from 'node:url' export const dynamicImport = (path) => import(pathToFileURL(path)).then((module) => module.default) diff --git a/lib/file.js b/lib/file.js index 3f88414e8..2d871fa43 100644 --- a/lib/file.js +++ b/lib/file.js @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs' +import fs from 'node:fs/promises' import debug from 'debug' diff --git a/lib/generateTasks.js b/lib/generateTasks.js index 99e3e91cf..b05d625f3 100644 --- a/lib/generateTasks.js +++ b/lib/generateTasks.js @@ -1,4 +1,4 @@ -import path from 'path' +import path from 'node:path' import debug from 'debug' import micromatch from 'micromatch' diff --git a/lib/getStagedFiles.js b/lib/getStagedFiles.js index 08f7723fd..b301d4225 100644 --- a/lib/getStagedFiles.js +++ b/lib/getStagedFiles.js @@ -1,4 +1,4 @@ -import path from 'path' +import path from 'node:path' import normalize from 'normalize-path' diff --git a/lib/gitWorkflow.js b/lib/gitWorkflow.js index a2f842355..8ae95e7e1 100644 --- a/lib/gitWorkflow.js +++ b/lib/gitWorkflow.js @@ -1,4 +1,4 @@ -import path from 'path' +import path from 'node:path' import debug from 'debug' diff --git a/lib/groupFilesByConfig.js b/lib/groupFilesByConfig.js index ee5c67a97..e6e90e7a8 100644 --- a/lib/groupFilesByConfig.js +++ b/lib/groupFilesByConfig.js @@ -1,4 +1,4 @@ -import path from 'path' +import path from 'node:path' import debug from 'debug' diff --git a/lib/resolveConfig.js b/lib/resolveConfig.js index 0b9f357c1..cb4ab0bde 100644 --- a/lib/resolveConfig.js +++ b/lib/resolveConfig.js @@ -1,4 +1,4 @@ -import { createRequire } from 'module' +import { createRequire } from 'node:module' /** * require() does not exist for ESM, so we must create it to use require.resolve(). diff --git a/lib/resolveGitRepo.js b/lib/resolveGitRepo.js index 3e7460369..f01570590 100644 --- a/lib/resolveGitRepo.js +++ b/lib/resolveGitRepo.js @@ -1,5 +1,5 @@ -import { promises as fs } from 'fs' -import path from 'path' +import fs from 'node:fs/promises' +import path from 'node:path' import debug from 'debug' import normalize from 'normalize-path' diff --git a/lib/runAll.js b/lib/runAll.js index 08f06d190..63b68a159 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -1,6 +1,6 @@ /** @typedef {import('./index').Logger} Logger */ -import path from 'path' +import path from 'node:path' import { dim } from 'colorette' import debug from 'debug' diff --git a/lib/searchConfigs.js b/lib/searchConfigs.js index 02fc3a56f..dce5b0dbc 100644 --- a/lib/searchConfigs.js +++ b/lib/searchConfigs.js @@ -1,6 +1,6 @@ /** @typedef {import('./index').Logger} Logger */ -import { basename, join } from 'path' +import path from 'node:path' import debug from 'debug' import normalize from 'normalize-path' @@ -15,7 +15,7 @@ const debugLog = debug('lint-staged:searchConfigs') const EXEC_GIT = ['ls-files', '-z', '--full-name'] const filterPossibleConfigFiles = (files) => - files.filter((file) => searchPlaces.includes(basename(file))) + files.filter((file) => searchPlaces.includes(path.basename(file))) const numberOfLevels = (file) => file.split('/').length @@ -68,7 +68,7 @@ export const searchConfigs = async ( /** Sort possible config files so that deepest is first */ const possibleConfigFiles = [...cachedFiles, ...otherFiles] - .map((file) => normalize(join(gitDir, file))) + .map((file) => normalize(path.join(gitDir, file))) .filter(isInsideDirectory(cwd)) .sort(sortDeepestParth) diff --git a/lib/validateOptions.js b/lib/validateOptions.js index 78b4c01e1..a97e60c1d 100644 --- a/lib/validateOptions.js +++ b/lib/validateOptions.js @@ -1,5 +1,6 @@ -import { constants, promises as fs } from 'fs' -import path from 'path' +import { constants } from 'node:fs' +import fs from 'node:fs/promises' +import path from 'node:path' import debug from 'debug' diff --git a/test/loadConfig.spec.js b/test/loadConfig.spec.js index 2a533a19c..44888364f 100644 --- a/test/loadConfig.spec.js +++ b/test/loadConfig.spec.js @@ -21,7 +21,7 @@ jest.unmock('execa') * This converts paths into `file://` urls, but this doesn't * work with `import()` when using babel + jest. */ -jest.mock('url', () => ({ +jest.mock('node:url', () => ({ pathToFileURL: (path) => path, })) From 5f0a6a73acf7cbe3dc8cd70e6dbc569dc452e2e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Mon, 30 May 2022 15:34:27 +0300 Subject: [PATCH 08/11] refactor: use optional chaining `?.` --- lib/index.js | 2 +- lib/printTaskOutput.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 2e250fecf..85420f546 100644 --- a/lib/index.js +++ b/lib/index.js @@ -109,7 +109,7 @@ const lintStaged = async ( printTaskOutput(ctx, logger) return true } catch (runAllError) { - if (runAllError && runAllError.ctx && runAllError.ctx.errors) { + if (runAllError?.ctx?.errors) { const { ctx } = runAllError if (ctx.errors.has(ConfigNotFoundError)) { diff --git a/lib/printTaskOutput.js b/lib/printTaskOutput.js index 831f8fd07..e3a4845d6 100644 --- a/lib/printTaskOutput.js +++ b/lib/printTaskOutput.js @@ -5,7 +5,7 @@ */ export const printTaskOutput = (ctx = {}, logger) => { if (!Array.isArray(ctx.output)) return - const log = ctx.errors && ctx.errors.size > 0 ? logger.error : logger.log + const log = ctx.errors?.size > 0 ? logger.error : logger.log for (const line of ctx.output) { log(line) } From 2750a3d9d909fd834b95da752f0f6800340922b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Mon, 30 May 2022 15:35:31 +0300 Subject: [PATCH 09/11] fix(deps): update `yaml@^2.1.1` --- package-lock.json | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 91619350b..0c35aa385 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ "pidtree": "^0.5.0", "string-argv": "^0.3.1", "supports-color": "^9.2.2", - "yaml": "^1.10.2" + "yaml": "^2.1.1" }, "bin": { "lint-staged": "bin/lint-staged.js" @@ -8171,11 +8171,11 @@ "dev": true }, "node_modules/yaml": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", - "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.1.1.tgz", + "integrity": "sha512-o96x3OPo8GjWeSLF+wOAbrPfhFOGY0W00GNaxCDv+9hkcDJEnev1yh8S7pgHF0ik6zc8sQLuL8hjHjJULZp8bw==", "engines": { - "node": ">= 6" + "node": ">= 14" } }, "node_modules/yargs": { @@ -14224,9 +14224,9 @@ "dev": true }, "yaml": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", - "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==" + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.1.1.tgz", + "integrity": "sha512-o96x3OPo8GjWeSLF+wOAbrPfhFOGY0W00GNaxCDv+9hkcDJEnev1yh8S7pgHF0ik6zc8sQLuL8hjHjJULZp8bw==" }, "yargs": { "version": "17.5.1", diff --git a/package.json b/package.json index 29fe518ff..96e67921d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "pidtree": "^0.5.0", "string-argv": "^0.3.1", "supports-color": "^9.2.2", - "yaml": "^1.10.2" + "yaml": "^2.1.1" }, "devDependencies": { "@babel/core": "^7.18.2", From 659c85c5cd4c4040a505bbe9fddbe7d416ac15c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Mon, 30 May 2022 15:38:31 +0300 Subject: [PATCH 10/11] fix(deps): update `execa@^6.1.0` --- lib/execGit.js | 2 +- lib/resolveTaskFn.js | 4 +- package-lock.json | 388 ++++++++++++++++++++++++++++++++----- package.json | 2 +- test/__mocks__/execa.js | 6 +- test/execGit.spec.js | 2 +- test/makeCmdTasks.spec.js | 2 +- test/resolveTaskFn.spec.js | 2 +- test/runAll.spec.js | 2 +- 9 files changed, 346 insertions(+), 64 deletions(-) diff --git a/lib/execGit.js b/lib/execGit.js index 432a290cb..e2f79c6b4 100644 --- a/lib/execGit.js +++ b/lib/execGit.js @@ -1,5 +1,5 @@ import debug from 'debug' -import execa from 'execa' +import { execa } from 'execa' const debugLog = debug('lint-staged:execGit') diff --git a/lib/resolveTaskFn.js b/lib/resolveTaskFn.js index 77a4ab777..45f16b570 100644 --- a/lib/resolveTaskFn.js +++ b/lib/resolveTaskFn.js @@ -1,5 +1,5 @@ import { redBright, dim } from 'colorette' -import execa from 'execa' +import { execa, execaCommand } from 'execa' import debug from 'debug' import { parseArgsStringToArgv } from 'string-argv' import pidTree from 'pidtree' @@ -139,7 +139,7 @@ export const resolveTaskFn = ({ return async (ctx = getInitialState()) => { const execaChildProcess = shell - ? execa.command(isFn ? command : `${command} ${files.join(' ')}`, execaOptions) + ? execaCommand(isFn ? command : `${command} ${files.join(' ')}`, execaOptions) : execa(cmd, isFn ? args : args.concat(files), execaOptions) const quitInterruptCheck = interruptExecutionOnError(ctx, execaChildProcess) diff --git a/package-lock.json b/package-lock.json index 0c35aa385..66f712a8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "colorette": "^2.0.16", "commander": "^9.3.0", "debug": "^4.3.4", - "execa": "^5.1.1", + "execa": "^6.1.0", "lilconfig": "2.0.5", "listr2": "^4.0.5", "micromatch": "^4.0.5", @@ -4094,27 +4094,52 @@ } }, "node_modules/execa": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", - "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-6.1.0.tgz", + "integrity": "sha512-QVWlX2e50heYJcCPG0iWtf8r0xjEYfz/OYLGDYH+IyjWezzPNxz63qNFOu0l4YftGWuizFVZHHs8PrLU5p2IDA==", "dependencies": { "cross-spawn": "^7.0.3", - "get-stream": "^6.0.0", - "human-signals": "^2.1.0", - "is-stream": "^2.0.0", + "get-stream": "^6.0.1", + "human-signals": "^3.0.1", + "is-stream": "^3.0.0", "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.1", - "onetime": "^5.1.2", - "signal-exit": "^3.0.3", - "strip-final-newline": "^2.0.0" + "npm-run-path": "^5.1.0", + "onetime": "^6.0.0", + "signal-exit": "^3.0.7", + "strip-final-newline": "^3.0.0" }, "engines": { - "node": ">=10" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "funding": { "url": "https://github.com/sindresorhus/execa?sponsor=1" } }, + "node_modules/execa/node_modules/mimic-fn": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", + "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/execa/node_modules/onetime": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", + "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", + "dependencies": { + "mimic-fn": "^4.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/exit": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", @@ -4483,11 +4508,11 @@ "dev": true }, "node_modules/human-signals": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", - "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-3.0.1.tgz", + "integrity": "sha512-rQLskxnM/5OCldHo+wNXbpVgDn5A17CUoKX+7Sokwaknlq7CdSnphy0W39GU8dw59XiCXmFXDg4fRuckQRKewQ==", "engines": { - "node": ">=10.17.0" + "node": ">=12.20.0" } }, "node_modules/husky": { @@ -4834,11 +4859,11 @@ } }, "node_modules/is-stream": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", - "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", + "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==", "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -5019,6 +5044,71 @@ "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" } }, + "node_modules/jest-changed-files/node_modules/execa": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", + "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.3", + "get-stream": "^6.0.0", + "human-signals": "^2.1.0", + "is-stream": "^2.0.0", + "merge-stream": "^2.0.0", + "npm-run-path": "^4.0.1", + "onetime": "^5.1.2", + "signal-exit": "^3.0.3", + "strip-final-newline": "^2.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sindresorhus/execa?sponsor=1" + } + }, + "node_modules/jest-changed-files/node_modules/human-signals": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", + "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", + "dev": true, + "engines": { + "node": ">=10.17.0" + } + }, + "node_modules/jest-changed-files/node_modules/is-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "dev": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/jest-changed-files/node_modules/npm-run-path": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", + "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "dev": true, + "dependencies": { + "path-key": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/jest-changed-files/node_modules/strip-final-newline": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", + "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/jest-circus": { "version": "28.1.0", "resolved": "https://registry.npmjs.org/jest-circus/-/jest-circus-28.1.0.tgz", @@ -6005,6 +6095,71 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/jest-runtime/node_modules/execa": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", + "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.3", + "get-stream": "^6.0.0", + "human-signals": "^2.1.0", + "is-stream": "^2.0.0", + "merge-stream": "^2.0.0", + "npm-run-path": "^4.0.1", + "onetime": "^5.1.2", + "signal-exit": "^3.0.3", + "strip-final-newline": "^2.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sindresorhus/execa?sponsor=1" + } + }, + "node_modules/jest-runtime/node_modules/human-signals": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", + "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", + "dev": true, + "engines": { + "node": ">=10.17.0" + } + }, + "node_modules/jest-runtime/node_modules/is-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "dev": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/jest-runtime/node_modules/npm-run-path": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", + "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "dev": true, + "dependencies": { + "path-key": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/jest-runtime/node_modules/strip-final-newline": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", + "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/jest-runtime/node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -6894,14 +7049,28 @@ } }, "node_modules/npm-run-path": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", - "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", + "integrity": "sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==", "dependencies": { - "path-key": "^3.0.0" + "path-key": "^4.0.0" }, "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/npm-run-path/node_modules/path-key": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", + "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/object-inspect": { @@ -7713,11 +7882,14 @@ } }, "node_modules/strip-final-newline": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", - "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", + "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==", "engines": { - "node": ">=6" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/strip-json-comments": { @@ -11221,19 +11393,34 @@ "dev": true }, "execa": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", - "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-6.1.0.tgz", + "integrity": "sha512-QVWlX2e50heYJcCPG0iWtf8r0xjEYfz/OYLGDYH+IyjWezzPNxz63qNFOu0l4YftGWuizFVZHHs8PrLU5p2IDA==", "requires": { "cross-spawn": "^7.0.3", - "get-stream": "^6.0.0", - "human-signals": "^2.1.0", - "is-stream": "^2.0.0", + "get-stream": "^6.0.1", + "human-signals": "^3.0.1", + "is-stream": "^3.0.0", "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.1", - "onetime": "^5.1.2", - "signal-exit": "^3.0.3", - "strip-final-newline": "^2.0.0" + "npm-run-path": "^5.1.0", + "onetime": "^6.0.0", + "signal-exit": "^3.0.7", + "strip-final-newline": "^3.0.0" + }, + "dependencies": { + "mimic-fn": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", + "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==" + }, + "onetime": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", + "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", + "requires": { + "mimic-fn": "^4.0.0" + } + } } }, "exit": { @@ -11513,9 +11700,9 @@ "dev": true }, "human-signals": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", - "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==" + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-3.0.1.tgz", + "integrity": "sha512-rQLskxnM/5OCldHo+wNXbpVgDn5A17CUoKX+7Sokwaknlq7CdSnphy0W39GU8dw59XiCXmFXDg4fRuckQRKewQ==" }, "husky": { "version": "8.0.1", @@ -11748,9 +11935,9 @@ } }, "is-stream": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", - "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", + "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==" }, "is-string": { "version": "1.0.7", @@ -11874,6 +12061,52 @@ "requires": { "execa": "^5.0.0", "throat": "^6.0.1" + }, + "dependencies": { + "execa": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", + "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.3", + "get-stream": "^6.0.0", + "human-signals": "^2.1.0", + "is-stream": "^2.0.0", + "merge-stream": "^2.0.0", + "npm-run-path": "^4.0.1", + "onetime": "^5.1.2", + "signal-exit": "^3.0.3", + "strip-final-newline": "^2.0.0" + } + }, + "human-signals": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", + "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", + "dev": true + }, + "is-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "dev": true + }, + "npm-run-path": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", + "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "dev": true, + "requires": { + "path-key": "^3.0.0" + } + }, + "strip-final-newline": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", + "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", + "dev": true + } } }, "jest-circus": { @@ -12614,6 +12847,50 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "execa": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", + "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.3", + "get-stream": "^6.0.0", + "human-signals": "^2.1.0", + "is-stream": "^2.0.0", + "merge-stream": "^2.0.0", + "npm-run-path": "^4.0.1", + "onetime": "^5.1.2", + "signal-exit": "^3.0.3", + "strip-final-newline": "^2.0.0" + } + }, + "human-signals": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", + "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", + "dev": true + }, + "is-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "dev": true + }, + "npm-run-path": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", + "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "dev": true, + "requires": { + "path-key": "^3.0.0" + } + }, + "strip-final-newline": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", + "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", + "dev": true + }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -13289,11 +13566,18 @@ "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" }, "npm-run-path": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", - "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", + "integrity": "sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==", "requires": { - "path-key": "^3.0.0" + "path-key": "^4.0.0" + }, + "dependencies": { + "path-key": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", + "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==" + } } }, "object-inspect": { @@ -13880,9 +14164,9 @@ "dev": true }, "strip-final-newline": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", - "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", + "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==" }, "strip-json-comments": { "version": "3.1.1", diff --git a/package.json b/package.json index 96e67921d..f7e382bb9 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "colorette": "^2.0.16", "commander": "^9.3.0", "debug": "^4.3.4", - "execa": "^5.1.1", + "execa": "^6.1.0", "lilconfig": "2.0.5", "listr2": "^4.0.5", "micromatch": "^4.0.5", diff --git a/test/__mocks__/execa.js b/test/__mocks__/execa.js index 5d0d45078..4534fd3e0 100644 --- a/test/__mocks__/execa.js +++ b/test/__mocks__/execa.js @@ -1,6 +1,6 @@ import { createExecaReturnValue } from '../utils/createExecaReturnValue' -const execa = jest.fn(() => +export const execa = jest.fn(() => createExecaReturnValue({ stdout: 'a-ok', stderr: '', @@ -12,6 +12,4 @@ const execa = jest.fn(() => }) ) -execa.command = execa - -module.exports = execa +export const execaCommand = execa diff --git a/test/execGit.spec.js b/test/execGit.spec.js index fec935100..17f9592ca 100644 --- a/test/execGit.spec.js +++ b/test/execGit.spec.js @@ -1,6 +1,6 @@ import path from 'path' -import execa from 'execa' +import { execa } from 'execa' import { execGit, GIT_GLOBAL_OPTIONS } from '../lib/execGit' diff --git a/test/makeCmdTasks.spec.js b/test/makeCmdTasks.spec.js index 5d5e3164c..999052faf 100644 --- a/test/makeCmdTasks.spec.js +++ b/test/makeCmdTasks.spec.js @@ -1,4 +1,4 @@ -import execa from 'execa' +import { execa } from 'execa' import { makeCmdTasks } from '../lib/makeCmdTasks' diff --git a/test/resolveTaskFn.spec.js b/test/resolveTaskFn.spec.js index f46d57998..c5bbb3368 100644 --- a/test/resolveTaskFn.spec.js +++ b/test/resolveTaskFn.spec.js @@ -1,4 +1,4 @@ -import execa from 'execa' +import { execa } from 'execa' import pidTree from 'pidtree' import { resolveTaskFn } from '../lib/resolveTaskFn' diff --git a/test/runAll.spec.js b/test/runAll.spec.js index 58a6cefe0..5c1e7420b 100644 --- a/test/runAll.spec.js +++ b/test/runAll.spec.js @@ -1,7 +1,7 @@ import path from 'path' import makeConsoleMock from 'consolemock' -import execa from 'execa' +import { execa } from 'execa' import normalize from 'normalize-path' import { getStagedFiles } from '../lib/getStagedFiles' From 50f95b3d51e69074ab5ff5ddb7147828fcd85b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Mon, 30 May 2022 15:41:46 +0300 Subject: [PATCH 11/11] refactor: remove `supports-color` --- bin/lint-staged.js | 6 +++--- package-lock.json | 17 ----------------- package.json | 1 - 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/bin/lint-staged.js b/bin/lint-staged.js index ca18bdf74..ff8c0d919 100755 --- a/bin/lint-staged.js +++ b/bin/lint-staged.js @@ -4,16 +4,16 @@ import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' +import { isColorSupported } from 'colorette' import { Option, program } from 'commander' import debug from 'debug' -import supportsColor from 'supports-color' import lintStaged from '../lib/index.js' import { CONFIG_STDIN_ERROR } from '../lib/messages.js' // Force colors for packages that depend on https://www.npmjs.com/package/supports-color -if (supportsColor.stdout) { - process.env.FORCE_COLOR = supportsColor.stdout.level.toString() +if (isColorSupported) { + process.env.FORCE_COLOR = '1' } // Do not terminate main Listr process on SIGINT diff --git a/package-lock.json b/package-lock.json index 66f712a8b..6859c49db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,6 @@ "object-inspect": "^1.12.2", "pidtree": "^0.5.0", "string-argv": "^0.3.1", - "supports-color": "^9.2.2", "yaml": "^2.1.1" }, "bin": { @@ -7904,17 +7903,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/supports-color": { - "version": "9.2.2", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-9.2.2.tgz", - "integrity": "sha512-XC6g/Kgux+rJXmwokjm9ECpD6k/smUoS5LKlUCcsYr4IY3rW0XyAympon2RmxGrlnZURMpg5T18gWDP9CsHXFA==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/chalk/supports-color?sponsor=1" - } - }, "node_modules/supports-hyperlinks": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-2.2.0.tgz", @@ -14174,11 +14162,6 @@ "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true }, - "supports-color": { - "version": "9.2.2", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-9.2.2.tgz", - "integrity": "sha512-XC6g/Kgux+rJXmwokjm9ECpD6k/smUoS5LKlUCcsYr4IY3rW0XyAympon2RmxGrlnZURMpg5T18gWDP9CsHXFA==" - }, "supports-hyperlinks": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-2.2.0.tgz", diff --git a/package.json b/package.json index f7e382bb9..7ca78e34b 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "object-inspect": "^1.12.2", "pidtree": "^0.5.0", "string-argv": "^0.3.1", - "supports-color": "^9.2.2", "yaml": "^2.1.1" }, "devDependencies": {