fastify / fastify-cli

Run a Fastify application with one command!
MIT License
657 stars 163 forks source link

Generate plugin nitpicks to work out of the box #690

Closed valerio-pizzichini closed 9 months ago

valerio-pizzichini commented 9 months ago

Prerequisites

Fastify version

4.x.x

Plugin version

No response

Node.js version

20.10.x

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

14.2.1

Description

I tried to generate a fastify plugin use the CLI but encountered few small issues. The goal is to provide a list of problems and quick solutions to make it work smoothly.

Steps to Reproduce

Generate a new plugin using the following steps

npm install --global fastify-cli
mkdir fastify-plugin-example && cd fastify-plugin-example
fastify generate-plugin .

1. Missing tap module

Run unit tests, failing for missing tap module

npm run unit

Screenshot 2024-01-02 at 12 04 22

Proposed solution: Install tap

2. Tap 18.x not working with current .taprc

// Using tap 18+
npm install tap
npm run unit

Screenshot 2024-01-02 at 13 26 14

Proposed solution: Either downgrade to tap@16 or update .taprc to the breaking changes added in tap@18

3. fastify-tsconfig throw error

Extending the fastify-tsconfig inside the tsconfig.json makes the project throw.

npm run unit

Screenshot 2024-01-02 at 14 26 10

Proposed solution: remove extends: 'fastify-tsconfig' inside tsconfig.json

4. Missing fastify and fastify-plugin dependencies

npm run unit

Screenshot 2024-01-02 at 14 29 05

Proposed solution: add both dependencies to package.json while generating the project

5. plugin is async while placeholder test is not waiting the registration

This could mislead the user making tests to randomly failing if the registration does not complete before the app readiness.

Proposed solution: just add await app.register(require('..')) to example test

Expected Behavior

To me, the example plugin should pass the tests smoothly to provide a good user experience.