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 29, 2020
1 parent defe045 commit d38b283
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 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
8 changes: 8 additions & 0 deletions test/chunkFiles.spec.js
@@ -1,3 +1,6 @@
import normalize from 'normalize-path'
import path from 'path'

import chunkFiles from '../lib/chunkFiles'

describe('chunkFiles', () => {
Expand Down Expand Up @@ -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.join(baseDir, file)))])
})
})

0 comments on commit d38b283

Please sign in to comment.