1
1
import sucrase from '@rollup/plugin-sucrase' ;
2
+ import virtual from '@rollup/plugin-virtual' ;
2
3
import * as path from 'path' ;
3
4
import type { InputOptions as RollupInputOptions , OutputOptions as RollupOutputOptions } from 'rollup' ;
4
5
import { rollup } from 'rollup' ;
5
6
6
- const getRollupInputOptions = ( proxyPath : string , userModulePath : string ) : RollupInputOptions => ( {
7
- input : proxyPath ,
7
+ const SENTRY_PROXY_MODULE_NAME = 'sentry-proxy-module' ;
8
+
9
+ const getRollupInputOptions = ( templateCode : string , userModulePath : string ) : RollupInputOptions => ( {
10
+ input : SENTRY_PROXY_MODULE_NAME ,
8
11
9
12
plugins : [
13
+ virtual ( {
14
+ [ SENTRY_PROXY_MODULE_NAME ] : templateCode ,
15
+ } ) ,
16
+
10
17
sucrase ( {
11
18
transforms : [ 'jsx' , 'typescript' ] ,
12
19
} ) ,
@@ -17,7 +24,7 @@ const getRollupInputOptions = (proxyPath: string, userModulePath: string): Rollu
17
24
// otherwise they won't be processed. (We need Rollup to process the former so that we can use the code, and we need
18
25
// it to process the latter so it knows what exports to re-export from the proxy module.) Past that, we don't care, so
19
26
// don't bother to process anything else.
20
- external : importPath => importPath !== proxyPath && importPath !== userModulePath ,
27
+ external : importPath => importPath !== SENTRY_PROXY_MODULE_NAME && importPath !== userModulePath ,
21
28
22
29
// Prevent rollup from stressing out about TS's use of global `this` when polyfilling await. (TS will polyfill if the
23
30
// user's tsconfig `target` is set to anything before `es2017`. See https://stackoverflow.com/a/72822340 and
@@ -53,17 +60,17 @@ const rollupOutputOptions: RollupOutputOptions = {
53
60
} ;
54
61
55
62
/**
56
- * Use Rollup to process the proxy module file (located at `tempProxyFilePath`) in order to split its `export * from
57
- * '<wrapped file>'` call into individual exports (which nextjs seems to need).
63
+ * Use Rollup to process the proxy module code, in order to split its `export * from '<wrapped file>'` call into
64
+ * individual exports (which nextjs seems to need).
58
65
*
59
66
* Note: Any errors which occur are handled by the proxy loader which calls this function.
60
67
*
61
- * @param tempProxyFilePath The path to the temporary file containing the proxy module code
68
+ * @param templateCode The proxy module code
62
69
* @param userModulePath The path to the file being wrapped
63
70
* @returns The processed proxy module code
64
71
*/
65
- export async function rollupize ( tempProxyFilePath : string , userModulePath : string ) : Promise < string > {
66
- const intermediateBundle = await rollup ( getRollupInputOptions ( tempProxyFilePath , userModulePath ) ) ;
72
+ export async function rollupize ( templateCode : string , userModulePath : string ) : Promise < string > {
73
+ const intermediateBundle = await rollup ( getRollupInputOptions ( templateCode , userModulePath ) ) ;
67
74
const finalBundle = await intermediateBundle . generate ( rollupOutputOptions ) ;
68
75
69
76
// The module at index 0 is always the entrypoint, which in this case is the proxy module.
0 commit comments