Skip to content

Commit 90589a8

Browse files
authored
fix(cli): fix version resolution for the --version option (#98)
`yargs` parses the `package.json` of the module and use its version value automatically when there is no explicit version passed to `.version()` Closes #97
1 parent 152b649 commit 90589a8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/cli/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const parsed = await y.parse();
3636

3737
const cli = await y
3838
.usage('Extract strings from files for translation.\nUsage: $0 [options]')
39-
.version(process.env.npm_package_version)
39+
.version()
4040
.alias('version', 'v')
4141
.help('help')
4242
.alias('help', 'h')

tests/cli/cli.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
1212
const REPOSITORY_ROOT = resolve(__dirname, '../..');
1313
const FIXTURES_PATH = resolve(REPOSITORY_ROOT, 'tests/cli/fixtures/');
1414
const TMP_PATH = resolve(REPOSITORY_ROOT, 'tests/cli/tmp');
15-
const CLI_PATH = resolve(TMP_PATH, 'dist/cli/cli.js');
15+
const CLI_PATH = resolve(TMP_PATH, 'dist/cli.js');
1616

1717
let nextFileId = 0;
1818
const createUniqueFileName = (fileName: string) => resolve(TMP_PATH, `${nextFileId++}-${fileName}`);
@@ -31,6 +31,13 @@ describe.concurrent('CLI Integration Tests', () => {
3131
await rm(TMP_PATH, { recursive: true });
3232
});
3333

34+
test('shows the version', async ({expect}) => {
35+
const packageJson = JSON.parse(await readFile(resolve(REPOSITORY_ROOT, 'package.json'), 'utf8'));
36+
const { stdout } = await execAsync(`node ${CLI_PATH} --version`);
37+
38+
expect(stdout.trim()).toBe(packageJson.version);
39+
})
40+
3441
test('shows the expected output when extracting', async ({expect}) => {
3542
const OUTPUT_FILE = createUniqueFileName('strings.json');
3643
const fixtureFiles = await readdir(FIXTURES_PATH);

0 commit comments

Comments
 (0)