From b7ad32e4f59269e45e7f5c79e1d89560e0ade90d Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 25 Apr 2022 13:35:08 +0200 Subject: [PATCH] Fix csv-parse implementation since major update Signed-off-by: CrazyMax --- jest.config.ts | 3 +++ src/context.ts | 20 +++++++++++--------- src/flavor.ts | 6 +++--- src/tag.ts | 6 +++--- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index 45f823e..7ff4e46 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -6,5 +6,8 @@ module.exports = { transform: { '^.+\\.ts$': 'ts-jest' }, + moduleNameMapper: { + '^csv-parse/sync': '/node_modules/csv-parse/dist/cjs/sync.cjs' + }, verbose: true }; diff --git a/src/context.ts b/src/context.ts index db5fd72..45a4e98 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 core from '@actions/core'; import {issueCommand} from '@actions/core/lib/command'; import * as fs from 'fs'; @@ -46,21 +46,23 @@ export function getInputList(name: string, ignoreComma?: boolean): string[] { return res; } - for (const output of csvparse(items, { + const records = parse(items, { columns: false, - relax: true, + relaxQuotes: true, comment: '#', 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()); diff --git a/src/flavor.ts b/src/flavor.ts index 91e4ebe..c46eca2 100644 --- a/src/flavor.ts +++ b/src/flavor.ts @@ -1,5 +1,5 @@ +import {parse} from 'csv-parse/sync'; import * as core from '@actions/core'; -import csvparse from 'csv-parse/lib/sync'; export interface Flavor { latest: string; @@ -19,9 +19,9 @@ export function Transform(inputs: string[]): Flavor { }; for (const input of inputs) { - const fields = csvparse(input, { + const fields = parse(input, { relaxColumnCount: true, - skipLinesWithEmptyValues: true + skipEmptyLines: true })[0]; let onlatestfor = ''; for (const field of fields) { diff --git a/src/tag.ts b/src/tag.ts index 86e88c8..8530885 100644 --- a/src/tag.ts +++ b/src/tag.ts @@ -1,4 +1,4 @@ -import csvparse from 'csv-parse/lib/sync'; +import {parse} from 'csv-parse/sync'; import * as core from '@actions/core'; export enum Type { @@ -86,9 +86,9 @@ export function Transform(inputs: string[]): Tag[] { } export function Parse(s: string): Tag { - const fields = csvparse(s, { + const fields = parse(s, { relaxColumnCount: true, - skipLinesWithEmptyValues: true + skipEmptyLines: true })[0]; const tag = new Tag();