@@ -5,6 +5,17 @@ import { Documentation, parse } from "react-docgen";
55import * as tsj from "ts-json-schema-generator" ;
66import { DOCUMENT_SCHEMAS_DIR } from "./paths" ;
77
8+ /**
9+ * Escapes special regex characters in a string to make it safe for use in RegExp.
10+ * This is necessary for Windows paths that contain backslashes and other special characters.
11+ *
12+ * @param s - The string to escape
13+ * @returns The escaped string safe for use in RegExp
14+ */
15+ export function escapeForRegExp ( s : string ) : string {
16+ return String ( s ) . replace ( / [ - \/ \\ ^ $ * + ? . ( ) | [ \] { } ] / g, "\\$&" ) ;
17+ }
18+
819/**
920 * Made to export the `renderAsync` function out of the user's email template
1021 * so that issues like https://github.com/resend/react-email/issues/649 don't
@@ -18,8 +29,10 @@ import { DOCUMENT_SCHEMAS_DIR } from "./paths";
1829export const htmldocsPlugin = ( documentTemplates : string [ ] , isBuild : boolean ) => ( {
1930 name : "htmldocs-plugin" ,
2031 setup : ( b : PluginBuild ) => {
32+ // Escape each path to handle Windows backslashes and other special characters
33+ const escapedPaths = documentTemplates . map ( escapeForRegExp ) ;
2134 b . onLoad (
22- { filter : new RegExp ( documentTemplates . join ( "|" ) ) } ,
35+ { filter : new RegExp ( escapedPaths . join ( "|" ) ) } ,
2336 async ( { path : pathToFile } ) => {
2437 let contents = await fs . promises . readFile ( pathToFile , "utf8" ) ;
2538 await generateAndWriteSchema ( contents , pathToFile ) ;
0 commit comments