diff --git a/packages/cli/src/json2csv.ts b/packages/cli/src/json2csv.ts index d96674e..2514145 100755 --- a/packages/cli/src/json2csv.ts +++ b/packages/cli/src/json2csv.ts @@ -21,14 +21,17 @@ import { type StreamParserOptions, } from '@json2csv/plainjs'; import { Transform as Json2csvTransform } from '@json2csv/node'; -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore not use resolveJSONmodule so package.json is not copied to bin -import pkg from '../package.json' assert { type: 'json' }; import parseNdJson from './utils/parseNdjson.js'; import TablePrinter, { type TablePrinterOptions, } from './utils/TablePrinter.js'; +// Workaround to avoid warnings +// import pkg from '../package.json' assert { type: 'json' }; +import { createRequire } from 'module'; +const require = createRequire(import.meta.url); +const pkg = require('../package.json'); + const { readFile, writeFile } = fsPromises; type InputOptions = { ndjson: boolean; eol: string }; diff --git a/packages/cli/test/CLI.js b/packages/cli/test/CLI.js index 8f7007c..89022da 100644 --- a/packages/cli/test/CLI.js +++ b/packages/cli/test/CLI.js @@ -53,7 +53,7 @@ export default function (jsonFixtures, csvFixtures) { t.fail('Exception expected'); } catch (err) { t.equal( - err.stderr.split('\n')[2].substring(7), + err.stderr.split('\n')[0].substring(7), 'Data should not be empty or the "fields" option should be included' ); } @@ -105,7 +105,7 @@ export default function (jsonFixtures, csvFixtures) { t.fail('Exception expected.'); } catch (err) { t.equal( - err.stderr.split('\n')[2].substring(7), + err.stderr.split('\n')[0].substring(7), "Invalid ND-JSON couldn't be parsed" ); } @@ -150,7 +150,7 @@ export default function (jsonFixtures, csvFixtures) { t.fail('Exception expected'); } catch (err) { t.equal( - err.stderr.split('\n')[2].substring(7), + err.stderr.split('\n')[0].substring(7), 'Data items should be objects or the "fields" option should be included' ); } @@ -166,7 +166,7 @@ export default function (jsonFixtures, csvFixtures) { t.fail('Exception expected.'); } catch (err) { t.equal( - err.stderr.split('\n')[2].substring(7), + err.stderr.split('\n')[0].substring(7), 'Data items should be objects or the "fields" option should be included' ); }