Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support modules to extend nitro builder #1789

Merged
merged 24 commits into from
Oct 28, 2023
Merged

feat: support modules to extend nitro builder #1789

merged 24 commits into from
Oct 28, 2023

Conversation

Barbapapazes
Copy link
Member

@Barbapapazes Barbapapazes commented Oct 5, 2023

πŸ”— Linked issue

fix #1788

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR introduce the concept of modules like in Nuxt.

  • Support for function in the nitro.config file
  • Support for function in the modules directory

This PR is a first implementation. depending of the usage, we will update the modules feature.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@Barbapapazes Barbapapazes marked this pull request as draft October 5, 2023 14:35
playground/nitro.config.ts Outdated Show resolved Hide resolved
src/module/define.ts Outdated Show resolved Hide resolved
src/module/define.ts Outdated Show resolved Hide resolved
src/module/define.ts Outdated Show resolved Hide resolved
src/module/install.ts Outdated Show resolved Hide resolved
src/context.ts Outdated Show resolved Hide resolved
@pi0
Copy link
Member

pi0 commented Oct 5, 2023

Thanks for picking up on it and nice you could take inspiration from the Nuxt module.

If you would like to work on your PR to be landed, i have added few comments to minify changes. Many of APIs and consideration in Nuxt happened over time and some based on legacy requirements we don't need to Nitro...

@Barbapapazes
Copy link
Member Author

Thanks for picking up on it and nice you could take inspiration from the Nuxt module.

If you would like to work on your PR to be landed, i have added few comments to minify changes. Many of APIs and consideration in Nuxt happened over time and some based on legacy requirements we don't need to Nitro...

Thanks! πŸͺ„

I update this PR a little and allow modules to be specify in a modules folder. Before continuing, I would like to know if I should specify how end-user will write a module. In Nuxt, there is the object meta and the nuxt-module-builder. Should we have the same thing? How could we improve the module implementation to have a better usage?

@pi0
Copy link
Member

pi0 commented Oct 5, 2023

I expect as simple as this:

import type { NitroModule } from 'nitropack'
export default <NitroModule>{ async setup(nitro) {} }

Let's not keep ahead of ourselves. This feature is initially intended for advanced use cases not user-facing as Nuxt modules are until we can figure out use-cases :)

@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

Merging #1789 (b183043) into main (6c1570d) will decrease coverage by 0.11%.
The diff coverage is 47.43%.

@@            Coverage Diff             @@
##             main    #1789      +/-   ##
==========================================
- Coverage   52.38%   52.28%   -0.11%     
==========================================
  Files         170      172       +2     
  Lines       11806    11882      +76     
  Branches      910      908       -2     
==========================================
+ Hits         6185     6212      +27     
- Misses       5525     5573      +48     
- Partials       96       97       +1     
Files Coverage Ξ”
src/build.ts 83.80% <100.00%> (+0.02%) ⬆️
src/scan.ts 100.00% <100.00%> (ΓΈ)
src/types/index.ts 100.00% <100.00%> (ΓΈ)
src/types/module.ts 100.00% <100.00%> (ΓΈ)
src/types/nitro.ts 100.00% <100.00%> (ΓΈ)
src/nitro.ts 82.48% <60.00%> (-4.08%) ⬇️
src/module.ts 17.50% <17.50%> (ΓΈ)

... and 2 files with indirect coverage changes

@Barbapapazes
Copy link
Member Author

I expect as simple as this:

import type { NitroModule } from 'nitropack'
export default <NitroModule>{ async setup(nitro) {} }

Let's not keep ahead of ourselves. This feature is initially intended for advanced use cases not user-facing as Nuxt modules are until we can figure out use-cases :)

So I think this PR is ready for a review!

@Barbapapazes Barbapapazes marked this pull request as ready for review October 5, 2023 21:24
src/build.ts Show resolved Hide resolved
playground/nitro.config.ts Outdated Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
src/module.ts Outdated Show resolved Hide resolved
@pi0 pi0 changed the title feat: add modules support feat: support nitro modules Oct 28, 2023
@pi0 pi0 changed the title feat: support nitro modules feat: support modules to extend nitro builder Oct 28, 2023
@pi0 pi0 merged commit 923b6cd into main Oct 28, 2023
8 of 9 checks passed
@pi0 pi0 deleted the feat/modules branch October 28, 2023 13:40
@pi0 pi0 mentioned this pull request Oct 28, 2023
@pi0 pi0 mentioned this pull request Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nitro modules to extend core
2 participants