Skip to content

Commit

Permalink
fix(package): Bump dependencies
Browse files Browse the repository at this point in the history
Dependencies
- chalk            { 2.3.0  => 2.3.1  }
- commander        { 2.12.2 => 2.14.1 }
- execa            { 0.8.0  => 0.9.0  }
- jest-validate    { 21.2.1 => 22.4.0 }
- lodash           { 4.17.4 => 4.17.5 }
- log-symbols      { 2.1.0  => 2.2.0  }
- micromatch       { 3.1.5  => 3.1.8  }
- staged-git-files { 1.0.0  => 1.1.0  }
- stringify-object { 3.2.1  => 3.2.2  }

Dev-Dependencies
- eslint             { 4.14.0 => 4.18.1 }
- eslint-plugin-node { 5.2.1  => 6.0.0  }
- jest               { 22.0.4 => 22.4.0 }
- prettier           { 1.9.2  => 1.10.2 }
  • Loading branch information
sudo-suhas committed Feb 21, 2018
1 parent 05a062d commit 267ff0f
Show file tree
Hide file tree
Showing 8 changed files with 434 additions and 358 deletions.
28 changes: 11 additions & 17 deletions .eslintrc.json
Expand Up @@ -3,29 +3,23 @@
"ecmaVersion": 6,
"sourceType": "script"
},
"extends": [
"okonet",
"plugin:node/recommended"
],
"extends": ["okonet", "plugin:node/recommended"],
"plugins": ["node"],
"rules": {
"strict": [
"error",
"global"
],
"strict": ["error", "global"],
"no-console": "off",
"prefer-destructuring": [
"error",
{
"VariableDeclarator": {
"array": true,
"object": true
},
"AssignmentExpression": {
"array": false,
"object": false
}
"VariableDeclarator": {
"array": true,
"object": true
},
"AssignmentExpression": {
"array": false,
"object": false
}
}
]
]
}
}
26 changes: 13 additions & 13 deletions package.json
Expand Up @@ -28,39 +28,39 @@
},
"dependencies": {
"app-root-path": "^2.0.1",
"chalk": "^2.1.0",
"commander": "^2.11.0",
"chalk": "^2.3.1",
"commander": "^2.14.1",
"cosmiconfig": "^4.0.0",
"debug": "^3.1.0",
"dedent": "^0.7.0",
"execa": "^0.8.0",
"execa": "^0.9.0",
"find-parent-dir": "^0.3.0",
"is-glob": "^4.0.0",
"jest-validate": "^21.1.0",
"jest-validate": "^22.4.0",
"listr": "^0.13.0",
"lodash": "^4.17.4",
"log-symbols": "^2.0.0",
"micromatch": "^3.1.5",
"lodash": "^4.17.5",
"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",
"pify": "^3.0.0",
"please-upgrade-node": "^3.0.1",
"staged-git-files": "1.0.0",
"stringify-object": "^3.2.0"
"staged-git-files": "1.1.0",
"stringify-object": "^3.2.2"
},
"devDependencies": {
"babel-preset-env": "^1.6.0",
"commitizen": "^2.9.6",
"consolemock": "^1.0.2",
"cz-conventional-changelog": "^2.0.0",
"eslint": "^4.5.0",
"eslint": "^4.18.1",
"eslint-config-okonet": "^5.0.1",
"eslint-plugin-node": "^5.1.1",
"eslint-plugin-node": "^6.0.0",
"husky": "^0.14.3",
"jest": "^22.0.4",
"jest": "^22.4.0",
"jsonlint": "^1.6.2",
"prettier": "1.9.2"
"prettier": "1.10.2"
},
"config": {
"commitizen": {
Expand Down
63 changes: 27 additions & 36 deletions src/runScript.js
Expand Up @@ -26,56 +26,47 @@ module.exports = function runScript(commands, pathsToLint, config) {
return lintersArray.map(linter => ({
title: linter,
task: () => {
try {
const res = findBin(linter)
const { bin, args } = findBin(linter)

// Only use gitDir as CWD if we are using the git binary
// e.g `npm` should run tasks in the actual CWD
const execaOptions =
/git(\.exe)?$/i.test(res.bin) && gitDir !== process.cwd() ? { cwd: gitDir } : {}
const execaOptions = { reject: false }
// Only use gitDir as CWD if we are using the git binary
// e.g `npm` should run tasks in the actual CWD
if (/git(\.exe)?$/i.test(bin) && gitDir !== process.cwd()) {
execaOptions.cwd = gitDir
}

const errors = []
const mapper = pathsChunk => {
const args = res.args.concat(pathsChunk)
const mapper = pathsChunk => {
const binArgs = args.concat(pathsChunk)

debug('bin:', res.bin)
debug('args: %O', args)
debug('opts: %o', execaOptions)
debug('bin:', bin)
debug('args: %O', binArgs)
debug('opts: %o', execaOptions)

return (
execa(res.bin, args, Object.assign({}, execaOptions))
/* If we don't catch, pMap will terminate on first rejection */
/* We want error information of all chunks */
.catch(err => {
errors.push(err)
})
)
}
return execa(bin, binArgs, Object.assign({}, execaOptions))
}

return pMap(filePathChunks, mapper, { concurrency })
.catch(err => {
/* This will probably never be called. But just in case.. */
throw new Error(dedent`
return pMap(filePathChunks, mapper, { concurrency })
.catch(err => {
/* This will probably never be called. But just in case.. */
throw new Error(dedent`
${logSymbols.error} ${linter} got an unexpected error.
${err.message}
`)
})
.then(() => {
if (errors.length === 0) return `${logSymbols.success} ${linter} passed!`
})
.then(results => {
const errors = results.filter(res => res.failed)
if (errors.length === 0) return `${logSymbols.success} ${linter} passed!`

const errStdout = errors.map(err => err.stdout).join('')
const errStderr = errors.map(err => err.stderr).join('')
const errStdout = errors.map(err => err.stdout).join('')
const errStderr = errors.map(err => err.stderr).join('')

// prettier-ignore
throw new Error(dedent`
// prettier-ignore
throw new Error(dedent`
${logSymbols.error} ${linter} found some errors. Please fix them and try committing again.
${errStdout}
${errStderr}
`)
})
} catch (err) {
throw err
}
})
}
}))
}
10 changes: 9 additions & 1 deletion test/__mocks__/execa.js
@@ -1 +1,9 @@
module.exports = jest.fn(() => Promise.resolve(true))
module.exports = jest.fn(() =>
Promise.resolve({
stdout: 'a-ok',
stderr: '',
code: 0,
failed: false,
cmd: 'mock cmd'
})
)
5 changes: 4 additions & 1 deletion test/runScript-mock-findBin.spec.js
Expand Up @@ -27,6 +27,9 @@ describe('runScript with absolute paths', () => {
const [linter] = runScript(['git add'], ['test.js'])
await linter.task()
expect(mockFn).toHaveBeenCalledTimes(1)
expect(mockFn).toHaveBeenCalledWith('/usr/local/bin/git', ['add', 'test.js'], { cwd: '../' })
expect(mockFn).toHaveBeenCalledWith('/usr/local/bin/git', ['add', 'test.js'], {
cwd: '../',
reject: false
})
})
})
12 changes: 11 additions & 1 deletion test/runScript-mock-pMap.spec.js
Expand Up @@ -12,7 +12,17 @@ describe('runScript', () => {

it('should respect concurrency', async () => {
expect.assertions(2)
pMapMock.mockImplementation(() => Promise.resolve(true))
pMapMock.mockImplementation(() =>
Promise.resolve([
{
stdout: 'a-ok',
stderr: '',
code: 0,
failed: false,
cmd: 'mock cmd'
}
])
)

const [linter] = runScript(['test'], ['test1.js', 'test2.js'], {
chunkSize: 1,
Expand Down
38 changes: 22 additions & 16 deletions test/runScript.spec.js
Expand Up @@ -49,12 +49,12 @@ describe('runScript', () => {
expect(taskPromise).toBeInstanceOf(Promise)
await taskPromise
expect(mockFn).toHaveBeenCalledTimes(1)
expect(mockFn).lastCalledWith('test', ['test.js'], {})
expect(mockFn).lastCalledWith('test', ['test.js'], { reject: false })
taskPromise = linter2.task()
expect(taskPromise).toBeInstanceOf(Promise)
await taskPromise
expect(mockFn).toHaveBeenCalledTimes(2)
expect(mockFn).lastCalledWith('test2', ['test.js'], {})
expect(mockFn).lastCalledWith('test2', ['test.js'], { reject: false })
})

it('should respect chunk size', async () => {
Expand All @@ -64,8 +64,8 @@ describe('runScript', () => {
})
await linter.task()
expect(mockFn).toHaveBeenCalledTimes(2)
expect(mockFn).toHaveBeenCalledWith('test', ['test1.js'], {})
expect(mockFn).lastCalledWith('test', ['test2.js'], {})
expect(mockFn).toHaveBeenCalledWith('test', ['test1.js'], { reject: false })
expect(mockFn).lastCalledWith('test', ['test2.js'], { reject: false })
})

it('should support non npm scripts', async () => {
Expand All @@ -78,11 +78,13 @@ describe('runScript', () => {

await linter1.task()
expect(mockFn).toHaveBeenCalledTimes(1)
expect(mockFn).lastCalledWith('node', ['--arg=true', './myscript.js', 'test.js'], {})
expect(mockFn).lastCalledWith('node', ['--arg=true', './myscript.js', 'test.js'], {
reject: false
})

await linter2.task()
expect(mockFn).toHaveBeenCalledTimes(2)
expect(mockFn).lastCalledWith('git', ['add', 'test.js'], {})
expect(mockFn).lastCalledWith('git', ['add', 'test.js'], { reject: false })
})

it('should pass cwd to execa if gitDir is different than process.cwd for non-npm tasks', async () => {
Expand All @@ -92,30 +94,35 @@ describe('runScript', () => {
const [linter1, linter2] = res
await linter1.task()
expect(mockFn).toHaveBeenCalledTimes(1)
expect(mockFn).lastCalledWith('test', ['test.js'], {})
expect(mockFn).lastCalledWith('test', ['test.js'], { reject: false })

await linter2.task()
expect(mockFn).toHaveBeenCalledTimes(2)
expect(mockFn).lastCalledWith('git', ['add', 'test.js'], { cwd: '../' })
expect(mockFn).lastCalledWith('git', ['add', 'test.js'], { cwd: '../', reject: false })
})

it('should not pass `gitDir` as `cwd` to `execa()` if a non-git binary is called', async () => {
expect.assertions(2)
const processCwdBkp = process.cwd
process.cwd = () => __dirname
const [linter] = runScript(['jest'], ['test.js'], {})
const [linter] = runScript(['jest'], ['test.js'], { reject: false })
await linter.task()
expect(mockFn).toHaveBeenCalledTimes(1)
expect(mockFn).lastCalledWith('jest', ['test.js'], {})
expect(mockFn).lastCalledWith('jest', ['test.js'], { reject: false })
process.cwd = processCwdBkp
})

it('should throw error for failed linters', async () => {
expect.assertions(1)
const linterErr = new Error()
linterErr.stdout = 'Mock error'
linterErr.stderr = ''
mockFn.mockImplementationOnce(() => Promise.reject(linterErr))
mockFn.mockImplementationOnce(() =>
Promise.resolve({
stdout: 'Mock error',
stderr: '',
code: 0,
failed: true,
cmd: 'mock cmd'
})
)

const [linter] = runScript('mock-fail-linter', ['test.js'])
try {
Expand All @@ -124,8 +131,7 @@ describe('runScript', () => {
// prettier-ignore
expect(err.message).toMatch(dedent`
${logSymbols.error} mock-fail-linter found some errors. Please fix them and try committing again.
${linterErr.stdout}
${linterErr.stderr}
Mock error
`)
}
})
Expand Down

0 comments on commit 267ff0f

Please sign in to comment.