From 8672fb99a16d31f39c870b07e078d0891a1f2302 Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Thu, 6 Oct 2022 18:46:22 +0200 Subject: [PATCH] Fix exports (#103) * remove index.js * mv /lib/schedulePlugin.js as index.js * fix export * add use strict * modify linting * add fastifySchedulePlugin as named export --- index.js | 37 +++++++++++++++++++++++++------------ lib/schedulePlugin.js | 23 ----------------------- package.json | 2 +- 3 files changed, 26 insertions(+), 36 deletions(-) delete mode 100644 lib/schedulePlugin.js diff --git a/index.js b/index.js index 9c6b458..63af0e4 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,28 @@ -const { fastifySchedulePlugin } = require("./lib/schedulePlugin"); +"use strict"; + +const { ToadScheduler } = require("toad-scheduler"); +const fp = require("fastify-plugin"); + +function plugin(fastify, opts, next) { + const scheduler = new ToadScheduler(); + fastify.decorate("scheduler", scheduler); + + fastify.addHook("onClose", (fastify, done) => { + scheduler.stop(); + done(); + }); + + next(); +} + +const fastifySchedulePlugin = fp(plugin, { + fastify: "4.x", + name: "@fastify/schedule", +}); + +module.exports = fastifySchedulePlugin; /** - * These export configurations enable JS and TS developers - * to consume fastify-schedule in whatever way best suits their needs. - * Some examples of supported import syntax includes: - * - `const fastifySchedulePlugin = require('fastify-schedule')` - * - `const { fastifySchedulePlugin } = require('fastify-schedule')` - * - `import * as fastifySchedulePlugin from 'fastify-schedule'` - * - `import { fastifySchedulePlugin } from 'fastify-schedule'` - * - `import fastifySchedulePlugin from 'fastify-schedule'` + * TODO: Should be removed in the next major release */ -fastifySchedulePlugin.fastifySchedulePlugin = fastifySchedulePlugin; -fastifySchedulePlugin.default = fastifySchedulePlugin; -module.exports = fastifySchedulePlugin; +module.exports.fastifySchedulePlugin = fastifySchedulePlugin; diff --git a/lib/schedulePlugin.js b/lib/schedulePlugin.js deleted file mode 100644 index 3c6559f..0000000 --- a/lib/schedulePlugin.js +++ /dev/null @@ -1,23 +0,0 @@ -const { ToadScheduler } = require("toad-scheduler"); -const fp = require("fastify-plugin"); - -function plugin(fastify, opts, next) { - const scheduler = new ToadScheduler(); - fastify.decorate("scheduler", scheduler); - - fastify.addHook("onClose", (fastify, done) => { - scheduler.stop(); - done(); - }); - - next(); -} - -const fastifySchedulePlugin = fp(plugin, { - fastify: "4.x", - name: "@fastify/schedule", -}); - -module.exports = { - fastifySchedulePlugin, -}; diff --git a/package.json b/package.json index b2142e1..d794b25 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "test": "npm run test:unit && npm run test:typescript", "test:unit": "tap", "test:typescript": "tsd", - "lint": "eslint \"lib/**/*.js\" \"test/**/*.js\" index.js", + "lint": "eslint \"test/**/*.js\" index.js", "lint:everything": "npm run lint && npm run test:typescript", "prettier": "prettier --write \"{lib,test}/**/*.js\" index.js index.d.ts", "postinstall": "husky install",