@sentry/solidstart 11.12.0 → 11.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/build/cjs/_virtual/_rolldown/runtime.js +34 -0
  2. package/build/cjs/client/index.js +11 -18
  3. package/build/cjs/client/sdk.js +19 -20
  4. package/build/cjs/client/sdk.js.map +1 -1
  5. package/build/cjs/client/solidrouter.js +8 -16
  6. package/build/cjs/common/tunnel.js +11 -8
  7. package/build/cjs/common/tunnel.js.map +1 -1
  8. package/build/cjs/config/addInstrumentation.js +110 -111
  9. package/build/cjs/config/addInstrumentation.js.map +1 -1
  10. package/build/cjs/config/index.js +2 -0
  11. package/build/cjs/config/withSentry.js +86 -87
  12. package/build/cjs/config/withSentry.js.map +1 -1
  13. package/build/cjs/config/wrapServerEntryWithDynamicImport.js +139 -135
  14. package/build/cjs/config/wrapServerEntryWithDynamicImport.js.map +1 -1
  15. package/build/cjs/index.client.js +12 -18
  16. package/build/cjs/index.server.js +162 -159
  17. package/build/cjs/index.server.js.map +1 -1
  18. package/build/cjs/nitro/tunnelPlugin.js +12 -10
  19. package/build/cjs/nitro/tunnelPlugin.js.map +1 -1
  20. package/build/cjs/server/index.js +151 -158
  21. package/build/cjs/server/middleware.js +26 -37
  22. package/build/cjs/server/middleware.js.map +1 -1
  23. package/build/cjs/server/sdk.js +13 -14
  24. package/build/cjs/server/sdk.js.map +1 -1
  25. package/build/cjs/server/solidrouter.js +26 -18
  26. package/build/cjs/server/solidrouter.js.map +1 -1
  27. package/build/cjs/server/utils.js +32 -27
  28. package/build/cjs/server/utils.js.map +1 -1
  29. package/build/cjs/server/withServerActionInstrumentation.js +46 -49
  30. package/build/cjs/server/withServerActionInstrumentation.js.map +1 -1
  31. package/build/cjs/solidrouter.client.js +9 -16
  32. package/build/cjs/solidrouter.js +12 -18
  33. package/build/cjs/solidrouter.server.js +3 -8
  34. package/build/cjs/vite/buildInstrumentationFile.js +46 -46
  35. package/build/cjs/vite/buildInstrumentationFile.js.map +1 -1
  36. package/build/cjs/vite/index.js +5 -10
  37. package/build/cjs/vite/sentrySolidStart.js +86 -39
  38. package/build/cjs/vite/sentrySolidStart.js.map +1 -1
  39. package/build/cjs/vite/sentrySolidStartVite.js +32 -35
  40. package/build/cjs/vite/sentrySolidStartVite.js.map +1 -1
  41. package/build/cjs/vite/sourceMaps.js +117 -152
  42. package/build/cjs/vite/sourceMaps.js.map +1 -1
  43. package/build/esm/client/index.js +2 -3
  44. package/build/esm/client/sdk.js +19 -18
  45. package/build/esm/client/sdk.js.map +1 -1
  46. package/build/esm/client/solidrouter.js +1 -2
  47. package/build/esm/common/tunnel.js +11 -6
  48. package/build/esm/common/tunnel.js.map +1 -1
  49. package/build/esm/config/addInstrumentation.js +107 -109
  50. package/build/esm/config/addInstrumentation.js.map +1 -1
  51. package/build/esm/config/index.js +1 -0
  52. package/build/esm/config/withSentry.js +86 -84
  53. package/build/esm/config/withSentry.js.map +1 -1
  54. package/build/esm/config/wrapServerEntryWithDynamicImport.js +139 -133
  55. package/build/esm/config/wrapServerEntryWithDynamicImport.js.map +1 -1
  56. package/build/esm/index.client.js +3 -3
  57. package/build/esm/index.server.js +14 -10
  58. package/build/esm/index.server.js.map +1 -1
  59. package/build/esm/nitro/tunnelPlugin.js +12 -10
  60. package/build/esm/nitro/tunnelPlugin.js.map +1 -1
  61. package/build/esm/package.json +1 -1
  62. package/build/esm/server/index.js +7 -7
  63. package/build/esm/server/middleware.js +26 -35
  64. package/build/esm/server/middleware.js.map +1 -1
  65. package/build/esm/server/sdk.js +13 -12
  66. package/build/esm/server/sdk.js.map +1 -1
  67. package/build/esm/server/solidrouter.js +25 -16
  68. package/build/esm/server/solidrouter.js.map +1 -1
  69. package/build/esm/server/utils.js +32 -25
  70. package/build/esm/server/utils.js.map +1 -1
  71. package/build/esm/server/withServerActionInstrumentation.js +46 -47
  72. package/build/esm/server/withServerActionInstrumentation.js.map +1 -1
  73. package/build/esm/solidrouter.client.js +2 -2
  74. package/build/esm/solidrouter.js +3 -3
  75. package/build/esm/solidrouter.server.js +1 -2
  76. package/build/esm/vite/buildInstrumentationFile.js +43 -44
  77. package/build/esm/vite/buildInstrumentationFile.js.map +1 -1
  78. package/build/esm/vite/index.js +3 -3
  79. package/build/esm/vite/sentrySolidStart.js +86 -37
  80. package/build/esm/vite/sentrySolidStart.js.map +1 -1
  81. package/build/esm/vite/sentrySolidStartVite.js +32 -33
  82. package/build/esm/vite/sentrySolidStartVite.js.map +1 -1
  83. package/build/esm/vite/sourceMaps.js +117 -150
  84. package/build/esm/vite/sourceMaps.js.map +1 -1
  85. package/package.json +20 -20
  86. package/build/cjs/client/index.js.map +0 -1
  87. package/build/cjs/client/solidrouter.js.map +0 -1
  88. package/build/cjs/index.client.js.map +0 -1
  89. package/build/cjs/server/index.js.map +0 -1
  90. package/build/cjs/solidrouter.client.js.map +0 -1
  91. package/build/cjs/solidrouter.js.map +0 -1
  92. package/build/cjs/solidrouter.server.js.map +0 -1
  93. package/build/cjs/vite/index.js.map +0 -1
  94. package/build/esm/client/index.js.map +0 -1
  95. package/build/esm/client/solidrouter.js.map +0 -1
  96. package/build/esm/index.client.js.map +0 -1
  97. package/build/esm/server/index.js.map +0 -1
  98. package/build/esm/solidrouter.client.js.map +0 -1
  99. package/build/esm/solidrouter.js.map +0 -1
  100. package/build/esm/solidrouter.server.js.map +0 -1
  101. package/build/esm/vite/index.js.map +0 -1
