Skip to content

Commit 5ea21bf

Browse files
committed
Fix csv-parse implementation since major update
Signed-off-by: CrazyMax <[email protected]>
1 parent 300b1bd commit 5ea21bf

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

jest.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
module.exports = {
22
clearMocks: false,
33
moduleFileExtensions: ['js', 'ts'],
4-
setupFiles: ["dotenv/config"],
4+
setupFiles: ['dotenv/config'],
55
testMatch: ['**/*.test.ts'],
66
transform: {
77
'^.+\\.ts$': 'ts-jest'
88
},
9+
moduleNameMapper: {
10+
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
11+
},
912
verbose: true
10-
}
13+
};

src/buildx.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import csvparse from 'csv-parse/lib/sync';
1+
import {parse} from 'csv-parse/sync';
22
import fs from 'fs';
33
import path from 'path';
44
import * as semver from 'semver';
@@ -77,18 +77,19 @@ export async function getSecret(kvp: string, file: boolean): Promise<string> {
7777
}
7878

7979
export function isLocalOrTarExporter(outputs: string[]): boolean {
80-
for (const output of csvparse(outputs.join(`\n`), {
80+
const records = parse(outputs.join(`\n`), {
8181
delimiter: ',',
8282
trim: true,
8383
columns: false,
8484
relaxColumnCount: true
85-
})) {
85+
});
86+
for (const record of records) {
8687
// Local if no type is defined
8788
// https://github.com/docker/buildx/blob/d2bf42f8b4784d83fde17acb3ed84703ddc2156b/build/output.go#L29-L43
88-
if (output.length == 1 && !output[0].startsWith('type=')) {
89+
if (record.length == 1 && !record[0].startsWith('type=')) {
8990
return true;
9091
}
91-
for (const [key, value] of output.map(chunk => chunk.split('=').map(item => item.trim()))) {
92+
for (const [key, value] of record.map(chunk => chunk.split('=').map(item => item.trim()))) {
9293
if (key == 'type' && (value == 'local' || value == 'tar')) {
9394
return true;
9495
}

src/context.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import csvparse from 'csv-parse/lib/sync';
1+
import {parse} from 'csv-parse/sync';
22
import * as fs from 'fs';
33
import * as os from 'os';
44
import * as path from 'path';
@@ -217,20 +217,22 @@ export async function getInputList(name: string, ignoreComma?: boolean): Promise
217217
return res;
218218
}
219219

220-
for (const output of (await csvparse(items, {
220+
const records = await parse(items, {
221221
columns: false,
222-
relax: true,
222+
relaxQuotes: true,
223223
relaxColumnCount: true,
224-
skipLinesWithEmptyValues: true
225-
})) as Array<string[]>) {
226-
if (output.length == 1) {
227-
res.push(output[0]);
224+
skipEmptyLines: true
225+
});
226+
227+
for (const record of records as Array<string[]>) {
228+
if (record.length == 1) {
229+
res.push(record[0]);
228230
continue;
229231
} else if (!ignoreComma) {
230-
res.push(...output);
232+
res.push(...record);
231233
continue;
232234
}
233-
res.push(output.join(','));
235+
res.push(record.join(','));
234236
}
235237

236238
return res.filter(item => item).map(pat => pat.trim());

0 commit comments

Comments
 (0)