Skip to content

Commit a486b90

Browse files
committed
fix(tools): dev server config watcher regexp
1 parent dd2e0b1 commit a486b90

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function cors(ctx: Context, next: Next) {
7474

7575
async function cacheBusterMiddleware(ctx: Context, next: Next) {
7676
await next();
77-
if (ctx.path.match(/elements\/[\w-]+\/[\w-]+.js$/)) {
77+
if (ctx.path.match(/(elements|pfe-core)\/.*\.js$/)) {
7878
const lm = new Date().toString();
7979
const etag = Date.now().toString();
8080
ctx.response.set('Cache-Control', 'no-store, no-cache, must-revalidate');
@@ -87,8 +87,18 @@ async function cacheBusterMiddleware(ctx: Context, next: Next) {
8787
function liveReloadTsChangesMiddleware(
8888
config: ReturnType<typeof normalizeOptions>,
8989
): Middleware {
90+
/**
91+
* capture group 1:
92+
* Either config.elementsDir or `pfe-core`
93+
* `/`
94+
* **ANY** (_>= 0x_)
95+
* `.js`
96+
*/
97+
const TYPESCRIPT_SOURCES_RE = new RegExp(`(${config.elementsDir}|pfe-core)/.*\\.js`);
98+
9099
return function(ctx, next) {
91-
if (!ctx.path.includes('node_modules') && ctx.path.match(new RegExp(`/^${config?.elementsDir}\\/.*.js/`))) {
100+
if (!ctx.path.includes('node_modules') && ctx.path
101+
.match(TYPESCRIPT_SOURCES_RE)) {
92102
ctx.redirect(ctx.path.replace('.js', '.ts'));
93103
} else {
94104
return next();

0 commit comments

Comments
 (0)