opticore-webapp 1.0.71 → 1.0.73
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/dist/index.cjs +66 -394
- package/dist/index.d.cts +39 -159
- package/dist/index.d.ts +39 -159
- package/dist/index.js +98 -425
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -5,6 +5,7 @@ import { TDependency } from 'opticore-dependency-inject';
|
|
|
5
5
|
import { express } from 'opticore-express';
|
|
6
6
|
import { LoggerCore } from 'opticore-logger';
|
|
7
7
|
import { CorsOptions } from 'cors';
|
|
8
|
+
import { HotReloadConfig } from 'opticore-watcher';
|
|
8
9
|
|
|
9
10
|
interface WebServerConstructorInterface {
|
|
10
11
|
app: express.Application;
|
|
@@ -12,6 +13,16 @@ interface WebServerConstructorInterface {
|
|
|
12
13
|
localLanguage: string;
|
|
13
14
|
environmentPath: any;
|
|
14
15
|
corsOriginOptions?: Partial<CorsOptions> | null;
|
|
16
|
+
/**
|
|
17
|
+
* Enable hot reload in development mode.
|
|
18
|
+
* - true → use all defaults
|
|
19
|
+
* - HotReloadConfig → custom configuration
|
|
20
|
+
* The watcher starts automatically when onStartServer() is called.
|
|
21
|
+
* On code changes the HTTP server is closed gracefully and the process
|
|
22
|
+
* exits (code 0) so your external runner restarts it:
|
|
23
|
+
* tsx --watch src/index.ts | nodemon | node --watch dist/index.js
|
|
24
|
+
*/
|
|
25
|
+
hotReload?: boolean | HotReloadConfig;
|
|
15
26
|
}
|
|
16
27
|
|
|
17
28
|
declare class WebServerCore {
|
|
@@ -25,6 +36,7 @@ declare class WebServerCore {
|
|
|
25
36
|
private readonly environmentPath;
|
|
26
37
|
private serverListenEvent;
|
|
27
38
|
private dependenciesRegistered;
|
|
39
|
+
private readonly hotReloadCfg;
|
|
28
40
|
constructor(paramsConstructor: WebServerConstructorInterface);
|
|
29
41
|
/**
|
|
30
42
|
*
|
|
@@ -53,6 +65,32 @@ declare class WebServerCore {
|
|
|
53
65
|
* @private
|
|
54
66
|
*/
|
|
55
67
|
private loadTranslationFiles;
|
|
68
|
+
/**
|
|
69
|
+
* Resolve the final HotReloadConfig by merging constructor config with
|
|
70
|
+
* HMR environment variables.
|
|
71
|
+
*
|
|
72
|
+
* Priority (highest → lowest):
|
|
73
|
+
* 1. Constructor hotReload properties (explicit code-level config)
|
|
74
|
+
* 2. HMR_* env variables (runtime / per-environment config)
|
|
75
|
+
* 3. HotReloadWatcher internal defaults (built-in fallbacks)
|
|
76
|
+
*
|
|
77
|
+
* The watcher starts when:
|
|
78
|
+
* - constructor passed hotReload: true | HotReloadConfig
|
|
79
|
+
* - OR HMR_ENABLED=true in the .env file
|
|
80
|
+
*/
|
|
81
|
+
private resolveHotReloadConfig;
|
|
82
|
+
/**
|
|
83
|
+
* Extract file extensions from glob patterns such as "src/** /*.ts".
|
|
84
|
+
* "src/** /*.ts"
|
|
85
|
+
* ".env" skipped, handled natively by the watcher
|
|
86
|
+
*/
|
|
87
|
+
private hmrExtractExtensions;
|
|
88
|
+
/**
|
|
89
|
+
* Extract ignore names from glob patterns such as "node_modules/**".
|
|
90
|
+
* "node_modules/**" → "node_modules"
|
|
91
|
+
* "dist/**" → "dist"
|
|
92
|
+
*/
|
|
93
|
+
private hmrExtractIgnore;
|
|
56
94
|
/**
|
|
57
95
|
*
|
|
58
96
|
* @param allFeatureRoutes
|
|
@@ -73,164 +111,6 @@ declare class WebServerCore {
|
|
|
73
111
|
|
|
74
112
|
declare const envPath: string;
|
|
75
113
|
|
|
76
|
-
interface HotReloadConfig {
|
|
77
|
-
/**
|
|
78
|
-
* Entry point file to run (e.g. 'dist/index.js' or 'src/index.ts')
|
|
79
|
-
*/
|
|
80
|
-
entry: string;
|
|
81
|
-
/**
|
|
82
|
-
* Runtime to use for spawning the child process.
|
|
83
|
-
* - 'node' : compiled JS only, supports IPC hot reload for .env
|
|
84
|
-
* - 'tsx' : runs TypeScript directly via tsx
|
|
85
|
-
* - 'ts-node' : runs TypeScript directly via ts-node
|
|
86
|
-
* @default 'node'
|
|
87
|
-
*/
|
|
88
|
-
runtime?: 'node' | 'tsx' | 'ts-node';
|
|
89
|
-
/**
|
|
90
|
-
* Extra arguments passed to the runtime before the entry file.
|
|
91
|
-
* Example: ['--experimental-specifier-resolution=node']
|
|
92
|
-
*/
|
|
93
|
-
runtimeArgs?: string[];
|
|
94
|
-
/**
|
|
95
|
-
* Root directory to watch for file changes.
|
|
96
|
-
* @default process.cwd()
|
|
97
|
-
*/
|
|
98
|
-
rootDir?: string;
|
|
99
|
-
/**
|
|
100
|
-
* Additional directories or glob patterns to watch.
|
|
101
|
-
* Merged with the default watched extensions (.ts, .js, .env, .json).
|
|
102
|
-
* Example: ['config', 'locales']
|
|
103
|
-
*/
|
|
104
|
-
watchDirs?: string[];
|
|
105
|
-
/**
|
|
106
|
-
* File extensions to watch.
|
|
107
|
-
* @default ['.ts', '.js', '.mjs', '.cjs', '.json', '.env']
|
|
108
|
-
*/
|
|
109
|
-
watchExtensions?: string[];
|
|
110
|
-
/**
|
|
111
|
-
* Patterns / file names to ignore in addition to the built-in ignores.
|
|
112
|
-
* Built-in ignores: node_modules, dist, .git, package.json, package-lock.json
|
|
113
|
-
* Example: ['coverage', 'tmp', 'myIgnored.json']
|
|
114
|
-
*/
|
|
115
|
-
ignore?: string[];
|
|
116
|
-
/**
|
|
117
|
-
* Path to the .env file that should be hot-reloaded without restarting.
|
|
118
|
-
* @default '.env'
|
|
119
|
-
*/
|
|
120
|
-
envFile?: string;
|
|
121
|
-
/**
|
|
122
|
-
* File extensions that support in-process hot reload (no server restart).
|
|
123
|
-
* All other watched extensions trigger a full server restart.
|
|
124
|
-
* @default ['.env', '.json']
|
|
125
|
-
*/
|
|
126
|
-
hotReloadExtensions?: string[];
|
|
127
|
-
/**
|
|
128
|
-
* Milliseconds to wait after the last change before acting (debounce).
|
|
129
|
-
* Prevents rapid successive restarts when many files change at once.
|
|
130
|
-
* @default 300
|
|
131
|
-
*/
|
|
132
|
-
debounceMs?: number;
|
|
133
|
-
/**
|
|
134
|
-
* Automatically restart the child process if it exits unexpectedly.
|
|
135
|
-
* @default true
|
|
136
|
-
*/
|
|
137
|
-
restartOnCrash?: boolean;
|
|
138
|
-
/**
|
|
139
|
-
* Maximum number of automatic restarts on crash before giving up.
|
|
140
|
-
* @default 5
|
|
141
|
-
*/
|
|
142
|
-
maxCrashRestarts?: number;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
declare class HotReloadWatcher {
|
|
146
|
-
private readonly cfg;
|
|
147
|
-
private child;
|
|
148
|
-
private watchers;
|
|
149
|
-
private debounceTimer;
|
|
150
|
-
private isRestarting;
|
|
151
|
-
private crashRestartCount;
|
|
152
|
-
private started;
|
|
153
|
-
private restartStart;
|
|
154
|
-
constructor(config: HotReloadConfig);
|
|
155
|
-
start(): Promise<void>;
|
|
156
|
-
stop(): Promise<void>;
|
|
157
|
-
private spawnChild;
|
|
158
|
-
private killChild;
|
|
159
|
-
private setupWatchers;
|
|
160
|
-
private watchDirectoryRecursive;
|
|
161
|
-
private onFileChange;
|
|
162
|
-
private doHotReload;
|
|
163
|
-
private scheduleRestart;
|
|
164
|
-
private sendIpc;
|
|
165
|
-
private shouldIgnoreDir;
|
|
166
|
-
private shouldIgnoreFile;
|
|
167
|
-
private isWatchedFile;
|
|
168
|
-
private isHotReloadable;
|
|
169
|
-
private isEnvFile;
|
|
170
|
-
private strip;
|
|
171
|
-
private ts;
|
|
172
|
-
/**
|
|
173
|
-
* Startup banner — mirrors the infoServer() box style from CoreService.
|
|
174
|
-
*
|
|
175
|
-
* ╔══════════════════════════════════════════╗
|
|
176
|
-
* gradient title
|
|
177
|
-
* ╔══ bgGreen box ════════════════════════╗
|
|
178
|
-
* entry dist/index.js
|
|
179
|
-
* runtime node (IPC enabled)
|
|
180
|
-
* root ./src
|
|
181
|
-
* watching .ts .js .json .env
|
|
182
|
-
* debounce 300ms
|
|
183
|
-
* ╚══════════════════════════════════════════╝
|
|
184
|
-
*/
|
|
185
|
-
private printBanner;
|
|
186
|
-
/**
|
|
187
|
-
* HOT event — in-process reload, no server restart.
|
|
188
|
-
*
|
|
189
|
-
* ✔ [ HOT ] 14:23:45 | .env → env variables reloaded
|
|
190
|
-
*/
|
|
191
|
-
private printHot;
|
|
192
|
-
/**
|
|
193
|
-
* RELOAD event — server restart triggered.
|
|
194
|
-
*
|
|
195
|
-
* ⚡ [ RELOAD ] 14:24:03 | src/routes/user.ts → restarting server...
|
|
196
|
-
*/
|
|
197
|
-
private printReloading;
|
|
198
|
-
/**
|
|
199
|
-
* READY event — server successfully restarted.
|
|
200
|
-
* Uses the same full-width bgGreen border as infoServer().
|
|
201
|
-
*
|
|
202
|
-
* ════════════════════════════════════════════
|
|
203
|
-
* READY server restarted in 245ms
|
|
204
|
-
* ════════════════════════════════════════════
|
|
205
|
-
*/
|
|
206
|
-
private printReady;
|
|
207
|
-
/**
|
|
208
|
-
* CRASH event — unexpected child process exit.
|
|
209
|
-
*
|
|
210
|
-
* ✘ [ CRASH ] 14:24:10 | server exited with code 1
|
|
211
|
-
*/
|
|
212
|
-
private printCrash;
|
|
213
|
-
/**
|
|
214
|
-
* RETRY event — auto-restart after crash.
|
|
215
|
-
*
|
|
216
|
-
* ↺ [ RETRY ] 14:24:11 | attempt 1 / 5
|
|
217
|
-
*/
|
|
218
|
-
private printCrashRetry;
|
|
219
|
-
/**
|
|
220
|
-
* LIMIT reached — give up restarting.
|
|
221
|
-
*/
|
|
222
|
-
private printCrashLimit;
|
|
223
|
-
/**
|
|
224
|
-
* Error — miscellaneous internal error.
|
|
225
|
-
*/
|
|
226
|
-
private printError;
|
|
227
|
-
/**
|
|
228
|
-
* Stopped — watcher shut down.
|
|
229
|
-
*/
|
|
230
|
-
private printStopped;
|
|
231
|
-
private setupProcessSignals;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
114
|
type KernelModuleType = [any[], () => void];
|
|
235
115
|
|
|
236
|
-
export { type
|
|
116
|
+
export { type KernelModuleType, WebServerCore as WebServer, envPath };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { TDependency } from 'opticore-dependency-inject';
|
|
|
5
5
|
import { express } from 'opticore-express';
|
|
6
6
|
import { LoggerCore } from 'opticore-logger';
|
|
7
7
|
import { CorsOptions } from 'cors';
|
|
8
|
+
import { HotReloadConfig } from 'opticore-watcher';
|
|
8
9
|
|
|
9
10
|
interface WebServerConstructorInterface {
|
|
10
11
|
app: express.Application;
|
|
@@ -12,6 +13,16 @@ interface WebServerConstructorInterface {
|
|
|
12
13
|
localLanguage: string;
|
|
13
14
|
environmentPath: any;
|
|
14
15
|
corsOriginOptions?: Partial<CorsOptions> | null;
|
|
16
|
+
/**
|
|
17
|
+
* Enable hot reload in development mode.
|
|
18
|
+
* - true → use all defaults
|
|
19
|
+
* - HotReloadConfig → custom configuration
|
|
20
|
+
* The watcher starts automatically when onStartServer() is called.
|
|
21
|
+
* On code changes the HTTP server is closed gracefully and the process
|
|
22
|
+
* exits (code 0) so your external runner restarts it:
|
|
23
|
+
* tsx --watch src/index.ts | nodemon | node --watch dist/index.js
|
|
24
|
+
*/
|
|
25
|
+
hotReload?: boolean | HotReloadConfig;
|
|
15
26
|
}
|
|
16
27
|
|
|
17
28
|
declare class WebServerCore {
|
|
@@ -25,6 +36,7 @@ declare class WebServerCore {
|
|
|
25
36
|
private readonly environmentPath;
|
|
26
37
|
private serverListenEvent;
|
|
27
38
|
private dependenciesRegistered;
|
|
39
|
+
private readonly hotReloadCfg;
|
|
28
40
|
constructor(paramsConstructor: WebServerConstructorInterface);
|
|
29
41
|
/**
|
|
30
42
|
*
|
|
@@ -53,6 +65,32 @@ declare class WebServerCore {
|
|
|
53
65
|
* @private
|
|
54
66
|
*/
|
|
55
67
|
private loadTranslationFiles;
|
|
68
|
+
/**
|
|
69
|
+
* Resolve the final HotReloadConfig by merging constructor config with
|
|
70
|
+
* HMR environment variables.
|
|
71
|
+
*
|
|
72
|
+
* Priority (highest → lowest):
|
|
73
|
+
* 1. Constructor hotReload properties (explicit code-level config)
|
|
74
|
+
* 2. HMR_* env variables (runtime / per-environment config)
|
|
75
|
+
* 3. HotReloadWatcher internal defaults (built-in fallbacks)
|
|
76
|
+
*
|
|
77
|
+
* The watcher starts when:
|
|
78
|
+
* - constructor passed hotReload: true | HotReloadConfig
|
|
79
|
+
* - OR HMR_ENABLED=true in the .env file
|
|
80
|
+
*/
|
|
81
|
+
private resolveHotReloadConfig;
|
|
82
|
+
/**
|
|
83
|
+
* Extract file extensions from glob patterns such as "src/** /*.ts".
|
|
84
|
+
* "src/** /*.ts"
|
|
85
|
+
* ".env" skipped, handled natively by the watcher
|
|
86
|
+
*/
|
|
87
|
+
private hmrExtractExtensions;
|
|
88
|
+
/**
|
|
89
|
+
* Extract ignore names from glob patterns such as "node_modules/**".
|
|
90
|
+
* "node_modules/**" → "node_modules"
|
|
91
|
+
* "dist/**" → "dist"
|
|
92
|
+
*/
|
|
93
|
+
private hmrExtractIgnore;
|
|
56
94
|
/**
|
|
57
95
|
*
|
|
58
96
|
* @param allFeatureRoutes
|
|
@@ -73,164 +111,6 @@ declare class WebServerCore {
|
|
|
73
111
|
|
|
74
112
|
declare const envPath: string;
|
|
75
113
|
|
|
76
|
-
interface HotReloadConfig {
|
|
77
|
-
/**
|
|
78
|
-
* Entry point file to run (e.g. 'dist/index.js' or 'src/index.ts')
|
|
79
|
-
*/
|
|
80
|
-
entry: string;
|
|
81
|
-
/**
|
|
82
|
-
* Runtime to use for spawning the child process.
|
|
83
|
-
* - 'node' : compiled JS only, supports IPC hot reload for .env
|
|
84
|
-
* - 'tsx' : runs TypeScript directly via tsx
|
|
85
|
-
* - 'ts-node' : runs TypeScript directly via ts-node
|
|
86
|
-
* @default 'node'
|
|
87
|
-
*/
|
|
88
|
-
runtime?: 'node' | 'tsx' | 'ts-node';
|
|
89
|
-
/**
|
|
90
|
-
* Extra arguments passed to the runtime before the entry file.
|
|
91
|
-
* Example: ['--experimental-specifier-resolution=node']
|
|
92
|
-
*/
|
|
93
|
-
runtimeArgs?: string[];
|
|
94
|
-
/**
|
|
95
|
-
* Root directory to watch for file changes.
|
|
96
|
-
* @default process.cwd()
|
|
97
|
-
*/
|
|
98
|
-
rootDir?: string;
|
|
99
|
-
/**
|
|
100
|
-
* Additional directories or glob patterns to watch.
|
|
101
|
-
* Merged with the default watched extensions (.ts, .js, .env, .json).
|
|
102
|
-
* Example: ['config', 'locales']
|
|
103
|
-
*/
|
|
104
|
-
watchDirs?: string[];
|
|
105
|
-
/**
|
|
106
|
-
* File extensions to watch.
|
|
107
|
-
* @default ['.ts', '.js', '.mjs', '.cjs', '.json', '.env']
|
|
108
|
-
*/
|
|
109
|
-
watchExtensions?: string[];
|
|
110
|
-
/**
|
|
111
|
-
* Patterns / file names to ignore in addition to the built-in ignores.
|
|
112
|
-
* Built-in ignores: node_modules, dist, .git, package.json, package-lock.json
|
|
113
|
-
* Example: ['coverage', 'tmp', 'myIgnored.json']
|
|
114
|
-
*/
|
|
115
|
-
ignore?: string[];
|
|
116
|
-
/**
|
|
117
|
-
* Path to the .env file that should be hot-reloaded without restarting.
|
|
118
|
-
* @default '.env'
|
|
119
|
-
*/
|
|
120
|
-
envFile?: string;
|
|
121
|
-
/**
|
|
122
|
-
* File extensions that support in-process hot reload (no server restart).
|
|
123
|
-
* All other watched extensions trigger a full server restart.
|
|
124
|
-
* @default ['.env', '.json']
|
|
125
|
-
*/
|
|
126
|
-
hotReloadExtensions?: string[];
|
|
127
|
-
/**
|
|
128
|
-
* Milliseconds to wait after the last change before acting (debounce).
|
|
129
|
-
* Prevents rapid successive restarts when many files change at once.
|
|
130
|
-
* @default 300
|
|
131
|
-
*/
|
|
132
|
-
debounceMs?: number;
|
|
133
|
-
/**
|
|
134
|
-
* Automatically restart the child process if it exits unexpectedly.
|
|
135
|
-
* @default true
|
|
136
|
-
*/
|
|
137
|
-
restartOnCrash?: boolean;
|
|
138
|
-
/**
|
|
139
|
-
* Maximum number of automatic restarts on crash before giving up.
|
|
140
|
-
* @default 5
|
|
141
|
-
*/
|
|
142
|
-
maxCrashRestarts?: number;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
declare class HotReloadWatcher {
|
|
146
|
-
private readonly cfg;
|
|
147
|
-
private child;
|
|
148
|
-
private watchers;
|
|
149
|
-
private debounceTimer;
|
|
150
|
-
private isRestarting;
|
|
151
|
-
private crashRestartCount;
|
|
152
|
-
private started;
|
|
153
|
-
private restartStart;
|
|
154
|
-
constructor(config: HotReloadConfig);
|
|
155
|
-
start(): Promise<void>;
|
|
156
|
-
stop(): Promise<void>;
|
|
157
|
-
private spawnChild;
|
|
158
|
-
private killChild;
|
|
159
|
-
private setupWatchers;
|
|
160
|
-
private watchDirectoryRecursive;
|
|
161
|
-
private onFileChange;
|
|
162
|
-
private doHotReload;
|
|
163
|
-
private scheduleRestart;
|
|
164
|
-
private sendIpc;
|
|
165
|
-
private shouldIgnoreDir;
|
|
166
|
-
private shouldIgnoreFile;
|
|
167
|
-
private isWatchedFile;
|
|
168
|
-
private isHotReloadable;
|
|
169
|
-
private isEnvFile;
|
|
170
|
-
private strip;
|
|
171
|
-
private ts;
|
|
172
|
-
/**
|
|
173
|
-
* Startup banner — mirrors the infoServer() box style from CoreService.
|
|
174
|
-
*
|
|
175
|
-
* ╔══════════════════════════════════════════╗
|
|
176
|
-
* gradient title
|
|
177
|
-
* ╔══ bgGreen box ════════════════════════╗
|
|
178
|
-
* entry dist/index.js
|
|
179
|
-
* runtime node (IPC enabled)
|
|
180
|
-
* root ./src
|
|
181
|
-
* watching .ts .js .json .env
|
|
182
|
-
* debounce 300ms
|
|
183
|
-
* ╚══════════════════════════════════════════╝
|
|
184
|
-
*/
|
|
185
|
-
private printBanner;
|
|
186
|
-
/**
|
|
187
|
-
* HOT event — in-process reload, no server restart.
|
|
188
|
-
*
|
|
189
|
-
* ✔ [ HOT ] 14:23:45 | .env → env variables reloaded
|
|
190
|
-
*/
|
|
191
|
-
private printHot;
|
|
192
|
-
/**
|
|
193
|
-
* RELOAD event — server restart triggered.
|
|
194
|
-
*
|
|
195
|
-
* ⚡ [ RELOAD ] 14:24:03 | src/routes/user.ts → restarting server...
|
|
196
|
-
*/
|
|
197
|
-
private printReloading;
|
|
198
|
-
/**
|
|
199
|
-
* READY event — server successfully restarted.
|
|
200
|
-
* Uses the same full-width bgGreen border as infoServer().
|
|
201
|
-
*
|
|
202
|
-
* ════════════════════════════════════════════
|
|
203
|
-
* READY server restarted in 245ms
|
|
204
|
-
* ════════════════════════════════════════════
|
|
205
|
-
*/
|
|
206
|
-
private printReady;
|
|
207
|
-
/**
|
|
208
|
-
* CRASH event — unexpected child process exit.
|
|
209
|
-
*
|
|
210
|
-
* ✘ [ CRASH ] 14:24:10 | server exited with code 1
|
|
211
|
-
*/
|
|
212
|
-
private printCrash;
|
|
213
|
-
/**
|
|
214
|
-
* RETRY event — auto-restart after crash.
|
|
215
|
-
*
|
|
216
|
-
* ↺ [ RETRY ] 14:24:11 | attempt 1 / 5
|
|
217
|
-
*/
|
|
218
|
-
private printCrashRetry;
|
|
219
|
-
/**
|
|
220
|
-
* LIMIT reached — give up restarting.
|
|
221
|
-
*/
|
|
222
|
-
private printCrashLimit;
|
|
223
|
-
/**
|
|
224
|
-
* Error — miscellaneous internal error.
|
|
225
|
-
*/
|
|
226
|
-
private printError;
|
|
227
|
-
/**
|
|
228
|
-
* Stopped — watcher shut down.
|
|
229
|
-
*/
|
|
230
|
-
private printStopped;
|
|
231
|
-
private setupProcessSignals;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
114
|
type KernelModuleType = [any[], () => void];
|
|
235
115
|
|
|
236
|
-
export { type
|
|
116
|
+
export { type KernelModuleType, WebServerCore as WebServer, envPath };
|