diff --git a/lib/cli.js b/lib/cli.js index 3f9974732..f1597950e 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -21,6 +21,7 @@ import {splitPatternAndLineNumbers} from './line-numbers.js'; import {loadConfig} from './load-config.js'; import normalizeModuleTypes from './module-types.js'; import normalizeNodeArguments from './node-arguments.js'; +import pkg from './pkg.cjs'; import providerManager from './provider-manager.js'; import DefaultReporter from './reporters/default.js'; import TapReporter from './reporters/tap.js'; @@ -102,7 +103,7 @@ export default async function loadCli() { // eslint-disable-line complexity let conf; let confError; try { - const {argv: {config: configFile}} = yargs(hideBin(process.argv)).help(false); + const {argv: {config: configFile}} = yargs(hideBin(process.argv)).help(false).version(false); conf = await loadConfig({configFile}); if (conf.configFile && path.basename(conf.configFile) !== path.relative(conf.projectDir, conf.configFile)) { console.log(chalk.magenta(` ${figures.warning} Using configuration from ${conf.configFile}`)); @@ -132,6 +133,7 @@ export default async function loadCli() { // eslint-disable-line complexity let resetCache = false; const {argv} = yargs(hideBin(process.argv)) + .version(pkg.version) .parserConfiguration({ 'boolean-negation': true, 'camel-case-expansion': false, @@ -319,16 +321,16 @@ export default async function loadCli() { // eslint-disable-line complexity exit('’sources’ has been removed. Use ’ignoredByWatcher’ to provide glob patterns of files that the watcher should ignore.'); } - let pkg; + let projectPackageObject; try { - pkg = JSON.parse(fs.readFileSync(path.resolve(projectDir, 'package.json'))); + projectPackageObject = JSON.parse(fs.readFileSync(path.resolve(projectDir, 'package.json'))); } catch (error) { if (error.code !== 'ENOENT') { throw error; } } - const {type: defaultModuleType = 'commonjs'} = pkg || {}; + const {type: defaultModuleType = 'commonjs'} = projectPackageObject || {}; const providers = []; if (Reflect.has(conf, 'typescript')) {