@sentry/svelte 8.0.0-alpha.4 → 8.0.0-alpha.7

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.
package/cjs/config.js CHANGED
@@ -32,8 +32,6 @@ function withSentryConfig(
32
32
 
33
33
  const shouldTrackComponents = mergedOptions.componentTracking && mergedOptions.componentTracking.trackComponents;
34
34
  if (shouldTrackComponents) {
35
- // TODO(v8): Remove eslint rule
36
- // eslint-disable-next-line deprecation/deprecation
37
35
  const firstPassPreproc = preprocessors.componentTrackingPreprocessor(mergedOptions.componentTracking);
38
36
  sentryPreprocessors.set(firstPassPreproc.sentryId || '', firstPassPreproc);
39
37
  }
package/cjs/config.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../../src/config.ts"],"sourcesContent":["import type { PreprocessorGroup } from 'svelte/types/compiler/preprocess';\n\nimport { componentTrackingPreprocessor, defaultComponentTrackingOptions } from './preprocessors';\nimport type { SentryPreprocessorGroup, SentrySvelteConfigOptions, SvelteConfig } from './types';\n\nconst DEFAULT_SENTRY_OPTIONS: SentrySvelteConfigOptions = {\n componentTracking: defaultComponentTrackingOptions,\n};\n\n/**\n * Add Sentry options to the Svelte config to be exported from the user's `svelte.config.js` file.\n *\n * @param originalConfig The existing config to be exported prior to adding Sentry\n * @param sentryOptions The configuration of the Sentry-added options\n *\n * @return The wrapped and modified config to be exported\n */\nexport function withSentryConfig(\n originalConfig: SvelteConfig,\n sentryOptions?: SentrySvelteConfigOptions,\n): SvelteConfig {\n const mergedOptions = {\n ...DEFAULT_SENTRY_OPTIONS,\n ...sentryOptions,\n };\n\n const originalPreprocessors = getOriginalPreprocessorArray(originalConfig);\n\n // Map is insertion-order-preserving. It's important to add preprocessors\n // to this map in the right order we want to see them being executed.\n // see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\n const sentryPreprocessors = new Map<string, SentryPreprocessorGroup>();\n\n const shouldTrackComponents = mergedOptions.componentTracking && mergedOptions.componentTracking.trackComponents;\n if (shouldTrackComponents) {\n // TODO(v8): Remove eslint rule\n // eslint-disable-next-line deprecation/deprecation\n const firstPassPreproc: SentryPreprocessorGroup = componentTrackingPreprocessor(mergedOptions.componentTracking);\n sentryPreprocessors.set(firstPassPreproc.sentryId || '', firstPassPreproc);\n }\n\n // We prioritize user-added preprocessors, so we don't insert sentry processors if they\n // have already been added by users.\n originalPreprocessors.forEach((p: SentryPreprocessorGroup) => {\n if (p.sentryId) {\n sentryPreprocessors.delete(p.sentryId);\n }\n });\n\n const mergedPreprocessors = [...sentryPreprocessors.values(), ...originalPreprocessors];\n\n return {\n ...originalConfig,\n preprocess: mergedPreprocessors,\n };\n}\n\n/**\n * Standardizes the different ways the user-provided preprocessor option can be specified.\n * Users can specify an array of preprocessors, a single one or no preprocessor.\n *\n * @param originalConfig the user-provided svelte config oject\n * @return an array of preprocessors or an empty array if no preprocessors were specified\n */\nfunction getOriginalPreprocessorArray(originalConfig: SvelteConfig): PreprocessorGroup[] {\n if (originalConfig.preprocess) {\n if (Array.isArray(originalConfig.preprocess)) {\n return originalConfig.preprocess;\n }\n return [originalConfig.preprocess];\n }\n return [];\n}\n"],"names":["defaultComponentTrackingOptions","componentTrackingPreprocessor"],"mappings":";;;;AAKA,MAAM,sBAAsB,GAA8B;AAC1D,EAAE,iBAAiB,EAAEA,6CAA+B;AACpD,CAAC,CAAA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gBAAgB;AAChC,EAAE,cAAc;AAChB,EAAE,aAAa;AACf,EAAgB;AAChB,EAAE,MAAM,gBAAgB;AACxB,IAAI,GAAG,sBAAsB;AAC7B,IAAI,GAAG,aAAa;AACpB,GAAG,CAAA;AACH;AACA,EAAE,MAAM,qBAAsB,GAAE,4BAA4B,CAAC,cAAc,CAAC,CAAA;AAC5E;AACA;AACA;AACA;AACA,EAAE,MAAM,mBAAoB,GAAE,IAAI,GAAG,EAAmC,CAAA;AACxE;AACA,EAAE,MAAM,qBAAsB,GAAE,aAAa,CAAC,iBAAkB,IAAG,aAAa,CAAC,iBAAiB,CAAC,eAAe,CAAA;AAClH,EAAE,IAAI,qBAAqB,EAAE;AAC7B;AACA;AACA,IAAI,MAAM,gBAAgB,GAA4BC,2CAA6B,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAA;AACpH,IAAI,mBAAmB,CAAC,GAAG,CAAC,gBAAgB,CAAC,QAAA,IAAY,EAAE,EAAE,gBAAgB,CAAC,CAAA;AAC9E,GAAE;AACF;AACA;AACA;AACA,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,KAA8B;AAChE,IAAI,IAAI,CAAC,CAAC,QAAQ,EAAE;AACpB,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;AAC5C,KAAI;AACJ,GAAG,CAAC,CAAA;AACJ;AACA,EAAE,MAAM,mBAAA,GAAsB,CAAC,GAAG,mBAAmB,CAAC,MAAM,EAAE,EAAE,GAAG,qBAAqB,CAAC,CAAA;AACzF;AACA,EAAE,OAAO;AACT,IAAI,GAAG,cAAc;AACrB,IAAI,UAAU,EAAE,mBAAmB;AACnC,GAAG,CAAA;AACH,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,4BAA4B,CAAC,cAAc,EAAqC;AACzF,EAAE,IAAI,cAAc,CAAC,UAAU,EAAE;AACjC,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;AAClD,MAAM,OAAO,cAAc,CAAC,UAAU,CAAA;AACtC,KAAI;AACJ,IAAI,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;AACtC,GAAE;AACF,EAAE,OAAO,EAAE,CAAA;AACX;;;;"}
1
+ {"version":3,"file":"config.js","sources":["../../src/config.ts"],"sourcesContent":["import type { PreprocessorGroup } from 'svelte/types/compiler/preprocess';\n\nimport { componentTrackingPreprocessor, defaultComponentTrackingOptions } from './preprocessors';\nimport type { SentryPreprocessorGroup, SentrySvelteConfigOptions, SvelteConfig } from './types';\n\nconst DEFAULT_SENTRY_OPTIONS: SentrySvelteConfigOptions = {\n componentTracking: defaultComponentTrackingOptions,\n};\n\n/**\n * Add Sentry options to the Svelte config to be exported from the user's `svelte.config.js` file.\n *\n * @param originalConfig The existing config to be exported prior to adding Sentry\n * @param sentryOptions The configuration of the Sentry-added options\n *\n * @return The wrapped and modified config to be exported\n */\nexport function withSentryConfig(\n originalConfig: SvelteConfig,\n sentryOptions?: SentrySvelteConfigOptions,\n): SvelteConfig {\n const mergedOptions = {\n ...DEFAULT_SENTRY_OPTIONS,\n ...sentryOptions,\n };\n\n const originalPreprocessors = getOriginalPreprocessorArray(originalConfig);\n\n // Map is insertion-order-preserving. It's important to add preprocessors\n // to this map in the right order we want to see them being executed.\n // see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\n const sentryPreprocessors = new Map<string, SentryPreprocessorGroup>();\n\n const shouldTrackComponents = mergedOptions.componentTracking && mergedOptions.componentTracking.trackComponents;\n if (shouldTrackComponents) {\n const firstPassPreproc: SentryPreprocessorGroup = componentTrackingPreprocessor(mergedOptions.componentTracking);\n sentryPreprocessors.set(firstPassPreproc.sentryId || '', firstPassPreproc);\n }\n\n // We prioritize user-added preprocessors, so we don't insert sentry processors if they\n // have already been added by users.\n originalPreprocessors.forEach((p: SentryPreprocessorGroup) => {\n if (p.sentryId) {\n sentryPreprocessors.delete(p.sentryId);\n }\n });\n\n const mergedPreprocessors = [...sentryPreprocessors.values(), ...originalPreprocessors];\n\n return {\n ...originalConfig,\n preprocess: mergedPreprocessors,\n };\n}\n\n/**\n * Standardizes the different ways the user-provided preprocessor option can be specified.\n * Users can specify an array of preprocessors, a single one or no preprocessor.\n *\n * @param originalConfig the user-provided svelte config oject\n * @return an array of preprocessors or an empty array if no preprocessors were specified\n */\nfunction getOriginalPreprocessorArray(originalConfig: SvelteConfig): PreprocessorGroup[] {\n if (originalConfig.preprocess) {\n if (Array.isArray(originalConfig.preprocess)) {\n return originalConfig.preprocess;\n }\n return [originalConfig.preprocess];\n }\n return [];\n}\n"],"names":["defaultComponentTrackingOptions","componentTrackingPreprocessor"],"mappings":";;;;AAKA,MAAM,sBAAsB,GAA8B;AAC1D,EAAE,iBAAiB,EAAEA,6CAA+B;AACpD,CAAC,CAAA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gBAAgB;AAChC,EAAE,cAAc;AAChB,EAAE,aAAa;AACf,EAAgB;AAChB,EAAE,MAAM,gBAAgB;AACxB,IAAI,GAAG,sBAAsB;AAC7B,IAAI,GAAG,aAAa;AACpB,GAAG,CAAA;AACH;AACA,EAAE,MAAM,qBAAsB,GAAE,4BAA4B,CAAC,cAAc,CAAC,CAAA;AAC5E;AACA;AACA;AACA;AACA,EAAE,MAAM,mBAAoB,GAAE,IAAI,GAAG,EAAmC,CAAA;AACxE;AACA,EAAE,MAAM,qBAAsB,GAAE,aAAa,CAAC,iBAAkB,IAAG,aAAa,CAAC,iBAAiB,CAAC,eAAe,CAAA;AAClH,EAAE,IAAI,qBAAqB,EAAE;AAC7B,IAAI,MAAM,gBAAgB,GAA4BC,2CAA6B,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAA;AACpH,IAAI,mBAAmB,CAAC,GAAG,CAAC,gBAAgB,CAAC,QAAA,IAAY,EAAE,EAAE,gBAAgB,CAAC,CAAA;AAC9E,GAAE;AACF;AACA;AACA;AACA,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,KAA8B;AAChE,IAAI,IAAI,CAAC,CAAC,QAAQ,EAAE;AACpB,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;AAC5C,KAAI;AACJ,GAAG,CAAC,CAAA;AACJ;AACA,EAAE,MAAM,mBAAA,GAAsB,CAAC,GAAG,mBAAmB,CAAC,MAAM,EAAE,EAAE,GAAG,qBAAqB,CAAC,CAAA;AACzF;AACA,EAAE,OAAO;AACT,IAAI,GAAG,cAAc;AACrB,IAAI,UAAU,EAAE,mBAAmB;AACnC,GAAG,CAAA;AACH,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,4BAA4B,CAAC,cAAc,EAAqC;AACzF,EAAE,IAAI,cAAc,CAAC,UAAU,EAAE;AACjC,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;AAClD,MAAM,OAAO,cAAc,CAAC,UAAU,CAAA;AACtC,KAAI;AACJ,IAAI,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;AACtC,GAAE;AACF,EAAE,OAAO,EAAE,CAAA;AACX;;;;"}
package/cjs/index.js CHANGED
@@ -2,14 +2,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
2
2
 
3
3
  const browser = require('@sentry/browser');
4
4
  const sdk = require('./sdk.js');
5
- const preprocessors = require('./preprocessors.js');
6
5
  const performance = require('./performance.js');
7
6
  const config = require('./config.js');
8
7
 
9
8
 
10
9
 
11
10
  exports.init = sdk.init;
12
- exports.componentTrackingPreprocessor = preprocessors.componentTrackingPreprocessor;
13
11
  exports.trackComponent = performance.trackComponent;
14
12
  exports.withSentryConfig = config.withSentryConfig;
15
13
  Object.prototype.hasOwnProperty.call(browser, '__proto__') &&
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;"}
@@ -16,8 +16,10 @@ const defaultTrackComponentOptions
16
16
  /**
17
17
  * Tracks the Svelte component's intialization and mounting operation as well as
18
18
  * updates and records them as spans.
19
+ *
19
20
  * This function is injected automatically into your Svelte components' code
20
- * if you are using the Sentry componentTrackingPreprocessor.
21
+ * if you are using the withSentryConfig wrapper.
22
+ *
21
23
  * Alternatively, you can call it yourself if you don't want to use the preprocessor.
22
24
  */
23
25
  function trackComponent(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"performance.js","sources":["../../src/performance.ts"],"sourcesContent":["import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/types';\nimport { afterUpdate, beforeUpdate, onMount } from 'svelte';\nimport { current_component } from 'svelte/internal';\n\nimport { getRootSpan, startInactiveSpan, withActiveSpan } from '@sentry/core';\nimport { DEFAULT_COMPONENT_NAME, UI_SVELTE_INIT, UI_SVELTE_UPDATE } from './constants';\nimport type { TrackComponentOptions } from './types';\n\nconst defaultTrackComponentOptions: {\n trackInit: boolean;\n trackUpdates: boolean;\n componentName?: string;\n} = {\n trackInit: true,\n trackUpdates: true,\n};\n\n/**\n * Tracks the Svelte component's intialization and mounting operation as well as\n * updates and records them as spans.\n * This function is injected automatically into your Svelte components' code\n * if you are using the Sentry componentTrackingPreprocessor.\n * Alternatively, you can call it yourself if you don't want to use the preprocessor.\n */\nexport function trackComponent(options?: TrackComponentOptions): void {\n const mergedOptions = { ...defaultTrackComponentOptions, ...options };\n\n const customComponentName = mergedOptions.componentName;\n\n // current_component.ctor.name is likely to give us the component's name automatically\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const componentName = `<${customComponentName || current_component.constructor.name || DEFAULT_COMPONENT_NAME}>`;\n\n let initSpan: Span | undefined = undefined;\n if (mergedOptions.trackInit) {\n initSpan = recordInitSpan(componentName);\n }\n\n if (mergedOptions.trackUpdates) {\n recordUpdateSpans(componentName, initSpan);\n }\n}\n\nfunction recordInitSpan(componentName: string): Span | undefined {\n const initSpan = startInactiveSpan({\n onlyIfParent: true,\n op: UI_SVELTE_INIT,\n name: componentName,\n attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },\n });\n\n onMount(() => {\n initSpan.end();\n });\n\n return initSpan;\n}\n\nfunction recordUpdateSpans(componentName: string, initSpan?: Span): void {\n let updateSpan: Span | undefined;\n beforeUpdate(() => {\n // We need to get the active transaction again because the initial one could\n // already be finished or there is currently no transaction going on.\n const activeSpan = getActiveSpan();\n if (!activeSpan) {\n return;\n }\n\n // If we are initializing the component when the update span is started, we start it as child\n // of the init span. Else, we start it as a child of the transaction.\n const parentSpan =\n initSpan && initSpan.isRecording() && getRootSpan(initSpan) === getRootSpan(activeSpan)\n ? initSpan\n : getRootSpan(activeSpan);\n\n if (!parentSpan) return;\n\n updateSpan = withActiveSpan(parentSpan, () => {\n return startInactiveSpan({\n op: UI_SVELTE_UPDATE,\n name: componentName,\n attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },\n });\n });\n });\n\n afterUpdate(() => {\n if (!updateSpan) {\n return;\n }\n updateSpan.end();\n updateSpan = undefined;\n });\n}\n"],"names":["current_component","DEFAULT_COMPONENT_NAME","startInactiveSpan","UI_SVELTE_INIT","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","onMount","beforeUpdate","getActiveSpan","getRootSpan","withActiveSpan","UI_SVELTE_UPDATE","afterUpdate"],"mappings":";;;;;;;;AASA,MAAM,4BAA4B;;AAIlC,GAAI;AACJ,EAAE,SAAS,EAAE,IAAI;AACjB,EAAE,YAAY,EAAE,IAAI;AACpB,CAAC,CAAA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,OAAO,EAAgC;AACtE,EAAE,MAAM,gBAAgB,EAAE,GAAG,4BAA4B,EAAE,GAAG,OAAA,EAAS,CAAA;AACvE;AACA,EAAE,MAAM,mBAAA,GAAsB,aAAa,CAAC,aAAa,CAAA;AACzD;AACA;AACA;AACA,EAAE,MAAM,aAAc,GAAE,CAAC,CAAC,EAAE,mBAAoB,IAAGA,0BAAiB,CAAC,WAAW,CAAC,IAAA,IAAQC,gCA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,OAAM;AAC3B;AACA,IAAI,UAAA,GAAaC,mBAAc,CAAC,UAAU,EAAE,MAAM;AAClD,MAAM,OAAOP,sBAAiB,CAAC;AAC/B,QAAQ,EAAE,EAAEQ,0BAAgB;AAC5B,QAAQ,IAAI,EAAE,aAAa;AAC3B,QAAQ,UAAU,EAAE,EAAE,CAACN,wCAAgC,GAAG,kBAAkB;AAC5E,OAAO,CAAC,CAAA;AACR,KAAK,CAAC,CAAA;AACN,GAAG,CAAC,CAAA;AACJ;AACA,EAAEO,kBAAW,CAAC,MAAM;AACpB,IAAI,IAAI,CAAC,UAAU,EAAE;AACrB,MAAM,OAAM;AACZ,KAAI;AACJ,IAAI,UAAU,CAAC,GAAG,EAAE,CAAA;AACpB,IAAI,UAAA,GAAa,SAAS,CAAA;AAC1B,GAAG,CAAC,CAAA;AACJ;;;;"}
1
+ {"version":3,"file":"performance.js","sources":["../../src/performance.ts"],"sourcesContent":["import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/types';\nimport { afterUpdate, beforeUpdate, onMount } from 'svelte';\nimport { current_component } from 'svelte/internal';\n\nimport { getRootSpan, startInactiveSpan, withActiveSpan } from '@sentry/core';\nimport { DEFAULT_COMPONENT_NAME, UI_SVELTE_INIT, UI_SVELTE_UPDATE } from './constants';\nimport type { TrackComponentOptions } from './types';\n\nconst defaultTrackComponentOptions: {\n trackInit: boolean;\n trackUpdates: boolean;\n componentName?: string;\n} = {\n trackInit: true,\n trackUpdates: true,\n};\n\n/**\n * Tracks the Svelte component's intialization and mounting operation as well as\n * updates and records them as spans.\n *\n * This function is injected automatically into your Svelte components' code\n * if you are using the withSentryConfig wrapper.\n *\n * Alternatively, you can call it yourself if you don't want to use the preprocessor.\n */\nexport function trackComponent(options?: TrackComponentOptions): void {\n const mergedOptions = { ...defaultTrackComponentOptions, ...options };\n\n const customComponentName = mergedOptions.componentName;\n\n // current_component.ctor.name is likely to give us the component's name automatically\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const componentName = `<${customComponentName || current_component.constructor.name || DEFAULT_COMPONENT_NAME}>`;\n\n let initSpan: Span | undefined = undefined;\n if (mergedOptions.trackInit) {\n initSpan = recordInitSpan(componentName);\n }\n\n if (mergedOptions.trackUpdates) {\n recordUpdateSpans(componentName, initSpan);\n }\n}\n\nfunction recordInitSpan(componentName: string): Span | undefined {\n const initSpan = startInactiveSpan({\n onlyIfParent: true,\n op: UI_SVELTE_INIT,\n name: componentName,\n attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },\n });\n\n onMount(() => {\n initSpan.end();\n });\n\n return initSpan;\n}\n\nfunction recordUpdateSpans(componentName: string, initSpan?: Span): void {\n let updateSpan: Span | undefined;\n beforeUpdate(() => {\n // We need to get the active transaction again because the initial one could\n // already be finished or there is currently no transaction going on.\n const activeSpan = getActiveSpan();\n if (!activeSpan) {\n return;\n }\n\n // If we are initializing the component when the update span is started, we start it as child\n // of the init span. Else, we start it as a child of the transaction.\n const parentSpan =\n initSpan && initSpan.isRecording() && getRootSpan(initSpan) === getRootSpan(activeSpan)\n ? initSpan\n : getRootSpan(activeSpan);\n\n if (!parentSpan) return;\n\n updateSpan = withActiveSpan(parentSpan, () => {\n return startInactiveSpan({\n op: UI_SVELTE_UPDATE,\n name: componentName,\n attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },\n });\n });\n });\n\n afterUpdate(() => {\n if (!updateSpan) {\n return;\n }\n updateSpan.end();\n updateSpan = undefined;\n });\n}\n"],"names":["current_component","DEFAULT_COMPONENT_NAME","startInactiveSpan","UI_SVELTE_INIT","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","onMount","beforeUpdate","getActiveSpan","getRootSpan","withActiveSpan","UI_SVELTE_UPDATE","afterUpdate"],"mappings":";;;;;;;;AASA,MAAM,4BAA4B;;AAIlC,GAAI;AACJ,EAAE,SAAS,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C,mBAAY,CAAC,MAAM;AACrB;AACA;AACA,IAAI,MAAM,UAAA,GAAaC,qBAAa,EAAE,CAAA;AACtC,IAAI,IAAI,CAAC,UAAU,EAAE;AACrB,MAAM,OAAM;AACZ,KAAI;AACJ;AACA;AACA;AACA,IAAI,MAAM,UAAW;AACrB,MAAM,QAAS,IAAG,QAAQ,CAAC,WAAW,EAAC,IAAKC,gBAAW,CAAC,QAAQ,CAAA,KAAMA,gBAAW,CAAC,UAAU,CAAA;AAC5F,UAAU,QAAA;AACV,UAAUA,gBAAW,CAAC,UAAU,CAAC,CAAA;AACjC;AACA,IAAI,IAAI,CAAC,UAAU,EAAE,OAAM;AAC3B;AACA,IAAI,UAAA,GAAaC,mBAAc,CAAC,UAAU,EAAE,MAAM;AAClD,MAAM,OAAOP,sBAAiB,CAAC;AAC/B,QAAQ,EAAE,EAAEQ,0BAAgB;AAC5B,QAAQ,IAAI,EAAE,aAAa;AAC3B,QAAQ,UAAU,EAAE,EAAE,CAACN,wCAAgC,GAAG,kBAAkB;AAC5E,OAAO,CAAC,CAAA;AACR,KAAK,CAAC,CAAA;AACN,GAAG,CAAC,CAAA;AACJ;AACA,EAAEO,kBAAW,CAAC,MAAM;AACpB,IAAI,IAAI,CAAC,UAAU,EAAE;AACrB,MAAM,OAAM;AACZ,KAAI;AACJ,IAAI,UAAU,CAAC,GAAG,EAAE,CAAA;AACpB,IAAI,UAAA,GAAa,SAAS,CAAA;AAC1B,GAAG,CAAC,CAAA;AACJ;;;;"}
@@ -13,9 +13,6 @@ const FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID = 'FIRST_PASS_COMPONENT_TRACKING_
13
13
  /**
14
14
  * Svelte Preprocessor to inject Sentry performance monitoring related code
15
15
  * into Svelte components.
16
- *
17
- * @deprecated Use `withSentryConfig` which is the new way of making compile-time modifications
18
- * to Svelte apps going forward.
19
16
  */
20
17
  function componentTrackingPreprocessor(options) {
21
18
  const mergedOptions = { ...defaultComponentTrackingOptions, ...options };
@@ -1 +1 @@
1
- {"version":3,"file":"preprocessors.js","sources":["../../src/preprocessors.ts"],"sourcesContent":["import MagicString from 'magic-string';\nimport type { PreprocessorGroup } from 'svelte/types/compiler/preprocess';\n\nimport type { ComponentTrackingInitOptions, SentryPreprocessorGroup, TrackComponentOptions } from './types';\n\nexport const defaultComponentTrackingOptions: Required<ComponentTrackingInitOptions> = {\n trackComponents: true,\n trackInit: true,\n trackUpdates: true,\n};\n\nexport const FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID = 'FIRST_PASS_COMPONENT_TRACKING_PREPROCESSOR';\n\n/**\n * Svelte Preprocessor to inject Sentry performance monitoring related code\n * into Svelte components.\n *\n * @deprecated Use `withSentryConfig` which is the new way of making compile-time modifications\n * to Svelte apps going forward.\n */\nexport function componentTrackingPreprocessor(options?: ComponentTrackingInitOptions): PreprocessorGroup {\n const mergedOptions = { ...defaultComponentTrackingOptions, ...options };\n\n const visitedFiles = new Set<string>();\n const visitedFilesMarkup = new Set<string>();\n\n const preprocessor: PreprocessorGroup = {\n // This markup hook is called once per .svelte component file, before the `script` hook is called\n // We use it to check if the passed component has a <script> tag. If it doesn't, we add one to inject our\n // code later on, when the `script` hook is executed.\n markup: ({ content, filename }) => {\n const finalFilename = filename || 'unknown';\n const shouldInject = shouldInjectFunction(mergedOptions.trackComponents, finalFilename, {}, visitedFilesMarkup);\n\n if (shouldInject && !hasScriptTag(content)) {\n // Insert a <script> tag into the component file where we can later on inject our code.\n // We have to add a placeholder to the script tag because for empty script tags,\n // the `script` preprocessor hook won't be called\n // Note: The space between <script> and </script> is important! Without any content,\n // the `script` hook wouldn't be executed for the added script tag.\n const s = new MagicString(content);\n s.prepend('<script>\\n</script>\\n');\n return { code: s.toString(), map: s.generateMap().toString() };\n }\n\n return { code: content };\n },\n\n // This script hook is called whenever a Svelte component's <script> content is preprocessed.\n // `content` contains the script code as a string\n script: ({ content, filename, attributes }) => {\n // TODO: Not sure when a filename could be undefined. Using this 'unknown' fallback for the time being\n const finalFilename = filename || 'unknown';\n\n if (!shouldInjectFunction(mergedOptions.trackComponents, finalFilename, attributes, visitedFiles)) {\n return { code: content };\n }\n\n const { trackInit, trackUpdates } = mergedOptions;\n const trackComponentOptions: TrackComponentOptions = {\n trackInit,\n trackUpdates,\n componentName: getBaseName(finalFilename),\n };\n\n const importStmt = 'import { trackComponent } from \"@sentry/svelte\";\\n';\n const functionCall = `trackComponent(${JSON.stringify(trackComponentOptions)});\\n`;\n\n const s = new MagicString(content);\n s.prepend(functionCall).prepend(importStmt);\n\n const updatedCode = s.toString();\n const updatedSourceMap = s.generateMap().toString();\n\n return { code: updatedCode, map: updatedSourceMap };\n },\n };\n\n const sentryPreprocessor: SentryPreprocessorGroup = {\n ...preprocessor,\n sentryId: FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID,\n };\n\n return sentryPreprocessor;\n}\n\nfunction shouldInjectFunction(\n trackComponents: Required<ComponentTrackingInitOptions['trackComponents']>,\n filename: string,\n attributes: Record<string, string | boolean>,\n visitedFiles: Set<string>,\n): boolean {\n // We do cannot inject our function multiple times into the same component\n // This can happen when a component has multiple <script> blocks\n if (visitedFiles.has(filename)) {\n return false;\n }\n visitedFiles.add(filename);\n\n // We can't inject our function call into <script context=\"module\"> blocks\n // because the code inside is not executed when the component is instantiated but\n // when the module is first imported.\n // see: https://svelte.dev/docs#component-format-script-context-module\n if (attributes.context === 'module') {\n return false;\n }\n\n if (!trackComponents) {\n return false;\n }\n\n if (Array.isArray(trackComponents)) {\n const componentName = getBaseName(filename);\n return trackComponents.some(allowed => allowed === componentName);\n }\n\n return true;\n}\n\nfunction getBaseName(filename: string): string {\n const segments = filename.split('/');\n return segments[segments.length - 1].replace('.svelte', '');\n}\n\nfunction hasScriptTag(content: string): boolean {\n // This regex is taken from the Svelte compiler code.\n // They use this regex to find matching script tags that are passed to the `script` preprocessor hook:\n // https://github.com/sveltejs/svelte/blob/bb83eddfc623437528f24e9fe210885b446e72fa/src/compiler/preprocess/index.ts#L144\n // However, we remove the first part of the regex to not match HTML comments\n const scriptTagRegex = /<script(\\s[^]*?)?(?:>([^]*?)<\\/script\\s*>|\\/>)/gi;\n\n // Regex testing is not a super safe way of checking for the presence of a <script> tag in the Svelte\n // component file but I think we can use it as a start.\n // A case that is not covered by regex-testing HTML is e.g. nested <script> tags but I cannot\n // think of why one would do this in Svelte components. For instance, the Svelte compiler errors\n // when there's more than one top-level script tag.\n return scriptTagRegex.test(content);\n}\n"],"names":["MagicString"],"mappings":";;;;AAKO,MAAM,+BAA+B,GAA2C;AACvF,EAAE,eAAe,EAAE,IAAI;AACvB,EAAE,SAAS,EAAE,IAAI;AACjB,EAAE,YAAY,EAAE,IAAI;AACpB,EAAC;AACD;AACO,MAAM,wCAAyC,GAAE,6CAA4C;AACpG;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,6BAA6B,CAAC,OAAO,EAAoD;AACzG,EAAE,MAAM,gBAAgB,EAAE,GAAG,+BAA+B,EAAE,GAAG,OAAA,EAAS,CAAA;AAC1E;AACA,EAAE,MAAM,YAAa,GAAE,IAAI,GAAG,EAAU,CAAA;AACxC,EAAE,MAAM,kBAAmB,GAAE,IAAI,GAAG,EAAU,CAAA;AAC9C;AACA,EAAE,MAAM,YAAY,GAAsB;AAC1C;AACA;AACA;AACA,IAAI,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,QAAA,EAAU,KAAK;AACvC,MAAM,MAAM,aAAA,GAAgB,QAAA,IAAY,SAAS,CAAA;AACjD,MAAM,MAAM,YAAA,GAAe,oBAAoB,CAAC,aAAa,CAAC,eAAe,EAAE,aAAa,EAAE,EAAE,EAAE,kBAAkB,CAAC,CAAA;AACrH;AACA,MAAM,IAAI,YAAa,IAAG,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE;AAClD;AACA;AACA;AACA;AACA;AACA,QAAQ,MAAM,CAAE,GAAE,IAAIA,mBAAW,CAAC,OAAO,CAAC,CAAA;AAC1C,QAAQ,CAAC,CAAC,OAAO,CAA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EAAE,CAAC,CAAA;AAC7D,CAAA;AACA;AACA,SAAS,YAAY,CAAC,OAAO,EAAmB;AAChD;AACA;AACA;AACA;AACA,EAAE,MAAM,cAAe,GAAE,kDAAkD,CAAA;AAC3E;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,OAAO,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACrC;;;;;;"}
1
+ {"version":3,"file":"preprocessors.js","sources":["../../src/preprocessors.ts"],"sourcesContent":["import MagicString from 'magic-string';\nimport type { PreprocessorGroup } from 'svelte/types/compiler/preprocess';\n\nimport type { ComponentTrackingInitOptions, SentryPreprocessorGroup, TrackComponentOptions } from './types';\n\nexport const defaultComponentTrackingOptions: Required<ComponentTrackingInitOptions> = {\n trackComponents: true,\n trackInit: true,\n trackUpdates: true,\n};\n\nexport const FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID = 'FIRST_PASS_COMPONENT_TRACKING_PREPROCESSOR';\n\n/**\n * Svelte Preprocessor to inject Sentry performance monitoring related code\n * into Svelte components.\n */\nexport function componentTrackingPreprocessor(options?: ComponentTrackingInitOptions): PreprocessorGroup {\n const mergedOptions = { ...defaultComponentTrackingOptions, ...options };\n\n const visitedFiles = new Set<string>();\n const visitedFilesMarkup = new Set<string>();\n\n const preprocessor: PreprocessorGroup = {\n // This markup hook is called once per .svelte component file, before the `script` hook is called\n // We use it to check if the passed component has a <script> tag. If it doesn't, we add one to inject our\n // code later on, when the `script` hook is executed.\n markup: ({ content, filename }) => {\n const finalFilename = filename || 'unknown';\n const shouldInject = shouldInjectFunction(mergedOptions.trackComponents, finalFilename, {}, visitedFilesMarkup);\n\n if (shouldInject && !hasScriptTag(content)) {\n // Insert a <script> tag into the component file where we can later on inject our code.\n // We have to add a placeholder to the script tag because for empty script tags,\n // the `script` preprocessor hook won't be called\n // Note: The space between <script> and </script> is important! Without any content,\n // the `script` hook wouldn't be executed for the added script tag.\n const s = new MagicString(content);\n s.prepend('<script>\\n</script>\\n');\n return { code: s.toString(), map: s.generateMap().toString() };\n }\n\n return { code: content };\n },\n\n // This script hook is called whenever a Svelte component's <script> content is preprocessed.\n // `content` contains the script code as a string\n script: ({ content, filename, attributes }) => {\n // TODO: Not sure when a filename could be undefined. Using this 'unknown' fallback for the time being\n const finalFilename = filename || 'unknown';\n\n if (!shouldInjectFunction(mergedOptions.trackComponents, finalFilename, attributes, visitedFiles)) {\n return { code: content };\n }\n\n const { trackInit, trackUpdates } = mergedOptions;\n const trackComponentOptions: TrackComponentOptions = {\n trackInit,\n trackUpdates,\n componentName: getBaseName(finalFilename),\n };\n\n const importStmt = 'import { trackComponent } from \"@sentry/svelte\";\\n';\n const functionCall = `trackComponent(${JSON.stringify(trackComponentOptions)});\\n`;\n\n const s = new MagicString(content);\n s.prepend(functionCall).prepend(importStmt);\n\n const updatedCode = s.toString();\n const updatedSourceMap = s.generateMap().toString();\n\n return { code: updatedCode, map: updatedSourceMap };\n },\n };\n\n const sentryPreprocessor: SentryPreprocessorGroup = {\n ...preprocessor,\n sentryId: FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID,\n };\n\n return sentryPreprocessor;\n}\n\nfunction shouldInjectFunction(\n trackComponents: Required<ComponentTrackingInitOptions['trackComponents']>,\n filename: string,\n attributes: Record<string, string | boolean>,\n visitedFiles: Set<string>,\n): boolean {\n // We do cannot inject our function multiple times into the same component\n // This can happen when a component has multiple <script> blocks\n if (visitedFiles.has(filename)) {\n return false;\n }\n visitedFiles.add(filename);\n\n // We can't inject our function call into <script context=\"module\"> blocks\n // because the code inside is not executed when the component is instantiated but\n // when the module is first imported.\n // see: https://svelte.dev/docs#component-format-script-context-module\n if (attributes.context === 'module') {\n return false;\n }\n\n if (!trackComponents) {\n return false;\n }\n\n if (Array.isArray(trackComponents)) {\n const componentName = getBaseName(filename);\n return trackComponents.some(allowed => allowed === componentName);\n }\n\n return true;\n}\n\nfunction getBaseName(filename: string): string {\n const segments = filename.split('/');\n return segments[segments.length - 1].replace('.svelte', '');\n}\n\nfunction hasScriptTag(content: string): boolean {\n // This regex is taken from the Svelte compiler code.\n // They use this regex to find matching script tags that are passed to the `script` preprocessor hook:\n // https://github.com/sveltejs/svelte/blob/bb83eddfc623437528f24e9fe210885b446e72fa/src/compiler/preprocess/index.ts#L144\n // However, we remove the first part of the regex to not match HTML comments\n const scriptTagRegex = /<script(\\s[^]*?)?(?:>([^]*?)<\\/script\\s*>|\\/>)/gi;\n\n // Regex testing is not a super safe way of checking for the presence of a <script> tag in the Svelte\n // component file but I think we can use it as a start.\n // A case that is not covered by regex-testing HTML is e.g. nested <script> tags but I cannot\n // think of why one would do this in Svelte components. For instance, the Svelte compiler errors\n // when there's more than one top-level script tag.\n return scriptTagRegex.test(content);\n}\n"],"names":["MagicString"],"mappings":";;;;AAKO,MAAM,+BAA+B,GAA2C;AACvF,EAAE,eAAe,EAAE,IAAI;AACvB,EAAE,SAAS,EAAE,IAAI;AACjB,EAAE,YAAY,EAAE,IAAI;AACpB,EAAC;AACD;AACO,MAAM,wCAAyC,GAAE,6CAA4C;AACpG;AACA;AACA;AACA;AACA;AACO,SAAS,6BAA6B,CAAC,OAAO,EAAoD;AACzG,EAAE,MAAM,gBAAgB,EAAE,GAAG,+BAA+B,EAAE,GAAG,OAAA,EAAS,CAAA;AAC1E;AACA,EAAE,MAAM,YAAa,GAAE,IAAI,GAAG,EAAU,CAAA;AACxC,EAAE,MAAM,kBAAmB,GAAE,IAAI,GAAG,EAAU,CAAA;AAC9C;AACA,EAAE,MAAM,YAAY,GAAsB;AAC1C;AACA;AACA;AACA,IAAI,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,QAAA,EAAU,KAAK;AACvC,MAAM,MAAM,aAAA,GAAgB,QAAA,IAAY,SAAS,CAAA;AACjD,MAAM,MAAM,YAAA,GAAe,oBAAoB,CAAC,aAAa,CAAC,eAAe,EAAE,aAAa,EAAE,EAAE,EAAE,kBAAkB,CAAC,CAAA;AACrH;AACA,MAAM,IAAI,YAAa,IAAG,CAAC,YA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AE,MAAM,WAAW,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AACtC,EAAE,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAO,GAAE,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;AAC7D,CAAA;AACA;AACA,SAAS,YAAY,CAAC,OAAO,EAAmB;AAChD;AACA;AACA;AACA;AACA,EAAE,MAAM,cAAe,GAAE,kDAAkD,CAAA;AAC3E;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,OAAO,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACrC;;;;;;"}
package/esm/config.js CHANGED
@@ -30,8 +30,6 @@ function withSentryConfig(
30
30
 
31
31
  const shouldTrackComponents = mergedOptions.componentTracking && mergedOptions.componentTracking.trackComponents;
32
32
  if (shouldTrackComponents) {
33
- // TODO(v8): Remove eslint rule
34
- // eslint-disable-next-line deprecation/deprecation
35
33
  const firstPassPreproc = componentTrackingPreprocessor(mergedOptions.componentTracking);
36
34
  sentryPreprocessors.set(firstPassPreproc.sentryId || '', firstPassPreproc);
37
35
  }
package/esm/config.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../../src/config.ts"],"sourcesContent":["import type { PreprocessorGroup } from 'svelte/types/compiler/preprocess';\n\nimport { componentTrackingPreprocessor, defaultComponentTrackingOptions } from './preprocessors';\nimport type { SentryPreprocessorGroup, SentrySvelteConfigOptions, SvelteConfig } from './types';\n\nconst DEFAULT_SENTRY_OPTIONS: SentrySvelteConfigOptions = {\n componentTracking: defaultComponentTrackingOptions,\n};\n\n/**\n * Add Sentry options to the Svelte config to be exported from the user's `svelte.config.js` file.\n *\n * @param originalConfig The existing config to be exported prior to adding Sentry\n * @param sentryOptions The configuration of the Sentry-added options\n *\n * @return The wrapped and modified config to be exported\n */\nexport function withSentryConfig(\n originalConfig: SvelteConfig,\n sentryOptions?: SentrySvelteConfigOptions,\n): SvelteConfig {\n const mergedOptions = {\n ...DEFAULT_SENTRY_OPTIONS,\n ...sentryOptions,\n };\n\n const originalPreprocessors = getOriginalPreprocessorArray(originalConfig);\n\n // Map is insertion-order-preserving. It's important to add preprocessors\n // to this map in the right order we want to see them being executed.\n // see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\n const sentryPreprocessors = new Map<string, SentryPreprocessorGroup>();\n\n const shouldTrackComponents = mergedOptions.componentTracking && mergedOptions.componentTracking.trackComponents;\n if (shouldTrackComponents) {\n // TODO(v8): Remove eslint rule\n // eslint-disable-next-line deprecation/deprecation\n const firstPassPreproc: SentryPreprocessorGroup = componentTrackingPreprocessor(mergedOptions.componentTracking);\n sentryPreprocessors.set(firstPassPreproc.sentryId || '', firstPassPreproc);\n }\n\n // We prioritize user-added preprocessors, so we don't insert sentry processors if they\n // have already been added by users.\n originalPreprocessors.forEach((p: SentryPreprocessorGroup) => {\n if (p.sentryId) {\n sentryPreprocessors.delete(p.sentryId);\n }\n });\n\n const mergedPreprocessors = [...sentryPreprocessors.values(), ...originalPreprocessors];\n\n return {\n ...originalConfig,\n preprocess: mergedPreprocessors,\n };\n}\n\n/**\n * Standardizes the different ways the user-provided preprocessor option can be specified.\n * Users can specify an array of preprocessors, a single one or no preprocessor.\n *\n * @param originalConfig the user-provided svelte config oject\n * @return an array of preprocessors or an empty array if no preprocessors were specified\n */\nfunction getOriginalPreprocessorArray(originalConfig: SvelteConfig): PreprocessorGroup[] {\n if (originalConfig.preprocess) {\n if (Array.isArray(originalConfig.preprocess)) {\n return originalConfig.preprocess;\n }\n return [originalConfig.preprocess];\n }\n return [];\n}\n"],"names":[],"mappings":";;AAKA,MAAM,sBAAsB,GAA8B;AAC1D,EAAE,iBAAiB,EAAE,+BAA+B;AACpD,CAAC,CAAA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gBAAgB;AAChC,EAAE,cAAc;AAChB,EAAE,aAAa;AACf,EAAgB;AAChB,EAAE,M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AAA;AACtC,KAAI;AACJ,IAAI,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;AACtC,GAAE;AACF,EAAE,OAAO,EAAE,CAAA;AACX;;;;"}
1
+ {"version":3,"file":"config.js","sources":["../../src/config.ts"],"sourcesContent":["import type { PreprocessorGroup } from 'svelte/types/compiler/preprocess';\n\nimport { componentTrackingPreprocessor, defaultComponentTrackingOptions } from './preprocessors';\nimport type { SentryPreprocessorGroup, SentrySvelteConfigOptions, SvelteConfig } from './types';\n\nconst DEFAULT_SENTRY_OPTIONS: SentrySvelteConfigOptions = {\n componentTracking: defaultComponentTrackingOptions,\n};\n\n/**\n * Add Sentry options to the Svelte config to be exported from the user's `svelte.config.js` file.\n *\n * @param originalConfig The existing config to be exported prior to adding Sentry\n * @param sentryOptions The configuration of the Sentry-added options\n *\n * @return The wrapped and modified config to be exported\n */\nexport function withSentryConfig(\n originalConfig: SvelteConfig,\n sentryOptions?: SentrySvelteConfigOptions,\n): SvelteConfig {\n const mergedOptions = {\n ...DEFAULT_SENTRY_OPTIONS,\n ...sentryOptions,\n };\n\n const originalPreprocessors = getOriginalPreprocessorArray(originalConfig);\n\n // Map is insertion-order-preserving. It's important to add preprocessors\n // to this map in the right order we want to see them being executed.\n // see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\n const sentryPreprocessors = new Map<string, SentryPreprocessorGroup>();\n\n const shouldTrackComponents = mergedOptions.componentTracking && mergedOptions.componentTracking.trackComponents;\n if (shouldTrackComponents) {\n const firstPassPreproc: SentryPreprocessorGroup = componentTrackingPreprocessor(mergedOptions.componentTracking);\n sentryPreprocessors.set(firstPassPreproc.sentryId || '', firstPassPreproc);\n }\n\n // We prioritize user-added preprocessors, so we don't insert sentry processors if they\n // have already been added by users.\n originalPreprocessors.forEach((p: SentryPreprocessorGroup) => {\n if (p.sentryId) {\n sentryPreprocessors.delete(p.sentryId);\n }\n });\n\n const mergedPreprocessors = [...sentryPreprocessors.values(), ...originalPreprocessors];\n\n return {\n ...originalConfig,\n preprocess: mergedPreprocessors,\n };\n}\n\n/**\n * Standardizes the different ways the user-provided preprocessor option can be specified.\n * Users can specify an array of preprocessors, a single one or no preprocessor.\n *\n * @param originalConfig the user-provided svelte config oject\n * @return an array of preprocessors or an empty array if no preprocessors were specified\n */\nfunction getOriginalPreprocessorArray(originalConfig: SvelteConfig): PreprocessorGroup[] {\n if (originalConfig.preprocess) {\n if (Array.isArray(originalConfig.preprocess)) {\n return originalConfig.preprocess;\n }\n return [originalConfig.preprocess];\n }\n return [];\n}\n"],"names":[],"mappings":";;AAKA,MAAM,sBAAsB,GAA8B;AAC1D,EAAE,iBAAiB,EAAE,+BAA+B;AACpD,CAAC,CAAA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gBAAgB;AAChC,EAAE,cAAc;AAChB,EAAE,aAAa;AACf,EAAgB;AAChB,EAAE,MAAM,gBAAgB;AACxB,IAAI,GAAG,sBAAsB;AAC7B,IAAI,GAAG,aAAa;AACpB,GAAG,CAAA;AACH;AACA,EAAE,MAAM,qBAAsB,GAAE,4BAA4B,CAAC,cAAc,CAAC,CAAA;AAC5E;AACA;AACA;AACA;AACA,EAAE,MAAM,mBAAoB,GAAE,IAAI,GAAG,EAAmC,CAAA;AACxE;AACA,EAAE,MAAM,qBAAsB,GAAE,aAAa,CAAC,iBAAkB,IAAG,aAAa,CAAC,iBAAiB,CAAC,eAAe,CAAA;AAClH,EAAE,IAAI,qBAAqB,EAAE;AAC7B,IAAI,MAAM,gBAAgB,GAA4B,6BAA6B,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAA;AACpH,IAAI,mBAAmB,CAAC,GAAG,CAAC,gBAAgB,CAAC,QAAA,IAAY,EAAE,EAAE,gBAAgB,CAAC,CAAA;AAC9E,GAAE;AACF;AACA;AACA;AACA,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,KAA8B;AAChE,IAAI,IAAI,CAAC,CAAC,QAAQ,EAAE;AACpB,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;AAC5C,KAAI;AACJ,GAAG,CAAC,CAAA;AACJ;AACA,EAAE,MAAM,mBAAA,GAAsB,CAAC,GAAG,mBAAmB,CAAC,MAAM,EAAE,EAAE,GAAG,qBAAqB,CAAC,CAAA;AACzF;AACA,EAAE,OAAO;AACT,IAAI,GAAG,cAAc;AACrB,IAAI,UAAU,EAAE,mBAAmB;AACnC,GAAG,CAAA;AACH,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,4BAA4B,CAAC,cAAc,EAAqC;AACzF,EAAE,IAAI,cAAc,CAAC,UAAU,EAAE;AACjC,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;AAClD,MAAM,OAAO,cAAc,CAAC,UAAU,CAAA;AACtC,KAAI;AACJ,IAAI,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;AACtC,GAAE;AACF,EAAE,OAAO,EAAE,CAAA;AACX;;;;"}
package/esm/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from '@sentry/browser';
2
2
  export { init } from './sdk.js';
3
- export { componentTrackingPreprocessor } from './preprocessors.js';
4
3
  export { trackComponent } from './performance.js';
5
4
  export { withSentryConfig } from './config.js';
6
5
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
package/esm/package.json CHANGED
@@ -1 +1 @@
1
- { "type": "module" }
1
+ {"type":"module","sideEffects":false}
@@ -14,8 +14,10 @@ const defaultTrackComponentOptions
14
14
  /**
15
15
  * Tracks the Svelte component's intialization and mounting operation as well as
16
16
  * updates and records them as spans.
17
+ *
17
18
  * This function is injected automatically into your Svelte components' code
18
- * if you are using the Sentry componentTrackingPreprocessor.
19
+ * if you are using the withSentryConfig wrapper.
20
+ *
19
21
  * Alternatively, you can call it yourself if you don't want to use the preprocessor.
20
22
  */
21
23
  function trackComponent(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"performance.js","sources":["../../src/performance.ts"],"sourcesContent":["import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/types';\nimport { afterUpdate, beforeUpdate, onMount } from 'svelte';\nimport { current_component } from 'svelte/internal';\n\nimport { getRootSpan, startInactiveSpan, withActiveSpan } from '@sentry/core';\nimport { DEFAULT_COMPONENT_NAME, UI_SVELTE_INIT, UI_SVELTE_UPDATE } from './constants';\nimport type { TrackComponentOptions } from './types';\n\nconst defaultTrackComponentOptions: {\n trackInit: boolean;\n trackUpdates: boolean;\n componentName?: string;\n} = {\n trackInit: true,\n trackUpdates: true,\n};\n\n/**\n * Tracks the Svelte component's intialization and mounting operation as well as\n * updates and records them as spans.\n * This function is injected automatically into your Svelte components' code\n * if you are using the Sentry componentTrackingPreprocessor.\n * Alternatively, you can call it yourself if you don't want to use the preprocessor.\n */\nexport function trackComponent(options?: TrackComponentOptions): void {\n const mergedOptions = { ...defaultTrackComponentOptions, ...options };\n\n const customComponentName = mergedOptions.componentName;\n\n // current_component.ctor.name is likely to give us the component's name automatically\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const componentName = `<${customComponentName || current_component.constructor.name || DEFAULT_COMPONENT_NAME}>`;\n\n let initSpan: Span | undefined = undefined;\n if (mergedOptions.trackInit) {\n initSpan = recordInitSpan(componentName);\n }\n\n if (mergedOptions.trackUpdates) {\n recordUpdateSpans(componentName, initSpan);\n }\n}\n\nfunction recordInitSpan(componentName: string): Span | undefined {\n const initSpan = startInactiveSpan({\n onlyIfParent: true,\n op: UI_SVELTE_INIT,\n name: componentName,\n attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },\n });\n\n onMount(() => {\n initSpan.end();\n });\n\n return initSpan;\n}\n\nfunction recordUpdateSpans(componentName: string, initSpan?: Span): void {\n let updateSpan: Span | undefined;\n beforeUpdate(() => {\n // We need to get the active transaction again because the initial one could\n // already be finished or there is currently no transaction going on.\n const activeSpan = getActiveSpan();\n if (!activeSpan) {\n return;\n }\n\n // If we are initializing the component when the update span is started, we start it as child\n // of the init span. Else, we start it as a child of the transaction.\n const parentSpan =\n initSpan && initSpan.isRecording() && getRootSpan(initSpan) === getRootSpan(activeSpan)\n ? initSpan\n : getRootSpan(activeSpan);\n\n if (!parentSpan) return;\n\n updateSpan = withActiveSpan(parentSpan, () => {\n return startInactiveSpan({\n op: UI_SVELTE_UPDATE,\n name: componentName,\n attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },\n });\n });\n });\n\n afterUpdate(() => {\n if (!updateSpan) {\n return;\n }\n updateSpan.end();\n updateSpan = undefined;\n });\n}\n"],"names":[],"mappings":";;;;;;AASA,MAAM,4BAA4B;;AAIlC,GAAI;AACJ,EAAE,SAAS,EAAE,IAAI;AACjB,EAAE,YAAY,EAAE,IAAI;AACpB,CAAC,CAAA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,OAAO,EAAgC;AACtE,EAAE,MAAM,gBAAgB,EAAE,GAAG,4BAA4B,EAAE,GAAG,OAAA,EAAS,CAAA;AACvE;AACA,EAAE,MAAM,mBAAA,GAAsB,aAAa,CAAC,aAAa,CAAA;AACzD;AACA;AACA;AACA,EAAE,MAAM,aAAc,GAAE,CAAC,CAAC,EAAE,mBAAoB,IAAG,iBAAiB,CAAC,WAAW,CAAC,IAAA,IAAQ,sBAAsB,CAAC,CAAC,CAAC,CAAA;AAClH;AACA,EAAE,IAAI,QAAQ,GAAqB,SAAS,CAAA;AAC5C,EAAE,IAAI,aAAa,CAAC,SAAS,EAAE;AAC/B,IAAI,QA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,EAAE,aAAa;AAC3B,QAAQ,UAAU,EAAE,EAAE,CAAC,gCAAgC,GAAG,kBAAkB;AAC5E,OAAO,CAAC,CAAA;AACR,KAAK,CAAC,CAAA;AACN,GAAG,CAAC,CAAA;AACJ;AACA,EAAE,WAAW,CAAC,MAAM;AACpB,IAAI,IAAI,CAAC,UAAU,EAAE;AACrB,MAAM,OAAM;AACZ,KAAI;AACJ,IAAI,UAAU,CAAC,GAAG,EAAE,CAAA;AACpB,IAAI,UAAA,GAAa,SAAS,CAAA;AAC1B,GAAG,CAAC,CAAA;AACJ;;;;"}
1
+ {"version":3,"file":"performance.js","sources":["../../src/performance.ts"],"sourcesContent":["import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/types';\nimport { afterUpdate, beforeUpdate, onMount } from 'svelte';\nimport { current_component } from 'svelte/internal';\n\nimport { getRootSpan, startInactiveSpan, withActiveSpan } from '@sentry/core';\nimport { DEFAULT_COMPONENT_NAME, UI_SVELTE_INIT, UI_SVELTE_UPDATE } from './constants';\nimport type { TrackComponentOptions } from './types';\n\nconst defaultTrackComponentOptions: {\n trackInit: boolean;\n trackUpdates: boolean;\n componentName?: string;\n} = {\n trackInit: true,\n trackUpdates: true,\n};\n\n/**\n * Tracks the Svelte component's intialization and mounting operation as well as\n * updates and records them as spans.\n *\n * This function is injected automatically into your Svelte components' code\n * if you are using the withSentryConfig wrapper.\n *\n * Alternatively, you can call it yourself if you don't want to use the preprocessor.\n */\nexport function trackComponent(options?: TrackComponentOptions): void {\n const mergedOptions = { ...defaultTrackComponentOptions, ...options };\n\n const customComponentName = mergedOptions.componentName;\n\n // current_component.ctor.name is likely to give us the component's name automatically\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const componentName = `<${customComponentName || current_component.constructor.name || DEFAULT_COMPONENT_NAME}>`;\n\n let initSpan: Span | undefined = undefined;\n if (mergedOptions.trackInit) {\n initSpan = recordInitSpan(componentName);\n }\n\n if (mergedOptions.trackUpdates) {\n recordUpdateSpans(componentName, initSpan);\n }\n}\n\nfunction recordInitSpan(componentName: string): Span | undefined {\n const initSpan = startInactiveSpan({\n onlyIfParent: true,\n op: UI_SVELTE_INIT,\n name: componentName,\n attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },\n });\n\n onMount(() => {\n initSpan.end();\n });\n\n return initSpan;\n}\n\nfunction recordUpdateSpans(componentName: string, initSpan?: Span): void {\n let updateSpan: Span | undefined;\n beforeUpdate(() => {\n // We need to get the active transaction again because the initial one could\n // already be finished or there is currently no transaction going on.\n const activeSpan = getActiveSpan();\n if (!activeSpan) {\n return;\n }\n\n // If we are initializing the component when the update span is started, we start it as child\n // of the init span. Else, we start it as a child of the transaction.\n const parentSpan =\n initSpan && initSpan.isRecording() && getRootSpan(initSpan) === getRootSpan(activeSpan)\n ? initSpan\n : getRootSpan(activeSpan);\n\n if (!parentSpan) return;\n\n updateSpan = withActiveSpan(parentSpan, () => {\n return startInactiveSpan({\n op: UI_SVELTE_UPDATE,\n name: componentName,\n attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },\n });\n });\n });\n\n afterUpdate(() => {\n if (!updateSpan) {\n return;\n }\n updateSpan.end();\n updateSpan = undefined;\n });\n}\n"],"names":[],"mappings":";;;;;;AASA,MAAM,4BAA4B;;AAIlC,GAAI;AACJ,EAAE,SAAS,EAAE,IAAI;AACjB,EAAE,YAAY,EAAE,IAAI;AACpB,CAAC,CAAA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,OAAO,EAAgC;AACtE,EAAE,MAAM,gBAAgB,EAAE,GAAG,4BAA4B,EAAE,GAAG,OAAA,EAAS,CAAA;AACvE;AACA,EAAE,MAAM,mBAAA,GAAsB,aAAa,CAAC,aAAa,CAAA;AACzD;AACA;AACA;AACA,EAAE,MAAM,aAAc,GA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AAC,UAAU,CAAC,CAAA;AACjC;AACA,IAAI,IAAI,CAAC,UAAU,EAAE,OAAM;AAC3B;AACA,IAAI,UAAA,GAAa,cAAc,CAAC,UAAU,EAAE,MAAM;AAClD,MAAM,OAAO,iBAAiB,CAAC;AAC/B,QAAQ,EAAE,EAAE,gBAAgB;AAC5B,QAAQ,IAAI,EAAE,aAAa;AAC3B,QAAQ,UAAU,EAAE,EAAE,CAAC,gCAAgC,GAAG,kBAAkB;AAC5E,OAAO,CAAC,CAAA;AACR,KAAK,CAAC,CAAA;AACN,GAAG,CAAC,CAAA;AACJ;AACA,EAAE,WAAW,CAAC,MAAM;AACpB,IAAI,IAAI,CAAC,UAAU,EAAE;AACrB,MAAM,OAAM;AACZ,KAAI;AACJ,IAAI,UAAU,CAAC,GAAG,EAAE,CAAA;AACpB,IAAI,UAAA,GAAa,SAAS,CAAA;AAC1B,GAAG,CAAC,CAAA;AACJ;;;;"}
@@ -11,9 +11,6 @@ const FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID = 'FIRST_PASS_COMPONENT_TRACKING_
11
11
  /**
12
12
  * Svelte Preprocessor to inject Sentry performance monitoring related code
13
13
  * into Svelte components.
14
- *
15
- * @deprecated Use `withSentryConfig` which is the new way of making compile-time modifications
16
- * to Svelte apps going forward.
17
14
  */
18
15
  function componentTrackingPreprocessor(options) {
19
16
  const mergedOptions = { ...defaultComponentTrackingOptions, ...options };
@@ -1 +1 @@
1
- {"version":3,"file":"preprocessors.js","sources":["../../src/preprocessors.ts"],"sourcesContent":["import MagicString from 'magic-string';\nimport type { PreprocessorGroup } from 'svelte/types/compiler/preprocess';\n\nimport type { ComponentTrackingInitOptions, SentryPreprocessorGroup, TrackComponentOptions } from './types';\n\nexport const defaultComponentTrackingOptions: Required<ComponentTrackingInitOptions> = {\n trackComponents: true,\n trackInit: true,\n trackUpdates: true,\n};\n\nexport const FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID = 'FIRST_PASS_COMPONENT_TRACKING_PREPROCESSOR';\n\n/**\n * Svelte Preprocessor to inject Sentry performance monitoring related code\n * into Svelte components.\n *\n * @deprecated Use `withSentryConfig` which is the new way of making compile-time modifications\n * to Svelte apps going forward.\n */\nexport function componentTrackingPreprocessor(options?: ComponentTrackingInitOptions): PreprocessorGroup {\n const mergedOptions = { ...defaultComponentTrackingOptions, ...options };\n\n const visitedFiles = new Set<string>();\n const visitedFilesMarkup = new Set<string>();\n\n const preprocessor: PreprocessorGroup = {\n // This markup hook is called once per .svelte component file, before the `script` hook is called\n // We use it to check if the passed component has a <script> tag. If it doesn't, we add one to inject our\n // code later on, when the `script` hook is executed.\n markup: ({ content, filename }) => {\n const finalFilename = filename || 'unknown';\n const shouldInject = shouldInjectFunction(mergedOptions.trackComponents, finalFilename, {}, visitedFilesMarkup);\n\n if (shouldInject && !hasScriptTag(content)) {\n // Insert a <script> tag into the component file where we can later on inject our code.\n // We have to add a placeholder to the script tag because for empty script tags,\n // the `script` preprocessor hook won't be called\n // Note: The space between <script> and </script> is important! Without any content,\n // the `script` hook wouldn't be executed for the added script tag.\n const s = new MagicString(content);\n s.prepend('<script>\\n</script>\\n');\n return { code: s.toString(), map: s.generateMap().toString() };\n }\n\n return { code: content };\n },\n\n // This script hook is called whenever a Svelte component's <script> content is preprocessed.\n // `content` contains the script code as a string\n script: ({ content, filename, attributes }) => {\n // TODO: Not sure when a filename could be undefined. Using this 'unknown' fallback for the time being\n const finalFilename = filename || 'unknown';\n\n if (!shouldInjectFunction(mergedOptions.trackComponents, finalFilename, attributes, visitedFiles)) {\n return { code: content };\n }\n\n const { trackInit, trackUpdates } = mergedOptions;\n const trackComponentOptions: TrackComponentOptions = {\n trackInit,\n trackUpdates,\n componentName: getBaseName(finalFilename),\n };\n\n const importStmt = 'import { trackComponent } from \"@sentry/svelte\";\\n';\n const functionCall = `trackComponent(${JSON.stringify(trackComponentOptions)});\\n`;\n\n const s = new MagicString(content);\n s.prepend(functionCall).prepend(importStmt);\n\n const updatedCode = s.toString();\n const updatedSourceMap = s.generateMap().toString();\n\n return { code: updatedCode, map: updatedSourceMap };\n },\n };\n\n const sentryPreprocessor: SentryPreprocessorGroup = {\n ...preprocessor,\n sentryId: FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID,\n };\n\n return sentryPreprocessor;\n}\n\nfunction shouldInjectFunction(\n trackComponents: Required<ComponentTrackingInitOptions['trackComponents']>,\n filename: string,\n attributes: Record<string, string | boolean>,\n visitedFiles: Set<string>,\n): boolean {\n // We do cannot inject our function multiple times into the same component\n // This can happen when a component has multiple <script> blocks\n if (visitedFiles.has(filename)) {\n return false;\n }\n visitedFiles.add(filename);\n\n // We can't inject our function call into <script context=\"module\"> blocks\n // because the code inside is not executed when the component is instantiated but\n // when the module is first imported.\n // see: https://svelte.dev/docs#component-format-script-context-module\n if (attributes.context === 'module') {\n return false;\n }\n\n if (!trackComponents) {\n return false;\n }\n\n if (Array.isArray(trackComponents)) {\n const componentName = getBaseName(filename);\n return trackComponents.some(allowed => allowed === componentName);\n }\n\n return true;\n}\n\nfunction getBaseName(filename: string): string {\n const segments = filename.split('/');\n return segments[segments.length - 1].replace('.svelte', '');\n}\n\nfunction hasScriptTag(content: string): boolean {\n // This regex is taken from the Svelte compiler code.\n // They use this regex to find matching script tags that are passed to the `script` preprocessor hook:\n // https://github.com/sveltejs/svelte/blob/bb83eddfc623437528f24e9fe210885b446e72fa/src/compiler/preprocess/index.ts#L144\n // However, we remove the first part of the regex to not match HTML comments\n const scriptTagRegex = /<script(\\s[^]*?)?(?:>([^]*?)<\\/script\\s*>|\\/>)/gi;\n\n // Regex testing is not a super safe way of checking for the presence of a <script> tag in the Svelte\n // component file but I think we can use it as a start.\n // A case that is not covered by regex-testing HTML is e.g. nested <script> tags but I cannot\n // think of why one would do this in Svelte components. For instance, the Svelte compiler errors\n // when there's more than one top-level script tag.\n return scriptTagRegex.test(content);\n}\n"],"names":[],"mappings":";;AAKO,MAAM,+BAA+B,GAA2C;AACvF,EAAE,eAAe,EAAE,IAA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Z,EAAE,YAAY;AACd,EAAW;AACX;AACA;AACA,EAAE,IAAI,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;AAClC,IAAI,OAAO,KAAK,CAAA;AAChB,GAAE;AACF,EAAE,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC5B;AACA;AACA;AACA;AACA;AACA,EAAE,IAAI,UAAU,CAAC,OAAQ,KAAI,QAAQ,EAAE;AACvC,IAAI,OAAO,KAAK,CAAA;AAChB,GAAE;AACF;AACA,EAAE,IAAI,CAAC,eAAe,EAAE;AACxB,IAAI,OAAO,KAAK,CAAA;AAChB,GAAE;AACF;AACA,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE;AACtC,IAAI,MAAM,aAAc,GAAE,WAAW,CAAC,QAAQ,CAAC,CAAA;AAC/C,IAAI,OAAO,eAAe,CAAC,IAAI,CAAC,WAAW,OAAA,KAAY,aAAa,CAAC,CAAA;AACrE,GAAE;AACF;AACA,EAAE,OAAO,IAAI,CAAA;AACb,CAAA;AACA;AACA,SAAS,WAAW,CAAC,QAAQ,EAAkB;AAC/C,EAAE,MAAM,WAAW,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AACtC,EAAE,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAO,GAAE,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;AAC7D,CAAA;AACA;AACA,SAAS,YAAY,CAAC,OAAO,EAAmB;AAChD;AACA;AACA;AACA;AACA,EAAE,MAAM,cAAe,GAAE,kDAAkD,CAAA;AAC3E;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,OAAO,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACrC;;;;"}
1
+ {"version":3,"file":"preprocessors.js","sources":["../../src/preprocessors.ts"],"sourcesContent":["import MagicString from 'magic-string';\nimport type { PreprocessorGroup } from 'svelte/types/compiler/preprocess';\n\nimport type { ComponentTrackingInitOptions, SentryPreprocessorGroup, TrackComponentOptions } from './types';\n\nexport const defaultComponentTrackingOptions: Required<ComponentTrackingInitOptions> = {\n trackComponents: true,\n trackInit: true,\n trackUpdates: true,\n};\n\nexport const FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID = 'FIRST_PASS_COMPONENT_TRACKING_PREPROCESSOR';\n\n/**\n * Svelte Preprocessor to inject Sentry performance monitoring related code\n * into Svelte components.\n */\nexport function componentTrackingPreprocessor(options?: ComponentTrackingInitOptions): PreprocessorGroup {\n const mergedOptions = { ...defaultComponentTrackingOptions, ...options };\n\n const visitedFiles = new Set<string>();\n const visitedFilesMarkup = new Set<string>();\n\n const preprocessor: PreprocessorGroup = {\n // This markup hook is called once per .svelte component file, before the `script` hook is called\n // We use it to check if the passed component has a <script> tag. If it doesn't, we add one to inject our\n // code later on, when the `script` hook is executed.\n markup: ({ content, filename }) => {\n const finalFilename = filename || 'unknown';\n const shouldInject = shouldInjectFunction(mergedOptions.trackComponents, finalFilename, {}, visitedFilesMarkup);\n\n if (shouldInject && !hasScriptTag(content)) {\n // Insert a <script> tag into the component file where we can later on inject our code.\n // We have to add a placeholder to the script tag because for empty script tags,\n // the `script` preprocessor hook won't be called\n // Note: The space between <script> and </script> is important! Without any content,\n // the `script` hook wouldn't be executed for the added script tag.\n const s = new MagicString(content);\n s.prepend('<script>\\n</script>\\n');\n return { code: s.toString(), map: s.generateMap().toString() };\n }\n\n return { code: content };\n },\n\n // This script hook is called whenever a Svelte component's <script> content is preprocessed.\n // `content` contains the script code as a string\n script: ({ content, filename, attributes }) => {\n // TODO: Not sure when a filename could be undefined. Using this 'unknown' fallback for the time being\n const finalFilename = filename || 'unknown';\n\n if (!shouldInjectFunction(mergedOptions.trackComponents, finalFilename, attributes, visitedFiles)) {\n return { code: content };\n }\n\n const { trackInit, trackUpdates } = mergedOptions;\n const trackComponentOptions: TrackComponentOptions = {\n trackInit,\n trackUpdates,\n componentName: getBaseName(finalFilename),\n };\n\n const importStmt = 'import { trackComponent } from \"@sentry/svelte\";\\n';\n const functionCall = `trackComponent(${JSON.stringify(trackComponentOptions)});\\n`;\n\n const s = new MagicString(content);\n s.prepend(functionCall).prepend(importStmt);\n\n const updatedCode = s.toString();\n const updatedSourceMap = s.generateMap().toString();\n\n return { code: updatedCode, map: updatedSourceMap };\n },\n };\n\n const sentryPreprocessor: SentryPreprocessorGroup = {\n ...preprocessor,\n sentryId: FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID,\n };\n\n return sentryPreprocessor;\n}\n\nfunction shouldInjectFunction(\n trackComponents: Required<ComponentTrackingInitOptions['trackComponents']>,\n filename: string,\n attributes: Record<string, string | boolean>,\n visitedFiles: Set<string>,\n): boolean {\n // We do cannot inject our function multiple times into the same component\n // This can happen when a component has multiple <script> blocks\n if (visitedFiles.has(filename)) {\n return false;\n }\n visitedFiles.add(filename);\n\n // We can't inject our function call into <script context=\"module\"> blocks\n // because the code inside is not executed when the component is instantiated but\n // when the module is first imported.\n // see: https://svelte.dev/docs#component-format-script-context-module\n if (attributes.context === 'module') {\n return false;\n }\n\n if (!trackComponents) {\n return false;\n }\n\n if (Array.isArray(trackComponents)) {\n const componentName = getBaseName(filename);\n return trackComponents.some(allowed => allowed === componentName);\n }\n\n return true;\n}\n\nfunction getBaseName(filename: string): string {\n const segments = filename.split('/');\n return segments[segments.length - 1].replace('.svelte', '');\n}\n\nfunction hasScriptTag(content: string): boolean {\n // This regex is taken from the Svelte compiler code.\n // They use this regex to find matching script tags that are passed to the `script` preprocessor hook:\n // https://github.com/sveltejs/svelte/blob/bb83eddfc623437528f24e9fe210885b446e72fa/src/compiler/preprocess/index.ts#L144\n // However, we remove the first part of the regex to not match HTML comments\n const scriptTagRegex = /<script(\\s[^]*?)?(?:>([^]*?)<\\/script\\s*>|\\/>)/gi;\n\n // Regex testing is not a super safe way of checking for the presence of a <script> tag in the Svelte\n // component file but I think we can use it as a start.\n // A case that is not covered by regex-testing HTML is e.g. nested <script> tags but I cannot\n // think of why one would do this in Svelte components. For instance, the Svelte compiler errors\n // when there's more than one top-level script tag.\n return scriptTagRegex.test(content);\n}\n"],"names":[],"mappings":";;AAKO,MAAM,+BAA+B,GAA2C;AACvF,EAAE,eAAe,EAAE,IAAI;AACvB,EAAE,SAAS,EAAE,IAAI;AACjB,EAAE,YAAY,EAAE,IAAI;AACpB,EAAC;AACD;AACO,MAAM,wCAAyC,GAAE,6CAA4C;AACpG;AACA;AACA;AACA;AACA;AACO,SAAS,6BAA6B,CAAC,OAAO,EAAoD;AACzG,EAAE,MAAM,gBAAgB,EAAE,GAAG,+BAA+B,EAAE,GAAG,OAAA,EAAS,CAAA;AAC1E;AACA,EAAE,MAAM,YAAa,GAAE,IAAI,GAAG,EAAU,CAAA;AACxC,EAAE,MAAM,kBAAmB,GAAE,IAAI,GAAG,EAAU,CAAA;AAC9C;AACA,EAAE,MAAM,YAAY,GAAsB;AAC1C;AACA;AACA;AACA,IAAI,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,QAAA,EAAU,KAAK;AACvC,MAAM,MAAM,aAAA,GAAgB,QAAA,IAAY,SAAS,CAAA;AACjD,MAAM,MAAM,YAAA,GAAe,oBAAoB,CAAC,aAAa,CAAC,eAAe,EAAE,aAAa,EAAE,EAAE,EAAE,kBAAkB,CAAC,CAAA;AACrH;AACA,MAAM,IAAI,YAAa,IAAG,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE;AAClD;AACA;AACA;AACA;AACA;AACA,QAAQ,MAAM,CAAE,GAAE,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;AAC1C,QAAQ,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAA;AAC1C,QAAQ,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAC,EAAG,CAAA;AACtE,OAAM;AACN;AACA,MAAM,OAAO,EAAE,IAAI,EAAE,SAAS,C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AAA;AACrC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/svelte",
3
- "version": "8.0.0-alpha.4",
3
+ "version": "8.0.0-alpha.7",
4
4
  "description": "Official Sentry SDK for Svelte",
5
5
  "repository": "git://github.com/getsentry/sentry-javascript.git",
6
6
  "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/svelte",
@@ -42,10 +42,10 @@
42
42
  "access": "public"
43
43
  },
44
44
  "dependencies": {
45
- "@sentry/browser": "8.0.0-alpha.4",
46
- "@sentry/core": "8.0.0-alpha.4",
47
- "@sentry/types": "8.0.0-alpha.4",
48
- "@sentry/utils": "8.0.0-alpha.4",
45
+ "@sentry/browser": "8.0.0-alpha.7",
46
+ "@sentry/core": "8.0.0-alpha.7",
47
+ "@sentry/types": "8.0.0-alpha.7",
48
+ "@sentry/utils": "8.0.0-alpha.7",
49
49
  "magic-string": "^0.30.0"
50
50
  },
51
51
  "peerDependencies": {
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA2B,yBAAyB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAMhG;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,YAAY,EAC5B,aAAa,CAAC,EAAE,yBAAyB,GACxC,YAAY,CAmCd"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA2B,yBAAyB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAMhG;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,YAAY,EAC5B,aAAa,CAAC,EAAE,yBAAyB,GACxC,YAAY,CAiCd"}
package/types/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export type { ComponentTrackingInitOptions as ComponentTrackingOptions, TrackComponentOptions as TrackingOptions, } from './types';
2
2
  export * from '@sentry/browser';
3
3
  export { init } from './sdk';
4
- export { componentTrackingPreprocessor } from './preprocessors';
5
4
  export { trackComponent } from './performance';
6
5
  export { withSentryConfig } from './config';
7
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,4BAA4B,IAAI,wBAAwB,EACxD,qBAAqB,IAAI,eAAe,GACzC,MAAM,SAAS,CAAC;AAEjB,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAI7B,OAAO,EAAE,6BAA6B,EAAE,MAAM,iBAAiB,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,4BAA4B,IAAI,wBAAwB,EACxD,qBAAqB,IAAI,eAAe,GACzC,MAAM,SAAS,CAAC;AAEjB,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
@@ -2,8 +2,10 @@ import type { TrackComponentOptions } from './types';
2
2
  /**
3
3
  * Tracks the Svelte component's intialization and mounting operation as well as
4
4
  * updates and records them as spans.
5
+ *
5
6
  * This function is injected automatically into your Svelte components' code
6
- * if you are using the Sentry componentTrackingPreprocessor.
7
+ * if you are using the withSentryConfig wrapper.
8
+ *
7
9
  * Alternatively, you can call it yourself if you don't want to use the preprocessor.
8
10
  */
9
11
  export declare function trackComponent(options?: TrackComponentOptions): void;
@@ -1 +1 @@
1
- {"version":3,"file":"performance.d.ts","sourceRoot":"","sources":["../../src/performance.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAWrD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAiBpE"}
1
+ {"version":3,"file":"performance.d.ts","sourceRoot":"","sources":["../../src/performance.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAWrD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAiBpE"}
@@ -5,9 +5,6 @@ export declare const FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID = "FIRST_PASS_COMP
5
5
  /**
6
6
  * Svelte Preprocessor to inject Sentry performance monitoring related code
7
7
  * into Svelte components.
8
- *
9
- * @deprecated Use `withSentryConfig` which is the new way of making compile-time modifications
10
- * to Svelte apps going forward.
11
8
  */
12
9
  export declare function componentTrackingPreprocessor(options?: ComponentTrackingInitOptions): PreprocessorGroup;
13
10
  //# sourceMappingURL=preprocessors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"preprocessors.d.ts","sourceRoot":"","sources":["../../src/preprocessors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1E,OAAO,KAAK,EAAE,4BAA4B,EAAkD,MAAM,SAAS,CAAC;AAE5G,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC,4BAA4B,CAIlF,CAAC;AAEF,eAAO,MAAM,wCAAwC,+CAA+C,CAAC;AAErG;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,CAAC,EAAE,4BAA4B,GAAG,iBAAiB,CAgEvG"}
1
+ {"version":3,"file":"preprocessors.d.ts","sourceRoot":"","sources":["../../src/preprocessors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1E,OAAO,KAAK,EAAE,4BAA4B,EAAkD,MAAM,SAAS,CAAC;AAE5G,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC,4BAA4B,CAIlF,CAAC;AAEF,eAAO,MAAM,wCAAwC,+CAA+C,CAAC;AAErG;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,CAAC,EAAE,4BAA4B,GAAG,iBAAiB,CAgEvG"}
@@ -1,7 +1,6 @@
1
1
  export { ComponentTrackingInitOptions as ComponentTrackingOptions, TrackComponentOptions as TrackingOptions, } from './types';
2
2
  export * from '@sentry/browser';
3
3
  export { init } from './sdk';
4
- export { componentTrackingPreprocessor } from './preprocessors';
5
4
  export { trackComponent } from './performance';
6
5
  export { withSentryConfig } from './config';
7
6
  //# sourceMappingURL=index.d.ts.map
@@ -2,8 +2,10 @@ import { TrackComponentOptions } from './types';
2
2
  /**
3
3
  * Tracks the Svelte component's intialization and mounting operation as well as
4
4
  * updates and records them as spans.
5
+ *
5
6
  * This function is injected automatically into your Svelte components' code
6
- * if you are using the Sentry componentTrackingPreprocessor.
7
+ * if you are using the withSentryConfig wrapper.
8
+ *
7
9
  * Alternatively, you can call it yourself if you don't want to use the preprocessor.
8
10
  */
9
11
  export declare function trackComponent(options?: TrackComponentOptions): void;
@@ -5,9 +5,6 @@ export declare const FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID = "FIRST_PASS_COMP
5
5
  /**
6
6
  * Svelte Preprocessor to inject Sentry performance monitoring related code
7
7
  * into Svelte components.
8
- *
9
- * @deprecated Use `withSentryConfig` which is the new way of making compile-time modifications
10
- * to Svelte apps going forward.
11
8
  */
12
9
  export declare function componentTrackingPreprocessor(options?: ComponentTrackingInitOptions): PreprocessorGroup;
13
10
  //# sourceMappingURL=preprocessors.d.ts.map