@madhanmaaz/udane 0.1.0 → 0.1.1

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.
@@ -0,0 +1 @@
1
+ github: madhanmaaz
package/lib/udane.js CHANGED
@@ -59,7 +59,12 @@ module.exports = async function udane(options = {}) {
59
59
  logController: new LogController({
60
60
  disableRequestLogging: (request) => {
61
61
  // Disable logs for /__udane/*
62
- return request.url.startsWith(`/${PUBLIC_DIR_PREFIX}/`);
62
+ return (
63
+ request.url.startsWith(`/${PUBLIC_DIR_PREFIX}/`) ||
64
+ /\.(css|js|map|png|jpe?g|gif|svg|ico|webp|woff2?)(\?|$)/i.test(
65
+ request.url,
66
+ )
67
+ );
63
68
  },
64
69
  }),
65
70
  logger,
@@ -69,38 +74,58 @@ module.exports = async function udane(options = {}) {
69
74
 
70
75
  const wss = new WebSocketServer({ server: app.server, path: WS_PATH });
71
76
 
77
+ // Polling spreads the events of one build over a full interval,
78
+ // so wait longer than that before sending anything.
79
+ const POLL_INTERVAL = 300;
80
+ const settle = Math.max(config.debounce, POLL_INTERVAL + 100);
81
+
72
82
  let timer = null;
73
83
  let pending = null;
84
+ const changed = new Set();
85
+
86
+ function flush() {
87
+ const message = pending;
88
+ pending = null;
89
+
90
+ if (config.logChanges && changed.size) {
91
+ const list = [...changed];
92
+ if (list.length <= 5) {
93
+ for (const item of list) console.log(`[+] ${item}`);
94
+ } else {
95
+ console.log(`[+] ${list.length} files changed`);
96
+ }
97
+ }
98
+ changed.clear();
74
99
 
75
- function schedule(message) {
100
+ broadcast(wss, message);
101
+ }
102
+
103
+ // "reload" always wins over "refreshcss"
104
+ function schedule(message, label) {
105
+ changed.add(label);
76
106
  if (pending !== "reload") pending = message;
77
107
 
78
108
  clearTimeout(timer);
79
- timer = setTimeout(() => {
80
- const next = pending;
81
- pending = null;
82
- broadcast(wss, next);
83
- }, config.debounce);
109
+ timer = setTimeout(flush, settle);
84
110
  }
85
111
 
86
112
  const watcher = chokidar
87
113
  .watch(config.watch, {
88
114
  ignored: createIgnore(config.ignore, config.watch),
89
115
  ignoreInitial: true,
116
+ usePolling: true,
117
+ interval: POLL_INTERVAL,
90
118
  })
91
119
  .on("all", (event, filepath) => {
92
- if (config.logChanges) {
93
- console.log(
94
- `[+] ${event} ${path.relative(process.cwd(), filepath)}`,
95
- );
96
- }
97
-
98
120
  const cssOnly =
99
121
  config.cssHotSwap &&
100
122
  event === "change" &&
101
123
  filepath.endsWith(".css");
102
124
 
103
- schedule(cssOnly ? "refreshcss" : "reload");
125
+ schedule(
126
+ cssOnly ? "refreshcss" : "reload",
127
+ `${event} ${path.relative(process.cwd(), filepath)}`,
128
+ );
104
129
  })
105
130
  .on("error", (error) => {
106
131
  console.error("[-] watcher error:", error.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madhanmaaz/udane",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Udane - a fast, lightweight development server with live reload, built on Fastify.",
5
5
  "author": {
6
6
  "name": "madhanmaaz",
@@ -11,6 +11,12 @@
11
11
  "url": "git+https://github.com/madhanmaaz/udane.git"
12
12
  },
13
13
  "homepage": "https://github.com/madhanmaaz/udane#readme",
14
+ "funding": [
15
+ {
16
+ "type": "github",
17
+ "url": "https://github.com/sponsors/madhanmaaz"
18
+ }
19
+ ],
14
20
  "bugs": {
15
21
  "url": "https://github.com/madhanmaaz/udane/issues"
16
22
  },