fastify-check-runtime-env
Advanced tools
Comparing version 0.1.0 to 0.2.0
# Change Log | ||
## [0.2.0](https://github.com/smartiniOnGitHub/fastify-check-runtime-env/releases/tag/0.2.0) (2022-03-27) | ||
Summary Changelog: | ||
- Update dependencies, but keep compatibility with Fastify 2.x (and Node.js 8 LTS) | ||
- Use 'check-runtime-env' latest release ('~0.3.0') with new features | ||
- Use Node.js assertions but in strict mode now | ||
- Ensure all works again | ||
- Feature: add new plugin option 'nodeStrictCheckAtStartup' | ||
to check if JavaScript is in strict mode (by default true) | ||
otherwise an exception will be raised at plugin startup | ||
(safer option, to be sure to use modern code/settings) | ||
- Breaking Change: rename plugin option 'onNodeVersionMismatch' | ||
into 'onCheckMismatch'; now this setting defines the behavior for checker | ||
failures on 'nodeStrictCheckAtStartup' and 'nodeVersionCheckAtStartup' options | ||
- Note: this is last release for Fastify 2.x | ||
## [0.1.0](https://github.com/smartiniOnGitHub/fastify-check-runtime-env/releases/tag/0.1.0) (2019-06-06) | ||
@@ -4,0 +19,0 @@ Summary Changelog: |
/* | ||
* Copyright 2019 the original author or authors. | ||
* Copyright 2019-2022 the original author or authors. | ||
* | ||
@@ -33,8 +33,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
fastify.register(require('../src/plugin'), { | ||
// nodeStrictCheckAtStartup: true, // same as default | ||
nodeVersionCheckAtStartup: true, | ||
// nodeVersionExpected: engines.node | ||
nodeVersionExpected: '>=16.0.0', // sample failing test | ||
// onNodeVersionMismatch: 'warning' // log a warning | ||
// onNodeVersionMismatch: 'exception' // throw an exception // same as default | ||
onNodeVersionMismatch: 'exit' // exit the process | ||
nodeVersionExpected: '<=8.17.0 >=200.0.0', // sample failing test | ||
// onCheckMismatch: 'warning' // log a warning | ||
// onCheckMismatch: 'exception' // throw an exception // same as default | ||
onCheckMismatch: 'exit' // exit the process | ||
}) | ||
@@ -57,4 +58,8 @@ | ||
fastify.ready(() => { | ||
// sample checker usage | ||
const CRE = fastify.CheckRuntimeEnv | ||
CRE.checkBoolean(true, 'sample checker usage') | ||
const routes = fastify.printRoutes() | ||
console.log(`Available Routes:\n${routes}`) | ||
}) |
/* | ||
* Copyright 2019 the original author or authors. | ||
* Copyright 2019-2022 the original author or authors. | ||
* | ||
@@ -30,5 +30,6 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
fastify.register(require('../src/plugin'), { | ||
// nodeStrictCheckAtStartup: true, // same as default | ||
nodeVersionCheckAtStartup: true, | ||
nodeVersionExpected: engines.node | ||
// onNodeVersionMismatch: 'exception' // throw an exception // same as default | ||
// onCheckMismatch: 'exception' // throw an exception // same as default | ||
}) | ||
@@ -51,4 +52,8 @@ | ||
fastify.ready(() => { | ||
// sample checker usage | ||
const CRE = fastify.CheckRuntimeEnv | ||
CRE.checkBoolean(true, 'sample checker usage') | ||
const routes = fastify.printRoutes() | ||
console.log(`Available Routes:\n${routes}`) | ||
}) |
{ | ||
"name": "fastify-check-runtime-env", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Fastify Plugin to check runtime environment properties", | ||
"main": "src/plugin", | ||
"scripts": { | ||
"clean:install": "rm -rf ./package-lock.json ./node_modules/", | ||
"dependency:log": "npm list > ./temp/dependencies.log", | ||
"docs:clean": "rm -rf ./docs/*", | ||
"docs:generate": "npx jsdoc -c .jsdoc.json -R README.md", | ||
"docs": "npm run docs:clean && npm run docs:generate", | ||
"example-failure": "node example/example-failure", | ||
"example:debug": "node --inspect-brk example/example", | ||
"example": "node example/example", | ||
"example-failure": "node example/example-failure", | ||
"lint": "standard \"./*.js\" \"./src/**/*.js\" \"./test/**/*.test.js\" \"./example/**/*.js\"", | ||
"test:unit": "tap -J --comments --strict --no-esm test/*.test.js", | ||
"test:unit:debug": "tap -T --node-arg=--inspect-brk --comments --strict --no-esm test/*.test.js", | ||
"lint:fix": "standard --fix", | ||
"lint:log": "npm run lint > ./temp/lint-standard.log", | ||
"lint:standard": "standard --verbose", | ||
"lint": "npm run lint:standard", | ||
"test:clean": "rm -rf .nyc_output/* ./coverage/*", | ||
"test:coverage": "npm run test:unit -- --cov --coverage-report=html", | ||
"test:unit:debug": "tap -T --node-arg=--inspect-brk test/*.test.js", | ||
"test:unit:dev": "tap -J --watch test/*.test.js", | ||
"test:unit": "tap -J test/*.test.js", | ||
"test": "npm run lint && npm run test:unit" | ||
}, | ||
"dependencies": { | ||
"fastify-plugin": "^1.6.0", | ||
"check-runtime-env": "~0.2.0" | ||
"fastify-plugin": "^1.6.1", | ||
"check-runtime-env": "~0.3.0" | ||
}, | ||
"devDependencies": { | ||
"fastify": "^2.1.0", | ||
"standard": "^12.0.1", | ||
"tap": "^14.2.1" | ||
"jsdoc": "^3.6.10", | ||
"fastify": "^2.15.3", | ||
"standard": "^16.0.4", | ||
"tap": "^15.2.3" | ||
}, | ||
"peerDependencies": {}, | ||
"engines": { | ||
"node": ">=8.9.0" | ||
"node": ">=8.17.0" | ||
}, | ||
@@ -29,0 +40,0 @@ "homepage": "https://github.com/smartiniOnGitHub/fastify-check-runtime-env#readme", |
@@ -33,6 +33,7 @@ # fastify-check-runtime-env | ||
fastify.register(require('fastify-check-runtime-env'), { | ||
// nodeStrictCheckAtStartup: true, // same as default | ||
nodeVersionCheckAtStartup: true, | ||
nodeVersionExpected: engines.node | ||
// nodeVersionExpected: '>=16.0.0', // sample failing test | ||
// onNodeVersionMismatch: 'exception' // throw an exception // same as default | ||
// nodeVersionExpected: '<=8.17.0 >=200.0.0', // sample failing test | ||
// onCheckMismatch: 'exception' // throw an exception // same as default | ||
}) | ||
@@ -50,16 +51,24 @@ | ||
Fastify ^2.1.0 , Node.js 8 LTS (8.9.x) or later. | ||
Fastify ^2.12.0 , Node.js 8 LTS (8.9.x) or later. | ||
Note that plugin releases 0.x are for Fastify 2.x, 3.x are for Fastify 3.x, etc. | ||
## Note | ||
The plugin decorate Fastify and expose some functions: | ||
- `CheckRuntimeEnv`, the checkers implementation, as a class (RuntimeEnvChecker) | ||
- `CheckRuntimeEnv`, the checkers implementation, as a class (RuntimeEnvChecker); | ||
but note that to use it you need to wait for this plugin to be | ||
fully loaded and initialized | ||
Plugin options are: | ||
- `onNodeVersionMismatch`, define what to do if Node.js version | ||
does not match with the expected one; by default 'exception' to raise an Error, | ||
- `onCheckMismatch`, define what to do if a checker fails (Node.js version | ||
does not match with the expected one, JavaScript not in strict mode, etc); | ||
by default 'exception' to raise an Error, | ||
but could be 'warning' (to log a message in Fastify logs), | ||
or 'exit' (to stop current Node.js process) with exit code 1 | ||
- `nodeVersionCheckAtStartup` flag to tell (when true) to check Node.js version | ||
- `nodeStrictCheckAtStartup`, flag to tell (when true) to check JavaScript | ||
strict mode; by default true (safer and already enforced as default mode | ||
in modern JavaScript code using classes, ES Modules, etc) | ||
- `nodeVersionCheckAtStartup`, flag to tell (when true) to check Node.js version | ||
at application startup; by default false | ||
@@ -66,0 +75,0 @@ - 'nodeVersion' the current Node.js version (by default 'process.version') |
/* | ||
* Copyright 2019 the original author or authors. | ||
* Copyright 2019-2022 the original author or authors. | ||
* | ||
@@ -23,3 +23,4 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
const { | ||
onNodeVersionMismatch = 'exception', | ||
onCheckMismatch = 'exception', | ||
nodeStrictCheckAtStartup = true, | ||
nodeVersionCheckAtStartup = false, | ||
@@ -29,6 +30,7 @@ nodeVersion = process.version, | ||
} = options | ||
ensureIsString(onNodeVersionMismatch, 'onNodeVersionMismatch') | ||
ensureIsString(onCheckMismatch, 'onCheckMismatch') | ||
ensureIsBoolean(nodeStrictCheckAtStartup, 'nodeStrictCheckAtStartup') | ||
ensureIsBoolean(nodeVersionCheckAtStartup, 'nodeVersionCheckAtStartup') | ||
ensureIsString(nodeVersion, 'nodeVersion') | ||
// ensureIsString(nodeVersionExpected, 'nodeVersionExpected') | ||
ensureIsString(nodeVersionExpected, 'nodeVersionExpected') | ||
@@ -39,2 +41,12 @@ // execute plugin code | ||
let err = null | ||
if (nodeStrictCheckAtStartup === true) { | ||
try { | ||
CRE.checkStrictMode() | ||
// CRE.checkBoolean(false) // test | ||
} catch (e) { | ||
err = handleMismatch(e, fastify, onCheckMismatch) | ||
} | ||
} | ||
if (nodeVersionCheckAtStartup === true) { | ||
@@ -44,17 +56,3 @@ try { | ||
} catch (e) { | ||
// console.log(e) | ||
switch (onNodeVersionMismatch) { | ||
case 'warning': | ||
fastify.log.warn(e) | ||
break | ||
case 'exception': | ||
err = e // set the exception for the callback only here | ||
break | ||
case 'exit': | ||
fastify.log.fatal(e) | ||
process.exit(1) | ||
// break // unreachable | ||
default: | ||
throw new Error(`Illegal value for serverUrlMode: '${onNodeVersionMismatch}'`) | ||
} | ||
err = handleMismatch(e, fastify, onCheckMismatch) | ||
} | ||
@@ -78,5 +76,23 @@ } | ||
function handleMismatch (e, fastify, mismatchMode) { | ||
// console.log(e) | ||
switch (mismatchMode) { | ||
case 'warning': | ||
fastify.log.warn(e) | ||
break | ||
case 'exception': | ||
return e // set the exception for the callback only here | ||
// break // unreachable | ||
case 'exit': | ||
fastify.log.fatal(e) | ||
process.exit(1) | ||
// break // unreachable | ||
default: | ||
throw new Error(`Illegal value for onCheckMismatch: '${mismatchMode}'`) | ||
} | ||
} | ||
module.exports = fp(fastifyCheckRuntimeEnv, { | ||
fastify: '^2.1.0', | ||
fastify: '^2.12.0', | ||
name: 'fastify-check-runtime-env' | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25709
186
84
4
+ Addedcheck-runtime-env@0.3.0(transitive)
+ Addedsemver@7.6.3(transitive)
- Removedcheck-runtime-env@0.2.0(transitive)
Updatedcheck-runtime-env@~0.3.0
Updatedfastify-plugin@^1.6.1