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: run framework detection and run plugins on netlify build #5029

Merged
merged 14 commits into from
Sep 8, 2022

Conversation

sarahetter
Copy link
Contributor

@sarahetter sarahetter commented Sep 6, 2022

🎉 Thanks for submitting a pull request! 🎉

Summary

Fixes #4948

This allows users to run netlify build and netlify deploy --build, and have framework detection run, enabling build plugins (and the next runtime) to install and run automatically, without requiring a user to run netlify link. Running these automatically simplifies the flow for the user, requiring less config, and duplicating recent similar work for netlify dev.

New flow/scenarios:

  1. User runs ntl build on a Next.js app with no extra config/netlify.toml/local plugin installed. They are no longer prompted to run ntl link. Framework detection runs, and passes the build directory, build command, and plugins specified by framework-info to the runBuild function. The newest plugin is installed and run.
  2. User runs ntl build on a Next.js app with a netlify.toml / package.json local plugin installed, with an older version of the plugin specified. They are no longer prompted to run ntl link. Framework detection still runs, but the user's local config overrides the version, and the local older version of the plugin is run.
  3. User runs ntl deploy --build on a Next.js app. This is as above in # 1, however as this is a deploy, they will still be prompted to link / create a new site. Framework detection is run, and the newest plugin is installed and run.
  4. User runs ntl build on a static, vanilla javascript website. Framework detection runs, finds no matching framework, and builds as normal.

For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)
images

@github-actions
Copy link

github-actions bot commented Sep 6, 2022

📊 Benchmark results

Comparing with 6593bc7

Package size: 222 MB

(no change)

^  222 MB  222 MB  222 MB  222 MB  222 MB 
│   ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-4     T-3     T-2     T-1      T    
Legend

Copy link
Contributor

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

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

Awesome! I've added a few questions. Could you change the PR name to follow conventional commits? Also a bit more detail in the PR description shopwing step by step exactly what happens. e.g. user runs ntl build, if the site exists but has no plugins then x, or if it does have plugins, or if the site doesn't exist then y and so on. I mean it's pretty clear but I know with the dev command, there were quite a few nuances that needed covering.

@sarahetter sarahetter changed the title Plugins build feat: run framework detection and run plugins on netlify build Sep 7, 2022
@github-actions github-actions bot added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Sep 7, 2022
@sarahetter
Copy link
Contributor Author

@ascorbic I've updated the description to be more clear about the flow, and made the rest of the recommended changes.

const defaultConfig = { build: {} }

if (settings.buildCommand) {
buildOptions.cachedConfig.config.build.command = settings.buildCommand
Copy link
Member

Choose a reason for hiding this comment

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

This is the sort of question that is tricky to answer without types in place, but is there a chance that some of these intermediate properties will be undefined, leaving to a reference error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eduardoboucas

Did some chasing here, and found that cachedConfig is created by @netlify/config - and cachedconfig.config.build is always added. https://github.com/netlify/build/blob/d2c74c02280bd2324cb9b933df4be9ba8c399789/packages/config/src/base.js#L32

I'm not sure what I should do to safeguard against that situation popping up if there's a breaking change in @netlify/config though. The node version doesn't support optional chaining, and I don't want to do 4 different hasOwnPropertys :/

But wow, wouldn't this all be so much nicer with Typescript 😅

ericapisani
ericapisani previously approved these changes Sep 8, 2022
Copy link
Contributor

@ericapisani ericapisani left a comment

Choose a reason for hiding this comment

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

One small nit, but this is otherwise looking great! Excited to see this ship 🚀

ericapisani
ericapisani previously approved these changes Sep 8, 2022
@sarahetter sarahetter added the automerge Add to Kodiak auto merge queue label Sep 8, 2022
@kodiakhq kodiakhq bot merged commit c85efc4 into main Sep 8, 2022
@kodiakhq kodiakhq bot deleted the plugins-build branch September 8, 2022 17:42
khendrikse pushed a commit that referenced this pull request Sep 9, 2022
* feat: getting the plugin when running build. doesn't run on deploy --build. next plugin also fails

* feat: running plugin through both deploy --build and build, plugin fails

* feat: adding some buildCommand plumbing

* chore: changes

* chore: removing unused import and console logs

* feat: remove check for site id when running build

* chore: cleanup

* feat: make dist available at all stages

* test: add tests

* fix: review cleanup

* fix: switch from exit to error

* chore: changing variable name for clarity

* fix: only change config values when both command and directory are found

Co-authored-by: Daniel Tschinder <231804+danez@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
@bronze
Copy link

bronze commented Sep 22, 2022

hi @sarahetter
at https://github.com/netlify/cli/blob/main/src/lib/build.js#L83 we have buildOptions.cachedConfig.config.build.publish = settings.buildCommand. should it be settings.dist?

   if (settings.buildCommand && settings.dist) {
      buildOptions.cachedConfig.config.build.command = settings.buildCommand
      defaultConfig.build.command = settings.buildCommand
      //buildOptions.cachedConfig.config.build.publish = settings.buildCommand
      buildOptions.cachedConfig.config.build.publish = settings.dist
      defaultConfig.build.publish = settings.dist
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Add to Kodiak auto merge queue type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improved automatic framework support in ntl build
6 participants