Skip to content

Commit 66b324b

Browse files
Merge pull request #1 from dportillo-ixs/copilot/apply-windows-path-fix
Configure @dportillo-ixs/htmldocs for npm publication and apply Windows path fix
2 parents 7c7e7cf + 9775fb3 commit 66b324b

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
},
2323
"packageManager": "pnpm@8.9.0",
2424
"publishConfig": {
25-
"registry": "https://npm.pkg.github.com"
25+
"registry": "https://registry.npmjs.org",
26+
"access": "public"
2627
},
2728
"engines": {
2829
"node": ">=18"

packages/htmldocs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "htmldocs",
2+
"name": "@dportillo-ixs/htmldocs",
33
"keywords": [
44
"pdf",
55
"document",

packages/htmldocs/src/utils/htmldocs-esbuild-plugin.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ import { Documentation, parse } from "react-docgen";
55
import * as tsj from "ts-json-schema-generator";
66
import { 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";
1829
export 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

Comments
 (0)