@sentry/nuxt 10.53.1 → 10.55.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 (66) hide show
  1. package/build/cjs/client/piniaIntegration.js +7 -19
  2. package/build/cjs/client/piniaIntegration.js.map +1 -1
  3. package/build/cjs/client/sdk.js +2 -9
  4. package/build/cjs/client/sdk.js.map +1 -1
  5. package/build/cjs/client/vueIntegration.js +3 -10
  6. package/build/cjs/client/vueIntegration.js.map +1 -1
  7. package/build/cjs/common/debug-build.js +0 -5
  8. package/build/cjs/common/debug-build.js.map +1 -1
  9. package/build/cjs/module.js +52 -107
  10. package/build/cjs/module.js.map +1 -1
  11. package/build/cjs/server/sdk.js +20 -60
  12. package/build/cjs/server/sdk.js.map +1 -1
  13. package/build/cjs/vendor/server-template.js +0 -6
  14. package/build/cjs/vendor/server-template.js.map +1 -1
  15. package/build/cjs/vite/addServerConfig.js +45 -144
  16. package/build/cjs/vite/addServerConfig.js.map +1 -1
  17. package/build/cjs/vite/databaseConfig.js +10 -32
  18. package/build/cjs/vite/databaseConfig.js.map +1 -1
  19. package/build/cjs/vite/middlewareConfig.js +11 -46
  20. package/build/cjs/vite/middlewareConfig.js.map +1 -1
  21. package/build/cjs/vite/sentryVitePlugin.js +7 -24
  22. package/build/cjs/vite/sentryVitePlugin.js.map +1 -1
  23. package/build/cjs/vite/sourceMaps.js +89 -248
  24. package/build/cjs/vite/sourceMaps.js.map +1 -1
  25. package/build/cjs/vite/storageConfig.js +4 -10
  26. package/build/cjs/vite/storageConfig.js.map +1 -1
  27. package/build/cjs/vite/utils.js +51 -143
  28. package/build/cjs/vite/utils.js.map +1 -1
  29. package/build/esm/client/piniaIntegration.js +7 -19
  30. package/build/esm/client/piniaIntegration.js.map +1 -1
  31. package/build/esm/client/sdk.js +2 -9
  32. package/build/esm/client/sdk.js.map +1 -1
  33. package/build/esm/client/vueIntegration.js +3 -10
  34. package/build/esm/client/vueIntegration.js.map +1 -1
  35. package/build/esm/common/debug-build.js +0 -5
  36. package/build/esm/common/debug-build.js.map +1 -1
  37. package/build/esm/module.js +52 -107
  38. package/build/esm/module.js.map +1 -1
  39. package/build/esm/package.json +1 -1
  40. package/build/esm/server/sdk.js +20 -60
  41. package/build/esm/server/sdk.js.map +1 -1
  42. package/build/esm/vendor/server-template.js +0 -6
  43. package/build/esm/vendor/server-template.js.map +1 -1
  44. package/build/esm/vite/addServerConfig.js +45 -144
  45. package/build/esm/vite/addServerConfig.js.map +1 -1
  46. package/build/esm/vite/databaseConfig.js +10 -32
  47. package/build/esm/vite/databaseConfig.js.map +1 -1
  48. package/build/esm/vite/middlewareConfig.js +11 -46
  49. package/build/esm/vite/middlewareConfig.js.map +1 -1
  50. package/build/esm/vite/sentryVitePlugin.js +7 -24
  51. package/build/esm/vite/sentryVitePlugin.js.map +1 -1
  52. package/build/esm/vite/sourceMaps.js +89 -248
  53. package/build/esm/vite/sourceMaps.js.map +1 -1
  54. package/build/esm/vite/storageConfig.js +4 -10
  55. package/build/esm/vite/storageConfig.js.map +1 -1
  56. package/build/esm/vite/utils.js +51 -143
  57. package/build/esm/vite/utils.js.map +1 -1
  58. package/build/module/module.d.mts +17 -0
  59. package/build/module/module.d.ts +17 -0
  60. package/build/module/module.json +1 -1
  61. package/build/module/module.mjs +6 -6
  62. package/build/types/common/types.d.ts +17 -0
  63. package/build/types/common/types.d.ts.map +1 -1
  64. package/build/types/vite/utils.d.ts +2 -1
  65. package/build/types/vite/utils.d.ts.map +1 -1
  66. package/package.json +8 -8
@@ -6,115 +6,75 @@ const node = require('@sentry/node');
6
6
  const nodeCore = require('@sentry/node-core');
7
7
  const debugBuild = require('../common/debug-build.js');
8
8
 
9
- /**
10
- * Initializes the server-side of the Nuxt SDK
11
- *
12
- * @param options Configuration options for the SDK.
13
- */
14
9
  function init(options) {
15
10
  const envFallback = !nodeCore.isCjs() && undefined ? core.DEV_ENVIRONMENT : core.DEFAULT_ENVIRONMENT;
16
11
  const sentryOptions = {
17
12
  environment: options.environment ?? process.env.SENTRY_ENVIRONMENT ?? envFallback,
18
13
  defaultIntegrations: getNuxtDefaultIntegrations(options),
19
- ...options,
14
+ ...options
20
15
  };
21
-
22
- core.applySdkMetadata(sentryOptions, 'nuxt', ['nuxt', 'node']);
23
-
16
+ core.applySdkMetadata(sentryOptions, "nuxt", ["nuxt", "node"]);
24
17
  const client = node.init(sentryOptions);
25
-
26
18
  core.getGlobalScope().addEventProcessor(lowQualityTransactionsFilter(options));
27
19
  core.getGlobalScope().addEventProcessor(clientSourceMapErrorFilter(options));
28
-
29
20
  return client;
30
21
  }
31
-
32
- /**
33
- * Filter out transactions for resource requests which we don't want to send to Sentry
34
- * for quota reasons.
35
- *
36
- * Only exported for testing
37
- */
38
22
  function lowQualityTransactionsFilter(options) {
39
23
  return Object.assign(
40
- (event => {
41
- if (event.type !== 'transaction' || !event.transaction || isCacheEvent(event)) {
24
+ ((event) => {
25
+ if (event.type !== "transaction" || !event.transaction || isCacheEvent(event)) {
42
26
  return event;
43
27
  }
44
-
45
- // Check if this looks like a parametrized route (contains :param or :param() patterns)
46
28
  const hasRouteParameters = /\/:[^(/\s]*(\([^)]*\))?[^/\s]*/.test(event.transaction);
47
-
48
29
  if (hasRouteParameters) {
49
30
  return event;
50
31
  }
51
-
52
- // We don't want to send transaction for file requests, so everything ending with a *.someExtension should be filtered out
53
- // path.extname will return an empty string for normal page requests
54
32
  if (path.extname(event.transaction)) {
55
- options.debug &&
56
- debugBuild.DEBUG_BUILD &&
57
- core.debug.log('NuxtLowQualityTransactionsFilter filtered transaction: ', event.transaction);
33
+ options.debug && debugBuild.DEBUG_BUILD && core.debug.log("NuxtLowQualityTransactionsFilter filtered transaction: ", event.transaction);
58
34
  return null;
59
35
  }
60
36
  return event;
61
- }) ,
62
- { id: 'NuxtLowQualityTransactionsFilter' },
37
+ }),
38
+ { id: "NuxtLowQualityTransactionsFilter" }
63
39
  );
64
40
  }
65
-
66
- /**
67
- * The browser devtools try to get the source maps, but as client source maps may not be available there is going to be an error (no problem for the application though).
68
- *
69
- * Only exported for testing
70
- */
71
41
  function clientSourceMapErrorFilter(options) {
72
42
  return Object.assign(
73
- (event => {
43
+ ((event) => {
74
44
  const errorMsg = event.exception?.values?.[0]?.value;
75
45
  if (errorMsg?.match(/^ENOENT: no such file or directory, open '.*\/_nuxt\/.*\.js\.map'/)) {
76
- options.debug && debugBuild.DEBUG_BUILD && core.debug.log('NuxtClientSourceMapErrorFilter filtered error: ', errorMsg);
46
+ options.debug && debugBuild.DEBUG_BUILD && core.debug.log("NuxtClientSourceMapErrorFilter filtered error: ", errorMsg);
77
47
  return null;
78
48
  }
79
49
  return event;
80
- }) ,
81
- { id: 'NuxtClientSourceMapErrorFilter' },
50
+ }),
51
+ { id: "NuxtClientSourceMapErrorFilter" }
82
52
  );
83
53
  }
84
-
85
54
  function getNuxtDefaultIntegrations(options) {
86
55
  return [
87
- ...node.getDefaultIntegrations(options).filter(integration => integration.name !== 'Http'),
56
+ ...node.getDefaultIntegrations(options).filter((integration) => integration.name !== "Http"),
88
57
  // The httpIntegration is added as defaultIntegration, so users can still overwrite it
89
58
  node.httpIntegration({
90
59
  instrumentation: {
91
60
  responseHook: () => {
92
- // Makes it possible to end the tracing span before closing the Vercel lambda (https://vercel.com/docs/functions/functions-api-reference#waituntil)
93
61
  core.vercelWaitUntil(flushSafelyWithTimeout());
94
- },
95
- },
96
- }),
62
+ }
63
+ }
64
+ })
97
65
  ];
