Skip to content

Commit 3131ccd

Browse files
authored
Explicitly configure ava --version value
Fixes #2942.
1 parent 51d2a51 commit 3131ccd

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/cli.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {splitPatternAndLineNumbers} from './line-numbers.js';
2121
import {loadConfig} from './load-config.js';
2222
import normalizeModuleTypes from './module-types.js';
2323
import normalizeNodeArguments from './node-arguments.js';
24+
import pkg from './pkg.cjs';
2425
import providerManager from './provider-manager.js';
2526
import DefaultReporter from './reporters/default.js';
2627
import TapReporter from './reporters/tap.js';
@@ -102,7 +103,7 @@ export default async function loadCli() { // eslint-disable-line complexity
102103
let conf;
103104
let confError;
104105
try {
105-
const {argv: {config: configFile}} = yargs(hideBin(process.argv)).help(false);
106+
const {argv: {config: configFile}} = yargs(hideBin(process.argv)).help(false).version(false);
106107
conf = await loadConfig({configFile});
107108
if (conf.configFile && path.basename(conf.configFile) !== path.relative(conf.projectDir, conf.configFile)) {
108109
console.log(chalk.magenta(` ${figures.warning} Using configuration from ${conf.configFile}`));
@@ -132,6 +133,7 @@ export default async function loadCli() { // eslint-disable-line complexity
132133

133134
let resetCache = false;
134135
const {argv} = yargs(hideBin(process.argv))
136+
.version(pkg.version)
135137
.parserConfiguration({
136138
'boolean-negation': true,
137139
'camel-case-expansion': false,
@@ -319,16 +321,16 @@ export default async function loadCli() { // eslint-disable-line complexity
319321
exit('’sources’ has been removed. Use ’ignoredByWatcher’ to provide glob patterns of files that the watcher should ignore.');
320322
}
321323

322-
let pkg;
324+
let projectPackageObject;
323325
try {
324-
pkg = JSON.parse(fs.readFileSync(path.resolve(projectDir, 'package.json')));
326+
projectPackageObject = JSON.parse(fs.readFileSync(path.resolve(projectDir, 'package.json')));
325327
} catch (error) {
326328
if (error.code !== 'ENOENT') {
327329
throw error;
328330
}
329331
}
330332

331-
const {type: defaultModuleType = 'commonjs'} = pkg || {};
333+
const {type: defaultModuleType = 'commonjs'} = projectPackageObject || {};
332334

333335
const providers = [];
334336
if (Reflect.has(conf, 'typescript')) {

0 commit comments

Comments
 (0)