Skip to content

Commit

Permalink
Load version when used.
Browse files Browse the repository at this point in the history
Only load the package in the rare case of showing the version. This is
somewhat dependent on the current behavior of commander and how it uses
the version parameter.
  • Loading branch information
davidlehn committed Jan 4, 2024
1 parent 1a6c862 commit 10dba2e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions bin/jsonld.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,28 @@
* Copyright (c) 2013-2022 Digital Bazaar, Inc.
* All rights reserved.
*/
import {fileURLToPath} from 'node:url';
import https from 'node:https';
import {inspect} from 'node:util';
import jsonld from 'jsonld';
import {jsonldRequest} from 'jsonld-request';
import path from 'node:path';
import {program} from 'commander';

import {fileURLToPath} from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));

import {readFileSync} from 'node:fs';
const version =
JSON.parse(readFileSync(path.join(__dirname, '..', 'package.json'))).version;

const version = {
value: undefined,
toString() {
// load version when used
if(this.value === undefined) {
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const pkg =
JSON.parse(readFileSync(path.join(__dirname, '..', 'package.json')));
this.value = pkg.version;
}
return this.value;
}
};

program.version(version);

Expand Down

0 comments on commit 10dba2e

Please sign in to comment.