Skip to content

Commit 3f8d8df

Browse files
committed
react router integration
1 parent b39721b commit 3f8d8df

File tree

6 files changed

+59
-5
lines changed

6 files changed

+59
-5
lines changed

packages/plugins/rum/src/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,35 @@ export const getPlugins: GetPlugins<OptionsWithRum> = (
3737
await uploadSourcemaps(rumOptions as RumOptionsWithSourcemaps, context, log);
3838
}
3939
},
40+
transform(code) {
41+
let updatedCode = code;
42+
const createBrowserRouterImportRegExp = new RegExp(
43+
/(import \{.*)createBrowserRouter[,]?(.*\} from "react-router-dom")/g,
44+
);
45+
const hasCreateBrowserRouterImport =
46+
code.match(createBrowserRouterImportRegExp) !== null;
47+
48+
if (hasCreateBrowserRouterImport) {
49+
// Remove the import of createBrowserRouter
50+
updatedCode = updatedCode.replace(
51+
createBrowserRouterImportRegExp,
52+
(_, p1, p2) => {
53+
return `${p1}${p2}`;
54+
},
55+
);
56+
57+
// replace all occurences of `createBrowserRouter` with `DD_RUM.createBrowserRouter`
58+
updatedCode = updatedCode.replace(
59+
new RegExp(/createBrowserRouter/g),
60+
'DD_RUM.createBrowserRouter',
61+
);
62+
}
63+
64+
return updatedCode;
65+
},
66+
transformInclude(id) {
67+
return id.match(new RegExp(/.*\.(js|jsx|ts|tsx)$/)) !== null;
68+
},
4069
},
4170
];
4271
};

packages/published/esbuild-plugin/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
"main": "./dist/src/index.js",
2222
"module": "./dist/src/index.mjs",
2323
"exports": {
24-
".": "./src/index.ts"
24+
"./package.json": "./package.json",
25+
".": {
26+
"import": "./dist/src/index.mjs",
27+
"require": "./dist/src/index.js",
28+
"types": "./dist/src/index.d.ts"
29+
}
2530
},
2631
"publishConfig": {
2732
"access": "public",

packages/published/rollup-plugin/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
"main": "./dist/src/index.js",
2222
"module": "./dist/src/index.mjs",
2323
"exports": {
24-
".": "./src/index.ts"
24+
"./package.json": "./package.json",
25+
".": {
26+
"import": "./dist/src/index.mjs",
27+
"require": "./dist/src/index.js",
28+
"types": "./dist/src/index.d.ts"
29+
}
2530
},
2631
"publishConfig": {
2732
"access": "public",

packages/published/rspack-plugin/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
"main": "./dist/src/index.js",
2222
"module": "./dist/src/index.mjs",
2323
"exports": {
24-
".": "./src/index.ts"
24+
"./package.json": "./package.json",
25+
".": {
26+
"import": "./dist/src/index.mjs",
27+
"require": "./dist/src/index.js",
28+
"types": "./dist/src/index.d.ts"
29+
}
2530
},
2631
"publishConfig": {
2732
"access": "public",

packages/published/vite-plugin/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
"main": "./dist/src/index.js",
2222
"module": "./dist/src/index.mjs",
2323
"exports": {
24-
".": "./src/index.ts"
24+
"./package.json": "./package.json",
25+
".": {
26+
"import": "./dist/src/index.mjs",
27+
"require": "./dist/src/index.js",
28+
"types": "./dist/src/index.d.ts"
29+
}
2530
},
2631
"publishConfig": {
2732
"access": "public",

packages/published/webpack-plugin/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
"main": "./dist/src/index.js",
2222
"module": "./dist/src/index.mjs",
2323
"exports": {
24-
".": "./src/index.ts"
24+
"./package.json": "./package.json",
25+
".": {
26+
"import": "./dist/src/index.mjs",
27+
"require": "./dist/src/index.js",
28+
"types": "./dist/src/index.d.ts"
29+
}
2530
},
2631
"publishConfig": {
2732
"access": "public",

0 commit comments

Comments
 (0)