98
66
  }
99
-
100
- /**
101
- * Flushes pending Sentry events with a 2-second timeout and in a way that cannot create unhandled promise rejections.
102
- */
103
67
  async function flushSafelyWithTimeout() {
104
68
  try {
105
- debugBuild.DEBUG_BUILD && core.debug.log('Flushing events...');
106
- await core.flush(2000);
107
- debugBuild.DEBUG_BUILD && core.debug.log('Done flushing events');
69
+ debugBuild.DEBUG_BUILD && core.debug.log("Flushing events...");
70
+ await core.flush(2e3);
71
+ debugBuild.DEBUG_BUILD && core.debug.log("Done flushing events");
108
72
  } catch (e) {
109
- debugBuild.DEBUG_BUILD && core.debug.log('Error while flushing events:\n', e);
73
+ debugBuild.DEBUG_BUILD && core.debug.log("Error while flushing events:\n", e);
110
74
  }
111
75
  }
112
-
113
- /**
114
- * Checks if the event is a cache event.
115
- */
116
76
  function isCacheEvent(e) {
117
- return e.contexts?.trace?.origin === 'auto.cache.nuxt';
77
+ return e.contexts?.trace?.origin === "auto.cache.nuxt";
118
78
  }
119
79
 
120
80
  exports.clientSourceMapErrorFilter = clientSourceMapErrorFilter;
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.js","sources":["../../../src/server/sdk.ts"],"sourcesContent":["import * as path from 'node:path';\nimport type { Client, Event, EventProcessor, Integration } from '@sentry/core';\nimport {\n applySdkMetadata,\n debug,\n DEFAULT_ENVIRONMENT,\n DEV_ENVIRONMENT,\n flush,\n getGlobalScope,\n vercelWaitUntil,\n} from '@sentry/core';\nimport {\n getDefaultIntegrations as getDefaultNodeIntegrations,\n httpIntegration,\n init as initNode,\n type NodeOptions,\n} from '@sentry/node';\nimport { isCjs } from '@sentry/node-core';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport type { SentryNuxtServerOptions } from '../common/types';\n\n/**\n * Initializes the server-side of the Nuxt SDK\n *\n * @param options Configuration options for the SDK.\n */\nexport function init(options: SentryNuxtServerOptions): Client | undefined {\n const envFallback = !isCjs() && import.meta.dev ? DEV_ENVIRONMENT : DEFAULT_ENVIRONMENT;\n const sentryOptions = {\n environment: options.environment ?? process.env.SENTRY_ENVIRONMENT ?? envFallback,\n defaultIntegrations: getNuxtDefaultIntegrations(options),\n ...options,\n };\n\n applySdkMetadata(sentryOptions, 'nuxt', ['nuxt', 'node']);\n\n const client = initNode(sentryOptions);\n\n getGlobalScope().addEventProcessor(lowQualityTransactionsFilter(options));\n getGlobalScope().addEventProcessor(clientSourceMapErrorFilter(options));\n\n return client;\n}\n\n/**\n * Filter out transactions for resource requests which we don't want to send to Sentry\n * for quota reasons.\n *\n * Only exported for testing\n */\nexport function lowQualityTransactionsFilter(options: SentryNuxtServerOptions): EventProcessor {\n return Object.assign(\n (event => {\n if (event.type !== 'transaction' || !event.transaction || isCacheEvent(event)) {\n return event;\n }\n\n // Check if this looks like a parametrized route (contains :param or :param() patterns)\n const hasRouteParameters = /\\/:[^(/\\s]*(\\([^)]*\\))?[^/\\s]*/.test(event.transaction);\n\n if (hasRouteParameters) {\n return event;\n }\n\n // We don't want to send transaction for file requests, so everything ending with a *.someExtension should be filtered out\n // path.extname will return an empty string for normal page requests\n if (path.extname(event.transaction)) {\n options.debug &&\n DEBUG_BUILD &&\n debug.log('NuxtLowQualityTransactionsFilter filtered transaction: ', event.transaction);\n return null;\n }\n return event;\n }) satisfies EventProcessor,\n { id: 'NuxtLowQualityTransactionsFilter' },\n );\n}\n\n/**\n * The browser devtools try to get the source maps, but as client source maps may not be available there is going to be an error (no problem for the application though).\n *\n * Only exported for testing\n */\nexport function clientSourceMapErrorFilter(options: SentryNuxtServerOptions): EventProcessor {\n return Object.assign(\n (event => {\n const errorMsg = event.exception?.values?.[0]?.value;\n if (errorMsg?.match(/^ENOENT: no such file or directory, open '.*\\/_nuxt\\/.*\\.js\\.map'/)) {\n options.debug && DEBUG_BUILD && debug.log('NuxtClientSourceMapErrorFilter filtered error: ', errorMsg);\n return null;\n }\n return event;\n }) satisfies EventProcessor,\n { id: 'NuxtClientSourceMapErrorFilter' },\n );\n}\n\nfunction getNuxtDefaultIntegrations(options: NodeOptions): Integration[] {\n return [\n ...getDefaultNodeIntegrations(options).filter(integration => integration.name !== 'Http'),\n // The httpIntegration is added as defaultIntegration, so users can still overwrite it\n httpIntegration({\n instrumentation: {\n responseHook: () => {\n // Makes it possible to end the tracing span before closing the Vercel lambda (https://vercel.com/docs/functions/functions-api-reference#waituntil)\n vercelWaitUntil(flushSafelyWithTimeout());\n },\n },\n }),\n ];\n}\n\n/**\n * Flushes pending Sentry events with a 2-second timeout and in a way that cannot create unhandled promise rejections.\n */\nasync function flushSafelyWithTimeout(): Promise<void> {\n try {\n DEBUG_BUILD && debug.log('Flushing events...');\n await flush(2000);\n DEBUG_BUILD && debug.log('Done flushing events');\n } catch (e) {\n DEBUG_BUILD && debug.log('Error while flushing events:\\n', e);\n }\n}\n\n/**\n * Checks if the event is a cache event.\n */\nfunction isCacheEvent(e: Event): boolean {\n return e.contexts?.trace?.origin === 'auto.cache.nuxt';\n}\n"],"names":["isCjs","DEV_ENVIRONMENT","DEFAULT_ENVIRONMENT","applySdkMetadata","initNode","getGlobalScope","DEBUG_BUILD","debug","getDefaultNodeIntegrations","httpIntegration","vercelWaitUntil","flush"],"mappings":";;;;;;;;AAqBA;AACA;AACA;AACA;AACA;AACO,SAAS,IAAI,CAAC,OAAO,EAA+C;AAC3E,EAAE,MAAM,WAAA,GAAc,CAACA,cAAK,EAAC,IAAK,SAAY,GAAMC,oBAAA,GAAkBC,wBAAmB;AACzF,EAAE,MAAM,gBAAgB;AACxB,IAAI,WAAW,EAAE,OAAO,CAAC,WAAA,IAAe,OAAO,CAAC,GAAG,CAAC,kBAAA,IAAsB,WAAW;AACrF,IAAI,mBAAmB,EAAE,0BAA0B,CAAC,OAAO,CAAC;AAC5D,IAAI,GAAG,OAAO;AACd,GAAG;;AAEH,EAAEC,qBAAgB,CAAC,aAAa,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;;AAE3D,EAAE,MAAM,MAAA,GAASC,SAAQ,CAAC,aAAa,CAAC;;AAExC,EAAEC,mBAAc,EAAE,CAAC,iBAAiB,CAAC,4BAA4B,CAAC,OAAO,CAAC,CAAC;AAC3E,EAAEA,mBAAc,EAAE,CAAC,iBAAiB,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC;;AAEzE,EAAE,OAAO,MAAM;AACf;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,4BAA4B,CAAC,OAAO,EAA2C;AAC/F,EAAE,OAAO,MAAM,CAAC,MAAM;AACtB,KAAK,SAAS;AACd,M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AO;AACT,IAAI,GAAGC,2BAA0B,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,WAAA,IAAe,WAAW,CAAC,IAAA,KAAS,MAAM,CAAC;AAC7F;AACA,IAAIC,oBAAe,CAAC;AACpB,MAAM,eAAe,EAAE;AACvB,QAAQ,YAAY,EAAE,MAAM;AAC5B;AACA,UAAUC,oBAAe,CAAC,sBAAsB,EAAE,CAAC;AACnD,QAAQ,CAAC;AACT,OAAO;AACP,KAAK,CAAC;AACN,GAAG;AACH;;AAEA;AACA;AACA;AACA,eAAe,sBAAsB,GAAkB;AACvD,EAAE,IAAI;AACN,IAAIJ,0BAAeC,UAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC;AAClD,IAAI,MAAMI,UAAK,CAAC,IAAI,CAAC;AACrB,IAAIL,0BAAeC,UAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC;AACpD,EAAE,CAAA,CAAE,OAAO,CAAC,EAAE;AACd,IAAID,sBAAA,IAAeC,UAAK,CAAC,GAAG,CAAC,gCAAgC,EAAE,CAAC,CAAC;AACjE,EAAE;AACF;;AAEA;AACA;AACA;AACA,SAAS,YAAY,CAAC,CAAC,EAAkB;AACzC,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAA,KAAW,iBAAiB;AACxD;;;;;;"}
1
+ {"version":3,"file":"sdk.js","sources":["../../../src/server/sdk.ts"],"sourcesContent":["import * as path from 'node:path';\nimport type { Client, Event, EventProcessor, Integration } from '@sentry/core';\nimport {\n applySdkMetadata,\n debug,\n DEFAULT_ENVIRONMENT,\n DEV_ENVIRONMENT,\n flush,\n getGlobalScope,\n vercelWaitUntil,\n} from '@sentry/core';\nimport {\n getDefaultIntegrations as getDefaultNodeIntegrations,\n httpIntegration,\n init as initNode,\n type NodeOptions,\n} from '@sentry/node';\nimport { isCjs } from '@sentry/node-core';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport type { SentryNuxtServerOptions } from '../common/types';\n\n/**\n * Initializes the server-side of the Nuxt SDK\n *\n * @param options Configuration options for the SDK.\n */\nexport function init(options: SentryNuxtServerOptions): Client | undefined {\n const envFallback = !isCjs() && import.meta.dev ? DEV_ENVIRONMENT : DEFAULT_ENVIRONMENT;\n const sentryOptions = {\n environment: options.environment ?? process.env.SENTRY_ENVIRONMENT ?? envFallback,\n defaultIntegrations: getNuxtDefaultIntegrations(options),\n ...options,\n };\n\n applySdkMetadata(sentryOptions, 'nuxt', ['nuxt', 'node']);\n\n const client = initNode(sentryOptions);\n\n getGlobalScope().addEventProcessor(lowQualityTransactionsFilter(options));\n getGlobalScope().addEventProcessor(clientSourceMapErrorFilter(options));\n\n return client;\n}\n\n/**\n * Filter out transactions for resource requests which we don't want to send to Sentry\n * for quota reasons.\n *\n * Only exported for testing\n */\nexport function lowQualityTransactionsFilter(options: SentryNuxtServerOptions): EventProcessor {\n return Object.assign(\n (event => {\n if (event.type !== 'transaction' || !event.transaction || isCacheEvent(event)) {\n return event;\n }\n\n // Check if this looks like a parametrized route (contains :param or :param() patterns)\n const hasRouteParameters = /\\/:[^(/\\s]*(\\([^)]*\\))?[^/\\s]*/.test(event.transaction);\n\n if (hasRouteParameters) {\n return event;\n }\n\n // We don't want to send transaction for file requests, so everything ending with a *.someExtension should be filtered out\n // path.extname will return an empty string for normal page requests\n if (path.extname(event.transaction)) {\n options.debug &&\n DEBUG_BUILD &&\n debug.log('NuxtLowQualityTransactionsFilter filtered transaction: ', event.transaction);\n return null;\n }\n return event;\n }) satisfies EventProcessor,\n { id: 'NuxtLowQualityTransactionsFilter' },\n );\n}\n\n/**\n * The browser devtools try to get the source maps, but as client source maps may not be available there is going to be an error (no problem for the application though).\n *\n * Only exported for testing\n */\nexport function clientSourceMapErrorFilter(options: SentryNuxtServerOptions): EventProcessor {\n return Object.assign(\n (event => {\n const errorMsg = event.exception?.values?.[0]?.value;\n if (errorMsg?.match(/^ENOENT: no such file or directory, open '.*\\/_nuxt\\/.*\\.js\\.map'/)) {\n options.debug && DEBUG_BUILD && debug.log('NuxtClientSourceMapErrorFilter filtered error: ', errorMsg);\n return null;\n }\n return event;\n }) satisfies EventProcessor,\n { id: 'NuxtClientSourceMapErrorFilter' },\n );\n}\n\nfunction getNuxtDefaultIntegrations(options: NodeOptions): Integration[] {\n return [\n ...getDefaultNodeIntegrations(options).filter(integration => integration.name !== 'Http'),\n // The httpIntegration is added as defaultIntegration, so users can still overwrite it\n httpIntegration({\n instrumentation: {\n responseHook: () => {\n // Makes it possible to end the tracing span before closing the Vercel lambda (https://vercel.com/docs/functions/functions-api-reference#waituntil)\n vercelWaitUntil(flushSafelyWithTimeout());\n },\n },\n }),\n ];\n}\n\n/**\n * Flushes pending Sentry events with a 2-second timeout and in a way that cannot create unhandled promise rejections.\n */\nasync function flushSafelyWithTimeout(): Promise<void> {\n try {\n DEBUG_BUILD && debug.log('Flushing events...');\n await flush(2000);\n DEBUG_BUILD && debug.log('Done flushing events');\n } catch (e) {\n DEBUG_BUILD && debug.log('Error while flushing events:\\n', e);\n }\n}\n\n/**\n * Checks if the event is a cache event.\n */\nfunction isCacheEvent(e: Event): boolean {\n return e.contexts?.trace?.origin === 'auto.cache.nuxt';\n}\n"],"names":["isCjs","DEV_ENVIRONMENT","DEFAULT_ENVIRONMENT","applySdkMetadata","initNode","getGlobalScope","DEBUG_BUILD","debug","getDefaultNodeIntegrations","httpIntegration","vercelWaitUntil","flush"],"mappings":";;;;;;;;AA0BO,SAAS,KAAK,OAAA,EAAsD;AACzE,EAAA,MAAM,cAAc,CAACA,cAAA,EAAM,IAAK,YAAkBC,oBAAA,GAAkBC,wBAAA;AACpE,EAAA,MAAM,aAAA,GAAgB;AAAA,IACpB,WAAA,EAAa,OAAA,CAAQ,WAAA,IAAe,OAAA,CAAQ,IAAI,kBAAA,IAAsB,WAAA;AAAA,IACtE,mBAAA,EAAqB,2BAA2B,OAAO,CAAA;AAAA,IACvD,GAAG;AAAA,GACL;AAEA,EAAAC,qBAAA,CAAiB,aAAA,EAAe,MAAA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A,OAAA,CAAQ,KAAA,IAASD,sBAAA,IAAeC,UAAA,CAAM,GAAA,CAAI,mDAAmD,QAAQ,CAAA;AACrG,QAAA,OAAO,IAAA;AAAA,MACT;AACA,MAAA,OAAO,KAAA;AAAA,IACT,CAAA;AAAA,IACA,EAAE,IAAI,gCAAA;AAAiC,GACzC;AACF;AAEA,SAAS,2BAA2B,OAAA,EAAqC;AACvE,EAAA,OAAO;AAAA,IACL,GAAGC,4BAA2B,OAAO,CAAA,CAAE,OAAO,CAAA,WAAA,KAAe,WAAA,CAAY,SAAS,MAAM,CAAA;AAAA;AAAA,IAExFC,oBAAA,CAAgB;AAAA,MACd,eAAA,EAAiB;AAAA,QACf,cAAc,MAAM;AAElB,UAAAC,oBAAA,CAAgB,wBAAwB,CAAA;AAAA,QAC1C;AAAA;AACF,KACD;AAAA,GACH;AACF;AAKA,eAAe,sBAAA,GAAwC;AACrD,EAAA,IAAI;AACF,IAAAJ,sBAAA,IAAeC,UAAA,CAAM,IAAI,oBAAoB,CAAA;AAC7C,IAAA,MAAMI,WAAM,GAAI,CAAA;AAChB,IAAAL,sBAAA,IAAeC,UAAA,CAAM,IAAI,sBAAsB,CAAA;AAAA,EACjD,SAAS,CAAA,EAAG;AACV,IAAAD,sBAAA,IAAeC,UAAA,CAAM,GAAA,CAAI,gCAAA,EAAkC,CAAC,CAAA;AAAA,EAC9D;AACF;AAKA,SAAS,aAAa,CAAA,EAAmB;AACvC,EAAA,OAAO,CAAA,CAAE,QAAA,EAAU,KAAA,EAAO,MAAA,KAAW,iBAAA;AACvC;;;;;;"}
@@ -2,18 +2,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const kit = require('@nuxt/kit');
4
4
 
5
- /**
6
- * Adds a virtual file that can be used within the Nuxt Nitro server build.
7
- * Available in NuxtKit v4, so we are porting it here.
8
- * https://github.com/nuxt/nuxt/blob/d6df732eec1a3bd442bdb325b0335beb7e10cd64/packages/kit/src/template.ts#L55-L62
9
- */
10
5
  function addServerTemplate(template) {
11
6
  const nuxt = kit.useNuxt();
12
7
  if (template.filename) {
13
8
  nuxt.options.nitro.virtual = nuxt.options.nitro.virtual || {};
14
9
  nuxt.options.nitro.virtual[template.filename] = template.getContents;
15
10
  }
16
-
17
11
  return template;
18
12
  }
19
13
 
@@ -1 +1 @@
1
- {"version":3,"file":"server-template.js","sources":["../../../src/vendor/server-template.ts"],"sourcesContent":["import { useNuxt } from '@nuxt/kit';\nimport type { NuxtTemplate } from '@nuxt/schema';\n\n/**\n * Adds a virtual file that can be used within the Nuxt Nitro server build.\n * Available in NuxtKit v4, so we are porting it here.\n * https://github.com/nuxt/nuxt/blob/d6df732eec1a3bd442bdb325b0335beb7e10cd64/packages/kit/src/template.ts#L55-L62\n */\nexport function addServerTemplate(template: NuxtTemplate): NuxtTemplate {\n const nuxt = useNuxt();\n if (template.filename) {\n nuxt.options.nitro.virtual = nuxt.options.nitro.virtual || {};\n nuxt.options.nitro.virtual[template.filename] = template.getContents;\n }\n\n return template;\n}\n"],"names":["useNuxt"],"mappings":";;;;AAGA;AACA;AACA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,QAAQ,EAA8B;AACxE,EAAE,MAAM,IAAA,GAAOA,WAAO,EAAE;AACxB,EAAE,IAAI,QAAQ,CAAC,QAAQ,EAAE;AACzB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAA,GAAU,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAA,IAAW,EAAE;AACjE,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAA,GAAI,QAAQ,CAAC,WAAW;AACxE,EAAE;;AAEF,EAAE,OAAO,QAAQ;AACjB;;;;"}
1
+ {"version":3,"file":"server-template.js","sources":["../../../src/vendor/server-template.ts"],"sourcesContent":["import { useNuxt } from '@nuxt/kit';\nimport type { NuxtTemplate } from '@nuxt/schema';\n\n/**\n * Adds a virtual file that can be used within the Nuxt Nitro server build.\n * Available in NuxtKit v4, so we are porting it here.\n * https://github.com/nuxt/nuxt/blob/d6df732eec1a3bd442bdb325b0335beb7e10cd64/packages/kit/src/template.ts#L55-L62\n */\nexport function addServerTemplate(template: NuxtTemplate): NuxtTemplate {\n const nuxt = useNuxt();\n if (template.filename) {\n nuxt.options.nitro.virtual = nuxt.options.nitro.virtual || {};\n nuxt.options.nitro.virtual[template.filename] = template.getContents;\n }\n\n return template;\n}\n"],"names":["useNuxt"],"mappings":";;;;AAQO,SAAS,kBAAkB,QAAA,EAAsC;AACtE,EAAA,MAAM,OAAOA,WAAA,EAAQ;AACrB,EAAA,IAAI,SAAS,QAAA,EAAU;AACrB,IAAA,IAAA,CAAK,QAAQ,KAAA,CAAM,OAAA,GAAU,KAAK,OAAA,CAAQ,KAAA,CAAM,WAAW,EAAC;AAC5D,IAAA,IAAA,CAAK,QAAQ,KAAA,CAAM,OAAA,CAAQ,QAAA,CAAS,QAAQ,IAAI,QAAA,CAAS,WAAA;AAAA,EAC3D;AAEA,EAAA,OAAO,QAAA;AACT;;;;"}
@@ -6,234 +6,135 @@ const core = require('@sentry/core');
6
6
  const fs = require('fs');
7
7
  const utils = require('./utils.js');
8
8
 
9
- const SERVER_CONFIG_FILENAME = 'sentry.server.config';
10
-
11
- /**
12
- * Adds the `sentry.server.config.ts` file as `sentry.server.config.mjs` to the `.output` directory to be able to reference this file in the node --import option.
13
- *
14
- * By adding a Rollup plugin to the Nitro Rollup options, the Sentry server config is transpiled and emitted to the server build.
15
- */
16
- function addServerConfigToBuild(
17
- moduleOptions,
18
- nitro,
19
- serverConfigFile,
20
- ) {
21
- nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {
22
- if (rollupConfig?.plugins === null || rollupConfig?.plugins === undefined) {
9
+ const SERVER_CONFIG_FILENAME = "sentry.server.config";
10
+ function addServerConfigToBuild(moduleOptions, nitro, serverConfigFile) {
11
+ nitro.hooks.hook("rollup:before", (nitro2, rollupConfig) => {
12
+ if (rollupConfig?.plugins === null || rollupConfig?.plugins === void 0) {
23
13
  rollupConfig.plugins = [];
24
14
  } else if (!Array.isArray(rollupConfig.plugins)) {
25
- // `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin
26
15
  rollupConfig.plugins = [rollupConfig.plugins];
27
16
  }
28
-
29
- rollupConfig.plugins.push(injectServerConfigPlugin(nitro, serverConfigFile, moduleOptions.debug));
17
+ rollupConfig.plugins.push(injectServerConfigPlugin(nitro2, serverConfigFile, moduleOptions.debug));
30
18
  });
31
19
  }
32
-
33
- /**
34
- * Adds the Sentry server config import at the top of the server entry file to load the SDK on the server.
35
- * This is necessary for environments where modifying the node option `--import` is not possible.
36
- * However, only limited tracing instrumentation is supported when doing this.
37
- */
38
20
  function addSentryTopImport(moduleOptions, nitro) {
39
- nitro.hooks.hook('close', async () => {
40
- const fileNameFromCommand =
41
- nitro.options.commands.preview && utils.getFilenameFromNodeStartCommand(nitro.options.commands.preview);
42
-
43
- // other presets ('node-server' or 'vercel') have an index.mjs
44
- const presetsWithServerFile = ['netlify'];
45
-
46
- const entryFileName = fileNameFromCommand
47
- ? fileNameFromCommand
48
- : typeof nitro.options.rollupConfig?.output.entryFileNames === 'string'
49
- ? nitro.options.rollupConfig?.output.entryFileNames
50
- : presetsWithServerFile.includes(nitro.options.preset)
51
- ? 'server.mjs'
52
- : 'index.mjs';
53
-
21
+ nitro.hooks.hook("close", async () => {
22
+ const fileNameFromCommand = nitro.options.commands.preview && utils.getFilenameFromNodeStartCommand(nitro.options.commands.preview);
23
+ const presetsWithServerFile = ["netlify"];
24
+ const entryFileName = fileNameFromCommand ? fileNameFromCommand : typeof nitro.options.rollupConfig?.output.entryFileNames === "string" ? nitro.options.rollupConfig?.output.entryFileNames : presetsWithServerFile.includes(nitro.options.preset) ? "server.mjs" : "index.mjs";
54
25
  const serverDirResolver = kit.createResolver(nitro.options.output.serverDir);
55
26
  const entryFilePath = serverDirResolver.resolve(entryFileName);
56
-
57
27
  try {
58
- fs.readFile(entryFilePath, 'utf8', (err, data) => {
59
- const updatedContent = `import './${SERVER_CONFIG_FILENAME}.mjs';\n${data}`;
60
-
61
- fs.writeFile(entryFilePath, updatedContent, 'utf8', () => {
28
+ fs.readFile(entryFilePath, "utf8", (err, data) => {
29
+ const updatedContent = `import './${SERVER_CONFIG_FILENAME}.mjs';
30
+ ${data}`;
31
+ fs.writeFile(entryFilePath, updatedContent, "utf8", () => {
62
32
  if (moduleOptions.debug) {
63
- // eslint-disable-next-line no-console
64
33
  console.log(
65
- `[Sentry] Successfully added the Sentry import to the server entry file "\`${entryFilePath}\`"`,
34
+ `[Sentry] Successfully added the Sentry import to the server entry file "\`${entryFilePath}\`"`
66
35
  );
67
36
  }
68
37
  });
69
38
  });
70
39
  } catch (err) {
71
40
  if (moduleOptions.debug) {
72
- // eslint-disable-next-line no-console
73
41
  console.warn(
74
42
  `[Sentry] An error occurred when trying to add the Sentry import to the server entry file "\`${entryFilePath}\`":`,
75
- err,
43
+ err
76
44
  );
77
45
  }
78
46
  }
79
47
  });
80
48
  }
81
-
82
- /**
83
- * This function modifies the Rollup configuration to include a plugin that wraps the entry file with a dynamic import (`import()`)
84
- * and adds the Sentry server config with the static `import` declaration.
85
- *
86
- * With this, the Sentry server config can be loaded before all other modules of the application (which is needed for import-in-the-middle).
87
- * See: https://nodejs.org/api/module.html#enabling
88
- */
89
- function addDynamicImportEntryFileWrapper(
90
- nitro,
91
- serverConfigFile,
92
- moduleOptions
93
- ,
94
- ) {
49
+ function addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions) {
95
50
  if (!nitro.options.rollupConfig) {
96
51
  nitro.options.rollupConfig = { output: {} };
97
52
  }
98
-
99
- if (nitro.options.rollupConfig?.plugins === null || nitro.options.rollupConfig?.plugins === undefined) {
53
+ if (nitro.options.rollupConfig?.plugins === null || nitro.options.rollupConfig?.plugins === void 0) {
100
54
  nitro.options.rollupConfig.plugins = [];
101
55
  } else if (!Array.isArray(nitro.options.rollupConfig.plugins)) {
102
- // `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin
103
56
  nitro.options.rollupConfig.plugins = [nitro.options.rollupConfig.plugins];
104
57
  }
105
-
106
58
  nitro.options.rollupConfig.plugins.push(
107
59
  wrapEntryWithDynamicImport({
108
60
  resolvedSentryConfigPath: kit.createResolver(nitro.options.rootDir).resolve(`/${serverConfigFile}`),
109
- experimental_entrypointWrappedFunctions: moduleOptions.experimental_entrypointWrappedFunctions,
110
- }),
61
+ experimental_entrypointWrappedFunctions: moduleOptions.experimental_entrypointWrappedFunctions
62
+ })
111
63
  );
112
64
  }
113
-
114
- /**
115
- * Rollup plugin to include the Sentry server configuration file to the server build output.
116
- */
117
65
  function injectServerConfigPlugin(nitro, serverConfigFile, isDebug) {
118
- const filePrefix = '\0virtual:sentry-server-config:';
119
-
66
+ const filePrefix = "\0virtual:sentry-server-config:";
120
67
  return {
121
- name: 'rollup-plugin-inject-sentry-server-config',
122
-
68
+ name: "rollup-plugin-inject-sentry-server-config",
123
69
  buildStart() {
124
70
  const configPath = kit.createResolver(nitro.options.rootDir).resolve(`/${serverConfigFile}`);
125
-
126
71
  if (!node_fs.existsSync(configPath)) {
127
72
  if (isDebug) {
128
73
  core.debug.log(`[Sentry] Sentry server config file not found: ${configPath}`);
129
74
  }
130
75
  return;
131
76
  }
132
-
133
- // Emitting a file adds it to the build output (Rollup is aware of the file, and we can later return the code in resolveId)
134
77
  this.emitFile({
135
- type: 'chunk',
78
+ type: "chunk",
136
79
  id: `${filePrefix}${serverConfigFile}`,
137
- fileName: `${SERVER_CONFIG_FILENAME}.mjs`,
80
+ fileName: `${SERVER_CONFIG_FILENAME}.mjs`
138
81
  });
139
82
  },
140
-
141
83
  resolveId(source) {
142
84
  if (source.startsWith(filePrefix)) {
143
- const originalFilePath = source.replace(filePrefix, '');
85
+ const originalFilePath = source.replace(filePrefix, "");
144
86
  const configPath = kit.createResolver(nitro.options.rootDir).resolve(`/${originalFilePath}`);
145
-
146
87
  return { id: configPath };
147
88
  }
148
89
  return null;
149
- },
90
+ }
150
91
  };
151
92
  }
152
-
153
- /**
154
- * A Rollup plugin which wraps the server entry with a dynamic `import()`. This makes it possible to initialize Sentry first
155
- * by using a regular `import` and load the server after that.
156
- * This also works with serverless `handler` functions, as it re-exports the `handler`.
157
- */
158
93
  function wrapEntryWithDynamicImport({
159
94
  resolvedSentryConfigPath,
160
95
  experimental_entrypointWrappedFunctions,
161
- debug,
162
- }
163
-
164
- ) {
165
- // In order to correctly import the server config file
166
- // and dynamically import the nitro runtime, we need to
167
- // mark the resolutionId with '\0raw' to fall into the
168
- // raw chunk group, c.f. https://github.com/nitrojs/nitro/commit/8b4a408231bdc222569a32ce109796a41eac4aa6#diff-e58102d2230f95ddeef2662957b48d847a6e891e354cfd0ae6e2e03ce848d1a2R142
169
- const resolutionIdPrefix = '\0raw';
170
-
96
+ debug: debug2
97
+ }) {
98
+ const resolutionIdPrefix = "\0raw";
171
99
  return {
172
- name: 'sentry-wrap-entry-with-dynamic-import',
100
+ name: "sentry-wrap-entry-with-dynamic-import",
173
101
  async resolveId(source, importer, options) {
174
102
  if (source.includes(`/${SERVER_CONFIG_FILENAME}`)) {
175
103
  return { id: source, moduleSideEffects: true };
176
104
  }
177
-
178
- if (source === 'import-in-the-middle/hook.mjs') {
179
- // We are importing "import-in-the-middle" in the returned code of the `load()` function below
180
- // By setting `moduleSideEffects` to `true`, the import is added to the bundle, although nothing is imported from it
181
- // By importing "import-in-the-middle/hook.mjs", we can make sure this file is included, as not all node builders are including files imported with `module.register()`.
182
- // Prevents the error "Failed to register ESM hook Error: Cannot find module 'import-in-the-middle/hook.mjs'"
105
+ if (source === "import-in-the-middle/hook.mjs") {
183
106
  return { id: source, moduleSideEffects: true, external: true };
184
107
  }
185
-
186
- if (options.isEntry && source.includes('.mjs') && !source.includes(`.mjs${utils.SENTRY_WRAPPED_ENTRY}`)) {
108
+ if (options.isEntry && source.includes(".mjs") && !source.includes(`.mjs${utils.SENTRY_WRAPPED_ENTRY}`)) {
187
109
  const resolution = await this.resolve(source, importer, options);
188
-
189
- // If it cannot be resolved or is external, just return it so that Rollup can display an error
190
110
  if (!resolution || resolution?.external) return resolution;
191
-
192
111
  const moduleInfo = await this.load(resolution);
193
-
194
112
  moduleInfo.moduleSideEffects = true;
195
-
196
- // The enclosing `if` already checks for the suffix in `source`, but a check in `resolution.id` is needed as well to prevent multiple attachment of the suffix
197
- return resolution.id.includes(`.mjs${utils.SENTRY_WRAPPED_ENTRY}`)
198
- ? resolution.id
199
- : `${resolutionIdPrefix}${resolution.id
200
- // Concatenates the query params to mark the file (also attaches names of re-exports - this is needed for serverless functions to re-export the handler)
201
- .concat(utils.SENTRY_WRAPPED_ENTRY)
202
- .concat(
203
- utils.constructWrappedFunctionExportQuery(
204
- moduleInfo.exportedBindings,
205
- experimental_entrypointWrappedFunctions,
206
- debug,
207
- ),
208
- )
209
- .concat(utils.QUERY_END_INDICATOR)}`;
113
+ return resolution.id.includes(`.mjs${utils.SENTRY_WRAPPED_ENTRY}`) ? resolution.id : `${resolutionIdPrefix}${resolution.id.concat(utils.SENTRY_WRAPPED_ENTRY).concat(
114
+ utils.constructWrappedFunctionExportQuery(
115
+ moduleInfo.exportedBindings,
116
+ experimental_entrypointWrappedFunctions,
117
+ debug2
118
+ )
119
+ ).concat(utils.QUERY_END_INDICATOR)}`;
210
120
  }
211
121
  return null;
212
122
  },
213
123
  load(id) {
214
124
  if (id.includes(`.mjs${utils.SENTRY_WRAPPED_ENTRY}`)) {
215
125
  const entryId = utils.removeSentryQueryFromPath(id).slice(resolutionIdPrefix.length);
216
-
217
- // Mostly useful for serverless `handler` functions
218
- const reExportedFunctions =
219
- id.includes(utils.SENTRY_WRAPPED_FUNCTIONS) || id.includes(utils.SENTRY_REEXPORTED_FUNCTIONS)
220
- ? utils.constructFunctionReExport(id, entryId)
221
- : '';
222
-
126
+ const reExportedFunctions = id.includes(utils.SENTRY_WRAPPED_FUNCTIONS) || id.includes(utils.SENTRY_REEXPORTED_FUNCTIONS) ? utils.constructFunctionReExport(id, entryId) : "";
223
127
  return (
224
128
  // Regular `import` of the Sentry config
225
- `import ${JSON.stringify(resolvedSentryConfigPath)};\n` +
226
- // Dynamic `import()` for the previous, actual entry point.
227
- // `import()` can be used for any code that should be run after the hooks are registered (https://nodejs.org/api/module.html#enabling)
228
- `import(${JSON.stringify(entryId)});\n` +
229
- // By importing "import-in-the-middle/hook.mjs", we can make sure this file wil be included, as not all node builders are including files imported with `module.register()`.
230
- "import 'import-in-the-middle/hook.mjs';\n" +
231
- `${reExportedFunctions}\n`
129
+ `import ${JSON.stringify(resolvedSentryConfigPath)};
130
+ import(${JSON.stringify(entryId)});
131
+ import 'import-in-the-middle/hook.mjs';
132
+ ${reExportedFunctions}
133
+ `
232
134
  );
233
135
  }
234
-
235
136
  return null;
236
- },
137
+ }
237
138
  };
238
139
  }
239
140
 
@@ -1 +1 @@
1
- {"version":3,"file":"addServerConfig.js","sources":["../../../src/vite/addServerConfig.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { createResolver } from '@nuxt/kit';\nimport { debug } from '@sentry/core';\nimport * as fs from 'fs';\nimport type { Nitro } from 'nitropack';\nimport type { InputPluginOption } from 'rollup';\nimport type { SentryNuxtModuleOptions } from '../common/types';\nimport {\n constructFunctionReExport,\n constructWrappedFunctionExportQuery,\n getFilenameFromNodeStartCommand,\n QUERY_END_INDICATOR,\n removeSentryQueryFromPath,\n SENTRY_REEXPORTED_FUNCTIONS,\n SENTRY_WRAPPED_ENTRY,\n SENTRY_WRAPPED_FUNCTIONS,\n} from './utils';\n\nconst SERVER_CONFIG_FILENAME = 'sentry.server.config';\n\n/**\n * Adds the `sentry.server.config.ts` file as `sentry.server.config.mjs` to the `.output` directory to be able to reference this file in the node --import option.\n *\n * By adding a Rollup plugin to the Nitro Rollup options, the Sentry server config is transpiled and emitted to the server build.\n */\nexport function addServerConfigToBuild(\n moduleOptions: SentryNuxtModuleOptions,\n nitro: Nitro,\n serverConfigFile: string,\n): void {\n nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {\n if (rollupConfig?.plugins === null || rollupConfig?.plugins === undefined) {\n rollupConfig.plugins = [];\n } else if (!Array.isArray(rollupConfig.plugins)) {\n // `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin\n rollupConfig.plugins = [rollupConfig.plugins];\n }\n\n rollupConfig.plugins.push(injectServerConfigPlugin(nitro, serverConfigFile, moduleOptions.debug));\n });\n}\n\n/**\n * Adds the Sentry server config import at the top of the server entry file to load the SDK on the server.\n * This is necessary for environments where modifying the node option `--import` is not possible.\n * However, only limited tracing instrumentation is supported when doing this.\n */\nexport function addSentryTopImport(moduleOptions: SentryNuxtModuleOptions, nitro: Nitro): void {\n nitro.hooks.hook('close', async () => {\n const fileNameFromCommand =\n nitro.options.commands.preview && getFilenameFromNodeStartCommand(nitro.options.commands.preview);\n\n // other presets ('node-server' or 'vercel') have an index.mjs\n const presetsWithServerFile = ['netlify'];\n\n const entryFileName = fileNameFromCommand\n ? fileNameFromCommand\n : typeof nitro.options.rollupConfig?.output.entryFileNames === 'string'\n ? nitro.options.rollupConfig?.output.entryFileNames\n : presetsWithServerFile.includes(nitro.options.preset)\n ? 'server.mjs'\n : 'index.mjs';\n\n const serverDirResolver = createResolver(nitro.options.output.serverDir);\n const entryFilePath = serverDirResolver.resolve(entryFileName);\n\n try {\n fs.readFile(entryFilePath, 'utf8', (err, data) => {\n const updatedContent = `import './${SERVER_CONFIG_FILENAME}.mjs';\\n${data}`;\n\n fs.writeFile(entryFilePath, updatedContent, 'utf8', () => {\n if (moduleOptions.debug) {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] Successfully added the Sentry import to the server entry file \"\\`${entryFilePath}\\`\"`,\n );\n }\n });\n });\n } catch (err) {\n if (moduleOptions.debug) {\n // eslint-disable-next-line no-console\n console.warn(\n `[Sentry] An error occurred when trying to add the Sentry import to the server entry file \"\\`${entryFilePath}\\`\":`,\n err,\n );\n }\n }\n });\n}\n\n/**\n * This function modifies the Rollup configuration to include a plugin that wraps the entry file with a dynamic import (`import()`)\n * and adds the Sentry server config with the static `import` declaration.\n *\n * With this, the Sentry server config can be loaded before all other modules of the application (which is needed for import-in-the-middle).\n * See: https://nodejs.org/api/module.html#enabling\n */\nexport function addDynamicImportEntryFileWrapper(\n nitro: Nitro,\n serverConfigFile: string,\n moduleOptions: Omit<SentryNuxtModuleOptions, 'experimental_entrypointWrappedFunctions'> &\n Required<Pick<SentryNuxtModuleOptions, 'experimental_entrypointWrappedFunctions'>>,\n): void {\n if (!nitro.options.rollupConfig) {\n nitro.options.rollupConfig = { output: {} };\n }\n\n if (nitro.options.rollupConfig?.plugins === null || nitro.options.rollupConfig?.plugins === undefined) {\n nitro.options.rollupConfig.plugins = [];\n } else if (!Array.isArray(nitro.options.rollupConfig.plugins)) {\n // `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin\n nitro.options.rollupConfig.plugins = [nitro.options.rollupConfig.plugins];\n }\n\n nitro.options.rollupConfig.plugins.push(\n wrapEntryWithDynamicImport({\n resolvedSentryConfigPath: createResolver(nitro.options.rootDir).resolve(`/${serverConfigFile}`),\n experimental_entrypointWrappedFunctions: moduleOptions.experimental_entrypointWrappedFunctions,\n }),\n );\n}\n\n/**\n * Rollup plugin to include the Sentry server configuration file to the server build output.\n */\nfunction injectServerConfigPlugin(nitro: Nitro, serverConfigFile: string, isDebug?: boolean): InputPluginOption {\n const filePrefix = '\\0virtual:sentry-server-config:';\n\n return {\n name: 'rollup-plugin-inject-sentry-server-config',\n\n buildStart() {\n const configPath = createResolver(nitro.options.rootDir).resolve(`/${serverConfigFile}`);\n\n if (!existsSync(configPath)) {\n if (isDebug) {\n debug.log(`[Sentry] Sentry server config file not found: ${configPath}`);\n }\n return;\n }\n\n // Emitting a file adds it to the build output (Rollup is aware of the file, and we can later return the code in resolveId)\n this.emitFile({\n type: 'chunk',\n id: `${filePrefix}${serverConfigFile}`,\n fileName: `${SERVER_CONFIG_FILENAME}.mjs`,\n });\n },\n\n resolveId(source) {\n if (source.startsWith(filePrefix)) {\n const originalFilePath = source.replace(filePrefix, '');\n const configPath = createResolver(nitro.options.rootDir).resolve(`/${originalFilePath}`);\n\n return { id: configPath };\n }\n return null;\n },\n };\n}\n\n/**\n * A Rollup plugin which wraps the server entry with a dynamic `import()`. This makes it possible to initialize Sentry first\n * by using a regular `import` and load the server after that.\n * This also works with serverless `handler` functions, as it re-exports the `handler`.\n */\nfunction wrapEntryWithDynamicImport({\n resolvedSentryConfigPath,\n experimental_entrypointWrappedFunctions,\n debug,\n}: {\n resolvedSentryConfigPath: string;\n experimental_entrypointWrappedFunctions: string[];\n debug?: boolean;\n}): InputPluginOption {\n // In order to correctly import the server config file\n // and dynamically import the nitro runtime, we need to\n // mark the resolutionId with '\\0raw' to fall into the\n // raw chunk group, c.f. https://github.com/nitrojs/nitro/commit/8b4a408231bdc222569a32ce109796a41eac4aa6#diff-e58102d2230f95ddeef2662957b48d847a6e891e354cfd0ae6e2e03ce848d1a2R142\n const resolutionIdPrefix = '\\0raw';\n\n return {\n name: 'sentry-wrap-entry-with-dynamic-import',\n async resolveId(source, importer, options) {\n if (source.includes(`/${SERVER_CONFIG_FILENAME}`)) {\n return { id: source, moduleSideEffects: true };\n }\n\n if (source === 'import-in-the-middle/hook.mjs') {\n // We are importing \"import-in-the-middle\" in the returned code of the `load()` function below\n // By setting `moduleSideEffects` to `true`, the import is added to the bundle, although nothing is imported from it\n // By importing \"import-in-the-middle/hook.mjs\", we can make sure this file is included, as not all node builders are including files imported with `module.register()`.\n // Prevents the error \"Failed to register ESM hook Error: Cannot find module 'import-in-the-middle/hook.mjs'\"\n return { id: source, moduleSideEffects: true, external: true };\n }\n\n if (options.isEntry && source.includes('.mjs') && !source.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {\n const resolution = await this.resolve(source, importer, options);\n\n // If it cannot be resolved or is external, just return it so that Rollup can display an error\n if (!resolution || resolution?.external) return resolution;\n\n const moduleInfo = await this.load(resolution);\n\n moduleInfo.moduleSideEffects = true;\n\n // The enclosing `if` already checks for the suffix in `source`, but a check in `resolution.id` is needed as well to prevent multiple attachment of the suffix\n return resolution.id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)\n ? resolution.id\n : `${resolutionIdPrefix}${resolution.id\n // Concatenates the query params to mark the file (also attaches names of re-exports - this is needed for serverless functions to re-export the handler)\n .concat(SENTRY_WRAPPED_ENTRY)\n .concat(\n constructWrappedFunctionExportQuery(\n moduleInfo.exportedBindings,\n experimental_entrypointWrappedFunctions,\n debug,\n ),\n )\n .concat(QUERY_END_INDICATOR)}`;\n }\n return null;\n },\n load(id: string) {\n if (id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {\n const entryId = removeSentryQueryFromPath(id).slice(resolutionIdPrefix.length);\n\n // Mostly useful for serverless `handler` functions\n const reExportedFunctions =\n id.includes(SENTRY_WRAPPED_FUNCTIONS) || id.includes(SENTRY_REEXPORTED_FUNCTIONS)\n ? constructFunctionReExport(id, entryId)\n : '';\n\n return (\n // Regular `import` of the Sentry config\n `import ${JSON.stringify(resolvedSentryConfigPath)};\\n` +\n // Dynamic `import()` for the previous, actual entry point.\n // `import()` can be used for any code that should be run after the hooks are registered (https://nodejs.org/api/module.html#enabling)\n `import(${JSON.stringify(entryId)});\\n` +\n // By importing \"import-in-the-middle/hook.mjs\", we can make sure this file wil be included, as not all node builders are including files imported with `module.register()`.\n \"import 'import-in-the-middle/hook.mjs';\\n\" +\n `${reExportedFunctions}\\n`\n );\n }\n\n return null;\n },\n };\n}\n"],"names":["getFilenameFromNodeStartCommand","createResolver","existsSync","debug","SENTRY_WRAPPED_ENTRY","constructWrappedFunctionExportQuery","QUERY_END_INDICATOR","removeSentryQueryFromPath","SENTRY_WRAPPED_FUNCTIONS","SENTRY_REEXPORTED_FUNCTIONS","constructFunctionReExport"],"mappings":";;;;;;;;AAkBA,MAAM,sBAAA,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A,CAAA;;AAEA;AACA,QAAA,MAAA,mBAAA;AACA,UAAA,EAAA,CAAA,QAAA,CAAAC,8BAAA,CAAA,IAAA,EAAA,CAAA,QAAA,CAAAC,iCAAA;AACA,cAAAC,+BAAA,CAAA,EAAA,EAAA,OAAA;AACA,cAAA,EAAA;;AAEA,QAAA;AACA;AACA,UAAA,CAAA,OAAA,EAAA,IAAA,CAAA,SAAA,CAAA,wBAAA,CAAA,CAAA,GAAA,CAAA;AACA;AACA;AACA,UAAA,CAAA,OAAA,EAAA,IAAA,CAAA,SAAA,CAAA,OAAA,CAAA,CAAA,IAAA,CAAA;AACA;AACA,UAAA,2CAAA;AACA,UAAA,CAAA,EAAA,mBAAA,CAAA,EAAA;AACA;AACA,MAAA;;AAEA,MAAA,OAAA,IAAA;AACA,IAAA,CAAA;AACA,GAAA;AACA;;;;;;"}
1
+ {"version":3,"file":"addServerConfig.js","sources":["../../../src/vite/addServerConfig.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { createResolver } from '@nuxt/kit';\nimport { debug } from '@sentry/core';\nimport * as fs from 'fs';\nimport type { Nitro } from 'nitropack';\nimport type { InputPluginOption } from 'rollup';\nimport type { SentryNuxtModuleOptions } from '../common/types';\nimport {\n constructFunctionReExport,\n constructWrappedFunctionExportQuery,\n getFilenameFromNodeStartCommand,\n QUERY_END_INDICATOR,\n removeSentryQueryFromPath,\n SENTRY_REEXPORTED_FUNCTIONS,\n SENTRY_WRAPPED_ENTRY,\n SENTRY_WRAPPED_FUNCTIONS,\n} from './utils';\n\nconst SERVER_CONFIG_FILENAME = 'sentry.server.config';\n\n/**\n * Adds the `sentry.server.config.ts` file as `sentry.server.config.mjs` to the `.output` directory to be able to reference this file in the node --import option.\n *\n * By adding a Rollup plugin to the Nitro Rollup options, the Sentry server config is transpiled and emitted to the server build.\n */\nexport function addServerConfigToBuild(\n moduleOptions: SentryNuxtModuleOptions,\n nitro: Nitro,\n serverConfigFile: string,\n): void {\n nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {\n if (rollupConfig?.plugins === null || rollupConfig?.plugins === undefined) {\n rollupConfig.plugins = [];\n } else if (!Array.isArray(rollupConfig.plugins)) {\n // `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin\n rollupConfig.plugins = [rollupConfig.plugins];\n }\n\n rollupConfig.plugins.push(injectServerConfigPlugin(nitro, serverConfigFile, moduleOptions.debug));\n });\n}\n\n/**\n * Adds the Sentry server config import at the top of the server entry file to load the SDK on the server.\n * This is necessary for environments where modifying the node option `--import` is not possible.\n * However, only limited tracing instrumentation is supported when doing this.\n */\nexport function addSentryTopImport(moduleOptions: SentryNuxtModuleOptions, nitro: Nitro): void {\n nitro.hooks.hook('close', async () => {\n const fileNameFromCommand =\n nitro.options.commands.preview && getFilenameFromNodeStartCommand(nitro.options.commands.preview);\n\n // other presets ('node-server' or 'vercel') have an index.mjs\n const presetsWithServerFile = ['netlify'];\n\n const entryFileName = fileNameFromCommand\n ? fileNameFromCommand\n : typeof nitro.options.rollupConfig?.output.entryFileNames === 'string'\n ? nitro.options.rollupConfig?.output.entryFileNames\n : presetsWithServerFile.includes(nitro.options.preset)\n ? 'server.mjs'\n : 'index.mjs';\n\n const serverDirResolver = createResolver(nitro.options.output.serverDir);\n const entryFilePath = serverDirResolver.resolve(entryFileName);\n\n try {\n fs.readFile(entryFilePath, 'utf8', (err, data) => {\n const updatedContent = `import './${SERVER_CONFIG_FILENAME}.mjs';\\n${data}`;\n\n fs.writeFile(entryFilePath, updatedContent, 'utf8', () => {\n if (moduleOptions.debug) {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] Successfully added the Sentry import to the server entry file \"\\`${entryFilePath}\\`\"`,\n );\n }\n });\n });\n } catch (err) {\n if (moduleOptions.debug) {\n // eslint-disable-next-line no-console\n console.warn(\n `[Sentry] An error occurred when trying to add the Sentry import to the server entry file \"\\`${entryFilePath}\\`\":`,\n err,\n );\n }\n }\n });\n}\n\n/**\n * This function modifies the Rollup configuration to include a plugin that wraps the entry file with a dynamic import (`import()`)\n * and adds the Sentry server config with the static `import` declaration.\n *\n * With this, the Sentry server config can be loaded before all other modules of the application (which is needed for import-in-the-middle).\n * See: https://nodejs.org/api/module.html#enabling\n */\nexport function addDynamicImportEntryFileWrapper(\n nitro: Nitro,\n serverConfigFile: string,\n moduleOptions: Omit<SentryNuxtModuleOptions, 'experimental_entrypointWrappedFunctions'> &\n Required<Pick<SentryNuxtModuleOptions, 'experimental_entrypointWrappedFunctions'>>,\n): void {\n if (!nitro.options.rollupConfig) {\n nitro.options.rollupConfig = { output: {} };\n }\n\n if (nitro.options.rollupConfig?.plugins === null || nitro.options.rollupConfig?.plugins === undefined) {\n nitro.options.rollupConfig.plugins = [];\n } else if (!Array.isArray(nitro.options.rollupConfig.plugins)) {\n // `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin\n nitro.options.rollupConfig.plugins = [nitro.options.rollupConfig.plugins];\n }\n\n nitro.options.rollupConfig.plugins.push(\n wrapEntryWithDynamicImport({\n resolvedSentryConfigPath: createResolver(nitro.options.rootDir).resolve(`/${serverConfigFile}`),\n experimental_entrypointWrappedFunctions: moduleOptions.experimental_entrypointWrappedFunctions,\n }),\n );\n}\n\n/**\n * Rollup plugin to include the Sentry server configuration file to the server build output.\n */\nfunction injectServerConfigPlugin(nitro: Nitro, serverConfigFile: string, isDebug?: boolean): InputPluginOption {\n const filePrefix = '\\0virtual:sentry-server-config:';\n\n return {\n name: 'rollup-plugin-inject-sentry-server-config',\n\n buildStart() {\n const configPath = createResolver(nitro.options.rootDir).resolve(`/${serverConfigFile}`);\n\n if (!existsSync(configPath)) {\n if (isDebug) {\n debug.log(`[Sentry] Sentry server config file not found: ${configPath}`);\n }\n return;\n }\n\n // Emitting a file adds it to the build output (Rollup is aware of the file, and we can later return the code in resolveId)\n this.emitFile({\n type: 'chunk',\n id: `${filePrefix}${serverConfigFile}`,\n fileName: `${SERVER_CONFIG_FILENAME}.mjs`,\n });\n },\n\n resolveId(source) {\n if (source.startsWith(filePrefix)) {\n const originalFilePath = source.replace(filePrefix, '');\n const configPath = createResolver(nitro.options.rootDir).resolve(`/${originalFilePath}`);\n\n return { id: configPath };\n }\n return null;\n },\n };\n}\n\n/**\n * A Rollup plugin which wraps the server entry with a dynamic `import()`. This makes it possible to initialize Sentry first\n * by using a regular `import` and load the server after that.\n * This also works with serverless `handler` functions, as it re-exports the `handler`.\n */\nfunction wrapEntryWithDynamicImport({\n resolvedSentryConfigPath,\n experimental_entrypointWrappedFunctions,\n debug,\n}: {\n resolvedSentryConfigPath: string;\n experimental_entrypointWrappedFunctions: string[];\n debug?: boolean;\n}): InputPluginOption {\n // In order to correctly import the server config file\n // and dynamically import the nitro runtime, we need to\n // mark the resolutionId with '\\0raw' to fall into the\n // raw chunk group, c.f. https://github.com/nitrojs/nitro/commit/8b4a408231bdc222569a32ce109796a41eac4aa6#diff-e58102d2230f95ddeef2662957b48d847a6e891e354cfd0ae6e2e03ce848d1a2R142\n const resolutionIdPrefix = '\\0raw';\n\n return {\n name: 'sentry-wrap-entry-with-dynamic-import',\n async resolveId(source, importer, options) {\n if (source.includes(`/${SERVER_CONFIG_FILENAME}`)) {\n return { id: source, moduleSideEffects: true };\n }\n\n if (source === 'import-in-the-middle/hook.mjs') {\n // We are importing \"import-in-the-middle\" in the returned code of the `load()` function below\n // By setting `moduleSideEffects` to `true`, the import is added to the bundle, although nothing is imported from it\n // By importing \"import-in-the-middle/hook.mjs\", we can make sure this file is included, as not all node builders are including files imported with `module.register()`.\n // Prevents the error \"Failed to register ESM hook Error: Cannot find module 'import-in-the-middle/hook.mjs'\"\n return { id: source, moduleSideEffects: true, external: true };\n }\n\n if (options.isEntry && source.includes('.mjs') && !source.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {\n const resolution = await this.resolve(source, importer, options);\n\n // If it cannot be resolved or is external, just return it so that Rollup can display an error\n if (!resolution || resolution?.external) return resolution;\n\n const moduleInfo = await this.load(resolution);\n\n moduleInfo.moduleSideEffects = true;\n\n // The enclosing `if` already checks for the suffix in `source`, but a check in `resolution.id` is needed as well to prevent multiple attachment of the suffix\n return resolution.id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)\n ? resolution.id\n : `${resolutionIdPrefix}${resolution.id\n // Concatenates the query params to mark the file (also attaches names of re-exports - this is needed for serverless functions to re-export the handler)\n .concat(SENTRY_WRAPPED_ENTRY)\n .concat(\n constructWrappedFunctionExportQuery(\n moduleInfo.exportedBindings,\n experimental_entrypointWrappedFunctions,\n debug,\n ),\n )\n .concat(QUERY_END_INDICATOR)}`;\n }\n return null;\n },\n load(id: string) {\n if (id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {\n const entryId = removeSentryQueryFromPath(id).slice(resolutionIdPrefix.length);\n\n // Mostly useful for serverless `handler` functions\n const reExportedFunctions =\n id.includes(SENTRY_WRAPPED_FUNCTIONS) || id.includes(SENTRY_REEXPORTED_FUNCTIONS)\n ? constructFunctionReExport(id, entryId)\n : '';\n\n return (\n // Regular `import` of the Sentry config\n `import ${JSON.stringify(resolvedSentryConfigPath)};\\n` +\n // Dynamic `import()` for the previous, actual entry point.\n // `import()` can be used for any code that should be run after the hooks are registered (https://nodejs.org/api/module.html#enabling)\n `import(${JSON.stringify(entryId)});\\n` +\n // By importing \"import-in-the-middle/hook.mjs\", we can make sure this file wil be included, as not all node builders are including files imported with `module.register()`.\n \"import 'import-in-the-middle/hook.mjs';\\n\" +\n `${reExportedFunctions}\\n`\n );\n }\n\n return null;\n },\n };\n}\n"],"names":["nitro","getFilenameFromNodeStartCommand","createResolver","existsSync","debug","SENTRY_WRAPPED_ENTRY","constructWrappedFunctionExportQuery","QUERY_END_INDICATOR","removeSentryQueryFromPath","SENTRY_WRAPPED_FUNCTIONS","SENTRY_REEXPORTED_FUNCTIONS","constructFunctionReExport"],"mappings":";;;;;;;;AAkBA,MAAM,sBAAA,GAAyB,sBAAA;AAOxB,SAAS,sBAAA,CACd,aAAA,EACA,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