Skip to content

Commit

Permalink
Fix csv-parse implementation since major update
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed May 4, 2022
1 parent c1f4007 commit 59dbafd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
7 changes: 5 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
setupFiles: ["dotenv/config"],
setupFiles: ['dotenv/config'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
},
moduleNameMapper: {
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
},
verbose: true
}
};
18 changes: 10 additions & 8 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -96,19 +96,21 @@ export function getInputList(name: string, ignoreComma?: boolean): string[] {
return res;
}

for (const output of csvparse(items, {
const records = parse(items, {
columns: false,
relaxColumnCount: true,
skipLinesWithEmptyValues: true
}) as Array<string[]>) {
if (output.length == 1) {
res.push(output[0]);
skipEmptyLines: true
});

for (const record of records as Array<string[]>) {
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());
Expand Down

0 comments on commit 59dbafd

Please sign in to comment.