Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Switch from execSync to execFileSync #180

Merged
merged 15 commits into from Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -111,3 +111,5 @@ nyc report --reporter=text-lcov > coverage.lcov
- v3.6.3 Fix for AWS Codebuild & package updates
- v3.6.4 Fix Cirrus CI
- v3.7.0 Remove the X-Amz-Acl: public-read header

.
53 changes: 35 additions & 18 deletions lib/codecov.js
Expand Up @@ -4,21 +4,21 @@ var request = require('teeny-request').teenyRequest
var urlgrey = require('urlgrey')
var jsYaml = require('js-yaml')
var walk = require('ignore-walk')
var execFileSync = require('child_process').execFileSync
var execSync = require('child_process').execSync

var detectProvider = require('./detect')

var version = 'v' + require('../package.json').version

var patterns,
more_patterns = ''
var patterns, more_patterns, winPatterns
drazisil marked this conversation as resolved.
Show resolved Hide resolved

var isWindows =
process.platform.match(/win32/) || process.platform.match(/win64/)

if (!isWindows) {
patterns =
"-type f \\( -name '*coverage.*' " +
patterns = (
"-type f -name '*coverage.*' " +
"-or -name 'nosetests.xml' " +
"-or -name 'jacoco*.xml' " +
"-or -name 'clover.xml' " +
Expand All @@ -29,7 +29,7 @@ if (!isWindows) {
"-or -name '*.lcov' " +
"-or -name 'gcov.info' " +
"-or -name '*.gcov' " +
"-or -name '*.lst' \\) " +
"-or -name '*.lst' " +
"-not -name '*.sh' " +
"-not -name '*.data' " +
"-not -name '*.py' " +
Expand Down Expand Up @@ -76,9 +76,10 @@ if (!isWindows) {
"-not -path '*/$bower_components/*' " +
"-not -path '*/node_modules/*' " +
"-not -path '*/conftest_*.c.gcov'"
).split(' ')
} else {
patterns =
'/a-d /b /s *coverage.* ' +
winPatterns = (
'/a:-d /b /s *coverage.* ' +
'/s nosetests.xml ' +
'/s jacoco*.xml ' +
'/s clover.xml ' +
Expand Down Expand Up @@ -136,6 +137,7 @@ if (!isWindows) {
'| findstr /i /v \\\\$bower_components\\ ' +
'| findstr /i /v \\node_modules\\ ' +
'| findstr /i /v \\conftest_.*\\.c\\.gcov '
).split(' ')
}

var sendToCodecovV2 = function(
Expand Down Expand Up @@ -355,7 +357,7 @@ var upload = function(args, on_success, on_failure) {
console.log('==> Building file structure')
try {
upload +=
execSync('git ls-files || hg locate', { cwd: root })
execFileSync('git', ['ls-files', '||', 'hg', 'locate'], { cwd: root })
.toString()
.trim() + '\n<<<<<< network\n'
} catch (err) {
Expand Down Expand Up @@ -414,7 +416,7 @@ var upload = function(args, on_success, on_failure) {
}
debug.push(gcov)
console.log(' $ ' + gcov)
execSync(gcov)
execFileSync(gcov)
} catch (e) {
console.log(' Failed to run gcov command.')
}
Expand All @@ -431,19 +433,23 @@ var upload = function(args, on_success, on_failure) {
.toString()
.trim()
} else {
bowerrc = execSync('if exist .bowerrc type .bowerrc', { cwd: root })
.toString()
.trim()
bowerrc = fs.existsSync('.bowerrc')
}
if (bowerrc) {
bowerrc = JSON.parse(bowerrc).directory
if (bowerrc) {
if (!isWindows) {
more_patterns =
" -not -path '*/" + bowerrc.toString().replace(/\/$/, '') + "/*'"
more_patterns = (
" -not -path '*/" +
bowerrc.toString().replace(/\/$/, '') +
"/*'"
).split(' ')
} else {
more_patterns =
'| findstr /i /v \\' + bowerrc.toString().replace(/\/$/, '') + '\\'
more_patterns = (
'| findstr /i /v \\' +
bowerrc.toString().replace(/\/$/, '') +
'\\'
).split(' ')
}
}
}
Expand Down Expand Up @@ -474,15 +480,26 @@ var upload = function(args, on_success, on_failure) {
} else if ((args.options.disable || '').split(',').indexOf('search') === -1) {
console.log('==> Scanning for reports')
var _files
var _findArgs
if (!isWindows) {
_files = execSync('find ' + root + ' ' + patterns + more_patterns)
// @TODO support for a root directory
// It's not straightforward due to the nature of the find command
_findArgs = [root].concat(patterns)
if (more_patterns) {
_findArgs.concat(more_patterns)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concat doesn't mutate, it returns a new instance. So in this case you'd need to do _findArgs = _findArgs.concat(more_patterns)

}
_files = execFileSync('find', _findArgs)
.toString()
.trim()
.split('\n')
} else {
// @TODO support for a root directory
// It's not straightforward due to the nature of the dir command
_files = execSync('dir ' + patterns + more_patterns)
_findArgs = [root].concat(winPatterns)
if (more_patterns) {
_findArgs.concat(more_patterns)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here with concat doesn't mutate.

}
_files = execSync('dir ' + winPatterns + more_patterns)
drazisil marked this conversation as resolved.
Show resolved Hide resolved
.toString()
.trim()
.split('\r\n')
Expand Down