4
4
* @module
5
5
*/
6
6
7
- import { BuildOptions } from "esbuild" ;
7
+ import type { BuildOptions } from "esbuild" ;
8
8
import { isEntryFile } from "./babel" ;
9
9
import { RNRBConfig , bundle , escape } from "./bundler" ;
10
10
import { join } from "path" ;
@@ -32,25 +32,10 @@ try {
32
32
// NOP
33
33
}
34
34
35
- export const transform = async ( args : any /* TODO */ ) => {
36
- const { filename, src } = args ;
37
- const isEntry = isEntryFile ( src , filename ) ;
38
- if ( isEntry ) {
39
- const res = await bundle ( filename , metroOptions ) ;
40
- return metroTransformer . transform ( {
41
- ...args ,
42
- src :
43
- "export default String.raw`" +
44
- escape ( res ) . replace ( / \$ \{ ( .* ?) \} / g, '\\$\\{$1\\}' ) +
45
- "`.replace(/\\\\([`${}])/g, '\\$1')" ,
46
- } ) ;
47
- }
48
-
49
- return metroTransformer . transform ( args ) ;
50
- } ;
51
-
52
- export const createTransformer = ( esbuildOptions : Omit < BuildOptions , "write" | "entryPoints" | "alias" > = { } ) => {
53
- const transform = async ( args : any /* TODO */ ) => {
35
+ export const createTransformer = (
36
+ esbuildOptions : Omit < BuildOptions , "write" | "entryPoints" | "alias" > = { }
37
+ ) => {
38
+ return async ( args : any /* TODO */ ) => {
54
39
const { filename, src } = args ;
55
40
const isEntry = isEntryFile ( src , filename ) ;
56
41
if ( isEntry ) {
@@ -59,12 +44,13 @@ export const createTransformer = (esbuildOptions: Omit<BuildOptions , "write" |
59
44
...args ,
60
45
src :
61
46
"export default String.raw`" +
62
- escape ( res ) . replace ( / \$ / g, ' \\$' ) +
47
+ escape ( res ) . replace ( / \$ \{ ( . * ? ) \} / g, " \\$\\{$1\\}" ) +
63
48
"`.replace(/\\\\([`${}])/g, '\\$1')" ,
64
49
} ) ;
65
50
}
66
-
51
+
67
52
return metroTransformer . transform ( args ) ;
68
- } ;
69
- return transform ;
70
- }
53
+ } ;
54
+ } ;
55
+
56
+ export const transform = createTransformer ( ) ;
0 commit comments