neex 0.6.46 → 0.6.47
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/commands/dev-commands.js +134 -30
- package/dist/src/dev-manager.js +151 -47
- package/package.json +1 -1
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -7,6 +30,86 @@ exports.addDevCommands = void 0;
|
|
|
7
30
|
const dev_manager_js_1 = require("../dev-manager.js");
|
|
8
31
|
const logger_manager_js_1 = require("../logger-manager.js");
|
|
9
32
|
const chalk_1 = __importDefault(require("chalk"));
|
|
33
|
+
// Helper function to run the development server
|
|
34
|
+
async function runDevServer(file, options) {
|
|
35
|
+
try {
|
|
36
|
+
let targetFile = file || 'src/index.ts';
|
|
37
|
+
logger_manager_js_1.loggerManager.printLine(`Starting development server for ${chalk_1.default.cyan(targetFile)}`, 'info');
|
|
38
|
+
// Check if file exists and suggest alternatives
|
|
39
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
40
|
+
if (!fs.existsSync(targetFile)) {
|
|
41
|
+
// Try common alternatives
|
|
42
|
+
const alternatives = [
|
|
43
|
+
'src/index.js',
|
|
44
|
+
'src/app.ts',
|
|
45
|
+
'src/app.js',
|
|
46
|
+
'src/server.ts',
|
|
47
|
+
'src/server.js',
|
|
48
|
+
'index.ts',
|
|
49
|
+
'index.js',
|
|
50
|
+
'app.ts',
|
|
51
|
+
'app.js',
|
|
52
|
+
'server.ts',
|
|
53
|
+
'server.js'
|
|
54
|
+
];
|
|
55
|
+
let found = false;
|
|
56
|
+
for (const alt of alternatives) {
|
|
57
|
+
if (fs.existsSync(alt)) {
|
|
58
|
+
logger_manager_js_1.loggerManager.printLine(`File ${targetFile} not found. Using ${alt} instead.`, 'warn');
|
|
59
|
+
targetFile = alt;
|
|
60
|
+
found = true;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!found) {
|
|
65
|
+
logger_manager_js_1.loggerManager.printLine(`File ${targetFile} not found. Common alternatives also not found.`, 'error');
|
|
66
|
+
logger_manager_js_1.loggerManager.printLine(`Please specify the correct file path or create ${targetFile}`, 'error');
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const devManager = new dev_manager_js_1.DevManager({
|
|
71
|
+
file: targetFile,
|
|
72
|
+
watch: options.watch.split(',').map((p) => p.trim()),
|
|
73
|
+
ignore: options.ignore.split(',').map((p) => p.trim()),
|
|
74
|
+
extensions: options.ext.split(',').map((e) => e.trim()),
|
|
75
|
+
delay: options.delay,
|
|
76
|
+
color: options.color,
|
|
77
|
+
quiet: options.quiet,
|
|
78
|
+
verbose: options.verbose,
|
|
79
|
+
clearConsole: options.clear,
|
|
80
|
+
inspect: options.inspect,
|
|
81
|
+
inspectBrk: options.inspectBrk,
|
|
82
|
+
envFile: options.env,
|
|
83
|
+
execCommand: options.exec,
|
|
84
|
+
useTypeScript: options.typescript
|
|
85
|
+
});
|
|
86
|
+
await devManager.start();
|
|
87
|
+
return devManager; // Return for cleanup
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (error instanceof Error) {
|
|
91
|
+
logger_manager_js_1.loggerManager.printLine(`Development server error: ${error.message}`, 'error');
|
|
92
|
+
// Provide helpful suggestions based on error type
|
|
93
|
+
if (error.message.includes('TypeScript execution not available')) {
|
|
94
|
+
logger_manager_js_1.loggerManager.printLine('', 'info');
|
|
95
|
+
logger_manager_js_1.loggerManager.printLine('To run TypeScript files, install one of the following:', 'info');
|
|
96
|
+
logger_manager_js_1.loggerManager.printLine(' npm install --save-dev tsx', 'info');
|
|
97
|
+
logger_manager_js_1.loggerManager.printLine(' npm install --save-dev ts-node', 'info');
|
|
98
|
+
logger_manager_js_1.loggerManager.printLine('', 'info');
|
|
99
|
+
logger_manager_js_1.loggerManager.printLine('Or use --exec to specify a custom command:', 'info');
|
|
100
|
+
logger_manager_js_1.loggerManager.printLine(' neex dev --exec "bun run" src/server.ts', 'info');
|
|
101
|
+
}
|
|
102
|
+
else if (error.message.includes('ENOENT')) {
|
|
103
|
+
logger_manager_js_1.loggerManager.printLine('', 'info');
|
|
104
|
+
logger_manager_js_1.loggerManager.printLine('Make sure the required runtime is installed and in PATH', 'info');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
logger_manager_js_1.loggerManager.printLine('An unknown development server error occurred', 'error');
|
|
109
|
+
}
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
10
113
|
function addDevCommands(program) {
|
|
11
114
|
let devManager = null;
|
|
12
115
|
// Dev command for hot reloading development
|
|
@@ -24,37 +127,38 @@ function addDevCommands(program) {
|
|
|
24
127
|
.option('--inspect', 'Enable Node.js inspector')
|
|
25
128
|
.option('--inspect-brk', 'Enable Node.js inspector with break')
|
|
26
129
|
.option('--env <file>', 'Load environment variables from file', '.env')
|
|
27
|
-
.option('--exec <command>', 'Command to execute instead of
|
|
130
|
+
.option('--exec <command>', 'Command to execute instead of auto-detection')
|
|
131
|
+
.option('--typescript', 'Force TypeScript mode')
|
|
28
132
|
.action(async (file, options) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
133
|
+
devManager = await runDevServer(file, options);
|
|
134
|
+
});
|
|
135
|
+
// Add a convenience command for TypeScript projects
|
|
136
|
+
program
|
|
137
|
+
.command('dev:ts [file]')
|
|
138
|
+
.description('Start development server with TypeScript support')
|
|
139
|
+
.option('-w, --watch <patterns>', 'Watch additional patterns (comma-separated)', 'src/**/*')
|
|
140
|
+
.option('-i, --ignore <patterns>', 'Ignore patterns (comma-separated)', 'node_modules,dist,build,.git')
|
|
141
|
+
.option('-d, --delay <ms>', 'Delay before restart (ms)', parseInt, 1000)
|
|
142
|
+
.option('-q, --quiet', 'Reduce output verbosity')
|
|
143
|
+
.option('-v, --verbose', 'Verbose output')
|
|
144
|
+
.option('--env <file>', 'Load environment variables from file', '.env')
|
|
145
|
+
.action(async (file, options) => {
|
|
146
|
+
// Call the main dev command with TypeScript forced
|
|
147
|
+
const newOptions = {
|
|
148
|
+
...options,
|
|
149
|
+
typescript: true,
|
|
150
|
+
color: true,
|
|
151
|
+
clear: true,
|
|
152
|
+
// Set defaults for options that might not be present in the dev:ts command
|
|
153
|
+
watch: options.watch || 'src/**/*',
|
|
154
|
+
ignore: options.ignore || 'node_modules,dist,build,.git',
|
|
155
|
+
ext: options.ext || 'ts,js,json',
|
|
156
|
+
delay: options.delay || 1000,
|
|
157
|
+
inspect: options.inspect || false,
|
|
158
|
+
inspectBrk: options.inspectBrk || false,
|
|
159
|
+
exec: options.exec || undefined
|
|
160
|
+
};
|
|
161
|
+
devManager = await runDevServer(file, newOptions);
|
|
58
162
|
});
|
|
59
163
|
// Cleanup function
|
|
60
164
|
const cleanupDev = () => {
|
package/dist/src/dev-manager.js
CHANGED
|
@@ -46,20 +46,97 @@ class DevManager {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
detectRuntime() {
|
|
50
|
+
// Check if we're running in Bun
|
|
51
|
+
if (typeof globalThis.Bun !== 'undefined' || process.versions.bun) {
|
|
52
|
+
return 'bun';
|
|
53
|
+
}
|
|
54
|
+
// Check if we're running in Deno
|
|
55
|
+
if (typeof globalThis.Deno !== 'undefined') {
|
|
56
|
+
return 'deno';
|
|
57
|
+
}
|
|
58
|
+
return 'node';
|
|
59
|
+
}
|
|
49
60
|
getExecuteCommand() {
|
|
50
61
|
if (this.options.execCommand) {
|
|
51
62
|
const parts = this.options.execCommand.split(' ');
|
|
52
63
|
return { command: parts[0], args: [...parts.slice(1), this.options.file] };
|
|
53
64
|
}
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
const runtime = this.detectRuntime();
|
|
66
|
+
const isTypeScript = this.options.file.endsWith('.ts') || this.options.useTypeScript;
|
|
67
|
+
let command;
|
|
68
|
+
let args = [];
|
|
69
|
+
switch (runtime) {
|
|
70
|
+
case 'bun':
|
|
71
|
+
command = 'bun';
|
|
72
|
+
args = ['run', this.options.file];
|
|
73
|
+
break;
|
|
74
|
+
case 'deno':
|
|
75
|
+
command = 'deno';
|
|
76
|
+
args = ['run', '--allow-all', this.options.file];
|
|
77
|
+
break;
|
|
78
|
+
case 'node':
|
|
79
|
+
default:
|
|
80
|
+
command = 'node';
|
|
81
|
+
if (isTypeScript) {
|
|
82
|
+
// Try different TypeScript execution methods
|
|
83
|
+
if (this.commandExists('tsx')) {
|
|
84
|
+
command = 'tsx';
|
|
85
|
+
args = [this.options.file];
|
|
86
|
+
}
|
|
87
|
+
else if (this.commandExists('ts-node')) {
|
|
88
|
+
command = 'ts-node';
|
|
89
|
+
args = [this.options.file];
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// Fallback: try to use node with --loader
|
|
93
|
+
const tsNodePath = this.findTsNodePath();
|
|
94
|
+
if (tsNodePath) {
|
|
95
|
+
args = ['--loader', tsNodePath, this.options.file];
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
throw new Error('TypeScript execution not available. Please install tsx or ts-node');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Regular JavaScript file
|
|
104
|
+
args = [this.options.file];
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
// Add inspect flags for Node.js
|
|
109
|
+
if (runtime === 'node' && command === 'node') {
|
|
110
|
+
if (this.options.inspect) {
|
|
111
|
+
args.unshift('--inspect');
|
|
112
|
+
}
|
|
113
|
+
if (this.options.inspectBrk) {
|
|
114
|
+
args.unshift('--inspect-brk');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return { command, args };
|
|
118
|
+
}
|
|
119
|
+
commandExists(command) {
|
|
120
|
+
try {
|
|
121
|
+
const { execSync } = require('child_process');
|
|
122
|
+
execSync(`which ${command}`, { stdio: 'ignore' });
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
catch (_a) {
|
|
126
|
+
return false;
|
|
58
127
|
}
|
|
59
|
-
|
|
60
|
-
|
|
128
|
+
}
|
|
129
|
+
findTsNodePath() {
|
|
130
|
+
const paths = [
|
|
131
|
+
path_1.default.join(process.cwd(), 'node_modules', 'ts-node', 'esm.mjs'),
|
|
132
|
+
path_1.default.join(process.cwd(), 'node_modules', 'ts-node', 'register.js'),
|
|
133
|
+
];
|
|
134
|
+
for (const tsPath of paths) {
|
|
135
|
+
if (fs_1.default.existsSync(tsPath)) {
|
|
136
|
+
return tsPath;
|
|
137
|
+
}
|
|
61
138
|
}
|
|
62
|
-
return
|
|
139
|
+
return null;
|
|
63
140
|
}
|
|
64
141
|
clearConsole() {
|
|
65
142
|
if (this.options.clearConsole && process.stdout.isTTY) {
|
|
@@ -72,50 +149,66 @@ class DevManager {
|
|
|
72
149
|
return;
|
|
73
150
|
}
|
|
74
151
|
this.loadEnvFile();
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.process = (0, child_process_1.spawn)(command, args, {
|
|
80
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
81
|
-
shell: false,
|
|
82
|
-
env: {
|
|
83
|
-
...process.env,
|
|
84
|
-
NODE_ENV: process.env.NODE_ENV || 'development',
|
|
85
|
-
FORCE_COLOR: this.options.color ? '1' : '0'
|
|
86
|
-
},
|
|
87
|
-
detached: true
|
|
88
|
-
});
|
|
89
|
-
this.startTime = new Date();
|
|
90
|
-
this.restartCount++;
|
|
91
|
-
if (!this.options.quiet) {
|
|
92
|
-
const timestamp = new Date().toLocaleTimeString();
|
|
93
|
-
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.green(figures_1.default.play)} Started ${chalk_1.default.cyan(this.options.file)} ${chalk_1.default.dim(`(${timestamp})`)}`, 'info');
|
|
94
|
-
}
|
|
95
|
-
(_a = this.process.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
96
|
-
if (!this.options.quiet) {
|
|
97
|
-
process.stdout.write(data);
|
|
152
|
+
try {
|
|
153
|
+
const { command, args } = this.getExecuteCommand();
|
|
154
|
+
if (this.options.verbose) {
|
|
155
|
+
logger_manager_js_1.loggerManager.printLine(`Executing: ${command} ${args.join(' ')}`, 'info');
|
|
98
156
|
}
|
|
99
|
-
|
|
100
|
-
|
|
157
|
+
this.process = (0, child_process_1.spawn)(command, args, {
|
|
158
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
159
|
+
shell: false,
|
|
160
|
+
env: {
|
|
161
|
+
...process.env,
|
|
162
|
+
NODE_ENV: process.env.NODE_ENV || 'development',
|
|
163
|
+
FORCE_COLOR: this.options.color ? '1' : '0',
|
|
164
|
+
// Add common TypeScript environment variables
|
|
165
|
+
TS_NODE_COMPILER_OPTIONS: '{"module":"commonjs","target":"es2020"}',
|
|
166
|
+
TS_NODE_TRANSPILE_ONLY: 'true'
|
|
167
|
+
},
|
|
168
|
+
detached: true
|
|
169
|
+
});
|
|
170
|
+
this.startTime = new Date();
|
|
171
|
+
this.restartCount++;
|
|
101
172
|
if (!this.options.quiet) {
|
|
102
|
-
|
|
173
|
+
const timestamp = new Date().toLocaleTimeString();
|
|
174
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.green(figures_1.default.play)} Started ${chalk_1.default.cyan(this.options.file)} ${chalk_1.default.dim(`(${timestamp})`)}`, 'info');
|
|
103
175
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
176
|
+
(_a = this.process.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
177
|
+
if (!this.options.quiet) {
|
|
178
|
+
process.stdout.write(data);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
(_b = this.process.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
182
|
+
if (!this.options.quiet) {
|
|
183
|
+
process.stderr.write(data);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
this.process.on('error', (error) => {
|
|
187
|
+
logger_manager_js_1.loggerManager.printLine(`Process error: ${error.message}`, 'error');
|
|
188
|
+
// Provide helpful error messages
|
|
189
|
+
if (error.message.includes('ENOENT')) {
|
|
190
|
+
logger_manager_js_1.loggerManager.printLine(`Command not found. Make sure the required runtime is installed.`, 'error');
|
|
191
|
+
}
|
|
192
|
+
else if (error.message.includes('EACCES')) {
|
|
193
|
+
logger_manager_js_1.loggerManager.printLine(`Permission denied. The command might not be executable.`, 'error');
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
this.process.on('exit', (code, signal) => {
|
|
197
|
+
if (this.process) {
|
|
198
|
+
this.process = null;
|
|
199
|
+
if (!this.isRestarting) {
|
|
200
|
+
if (code !== 0) {
|
|
201
|
+
const duration = this.startTime ? Date.now() - this.startTime.getTime() : 0;
|
|
202
|
+
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.red(figures_1.default.cross)} Process exited with code ${code} after ${duration}ms`, 'error');
|
|
203
|
+
}
|
|
115
204
|
}
|
|
116
205
|
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
logger_manager_js_1.loggerManager.printLine(`Failed to start process: ${error.message}`, 'error');
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
119
212
|
}
|
|
120
213
|
async stopProcess() {
|
|
121
214
|
if (!this.process) {
|
|
@@ -182,6 +275,12 @@ class DevManager {
|
|
|
182
275
|
'**/dist/**',
|
|
183
276
|
'**/build/**',
|
|
184
277
|
'**/*.log',
|
|
278
|
+
'**/.next/**',
|
|
279
|
+
'**/.nuxt/**',
|
|
280
|
+
'**/.vscode/**',
|
|
281
|
+
'**/.idea/**',
|
|
282
|
+
'**/coverage/**',
|
|
283
|
+
'**/*.map',
|
|
185
284
|
...this.options.ignore.map(pattern => `**/${pattern}/**`)
|
|
186
285
|
];
|
|
187
286
|
this.watcher = (0, chokidar_1.watch)(watchPatterns, {
|
|
@@ -189,7 +288,11 @@ class DevManager {
|
|
|
189
288
|
ignoreInitial: true,
|
|
190
289
|
followSymlinks: false,
|
|
191
290
|
usePolling: false,
|
|
192
|
-
atomic: 300
|
|
291
|
+
atomic: 300,
|
|
292
|
+
awaitWriteFinish: {
|
|
293
|
+
stabilityThreshold: 100,
|
|
294
|
+
pollInterval: 50
|
|
295
|
+
}
|
|
193
296
|
});
|
|
194
297
|
this.watcher.on('change', (filePath) => {
|
|
195
298
|
if (this.options.verbose) {
|
|
@@ -228,6 +331,7 @@ class DevManager {
|
|
|
228
331
|
logger_manager_js_1.loggerManager.printLine(`Target file: ${this.options.file}`, 'info');
|
|
229
332
|
logger_manager_js_1.loggerManager.printLine(`Watch patterns: ${this.options.watch.join(', ')}`, 'info');
|
|
230
333
|
logger_manager_js_1.loggerManager.printLine(`Restart delay: ${this.options.delay}ms`, 'info');
|
|
334
|
+
logger_manager_js_1.loggerManager.printLine(`Runtime: ${this.detectRuntime()}`, 'info');
|
|
231
335
|
}
|
|
232
336
|
this.setupWatcher();
|
|
233
337
|
await this.startProcess();
|