@@ -1,93 +1,92 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- const node_url = require('node:url');
4
- const core = require('@sentry/core');
5
- const config = require('@sentry/server-utils/orchestrion/config');
6
- const rollup = require('@sentry/server-utils/orchestrion/rollup');
7
- const tunnel = require('../common/tunnel.js');
8
- const sentrySolidStartVite = require('../vite/sentrySolidStartVite.js');
9
- const addInstrumentation = require('./addInstrumentation.js');
10
-
11
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
1
+ const require_tunnel = require("../common/tunnel.js");
2
+ const require_sentrySolidStartVite = require("../vite/sentrySolidStartVite.js");
3
+ const require_addInstrumentation = require("./addInstrumentation.js");
4
+ let _sentry_core = require("@sentry/core");
5
+ let node_url = require("node:url");
6
+ let _sentry_server_utils_orchestrion_config = require("@sentry/server-utils/orchestrion/config");
7
+ let _sentry_server_utils_orchestrion_rollup = require("@sentry/server-utils/orchestrion/rollup");
8
+ // src/config/withSentry.ts
12
9
  const IORedisDependencies = ["standard-as-callback"];
13
- const defaultSentrySolidStartPluginOptions = {
14
- experimental_entrypointWrappedFunctions: ["default", "handler", "server"]
15
- };
10
+ const defaultSentrySolidStartPluginOptions = { experimental_entrypointWrappedFunctions: [
11
+ "default",
12
+ "handler",
13
+ "server"
14
+ ] };
15
+ /**
16
+ * Modifies the passed in Solid Start configuration with build-time enhancements such as
17
+ * building the `instrument.server.ts` file into the appropriate build folder based on
18
+ * build preset.
19
+ *
20
+ * @param solidStartConfig A Solid Start configuration object, as usually passed to `defineConfig` in `app.config.ts|js`
21
+ * @param sentrySolidStartPluginOptions Options to configure the plugin
22
+ * @returns The modified config to be exported and passed back into `defineConfig`
23
+ */
16
24
  function withSentry(solidStartConfig = {}, sentrySolidStartPluginOptions) {
17
- const sentryPluginOptions = {
18
- ...sentrySolidStartPluginOptions,
19
- ...defaultSentrySolidStartPluginOptions
20
- };
21
- const server = solidStartConfig.server || {};
22
- const tunnelBasePath = core._INTERNAL_normalizeTunnelBasePath(
23
- server.baseURL
24
- );
25
- if (tunnelBasePath) {
26
- core.GLOBAL_OBJ[tunnel.TUNNEL_BASE_PATH_GLOBAL] = tunnelBasePath;
27
- }
28
- const viteConfig = solidStartConfig.vite;
29
- const vite = typeof viteConfig === "function" ? (...args) => sentrySolidStartVite.addSentryPluginToVite(viteConfig(...args), sentryPluginOptions, tunnelBasePath) : sentrySolidStartVite.addSentryPluginToVite(viteConfig, sentryPluginOptions, tunnelBasePath);
30
- const addBuildTimeInstrumentation = sentryPluginOptions.buildTimeInstrumentation !== false;
31
- const sentryNitroModule = (nitro) => {
32
- nitro.hooks.hook("rollup:before", async (nitro2, rollupConfig) => {
33
- const sentryRollupConfig = rollupConfig;
34
- if (tunnelBasePath) {
35
- sentryRollupConfig.plugins.push({
36
- name: "sentry-solidstart-tunnel-base-path",
37
- banner: `globalThis.${tunnel.TUNNEL_BASE_PATH_GLOBAL} = ${JSON.stringify(tunnelBasePath)};`
38
- });
39
- }
40
- if (addBuildTimeInstrumentation) {
41
- sentryRollupConfig.plugins.push(
42
- rollup.sentryOrchestrionPlugin({ buildTimeInstrumentation: sentryPluginOptions.buildTimeInstrumentation }),
43
- rollup.sentryCommonJSInteropPlugin()
44
- );
45
- }
46
- if (sentrySolidStartPluginOptions?.autoInjectServerSentry === "experimental_dynamic-import") {
47
- await addInstrumentation.addDynamicImportEntryFileWrapper({
48
- nitro: nitro2,
49
- rollupConfig: sentryRollupConfig,
50
- sentryPluginOptions
51
- });
52
- sentrySolidStartPluginOptions.debug && core.debug.log(
53
- "Wrapping the server entry file with a dynamic `import()`, so Sentry can be preloaded before the server initializes."
54
- );
55
- } else {
56
- await addInstrumentation.addInstrumentationFileToBuild(nitro2);
57
- if (sentrySolidStartPluginOptions?.autoInjectServerSentry === "top-level-import") {
58
- await addInstrumentation.addSentryTopImport(nitro2);
59
- }
60
- }
61
- });
62
- };
63
- const existingModules = server.modules || [];
64
- let externals = server.externals;
65
- let commonJS = server.commonJS;
66
- if (addBuildTimeInstrumentation) {
67
- const existingInline = externals?.inline || [];
68
- externals = {
69
- ...externals,
70
- inline: [.../* @__PURE__ */ new Set([...existingInline, ...config.INSTRUMENTED_MODULE_NAMES, ...IORedisDependencies])]
71
- };
72
- commonJS = { ...rollup.commonJSInteropOptions(), ...commonJS };
73
- }
74
- return {
75
- ...solidStartConfig,
76
- vite,
77
- server: {
78
- ...server,
79
- externals,
80
- commonJS,
81
- modules: [...existingModules, sentryNitroModule],
82
- // Through `server.plugins`, since vinxi's dev server ignores plugins that Nitro modules add.
83
- plugins: [...server.plugins || [], getTunnelPluginPath()]
84
- }
85
- };
25
+ const sentryPluginOptions = {
26
+ ...sentrySolidStartPluginOptions,
27
+ ...defaultSentrySolidStartPluginOptions
28
+ };
29
+ const server = solidStartConfig.server || {};
30
+ const tunnelBasePath = (0, _sentry_core._INTERNAL_normalizeTunnelBasePath)(server.baseURL);
31
+ if (tunnelBasePath) _sentry_core.GLOBAL_OBJ[require_tunnel.TUNNEL_BASE_PATH_GLOBAL] = tunnelBasePath;
32
+ const viteConfig = solidStartConfig.vite;
33
+ const vite = typeof viteConfig === "function" ? (...args) => require_sentrySolidStartVite.addSentryPluginToVite(viteConfig(...args), sentryPluginOptions, tunnelBasePath) : require_sentrySolidStartVite.addSentryPluginToVite(viteConfig, sentryPluginOptions, tunnelBasePath);
34
+ const addBuildTimeInstrumentation = sentryPluginOptions.buildTimeInstrumentation !== false;
35
+ const sentryNitroModule = (nitro) => {
36
+ nitro.hooks.hook("rollup:before", async (nitro, rollupConfig) => {
37
+ const sentryRollupConfig = rollupConfig;
38
+ if (tunnelBasePath) sentryRollupConfig.plugins.push({
39
+ name: "sentry-solidstart-tunnel-base-path",
40
+ banner: `globalThis.${require_tunnel.TUNNEL_BASE_PATH_GLOBAL} = ${JSON.stringify(tunnelBasePath)};`
41
+ });
42
+ if (addBuildTimeInstrumentation) sentryRollupConfig.plugins.push((0, _sentry_server_utils_orchestrion_rollup.sentryOrchestrionPlugin)({ buildTimeInstrumentation: sentryPluginOptions.buildTimeInstrumentation }), (0, _sentry_server_utils_orchestrion_rollup.sentryCommonJSInteropPlugin)());
43
+ if (sentrySolidStartPluginOptions?.autoInjectServerSentry === "experimental_dynamic-import") {
44
+ await require_addInstrumentation.addDynamicImportEntryFileWrapper({
45
+ nitro,
46
+ rollupConfig: sentryRollupConfig,
47
+ sentryPluginOptions
48
+ });
49
+ sentrySolidStartPluginOptions.debug && _sentry_core.debug.log("Wrapping the server entry file with a dynamic `import()`, so Sentry can be preloaded before the server initializes.");
50
+ } else {
51
+ await require_addInstrumentation.addInstrumentationFileToBuild(nitro);
52
+ if (sentrySolidStartPluginOptions?.autoInjectServerSentry === "top-level-import") await require_addInstrumentation.addSentryTopImport(nitro);
53
+ }
54
+ });
55
+ };
56
+ const existingModules = server.modules || [];
57
+ let externals = server.externals;
58
+ let commonJS = server.commonJS;
59
+ if (addBuildTimeInstrumentation) {
60
+ const existingInline = externals?.inline || [];
61
+ externals = {
62
+ ...externals,
63
+ inline: [.../* @__PURE__ */ new Set([
64
+ ...existingInline,
65
+ ..._sentry_server_utils_orchestrion_config.INSTRUMENTED_MODULE_NAMES,
66
+ ...IORedisDependencies
67
+ ])]
68
+ };
69
+ commonJS = {
70
+ ...(0, _sentry_server_utils_orchestrion_rollup.commonJSInteropOptions)(),
71
+ ...commonJS
72
+ };
73
+ }
74
+ return {
75
+ ...solidStartConfig,
76
+ vite,
77
+ server: {
78
+ ...server,
79
+ externals,
80
+ commonJS,
81
+ modules: [...existingModules, sentryNitroModule],
82
+ plugins: [...server.plugins || [], getTunnelPluginPath()]
83
+ }
84
+ };
86
85
  }
