fix(pfe-tools): use WDS plugin for TS redirect instead of koa middleware#3144
fix(pfe-tools): use WDS plugin for TS redirect instead of koa middleware#3144bennypowers wants to merge 2 commits into
Conversation
The liveReloadTsChangesMiddleware ran as koa middleware, which executes AFTER WDS static file serving (koa-send). When a .js file didn't exist on disk, koa-send returned 404 before the middleware could redirect to the .ts source. Convert to a WDS plugin with a serve hook, which runs BEFORE static file resolution. This fixes 404 errors for elements that only have .ts source files (no pre-compiled .js). Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
✅ Commitlint tests passed!More Info{
"valid": true,
"errors": [],
"warnings": [],
"input": "fix(pfe-tools): use WDS plugin for TS redirect instead of koa middleware"
} |
✅ Deploy Preview for patternfly-elements ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
The previous approach (serve hook) broke esbuild compilation because returning from serve() prevents other plugins from running. Instead, keep the koa middleware but call next() first, then redirect to .ts only when the .js file doesn't exist (404). This is backwards compatible: when compiled .js exists, it serves normally. Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Updates the PFE dev-server request handling to improve TypeScript-source resolution when .js files are requested but only .ts sources exist in the repo, reducing 404s during local development and test runs.
Changes:
- Adjusts
liveReloadTsChangesMiddlewareto run after downstream middleware and only redirect when the response is a 404. - Removes the inline comment describing the previous regex capture-group behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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)) { | ||
| return async function(ctx, next) { | ||
| await next(); | ||
| if (ctx.status === 404 | ||
| && !ctx.path.includes('node_modules') | ||
| && TYPESCRIPT_SOURCES_RE.test(ctx.path)) { | ||
| ctx.redirect(ctx.path.replace('.js', '.ts')); |
| return async function(ctx, next) { | ||
| await next(); | ||
| if (ctx.status === 404 | ||
| && !ctx.path.includes('node_modules') | ||
| && TYPESCRIPT_SOURCES_RE.test(ctx.path)) { | ||
| ctx.redirect(ctx.path.replace('.js', '.ts')); | ||
| } else { | ||
| return next(); | ||
| } |
Summary
liveReloadTsChangesMiddlewarefrom koa middleware to a WDSservehook pluginkoa-send(static file serving), so when a.jsfile didn't exist on disk,koa-sendreturned 404 before the middleware could rewrite the path to.tsservehook, the path rewrite runs BEFORE static file resolution.tssource files (no pre-compiled.js), such aspf-v6-tooltipTest plan
npx wtr elements/pf-v5-clipboard-copy/test/pf-clipboard-copy.spec.tspasses with no compiled.jsin elements/pf-v6-tooltipor other elements