@getglue/jsx-runtime 2.1.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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generate a deterministic ID from source location and tag name.
3
+ * Format: auto:<8-char-base32>
4
+ *
5
+ * @param relativeFile - Relative file path (e.g., "src/Button.tsx")
6
+ * @param line - Line number in source file
7
+ * @param column - Column number in source file
8
+ * @param tagName - JSX tag name (e.g., "button")
9
+ * @returns Deterministic ID string (e.g., "auto:K8M2ZP1A")
10
+ */
11
+ export declare function generateDeterministicId(relativeFile: string, line: number, column: number, tagName: string): string;
12
+ //# sourceMappingURL=id-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-generator.d.ts","sourceRoot":"","sources":["../src/id-generator.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,MAAM,CAYR"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateDeterministicId = generateDeterministicId;
4
+ const crypto_1 = require("crypto");
5
+ /**
6
+ * Generate a deterministic ID from source location and tag name.
7
+ * Format: auto:<8-char-base32>
8
+ *
9
+ * @param relativeFile - Relative file path (e.g., "src/Button.tsx")
10
+ * @param line - Line number in source file
11
+ * @param column - Column number in source file
12
+ * @param tagName - JSX tag name (e.g., "button")
13
+ * @returns Deterministic ID string (e.g., "auto:K8M2ZP1A")
14
+ */
15
+ function generateDeterministicId(relativeFile, line, column, tagName) {
16
+ // Create stable input string
17
+ const input = `${relativeFile}:${line}:${column}:${tagName}`;
18
+ // Hash with SHA-256 (cryptographically secure)
19
+ const hash = (0, crypto_1.createHash)('sha256').update(input, 'utf8').digest();
20
+ // Convert first 5 bytes to base32 (8 characters)
21
+ // 5 bytes = 40 bits = ~1 trillion combinations
22
+ const base32 = base32Encode(hash.subarray(0, 5));
23
+ return `auto:${base32}`;
24
+ }
25
+ /**
26
+ * Base32 encoding alphabet (RFC 4648)
27
+ * Uses uppercase letters and digits 2-7
28
+ */
29
+ const BASE32_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
30
+ /**
31
+ * Encode buffer to base32 string
32
+ * @param buffer - Binary data to encode
33
+ * @returns Base32-encoded string
34
+ */
35
+ function base32Encode(buffer) {
36
+ let result = '';
37
+ let bits = 0;
38
+ let value = 0;
39
+ for (let i = 0; i < buffer.length; i++) {
40
+ value = (value << 8) | buffer[i];
41
+ bits += 8;
42
+ while (bits >= 5) {
43
+ const index = (value >>> (bits - 5)) & 31;
44
+ result += BASE32_ALPHABET[index];
45
+ bits -= 5;
46
+ }
47
+ }
48
+ // Handle remaining bits (if any)
49
+ if (bits > 0) {
50
+ const index = (value << (5 - bits)) & 31;
51
+ result += BASE32_ALPHABET[index];
52
+ }
53
+ return result;
54
+ }
55
+ //# sourceMappingURL=id-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-generator.js","sourceRoot":"","sources":["../src/id-generator.ts"],"names":[],"mappings":";;AAYA,0DAiBC;AA7BD,mCAAoC;AAEpC;;;;;;;;;GASG;AACH,SAAgB,uBAAuB,CACrC,YAAoB,EACpB,IAAY,EACZ,MAAc,EACd,OAAe;IAEf,6BAA6B;IAC7B,MAAM,KAAK,GAAG,GAAG,YAAY,IAAI,IAAI,IAAI,MAAM,IAAI,OAAO,EAAE,CAAC;IAE7D,+CAA+C;IAC/C,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;IAEjE,iDAAiD;IACjD,+CAA+C;IAC/C,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEjD,OAAO,QAAQ,MAAM,EAAE,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,eAAe,GAAG,kCAAkC,CAAC;AAE3D;;;;GAIG;AACH,SAAS,YAAY,CAAC,MAAc;IAClC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,KAAK,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,IAAI,CAAC,CAAC;QAEV,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC;YACjB,MAAM,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;YAC1C,MAAM,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;YACjC,IAAI,IAAI,CAAC,CAAC;QACZ,CAAC;IACH,CAAC;IAED,iCAAiC;IACjC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;QACzC,MAAM,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @glue/jsx-runtime
3
+ *
4
+ * Custom JSX runtime for Glue instrumentation.
5
+ * Compatible with SWC and doesn't require Babel configuration.
6
+ *
7
+ * Usage in tsconfig.json:
8
+ * {
9
+ * "compilerOptions": {
10
+ * "jsx": "react-jsx",
11
+ * "jsxImportSource": "@glue/jsx-runtime"
12
+ * }
13
+ * }
14
+ *
15
+ * Or use pragma in individual files:
16
+ * @jsxImportSource @glue/jsx-runtime
17
+ */
18
+ export { jsx, jsxs, Fragment } from './jsx-runtime';
19
+ export { extractSourceFromStack } from './stack-parser';
20
+ export { generateDeterministicId } from './id-generator';
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /**
3
+ * @glue/jsx-runtime
4
+ *
5
+ * Custom JSX runtime for Glue instrumentation.
6
+ * Compatible with SWC and doesn't require Babel configuration.
7
+ *
8
+ * Usage in tsconfig.json:
9
+ * {
10
+ * "compilerOptions": {
11
+ * "jsx": "react-jsx",
12
+ * "jsxImportSource": "@glue/jsx-runtime"
13
+ * }
14
+ * }
15
+ *
16
+ * Or use pragma in individual files:
17
+ * @jsxImportSource @glue/jsx-runtime
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.generateDeterministicId = exports.extractSourceFromStack = exports.Fragment = exports.jsxs = exports.jsx = void 0;
21
+ var jsx_runtime_1 = require("./jsx-runtime");
22
+ Object.defineProperty(exports, "jsx", { enumerable: true, get: function () { return jsx_runtime_1.jsx; } });
23
+ Object.defineProperty(exports, "jsxs", { enumerable: true, get: function () { return jsx_runtime_1.jsxs; } });
24
+ Object.defineProperty(exports, "Fragment", { enumerable: true, get: function () { return jsx_runtime_1.Fragment; } });
25
+ var stack_parser_1 = require("./stack-parser");
26
+ Object.defineProperty(exports, "extractSourceFromStack", { enumerable: true, get: function () { return stack_parser_1.extractSourceFromStack; } });
27
+ var id_generator_1 = require("./id-generator");
28
+ Object.defineProperty(exports, "generateDeterministicId", { enumerable: true, get: function () { return id_generator_1.generateDeterministicId; } });
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAEH,6CAAoD;AAA3C,kGAAA,GAAG,OAAA;AAAE,mGAAA,IAAI,OAAA;AAAE,uGAAA,QAAQ,OAAA;AAC5B,+CAAwD;AAA/C,sHAAA,sBAAsB,OAAA;AAC/B,+CAAyD;AAAhD,uHAAA,uBAAuB,OAAA"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Custom JSX development runtime for Glue instrumentation
3
+ *
4
+ * This is the development version of the JSX runtime used when React
5
+ * is in development mode. It includes additional debug information.
6
+ */
7
+ import { _FragmentDev as _Fragment } from './react-original';
8
+ /**
9
+ * Custom jsxDEV() function that wraps React's jsxDEV()
10
+ *
11
+ * The jsxDEV function receives a `source` parameter from SWC that contains
12
+ * structured source location information: { fileName, lineNumber, columnNumber }
13
+ * This provides line-exact precision without needing stack traces.
14
+ */
15
+ export declare function jsxDEV(type: any, props: any, key: any, isStaticChildren: boolean, source: any, self: any): any;
16
+ /**
17
+ * Re-export Fragment
18
+ */
19
+ export { _Fragment as Fragment };
20
+ //# sourceMappingURL=jsx-dev-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-dev-runtime.d.ts","sourceRoot":"","sources":["../src/jsx-dev-runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAW,YAAY,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAYtE;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,GAAG,EACV,GAAG,EAAE,GAAG,EACR,gBAAgB,EAAE,OAAO,EACzB,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,GAAG,GACR,GAAG,CA0DL;AAED;;GAEG;AACH,OAAO,EAAE,SAAS,IAAI,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ /**
3
+ * Custom JSX development runtime for Glue instrumentation
4
+ *
5
+ * This is the development version of the JSX runtime used when React
6
+ * is in development mode. It includes additional debug information.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Fragment = void 0;
10
+ exports.jsxDEV = jsxDEV;
11
+ const react_original_1 = require("./react-original");
12
+ Object.defineProperty(exports, "Fragment", { enumerable: true, get: function () { return react_original_1._FragmentDev; } });
13
+ const id_generator_1 = require("./id-generator");
14
+ const ATTRIBUTE_PREFIX = 'data-agent';
15
+ /**
16
+ * Check if a JSX type represents a host element (DOM element)
17
+ */
18
+ function isHostElement(type) {
19
+ return typeof type === 'string';
20
+ }
21
+ /**
22
+ * Custom jsxDEV() function that wraps React's jsxDEV()
23
+ *
24
+ * The jsxDEV function receives a `source` parameter from SWC that contains
25
+ * structured source location information: { fileName, lineNumber, columnNumber }
26
+ * This provides line-exact precision without needing stack traces.
27
+ */
28
+ function jsxDEV(type, props, key, isStaticChildren, source, self) {
29
+ // Only instrument host elements (lowercase tags like div, span, etc.)
30
+ if (isHostElement(type) && source && source.fileName) {
31
+ // Skip if already instrumented
32
+ if (props && props[`${ATTRIBUTE_PREFIX}-id`]) {
33
+ return (0, react_original_1._jsxDEV)(type, props, key, isStaticChildren, source, self);
34
+ }
35
+ // Use the structured source info from jsxDEV's source parameter
36
+ // This is provided by SWC and gives us line-exact precision
37
+ const agentId = (0, id_generator_1.generateDeterministicId)(source.fileName, source.lineNumber, source.columnNumber || 0, type);
38
+ // Debug logging and visual indicator to verify instrumentation is working
39
+ if (typeof globalThis !== 'undefined' && typeof globalThis.window !== 'undefined') {
40
+ const win = globalThis.window;
41
+ if (!win.__glueDebugLogged) {
42
+ console.log('[Glue] JSX instrumentation active! Example element:', {
43
+ type,
44
+ agentId,
45
+ sourceFile: source.fileName,
46
+ sourceLine: source.lineNumber
47
+ });
48
+ // Add a visible banner to the page to confirm it's working
49
+ setTimeout(() => {
50
+ const banner = win.document.createElement('div');
51
+ banner.id = 'glue-debug-banner';
52
+ banner.innerHTML = '✅ Glue instrumentation is ACTIVE! Check DevTools Elements panel for data-agent-* attributes.';
53
+ banner.style.cssText = 'position: fixed; top: 0; left: 0; right: 0; background: #10b981; color: white; padding: 8px; text-align: center; z-index: 999999; font-size: 14px; font-family: monospace;';
54
+ win.document.body.appendChild(banner);
55
+ // Auto-hide after 5 seconds
56
+ setTimeout(() => banner.remove(), 5000);
57
+ }, 100);
58
+ win.__glueDebugLogged = true;
59
+ }
60
+ }
61
+ // Create new props object with instrumentation attributes
62
+ const instrumentedProps = {
63
+ ...props,
64
+ [`${ATTRIBUTE_PREFIX}-id`]: agentId,
65
+ [`${ATTRIBUTE_PREFIX}-source-file`]: source.fileName,
66
+ [`${ATTRIBUTE_PREFIX}-source-line`]: String(source.lineNumber),
67
+ [`${ATTRIBUTE_PREFIX}-source-col`]: String(source.columnNumber || 0)
68
+ };
69
+ return (0, react_original_1._jsxDEV)(type, instrumentedProps, key, isStaticChildren, source, self);
70
+ }
71
+ // Pass through non-host elements and elements without source info
72
+ return (0, react_original_1._jsxDEV)(type, props, key, isStaticChildren, source, self);
73
+ }
74
+ //# sourceMappingURL=jsx-dev-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-dev-runtime.js","sourceRoot":"","sources":["../src/jsx-dev-runtime.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAqBH,wBAiEC;AApFD,qDAAsE;AAyFhD,yFAzFY,6BAAS,OAyFb;AAxF9B,iDAAyD;AAEzD,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAEtC;;GAEG;AACH,SAAS,aAAa,CAAC,IAAS;IAC9B,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC;AAClC,CAAC;AAED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,4KAA4K,CAAC;oBACpM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;oBAEtC,4BAA4B;oBAC5B,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,CAAC;gBAC1C,CAAC,EAAE,GAAG,CAAC,CAAC;gBAER,GAAG,CAAC,iBAAiB,GAAG,IAAI,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,0DAA0D;QAC1D,MAAM,iBAAiB,GAAG;YACxB,GAAG,KAAK;YACR,CAAC,GAAG,gBAAgB,KAAK,CAAC,EAAE,OAAO;YACnC,CAAC,GAAG,gBAAgB,cAAc,CAAC,EAAE,MAAM,CAAC,QAAQ;YACpD,CAAC,GAAG,gBAAgB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;YAC9D,CAAC,GAAG,gBAAgB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC;SACrE,CAAC;QAEF,OAAO,IAAA,wBAAO,EAAC,IAAW,EAAE,iBAAiB,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACtF,CAAC;IAED,kEAAkE;IAClE,OAAO,IAAA,wBAAO,EAAC,IAAW,EAAE,KAAK,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Custom JSX runtime for Glue instrumentation
3
+ *
4
+ * This wraps React's JSX runtime to inject data-agent-* attributes
5
+ * into host elements (lowercase tags like div, button, etc.)
6
+ */
7
+ import { _Fragment } from './react-original';
8
+ /**
9
+ * Custom jsx() function that wraps React's jsx()
10
+ */
11
+ export declare function jsx(type: any, props: any, key?: any): any;
12
+ /**
13
+ * Custom jsxs() function that wraps React's jsxs()
14
+ * Used for elements with multiple children
15
+ */
16
+ export declare function jsxs(type: any, props: any, key?: any): any;
17
+ /**
18
+ * Re-export Fragment
19
+ */
20
+ export { _Fragment as Fragment };
21
+ //# sourceMappingURL=jsx-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-runtime.d.ts","sourceRoot":"","sources":["../src/jsx-runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAe,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAqD1D;;GAEG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,CAMzD;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,CAM1D;AAED;;GAEG;AACH,OAAO,EAAE,SAAS,IAAI,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /**
3
+ * Custom JSX runtime for Glue instrumentation
4
+ *
5
+ * This wraps React's JSX runtime to inject data-agent-* attributes
6
+ * into host elements (lowercase tags like div, button, etc.)
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Fragment = void 0;
10
+ exports.jsx = jsx;
11
+ exports.jsxs = jsxs;
12
+ const react_original_1 = require("./react-original");
13
+ Object.defineProperty(exports, "Fragment", { enumerable: true, get: function () { return react_original_1._Fragment; } });
14
+ const stack_parser_1 = require("./stack-parser");
15
+ const id_generator_1 = require("./id-generator");
16
+ const ATTRIBUTE_PREFIX = 'data-agent';
17
+ /**
18
+ * Check if a JSX type represents a host element (DOM element)
19
+ * Host elements are strings ('div', 'button', etc.)
20
+ * Component elements are functions or classes
21
+ */
22
+ function isHostElement(type) {
23
+ return typeof type === 'string';
24
+ }
25
+ /**
26
+ * Inject Glue instrumentation attributes into props
27
+ */
28
+ function injectGlueAttributes(type, props) {
29
+ // Skip if already instrumented
30
+ if (props && props[`${ATTRIBUTE_PREFIX}-id`]) {
31
+ return props;
32
+ }
33
+ // Extract source location from stack trace
34
+ const source = (0, stack_parser_1.extractSourceFromStack)();
35
+ if (!source) {
36
+ return props; // Can't get source info, return original props
37
+ }
38
+ // Generate deterministic ID
39
+ const agentId = (0, id_generator_1.generateDeterministicId)(source.file, source.line, source.column, type);
40
+ // Create new props object with instrumentation attributes
41
+ const instrumentedProps = {
42
+ ...props,
43
+ [`${ATTRIBUTE_PREFIX}-id`]: agentId,
44
+ [`${ATTRIBUTE_PREFIX}-source-file`]: source.file,
45
+ [`${ATTRIBUTE_PREFIX}-source-line`]: String(source.line),
46
+ [`${ATTRIBUTE_PREFIX}-source-col`]: String(source.column)
47
+ };
48
+ return instrumentedProps;
49
+ }
50
+ /**
51
+ * Custom jsx() function that wraps React's jsx()
52
+ */
53
+ function jsx(type, props, key) {
54
+ if (isHostElement(type)) {
55
+ const instrumentedProps = injectGlueAttributes(type, props);
56
+ return (0, react_original_1._jsx)(type, instrumentedProps, key);
57
+ }
58
+ return (0, react_original_1._jsx)(type, props, key);
59
+ }
60
+ /**
61
+ * Custom jsxs() function that wraps React's jsxs()
62
+ * Used for elements with multiple children
63
+ */
64
+ function jsxs(type, props, key) {
65
+ if (isHostElement(type)) {
66
+ const instrumentedProps = injectGlueAttributes(type, props);
67
+ return (0, react_original_1._jsxs)(type, instrumentedProps, key);
68
+ }
69
+ return (0, react_original_1._jsxs)(type, props, key);
70
+ }
71
+ //# sourceMappingURL=jsx-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-runtime.js","sourceRoot":"","sources":["../src/jsx-runtime.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA0DH,kBAMC;AAMD,oBAMC;AA1ED,qDAA0D;AA+EpC,yFA/EA,0BAAS,OA+ED;AA9E9B,iDAAwD;AACxD,iDAAyD;AAEzD,MAAM,gBAAgB,GAAG,YAAY,CAAC;A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nD,CAAC;IACD,OAAO,IAAA,qBAAI,EAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,SAAgB,IAAI,CAAC,IAAS,EAAE,KAAU,EAAE,GAAS;IACnD,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5D,OAAO,IAAA,sBAAK,EAAC,IAAW,EAAE,iBAAiB,EAAE,GAAG,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,IAAA,sBAAK,EAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Imports the real React JSX runtime, bypassing webpack aliases
3
+ *
4
+ * This file imports from React's actual jsx-runtime. Our webpack plugin
5
+ * is configured to NOT apply the alias when imports originate from within
6
+ * the @glue/jsx-runtime package, allowing us to get the real React functions.
7
+ */
8
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from 'react/jsx-runtime';
9
+ import { jsxDEV as _jsxDEV, Fragment as _FragmentDev } from 'react/jsx-dev-runtime';
10
+ export { _jsx, _jsxs, _Fragment, _jsxDEV, _FragmentDev };
11
+ //# sourceMappingURL=react-original.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-original.d.ts","sourceRoot":"","sources":["../src/react-original.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,GAAG,IAAI,IAAI,EAAE,IAAI,IAAI,KAAK,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGpF,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * Imports the real React JSX runtime, bypassing webpack aliases
4
+ *
5
+ * This file imports from React's actual jsx-runtime. Our webpack plugin
6
+ * is configured to NOT apply the alias when imports originate from within
7
+ * the @glue/jsx-runtime package, allowing us to get the real React functions.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports._FragmentDev = exports._jsxDEV = exports._Fragment = exports._jsxs = exports._jsx = void 0;
11
+ // Import the real React jsx functions
12
+ // The webpack plugin checks the issuer and skips aliasing for our package
13
+ const jsx_runtime_1 = require("react/jsx-runtime");
14
+ Object.defineProperty(exports, "_jsx", { enumerable: true, get: function () { return jsx_runtime_1.jsx; } });
15
+ Object.defineProperty(exports, "_jsxs", { enumerable: true, get: function () { return jsx_runtime_1.jsxs; } });
16
+ Object.defineProperty(exports, "_Fragment", { enumerable: true, get: function () { return jsx_runtime_1.Fragment; } });
17
+ const jsx_dev_runtime_1 = require("react/jsx-dev-runtime");
18
+ Object.defineProperty(exports, "_jsxDEV", { enumerable: true, get: function () { return jsx_dev_runtime_1.jsxDEV; } });
19
+ Object.defineProperty(exports, "_FragmentDev", { enumerable: true, get: function () { return jsx_dev_runtime_1.Fragment; } });
20
+ //# sourceMappingURL=react-original.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-original.js","sourceRoot":"","sources":["../src/react-original.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,sCAAsC;AACtC,0EAA0E;AAC1E,mDAAsF;AAI7E,qFAJO,iBAAI,OAIP;AAAE,sFAJe,kBAAK,OAIf;AAAE,0FAJ2B,sBAAS,OAI3B;AAH/B,2DAAoF;AAGnD,wFAHd,wBAAO,OAGc;AAAE,6FAHF,0BAAY,OAGE"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Parse Error stack traces to extract source location information
3
+ */
4
+ export interface SourceLocation {
5
+ file: string;
6
+ line: number;
7
+ column: number;
8
+ }
9
+ /**
10
+ * Parse stack trace to extract the first relevant source location
11
+ *
12
+ * Skips internal frames (node_modules, jsx-runtime itself) and finds
13
+ * the first user code location.
14
+ */
15
+ export declare function extractSourceFromStack(): SourceLocation | null;
16
+ //# sourceMappingURL=stack-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stack-parser.d.ts","sourceRoot":"","sources":["../src/stack-parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,IAAI,cAAc,GAAG,IAAI,CAmC9D"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ /**
3
+ * Parse Error stack traces to extract source location information
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.extractSourceFromStack = extractSourceFromStack;
7
+ /**
8
+ * Parse stack trace to extract the first relevant source location
9
+ *
10
+ * Skips internal frames (node_modules, jsx-runtime itself) and finds
11
+ * the first user code location.
12
+ */
13
+ function extractSourceFromStack() {
14
+ try {
15
+ const error = new Error();
16
+ const stack = error.stack;
17
+ if (!stack) {
18
+ return null;
19
+ }
20
+ // Split into lines and skip the first line (Error message)
21
+ const lines = stack.split('\n').slice(1);
22
+ for (const line of lines) {
23
+ // Skip internal frames
24
+ if (line.includes('node_modules') ||
25
+ line.includes('@glue/jsx-runtime') ||
26
+ line.includes('jsx-runtime') ||
27
+ line.includes('jsx-dev-runtime')) {
28
+ continue;
29
+ }
30
+ // Try to extract location from various stack trace formats
31
+ const location = parseStackLine(line);
32
+ if (location) {
33
+ return location;
34
+ }
35
+ }
36
+ return null;
37
+ }
38
+ catch (error) {
39
+ // Fail gracefully if stack parsing fails
40
+ return null;
41
+ }
42
+ }
43
+ /**
44
+ * Parse a single stack trace line to extract source location
45
+ *
46
+ * Handles multiple formats:
47
+ * - V8 (Node/Chrome): "at functionName (file:line:col)"
48
+ * - V8 anonymous: "at file:line:col"
49
+ * - SpiderMonkey (Firefox): "functionName@file:line:col"
50
+ */
51
+ function parseStackLine(line) {
52
+ // V8 format: " at Component (file.tsx:42:10)"
53
+ const v8Match = line.match(/at\s+(?:.*\s+)?\(?([^:]+):(\d+):(\d+)\)?/);
54
+ if (v8Match) {
55
+ return {
56
+ file: cleanFilePath(v8Match[1]),
57
+ line: parseInt(v8Match[2], 10),
58
+ column: parseInt(v8Match[3], 10)
59
+ };
60
+ }
61
+ // SpiderMonkey format: "Component@file.tsx:42:10"
62
+ const spiderMonkeyMatch = line.match(/([^@]+)@([^:]+):(\d+):(\d+)/);
63
+ if (spiderMonkeyMatch) {
64
+ return {
65
+ file: cleanFilePath(spiderMonkeyMatch[2]),
66
+ line: parseInt(spiderMonkeyMatch[3], 10),
67
+ column: parseInt(spiderMonkeyMatch[4], 10)
68
+ };
69
+ }
70
+ return null;
71
+ }
72
+ /**
73
+ * Clean file path to remove file:// protocol and make it relative
74
+ */
75
+ function cleanFilePath(filePath) {
76
+ // Remove file:// protocol
77
+ let cleaned = filePath.replace(/^file:\/\//, '');
78
+ // Try to make it relative to cwd
79
+ const cwd = process.cwd();
80
+ if (cleaned.startsWith(cwd)) {
81
+ cleaned = cleaned.slice(cwd.length + 1); // +1 for the slash
82
+ }
83
+ return cleaned;
84
+ }
85
+ //# sourceMappingURL=stack-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stack-parser.js","sourceRoot":"","sources":["../src/stack-parser.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAcH,wDAmCC;AAzCD;;;;;GAKG;AACH,SAAgB,sBAAsB;IACpC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAE1B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,IAAI,CAAC;QACd,CAAC;QAED,2DAA2D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C,CAAC,CAAC,CAAC;YACzC,IAAI,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;SAC3C,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,QAAgB;IACrC,0BAA0B;IAC1B,IAAI,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAEjD,iCAAiC;IACjC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB;IAC9D,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@getglue/jsx-runtime",
3
+ "version": "2.1.0",
4
+ "description": "Custom JSX runtime for Glue instrumentation - compatible with SWC and next/font",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./jsx-runtime": {
13
+ "types": "./dist/jsx-runtime.d.ts",
14
+ "default": "./dist/jsx-runtime.js"
15
+ },
16
+ "./jsx-dev-runtime": {
17
+ "types": "./dist/jsx-dev-runtime.d.ts",
18
+ "default": "./dist/jsx-dev-runtime.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/billwithwillow/glue.git",
28
+ "directory": "packages/jsx-runtime"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc",
35
+ "watch": "tsc --watch",
36
+ "clean": "rm -rf dist"
37
+ },
38
+ "keywords": [
39
+ "jsx",
40
+ "runtime",
41
+ "react",
42
+ "instrumentation",
43
+ "glue"
44
+ ],
45
+ "author": "Tejas Priyadarshi",
46
+ "license": "MIT",
47
+ "peerDependencies": {
48
+ "react": ">=17.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "@types/react": "^18.3.0",
52
+ "@types/node": "^20.11.19",
53
+ "typescript": "^5.3.3"
54
+ }
55
+ }