File tree Expand file tree Collapse file tree 6 files changed +59
-5
lines changed
Expand file tree Collapse file tree 6 files changed +59
-5
lines changed Original file line number Diff line number Diff 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+ / ( i m p o r t \{ .* ) c r e a t e B r o w s e r R o u t e r [ , ] ? ( .* \} f r o m " r e a c t - r o u t e r - d o m " ) / 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 ( / c r e a t e B r o w s e r R o u t e r / g) ,
60+ 'DD_RUM.createBrowserRouter' ,
61+ ) ;
62+ }
63+
64+ return updatedCode ;
65+ } ,
66+ transformInclude ( id ) {
67+ return id . match ( new RegExp ( / .* \. ( j s | j s x | t s | t s x ) $ / ) ) !== null ;
68+ } ,
4069 } ,
4170 ] ;
4271} ;
Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 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" ,
You can’t perform that action at this time.
0 commit comments