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: add support for the Frameworks API #6735

Merged
merged 3 commits into from
Jun 28, 2024
Merged

Conversation

eduardoboucas
Copy link
Member

Summary

Adds support for the Frameworks API to the deploy and serve commands.

@eduardoboucas eduardoboucas requested a review from a team as a code owner June 27, 2024 16:25
Copy link

github-actions bot commented Jun 27, 2024

📊 Benchmark results

Comparing with 73f4eb5

  • Dependency count: 1,213 (no change)
  • Package size: 313 MB ⬇️ 0.00% decrease vs. 73f4eb5
  • Number of ts-expect-error directives: 976 ⬇️ 0.10% decrease vs. 73f4eb5

Copy link
Collaborator

@serhalp serhalp left a comment

Choose a reason for hiding this comment

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

LGTM, just some uncertainty around the feature flag and some nits

Comment on lines 468 to +472
// The order of the directories matter: zip-it-and-ship-it will prioritize
// functions from the rightmost directories. In this case, we want user
// functions to take precedence over internal functions.
const functionDirectories = [internalFunctionsFolder, functionsFolder].filter((folder): folder is string =>
Boolean(folder),
const functionDirectories = [internalFunctionsFolder, frameworksAPIPaths.functions.path, functionsFolder].filter(
(folder): folder is string => Boolean(folder),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the order is behaviourally important, would it be possible to add test coverage for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're already testing that here, by hitting the deployed site and asserting that the output comes from the function we expect. I can add a few more cases here in a follow-up, though.

/**
* Returns an object containing the paths for all the operations of the
* Frameworks API. Each key maps to an object containing a `path` property
* with the path of the operation and a `ensureExists` methos that creates
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:

Suggested change
* with the path of the operation and a `ensureExists` methos that creates
* with the path of the operation and an `ensureExists` method that creates

Comment on lines +1 to +2
import { mkdir } from 'fs/promises'
import { resolve } from 'node:path'
Copy link
Collaborator

Choose a reason for hiding this comment

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

consistency nit:

Suggested change
import { mkdir } from 'fs/promises'
import { resolve } from 'node:path'
import { mkdir } from 'node:fs/promises'
import { resolve } from 'node:path'

* the directory in case it doesn't exist.
*/
export const getFrameworksAPIPaths = (basePath: string, packagePath?: string) => {
const root = resolve(basePath, packagePath || '', '.netlify/v1')
Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL

> path.resolve('/hello', '', 'world')
'/hello/world'

Copy link
Collaborator

Choose a reason for hiding this comment

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

... huh, interesting rabbit hole:

> path.resolve('/hello', ' ', 'world')
'/hello/ /world'
> path.resolve(' ', ' ', '/hello', 'world')
'/hello/world'
> path.resolve('/hello', 'world', ' ')
'/hello/world/ '

}

/**
* Returns an object containing the paths for all the operations of the
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏼 Nice approach

Comment on lines 7 to +9
import { FunctionsRegistry } from '../../../../dist/lib/functions/registry.js'
import { watchDebounced } from '../../../../dist/utils/command-helpers.js'
import { getFrameworksAPIPaths } from '../../../../dist/utils/frameworks-api.js'
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 Huh, why do all the unit tests test the built code while the integration tests test the source? That's odd.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I'm not sure! I know we've gradually introduced vitest over ava, and there was some complexity in that transition. But that doesn't explain this. I'll take a look.

Comment on lines 351 to 352
// The order of the function directories matters. Rightmost directories take
// precedence.
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here, is it possible to test this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same answer as above. We end up testing this in the different commands by creating conflicting function and checking the output of the one that wins.

@@ -23,6 +23,7 @@ export const getFeatureFlagsFromSiteInfo = (siteInfo: {
...(siteInfo.feature_flags || {}),
// see https://github.com/netlify/pod-dev-foundations/issues/581#issuecomment-1731022753
zisi_golang_use_al2: isFeatureFlagEnabled('cli_golang_use_al2', siteInfo),
netlify_build_frameworks_api: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 Were you initially thinking of feature flagging this and then you changed your mind and forgot to remove this? I might be missing something otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the idea here is to always enable the Frameworks API in Netlify Build, which is still behind a feature flag in our build system.

@eduardoboucas eduardoboucas merged commit 6a48a38 into main Jun 28, 2024
48 checks passed
@eduardoboucas eduardoboucas deleted the feat/frameworks-api branch June 28, 2024 08:09
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.

None yet

2 participants