Skip to content

Commit

Permalink
fix: fix issue with CLI and node JSON import warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed May 24, 2023
1 parent 2afce9d commit d316310
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions packages/cli/src/json2csv.ts
Expand Up @@ -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 };
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/test/CLI.js
Expand Up @@ -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'
);
}
Expand Down Expand Up @@ -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"
);
}
Expand Down Expand Up @@ -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'
);
}
Expand All @@ -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'
);
}
Expand Down

0 comments on commit d316310

Please sign in to comment.