-
Notifications
You must be signed in to change notification settings - Fork 416
feat: load generated functions from Netlify Build #7408
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
Changes from 7 commits
d7c8699
e575da7
35fcc79
b0abce0
dd189fc
8029956
81558e5
14518df
cbf1ada
03f3b3e
6841961
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { createRequire } from 'module' | |
import { basename, extname, isAbsolute, join, resolve } from 'path' | ||
import { env } from 'process' | ||
|
||
import type { GeneratedFunction } from '@netlify/build' | ||
import { type ListedFunction, listFunctions, type Manifest } from '@netlify/zip-it-and-ship-it' | ||
import extractZip from 'extract-zip' | ||
|
||
|
@@ -74,6 +75,7 @@ export class FunctionsRegistry { | |
private config: NormalizedCachedConfigConfig | ||
private debug: boolean | ||
private frameworksAPIPaths: ReturnType<typeof getFrameworksAPIPaths> | ||
private generatedFunctions: GeneratedFunction[] | ||
private isConnected: boolean | ||
private logLambdaCompat: boolean | ||
private manifest?: Manifest | ||
|
@@ -88,6 +90,7 @@ export class FunctionsRegistry { | |
config, | ||
debug = false, | ||
frameworksAPIPaths, | ||
generatedFunctions, | ||
isConnected = false, | ||
logLambdaCompat, | ||
manifest, | ||
|
@@ -103,6 +106,7 @@ export class FunctionsRegistry { | |
config: NormalizedCachedConfigConfig | ||
debug?: boolean | ||
frameworksAPIPaths: ReturnType<typeof getFrameworksAPIPaths> | ||
generatedFunctions: GeneratedFunction[] | ||
isConnected?: boolean | ||
logLambdaCompat: boolean | ||
manifest?: Manifest | ||
|
@@ -115,6 +119,7 @@ export class FunctionsRegistry { | |
this.config = config | ||
this.debug = debug | ||
this.frameworksAPIPaths = frameworksAPIPaths | ||
this.generatedFunctions = generatedFunctions ?? [] | ||
this.isConnected = isConnected | ||
this.projectRoot = projectRoot | ||
this.timeouts = timeouts | ||
|
@@ -465,14 +470,32 @@ export class FunctionsRegistry { | |
|
||
await Promise.all(directories.map((path) => FunctionsRegistry.prepareDirectory(path))) | ||
|
||
const functions = await this.listFunctions(directories, { | ||
featureFlags: { | ||
buildRustSource: env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE === 'true', | ||
const functions = await this.listFunctions( | ||
{ | ||
generated: { | ||
functions: this.generatedFunctions.map((func) => func.path), | ||
}, | ||
user: { | ||
// In reality, `directories` contains both directories with user and | ||
// generated functions. The registry currently lacks knowledge about | ||
// the contents of each directory, so we put them in the same bag and | ||
// rely on the order of the directories to get the priority right. | ||
// But now that zip-it-and-ship-it accepts an object with mixed paths | ||
// that lets us specify exactly which paths contain user functions or | ||
// generated functions, we should refactor this call so it encodes | ||
// that distiction. | ||
directories, | ||
}, | ||
}, | ||
configFileDirectories: [getPathInProject([INTERNAL_FUNCTIONS_FOLDER])], | ||
// @ts-expect-error -- TODO(serhalp): Function config types do not match. Investigate and fix. | ||
config: this.config.functions, | ||
}) | ||
{ | ||
featureFlags: { | ||
buildRustSource: env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE === 'true', | ||
}, | ||
configFileDirectories: [getPathInProject([INTERNAL_FUNCTIONS_FOLDER])], | ||
// @ts-expect-error -- TODO(serhalp): Function config types do not match. Investigate and fix. | ||
config: this.config.functions, | ||
}, | ||
) | ||
|
||
// user-defined functions take precedence over internal functions, | ||
// so we want to ignore any internal functions where there's a user-defined one with the same name | ||
|
@@ -506,7 +529,7 @@ export class FunctionsRegistry { | |
// zip-it-and-ship-it returns an array sorted based on which extension should have precedence, | ||
// where the last ones precede the previous ones. This is why | ||
// we reverse the array so we get the right functions precedence in the CLI. | ||
functions.reverse().map(async ({ displayName, mainFile, name, runtime: runtimeName }) => { | ||
functions.reverse().map(async ({ displayName, mainFile, name, runtime: runtimeName, srcPath }) => { | ||
if (ignoredFunctions.has(name)) { | ||
return | ||
} | ||
|
@@ -527,7 +550,6 @@ export class FunctionsRegistry { | |
const func = new NetlifyFunction({ | ||
blobsContext: this.blobsContext, | ||
config: this.config, | ||
directory: directories.find((directory) => mainFile.startsWith(directory)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was weird. We were computing But that's exactly what the |
||
mainFile, | ||
name, | ||
displayName, | ||
|
@@ -539,6 +561,7 @@ export class FunctionsRegistry { | |
timeoutBackground: this.timeouts.backgroundFunctions, | ||
timeoutSynchronous: this.timeouts.syncFunctions, | ||
settings: this.settings, | ||
srcPath, | ||
}) | ||
|
||
// If a function we're registering was also unregistered in this run, | ||
|
Uh oh!
There was an error while loading. Please reload this page.