Skip to content

Chore: refactor fastify.js#1506

Merged
delvedor merged 5 commits intomasterfrom
refactor-project-structure
Mar 11, 2019
Merged

Chore: refactor fastify.js#1506
delvedor merged 5 commits intomasterfrom
refactor-project-structure

Conversation

@delvedor
Copy link
Copy Markdown
Member

@delvedor delvedor commented Mar 5, 2019

Hello team!

As all of you know, our entry point is a mess! 😱
We worked really hard during the past year on adding new features and applied bugfixes, and we leave this file organization out in the cold.
This pr aims to start cleaning up this file. I can't do everything in this pr since it will be a massive change, furthermore, some work will be done in conjunction with #1503.

As you can see a test is failing, not sure how to fix it.

Related: #1475

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

@delvedor delvedor added the internals Change that won't impact the surface API. label Mar 5, 2019
@delvedor delvedor requested a review from a team March 5, 2019 17:40
Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked if benchmarks are staying the same?

Comment thread test/internals/logger.test.js
@mcollina
Copy link
Copy Markdown
Member

mcollina commented Mar 5, 2019

I would also seek to refactor out the 404 handling, override and route definition, if possible.

@delvedor
Copy link
Copy Markdown
Member Author

delvedor commented Mar 9, 2019

I would also seek to refactor out the 404 handling, override and route definition, if possible.

I agree, but I think we should split this work in multiple pull requests, otherwise, we will end up to break any other ongoing contribution.

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@delvedor delvedor added the v2.x Issue or pr related to Fastify v2 label Mar 9, 2019
Comment thread lib/contentTypeParser.js

module.exports = ContentTypeParser
module.exports.buildContentTypeParser = buildContentTypeParser
module.exports.helpers = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these helper functions exposed to the public API or just meant to be used internally? If they are going to be used externally I'd request we add some types; if not, no types are needed

Copy link
Copy Markdown
Member Author

@delvedor delvedor Mar 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The public API is the big fastify object you can see in the main file :)

Copy link
Copy Markdown
Member Author

@delvedor delvedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fastify/fastify please take a look :)
As said above I think we should refactor this file in multiple pull request, to avoid a complex review and destroy other people pull request with massive rebases.

The main focus of this pr was to create a fastify object that represents our public API and start reordering the internal functions.

ps: I would also recommend to see the resulting work in the working branch, since the diff is quite messy 😄

@delvedor delvedor requested a review from a team March 10, 2019 14:54
Comment thread lib/logger.js
} else if (!options.logger) {
const logger = Object.create(abstractLogging)
logger.child = () => logger
return [logger, false]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an object instead of an array would make this code easier to understand. With the array, it's not clear what false means here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback, but for now I'll leave it as is. By reading the code is easy to understand what that boolean is, and if this becomes a problem in the future I'll add some more doc.
Furthermore this syntax is becoming commonly used in JavaScript, so let's start embracing it :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @nwoltman. Just reading this function, I can't begin to tell you how this result will be used. Going over to fastify.js I can see that it is meant to be {logger, hasLogger}. I think this function should return {logger, hasLogger: false}.

See https://docs.google.com/document/d/1hWb-lQW4NSG9yRpyyiAA_9Ktytd5lypLnVLhPX9vamE/edit for information on array destructuring. I'm not opposed to array destructuring because of the doc, but it's something to keep in mind. I am simply opposed here due to legibility.

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@delvedor delvedor merged commit 7eaaabc into master Mar 11, 2019
@delvedor delvedor deleted the refactor-project-structure branch March 11, 2019 18:38
@delvedor delvedor mentioned this pull request Mar 12, 2019
4 tasks
@github-actions
Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

internals Change that won't impact the surface API. v2.x Issue or pr related to Fastify v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants