Skip to content

Commit b922957

Browse files
committed
Add version number to log message
1 parent a8bcf6a commit b922957

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

spec/package.spec.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,37 @@ describe('The "dist" folder', () => {
2222

2323
});
2424

25+
////////////////////////////////////////////////////////////////////////////////
26+
describe('Library version number', () => {
27+
28+
it('follows semantic version formatting', () => {
29+
const version = esmToPlainJs.version;
30+
const semVer = /\d+[.]\d+[.]\d+/;
31+
const actual = { version: version, valid: semVer.test(version) };
32+
const expected = { version: version, valid: true };
33+
assertDeepStrictEqual(actual, expected);
34+
});
35+
36+
});
37+
2538
////////////////////////////////////////////////////////////////////////////////
2639
describe('Library module', () => {
2740

28-
it('is an object', () => {
29-
const actual = { constructor: esmToPlainJs.constructor.name };
30-
const expected = { constructor: 'Object' };
41+
it('is exported as an object', () => {
42+
const actual = { type: typeof esmToPlainJs };
43+
const expected = { type: 'object' };
3144
assertDeepStrictEqual(actual, expected);
3245
});
3346

34-
it('has functions named assert(), cli(), reporter(), and transform()', () => {
47+
it('has the correct properties', () => {
3548
const module = esmToPlainJs;
3649
const actual = Object.keys(module).sort().map(key => [key, typeof module[key]]);
3750
const expected = [
3851
['assertOk', 'function'],
3952
['cli', 'function'],
4053
['reporter', 'function'],
4154
['transform', 'function'],
55+
['version', 'string'],
4256
];
4357
assertDeepStrictEqual(actual, expected);
4458
});

src/esm-to-plain-js.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export type Result = {
3737

3838
const esmToPlainJs = {
3939

40+
version: '{{package.version}}',
41+
4042
assertOk(ok: unknown, message: string | null) {
4143
if (!ok)
4244
throw new Error(`[esm-to-plain-js] ${message}`);
@@ -107,10 +109,10 @@ const esmToPlainJs = {
107109
},
108110

109111
reporter(result: Result) {
110-
const name = chalk.gray('esm-to-plain-js');
111-
const ancestor = cliArgvUtil.calcAncestor(result.origin, result.dest);
112-
const info = chalk.white(`(${result.duration}ms)`);
113-
log(name, ancestor.message, info);
112+
const name = chalk.gray('esm-to-plain-js');
113+
const version = chalk.gray('v' + esmToPlainJs.version);
114+
const info = chalk.blue(`(${result.duration}ms)`);
115+
log(name, version, cliArgvUtil.colorizePath(result.dest), info);
114116
},
115117

116118
};

0 commit comments

Comments
 (0)