@jxsuite/server 0.23.1 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,8 @@
2
2
 
3
3
  import chokidar from "chokidar";
4
4
  import { relative } from "node:path";
5
- import { rebuild } from "./build.js";
5
+ import { rebuild } from "./build.ts";
6
+ import type { BuildEntry } from "./types.ts";
6
7
 
7
8
  const DEFAULT_IGNORE = [
8
9
  "**/node_modules/**",
@@ -16,7 +17,7 @@ const DEFAULT_IGNORE = [
16
17
  ];
17
18
 
18
19
  /** @param {string} value */
19
- function normalizePath(value) {
20
+ function normalizePath(value: string) {
20
21
  return value.replaceAll("\\", "/");
21
22
  }
22
23
 
@@ -24,7 +25,7 @@ function normalizePath(value) {
24
25
  * @param {string} pathname
25
26
  * @param {string[]} ignore
26
27
  */
27
- function shouldIgnore(pathname, ignore) {
28
+ function shouldIgnore(pathname: string, ignore: string[]) {
28
29
  const normalizedPath = normalizePath(pathname);
29
30
  return ignore.some((pattern) => {
30
31
  const normalizedPattern = normalizePath(pattern);
@@ -45,7 +46,7 @@ export { shouldIgnore };
45
46
  export const SSE_SCRIPT = `\n<script>new EventSource('/__reload').onmessage=()=>location.reload()</script>`;
46
47
 
47
48
  /** @param {string} html */
48
- export function injectSSE(html) {
49
+ export function injectSSE(html: string) {
49
50
  return html.includes("</body>")
50
51
  ? html.replace("</body>", SSE_SCRIPT + "\n</body>")
51
52
  : html + SSE_SCRIPT;
@@ -63,13 +64,16 @@ export function injectSSE(html) {
63
64
  * watcher: import("chokidar").FSWatcher;
64
65
  * }}
65
66
  */
66
- export function createWatcher(root, builds, opts = {}) {
67
+ export function createWatcher(
68
+ root: string,
69
+ builds: BuildEntry[],
70
+ opts: { ignore?: string[]; debounce?: number; reloadOnAnyChange?: boolean } = {},
71
+ ) {
67
72
  const ignore = opts.ignore ?? DEFAULT_IGNORE;
68
73
  const debounceMs = opts.debounce ?? 50;
69
74
  const reloadOnAnyChange = opts.reloadOnAnyChange ?? false;
70
75
 
71
- /** @type {Set<(msg: string) => void>} */
72
- const clients = new Set();
76
+ const clients: Set<(msg: string) => void> = new Set();
73
77
  const encoder = new TextEncoder();
74
78
 
75
79
  function broadcast() {
@@ -78,10 +82,10 @@ export function createWatcher(root, builds, opts = {}) {
78
82
 
79
83
  function handleSSE() {
80
84
  /** @type {((msg: string) => void) | undefined} */
81
- let send;
85
+ let send: ((msg: string) => void) | undefined;
82
86
  const stream = new ReadableStream({
83
87
  start(c) {
84
- send = (/** @type {string} */ msg) => {
88
+ send = (msg: string) => {
85
89
  try {
86
90
  c.enqueue(encoder.encode(msg));
87
91
  } catch {}
@@ -108,8 +112,7 @@ export function createWatcher(root, builds, opts = {}) {
108
112
  });
109
113
  }
110
114
 
111
- /** @type {ReturnType<typeof setTimeout> | null} */
112
- let timer = null;
115
+ let timer: ReturnType<typeof setTimeout> | null = null;
113
116
  const watcher = chokidar.watch(root, {
114
117
  ignored: (watchedPath) => shouldIgnore(watchedPath, ignore),
115
118
  ignoreInitial: true,