vovk 2.0.0-beta.6 → 2.0.0-beta.8
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.
- package/cli/server.cjs +15 -4
- package/package.json +1 -1
package/cli/server.cjs
CHANGED
|
@@ -63,7 +63,7 @@ const showDiff = ({ addedKeys, removedKeys, constantName }) => {
|
|
|
63
63
|
let is404Reported = false;
|
|
64
64
|
|
|
65
65
|
/** @type {() => Promise<void>} */
|
|
66
|
-
const
|
|
66
|
+
const pingNoDebounce = async () => {
|
|
67
67
|
const env = await getVars();
|
|
68
68
|
let prefix = env.VOVK_PREFIX;
|
|
69
69
|
prefix = prefix.startsWith('http://')
|
|
@@ -84,6 +84,14 @@ const ping = async () => {
|
|
|
84
84
|
});
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
+
/** @type {NodeJS.Timeout} */
|
|
88
|
+
let timer;
|
|
89
|
+
/** @type {() => void} */
|
|
90
|
+
const ping = () => {
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
timer = setTimeout(() => void pingNoDebounce(), 1000);
|
|
93
|
+
};
|
|
94
|
+
|
|
87
95
|
const server = http.createServer((req, res) => {
|
|
88
96
|
if (req.method === 'POST' && req.url === '/__metadata') {
|
|
89
97
|
let body = '';
|
|
@@ -155,12 +163,15 @@ async function startVovkServer(env) {
|
|
|
155
163
|
|
|
156
164
|
// due to changes at Next.js 14.2.0 we get too many logs, therefore the interval should be changed to fs.watch
|
|
157
165
|
// Old approach: setInterval(() => void ping(), 1000 * 3);
|
|
166
|
+
|
|
167
|
+
const srcRoot = path.join(__dirname, '../../..', 'src');
|
|
158
168
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
159
|
-
for await (const info of fs.watch(
|
|
169
|
+
for await (const info of fs.watch(srcRoot, { recursive: true })) {
|
|
160
170
|
if (info.filename) {
|
|
171
|
+
const filename = path.join(srcRoot, info.filename);
|
|
161
172
|
const importRegex = /import\s*{[^}]*\b(get|post|put|del|head|options)\b[^}]*}\s*from\s*['"]vovk['"]/;
|
|
162
|
-
const fileContent = await fs.readFile(
|
|
163
|
-
if (importRegex.test(fileContent))
|
|
173
|
+
const fileContent = await fs.readFile(filename, 'utf-8');
|
|
174
|
+
if (importRegex.test(fileContent)) void ping();
|
|
164
175
|
}
|
|
165
176
|
}
|
|
166
177
|
}
|