use log-helper fileScope
authorJustin Wind <justin.wind+git@gmail.com>
Wed, 15 Nov 2023 21:13:26 +0000 (13:13 -0800)
committerJustin Wind <justin.wind+git@gmail.com>
Wed, 15 Nov 2023 21:13:26 +0000 (13:13 -0800)
lib/common.js
lib/communication.js
package-lock.json
package.json
test/lib/common.js

index b52b819da963d5172a06779e279cf3e2531acbcb..7a918bb9f4eaf1d7b588152d35290268ced89aa5 100644 (file)
@@ -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
+};
index 6d2334a246f633bfea998820a7507c77829e2654..7a9f6e318f4675a560f0714a0fb7efd1470e4998 100644 (file)
@@ -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:]+\]/;
index 2a9ea3894342ef31a2e381b3a42c171e21871110..2ed630c33ff06aa6e79fbd09e295ebd85dd22cd9 100644 (file)
@@ -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",
       "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",
       "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",
index 982d0fe4285b35978e52ce7bca974cba9c87f254..ce3d3e176fcd8ec58664fe97796711387b80b692 100644 (file)
@@ -25,6 +25,7 @@
   "author": "Justin Wind <jwind-npm@squeep.com>",
   "license": "ISC",
   "dependencies": {
+    "@squeep/log-helper": "^1.0.0",
     "@squeep/web-linking": "^1.0.8",
     "got": "^13.0.0",
     "iconv": "^3.0.1",
index ff250a4c43098e0be305ab523d2d396eb6defc8b..3adb2e8e6f4d4f77556d8e1e8aa3cdd796c2ff17 100644 (file)
@@ -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