@vandenberghinc/volt 1.1.6 → 1.1.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.
@@ -2,347 +2,328 @@
2
2
  /*
3
3
  * Author: Daan van den Bergh
4
4
  * Copyright: © 2022 - 2024 Daan van den Bergh.
5
+ * @deprecated use tsc & nodemon instead.
5
6
  */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || (function () {
23
- var ownKeys = function(o) {
24
- ownKeys = Object.getOwnPropertyNames || function (o) {
25
- var ar = [];
26
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
- return ar;
28
- };
29
- return ownKeys(o);
30
- };
31
- return function (mod) {
32
- if (mod && mod.__esModule) return mod;
33
- var result = {};
34
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
- __setModuleDefault(result, mod);
36
- return result;
37
- };
38
- })();
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.FileWatcher = exports.StaticFileWatcher = void 0;
41
- // ---------------------------------------------------------
42
- // Libraries.
43
- const fs = __importStar(require("fs"));
44
- const path = __importStar(require("path"));
45
- const child_process_1 = require("child_process");
46
- const _vinc_1 = require("./vinc.js");
47
- const logger_js_1 = require("./logger.js");
48
- // ---------------------------------------------------------
49
- // Static endpoints file watcher watcher only used for checking static files with reloads.
50
- class StaticFileWatcher {
51
- server;
52
- mtimes;
53
- endpoints;
54
- // @ts-ignore
55
- log_source;
56
- interval;
57
- constructor(server) {
58
- this.server = server;
59
- this.mtimes = new Map();
60
- this.endpoints = new Map();
61
- this.log_source = new logger_js_1.LogSource("StaticFileWatcher");
62
- }
63
- async start() {
64
- // Set interval.
65
- this.interval = setInterval(async () => {
66
- // Changed endpoints.
67
- const changed_endpoints = [];
68
- let changed_aspect_ratio = false;
69
- // Check file paths.
70
- for (const endpoint of this.endpoints.values()) {
71
- if (endpoint._path && !endpoint.view?.is_js_ts_view) {
72
- const path = new _vinc_1.vlib.Path(endpoint._path);
73
- if (path.mtime !== this.mtimes.get(endpoint._path)) {
74
- if (this.mtimes.get(endpoint._path) != null) {
75
- logger_js_1.logger.log(1, this.log_source, `Refreshing endpoint ${endpoint.method}:${endpoint.endpoint}.`);
76
- // Image.
77
- if (endpoint.is_image_endpoint) {
78
- endpoint._clear_cache();
79
- const aspect_ratio = await endpoint.get_aspect_ratio();
80
- if (aspect_ratio && this.server.statics_aspect_ratios.get(endpoint.endpoint) !== aspect_ratio) {
81
- changed_aspect_ratio = true;
82
- this.server.statics_aspect_ratios.set(endpoint.endpoint, aspect_ratio);
83
- }
84
- }
85
- // Static file.
86
- else if (endpoint.view == null) {
87
- endpoint._load_data_by_path(this.server);
88
- changed_endpoints.push(endpoint.endpoint);
89
- }
90
- // Refresh browser.
91
- if (this.server.browser_preview) {
92
- await this.server.browser_preview.refresh(endpoint.endpoint);
93
- }
94
- }
95
- this.mtimes.set(endpoint._path, path.mtime);
96
- }
97
- }
98
- }
99
- // Iterate all endpoints using view to check if any included scripts have changed.
100
- for (const endpoint of this.endpoints.values()) {
101
- if (endpoint.view && !endpoint.view?.is_js_ts_view) {
102
- let changed = changed_aspect_ratio;
103
- if (!changed && changed_endpoints.length > 0) {
104
- changed = endpoint.view._embedded_sources.some(url => {
105
- return changed_endpoints.includes(url);
106
- });
107
- }
108
- if (changed) {
109
- logger_js_1.logger.log(1, this.log_source, `Refreshing endpoint ${endpoint.method}:${endpoint.endpoint}.`);
110
- endpoint._refresh(this.server);
111
- if (this.server.browser_preview) {
112
- await this.server.browser_preview.refresh(endpoint.endpoint);
113
- }
114
- }
115
- }
116
- }
117
- }, 500);
118
- }
119
- add(endpoint) {
120
- if (endpoint._path) {
121
- this.mtimes.set(endpoint._path, new _vinc_1.vlib.Path(endpoint._path).mtime);
122
- }
123
- this.endpoints.set(endpoint.endpoint, endpoint);
124
- }
125
- has(endpoint) {
126
- return this.endpoints.has(endpoint);
127
- }
128
- stop() {
129
- if (this.interval) {
130
- clearInterval(this.interval);
131
- }
132
- }
133
- }
134
- exports.StaticFileWatcher = StaticFileWatcher;
135
- // ---------------------------------------------------------
136
- // File watcher watching entire files and restarting when needed.
137
- /* @docs:
138
- * @nav: Backend
139
- @chapter: Server
140
- @title: FileWatcher
141
- @description:
142
- Used to watch all included files and restart the server when any changes have been made.
143
-
144
- @parameter:
145
- @name: source
146
- @description: The path to the source directory to watch.
147
- @type: string
148
- @parameter:
149
- @name: config
150
- @description: The path to the server's configuration file.
151
- @type: string
152
- @parameter:
153
- @name: interval
154
- @description: The interval in milliseconds between file change checks.
155
- @type: number
156
- @parameter:
157
- @name: start_file
158
- @description: The optional start js file to start the server.
159
- @type: string
160
- */
161
- class FileWatcher {
162
- source;
163
- config;
164
- interval;
165
- excluded;
166
- additional_paths;
167
- start_file;
168
- // @ts-ignore
169
- log_source;
170
- args;
171
- mtimes;
172
- promise;
173
- proc;
174
- has_changed = false;
175
- _com_file;
176
- constructor({ source, config = undefined, interval = 750, excluded = [], additional_paths = [], start_file = undefined, }) {
177
- // Arguments.
178
- // this.source = source == null ? source : new vlib.Path(source).abs().str();
179
- this.config = config;
180
- this.interval = interval;
181
- this.excluded = excluded ?? [];
182
- this.excluded = this.excluded.filter(Boolean).map(path => new _vinc_1.vlib.Path(path).abs().str());
183
- this.start_file = start_file;
184
- // Check source.
185
- if (source) {
186
- source = new _vinc_1.vlib.Path(source).abs().str();
187
- }
188
- if (source instanceof _vinc_1.vlib.Path) {
189
- source = source.str();
190
- }
191
- this.source = source;
192
- if (this.source == null) {
193
- throw Error("Define argument: source.");
194
- }
195
- this.log_source = new logger_js_1.LogSource("FileWatcher");
196
- // Check if the excluded paths exist for user mistakes, these happen often.
197
- this.excluded.forEach(path => {
198
- if (!new _vinc_1.vlib.Path(path).exists()) {
199
- logger_js_1.logger.warn(1, this.log_source, `Excluded file watcher path ${path} does not exist.`);
200
- }
201
- });
202
- // Attributes.
203
- this.additional_paths = additional_paths.map(path => new _vinc_1.vlib.Path(path).abs().str());
204
- this.args = [];
205
- this.mtimes = {};
206
- this.promise = new Promise(() => { });
207
- }
208
- // Add path.
209
- add_path(path) {
210
- try {
211
- const add = new _vinc_1.vlib.Path(path).abs().str();
212
- logger_js_1.logger.log(2, this.log_source, "Add file watcher exclude", add);
213
- this.additional_paths.push(add);
214
- }
215
- catch (e) {
216
- logger_js_1.logger.warn(0, this.log_source, `Additional file watcher path ${path.toString()} does not exist.`);
217
- }
218
- }
219
- // Add exclude.
220
- add_exclude(path) {
221
- try {
222
- const add = new _vinc_1.vlib.Path(path).abs().str();
223
- logger_js_1.logger.log(2, this.log_source, "Add file watcher exclude", add);
224
- this.excluded.push(add);
225
- }
226
- catch (e) {
227
- logger_js_1.logger.warn(1, this.log_source, `Excluded file watcher path ${path.toString()} does not exist.`);
228
- }
229
- }
230
- // Start.
231
- async start() {
232
- process.on('SIGTERM', () => {
233
- this.proc.kill("SIGTERM");
234
- process.exit(0);
235
- });
236
- process.on('SIGINT', () => {
237
- this.proc.kill("SIGINT");
238
- process.exit(0);
239
- });
240
- // Spawn process.
241
- this.scan_files();
242
- this.has_changed = false;
243
- this.spawn_process();
244
- this.args.push("--file-watcher-restart");
245
- // Start scan loop.
246
- await this.scan();
247
- }
248
- // Scan.
249
- async scan() {
250
- this.scan_files();
251
- let interval = this.interval;
252
- if (this.has_changed) {
253
- interval += 250;
254
- await new Promise((resolve) => {
255
- setTimeout(async () => {
256
- this.scan_files();
257
- this.has_changed = false;
258
- await this.restart_process();
259
- resolve(null);
260
- }, 250);
261
- });
262
- }
263
- setTimeout(() => this.scan(), interval);
264
- }
265
- // Scan files.
266
- scan_files() {
267
- const scan_files = (dir) => {
268
- fs.readdirSync(dir).forEach((name) => scan_file(path.join(dir, name)));
269
- };
270
- const scan_file = (path) => {
271
- if (this.excluded.includes(path)) {
272
- return null;
273
- }
274
- let stat;
275
- try {
276
- stat = fs.statSync(path);
277
- }
278
- catch (e) {
279
- delete this.mtimes[path]; // a file was deleted.
280
- return;
281
- }
282
- if (this.mtimes[path] != stat.mtimeMs) {
283
- if (this.mtimes[path] != null) {
284
- logger_js_1.logger.log(1, this.log_source, `Source file ${path} changed.`);
285
- }
286
- this.has_changed = true;
287
- }
288
- this.mtimes[path] = stat.mtimeMs;
289
- if (stat.isDirectory()) {
290
- scan_files(path);
291
- }
292
- };
293
- scan_files(this.source);
294
- this.additional_paths.forEach((path) => scan_file(path));
295
- }
296
- // Spawn process.
297
- spawn_process() {
298
- if (this._com_file === undefined) {
299
- // @ts-ignore
300
- this._com_file = new _vinc_1.vlib.Path(`/tmp/${String.random(12)}`);
301
- }
302
- if (this.config == null && this.start_file == null) {
303
- throw new Error("When 'Server.file_watcher.start_file' is undefined, the server must be started using `$ volt --start` in order to use the file watcher.");
304
- }
305
- this.proc = (0, child_process_1.spawn)(this.start_file ? "node" : "volt", this.start_file
306
- ? [this.start_file, ...this.args, ...process.argv]
307
- : ["--start", "--config", this.config || "", ...this.args, ...process.argv], {
308
- cwd: this.source,
309
- stdio: "inherit",
310
- env: {
311
- ...process.env,
312
- "VOLT_FILE_WATCHER": "1",
313
- "VOLT_STARTED_FILE": this._com_file.str(),
314
- },
315
- });
316
- this.proc.on("exit", (code) => {
317
- if (code === 0) {
318
- this.scan_files(); // scan again so any subsequent file changes will be updated as well.
319
- this.has_changed = false;
320
- this.spawn_process();
321
- }
322
- else {
323
- process.exit(code || 1);
324
- }
325
- });
326
- this.proc.on("error", (e) => {
327
- console.error(e);
328
- process.exit(1);
329
- });
330
- }
331
- // Spawn process.
332
- async restart_process() {
333
- logger_js_1.logger.log(0, this.log_source, `Restarting server due to file changes.`);
334
- this._com_file.save_sync("0");
335
- this.has_changed = false;
336
- this.proc.kill("SIGINT");
337
- await new Promise((resolve) => {
338
- const loop = () => {
339
- if (this._com_file.load_sync() === "1") {
340
- return resolve();
341
- }
342
- setTimeout(loop, 150);
343
- };
344
- loop();
345
- });
346
- }
347
- }
348
- exports.FileWatcher = FileWatcher;
7
+ // // ---------------------------------------------------------
8
+ // // Libraries.
9
+ // import * as fs from "fs";
10
+ // import * as path from "path";
11
+ // import { spawn, type ChildProcess } from "child_process";
12
+ // import { vlib } from "./vinc.js";
13
+ // import { BrowserPreview } from "./plugins/browser.js";
14
+ // import { logger, LogSource } from "./logger.js";
15
+ // // ---------------------------------------------------------
16
+ // // Static endpoints file watcher watcher only used for checking static files with reloads.
17
+ // class StaticFileWatcher {
18
+ // private server: any;
19
+ // private mtimes: Map<string, number>;
20
+ // private endpoints: Map<string, any>;
21
+ // // @ts-ignore
22
+ // private log_source: LogSource;
23
+ // private interval: NodeJS.Timeout | undefined;
24
+ // constructor(server: any) {
25
+ // this.server = server;
26
+ // this.mtimes = new Map();
27
+ // this.endpoints = new Map();
28
+ // this.log_source = new LogSource("StaticFileWatcher");
29
+ // }
30
+ // async start(): Promise<void> {
31
+ // // Set interval.
32
+ // this.interval = setInterval(async () => {
33
+ // // Changed endpoints.
34
+ // const changed_endpoints: string[] = [];
35
+ // let changed_aspect_ratio = false;
36
+ // // Check file paths.
37
+ // for (const endpoint of this.endpoints.values()) {
38
+ // if (endpoint._path && !endpoint.view?.is_js_ts_view) {
39
+ // const path = new vlib.Path(endpoint._path);
40
+ // if (path.mtime !== this.mtimes.get(endpoint._path)) {
41
+ // if (this.mtimes.get(endpoint._path) != null) {
42
+ // logger.log(1, this.log_source, `Refreshing endpoint ${endpoint.method}:${endpoint.endpoint}.`)
43
+ // // Image.
44
+ // if (endpoint.is_image_endpoint) {
45
+ // endpoint._clear_cache();
46
+ // const aspect_ratio = await endpoint.get_aspect_ratio()
47
+ // if (aspect_ratio && this.server.statics_aspect_ratios.get(endpoint.endpoint) !== aspect_ratio) {
48
+ // changed_aspect_ratio = true;
49
+ // this.server.statics_aspect_ratios.set(endpoint.endpoint, aspect_ratio);
50
+ // }
51
+ // }
52
+ // // Static file.
53
+ // else if (endpoint.view == null) {
54
+ // endpoint._load_data_by_path(this.server);
55
+ // changed_endpoints.push(endpoint.endpoint);
56
+ // }
57
+ // // Refresh browser.
58
+ // if (this.server.browser_preview) {
59
+ // await this.server.browser_preview.refresh(endpoint.endpoint);
60
+ // }
61
+ // }
62
+ // this.mtimes.set(endpoint._path, path.mtime);
63
+ // }
64
+ // }
65
+ // }
66
+ // // Iterate all endpoints using view to check if any included scripts have changed.
67
+ // for (const endpoint of this.endpoints.values()) {
68
+ // if (endpoint.view && !endpoint.view?.is_js_ts_view) {
69
+ // let changed = changed_aspect_ratio;
70
+ // if (!changed && changed_endpoints.length > 0) {
71
+ // changed = endpoint.view._embedded_sources.some(url => {
72
+ // return changed_endpoints.includes(url);
73
+ // });
74
+ // }
75
+ // if (changed) {
76
+ // logger.log(1, this.log_source, `Refreshing endpoint ${endpoint.method}:${endpoint.endpoint}.`)
77
+ // endpoint._refresh(this.server)
78
+ // if (this.server.browser_preview) {
79
+ // await this.server.browser_preview.refresh(endpoint.endpoint);
80
+ // }
81
+ // }
82
+ // }
83
+ // }
84
+ // }, 500)
85
+ // }
86
+ // add(endpoint: any): void {
87
+ // if (endpoint._path) {
88
+ // this.mtimes.set(endpoint._path, new vlib.Path(endpoint._path).mtime)
89
+ // }
90
+ // this.endpoints.set(endpoint.endpoint, endpoint);
91
+ // }
92
+ // has(endpoint: string): boolean {
93
+ // return this.endpoints.has(endpoint);
94
+ // }
95
+ // stop(): void {
96
+ // if (this.interval) {
97
+ // clearInterval(this.interval)
98
+ // }
99
+ // }
100
+ // }
101
+ // // ---------------------------------------------------------
102
+ // // File watcher watching entire files and restarting when needed.
103
+ // /* @docs:
104
+ // * @nav: Backend
105
+ // @chapter: Server
106
+ // @title: FileWatcher
107
+ // @description:
108
+ // Used to watch all included files and restart the server when any changes have been made.
109
+ // @parameter:
110
+ // @name: source
111
+ // @description: The path to the source directory to watch.
112
+ // @type: string
113
+ // @parameter:
114
+ // @name: config
115
+ // @description: The path to the server's configuration file.
116
+ // @type: string
117
+ // @parameter:
118
+ // @name: interval
119
+ // @description: The interval in milliseconds between file change checks.
120
+ // @type: number
121
+ // @parameter:
122
+ // @name: start_file
123
+ // @description: The optional start js file to start the server.
124
+ // @type: string
125
+ // */
126
+ // class FileWatcher {
127
+ // private source: string;
128
+ // private config?: string;
129
+ // private interval: number;
130
+ // private excluded: string[];
131
+ // private additional_paths: string[];
132
+ // private start_file?: string;
133
+ // // @ts-ignore
134
+ // private log_source: LogSource;
135
+ // private args: string[];
136
+ // private mtimes: Record<string, number>;
137
+ // public promise: Promise<any>;
138
+ // private proc!: ChildProcess;
139
+ // private has_changed: boolean = false;
140
+ // private _com_file?: any;
141
+ // constructor({
142
+ // source,
143
+ // config = undefined,
144
+ // interval = 750,
145
+ // excluded = [],
146
+ // additional_paths = [],
147
+ // start_file = undefined,
148
+ // }: {
149
+ // source: vlib.Path | string,
150
+ // config?: string,
151
+ // interval?: number,
152
+ // excluded?: string[],
153
+ // additional_paths?: string[],
154
+ // start_file?: string,
155
+ // }) {
156
+ // // Arguments.
157
+ // // this.source = source == null ? source : new vlib.Path(source).abs().str();
158
+ // this.config = config;
159
+ // this.interval = interval;
160
+ // this.excluded = excluded ?? [];
161
+ // this.excluded = this.excluded.filter(Boolean).map(path => new vlib.Path(path).abs().str())
162
+ // this.start_file = start_file;
163
+ // // Check source.
164
+ // if (source) {
165
+ // source = new vlib.Path(source).abs().str();
166
+ // }
167
+ // if ((source as any) instanceof vlib.Path) {
168
+ // source = (source as any).str();
169
+ // }
170
+ // this.source = source as string;
171
+ // if (this.source == null) {
172
+ // throw Error("Define argument: source.");
173
+ // }
174
+ // this.log_source = new LogSource("FileWatcher");
175
+ // // Check if the excluded paths exist for user mistakes, these happen often.
176
+ // this.excluded.forEach(path => {
177
+ // if (!new vlib.Path(path).exists()) {
178
+ // logger.warn(1, this.log_source, `Excluded file watcher path ${path} does not exist.`);
179
+ // }
180
+ // })
181
+ // // Attributes.
182
+ // this.additional_paths = additional_paths.map(path => new vlib.Path(path).abs().str());
183
+ // this.args = [];
184
+ // this.mtimes = {};
185
+ // this.promise = new Promise(() => {});
186
+ // }
187
+ // // Add path.
188
+ // add_path(path: string | vlib.Path): void {
189
+ // try {
190
+ // const add = new vlib.Path(path).abs().str();
191
+ // logger.log(2, this.log_source, "Add file watcher exclude", add)
192
+ // this.additional_paths.push(add)
193
+ // } catch (e) {
194
+ // logger.warn(0, this.log_source, `Additional file watcher path ${path.toString()} does not exist.`);
195
+ // }
196
+ // }
197
+ // // Add exclude.
198
+ // add_exclude(path: string | vlib.Path): void {
199
+ // try {
200
+ // const add = new vlib.Path(path).abs().str();
201
+ // logger.log(2, this.log_source, "Add file watcher exclude", add)
202
+ // this.excluded.push(add)
203
+ // } catch (e) {
204
+ // logger.warn(1, this.log_source, `Excluded file watcher path ${path.toString()} does not exist.`);
205
+ // }
206
+ // }
207
+ // // Start.
208
+ // async start(): Promise<void> {
209
+ // process.on('SIGTERM', () => {
210
+ // this.proc.kill("SIGTERM");
211
+ // process.exit(0)
212
+ // });
213
+ // process.on('SIGINT', () => {
214
+ // this.proc.kill("SIGINT");
215
+ // process.exit(0)
216
+ // });
217
+ // // Spawn process.
218
+ // this.scan_files();
219
+ // this.has_changed = false;
220
+ // this.spawn_process();
221
+ // this.args.push("--file-watcher-restart")
222
+ // // Start scan loop.
223
+ // await this.scan();
224
+ // }
225
+ // // Scan.
226
+ // async scan(): Promise<void> {
227
+ // this.scan_files()
228
+ // let interval = this.interval;
229
+ // if (this.has_changed) {
230
+ // interval += 250;
231
+ // await new Promise((resolve) => {
232
+ // setTimeout(async () => {
233
+ // this.scan_files()
234
+ // this.has_changed = false;
235
+ // await this.restart_process();
236
+ // resolve(null);
237
+ // }, 250)
238
+ // })
239
+ // }
240
+ // setTimeout(() => this.scan(), interval);
241
+ // }
242
+ // // Scan files.
243
+ // scan_files(): void {
244
+ // const scan_files = (dir: string) => {
245
+ // fs.readdirSync(dir).forEach((name) => scan_file(path.join(dir, name)));
246
+ // }
247
+ // const scan_file = (path: string) => {
248
+ // if (this.excluded.includes(path)) {
249
+ // return null;
250
+ // }
251
+ // let stat;
252
+ // try {
253
+ // stat = fs.statSync(path);
254
+ // } catch (e) {
255
+ // delete this.mtimes[path]; // a file was deleted.
256
+ // return;
257
+ // }
258
+ // if (this.mtimes[path] != stat.mtimeMs) {
259
+ // if (this.mtimes[path] != null) {
260
+ // logger.log(1, this.log_source, `Source file ${path} changed.`);
261
+ // }
262
+ // this.has_changed = true;
263
+ // }
264
+ // this.mtimes[path] = stat.mtimeMs;
265
+ // if (stat.isDirectory()) {
266
+ // scan_files(path)
267
+ // }
268
+ // }
269
+ // scan_files(this.source);
270
+ // this.additional_paths.forEach((path) => scan_file(path));
271
+ // }
272
+ // // Spawn process.
273
+ // spawn_process(): void {
274
+ // if (this._com_file === undefined) {
275
+ // // @ts-ignore
276
+ // this._com_file = new vlib.Path(`/tmp/${String.random(12)}`);
277
+ // }
278
+ // if (this.config == null && this.start_file == null) {
279
+ // throw new Error("When 'Server.file_watcher.start_file' is undefined, the server must be started using `$ volt --start` in order to use the file watcher.");
280
+ // }
281
+ // this.proc = spawn(
282
+ // this.start_file ? "node" : "volt",
283
+ // this.start_file
284
+ // ? [this.start_file, ...this.args, ...process.argv]
285
+ // : ["--start", "--config", this.config || "", ...this.args, ...process.argv],
286
+ // {
287
+ // cwd: this.source,
288
+ // stdio: "inherit",
289
+ // env: {
290
+ // ...process.env,
291
+ // "VOLT_FILE_WATCHER": "1",
292
+ // "VOLT_STARTED_FILE": this._com_file.str(),
293
+ // },
294
+ // }
295
+ // );
296
+ // this.proc.on("exit", (code) => {
297
+ // if (code === 0) {
298
+ // this.scan_files(); // scan again so any subsequent file changes will be updated as well.
299
+ // this.has_changed = false;
300
+ // this.spawn_process();
301
+ // } else {
302
+ // process.exit(code || 1);
303
+ // }
304
+ // })
305
+ // this.proc.on("error", (e) => {
306
+ // console.error(e)
307
+ // process.exit(1);
308
+ // })
309
+ // }
310
+ // // Spawn process.
311
+ // async restart_process(): Promise<void> {
312
+ // logger.log(0, this.log_source, `Restarting server due to file changes.`);
313
+ // this._com_file.save_sync("0");
314
+ // this.has_changed = false;
315
+ // this.proc.kill("SIGINT");
316
+ // await new Promise<void>((resolve) => {
317
+ // const loop = () => {
318
+ // if (this._com_file.load_sync() === "1") {
319
+ // return resolve();
320
+ // }
321
+ // setTimeout(loop, 150)
322
+ // }
323
+ // loop();
324
+ // })
325
+ // }
326
+ // }
327
+ // // ---------------------------------------------------------
328
+ // // Exports.
329
+ // export { StaticFileWatcher, FileWatcher };