nmtjs 0.15.0-beta.13 → 0.15.0-beta.14
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/entrypoints/main.js +79 -10
- package/dist/entrypoints/main.js.map +1 -1
- package/dist/entrypoints/thread.js +129 -27
- package/dist/entrypoints/thread.js.map +1 -1
- package/dist/runtime/server/applications.d.ts +4 -1
- package/dist/runtime/server/applications.js +38 -15
- package/dist/runtime/server/applications.js.map +1 -1
- package/dist/runtime/server/config.d.ts +4 -0
- package/dist/runtime/server/config.js.map +1 -1
- package/dist/runtime/server/pool.d.ts +4 -2
- package/dist/runtime/server/pool.js +91 -20
- package/dist/runtime/server/pool.js.map +1 -1
- package/dist/runtime/server/proxy.js +7 -1
- package/dist/runtime/server/proxy.js.map +1 -1
- package/dist/runtime/server/server.d.ts +17 -1
- package/dist/runtime/server/server.js.map +1 -1
- package/dist/runtime/types.d.ts +13 -3
- package/dist/vite/servers/worker.d.ts +5 -2
- package/dist/vite/servers/worker.js +27 -0
- package/dist/vite/servers/worker.js.map +1 -1
- package/package.json +12 -12
- package/src/entrypoints/main.ts +103 -15
- package/src/entrypoints/thread.ts +145 -34
- package/src/runtime/server/applications.ts +53 -14
- package/src/runtime/server/config.ts +4 -0
- package/src/runtime/server/pool.ts +100 -23
- package/src/runtime/server/proxy.ts +7 -1
- package/src/runtime/server/server.ts +23 -1
- package/src/runtime/types.ts +16 -1
- package/src/vite/servers/worker.ts +37 -1
|
@@ -6,6 +6,8 @@ export class Thread extends EventEmitter {
|
|
|
6
6
|
port;
|
|
7
7
|
worker;
|
|
8
8
|
state = 'pending';
|
|
9
|
+
readyMessage;
|
|
10
|
+
startPromise;
|
|
9
11
|
constructor(port, workerPath, workerOptions) {
|
|
10
12
|
super();
|
|
11
13
|
this.port = port;
|
|
@@ -13,36 +15,94 @@ export class Thread extends EventEmitter {
|
|
|
13
15
|
...workerOptions,
|
|
14
16
|
execArgv: process.execArgv.filter((f) => !omitExecArgv.includes(f)),
|
|
15
17
|
});
|
|
16
|
-
|
|
18
|
+
this.port.on('message', (msg) => {
|
|
17
19
|
const { type, data } = msg;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
switch (type) {
|
|
21
|
+
case 'ready': {
|
|
22
|
+
this.state = 'ready';
|
|
23
|
+
this.readyMessage = data;
|
|
24
|
+
this.emit('ready', data);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case 'error': {
|
|
28
|
+
const error = createWorkerThreadError(data);
|
|
29
|
+
this.state = 'error';
|
|
30
|
+
this.emit('error', error);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case 'task': {
|
|
34
|
+
this.emit('task', data);
|
|
35
|
+
const { id, task } = data;
|
|
36
|
+
this.emit(`task-${id}`, task);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
22
39
|
}
|
|
23
|
-
};
|
|
24
|
-
this.
|
|
40
|
+
});
|
|
41
|
+
this.worker.once('exit', (code) => {
|
|
42
|
+
if (this.state === 'terminating')
|
|
43
|
+
return;
|
|
44
|
+
const error = createWorkerThreadError({
|
|
45
|
+
message: `Worker thread ${this.worker.threadId} exited unexpectedly with code ${code}`,
|
|
46
|
+
name: 'WorkerThreadExitError',
|
|
47
|
+
origin: 'runtime',
|
|
48
|
+
fatal: code !== 0,
|
|
49
|
+
}, false);
|
|
50
|
+
this.state = 'error';
|
|
51
|
+
this.emit('error', error);
|
|
52
|
+
});
|
|
25
53
|
}
|
|
26
54
|
async start() {
|
|
55
|
+
if (this.state === 'ready')
|
|
56
|
+
return;
|
|
57
|
+
if (this.startPromise)
|
|
58
|
+
return this.startPromise;
|
|
27
59
|
switch (this.state) {
|
|
28
60
|
case 'error':
|
|
29
61
|
case 'terminating':
|
|
30
62
|
case 'starting':
|
|
31
63
|
throw new Error('Cannot start worker thread in current state');
|
|
32
|
-
case 'pending':
|
|
33
|
-
|
|
34
|
-
const signal = AbortSignal.timeout(15000);
|
|
35
|
-
try {
|
|
36
|
-
await once(this, 'ready', { signal });
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
const error = new Error('Worker thread did not become ready in time', { cause: err });
|
|
40
|
-
this.emit('error', error);
|
|
41
|
-
this.stop();
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
64
|
+
case 'pending':
|
|
65
|
+
break;
|
|
45
66
|
}
|
|
67
|
+
this.state = 'starting';
|
|
68
|
+
this.startPromise = new Promise((resolve, reject) => {
|
|
69
|
+
let settled = false;
|
|
70
|
+
let timer;
|
|
71
|
+
const cleanup = () => {
|
|
72
|
+
if (settled)
|
|
73
|
+
return;
|
|
74
|
+
settled = true;
|
|
75
|
+
if (timer)
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
this.off('ready', handleReady);
|
|
78
|
+
this.off('error', handleError);
|
|
79
|
+
this.startPromise = undefined;
|
|
80
|
+
};
|
|
81
|
+
const handleReady = () => {
|
|
82
|
+
cleanup();
|
|
83
|
+
resolve();
|
|
84
|
+
};
|
|
85
|
+
const handleError = (error) => {
|
|
86
|
+
cleanup();
|
|
87
|
+
reject(error);
|
|
88
|
+
};
|
|
89
|
+
this.once('ready', handleReady);
|
|
90
|
+
this.once('error', handleError);
|
|
91
|
+
timer = setTimeout(() => {
|
|
92
|
+
const error = createWorkerThreadError({
|
|
93
|
+
message: 'Worker thread did not become ready in time',
|
|
94
|
+
name: 'WorkerStartupTimeoutError',
|
|
95
|
+
origin: 'start',
|
|
96
|
+
fatal: true,
|
|
97
|
+
}, false);
|
|
98
|
+
cleanup();
|
|
99
|
+
this.state = 'error';
|
|
100
|
+
this.emit('error', error);
|
|
101
|
+
reject(error);
|
|
102
|
+
}, 15000);
|
|
103
|
+
});
|
|
104
|
+
await this.startPromise;
|
|
105
|
+
this.startPromise = undefined;
|
|
46
106
|
}
|
|
47
107
|
async stop() {
|
|
48
108
|
switch (this.state) {
|
|
@@ -79,6 +139,17 @@ export class Thread extends EventEmitter {
|
|
|
79
139
|
this.port.postMessage({ type, data });
|
|
80
140
|
}
|
|
81
141
|
}
|
|
142
|
+
function createWorkerThreadError(message, includeStack = true) {
|
|
143
|
+
const error = new Error(message.message);
|
|
144
|
+
if (message.name)
|
|
145
|
+
error.name = message.name;
|
|
146
|
+
if (includeStack && message.stack) {
|
|
147
|
+
error.stack = message.stack;
|
|
148
|
+
}
|
|
149
|
+
error.origin = message.origin;
|
|
150
|
+
error.fatal = message.fatal;
|
|
151
|
+
return error;
|
|
152
|
+
}
|
|
82
153
|
export class Pool extends EventEmitter {
|
|
83
154
|
options;
|
|
84
155
|
threads = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/runtime/server/pool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,YAAY,EAAE,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/runtime/server/pool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,YAAY,EAAE,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAY5D,MAAM,YAAY,GAAG,CAAC,aAAa,CAAC,CAAA;AASpC,MAAM,OAAO,MAAO,SAAQ,YAW3B;IAOY;IANX,MAAM,CAAQ;IACd,KAAK,GAAgB,SAAS,CAAA;IACpB,YAAY,CAAkC;IAC9C,YAAY,CAAgB;IAEtC,YACW,IAAiB,EAC1B,UAAkB,EAClB,aAA4B;QAE5B,KAAK,EAAE,CAAA;QAJE,SAAI,GAAJ,IAAI,CAAa;QAK1B,IAAI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D,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,GAAG,CAAC,EAAE;YAC5C,YAAY,EAAE,CAAC,KAAK,CAAC;SACtB,CAAC,CAAA;QACF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,CAAA;QAC9B,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACvC,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACpC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC7B,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;YACzB,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;QACF,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
|
@@ -32,7 +32,13 @@ export class ApplicationServerProxy {
|
|
|
32
32
|
tls: config.tls
|
|
33
33
|
? { keyPath: config.tls.key, certPath: config.tls.cert }
|
|
34
34
|
: undefined,
|
|
35
|
-
applications:
|
|
35
|
+
applications: Object.entries(config.applications)
|
|
36
|
+
.filter(([_, options]) => options !== undefined)
|
|
37
|
+
.map(([app, options]) => ({
|
|
38
|
+
name: app,
|
|
39
|
+
routing: options.routing,
|
|
40
|
+
sni: options.sni,
|
|
41
|
+
})),
|
|
36
42
|
});
|
|
37
43
|
this.onAdd = (application, upstream) => {
|
|
38
44
|
const proxyUpstream = toProxyUpstream(upstream);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/runtime/server/proxy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,cAAc,CAAA;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AI;QACR,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;QAEnD,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;QAC/C,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QAErD,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAA;IAC/B,CAAC;CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type EventEmitter from 'node:events';
|
|
1
2
|
import type { Worker } from 'node:worker_threads';
|
|
2
3
|
import type { Logger } from '@nmtjs/core';
|
|
3
|
-
import type { Store } from '../types.ts';
|
|
4
|
+
import type { Store, ThreadPortMessageTypes, WorkerThreadError } from '../types.ts';
|
|
4
5
|
import type { ServerConfig } from './config.ts';
|
|
5
6
|
import { ApplicationServerApplications } from './applications.ts';
|
|
6
7
|
import { ApplicationServerJobs } from './jobs.ts';
|
|
@@ -10,10 +11,25 @@ export type ApplicationServerRunOptions = {
|
|
|
10
11
|
scheduler: boolean;
|
|
11
12
|
jobs: boolean;
|
|
12
13
|
};
|
|
14
|
+
export type ApplicationWorkerReadyEvent = {
|
|
15
|
+
application: string;
|
|
16
|
+
threadId: number;
|
|
17
|
+
hosts?: ThreadPortMessageTypes['ready']['hosts'];
|
|
18
|
+
};
|
|
19
|
+
export type ApplicationWorkerErrorEvent = {
|
|
20
|
+
application: string;
|
|
21
|
+
threadId: number;
|
|
22
|
+
error: WorkerThreadError;
|
|
23
|
+
};
|
|
13
24
|
export type ApplicationServerWorkerConfig = {
|
|
14
25
|
path: string;
|
|
15
26
|
workerData?: any;
|
|
16
27
|
worker?: (worker: Worker) => any;
|
|
28
|
+
events?: EventEmitter<{
|
|
29
|
+
worker: [Worker];
|
|
30
|
+
'worker-ready': [ApplicationWorkerReadyEvent];
|
|
31
|
+
'worker-error': [ApplicationWorkerErrorEvent];
|
|
32
|
+
}>;
|
|
17
33
|
};
|
|
18
34
|
export declare class ApplicationServer {
|
|
19
35
|
readonly config: ServerConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/runtime/server/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/runtime/server/server.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAQ1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AA+BnD,MAAM,OAAO,iBAAiB;IAUjB;IACA;IAIA;IACA;IAfX,MAAM,CAAQ;IAEd,YAAY,CAAgC;IAC5C,UAAU,CAAwB;IAElC,KAAK,CAAyB;IAC9B,KAAK,CAAQ;IAEb,YACW,MAAoB,EACpB,kBAGR,EACQ,YAA2C,EAC3C,aAA0C;QACjD,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;QAC9C,SAAS,EAAE,KAAK;QAChB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC;KACzC;QAVQ,WAAM,GAAN,MAAM,CAAc;QACpB,uBAAkB,GAAlB,kBAAkB,CAG1B;QACQ,iBAAY,GAAZ,YAAY,CAA+B;QAC3C,eAAU,GAAV,UAAU,CAIlB;QAED,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QACnD,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,EAAE,YAAY,EAAE,kBAAk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ts
CHANGED
|
@@ -5,6 +5,18 @@ import type { Redis as Valkey, RedisOptions as ValkeyOptions } from 'iovalkey';
|
|
|
5
5
|
import type { ApplicationConfig } from './application/config.ts';
|
|
6
6
|
import type { BaseRuntime } from './core/runtime.ts';
|
|
7
7
|
import type { LifecycleHook, StoreType } from './enums.ts';
|
|
8
|
+
export type WorkerThreadErrorOrigin = 'bootstrap' | 'start' | 'runtime';
|
|
9
|
+
export type ThreadErrorMessage = {
|
|
10
|
+
message: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
stack?: string;
|
|
13
|
+
origin: WorkerThreadErrorOrigin;
|
|
14
|
+
fatal: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type WorkerThreadError = Error & {
|
|
17
|
+
origin?: WorkerThreadErrorOrigin;
|
|
18
|
+
fatal?: boolean;
|
|
19
|
+
};
|
|
8
20
|
export type ServerPortMessageTypes = {
|
|
9
21
|
stop: undefined;
|
|
10
22
|
task: {
|
|
@@ -19,9 +31,7 @@ export type ThreadPortMessageTypes = {
|
|
|
19
31
|
url: string;
|
|
20
32
|
}[];
|
|
21
33
|
};
|
|
22
|
-
error:
|
|
23
|
-
error: Error;
|
|
24
|
-
};
|
|
34
|
+
error: ThreadErrorMessage;
|
|
25
35
|
task: {
|
|
26
36
|
id: string;
|
|
27
37
|
task: JobTaskResult;
|
|
@@ -3,6 +3,9 @@ import type { Worker } from 'node:worker_threads';
|
|
|
3
3
|
import type { ViteDevServer } from 'vite';
|
|
4
4
|
import type { NeemataConfig } from '../../config.ts';
|
|
5
5
|
import type { ViteConfigOptions } from '../config.ts';
|
|
6
|
-
export
|
|
6
|
+
export type WorkerServerEventMap = {
|
|
7
7
|
worker: [Worker];
|
|
8
|
-
|
|
8
|
+
'worker-error': [unknown];
|
|
9
|
+
'worker-ready': [unknown];
|
|
10
|
+
};
|
|
11
|
+
export declare function createWorkerServer(options: ViteConfigOptions, mode: 'development' | 'production', neemataConfig: NeemataConfig, events: EventEmitter<WorkerServerEventMap>): Promise<ViteDevServer>;
|
|
@@ -67,6 +67,33 @@ export async function createWorkerServer(options, mode, neemataConfig, events) {
|
|
|
67
67
|
handlers.delete(event);
|
|
68
68
|
},
|
|
69
69
|
};
|
|
70
|
+
let lastError;
|
|
71
|
+
events.on('worker-error', (payload) => {
|
|
72
|
+
lastError = payload?.error ?? payload;
|
|
73
|
+
const error = lastError instanceof Error
|
|
74
|
+
? lastError
|
|
75
|
+
: new Error(String(lastError));
|
|
76
|
+
const message = {
|
|
77
|
+
type: 'error',
|
|
78
|
+
err: {
|
|
79
|
+
message: error.message,
|
|
80
|
+
stack: error.stack ?? '',
|
|
81
|
+
plugin: 'neemata:worker',
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
for (const client of clients.values()) {
|
|
85
|
+
client.send(message);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
events.on('worker-ready', () => {
|
|
89
|
+
if (!lastError)
|
|
90
|
+
return;
|
|
91
|
+
lastError = undefined;
|
|
92
|
+
const message = { type: 'full-reload' };
|
|
93
|
+
for (const client of clients.values()) {
|
|
94
|
+
client.send(message);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
70
97
|
const environment = new DevEnvironment(name, config, {
|
|
71
98
|
hot: mode === 'development',
|
|
72
99
|
transport,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/vite/servers/worker.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAIrC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/vite/servers/worker.ts"],"names":[],"mappings":"AA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EF,MAAM,WAAW,GAAG,IAAI,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE;gBACnD,GAAG,EAAE,IAAI,KAAK,aAAa;gBAC3B,SAAS;aACV,CAAC,CAAA;YAEF,OAAO,WAAW,CAAA;QACpB,CAAC;KACF,CACF,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -27,23 +27,23 @@
|
|
|
27
27
|
"oxc-resolver": "^11.13.2",
|
|
28
28
|
"vite": "8.0.0-beta.2",
|
|
29
29
|
"vite-plugin-static-copy": "3.1.4",
|
|
30
|
-
"@nmtjs/
|
|
31
|
-
"@nmtjs/
|
|
32
|
-
"@nmtjs/
|
|
33
|
-
"@nmtjs/
|
|
34
|
-
"@nmtjs/
|
|
35
|
-
"@nmtjs/protocol": "0.15.0-beta.
|
|
36
|
-
"@nmtjs/
|
|
37
|
-
"@nmtjs/ws-transport": "0.15.0-beta.
|
|
38
|
-
"@nmtjs/
|
|
30
|
+
"@nmtjs/common": "0.15.0-beta.14",
|
|
31
|
+
"@nmtjs/contract": "0.15.0-beta.14",
|
|
32
|
+
"@nmtjs/gateway": "0.15.0-beta.14",
|
|
33
|
+
"@nmtjs/json-format": "0.15.0-beta.14",
|
|
34
|
+
"@nmtjs/core": "0.15.0-beta.14",
|
|
35
|
+
"@nmtjs/protocol": "0.15.0-beta.14",
|
|
36
|
+
"@nmtjs/type": "0.15.0-beta.14",
|
|
37
|
+
"@nmtjs/ws-transport": "0.15.0-beta.14",
|
|
38
|
+
"@nmtjs/http-transport": "0.15.0-beta.14"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"zod": "^4.1.0",
|
|
42
|
-
"@nmtjs/proxy": "0.15.0-beta.
|
|
42
|
+
"@nmtjs/proxy": "0.15.0-beta.14"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"zod": "^4.1.0",
|
|
46
|
-
"@nmtjs/proxy": "0.15.0-beta.
|
|
46
|
+
"@nmtjs/proxy": "0.15.0-beta.14"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
49
49
|
"@nmtjs/proxy": {
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"LICENSE.md",
|
|
57
57
|
"README.md"
|
|
58
58
|
],
|
|
59
|
-
"version": "0.15.0-beta.
|
|
59
|
+
"version": "0.15.0-beta.14",
|
|
60
60
|
"scripts": {
|
|
61
61
|
"clean-build": "rm -rf ./dist",
|
|
62
62
|
"build": "tsc --declaration --sourcemap",
|
package/src/entrypoints/main.ts
CHANGED
|
@@ -2,10 +2,16 @@ import type { Worker } from 'node:worker_threads'
|
|
|
2
2
|
import EventEmitter from 'node:events'
|
|
3
3
|
import { fileURLToPath } from 'node:url'
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
ApplicationWorkerErrorEvent,
|
|
7
|
+
ApplicationWorkerReadyEvent,
|
|
8
|
+
ServerConfig,
|
|
9
|
+
} from 'nmtjs/runtime'
|
|
6
10
|
import type { ViteDevServer } from 'vite'
|
|
7
11
|
import { ApplicationServer, isServerConfig } from 'nmtjs/runtime'
|
|
8
12
|
|
|
13
|
+
import type { WorkerServerEventMap as BaseWorkerServerEventMap } from '../vite/servers/worker.ts'
|
|
14
|
+
|
|
9
15
|
declare global {
|
|
10
16
|
const __VITE_CONFIG__: string
|
|
11
17
|
const __APPLICATIONS_CONFIG__: string
|
|
@@ -27,15 +33,22 @@ const applicationsConfig: Record<
|
|
|
27
33
|
{ type: 'neemata' | 'custom'; specifier: string }
|
|
28
34
|
> = __APPLICATIONS_CONFIG__ ? JSON.parse(__APPLICATIONS_CONFIG__) : {}
|
|
29
35
|
|
|
30
|
-
|
|
36
|
+
type WorkerEventMap = BaseWorkerServerEventMap & {
|
|
37
|
+
'worker-error': [ApplicationWorkerErrorEvent]
|
|
38
|
+
'worker-ready': [ApplicationWorkerReadyEvent]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let _viteServerEvents: EventEmitter<WorkerEventMap> | undefined
|
|
31
42
|
let _viteWorkerServer: ViteDevServer | undefined
|
|
32
43
|
|
|
33
|
-
let server: ApplicationServer
|
|
44
|
+
let server: ApplicationServer | undefined
|
|
45
|
+
let hasActiveWorkerError = false
|
|
46
|
+
const isDev = _vite?.mode === 'development'
|
|
34
47
|
|
|
35
48
|
if (import.meta.env.DEV && import.meta.hot) {
|
|
36
49
|
import.meta.hot.accept('#server', async (module) => {
|
|
37
|
-
await
|
|
38
|
-
await
|
|
50
|
+
await shutdownServer()
|
|
51
|
+
await bootWithHandling(module?.default)
|
|
39
52
|
})
|
|
40
53
|
}
|
|
41
54
|
|
|
@@ -45,7 +58,9 @@ if (_vite) {
|
|
|
45
58
|
/* @vite-ignore */
|
|
46
59
|
_vite.options.configPath
|
|
47
60
|
).then((m) => m.default as import('../config.ts').NeemataConfig)
|
|
48
|
-
_viteServerEvents = new EventEmitter<
|
|
61
|
+
_viteServerEvents = new EventEmitter<WorkerEventMap>()
|
|
62
|
+
_viteServerEvents.on('worker-error', handleWorkerError)
|
|
63
|
+
_viteServerEvents.on('worker-ready', handleWorkerReady)
|
|
49
64
|
_viteWorkerServer = await createWorkerServer(
|
|
50
65
|
_vite.options,
|
|
51
66
|
_vite.mode,
|
|
@@ -54,18 +69,41 @@ if (_vite) {
|
|
|
54
69
|
)
|
|
55
70
|
}
|
|
56
71
|
|
|
57
|
-
async function
|
|
58
|
-
if (!isServerConfig(
|
|
59
|
-
|
|
72
|
+
async function bootServer(configValue: ServerConfig | undefined) {
|
|
73
|
+
if (!isServerConfig(configValue)) throw new InvalidServerConfigError()
|
|
74
|
+
const workerConfig = {
|
|
60
75
|
path: fileURLToPath(import.meta.resolve(`./thread${_ext}`)),
|
|
61
76
|
workerData: { vite: _vite?.mode },
|
|
62
77
|
worker: _viteServerEvents
|
|
63
|
-
? (worker) => {
|
|
78
|
+
? (worker: Worker) => {
|
|
64
79
|
_viteServerEvents.emit('worker', worker)
|
|
65
80
|
}
|
|
66
81
|
: undefined,
|
|
67
|
-
|
|
68
|
-
|
|
82
|
+
events: _viteServerEvents,
|
|
83
|
+
}
|
|
84
|
+
const appServer = new ApplicationServer(
|
|
85
|
+
configValue,
|
|
86
|
+
applicationsConfig,
|
|
87
|
+
workerConfig,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
await appServer.start()
|
|
92
|
+
server = appServer
|
|
93
|
+
clearWorkerErrorOverlay()
|
|
94
|
+
} catch (error) {
|
|
95
|
+
await appServer.stop().catch(() => {})
|
|
96
|
+
throw error
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function bootWithHandling(configValue: ServerConfig | undefined) {
|
|
101
|
+
try {
|
|
102
|
+
await bootServer(configValue)
|
|
103
|
+
} catch (error) {
|
|
104
|
+
handleStartupError(error)
|
|
105
|
+
if (!isDev) throw error
|
|
106
|
+
}
|
|
69
107
|
}
|
|
70
108
|
|
|
71
109
|
let isTerminating = false
|
|
@@ -73,7 +111,7 @@ let isTerminating = false
|
|
|
73
111
|
async function handleTermination() {
|
|
74
112
|
if (isTerminating) return
|
|
75
113
|
isTerminating = true
|
|
76
|
-
await
|
|
114
|
+
await shutdownServer()
|
|
77
115
|
_viteWorkerServer?.close()
|
|
78
116
|
process.exit(0)
|
|
79
117
|
}
|
|
@@ -82,17 +120,66 @@ function handleUnexpectedError(error: Error) {
|
|
|
82
120
|
console.error(new Error('Unexpected Error:', { cause: error }))
|
|
83
121
|
}
|
|
84
122
|
|
|
123
|
+
async function shutdownServer() {
|
|
124
|
+
if (!server) return
|
|
125
|
+
try {
|
|
126
|
+
await server.stop()
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error(
|
|
129
|
+
new Error('Failed to stop application server', { cause: error as Error }),
|
|
130
|
+
)
|
|
131
|
+
} finally {
|
|
132
|
+
server = undefined
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function handleWorkerError(event: ApplicationWorkerErrorEvent) {
|
|
137
|
+
hasActiveWorkerError = true
|
|
138
|
+
console.error(
|
|
139
|
+
new Error(`Worker ${event.application} thread ${event.threadId} error`, {
|
|
140
|
+
cause: event.error,
|
|
141
|
+
}),
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function handleWorkerReady(_: ApplicationWorkerReadyEvent) {
|
|
146
|
+
clearWorkerErrorOverlay()
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function handleStartupError(error: unknown) {
|
|
150
|
+
const normalized = error instanceof Error ? error : new Error(String(error))
|
|
151
|
+
if (_viteServerEvents) {
|
|
152
|
+
_viteServerEvents.emit('worker-error', {
|
|
153
|
+
application: 'server',
|
|
154
|
+
threadId: -1,
|
|
155
|
+
error: normalized,
|
|
156
|
+
} as ApplicationWorkerErrorEvent)
|
|
157
|
+
} else {
|
|
158
|
+
hasActiveWorkerError = true
|
|
159
|
+
console.error(
|
|
160
|
+
new Error('Failed to start application server', { cause: normalized }),
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function clearWorkerErrorOverlay() {
|
|
166
|
+
if (!hasActiveWorkerError) return
|
|
167
|
+
hasActiveWorkerError = false
|
|
168
|
+
}
|
|
169
|
+
|
|
85
170
|
process.once('SIGTERM', handleTermination)
|
|
86
171
|
process.once('SIGINT', handleTermination)
|
|
87
172
|
process.on('uncaughtException', handleUnexpectedError)
|
|
88
173
|
process.on('unhandledRejection', handleUnexpectedError)
|
|
89
174
|
|
|
90
|
-
await
|
|
175
|
+
await bootWithHandling(
|
|
91
176
|
await import(
|
|
92
177
|
// @ts-expect-error
|
|
93
178
|
'#server'
|
|
94
179
|
).then((m) => m.default),
|
|
95
|
-
)
|
|
180
|
+
).catch(() => {
|
|
181
|
+
if (!isDev) process.exit(1)
|
|
182
|
+
})
|
|
96
183
|
|
|
97
184
|
const { format } = Intl.NumberFormat('en', {
|
|
98
185
|
notation: 'compact',
|
|
@@ -108,5 +195,6 @@ const printMem = () => {
|
|
|
108
195
|
`Memory Usage: RSS=${format(memoryUsage.rss)}, HeapTotal=${format(memoryUsage.heapTotal)}, HeapUsed=${format(memoryUsage.heapUsed)}, External=${format(memoryUsage.external)}, ArrayBuffers=${format(memoryUsage.arrayBuffers)}`,
|
|
109
196
|
)
|
|
110
197
|
}
|
|
198
|
+
void printMem
|
|
111
199
|
// printMem()
|
|
112
200
|
// setInterval(printMem, 5000)
|