neex 0.2.7 → 0.2.9
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/README.md +3 -1
- package/bun.lock +118 -518
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +199 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/build.d.ts +3 -0
- package/dist/commands/build.js +41 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/cache.d.ts +3 -0
- package/dist/commands/cache.js +34 -0
- package/dist/commands/cache.js.map +1 -0
- package/dist/commands/dev.d.ts +3 -0
- package/dist/commands/dev.js +51 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/process.d.ts +2 -0
- package/dist/commands/process.js +216 -0
- package/dist/commands/process.js.map +1 -0
- package/dist/commands/run.d.ts +2 -0
- package/dist/commands/run.js +81 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/start.d.ts +3 -0
- package/dist/commands/start.js +45 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/dev-manager.d.ts +34 -0
- package/dist/dev-manager.js +172 -0
- package/dist/dev-manager.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +31 -0
- package/dist/logger.js +238 -0
- package/dist/logger.js.map +1 -0
- package/dist/process-manager.d.ts +51 -0
- package/dist/process-manager.js +258 -0
- package/dist/process-manager.js.map +1 -0
- package/dist/project-manager.d.ts +50 -0
- package/dist/project-manager.js +241 -0
- package/dist/project-manager.js.map +1 -0
- package/dist/runner.d.ts +16 -0
- package/dist/runner.js +331 -0
- package/dist/runner.js.map +1 -0
- package/dist/src/cli.js +186 -157
- package/dist/src/process-manager.js +110 -60
- package/dist/types.d.ts +37 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/typescript-runner.d.ts +12 -0
- package/dist/typescript-runner.js +161 -0
- package/dist/typescript-runner.js.map +1 -0
- package/package.json +7 -2
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.processManager = void 0;
|
|
4
7
|
const child_process_1 = require("child_process");
|
|
5
8
|
const chokidar_1 = require("chokidar");
|
|
6
9
|
const fs_1 = require("fs");
|
|
7
10
|
const path_1 = require("path");
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
12
|
const events_1 = require("events");
|
|
13
|
+
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
14
|
+
const child_process_2 = require("child_process");
|
|
9
15
|
class ProcessManager extends events_1.EventEmitter {
|
|
10
16
|
constructor() {
|
|
11
17
|
super();
|
|
12
18
|
this.processes = new Map();
|
|
13
19
|
this.watchers = new Map();
|
|
14
20
|
this.defaultMaxRestarts = 5;
|
|
15
|
-
this.defaultRestartDelay = 1000;
|
|
21
|
+
this.defaultRestartDelay = 1000;
|
|
16
22
|
this.logDir = (0, path_1.resolve)(process.cwd(), '.neex-logs');
|
|
17
23
|
this.configFile = (0, path_1.resolve)(process.cwd(), '.neex-config.json');
|
|
18
24
|
this.initialize();
|
|
@@ -33,27 +39,26 @@ class ProcessManager extends events_1.EventEmitter {
|
|
|
33
39
|
const config = Object.fromEntries(this.processes);
|
|
34
40
|
(0, fs_1.writeFileSync)(this.configFile, JSON.stringify(config, null, 2));
|
|
35
41
|
}
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
generateName(command) {
|
|
43
|
+
const baseName = command.split(' ')[0].replace(/[^a-zA-Z0-9]/g, '');
|
|
44
|
+
const timestamp = Date.now().toString(36);
|
|
45
|
+
return `${baseName}-${timestamp}`;
|
|
38
46
|
}
|
|
39
|
-
getLogPath(
|
|
40
|
-
return (0, path_1.join)(this.logDir, `${
|
|
47
|
+
getLogPath(name) {
|
|
48
|
+
return (0, path_1.join)(this.logDir, `${name}.log`);
|
|
41
49
|
}
|
|
42
|
-
async startx(
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
throw new Error(`Path ${path} does not exist`);
|
|
50
|
+
async startx(command, options = {}) {
|
|
51
|
+
const name = options.name || this.generateName(command);
|
|
52
|
+
const cwd = options.cwd || process.cwd();
|
|
53
|
+
if (this.processes.has(name)) {
|
|
54
|
+
throw new Error(`Process with name ${name} already exists`);
|
|
48
55
|
}
|
|
49
56
|
const processInfo = {
|
|
50
|
-
id,
|
|
51
57
|
name,
|
|
52
58
|
pid: 0,
|
|
53
59
|
status: 'stopped',
|
|
54
60
|
startTime: Date.now(),
|
|
55
|
-
|
|
56
|
-
command: `node ${fullPath}`,
|
|
61
|
+
command,
|
|
57
62
|
logs: [],
|
|
58
63
|
memory: 0,
|
|
59
64
|
cpu: 0,
|
|
@@ -61,7 +66,8 @@ class ProcessManager extends events_1.EventEmitter {
|
|
|
61
66
|
restarts: 0,
|
|
62
67
|
maxRestarts: options.maxRestarts || this.defaultMaxRestarts,
|
|
63
68
|
restartDelay: options.restartDelay || this.defaultRestartDelay,
|
|
64
|
-
watch: options.watch
|
|
69
|
+
watch: options.watch,
|
|
70
|
+
cwd
|
|
65
71
|
};
|
|
66
72
|
try {
|
|
67
73
|
await this.startProcess(processInfo);
|
|
@@ -70,56 +76,60 @@ class ProcessManager extends events_1.EventEmitter {
|
|
|
70
76
|
catch (error) {
|
|
71
77
|
processInfo.status = 'error';
|
|
72
78
|
processInfo.lastError = error.message;
|
|
73
|
-
this.processes.set(
|
|
79
|
+
this.processes.set(name, processInfo);
|
|
74
80
|
this.saveConfig();
|
|
75
81
|
throw error;
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
async startProcess(processInfo) {
|
|
79
85
|
var _a, _b;
|
|
80
|
-
const
|
|
86
|
+
const [cmd, ...args] = processInfo.command.split(' ');
|
|
87
|
+
const child = (0, child_process_1.spawn)(cmd, args, {
|
|
81
88
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
82
|
-
env: { ...process.env, NODE_ENV: 'production' }
|
|
89
|
+
env: { ...process.env, NODE_ENV: 'production' },
|
|
90
|
+
cwd: processInfo.cwd,
|
|
91
|
+
shell: true
|
|
83
92
|
});
|
|
84
93
|
processInfo.pid = child.pid || 0;
|
|
85
94
|
processInfo.status = 'running';
|
|
86
95
|
processInfo.startTime = Date.now();
|
|
87
96
|
// Setup logging
|
|
88
|
-
|
|
97
|
+
(0, fs_1.writeFileSync)(this.getLogPath(processInfo.name), '', { flag: 'a' });
|
|
89
98
|
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
90
99
|
const log = data.toString();
|
|
91
100
|
processInfo.logs.push(log);
|
|
92
|
-
(0, fs_1.writeFileSync)(this.getLogPath(processInfo.
|
|
93
|
-
this.emit('log', {
|
|
101
|
+
(0, fs_1.writeFileSync)(this.getLogPath(processInfo.name), log, { flag: 'a' });
|
|
102
|
+
this.emit('log', { name: processInfo.name, log });
|
|
94
103
|
});
|
|
95
104
|
(_b = child.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
96
105
|
const log = data.toString();
|
|
97
106
|
processInfo.logs.push(log);
|
|
98
|
-
(0, fs_1.writeFileSync)(this.getLogPath(processInfo.
|
|
99
|
-
this.emit('error', {
|
|
107
|
+
(0, fs_1.writeFileSync)(this.getLogPath(processInfo.name), log, { flag: 'a' });
|
|
108
|
+
this.emit('error', { name: processInfo.name, log });
|
|
100
109
|
});
|
|
101
110
|
// Setup monitoring
|
|
102
|
-
if (processInfo.watch) {
|
|
103
|
-
const watcher = (0, chokidar_1.watch)(processInfo.
|
|
111
|
+
if (processInfo.watch && processInfo.cwd) {
|
|
112
|
+
const watcher = (0, chokidar_1.watch)(processInfo.cwd, {
|
|
104
113
|
ignored: /(^|[\/\\])\../,
|
|
105
114
|
persistent: true
|
|
106
115
|
});
|
|
107
116
|
watcher.on('change', () => {
|
|
108
|
-
this.restart(processInfo.
|
|
117
|
+
this.restart(processInfo.name);
|
|
109
118
|
});
|
|
110
|
-
this.watchers.set(processInfo.
|
|
119
|
+
this.watchers.set(processInfo.name, watcher);
|
|
111
120
|
}
|
|
112
121
|
// Monitor process
|
|
113
122
|
const monitorInterval = setInterval(() => {
|
|
114
123
|
if (child.pid) {
|
|
115
124
|
try {
|
|
116
|
-
const stats =
|
|
117
|
-
processInfo.memory = stats.
|
|
125
|
+
const stats = this.getProcessStats(child.pid);
|
|
126
|
+
processInfo.memory = stats.memory;
|
|
127
|
+
processInfo.cpu = stats.cpu;
|
|
118
128
|
processInfo.uptime = (Date.now() - processInfo.startTime) / 1000;
|
|
119
|
-
this.emit('stats', {
|
|
129
|
+
this.emit('stats', { name: processInfo.name, stats: processInfo });
|
|
120
130
|
}
|
|
121
131
|
catch (error) {
|
|
122
|
-
console.error(`Error monitoring process ${processInfo.
|
|
132
|
+
console.error(`Error monitoring process ${processInfo.name}:`, error);
|
|
123
133
|
}
|
|
124
134
|
}
|
|
125
135
|
}, 1000);
|
|
@@ -128,17 +138,16 @@ class ProcessManager extends events_1.EventEmitter {
|
|
|
128
138
|
if (code !== 0) {
|
|
129
139
|
processInfo.status = 'error';
|
|
130
140
|
processInfo.lastError = `Process exited with code ${code}`;
|
|
131
|
-
this.emit('error', {
|
|
132
|
-
// Auto-restart logic
|
|
141
|
+
this.emit('error', { name: processInfo.name, code });
|
|
133
142
|
if (processInfo.restarts < processInfo.maxRestarts) {
|
|
134
143
|
processInfo.status = 'restarting';
|
|
135
|
-
this.emit('restart', {
|
|
144
|
+
this.emit('restart', { name: processInfo.name, attempt: processInfo.restarts + 1 });
|
|
136
145
|
await new Promise(resolve => setTimeout(resolve, processInfo.restartDelay));
|
|
137
146
|
processInfo.restarts++;
|
|
138
147
|
await this.startProcess(processInfo);
|
|
139
148
|
}
|
|
140
149
|
else {
|
|
141
|
-
this.emit('max-restarts', {
|
|
150
|
+
this.emit('max-restarts', { name: processInfo.name, maxRestarts: processInfo.maxRestarts });
|
|
142
151
|
}
|
|
143
152
|
}
|
|
144
153
|
else {
|
|
@@ -146,63 +155,104 @@ class ProcessManager extends events_1.EventEmitter {
|
|
|
146
155
|
}
|
|
147
156
|
this.saveConfig();
|
|
148
157
|
});
|
|
149
|
-
this.processes.set(processInfo.
|
|
158
|
+
this.processes.set(processInfo.name, processInfo);
|
|
150
159
|
this.saveConfig();
|
|
151
|
-
this.emit('start', {
|
|
160
|
+
this.emit('start', { name: processInfo.name, processInfo });
|
|
152
161
|
}
|
|
153
|
-
|
|
154
|
-
|
|
162
|
+
getProcessStats(pid) {
|
|
163
|
+
try {
|
|
164
|
+
const stats = (0, child_process_2.execSync)(`ps -p ${pid} -o %mem,%cpu`).toString().split('\n')[1].trim().split(/\s+/);
|
|
165
|
+
return {
|
|
166
|
+
memory: parseFloat(stats[0]),
|
|
167
|
+
cpu: parseFloat(stats[1])
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
catch (_a) {
|
|
171
|
+
return { memory: 0, cpu: 0 };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async stopx(name) {
|
|
175
|
+
const processInfo = this.processes.get(name);
|
|
155
176
|
if (!processInfo) {
|
|
156
|
-
throw new Error(`Process ${
|
|
177
|
+
throw new Error(`Process ${name} not found`);
|
|
157
178
|
}
|
|
158
179
|
try {
|
|
159
180
|
process.kill(processInfo.pid);
|
|
160
|
-
const watcher = this.watchers.get(
|
|
181
|
+
const watcher = this.watchers.get(name);
|
|
161
182
|
if (watcher) {
|
|
162
183
|
watcher.close();
|
|
163
|
-
this.watchers.delete(
|
|
184
|
+
this.watchers.delete(name);
|
|
164
185
|
}
|
|
165
|
-
this.processes.delete(
|
|
186
|
+
this.processes.delete(name);
|
|
166
187
|
this.saveConfig();
|
|
167
|
-
this.emit('stop', {
|
|
188
|
+
this.emit('stop', { name });
|
|
168
189
|
}
|
|
169
190
|
catch (error) {
|
|
170
|
-
throw new Error(`Failed to stop process ${
|
|
191
|
+
throw new Error(`Failed to stop process ${name}: ${error.message}`);
|
|
171
192
|
}
|
|
172
193
|
}
|
|
173
194
|
list() {
|
|
174
|
-
|
|
195
|
+
const table = new cli_table3_1.default({
|
|
196
|
+
head: ['Name', 'Status', 'PID', 'Memory', 'CPU', 'Uptime', 'Restarts'],
|
|
197
|
+
style: { head: ['cyan'] }
|
|
198
|
+
});
|
|
199
|
+
Array.from(this.processes.values()).forEach(process => {
|
|
200
|
+
const statusColor = process.status === 'running' ? 'green' :
|
|
201
|
+
process.status === 'error' ? 'red' :
|
|
202
|
+
process.status === 'restarting' ? 'yellow' : 'gray';
|
|
203
|
+
table.push([
|
|
204
|
+
process.name,
|
|
205
|
+
chalk_1.default[statusColor](process.status),
|
|
206
|
+
process.pid || '-',
|
|
207
|
+
`${process.memory.toFixed(2)}MB`,
|
|
208
|
+
`${process.cpu.toFixed(1)}%`,
|
|
209
|
+
`${Math.floor(process.uptime)}s`,
|
|
210
|
+
`${process.restarts}/${process.maxRestarts}`
|
|
211
|
+
]);
|
|
212
|
+
});
|
|
213
|
+
return table.toString();
|
|
175
214
|
}
|
|
176
|
-
monit(
|
|
177
|
-
const processInfo = this.processes.get(
|
|
215
|
+
monit(name) {
|
|
216
|
+
const processInfo = this.processes.get(name);
|
|
178
217
|
if (!processInfo) {
|
|
179
|
-
throw new Error(`Process ${
|
|
218
|
+
throw new Error(`Process ${name} not found`);
|
|
219
|
+
}
|
|
220
|
+
const table = new cli_table3_1.default({
|
|
221
|
+
style: { head: ['cyan'] }
|
|
222
|
+
});
|
|
223
|
+
table.push(['Name', processInfo.name], ['Status', chalk_1.default[processInfo.status === 'running' ? 'green' : 'red'](processInfo.status)], ['PID', processInfo.pid.toString()], ['Memory', `${processInfo.memory.toFixed(2)}MB`], ['CPU', `${processInfo.cpu.toFixed(1)}%`], ['Uptime', `${Math.floor(processInfo.uptime)}s`], ['Restarts', `${processInfo.restarts}/${processInfo.maxRestarts}`]);
|
|
224
|
+
if (processInfo.lastError) {
|
|
225
|
+
table.push(['Last Error', chalk_1.default.red(processInfo.lastError)]);
|
|
180
226
|
}
|
|
181
227
|
return {
|
|
182
|
-
|
|
183
|
-
logs: processInfo.logs.slice(-100)
|
|
228
|
+
table: table.toString(),
|
|
229
|
+
logs: processInfo.logs.slice(-100)
|
|
184
230
|
};
|
|
185
231
|
}
|
|
186
|
-
log(
|
|
187
|
-
const processInfo = this.processes.get(
|
|
232
|
+
log(name, lines = 100) {
|
|
233
|
+
const processInfo = this.processes.get(name);
|
|
188
234
|
if (!processInfo) {
|
|
189
|
-
throw new Error(`Process ${
|
|
235
|
+
throw new Error(`Process ${name} not found`);
|
|
190
236
|
}
|
|
191
|
-
const logPath = this.getLogPath(
|
|
237
|
+
const logPath = this.getLogPath(name);
|
|
192
238
|
if (!(0, fs_1.existsSync)(logPath)) {
|
|
193
239
|
return [];
|
|
194
240
|
}
|
|
195
241
|
const logs = (0, fs_1.readFileSync)(logPath, 'utf-8').split('\n');
|
|
196
242
|
return logs.slice(-lines);
|
|
197
243
|
}
|
|
198
|
-
async restart(
|
|
199
|
-
const processInfo = this.processes.get(
|
|
244
|
+
async restart(name) {
|
|
245
|
+
const processInfo = this.processes.get(name);
|
|
200
246
|
if (!processInfo) {
|
|
201
|
-
throw new Error(`Process ${
|
|
247
|
+
throw new Error(`Process ${name} not found`);
|
|
202
248
|
}
|
|
203
|
-
await this.stopx(
|
|
249
|
+
await this.stopx(name);
|
|
204
250
|
processInfo.restarts++;
|
|
205
|
-
await this.startx(processInfo.
|
|
251
|
+
await this.startx(processInfo.command, {
|
|
252
|
+
name: processInfo.name,
|
|
253
|
+
watch: true,
|
|
254
|
+
cwd: processInfo.cwd
|
|
255
|
+
});
|
|
206
256
|
}
|
|
207
257
|
}
|
|
208
258
|
exports.processManager = new ProcessManager();
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface RunOptions {
|
|
2
|
+
parallel: boolean;
|
|
3
|
+
maxParallel?: number;
|
|
4
|
+
printOutput: boolean;
|
|
5
|
+
color: boolean;
|
|
6
|
+
showTiming: boolean;
|
|
7
|
+
prefix: boolean;
|
|
8
|
+
stopOnError: boolean;
|
|
9
|
+
minimalOutput: boolean;
|
|
10
|
+
groupOutput: boolean;
|
|
11
|
+
isServerMode: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface RunResult {
|
|
14
|
+
command: string;
|
|
15
|
+
success: boolean;
|
|
16
|
+
code: number | null;
|
|
17
|
+
startTime: Date;
|
|
18
|
+
endTime: Date | null;
|
|
19
|
+
duration?: number;
|
|
20
|
+
error?: Error;
|
|
21
|
+
output?: CommandOutput[];
|
|
22
|
+
}
|
|
23
|
+
export interface CommandOutput {
|
|
24
|
+
command: string;
|
|
25
|
+
type: 'stdout' | 'stderr';
|
|
26
|
+
data: string;
|
|
27
|
+
timestamp: Date;
|
|
28
|
+
}
|
|
29
|
+
export interface ServerInfo {
|
|
30
|
+
name: string;
|
|
31
|
+
url?: string;
|
|
32
|
+
status: 'starting' | 'running' | 'error' | 'stopped';
|
|
33
|
+
pid?: number;
|
|
34
|
+
port?: number;
|
|
35
|
+
startTime?: Date;
|
|
36
|
+
}
|
|
37
|
+
export type LogLevel = 'info' | 'warn' | 'error' | 'debug' | 'success';
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class FastTypeScriptRunner {
|
|
2
|
+
private cache;
|
|
3
|
+
private compiler;
|
|
4
|
+
private tempDir;
|
|
5
|
+
constructor();
|
|
6
|
+
private detectBestCompiler;
|
|
7
|
+
compile(filePath: string): Promise<string>;
|
|
8
|
+
private compileWithSWC;
|
|
9
|
+
private compileWithESBuild;
|
|
10
|
+
private compileWithTSC;
|
|
11
|
+
clearCache(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FastTypeScriptRunner = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const figures_1 = __importDefault(require("figures"));
|
|
12
|
+
const crypto_1 = require("crypto");
|
|
13
|
+
const util_1 = require("util");
|
|
14
|
+
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
15
|
+
// TypeScript Cache Manager for faster transpilation
|
|
16
|
+
class TypeScriptCache {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.enabled = true;
|
|
19
|
+
this.cacheDir = (0, path_1.join)(process.cwd(), '.neex', 'cache');
|
|
20
|
+
if (!(0, fs_1.existsSync)(this.cacheDir)) {
|
|
21
|
+
(0, fs_1.mkdirSync)(this.cacheDir, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
getFileHash(filePath) {
|
|
25
|
+
try {
|
|
26
|
+
const content = (0, fs_1.readFileSync)(filePath, 'utf8');
|
|
27
|
+
return (0, crypto_1.createHash)('md5').update(content).digest('hex');
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
getCachePath(filePath) {
|
|
34
|
+
const hash = this.getFileHash(filePath);
|
|
35
|
+
const fileName = `${hash}.js`;
|
|
36
|
+
return (0, path_1.join)(this.cacheDir, fileName);
|
|
37
|
+
}
|
|
38
|
+
isCached(filePath) {
|
|
39
|
+
if (!this.enabled)
|
|
40
|
+
return false;
|
|
41
|
+
const cachePath = this.getCachePath(filePath);
|
|
42
|
+
return (0, fs_1.existsSync)(cachePath);
|
|
43
|
+
}
|
|
44
|
+
getCachedFile(filePath) {
|
|
45
|
+
if (!this.isCached(filePath))
|
|
46
|
+
return null;
|
|
47
|
+
return this.getCachePath(filePath);
|
|
48
|
+
}
|
|
49
|
+
cacheFile(originalPath, compiledPath) {
|
|
50
|
+
if (!this.enabled)
|
|
51
|
+
return;
|
|
52
|
+
try {
|
|
53
|
+
const cachePath = this.getCachePath(originalPath);
|
|
54
|
+
const compiledContent = (0, fs_1.readFileSync)(compiledPath, 'utf8');
|
|
55
|
+
(0, fs_1.writeFileSync)(cachePath, compiledContent);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.warn(chalk_1.default.yellow(`Warning: Failed to cache ${originalPath}`));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
clear() {
|
|
62
|
+
try {
|
|
63
|
+
(0, child_process_1.exec)(`rm -rf ${this.cacheDir}`);
|
|
64
|
+
(0, fs_1.mkdirSync)(this.cacheDir, { recursive: true });
|
|
65
|
+
console.log(chalk_1.default.green(`${figures_1.default.tick} Cache cleared successfully`));
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error(chalk_1.default.red(`${figures_1.default.cross} Failed to clear cache`));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class FastTypeScriptRunner {
|
|
73
|
+
constructor() {
|
|
74
|
+
this.cache = new TypeScriptCache();
|
|
75
|
+
this.tempDir = (0, path_1.join)(process.cwd(), '.neex', 'temp');
|
|
76
|
+
if (!(0, fs_1.existsSync)(this.tempDir)) {
|
|
77
|
+
(0, fs_1.mkdirSync)(this.tempDir, { recursive: true });
|
|
78
|
+
}
|
|
79
|
+
this.compiler = this.detectBestCompiler();
|
|
80
|
+
}
|
|
81
|
+
detectBestCompiler() {
|
|
82
|
+
try {
|
|
83
|
+
require.resolve('@swc/core');
|
|
84
|
+
return 'swc';
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
try {
|
|
88
|
+
require.resolve('esbuild');
|
|
89
|
+
return 'esbuild';
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return 'tsc';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async compile(filePath) {
|
|
97
|
+
const cachedFile = this.cache.getCachedFile(filePath);
|
|
98
|
+
if (cachedFile) {
|
|
99
|
+
return cachedFile;
|
|
100
|
+
}
|
|
101
|
+
const outputPath = (0, path_1.join)(this.tempDir, `${Date.now()}.js`);
|
|
102
|
+
try {
|
|
103
|
+
switch (this.compiler) {
|
|
104
|
+
case 'swc':
|
|
105
|
+
await this.compileWithSWC(filePath, outputPath);
|
|
106
|
+
break;
|
|
107
|
+
case 'esbuild':
|
|
108
|
+
await this.compileWithESBuild(filePath, outputPath);
|
|
109
|
+
break;
|
|
110
|
+
default:
|
|
111
|
+
await this.compileWithTSC(filePath, outputPath);
|
|
112
|
+
}
|
|
113
|
+
this.cache.cacheFile(filePath, outputPath);
|
|
114
|
+
return outputPath;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
throw new Error(`Compilation failed: ${error}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async compileWithSWC(input, output) {
|
|
121
|
+
const swc = require('@swc/core');
|
|
122
|
+
const result = await swc.transformFile(input, {
|
|
123
|
+
jsc: {
|
|
124
|
+
parser: {
|
|
125
|
+
syntax: 'typescript',
|
|
126
|
+
tsx: false,
|
|
127
|
+
decorators: true,
|
|
128
|
+
},
|
|
129
|
+
target: 'es2022',
|
|
130
|
+
transform: {
|
|
131
|
+
legacyDecorator: true,
|
|
132
|
+
decoratorMetadata: true,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
module: {
|
|
136
|
+
type: 'commonjs',
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
(0, fs_1.writeFileSync)(output, result.code);
|
|
140
|
+
}
|
|
141
|
+
async compileWithESBuild(input, output) {
|
|
142
|
+
const esbuild = require('esbuild');
|
|
143
|
+
await esbuild.build({
|
|
144
|
+
entryPoints: [input],
|
|
145
|
+
outfile: output,
|
|
146
|
+
platform: 'node',
|
|
147
|
+
target: 'node18',
|
|
148
|
+
format: 'cjs',
|
|
149
|
+
sourcemap: true,
|
|
150
|
+
bundle: false,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async compileWithTSC(input, output) {
|
|
154
|
+
await execAsync(`npx tsc ${input} --outFile ${output} --target ES2022 --module commonjs --esModuleInterop --allowSyntheticDefaultImports --experimentalDecorators --emitDecoratorMetadata --skipLibCheck`);
|
|
155
|
+
}
|
|
156
|
+
clearCache() {
|
|
157
|
+
this.cache.clear();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.FastTypeScriptRunner = FastTypeScriptRunner;
|
|
161
|
+
//# sourceMappingURL=typescript-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript-runner.js","sourceRoot":"","sources":["../src/typescript-runner.ts"],"names":[],"mappings":";;;;;;AAAA,iDAA0D;AAC1D,+BAAqC;AACrC,2BAAwE;AACxE,kDAA0B;AAC1B,sDAA8B;AAC9B,mCAAoC;AACpC,+BAAiC;AAEjC,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAC;AAElC,oDAAoD;AACpD,MAAM,eAAe;IAIjB;QAFQ,YAAO,GAAY,IAAI,CAAC;QAG5B,IAAI,CAAC,QAAQ,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACtD,IAAI,CAAC,IAAA,eAAU,EAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7B,IAAA,cAAS,EAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;IACL,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EAAE,YAAY;oBACpB,GAAG,EAAE,KAAK;oBACV,UAAU,EAAE,IAAI;iBACnB;gBACD,MAAM,EAAE,QAAQ;gBAChB,SAAS,EAAE;oBACP,eAAe,EAAE,IAAI;oBACrB,iBAAiB,EAAE,IAAI;iBAC1B;aACJ;YACD,MAAM,EAAE;gBACJ,IAAI,EAAE,UAAU;aACnB;SACJ,CAAC,CAAC;QACH,IAAA,kBAAa,EAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAAC,KAAa,EAAE,MAAc;QAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;QACnC,MAAM,OAAO,CAAC,KAAK,CAAC;YAChB,WAAW,EAAE,CAAC,KAAK,CAAC;YACpB,OAAO,EAAE,MAAM;YACf,QAAQ,EAAE,MAAM;YAChB,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,KAAK;YACb,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,KAAK;SAChB,CAAC,CAAC;IACP,CAAC;IAEO,KAAK,CAAC,cAAc,CAAC,KAAa,EAAE,MAAc;QACtD,MAAM,SAAS,CAAC,WAAW,KAAK,cAAc,MAAM,qJAAqJ,CAAC,CAAC;IAC/M,CAAC;IAED,UAAU;QACN,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACJ;AAjGD,oDAiGC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "neex",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "The Modern Build System for Polyrepo-in-Monorepo Architecture",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -28,12 +28,17 @@
|
|
|
28
28
|
"author": "foshati",
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@types/express": "^5.0.3",
|
|
31
32
|
"chalk": "^4.1.2",
|
|
32
|
-
"chokidar": "^
|
|
33
|
+
"chokidar": "^4.0.3",
|
|
34
|
+
"cli-table3": "^0.6.5",
|
|
33
35
|
"commander": "^9.4.0",
|
|
36
|
+
"esbuild": "^0.25.5",
|
|
37
|
+
"express": "^5.1.0",
|
|
34
38
|
"figlet": "^1.8.1",
|
|
35
39
|
"figures": "^3.2.0",
|
|
36
40
|
"gradient-string": "^3.0.0",
|
|
41
|
+
"node-notifier": "^10.0.1",
|
|
37
42
|
"npm-run-path": "^4.0.1",
|
|
38
43
|
"p-map": "^4.0.0",
|
|
39
44
|
"string-width": "^4.2.3",
|