87
86
  function getTunnelPluginPath() {
88
- const url = new URL("../nitro/tunnelPlugin.js", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('config/withSentry.js', document.baseURI).href)));
89
- return url.protocol === "file:" ? node_url.fileURLToPath(url) : url.pathname;
87
+ const url = new URL("../nitro/tunnelPlugin.js", require("url").pathToFileURL(__filename).href);
88
+ return url.protocol === "file:" ? (0, node_url.fileURLToPath)(url) : url.pathname;
90
89
  }
91
-
92
90
  exports.withSentry = withSentry;
93
- //# sourceMappingURL=withSentry.js.map
91
+
92
+ //# sourceMappingURL=withSentry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"withSentry.js","sources":["../../../src/config/withSentry.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url';\nimport { debug, GLOBAL_OBJ, _INTERNAL_normalizeTunnelBasePath as normalizeTunnelBasePath } from '@sentry/core';\nimport { INSTRUMENTED_MODULE_NAMES } from '@sentry/server-utils/orchestrion/config';\nimport {\n commonJSInteropOptions,\n sentryCommonJSInteropPlugin,\n sentryOrchestrionPlugin,\n} from '@sentry/server-utils/orchestrion/rollup';\nimport type { Nitro, NitroConfig } from 'nitropack';\nimport { TUNNEL_BASE_PATH_GLOBAL } from '../common/tunnel';\nimport { addSentryPluginToVite } from '../vite/sentrySolidStartVite';\nimport type { SentrySolidStartPluginOptions } from '../vite/types';\nimport {\n addDynamicImportEntryFileWrapper,\n addInstrumentationFileToBuild,\n addSentryTopImport,\n} from './addInstrumentation';\nimport type { RollupConfig, SolidStartInlineConfig, SolidStartInlineServerConfig } from './types';\n\n// ioredis requires this CommonJS helper to be bundled with it. Leaving it\n// external makes Nitro resolve the default export as a namespace object.\nconst IORedisDependencies = ['standard-as-callback'];\n\nconst defaultSentrySolidStartPluginOptions: Omit<\n SentrySolidStartPluginOptions,\n 'experimental_entrypointWrappedFunctions'\n> &\n Required<Pick<SentrySolidStartPluginOptions, 'experimental_entrypointWrappedFunctions'>> = {\n experimental_entrypointWrappedFunctions: ['default', 'handler', 'server'],\n};\n\n/**\n * Modifies the passed in Solid Start configuration with build-time enhancements such as\n * building the `instrument.server.ts` file into the appropriate build folder based on\n * build preset.\n *\n * @param solidStartConfig A Solid Start configuration object, as usually passed to `defineConfig` in `app.config.ts|js`\n * @param sentrySolidStartPluginOptions Options to configure the plugin\n * @returns The modified config to be exported and passed back into `defineConfig`\n */\nexport function withSentry(\n solidStartConfig: SolidStartInlineConfig = {},\n sentrySolidStartPluginOptions: SentrySolidStartPluginOptions,\n): SolidStartInlineConfig {\n const sentryPluginOptions = {\n ...sentrySolidStartPluginOptions,\n ...defaultSentrySolidStartPluginOptions,\n };\n\n const server = (solidStartConfig.server || {}) as SolidStartInlineServerConfig;\n // Requests reach the tunnel with `server.baseURL` still in front, so both sides serve it under that.\n const tunnelBasePath = normalizeTunnelBasePath(\n (server as SolidStartInlineServerConfig & { baseURL?: string }).baseURL,\n );\n // vinxi's dev server runs Nitro in this process, so the tunnel plugin can read it from here in dev.\n if (tunnelBasePath) {\n (GLOBAL_OBJ as { [TUNNEL_BASE_PATH_GLOBAL]?: string })[TUNNEL_BASE_PATH_GLOBAL] = tunnelBasePath;\n }\n\n const viteConfig = solidStartConfig.vite;\n const vite =\n typeof viteConfig === 'function'\n ? (...args: Parameters<typeof viteConfig>) =>\n addSentryPluginToVite(viteConfig(...args), sentryPluginOptions, tunnelBasePath)\n : addSentryPluginToVite(viteConfig, sentryPluginOptions, tunnelBasePath);\n\n const addBuildTimeInstrumentation = sentryPluginOptions.buildTimeInstrumentation !== false;\n\n // Use a module so we don't override preset hooks.\n const sentryNitroModule = (nitro: Nitro) => {\n nitro.hooks.hook('rollup:before', async (nitro, rollupConfig) => {\n // Nitro types the `rollup:before` hook's `rollupConfig.plugins` as `string[]` (plugin paths),\n // but at runtime it holds resolved plugin objects we can push onto, so narrow to our own shape.\n const sentryRollupConfig = rollupConfig as unknown as RollupConfig;\n\n if (tunnelBasePath) {\n // The built server runs in another process, so the tunnel plugin reads the base path from the bundle.\n sentryRollupConfig.plugins.push({\n name: 'sentry-solidstart-tunnel-base-path',\n banner: `globalThis.${TUNNEL_BASE_PATH_GLOBAL} = ${JSON.stringify(tunnelBasePath)};`,\n });\n }\n\n if (addBuildTimeInstrumentation) {\n sentryRollupConfig.plugins.push(\n sentryOrchestrionPlugin({ buildTimeInstrumentation: sentryPluginOptions.buildTimeInstrumentation }),\n sentryCommonJSInteropPlugin(),\n );\n }\n\n if (sentrySolidStartPluginOptions?.autoInjectServerSentry === 'experimental_dynamic-import') {\n await addDynamicImportEntryFileWrapper({\n nitro,\n rollupConfig: sentryRollupConfig,\n sentryPluginOptions,\n });\n\n sentrySolidStartPluginOptions.debug &&\n debug.log(\n 'Wrapping the server entry file with a dynamic `import()`, so Sentry can be preloaded before the server initializes.',\n );\n } else {\n await addInstrumentationFileToBuild(nitro);\n\n if (sentrySolidStartPluginOptions?.autoInjectServerSentry === 'top-level-import') {\n await addSentryTopImport(nitro);\n }\n }\n });\n };\n\n const existingModules = (server as SolidStartInlineServerConfig & { modules?: unknown[] }).modules || [];\n\n // An externalized dependency never passes through the orchestrion code transform, so force-inline\n // the instrumented modules. This has to be set statically on the Nitro config (not in a hook)\n // because externalization is a resolution-time decision made before Rollup normalizes `external`.\n let externals = (server as SolidStartInlineServerConfig & { externals?: { inline?: string[] } }).externals;\n let commonJS = (server as SolidStartInlineServerConfig & { commonJS?: NitroConfig['commonJS'] }).commonJS;\n if (addBuildTimeInstrumentation) {\n const existingInline = externals?.inline || [];\n externals = {\n ...externals,\n inline: [...new Set([...existingInline, ...INSTRUMENTED_MODULE_NAMES, ...IORedisDependencies])],\n };\n\n // The inlined drivers `require()` CommonJS dependencies that stay external. Fix the interop\n // for those requires (see `commonJSInteropOptions`). User-provided options win.\n commonJS = { ...commonJSInteropOptions(), ...commonJS };\n }\n\n return {\n ...solidStartConfig,\n vite,\n server: {\n ...server,\n externals,\n commonJS,\n modules: [...existingModules, sentryNitroModule],\n // Through `server.plugins`, since vinxi's dev server ignores plugins that Nitro modules add.\n plugins: [...(server.plugins || []), getTunnelPluginPath()],\n },\n };\n}\n\nfunction getTunnelPluginPath(): string {\n const url = new URL('../nitro/tunnelPlugin.js', import.meta.url);\n\n // `import.meta.url` is a file URL in the built package, but not in every test environment.\n return url.protocol === 'file:' ? fileURLToPath(url) : url.pathname;\n}\n"],"names":["normalizeTunnelBasePath","GLOBAL_OBJ","TUNNEL_BASE_PATH_GLOBAL","addSentryPluginToVite","nitro","sentryOrchestrionPlugin","sentryCommonJSInteropPlugin","addDynamicImportEntryFileWrapper","debug","addInstrumentationFileToBuild","addSentryTopImport","INSTRUMENTED_MODULE_NAMES","commonJSInteropOptions","fileURLToPath"],"mappings":";;;;;;;;;;;AAqBA,MAAM,mBAAA,GAAsB,CAAC,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,gBAAA;AAAA,IACH,IAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,GAAG,MAAA;AAAA,MACH,SAAA;AAAA,MACA,QAAA;AAAA,MACA,OAAA,EAAS,CAAC,GAAG,eAAA,EAAiB,iBAAiB,CAAA;AAAA;AAAA,MAE/C,OAAA,EAAS,CAAC,GAAI,MAAA,CAAO,WAAW,EAAC,EAAI,qBAAqB;AAAA;AAC5D,GACF;AACF;AAEA,SAAS,mBAAA,GAA8B;AACrC,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,0BAAA,EAA4B,sQAAe,CAAA;AAG/D,EAAA,OAAO,IAAI,QAAA,KAAa,OAAA,GAAUC,sBAAA,CAAc,GAAG,IAAI,GAAA,CAAI,QAAA;AAC7D;;;;"}
1
+ {"version":3,"file":"withSentry.js","names":["normalizeTunnelBasePath","GLOBAL_OBJ","TUNNEL_BASE_PATH_GLOBAL","addSentryPluginToVite","sentryOrchestrionPlugin","sentryCommonJSInteropPlugin","addDynamicImportEntryFileWrapper","debug","addInstrumentationFileToBuild","addSentryTopImport","INSTRUMENTED_MODULE_NAMES","commonJSInteropOptions","fileURLToPath"],"sources":["../../../src/config/withSentry.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url';\nimport { debug, GLOBAL_OBJ, _INTERNAL_normalizeTunnelBasePath as normalizeTunnelBasePath } from '@sentry/core';\nimport { INSTRUMENTED_MODULE_NAMES } from '@sentry/server-utils/orchestrion/config';\nimport {\n commonJSInteropOptions,\n sentryCommonJSInteropPlugin,\n sentryOrchestrionPlugin,\n} from '@sentry/server-utils/orchestrion/rollup';\nimport type { Nitro, NitroConfig } from 'nitropack';\nimport { TUNNEL_BASE_PATH_GLOBAL } from '../common/tunnel';\nimport { addSentryPluginToVite } from '../vite/sentrySolidStartVite';\nimport type { SentrySolidStartPluginOptions } from '../vite/types';\nimport {\n addDynamicImportEntryFileWrapper,\n addInstrumentationFileToBuild,\n addSentryTopImport,\n} from './addInstrumentation';\nimport type { RollupConfig, SolidStartInlineConfig, SolidStartInlineServerConfig } from './types';\n\n// ioredis requires this CommonJS helper to be bundled with it. Leaving it\n// external makes Nitro resolve the default export as a namespace object.\nconst IORedisDependencies = ['standard-as-callback'];\n\nconst defaultSentrySolidStartPluginOptions: Omit<\n SentrySolidStartPluginOptions,\n 'experimental_entrypointWrappedFunctions'\n> &\n Required<Pick<SentrySolidStartPluginOptions, 'experimental_entrypointWrappedFunctions'>> = {\n experimental_entrypointWrappedFunctions: ['default', 'handler', 'server'],\n};\n\n/**\n * Modifies the passed in Solid Start configuration with build-time enhancements such as\n * building the `instrument.server.ts` file into the appropriate build folder based on\n * build preset.\n *\n * @param solidStartConfig A Solid Start configuration object, as usually passed to `defineConfig` in `app.config.ts|js`\n * @param sentrySolidStartPluginOptions Options to configure the plugin\n * @returns The modified config to be exported and passed back into `defineConfig`\n */\nexport function withSentry(\n solidStartConfig: SolidStartInlineConfig = {},\n sentrySolidStartPluginOptions: SentrySolidStartPluginOptions,\n): SolidStartInlineConfig {\n const sentryPluginOptions = {\n ...sentrySolidStartPluginOptions,\n ...defaultSentrySolidStartPluginOptions,\n };\n\n const server = (solidStartConfig.server || {}) as SolidStartInlineServerConfig;\n // Requests reach the tunnel with `server.baseURL` still in front, so both sides serve it under that.\n const tunnelBasePath = normalizeTunnelBasePath(\n (server as SolidStartInlineServerConfig & { baseURL?: string }).baseURL,\n );\n // vinxi's dev server runs Nitro in this process, so the tunnel plugin can read it from here in dev.\n if (tunnelBasePath) {\n (GLOBAL_OBJ as { [TUNNEL_BASE_PATH_GLOBAL]?: string })[TUNNEL_BASE_PATH_GLOBAL] = tunnelBasePath;\n }\n\n const viteConfig = solidStartConfig.vite;\n const vite =\n typeof viteConfig === 'function'\n ? (...args: Parameters<typeof viteConfig>) =>\n addSentryPluginToVite(viteConfig(...args), sentryPluginOptions, tunnelBasePath)\n : addSentryPluginToVite(viteConfig, sentryPluginOptions, tunnelBasePath);\n\n const addBuildTimeInstrumentation = sentryPluginOptions.buildTimeInstrumentation !== false;\n\n // Use a module so we don't override preset hooks.\n const sentryNitroModule = (nitro: Nitro) => {\n nitro.hooks.hook('rollup:before', async (nitro, rollupConfig) => {\n // Nitro types the `rollup:before` hook's `rollupConfig.plugins` as `string[]` (plugin paths),\n // but at runtime it holds resolved plugin objects we can push onto, so narrow to our own shape.\n const sentryRollupConfig = rollupConfig as unknown as RollupConfig;\n\n if (tunnelBasePath) {\n // The built server runs in another process, so the tunnel plugin reads the base path from the bundle.\n sentryRollupConfig.plugins.push({\n name: 'sentry-solidstart-tunnel-base-path',\n banner: `globalThis.${TUNNEL_BASE_PATH_GLOBAL} = ${JSON.stringify(tunnelBasePath)};`,\n });\n }\n\n if (addBuildTimeInstrumentation) {\n sentryRollupConfig.plugins.push(\n sentryOrchestrionPlugin({ buildTimeInstrumentation: sentryPluginOptions.buildTimeInstrumentation }),\n sentryCommonJSInteropPlugin(),\n );\n }\n\n if (sentrySolidStartPluginOptions?.autoInjectServerSentry === 'experimental_dynamic-import') {\n await addDynamicImportEntryFileWrapper({\n nitro,\n rollupConfig: sentryRollupConfig,\n sentryPluginOptions,\n });\n\n sentrySolidStartPluginOptions.debug &&\n debug.log(\n 'Wrapping the server entry file with a dynamic `import()`, so Sentry can be preloaded before the server initializes.',\n );\n } else {\n await addInstrumentationFileToBuild(nitro);\n\n if (sentrySolidStartPluginOptions?.autoInjectServerSentry === 'top-level-import') {\n await addSentryTopImport(nitro);\n }\n }\n });\n };\n\n const existingModules = (server as SolidStartInlineServerConfig & { modules?: unknown[] }).modules || [];\n\n // An externalized dependency never passes through the orchestrion code transform, so force-inline\n // the instrumented modules. This has to be set statically on the Nitro config (not in a hook)\n // because externalization is a resolution-time decision made before Rollup normalizes `external`.\n let externals = (server as SolidStartInlineServerConfig & { externals?: { inline?: string[] } }).externals;\n let commonJS = (server as SolidStartInlineServerConfig & { commonJS?: NitroConfig['commonJS'] }).commonJS;\n if (addBuildTimeInstrumentation) {\n const existingInline = externals?.inline || [];\n externals = {\n ...externals,\n inline: [...new Set([...existingInline, ...INSTRUMENTED_MODULE_NAMES, ...IORedisDependencies])],\n };\n\n // The inlined drivers `require()` CommonJS dependencies that stay external. Fix the interop\n // for those requires (see `commonJSInteropOptions`). User-provided options win.\n commonJS = { ...commonJSInteropOptions(), ...commonJS };\n }\n\n return {\n ...solidStartConfig,\n vite,\n server: {\n ...server,\n externals,\n commonJS,\n modules: [...existingModules, sentryNitroModule],\n // Through `server.plugins`, since vinxi's dev server ignores plugins that Nitro modules add.\n plugins: [...(server.plugins || []), getTunnelPluginPath()],\n },\n };\n}\n\nfunction getTunnelPluginPath(): string {\n const url = new URL('../nitro/tunnelPlugin.js', import.meta.url);\n\n // `import.meta.url` is a file URL in the built package, but not in every test environment.\n return url.protocol === 'file:' ? fileURLToPath(url) : url.pathname;\n}\n"],"mappings":";;;;;;;;AAqBA,MAAM,sBAAsB,CAAC,sBAAsB;AAEnD,MAAM,uCAIuF,EAC3F,yCAAyC;CAAC;CAAW;CAAW;AAAQ,EAC1E;;;;;;;;;;AAWA,SAAgB,WACd,mBAA2C,CAAC,GAC5C,+BACwB;CACxB,MAAM,sBAAsB;EAC1B,GAAG;EACH,GAAG;CACL;CAEA,MAAM,SAAU,iBAAiB,UAAU,CAAC;CAE5C,MAAM,kBAAA,GAAiBA,aAAAA,kCAAAA,CACpB,OAA+D,OAClE;CAEA,IAAI,gBACDC,aAAAA,WAAsDC,eAAAA,2BAA2B;CAGpF,MAAM,aAAa,iBAAiB;CACpC,MAAM,OACJ,OAAO,eAAe,cACjB,GAAG,SACFC,6BAAAA,sBAAsB,WAAW,GAAG,IAAI,GAAG,qBAAqB,cAAc,IAChFA,6BAAAA,sBAAsB,YAAY,qBAAqB,cAAc;CAE3E,MAAM,8BAA8B,oBAAoB,6BAA6B;CAGrF,MAAM,qBAAqB,UAAiB;EAC1C,MAAM,MAAM,KAAK,iBAAiB,OAAO,OAAO,iBAAiB;GAG/D,MAAM,qBAAqB;GAE3B,IAAI,gBA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aAAa,WAAA,GAAUC,SAAAA,cAAAA,CAAc,GAAG,IAAI,IAAI;AAC7D"}
@@ -1,155 +1,158 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- const node_path = require('node:path');
4
- const node_url = require('node:url');
5
- const core = require('@sentry/core');
6
-
1
+ let _sentry_core = require("@sentry/core");
2
+ let node_url = require("node:url");
3
+ let node_path = require("node:path");
4
+ // src/config/wrapServerEntryWithDynamicImport.ts
5
+ /** THIS FILE IS AN UTILITY FOR NITRO-BASED PACKAGES AND SHOULD BE KEPT IN SYNC IN NUXT, SOLIDSTART, ETC. */
7
6
  const SENTRY_WRAPPED_ENTRY = "?sentry-query-wrapped-entry";
