Skip to content

Commit

Permalink
Fix exports (#103)
Browse files Browse the repository at this point in the history
* remove index.js

* mv /lib/schedulePlugin.js as index.js

* fix export

* add use strict

* modify linting

* add fastifySchedulePlugin as named export
  • Loading branch information
Uzlopak authored Oct 6, 2022
1 parent 9181c05 commit 8672fb9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
37 changes: 25 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
23 changes: 0 additions & 23 deletions lib/schedulePlugin.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8672fb9

Please sign in to comment.