Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
},
"packageManager": "pnpm@8.9.0",
"publishConfig": {
"registry": "https://npm.pkg.github.com"
"registry": "https://registry.npmjs.org",
"access": "public"
},
"engines": {
"node": ">=18"
Expand Down
2 changes: 1 addition & 1 deletion packages/htmldocs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "htmldocs",
"name": "@dportillo-ixs/htmldocs",
"keywords": [
"pdf",
"document",
Expand Down
15 changes: 14 additions & 1 deletion packages/htmldocs/src/utils/htmldocs-esbuild-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import { Documentation, parse } from "react-docgen";
import * as tsj from "ts-json-schema-generator";
import { DOCUMENT_SCHEMAS_DIR } from "./paths";

/**
* Escapes special regex characters in a string to make it safe for use in RegExp.
* This is necessary for Windows paths that contain backslashes and other special characters.
*
* @param s - The string to escape
* @returns The escaped string safe for use in RegExp
*/
export function escapeForRegExp(s: string): string {
return String(s).replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
}

/**
* Made to export the `renderAsync` function out of the user's email template
* so that issues like https://github.com/resend/react-email/issues/649 don't
Expand All @@ -18,8 +29,10 @@ import { DOCUMENT_SCHEMAS_DIR } from "./paths";
export const htmldocsPlugin = (documentTemplates: string[], isBuild: boolean) => ({
name: "htmldocs-plugin",
setup: (b: PluginBuild) => {
// Escape each path to handle Windows backslashes and other special characters
const escapedPaths = documentTemplates.map(escapeForRegExp);
b.onLoad(
{ filter: new RegExp(documentTemplates.join("|")) },
{ filter: new RegExp(escapedPaths.join("|")) },
async ({ path: pathToFile }) => {
let contents = await fs.promises.readFile(pathToFile, "utf8");
await generateAndWriteSchema(contents, pathToFile);
Expand Down