8
7
  const SENTRY_WRAPPED_FUNCTIONS = "?sentry-query-wrapped-functions=";
9
8
  const SENTRY_REEXPORTED_FUNCTIONS = "?sentry-query-reexported-functions=";
10
9
  const QUERY_END_INDICATOR = "SENTRY-QUERY-END";
10
+ /**
11
+ * `load()` emits `file://` specifiers because Node's ESM loader rejects bare Windows
12
+ * paths (`ERR_UNSUPPORTED_ESM_URL_SCHEME`), but Rollup's resolver only understands
13
+ * filesystem paths. Returns `undefined` for a malformed `file://` URL.
14
+ *
15
+ * **Only exported for testing**
16
+ */
11
17
  function toResolvablePath(source) {
12
- if (!source.startsWith("file://")) {
13
- return { path: source, wasFileUrl: false };
14
- }
15
- if (source === "file://" || source === "file:///") {
16
- return void 0;
17
- }
18
- try {
19
- const filePath = node_url.fileURLToPath(source);
20
- if (!filePath || filePath === "/" || filePath === "\\") {
21
- return void 0;
22
- }
23
- return { path: filePath, wasFileUrl: true };
24
- } catch {
25
- return void 0;
26
- }
18
+ if (!source.startsWith("file://")) return {
19
+ path: source,
20
+ wasFileUrl: false
21
+ };
22
+ if (source === "file://" || source === "file:///") return;
23
+ try {
24
+ const filePath = (0, node_url.fileURLToPath)(source);
25
+ if (!filePath || filePath === "/" || filePath === "\\") return;
26
+ return {
27
+ path: filePath,
28
+ wasFileUrl: true
29
+ };
30
+ } catch {
31
+ return;
32
+ }
27
33
  }
