@sentry/svelte 8.9.1 → 8.10.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.
package/cjs/preprocessors.js
CHANGED
|
@@ -115,6 +115,7 @@ function shouldInjectFunction(
|
|
|
115
115
|
|
|
116
116
|
function getBaseName(filename) {
|
|
117
117
|
const segments = filename.split('/');
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
118
119
|
return segments[segments.length - 1].replace('.svelte', '');
|
|
119
120
|
}
|
|
120
121
|
|
package/cjs/preprocessors.js.map
CHANGED
|
@@ -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 */\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]
|
|
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 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\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,YAAY,CAAC,OAAO,CAAC,EAAE;AAClD;AACA;AACA;AAC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,CAAC,CAAA;AACtC;AACA,EAAE,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAO,GAAE,CAAC,CAAC,CAAE,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;AAC9D,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/preprocessors.js
CHANGED
|
@@ -113,6 +113,7 @@ function shouldInjectFunction(
|
|
|
113
113
|
|
|
114
114
|
function getBaseName(filename) {
|
|
115
115
|
const segments = filename.split('/');
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
116
117
|
return segments[segments.length - 1].replace('.svelte', '');
|
|
117
118
|
}
|
|
118
119
|
|
package/esm/preprocessors.js.map
CHANGED
|
@@ -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 */\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]
|
|
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 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\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,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;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;AACA,EAAE,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAO,GAAE,CAAC,CAAC,CAAE,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;AAC9D,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/svelte",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.10.0",
|
|
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.
|
|
46
|
-
"@sentry/core": "8.
|
|
47
|
-
"@sentry/types": "8.
|
|
48
|
-
"@sentry/utils": "8.
|
|
45
|
+
"@sentry/browser": "8.10.0",
|
|
46
|
+
"@sentry/core": "8.10.0",
|
|
47
|
+
"@sentry/types": "8.10.0",
|
|
48
|
+
"@sentry/utils": "8.10.0",
|
|
49
49
|
"magic-string": "^0.30.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|