Skip to content

Commit

Permalink
refactor: remove support for chunking
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Very long arguments strings are no longer chunked on Windows. Function linters should be used instead to customise this behaviour.
  • Loading branch information
Iiro Jäppinen authored and okonet committed Jul 1, 2019
1 parent f76c0d1 commit 2ca9050
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 282 deletions.
2 changes: 0 additions & 2 deletions package.json
Expand Up @@ -34,14 +34,12 @@
"del": "^3.0.0",
"execa": "^1.0.0",
"is-glob": "^4.0.0",
"is-windows": "^1.0.2",
"listr": "^0.14.2",
"listr-update-renderer": "^0.5.0",
"lodash": "^4.17.11",
"log-symbols": "^2.2.0",
"micromatch": "^3.1.8",
"npm-which": "^3.0.1",
"p-map": "^1.1.1",
"path-is-inside": "^1.0.2",
"please-upgrade-node": "^3.0.2",
"string-argv": "^0.0.2",
Expand Down
42 changes: 0 additions & 42 deletions src/calcChunkSize.js

This file was deleted.

59 changes: 6 additions & 53 deletions src/resolveTaskFn.js
@@ -1,13 +1,9 @@
'use strict'

const chunk = require('lodash/chunk')
const dedent = require('dedent')
const isWindows = require('is-windows')
const execa = require('execa')
const chalk = require('chalk')
const symbols = require('log-symbols')
const pMap = require('p-map')
const calcChunkSize = require('./calcChunkSize')
const findBin = require('./findBin')

const debug = require('debug')('lint-staged:task')
Expand Down Expand Up @@ -108,55 +104,12 @@ module.exports = function resolveTaskFn(options) {
execaOptions.cwd = gitDir
}

if (!isWindows()) {
debug('%s OS: %s; File path chunking unnecessary', symbols.success, process.platform)
return ctx =>
execLinter(bin, argsWithPaths, execaOptions).then(result => {
if (result.failed || result.killed || result.signal != null) {
throw makeErr(linter, result, ctx)
}

return successMsg(linter)
})
}

const { chunkSize, subTaskConcurrency: concurrency } = options

const filePathChunks = chunk(pathsToLint, calcChunkSize(pathsToLint, chunkSize))
const mapper = execLinter.bind(null, bin, argsWithPaths, execaOptions)

debug(
'OS: %s; Creating linter task with %d chunked file paths',
process.platform,
filePathChunks.length
)
return ctx =>
pMap(filePathChunks, mapper, { concurrency })
.catch(err => {
/* This will probably never be called. But just in case.. */
throw new Error(dedent`
${symbols.error} ${linter} got an unexpected error.
${err.message}
`)
})
.then(results => {
const errors = results.filter(res => res.failed || res.killed)
const failed = results.some(res => res.failed)
const killed = results.some(res => res.killed)
const signals = results.map(res => res.signal).filter(Boolean)

if (failed || killed || signals.length > 0) {
const finalResult = {
stdout: errors.map(err => err.stdout).join(''),
stderr: errors.map(err => err.stderr).join(''),
failed,
killed,
signal: signals.join(', ')
}

throw makeErr(linter, finalResult, ctx)
}
execLinter(bin, argsWithPaths, execaOptions).then(result => {
if (result.failed || result.killed || result.signal != null) {
throw makeErr(linter, result, ctx)
}

return successMsg(linter)
})
return successMsg(linter)
})
}
27 changes: 0 additions & 27 deletions test/calcChunkSize.spec.js

This file was deleted.

158 changes: 0 additions & 158 deletions test/resolveTaskFn-chunked.spec.js

This file was deleted.

0 comments on commit 2ca9050

Please sign in to comment.