44 * @module
55 */
66
7- import { BuildOptions } from "esbuild" ;
7+ import type { BuildOptions } from "esbuild" ;
88import { isEntryFile } from "./babel" ;
99import { RNRBConfig , bundle , escape } from "./bundler" ;
1010import { join } from "path" ;
@@ -32,25 +32,10 @@ try {
3232 // NOP
3333}
3434
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 */ ) => {
5439 const { filename, src } = args ;
5540 const isEntry = isEntryFile ( src , filename ) ;
5641 if ( isEntry ) {
@@ -59,12 +44,13 @@ export const createTransformer = (esbuildOptions: Omit<BuildOptions , "write" |
5944 ...args ,
6045 src :
6146 "export default String.raw`" +
62- escape ( res ) . replace ( / \$ / g, ' \\$' ) +
47+ escape ( res ) . replace ( / \$ \{ ( . * ? ) \} / g, " \\$\\{$1\\}" ) +
6348 "`.replace(/\\\\([`${}])/g, '\\$1')" ,
6449 } ) ;
6550 }
66-
51+
6752 return metroTransformer . transform ( args ) ;
68- } ;
69- return transform ;
70- }
53+ } ;
54+ } ;
55+
56+ export const transform = createTransformer ( ) ;
0 commit comments