From: Justin Wind Date: Wed, 15 Nov 2023 21:13:26 +0000 (-0800) Subject: use log-helper fileScope X-Git-Tag: v1.4.0~2 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=ddf28d2e4816d7c4e188f8dd510b48ad87aee478;p=squeep-indieauth-helper use log-helper fileScope --- diff --git a/lib/common.js b/lib/common.js index b52b819..7a918bb 100644 --- a/lib/common.js +++ b/lib/common.js @@ -1,21 +1,5 @@ '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) => { - const shortFilename = path.basename(filename, '.js'); - const fScope = (shortFilename === 'index') ? path.basename(path.dirname(filename)) : shortFilename; - return (scope) => [libraryIdentifier, fScope, scope].join(':'); -} - - /** * Pick out useful got response fields. * @param {GotResponse} res @@ -108,10 +92,9 @@ const properURLComponentName = (component) => { module.exports = { - fileScope, gotResponseLogData, logTruncate, pick, setSymmetricDifference, properURLComponentName, -}; \ No newline at end of file +}; diff --git a/lib/communication.js b/lib/communication.js index 6d2334a..7a9f6e3 100644 --- a/lib/communication.js +++ b/lib/communication.js @@ -12,8 +12,9 @@ const dns = require('dns'); const common = require('./common'); const Enum = require('./enum'); const { ValidationError } = require('./errors'); +const { fileScope } = require('@squeep/log-helper'); -const _fileScope = common.fileScope(__filename); +const _fileScope = fileScope(__filename); const noDotPathRE = /(\/\.\/|\/\.\.\/)/; const v6HostRE = /\[[0-9a-f:]+\]/; diff --git a/package-lock.json b/package-lock.json index 2a9ea38..2ed630c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.3.0", "license": "ISC", "dependencies": { + "@squeep/log-helper": "^1.0.0", "@squeep/web-linking": "^1.0.8", "got": "^13.0.0", "iconv": "^3.0.1", @@ -838,6 +839,14 @@ "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", "dev": true }, + "node_modules/@squeep/log-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@squeep/log-helper/-/log-helper-1.0.0.tgz", + "integrity": "sha512-i61ECZLWQI2rhkXj9pDzH1Md5ICghL9zvh5QFVo0BTayuSrdS9SWkJ6gV1qWki/Xz6SuE0y0y145NyHlvOuVaw==", + "engines": { + "node": ">=14" + } + }, "node_modules/@squeep/web-linking": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@squeep/web-linking/-/web-linking-1.0.8.tgz", @@ -4720,6 +4729,11 @@ "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", "dev": true }, + "@squeep/log-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@squeep/log-helper/-/log-helper-1.0.0.tgz", + "integrity": "sha512-i61ECZLWQI2rhkXj9pDzH1Md5ICghL9zvh5QFVo0BTayuSrdS9SWkJ6gV1qWki/Xz6SuE0y0y145NyHlvOuVaw==" + }, "@squeep/web-linking": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@squeep/web-linking/-/web-linking-1.0.8.tgz", diff --git a/package.json b/package.json index 982d0fe..ce3d3e1 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "author": "Justin Wind ", "license": "ISC", "dependencies": { + "@squeep/log-helper": "^1.0.0", "@squeep/web-linking": "^1.0.8", "got": "^13.0.0", "iconv": "^3.0.1", diff --git a/test/lib/common.js b/test/lib/common.js index ff250a4..3adb2e8 100644 --- a/test/lib/common.js +++ b/test/lib/common.js @@ -5,18 +5,6 @@ const assert = require('assert'); const common = require('../../lib/common'); describe('common', function () { - describe('fileScope', function () { - it('names a file path', function () { - const filename = 'lib/foo/bar.js'; - const result = common.fileScope(filename)('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(result.endsWith(':foo:baz')); - }); - }); // fileScope describe('pick', function () { it('picks', function () { @@ -194,4 +182,4 @@ describe('common', function () { }); }); // properURLComponentName -}); // common \ No newline at end of file +}); // common