1+ import  type  {  RollupSucraseOptions  }  from  '@rollup/plugin-sucrase' ; 
12import  sucrase  from  '@rollup/plugin-sucrase' ; 
2- import  virtual  from  '@rollup/plugin-virtual' ; 
33import  {  logger  }  from  '@sentry/utils' ; 
44import  *  as  path  from  'path' ; 
55import  type  {  InputOptions  as  RollupInputOptions ,  OutputOptions  as  RollupOutputOptions  }  from  'rollup' ; 
66import  {  rollup  }  from  'rollup' ; 
77
8- const  SENTRY_PROXY_MODULE_NAME   =   'sentry-proxy-module' ; 
9- 
10- const   getRollupInputOptions   =   ( userModulePath :  string ,   proxyTemplateCode :  string ) :  RollupInputOptions   =>   ( { 
11-    input :  SENTRY_PROXY_MODULE_NAME , 
12- 
8+ const  getRollupInputOptions :  ( proxyPath :  string ,   resourcePath :  string )   =>   RollupInputOptions   =   ( 
9+    proxyPath , 
10+    resourcePath , 
11+ )   =>   ( { 
12+    input :  proxyPath , 
1313  plugins : [ 
14-     virtual ( { 
15-       [ SENTRY_PROXY_MODULE_NAME ] : proxyTemplateCode , 
16-     } ) , 
14+     // For some reason, even though everything in `RollupSucraseOptions` besides `transforms` is supposed to be 
15+     // optional, TS complains that there are a bunch of missing properties (hence the typecast). Similar to 
16+     // https://github.com/microsoft/TypeScript/issues/20722, though that's been fixed. (In this case it's an interface 
17+     // exporting a `Pick` picking optional properties which is turning them required somehow.)' 
1718    sucrase ( { 
1819      transforms : [ 'jsx' ,  'typescript' ] , 
19-     } ) , 
20+     }   as   unknown   as   RollupSucraseOptions ) , 
2021  ] , 
2122
2223  // We want to process as few files as possible, so as not to slow down the build any more than we have to. We need the 
2324  // proxy module (living in the temporary file we've created) and the file we're wrapping not to be external, because 
2425  // otherwise they won't be processed. (We need Rollup to process the former so that we can use the code, and we need 
2526  // it to process the latter so it knows what exports to re-export from the proxy module.) Past that, we don't care, so 
2627  // don't bother to process anything else. 
27-   external : importPath  =>  importPath  !==  SENTRY_PROXY_MODULE_NAME  &&  importPath  !==  userModulePath , 
28+   external : importPath  =>  importPath  !==  proxyPath  &&  importPath  !==  resourcePath , 
2829
2930  // Prevent rollup from stressing out about TS's use of global `this` when polyfilling await. (TS will polyfill if the 
3031  // user's tsconfig `target` is set to anything before `es2017`. See https://stackoverflow.com/a/72822340 and 
@@ -65,19 +66,19 @@ const rollupOutputOptions: RollupOutputOptions = {
6566 * '<wrapped file>'` call into individual exports (which nextjs seems to need). 
6667 * 
6768 * @param  tempProxyFilePath The path to the temporary file containing the proxy module code 
68-  * @param  userModulePath  The path to the file being wrapped 
69+  * @param  resourcePath  The path to the file being wrapped 
6970 * @returns  The processed proxy module code, or undefined if an error occurs 
7071 */ 
71- export  async  function  rollupize ( userModulePath : string ,  templateCode : string ) : Promise < string  |  undefined >  { 
72+ export  async  function  rollupize ( tempProxyFilePath : string ,  resourcePath : string ) : Promise < string  |  undefined >  { 
7273  let  finalBundle ; 
7374
7475  try  { 
75-     const  intermediateBundle  =  await  rollup ( getRollupInputOptions ( userModulePath ,   templateCode ) ) ; 
76+     const  intermediateBundle  =  await  rollup ( getRollupInputOptions ( tempProxyFilePath ,   resourcePath ) ) ; 
7677    finalBundle  =  await  intermediateBundle . generate ( rollupOutputOptions ) ; 
7778  }  catch  ( err )  { 
7879    __DEBUG_BUILD__  && 
7980      logger . warn ( 
80-         `Could not wrap ${ userModulePath } ${ err }  , 
81+         `Could not wrap ${ resourcePath } ${ err }  , 
8182      ) ; 
8283    return  undefined ; 
8384  } 
@@ -91,7 +92,7 @@ export async function rollupize(userModulePath: string, templateCode: string): P
9192  // square brackets into underscores. Further, Rollup adds file extensions to bare-path-type import and export sources. 
9293  // Because it assumes that everything will have already been processed, it always uses `.js` as the added extension. 
9394  // We need to restore the original name and extension so that Webpack will be able to find the wrapped file. 
94-   const  resourceFilename  =  path . basename ( userModulePath ) ; 
95+   const  resourceFilename  =  path . basename ( resourcePath ) ; 
9596  const  mutatedResourceFilename  =  resourceFilename 
9697    // `[\\[\\]]` is the character class containing `[` and `]` 
9798    . replace ( new  RegExp ( '[\\[\\]]' ,  'g' ) ,  '_' ) 
0 commit comments