fastify-plugin
Advanced tools
Comparing version 0.1.0 to 0.1.1
11
index.js
'use strict' | ||
const semver = require('semver') | ||
const console = require('console') | ||
@@ -15,4 +16,10 @@ function plugin (fn, version) { | ||
const fastifyVersion = require('fastify/package.json').version | ||
if (!semver.satisfies(fastifyVersion, version)) { | ||
var fastifyVersion | ||
try { | ||
fastifyVersion = require('fastify/package.json').version | ||
} catch (_) { | ||
console.info('fastify not found, proceeding anyway') | ||
} | ||
if (fastifyVersion && !semver.satisfies(fastifyVersion, version)) { | ||
throw new Error(`fastify-plugin - expected '${version}' fastify version, '${fastifyVersion}' is installed`) | ||
@@ -19,0 +26,0 @@ } |
{ | ||
"name": "fastify-plugin", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Plugin helper for Fastify", | ||
@@ -25,4 +25,5 @@ "main": "index.js", | ||
"devDependencies": { | ||
"fastify": "^0.12.0", | ||
"standard": "^9.0.2", | ||
"fastify": "^0.18.0", | ||
"proxyquire": "^1.8.0", | ||
"standard": "^10.0.0", | ||
"tap": "^10.3.0" | ||
@@ -29,0 +30,0 @@ }, |
# fastify-plugin | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) | ||
@@ -6,3 +7,3 @@ [![Build Status](https://travis-ci.org/fastify/fastify-plugin.svg?branch=master)](https://travis-ci.org/fastify/fastify-plugin) | ||
`fastify-plugin` is a plugin helper for [Fastify](https://github.com/fastify/fastify). | ||
When you build plugins for Fastify and you want that them to be accessible in the same contewxt where you require them, you have two ways: | ||
When you build plugins for Fastify and you want that them to be accessible in the same context where you require them, you have two ways: | ||
1. Use the `skip-override` hidden property | ||
@@ -9,0 +10,0 @@ 2. Use this module |
20
test.js
'use strict' | ||
const t = require('tap') | ||
const proxyquire = require('proxyquire') | ||
const test = t.test | ||
@@ -75,1 +76,20 @@ const fp = require('./') | ||
}) | ||
test('should not throw if fastify is not found', t => { | ||
t.plan(1) | ||
const fp = proxyquire('./index.js', { | ||
'fastify/package.json': null, | ||
console: { | ||
info: function (msg) { | ||
t.is(msg, 'fastify not found, proceeding anyway') | ||
} | ||
} | ||
}) | ||
function plugin (fastify, opts, next) { | ||
next() | ||
} | ||
fp(plugin, '>= 0') | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
6908
100
47
4
1