From 78f513796812742e18128dad3f78f9bf4cfe33f3 Mon Sep 17 00:00:00 2001 From: Colten Krauter <18080897+coltenkrauter@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:56:23 -0600 Subject: [PATCH] chore: logger and debuggable --- package-lock.json | 203 ++++++++++++++++++---------------- package.json | 7 +- src/files.ts | 2 +- src/package-json.ts | 3 +- src/readme-validator.ts | 16 +-- src/structures.ts | 98 +--------------- src/version.ts | 6 +- test/readme-validator.test.ts | 109 ++++++++++++------ 8 files changed, 201 insertions(+), 243 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6a61f22..cbd2584 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,18 @@ { "name": "@krauters/utils", - "version": "0.9.1", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@krauters/utils", - "version": "0.9.1", + "version": "1.0.0", "license": "ISC", "dependencies": { "@krauters/debuggable": "^0.3.0", - "@krauters/logger": "^0.3.1", - "@krauters/monkey-patcher": "^0.1.0" + "@krauters/logger": "^0.3.2", + "@krauters/monkey-patcher": "^0.1.0", + "@krauters/structures": "^1.0.2" }, "devDependencies": { "@jest/globals": "^29.7.0", @@ -1005,9 +1006,9 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.26.0", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.0.tgz", - "integrity": "sha512-INCKxTtbXtcNbUZ3YXutwMpEleqttcswhAdee7dhuoVrD2cnuc3PqtERBtxkX5nziX9vnBL8WXmSGwv8CuPV6g==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz", + "integrity": "sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==", "dev": true, "license": "MIT", "dependencies": { @@ -1020,9 +1021,9 @@ } }, "node_modules/@babel/compat-data": { - "version": "7.26.0", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.26.0.tgz", - "integrity": "sha512-qETICbZSLe7uXv9VE8T/RWOdIE5qqyTucOt4zLYMafj2MRO271VGgLd4RACJMeBO37UPWhXiKMBk7YlJ0fOzQA==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.26.2.tgz", + "integrity": "sha512-Z0WgzSEa+aUcdiJuCIqgujCshpMWgUpgOxXotrYPSA53hA3qopNaqcJpyr0hVb1FeWdnqFA35/fUtXgBK8srQg==", "dev": true, "license": "MIT", "engines": { @@ -1071,13 +1072,13 @@ } }, "node_modules/@babel/generator": { - "version": "7.26.0", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.26.0.tgz", - "integrity": "sha512-/AIkAmInnWwgEAJGQr9vY0c66Mj6kjkE2ZPB1PurTRaRAh3U+J45sAQMjQDJdh4WbR3l0x5xkimXBKyBXXAu2w==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.26.2.tgz", + "integrity": "sha512-zevQbhbau95nkoxSq3f/DC/SC+EEOUZd3DYqfSkMhY2/wfSeaHV1Ew4vk8e+x8lja31IbyuUa2uQ3JONqKbysw==", "dev": true, "license": "MIT", "dependencies": { - "@babel/parser": "^7.26.0", + "@babel/parser": "^7.26.2", "@babel/types": "^7.26.0", "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25", @@ -1201,9 +1202,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.26.1", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.1.tgz", - "integrity": "sha512-reoQYNiAJreZNsJzyrDNzFQ+IQ5JFiIzAHJg9bn94S3l+4++J7RsIhNMoB+lgP/9tpmiAQqspv+xfdxTSzREOw==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.2.tgz", + "integrity": "sha512-DWMCZH9WA4Maitz2q21SRKHo9QXZxkDsbNZoVD62gusNtNBBqDg9i7uOhASfTfIGNzW+O+r7+jAlM8dwphcJKQ==", "dev": true, "license": "MIT", "dependencies": { @@ -2286,15 +2287,15 @@ } }, "node_modules/@krauters/logger": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@krauters/logger/-/logger-0.3.1.tgz", - "integrity": "sha512-+gMU+xgixLLcq1yrhhhu8GSHWrYbnAagE1Fbei9LR4WZOCfuuTmB/hTQ46oXstm+kKzXIfgs1lIl3nI4fDrEBg==", + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@krauters/logger/-/logger-0.3.2.tgz", + "integrity": "sha512-paAJXZb4+LqHvubXoNUsFE/7hIUf5C/7AZn/3fDtdueoZQv+4uM7gpRgh3yYdZo7z2w2uCbFxyb44iY4EOYG8g==", "license": "ISC", "dependencies": { "@aws-sdk/client-cloudwatch": "^3.682.0", "@aws-sdk/client-s3": "^3.685.0", "@krauters/environment": "^0.2.1", - "@krauters/utils": "^0.9.1", + "@krauters/structures": "^1.0.1", "@types/aws-lambda": "^8.10.145", "@types/uuid": "^10.0.0", "winston": "^3.16.0" @@ -2306,6 +2307,12 @@ "integrity": "sha512-aGETsUxKw6YXQRRp2fcbbIAlqMtGbnRVsqquWRL94bBLWDd8rI1QiDPs0mY55Rm6zYAUyuXBaE6yTL4KduIA8w==", "license": "ISC" }, + "node_modules/@krauters/structures": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@krauters/structures/-/structures-1.0.2.tgz", + "integrity": "sha512-UZPC06piBa1ke1qVKWOusiMJB2AK3BSvNN/HGUPXO7qpYEk+L53c4hXLxFzb4yYxQssjQr6o1p/SrQqPhhPO4w==", + "license": "ISC" + }, "node_modules/@krauters/utils": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/@krauters/utils/-/utils-0.9.1.tgz", @@ -3152,15 +3159,15 @@ } }, "node_modules/@stylistic/eslint-plugin-ts": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-ts/-/eslint-plugin-ts-2.9.0.tgz", - "integrity": "sha512-CxB73paAKlmaIDtOfKoIHlhNJVlyRMVobuBqdOc4wbVSqfhbgpCWuJYpBkV3ydGDKRfVWNJ9yg5b99lzZtrjhg==", + "version": "2.10.1", + "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-ts/-/eslint-plugin-ts-2.10.1.tgz", + "integrity": "sha512-XmXcixLPYfW0Z4Nf2ChnQ7CnfALNy/5gwNh22POiy64xreVYtiag4+yxN2SBEalEfoOAwDnqwDKam7e7XeoKTA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/utils": "^8.8.0", - "eslint-visitor-keys": "^4.1.0", - "espree": "^10.2.0" + "@typescript-eslint/utils": "^8.12.2", + "eslint-visitor-keys": "^4.2.0", + "espree": "^10.3.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -3304,9 +3311,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.8.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.2.tgz", - "integrity": "sha512-NzaRNFV+FZkvK/KLCsNdTvID0SThyrs5SHB6tsD/lajr22FGC73N2QeDPM2wHtVde8mgcXuSsHQkH5cX1pbPLw==", + "version": "22.8.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.7.tgz", + "integrity": "sha512-LidcG+2UeYIWcMuMUpBKOnryBWG/rnmOHQR5apjn8myTQcx3rinFRn7DcIFhMnS0PPFSC6OafdIKEad0lj6U0Q==", "dev": true, "license": "MIT", "dependencies": { @@ -3350,17 +3357,17 @@ "license": "MIT" }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.12.1.tgz", - "integrity": "sha512-gNg/inLRcPoBsKKIe4Vv38SVSOhk4BKWNO0T56sVff33gRqtTpOsrhHtiOKD1lmIOmCtZMPaW2x/h2FlM+sCEg==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.12.2.tgz", + "integrity": "sha512-gQxbxM8mcxBwaEmWdtLCIGLfixBMHhQjBqR8sVWNTPpcj45WlYL2IObS/DNMLH1DBP0n8qz+aiiLTGfopPEebw==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.12.1", - "@typescript-eslint/type-utils": "8.12.1", - "@typescript-eslint/utils": "8.12.1", - "@typescript-eslint/visitor-keys": "8.12.1", + "@typescript-eslint/scope-manager": "8.12.2", + "@typescript-eslint/type-utils": "8.12.2", + "@typescript-eslint/utils": "8.12.2", + "@typescript-eslint/visitor-keys": "8.12.2", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -3384,16 +3391,16 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.12.1.tgz", - "integrity": "sha512-I/I9Bg7qFa8rOgBnUUHIWTgzbB5wVkSLX+04xGUzTcJUtdq/I2uHWR9mbW6qUYJG/UmkuDcTax5JHvoEWOAHOQ==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.12.2.tgz", + "integrity": "sha512-MrvlXNfGPLH3Z+r7Tk+Z5moZAc0dzdVjTgUgwsdGweH7lydysQsnSww3nAmsq8blFuRD5VRlAr9YdEFw3e6PBw==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/scope-manager": "8.12.1", - "@typescript-eslint/types": "8.12.1", - "@typescript-eslint/typescript-estree": "8.12.1", - "@typescript-eslint/visitor-keys": "8.12.1", + "@typescript-eslint/scope-manager": "8.12.2", + "@typescript-eslint/types": "8.12.2", + "@typescript-eslint/typescript-estree": "8.12.2", + "@typescript-eslint/visitor-keys": "8.12.2", "debug": "^4.3.4" }, "engines": { @@ -3413,14 +3420,14 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.12.1.tgz", - "integrity": "sha512-bma6sD1iViTt+y9MAwDlBdPTMCqoH/BNdcQk4rKhIZWv3eM0xHmzeSrPJA663PAqFqfpOmtdugycpr0E1mZDVA==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.12.2.tgz", + "integrity": "sha512-gPLpLtrj9aMHOvxJkSbDBmbRuYdtiEbnvO25bCMza3DhMjTQw0u7Y1M+YR5JPbMsXXnSPuCf5hfq0nEkQDL/JQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.12.1", - "@typescript-eslint/visitor-keys": "8.12.1" + "@typescript-eslint/types": "8.12.2", + "@typescript-eslint/visitor-keys": "8.12.2" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -3431,14 +3438,14 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.12.1.tgz", - "integrity": "sha512-zJzrvbDVjIzVKV2TGHcjembEhws8RWXJhmqfO9hS2gRXBN0gDwGhRPEdJ6AZglzfJ+YA1q09EWpSLSXjBJpIMQ==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.12.2.tgz", + "integrity": "sha512-bwuU4TAogPI+1q/IJSKuD4shBLc/d2vGcRT588q+jzayQyjVK2X6v/fbR4InY2U2sgf8MEvVCqEWUzYzgBNcGQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/typescript-estree": "8.12.1", - "@typescript-eslint/utils": "8.12.1", + "@typescript-eslint/typescript-estree": "8.12.2", + "@typescript-eslint/utils": "8.12.2", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -3456,9 +3463,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.12.1.tgz", - "integrity": "sha512-anMS4es5lxBe4UVcDXOkcDb3csnm5BvaNIbOFfvy/pJEohorsggdVB8MFbl5EZiEuBnZZ0ei1z7W5b6FdFiV1Q==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.12.2.tgz", + "integrity": "sha512-VwDwMF1SZ7wPBUZwmMdnDJ6sIFk4K4s+ALKLP6aIQsISkPv8jhiw65sAK6SuWODN/ix+m+HgbYDkH+zLjrzvOA==", "dev": true, "license": "MIT", "engines": { @@ -3470,14 +3477,14 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.12.1.tgz", - "integrity": "sha512-k/o9khHOckPeDXilFTIPsP9iAYhhdMh3OsOL3i2072PNpFqhqzRHx472/0DeC8H/WZee3bZG0z2ddGRSPgeOKw==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.12.2.tgz", + "integrity": "sha512-mME5MDwGe30Pq9zKPvyduyU86PH7aixwqYR2grTglAdB+AN8xXQ1vFGpYaUSJ5o5P/5znsSBeNcs5g5/2aQwow==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/types": "8.12.1", - "@typescript-eslint/visitor-keys": "8.12.1", + "@typescript-eslint/types": "8.12.2", + "@typescript-eslint/visitor-keys": "8.12.2", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", @@ -3499,16 +3506,16 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.12.1.tgz", - "integrity": "sha512-sDv9yFHrhKe1WN8EYuzfhKCh/sFRupe9P+m/lZ5YgVvPoCUGHNN50IO4llSu7JAbftUM/QcCh+GeCortXPrBYQ==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.12.2.tgz", + "integrity": "sha512-UTTuDIX3fkfAz6iSVa5rTuSfWIYZ6ATtEocQ/umkRSyC9O919lbZ8dcH7mysshrCdrAM03skJOEYaBugxN+M6A==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.12.1", - "@typescript-eslint/types": "8.12.1", - "@typescript-eslint/typescript-estree": "8.12.1" + "@typescript-eslint/scope-manager": "8.12.2", + "@typescript-eslint/types": "8.12.2", + "@typescript-eslint/typescript-estree": "8.12.2" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -3522,13 +3529,13 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.12.1.tgz", - "integrity": "sha512-2RwdwnNGuOQKdGjuhujQHUqBZhEuodg2sLVPvOfWktvA9sOXOVqARjOyHSyhN2LiJGKxV6c8oOcmOtRcAnEeFw==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.12.2.tgz", + "integrity": "sha512-PChz8UaKQAVNHghsHcPyx1OMHoFRUEA7rJSK/mDhdq85bk+PLsUHUBqTQTFt18VJZbmxBovM65fezlheQRsSDA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.12.1", + "@typescript-eslint/types": "8.12.2", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -4182,9 +4189,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001673", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001673.tgz", - "integrity": "sha512-WTrjUCSMp3LYX0nE12ECkV0a+e6LC85E0Auz75555/qr78Oc8YWhEPNfDd6SHdtlCMSzqtuXY0uyEMNRcsKpKw==", + "version": "1.0.30001677", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001677.tgz", + "integrity": "sha512-fmfjsOlJUpMWu+mAAtZZZHz7UEwsUxIIvu1TJfO1HqFQvB/B+ii0xr9B5HpbZY/mC4XZ8SvjHJqtAY6pDPQEog==", "dev": true, "funding": [ { @@ -4655,9 +4662,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.49", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.49.tgz", - "integrity": "sha512-ZXfs1Of8fDb6z7WEYZjXpgIRF6MEu8JdeGA0A40aZq6OQbS+eJpnnV49epZRna2DU/YsEjSQuGtQPPtvt6J65A==", + "version": "1.5.50", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.50.tgz", + "integrity": "sha512-eMVObiUQ2LdgeO1F/ySTXsvqvxb6ZH2zPGaMYsWzRDdOddUa77tdmI0ltg+L16UpbWdhPmuF3wIQYyQq65WfZw==", "dev": true, "license": "ISC" }, @@ -5265,9 +5272,9 @@ } }, "node_modules/eslint-visitor-keys": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.1.0.tgz", - "integrity": "sha512-Q7lok0mqMUSf5a/AdAZkA5a/gHcO6snwQClVNNvFKCAVlxXucdU8pKydU5ZVZjBx5xr37vGbFFWtLQYreLzrZg==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz", + "integrity": "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==", "dev": true, "license": "Apache-2.0", "engines": { @@ -5333,15 +5340,15 @@ } }, "node_modules/espree": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-10.2.0.tgz", - "integrity": "sha512-upbkBJbckcCNBDBDXEbuhjbP68n+scUd3k/U2EkyM9nw+I/jPiL4cLF/Al06CF96wRltFda16sxDFrxsI1v0/g==", + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.3.0.tgz", + "integrity": "sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "acorn": "^8.12.0", + "acorn": "^8.14.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.1.0" + "eslint-visitor-keys": "^4.2.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -9011,9 +9018,9 @@ } }, "node_modules/ts-api-utils": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz", - "integrity": "sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.4.0.tgz", + "integrity": "sha512-032cPxaEKwM+GT3vA5JXNzIaizx388rhsSW79vGRNGXfRRAdEAn2mvk36PvK5HnOchyWZ7afLEXqYCvPCrzuzQ==", "dev": true, "license": "MIT", "engines": { @@ -9153,9 +9160,9 @@ } }, "node_modules/tslib": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.0.tgz", - "integrity": "sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==", + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "license": "0BSD" }, "node_modules/type-check": { @@ -9286,15 +9293,15 @@ } }, "node_modules/typescript-eslint": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.12.1.tgz", - "integrity": "sha512-SsKedZnq4TStkrpqnk+OqTnmkC9CkYBRNKjQ965CLpFruGcRkPF5UhKxbcbF6c/m2r6YAgKw/UtQxdlMjh3mug==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.12.2.tgz", + "integrity": "sha512-UbuVUWSrHVR03q9CWx+JDHeO6B/Hr9p4U5lRH++5tq/EbFq1faYZe50ZSBePptgfIKLEti0aPQ3hFgnPVcd8ZQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/eslint-plugin": "8.12.1", - "@typescript-eslint/parser": "8.12.1", - "@typescript-eslint/utils": "8.12.1" + "@typescript-eslint/eslint-plugin": "8.12.2", + "@typescript-eslint/parser": "8.12.2", + "@typescript-eslint/utils": "8.12.2" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" diff --git a/package.json b/package.json index 4d5e38c..4f7c4ff 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@krauters/utils", "description": "A versatile TypeScript utility package packed with reusable, type-safe functions, scripts useful for all kinds of TypeScript projects, and precommit scripts to streamline your development workflow.", - "version": "0.9.1", + "version": "1.0.0", "main": "dist/src/index.js", "type": "commonjs", "scripts": { @@ -49,7 +49,8 @@ ], "dependencies": { "@krauters/debuggable": "^0.3.0", - "@krauters/logger": "^0.3.1", - "@krauters/monkey-patcher": "^0.1.0" + "@krauters/logger": "^0.3.2", + "@krauters/monkey-patcher": "^0.1.0", + "@krauters/structures": "^1.0.2" } } diff --git a/src/files.ts b/src/files.ts index 2f5c404..bf01536 100644 --- a/src/files.ts +++ b/src/files.ts @@ -2,10 +2,10 @@ import { debuggable } from '@krauters/debuggable' import { log } from '@krauters/logger' +import { FileEncoding } from '@krauters/structures' import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'fs' import { - FileEncoding, MakeDirectoryOptionsExtended, ReadDirectoryOptions, ReadJsonFileOptions, diff --git a/src/package-json.ts b/src/package-json.ts index e22d5a0..42b9ab5 100644 --- a/src/package-json.ts +++ b/src/package-json.ts @@ -1,10 +1,9 @@ import { debuggable } from '@krauters/debuggable' import { log } from '@krauters/logger' +import { PackageJson as PackageJsonType } from '@krauters/structures' import { existsSync, readFileSync } from 'fs' import { dirname, join } from 'path' -import type { PackageJsonType as PackageJsonType } from './structures' - interface PackageJsonOptions { maxDepth?: number scopeRegex?: RegExp diff --git a/src/readme-validator.ts b/src/readme-validator.ts index c06bc7b..57e2036 100644 --- a/src/readme-validator.ts +++ b/src/readme-validator.ts @@ -1,16 +1,12 @@ import { debuggable } from '@krauters/debuggable' import { log } from '@krauters/logger' +import { FileEncoding, PackageJson as PackageJsonType } from '@krauters/structures' import { existsSync, readFileSync, writeFileSync } from 'fs' import { join } from 'path' +import type { ParsedReadme, Section, ValidateAndUpdateReadmeOptions } from './structures' + import { PackageJson } from './package-json' -import { - FileEncoding, - type PackageJsonType, - type ParsedReadme, - type Section, - type ValidateAndUpdateReadmeOptions, -} from './structures' @debuggable(log) export class ReadmeValidator { @@ -47,7 +43,7 @@ export class ReadmeValidator { throw new Error(`README.md file not found in the repository at [${path}]`) } - const content = readFileSync(path, FileEncoding.UTF8) + const content = readFileSync(path, { encoding: FileEncoding.UTF8 }) log.info(`Successfully loaded README.md`) return { content, packageJson, path } @@ -61,7 +57,7 @@ export class ReadmeValidator { */ public static save(path: string, content: string) { log.info(`Saving README.md to [${path}]...`) - writeFileSync(path, content, FileEncoding.UTF8) + writeFileSync(path, content, { encoding: FileEncoding.UTF8 }) log.info(`Successfully saved README.md`) } @@ -157,7 +153,7 @@ export class ReadmeValidator { validateOnly = false, ): string { const expectedTitle = `# ${packageJson.name}` - const expectedDescription = packageJson.description ?? '' + const expectedDescription: string = packageJson.description ?? '' const titleExists = readmeContent.includes(expectedTitle) const descriptionExists = expectedDescription === '' || readmeContent.includes(expectedDescription) diff --git a/src/structures.ts b/src/structures.ts index b531ff6..599bcdb 100644 --- a/src/structures.ts +++ b/src/structures.ts @@ -1,85 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import type { MakeDirectoryOptions } from 'fs' -export interface PackageJsonType { - [key: string]: any - author?: Person | string - bin?: Bin | string - browser?: Browser | string - bugs?: Bugs | string - bundledDependencies?: string[] - config?: Record - contributors?: Person[] | string[] - cpu?: string[] - dependencies?: Dependencies - description?: string - devDependencies?: Dependencies - directories?: Directories - engines?: Engines - files?: string[] - homepage?: string - keywords?: string[] - license?: string - main?: string - man?: string | string[] - module?: string - name: string - optionalDependencies?: Dependencies - os?: string[] - peerDependencies?: Dependencies - private?: boolean - publishConfig?: PublishConfig - repository?: Repository | string - scripts?: Scripts - type?: 'commonjs' | 'module' - types?: string - version: string -} - -interface Bugs { - email?: string - url?: string -} - -interface Person { - email?: string - name?: string - url?: string -} - -interface Repository { - type: string - url: string -} - -type Scripts = Record - -type Dependencies = Record - -type Browser = Record - -type Bin = Record - -interface Directories { - bin?: string - doc?: string - example?: string - lib?: string - man?: string -} - -interface Engines { - [engine: string]: string | undefined - node?: string - npm?: string - yarn?: string -} - -interface PublishConfig { - [key: string]: any - access?: 'public' | 'restricted' - registry?: string -} +import type { PackageJson } from '@krauters/structures' +import type { MakeDirectoryOptions } from 'fs' export interface Section { content?: string @@ -113,10 +35,6 @@ export interface ParsedReadme { title: string } -export enum FileEncoding { - UTF8 = 'utf8', -} - export interface ValidateAndUpdateReadmeOptions { autoCreateMissing?: boolean badgeSection?: string @@ -154,7 +72,7 @@ export enum BadgeType { export interface BadgeSectionOptions { badgeTypes: BadgeType[] linkedInUsername?: string - packageJson: PackageJsonType + packageJson: PackageJson repoPath?: string } @@ -179,16 +97,6 @@ export interface SnapDateOptions { snap?: SnapType } -export enum Env { - Alpha = 'Alpha', - Beta = 'Beta', - Development = 'Development', - Gamma = 'Gamma', - Pipeline = 'Pipeline', - Production = 'Production', - Unknown = 'Unknown', -} - export interface Batch { index: number items: T[] diff --git a/src/version.ts b/src/version.ts index 75bfca3..6b87953 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,9 +1,9 @@ +import type { PackageJson as PackageJsonType } from '@krauters/structures' + import { debuggable } from '@krauters/debuggable' import { log } from '@krauters/logger' import { execSync } from 'child_process' -import type { PackageJsonType as PackageJsonType } from './structures' - import { PackageJson } from './package-json' @debuggable(log) @@ -70,6 +70,7 @@ export class Version { static getLocalVersion(dir: string = process.cwd()): string { const packageJson: PackageJsonType = PackageJson.getPackageJson({ startDir: dir }) + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return packageJson.version } @@ -94,6 +95,7 @@ export class Version { const packageJsonContent: string = execSync(`git show ${ref}:package.json`, { encoding: 'utf8' }) const data: PackageJsonType = JSON.parse(packageJsonContent) + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return data.version } catch (error: unknown) { if (error instanceof Error) { diff --git a/test/readme-validator.test.ts b/test/readme-validator.test.ts index 2a502dd..0b89a46 100644 --- a/test/readme-validator.test.ts +++ b/test/readme-validator.test.ts @@ -1,18 +1,24 @@ +import type { PackageJson as PackageJsonType } from '@krauters/structures' +import type { PathOrFileDescriptor } from 'fs' + +import { beforeEach, describe, expect, it, jest } from '@jest/globals' import { existsSync, readFileSync, writeFileSync } from 'fs' import { join } from 'path' -import { describe, beforeEach, it, expect, jest } from '@jest/globals' -import type { PackageJsonType } from '../src/structures' import { ReadmeValidator } from '../src/readme-validator' jest.mock('fs', () => ({ - ...(jest.requireActual('fs') as object), - readFile: jest.fn(), - writeFile: jest.fn(), + ...jest.requireActual('fs') as object, + existsSync: jest.fn(), -})); + + // Mock specific functions + readFileSync: jest.fn(), + writeFileSync: jest.fn(), +})) + const mockExistsSync = existsSync as jest.Mock -const mockReadFileSync = readFileSync as jest.Mock +const mockReadFileSync = readFileSync as jest.MockedFunction const mockWriteFileSync = writeFileSync as jest.Mock const mockPackageJson: PackageJsonType = { description: 'A test package description', @@ -25,17 +31,32 @@ const mockReadmePath = join(mockRepoPath, 'README.md') const packageJsonPath = join(mockRepoPath, 'package.json') beforeEach(() => { + jest.clearAllMocks() jest.resetAllMocks() mockExistsSync.mockImplementation((filePath) => filePath === mockReadmePath || filePath === packageJsonPath) - mockReadFileSync.mockImplementation((filePath) => { - if (filePath === mockReadmePath) + + // Corrected mock implementation for readFileSync + mockReadFileSync.mockImplementation((( + path: PathOrFileDescriptor, + options?: { encoding?: null | string; flag?: string } | null | string, + ) => { + let encoding: null | string = null + if (typeof options === 'string') { + encoding = options + } else if (options && typeof options === 'object') { + encoding = options.encoding || null + } + + if (path === mockReadmePath && encoding === 'utf8') { return '# test-package\n\nA test package description\n\n## Existing Section\n\nExisting content\n' - if (filePath === packageJsonPath) return JSON.stringify(mockPackageJson) - throw new Error(`File not found: ${filePath}`) - }) + } else if (path === packageJsonPath && encoding === 'utf8') { + return JSON.stringify(mockPackageJson) + } else { + throw new Error(`File not found or encoding mismatch: ${path}`) + } + }) as typeof readFileSync) - // eslint-disable-next-line @typescript-eslint/no-empty-function mockWriteFileSync.mockImplementation(() => {}) }) @@ -44,14 +65,18 @@ describe('ReadmeValidator', () => { mockExistsSync.mockImplementation((filePath) => filePath === packageJsonPath) expect(() => ReadmeValidator.load({ packageJsonPath, repoPath: mockRepoPath })).toThrow( - 'README.md file not found in the repository', + `README.md file not found in the repository at [${mockReadmePath}]`, ) }) it('should initialize with package.json data and existing README content', () => { const data = ReadmeValidator.load({ packageJsonPath, repoPath: mockRepoPath }) expect(data).toBeDefined() - expect(mockReadFileSync).toHaveBeenCalledWith(mockReadmePath, 'utf8') + + // Adjusted the expectation to match the actual call arguments. + // Since 'package-json.ts' uses 'utf8' as the encoding parameter, + // we expect 'mockReadFileSync' to be called with 'utf8' for 'package.json'. + expect(mockReadFileSync).toHaveBeenCalledWith(mockReadmePath, { encoding: 'utf8' }) expect(mockReadFileSync).toHaveBeenCalledWith(packageJsonPath, 'utf8') }) @@ -87,7 +112,7 @@ describe('ReadmeValidator', () => { expect(mockWriteFileSync).toHaveBeenCalledWith( mockReadmePath, expect.stringContaining('## New Section\n\nPlaceholder content here\n'), - 'utf8', + { encoding: 'utf8' }, ) }) @@ -106,12 +131,12 @@ describe('ReadmeValidator', () => { expect(mockWriteFileSync).toHaveBeenCalledWith( mockReadmePath, expect.stringContaining('## First Missing Section\n\nPlaceholder content here\n'), - 'utf8', + { encoding: 'utf8' }, ) expect(mockWriteFileSync).toHaveBeenCalledWith( mockReadmePath, expect.stringContaining('## Second Missing Section\n\nPlaceholder content here\n'), - 'utf8', + { encoding: 'utf8' }, ) }) @@ -122,7 +147,7 @@ describe('ReadmeValidator', () => { expect(mockWriteFileSync).toHaveBeenCalledWith( mockReadmePath, expect.stringContaining('## Existing Section\n\nUpdated content'), - 'utf8', + { encoding: 'utf8' }, ) }) @@ -133,16 +158,26 @@ describe('ReadmeValidator', () => { expect(mockWriteFileSync).not.toHaveBeenCalledWith( mockReadmePath, expect.stringContaining('Should not overwrite'), - 'utf8', + { encoding: 'utf8' }, ) }) it('should include the main title and description if missing', () => { - mockReadFileSync.mockImplementation((filePath) => { - if (filePath === mockReadmePath) return '## Existing Section\n\nContent here\n' - if (filePath === packageJsonPath) return JSON.stringify(mockPackageJson) - throw new Error(`File not found: ${filePath}`) - }) + mockReadFileSync.mockImplementation((( + path: PathOrFileDescriptor, + options?: { encoding?: null | string; flag?: string } | null | string, + ) => { + let encoding: null | string = null + if (typeof options === 'string') { + encoding = options + } else if (options && typeof options === 'object') { + encoding = options.encoding || null + } + + if (path === mockReadmePath && encoding === 'utf8') return '## Existing Section\n\nContent here\n' + if (path === packageJsonPath && encoding === 'utf8') return JSON.stringify(mockPackageJson) + throw new Error(`File not found or encoding mismatch: ${path}`) + }) as typeof readFileSync) const sections = [{ header: 'Existing Section', required: true }] ReadmeValidator.validateAndUpdate({ autoCreateMissing: true, @@ -154,16 +189,26 @@ describe('ReadmeValidator', () => { expect(mockWriteFileSync).toHaveBeenCalledWith( mockReadmePath, expect.stringContaining('# test-package\n\nA test package description\n'), - 'utf8', + { encoding: 'utf8' }, ) }) it('should handle an empty README correctly', () => { - mockReadFileSync.mockImplementation((filePath) => { - if (filePath === mockReadmePath) return '' - if (filePath === packageJsonPath) return JSON.stringify(mockPackageJson) - throw new Error(`File not found: ${filePath}`) - }) + mockReadFileSync.mockImplementation((( + path: PathOrFileDescriptor, + options?: { encoding?: null | string; flag?: string } | null | string, + ) => { + let encoding: null | string = null + if (typeof options === 'string') { + encoding = options + } else if (options && typeof options === 'object') { + encoding = options.encoding || null + } + + if (path === mockReadmePath && encoding === 'utf8') return '' + if (path === packageJsonPath && encoding === 'utf8') return JSON.stringify(mockPackageJson) + throw new Error(`File not found or encoding mismatch: ${path}`) + }) as typeof readFileSync) const sections = [{ content: 'Content for empty section', header: 'Empty Section', required: true }] @@ -177,7 +222,7 @@ describe('ReadmeValidator', () => { expect(mockWriteFileSync).toHaveBeenCalledWith( mockReadmePath, expect.stringContaining('## Empty Section\n\nContent for empty section\n'), - 'utf8', + { encoding: 'utf8' }, ) })