@grafana/faro-react 2.3.0 → 2.4.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/dist/cjs/errorBoundary/FaroErrorBoundary.js +31 -49
- package/dist/cjs/errorBoundary/FaroErrorBoundary.js.map +1 -1
- package/dist/cjs/errorBoundary/withFaroErrorBoundary.js +8 -19
- package/dist/cjs/errorBoundary/withFaroErrorBoundary.js.map +1 -1
- package/dist/cjs/instrumentation.js +12 -31
- package/dist/cjs/instrumentation.js.map +1 -1
- package/dist/cjs/profiler/FaroProfiler.js +46 -90
- package/dist/cjs/profiler/FaroProfiler.js.map +1 -1
- package/dist/cjs/profiler/withFaroProfiler.js +8 -19
- package/dist/cjs/profiler/withFaroProfiler.js.map +1 -1
- package/dist/cjs/router/initialize.js +8 -8
- package/dist/cjs/router/initialize.js.map +1 -1
- package/dist/cjs/router/v4v5/FaroRoute.js +4 -15
- package/dist/cjs/router/v4v5/FaroRoute.js.map +1 -1
- package/dist/cjs/router/v4v5/activeEvent.js +3 -3
- package/dist/cjs/router/v4v5/activeEvent.js.map +1 -1
- package/dist/cjs/router/v4v5/initialize.js +12 -12
- package/dist/cjs/router/v4v5/initialize.js.map +1 -1
- package/dist/cjs/router/v6v7/FaroRoutes.js +16 -27
- package/dist/cjs/router/v6v7/FaroRoutes.js.map +1 -1
- package/dist/cjs/router/v6v7/initialize.js +8 -8
- package/dist/cjs/router/v6v7/initialize.js.map +1 -1
- package/dist/cjs/router/v6v7/utils.js +9 -9
- package/dist/cjs/router/v6v7/utils.js.map +1 -1
- package/dist/cjs/router/v6v7/withFaroRouterInstrumentation.js +13 -24
- package/dist/cjs/router/v6v7/withFaroRouterInstrumentation.js.map +1 -1
- package/dist/cjs/utils/reactVersion.js +2 -2
- package/dist/cjs/utils/reactVersion.js.map +1 -1
- package/package.json +11 -8
|
@@ -1,78 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.FaroErrorBoundary = void 0;
|
|
19
4
|
// React is required in scope for JSX transformation with the classic transform
|
|
20
5
|
// @ts-expect-error - TS6133: React appears unused but is required for JSX
|
|
21
6
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
_this.resetErrorBoundary = _this.resetErrorBoundary.bind(_this);
|
|
33
|
-
return _this;
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
9
|
+
const dependencies_1 = require("../dependencies");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
const const_1 = require("./const");
|
|
12
|
+
class FaroErrorBoundary extends react_1.Component {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(props);
|
|
15
|
+
this.state = const_1.faroErrorBoundaryInitialState;
|
|
16
|
+
this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
|
|
34
17
|
}
|
|
35
|
-
|
|
18
|
+
getErrorWithComponentStack(error, errorInfo) {
|
|
36
19
|
if (!utils_1.isReactVersionAtLeast17 || !errorInfo.componentStack) {
|
|
37
20
|
return error;
|
|
38
21
|
}
|
|
39
|
-
|
|
40
|
-
newError.name =
|
|
22
|
+
const newError = new Error(error.message);
|
|
23
|
+
newError.name = `React ErrorBoundary ${error.name}`;
|
|
41
24
|
newError.stack = errorInfo.componentStack;
|
|
42
25
|
return newError;
|
|
43
|
-
}
|
|
44
|
-
|
|
26
|
+
}
|
|
27
|
+
static getDerivedStateFromError(error) {
|
|
45
28
|
return {
|
|
46
29
|
hasError: true,
|
|
47
|
-
error
|
|
30
|
+
error,
|
|
48
31
|
};
|
|
49
|
-
}
|
|
50
|
-
|
|
32
|
+
}
|
|
33
|
+
componentDidCatch(error, errorInfo) {
|
|
51
34
|
var _a, _b, _c, _d;
|
|
52
|
-
|
|
35
|
+
const errorWithComponentStack = this.getErrorWithComponentStack(error, errorInfo);
|
|
53
36
|
(_b = (_a = this.props).beforeCapture) === null || _b === void 0 ? void 0 : _b.call(_a, errorWithComponentStack);
|
|
54
37
|
dependencies_1.api.pushError(errorWithComponentStack, this.props.pushErrorOptions);
|
|
55
38
|
(_d = (_c = this.props).onError) === null || _d === void 0 ? void 0 : _d.call(_c, errorWithComponentStack);
|
|
56
|
-
this.setState({ hasError: true, error
|
|
57
|
-
}
|
|
58
|
-
|
|
39
|
+
this.setState({ hasError: true, error });
|
|
40
|
+
}
|
|
41
|
+
componentDidMount() {
|
|
59
42
|
var _a, _b;
|
|
60
43
|
(_b = (_a = this.props).onMount) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
61
|
-
}
|
|
62
|
-
|
|
44
|
+
}
|
|
45
|
+
componentWillUnmount() {
|
|
63
46
|
var _a, _b;
|
|
64
47
|
(_b = (_a = this.props).onUnmount) === null || _b === void 0 ? void 0 : _b.call(_a, this.state.error);
|
|
65
|
-
}
|
|
66
|
-
|
|
48
|
+
}
|
|
49
|
+
resetErrorBoundary() {
|
|
67
50
|
var _a, _b;
|
|
68
51
|
(_b = (_a = this.props).onReset) === null || _b === void 0 ? void 0 : _b.call(_a, this.state.error);
|
|
69
52
|
this.setState(const_1.faroErrorBoundaryInitialState);
|
|
70
|
-
}
|
|
71
|
-
|
|
53
|
+
}
|
|
54
|
+
render() {
|
|
72
55
|
if (!this.state.hasError) {
|
|
73
56
|
return (0, faro_web_sdk_1.isFunction)(this.props.children) ? this.props.children() : this.props.children;
|
|
74
57
|
}
|
|
75
|
-
|
|
58
|
+
const element = !(0, faro_web_sdk_1.isFunction)(this.props.fallback)
|
|
76
59
|
? this.props.fallback
|
|
77
60
|
: this.props.fallback(this.state.error, this.resetErrorBoundary);
|
|
78
61
|
if ((0, react_1.isValidElement)(element)) {
|
|
@@ -82,8 +65,7 @@ var FaroErrorBoundary = /** @class */ (function (_super) {
|
|
|
82
65
|
dependencies_1.internalLogger === null || dependencies_1.internalLogger === void 0 ? void 0 : dependencies_1.internalLogger.warn('ErrorBoundary\n', 'Cannot get a valid ReactElement from "fallback"');
|
|
83
66
|
}
|
|
84
67
|
return null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
}(react_1.Component));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
88
70
|
exports.FaroErrorBoundary = FaroErrorBoundary;
|
|
89
71
|
//# sourceMappingURL=FaroErrorBoundary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FaroErrorBoundary.js","sourceRoot":"","sources":["../../../src/errorBoundary/FaroErrorBoundary.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FaroErrorBoundary.js","sourceRoot":"","sources":["../../../src/errorBoundary/FaroErrorBoundary.tsx"],"names":[],"mappings":"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","sourcesContent":["// React is required in scope for JSX transformation with the classic transform\n// @ts-expect-error - TS6133: React appears unused but is required for JSX\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport React, { Component, isValidElement } from 'react';\nimport type { ErrorInfo, ReactNode } from 'react';\n\nimport { isFunction } from '@grafana/faro-web-sdk';\n\nimport { api, internalLogger } from '../dependencies';\nimport { isReactVersionAtLeast17 } from '../utils';\n\nimport { faroErrorBoundaryInitialState } from './const';\nimport type { FaroErrorBoundaryProps, FaroErrorBoundaryState } from './types';\n\nexport class FaroErrorBoundary extends Component<FaroErrorBoundaryProps, FaroErrorBoundaryState> {\n override state: FaroErrorBoundaryState = faroErrorBoundaryInitialState;\n\n constructor(props: FaroErrorBoundaryProps) {\n super(props);\n\n this.resetErrorBoundary = this.resetErrorBoundary.bind(this);\n }\n\n getErrorWithComponentStack(error: Error, errorInfo: ErrorInfo): Error {\n if (!isReactVersionAtLeast17 || !errorInfo.componentStack) {\n return error;\n }\n\n const newError = new Error(error.message);\n\n newError.name = `React ErrorBoundary ${error.name}`;\n newError.stack = errorInfo.componentStack;\n\n return newError;\n }\n\n static getDerivedStateFromError(error: Error): FaroErrorBoundaryState {\n return {\n hasError: true,\n error,\n };\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo): void {\n const errorWithComponentStack = this.getErrorWithComponentStack(error, errorInfo);\n\n this.props.beforeCapture?.(errorWithComponentStack);\n\n api.pushError(errorWithComponentStack, this.props.pushErrorOptions);\n\n this.props.onError?.(errorWithComponentStack);\n\n this.setState({ hasError: true, error });\n }\n\n override componentDidMount(): void {\n this.props.onMount?.();\n }\n\n override componentWillUnmount(): void {\n this.props.onUnmount?.(this.state.error);\n }\n\n resetErrorBoundary(): void {\n this.props.onReset?.(this.state.error);\n\n this.setState(faroErrorBoundaryInitialState);\n }\n\n override render(): ReactNode {\n if (!this.state.hasError) {\n return isFunction(this.props.children) ? this.props.children() : this.props.children;\n }\n\n const element = !isFunction(this.props.fallback)\n ? this.props.fallback\n : this.props.fallback(this.state.error!, this.resetErrorBoundary);\n\n if (isValidElement(element)) {\n return element;\n }\n\n if (this.props.fallback) {\n internalLogger?.warn('ErrorBoundary\\n', 'Cannot get a valid ReactElement from \"fallback\"');\n }\n\n return null;\n }\n}\n"]}
|
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.withFaroErrorBoundary = withFaroErrorBoundary;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
const hoist_non_react_statics_1 = __importDefault(require("hoist-non-react-statics"));
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const faro_core_1 = require("@grafana/faro-core");
|
|
10
|
+
const FaroErrorBoundary_1 = require("./FaroErrorBoundary");
|
|
22
11
|
function withFaroErrorBoundary(WrappedComponent, errorBoundaryProps) {
|
|
23
12
|
var _a, _b;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
react_1.default.createElement(WrappedComponent,
|
|
27
|
-
Component.displayName =
|
|
13
|
+
const componentDisplayName = (_b = (_a = WrappedComponent.displayName) !== null && _a !== void 0 ? _a : WrappedComponent.name) !== null && _b !== void 0 ? _b : faro_core_1.unknownString;
|
|
14
|
+
const Component = (wrappedComponentProps) => (react_1.default.createElement(FaroErrorBoundary_1.FaroErrorBoundary, Object.assign({}, errorBoundaryProps),
|
|
15
|
+
react_1.default.createElement(WrappedComponent, Object.assign({}, wrappedComponentProps))));
|
|
16
|
+
Component.displayName = `faroErrorBoundary(${componentDisplayName})`;
|
|
28
17
|
(0, hoist_non_react_statics_1.default)(Component, WrappedComponent);
|
|
29
18
|
return Component;
|
|
30
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withFaroErrorBoundary.js","sourceRoot":"","sources":["../../../src/errorBoundary/withFaroErrorBoundary.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withFaroErrorBoundary.js","sourceRoot":"","sources":["../../../src/errorBoundary/withFaroErrorBoundary.tsx"],"names":[],"mappings":";;;;;AASA,sDAiBC;AA1BD,sFAA2D;AAC3D,kDAA0B;AAG1B,kDAAmD;AAEnD,2DAAwD;AAGxD,SAAgB,qBAAqB,CACnC,gBAAkC,EAClC,kBAA0C;;IAE1C,MAAM,oBAAoB,GAAG,MAAA,MAAA,gBAAgB,CAAC,WAAW,mCAAI,gBAAgB,CAAC,IAAI,mCAAI,yBAAa,CAAC;IAEpG,MAAM,SAAS,GAAU,CAAC,qBAAwB,EAAE,EAAE,CAAC,CACrD,8BAAC,qCAAiB,oBAAK,kBAAkB;QACvC,8BAAC,gBAAgB,oBAAK,qBAAqB,EAAI,CAC7B,CACrB,CAAC;IAEF,SAAS,CAAC,WAAW,GAAG,qBAAqB,oBAAoB,GAAG,CAAC;IAErE,IAAA,iCAAoB,EAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;IAElD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import hoistNonReactStatics from 'hoist-non-react-statics';\nimport React from 'react';\nimport type { ComponentType, FC } from 'react';\n\nimport { unknownString } from '@grafana/faro-core';\n\nimport { FaroErrorBoundary } from './FaroErrorBoundary';\nimport type { FaroErrorBoundaryProps, ReactProps } from './types';\n\nexport function withFaroErrorBoundary<P extends ReactProps = {}>(\n WrappedComponent: ComponentType<P>,\n errorBoundaryProps: FaroErrorBoundaryProps\n): FC<P> {\n const componentDisplayName = WrappedComponent.displayName ?? WrappedComponent.name ?? unknownString;\n\n const Component: FC<P> = (wrappedComponentProps: P) => (\n <FaroErrorBoundary {...errorBoundaryProps}>\n <WrappedComponent {...wrappedComponentProps} />\n </FaroErrorBoundary>\n );\n\n Component.displayName = `faroErrorBoundary(${componentDisplayName})`;\n\n hoistNonReactStatics(Component, WrappedComponent);\n\n return Component;\n}\n"]}
|
|
@@ -1,39 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.ReactIntegration = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_this.name = '@grafana/faro-react';
|
|
29
|
-
_this.version = faro_web_sdk_1.VERSION;
|
|
30
|
-
return _this;
|
|
4
|
+
const faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
5
|
+
const dependencies_1 = require("./dependencies");
|
|
6
|
+
const router_1 = require("./router");
|
|
7
|
+
class ReactIntegration extends faro_web_sdk_1.BaseInstrumentation {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
super();
|
|
10
|
+
this.options = options;
|
|
11
|
+
this.name = '@grafana/faro-react';
|
|
12
|
+
this.version = faro_web_sdk_1.VERSION;
|
|
31
13
|
}
|
|
32
|
-
|
|
14
|
+
initialize() {
|
|
33
15
|
(0, dependencies_1.setDependencies)(this.internalLogger, this.api);
|
|
34
16
|
(0, router_1.initializeReactRouterInstrumentation)(this.options);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
}(faro_web_sdk_1.BaseInstrumentation));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
38
19
|
exports.ReactIntegration = ReactIntegration;
|
|
39
20
|
//# sourceMappingURL=instrumentation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";;;AAAA,wDAAqE;AAErE,iDAAiD;AACjD,qCAAgE;AAGhE,MAAa,gBAAiB,SAAQ,kCAAmB;IAIvD,YAAoB,UAAkC,EAAE;QACtD,KAAK,EAAE,CAAC;QADU,YAAO,GAAP,OAAO,CAA6B;QAHxD,SAAI,GAAG,qBAAqB,CAAC;QAC7B,YAAO,GAAG,sBAAO,CAAC;IAIlB,CAAC;IAED,UAAU;QACR,IAAA,8BAAe,EAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAA,6CAAoC,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrD,CAAC;CACF;AAZD,4CAYC","sourcesContent":["import { BaseInstrumentation, VERSION } from '@grafana/faro-web-sdk';\n\nimport { setDependencies } from './dependencies';\nimport { initializeReactRouterInstrumentation } from './router';\nimport type { ReactIntegrationConfig } from './types';\n\nexport class ReactIntegration extends BaseInstrumentation {\n name = '@grafana/faro-react';\n version = VERSION;\n\n constructor(private options: ReactIntegrationConfig = {}) {\n super();\n }\n\n initialize(): void {\n setDependencies(this.internalLogger, this.api);\n initializeReactRouterInstrumentation(this.options);\n }\n}\n"]}
|
|
@@ -1,107 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
3
|
exports.FaroProfiler = void 0;
|
|
30
4
|
// React is required in scope for JSX transformation with the classic transform
|
|
31
5
|
// @ts-expect-error - TS6133: React appears unused but is required for JSX
|
|
32
6
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var _this = _super.call(this, props) || this;
|
|
40
|
-
_this.mountSpan = undefined;
|
|
41
|
-
_this.mountSpanEndTime = undefined;
|
|
42
|
-
_this.updateSpan = undefined;
|
|
43
|
-
if (_this.isOtelInitialized) {
|
|
44
|
-
_this.mountSpan = _this.createSpan('componentMount');
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
dependencies_1.internalLogger === null || dependencies_1.internalLogger === void 0 ? void 0 : dependencies_1.internalLogger.error('The Faro React Profiler requires tracing instrumentation. Please enable it in the "instrumentations" section of your config.');
|
|
48
|
-
}
|
|
49
|
-
return _this;
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
9
|
+
const dependencies_1 = require("../dependencies");
|
|
10
|
+
class FaroProfiler extends react_1.Component {
|
|
11
|
+
get isOtelInitialized() {
|
|
12
|
+
return !!(dependencies_1.api === null || dependencies_1.api === void 0 ? void 0 : dependencies_1.api.isOTELInitialized());
|
|
50
13
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get: function () {
|
|
60
|
-
return dependencies_1.api === null || dependencies_1.api === void 0 ? void 0 : dependencies_1.api.getOTEL();
|
|
61
|
-
},
|
|
62
|
-
enumerable: false,
|
|
63
|
-
configurable: true
|
|
64
|
-
});
|
|
65
|
-
Object.defineProperty(FaroProfiler.prototype, "tracer", {
|
|
66
|
-
get: function () {
|
|
67
|
-
var _a;
|
|
68
|
-
return (_a = this.otel) === null || _a === void 0 ? void 0 : _a.trace.getTracer('@grafana/faro-react', faro_web_sdk_1.VERSION);
|
|
69
|
-
},
|
|
70
|
-
enumerable: false,
|
|
71
|
-
configurable: true
|
|
72
|
-
});
|
|
73
|
-
FaroProfiler.prototype.createSpan = function (spanName, options) {
|
|
14
|
+
get otel() {
|
|
15
|
+
return dependencies_1.api === null || dependencies_1.api === void 0 ? void 0 : dependencies_1.api.getOTEL();
|
|
16
|
+
}
|
|
17
|
+
get tracer() {
|
|
18
|
+
var _a;
|
|
19
|
+
return (_a = this.otel) === null || _a === void 0 ? void 0 : _a.trace.getTracer('@grafana/faro-react', faro_web_sdk_1.VERSION);
|
|
20
|
+
}
|
|
21
|
+
createSpan(spanName, options) {
|
|
74
22
|
var _a, _b;
|
|
75
|
-
|
|
23
|
+
const span = this.tracer.startSpan(spanName, {
|
|
76
24
|
startTime: options === null || options === void 0 ? void 0 : options.startTime,
|
|
77
|
-
attributes:
|
|
25
|
+
attributes: Object.assign({ 'react.component.name': this.props.name }, ((_a = options === null || options === void 0 ? void 0 : options.attributes) !== null && _a !== void 0 ? _a : {})),
|
|
78
26
|
});
|
|
79
27
|
(_b = this.otel) === null || _b === void 0 ? void 0 : _b.trace.setSpan(this.otel.context.active(), span);
|
|
80
28
|
if (options === null || options === void 0 ? void 0 : options.endTime) {
|
|
81
29
|
span.end(options.endTime);
|
|
82
30
|
}
|
|
83
31
|
return span;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
var _this = this;
|
|
32
|
+
}
|
|
33
|
+
createChildSpan(spanName, parent, options) {
|
|
87
34
|
var _a;
|
|
88
|
-
|
|
89
|
-
(_a = this.otel) === null || _a === void 0 ? void 0 : _a.context.with(this.otel.trace.setSpan(this.otel.context.active(), parent),
|
|
90
|
-
span =
|
|
35
|
+
let span;
|
|
36
|
+
(_a = this.otel) === null || _a === void 0 ? void 0 : _a.context.with(this.otel.trace.setSpan(this.otel.context.active(), parent), () => {
|
|
37
|
+
span = this.createSpan(spanName, options);
|
|
91
38
|
});
|
|
92
39
|
return span;
|
|
93
|
-
}
|
|
94
|
-
|
|
40
|
+
}
|
|
41
|
+
constructor(props) {
|
|
42
|
+
super(props);
|
|
43
|
+
this.mountSpan = undefined;
|
|
44
|
+
this.mountSpanEndTime = undefined;
|
|
45
|
+
this.updateSpan = undefined;
|
|
46
|
+
if (this.isOtelInitialized) {
|
|
47
|
+
this.mountSpan = this.createSpan('componentMount');
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
dependencies_1.internalLogger === null || dependencies_1.internalLogger === void 0 ? void 0 : dependencies_1.internalLogger.error('The Faro React Profiler requires tracing instrumentation. Please enable it in the "instrumentations" section of your config.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
componentDidMount() {
|
|
95
54
|
if (this.isOtelInitialized && this.mountSpan) {
|
|
96
55
|
this.mountSpanEndTime = Date.now();
|
|
97
56
|
this.mountSpan.end(this.mountSpanEndTime);
|
|
98
57
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
var _this = this;
|
|
102
|
-
var updateProps = _a.updateProps;
|
|
58
|
+
}
|
|
59
|
+
shouldComponentUpdate({ updateProps }) {
|
|
103
60
|
if (this.isOtelInitialized && this.mountSpan && updateProps !== this.props.updateProps) {
|
|
104
|
-
|
|
61
|
+
const changedProps = Object.keys(updateProps).filter((key) => updateProps[key] !== this.props.updateProps[key]);
|
|
105
62
|
if (changedProps.length > 0) {
|
|
106
63
|
this.updateSpan = this.createChildSpan('componentUpdate', this.mountSpan, {
|
|
107
64
|
attributes: {
|
|
@@ -111,25 +68,24 @@ var FaroProfiler = /** @class */ (function (_super) {
|
|
|
111
68
|
}
|
|
112
69
|
}
|
|
113
70
|
return true;
|
|
114
|
-
}
|
|
115
|
-
|
|
71
|
+
}
|
|
72
|
+
componentDidUpdate() {
|
|
116
73
|
if (this.isOtelInitialized && this.updateSpan) {
|
|
117
74
|
this.updateSpan.end();
|
|
118
75
|
this.updateSpan = undefined;
|
|
119
76
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
77
|
+
}
|
|
78
|
+
componentWillUnmount() {
|
|
122
79
|
if (this.isOtelInitialized && this.mountSpan) {
|
|
123
80
|
this.createChildSpan('componentRender', this.mountSpan, {
|
|
124
81
|
startTime: this.mountSpanEndTime,
|
|
125
82
|
endTime: Date.now(),
|
|
126
83
|
});
|
|
127
84
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
85
|
+
}
|
|
86
|
+
render() {
|
|
130
87
|
return this.props.children;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
}(react_1.Component));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
134
90
|
exports.FaroProfiler = FaroProfiler;
|
|
135
91
|
//# sourceMappingURL=FaroProfiler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FaroProfiler.js","sourceRoot":"","sources":["../../../src/profiler/FaroProfiler.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FaroProfiler.js","sourceRoot":"","sources":["../../../src/profiler/FaroProfiler.tsx"],"names":[],"mappings":"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","sourcesContent":["import type { Attributes, Span, Tracer } from '@opentelemetry/api';\n// React is required in scope for JSX transformation with the classic transform\n// @ts-expect-error - TS6133: React appears unused but is required for JSX\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport React, { Component } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { VERSION } from '@grafana/faro-web-sdk';\nimport type { OTELApi } from '@grafana/faro-web-sdk';\n\nimport { api, internalLogger } from '../dependencies';\n\nexport interface FaroProfilerProps {\n children: ReactNode;\n name: string;\n updateProps: Record<string, unknown>;\n}\n\nexport class FaroProfiler extends Component<FaroProfilerProps> {\n protected mountSpan: Span | undefined = undefined;\n protected mountSpanEndTime: number | undefined = undefined;\n protected updateSpan: Span | undefined = undefined;\n\n private get isOtelInitialized(): boolean {\n return !!api?.isOTELInitialized();\n }\n\n private get otel(): OTELApi | undefined {\n return api?.getOTEL()!;\n }\n\n private get tracer(): Tracer {\n return this.otel?.trace.getTracer('@grafana/faro-react', VERSION)!;\n }\n\n private createSpan(\n spanName: string,\n options?: { startTime?: number; endTime?: number; attributes?: Attributes }\n ): Span {\n const span = this.tracer.startSpan(spanName, {\n startTime: options?.startTime,\n attributes: {\n 'react.component.name': this.props.name,\n ...(options?.attributes ?? {}),\n },\n });\n\n this.otel?.trace.setSpan(this.otel.context.active(), span);\n\n if (options?.endTime) {\n span.end(options.endTime);\n }\n\n return span;\n }\n\n private createChildSpan(\n spanName: string,\n parent: Span,\n options?: { startTime?: number; endTime?: number; attributes?: Attributes }\n ): Span {\n let span: Span;\n\n this.otel?.context.with(this.otel.trace.setSpan(this.otel.context.active(), parent), () => {\n span = this.createSpan(spanName, options);\n });\n\n return span!;\n }\n\n constructor(props: FaroProfilerProps) {\n super(props);\n\n if (this.isOtelInitialized) {\n this.mountSpan = this.createSpan('componentMount');\n } else {\n internalLogger?.error(\n 'The Faro React Profiler requires tracing instrumentation. Please enable it in the \"instrumentations\" section of your config.'\n );\n }\n }\n\n override componentDidMount(): void {\n if (this.isOtelInitialized && this.mountSpan) {\n this.mountSpanEndTime = Date.now();\n this.mountSpan.end(this.mountSpanEndTime);\n }\n }\n\n override shouldComponentUpdate({ updateProps }: FaroProfilerProps): boolean {\n if (this.isOtelInitialized && this.mountSpan && updateProps !== this.props.updateProps) {\n const changedProps = Object.keys(updateProps).filter((key) => updateProps[key] !== this.props.updateProps[key]);\n\n if (changedProps.length > 0) {\n this.updateSpan = this.createChildSpan('componentUpdate', this.mountSpan, {\n attributes: {\n 'react.component.changed_props': changedProps,\n },\n });\n }\n }\n\n return true;\n }\n\n override componentDidUpdate(): void {\n if (this.isOtelInitialized && this.updateSpan) {\n this.updateSpan.end();\n this.updateSpan = undefined;\n }\n }\n\n override componentWillUnmount(): void {\n if (this.isOtelInitialized && this.mountSpan) {\n this.createChildSpan('componentRender', this.mountSpan, {\n startTime: this.mountSpanEndTime,\n endTime: Date.now(),\n });\n }\n }\n\n override render(): ReactNode {\n return this.props.children;\n }\n}\n"]}
|
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.withFaroProfiler = withFaroProfiler;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
const hoist_non_react_statics_1 = __importDefault(require("hoist-non-react-statics"));
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const faro_core_1 = require("@grafana/faro-core");
|
|
10
|
+
const FaroProfiler_1 = require("./FaroProfiler");
|
|
22
11
|
function withFaroProfiler(WrappedComponent, options) {
|
|
23
12
|
var _a, _b, _c;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
react_1.default.createElement(WrappedComponent,
|
|
27
|
-
Component.displayName =
|
|
13
|
+
const componentDisplayName = (_c = (_b = (_a = options === null || options === void 0 ? void 0 : options.name) !== null && _a !== void 0 ? _a : WrappedComponent.displayName) !== null && _b !== void 0 ? _b : WrappedComponent.name) !== null && _c !== void 0 ? _c : faro_core_1.unknownString;
|
|
14
|
+
const Component = (props) => (react_1.default.createElement(FaroProfiler_1.FaroProfiler, { name: componentDisplayName, updateProps: props },
|
|
15
|
+
react_1.default.createElement(WrappedComponent, Object.assign({}, props))));
|
|
16
|
+
Component.displayName = `faroProfiler(${componentDisplayName})`;
|
|
28
17
|
(0, hoist_non_react_statics_1.default)(Component, WrappedComponent);
|
|
29
18
|
return Component;
|
|
30
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withFaroProfiler.js","sourceRoot":"","sources":["../../../src/profiler/withFaroProfiler.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withFaroProfiler.js","sourceRoot":"","sources":["../../../src/profiler/withFaroProfiler.tsx"],"names":[],"mappings":";;;;;AASA,4CAiBC;AA1BD,sFAA2D;AAC3D,kDAA0B;AAG1B,kDAAmD;AAEnD,iDAA8C;AAG9C,SAAgB,gBAAgB,CAC9B,gBAAkC,EAClC,OAAgD;;IAEhD,MAAM,oBAAoB,GAAG,MAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,mCAAI,gBAAgB,CAAC,WAAW,mCAAI,gBAAgB,CAAC,IAAI,mCAAI,yBAAa,CAAC;IAErH,MAAM,SAAS,GAAU,CAAC,KAAQ,EAAE,EAAE,CAAC,CACrC,8BAAC,2BAAY,IAAC,IAAI,EAAE,oBAAoB,EAAE,WAAW,EAAE,KAAK;QAC1D,8BAAC,gBAAgB,oBAAK,KAAK,EAAI,CAClB,CAChB,CAAC;IAEF,SAAS,CAAC,WAAW,GAAG,gBAAgB,oBAAoB,GAAG,CAAC;IAEhE,IAAA,iCAAoB,EAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;IAElD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import hoistNonReactStatics from 'hoist-non-react-statics';\nimport React from 'react';\nimport type { ComponentType, FC } from 'react';\n\nimport { unknownString } from '@grafana/faro-core';\n\nimport { FaroProfiler } from './FaroProfiler';\nimport type { FaroProfilerProps } from './FaroProfiler';\n\nexport function withFaroProfiler<P extends Record<string, any>>(\n WrappedComponent: ComponentType<P>,\n options?: Omit<FaroProfilerProps, 'updateProps'>\n): FC<P> {\n const componentDisplayName = options?.name ?? WrappedComponent.displayName ?? WrappedComponent.name ?? unknownString;\n\n const Component: FC<P> = (props: P) => (\n <FaroProfiler name={componentDisplayName} updateProps={props}>\n <WrappedComponent {...props} />\n </FaroProfiler>\n );\n\n Component.displayName = `faroProfiler(${componentDisplayName})`;\n\n hoistNonReactStatics(Component, WrappedComponent);\n\n return Component;\n}\n"]}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initializeReactRouterInstrumentation = initializeReactRouterInstrumentation;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const dependencies_1 = require("../dependencies");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const v4v5_1 = require("./v4v5");
|
|
7
|
+
const v6v7_1 = require("./v6v7");
|
|
8
8
|
function initializeReactRouterInstrumentation(options) {
|
|
9
9
|
var _a;
|
|
10
|
-
|
|
10
|
+
const initMessage = 'Initializing React Router';
|
|
11
11
|
switch ((_a = options.router) === null || _a === void 0 ? void 0 : _a.version) {
|
|
12
12
|
case types_1.ReactRouterVersion.V7:
|
|
13
13
|
case types_1.ReactRouterVersion.V6:
|
|
14
|
-
dependencies_1.internalLogger.debug(
|
|
14
|
+
dependencies_1.internalLogger.debug(`${initMessage} ${options.router.version} instrumentation`);
|
|
15
15
|
(0, v6v7_1.initializeReactRouterV6Instrumentation)(options.router.dependencies);
|
|
16
16
|
break;
|
|
17
17
|
case types_1.ReactRouterVersion.V7_data_router:
|
|
18
18
|
case types_1.ReactRouterVersion.V6_data_router:
|
|
19
|
-
dependencies_1.internalLogger.debug(
|
|
19
|
+
dependencies_1.internalLogger.debug(`${initMessage} ${options.router.version} data router instrumentation`);
|
|
20
20
|
(0, v6v7_1.initializeReactRouterV6DataRouterInstrumentation)(options.router.dependencies);
|
|
21
21
|
break;
|
|
22
22
|
case types_1.ReactRouterVersion.V5:
|
|
23
23
|
case types_1.ReactRouterVersion.V4:
|
|
24
|
-
dependencies_1.internalLogger.debug(
|
|
24
|
+
dependencies_1.internalLogger.debug(`${initMessage} ${options.router.version} instrumentation`);
|
|
25
25
|
(0, v4v5_1.initializeReactRouterV4V5Instrumentation)(options.router.dependencies);
|
|
26
26
|
break;
|
|
27
27
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../src/router/initialize.ts"],"names":[],"mappings":";;AAOA,oFAyBC;AAhCD,
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../src/router/initialize.ts"],"names":[],"mappings":";;AAOA,oFAyBC;AAhCD,kDAAiD;AAGjD,mCAA6C;AAC7C,iCAAkE;AAClE,iCAAkH;AAElH,SAAgB,oCAAoC,CAAC,OAA+B;;IAClF,MAAM,WAAW,GAAG,2BAA2B,CAAC;IAEhD,QAAQ,MAAA,OAAO,CAAC,MAAM,0CAAE,OAAO,EAAE,CAAC;QAChC,KAAK,0BAAkB,CAAC,EAAE,CAAC;QAC3B,KAAK,0BAAkB,CAAC,EAAE;YACxB,6BAAc,CAAC,KAAK,CAAC,GAAG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;YACjF,IAAA,6CAAsC,EAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YACpE,MAAM;QAER,KAAK,0BAAkB,CAAC,cAAc,CAAC;QACvC,KAAK,0BAAkB,CAAC,cAAc;YACpC,6BAAc,CAAC,KAAK,CAAC,GAAG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,8BAA8B,CAAC,CAAC;YAC7F,IAAA,uDAAgD,EAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAC9E,MAAM;QAER,KAAK,0BAAkB,CAAC,EAAE,CAAC;QAC3B,KAAK,0BAAkB,CAAC,EAAE;YACxB,6BAAc,CAAC,KAAK,CAAC,GAAG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;YACjF,IAAA,+CAAwC,EAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YACtE,MAAM;QAER;YACE,6BAAc,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;IACpF,CAAC;AACH,CAAC","sourcesContent":["import { internalLogger } from '../dependencies';\nimport type { ReactIntegrationConfig } from '../types';\n\nimport { ReactRouterVersion } from './types';\nimport { initializeReactRouterV4V5Instrumentation } from './v4v5';\nimport { initializeReactRouterV6DataRouterInstrumentation, initializeReactRouterV6Instrumentation } from './v6v7';\n\nexport function initializeReactRouterInstrumentation(options: ReactIntegrationConfig): void {\n const initMessage = 'Initializing React Router';\n\n switch (options.router?.version) {\n case ReactRouterVersion.V7:\n case ReactRouterVersion.V6:\n internalLogger.debug(`${initMessage} ${options.router.version} instrumentation`);\n initializeReactRouterV6Instrumentation(options.router.dependencies);\n break;\n\n case ReactRouterVersion.V7_data_router:\n case ReactRouterVersion.V6_data_router:\n internalLogger.debug(`${initMessage} ${options.router.version} data router instrumentation`);\n initializeReactRouterV6DataRouterInstrumentation(options.router.dependencies);\n break;\n\n case ReactRouterVersion.V5:\n case ReactRouterVersion.V4:\n internalLogger.debug(`${initMessage} ${options.router.version} instrumentation`);\n initializeReactRouterV4V5Instrumentation(options.router.dependencies);\n break;\n\n default:\n internalLogger.debug('Skipping initialization of React Router instrumentation');\n }\n}\n"]}
|
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.FaroRoute = FaroRoute;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const activeEvent_1 = require("./activeEvent");
|
|
9
|
+
const routerDependencies_1 = require("./routerDependencies");
|
|
21
10
|
function FaroRoute(props) {
|
|
22
11
|
var _a;
|
|
23
12
|
if ((_a = props === null || props === void 0 ? void 0 : props.computedMatch) === null || _a === void 0 ? void 0 : _a.isExact) {
|
|
24
13
|
(0, activeEvent_1.setActiveEventRoute)(props.computedMatch.path);
|
|
25
14
|
}
|
|
26
|
-
return react_1.default.createElement(routerDependencies_1.Route,
|
|
15
|
+
return react_1.default.createElement(routerDependencies_1.Route, Object.assign({}, props));
|
|
27
16
|
}
|
|
28
17
|
//# sourceMappingURL=FaroRoute.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FaroRoute.js","sourceRoot":"","sources":["../../../../src/router/v4v5/FaroRoute.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FaroRoute.js","sourceRoot":"","sources":["../../../../src/router/v4v5/FaroRoute.tsx"],"names":[],"mappings":";;;;;AAMA,8BAMC;AAZD,kDAA0B;AAE1B,+CAAoD;AACpD,6DAA6C;AAG7C,SAAgB,SAAS,CAAC,KAAgC;;IACxD,IAAI,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,aAAa,0CAAE,OAAO,EAAE,CAAC;QAClC,IAAA,iCAAmB,EAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,8BAAC,0BAAK,oBAAK,KAAK,EAAI,CAAC;AAC9B,CAAC","sourcesContent":["import React from 'react';\n\nimport { setActiveEventRoute } from './activeEvent';\nimport { Route } from './routerDependencies';\nimport type { ReactRouterV4V5RouteProps } from './types';\n\nexport function FaroRoute(props: ReactRouterV4V5RouteProps) {\n if (props?.computedMatch?.isExact) {\n setActiveEventRoute(props.computedMatch.path);\n }\n\n return <Route {...props} />;\n}\n"]}
|
|
@@ -4,13 +4,13 @@ exports.activeEvent = void 0;
|
|
|
4
4
|
exports.createNewActiveEvent = createNewActiveEvent;
|
|
5
5
|
exports.setActiveEventRoute = setActiveEventRoute;
|
|
6
6
|
exports.sendActiveEvent = sendActiveEvent;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
8
|
+
const dependencies_1 = require("../../dependencies");
|
|
9
9
|
exports.activeEvent = undefined;
|
|
10
10
|
function createNewActiveEvent(url) {
|
|
11
11
|
exports.activeEvent = {
|
|
12
12
|
route: '',
|
|
13
|
-
url
|
|
13
|
+
url,
|
|
14
14
|
};
|
|
15
15
|
return exports.activeEvent;
|
|
16
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activeEvent.js","sourceRoot":"","sources":["../../../../src/router/v4v5/activeEvent.ts"],"names":[],"mappings":";;;AAQA,oDAOC;AAED,kDAIC;AAED,0CAIC;AA3BD,
|
|
1
|
+
{"version":3,"file":"activeEvent.js","sourceRoot":"","sources":["../../../../src/router/v4v5/activeEvent.ts"],"names":[],"mappings":";;;AAQA,oDAOC;AAED,kDAIC;AAED,0CAIC;AA3BD,wDAA2D;AAE3D,qDAAyC;AAI9B,QAAA,WAAW,GAA2C,SAAS,CAAC;AAE3E,SAAgB,oBAAoB,CAAC,GAAW;IAC9C,mBAAW,GAAG;QACZ,KAAK,EAAE,EAAE;QACT,GAAG;KACJ,CAAC;IAEF,OAAO,mBAAW,CAAC;AACrB,CAAC;AAED,SAAgB,mBAAmB,CAAC,KAAa;IAC/C,IAAI,mBAAW,EAAE,CAAC;QAChB,mBAAW,CAAC,KAAK,GAAG,KAAK,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,SAAgB,eAAe;IAC7B,kBAAG,CAAC,SAAS,CAAC,iCAAkB,EAAE,mBAAW,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IAEhF,mBAAW,GAAG,SAAS,CAAC;AAC1B,CAAC","sourcesContent":["import { EVENT_ROUTE_CHANGE } from '@grafana/faro-web-sdk';\n\nimport { api } from '../../dependencies';\n\nimport type { ReactRouterV4V5ActiveEvent } from './types';\n\nexport let activeEvent: ReactRouterV4V5ActiveEvent | undefined = undefined;\n\nexport function createNewActiveEvent(url: string): ReactRouterV4V5ActiveEvent {\n activeEvent = {\n route: '',\n url,\n };\n\n return activeEvent;\n}\n\nexport function setActiveEventRoute(route: string): void {\n if (activeEvent) {\n activeEvent.route = route;\n }\n}\n\nexport function sendActiveEvent(): void {\n api.pushEvent(EVENT_ROUTE_CHANGE, activeEvent, undefined, { skipDedupe: true });\n\n activeEvent = undefined;\n}\n"]}
|
|
@@ -6,21 +6,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.initializeReactRouterV4V5Instrumentation = initializeReactRouterV4V5Instrumentation;
|
|
7
7
|
exports.createReactRouterV4Options = createReactRouterV4Options;
|
|
8
8
|
exports.createReactRouterV5Options = createReactRouterV5Options;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const hoist_non_react_statics_1 = __importDefault(require("hoist-non-react-statics"));
|
|
10
|
+
const faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
11
|
+
const types_1 = require("../types");
|
|
12
|
+
const activeEvent_1 = require("./activeEvent");
|
|
13
|
+
const FaroRoute_1 = require("./FaroRoute");
|
|
14
|
+
const routerDependencies_1 = require("./routerDependencies");
|
|
15
15
|
function initializeReactRouterV4V5Instrumentation(dependencies) {
|
|
16
16
|
var _a, _b, _c, _d;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
FaroRoute_1.FaroRoute.displayName =
|
|
17
|
+
const Route = dependencies.Route;
|
|
18
|
+
const componentDisplayName = (_a = Route.displayName) !== null && _a !== void 0 ? _a : Route.name;
|
|
19
|
+
FaroRoute_1.FaroRoute.displayName = `faroRoute(${componentDisplayName})`;
|
|
20
20
|
(0, hoist_non_react_statics_1.default)(FaroRoute_1.FaroRoute, Route);
|
|
21
21
|
(0, routerDependencies_1.setReactRouterV4V5Dependencies)(dependencies);
|
|
22
22
|
(0, activeEvent_1.createNewActiveEvent)((_b = faro_web_sdk_1.globalObject.location) === null || _b === void 0 ? void 0 : _b.href);
|
|
23
|
-
(_d = (_c = dependencies.history).listen) === null || _d === void 0 ? void 0 : _d.call(_c,
|
|
23
|
+
(_d = (_c = dependencies.history).listen) === null || _d === void 0 ? void 0 : _d.call(_c, (_location, action) => {
|
|
24
24
|
var _a;
|
|
25
25
|
if (action === types_1.NavigationType.Push || action === types_1.NavigationType.Pop) {
|
|
26
26
|
(0, activeEvent_1.sendActiveEvent)();
|
|
@@ -31,13 +31,13 @@ function initializeReactRouterV4V5Instrumentation(dependencies) {
|
|
|
31
31
|
function createReactRouterV4Options(dependencies) {
|
|
32
32
|
return {
|
|
33
33
|
version: types_1.ReactRouterVersion.V4,
|
|
34
|
-
dependencies
|
|
34
|
+
dependencies,
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
function createReactRouterV5Options(dependencies) {
|
|
38
38
|
return {
|
|
39
39
|
version: types_1.ReactRouterVersion.V5,
|
|
40
|
-
dependencies
|
|
40
|
+
dependencies,
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
//# sourceMappingURL=initialize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/router/v4v5/initialize.ts"],"names":[],"mappings":";;;;;AAaA,4FAiBC;AAED,gEAKC;AAED,gEAKC;AA5CD,
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/router/v4v5/initialize.ts"],"names":[],"mappings":";;;;;AAaA,4FAiBC;AAED,gEAKC;AAED,gEAKC;AA5CD,sFAA2D;AAG3D,wDAAqD;AAGrD,oCAA8D;AAE9D,+CAAsE;AACtE,2CAAwC;AACxC,6DAAsE;AAGtE,SAAgB,wCAAwC,CAAC,YAAyC;;IAChG,MAAM,KAAK,GAAG,YAAY,CAAC,KAA0B,CAAC;IACtD,MAAM,oBAAoB,GAAG,MAAA,KAAK,CAAC,WAAW,mCAAI,KAAK,CAAC,IAAI,CAAC;IAC5D,qBAA+B,CAAC,WAAW,GAAG,aAAa,oBAAoB,GAAG,CAAC;IACpF,IAAA,iCAAoB,EAAC,qBAAS,EAAE,KAAK,CAAC,CAAC;IAEvC,IAAA,mDAA8B,EAAC,YAAY,CAAC,CAAC;IAE7C,IAAA,kCAAoB,EAAC,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,CAAC,CAAC;IAElD,MAAA,MAAA,YAAY,CAAC,OAAO,EAAC,MAAM,mDAAG,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE;;QAClD,IAAI,MAAM,KAAK,sBAAc,CAAC,IAAI,IAAI,MAAM,KAAK,sBAAc,CAAC,GAAG,EAAE,CAAC;YACpE,IAAA,6BAAe,GAAE,CAAC;YAElB,IAAA,kCAAoB,EAAC,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,CAAC,CAAC;QACpD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,0BAA0B,CAAC,YAAyC;IAClF,OAAO;QACL,OAAO,EAAE,0BAAkB,CAAC,EAAE;QAC9B,YAAY;KACb,CAAC;AACJ,CAAC;AAED,SAAgB,0BAA0B,CAAC,YAAyC;IAClF,OAAO;QACL,OAAO,EAAE,0BAAkB,CAAC,EAAE;QAC9B,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["import hoistNonReactStatics from 'hoist-non-react-statics';\nimport type { FunctionComponent } from 'react';\n\nimport { globalObject } from '@grafana/faro-web-sdk';\n\nimport type { ReactRouterV4V5Config } from '../../types';\nimport { NavigationType, ReactRouterVersion } from '../types';\n\nimport { createNewActiveEvent, sendActiveEvent } from './activeEvent';\nimport { FaroRoute } from './FaroRoute';\nimport { setReactRouterV4V5Dependencies } from './routerDependencies';\nimport type { ReactRouterV4V5Dependencies } from './types';\n\nexport function initializeReactRouterV4V5Instrumentation(dependencies: ReactRouterV4V5Dependencies): void {\n const Route = dependencies.Route as FunctionComponent;\n const componentDisplayName = Route.displayName ?? Route.name;\n (FaroRoute as FunctionComponent).displayName = `faroRoute(${componentDisplayName})`;\n hoistNonReactStatics(FaroRoute, Route);\n\n setReactRouterV4V5Dependencies(dependencies);\n\n createNewActiveEvent(globalObject.location?.href);\n\n dependencies.history.listen?.((_location, action) => {\n if (action === NavigationType.Push || action === NavigationType.Pop) {\n sendActiveEvent();\n\n createNewActiveEvent(globalObject.location?.href);\n }\n });\n}\n\nexport function createReactRouterV4Options(dependencies: ReactRouterV4V5Dependencies): ReactRouterV4V5Config {\n return {\n version: ReactRouterVersion.V4,\n dependencies,\n };\n}\n\nexport function createReactRouterV5Options(dependencies: ReactRouterV4V5Dependencies): ReactRouterV4V5Config {\n return {\n version: ReactRouterVersion.V5,\n dependencies,\n };\n}\n"]}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -45,31 +34,31 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
45
34
|
})();
|
|
46
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
36
|
exports.FaroRoutes = FaroRoutes;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
38
|
+
const faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
39
|
+
const dependencies_1 = require("../../dependencies");
|
|
40
|
+
const types_1 = require("../types");
|
|
41
|
+
const routerDependencies_1 = require("./routerDependencies");
|
|
42
|
+
const utils_1 = require("./utils");
|
|
54
43
|
function FaroRoutes(props) {
|
|
55
44
|
var _a;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
(0, react_1.useEffect)(
|
|
45
|
+
const location = routerDependencies_1.useLocation === null || routerDependencies_1.useLocation === void 0 ? void 0 : (0, routerDependencies_1.useLocation)();
|
|
46
|
+
const navigationType = routerDependencies_1.useNavigationType === null || routerDependencies_1.useNavigationType === void 0 ? void 0 : (0, routerDependencies_1.useNavigationType)();
|
|
47
|
+
const routes = (0, react_1.useMemo)(() => { var _a; return (_a = routerDependencies_1.createRoutesFromChildren === null || routerDependencies_1.createRoutesFromChildren === void 0 ? void 0 : (0, routerDependencies_1.createRoutesFromChildren)(props.children)) !== null && _a !== void 0 ? _a : []; }, [props.children]);
|
|
48
|
+
const lastRouteRef = (0, react_1.useRef)({});
|
|
49
|
+
(0, react_1.useEffect)(() => {
|
|
61
50
|
var _a, _b;
|
|
62
51
|
if (routerDependencies_1.isInitialized && (navigationType === types_1.NavigationType.Push || navigationType === types_1.NavigationType.Pop)) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
dependencies_1.api.pushEvent(faro_web_sdk_1.EVENT_ROUTE_CHANGE,
|
|
52
|
+
const route = (0, utils_1.getRouteFromLocation)(routes, location);
|
|
53
|
+
const url = (_a = faro_web_sdk_1.globalObject.location) === null || _a === void 0 ? void 0 : _a.href;
|
|
54
|
+
dependencies_1.api.pushEvent(faro_web_sdk_1.EVENT_ROUTE_CHANGE, Object.assign({ toRoute: route, toUrl: (_b = faro_web_sdk_1.globalObject.location) === null || _b === void 0 ? void 0 : _b.href }, lastRouteRef.current));
|
|
66
55
|
lastRouteRef.current = {
|
|
67
56
|
fromRoute: route,
|
|
68
57
|
fromUrl: url,
|
|
69
58
|
};
|
|
70
59
|
}
|
|
71
60
|
}, [location, navigationType, routes]);
|
|
72
|
-
|
|
73
|
-
return react_1.default.createElement(ActualRoutes,
|
|
61
|
+
const ActualRoutes = (_a = props.routesComponent) !== null && _a !== void 0 ? _a : routerDependencies_1.Routes;
|
|
62
|
+
return react_1.default.createElement(ActualRoutes, Object.assign({}, props));
|
|
74
63
|
}
|
|
75
64
|
//# sourceMappingURL=FaroRoutes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FaroRoutes.js","sourceRoot":"","sources":["../../../../src/router/v6v7/FaroRoutes.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FaroRoutes.js","sourceRoot":"","sources":["../../../../src/router/v6v7/FaroRoutes.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,gCA6BC;AAxCD,+CAA0D;AAE1D,wDAAyE;AAEzE,qDAAyC;AACzC,oCAA0C;AAE1C,6DAAuH;AAEvH,mCAA+C;AAE/C,SAAgB,UAAU,CAAC,KAA+B;;IACxD,MAAM,QAAQ,GAAG,gCAAW,aAAX,gCAAW,2BAAX,gCAAW,GAAI,CAAC;IACjC,MAAM,cAAc,GAAG,sCAAiB,aAAjB,sCAAiB,2BAAjB,sCAAiB,GAAI,CAAC;IAE7C,MAAM,MAAM,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE,WAAC,OAAA,MAAA,6CAAwB,aAAxB,6CAAwB,2BAAxB,6CAAwB,EAAG,KAAK,CAAC,QAAQ,CAAC,mCAAI,EAAE,CAAA,EAAA,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEjG,MAAM,YAAY,GAAG,IAAA,cAAM,EAAiC,EAAE,CAAC,CAAC;IAEhE,IAAA,iBAAS,EAAC,GAAG,EAAE;;QACb,IAAI,kCAAa,IAAI,CAAC,cAAc,KAAK,sBAAc,CAAC,IAAI,IAAI,cAAc,KAAK,sBAAc,CAAC,GAAG,CAAC,EAAE,CAAC;YACvG,MAAM,KAAK,GAAG,IAAA,4BAAoB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACrD,MAAM,GAAG,GAAG,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,CAAC;YAExC,kBAAG,CAAC,SAAS,CAAC,iCAAkB,kBAC9B,OAAO,EAAE,KAAK,EACd,KAAK,EAAE,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,IAC/B,YAAY,CAAC,OAAO,EACvB,CAAC;YAEH,YAAY,CAAC,OAAO,GAAG;gBACrB,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,GAAG;aACb,CAAC;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;IAEvC,MAAM,YAAY,GAAG,MAAA,KAAK,CAAC,eAAe,mCAAI,2BAAM,CAAC;IAErD,OAAO,8BAAC,YAAY,oBAAK,KAAK,EAAI,CAAC;AACrC,CAAC","sourcesContent":["import React, { useEffect, useMemo, useRef } from 'react';\n\nimport { EVENT_ROUTE_CHANGE, globalObject } from '@grafana/faro-web-sdk';\n\nimport { api } from '../../dependencies';\nimport { NavigationType } from '../types';\n\nimport { createRoutesFromChildren, isInitialized, Routes, useLocation, useNavigationType } from './routerDependencies';\nimport type { EventRouteTransitionAttributes, ReactRouterV6RoutesProps } from './types';\nimport { getRouteFromLocation } from './utils';\n\nexport function FaroRoutes(props: ReactRouterV6RoutesProps) {\n const location = useLocation?.();\n const navigationType = useNavigationType?.();\n\n const routes = useMemo(() => createRoutesFromChildren?.(props.children) ?? [], [props.children]);\n\n const lastRouteRef = useRef<EventRouteTransitionAttributes>({});\n\n useEffect(() => {\n if (isInitialized && (navigationType === NavigationType.Push || navigationType === NavigationType.Pop)) {\n const route = getRouteFromLocation(routes, location);\n const url = globalObject.location?.href;\n\n api.pushEvent(EVENT_ROUTE_CHANGE, {\n toRoute: route,\n toUrl: globalObject.location?.href,\n ...lastRouteRef.current,\n });\n\n lastRouteRef.current = {\n fromRoute: route,\n fromUrl: url,\n };\n }\n }, [location, navigationType, routes]);\n\n const ActualRoutes = props.routesComponent ?? Routes;\n\n return <ActualRoutes {...props} />;\n}\n"]}
|
|
@@ -9,10 +9,10 @@ exports.initializeReactRouterV6DataRouterInstrumentation = initializeReactRouter
|
|
|
9
9
|
exports.createReactRouterV6DataOptions = createReactRouterV6DataOptions;
|
|
10
10
|
exports.createReactRouterV7Options = createReactRouterV7Options;
|
|
11
11
|
exports.createReactRouterV7DataOptions = createReactRouterV7DataOptions;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const hoist_non_react_statics_1 = __importDefault(require("hoist-non-react-statics"));
|
|
13
|
+
const types_1 = require("../types");
|
|
14
|
+
const FaroRoutes_1 = require("./FaroRoutes");
|
|
15
|
+
const routerDependencies_1 = require("./routerDependencies");
|
|
16
16
|
function initializeReactRouterV6Instrumentation(dependencies) {
|
|
17
17
|
(0, hoist_non_react_statics_1.default)(FaroRoutes_1.FaroRoutes, dependencies.Routes);
|
|
18
18
|
(0, routerDependencies_1.setReactRouterV6Dependencies)(dependencies);
|
|
@@ -20,7 +20,7 @@ function initializeReactRouterV6Instrumentation(dependencies) {
|
|
|
20
20
|
function createReactRouterV6Options(dependencies) {
|
|
21
21
|
return {
|
|
22
22
|
version: types_1.ReactRouterVersion.V6,
|
|
23
|
-
dependencies
|
|
23
|
+
dependencies,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
function initializeReactRouterV6DataRouterInstrumentation(dependencies) {
|
|
@@ -29,19 +29,19 @@ function initializeReactRouterV6DataRouterInstrumentation(dependencies) {
|
|
|
29
29
|
function createReactRouterV6DataOptions(dependencies) {
|
|
30
30
|
return {
|
|
31
31
|
version: types_1.ReactRouterVersion.V6_data_router,
|
|
32
|
-
dependencies
|
|
32
|
+
dependencies,
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function createReactRouterV7Options(dependencies) {
|
|
36
36
|
return {
|
|
37
37
|
version: types_1.ReactRouterVersion.V7,
|
|
38
|
-
dependencies
|
|
38
|
+
dependencies,
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
function createReactRouterV7DataOptions(dependencies) {
|
|
42
42
|
return {
|
|
43
43
|
version: types_1.ReactRouterVersion.V7_data_router,
|
|
44
|
-
dependencies
|
|
44
|
+
dependencies,
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
//# sourceMappingURL=initialize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/router/v6v7/initialize.ts"],"names":[],"mappings":";;;;;AAiBA,wFAGC;AAED,gEAKC;AAED,4GAIC;AAED,wEAOC;AAED,gEAKC;AAED,wEAOC;AA1DD,
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/router/v6v7/initialize.ts"],"names":[],"mappings":";;;;;AAiBA,wFAGC;AAED,gEAKC;AAED,4GAIC;AAED,wEAOC;AAED,gEAKC;AAED,wEAOC;AA1DD,sFAA2D;AAQ3D,oCAA8C;AAE9C,6CAA0C;AAC1C,6DAG8B;AAG9B,SAAgB,sCAAsC,CAAC,YAAuC;IAC5F,IAAA,iCAAoB,EAAC,uBAAU,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IACtD,IAAA,iDAA4B,EAAC,YAAY,CAAC,CAAC;AAC7C,CAAC;AAED,SAAgB,0BAA0B,CAAC,YAAuC;IAChF,OAAO;QACL,OAAO,EAAE,0BAAkB,CAAC,EAAE;QAC9B,YAAY;KACb,CAAC;AACJ,CAAC;AAED,SAAgB,gDAAgD,CAC9D,YAAiD;IAEjD,IAAA,2DAAsC,EAAC,YAAY,CAAC,CAAC;AACvD,CAAC;AAED,SAAgB,8BAA8B,CAC5C,YAAiD;IAEjD,OAAO;QACL,OAAO,EAAE,0BAAkB,CAAC,cAAc;QAC1C,YAAY;KACb,CAAC;AACJ,CAAC;AAED,SAAgB,0BAA0B,CAAC,YAAuC;IAChF,OAAO;QACL,OAAO,EAAE,0BAAkB,CAAC,EAAE;QAC9B,YAAY;KACb,CAAC;AACJ,CAAC;AAED,SAAgB,8BAA8B,CAC5C,YAAiD;IAEjD,OAAO;QACL,OAAO,EAAE,0BAAkB,CAAC,cAAc;QAC1C,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["import hoistNonReactStatics from 'hoist-non-react-statics';\n\nimport type {\n ReactRouterV6Config,\n ReactRouterV6DataRouterConfig,\n ReactRouterV7Config,\n ReactRouterV7DataRouterConfig,\n} from '../../types';\nimport { ReactRouterVersion } from '../types';\n\nimport { FaroRoutes } from './FaroRoutes';\nimport {\n setReactRouterV6DataRouterDependencies as setReactRouterV6DataRouterDependencies,\n setReactRouterV6Dependencies,\n} from './routerDependencies';\nimport type { ReactRouterV6DataRouterDependencies, ReactRouterV6Dependencies } from './types';\n\nexport function initializeReactRouterV6Instrumentation(dependencies: ReactRouterV6Dependencies): void {\n hoistNonReactStatics(FaroRoutes, dependencies.Routes);\n setReactRouterV6Dependencies(dependencies);\n}\n\nexport function createReactRouterV6Options(dependencies: ReactRouterV6Dependencies): ReactRouterV6Config {\n return {\n version: ReactRouterVersion.V6,\n dependencies,\n };\n}\n\nexport function initializeReactRouterV6DataRouterInstrumentation(\n dependencies: ReactRouterV6DataRouterDependencies\n): void {\n setReactRouterV6DataRouterDependencies(dependencies);\n}\n\nexport function createReactRouterV6DataOptions(\n dependencies: ReactRouterV6DataRouterDependencies\n): ReactRouterV6DataRouterConfig {\n return {\n version: ReactRouterVersion.V6_data_router,\n dependencies,\n };\n}\n\nexport function createReactRouterV7Options(dependencies: ReactRouterV6Dependencies): ReactRouterV7Config {\n return {\n version: ReactRouterVersion.V7,\n dependencies,\n };\n}\n\nexport function createReactRouterV7DataOptions(\n dependencies: ReactRouterV6DataRouterDependencies\n): ReactRouterV7DataRouterConfig {\n return {\n version: ReactRouterVersion.V7_data_router,\n dependencies,\n };\n}\n"]}
|
|
@@ -2,27 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getNumberOfUrlSegments = getNumberOfUrlSegments;
|
|
4
4
|
exports.getRouteFromLocation = getRouteFromLocation;
|
|
5
|
-
|
|
5
|
+
const routerDependencies_1 = require("./routerDependencies");
|
|
6
6
|
function getNumberOfUrlSegments(url) {
|
|
7
|
-
return url.split(/\\?\//).filter(
|
|
7
|
+
return url.split(/\\?\//).filter((currentSegment) => currentSegment.length > 0 && currentSegment !== ',').length;
|
|
8
8
|
}
|
|
9
9
|
function getRouteFromLocation(routes, location) {
|
|
10
10
|
if (!routes || routes.length === 0) {
|
|
11
11
|
return location.pathname;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const matchedRoutes = (0, routerDependencies_1.matchRoutes)(routes, location);
|
|
14
|
+
let pathBuilder = '';
|
|
15
15
|
if (matchedRoutes) {
|
|
16
|
-
for (
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
for (let x = 0; x < matchedRoutes.length; x++) {
|
|
17
|
+
const branch = matchedRoutes[x];
|
|
18
|
+
const route = branch.route;
|
|
19
19
|
if (route) {
|
|
20
20
|
if (route.index) {
|
|
21
21
|
return branch.pathname;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
let path = route.path;
|
|
24
24
|
if (path) {
|
|
25
|
-
path = path.startsWith('/') ? path :
|
|
25
|
+
path = path.startsWith('/') ? path : `/${path}`;
|
|
26
26
|
pathBuilder += path;
|
|
27
27
|
if (branch.pathname === location.pathname) {
|
|
28
28
|
if (getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/router/v6v7/utils.ts"],"names":[],"mappings":";;AAKA,wDAEC;AAED,oDAuCC;AA9CD,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/router/v6v7/utils.ts"],"names":[],"mappings":";;AAKA,wDAEC;AAED,oDAuCC;AA9CD,6DAAmD;AAGnD,SAAgB,sBAAsB,CAAC,GAAW;IAChD,OAAO,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,IAAI,cAAc,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC;AACnH,CAAC;AAED,SAAgB,oBAAoB,CAAC,MAAkC,EAAE,QAA6B;IACpG,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;IAED,MAAM,aAAa,GAAG,IAAA,gCAAW,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEpD,IAAI,WAAW,GAAG,EAAE,CAAC;IAErB,IAAI,aAAa,EAAE,CAAC;QAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9C,MAAM,MAAM,GAAG,aAAa,CAAC,CAAC,CAAE,CAAC;YACjC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;YAE3B,IAAI,KAAK,EAAE,CAAC;gBACV,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;oBAChB,OAAO,MAAM,CAAC,QAAQ,CAAC;gBACzB,CAAC;gBAED,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;gBAEtB,IAAI,IAAI,EAAE,CAAC;oBACT,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;oBAEhD,WAAW,IAAI,IAAI,CAAC;oBAEpB,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ,EAAE,CAAC;wBAC1C,IAAI,sBAAsB,CAAC,WAAW,CAAC,KAAK,sBAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;4BACpF,OAAO,IAAI,CAAC;wBACd,CAAC;wBAED,OAAO,WAAW,CAAC;oBACrB,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC,QAAQ,CAAC;AAC3B,CAAC","sourcesContent":["import type { ReactRouterLocation } from '../types';\n\nimport { matchRoutes } from './routerDependencies';\nimport type { ReactRouterV6RouteObject } from './types';\n\nexport function getNumberOfUrlSegments(url: string): number {\n return url.split(/\\\\?\\//).filter((currentSegment) => currentSegment.length > 0 && currentSegment !== ',').length;\n}\n\nexport function getRouteFromLocation(routes: ReactRouterV6RouteObject[], location: ReactRouterLocation): string {\n if (!routes || routes.length === 0) {\n return location.pathname;\n }\n\n const matchedRoutes = matchRoutes(routes, location);\n\n let pathBuilder = '';\n\n if (matchedRoutes) {\n for (let x = 0; x < matchedRoutes.length; x++) {\n const branch = matchedRoutes[x]!;\n const route = branch.route;\n\n if (route) {\n if (route.index) {\n return branch.pathname;\n }\n\n let path = route.path;\n\n if (path) {\n path = path.startsWith('/') ? path : `/${path}`;\n\n pathBuilder += path;\n\n if (branch.pathname === location.pathname) {\n if (getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname)) {\n return path;\n }\n\n return pathBuilder;\n }\n }\n }\n }\n }\n\n return location.pathname;\n}\n"]}
|
|
@@ -1,36 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.withFaroRouterInstrumentation = withFaroRouterInstrumentation;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
const faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
5
|
+
const dependencies_1 = require("../../dependencies");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const routerDependencies_1 = require("./routerDependencies");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
20
9
|
/**
|
|
21
10
|
* To use with React Router 6.4 data APIs.
|
|
22
11
|
*/
|
|
23
12
|
function withFaroRouterInstrumentation(router) {
|
|
24
|
-
|
|
25
|
-
router.subscribe(
|
|
13
|
+
let lastRoute = {};
|
|
14
|
+
router.subscribe((state) => {
|
|
26
15
|
var _a, _b;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
const navigationType = state.historyAction;
|
|
17
|
+
const location = state.location;
|
|
18
|
+
const routes = router.routes;
|
|
30
19
|
if (routerDependencies_1.isInitialized && (navigationType === types_1.NavigationType.Push || navigationType === types_1.NavigationType.Pop)) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
dependencies_1.api.pushEvent(faro_web_sdk_1.EVENT_ROUTE_CHANGE,
|
|
20
|
+
const route = (0, utils_1.getRouteFromLocation)(routes, location);
|
|
21
|
+
const url = (_a = faro_web_sdk_1.globalObject.location) === null || _a === void 0 ? void 0 : _a.href;
|
|
22
|
+
dependencies_1.api.pushEvent(faro_web_sdk_1.EVENT_ROUTE_CHANGE, Object.assign({ toRoute: route, toUrl: (_b = faro_web_sdk_1.globalObject.location) === null || _b === void 0 ? void 0 : _b.href }, lastRoute));
|
|
34
23
|
lastRoute = {
|
|
35
24
|
fromRoute: route,
|
|
36
25
|
fromUrl: url,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withFaroRouterInstrumentation.js","sourceRoot":"","sources":["../../../../src/router/v6v7/withFaroRouterInstrumentation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withFaroRouterInstrumentation.js","sourceRoot":"","sources":["../../../../src/router/v6v7/withFaroRouterInstrumentation.ts"],"names":[],"mappings":";;AAwBA,sEA0BC;AAlDD,wDAAyE;AAEzE,qDAAyC;AACzC,oCAA0C;AAG1C,6DAAqD;AAErD,mCAA+C;AAa/C;;GAEG;AACH,SAAgB,6BAA6B,CAA4B,MAAS;IAChF,IAAI,SAAS,GAAmC,EAAE,CAAC;IAEnD,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;;QACzB,MAAM,cAAc,GAAmB,KAAK,CAAC,aAAa,CAAC;QAC3D,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE7B,IAAI,kCAAa,IAAI,CAAC,cAAc,KAAK,sBAAc,CAAC,IAAI,IAAI,cAAc,KAAK,sBAAc,CAAC,GAAG,CAAC,EAAE,CAAC;YACvG,MAAM,KAAK,GAAG,IAAA,4BAAoB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACrD,MAAM,GAAG,GAAG,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,CAAC;YAExC,kBAAG,CAAC,SAAS,CAAC,iCAAkB,kBAC9B,OAAO,EAAE,KAAK,EACd,KAAK,EAAE,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,IAC/B,SAAS,EACZ,CAAC;YAEH,SAAS,GAAG;gBACV,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,GAAG;aACb,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { EVENT_ROUTE_CHANGE, globalObject } from '@grafana/faro-web-sdk';\n\nimport { api } from '../../dependencies';\nimport { NavigationType } from '../types';\nimport type { ReactRouterLocation } from '../types';\n\nimport { isInitialized } from './routerDependencies';\nimport type { EventRouteTransitionAttributes, RouteObjectV6DataRouter } from './types';\nimport { getRouteFromLocation } from './utils';\n\ninterface RouterState {\n historyAction: NavigationType | any;\n location: ReactRouterLocation;\n}\n\ninterface Router {\n state: RouterState;\n routes: RouteObjectV6DataRouter[];\n subscribe(fn: (state: RouterState) => void): () => void;\n}\n\n/**\n * To use with React Router 6.4 data APIs.\n */\nexport function withFaroRouterInstrumentation<R extends Router = Router>(router: R) {\n let lastRoute: EventRouteTransitionAttributes = {};\n\n router.subscribe((state) => {\n const navigationType: NavigationType = state.historyAction;\n const location = state.location;\n const routes = router.routes;\n\n if (isInitialized && (navigationType === NavigationType.Push || navigationType === NavigationType.Pop)) {\n const route = getRouteFromLocation(routes, location);\n const url = globalObject.location?.href;\n\n api.pushEvent(EVENT_ROUTE_CHANGE, {\n toRoute: route,\n toUrl: globalObject.location?.href,\n ...lastRoute,\n });\n\n lastRoute = {\n fromRoute: route,\n fromUrl: url,\n };\n }\n });\n\n return router;\n}\n"]}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isReactVersionAtLeast16 = exports.isReactVersionAtLeast17 = exports.isReactVersionAtLeast18 = exports.isReactVersionAtLeast19 = exports.reactVersionMajor = exports.reactVersion = void 0;
|
|
4
4
|
exports.getMajorReactVersion = getMajorReactVersion;
|
|
5
5
|
exports.isReactVersionAtLeast = isReactVersionAtLeast;
|
|
6
|
-
|
|
6
|
+
const react_1 = require("react");
|
|
7
7
|
exports.reactVersion = react_1.version;
|
|
8
8
|
exports.reactVersionMajor = getMajorReactVersion();
|
|
9
9
|
exports.isReactVersionAtLeast19 = isReactVersionAtLeast(19);
|
|
@@ -11,7 +11,7 @@ exports.isReactVersionAtLeast18 = isReactVersionAtLeast(18);
|
|
|
11
11
|
exports.isReactVersionAtLeast17 = isReactVersionAtLeast(17);
|
|
12
12
|
exports.isReactVersionAtLeast16 = isReactVersionAtLeast(16);
|
|
13
13
|
function getMajorReactVersion() {
|
|
14
|
-
|
|
14
|
+
const major = exports.reactVersion.split('.');
|
|
15
15
|
try {
|
|
16
16
|
return major[0] ? parseInt(major[0], 10) : null;
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactVersion.js","sourceRoot":"","sources":["../../../src/utils/reactVersion.ts"],"names":[],"mappings":";;;AASA,oDAQC;AAED,sDAEC;AArBD
|
|
1
|
+
{"version":3,"file":"reactVersion.js","sourceRoot":"","sources":["../../../src/utils/reactVersion.ts"],"names":[],"mappings":";;;AASA,oDAQC;AAED,sDAEC;AArBD,iCAAgC;AAEnB,QAAA,YAAY,GAAG,eAAO,CAAC;AACvB,QAAA,iBAAiB,GAAG,oBAAoB,EAAE,CAAC;AAC3C,QAAA,uBAAuB,GAAG,qBAAqB,CAAC,EAAE,CAAC,CAAC;AACpD,QAAA,uBAAuB,GAAG,qBAAqB,CAAC,EAAE,CAAC,CAAC;AACpD,QAAA,uBAAuB,GAAG,qBAAqB,CAAC,EAAE,CAAC,CAAC;AACpD,QAAA,uBAAuB,GAAG,qBAAqB,CAAC,EAAE,CAAC,CAAC;AAEjE,SAAgB,oBAAoB;IAClC,MAAM,KAAK,GAAG,oBAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEtC,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAClD,CAAC;IAAC,OAAO,IAAI,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAgB,qBAAqB,CAAC,OAAe;IACnD,OAAO,yBAAiB,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,yBAAiB,IAAI,OAAO,CAAC;AAC3E,CAAC","sourcesContent":["import { version } from 'react';\n\nexport const reactVersion = version;\nexport const reactVersionMajor = getMajorReactVersion();\nexport const isReactVersionAtLeast19 = isReactVersionAtLeast(19);\nexport const isReactVersionAtLeast18 = isReactVersionAtLeast(18);\nexport const isReactVersionAtLeast17 = isReactVersionAtLeast(17);\nexport const isReactVersionAtLeast16 = isReactVersionAtLeast(16);\n\nexport function getMajorReactVersion(): number | null {\n const major = reactVersion.split('.');\n\n try {\n return major[0] ? parseInt(major[0], 10) : null;\n } catch (_err) {\n return null;\n }\n}\n\nexport function isReactVersionAtLeast(version: number): boolean {\n return reactVersionMajor === null ? false : reactVersionMajor >= version;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/faro-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Faro package that enables easier integration in projects built with React.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"observability",
|
|
@@ -45,23 +45,26 @@
|
|
|
45
45
|
"quality": "run-s 'quality:*'",
|
|
46
46
|
"quality:test": "jest --passWithNoTests",
|
|
47
47
|
"quality:format": "prettier --cache --cache-location=../../.cache/prettier/react --ignore-path ../../.prettierignore -w \"./**/*.{js,jsx,ts,tsx,css,scss,md,yaml,yml,json}\"",
|
|
48
|
-
"quality:lint": "run-s
|
|
48
|
+
"quality:lint": "run-s quality:lint:eslint quality:lint:prettier quality:lint:md",
|
|
49
49
|
"quality:lint:eslint": "eslint --cache --cache-location ../../.cache/eslint/react \"./**/*.{js,jsx,ts,tsx}\"",
|
|
50
50
|
"quality:lint:prettier": "prettier --cache --cache-location=../../.cache/prettier/react --ignore-path ../../.prettierignore -c \"./**/*.{js,jsx,ts,tsx,css,scss,md,yaml,yml,json}\"",
|
|
51
51
|
"quality:lint:md": "markdownlint README.md",
|
|
52
|
+
"quality:lint:fix": "run-s 'quality:lint:fix:*'",
|
|
53
|
+
"quality:lint:fix:eslint": "eslint --fix --cache --cache-location ../../.cache/eslint/react \"./**/*.{js,jsx,ts,tsx}\"",
|
|
54
|
+
"quality:lint:fix:prettier": "prettier --cache --cache-location=../../.cache/prettier/react --ignore-path ../../.prettierignore -w \"./**/*.{js,jsx,ts,tsx,css,scss,md,yaml,yml,json}\"",
|
|
52
55
|
"quality:circular-deps": "madge --circular ."
|
|
53
56
|
},
|
|
54
57
|
"dependencies": {
|
|
55
|
-
"@grafana/faro-web-sdk": "^2.
|
|
56
|
-
"@grafana/faro-web-tracing": "^2.
|
|
58
|
+
"@grafana/faro-web-sdk": "^2.4.0",
|
|
59
|
+
"@grafana/faro-web-tracing": "^2.4.0",
|
|
57
60
|
"hoist-non-react-statics": "^3.3.2"
|
|
58
61
|
},
|
|
59
62
|
"devDependencies": {
|
|
60
63
|
"@types/hoist-non-react-statics": "3.3.7",
|
|
61
64
|
"@types/react": "19.2.14",
|
|
62
|
-
"react": "19.2.
|
|
63
|
-
"react-dom": "19.2.
|
|
64
|
-
"react-router": "7.
|
|
65
|
+
"react": "19.2.5",
|
|
66
|
+
"react-dom": "19.2.5",
|
|
67
|
+
"react-router": "7.14.1"
|
|
65
68
|
},
|
|
66
69
|
"peerDependencies": {
|
|
67
70
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
@@ -83,5 +86,5 @@
|
|
|
83
86
|
"publishConfig": {
|
|
84
87
|
"access": "public"
|
|
85
88
|
},
|
|
86
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "0dcca81629cfc20cb18c6a7306209dceccdc75c8"
|
|
87
90
|
}
|