nmtjs 0.16.1 → 0.17.0-beta.2
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/LICENSE.md +1 -1
- package/README.md +41 -1
- package/dist/index.d.ts +22 -161
- package/dist/index.js +24 -53
- package/dist/index.js.map +1 -1
- package/package.json +11 -63
- package/src/index.ts +71 -91
- package/bin/cli.js +0 -2
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -137
- package/dist/cli.js.map +0 -1
- package/dist/codegen.d.ts +0 -5
- package/dist/codegen.js +0 -18
- package/dist/codegen.js.map +0 -1
- package/dist/config.d.ts +0 -47
- package/dist/config.js +0 -16
- package/dist/config.js.map +0 -1
- package/dist/entrypoints/cli.d.ts +0 -1
- package/dist/entrypoints/cli.js +0 -12
- package/dist/entrypoints/cli.js.map +0 -1
- package/dist/entrypoints/main.d.ts +0 -5
- package/dist/entrypoints/main.js +0 -248
- package/dist/entrypoints/main.js.map +0 -1
- package/dist/entrypoints/thread.d.ts +0 -16
- package/dist/entrypoints/thread.js +0 -182
- package/dist/entrypoints/thread.js.map +0 -1
- package/dist/entrypoints/worker.d.ts +0 -9
- package/dist/entrypoints/worker.js +0 -143
- package/dist/entrypoints/worker.js.map +0 -1
- package/dist/resolver.d.ts +0 -2
- package/dist/resolver.js +0 -7
- package/dist/resolver.js.map +0 -1
- package/dist/runtime/application/index.d.ts +0 -1
- package/dist/runtime/application/index.js +0 -2
- package/dist/runtime/application/index.js.map +0 -1
- package/dist/runtime/constants.d.ts +0 -8
- package/dist/runtime/constants.js +0 -5
- package/dist/runtime/constants.js.map +0 -1
- package/dist/runtime/enums.d.ts +0 -10
- package/dist/runtime/enums.js +0 -13
- package/dist/runtime/enums.js.map +0 -1
- package/dist/runtime/hooks.d.ts +0 -1
- package/dist/runtime/hooks.js +0 -2
- package/dist/runtime/hooks.js.map +0 -1
- package/dist/runtime/index.d.ts +0 -28
- package/dist/runtime/index.js +0 -29
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/injectables.d.ts +0 -69
- package/dist/runtime/injectables.js +0 -40
- package/dist/runtime/injectables.js.map +0 -1
- package/dist/runtime/jobs/job.d.ts +0 -146
- package/dist/runtime/jobs/job.js +0 -89
- package/dist/runtime/jobs/job.js.map +0 -1
- package/dist/runtime/jobs/manager.d.ts +0 -131
- package/dist/runtime/jobs/manager.js +0 -309
- package/dist/runtime/jobs/manager.js.map +0 -1
- package/dist/runtime/jobs/router.d.ts +0 -296
- package/dist/runtime/jobs/router.js +0 -458
- package/dist/runtime/jobs/router.js.map +0 -1
- package/dist/runtime/jobs/runner.d.ts +0 -103
- package/dist/runtime/jobs/runner.js +0 -425
- package/dist/runtime/jobs/runner.js.map +0 -1
- package/dist/runtime/jobs/step.d.ts +0 -26
- package/dist/runtime/jobs/step.js +0 -18
- package/dist/runtime/jobs/step.js.map +0 -1
- package/dist/runtime/jobs/types.d.ts +0 -86
- package/dist/runtime/jobs/types.js +0 -5
- package/dist/runtime/jobs/types.js.map +0 -1
- package/dist/runtime/metrics/metric.d.ts +0 -8
- package/dist/runtime/metrics/metric.js +0 -11
- package/dist/runtime/metrics/metric.js.map +0 -1
- package/dist/runtime/metrics/registry.d.ts +0 -3
- package/dist/runtime/metrics/registry.js +0 -5
- package/dist/runtime/metrics/registry.js.map +0 -1
- package/dist/runtime/metrics/server.d.ts +0 -7
- package/dist/runtime/metrics/server.js +0 -53
- package/dist/runtime/metrics/server.js.map +0 -1
- package/dist/runtime/plugin.d.ts +0 -2
- package/dist/runtime/plugin.js +0 -2
- package/dist/runtime/plugin.js.map +0 -1
- package/dist/runtime/runtime.d.ts +0 -27
- package/dist/runtime/runtime.js +0 -77
- package/dist/runtime/runtime.js.map +0 -1
- package/dist/runtime/scheduler/index.d.ts +0 -22
- package/dist/runtime/scheduler/index.js +0 -20
- package/dist/runtime/scheduler/index.js.map +0 -1
- package/dist/runtime/server/applications.d.ts +0 -91
- package/dist/runtime/server/applications.js +0 -171
- package/dist/runtime/server/applications.js.map +0 -1
- package/dist/runtime/server/config.d.ts +0 -148
- package/dist/runtime/server/config.js +0 -33
- package/dist/runtime/server/config.js.map +0 -1
- package/dist/runtime/server/environment.d.ts +0 -43
- package/dist/runtime/server/environment.js +0 -33
- package/dist/runtime/server/environment.js.map +0 -1
- package/dist/runtime/server/error-policy.d.ts +0 -62
- package/dist/runtime/server/error-policy.js +0 -73
- package/dist/runtime/server/error-policy.js.map +0 -1
- package/dist/runtime/server/hmr-coordinator.d.ts +0 -37
- package/dist/runtime/server/hmr-coordinator.js +0 -94
- package/dist/runtime/server/hmr-coordinator.js.map +0 -1
- package/dist/runtime/server/jobs.d.ts +0 -54
- package/dist/runtime/server/jobs.js +0 -176
- package/dist/runtime/server/jobs.js.map +0 -1
- package/dist/runtime/server/lifecycle.d.ts +0 -85
- package/dist/runtime/server/lifecycle.js +0 -177
- package/dist/runtime/server/lifecycle.js.map +0 -1
- package/dist/runtime/server/managed-worker.d.ts +0 -158
- package/dist/runtime/server/managed-worker.js +0 -420
- package/dist/runtime/server/managed-worker.js.map +0 -1
- package/dist/runtime/server/pool-manager.d.ts +0 -85
- package/dist/runtime/server/pool-manager.js +0 -129
- package/dist/runtime/server/pool-manager.js.map +0 -1
- package/dist/runtime/server/proxy.d.ts +0 -21
- package/dist/runtime/server/proxy.js +0 -76
- package/dist/runtime/server/proxy.js.map +0 -1
- package/dist/runtime/server/server.d.ts +0 -60
- package/dist/runtime/server/server.js +0 -163
- package/dist/runtime/server/server.js.map +0 -1
- package/dist/runtime/server/types.d.ts +0 -31
- package/dist/runtime/server/types.js +0 -2
- package/dist/runtime/server/types.js.map +0 -1
- package/dist/runtime/server/worker-pool.d.ts +0 -121
- package/dist/runtime/server/worker-pool.js +0 -171
- package/dist/runtime/server/worker-pool.js.map +0 -1
- package/dist/runtime/store/index.d.ts +0 -3
- package/dist/runtime/store/index.js +0 -23
- package/dist/runtime/store/index.js.map +0 -1
- package/dist/runtime/subscription/manager.d.ts +0 -49
- package/dist/runtime/subscription/manager.js +0 -170
- package/dist/runtime/subscription/manager.js.map +0 -1
- package/dist/runtime/subscription/redis.d.ts +0 -18
- package/dist/runtime/subscription/redis.js +0 -119
- package/dist/runtime/subscription/redis.js.map +0 -1
- package/dist/runtime/types.d.ts +0 -95
- package/dist/runtime/types.js +0 -2
- package/dist/runtime/types.js.map +0 -1
- package/dist/runtime/workers/application.d.ts +0 -29
- package/dist/runtime/workers/application.js +0 -77
- package/dist/runtime/workers/application.js.map +0 -1
- package/dist/runtime/workers/base.d.ts +0 -14
- package/dist/runtime/workers/base.js +0 -41
- package/dist/runtime/workers/base.js.map +0 -1
- package/dist/runtime/workers/cli.d.ts +0 -1
- package/dist/runtime/workers/cli.js +0 -2
- package/dist/runtime/workers/cli.js.map +0 -1
- package/dist/runtime/workers/job.d.ts +0 -20
- package/dist/runtime/workers/job.js +0 -170
- package/dist/runtime/workers/job.js.map +0 -1
- package/dist/vite/builder.d.ts +0 -5
- package/dist/vite/builder.js +0 -79
- package/dist/vite/builder.js.map +0 -1
- package/dist/vite/config.d.ts +0 -28
- package/dist/vite/config.js +0 -22
- package/dist/vite/config.js.map +0 -1
- package/dist/vite/plugins.d.ts +0 -2
- package/dist/vite/plugins.js +0 -43
- package/dist/vite/plugins.js.map +0 -1
- package/dist/vite/runners/worker.d.ts +0 -3
- package/dist/vite/runners/worker.js +0 -34
- package/dist/vite/runners/worker.js.map +0 -1
- package/dist/vite/server.d.ts +0 -3
- package/dist/vite/server.js +0 -36
- package/dist/vite/server.js.map +0 -1
- package/dist/vite/servers/main.d.ts +0 -8
- package/dist/vite/servers/main.js +0 -24
- package/dist/vite/servers/main.js.map +0 -1
- package/dist/vite/servers/worker.d.ts +0 -13
- package/dist/vite/servers/worker.js +0 -124
- package/dist/vite/servers/worker.js.map +0 -1
- package/src/cli.ts +0 -162
- package/src/codegen.ts +0 -30
- package/src/config.ts +0 -69
- package/src/entrypoints/cli.ts +0 -13
- package/src/entrypoints/main.ts +0 -317
- package/src/entrypoints/thread.ts +0 -223
- package/src/entrypoints/worker.ts +0 -174
- package/src/resolver.ts +0 -7
- package/src/runtime/application/index.ts +0 -1
- package/src/runtime/constants.ts +0 -13
- package/src/runtime/enums.ts +0 -12
- package/src/runtime/hooks.ts +0 -1
- package/src/runtime/index.ts +0 -29
- package/src/runtime/injectables.ts +0 -101
- package/src/runtime/jobs/job.ts +0 -467
- package/src/runtime/jobs/manager.ts +0 -454
- package/src/runtime/jobs/router.ts +0 -967
- package/src/runtime/jobs/runner.ts +0 -583
- package/src/runtime/jobs/step.ts +0 -66
- package/src/runtime/jobs/types.ts +0 -116
- package/src/runtime/metrics/metric.ts +0 -18
- package/src/runtime/metrics/registry.ts +0 -11
- package/src/runtime/metrics/server.ts +0 -69
- package/src/runtime/plugin.ts +0 -2
- package/src/runtime/runtime.ts +0 -103
- package/src/runtime/scheduler/index.ts +0 -39
- package/src/runtime/server/applications.ts +0 -264
- package/src/runtime/server/config.ts +0 -199
- package/src/runtime/server/environment.ts +0 -71
- package/src/runtime/server/error-policy.ts +0 -132
- package/src/runtime/server/hmr-coordinator.ts +0 -116
- package/src/runtime/server/jobs.ts +0 -266
- package/src/runtime/server/lifecycle.ts +0 -234
- package/src/runtime/server/managed-worker.ts +0 -546
- package/src/runtime/server/pool-manager.ts +0 -187
- package/src/runtime/server/proxy.ts +0 -119
- package/src/runtime/server/server.ts +0 -218
- package/src/runtime/server/types.ts +0 -32
- package/src/runtime/server/worker-pool.ts +0 -275
- package/src/runtime/store/index.ts +0 -30
- package/src/runtime/subscription/manager.ts +0 -307
- package/src/runtime/subscription/redis.ts +0 -159
- package/src/runtime/types.ts +0 -84
- package/src/runtime/workers/application.ts +0 -133
- package/src/runtime/workers/base.ts +0 -65
- package/src/runtime/workers/cli.ts +0 -0
- package/src/runtime/workers/job.ts +0 -142
- package/src/vite/builder.ts +0 -94
- package/src/vite/config.ts +0 -45
- package/src/vite/plugins.ts +0 -53
- package/src/vite/runners/worker.ts +0 -55
- package/src/vite/server.ts +0 -55
- package/src/vite/servers/main.ts +0 -41
- package/src/vite/servers/worker.ts +0 -177
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { DevEnvironment, mergeConfig } from 'vite';
|
|
2
|
-
import { createConfig } from '../config.js';
|
|
3
|
-
import { plugins } from '../plugins.js';
|
|
4
|
-
import { createServer } from '../server.js';
|
|
5
|
-
export async function createViteServer(options, mode, neemataConfig, events) {
|
|
6
|
-
const config = createConfig(options);
|
|
7
|
-
const applicationEntries = Object.values(options.applicationImports).map((v) => v.path);
|
|
8
|
-
const _injectHmr = `\n\nif(import.meta.hot) { import.meta.hot.accept((module) => globalThis._hotAccept?.(module)) }`;
|
|
9
|
-
const server = await createServer(options, mergeConfig(neemataConfig.vite, {
|
|
10
|
-
appType: 'custom',
|
|
11
|
-
clearScreen: false,
|
|
12
|
-
resolve: { alias: config.alias, external: ['@nmtjs/proxy'] },
|
|
13
|
-
mode,
|
|
14
|
-
optimizeDeps: { noDiscovery: true },
|
|
15
|
-
plugins: [
|
|
16
|
-
...plugins,
|
|
17
|
-
...(mode === 'development'
|
|
18
|
-
? [
|
|
19
|
-
{
|
|
20
|
-
name: 'neemata-worker-application-hmr',
|
|
21
|
-
transform(code, id, _options) {
|
|
22
|
-
if (applicationEntries.includes(id)) {
|
|
23
|
-
return code + _injectHmr;
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
handleHotUpdate(ctx) {
|
|
27
|
-
// Emit event when application entry files change
|
|
28
|
-
// This allows restarting failed workers after code fixes
|
|
29
|
-
if (ctx.file && applicationEntries.includes(ctx.file)) {
|
|
30
|
-
events.emit('hmr-update', { file: ctx.file });
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
]
|
|
35
|
-
: []),
|
|
36
|
-
],
|
|
37
|
-
}), {
|
|
38
|
-
createEnvironment: async (name, config, context) => {
|
|
39
|
-
const connections = new Map();
|
|
40
|
-
const clients = new Map();
|
|
41
|
-
const handlers = new Map();
|
|
42
|
-
const emit = (event, data, client) => {
|
|
43
|
-
const listeners = handlers.get(event);
|
|
44
|
-
if (!listeners?.size)
|
|
45
|
-
return;
|
|
46
|
-
for (const listener of listeners) {
|
|
47
|
-
;
|
|
48
|
-
listener(data, client);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
events.on('worker', ({ worker, vitePort }) => {
|
|
52
|
-
if (!vitePort)
|
|
53
|
-
return;
|
|
54
|
-
const client = {
|
|
55
|
-
send: (payload) => {
|
|
56
|
-
vitePort.postMessage(payload);
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
const handleMessage = (value) => {
|
|
60
|
-
if (value.type === 'custom') {
|
|
61
|
-
emit(value.event, value.data, client);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
let disconnected = false;
|
|
65
|
-
const disconnect = (closePort) => {
|
|
66
|
-
if (disconnected)
|
|
67
|
-
return;
|
|
68
|
-
disconnected = true;
|
|
69
|
-
emit('vite:client:disconnect', undefined, client);
|
|
70
|
-
vitePort.off('message', handleMessage);
|
|
71
|
-
worker.off('exit', handleWorkerExit);
|
|
72
|
-
vitePort.off('close', handlePortClose);
|
|
73
|
-
if (closePort) {
|
|
74
|
-
vitePort.close();
|
|
75
|
-
}
|
|
76
|
-
connections.delete(worker.threadId);
|
|
77
|
-
clients.delete(worker.threadId);
|
|
78
|
-
};
|
|
79
|
-
const handleWorkerExit = () => disconnect(true);
|
|
80
|
-
const handlePortClose = () => disconnect(false);
|
|
81
|
-
vitePort.on('message', handleMessage);
|
|
82
|
-
worker.once('exit', handleWorkerExit);
|
|
83
|
-
vitePort.once('close', handlePortClose);
|
|
84
|
-
connections.set(worker.threadId, { worker, port: vitePort, client });
|
|
85
|
-
clients.set(worker.threadId, client);
|
|
86
|
-
emit('vite:client:connect', undefined, client);
|
|
87
|
-
});
|
|
88
|
-
const transport = {
|
|
89
|
-
send(data) {
|
|
90
|
-
for (const connection of connections.values()) {
|
|
91
|
-
connection.port.postMessage(data);
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
on(event, handler) {
|
|
95
|
-
let listeners = handlers.get(event);
|
|
96
|
-
if (!listeners) {
|
|
97
|
-
listeners = new Set();
|
|
98
|
-
handlers.set(event, listeners);
|
|
99
|
-
}
|
|
100
|
-
listeners.add(handler);
|
|
101
|
-
},
|
|
102
|
-
off(event, handler) {
|
|
103
|
-
if (!handler) {
|
|
104
|
-
handlers.delete(event);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const listeners = handlers.get(event);
|
|
108
|
-
if (!listeners)
|
|
109
|
-
return;
|
|
110
|
-
listeners.delete(handler);
|
|
111
|
-
if (!listeners.size) {
|
|
112
|
-
handlers.delete(event);
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
return new DevEnvironment(name, config, {
|
|
117
|
-
hot: mode === 'development',
|
|
118
|
-
transport,
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
return server;
|
|
123
|
-
}
|
|
124
|
-
//# sourceMappingURL=worker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/vite/servers/worker.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,MAAM,CAAA;AAKlD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAQ3C,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAA0B,EAC1B,IAAkC,EAClC,aAA4B,EAC5B,MAA0C;IAE1C,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;IACpC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,GAAG,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CAAC,SAAS,EAAE,CAAC;wBACf,SAAS,GAAG,IAAI,GAAG,EAAE,CAAA;wBACrB,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;oBAChC,CAAC;oBACD,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;gBACxB,CAAC;gBACD,GAAG,CAAC,KAAK,EAAE,OAAO;oBAChB,IAAI,CAAC,OAAO,EAAE,CAAC;wBACb,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;wBACtB,OAAM;oBACR,CAAC;oBAED,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;oBACrC,IAAI,CAAC,SAAS;wBAAE,OAAM;oBACtB,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;oBACzB,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;wBACpB,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;oBACxB,CAAC;gBACH,CAAC;aACF,CAAA;YAED,OAAO,IAAI,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE;gBACtC,GAAG,EAAE,IAAI,KAAK,aAAa;gBAC3B,SAAS;aACV,CAAC,CAAA;QACJ,CAAC;KACF,CACF,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/src/cli.ts
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs'
|
|
2
|
-
import { relative, resolve } from 'node:path'
|
|
3
|
-
import process from 'node:process'
|
|
4
|
-
|
|
5
|
-
import type { ArgDef } from 'citty'
|
|
6
|
-
import { defineCommand, runMain } from 'citty'
|
|
7
|
-
import { config as dotenv } from 'dotenv'
|
|
8
|
-
|
|
9
|
-
import type { NeemataConfig } from './config.ts'
|
|
10
|
-
import type { ViteConfigOptions } from './vite/config.ts'
|
|
11
|
-
import { generateTypings } from './codegen.ts'
|
|
12
|
-
import { resolver } from './resolver.ts'
|
|
13
|
-
import { createBuilder } from './vite/builder.ts'
|
|
14
|
-
import { baseViteConfigOptions } from './vite/config.ts'
|
|
15
|
-
import { createMainServer } from './vite/servers/main.ts'
|
|
16
|
-
|
|
17
|
-
const commonArgs = {
|
|
18
|
-
config: {
|
|
19
|
-
type: 'string',
|
|
20
|
-
alias: 'c',
|
|
21
|
-
description: 'Path to Neemata config file',
|
|
22
|
-
required: false,
|
|
23
|
-
},
|
|
24
|
-
} satisfies Record<string, ArgDef>
|
|
25
|
-
|
|
26
|
-
function resolveConfigPath(configPathArg: string | undefined): string {
|
|
27
|
-
if (configPathArg) {
|
|
28
|
-
return resolve(configPathArg)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const tsConfigPath = resolve('./neemata.config.ts')
|
|
32
|
-
if (existsSync(tsConfigPath)) {
|
|
33
|
-
return tsConfigPath
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const jsConfigPath = resolve('./neemata.config.js')
|
|
37
|
-
if (existsSync(jsConfigPath)) {
|
|
38
|
-
return jsConfigPath
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
throw new Error(
|
|
42
|
-
'Failed to resolve Neemata config file. Create neemata.config.ts or neemata.config.js, or pass --config.',
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let config: NeemataConfig
|
|
47
|
-
let viteConfigOptions: ViteConfigOptions
|
|
48
|
-
let applicationImports: Record<
|
|
49
|
-
string,
|
|
50
|
-
{ path: string; specifier: string; type: 'neemata' | 'custom' }
|
|
51
|
-
>
|
|
52
|
-
|
|
53
|
-
async function runPrepare() {
|
|
54
|
-
await generateTypings(applicationImports)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const mainCommand = defineCommand({
|
|
58
|
-
meta: { description: 'Neemata CLI' },
|
|
59
|
-
args: { ...commonArgs },
|
|
60
|
-
async setup(ctx) {
|
|
61
|
-
const configPath = resolveConfigPath(ctx.args.config as string | undefined)
|
|
62
|
-
config = await import(configPath).then((m) => m.default)
|
|
63
|
-
|
|
64
|
-
for (const env of config.env) {
|
|
65
|
-
if (typeof env === 'string') {
|
|
66
|
-
const { error } = dotenv({ path: env })
|
|
67
|
-
if (error) console.warn(error)
|
|
68
|
-
} else if (typeof env === 'object') {
|
|
69
|
-
for (const key in env) {
|
|
70
|
-
process.env[key] = env[key]
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
applicationImports = {}
|
|
76
|
-
const currentPkg = resolver.sync(process.cwd(), './package.json')
|
|
77
|
-
|
|
78
|
-
for (const [appName, application] of Object.entries(config.applications)) {
|
|
79
|
-
const { specifier: appSpecifier, type } = application
|
|
80
|
-
const resolution = resolver.sync(process.cwd(), appSpecifier)
|
|
81
|
-
if (resolution.error)
|
|
82
|
-
throw new Error(
|
|
83
|
-
`Failed to resolve application path for ${appName}: ${resolution.error}`,
|
|
84
|
-
)
|
|
85
|
-
if (!resolution.path)
|
|
86
|
-
throw new Error(
|
|
87
|
-
`Failed to resolve application path for ${appName}: no path found`,
|
|
88
|
-
)
|
|
89
|
-
const specifier =
|
|
90
|
-
resolution.packageJsonPath === currentPkg.path
|
|
91
|
-
? relative(resolve('.neemata'), resolution.path)
|
|
92
|
-
: appSpecifier
|
|
93
|
-
applicationImports[appName] = { path: resolution.path, specifier, type }
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
viteConfigOptions = {
|
|
97
|
-
applicationImports,
|
|
98
|
-
serverEntryPath: resolve(config.serverPath),
|
|
99
|
-
...baseViteConfigOptions,
|
|
100
|
-
configPath,
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
subCommands: {
|
|
104
|
-
prepare: defineCommand({
|
|
105
|
-
async run(ctx) {
|
|
106
|
-
await runPrepare()
|
|
107
|
-
},
|
|
108
|
-
}),
|
|
109
|
-
dev: defineCommand({
|
|
110
|
-
async run(ctx) {
|
|
111
|
-
await runPrepare()
|
|
112
|
-
const { runner } = await createMainServer(
|
|
113
|
-
viteConfigOptions,
|
|
114
|
-
'development',
|
|
115
|
-
config,
|
|
116
|
-
)
|
|
117
|
-
await runner.import(viteConfigOptions.entrypointMainPath)
|
|
118
|
-
},
|
|
119
|
-
}),
|
|
120
|
-
preview: defineCommand({
|
|
121
|
-
async run(ctx) {
|
|
122
|
-
await runPrepare()
|
|
123
|
-
const { runner } = await createMainServer(
|
|
124
|
-
viteConfigOptions,
|
|
125
|
-
'production',
|
|
126
|
-
config,
|
|
127
|
-
)
|
|
128
|
-
await runner.import(viteConfigOptions.entrypointMainPath)
|
|
129
|
-
},
|
|
130
|
-
}),
|
|
131
|
-
build: defineCommand({
|
|
132
|
-
async run(ctx) {
|
|
133
|
-
await runPrepare()
|
|
134
|
-
const builder = await createBuilder(viteConfigOptions, config)
|
|
135
|
-
await builder.build()
|
|
136
|
-
},
|
|
137
|
-
}),
|
|
138
|
-
// command: defineCommand({
|
|
139
|
-
// async run(ctx) {
|
|
140
|
-
// const runner = await createRunner(
|
|
141
|
-
// viteConfigOptions,
|
|
142
|
-
// 'production',
|
|
143
|
-
// config,
|
|
144
|
-
// )
|
|
145
|
-
// const workerModule = await runner.import<
|
|
146
|
-
// typeof import('./entrypoints/worker.ts')
|
|
147
|
-
// >(import.meta.resolve('./entrypoints/worker.js'))
|
|
148
|
-
// const commandModule = await runner.import<
|
|
149
|
-
// typeof import('./command.ts')
|
|
150
|
-
// >(import.meta.resolve('./command.js'))
|
|
151
|
-
// const worker = await workerModule.default({
|
|
152
|
-
// applicationWorkerData: undefined,
|
|
153
|
-
// type: ApplicationType.Command,
|
|
154
|
-
// workerType: ApplicationWorkerType.Command,
|
|
155
|
-
// })
|
|
156
|
-
// await runMain(commandModule.default(worker), { rawArgs: ctx.rawArgs })
|
|
157
|
-
// },
|
|
158
|
-
// }),
|
|
159
|
-
},
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
runMain(mainCommand)
|
package/src/codegen.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { mkdir, writeFile } from 'node:fs/promises'
|
|
2
|
-
import { resolve } from 'node:path'
|
|
3
|
-
|
|
4
|
-
import dedent from 'dedent'
|
|
5
|
-
|
|
6
|
-
export async function generateTypings(
|
|
7
|
-
applicationImports: Record<
|
|
8
|
-
string,
|
|
9
|
-
{ path: string; specifier: string; type: 'neemata' | 'custom' }
|
|
10
|
-
>,
|
|
11
|
-
) {
|
|
12
|
-
await mkdir('.neemata', { recursive: true }).catch(() => {})
|
|
13
|
-
await writeFile(
|
|
14
|
-
resolve('.neemata', 'types.d.ts'),
|
|
15
|
-
dedent`
|
|
16
|
-
/// <reference types="nmtjs/runtime/types" />
|
|
17
|
-
|
|
18
|
-
declare module 'nmtjs/runtime/types' {
|
|
19
|
-
interface Applications {
|
|
20
|
-
${Object.entries(applicationImports)
|
|
21
|
-
.map(
|
|
22
|
-
([appName, { specifier, type }]) =>
|
|
23
|
-
`'${appName}': { type: '${type}'; definition: typeof import('${specifier}').default }`,
|
|
24
|
-
)
|
|
25
|
-
.join('\n')}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
`,
|
|
29
|
-
)
|
|
30
|
-
}
|
package/src/config.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'node:path'
|
|
2
|
-
|
|
3
|
-
import type { UserConfig } from 'vite'
|
|
4
|
-
import { mergeConfig } from 'vite'
|
|
5
|
-
|
|
6
|
-
export type ExternalDependency = string | RegExp
|
|
7
|
-
|
|
8
|
-
type DeepPartial<T> = {
|
|
9
|
-
[P in keyof T]?: T[P] extends Record<any, unknown> ? DeepPartial<T[P]> : T[P]
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface NeemataConfig {
|
|
13
|
-
/**
|
|
14
|
-
* Path to application entry point
|
|
15
|
-
*/
|
|
16
|
-
applications: {
|
|
17
|
-
/**
|
|
18
|
-
* Application name
|
|
19
|
-
*/
|
|
20
|
-
[appName: string]: { type: 'neemata' | 'custom'; specifier: string }
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Path to server entry point
|
|
24
|
-
*/
|
|
25
|
-
serverPath: string
|
|
26
|
-
/**
|
|
27
|
-
* External dependencies to exclude from application bundle
|
|
28
|
-
*
|
|
29
|
-
* 'prod' - exclude production dependencies from package.json
|
|
30
|
-
*
|
|
31
|
-
* 'all' - exclude all dependencies from package.json
|
|
32
|
-
*
|
|
33
|
-
* ExternalDependency[] - array of package names or regular expressions to match package names
|
|
34
|
-
*/
|
|
35
|
-
externalDependencies: 'prod' | 'all' | ExternalDependency[]
|
|
36
|
-
/**
|
|
37
|
-
* Timeout in milliseconds for graceful shutdown of application workers
|
|
38
|
-
*/
|
|
39
|
-
timeout: number
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Environment variables to set for application workers
|
|
43
|
-
*
|
|
44
|
-
* Strings are paths to .env files
|
|
45
|
-
* Records are key-value pairs to set directly
|
|
46
|
-
*/
|
|
47
|
-
env: (Record<string, string> | string)[]
|
|
48
|
-
|
|
49
|
-
vite: UserConfig
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function defineConfig(
|
|
53
|
-
config: DeepPartial<NeemataConfig> = {},
|
|
54
|
-
): NeemataConfig {
|
|
55
|
-
return {
|
|
56
|
-
serverPath: './src/server.ts',
|
|
57
|
-
externalDependencies: 'prod',
|
|
58
|
-
timeout: 10000,
|
|
59
|
-
env: [],
|
|
60
|
-
plugins: [],
|
|
61
|
-
...config,
|
|
62
|
-
// @ts-expect-error
|
|
63
|
-
applications: config.applications || {},
|
|
64
|
-
vite: mergeConfig(
|
|
65
|
-
{ build: { outDir: resolve('./dist'), minify: true } },
|
|
66
|
-
config.vite || {},
|
|
67
|
-
),
|
|
68
|
-
}
|
|
69
|
-
}
|
package/src/entrypoints/cli.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// // import { ApplicationType, ApplicationWorkerType } from '@nmtjs/application'
|
|
2
|
-
// import { runMain } from 'citty'
|
|
3
|
-
|
|
4
|
-
// import command from '../command.ts'
|
|
5
|
-
// import createWorker from './worker.ts'
|
|
6
|
-
|
|
7
|
-
// const worker = await createWorker({
|
|
8
|
-
// applicationWorkerData: undefined,
|
|
9
|
-
// // type: ApplicationType.Command,
|
|
10
|
-
// // workerType: ApplicationWorkerType.Command,
|
|
11
|
-
// })
|
|
12
|
-
|
|
13
|
-
// runMain(command(worker))
|