Skip to content

Commit 63a89a5

Browse files
authored
feat(zip-it-and-ship-it): feature flag ability to dynamically import funcion inside request handler (#6248)
this gives us the ability to catch any errors which may arise when importing the function's code, and also allows us to prepare more within the bootstrapping phase before the functions code is executed - such as populating process.env or any bootstrapping that may require information provided by Proxy for the invocation
1 parent 9776b52 commit 63a89a5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

packages/zip-it-and-ship-it/src/feature_flags.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export const defaultFlags = {
2929

3030
// Adds the `___netlify-telemetry.mjs` file to the function bundle.
3131
zisi_add_instrumentation_loader: true,
32+
33+
// Dynamically import the function handler.
34+
zisi_dynamic_import_function_handler: false,
3235
} as const
3336

3437
export type FeatureFlags = Partial<Record<keyof typeof defaultFlags, boolean>>

packages/zip-it-and-ship-it/src/runtimes/node/utils/entry_file.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ const getEntryFileContents = (
5151
const importPath = `.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}`
5252

5353
if (runtimeAPIVersion === 2) {
54+
if (featureFlags.zisi_dynamic_import_function_handler) {
55+
return [
56+
`import * as bootstrap from './${BOOTSTRAP_FILE_NAME}'`,
57+
`export const handler = bootstrap.getLambdaHandler('${importPath}')`,
58+
].join(';')
59+
}
5460
return [
5561
`import * as bootstrap from './${BOOTSTRAP_FILE_NAME}'`,
5662
`import * as func from '${importPath}'`,

0 commit comments

Comments
 (0)