(pathWithQuery: string, entryId: string)
| 181 | * Constructs a code snippet with function reexports (can be used in Rollup plugins as a return value for `load()`) |
| 182 | */ |
| 183 | export function constructFunctionReExport(pathWithQuery: string, entryId: string): string { |
| 184 | const { wrap: wrapFunctions, reexport: reexportFunctions } = extractFunctionReexportQueryParameters(pathWithQuery); |
| 185 | |
| 186 | return wrapFunctions |
| 187 | .reduce( |
| 188 | (functionsCode, currFunctionName) => |
| 189 | functionsCode.concat( |
| 190 | `async function ${currFunctionName}_sentryWrapped(...args) {\n` + |
| 191 | ` const res = await import(${JSON.stringify(entryId)});\n` + |
| 192 | ` return res.${currFunctionName}.call(this, ...args);\n` + |
| 193 | '}\n' + |
| 194 | `export { ${currFunctionName}_sentryWrapped as ${currFunctionName} };\n`, |
| 195 | ), |
| 196 | '', |
| 197 | ) |
| 198 | .concat( |
| 199 | reexportFunctions.reduce( |
| 200 | (functionsCode, currFunctionName) => |
| 201 | functionsCode.concat(`export { ${currFunctionName} } from ${JSON.stringify(entryId)};`), |
| 202 | '', |
| 203 | ), |
| 204 | ); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Sets up alias to work around OpenTelemetry's incomplete ESM imports. |
no test coverage detected