neex 0.6.62 → 0.6.63
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/src/dev-manager.js +105 -10
- package/package.json +1 -1
package/dist/src/dev-manager.js
CHANGED
|
@@ -13,6 +13,7 @@ const figures_1 = __importDefault(require("figures"));
|
|
|
13
13
|
const path_1 = __importDefault(require("path"));
|
|
14
14
|
const fs_1 = __importDefault(require("fs"));
|
|
15
15
|
const lodash_1 = require("lodash");
|
|
16
|
+
const child_process_2 = require("child_process");
|
|
16
17
|
class DevManager {
|
|
17
18
|
constructor(options) {
|
|
18
19
|
this.process = null;
|
|
@@ -46,20 +47,109 @@ class DevManager {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
checkCommandExists(command) {
|
|
51
|
+
try {
|
|
52
|
+
(0, child_process_2.execSync)(`command -v ${command}`, { stdio: 'ignore' });
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
catch (_a) {
|
|
56
|
+
try {
|
|
57
|
+
(0, child_process_2.execSync)(`where ${command}`, { stdio: 'ignore' });
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
catch (_b) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
findBestExecutor() {
|
|
66
|
+
const fileExt = path_1.default.extname(this.options.file).toLowerCase();
|
|
67
|
+
const isTypeScript = fileExt === '.ts' || fileExt === '.tsx';
|
|
68
|
+
// اگر کاربر خودش command مشخص کرده
|
|
50
69
|
if (this.options.execCommand) {
|
|
51
70
|
const parts = this.options.execCommand.split(' ');
|
|
52
|
-
return {
|
|
71
|
+
return {
|
|
72
|
+
command: parts[0],
|
|
73
|
+
args: [...parts.slice(1), this.options.file],
|
|
74
|
+
needsRegister: false
|
|
75
|
+
};
|
|
53
76
|
}
|
|
54
|
-
|
|
55
|
-
const args = ['--loader', 'tsx', this.options.file];
|
|
77
|
+
const baseArgs = [this.options.file];
|
|
56
78
|
if (this.options.inspect) {
|
|
57
|
-
|
|
79
|
+
baseArgs.unshift('--inspect');
|
|
58
80
|
}
|
|
59
81
|
if (this.options.inspectBrk) {
|
|
60
|
-
|
|
82
|
+
baseArgs.unshift('--inspect-brk');
|
|
83
|
+
}
|
|
84
|
+
// بررسی tsx
|
|
85
|
+
if (this.checkCommandExists('tsx')) {
|
|
86
|
+
if (this.options.verbose) {
|
|
87
|
+
logger_manager_js_1.loggerManager.printLine('Using tsx for execution', 'info');
|
|
88
|
+
}
|
|
89
|
+
return { command: 'tsx', args: baseArgs, needsRegister: false };
|
|
90
|
+
}
|
|
91
|
+
// بررسی ts-node
|
|
92
|
+
if (isTypeScript && this.checkCommandExists('ts-node')) {
|
|
93
|
+
if (this.options.verbose) {
|
|
94
|
+
logger_manager_js_1.loggerManager.printLine('Using ts-node for execution', 'info');
|
|
95
|
+
}
|
|
96
|
+
return { command: 'ts-node', args: baseArgs, needsRegister: false };
|
|
97
|
+
}
|
|
98
|
+
// بررسی bun
|
|
99
|
+
if (this.checkCommandExists('bun')) {
|
|
100
|
+
if (this.options.verbose) {
|
|
101
|
+
logger_manager_js_1.loggerManager.printLine('Using bun for execution', 'info');
|
|
102
|
+
}
|
|
103
|
+
return { command: 'bun', args: baseArgs, needsRegister: false };
|
|
104
|
+
}
|
|
105
|
+
// بررسی deno
|
|
106
|
+
if (this.checkCommandExists('deno')) {
|
|
107
|
+
if (this.options.verbose) {
|
|
108
|
+
logger_manager_js_1.loggerManager.printLine('Using deno for execution', 'info');
|
|
109
|
+
}
|
|
110
|
+
return { command: 'deno', args: ['run', '--allow-all', this.options.file], needsRegister: false };
|
|
111
|
+
}
|
|
112
|
+
// Fallback به node با ts-node/register اگر فایل TypeScript باشه
|
|
113
|
+
if (isTypeScript) {
|
|
114
|
+
// بررسی ts-node/register
|
|
115
|
+
try {
|
|
116
|
+
require.resolve('ts-node/register');
|
|
117
|
+
if (this.options.verbose) {
|
|
118
|
+
logger_manager_js_1.loggerManager.printLine('Using node with ts-node/register', 'info');
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
command: 'node',
|
|
122
|
+
args: ['--require', 'ts-node/register', ...baseArgs],
|
|
123
|
+
needsRegister: true
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
catch (_a) {
|
|
127
|
+
// اگر ts-node نباشه، خطا بده
|
|
128
|
+
throw new Error('TypeScript file detected but no TypeScript executor found. Please install one of:\n' +
|
|
129
|
+
' • tsx: npm install -g tsx\n' +
|
|
130
|
+
' • ts-node: npm install -g ts-node\n' +
|
|
131
|
+
' • bun: curl -fsSL https://bun.sh/install | bash\n' +
|
|
132
|
+
' • Or compile to JavaScript first');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// برای فایلهای JavaScript از node استفاده کن
|
|
136
|
+
if (this.options.verbose) {
|
|
137
|
+
logger_manager_js_1.loggerManager.printLine('Using node for execution', 'info');
|
|
138
|
+
}
|
|
139
|
+
return { command: 'node', args: baseArgs, needsRegister: false };
|
|
140
|
+
}
|
|
141
|
+
showExecutorInfo(executor) {
|
|
142
|
+
const fileExt = path_1.default.extname(this.options.file).toLowerCase();
|
|
143
|
+
const isTypeScript = fileExt === '.ts' || fileExt === '.tsx';
|
|
144
|
+
if (!this.options.quiet) {
|
|
145
|
+
if (isTypeScript && executor.command === 'node' && executor.needsRegister) {
|
|
146
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.yellow(figures_1.default.warning)} TypeScript support via ts-node/register (consider installing tsx for better performance)`, 'warn');
|
|
147
|
+
}
|
|
148
|
+
if (this.options.verbose) {
|
|
149
|
+
logger_manager_js_1.loggerManager.printLine(`Executor: ${executor.command}`, 'info');
|
|
150
|
+
logger_manager_js_1.loggerManager.printLine(`Arguments: ${executor.args.join(' ')}`, 'info');
|
|
151
|
+
}
|
|
61
152
|
}
|
|
62
|
-
return { command: 'node', args };
|
|
63
153
|
}
|
|
64
154
|
clearConsole() {
|
|
65
155
|
if (this.options.clearConsole && process.stdout.isTTY) {
|
|
@@ -72,11 +162,12 @@ class DevManager {
|
|
|
72
162
|
return;
|
|
73
163
|
}
|
|
74
164
|
this.loadEnvFile();
|
|
75
|
-
const
|
|
165
|
+
const executor = this.findBestExecutor();
|
|
166
|
+
this.showExecutorInfo(executor);
|
|
76
167
|
if (this.options.verbose) {
|
|
77
|
-
logger_manager_js_1.loggerManager.printLine(`Executing: ${command} ${args.join(' ')}`, 'info');
|
|
168
|
+
logger_manager_js_1.loggerManager.printLine(`Executing: ${executor.command} ${executor.args.join(' ')}`, 'info');
|
|
78
169
|
}
|
|
79
|
-
this.process = (0, child_process_1.spawn)(command, args, {
|
|
170
|
+
this.process = (0, child_process_1.spawn)(executor.command, executor.args, {
|
|
80
171
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
81
172
|
shell: false,
|
|
82
173
|
env: {
|
|
@@ -104,6 +195,10 @@ class DevManager {
|
|
|
104
195
|
});
|
|
105
196
|
this.process.on('error', (error) => {
|
|
106
197
|
logger_manager_js_1.loggerManager.printLine(`Process error: ${error.message}`, 'error');
|
|
198
|
+
// اگر خطا مربوط به نبود command باشه، راهنمایی بده
|
|
199
|
+
if (error.message.includes('ENOENT')) {
|
|
200
|
+
logger_manager_js_1.loggerManager.printLine('Command not found. Please check if the executor is installed and accessible.', 'error');
|
|
201
|
+
}
|
|
107
202
|
});
|
|
108
203
|
this.process.on('exit', (code, signal) => {
|
|
109
204
|
if (this.process) {
|