hightjs 0.3.3 → 0.3.4
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/adapters/factory.js +8 -8
- package/dist/adapters/native.js +3 -3
- package/dist/auth/client.js +5 -5
- package/dist/auth/components.js +2 -2
- package/dist/auth/core.js +2 -2
- package/dist/auth/react.js +4 -4
- package/dist/auth/routes.js +1 -1
- package/dist/bin/hightjs.js +29 -328
- package/dist/builder.js +7 -19
- package/dist/client/DefaultNotFound.js +1 -1
- package/dist/client/entry.client.js +3 -3
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +90 -28
- package/dist/hotReload.js +12 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -30
- package/dist/router.js +133 -62
- package/dist/types.d.ts +42 -0
- package/docs/config.md +201 -0
- package/example/hightjs.config.ts +81 -0
- package/example/package-lock.json +633 -3054
- package/example/package.json +1 -1
- package/package.json +1 -1
- package/src/adapters/factory.ts +8 -8
- package/src/adapters/native.ts +3 -3
- package/src/auth/client.ts +5 -5
- package/src/auth/components.tsx +2 -2
- package/src/auth/core.ts +2 -2
- package/src/auth/react.tsx +4 -4
- package/src/auth/routes.ts +1 -1
- package/src/bin/hightjs.js +30 -391
- package/src/builder.js +7 -20
- package/src/client/DefaultNotFound.tsx +1 -1
- package/src/client/entry.client.tsx +3 -3
- package/src/helpers.ts +105 -29
- package/src/hotReload.ts +12 -12
- package/src/index.ts +20 -33
- package/src/router.ts +140 -63
- package/src/types.ts +52 -0
- package/example/.hweb/entry.client.js +0 -24
- package/example/hweb-dist/main-5KKAYNUU.js +0 -1137
package/dist/builder.js
CHANGED
|
@@ -82,7 +82,7 @@ const postcssPlugin = {
|
|
|
82
82
|
plugins.push(pluginModule(pluginOptions || {}));
|
|
83
83
|
}
|
|
84
84
|
catch (error) {
|
|
85
|
-
Console.warn(`
|
|
85
|
+
Console.warn(`Unable to load plugin ${pluginName}:`, error.message);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -96,8 +96,8 @@ const postcssPlugin = {
|
|
|
96
96
|
processedCss = result.css;
|
|
97
97
|
}
|
|
98
98
|
catch (postcssError) {
|
|
99
|
-
Console.warn(`
|
|
100
|
-
Console.warn(`
|
|
99
|
+
Console.warn(`Error processing CSS with PostCSS:`, postcssError.message);
|
|
100
|
+
Console.warn(`Using raw CSS without processing.`);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
return {
|
|
@@ -185,9 +185,6 @@ const reactResolvePlugin = {
|
|
|
185
185
|
async function buildWithChunks(entryPoint, outdir, isProduction = false) {
|
|
186
186
|
// limpar diretorio
|
|
187
187
|
fs.rmSync(outdir, { recursive: true, force: true });
|
|
188
|
-
if (!isProduction) {
|
|
189
|
-
console.log(`Iniciando o build com chunks de \"${entryPoint}\"...`);
|
|
190
|
-
}
|
|
191
188
|
try {
|
|
192
189
|
await esbuild.build({
|
|
193
190
|
entryPoints: [entryPoint],
|
|
@@ -214,12 +211,9 @@ async function buildWithChunks(entryPoint, outdir, isProduction = false) {
|
|
|
214
211
|
keepNames: true,
|
|
215
212
|
treeShaking: true,
|
|
216
213
|
});
|
|
217
|
-
if (!isProduction) {
|
|
218
|
-
console.log(`Build com chunks finalizado! Saída: \"${outdir}\".`);
|
|
219
|
-
}
|
|
220
214
|
}
|
|
221
215
|
catch (error) {
|
|
222
|
-
console.error('
|
|
216
|
+
console.error('An error occurred while building:', error);
|
|
223
217
|
process.exit(1);
|
|
224
218
|
}
|
|
225
219
|
}
|
|
@@ -281,7 +275,7 @@ async function watchWithChunks(entryPoint, outdir, hotReloadManager = null) {
|
|
|
281
275
|
}
|
|
282
276
|
catch (error) {
|
|
283
277
|
console.error(error);
|
|
284
|
-
Console.error('
|
|
278
|
+
Console.error('Error starting watch mode with chunks:', error);
|
|
285
279
|
throw error;
|
|
286
280
|
}
|
|
287
281
|
}
|
|
@@ -296,9 +290,6 @@ async function build(entryPoint, outfile, isProduction = false) {
|
|
|
296
290
|
// limpar diretorio do outfile
|
|
297
291
|
const outdir = path.dirname(outfile);
|
|
298
292
|
fs.rmSync(outdir, { recursive: true, force: true });
|
|
299
|
-
if (!isProduction) {
|
|
300
|
-
console.log(`Iniciando o build de \"${entryPoint}\"...`);
|
|
301
|
-
}
|
|
302
293
|
try {
|
|
303
294
|
await esbuild.build({
|
|
304
295
|
entryPoints: [entryPoint],
|
|
@@ -328,12 +319,9 @@ async function build(entryPoint, outfile, isProduction = false) {
|
|
|
328
319
|
treeShaking: true,
|
|
329
320
|
drop: [], // Não remove nada automaticamente
|
|
330
321
|
});
|
|
331
|
-
if (!isProduction) {
|
|
332
|
-
console.log(`Build finalizado com sucesso! Saída: \"${outfile}\".`);
|
|
333
|
-
}
|
|
334
322
|
}
|
|
335
323
|
catch (error) {
|
|
336
|
-
console.error('
|
|
324
|
+
console.error('An error occurred during build:', error);
|
|
337
325
|
process.exit(1);
|
|
338
326
|
}
|
|
339
327
|
}
|
|
@@ -396,7 +384,7 @@ async function watch(entryPoint, outfile, hotReloadManager = null) {
|
|
|
396
384
|
await context.watch();
|
|
397
385
|
}
|
|
398
386
|
catch (error) {
|
|
399
|
-
Console.error('
|
|
387
|
+
Console.error('Error starting watch mode:', error);
|
|
400
388
|
throw error;
|
|
401
389
|
}
|
|
402
390
|
}
|
|
@@ -265,7 +265,7 @@ function DevIndicator() {
|
|
|
265
265
|
function initializeClient() {
|
|
266
266
|
const initialData = window.__HWEB_INITIAL_DATA__;
|
|
267
267
|
if (!initialData) {
|
|
268
|
-
console.error('[hweb]
|
|
268
|
+
console.error('[hweb] Initial data not found on page.');
|
|
269
269
|
return;
|
|
270
270
|
}
|
|
271
271
|
// Cria o mapa de componentes dinamicamente a partir dos módulos carregados
|
|
@@ -276,7 +276,7 @@ function initializeClient() {
|
|
|
276
276
|
}
|
|
277
277
|
const container = document.getElementById('root');
|
|
278
278
|
if (!container) {
|
|
279
|
-
console.error('[hweb] Container #root
|
|
279
|
+
console.error('[hweb] Container #root not found.');
|
|
280
280
|
return;
|
|
281
281
|
}
|
|
282
282
|
try {
|
|
@@ -285,7 +285,7 @@ function initializeClient() {
|
|
|
285
285
|
root.render((0, jsx_runtime_1.jsx)(App, { componentMap: componentMap, routes: initialData.routes, initialComponentPath: initialData.initialComponentPath, initialParams: initialData.initialParams, layoutComponent: window.__HWEB_LAYOUT__ }));
|
|
286
286
|
}
|
|
287
287
|
catch (error) {
|
|
288
|
-
console.error('[hweb]
|
|
288
|
+
console.error('[hweb] Error rendering application:', error);
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
// Executa quando o DOM estiver pronto
|
package/dist/helpers.d.ts
CHANGED
package/dist/helpers.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
"use strict";
|
|
2
3
|
/*
|
|
3
4
|
* This file is part of the HightJS Project.
|
|
@@ -57,6 +58,7 @@ exports.app = app;
|
|
|
57
58
|
const http_1 = __importDefault(require("http"));
|
|
58
59
|
const os_1 = __importDefault(require("os"));
|
|
59
60
|
const url_1 = require("url"); // API moderna, substitui 'querystring'
|
|
61
|
+
const path_1 = __importDefault(require("path"));
|
|
60
62
|
// Helpers para integração com diferentes frameworks
|
|
61
63
|
const index_1 = __importStar(require("./index")); // Importando o tipo
|
|
62
64
|
const console_1 = __importStar(require("./api/console"));
|
|
@@ -81,28 +83,85 @@ function getLocalExternalIp() {
|
|
|
81
83
|
return 'localhost'; // Fallback
|
|
82
84
|
}
|
|
83
85
|
const sendBox = (options) => {
|
|
84
|
-
const isDev = options.dev ? "
|
|
86
|
+
const isDev = options.dev ? "Running in development mode" : null;
|
|
85
87
|
// 1. Verifica se o SSL está ativado (baseado na mesma lógica do initNativeServer)
|
|
86
88
|
const isSSL = options.ssl && options.ssl.key && options.ssl.cert;
|
|
87
89
|
const protocol = isSSL ? 'https' : 'http';
|
|
88
90
|
const localIp = getLocalExternalIp(); // Assume que getLocalExternalIp() existe
|
|
89
91
|
// 2. Monta as mensagens com o protocolo correto
|
|
90
92
|
const messages = [
|
|
91
|
-
` ${console_1.Colors.FgGray}┃${console_1.Colors.Reset} Local:
|
|
93
|
+
` ${console_1.Colors.FgGray}┃${console_1.Colors.Reset} Local: ${console_1.Colors.FgGreen}${protocol}://localhost:${options.port}${console_1.Colors.Reset}`,
|
|
92
94
|
];
|
|
93
95
|
// Só adiciona a rede se o IP local for encontrado
|
|
94
96
|
if (localIp) {
|
|
95
|
-
messages.push(` ${console_1.Colors.FgGray}┃${console_1.Colors.Reset}
|
|
97
|
+
messages.push(` ${console_1.Colors.FgGray}┃${console_1.Colors.Reset} Network: ${console_1.Colors.FgGreen}${protocol}://${localIp}:${options.port}${console_1.Colors.Reset}`);
|
|
96
98
|
}
|
|
97
99
|
if (isDev) {
|
|
98
100
|
messages.push(` ${console_1.Colors.FgGray}┃${console_1.Colors.Reset} ${isDev}`);
|
|
99
101
|
}
|
|
100
102
|
// Adiciona aviso de redirecionamento se estiver em modo SSL
|
|
101
103
|
if (isSSL && options.ssl?.redirectPort) {
|
|
102
|
-
messages.push(` ${console_1.Colors.FgGray}┃${console_1.Colors.Reset} HTTP (
|
|
104
|
+
messages.push(` ${console_1.Colors.FgGray}┃${console_1.Colors.Reset} HTTP (port ${options.ssl?.redirectPort}) is redirecting to HTTPS.`);
|
|
103
105
|
}
|
|
104
|
-
console_1.default.box(messages.join("\n"), { title: "
|
|
106
|
+
console_1.default.box(messages.join("\n"), { title: "Access on:" });
|
|
105
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Carrega o arquivo de configuração hightjs.config.ts ou hightjs.config.js do projeto
|
|
110
|
+
* @param projectDir Diretório raiz do projeto
|
|
111
|
+
* @param phase Fase de execução ('development' ou 'production')
|
|
112
|
+
* @returns Configuração mesclada com os valores padrão
|
|
113
|
+
*/
|
|
114
|
+
async function loadHightConfig(projectDir, phase) {
|
|
115
|
+
const defaultConfig = {
|
|
116
|
+
maxHeadersCount: 100,
|
|
117
|
+
headersTimeout: 60000,
|
|
118
|
+
requestTimeout: 30000,
|
|
119
|
+
serverTimeout: 35000,
|
|
120
|
+
individualRequestTimeout: 30000,
|
|
121
|
+
maxUrlLength: 2048,
|
|
122
|
+
};
|
|
123
|
+
try {
|
|
124
|
+
// Tenta primeiro .ts, depois .js
|
|
125
|
+
const possiblePaths = [
|
|
126
|
+
path_1.default.join(projectDir, 'hightjs.config.ts'),
|
|
127
|
+
path_1.default.join(projectDir, 'hightjs.config.js'),
|
|
128
|
+
];
|
|
129
|
+
let configPath = null;
|
|
130
|
+
for (const p of possiblePaths) {
|
|
131
|
+
if (fs_1.default.existsSync(p)) {
|
|
132
|
+
configPath = p;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!configPath) {
|
|
137
|
+
return defaultConfig;
|
|
138
|
+
}
|
|
139
|
+
// Remove do cache para permitir hot reload da configuração em dev
|
|
140
|
+
delete require.cache[require.resolve(configPath)];
|
|
141
|
+
const configModule = require(configPath);
|
|
142
|
+
const configExport = configModule.default || configModule;
|
|
143
|
+
let userConfig;
|
|
144
|
+
if (typeof configExport === 'function') {
|
|
145
|
+
// Suporta tanto função síncrona quanto assíncrona
|
|
146
|
+
userConfig = await Promise.resolve(configExport(phase, { defaultConfig }));
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
userConfig = configExport;
|
|
150
|
+
}
|
|
151
|
+
// Mescla a configuração do usuário com a padrão
|
|
152
|
+
const mergedConfig = { ...defaultConfig, ...userConfig };
|
|
153
|
+
const configFileName = path_1.default.basename(configPath);
|
|
154
|
+
console_1.default.info(`${console_1.Colors.FgCyan}[Config]${console_1.Colors.Reset} Loaded ${configFileName}`);
|
|
155
|
+
return mergedConfig;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (error instanceof Error) {
|
|
159
|
+
console_1.default.warn(`${console_1.Colors.FgYellow}[Config]${console_1.Colors.Reset} Error loading hightjs.config: ${error.message}`);
|
|
160
|
+
console_1.default.warn(`${console_1.Colors.FgYellow}[Config]${console_1.Colors.Reset} Using default configuration`);
|
|
161
|
+
}
|
|
162
|
+
return defaultConfig;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
106
165
|
/**
|
|
107
166
|
* Middleware para parsing do body com proteções de segurança (versão melhorada).
|
|
108
167
|
* Rejeita a promise em caso de erro de parsing ou estouro de limite.
|
|
@@ -181,8 +240,12 @@ const parseBody = (req) => {
|
|
|
181
240
|
async function initNativeServer(hwebApp, options, port, hostname) {
|
|
182
241
|
const time = Date.now();
|
|
183
242
|
await hwebApp.prepare();
|
|
243
|
+
// Carrega a configuração do arquivo hightjs.config.js
|
|
244
|
+
const projectDir = options.dir || process.cwd();
|
|
245
|
+
const phase = options.dev ? 'development' : 'production';
|
|
246
|
+
const hightConfig = await loadHightConfig(projectDir, phase);
|
|
184
247
|
const handler = hwebApp.getRequestHandler();
|
|
185
|
-
const msg = console_1.default.dynamicLine(` ${console_1.Colors.BgYellow} ready ${console_1.Colors.Reset} ${console_1.Colors.Bright}
|
|
248
|
+
const msg = console_1.default.dynamicLine(` ${console_1.Colors.BgYellow} ready ${console_1.Colors.Reset} ${console_1.Colors.Bright}Starting HightJS on port ${options.port}${console_1.Colors.Reset}`);
|
|
186
249
|
// --- LÓGICA DO LISTENER (REUTILIZÁVEL) ---
|
|
187
250
|
// Extraímos a lógica principal para uma variável
|
|
188
251
|
// para que possa ser usada tanto pelo servidor HTTP quanto HTTPS.
|
|
@@ -197,15 +260,16 @@ async function initNativeServer(hwebApp, options, port, hostname) {
|
|
|
197
260
|
if (options.ssl) {
|
|
198
261
|
res.setHeader('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
|
|
199
262
|
}
|
|
200
|
-
// Timeout por requisição
|
|
201
|
-
req.setTimeout(30000, () => {
|
|
263
|
+
// Timeout por requisição (usa configuração personalizada)
|
|
264
|
+
req.setTimeout(hightConfig.individualRequestTimeout || 30000, () => {
|
|
202
265
|
res.statusCode = 408; // Request Timeout
|
|
203
266
|
res.end('Request timeout');
|
|
204
267
|
});
|
|
205
268
|
try {
|
|
206
|
-
// Validação básica de URL
|
|
269
|
+
// Validação básica de URL (usa configuração personalizada)
|
|
207
270
|
const url = req.url || '/';
|
|
208
|
-
|
|
271
|
+
const maxUrlLength = hightConfig.maxUrlLength || 2048;
|
|
272
|
+
if (url.length > maxUrlLength) {
|
|
209
273
|
res.statusCode = 414; // URI Too Long
|
|
210
274
|
res.end('URL too long');
|
|
211
275
|
return;
|
|
@@ -220,10 +284,10 @@ async function initNativeServer(hwebApp, options, port, hostname) {
|
|
|
220
284
|
catch (error) {
|
|
221
285
|
// Log do erro no servidor
|
|
222
286
|
if (error instanceof Error) {
|
|
223
|
-
console_1.default.error(`
|
|
287
|
+
console_1.default.error(`Native server error: ${error.message}`);
|
|
224
288
|
}
|
|
225
289
|
else {
|
|
226
|
-
console_1.default.error('
|
|
290
|
+
console_1.default.error('Unknown native server error:', error);
|
|
227
291
|
}
|
|
228
292
|
// Tratamento de erro (idêntico ao seu original)
|
|
229
293
|
if (!res.headersSent) {
|
|
@@ -286,14 +350,14 @@ async function initNativeServer(hwebApp, options, port, hostname) {
|
|
|
286
350
|
// Cria o servidor HTTP nativo
|
|
287
351
|
server = http_1.default.createServer(requestListener); // (any para contornar HWebIncomingMessage)
|
|
288
352
|
}
|
|
289
|
-
// Configurações de segurança do servidor (
|
|
290
|
-
server.setTimeout(35000); // Timeout geral do servidor
|
|
291
|
-
server.maxHeadersCount = 100; // Limita número de headers
|
|
292
|
-
server.headersTimeout = 60000; // Timeout para headers
|
|
293
|
-
server.requestTimeout = 30000; // Timeout para requisições
|
|
353
|
+
// Configurações de segurança do servidor (usa configuração personalizada)
|
|
354
|
+
server.setTimeout(hightConfig.serverTimeout || 35000); // Timeout geral do servidor
|
|
355
|
+
server.maxHeadersCount = hightConfig.maxHeadersCount || 100; // Limita número de headers
|
|
356
|
+
server.headersTimeout = hightConfig.headersTimeout || 60000; // Timeout para headers
|
|
357
|
+
server.requestTimeout = hightConfig.requestTimeout || 30000; // Timeout para requisições
|
|
294
358
|
server.listen(port, hostname, () => {
|
|
295
359
|
sendBox({ ...options, port });
|
|
296
|
-
msg.end(` ${console_1.Colors.BgGreen} ready ${console_1.Colors.Reset} ${console_1.Colors.Bright}
|
|
360
|
+
msg.end(` ${console_1.Colors.BgGreen} ready ${console_1.Colors.Reset} ${console_1.Colors.Bright}Ready on port ${console_1.Colors.BgGreen} ${options.port} ${console_1.Colors.Reset}${console_1.Colors.Bright} in ${Date.now() - time}ms${console_1.Colors.Reset}\n`);
|
|
297
361
|
});
|
|
298
362
|
// Configura WebSocket para hot reload (Comum a ambos)
|
|
299
363
|
hwebApp.setupWebSocket(server);
|
|
@@ -325,7 +389,7 @@ function app(options = {}) {
|
|
|
325
389
|
serverApp.use(cookieParser());
|
|
326
390
|
}
|
|
327
391
|
catch (e) {
|
|
328
|
-
console_1.default.error("
|
|
392
|
+
console_1.default.error("Could not find cookie-parser");
|
|
329
393
|
}
|
|
330
394
|
serverApp.use(express.json());
|
|
331
395
|
serverApp.use(express.urlencoded({ extended: true }));
|
|
@@ -337,13 +401,13 @@ function app(options = {}) {
|
|
|
337
401
|
await serverApp.register(require('@fastify/cookie'));
|
|
338
402
|
}
|
|
339
403
|
catch (e) {
|
|
340
|
-
console_1.default.error("
|
|
404
|
+
console_1.default.error("Could not find @fastify/cookie");
|
|
341
405
|
}
|
|
342
406
|
try {
|
|
343
407
|
await serverApp.register(require('@fastify/formbody'));
|
|
344
408
|
}
|
|
345
409
|
catch (e) {
|
|
346
|
-
console_1.default.error("
|
|
410
|
+
console_1.default.error("Could not find @fastify/formbody");
|
|
347
411
|
}
|
|
348
412
|
await serverApp.register(async (fastify) => {
|
|
349
413
|
fastify.all('*', handler);
|
|
@@ -371,7 +435,7 @@ function app(options = {}) {
|
|
|
371
435
|
return data.version;
|
|
372
436
|
}
|
|
373
437
|
catch (error) {
|
|
374
|
-
console_1.default.error('
|
|
438
|
+
console_1.default.error('Could not check for the latest HightJS version:', error);
|
|
375
439
|
return currentVersion; // Retorna a versão atual em caso de erro
|
|
376
440
|
}
|
|
377
441
|
}
|
|
@@ -379,22 +443,20 @@ function app(options = {}) {
|
|
|
379
443
|
const isUpToDate = latestVersion === currentVersion;
|
|
380
444
|
let message;
|
|
381
445
|
if (!isUpToDate) {
|
|
382
|
-
message = `${console_1.Colors.FgGreen}
|
|
446
|
+
message = `${console_1.Colors.FgGreen} A new version is available (v${latestVersion})${console_1.Colors.FgMagenta}`;
|
|
383
447
|
}
|
|
384
448
|
else {
|
|
385
|
-
message = `${console_1.Colors.FgGreen}
|
|
449
|
+
message = `${console_1.Colors.FgGreen} You are on the latest version${console_1.Colors.FgMagenta}`;
|
|
386
450
|
}
|
|
387
451
|
console.log(`${console_1.Colors.FgMagenta}
|
|
388
452
|
__ ___ ${console_1.Colors.FgGreen} __ ${console_1.Colors.FgMagenta}
|
|
389
453
|
|__| | / _\` |__| | ${console_1.Colors.FgGreen} | /__\` ${console_1.Colors.FgMagenta} ${console_1.Colors.FgMagenta}HightJS ${console_1.Colors.FgGray}(v${require('../package.json').version}) - itsmuzin${console_1.Colors.FgMagenta}
|
|
390
|
-
| | | \\__> | | | ${console_1.Colors.FgGreen}\\__/ .__/ ${message}
|
|
391
|
-
|
|
392
|
-
|
|
454
|
+
| | | \\__> | | | ${console_1.Colors.FgGreen}\\__/ .__/ ${message}
|
|
393
455
|
${console_1.Colors.Reset}`);
|
|
394
456
|
const actualPort = options.port || 3000;
|
|
395
457
|
const actualHostname = options.hostname || "0.0.0.0";
|
|
396
458
|
if (framework !== 'native') {
|
|
397
|
-
console_1.default.warn(`
|
|
459
|
+
console_1.default.warn(`The "${framework}" framework was selected, but the init() method only works with the "native" framework. Starting native server...`);
|
|
398
460
|
}
|
|
399
461
|
return await initNativeServer(hwebApp, options, actualPort, actualHostname);
|
|
400
462
|
}
|
package/dist/hotReload.js
CHANGED
|
@@ -202,7 +202,7 @@ class HotReloadManager {
|
|
|
202
202
|
this.clearBackendCache(filePath);
|
|
203
203
|
// Se for arquivo de frontend, aguarda o build terminar antes de recarregar
|
|
204
204
|
if (isFrontendFile) {
|
|
205
|
-
console_1.default.logWithout(console_1.Levels.INFO, console_1.Colors.BgRed, `📄
|
|
205
|
+
console_1.default.logWithout(console_1.Levels.INFO, console_1.Colors.BgRed, `📄 Waiting for frontend build...`);
|
|
206
206
|
// Marca que estamos esperando um build
|
|
207
207
|
this.isBuilding = true;
|
|
208
208
|
// Cria uma promise que será resolvida quando o build terminar
|
|
@@ -215,12 +215,12 @@ class HotReloadManager {
|
|
|
215
215
|
});
|
|
216
216
|
try {
|
|
217
217
|
await Promise.race([buildPromise, timeoutPromise]);
|
|
218
|
-
console_1.default.logWithout(console_1.Levels.INFO, console_1.Colors.BgRed, `✅ Build
|
|
218
|
+
console_1.default.logWithout(console_1.Levels.INFO, console_1.Colors.BgRed, `✅ Build complete, reloading frontend...`);
|
|
219
219
|
this.frontendChangeCallback?.();
|
|
220
220
|
this.notifyClients('frontend-reload', { file: filePath, event: 'change' });
|
|
221
221
|
}
|
|
222
222
|
catch (error) {
|
|
223
|
-
console_1.default.logWithout(console_1.Levels.ERROR, console_1.Colors.BgRed, `⚠️ Timeout
|
|
223
|
+
console_1.default.logWithout(console_1.Levels.ERROR, console_1.Colors.BgRed, `⚠️ Timeout in build, reloading anyway...`);
|
|
224
224
|
this.frontendChangeCallback?.();
|
|
225
225
|
this.notifyClients('frontend-reload', { file: filePath, event: 'change' });
|
|
226
226
|
}
|
|
@@ -231,13 +231,13 @@ class HotReloadManager {
|
|
|
231
231
|
}
|
|
232
232
|
// Se for arquivo de backend, recarrega o módulo e notifica
|
|
233
233
|
if (isBackendFile) {
|
|
234
|
-
console_1.default.logWithout(console_1.Levels.INFO, console_1.Colors.BgRed, `⚙️
|
|
234
|
+
console_1.default.logWithout(console_1.Levels.INFO, console_1.Colors.BgRed, `⚙️ Reloading backend...`);
|
|
235
235
|
this.backendApiChangeCallback?.();
|
|
236
236
|
this.notifyClients('backend-api-reload', { file: filePath, event: 'change' });
|
|
237
237
|
}
|
|
238
238
|
// Fallback: se não for nem frontend nem backend detectado, recarrega tudo
|
|
239
239
|
if (!isFrontendFile && !isBackendFile) {
|
|
240
|
-
console_1.default.logWithout(console_1.Levels.INFO, console_1.Colors.BgRed, `🔄
|
|
240
|
+
console_1.default.logWithout(console_1.Levels.INFO, console_1.Colors.BgRed, `🔄 Reloading application...`);
|
|
241
241
|
this.frontendChangeCallback?.();
|
|
242
242
|
this.backendApiChangeCallback?.();
|
|
243
243
|
this.notifyClients('src-reload', { file: filePath, event: 'change' });
|
|
@@ -249,7 +249,7 @@ class HotReloadManager {
|
|
|
249
249
|
}
|
|
250
250
|
catch (error) {
|
|
251
251
|
// @ts-ignore
|
|
252
|
-
console_1.default.logWithout(console_1.Levels.ERROR, `
|
|
252
|
+
console_1.default.logWithout(console_1.Levels.ERROR, `Error in custom listener: ${error.message}`);
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
}
|
|
@@ -265,7 +265,7 @@ class HotReloadManager {
|
|
|
265
265
|
ws.send(message);
|
|
266
266
|
}
|
|
267
267
|
catch (error) {
|
|
268
|
-
console_1.default.logWithout(console_1.Levels.ERROR, console_1.Colors.BgRed, `
|
|
268
|
+
console_1.default.logWithout(console_1.Levels.ERROR, console_1.Colors.BgRed, `Error sending WebSocket message: ${error}`);
|
|
269
269
|
deadClients.push(ws);
|
|
270
270
|
}
|
|
271
271
|
}
|
|
@@ -327,7 +327,7 @@ class HotReloadManager {
|
|
|
327
327
|
ws = new WebSocket('ws://localhost:3000/hweb-hotreload/');
|
|
328
328
|
|
|
329
329
|
ws.onopen = function() {
|
|
330
|
-
console.log('🔌 Hot-reload
|
|
330
|
+
console.log('🔌 Hot-reload connected');
|
|
331
331
|
isConnected = true;
|
|
332
332
|
reconnectAttempts = 0;
|
|
333
333
|
reconnectInterval = 1000;
|
|
@@ -347,13 +347,13 @@ class HotReloadManager {
|
|
|
347
347
|
window.location.reload();
|
|
348
348
|
break;
|
|
349
349
|
case 'server-restart':
|
|
350
|
-
console.log('🔄
|
|
350
|
+
console.log('🔄 Server restarting...');
|
|
351
351
|
break;
|
|
352
352
|
case 'server-ready':
|
|
353
353
|
setTimeout(() => window.location.reload(), 500);
|
|
354
354
|
break;
|
|
355
355
|
case 'frontend-error':
|
|
356
|
-
console.error('❌
|
|
356
|
+
console.error('❌ Frontend error:', message.data);
|
|
357
357
|
break;
|
|
358
358
|
}
|
|
359
359
|
} catch (e) {
|
|
@@ -378,7 +378,7 @@ class HotReloadManager {
|
|
|
378
378
|
};
|
|
379
379
|
|
|
380
380
|
} catch (error) {
|
|
381
|
-
console.error('
|
|
381
|
+
console.error('Error creating WebSocket:', error);
|
|
382
382
|
scheduleReconnect();
|
|
383
383
|
}
|
|
384
384
|
}
|
|
@@ -443,7 +443,7 @@ class HotReloadManager {
|
|
|
443
443
|
}
|
|
444
444
|
setHotReloadListener(listener) {
|
|
445
445
|
this.customHotReloadListener = listener;
|
|
446
|
-
console_1.default.info('🔌 Hot reload listener
|
|
446
|
+
console_1.default.info('🔌 Hot reload custom listener registered');
|
|
447
447
|
}
|
|
448
448
|
removeHotReloadListener() {
|
|
449
449
|
this.customHotReloadListener = null;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,11 +8,11 @@ export { FrameworkAdapterFactory } from './adapters/factory';
|
|
|
8
8
|
export type { GenericRequest, GenericResponse, CookieOptions } from './types/framework';
|
|
9
9
|
export { app } from './helpers';
|
|
10
10
|
export type { WebSocketContext, WebSocketHandler } from './types';
|
|
11
|
+
export type { HightConfig, HightConfigFunction } from './types';
|
|
11
12
|
export default function hweb(options: HightJSOptions): {
|
|
12
13
|
prepare: () => Promise<void>;
|
|
13
14
|
executeInstrumentation: () => void;
|
|
14
15
|
getRequestHandler: () => RequestHandler;
|
|
15
16
|
setupWebSocket: (server: any) => void;
|
|
16
|
-
build: () => Promise<void>;
|
|
17
17
|
stop: () => void;
|
|
18
18
|
};
|
package/dist/index.js
CHANGED
|
@@ -236,23 +236,20 @@ function hweb(options) {
|
|
|
236
236
|
await hotReloadManager.start();
|
|
237
237
|
// Adiciona callback para recarregar TUDO quando qualquer arquivo mudar
|
|
238
238
|
hotReloadManager.onBackendApiChange(() => {
|
|
239
|
-
console_1.default.info('🔄 Recarregando backend e dependências...');
|
|
240
239
|
(0, router_1.loadBackendRoutes)(userBackendRoutesDir);
|
|
241
240
|
(0, router_1.processWebSocketRoutes)(); // Processa rotas WS após recarregar backend
|
|
242
241
|
});
|
|
243
242
|
// Adiciona callback para regenerar entry file quando frontend mudar
|
|
244
243
|
hotReloadManager.onFrontendChange(() => {
|
|
245
|
-
console_1.default.info('🔄 Regenerando frontend...');
|
|
246
244
|
regenerateEntryFile();
|
|
247
245
|
});
|
|
248
246
|
}
|
|
249
247
|
const now = Date.now();
|
|
250
|
-
const timee = console_1.default.dynamicLine(` ${console_1.Colors.BgYellow} router ${console_1.Colors.Reset}
|
|
248
|
+
const timee = console_1.default.dynamicLine(` ${console_1.Colors.BgYellow} router ${console_1.Colors.Reset} Loading routes and components`);
|
|
251
249
|
const spinnerFrames1 = ['|', '/', '-', '\\'];
|
|
252
250
|
let frameIndex1 = 0;
|
|
253
251
|
const spinner1 = setInterval(() => {
|
|
254
|
-
console_1.
|
|
255
|
-
timee.update(` ${console_1.Colors.FgYellow}${spinnerFrames1[frameIndex1]}${console_1.Colors.Reset} Carregando rotas e componentes...`);
|
|
252
|
+
timee.update(` ${console_1.Colors.FgYellow}${spinnerFrames1[frameIndex1]}${console_1.Colors.Reset} Loading routes and components...`);
|
|
256
253
|
frameIndex1 = (frameIndex1 + 1) % spinnerFrames1.length;
|
|
257
254
|
}, 100); // muda a cada 100ms
|
|
258
255
|
// ORDEM IMPORTANTE: Carrega TUDO antes de criar o arquivo de entrada
|
|
@@ -267,14 +264,14 @@ function hweb(options) {
|
|
|
267
264
|
fs_1.default.mkdirSync(outDir, { recursive: true });
|
|
268
265
|
entryPoint = createEntryFile(dir, frontendRoutes);
|
|
269
266
|
clearInterval(spinner1);
|
|
270
|
-
timee.end(` ${console_1.Colors.BgGreen} router ${console_1.Colors.Reset}
|
|
267
|
+
timee.end(` ${console_1.Colors.BgGreen} router ${console_1.Colors.Reset} Routes and components loaded in ${Date.now() - now}ms`);
|
|
271
268
|
if (isProduction) {
|
|
272
|
-
const time = console_1.default.dynamicLine(` ${console_1.Colors.BgYellow} build ${console_1.Colors.Reset}
|
|
269
|
+
const time = console_1.default.dynamicLine(` ${console_1.Colors.BgYellow} build ${console_1.Colors.Reset} Starting client build`);
|
|
273
270
|
// Spinner
|
|
274
271
|
const spinnerFrames = ['|', '/', '-', '\\'];
|
|
275
272
|
let frameIndex = 0;
|
|
276
273
|
const spinner = setInterval(() => {
|
|
277
|
-
time.update(` ${console_1.Colors.FgYellow}${spinnerFrames[frameIndex]}${console_1.Colors.Reset}
|
|
274
|
+
time.update(` ${console_1.Colors.FgYellow}${spinnerFrames[frameIndex]}${console_1.Colors.Reset} Building...`);
|
|
278
275
|
frameIndex = (frameIndex + 1) % spinnerFrames.length;
|
|
279
276
|
}, 100); // muda a cada 100ms
|
|
280
277
|
const now = Date.now();
|
|
@@ -282,14 +279,14 @@ function hweb(options) {
|
|
|
282
279
|
const elapsed = Date.now() - now;
|
|
283
280
|
clearInterval(spinner); // para o spinner
|
|
284
281
|
time.update(""); // limpa a linha
|
|
285
|
-
time.end(` ${console_1.Colors.BgGreen} build ${console_1.Colors.Reset}
|
|
282
|
+
time.end(` ${console_1.Colors.BgGreen} build ${console_1.Colors.Reset} Client build completed in ${elapsed}ms`);
|
|
286
283
|
}
|
|
287
284
|
else {
|
|
288
|
-
const time = console_1.default.dynamicLine(` ${console_1.Colors.BgYellow} watcher ${console_1.Colors.Reset}
|
|
285
|
+
const time = console_1.default.dynamicLine(` ${console_1.Colors.BgYellow} watcher ${console_1.Colors.Reset} Starting client watch`);
|
|
289
286
|
(0, builder_1.watchWithChunks)(entryPoint, outDir, hotReloadManager).catch(err => {
|
|
290
|
-
console_1.default.error(`
|
|
287
|
+
console_1.default.error(`Error starting watch`, err);
|
|
291
288
|
});
|
|
292
|
-
time.end(` ${console_1.Colors.BgGreen} watcher ${console_1.Colors.Reset} Watch
|
|
289
|
+
time.end(` ${console_1.Colors.BgGreen} watcher ${console_1.Colors.Reset} Client Watch started`);
|
|
293
290
|
}
|
|
294
291
|
},
|
|
295
292
|
executeInstrumentation: () => {
|
|
@@ -303,7 +300,6 @@ function hweb(options) {
|
|
|
303
300
|
if (instrumentation.hotReloadListener && typeof instrumentation.hotReloadListener === 'function') {
|
|
304
301
|
if (hotReloadManager) {
|
|
305
302
|
hotReloadManager.setHotReloadListener(instrumentation.hotReloadListener);
|
|
306
|
-
console_1.default.info('✅ Hot reload listener registrado');
|
|
307
303
|
}
|
|
308
304
|
}
|
|
309
305
|
if (typeof instrumentation === 'function') {
|
|
@@ -313,7 +309,7 @@ function hweb(options) {
|
|
|
313
309
|
instrumentation.default();
|
|
314
310
|
}
|
|
315
311
|
else {
|
|
316
|
-
console_1.default.warn(`
|
|
312
|
+
console_1.default.warn(`The instrumentation file ${instrumentationFile} does not export a default function.`);
|
|
317
313
|
}
|
|
318
314
|
}
|
|
319
315
|
},
|
|
@@ -420,8 +416,8 @@ function hweb(options) {
|
|
|
420
416
|
}
|
|
421
417
|
}
|
|
422
418
|
catch (error) {
|
|
423
|
-
console_1.default.error(`
|
|
424
|
-
genericRes.status(500).text('
|
|
419
|
+
console_1.default.error(`API route error ${pathname}:`, error);
|
|
420
|
+
genericRes.status(500).text('Internal server error in API');
|
|
425
421
|
return;
|
|
426
422
|
}
|
|
427
423
|
}
|
|
@@ -446,8 +442,8 @@ function hweb(options) {
|
|
|
446
442
|
return;
|
|
447
443
|
}
|
|
448
444
|
catch (error) {
|
|
449
|
-
console_1.default.error(`
|
|
450
|
-
genericRes.status(404).text('
|
|
445
|
+
console_1.default.error(`Error rendering page 404:`, error);
|
|
446
|
+
genericRes.status(404).text('Page not found');
|
|
451
447
|
return;
|
|
452
448
|
}
|
|
453
449
|
}
|
|
@@ -461,8 +457,8 @@ function hweb(options) {
|
|
|
461
457
|
genericRes.status(200).header('Content-Type', 'text/html').send(html);
|
|
462
458
|
}
|
|
463
459
|
catch (error) {
|
|
464
|
-
console_1.default.error(`
|
|
465
|
-
genericRes.status(500).text('
|
|
460
|
+
console_1.default.error(`Error rendering page ${pathname}:`, error);
|
|
461
|
+
genericRes.status(500).text('Internal server error');
|
|
466
462
|
}
|
|
467
463
|
};
|
|
468
464
|
},
|
|
@@ -474,16 +470,6 @@ function hweb(options) {
|
|
|
474
470
|
// Usa o sistema coordenado de WebSocket upgrade que integra hot-reload e rotas de usuário
|
|
475
471
|
(0, router_1.setupWebSocketUpgrade)(actualServer, hotReloadManager);
|
|
476
472
|
},
|
|
477
|
-
build: async () => {
|
|
478
|
-
const msg = console_1.default.dynamicLine(` ${console_1.Colors.FgYellow}● ${console_1.Colors.Reset}Iniciando build do cliente para produção`);
|
|
479
|
-
const outDir = path_1.default.join(dir, 'hweb-dist');
|
|
480
|
-
fs_1.default.mkdirSync(outDir, { recursive: true });
|
|
481
|
-
const routes = (0, router_1.loadRoutes)(userWebRoutesDir);
|
|
482
|
-
const entryPoint = createEntryFile(dir, routes);
|
|
483
|
-
const outfile = path_1.default.join(outDir, 'main.js');
|
|
484
|
-
await (0, builder_1.build)(entryPoint, outfile, true); // Força produção no build manual
|
|
485
|
-
msg.end(` ${console_1.Colors.FgGreen}● ${console_1.Colors.Reset}Build do cliente concluído: ${outfile}`);
|
|
486
|
-
},
|
|
487
473
|
stop: () => {
|
|
488
474
|
if (hotReloadManager) {
|
|
489
475
|
hotReloadManager.stop();
|