From 3d41f4dd33d59d0c11c97ddeb51ab22d851b93e6 Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Tue, 27 Dec 2022 14:07:58 -0800 Subject: [PATCH] logged scope now includes library and version --- lib/common.js | 11 ++++++----- test/lib/common.js | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/common.js b/lib/common.js index f199b49..3bf7e55 100644 --- a/lib/common.js +++ b/lib/common.js @@ -1,17 +1,18 @@ 'use strict'; const path = require('path'); +const { name: packageName, version: packageVersion } = require('../package'); + +const libraryIdentifier = `${packageName}@${packageVersion}`; /** * Return a function which combines a part of the filename with a scope, for use in logging. * @param {string} filename */ const fileScope = (filename) => { - let fScope = path.basename(filename, '.js'); - if (fScope === 'index') { - fScope = path.basename(path.dirname(filename)); - } - return (scope) => `${fScope}:${scope}`; + const shortFilename = path.basename(filename, '.js'); + const fScope = (shortFilename === 'index') ? path.basename(path.dirname(filename)) : shortFilename; + return (scope) => [libraryIdentifier, fScope, scope].join(':'); } diff --git a/test/lib/common.js b/test/lib/common.js index 7ebc91b..20911c1 100644 --- a/test/lib/common.js +++ b/test/lib/common.js @@ -9,12 +9,12 @@ describe('common', function () { it('names a file path', function () { const filename = 'lib/foo/bar.js'; const result = common.fileScope(filename)('baz'); - assert.strictEqual(result, 'bar:baz'); + assert(result.endsWith(':bar:baz')); }); it('names an index path', function () { const filename = 'lib/foo/index.js'; const result = common.fileScope(filename)('baz'); - assert.strictEqual(result, 'foo:baz'); + assert(result.endsWith(':foo:baz')); }); }); // fileScope -- 2.43.2