Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

feat: add support for feature flags #567

Merged
merged 2 commits into from
Jul 5, 2021
Merged

Conversation

eduardoboucas
Copy link
Member

- Summary

Unlike Netlify Build, zip-it-and-ship-it doesn't have an official feature flag mechanism. We've been using the functions configuration object to that effect, but that falls short in some situations.

For example, the config is only evaluated when a function is being processed, but we might want to have a feature flag that determines whether a function is even created or not, meaning the feature flag needs to come earlier in the process.

This PR adds a featureFlags property that is passed to both zipFunction and zipFunctions and subsequently supplied to getFunctionsFromPaths.

- Test plan

New tests added.

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

main_xkdhX3G

@eduardoboucas eduardoboucas added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Jul 4, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2021

⏱ Benchmark results

Comparing with d5392a0

largeDepsEsbuild: 10.6s

⬇️ 18.96% decrease vs. d5392a0

^                                                                                           13s           
│          12.4s   12.4s                           12.5s                                    ┌──┐          
│           ┌──┐    ┌──┐                            ┌──┐            12s            11.7s    |  |          
│ ─10.8s────┼──┼────┼──┼───────────────────10.9s────┼──┼────────────┌──┐────────────┌──┐────┼──┼──────────
│   ┌──┐    |  |    |  |   10.5s   10.7s    ┌──┐    |  |   10.6s    |  |   10.3s    |  |    |  |   10.6s  
│   |  |    |  |    |  |    ┌──┐    ┌──┐    |  |    |  |    ┌──┐    |  |    ┌──┐    |  |    |  |    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

largeDepsZisi: 55.3s

⬇️ 18.06% decrease vs. d5392a0

^                                                                                         1m 9.5s         
│         1m 4.8s 1m 4.7s                                                                   ┌──┐          
│           ┌──┐    ┌──┐                          1m 3.1s         1m 3.9s                   |  |          
│           |  |    |  |                            ┌──┐            ┌──┐           59.5s    |  |          
│ ─54.8s────┼──┼────┼──┼───54.5s───54.6s───55.4s────┼──┼────54s─────┼──┼───54.3s────┌──┐────┼──┼───55.3s──
│   ┌──┐    |  |    |  |    ┌──┐    ┌──┐    ┌──┐    |  |    ┌──┐    |  |    ┌──┐    |  |    |  |    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

// List of supported flags and their default value.
const FLAGS = {}

const getFlags = (input = {}, flags = FLAGS) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

[sand] Would (input, flags = FLAGS) => ({ ...flags, ...input }) (or (input, flags = FLAGS) => ({ ...flags, ...removeFalsy(input) }) if input might contain undefined keys) be simpler?
One difference is that if input contains unknown flags, those would not be filtered, but that should not be a problem?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would actually like FLAGS to contain all the feature flags that ZISI is currently accepting, and make it so that any supplied flags that don't belong to that list are ignored (e.g. https://github.com/netlify/zip-it-and-ship-it/pull/567/files#diff-84cbdd132bc7ff6db27e194fa841b40864de4a8f661e0a79273ff9b2477e9e3dR11-R15). I think this is important to ensure that any flags used throughout the codebase are declared in one place for greater visibility.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll merge this as is for now, but I'm happy to rework this later if you think we should.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good 👍

@eduardoboucas eduardoboucas merged commit 6914246 into main Jul 5, 2021
@eduardoboucas eduardoboucas deleted the feat/feature-flags branch July 5, 2021 10:01
Skn0tt pushed a commit to netlify/build that referenced this pull request May 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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.

2 participants