diff --git a/jest.config.ts b/jest.config.ts index 24bd194..5630755 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,10 +1,13 @@ module.exports = { clearMocks: false, moduleFileExtensions: ['js', 'ts'], - setupFiles: ["dotenv/config"], + setupFiles: ['dotenv/config'], testMatch: ['**/*.test.ts'], transform: { '^.+\\.ts$': 'ts-jest' }, + moduleNameMapper: { + '^csv-parse/sync': '/node_modules/csv-parse/dist/cjs/sync.cjs' + }, verbose: true -} +}; diff --git a/src/buildx.ts b/src/buildx.ts index 1c1e7cc..a7afb39 100644 --- a/src/buildx.ts +++ b/src/buildx.ts @@ -1,4 +1,4 @@ -import csvparse from 'csv-parse/lib/sync'; +import {parse} from 'csv-parse/sync'; import fs from 'fs'; import path from 'path'; import * as semver from 'semver'; @@ -77,18 +77,19 @@ export async function getSecret(kvp: string, file: boolean): Promise { } export function isLocalOrTarExporter(outputs: string[]): boolean { - for (const output of csvparse(outputs.join(`\n`), { + const records = parse(outputs.join(`\n`), { delimiter: ',', trim: true, columns: false, relaxColumnCount: true - })) { + }); + for (const record of records) { // Local if no type is defined // https://github.com/docker/buildx/blob/d2bf42f8b4784d83fde17acb3ed84703ddc2156b/build/output.go#L29-L43 - if (output.length == 1 && !output[0].startsWith('type=')) { + if (record.length == 1 && !record[0].startsWith('type=')) { return true; } - for (const [key, value] of output.map(chunk => chunk.split('=').map(item => item.trim()))) { + for (const [key, value] of record.map(chunk => chunk.split('=').map(item => item.trim()))) { if (key == 'type' && (value == 'local' || value == 'tar')) { return true; } diff --git a/src/context.ts b/src/context.ts index af73633..d937aa5 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,4 +1,4 @@ -import csvparse from 'csv-parse/lib/sync'; +import {parse} from 'csv-parse/sync'; import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; @@ -217,20 +217,22 @@ export async function getInputList(name: string, ignoreComma?: boolean): Promise return res; } - for (const output of (await csvparse(items, { + const records = await parse(items, { columns: false, - relax: true, + relaxQuotes: true, relaxColumnCount: true, - skipLinesWithEmptyValues: true - })) as Array) { - if (output.length == 1) { - res.push(output[0]); + skipEmptyLines: true + }); + + for (const record of records as Array) { + if (record.length == 1) { + res.push(record[0]); continue; } else if (!ignoreComma) { - res.push(...output); + res.push(...record); continue; } - res.push(output.join(',')); + res.push(record.join(',')); } return res.filter(item => item).map(pat => pat.trim());