@sentry/bundler-plugins 10.64.0 → 10.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/build/cjs/babel-plugin/component-annotation.js +46 -0
  2. package/build/cjs/babel-plugin/component-annotation.js.map +1 -0
  3. package/build/cjs/babel-plugin/index.js +19 -49
  4. package/build/cjs/babel-plugin/index.js.map +1 -1
  5. package/build/cjs/core/component-annotation-vite-ast.js +27 -0
  6. package/build/cjs/core/component-annotation-vite-ast.js.map +1 -0
  7. package/build/cjs/core/component-annotation-vite-fragments.js +91 -0
  8. package/build/cjs/core/component-annotation-vite-fragments.js.map +1 -0
  9. package/build/cjs/core/component-annotation-vite-jsx.js +140 -0
  10. package/build/cjs/core/component-annotation-vite-jsx.js.map +1 -0
  11. package/build/cjs/core/component-annotation-vite-walk.js +121 -0
  12. package/build/cjs/core/component-annotation-vite-walk.js.map +1 -0
  13. package/build/cjs/core/component-annotation-vite.js +101 -0
  14. package/build/cjs/core/component-annotation-vite.js.map +1 -0
  15. package/build/cjs/core/index.js +20 -7
  16. package/build/cjs/core/index.js.map +1 -1
  17. package/build/cjs/core/version.js +1 -1
  18. package/build/cjs/core/version.js.map +1 -1
  19. package/build/cjs/rollup/index.js +52 -3
  20. package/build/cjs/rollup/index.js.map +1 -1
  21. package/build/esm/babel-plugin/component-annotation.js +38 -0
  22. package/build/esm/babel-plugin/component-annotation.js.map +1 -0
  23. package/build/esm/babel-plugin/index.js +20 -50
  24. package/build/esm/babel-plugin/index.js.map +1 -1
  25. package/build/esm/core/component-annotation-vite-ast.js +24 -0
  26. package/build/esm/core/component-annotation-vite-ast.js.map +1 -0
  27. package/build/esm/core/component-annotation-vite-fragments.js +89 -0
  28. package/build/esm/core/component-annotation-vite-fragments.js.map +1 -0
  29. package/build/esm/core/component-annotation-vite-jsx.js +130 -0
  30. package/build/esm/core/component-annotation-vite-jsx.js.map +1 -0
  31. package/build/esm/core/component-annotation-vite-walk.js +119 -0
  32. package/build/esm/core/component-annotation-vite-walk.js.map +1 -0
  33. package/build/esm/core/component-annotation-vite.js +94 -0
  34. package/build/esm/core/component-annotation-vite.js.map +1 -0
  35. package/build/esm/core/index.js +16 -3
  36. package/build/esm/core/index.js.map +1 -1
  37. package/build/esm/core/version.js +1 -1
  38. package/build/esm/core/version.js.map +1 -1
  39. package/build/esm/package.json +1 -1
  40. package/build/esm/rollup/index.js +52 -3
  41. package/build/esm/rollup/index.js.map +1 -1
  42. package/build/types/babel-plugin/component-annotation.d.ts +20 -0
  43. package/build/types/babel-plugin/component-annotation.d.ts.map +1 -0
  44. package/build/types/babel-plugin/index.d.ts.map +1 -1
  45. package/build/types/core/component-annotation-vite-ast.d.ts +57 -0
  46. package/build/types/core/component-annotation-vite-ast.d.ts.map +1 -0
  47. package/build/types/core/component-annotation-vite-fragments.d.ts +3 -0
  48. package/build/types/core/component-annotation-vite-fragments.d.ts.map +1 -0
  49. package/build/types/core/component-annotation-vite-jsx.d.ts +16 -0
  50. package/build/types/core/component-annotation-vite-jsx.d.ts.map +1 -0
  51. package/build/types/core/component-annotation-vite-walk.d.ts +3 -0
  52. package/build/types/core/component-annotation-vite-walk.d.ts.map +1 -0
  53. package/build/types/core/component-annotation-vite.d.ts +6 -0
  54. package/build/types/core/component-annotation-vite.d.ts.map +1 -0
  55. package/build/types/core/index.d.ts.map +1 -1
  56. package/build/types/core/version.d.ts +1 -1
  57. package/build/types/rollup/index.d.ts +7 -1
  58. package/build/types/rollup/index.d.ts.map +1 -1
  59. package/build/types-ts3.8/babel-plugin/component-annotation.d.ts +27 -0
  60. package/build/types-ts3.8/core/component-annotation-vite-ast.d.ts +57 -0
  61. package/build/types-ts3.8/core/component-annotation-vite-fragments.d.ts +3 -0
  62. package/build/types-ts3.8/core/component-annotation-vite-jsx.d.ts +16 -0
  63. package/build/types-ts3.8/core/component-annotation-vite-walk.d.ts +3 -0
  64. package/build/types-ts3.8/core/component-annotation-vite.d.ts +6 -0
  65. package/build/types-ts3.8/core/version.d.ts +1 -1
  66. package/build/types-ts3.8/rollup/index.d.ts +7 -1
  67. package/package.json +3 -3
