From 9413441dbb4214c34ed5a43dc5bc05a5f592882e Mon Sep 17 00:00:00 2001 From: gesslar <1266935+gesslar@users.noreply.github.com> Date: Thu, 13 Feb 2025 00:21:39 -0500 Subject: [PATCH 1/3] Improve error handling in API requests (#156) * bleh * bleh --- .../bedoc-markdown-printer.js | 6 +- package-lock.json | 239 +++--------------- package.json | 3 +- 3 files changed, 38 insertions(+), 210 deletions(-) diff --git a/examples/node_modules_test/bedoc-markdown-printer/bedoc-markdown-printer.js b/examples/node_modules_test/bedoc-markdown-printer/bedoc-markdown-printer.js index 1ba562f..bc030fb 100644 --- a/examples/node_modules_test/bedoc-markdown-printer/bedoc-markdown-printer.js +++ b/examples/node_modules_test/bedoc-markdown-printer/bedoc-markdown-printer.js @@ -15,10 +15,10 @@ export const actions = [ * This is the action to print structured object to text. * * @param {object} module Data coming in from the printer - * @param {string} module.moduleName The module name (base name) of the - * file + * @param {object} module.file The file object representing the file + * being currently being processed * @param {object[]} module.moduleContent An array of objects containing - * function definitions. + * function definitions prepared by the parser. * @returns {Promise} The result of the print operations. */ async run(module) { diff --git a/package-lock.json b/package-lock.json index 39f92c7..0c14ebd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "dotenv": "^16.4.7", "error-stack-parser": "^2.1.4", "globby": "^14.0.2", + "json5": "^2.2.3", "micromatch": "^4.0.8", "node-fetch": "^3.3.2", "yaml": "^2.7.0" @@ -128,9 +129,9 @@ } }, "node_modules/@eslint/core": { - "version": "0.10.0", - "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.10.0.tgz", - "integrity": "sha512-gFHJ+xBOo4G3WRlR1e/3G8A6/KZAH6zcE/hkLRCZTi/B9avAG365QhFA8uOGzTMqgTghpn7/fSnscW++dpMSAw==", + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.11.0.tgz", + "integrity": "sha512-DWUB2pksgNEb6Bz2fggIy1wh6fGgZP4Xyy/Mt0QZPiloKKXerbqq9D3SBQTlCRYOrcRPu4vuz+CGjwdfqxnoWA==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -222,6 +223,19 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@eslint/plugin-kit/node_modules/@eslint/core": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.10.0.tgz", + "integrity": "sha512-gFHJ+xBOo4G3WRlR1e/3G8A6/KZAH6zcE/hkLRCZTi/B9avAG365QhFA8uOGzTMqgTghpn7/fSnscW++dpMSAw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@types/json-schema": "^7.0.15" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@humanfs/core": { "version": "0.19.1", "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz", @@ -409,56 +423,6 @@ "typescript": ">=4.8.4 <5.8.0" } }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/scope-manager": { - "version": "8.24.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.24.0.tgz", - "integrity": "sha512-HZIX0UByphEtdVBKaQBgTDdn9z16l4aTUz8e8zPQnyxwHBtf5vtl1L+OhH+m1FGV9DrRmoDuYKqzVrvWDcDozw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.24.0", - "@typescript-eslint/visitor-keys": "8.24.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/types": { - "version": "8.24.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.24.0.tgz", - "integrity": "sha512-VacJCBTyje7HGAw7xp11q439A+zeGG0p0/p2zsZwpnMzjPB5WteaWqt4g2iysgGFafrqvyLWqq6ZPZAOCoefCw==", - "dev": true, - "license": "MIT", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/visitor-keys": { - "version": "8.24.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.24.0.tgz", - "integrity": "sha512-kArLq83QxGLbuHrTMoOEWO+l2MwsNS2TGISEdx8xgqpkbytB07XmlQyQdNDrCc1ecSqx0cnmhGvpX+VBwqqSkg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.24.0", - "eslint-visitor-keys": "^4.2.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@typescript-eslint/parser": { "version": "8.24.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.24.0.tgz", @@ -484,7 +448,7 @@ "typescript": ">=4.8.4 <5.8.0" } }, - "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/scope-manager": { + "node_modules/@typescript-eslint/scope-manager": { "version": "8.24.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.24.0.tgz", "integrity": "sha512-HZIX0UByphEtdVBKaQBgTDdn9z16l4aTUz8e8zPQnyxwHBtf5vtl1L+OhH+m1FGV9DrRmoDuYKqzVrvWDcDozw==", @@ -502,65 +466,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/types": { - "version": "8.24.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.24.0.tgz", - "integrity": "sha512-VacJCBTyje7HGAw7xp11q439A+zeGG0p0/p2zsZwpnMzjPB5WteaWqt4g2iysgGFafrqvyLWqq6ZPZAOCoefCw==", - "dev": true, - "license": "MIT", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree": { - "version": "8.24.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.24.0.tgz", - "integrity": "sha512-ITjYcP0+8kbsvT9bysygfIfb+hBj6koDsu37JZG7xrCiy3fPJyNmfVtaGsgTUSEuTzcvME5YI5uyL5LD1EV5ZQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.24.0", - "@typescript-eslint/visitor-keys": "8.24.0", - "debug": "^4.3.4", - "fast-glob": "^3.3.2", - "is-glob": "^4.0.3", - "minimatch": "^9.0.4", - "semver": "^7.6.0", - "ts-api-utils": "^2.0.1" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "typescript": ">=4.8.4 <5.8.0" - } - }, - "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/visitor-keys": { - "version": "8.24.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.24.0.tgz", - "integrity": "sha512-kArLq83QxGLbuHrTMoOEWO+l2MwsNS2TGISEdx8xgqpkbytB07XmlQyQdNDrCc1ecSqx0cnmhGvpX+VBwqqSkg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.24.0", - "eslint-visitor-keys": "^4.2.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@typescript-eslint/type-utils": { "version": "8.24.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.24.0.tgz", @@ -585,7 +490,7 @@ "typescript": ">=4.8.4 <5.8.0" } }, - "node_modules/@typescript-eslint/type-utils/node_modules/@typescript-eslint/types": { + "node_modules/@typescript-eslint/types": { "version": "8.24.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.24.0.tgz", "integrity": "sha512-VacJCBTyje7HGAw7xp11q439A+zeGG0p0/p2zsZwpnMzjPB5WteaWqt4g2iysgGFafrqvyLWqq6ZPZAOCoefCw==", @@ -599,7 +504,7 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@typescript-eslint/type-utils/node_modules/@typescript-eslint/typescript-estree": { + "node_modules/@typescript-eslint/typescript-estree": { "version": "8.24.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.24.0.tgz", "integrity": "sha512-ITjYcP0+8kbsvT9bysygfIfb+hBj6koDsu37JZG7xrCiy3fPJyNmfVtaGsgTUSEuTzcvME5YI5uyL5LD1EV5ZQ==", @@ -626,24 +531,6 @@ "typescript": ">=4.8.4 <5.8.0" } }, - "node_modules/@typescript-eslint/type-utils/node_modules/@typescript-eslint/visitor-keys": { - "version": "8.24.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.24.0.tgz", - "integrity": "sha512-kArLq83QxGLbuHrTMoOEWO+l2MwsNS2TGISEdx8xgqpkbytB07XmlQyQdNDrCc1ecSqx0cnmhGvpX+VBwqqSkg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.24.0", - "eslint-visitor-keys": "^4.2.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@typescript-eslint/utils": { "version": "8.24.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.24.0.tgz", @@ -668,66 +555,7 @@ "typescript": ">=4.8.4 <5.8.0" } }, - "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/scope-manager": { - "version": "8.24.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.24.0.tgz", - "integrity": "sha512-HZIX0UByphEtdVBKaQBgTDdn9z16l4aTUz8e8zPQnyxwHBtf5vtl1L+OhH+m1FGV9DrRmoDuYKqzVrvWDcDozw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.24.0", - "@typescript-eslint/visitor-keys": "8.24.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/types": { - "version": "8.24.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.24.0.tgz", - "integrity": "sha512-VacJCBTyje7HGAw7xp11q439A+zeGG0p0/p2zsZwpnMzjPB5WteaWqt4g2iysgGFafrqvyLWqq6ZPZAOCoefCw==", - "dev": true, - "license": "MIT", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/typescript-estree": { - "version": "8.24.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.24.0.tgz", - "integrity": "sha512-ITjYcP0+8kbsvT9bysygfIfb+hBj6koDsu37JZG7xrCiy3fPJyNmfVtaGsgTUSEuTzcvME5YI5uyL5LD1EV5ZQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.24.0", - "@typescript-eslint/visitor-keys": "8.24.0", - "debug": "^4.3.4", - "fast-glob": "^3.3.2", - "is-glob": "^4.0.3", - "minimatch": "^9.0.4", - "semver": "^7.6.0", - "ts-api-utils": "^2.0.1" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "typescript": ">=4.8.4 <5.8.0" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/visitor-keys": { + "node_modules/@typescript-eslint/visitor-keys": { "version": "8.24.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.24.0.tgz", "integrity": "sha512-kArLq83QxGLbuHrTMoOEWO+l2MwsNS2TGISEdx8xgqpkbytB07XmlQyQdNDrCc1ecSqx0cnmhGvpX+VBwqqSkg==", @@ -1184,19 +1012,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint/node_modules/@eslint/core": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.11.0.tgz", - "integrity": "sha512-DWUB2pksgNEb6Bz2fggIy1wh6fGgZP4Xyy/Mt0QZPiloKKXerbqq9D3SBQTlCRYOrcRPu4vuz+CGjwdfqxnoWA==", - "dev": true, - "license": "Apache-2.0", - "dependencies": { - "@types/json-schema": "^7.0.15" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - } - }, "node_modules/eslint/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -1667,6 +1482,18 @@ "dev": true, "license": "MIT" }, + "node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "license": "MIT", + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", diff --git a/package.json b/package.json index cd1f750..ca2ca87 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "dotenv": "^16.4.7", "error-stack-parser": "^2.1.4", "globby": "^14.0.2", + "json5": "^2.2.3", "micromatch": "^4.0.8", "node-fetch": "^3.3.2", "yaml": "^2.7.0" @@ -49,8 +50,8 @@ "@typescript-eslint/parser": "^8.22.0", "axios": "^1.7.9", "chokidar": "^4.0.3", - "eslint-plugin-jsdoc": "^50.6.3", "eslint": "^9.18.0", + "eslint-plugin-jsdoc": "^50.6.3", "form-data": "^4.0.1" }, "keywords": [ From 459a8a77de6c4c2f27f7f343655cc3637d1799ee Mon Sep 17 00:00:00 2001 From: gesslar <1266935+gesslar@users.noreply.github.com> Date: Thu, 13 Feb 2025 00:31:16 -0500 Subject: [PATCH 2/3] fixing some issues and maybe everything is better --- ...he parser has access to BeDoc's core lo.md | 35 +++++++++++++++++++ examples/config-lpc-to-markdown.json | 9 +++-- examples/config-lpc-to-markdown.json5 | 10 ++++++ src/core/ActionManager.js | 4 +-- src/core/Configuration.js | 19 ++++++---- src/core/Discovery.js | 10 +++--- src/core/HookManager.js | 3 +- src/core/util/ActionUtil.js | 8 +++-- src/core/util/ModuleUtil.js | 5 +-- 9 files changed, 80 insertions(+), 23 deletions(-) create mode 100644 TODO/The parser has access to BeDoc's core lo.md create mode 100644 examples/config-lpc-to-markdown.json5 diff --git a/TODO/The parser has access to BeDoc's core lo.md b/TODO/The parser has access to BeDoc's core lo.md new file mode 100644 index 0000000..6ba4ac5 --- /dev/null +++ b/TODO/The parser has access to BeDoc's core lo.md @@ -0,0 +1,35 @@ +The parser has access to BeDoc's core logging utilities through `this.log`. +There are four logging functions available: + +- `this.log.debug(string[, ...arg])`: Debug messages + ```javascript + async parse(file, content) { + this.log.debug("This will only show in debug mode") + } + + // [BeDoc] Debug: This will only show in debug mode + ``` +- `this.log.info(string[, ...arg])`: Informational messages + ```javascript + async parse(file, content) { + this.log.info("A wild Happy Fun Ball has appeared.") + } + + // [BeDoc] Info: A wild Happy Fun Ball has appeared. + ``` +- `this.log.warn(string[, ...arg])`: Warning messages + ```javascript + async parse(file, content) { + this.log.warn("Do not taunt Happy Fun Ball.") + } + + // [BeDoc] Warn: Do not taunt Happy Fun Ball. + ``` +- `this.log.error(string[, ...arg])`: Error messages + ```javascript + async parse(file, content) { + this.log.error("You have been eaten by Happy Fun Ball. 🙀") + } + + // [BeDoc] Error: You have been eaten by Happy Fun Ball. 🙀 + ``` diff --git a/examples/config-lpc-to-markdown.json b/examples/config-lpc-to-markdown.json index 0c9424b..397858f 100644 --- a/examples/config-lpc-to-markdown.json +++ b/examples/config-lpc-to-markdown.json @@ -1,7 +1,10 @@ { "language": "lpc", "format": "markdown", - "output": "output/", - "input": ["wip/sample/arrays.c", "wip/sample/base64.c"], - "hooks": "wip/wikitext-hooks.js" + "output": "output/markdown", + "input": [ + "examples/source/lpc/arrays.c", + "examples/source/lpc/base64.c" + ], + "hooks": "examples/hooks/lpc-wikitext-hooks.js" } diff --git a/examples/config-lpc-to-markdown.json5 b/examples/config-lpc-to-markdown.json5 new file mode 100644 index 0000000..f04e2e1 --- /dev/null +++ b/examples/config-lpc-to-markdown.json5 @@ -0,0 +1,10 @@ +{ + "language": "lpc", + "format": "markdown", + "output": "examples/output/markdown", + "input": [ + "examples/source/lpc/arrays.c", + "examples/source/lpc/base64.c" + ], + "hooks": "examples/hooks/lpc-wikitext-hooks.js" +} diff --git a/src/core/ActionManager.js b/src/core/ActionManager.js index 4ef8e81..c3d3418 100644 --- a/src/core/ActionManager.js +++ b/src/core/ActionManager.js @@ -71,9 +71,7 @@ export default class ActionManager { if(!setup) return - await this.action.setup.call( - this.action, {parent: this, log: this.#log} - ) + await this.action.setup.call(this.action, {log: this.#log}) } async #cleanupAction() { diff --git a/src/core/Configuration.js b/src/core/Configuration.js index 51f2df3..2dfbc20 100644 --- a/src/core/Configuration.js +++ b/src/core/Configuration.js @@ -1,5 +1,6 @@ import process from "node:process" import {Environment} from "./Core.js" +import JSON5 from "json5" import { ConfigurationParameters, @@ -217,7 +218,7 @@ export default class Configuration { if(environmentVariables) allOptions.push({source: "environment", options: environmentVariables}) - const packageJson = entryOptions.packageJson + const packageJson = entryOptions?.packageJson if(packageJson?.bedoc) allOptions.push({source: "packageJson", options: packageJson.bedoc}) @@ -228,12 +229,16 @@ export default class Configuration { environmentVariables?.config if(useConfig) { - const configFilename = packageJson?.bedoc?.config || entryOptions.config - - if(!configFilename) + const configFile = + packageJson?.bedoc?.config + ? resolveFilename(packageJson?.bedoc?.config) + : entryOptions.config?.value + ? resolveFilename(entryOptions.config.value) + : null + + if(!configFile) throw new Error("No config file specified") - const configFile = resolveFilename(configFilename) const config = loadJson(configFile) allOptions.push({source: "config", options: config}) @@ -303,7 +308,7 @@ export default class Configuration { // Last, but not least, add any defaulted options that are not in the // mapped options - for(const [key, value] of Object.entries(entryOptions)) { + for(const [key, value] of Object.entries(entryOptions ?? {})) { if(!mappedOptions[key]) { if(value.source) mappedOptions[key] = value.value @@ -329,7 +334,7 @@ export default class Configuration { switch(param.type.toString()) { case "boolean": case "number": - options[key] = JSON.parse(options[key]) + options[key] = JSON5.parse(options[key]) break } } diff --git a/src/core/Discovery.js b/src/core/Discovery.js index dc2c047..d311683 100644 --- a/src/core/Discovery.js +++ b/src/core/Discovery.js @@ -50,10 +50,10 @@ export default class Discovery { debug("Mock path not set, discovering actions in node_modules", 1) debug("Looking for actions in project's package.json", 2) - if(this.core.packageJson?.bedoc?.modules) { - const actions = this.core.packageJson?.bedoc?.modules + if(this.core.packageJson?.modules) { + const actions = this.core.packageJson?.modules - debug("Found %d actions in package.json: %d", 3, actions) + debug("Found %d actions in package.json", 3, actions) debug("Actions found in package.json action in package.json: %o", 3, actions) if(actions && typeof(actions) === "object") @@ -158,7 +158,7 @@ export default class Discovery { const loadedActions = [] for(const file of toLoad) { - debug("Loading module `%s`", 2, file.absolutePath) + debug("Loading module `%s`", 2, file.absoluteUri) const loading = await this.#loadModule(file) const loaded = loading.actions.map((action, index) => { @@ -283,8 +283,10 @@ export default class Discovery { debug("No specific `%s` action found", 3, actionType) } + // Hmm! We didn't find anything specific. Let's check the criterion debug("Checking for `%s` actions with criterion `%s`", 3, actionType, criterion) + debug("Validated config to check against: %o", 3, validatedConfig) const found = actions[actionType].filter(a => { debug("Meta criterion value: %o", 4, a.action.meta[criterion]) debug("Config criterion value: %o", 4, validatedConfig[criterion]) diff --git a/src/core/HookManager.js b/src/core/HookManager.js index f4c6894..88bfb0e 100644 --- a/src/core/HookManager.js +++ b/src/core/HookManager.js @@ -90,6 +90,7 @@ export default class HookManager { return null hooksObj.log = instance.log + hooksObj.timeout = this.timeout instance.#hooks = hooksObj debug("Hooks loaded successfully for `%s`", 2, instance.action) @@ -121,7 +122,7 @@ export default class HookManager { assert(isType(hook, "function"), `Hook "${event}" is not a function`, 1) const hookExecution = await hook.call(this.hooks, args) - const hookTimeout = this.parent.timeout + const hookTimeout = this.timeout const expireAsync = () => timeoutPromise( hookTimeout, diff --git a/src/core/util/ActionUtil.js b/src/core/util/ActionUtil.js index f7cc3e0..d616ab5 100644 --- a/src/core/util/ActionUtil.js +++ b/src/core/util/ActionUtil.js @@ -1,4 +1,6 @@ import * as FDUtil from "./FDUtil.js" +import process from "node:process" +import JSON5 from "json5" const {readFile, fileExists, composeFilename} = FDUtil @@ -20,7 +22,7 @@ const actionMetaRequirements = freeze({ function loadJson(jsonFileObject) { // Read the file const jsonContent = readFile(jsonFileObject) - const json = JSON.parse(jsonContent) + const json = JSON5.parse(jsonContent) return json } @@ -31,11 +33,11 @@ function loadJson(jsonFileObject) { * @returns {object?} The parsed package.json content or null if the file does * not exist */ -function loadPackageJson(basePath = null) { +function loadPackageJson(basePath = process.cwd()) { const packageJsonFileObject = composeFilename(basePath, "./package.json") if(fileExists(packageJsonFileObject)) { const jsonContent = readFile(packageJsonFileObject) - const json = JSON.parse(jsonContent) + const json = JSON5.parse(jsonContent) return json } else return null diff --git a/src/core/util/ModuleUtil.js b/src/core/util/ModuleUtil.js index bf46e3c..fa38d43 100644 --- a/src/core/util/ModuleUtil.js +++ b/src/core/util/ModuleUtil.js @@ -1,5 +1,6 @@ import {createRequire} from "module" import FDUtil from "./FDUtil.js" +import JSON5 from "json5" export default class ModuleUtil { /** @@ -21,7 +22,7 @@ export default class ModuleUtil { static async loadJson(jsonFileObject) { // Read the file const jsonContent = await FDUtil.readFile(jsonFileObject) - const json = JSON.parse(jsonContent) + const json = JSON5.parse(jsonContent) return json } @@ -33,7 +34,7 @@ export default class ModuleUtil { static async loadPackageJson() { const packageJsonFileObject = FDUtil.resolveFilename("./package.json") const jsonContent = await FDUtil.readFile(packageJsonFileObject) - const json = JSON.parse(jsonContent) + const json = JSON5.parse(jsonContent) return json } } From 6d6ceb0a889ad287fa423407dae9f566c08f3155 Mon Sep 17 00:00:00 2001 From: gesslar <1266935+gesslar@users.noreply.github.com> Date: Thu, 13 Feb 2025 00:32:04 -0500 Subject: [PATCH 3/3] bump version to 1.6.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ca2ca87..0456813 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gesslar/bedoc", - "version": "1.5.2", + "version": "1.6.0", "description": "Pluggable documentation engine for any language and format", "publisher": "gesslar", "main": "./src/core/Core.js",