Skip to content

Commit bc004da

Browse files
committed
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) <noreply@anthropic.com>
1 parent 402b3b0 commit bc004da

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

tools/pfe-tools/dev-server/config.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,11 @@ async function cacheBusterMiddleware(ctx: Context, next: () => Promise<any>) {
8888
function liveReloadTsChangesMiddleware(
8989
config: ReturnType<typeof normalizeOptions>,
9090
): Middleware {
91-
/**
92-
* capture group 1:
93-
* Either config.elementsDir or `pfe-core`
94-
* `/`
95-
* **ANY** (_>= 0x_)
96-
* `.js`
97-
*/
98-
const TYPESCRIPT_SOURCES_RE = new RegExp(`(${config.elementsDir}|pfe-core)/.*\\.js`);
99-
91+
const TYPESCRIPT_SOURCES_RE = new RegExp(`(${config.elementsDir}|pfe-core)/.*\\.js$`);
10092
return function(ctx, next) {
101-
if (!ctx.path.includes('node_modules') && ctx.path
102-
.match(TYPESCRIPT_SOURCES_RE)) {
103-
ctx.redirect(ctx.path.replace('.js', '.ts'));
93+
if (!ctx.path.includes('node_modules')
94+
&& TYPESCRIPT_SOURCES_RE.test(ctx.path)) {
95+
ctx.redirect(ctx.path.replace(/\.js$/, '.ts'));
10496
} else {
10597
return next();
10698
}

0 commit comments

Comments
 (0)