@@ -0,0 +1,140 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const componentAnnotation = require('../babel-plugin/component-annotation.js');
4
+ const componentAnnotationViteAst = require('./component-annotation-vite-ast.js');
5
+ const core = require('@sentry/core');
6
+
7
+ const UNKNOWN_ELEMENT_NAME = "unknown";
8
+ const WEB_ATTRIBUTE_NAMES = [componentAnnotation.WEB_ELEMENT_NAME, componentAnnotation.WEB_COMPONENT_NAME, componentAnnotation.WEB_SOURCE_FILE_NAME];
9
+ const WEB_ATTRIBUTE_NAME_SET = new Set(WEB_ATTRIBUTE_NAMES);
10
+ function isJSXElement(value) {
11
+ return componentAnnotationViteAst.isAstNode(value) && value.type === "JSXElement";
12
+ }
13
+ function isJSXFragment(value) {
14
+ return componentAnnotationViteAst.isAstNode(value) && value.type === "JSXFragment";
15
+ }
16
+ function isJSXRoot(value) {
17
+ return isJSXElement(value) || isJSXFragment(value);
18
+ }
19
+ function getStringName(node) {
20
+ return core.isObjectLike(node) && typeof node.name === "string" ? node.name : null;
21
+ }
22
+ function getJSXName(name) {
23
+ if (!componentAnnotationViteAst.isAstNode(name)) {
24
+ return UNKNOWN_ELEMENT_NAME;
25
+ }
26
+ if (name.type === "JSXIdentifier") {
27
+ return getStringName(name) ?? UNKNOWN_ELEMENT_NAME;
28
+ }
29
+ if (name.type === "JSXNamespacedName") {
30
+ return getStringName(name.name) ?? UNKNOWN_ELEMENT_NAME;
31
+ }
32
+ if (name.type === "JSXMemberExpression") {
33
+ const objectName = getJSXName(name.object);
34
+ const propertyName = getJSXName(name.property);
35
+ return `${objectName}.${propertyName}`;
36
+ }
37
+ return UNKNOWN_ELEMENT_NAME;
38
+ }
39
+ function getInsertionOffset(code, openingElement) {
40
+ if (typeof openingElement.end !== "number") {
41
+ return null;
42
+ }
43
+ if (!openingElement.selfClosing) {
44
+ return openingElement.end - 1;
45
+ }
46
+ let offset = openingElement.end - 2;
47
+ while (offset > 0 && /\s/.test(code[offset] ?? "")) {
48
+ offset -= 1;
49
+ }
50
+ return code[offset] === "/" ? offset : openingElement.end - 1;
51
+ }
52
+ function isReactFragment(openingElement, fragmentContext) {
53
+ const elementName = getJSXName(openingElement.name);
54
+ if (elementName === "Fragment" || elementName === "React.Fragment") {
55
+ return true;
56
+ }
57
+ if (fragmentContext.fragmentAliases.has(elementName)) {
58
+ return true;
59
+ }
60
+ if (core.isObjectLike(openingElement.name) && openingElement.name.type === "JSXMemberExpression") {
61
+ const objectName = getJSXName(openingElement.name.object);
62
+ const propertyName = getJSXName(openingElement.name.property);
63
+ return propertyName === "Fragment" && (fragmentContext.reactNamespaceAliases.has(objectName) || fragmentContext.fragmentAliases.has(objectName));
64
+ }
65
+ return false;
66
+ }
67
+ function addPendingAttributes(code, openingElement, componentName, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset) {
68
+ const offset = getInsertionOffset(code, openingElement);
69
+ if (offset === null) {
70
+ return;
71
+ }
72
+ const pendingInsertion = insertionsByOffset.get(offset);
73
+ const existingAttributes = getExistingAttributeNames(openingElement);
74
+ for (const attributeName of pendingInsertion?.attributeValues.keys() ?? []) {
75
+ existingAttributes.add(attributeName);
76
+ }
77
+ const attributes = componentAnnotation.getComponentAnnotationAttributes({
78
+ attributeNames: [componentAnnotation.WEB_COMPONENT_NAME, componentAnnotation.WEB_ELEMENT_NAME, componentAnnotation.WEB_SOURCE_FILE_NAME],
79
+ componentName,
80
+ elementName: getJSXName(openingElement.name),
81
+ existingAttributes,
82
+ ignoredComponents,
83
+ isFragment: isReactFragment(openingElement, fragmentContext),
84
+ sourceFileName
85
+ });
86
+ if (attributes.length === 0) {
87
+ return;
88
+ }
89
+ const insertion = pendingInsertion ?? insertionsByOffset.set(offset, {
90
+ offset,
91
+ attributeValues: /* @__PURE__ */ new Map()
92
+ }).get(offset);
93
+ for (const [name, value] of attributes) {
94
+ insertion?.attributeValues.set(name, value);
95
+ }
96
+ }
97
+ function toAttributeInsertions(insertionsByOffset) {
98
+ return [...insertionsByOffset.values()].map(({ offset, attributeValues }) => ({
99
+ offset,
100
+ attributes: getOrderedAttributes(attributeValues)
101
+ }));
102
+ }
103
+ function getExistingAttributeNames(openingElement) {
104
+ const names = /* @__PURE__ */ new Set();
105
+ for (const attribute of openingElement.attributes ?? []) {
106
+ if (attribute.type === "JSXAttribute") {
107
+ const name = getStringName(attribute.name);
108
+ if (name) {
109
+ names.add(name);
110
+ }
111
+ }
112
+ }
113
+ return names;
114
+ }
115
+ function getOrderedAttributes(attributeValues) {
116
+ const attributes = [];
117
+ for (const name of WEB_ATTRIBUTE_NAMES) {
118
+ const value = attributeValues.get(name);
119
+ if (value) {
120
+ attributes.push([name, value]);
121
+ }
122
+ }
123
+ for (const [name, value] of attributeValues) {
124
+ if (!WEB_ATTRIBUTE_NAME_SET.has(name)) {
125
+ attributes.push([name, value]);
126
+ }
127
+ }
128
+ return attributes;
129
+ }
130
+
131
+ exports.addPendingAttributes = addPendingAttributes;
132
+ exports.getInsertionOffset = getInsertionOffset;
133
+ exports.getJSXName = getJSXName;
134
+ exports.getStringName = getStringName;
135
+ exports.isJSXElement = isJSXElement;
136
+ exports.isJSXFragment = isJSXFragment;
137
+ exports.isJSXRoot = isJSXRoot;
138
+ exports.isReactFragment = isReactFragment;
139
+ exports.toAttributeInsertions = toAttributeInsertions;
140
+ //# sourceMappingURL=component-annotation-vite-jsx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-annotation-vite-jsx.js","sources":["../../../src/core/component-annotation-vite-jsx.ts"],"sourcesContent":["import {\n getComponentAnnotationAttributes,\n WEB_COMPONENT_NAME,\n WEB_ELEMENT_NAME,\n WEB_SOURCE_FILE_NAME,\n} from '../babel-plugin/component-annotation';\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\nimport type {\n AttributeInsertion,\n FragmentContext,\n JSXElementNode,\n JSXFragmentNode,\n JSXOpeningElementNode,\n JSXRootNode,\n} from './component-annotation-vite-ast';\nimport { isAstNode, isObjectLike } from './component-annotation-vite-ast';\n\nconst UNKNOWN_ELEMENT_NAME = 'unknown';\nconst WEB_ATTRIBUTE_NAMES = [WEB_ELEMENT_NAME, WEB_COMPONENT_NAME, WEB_SOURCE_FILE_NAME] as const;\nconst WEB_ATTRIBUTE_NAME_SET = new Set<string>(WEB_ATTRIBUTE_NAMES);\n\ntype PendingInsertion = {\n offset: number;\n attributeValues: Map<string, string>;\n};\n\nexport function isJSXElement(value: unknown): value is JSXElementNode {\n return isAstNode(value) && value.type === 'JSXElement';\n}\n\nexport function isJSXFragment(value: unknown): value is JSXFragmentNode {\n return isAstNode(value) && value.type === 'JSXFragment';\n}\n\nexport function isJSXRoot(value: unknown): value is JSXRootNode {\n return isJSXElement(value) || isJSXFragment(value);\n}\n\nexport function getStringName(node: unknown): string | null {\n return isObjectLike(node) && typeof node.name === 'string' ? node.name : null;\n}\n\nexport function getJSXName(name: unknown): string {\n if (!isAstNode(name)) {\n return UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXIdentifier') {\n return getStringName(name) ?? UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXNamespacedName') {\n return getStringName(name.name) ?? UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXMemberExpression') {\n const objectName = getJSXName(name.object);\n const propertyName = getJSXName(name.property);\n\n return `${objectName}.${propertyName}`;\n }\n\n return UNKNOWN_ELEMENT_NAME;\n}\n\nexport function getInsertionOffset(code: string, openingElement: JSXOpeningElementNode): number | null {\n if (typeof openingElement.end !== 'number') {\n return null;\n }\n\n if (!openingElement.selfClosing) {\n return openingElement.end - 1;\n }\n\n let offset = openingElement.end - 2;\n\n while (offset > 0 && /\\s/.test(code[offset] ?? '')) {\n offset -= 1;\n }\n\n return code[offset] === '/' ? offset : openingElement.end - 1;\n}\n\nexport function isReactFragment(openingElement: JSXOpeningElementNode, fragmentContext: FragmentContext): boolean {\n const elementName = getJSXName(openingElement.name);\n\n if (elementName === 'Fragment' || elementName === 'React.Fragment') {\n return true;\n }\n\n if (fragmentContext.fragmentAliases.has(elementName)) {\n return true;\n }\n\n if (isObjectLike(openingElement.name) && openingElement.name.type === 'JSXMemberExpression') {\n const objectName = getJSXName(openingElement.name.object);\n const propertyName = getJSXName(openingElement.name.property);\n\n return (\n propertyName === 'Fragment' &&\n (fragmentContext.reactNamespaceAliases.has(objectName) || fragmentContext.fragmentAliases.has(objectName))\n );\n }\n\n return false;\n}\n\nexport function addPendingAttributes(\n code: string,\n openingElement: JSXOpeningElementNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n sourceFileName: string,\n insertionsByOffset: Map<number, PendingInsertion>,\n): void {\n const offset = getInsertionOffset(code, openingElement);\n if (offset === null) {\n return;\n }\n\n const pendingInsertion = insertionsByOffset.get(offset);\n const existingAttributes = getExistingAttributeNames(openingElement);\n\n for (const attributeName of pendingInsertion?.attributeValues.keys() ?? []) {\n existingAttributes.add(attributeName);\n }\n\n const attributes = getComponentAnnotationAttributes({\n attributeNames: [WEB_COMPONENT_NAME, WEB_ELEMENT_NAME, WEB_SOURCE_FILE_NAME],\n componentName,\n elementName: getJSXName(openingElement.name),\n existingAttributes,\n ignoredComponents,\n isFragment: isReactFragment(openingElement, fragmentContext),\n sourceFileName,\n });\n\n if (attributes.length === 0) {\n return;\n }\n\n const insertion =\n pendingInsertion ??\n insertionsByOffset\n .set(offset, {\n offset,\n attributeValues: new Map(),\n })\n .get(offset);\n\n for (const [name, value] of attributes) {\n insertion?.attributeValues.set(name, value);\n }\n}\n\nexport function toAttributeInsertions(insertionsByOffset: Map<number, PendingInsertion>): AttributeInsertion[] {\n return [...insertionsByOffset.values()].map(({ offset, attributeValues }) => ({\n offset,\n attributes: getOrderedAttributes(attributeValues),\n }));\n}\n\nfunction getExistingAttributeNames(openingElement: JSXOpeningElementNode): Set<string> {\n const names = new Set<string>();\n\n for (const attribute of openingElement.attributes ?? []) {\n if (attribute.type === 'JSXAttribute') {\n const name = getStringName(attribute.name);\n if (name) {\n names.add(name);\n }\n }\n }\n\n return names;\n}\n\nfunction getOrderedAttributes(attributeValues: ReadonlyMap<string, string>): ComponentAnnotationAttribute[] {\n const attributes: ComponentAnnotationAttribute[] = [];\n\n for (const name of WEB_ATTRIBUTE_NAMES) {\n const value = attributeValues.get(name);\n if (value) {\n attributes.push([name, value]);\n }\n }\n\n for (const [name, value] of attributeValues) {\n if (!WEB_ATTRIBUTE_NAME_SET.has(name)) {\n attributes.push([name, value]);\n }\n }\n\n return attributes;\n}\n"],"names":["WEB_ELEMENT_NAME","WEB_COMPONENT_NAME","WEB_SOURCE_FILE_NAME","isAstNode","isObjectLike","getComponentAnnotationAttributes"],"mappings":";;;;;;AAiBA,MAAM,oBAAA,GAAuB,SAAA;AAC7B,MAAM,mBAAA,GAAsB,CAACA,oCAAA,EAAkBC,sCAAA,EAAoBC,wCAAoB,CAAA;AACvF,MAAM,sBAAA,GAAyB,IAAI,GAAA,CAAY,mBAAmB,CAAA;AAO3D,SAAS,aAAa,KAAA,EAAyC;AACpE,EAAA,OAAOC,oCAAA,CAAU,KAAK,CAAA,IAAK,KAAA,CAAM,IAAA,KAAS,YAAA;AAC5C;AAEO,SAAS,cAAc,KAAA,EAA0C;AACtE,EAAA,OAAOA,oCAAA,CAAU,KAAK,CAAA,IAAK,KAAA,CAAM,IAAA,KAAS,aAAA;AAC5C;AAEO,SAAS,UAAU,KAAA,EAAsC;AAC9D,EAAA,OAAO,YAAA,CAAa,KAAK,CAAA,IAAK,aAAA,CAAc,KAAK,CAAA;AACnD;AAEO,SAAS,cAAc,IAAA,EAA8B;AAC1D,EAAA,OAAOC,iBAAA,CAAa,IAAI,CAAA,IAAK,OAAO,KAAK,IAAA,KAAS,QAAA,GAAW,KAAK,IAAA,GAAO,IAAA;AAC3E;AAEO,SAAS,WAAW,IAAA,EAAuB;AAChD,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AA,IAAI,IAAA,EAAM;AACR,QAAA,KAAA,CAAM,IAAI,IAAI,CAAA;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,KAAA;AACT;AAEA,SAAS,qBAAqB,eAAA,EAA8E;AAC1G,EAAA,MAAM,aAA6C,EAAC;AAEpD,EAAA,KAAA,MAAW,QAAQ,mBAAA,EAAqB;AACtC,IAAA,MAAM,KAAA,GAAQ,eAAA,CAAgB,GAAA,CAAI,IAAI,CAAA;AACtC,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,UAAA,CAAW,IAAA,CAAK,CAAC,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA,IAC/B;AAAA,EACF;AAEA,EAAA,KAAA,MAAW,CAAC,IAAA,EAAM,KAAK,CAAA,IAAK,eAAA,EAAiB;AAC3C,IAAA,IAAI,CAAC,sBAAA,CAAuB,GAAA,CAAI,IAAI,CAAA,EAAG;AACrC,MAAA,UAAA,CAAW,IAAA,CAAK,CAAC,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA,IAC/B;AAAA,EACF;AAEA,EAAA,OAAO,UAAA;AACT;;;;;;;;;;;;"}
@@ -0,0 +1,121 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const componentAnnotationViteJsx = require('./component-annotation-vite-jsx.js');
4
+ const componentAnnotationViteAst = require('./component-annotation-vite-ast.js');
5
+ const componentAnnotationViteFragments = require('./component-annotation-vite-fragments.js');
6
+ const core = require('@sentry/core');
7
+
8
+ function collectViteComponentAnnotationInsertions(code, ast, ignoredComponents, sourceFileName) {
9
+ const fragmentContext = componentAnnotationViteFragments.collectFragmentContext(ast);
10
+ const components = collectComponentJSXRoots(ast);
11
+ const insertionsByOffset = /* @__PURE__ */ new Map();
12
+ for (const component of components) {
13
+ for (const root of component.roots) {
14
+ processJSX(code, root, component.name, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);
15
+ }
16
+ }
17
+ return componentAnnotationViteJsx.toAttributeInsertions(insertionsByOffset);
18
+ }
19
+ function getJSXRootsFromReturnArgument(argument) {
20
+ if (componentAnnotationViteJsx.isJSXRoot(argument)) {
21
+ return [argument];
22
+ }
23
+ if (core.isObjectLike(argument) && argument.type === "ConditionalExpression") {
24
+ return [argument.consequent, argument.alternate].filter(componentAnnotationViteJsx.isJSXRoot);
25
+ }
26
+ return [];
27
+ }
28
+ function getReturnedJSXFromFunction(functionNode) {
29
+ const body = functionNode.body;
30
+ if (componentAnnotationViteJsx.isJSXRoot(body)) {
31
+ return [body];
32
+ }
33
+ if (!core.isObjectLike(body) || body.type !== "BlockStatement") {
34
+ return [];
35
+ }
36
+ const bodyStatements = Array.isArray(body.body) ? body.body : [];
37
+ const returnStatement = bodyStatements.find((statement) => {
38
+ return componentAnnotationViteAst.isAstNode(statement) && statement.type === "ReturnStatement";
39
+ });
40
+ return core.isObjectLike(returnStatement) ? getJSXRootsFromReturnArgument(returnStatement.argument) : [];
41
+ }
42
+ function pushFunctionComponent(components, nameNode, functionNode) {
43
+ const name = componentAnnotationViteJsx.getStringName(nameNode);
44
+ if (name) {
45
+ components.push({
46
+ name,
47
+ roots: getReturnedJSXFromFunction(functionNode)
48
+ });
49
+ }
50
+ }
51
+ function collectComponentJSXRoots(ast) {
52
+ const components = [];
53
+ componentAnnotationViteAst.walkAst(ast, (node) => {
54
+ if (node.type === "FunctionDeclaration" && core.isObjectLike(node.id)) {
55
+ pushFunctionComponent(components, node.id, node);
56
+ return;
57
+ }
58
+ if (node.type === "VariableDeclarator" && core.isObjectLike(node.id)) {
59
+ if (componentAnnotationViteAst.isAstNode(node.init) && node.init.type === "ArrowFunctionExpression") {
60
+ pushFunctionComponent(components, node.id, node.init);
61
+ }
62
+ return;
63
+ }
64
+ if (node.type === "ClassDeclaration") {
65
+ pushClassComponent(components, node);
66
+ }
67
+ });
68
+ return components;
69
+ }
70
+ function pushClassComponent(components, node) {
71
+ const renderMethodBody = getClassRenderMethodBody(node);
72
+ if (!renderMethodBody) {
73
+ return;
74
+ }
75
+ const roots = [];
76
+ componentAnnotationViteAst.walkAst(renderMethodBody, (child) => {
77
+ if (child.type === "ReturnStatement" && componentAnnotationViteJsx.isJSXRoot(child.argument)) {
78
+ roots.push(child.argument);
79
+ }
80
+ });
81
+ components.push({
82
+ name: componentAnnotationViteJsx.getStringName(node.id) ?? "",
83
+ roots
84
+ });
85
+ }
86
+ function getClassRenderMethodBody(node) {
87
+ if (!core.isObjectLike(node.body) || !Array.isArray(node.body.body)) {
88
+ return null;
89
+ }
90
+ const renderMethod = node.body.body.find((member) => {
91
+ return core.isObjectLike(member) && core.isObjectLike(member.key) && componentAnnotationViteJsx.getStringName(member.key) === "render" && (core.isObjectLike(member.value) || core.isObjectLike(member.body));
92
+ });
93
+ if (!core.isObjectLike(renderMethod)) {
94
+ return null;
95
+ }
96
+ if (componentAnnotationViteAst.isAstNode(renderMethod.value)) {
97
+ return renderMethod.value;
98
+ }
99
+ return componentAnnotationViteAst.isAstNode(renderMethod) ? renderMethod : null;
100
+ }
101
+ function processJSX(code, node, componentName, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset) {
102
+ if (componentAnnotationViteJsx.isJSXElement(node)) {
103
+ componentAnnotationViteJsx.addPendingAttributes(
104
+ code,
105
+ node.openingElement,
106
+ componentName,
107
+ ignoredComponents,
108
+ fragmentContext,
109
+ sourceFileName,
110
+ insertionsByOffset
111
+ );
112
+ }
113
+ for (const child of node.children ?? []) {
114
+ if (componentAnnotationViteJsx.isJSXRoot(child)) {
115
+ processJSX(code, child, "", ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);
116
+ }
117
+ }
118
+ }
119
+
120
+ exports.collectViteComponentAnnotationInsertions = collectViteComponentAnnotationInsertions;
121
+ //# sourceMappingURL=component-annotation-vite-walk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-annotation-vite-walk.js","sources":["../../../src/core/component-annotation-vite-walk.ts"],"sourcesContent":["import type { AstNode, AttributeInsertion, FragmentContext, JSXRootNode } from './component-annotation-vite-ast';\nimport {\n addPendingAttributes,\n getStringName,\n isJSXElement,\n isJSXRoot,\n toAttributeInsertions,\n} from './component-annotation-vite-jsx';\nimport { isAstNode, isObjectLike, walkAst } from './component-annotation-vite-ast';\nimport { collectFragmentContext } from './component-annotation-vite-fragments';\n\ntype ComponentJSXRoots = { name: string; roots: JSXRootNode[] };\n\nexport function collectViteComponentAnnotationInsertions(\n code: string,\n ast: AstNode,\n ignoredComponents: string[],\n sourceFileName: string,\n): AttributeInsertion[] {\n const fragmentContext = collectFragmentContext(ast);\n const components = collectComponentJSXRoots(ast);\n const insertionsByOffset = new Map<number, { offset: number; attributeValues: Map<string, string> }>();\n\n for (const component of components) {\n for (const root of component.roots) {\n processJSX(code, root, component.name, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n\n return toAttributeInsertions(insertionsByOffset);\n}\n\nfunction getJSXRootsFromReturnArgument(argument: unknown): JSXRootNode[] {\n if (isJSXRoot(argument)) {\n return [argument];\n }\n\n if (isObjectLike(argument) && argument.type === 'ConditionalExpression') {\n return [argument.consequent, argument.alternate].filter(isJSXRoot);\n }\n\n return [];\n}\n\nfunction getReturnedJSXFromFunction(functionNode: AstNode): JSXRootNode[] {\n const body = functionNode.body;\n\n if (isJSXRoot(body)) {\n return [body];\n }\n\n if (!isObjectLike(body) || body.type !== 'BlockStatement') {\n return [];\n }\n\n const bodyStatements = Array.isArray(body.body) ? body.body : [];\n const returnStatement = bodyStatements.find(statement => {\n return isAstNode(statement) && statement.type === 'ReturnStatement';\n });\n\n return isObjectLike(returnStatement) ? getJSXRootsFromReturnArgument(returnStatement.argument) : [];\n}\n\nfunction pushFunctionComponent(components: ComponentJSXRoots[], nameNode: unknown, functionNode: AstNode): void {\n const name = getStringName(nameNode);\n\n if (name) {\n components.push({\n name,\n roots: getReturnedJSXFromFunction(functionNode),\n });\n }\n}\n\nfunction collectComponentJSXRoots(ast: AstNode): ComponentJSXRoots[] {\n const components: ComponentJSXRoots[] = [];\n\n walkAst(ast, node => {\n if (node.type === 'FunctionDeclaration' && isObjectLike(node.id)) {\n pushFunctionComponent(components, node.id, node);\n return;\n }\n\n if (node.type === 'VariableDeclarator' && isObjectLike(node.id)) {\n if (isAstNode(node.init) && node.init.type === 'ArrowFunctionExpression') {\n pushFunctionComponent(components, node.id, node.init);\n }\n\n return;\n }\n\n if (node.type === 'ClassDeclaration') {\n pushClassComponent(components, node);\n }\n });\n\n return components;\n}\n\nfunction pushClassComponent(components: ComponentJSXRoots[], node: AstNode): void {\n const renderMethodBody = getClassRenderMethodBody(node);\n\n if (!renderMethodBody) {\n return;\n }\n\n const roots: JSXRootNode[] = [];\n\n walkAst(renderMethodBody, child => {\n if (child.type === 'ReturnStatement' && isJSXRoot(child.argument)) {\n roots.push(child.argument);\n }\n });\n\n components.push({\n name: getStringName(node.id) ?? '',\n roots,\n });\n}\n\nfunction getClassRenderMethodBody(node: AstNode): AstNode | null {\n if (!isObjectLike(node.body) || !Array.isArray(node.body.body)) {\n return null;\n }\n\n const renderMethod = node.body.body.find(member => {\n return (\n isObjectLike(member) &&\n isObjectLike(member.key) &&\n getStringName(member.key) === 'render' &&\n (isObjectLike(member.value) || isObjectLike(member.body))\n );\n });\n\n if (!isObjectLike(renderMethod)) {\n return null;\n }\n\n if (isAstNode(renderMethod.value)) {\n return renderMethod.value;\n }\n\n return isAstNode(renderMethod) ? renderMethod : null;\n}\n\nfunction processJSX(\n code: string,\n node: JSXRootNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n sourceFileName: string,\n insertionsByOffset: Map<number, { offset: number; attributeValues: Map<string, string> }>,\n): void {\n if (isJSXElement(node)) {\n addPendingAttributes(\n code,\n node.openingElement,\n componentName,\n ignoredComponents,\n fragmentContext,\n sourceFileName,\n insertionsByOffset,\n );\n }\n\n for (const child of node.children ?? []) {\n if (isJSXRoot(child)) {\n processJSX(code, child, '', ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n}\n"],"names":["collectFragmentContext","toAttributeInsertions","isJSXRoot","isObjectLike","isAstNode","getStringName","walkAst","isJSXElement","addPendingAttributes"],"mappings":";;;;;;;AAaO,SAAS,wCAAA,CACd,IAAA,EACA,GAAA,EACA,iBAAA,EACA,cAAA,EACsB;AACtB,EAAA,MAAM,eAAA,GAAkBA,wDAAuB,GAAG,CAAA;AAClD,EAAA,MAAM,UAAA,GAAa,yBAAyB,GAAG,CAAA;AAC/C,EAAA,MAAM,kBAAA,uBAAyB,GAAA,EAAsE;AAErG,EAAA,KAAA,MAAW,aAAa,UAAA,EAAY;AAClC,IAAA,KAAA,MAAW,IAAA,IAAQ,UAAU,KAAA,EAAO;AAClC,MAAA,UAAA,CAAW,MAAM,IAAA,EAAM,SAAA,CAAU,MAAM,iBAAA,EAAmB,eAAA,EAAiB,gBAAgB,kBAAkB,CAAA;AAAA,IAC/G;AAAA,EACF;AAEA,EAAA,OAAOC,iDAAsB,kBAAkB,CAAA;AACjD;AAEA,SAAS,8BAA8B,QAAA,EAAkC;AACvE,EAAA,IAAIC,oCAAA,CAAU,QAAQ,CAAA,EAAG;AACvB,IAAA,OAAO,CAAC,QAAQ,CAAA;AAAA,EAClB;AAEA,EAAA,IAAIC,iBAAA,CAAa,QAAQ,CAAA,IAAK,QAAA,CAAS,SAAS,uBAAA,EAAyB;AACvE,IAAA,OAAO,CAAC,QAAA,CAAS,UAAA,EAAY,SAAS,SAAS,CAAA,CAAE,OAAOD,oCAAS,CAAA;AAAA,EACnE;AAEA,EAAA,OAAO,EAAC;AACV;AAEA,SAAS,2BAA2B,YAAA,EAAsC;AACxE,EAAA,MAAM,OAAO,YAAA,CAAa,IAAA;AAE1B,EAAA,IAAIA,oCAAA,CAAU,IAAI,CAAA,EAAG;AACnB,IAAA,OAAO,CAAC,IAAI,CAAA;AAAA,EACd;AAEA,EAAA,IAAI,CAACC,iBAAA,CAAa,IAAI,CAAA,IAAK,IAAA,CAAK,SAAS,gBAAA,EAAk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A,KAAM,aAC7BF,iBAAA,CAAa,MAAA,CAAO,KAAK,CAAA,IAAKA,iBAAA,CAAa,OAAO,IAAI,CAAA,CAAA;AAAA,EAE3D,CAAC,CAAA;AAED,EAAA,IAAI,CAACA,iBAAA,CAAa,YAAY,CAAA,EAAG;AAC/B,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,IAAIC,oCAAA,CAAU,YAAA,CAAa,KAAK,CAAA,EAAG;AACjC,IAAA,OAAO,YAAA,CAAa,KAAA;AAAA,EACtB;AAEA,EAAA,OAAOA,oCAAA,CAAU,YAAY,CAAA,GAAI,YAAA,GAAe,IAAA;AAClD;AAEA,SAAS,WACP,IAAA,EACA,IAAA,EACA,eACA,iBAAA,EACA,eAAA,EACA,gBACA,kBAAA,EACM;AACN,EAAA,IAAIG,uCAAA,CAAa,IAAI,CAAA,EAAG;AACtB,IAAAC,+CAAA;AAAA,MACE,IAAA;AAAA,MACA,IAAA,CAAK,cAAA;AAAA,MACL,aAAA;AAAA,MACA,iBAAA;AAAA,MACA,eAAA;AAAA,MACA,cAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAEA,EAAA,KAAA,MAAW,KAAA,IAAS,IAAA,CAAK,QAAA,IAAY,EAAC,EAAG;AACvC,IAAA,IAAIN,oCAAA,CAAU,KAAK,CAAA,EAAG;AACpB,MAAA,UAAA,CAAW,MAAM,KAAA,EAAO,EAAA,EAAI,iBAAA,EAAmB,eAAA,EAAiB,gBAAgB,kBAAkB,CAAA;AAAA,IACpG;AAAA,EACF;AACF;;;;"}
@@ -0,0 +1,101 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const path = require('node:path');
4
+ const MagicString = require('magic-string');
5
+ const constants = require('../babel-plugin/constants.js');
6
+ const utils = require('./utils.js');
7
+ const componentAnnotationViteAst = require('./component-annotation-vite-ast.js');
8
+ const componentAnnotationViteWalk = require('./component-annotation-vite-walk.js');
9
+
10
+ const _interopDefault = e => e && e.__esModule ? e.default : e;
11
+
12
+ const path__default = /*#__PURE__*/_interopDefault(path);
13
+ const MagicString__default = /*#__PURE__*/_interopDefault(MagicString);
14
+
15
+ const JSX_TAG_START_REGEXP = /<[$_\p{ID_Start}][$_\u200c\u200d\p{ID_Continue}.:-]*|<>/u;
16
+ const JSX_FILE_REGEXP = /\.[jt]sx$/;
17
+ function isViteAnnotationFile(idWithoutQueryAndHash) {
18
+ if (idWithoutQueryAndHash.match(/\\node_modules\\|\/node_modules\//)) {
19
+ return false;
20
+ }
21
+ return JSX_FILE_REGEXP.test(idWithoutQueryAndHash);
22
+ }
23
+ function shouldTryParse(code) {
24
+ return JSX_TAG_START_REGEXP.test(code);
25
+ }
26
+ function shouldSkipIncompatibleFile(idWithoutQueryAndHash) {
27
+ return constants.KNOWN_INCOMPATIBLE_PLUGINS.some((pluginName) => {
28
+ return idWithoutQueryAndHash.includes(`/node_modules/${pluginName}/`) || idWithoutQueryAndHash.includes(`\\node_modules\\${pluginName}\\`);
29
+ });
30
+ }
31
+ function escapeAttributeValue(value) {
32
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
33
+ }
34
+ function makeAttributeText(code, insertionOffset, attributes) {
35
+ const previousCharIsWhitespace = insertionOffset > 0 && /\s/.test(code[insertionOffset - 1] ?? "");
36
+ const prefix = previousCharIsWhitespace ? "" : " ";
37
+ const suffix = previousCharIsWhitespace && code[insertionOffset] === "/" ? " " : "";
38
+ const attributeText = attributes.map(([name, value]) => `${name}="${escapeAttributeValue(value)}"`).join(" ");
39
+ return `${prefix}${attributeText}${suffix}`;
40
+ }
41
+ function getMagicString(code, meta) {
42
+ if (meta?.magicString) {
43
+ return { magicString: meta.magicString, isNative: true };
44
+ }
45
+ return { magicString: new MagicString__default(code), isNative: false };
46
+ }
47
+ async function annotateWithViteParser(code, id, ignoredComponents, parseAstAsync, meta) {
48
+ const idWithoutQueryAndHash = utils.stripQueryAndHashFromPath(id);
49
+ if (!idWithoutQueryAndHash || !isViteAnnotationFile(idWithoutQueryAndHash) || !shouldTryParse(code) || shouldSkipIncompatibleFile(idWithoutQueryAndHash)) {
50
+ return null;
51
+ }
52
+ const ast = await parseAstAsync(code, {
53
+ lang: idWithoutQueryAndHash.endsWith(".jsx") ? "jsx" : "tsx"
54
+ });
55
+ if (!componentAnnotationViteAst.isAstNode(ast)) {
56
+ return void 0;
57
+ }
58
+ const insertions = componentAnnotationViteWalk.collectViteComponentAnnotationInsertions(
59
+ code,
60
+ ast,
61
+ ignoredComponents,
62
+ path__default.basename(idWithoutQueryAndHash)
63
+ );
64
+ if (insertions.length === 0) {
65
+ return null;
66
+ }
67
+ const { magicString, isNative } = getMagicString(code, meta);
68
+ for (const insertion of insertions) {
69
+ magicString.appendLeft(insertion.offset, makeAttributeText(code, insertion.offset, insertion.attributes));
70
+ }
71
+ if (isNative) {
72
+ return { code: magicString };
73
+ }
74
+ return {
75
+ code: magicString.toString(),
76
+ map: magicString.generateMap?.({
77
+ file: id,
78
+ source: idWithoutQueryAndHash,
79
+ includeContent: true,
80
+ hires: true
81
+ })
82
+ };
83
+ }
84
+ function createViteComponentNameAnnotateHooks(ignoredComponents, getParseAstAsync) {
85
+ return {
86
+ async transform(code, id, meta) {
87
+ try {
88
+ const parseAstAsync = await getParseAstAsync();
89
+ if (!parseAstAsync) {
90
+ return void 0;
91
+ }
92
+ return await annotateWithViteParser(code, id, ignoredComponents, parseAstAsync, meta);
93
+ } catch {
94
+ return void 0;
95
+ }
96
+ }
97
+ };
98
+ }
99
+
100
+ exports.createViteComponentNameAnnotateHooks = createViteComponentNameAnnotateHooks;
101
+ //# sourceMappingURL=component-annotation-vite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-annotation-vite.js","sources":["../../../src/core/component-annotation-vite.ts"],"sourcesContent":["import path from 'node:path';\n\nimport MagicString from 'magic-string';\n\nimport { KNOWN_INCOMPATIBLE_PLUGINS } from '../babel-plugin/constants';\nimport { stripQueryAndHashFromPath } from './utils';\nimport { isAstNode } from './component-annotation-vite-ast';\nimport { collectViteComponentAnnotationInsertions } from './component-annotation-vite-walk';\nimport type {\n AttributeInsertion,\n ComponentAnnotationTransformMeta,\n ComponentAnnotationTransformResult,\n MagicStringLike,\n ParseAstAsync,\n} from './component-annotation-vite-ast';\n\nexport type {\n ComponentAnnotationTransformMeta,\n ComponentAnnotationTransformResult,\n} from './component-annotation-vite-ast';\n\n// Keep this as a superset of JSX tag starts Babel can annotate, because a miss suppresses Babel fallback.\nconst JSX_TAG_START_REGEXP = /<[$_\\p{ID_Start}][$_\\u200c\\u200d\\p{ID_Continue}.:-]*|<>/u;\nconst JSX_FILE_REGEXP = /\\.[jt]sx$/;\n\nfunction isViteAnnotationFile(idWithoutQueryAndHash: string): boolean {\n if (idWithoutQueryAndHash.match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n return false;\n }\n\n return JSX_FILE_REGEXP.test(idWithoutQueryAndHash);\n}\n\nfunction shouldTryParse(code: string): boolean {\n return JSX_TAG_START_REGEXP.test(code);\n}\n\nfunction shouldSkipIncompatibleFile(idWithoutQueryAndHash: string): boolean {\n return KNOWN_INCOMPATIBLE_PLUGINS.some(pluginName => {\n return (\n idWithoutQueryAndHash.includes(`/node_modules/${pluginName}/`) ||\n idWithoutQueryAndHash.includes(`\\\\node_modules\\\\${pluginName}\\\\`)\n );\n });\n}\n\nfunction escapeAttributeValue(value: string): string {\n return value.replace(/&/g, '&amp;').replace(/\"/g, '&quot;');\n}\n\nfunction makeAttributeText(\n code: string,\n insertionOffset: number,\n attributes: AttributeInsertion['attributes'],\n): string {\n const previousCharIsWhitespace = insertionOffset > 0 && /\\s/.test(code[insertionOffset - 1] ?? '');\n const prefix = previousCharIsWhitespace ? '' : ' ';\n const suffix = previousCharIsWhitespace && code[insertionOffset] === '/' ? ' ' : '';\n const attributeText = attributes.map(([name, value]) => `${name}=\"${escapeAttributeValue(value)}\"`).join(' ');\n\n return `${prefix}${attributeText}${suffix}`;\n}\n\nfunction getMagicString(\n code: string,\n meta?: ComponentAnnotationTransformMeta,\n): { magicString: MagicStringLike; isNative: boolean } {\n if (meta?.magicString) {\n return { magicString: meta.magicString, isNative: true };\n }\n\n return { magicString: new MagicString(code), isNative: false };\n}\n\nasync function annotateWithViteParser(\n code: string,\n id: string,\n ignoredComponents: string[],\n parseAstAsync: ParseAstAsync,\n meta?: ComponentAnnotationTransformMeta,\n): Promise<ComponentAnnotationTransformResult> {\n const idWithoutQueryAndHash = stripQueryAndHashFromPath(id);\n\n if (\n !idWithoutQueryAndHash ||\n !isViteAnnotationFile(idWithoutQueryAndHash) ||\n !shouldTryParse(code) ||\n shouldSkipIncompatibleFile(idWithoutQueryAndHash)\n ) {\n return null;\n }\n\n const ast = await parseAstAsync(code, {\n lang: idWithoutQueryAndHash.endsWith('.jsx') ? 'jsx' : 'tsx',\n });\n\n // Fall through to the Babel fallback (return undefined, not null) when the parser yields an\n // unexpected result, mirroring the catch path — null would suppress Babel and drop annotations.\n if (!isAstNode(ast)) {\n return undefined;\n }\n\n const insertions = collectViteComponentAnnotationInsertions(\n code,\n ast,\n ignoredComponents,\n path.basename(idWithoutQueryAndHash),\n );\n\n if (insertions.length === 0) {\n return null;\n }\n\n const { magicString, isNative } = getMagicString(code, meta);\n\n for (const insertion of insertions) {\n magicString.appendLeft(insertion.offset, makeAttributeText(code, insertion.offset, insertion.attributes));\n }\n\n if (isNative) {\n return { code: magicString as unknown as string };\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap?.({\n file: id,\n source: idWithoutQueryAndHash,\n includeContent: true,\n hires: true,\n }),\n };\n}\n\nexport function createViteComponentNameAnnotateHooks(\n ignoredComponents: string[],\n getParseAstAsync: () => Promise<ParseAstAsync | null>,\n): {\n transform(\n code: string,\n id: string,\n meta?: ComponentAnnotationTransformMeta,\n ): Promise<ComponentAnnotationTransformResult>;\n} {\n return {\n async transform(code, id, meta) {\n try {\n const parseAstAsync = await getParseAstAsync();\n\n if (!parseAstAsync) {\n return undefined;\n }\n\n return await annotateWithViteParser(code, id, ignoredComponents, parseAstAsync, meta);\n } catch {\n return undefined;\n }\n },\n };\n}\n"],"names":["KNOWN_INCOMPATIBLE_PLUGINS","MagicString","stripQueryAndHashFromPath","isAstNode","collectViteComponentAnnotationInsertions","path"],"mappings":";;;;;;;;;;;;;;AAsBA,MAAM,oBAAA,GAAuB,0DAAA;AAC7B,MAAM,eAAA,GAAkB,WAAA;AAExB,SAAS,qBAAqB,qBAAA,EAAwC;AACpE,EAAA,IAAI,qBAAA,CAAsB,KAAA,CAAM,mCAAmC,CAAA,EAAG;AACpE,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,OAAO,eAAA,CAAgB,KAAK,qBAAqB,CAAA;AACnD;AAEA,SAAS,eAAe,IAAA,EAAuB;AAC7C,EAAA,OAAO,oBAAA,CAAqB,KAAK,IAAI,CAAA;AACvC;AAEA,SAAS,2BAA2B,qBAAA,EAAwC;AAC1E,EAAA,OAAOA,oCAAA,CAA2B,KAAK,CAAA,UAAA,KAAc;AACnD,IAAA,OACE,qBAAA,CAAsB,QAAA,CAAS,CAAA,cAAA,EAAiB,UAAU,CAAA,CAAA,CAAG,KAC7D,qBAAA,CAAsB,QAAA,CAAS,CAAA,gBAAA,EAAmB,UAAU,CAAA,EAAA,CAAI,CAAA;AAAA,EAEpE,CAAC,CAAA;AACH;AAEA,SAAS,qBAAqB,KAAA,EAAuB;AACnD,EAAA,OAAO,MAAM,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAA,CAAE,OAAA,CAAQ,MAAM,QAAQ,CAAA;AAC5D;AAEA,SAAS,iBAAA,CACP,IAAA,EACA,eAAA,EACA,UAAA,EACQ;AACR,EAAA,MAAM,wBAAA,GAA2B,kBAAkB,CAAA,IAAK,IAAA,CAAK,KAAK,IAAA,CAAK,eAAA,GAAkB,CAAC,CAAA,IAAK,EAAE,CAAA;AACjG,EAAA,MAAM,MAAA,GAAS,2BAA2B,EAAA,GAAK,GAAA;AAC/C,EAAA,MAAM,SAAS,wB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12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const core = require('@babel/core');
4
- const index = require('../babel-plugin/index.js');
5
3
  const SentryCli = require('@sentry/cli');
6
- const core$1 = require('@sentry/core');
4
+ const core = require('@sentry/core');
7
5
  const fs = require('fs');
8
6
  const utils = require('./utils.js');
9
7
  const glob = require('./glob.js');
10
8
  const buildPluginManager = require('./build-plugin-manager.js');
11
9
  const debugIdUpload = require('./debug-id-upload.js');
12
- const experimental = require('../babel-plugin/experimental.js');
13
10
 
14
11
  const _interopDefault = e => e && e.__esModule ? e.default : e;
15
12
 
@@ -28,6 +25,21 @@ function _interopNamespace(e) {
28
25
  const SentryCli__default = /*#__PURE__*/_interopDefault(SentryCli);
29
26
  const fs__namespace = /*#__PURE__*/_interopNamespace(fs);
30
27
 
28
+ let babelAnnotationRuntimePromise;
29
+ function loadBabelAnnotationRuntime() {
30
+ if (!babelAnnotationRuntimePromise) {
31
+ babelAnnotationRuntimePromise = Promise.all([import('@babel/core'), Promise.resolve().then(() => require('../babel-plugin/index.js'))]).then(
32
+ ([babel, babelPlugin]) => {
33
+ return {
34
+ transformAsync: babel.transformAsync,
35
+ componentNameAnnotatePlugin: babelPlugin.default,
36
+ experimentalComponentNameAnnotatePlugin: babelPlugin.experimentalComponentNameAnnotatePlugin
37
+ };
38
+ }
39
+ );
40
+ }
41
+ return babelAnnotationRuntimePromise;
42
+ }
31
43
  function sentryCliBinaryExists() {
32
44
  return fs__namespace.existsSync(SentryCli__default.getPath());
33
45
  }
@@ -64,9 +76,10 @@ function createComponentNameAnnotateHooks(ignoredComponents, injectIntoHtml) {
64
76
  } else if (idWithoutQueryAndHash.endsWith(".tsx")) {
65
77
  parserPlugins.push("jsx", "typescript");
66
78
  }
67
- const plugin = injectIntoHtml ? experimental.experimentalComponentNameAnnotatePlugin : index.default;
79
+ const { transformAsync, componentNameAnnotatePlugin, experimentalComponentNameAnnotatePlugin } = await loadBabelAnnotationRuntime();
80
+ const plugin = injectIntoHtml ? experimentalComponentNameAnnotatePlugin : componentNameAnnotatePlugin;
68
81
  try {
69
- const result = await core.transformAsync(code, {
82
+ const result = await transformAsync(code, {
70
83
  plugins: [[plugin, { ignoredComponents }]],
71
84
  filename: id,
72
85
  parserOpts: {
@@ -84,7 +97,7 @@ function createComponentNameAnnotateHooks(ignoredComponents, injectIntoHtml) {
84
97
  map: result?.map
85
98
  };
86
99
  } catch (e) {
87
- core$1.debug.error(`Failed to apply react annotate plugin`, e);
100
+ core.debug.error(`Failed to apply react annotate plugin`, e);
88
101
  }
89
102
  return { code };
90
103
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/core/index.ts"],"sourcesContent":["import { transformAsync } from '@babel/core';\nimport componentNameAnnotatePlugin, { experimentalComponentNameAnnotatePlugin } from '../babel-plugin';\nimport SentryCli from '@sentry/cli';\nimport { debug } from '@sentry/core';\nimport * as fs from 'fs';\nimport { CodeInjection, containsOnlyImports, stripQueryAndHashFromPath } from './utils';\n\n/**\n * Determines whether the Sentry CLI binary is in its expected location.\n * This function is useful since `@sentry/cli` installs the binary via a post-install\n * script and post-install scripts may not always run. E.g. with `npm i --ignore-scripts`.\n */\nexport function sentryCliBinaryExists(): boolean {\n return fs.existsSync(SentryCli.getPath());\n}\n\n// We need to be careful not to inject the snippet before any `\"use strict\";`s.\n// As an additional complication `\"use strict\";`s may come after any number of comments.\nexport const COMMENT_USE_STRICT_REGEX =\n // Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files.\n /^(?:\\s*|\\/\\*(?:.|\\r|\\n)*?\\*\\/|\\/\\/.*[\\n\\r])*(?:\"[^\"]*\";|'[^']*';)?/;\n\n/**\n * Checks if a file is a JavaScript file based on its extension.\n * Handles query strings and hashes in the filename.\n */\nexport function isJsFile(fileName: string): boolean {\n const cleanFileName = stripQueryAndHashFromPath(fileName);\n return ['.js', '.mjs', '.cjs'].some(ext => cleanFileName.endsWith(ext));\n}\n\n/**\n * Checks if a chunk should be skipped for code injection\n *\n * This is necessary to handle Vite's MPA (multi-page application) mode where\n * HTML entry points create \"facade\" chunks that should not contain injected code.\n * See: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829\n *\n * However, in SPA mode, the main bundle also has an HTML facade but contains\n * substantial application code. We should NOT skip injection for these bundles.\n *\n * @param code - The chunk's code content\n * @param facadeModuleId - The facade module ID (if any) - HTML files create facade chunks\n * @returns true if the chunk should be skipped\n */\nexport function shouldSkipCodeInjection(code: string, facadeModuleId: string | null | undefined): boolean {\n // Skip empty chunks - these are placeholder chunks that should be optimized away\n if (code.trim().length === 0) {\n return true;\n }\n\n // For HTML facade chunks, only skip if they contain only import statements\n if (facadeModuleId && stripQueryAndHashFromPath(facadeModuleId).endsWith('.html')) {\n return containsOnlyImports(code);\n }\n\n return false;\n}\n\nexport { globFiles } from './glob';\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function createComponentNameAnnotateHooks(ignoredComponents: string[], injectIntoHtml: boolean) {\n type ParserPlugins = NonNullable<NonNullable<Parameters<typeof transformAsync>[1]>['parserOpts']>['plugins'];\n\n return {\n async transform(this: void, code: string, id: string) {\n // id may contain query and hash which will trip up our file extension logic below\n const idWithoutQueryAndHash = stripQueryAndHashFromPath(id);\n\n if (idWithoutQueryAndHash.match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n return null;\n }\n\n // We will only apply this plugin on jsx and tsx files\n if (!['.jsx', '.tsx'].some(ending => idWithoutQueryAndHash.endsWith(ending))) {\n return null;\n }\n\n const parserPlugins: ParserPlugins = [];\n if (idWithoutQueryAndHash.endsWith('.jsx')) {\n parserPlugins.push('jsx');\n } else if (idWithoutQueryAndHash.endsWith('.tsx')) {\n parserPlugins.push('jsx', 'typescript');\n }\n\n const plugin = injectIntoHtml ? experimentalComponentNameAnnotatePlugin : componentNameAnnotatePlugin;\n\n try {\n const result = await transformAsync(code, {\n plugins: [[plugin, { ignoredComponents }]],\n filename: id,\n parserOpts: {\n sourceType: 'module',\n allowAwaitOutsideFunction: true,\n plugins: parserPlugins,\n },\n generatorOpts: {\n decoratorsBeforeExport: true,\n },\n sourceMaps: true,\n });\n\n return {\n code: result?.code ?? code,\n map: result?.map,\n };\n } catch (e) {\n debug.error(`Failed to apply react annotate plugin`, e);\n }\n\n return { code };\n },\n };\n}\n\nexport function getDebugIdSnippet(debugId: string): CodeInjection {\n return new CodeInjection(\n `var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\"${debugId}\",e._sentryDebugIdIdentifier=\"sentry-dbid-${debugId}\");`,\n );\n}\n\nexport type { Logger } from './logger';\nexport type { Options, SentrySDKBuildFlags } from './types';\nexport {\n CodeInjection,\n replaceBooleanFlagsInCode,\n stringToUUID,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n} from './utils';\nexport { createSentryBuildPluginManager } from './build-plugin-manager';\nexport { createDebugIdUploadFunction } from './debug-id-upload';\n"],"names":["fs","SentryCli","stripQueryAndHashFromPath","containsOnlyImports","experimentalComponentNameAnnotatePlugin","componentNameAnnotatePlugin","transformAsync","debug","CodeInjection"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,OAAOA,aAAA,CAAG,UAAA,CAAWC,kBAAA,CAAU,OAAA,EAAS,CAAA;AAC1C;AAIO,MAAM,wBAAA;AAAA;AAAA,EAEX;AAAA;AAMK,SAAS,SAAS,QAAA,EAA2B;AAClD,EAAA,MAAM,aAAA,GAAgBC,gCAA0B,QAAQ,CAAA;AACxD,EAAA,OAAO,CAAC,KAAA,EAAO,MAAA,EAAQ,MAAM,CAAA,CAAE,KAAK,CAAA,GAAA,KAAO,aAAA,CAAc,QAAA,CAAS,GAAG,CAAC,CAAA;AACxE;AAgBO,SAAS,uBAAA,CAAwB,MAAc,cAAA,EAAoD;AAExG,EAAA,IAAI,IAAA,CAAK,IAAA,EAAK,CAAE,M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AAA,YACV,UAAA,EAAY,QAAA;AAAA,YACZ,yBAAA,EAA2B,IAAA;AAAA,YAC3B,OAAA,EAAS;AAAA,WACX;AAAA,UACA,aAAA,EAAe;AAAA,YACb,sBAAA,EAAwB;AAAA,WAC1B;AAAA,UACA,UAAA,EAAY;AAAA,SACb,CAAA;AAED,QAAA,OAAO;AAAA,UACL,IAAA,EAAM,QAAQ,IAAA,IAAQ,IAAA;AAAA,UACtB,KAAK,MAAA,EAAQ;AAAA,SACf;AAAA,MACF,SAAS,CAAA,EAAG;AACV,QAAAC,YAAA,CAAM,KAAA,CAAM,yCAAyC,CAAC,CAAA;AAAA,MACxD;AAEA,MAAA,OAAO,EAAE,IAAA,EAAK;AAAA,IAChB;AAAA,GACF;AACF;AAEO,SAAS,kBAAkB,OAAA,EAAgC;AAChE,EAAA,OAAO,IAAIC,mBAAA;AAAA,IACT,CAAA,4FAAA,EAA+F,OAAO,CAAA,0CAAA,EAA6C,OAAO,CAAA,GAAA;AAAA,GAC5J;AACF;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/core/index.ts"],"sourcesContent":["import SentryCli from '@sentry/cli';\nimport { debug } from '@sentry/core';\nimport * as fs from 'fs';\nimport { CodeInjection, containsOnlyImports, stripQueryAndHashFromPath } from './utils';\nimport type { transformAsync as babelTransformAsync } from '@babel/core';\nimport type componentNameAnnotatePlugin from '../babel-plugin';\nimport type { experimentalComponentNameAnnotatePlugin } from '../babel-plugin';\n\ntype BabelTransformAsync = typeof babelTransformAsync;\ntype BabelParserPlugins = NonNullable<NonNullable<Parameters<BabelTransformAsync>[1]>['parserOpts']>['plugins'];\ntype BabelAnnotationRuntime = {\n transformAsync: BabelTransformAsync;\n componentNameAnnotatePlugin: typeof componentNameAnnotatePlugin;\n experimentalComponentNameAnnotatePlugin: typeof experimentalComponentNameAnnotatePlugin;\n};\n\nlet babelAnnotationRuntimePromise: Promise<BabelAnnotationRuntime> | undefined;\n\nfunction loadBabelAnnotationRuntime(): Promise<BabelAnnotationRuntime> {\n if (!babelAnnotationRuntimePromise) {\n babelAnnotationRuntimePromise = Promise.all([import('@babel/core'), import('../babel-plugin')]).then(\n ([babel, babelPlugin]) => {\n return {\n transformAsync: babel.transformAsync,\n componentNameAnnotatePlugin: babelPlugin.default,\n experimentalComponentNameAnnotatePlugin: babelPlugin.experimentalComponentNameAnnotatePlugin,\n };\n },\n );\n }\n\n return babelAnnotationRuntimePromise;\n}\n\n/**\n * Determines whether the Sentry CLI binary is in its expected location.\n * This function is useful since `@sentry/cli` installs the binary via a post-install\n * script and post-install scripts may not always run. E.g. with `npm i --ignore-scripts`.\n */\nexport function sentryCliBinaryExists(): boolean {\n return fs.existsSync(SentryCli.getPath());\n}\n\n// We need to be careful not to inject the snippet before any `\"use strict\";`s.\n// As an additional complication `\"use strict\";`s may come after any number of comments.\nexport const COMMENT_USE_STRICT_REGEX =\n // Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files.\n /^(?:\\s*|\\/\\*(?:.|\\r|\\n)*?\\*\\/|\\/\\/.*[\\n\\r])*(?:\"[^\"]*\";|'[^']*';)?/;\n\n/**\n * Checks if a file is a JavaScript file based on its extension.\n * Handles query strings and hashes in the filename.\n */\nexport function isJsFile(fileName: string): boolean {\n const cleanFileName = stripQueryAndHashFromPath(fileName);\n return ['.js', '.mjs', '.cjs'].some(ext => cleanFileName.endsWith(ext));\n}\n\n/**\n * Checks if a chunk should be skipped for code injection\n *\n * This is necessary to handle Vite's MPA (multi-page application) mode where\n * HTML entry points create \"facade\" chunks that should not contain injected code.\n * See: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829\n *\n * However, in SPA mode, the main bundle also has an HTML facade but contains\n * substantial application code. We should NOT skip injection for these bundles.\n *\n * @param code - The chunk's code content\n * @param facadeModuleId - The facade module ID (if any) - HTML files create facade chunks\n * @returns true if the chunk should be skipped\n */\nexport function shouldSkipCodeInjection(code: string, facadeModuleId: string | null | undefined): boolean {\n // Skip empty chunks - these are placeholder chunks that should be optimized away\n if (code.trim().length === 0) {\n return true;\n }\n\n // For HTML facade chunks, only skip if they contain only import statements\n if (facadeModuleId && stripQueryAndHashFromPath(facadeModuleId).endsWith('.html')) {\n return containsOnlyImports(code);\n }\n\n return false;\n}\n\nexport { globFiles } from './glob';\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function createComponentNameAnnotateHooks(ignoredComponents: string[], injectIntoHtml: boolean) {\n return {\n async transform(this: void, code: string, id: string) {\n // id may contain query and hash which will trip up our file extension logic below\n const idWithoutQueryAndHash = stripQueryAndHashFromPath(id);\n\n if (idWithoutQueryAndHash.match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n return null;\n }\n\n // We will only apply this plugin on jsx and tsx files\n if (!['.jsx', '.tsx'].some(ending => idWithoutQueryAndHash.endsWith(ending))) {\n return null;\n }\n\n const parserPlugins: BabelParserPlugins = [];\n if (idWithoutQueryAndHash.endsWith('.jsx')) {\n parserPlugins.push('jsx');\n } else if (idWithoutQueryAndHash.endsWith('.tsx')) {\n parserPlugins.push('jsx', 'typescript');\n }\n\n const { transformAsync, componentNameAnnotatePlugin, experimentalComponentNameAnnotatePlugin } =\n await loadBabelAnnotationRuntime();\n const plugin = injectIntoHtml ? experimentalComponentNameAnnotatePlugin : componentNameAnnotatePlugin;\n\n try {\n const result = await transformAsync(code, {\n plugins: [[plugin, { ignoredComponents }]],\n filename: id,\n parserOpts: {\n sourceType: 'module',\n allowAwaitOutsideFunction: true,\n plugins: parserPlugins,\n },\n generatorOpts: {\n decoratorsBeforeExport: true,\n },\n sourceMaps: true,\n });\n\n return {\n code: result?.code ?? code,\n map: result?.map,\n };\n } catch (e) {\n debug.error(`Failed to apply react annotate plugin`, e);\n }\n\n return { code };\n },\n };\n}\n\nexport function getDebugIdSnippet(debugId: string): CodeInjection {\n return new CodeInjection(\n `var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\"${debugId}\",e._sentryDebugIdIdentifier=\"sentry-dbid-${debugId}\");`,\n );\n}\n\nexport type { Logger } from './logger';\nexport type { Options, SentrySDKBuildFlags } from './types';\nexport {\n CodeInjection,\n replaceBooleanFlagsInCode,\n stringToUUID,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n} from './utils';\nexport { createSentryBuildPluginManager } from './build-plugin-manager';\nexport { createDebugIdUploadFunction } from './debug-id-upload';\n"],"names":["fs","SentryCli","stripQueryAndHashFromPath","containsOnlyImports","debug","CodeInjection"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,IAAI,6BAAA;AAEJ,SAAS,0BAAA,GAA8D;AACrE,EAAA,IAAI,CAAC,6BAAA,EAA+B;AAClC,IAAA,6BAAA,GAAgC,OAAA,CAAQ,GAAA,CAAI,CAAC,OAAO,aAAa,GAAG,qCAAO,0BAAiB,EAAC,CAAC,CAAA,CAAE,IAAA;AAAA,MAC9F,CAAC,CAAC,KAAA,EAAO,WAAW,CAAA,KAAM;AACxB,QAAA,OAAO;AAAA,UACL,gBAAgB,KAAA,CAAM,cAAA;AAAA,UACtB,6BAA6B,WAAA,CAAY,OAAA;AAAA,UACzC,yCAAyC,WAAA,CAAY;AAAA,SACvD;AAAA,MACF;AAAA,KACF;AAAA,EACF;AAEA,EAAA,OAAO,6BAAA;AACT;AAOO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,OAAOA,aAAA,CAAG,UAAA,CAAWC,kBAAA,CAAU,OAAA,EAAS,CAAA;AAC1C;AAIO,MAAM,wBAAA;AAAA;AAAA,EAEX;AAAA;AAMK,SAAS,SAAS,QAAA,EAA2B;AAClD,EAAA,MAAM,aAAA,GAAgBC,gCAA0B,QAAQ,CAAA;AACxD,EAAA,OAAO,CAAC,KAAA,EAAO,MAAA,EAAQ,MAAM,CAAA,CAAE,KAAK,CAAA,GAAA,KAAO,aAAA,CAAc,QAAA,CAAS,GAAG,CAAC,CAAA;AACxE;AAgBO,SAAS,uBAA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M,MAAA,GAAS,MAAM,cAAA,CAAe,IAAA,EAAM;AAAA,UACxC,SAAS,CAAC,CAAC,QAAQ,EAAE,iBAAA,EAAmB,CAAC,CAAA;AAAA,UACzC,QAAA,EAAU,EAAA;AAAA,UACV,UAAA,EAAY;AAAA,YACV,UAAA,EAAY,QAAA;AAAA,YACZ,yBAAA,EAA2B,IAAA;AAAA,YAC3B,OAAA,EAAS;AAAA,WACX;AAAA,UACA,aAAA,EAAe;AAAA,YACb,sBAAA,EAAwB;AAAA,WAC1B;AAAA,UACA,UAAA,EAAY;AAAA,SACb,CAAA;AAED,QAAA,OAAO;AAAA,UACL,IAAA,EAAM,QAAQ,IAAA,IAAQ,IAAA;AAAA,UACtB,KAAK,MAAA,EAAQ;AAAA,SACf;AAAA,MACF,SAAS,CAAA,EAAG;AACV,QAAAE,UAAA,CAAM,KAAA,CAAM,yCAAyC,CAAC,CAAA;AAAA,MACxD;AAEA,MAAA,OAAO,EAAE,IAAA,EAAK;AAAA,IAChB;AAAA,GACF;AACF;AAEO,SAAS,kBAAkB,OAAA,EAAgC;AAChE,EAAA,OAAO,IAAIC,mBAAA;AAAA,IACT,CAAA,4FAAA,EAA+F,OAAO,CAAA,0CAAA,EAA6C,OAAO,CAAA,GAAA;AAAA,GAC5J;AACF;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const LIB_VERSION = "10.64.0";
3
+ const LIB_VERSION = "10.66.0";
4
4
 
5
5
  exports.LIB_VERSION = LIB_VERSION;
6
6
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sources":["../../../src/core/version.ts"],"sourcesContent":["export const LIB_VERSION = \"10.64.0\";\n"],"names":[],"mappings":";;AAAO,MAAM,WAAA,GAAc;;;;"}
1
+ {"version":3,"file":"version.js","sources":["../../../src/core/version.ts"],"sourcesContent":["export const LIB_VERSION = \"10.66.0\";\n"],"names":[],"mappings":";;AAAO,MAAM,WAAA,GAAc;;;;"}
@@ -27,6 +27,8 @@ function _interopNamespace(e) {
27
27
  const MagicString__default = /*#__PURE__*/_interopDefault(MagicString);
28
28
  const path__namespace = /*#__PURE__*/_interopNamespace(path);
29
29
 
30
+ let viteParseAstAsyncPromise;
31
+ const JS_MODULE_ID_FILTER = /\.[cm]?[jt]sx?(?:[?#].*)?$/;
30
32
  function hasExistingDebugID(code) {
31
33
  const chunkStartSnippet = code.slice(0, 6e3);
32
34
  const chunkEndSnippet = code.slice(-500);
@@ -44,6 +46,23 @@ function getRollupMajorVersion() {
44
46
  }
45
47
  return void 0;
46
48
  }
49
+ function getViteParseAstAsync() {
50
+ if (!viteParseAstAsyncPromise) {
51
+ viteParseAstAsyncPromise = Promise.resolve().then(async () => {
52
+ const viteModule = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('rollup/index.js', document.baseURI).href)))("vite");
53
+ if (typeof viteModule.parseAstAsync !== "function") {
54
+ return null;
55
+ }
56
+ try {
57
+ await viteModule.parseAstAsync("const x = <div />;", { lang: "tsx" });
58
+ } catch {
59
+ return null;
60
+ }
61
+ return viteModule.parseAstAsync;
62
+ }).catch(() => null);
63
+ }
64
+ return viteParseAstAsyncPromise;
65
+ }
47
66
  function _rollupPluginInternal(userOptions = {}, buildTool, buildToolMajorVersion) {
48
67
  const sentryBuildPluginManager = buildPluginManager.createSentryBuildPluginManager(userOptions, {
49
68
  loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[sentry-${buildTool}-plugin]`,
@@ -90,14 +109,40 @@ function _rollupPluginInternal(userOptions = {}, buildTool, buildToolMajorVersio
90
109
  options.reactComponentAnnotation?.ignoredComponents || [],
91
110
  !!options.reactComponentAnnotation?._experimentalInjectIntoHtml
92
111
  ) : void 0;
112
+ const transformViteAnnotations = options.reactComponentAnnotation?.enabled && buildTool === "vite" && buildToolMajorVersion === "8" && !options.reactComponentAnnotation?._experimentalInjectIntoHtml ? /* @__PURE__ */ (() => {
113
+ let viteAnnotationHooksPromise;
114
+ return {
115
+ transform(code, id, meta) {
116
+ if (!viteAnnotationHooksPromise) {
117
+ viteAnnotationHooksPromise = Promise.resolve().then(() => require('../core/component-annotation-vite.js')).then(
118
+ ({ createViteComponentNameAnnotateHooks }) => createViteComponentNameAnnotateHooks(
119
+ options.reactComponentAnnotation?.ignoredComponents || [],
120
+ getViteParseAstAsync
121
+ )
122
+ );
123
+ }
124
+ return viteAnnotationHooksPromise.then((hooks) => hooks.transform(code, id, meta));
125
+ }
126
+ };
127
+ })() : void 0;
93
128
  const transformReplace = Object.keys(replacementValues).length > 0;
94
129
  const shouldTransform = transformAnnotations || transformReplace;
95
130
  function buildStart() {
96
131
  void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {
97
132
  });
98
133
  }
99
- async function transform(code, id) {
100
- if (transformAnnotations?.transform) {
134
+ async function transform(code, id, meta) {
135
+ let shouldRunBabelAnnotations = true;
136
+ if (transformViteAnnotations?.transform) {
137
+ const result = await transformViteAnnotations.transform(code, id, meta);
138
+ if (result) {
139
+ return result;
140
+ }
141
+ if (result === null) {
142
+ shouldRunBabelAnnotations = false;
143
+ }
144
+ }
145
+ if (shouldRunBabelAnnotations && transformAnnotations?.transform) {
101
146
  const result = await transformAnnotations.transform(code, id);
102
147
  if (result) {
103
148
  return result;
@@ -168,10 +213,14 @@ function _rollupPluginInternal(userOptions = {}, buildTool, buildToolMajorVersio
168
213
  }
169
214
  const name = `sentry-${buildTool}-plugin`;
170
215
  if (shouldTransform) {
216
+ const transformHook = buildTool === "vite" ? {
217
+ filter: { id: JS_MODULE_ID_FILTER },
218
+ handler: transform
219
+ } : transform;
171
220
  return {
172
221
  name,
173
222
  buildStart,
174
- transform,
223
+ transform: transformHook,
175
224
  renderChunk,
176
225
  writeBundle
177
226
  };