Skip to content

Commit 7b9795a

Browse files
committed
Fix deprecation warning on Node.js 24
Change chunkify to return arrays and remove `shell: true`` from execFile
1 parent 37f421d commit 7b9795a

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

lib/chunkify.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@
22

33
function chunkify(files, maxChars) {
44
const filesChunk = [];
5-
let chunk = '';
5+
let chunk = [];
6+
let chunkLength = 0;
67

78
for (const file of files) {
8-
if (chunk.length + (file.length + 1) > maxChars) {
9-
filesChunk.push(chunk.trim());
10-
chunk = '';
9+
// Account for space between arguments
10+
const fileLength = file.length + 1;
11+
12+
if (chunkLength + fileLength > maxChars) {
13+
filesChunk.push(chunk);
14+
chunk = [];
15+
chunkLength = 0;
1116
}
1217

13-
chunk += `"${file}" `;
18+
chunk.push(file);
19+
chunkLength += fileLength;
1420
}
1521

16-
filesChunk.push(chunk.trim());
22+
if (chunk.length > 0) {
23+
filesChunk.push(chunk);
24+
}
1725

1826
return filesChunk;
1927
}

lib/htmllint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function htmllint(config, done) {
4343
async.mapLimit(chunks, threads, (chunk, cb) => {
4444
const args = javaArgs(java, chunk, config);
4545

46-
execFile('java', args, { maxBuffer: MAX_BUFFER, shell: true }, (error, stdout, stderr) => {
46+
execFile('java', args, { maxBuffer: MAX_BUFFER }, (error, stdout, stderr) => {
4747
if (error && (error.code !== 1 || error.killed || error.signal)) {
4848
cb(error);
4949
return;

lib/javaArgs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function javaArgs(java, chunk, config) {
1111
args.push('-Xss512k');
1212
}
1313

14-
args.push(config.server ? '-cp' : '-jar', `"${jar}"`);
14+
args.push(config.server ? '-cp' : '-jar', jar);
1515

1616
if (config.server) {
1717
if (config.server.host) {
@@ -22,7 +22,7 @@ function javaArgs(java, chunk, config) {
2222
args.push(`-Dnu.validator.client.port=${config.server.port}`);
2323
}
2424

25-
args.push('-Dnu.validator.client.out=json nu.validator.client.HttpClient');
25+
args.push('-Dnu.validator.client.out=json', 'nu.validator.client.HttpClient');
2626
} else {
2727
args.push('--format', 'json');
2828
}
@@ -31,7 +31,7 @@ function javaArgs(java, chunk, config) {
3131
args.push('--no-langdetect');
3232
}
3333

34-
return [...args, chunk];
34+
return [...args, ...chunk];
3535
}
3636

3737
module.exports = javaArgs;

test/chunkify_test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ describe('chunkify', () => {
1111
'./some/long/path/to/3/file.html'
1212
];
1313
const chunked = [
14-
'"./some/long/path/to/1/file.html" "./some/long/path/to/2/file.html"',
15-
'"./some/long/path/to/3/file.html"'
14+
['./some/long/path/to/1/file.html', './some/long/path/to/2/file.html'],
15+
['./some/long/path/to/3/file.html']
1616
];
17-
const all = ['"./some/long/path/to/1/file.html" "./some/long/path/to/2/file.html" "./some/long/path/to/3/file.html"'];
17+
const all = [[
18+
'./some/long/path/to/1/file.html',
19+
'./some/long/path/to/2/file.html',
20+
'./some/long/path/to/3/file.html'
21+
]];
1822

1923
assert.deepEqual(chunkify(files, 70), chunked, 'Should split the file list of file in 2 chunks');
2024
assert.deepEqual(chunkify(files, 120), all, 'Should do a single chunk');

0 commit comments

Comments
 (0)