Uh oh!
There was an error while loading. Please reload this page.
feat(nuxt): Add entrypointWrappedFunctions to define async wrapped server functions - #14104
Conversation
75db7b5 to
031e219Comparesize-limit report 📦
|
| * The `asyncFunctionReExports` option is only relevant when `dynamicImportForServerEntry: true` (default value). | ||
| * | ||
| * As the server entry file is wrapped with a dynamic `import()`, previous async function exports need to be re-exported. | ||
| * The SDK detects and re-exports those exports (mostly serverless functions). This is why they are re-exported as async functions. | ||
| * In case you have a custom setup and your server exports other async functions, you can override the default array with this option. |
There was a problem hiding this comment.
l: Maybe we can rewrite this a bit, to a perspective of somebody who does not have deep understanding of all of this :D
| *The`asyncFunctionReExports`option is onlyrelevantwhen`dynamicImportForServerEntry: true`(defaultvalue). | |
| * | |
| *Astheserverentryfileiswrappedwithadynamic`import()`,previousasyncfunctionexportsneedtobere-exported. | |
| *TheSDKdetectsandre-exportsthoseexports(mostlyserverlessfunctions).Thisiswhytheyarere-exportedasasyncfunctions. | |
| *Incaseyouhaveacustomsetupandyourserverexportsotherasyncfunctions,youcanoverridethedefaultarraywiththisoption. | |
| *Bydefault(unlessyouconfigure`dynamicImportForServerEntry: false`)theSDKwilltrytowrapyourapplicationentrypointwithadynamic`import()`toensurealldependenciescanbeproperlyinstrumented. | |
| * | |
| *Bydefault,theSDKwillwrapthedefaultexportaswellasa `handler` or `server` exportfromtheentrypoint.Ifyourapplicationhasadifferentmainexportthatisusedtoruntheapplication,youcanoverwritethisbyprovidinganarrayofexportnamestowrap. | |
| *Anywrappedexportisexpectedtobeanasyncfunction. |
| asyncFunctionReExports: moduleOptionsParam.asyncFunctionReExports | ||
| ? moduleOptionsParam.asyncFunctionReExports | ||
| : ['default', 'handler', 'server'], |
There was a problem hiding this comment.
super-l: I find it slightly easier to read:
| asyncFunctionReExports: moduleOptionsParam.asyncFunctionReExports | |
| ? moduleOptionsParam.asyncFunctionReExports | |
| : ['default','handler','server'], | |
| asyncFunctionReExports: moduleOptionsParam.asyncFunctionReExports||['default','handler','server'], |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| const expected = ` | ||
| async function reExport(...args) { | ||
| async function reExport0(...args) { |
There was a problem hiding this comment.
m: Can we also have a test here to show that it does not change/wrap an export that does not match?
There was a problem hiding this comment.
That would require changing a lot of logic in the code. The here tested function constructFunctionReExport is only getting the input from the query parameters and creating a function for each query param.
The part, where those query params are actually added is here:
constfunctionsToExport=flatten(Object.values(moduleInfo.exportedBindings||{})).filter(functionName=>asyncFunctionReExports.includes(functionName),);One thing I could do is extracting this part as a function to test this step as well. But as adding the query params and generating the function code happen in two different Rollup hooks, I cannot combine those two things in one function or test.
lforst
commented
Oct 29, 2024
I'd design the API as follows: interfaceWhateverOptions{entrypointExportOverrides: {asyncFunctions: string[];functions: string[];}} |
mydea
commented
Oct 29, 2024
We cannot wrap functions this way though, can we? Or we'd turn the sync function into an async one (which we already do anyhow right now if we'd match)? |
lforst
commented
Oct 29, 2024
Right, I feel like we need a mechanism that will just exclude certain exports from the whole shebang |
mydea
commented
Oct 29, 2024
I think the idea is (Sigrid correct me if I'm wrong): We do not wrap anything, generally, except the exports defined in this array (all of which are assumed to be async functions). If you do not want to wrap anything you could define |
s1gr1d
commented
Oct 30, 2024
I think the suggestion of @lforst makes sense because if nothing is re-exported it's not exported at all. The problem here is that |
84ff708 to
b8a73caCompareasyncFunctionReExports to define re-exported server functionsentrypointWrappedFunctions to define async wrapped server functionsUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Based on this PR: #14086
We get the names of the exports with Rollup's
exportedBindings, but we cannot know whether this is a function or something else. As we need to re-export serverless functions for Netlify, Vercel and so on, an educated guess is made that'default', 'handler', 'server'are potential serverless functions that need to be wrapped by Sentry and re-exported.In case users experience issues, this can be changed with
entrypointWrappedFunctions.All other exports are exported as they were before.