-
Notifications
You must be signed in to change notification settings - Fork 386
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
Conversation
There was a problem hiding this 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
// 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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
* with the path of the operation and a `ensureExists` methos that creates | |
* with the path of the operation and an `ensureExists` method that creates |
import { mkdir } from 'fs/promises' | ||
import { resolve } from 'node:path' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consistency nit:
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') |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼 Nice approach
import { FunctionsRegistry } from '../../../../dist/lib/functions/registry.js' | ||
import { watchDebounced } from '../../../../dist/utils/command-helpers.js' | ||
import { getFrameworksAPIPaths } from '../../../../dist/utils/frameworks-api.js' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
// The order of the function directories matters. Rightmost directories take | ||
// precedence. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Summary
Adds support for the Frameworks API to the
deploy
andserve
commands.