Skip to content

Commit

Permalink
fix: normalize chunked paths even when maxArgLength is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Apr 30, 2020
1 parent defe045 commit ba67f48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/chunkFiles.js
Expand Up @@ -33,14 +33,15 @@ function chunkArray(arr, chunkCount) {
* @returns {Array<Array<String>>}
*/
module.exports = function chunkFiles({ files, baseDir, maxArgLength = null, relative = false }) {
const normalizedFiles = files.map((file) =>
normalize(relative || !baseDir ? file : path.resolve(baseDir, file))
)

if (!maxArgLength) {
debug('Skip chunking files because of undefined maxArgLength')
return [files]
return [normalizedFiles] // wrap in an array to return a single chunk
}

const normalizedFiles = files.map((file) =>
normalize(relative || !baseDir ? file : path.resolve(baseDir, file))
)
const fileListLength = normalizedFiles.join(' ').length
debug(
`Resolved an argument string length of ${fileListLength} characters from ${normalizedFiles.length} files`
Expand Down
10 changes: 9 additions & 1 deletion test/chunkFiles.spec.js
@@ -1,8 +1,11 @@
import normalize from 'normalize-path'
import path from 'path'

import chunkFiles from '../lib/chunkFiles'

describe('chunkFiles', () => {
const files = ['example.js', 'foo.js', 'bar.js', 'foo/bar.js']
const baseDir = '/opt/git/example.git'
const baseDir = normalize('/opt/git/example.git')

it('should default to sane value', () => {
const chunkedFiles = chunkFiles({ baseDir, files: ['foo.js'], relative: true })
Expand All @@ -26,4 +29,9 @@ describe('chunkFiles', () => {
[files[2], files[3]],
])
})

it('should resolve paths when relative: false', () => {
const chunkedFiles = chunkFiles({ baseDir, files, relative: false })
expect(chunkedFiles).toEqual([files.map((file) => normalize(path.resolve(baseDir, file)))])
})
})

0 comments on commit ba67f48

Please sign in to comment.