hightjs 0.5.2 → 0.5.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/builder.js +8 -8
- package/dist/hotReload.js +4 -7
- package/dist/router.js +16 -24
- package/package.json +1 -1
- package/src/builder.js +8 -8
- package/src/hotReload.ts +4 -7
- package/src/router.ts +14 -26
package/dist/builder.js
CHANGED
|
@@ -366,7 +366,7 @@ async function buildWithChunks(entryPoint, outdir, isProduction = false) {
|
|
|
366
366
|
sourcemap: !isProduction,
|
|
367
367
|
platform: 'browser',
|
|
368
368
|
outdir: outdir,
|
|
369
|
-
loader: { '.js': '
|
|
369
|
+
loader: { '.js': 'js', '.ts': 'tsx' },
|
|
370
370
|
external: nodeBuiltIns,
|
|
371
371
|
plugins: [postcssPlugin, npmDependenciesPlugin, reactResolvePlugin, markdownPlugin, assetsPlugin],
|
|
372
372
|
format: 'esm', // ESM suporta melhor o code splitting
|
|
@@ -376,7 +376,7 @@ async function buildWithChunks(entryPoint, outdir, isProduction = false) {
|
|
|
376
376
|
},
|
|
377
377
|
conditions: ['development'],
|
|
378
378
|
mainFields: ['browser', 'module', 'main'],
|
|
379
|
-
resolveExtensions: ['.tsx', '.ts', '.
|
|
379
|
+
resolveExtensions: ['.tsx', '.ts', '.js'],
|
|
380
380
|
splitting: true,
|
|
381
381
|
chunkNames: 'chunks/[name]-[hash]',
|
|
382
382
|
// Força o nome do entry para main(.js) ou main-[hash].js em prod
|
|
@@ -427,7 +427,7 @@ async function watchWithChunks(entryPoint, outdir, hotReloadManager = null) {
|
|
|
427
427
|
sourcemap: true,
|
|
428
428
|
platform: 'browser',
|
|
429
429
|
outdir: outdir,
|
|
430
|
-
loader: { '.js': '
|
|
430
|
+
loader: { '.js': 'js', '.ts': 'tsx' },
|
|
431
431
|
external: nodeBuiltIns,
|
|
432
432
|
plugins: [postcssPlugin, npmDependenciesPlugin, reactResolvePlugin, hmrPlugin, buildCompletePlugin, markdownPlugin, assetsPlugin],
|
|
433
433
|
format: 'esm',
|
|
@@ -437,7 +437,7 @@ async function watchWithChunks(entryPoint, outdir, hotReloadManager = null) {
|
|
|
437
437
|
},
|
|
438
438
|
conditions: ['development'],
|
|
439
439
|
mainFields: ['browser', 'module', 'main'],
|
|
440
|
-
resolveExtensions: ['.tsx', '.ts', '.
|
|
440
|
+
resolveExtensions: ['.tsx', '.ts', '.js'],
|
|
441
441
|
splitting: true,
|
|
442
442
|
chunkNames: 'chunks/[name]-[hash]',
|
|
443
443
|
entryNames: 'main',
|
|
@@ -471,7 +471,7 @@ async function build(entryPoint, outfile, isProduction = false) {
|
|
|
471
471
|
sourcemap: !isProduction, // Só gera sourcemap em dev
|
|
472
472
|
platform: 'browser',
|
|
473
473
|
outfile: outfile,
|
|
474
|
-
loader: { '.js': '
|
|
474
|
+
loader: { '.js': 'js', '.ts': 'tsx' },
|
|
475
475
|
external: nodeBuiltIns,
|
|
476
476
|
plugins: [postcssPlugin, npmDependenciesPlugin, reactResolvePlugin, markdownPlugin, assetsPlugin],
|
|
477
477
|
format: 'iife',
|
|
@@ -483,7 +483,7 @@ async function build(entryPoint, outfile, isProduction = false) {
|
|
|
483
483
|
// Configurações específicas para React 19
|
|
484
484
|
conditions: ['development'],
|
|
485
485
|
mainFields: ['browser', 'module', 'main'],
|
|
486
|
-
resolveExtensions: ['.tsx', '.ts', '.
|
|
486
|
+
resolveExtensions: ['.tsx', '.ts', '.js'],
|
|
487
487
|
// Garante que não há duplicação de dependências
|
|
488
488
|
splitting: false,
|
|
489
489
|
// Preserva nomes de funções e comportamento
|
|
@@ -533,7 +533,7 @@ async function watch(entryPoint, outfile, hotReloadManager = null) {
|
|
|
533
533
|
sourcemap: true,
|
|
534
534
|
platform: 'browser',
|
|
535
535
|
outfile: outfile,
|
|
536
|
-
loader: { '.js': '
|
|
536
|
+
loader: { '.js': 'js', '.ts': 'tsx' },
|
|
537
537
|
external: nodeBuiltIns,
|
|
538
538
|
format: 'iife',
|
|
539
539
|
globalName: 'HwebApp',
|
|
@@ -544,7 +544,7 @@ async function watch(entryPoint, outfile, hotReloadManager = null) {
|
|
|
544
544
|
// Configurações específicas para React 19 (mesmo que no build)
|
|
545
545
|
conditions: ['development'],
|
|
546
546
|
mainFields: ['browser', 'module', 'main'],
|
|
547
|
-
resolveExtensions: ['.tsx', '.ts', '.
|
|
547
|
+
resolveExtensions: ['.tsx', '.ts', '.js'],
|
|
548
548
|
// Garante que não há duplicação de dependências
|
|
549
549
|
splitting: false,
|
|
550
550
|
// Preserva nomes de funções e comportamento
|
package/dist/hotReload.js
CHANGED
|
@@ -193,8 +193,7 @@ class HotReloadManager {
|
|
|
193
193
|
filePath.includes(path.join('src', 'web', 'components')) ||
|
|
194
194
|
filePath.includes('layout.tsx') ||
|
|
195
195
|
filePath.includes('not-found.tsx') ||
|
|
196
|
-
filePath.endsWith('.tsx')
|
|
197
|
-
filePath.endsWith('.jsx');
|
|
196
|
+
filePath.endsWith('.tsx');
|
|
198
197
|
const isBackendFile = filePath.includes(path.join('src', 'backend')) && !isFrontendFile;
|
|
199
198
|
// Limpa o cache do arquivo alterado
|
|
200
199
|
(0, router_1.clearFileCache)(filePath);
|
|
@@ -378,9 +377,7 @@ class HotReloadManager {
|
|
|
378
377
|
// Mudanças que exigem reload completo
|
|
379
378
|
const needsFullReload =
|
|
380
379
|
file.includes('layout.tsx') ||
|
|
381
|
-
file.includes('layout.jsx') ||
|
|
382
380
|
file.includes('not-found.tsx') ||
|
|
383
|
-
file.includes('not-found.jsx') ||
|
|
384
381
|
file.endsWith('.css');
|
|
385
382
|
|
|
386
383
|
if (needsFullReload) {
|
|
@@ -390,15 +387,15 @@ class HotReloadManager {
|
|
|
390
387
|
}
|
|
391
388
|
|
|
392
389
|
// Mudanças em rotas: tenta HMR
|
|
393
|
-
if (file.includes('/routes/') || file.includes('
|
|
390
|
+
if (file.includes('/routes/') || file.includes('routes')) {
|
|
394
391
|
console.log('⚡ Route component changed, hot reloading...');
|
|
395
|
-
|
|
392
|
+
|
|
396
393
|
// Dispara evento para forçar re-render
|
|
397
394
|
const event = new CustomEvent('hmr:component-update', {
|
|
398
395
|
detail: { file: data.file, timestamp: Date.now() }
|
|
399
396
|
});
|
|
400
397
|
window.dispatchEvent(event);
|
|
401
|
-
|
|
398
|
+
|
|
402
399
|
// Aguarda 500ms para ver se o HMR foi bem-sucedido
|
|
403
400
|
setTimeout(() => {
|
|
404
401
|
const hmrSuccess = window.__HMR_SUCCESS__;
|
package/dist/router.js
CHANGED
|
@@ -70,6 +70,7 @@ function clearRequireCache(filePath) {
|
|
|
70
70
|
// Arquivo pode não estar no cache ou não ser resolvível
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
+
// Nota: Suporte apenas para TypeScript (.ts, .tsx). Não tratamos .jsx aqui.
|
|
73
74
|
/**
|
|
74
75
|
* Limpa todo o cache de rotas carregadas
|
|
75
76
|
*/
|
|
@@ -111,12 +112,8 @@ function clearFileCache(changedFilePath) {
|
|
|
111
112
|
function loadLayout(webDir) {
|
|
112
113
|
const layoutPath = path_1.default.join(webDir, 'layout.tsx');
|
|
113
114
|
const layoutPathTs = path_1.default.join(webDir, 'layout.ts');
|
|
114
|
-
const layoutPathJsx = path_1.default.join(webDir, 'layout.jsx');
|
|
115
|
-
const layoutPathJs = path_1.default.join(webDir, 'layout.js');
|
|
116
115
|
const layoutFile = fs_1.default.existsSync(layoutPath) ? layoutPath :
|
|
117
|
-
fs_1.default.existsSync(layoutPathTs) ? layoutPathTs :
|
|
118
|
-
fs_1.default.existsSync(layoutPathJsx) ? layoutPathJsx :
|
|
119
|
-
fs_1.default.existsSync(layoutPathJs) ? layoutPathJs : null;
|
|
116
|
+
fs_1.default.existsSync(layoutPathTs) ? layoutPathTs : null;
|
|
120
117
|
if (layoutFile) {
|
|
121
118
|
const absolutePath = path_1.default.resolve(layoutFile);
|
|
122
119
|
const componentPath = path_1.default.relative(process.cwd(), layoutFile).replace(/\\/g, '/');
|
|
@@ -127,8 +124,10 @@ function loadLayout(webDir) {
|
|
|
127
124
|
.replace(/import\s+['"][^'"]*\.css['"];?/g, '// CSS import removido para servidor')
|
|
128
125
|
.replace(/import\s+['"][^'"]*\.scss['"];?/g, '// SCSS import removido para servidor')
|
|
129
126
|
.replace(/import\s+['"][^'"]*\.sass['"];?/g, '// SASS import removido para servidor');
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
// Escreve um arquivo temporário .temp.tsx ou .temp.ts sem imports de CSS
|
|
128
|
+
const ext = path_1.default.extname(layoutFile).toLowerCase();
|
|
129
|
+
const tempFile = layoutFile.replace(/\.(tsx|ts)$/i, '.temp.$1');
|
|
130
|
+
fs_1.default.writeFileSync(tempFile, tempContent, 'utf8');
|
|
132
131
|
// Otimização: limpa cache apenas se existir
|
|
133
132
|
try {
|
|
134
133
|
const resolvedPath = require.resolve(tempFile);
|
|
@@ -139,7 +138,10 @@ function loadLayout(webDir) {
|
|
|
139
138
|
catch { }
|
|
140
139
|
const layoutModule = require(tempFile);
|
|
141
140
|
// Remove o arquivo temporário
|
|
142
|
-
|
|
141
|
+
try {
|
|
142
|
+
fs_1.default.unlinkSync(tempFile);
|
|
143
|
+
}
|
|
144
|
+
catch { }
|
|
143
145
|
const metadata = layoutModule.metadata || null;
|
|
144
146
|
// Registra o arquivo como carregado
|
|
145
147
|
loadedLayoutFiles.add(absolutePath);
|
|
@@ -185,9 +187,8 @@ function loadRoutes(routesDir) {
|
|
|
185
187
|
scanDirectory(path_1.default.join(dir, entry.name), relativePath);
|
|
186
188
|
}
|
|
187
189
|
else if (entry.isFile()) {
|
|
188
|
-
// Filtra apenas arquivos .ts/.tsx
|
|
189
|
-
if (entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')
|
|
190
|
-
entry.name.endsWith('.js') || entry.name.endsWith('.jsx')) {
|
|
190
|
+
// Filtra apenas arquivos .ts/.tsx
|
|
191
|
+
if (entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')) {
|
|
191
192
|
routeFiles.push(relativePath);
|
|
192
193
|
}
|
|
193
194
|
}
|
|
@@ -265,15 +266,11 @@ let loadedMiddlewares = new Map();
|
|
|
265
266
|
*/
|
|
266
267
|
function loadMiddlewareFromDirectory(dir) {
|
|
267
268
|
const middlewares = [];
|
|
268
|
-
// Procura por middleware.ts, middleware.tsx
|
|
269
|
+
// Procura por middleware.ts, middleware.tsx
|
|
269
270
|
const middlewarePath = path_1.default.join(dir, 'middleware.ts');
|
|
270
271
|
const middlewarePathTsx = path_1.default.join(dir, 'middleware.tsx');
|
|
271
|
-
const middlewarePathJs = path_1.default.join(dir, 'middleware.js');
|
|
272
|
-
const middlewarePathJsx = path_1.default.join(dir, 'middleware.jsx');
|
|
273
272
|
const middlewareFile = fs_1.default.existsSync(middlewarePath) ? middlewarePath :
|
|
274
|
-
fs_1.default.existsSync(middlewarePathTsx) ? middlewarePathTsx :
|
|
275
|
-
fs_1.default.existsSync(middlewarePathJs) ? middlewarePathJs :
|
|
276
|
-
fs_1.default.existsSync(middlewarePathJsx) ? middlewarePathJsx : null;
|
|
273
|
+
fs_1.default.existsSync(middlewarePathTsx) ? middlewarePathTsx : null;
|
|
277
274
|
if (middlewareFile) {
|
|
278
275
|
try {
|
|
279
276
|
const absolutePath = path_1.default.resolve(middlewareFile);
|
|
@@ -340,8 +337,7 @@ function loadBackendRoutes(backendRoutesDir) {
|
|
|
340
337
|
scanDirectory(path_1.default.join(dir, entry.name), relativePath);
|
|
341
338
|
}
|
|
342
339
|
else if (entry.isFile()) {
|
|
343
|
-
const isSupported = entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')
|
|
344
|
-
entry.name.endsWith('.js') || entry.name.endsWith('.jsx');
|
|
340
|
+
const isSupported = entry.name.endsWith('.ts') || entry.name.endsWith('.tsx');
|
|
345
341
|
if (!isSupported)
|
|
346
342
|
continue;
|
|
347
343
|
// Identifica middlewares durante o scan
|
|
@@ -456,12 +452,8 @@ function findMatchingBackendRoute(pathname, method) {
|
|
|
456
452
|
function loadNotFound(webDir) {
|
|
457
453
|
const notFoundPath = path_1.default.join(webDir, 'notFound.tsx');
|
|
458
454
|
const notFoundPathTs = path_1.default.join(webDir, 'notFound.ts');
|
|
459
|
-
const notFoundPathJsx = path_1.default.join(webDir, 'notFound.jsx');
|
|
460
|
-
const notFoundPathJs = path_1.default.join(webDir, 'notFound.js');
|
|
461
455
|
const notFoundFile = fs_1.default.existsSync(notFoundPath) ? notFoundPath :
|
|
462
|
-
fs_1.default.existsSync(notFoundPathTs) ? notFoundPathTs :
|
|
463
|
-
fs_1.default.existsSync(notFoundPathJsx) ? notFoundPathJsx :
|
|
464
|
-
fs_1.default.existsSync(notFoundPathJs) ? notFoundPathJs : null;
|
|
456
|
+
fs_1.default.existsSync(notFoundPathTs) ? notFoundPathTs : null;
|
|
465
457
|
if (notFoundFile) {
|
|
466
458
|
const absolutePath = path_1.default.resolve(notFoundFile);
|
|
467
459
|
const componentPath = path_1.default.relative(process.cwd(), notFoundFile).replace(/\\/g, '/');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hightjs",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "HightJS is a high-level framework for building web applications with ease and speed. It provides a robust set of tools and features to streamline development and enhance productivity.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/builder.js
CHANGED
|
@@ -409,7 +409,7 @@ async function buildWithChunks(entryPoint, outdir, isProduction = false) {
|
|
|
409
409
|
sourcemap: !isProduction,
|
|
410
410
|
platform: 'browser',
|
|
411
411
|
outdir: outdir,
|
|
412
|
-
loader: { '.js': '
|
|
412
|
+
loader: { '.js': 'js', '.ts': 'tsx' },
|
|
413
413
|
external: nodeBuiltIns,
|
|
414
414
|
plugins: [postcssPlugin, npmDependenciesPlugin, reactResolvePlugin, markdownPlugin, assetsPlugin],
|
|
415
415
|
format: 'esm', // ESM suporta melhor o code splitting
|
|
@@ -419,7 +419,7 @@ async function buildWithChunks(entryPoint, outdir, isProduction = false) {
|
|
|
419
419
|
},
|
|
420
420
|
conditions: ['development'],
|
|
421
421
|
mainFields: ['browser', 'module', 'main'],
|
|
422
|
-
resolveExtensions: ['.tsx', '.ts', '.
|
|
422
|
+
resolveExtensions: ['.tsx', '.ts', '.js'],
|
|
423
423
|
splitting: true,
|
|
424
424
|
chunkNames: 'chunks/[name]-[hash]',
|
|
425
425
|
// Força o nome do entry para main(.js) ou main-[hash].js em prod
|
|
@@ -471,7 +471,7 @@ async function watchWithChunks(entryPoint, outdir, hotReloadManager = null) {
|
|
|
471
471
|
sourcemap: true,
|
|
472
472
|
platform: 'browser',
|
|
473
473
|
outdir: outdir,
|
|
474
|
-
loader: { '.js': '
|
|
474
|
+
loader: { '.js': 'js', '.ts': 'tsx' },
|
|
475
475
|
external: nodeBuiltIns,
|
|
476
476
|
plugins: [postcssPlugin, npmDependenciesPlugin, reactResolvePlugin, hmrPlugin, buildCompletePlugin, markdownPlugin, assetsPlugin],
|
|
477
477
|
format: 'esm',
|
|
@@ -481,7 +481,7 @@ async function watchWithChunks(entryPoint, outdir, hotReloadManager = null) {
|
|
|
481
481
|
},
|
|
482
482
|
conditions: ['development'],
|
|
483
483
|
mainFields: ['browser', 'module', 'main'],
|
|
484
|
-
resolveExtensions: ['.tsx', '.ts', '.
|
|
484
|
+
resolveExtensions: ['.tsx', '.ts', '.js'],
|
|
485
485
|
splitting: true,
|
|
486
486
|
chunkNames: 'chunks/[name]-[hash]',
|
|
487
487
|
entryNames: 'main',
|
|
@@ -517,7 +517,7 @@ async function build(entryPoint, outfile, isProduction = false) {
|
|
|
517
517
|
sourcemap: !isProduction, // Só gera sourcemap em dev
|
|
518
518
|
platform: 'browser',
|
|
519
519
|
outfile: outfile,
|
|
520
|
-
loader: { '.js': '
|
|
520
|
+
loader: { '.js': 'js', '.ts': 'tsx' },
|
|
521
521
|
external: nodeBuiltIns,
|
|
522
522
|
plugins: [postcssPlugin, npmDependenciesPlugin, reactResolvePlugin, markdownPlugin, assetsPlugin],
|
|
523
523
|
format: 'iife',
|
|
@@ -529,7 +529,7 @@ async function build(entryPoint, outfile, isProduction = false) {
|
|
|
529
529
|
// Configurações específicas para React 19
|
|
530
530
|
conditions: ['development'],
|
|
531
531
|
mainFields: ['browser', 'module', 'main'],
|
|
532
|
-
resolveExtensions: ['.tsx', '.ts', '.
|
|
532
|
+
resolveExtensions: ['.tsx', '.ts', '.js'],
|
|
533
533
|
// Garante que não há duplicação de dependências
|
|
534
534
|
splitting: false,
|
|
535
535
|
// Preserva nomes de funções e comportamento
|
|
@@ -580,7 +580,7 @@ async function watch(entryPoint, outfile, hotReloadManager = null) {
|
|
|
580
580
|
sourcemap: true,
|
|
581
581
|
platform: 'browser',
|
|
582
582
|
outfile: outfile,
|
|
583
|
-
loader: { '.js': '
|
|
583
|
+
loader: { '.js': 'js', '.ts': 'tsx' },
|
|
584
584
|
external: nodeBuiltIns,
|
|
585
585
|
format: 'iife',
|
|
586
586
|
globalName: 'HwebApp',
|
|
@@ -591,7 +591,7 @@ async function watch(entryPoint, outfile, hotReloadManager = null) {
|
|
|
591
591
|
// Configurações específicas para React 19 (mesmo que no build)
|
|
592
592
|
conditions: ['development'],
|
|
593
593
|
mainFields: ['browser', 'module', 'main'],
|
|
594
|
-
resolveExtensions: ['.tsx', '.ts', '.
|
|
594
|
+
resolveExtensions: ['.tsx', '.ts', '.js'],
|
|
595
595
|
// Garante que não há duplicação de dependências
|
|
596
596
|
splitting: false,
|
|
597
597
|
// Preserva nomes de funções e comportamento
|
package/src/hotReload.ts
CHANGED
|
@@ -192,8 +192,7 @@ export class HotReloadManager {
|
|
|
192
192
|
filePath.includes(path.join('src', 'web', 'components')) ||
|
|
193
193
|
filePath.includes('layout.tsx') ||
|
|
194
194
|
filePath.includes('not-found.tsx') ||
|
|
195
|
-
filePath.endsWith('.tsx')
|
|
196
|
-
filePath.endsWith('.jsx');
|
|
195
|
+
filePath.endsWith('.tsx');
|
|
197
196
|
|
|
198
197
|
const isBackendFile = filePath.includes(path.join('src', 'backend')) && !isFrontendFile;
|
|
199
198
|
|
|
@@ -393,9 +392,7 @@ export class HotReloadManager {
|
|
|
393
392
|
// Mudanças que exigem reload completo
|
|
394
393
|
const needsFullReload =
|
|
395
394
|
file.includes('layout.tsx') ||
|
|
396
|
-
file.includes('layout.jsx') ||
|
|
397
395
|
file.includes('not-found.tsx') ||
|
|
398
|
-
file.includes('not-found.jsx') ||
|
|
399
396
|
file.endsWith('.css');
|
|
400
397
|
|
|
401
398
|
if (needsFullReload) {
|
|
@@ -405,15 +402,15 @@ export class HotReloadManager {
|
|
|
405
402
|
}
|
|
406
403
|
|
|
407
404
|
// Mudanças em rotas: tenta HMR
|
|
408
|
-
if (file.includes('/routes/') || file.includes('
|
|
405
|
+
if (file.includes('/routes/') || file.includes('routes')) {
|
|
409
406
|
console.log('⚡ Route component changed, hot reloading...');
|
|
410
|
-
|
|
407
|
+
|
|
411
408
|
// Dispara evento para forçar re-render
|
|
412
409
|
const event = new CustomEvent('hmr:component-update', {
|
|
413
410
|
detail: { file: data.file, timestamp: Date.now() }
|
|
414
411
|
});
|
|
415
412
|
window.dispatchEvent(event);
|
|
416
|
-
|
|
413
|
+
|
|
417
414
|
// Aguarda 500ms para ver se o HMR foi bem-sucedido
|
|
418
415
|
setTimeout(() => {
|
|
419
416
|
const hmrSuccess = window.__HMR_SUCCESS__;
|
package/src/router.ts
CHANGED
|
@@ -61,6 +61,8 @@ function clearRequireCache(filePath: string) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
// Nota: Suporte apenas para TypeScript (.ts, .tsx). Não tratamos .jsx aqui.
|
|
65
|
+
|
|
64
66
|
/**
|
|
65
67
|
* Limpa todo o cache de rotas carregadas
|
|
66
68
|
*/
|
|
@@ -108,13 +110,8 @@ export function clearFileCache(changedFilePath: string) {
|
|
|
108
110
|
export function loadLayout(webDir: string): { componentPath: string; metadata?: any } | null {
|
|
109
111
|
const layoutPath = path.join(webDir, 'layout.tsx');
|
|
110
112
|
const layoutPathTs = path.join(webDir, 'layout.ts');
|
|
111
|
-
const layoutPathJsx = path.join(webDir, 'layout.jsx');
|
|
112
|
-
const layoutPathJs = path.join(webDir, 'layout.js');
|
|
113
|
-
|
|
114
113
|
const layoutFile = fs.existsSync(layoutPath) ? layoutPath :
|
|
115
|
-
fs.existsSync(layoutPathTs) ? layoutPathTs :
|
|
116
|
-
fs.existsSync(layoutPathJsx) ? layoutPathJsx :
|
|
117
|
-
fs.existsSync(layoutPathJs) ? layoutPathJs : null;
|
|
114
|
+
fs.existsSync(layoutPathTs) ? layoutPathTs : null;
|
|
118
115
|
|
|
119
116
|
if (layoutFile) {
|
|
120
117
|
const absolutePath = path.resolve(layoutFile);
|
|
@@ -128,8 +125,10 @@ export function loadLayout(webDir: string): { componentPath: string; metadata?:
|
|
|
128
125
|
.replace(/import\s+['"][^'"]*\.scss['"];?/g, '// SCSS import removido para servidor')
|
|
129
126
|
.replace(/import\s+['"][^'"]*\.sass['"];?/g, '// SASS import removido para servidor');
|
|
130
127
|
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
// Escreve um arquivo temporário .temp.tsx ou .temp.ts sem imports de CSS
|
|
129
|
+
const ext = path.extname(layoutFile).toLowerCase();
|
|
130
|
+
const tempFile = layoutFile.replace(/\.(tsx|ts)$/i, '.temp.$1');
|
|
131
|
+
fs.writeFileSync(tempFile, tempContent, 'utf8');
|
|
133
132
|
|
|
134
133
|
// Otimização: limpa cache apenas se existir
|
|
135
134
|
try {
|
|
@@ -142,7 +141,7 @@ export function loadLayout(webDir: string): { componentPath: string; metadata?:
|
|
|
142
141
|
const layoutModule = require(tempFile);
|
|
143
142
|
|
|
144
143
|
// Remove o arquivo temporário
|
|
145
|
-
fs.unlinkSync(tempFile);
|
|
144
|
+
try { fs.unlinkSync(tempFile); } catch {}
|
|
146
145
|
|
|
147
146
|
const metadata = layoutModule.metadata || null;
|
|
148
147
|
|
|
@@ -193,9 +192,8 @@ export function loadRoutes(routesDir: string): (RouteConfig & { componentPath: s
|
|
|
193
192
|
if (entry.name === 'backend') continue;
|
|
194
193
|
scanDirectory(path.join(dir, entry.name), relativePath);
|
|
195
194
|
} else if (entry.isFile()) {
|
|
196
|
-
// Filtra apenas arquivos .ts/.tsx
|
|
197
|
-
if (entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')
|
|
198
|
-
entry.name.endsWith('.js') || entry.name.endsWith('.jsx')) {
|
|
195
|
+
// Filtra apenas arquivos .ts/.tsx
|
|
196
|
+
if (entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')) {
|
|
199
197
|
routeFiles.push(relativePath);
|
|
200
198
|
}
|
|
201
199
|
}
|
|
@@ -288,16 +286,12 @@ let loadedMiddlewares: Map<string, HightMiddleware[]> = new Map();
|
|
|
288
286
|
function loadMiddlewareFromDirectory(dir: string): HightMiddleware[] {
|
|
289
287
|
const middlewares: HightMiddleware[] = [];
|
|
290
288
|
|
|
291
|
-
// Procura por middleware.ts, middleware.tsx
|
|
289
|
+
// Procura por middleware.ts, middleware.tsx
|
|
292
290
|
const middlewarePath = path.join(dir, 'middleware.ts');
|
|
293
291
|
const middlewarePathTsx = path.join(dir, 'middleware.tsx');
|
|
294
|
-
const middlewarePathJs = path.join(dir, 'middleware.js');
|
|
295
|
-
const middlewarePathJsx = path.join(dir, 'middleware.jsx');
|
|
296
292
|
|
|
297
293
|
const middlewareFile = fs.existsSync(middlewarePath) ? middlewarePath :
|
|
298
|
-
fs.existsSync(middlewarePathTsx) ? middlewarePathTsx :
|
|
299
|
-
fs.existsSync(middlewarePathJs) ? middlewarePathJs :
|
|
300
|
-
fs.existsSync(middlewarePathJsx) ? middlewarePathJsx : null;
|
|
294
|
+
fs.existsSync(middlewarePathTsx) ? middlewarePathTsx : null;
|
|
301
295
|
|
|
302
296
|
if (middlewareFile) {
|
|
303
297
|
try {
|
|
@@ -374,8 +368,7 @@ export function loadBackendRoutes(backendRoutesDir: string) {
|
|
|
374
368
|
if (entry.isDirectory()) {
|
|
375
369
|
scanDirectory(path.join(dir, entry.name), relativePath);
|
|
376
370
|
} else if (entry.isFile()) {
|
|
377
|
-
const isSupported = entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')
|
|
378
|
-
entry.name.endsWith('.js') || entry.name.endsWith('.jsx');
|
|
371
|
+
const isSupported = entry.name.endsWith('.ts') || entry.name.endsWith('.tsx');
|
|
379
372
|
if (!isSupported) continue;
|
|
380
373
|
|
|
381
374
|
// Identifica middlewares durante o scan
|
|
@@ -498,13 +491,8 @@ export function findMatchingBackendRoute(pathname: string, method: string) {
|
|
|
498
491
|
export function loadNotFound(webDir: string): { componentPath: string } | null {
|
|
499
492
|
const notFoundPath = path.join(webDir, 'notFound.tsx');
|
|
500
493
|
const notFoundPathTs = path.join(webDir, 'notFound.ts');
|
|
501
|
-
const notFoundPathJsx = path.join(webDir, 'notFound.jsx');
|
|
502
|
-
const notFoundPathJs = path.join(webDir, 'notFound.js');
|
|
503
|
-
|
|
504
494
|
const notFoundFile = fs.existsSync(notFoundPath) ? notFoundPath :
|
|
505
|
-
fs.existsSync(notFoundPathTs) ? notFoundPathTs :
|
|
506
|
-
fs.existsSync(notFoundPathJsx) ? notFoundPathJsx :
|
|
507
|
-
fs.existsSync(notFoundPathJs) ? notFoundPathJs : null;
|
|
495
|
+
fs.existsSync(notFoundPathTs) ? notFoundPathTs : null;
|
|
508
496
|
|
|
509
497
|
if (notFoundFile) {
|
|
510
498
|
const absolutePath = path.resolve(notFoundFile);
|