From: Justin Wind Date: Tue, 27 Dec 2022 22:07:58 +0000 (-0800) Subject: logged scope now includes library and version X-Git-Tag: v1.2.2~1 X-Git-Url: https://git.squeep.com/?p=squeep-indieauth-helper;a=commitdiff_plain;h=3d41f4dd33d59d0c11c97ddeb51ab22d851b93e6 logged scope now includes library and version --- 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