Skip to content

feat: enable API, SSR and DSG functions individually as required #375

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

Merged
merged 9 commits into from
May 18, 2022

Conversation

orinokai
Copy link
Contributor

@orinokai orinokai commented May 13, 2022

Summary

This PR switches shouldSkipFunctions() for getNeededFunctions() which checks the skip file generated by gatsby-plugin-netlify and returns an array of the required functions, rather than a boolean.

This array is then used throughout the remaining function setup code to enable each function individually.

Backward compatibility is maintained by disabling all functions if an empty skip file is provided and enabling all functions if no skip file exists.

The current env var NETLIFY_SKIP_GATSBY_FUNCTIONS still disables all functions as before, but 3 additional env vars have been added to control each function individually:

NETLIFY_SKIP_API_FUNCTION
NETLIFY_SKIP_SSR_FUNCTION
NETLIFY_SKIP_DSG_FUNCTION

Test plan

  • A site with no functions requirements should not generate any functions
  • A site with API, SSR and DSG requirements should generate all 3 functions
  • A site with API, SSR and DSG requirements, with NETLIFY_SKIP_GATSBY_FUNCTIONS = true, should not generate any functions
  • A site with only Gatsby Functions should generate the API function, but not the SSR or DSG functions

Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal

Fixes #374

The additional functionality in this PR is only possible when paired with this PR in the gatsby-plugin-repo, but the plugin still works as before without it.

possum

Standard checks:

  • Check the Deploy Preview's Demo site for your PR's functionality
  • Add docs when necessary

🧪 Once merged, make sure to update the version if needed and that it was
published correctly.

@netlify
Copy link

netlify bot commented May 13, 2022

Deploy Preview for netlify-plugin-gatsby-demo ready!

Name Link
🔨 Latest commit 6d69ae0
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-gatsby-demo/deploys/6284c1eeb951440008e07d25
😎 Deploy Preview https://deploy-preview-375--netlify-plugin-gatsby-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@orinokai orinokai self-assigned this May 13, 2022
@orinokai orinokai marked this pull request as ready for review May 18, 2022 08:40
@orinokai orinokai requested review from a team and ascorbic May 18, 2022 08:40
ascorbic
ascorbic previously approved these changes May 18, 2022
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.

Great stuff! Just one small comment

// eslint-disable-next-line complexity
function overrideNeededFunctions(neededFunctions) {
const skipAll =
process.env.NETLIFY_SKIP_GATSBY_FUNCTIONS === 'true' ||
Copy link
Contributor

Choose a reason for hiding this comment

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

[sand] I wonder if these repeated checks could be abstracted into a helper that checks for true or 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Have updated. Reads cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow API, SSR and DSG functions to be disabled individually
2 participants