From bc004da16cb0dc3f400b208f4dfe9db696e7a2c6 Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Sat, 23 May 2026 22:52:37 +0300 Subject: [PATCH] fix(pfe-tools): end-anchor TS redirect regex to avoid rewriting .js.map The `.js` regex in `liveReloadTsChangesMiddleware` was not end-anchored, so requests for `.js.map` (source maps) were matched and rewritten to `.ts.map`, breaking source maps in the dev server. End-anchor the regex (`\.js$`) and use a regex replacement so only the final `.js` extension is rewritten to `.ts`. Assisted-By: Claude Opus 4.6 (1M context) --- tools/pfe-tools/dev-server/config.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tools/pfe-tools/dev-server/config.ts b/tools/pfe-tools/dev-server/config.ts index 806e9a182f..fb79b7b8db 100644 --- a/tools/pfe-tools/dev-server/config.ts +++ b/tools/pfe-tools/dev-server/config.ts @@ -88,19 +88,11 @@ async function cacheBusterMiddleware(ctx: Context, next: () => Promise) { function liveReloadTsChangesMiddleware( config: ReturnType, ): Middleware { - /** - * capture group 1: - * Either config.elementsDir or `pfe-core` - * `/` - * **ANY** (_>= 0x_) - * `.js` - */ - const TYPESCRIPT_SOURCES_RE = new RegExp(`(${config.elementsDir}|pfe-core)/.*\\.js`); - + const TYPESCRIPT_SOURCES_RE = new RegExp(`(${config.elementsDir}|pfe-core)/.*\\.js$`); return function(ctx, next) { - if (!ctx.path.includes('node_modules') && ctx.path - .match(TYPESCRIPT_SOURCES_RE)) { - ctx.redirect(ctx.path.replace('.js', '.ts')); + if (!ctx.path.includes('node_modules') + && TYPESCRIPT_SOURCES_RE.test(ctx.path)) { + ctx.redirect(ctx.path.replace(/\.js$/, '.ts')); } else { return next(); }