28
- const CONFIG_EXTENSIONS = [".ts", ".js", ".mjs", ".cjs", ".mts", ".cts"];
34
+ const CONFIG_EXTENSIONS = [
35
+ ".ts",
36
+ ".js",
37
+ ".mjs",
38
+ ".cjs",
39
+ ".mts",
40
+ ".cts"
41
+ ];
29
42
  function isServerConfigFile(sourcePath, resolvedPath, configFileName) {
30
- if (sourcePath === resolvedPath) {
31
- return true;
32
- }
33
- const name = node_path.basename(sourcePath);
34
- return name === configFileName || CONFIG_EXTENSIONS.some((ext) => name === `${configFileName}${ext}`);
43
+ if (sourcePath === resolvedPath) return true;
44
+ const name = (0, node_path.basename)(sourcePath);
45
+ return name === configFileName || CONFIG_EXTENSIONS.some((ext) => name === `${configFileName}${ext}`);
35
46
  }
47
+ /**
48
+ * A Rollup plugin which wraps the server entry with a dynamic `import()`. This makes it possible to initialize Sentry first
49
+ * by using a regular `import` and load the server after that.
50
+ * This also works with serverless `handler` functions, as it re-exports the `handler`.
51
+ *
52
+ * @param config Configuration options for the Rollup Plugin
53
+ * @param config.serverConfigFileName Name of the Sentry server config (without file extension). E.g. 'sentry.server.config'
54
+ * @param config.serverEntrypointFileName The server entrypoint (with file extension). Usually, this is defined by the Nitro preset and is something like 'node-server.mjs'
55
+ * @param config.resolvedServerConfigPath Resolved path of the Sentry server config (based on `src` directory)
56
+ * @param config.entryPointWrappedFunctions Exported bindings of the server entry file, which are wrapped as async function. E.g. ['default', 'handler', 'server']
57
+ * @param config.debug Whether debug logs are enabled in the build time environment
58
+ */
36
59
  function wrapServerEntryWithDynamicImport(config) {
37
- const {
38
- serverConfigFileName,
39
- serverEntrypointFileName,
40
- resolvedServerConfigPath,
41
- entrypointWrappedFunctions,
42
- debug
43
- } = config;
44
- const resolutionIdPrefix = "\0raw";
45
- return {
46
- name: "sentry-wrap-server-entry-with-dynamic-import",
47
- async resolveId(source, importer, options) {
48
- const resolvable = toResolvablePath(source);
49
- if (!resolvable) {
50
- return null;
51
- }
52
- const { path: normalizedSource, wasFileUrl } = resolvable;
53
- if (isServerConfigFile(normalizedSource, resolvedServerConfigPath, serverConfigFileName)) {
54
- return { id: normalizedSource, moduleSideEffects: true };
55
- }
56
- if (options.isEntry && normalizedSource.includes(serverEntrypointFileName) && normalizedSource.includes(".mjs") && !normalizedSource.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {
57
- const resolution = await this.resolve(normalizedSource, importer, options);
58
- if (!resolution || resolution?.external) return resolution;
59
- const moduleInfo = await this.load(resolution);
60
- moduleInfo.moduleSideEffects = true;
61
- return resolution.id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`) ? resolution.id : `${resolutionIdPrefix}${resolution.id.concat(SENTRY_WRAPPED_ENTRY).concat(
62
- constructWrappedFunctionExportQuery(moduleInfo.exportedBindings, entrypointWrappedFunctions, debug)
63
- ).concat(QUERY_END_INDICATOR)}`;
64
- }
65
- if (wasFileUrl) {
66
- const resolved = await this.resolve(normalizedSource, importer, { ...options, isEntry: false });
67
- if (resolved) return resolved;
68
- return { id: normalizedSource };
69
- }
70
- return null;
71
- },
72
- load(id) {
73
- if (id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {
74
- const entryId = removeSentryQueryFromPath(id).slice(resolutionIdPrefix.length);
75
- const entryIdUrl = node_url.pathToFileURL(entryId).href;
76
- const configUrl = node_url.pathToFileURL(resolvedServerConfigPath).href;
77
- const reExportedFunctions = id.includes(SENTRY_WRAPPED_FUNCTIONS) || id.includes(SENTRY_REEXPORTED_FUNCTIONS) ? constructFunctionReExport(id, entryIdUrl) : "";
78
- return (
79
- // Regular `import` of the Sentry config
80
- `import ${JSON.stringify(configUrl)};
81
- import(${JSON.stringify(entryIdUrl)});
82
- ${reExportedFunctions}
83
- `
84
- );
85
- }
86
- return null;
87
- }
88
- };
60
+ const { serverConfigFileName, serverEntrypointFileName, resolvedServerConfigPath, entrypointWrappedFunctions, debug } = config;
61
+ const resolutionIdPrefix = "\0raw";
62
+ return {
63
+ name: "sentry-wrap-server-entry-with-dynamic-import",
64
+ async resolveId(source, importer, options) {
65
+ const resolvable = toResolvablePath(source);
66
+ if (!resolvable) return null;
67
+ const { path: normalizedSource, wasFileUrl } = resolvable;
68
+ if (isServerConfigFile(normalizedSource, resolvedServerConfigPath, serverConfigFileName)) return {
69
+ id: normalizedSource,
70
+ moduleSideEffects: true
71
+ };
72
+ if (options.isEntry && normalizedSource.includes(serverEntrypointFileName) && normalizedSource.includes(".mjs") && !normalizedSource.includes(`.mjs?sentry-query-wrapped-entry`)) {
73
+ const resolution = await this.resolve(normalizedSource, importer, options);
74
+ if (!resolution || resolution?.external) return resolution;
75
+ const moduleInfo = await this.load(resolution);
76
+ moduleInfo.moduleSideEffects = true;
77
+ return resolution.id.includes(`.mjs?sentry-query-wrapped-entry`) ? resolution.id : `${resolutionIdPrefix}${resolution.id.concat(SENTRY_WRAPPED_ENTRY).concat(constructWrappedFunctionExportQuery(moduleInfo.exportedBindings, entrypointWrappedFunctions, debug)).concat(QUERY_END_INDICATOR)}`;
78
+ }
79
+ if (wasFileUrl) {
80
+ const resolved = await this.resolve(normalizedSource, importer, {
81
+ ...options,
82
+ isEntry: false
83
+ });
84
+ if (resolved) return resolved;
85
+ return { id: normalizedSource };
86
+ }
87
+ return null;
88
+ },
89
+ load(id) {
90
+ if (id.includes(`.mjs?sentry-query-wrapped-entry`)) {
91
+ const entryId = removeSentryQueryFromPath(id).slice(4);
92
+ const entryIdUrl = (0, node_url.pathToFileURL)(entryId).href;
93
+ const configUrl = (0, node_url.pathToFileURL)(resolvedServerConfigPath).href;
94
+ const reExportedFunctions = id.includes("?sentry-query-wrapped-functions=") || id.includes("?sentry-query-reexported-functions=") ? constructFunctionReExport(id, entryIdUrl) : "";
95
+ return `import ${JSON.stringify(configUrl)};\nimport(${JSON.stringify(entryIdUrl)});\n${reExportedFunctions}\n`;
96
+ }
97
+ return null;
98
+ }
99
+ };
89
100
  }
101
+ /**
102
+ * Strips the Sentry query part from a path.
103
+ * Example: example/path?sentry-query-wrapped-entry?sentry-query-functions-reexport=foo,SENTRY-QUERY-END -> /example/path
104
+ *
105
+ * **Only exported for testing**
106
+ */
90
107
  function removeSentryQueryFromPath(url) {
91
- const regex = new RegExp(`\\${SENTRY_WRAPPED_ENTRY}.*?\\${QUERY_END_INDICATOR}`);
92
- return url.replace(regex, "");
108
+ const regex = new RegExp(`\\${SENTRY_WRAPPED_ENTRY}.*?\\${QUERY_END_INDICATOR}`);
109
+ return url.replace(regex, "");
93
110
  }
111
+ /**
112
+ * Extracts and sanitizes function re-export and function wrap query parameters from a query string.
113
+ * If it is a default export, it is not considered for re-exporting.
114
+ *
115
+ * **Only exported for testing**
116
+ */
94
117
  function extractFunctionReexportQueryParameters(query) {
95
- const wrapRegex = new RegExp(
96
- `\\${SENTRY_WRAPPED_FUNCTIONS}(.*?)(\\${QUERY_END_INDICATOR}|\\${SENTRY_REEXPORTED_FUNCTIONS})`
97
- );
98
- const reexportRegex = new RegExp(`\\${SENTRY_REEXPORTED_FUNCTIONS}(.*?)(\\${QUERY_END_INDICATOR})`);
99
- const wrapMatch = query.match(wrapRegex);
100
- const reexportMatch = query.match(reexportRegex);
101
- const wrap = wrapMatch?.[1] ? wrapMatch[1].split(",").filter((param) => param !== "").map((str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) : [];
102
- const reexport = reexportMatch?.[1] ? reexportMatch[1].split(",").filter((param) => param !== "" && param !== "default").map((str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) : [];
103
- return { wrap, reexport };
118
+ const wrapRegex = new RegExp(`\\${SENTRY_WRAPPED_FUNCTIONS}(.*?)(\\${QUERY_END_INDICATOR}|\\${SENTRY_REEXPORTED_FUNCTIONS})`);
119
+ const reexportRegex = new RegExp(`\\${SENTRY_REEXPORTED_FUNCTIONS}(.*?)(\\${QUERY_END_INDICATOR})`);
120
+ const wrapMatch = query.match(wrapRegex);
121
+ const reexportMatch = query.match(reexportRegex);
122
+ return {
123
+ wrap: wrapMatch?.[1] ? wrapMatch[1].split(",").filter((param) => param !== "").map((str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) : [],
124
+ reexport: reexportMatch?.[1] ? reexportMatch[1].split(",").filter((param) => param !== "" && param !== "default").map((str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) : []
125
+ };
104
126
  }
127
+ /**
128
+ * Constructs a comma-separated string with all functions that need to be re-exported later from the server entry.
129
+ * It uses Rollup's `exportedBindings` to determine the functions to re-export. Functions which should be wrapped
130
+ * (e.g. serverless handlers) are wrapped by Sentry.
131
+ *
132
+ * **Only exported for testing**
133
+ */
105
134
  function constructWrappedFunctionExportQuery(exportedBindings, entrypointWrappedFunctions, debug) {
106
- const functionsToExport = {
107
- wrap: [],
108
- reexport: []
109
- };
110
- Object.values(exportedBindings || {}).forEach(
111
- (functions) => functions.forEach((fn) => {
112
- if (entrypointWrappedFunctions.includes(fn)) {
113
- functionsToExport.wrap.push(fn);
114
- } else {
115
- functionsToExport.reexport.push(fn);
116
- }
117
- })
118
- );
119
- if (debug && functionsToExport.wrap.length === 0) {
120
- core.consoleSandbox(
121
- () => (
122
- // eslint-disable-next-line no-console
123
- console.warn(
124
- "[Sentry] No functions found to wrap. In case the server needs to export async functions other than `handler` or `server`, consider adding the name(s) to `entrypointWrappedFunctions`."
125
- )
126
- )
127
- );
128
- }
129
- const wrapQuery = functionsToExport.wrap.length ? `${SENTRY_WRAPPED_FUNCTIONS}${functionsToExport.wrap.join(",")}` : "";
130
- const reexportQuery = functionsToExport.reexport.length ? `${SENTRY_REEXPORTED_FUNCTIONS}${functionsToExport.reexport.join(",")}` : "";
131
- return [wrapQuery, reexportQuery].join("");
135
+ const functionsToExport = {
136
+ wrap: [],
137
+ reexport: []
138
+ };
139
+ Object.values(exportedBindings || {}).forEach((functions) => functions.forEach((fn) => {
140
+ if (entrypointWrappedFunctions.includes(fn)) functionsToExport.wrap.push(fn);
141
+ else functionsToExport.reexport.push(fn);
142
+ }));
143
+ if (debug && functionsToExport.wrap.length === 0) (0, _sentry_core.consoleSandbox)(() => console.warn("[Sentry] No functions found to wrap. In case the server needs to export async functions other than `handler` or `server`, consider adding the name(s) to `entrypointWrappedFunctions`."));
144
+ return [functionsToExport.wrap.length ? `${SENTRY_WRAPPED_FUNCTIONS}${functionsToExport.wrap.join(",")}` : "", functionsToExport.reexport.length ? `${SENTRY_REEXPORTED_FUNCTIONS}${functionsToExport.reexport.join(",")}` : ""].join("");
132
145
  }
146
+ /**
147
+ * Constructs a code snippet with function reexports (can be used in Rollup plugins as a return value for `load()`)
148
+ *
149
+ * **Only exported for testing**
150
+ */
133
151
  function constructFunctionReExport(pathWithQuery, entryId) {
134
- const { wrap: wrapFunctions, reexport: reexportFunctions } = extractFunctionReexportQueryParameters(pathWithQuery);
135
- return wrapFunctions.reduce(
136
- (functionsCode, currFunctionName) => functionsCode.concat(
137
- `async function ${currFunctionName}_sentryWrapped(...args) {
138
- const res = await import(${JSON.stringify(entryId)});
139
- return res.${currFunctionName}.call(this, ...args);
140
- }
141
- export { ${currFunctionName}_sentryWrapped as ${currFunctionName} };
142
- `
143
- ),
144
- ""
145
- ).concat(
146
- reexportFunctions.reduce(
147
- (functionsCode, currFunctionName) => functionsCode.concat(`export { ${currFunctionName} } from ${JSON.stringify(entryId)};`),
148
- ""
149
- )
150
- );
152
+ const { wrap: wrapFunctions, reexport: reexportFunctions } = extractFunctionReexportQueryParameters(pathWithQuery);
153
+ return wrapFunctions.reduce((functionsCode, currFunctionName) => functionsCode.concat(`async function ${currFunctionName}_sentryWrapped(...args) {\n const res = await import(${JSON.stringify(entryId)});\n return res.${currFunctionName}.call(this, ...args);\n}
154
+ export { ${currFunctionName}_sentryWrapped as ${currFunctionName} };\n`), "").concat(reexportFunctions.reduce((functionsCode, currFunctionName) => functionsCode.concat(`export { ${currFunctionName} } from ${JSON.stringify(entryId)};`), ""));
151
155
  }
152
-
153
156
  exports.QUERY_END_INDICATOR = QUERY_END_INDICATOR;
154
157
  exports.SENTRY_REEXPORTED_FUNCTIONS = SENTRY_REEXPORTED_FUNCTIONS;
155
158
  exports.SENTRY_WRAPPED_ENTRY = SENTRY_WRAPPED_ENTRY;
@@ -160,4 +163,5 @@ exports.extractFunctionReexportQueryParameters = extractFunctionReexportQueryPar
160
163
  exports.removeSentryQueryFromPath = removeSentryQueryFromPath;
161
164
  exports.toResolvablePath = toResolvablePath;
162
165
  exports.wrapServerEntryWithDynamicImport = wrapServerEntryWithDynamicImport;
163
- //# sourceMappingURL=wrapServerEntryWithDynamicImport.js.map
166
+
167
+ //# sourceMappingURL=wrapServerEntryWithDynamicImport.js.map