hightjs 0.1.1

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.
Files changed (131) hide show
  1. package/.idea/HightJS.iml +9 -0
  2. package/.idea/copilot.data.migration.agent.xml +6 -0
  3. package/.idea/copilot.data.migration.ask.xml +6 -0
  4. package/.idea/copilot.data.migration.ask2agent.xml +6 -0
  5. package/.idea/copilot.data.migration.edit.xml +6 -0
  6. package/.idea/inspectionProfiles/Project_Default.xml +13 -0
  7. package/.idea/libraries/test_package.xml +9 -0
  8. package/.idea/libraries/ts_commonjs_default_export.xml +9 -0
  9. package/.idea/misc.xml +7 -0
  10. package/.idea/modules.xml +8 -0
  11. package/.idea/vcs.xml +6 -0
  12. package/LICENSE +13 -0
  13. package/README.md +508 -0
  14. package/dist/adapters/express.d.ts +7 -0
  15. package/dist/adapters/express.js +63 -0
  16. package/dist/adapters/factory.d.ts +23 -0
  17. package/dist/adapters/factory.js +122 -0
  18. package/dist/adapters/fastify.d.ts +25 -0
  19. package/dist/adapters/fastify.js +61 -0
  20. package/dist/adapters/native.d.ts +8 -0
  21. package/dist/adapters/native.js +203 -0
  22. package/dist/adapters/starters/express.d.ts +0 -0
  23. package/dist/adapters/starters/express.js +1 -0
  24. package/dist/adapters/starters/factory.d.ts +0 -0
  25. package/dist/adapters/starters/factory.js +1 -0
  26. package/dist/adapters/starters/fastify.d.ts +0 -0
  27. package/dist/adapters/starters/fastify.js +1 -0
  28. package/dist/adapters/starters/index.d.ts +0 -0
  29. package/dist/adapters/starters/index.js +1 -0
  30. package/dist/adapters/starters/native.d.ts +0 -0
  31. package/dist/adapters/starters/native.js +1 -0
  32. package/dist/api/console.d.ts +92 -0
  33. package/dist/api/console.js +276 -0
  34. package/dist/api/http.d.ts +180 -0
  35. package/dist/api/http.js +467 -0
  36. package/dist/auth/client.d.ts +14 -0
  37. package/dist/auth/client.js +68 -0
  38. package/dist/auth/components.d.ts +29 -0
  39. package/dist/auth/components.js +84 -0
  40. package/dist/auth/core.d.ts +38 -0
  41. package/dist/auth/core.js +124 -0
  42. package/dist/auth/index.d.ts +7 -0
  43. package/dist/auth/index.js +27 -0
  44. package/dist/auth/jwt.d.ts +41 -0
  45. package/dist/auth/jwt.js +169 -0
  46. package/dist/auth/providers.d.ts +5 -0
  47. package/dist/auth/providers.js +14 -0
  48. package/dist/auth/react/index.d.ts +6 -0
  49. package/dist/auth/react/index.js +32 -0
  50. package/dist/auth/react.d.ts +22 -0
  51. package/dist/auth/react.js +175 -0
  52. package/dist/auth/routes.d.ts +16 -0
  53. package/dist/auth/routes.js +104 -0
  54. package/dist/auth/types.d.ts +62 -0
  55. package/dist/auth/types.js +2 -0
  56. package/dist/bin/hightjs.d.ts +2 -0
  57. package/dist/bin/hightjs.js +35 -0
  58. package/dist/builder.d.ts +32 -0
  59. package/dist/builder.js +341 -0
  60. package/dist/client/DefaultNotFound.d.ts +1 -0
  61. package/dist/client/DefaultNotFound.js +53 -0
  62. package/dist/client/ErrorBoundary.d.ts +16 -0
  63. package/dist/client/ErrorBoundary.js +181 -0
  64. package/dist/client/clientRouter.d.ts +58 -0
  65. package/dist/client/clientRouter.js +116 -0
  66. package/dist/client/entry.client.d.ts +1 -0
  67. package/dist/client/entry.client.js +271 -0
  68. package/dist/client/routerContext.d.ts +26 -0
  69. package/dist/client/routerContext.js +62 -0
  70. package/dist/client.d.ts +3 -0
  71. package/dist/client.js +8 -0
  72. package/dist/components/Link.d.ts +7 -0
  73. package/dist/components/Link.js +13 -0
  74. package/dist/eslint/index.d.ts +32 -0
  75. package/dist/eslint/index.js +15 -0
  76. package/dist/eslint/use-client-rule.d.ts +19 -0
  77. package/dist/eslint/use-client-rule.js +99 -0
  78. package/dist/eslintSetup.d.ts +0 -0
  79. package/dist/eslintSetup.js +1 -0
  80. package/dist/example/src/web/routes/index.d.ts +3 -0
  81. package/dist/example/src/web/routes/index.js +15 -0
  82. package/dist/helpers.d.ts +18 -0
  83. package/dist/helpers.js +318 -0
  84. package/dist/hotReload.d.ts +23 -0
  85. package/dist/hotReload.js +292 -0
  86. package/dist/index.d.ts +17 -0
  87. package/dist/index.js +480 -0
  88. package/dist/renderer.d.ts +14 -0
  89. package/dist/renderer.js +106 -0
  90. package/dist/router.d.ts +78 -0
  91. package/dist/router.js +359 -0
  92. package/dist/types/framework.d.ts +37 -0
  93. package/dist/types/framework.js +2 -0
  94. package/dist/types.d.ts +43 -0
  95. package/dist/types.js +2 -0
  96. package/dist/typescript/use-client-plugin.d.ts +5 -0
  97. package/dist/typescript/use-client-plugin.js +113 -0
  98. package/dist/validation.d.ts +0 -0
  99. package/dist/validation.js +1 -0
  100. package/package.json +72 -0
  101. package/src/adapters/express.ts +70 -0
  102. package/src/adapters/factory.ts +96 -0
  103. package/src/adapters/fastify.ts +88 -0
  104. package/src/adapters/native.ts +223 -0
  105. package/src/api/console.ts +285 -0
  106. package/src/api/http.ts +515 -0
  107. package/src/auth/client.ts +74 -0
  108. package/src/auth/components.tsx +109 -0
  109. package/src/auth/core.ts +143 -0
  110. package/src/auth/index.ts +9 -0
  111. package/src/auth/jwt.ts +194 -0
  112. package/src/auth/providers.ts +13 -0
  113. package/src/auth/react/index.ts +9 -0
  114. package/src/auth/react.tsx +209 -0
  115. package/src/auth/routes.ts +133 -0
  116. package/src/auth/types.ts +73 -0
  117. package/src/bin/hightjs.js +40 -0
  118. package/src/builder.js +362 -0
  119. package/src/client/DefaultNotFound.tsx +68 -0
  120. package/src/client/clientRouter.ts +137 -0
  121. package/src/client/entry.client.tsx +302 -0
  122. package/src/client.ts +8 -0
  123. package/src/components/Link.tsx +22 -0
  124. package/src/helpers.ts +316 -0
  125. package/src/hotReload.ts +289 -0
  126. package/src/index.ts +514 -0
  127. package/src/renderer.tsx +122 -0
  128. package/src/router.ts +400 -0
  129. package/src/types/framework.ts +42 -0
  130. package/src/types.ts +54 -0
  131. package/tsconfig.json +17 -0
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAuthRoutes = createAuthRoutes;
4
+ const http_1 = require("../api/http");
5
+ const core_1 = require("./core");
6
+ /**
7
+ * Cria o handler catch-all para /api/auth/[...value]
8
+ */
9
+ function createAuthRoutes(config) {
10
+ const auth = new core_1.HWebAuth(config);
11
+ /**
12
+ * Handler principal que gerencia todas as rotas de auth
13
+ * Uso: /api/auth/[...value].ts
14
+ */
15
+ return {
16
+ pattern: '/api/auth/[value]',
17
+ async GET(req, params) {
18
+ const path = params["value"];
19
+ const route = Array.isArray(path) ? path.join('/') : path || '';
20
+ switch (route) {
21
+ case 'session':
22
+ return await handleSession(req, auth);
23
+ case 'csrf':
24
+ return await handleCsrf(req);
25
+ case 'providers':
26
+ return await handleProviders(config);
27
+ default:
28
+ return http_1.HightJSResponse.json({ error: 'Route not found' }, { status: 404 });
29
+ }
30
+ },
31
+ async POST(req, params) {
32
+ const path = params["value"];
33
+ const route = Array.isArray(path) ? path.join('/') : path || '';
34
+ switch (route) {
35
+ case 'signin':
36
+ return await handleSignIn(req, auth);
37
+ case 'signout':
38
+ return await handleSignOut(req, auth);
39
+ default:
40
+ return http_1.HightJSResponse.json({ error: 'Route not found' }, { status: 404 });
41
+ }
42
+ },
43
+ // Instância do auth para uso manual
44
+ auth
45
+ };
46
+ }
47
+ /**
48
+ * Handler para GET /api/auth/session
49
+ */
50
+ async function handleSession(req, auth) {
51
+ const session = await auth.getSession(req);
52
+ if (!session) {
53
+ return http_1.HightJSResponse.json({ session: null });
54
+ }
55
+ return http_1.HightJSResponse.json({ session });
56
+ }
57
+ /**
58
+ * Handler para GET /api/auth/csrf
59
+ */
60
+ async function handleCsrf(req) {
61
+ // Token CSRF simples para proteção
62
+ const csrfToken = Math.random().toString(36).substring(2, 15) +
63
+ Math.random().toString(36).substring(2, 15);
64
+ return http_1.HightJSResponse.json({ csrfToken });
65
+ }
66
+ /**
67
+ * Handler para GET /api/auth/providers
68
+ */
69
+ async function handleProviders(config) {
70
+ const providers = config.providers
71
+ .filter(p => p.type === 'credentials') // Apenas credentials
72
+ .map(p => ({
73
+ id: p.id,
74
+ name: p.name,
75
+ type: p.type
76
+ }));
77
+ return http_1.HightJSResponse.json({ providers });
78
+ }
79
+ /**
80
+ * Handler para POST /api/auth/signin
81
+ */
82
+ async function handleSignIn(req, auth) {
83
+ try {
84
+ const { provider = 'credentials', ...credentials } = await req.json();
85
+ // Apenas credentials agora
86
+ const result = await auth.signIn(provider, credentials);
87
+ if (!result) {
88
+ return http_1.HightJSResponse.json({ error: 'Invalid credentials' }, { status: 401 });
89
+ }
90
+ return auth.createAuthResponse(result.token, {
91
+ success: true,
92
+ user: result.session.user
93
+ });
94
+ }
95
+ catch (error) {
96
+ return http_1.HightJSResponse.json({ error: 'Authentication failed' }, { status: 500 });
97
+ }
98
+ }
99
+ /**
100
+ * Handler para POST /api/auth/signout
101
+ */
102
+ async function handleSignOut(req, auth) {
103
+ return auth.signOut();
104
+ }
@@ -0,0 +1,62 @@
1
+ export type User = Record<string, any>;
2
+ export interface Session {
3
+ user: User;
4
+ expires: string;
5
+ accessToken?: string;
6
+ }
7
+ export interface AuthConfig {
8
+ providers: AuthProvider[];
9
+ pages?: {
10
+ signIn?: string;
11
+ signOut?: string;
12
+ error?: string;
13
+ };
14
+ callbacks?: {
15
+ signIn?: (user: User, account: any, profile: any) => boolean | Promise<boolean>;
16
+ session?: (session: Session, user: User) => Session | Promise<Session>;
17
+ jwt?: (token: any, user: User, account: any, profile: any) => any | Promise<any>;
18
+ };
19
+ session?: {
20
+ strategy?: 'jwt' | 'database';
21
+ maxAge?: number;
22
+ updateAge?: number;
23
+ };
24
+ secret?: string;
25
+ debug?: boolean;
26
+ }
27
+ export interface AuthProvider {
28
+ id: string;
29
+ name: string;
30
+ type: 'credentials';
31
+ authorize?: (credentials: Record<string, string>) => Promise<User | null> | User | null;
32
+ }
33
+ export interface SignInOptions {
34
+ redirect?: boolean;
35
+ callbackUrl?: string;
36
+ [key: string]: any;
37
+ }
38
+ export interface SignInResult {
39
+ error?: string;
40
+ status?: number;
41
+ ok?: boolean;
42
+ url?: string;
43
+ }
44
+ export interface SessionContextType {
45
+ data: Session | null;
46
+ status: 'loading' | 'authenticated' | 'unauthenticated';
47
+ signIn: (provider?: string, options?: SignInOptions) => Promise<SignInResult | undefined>;
48
+ signOut: (options?: {
49
+ callbackUrl?: string;
50
+ }) => Promise<void>;
51
+ update: () => Promise<Session | null>;
52
+ }
53
+ export interface CredentialsConfig {
54
+ id?: string;
55
+ name?: string;
56
+ credentials: Record<string, {
57
+ label: string;
58
+ type: string;
59
+ placeholder?: string;
60
+ }>;
61
+ authorize: (credentials: Record<string, string>) => Promise<User | null> | User | null;
62
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ // Registra o ts-node para que o Node.js entenda TypeScript/TSX
4
+ require('ts-node').register();
5
+ const { program } = require('commander');
6
+ const teste = require("../helpers");
7
+ program
8
+ .version('1.0.0')
9
+ .description('CLI para gerenciar a aplicação.');
10
+ // --- Comando DEV ---
11
+ program
12
+ .command('dev')
13
+ .description('Inicia a aplicação em modo de desenvolvimento.')
14
+ .option('-p, --port <number>', 'Especifica a porta para rodar', '3000')
15
+ .option('-H, --hostname <string>', 'Especifica o hostname para rodar', '0.0.0.0')
16
+ .option('-f, --framework <string>', 'Especifica o framework a ser usado (native/express/fastify)', 'native')
17
+ .action((options) => {
18
+ const teste = require("../helpers");
19
+ const t = teste.default({ dev: true, port: options.port, hostname: options.hostname, framework: options.framework });
20
+ t.init();
21
+ });
22
+ // --- Comando START (Produção) ---
23
+ program
24
+ .command('start')
25
+ .description('Inicia a aplicação em modo produção.')
26
+ .option('-p, --port <number>', 'Especifica a porta para rodar', '3000')
27
+ .option('-H, --hostname <string>', 'Especifica o hostname para rodar', '0.0.0.0')
28
+ .option('-f, --framework <string>', 'Especifica o framework a ser usado (native/express/fastify)', 'native')
29
+ .action((options) => {
30
+ const teste = require("../helpers");
31
+ const t = teste.default({ dev: false, port: options.port, hostname: options.hostname, framework: options.framework });
32
+ t.init();
33
+ });
34
+ // Faz o "parse" dos argumentos passados na linha de comando
35
+ program.parse(process.argv);
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Builds a single entry point into a single output file.
3
+ * @param {string} entryPoint - The path to the entry file.
4
+ * @param {string} outfile - The full path to the output file.
5
+ * @param {boolean} isProduction - Se está em modo produção ou não.
6
+ * @returns {Promise<void>}
7
+ */
8
+ export function build(entryPoint: string, outfile: string, isProduction?: boolean): Promise<void>;
9
+ /**
10
+ * Watches an entry point and its dependencies, rebuilding to a single output file.
11
+ * @param {string} entryPoint - The path to the entry file.
12
+ * @param {string} outfile - The full path to the output file.
13
+ * @param {Object} hotReloadManager - Manager de hot reload (opcional).
14
+ * @returns {Promise<void>}
15
+ */
16
+ export function watch(entryPoint: string, outfile: string, hotReloadManager?: Object): Promise<void>;
17
+ /**
18
+ * Builds with code splitting into multiple chunks based on module types.
19
+ * @param {string} entryPoint - The path to the entry file.
20
+ * @param {string} outdir - The directory for output files.
21
+ * @param {boolean} isProduction - Se está em modo produção ou não.
22
+ * @returns {Promise<void>}
23
+ */
24
+ export function buildWithChunks(entryPoint: string, outdir: string, isProduction?: boolean): Promise<void>;
25
+ /**
26
+ * Watches with code splitting enabled
27
+ * @param {string} entryPoint - The path to the entry file.
28
+ * @param {string} outdir - The directory for output files.
29
+ * @param {Object} hotReloadManager - Manager de hot reload (opcional).
30
+ * @returns {Promise<void>}
31
+ */
32
+ export function watchWithChunks(entryPoint: string, outdir: string, hotReloadManager?: Object): Promise<void>;
@@ -0,0 +1,341 @@
1
+ "use strict";
2
+ const esbuild = require('esbuild');
3
+ const path = require('path');
4
+ const Console = require("./api/console");
5
+ // Lista de módulos nativos do Node.js para marcar como externos (apenas os built-ins do Node)
6
+ const nodeBuiltIns = [
7
+ 'assert', 'buffer', 'child_process', 'cluster', 'crypto', 'dgram', 'dns',
8
+ 'domain', 'events', 'fs', 'http', 'https', 'net', 'os', 'path', 'punycode',
9
+ 'querystring', 'readline', 'stream', 'string_decoder', 'tls', 'tty', 'url',
10
+ 'util', 'v8', 'vm', 'zlib', 'module', 'worker_threads', 'perf_hooks'
11
+ ];
12
+ /**
13
+ * Plugin para processar CSS com PostCSS e Tailwind
14
+ */
15
+ const postcssPlugin = {
16
+ name: 'postcss-plugin',
17
+ setup(build) {
18
+ build.onLoad({ filter: /\.css$/ }, async (args) => {
19
+ const fs = require('fs');
20
+ const path = require('path');
21
+ try {
22
+ // Lê o CSS original
23
+ let css = await fs.promises.readFile(args.path, 'utf8');
24
+ // Verifica se tem PostCSS config no projeto
25
+ const projectDir = process.cwd();
26
+ const postcssConfigPath = path.join(projectDir, 'postcss.config.js');
27
+ const postcssConfigMjsPath = path.join(projectDir, 'postcss.config.mjs');
28
+ let processedCss = css;
29
+ if (fs.existsSync(postcssConfigPath) || fs.existsSync(postcssConfigMjsPath)) {
30
+ try {
31
+ // Importa PostCSS do projeto (não do SDK)
32
+ const postcssPath = path.join(projectDir, 'node_modules', 'postcss');
33
+ const postcss = require(postcssPath);
34
+ // Carrega a config do PostCSS
35
+ const configPath = fs.existsSync(postcssConfigPath) ? postcssConfigPath : postcssConfigMjsPath;
36
+ delete require.cache[require.resolve(configPath)];
37
+ const config = require(configPath);
38
+ const postcssConfig = config.default || config;
39
+ // Resolve plugins do projeto
40
+ const plugins = [];
41
+ if (postcssConfig.plugins) {
42
+ if (Array.isArray(postcssConfig.plugins)) {
43
+ // Formato array: ["@tailwindcss/postcss"]
44
+ plugins.push(...postcssConfig.plugins.map(plugin => {
45
+ if (typeof plugin === 'string') {
46
+ try {
47
+ // Tenta resolver do node_modules do projeto primeiro
48
+ return require.resolve(plugin, { paths: [projectDir] });
49
+ }
50
+ catch {
51
+ // Fallback para require direto
52
+ return require(plugin);
53
+ }
54
+ }
55
+ return plugin;
56
+ }));
57
+ }
58
+ else {
59
+ // Formato objeto: { tailwindcss: {}, autoprefixer: {} }
60
+ for (const [pluginName, pluginOptions] of Object.entries(postcssConfig.plugins)) {
61
+ try {
62
+ // Resolve o plugin do projeto
63
+ const resolvedPath = require.resolve(pluginName, { paths: [projectDir] });
64
+ const pluginModule = require(resolvedPath);
65
+ plugins.push(pluginModule(pluginOptions || {}));
66
+ }
67
+ catch (error) {
68
+ Console.warn(`Não foi possível carregar plugin ${pluginName}:`, error.message);
69
+ }
70
+ }
71
+ }
72
+ }
73
+ // Processa o CSS com PostCSS
74
+ const result = await postcss(plugins)
75
+ .process(css, {
76
+ from: args.path,
77
+ to: args.path.replace(/\.css$/, '.processed.css')
78
+ });
79
+ processedCss = result.css;
80
+ }
81
+ catch (postcssError) {
82
+ Console.warn(`Erro ao processar CSS com PostCSS:`, postcssError.message);
83
+ Console.warn(`Usando CSS original sem processamento.`);
84
+ }
85
+ }
86
+ return {
87
+ contents: `
88
+ const css = ${JSON.stringify(processedCss)};
89
+ if (typeof document !== 'undefined') {
90
+ const style = document.createElement('style');
91
+ style.textContent = css;
92
+ document.head.appendChild(style);
93
+ }
94
+ export default css;
95
+ `,
96
+ loader: 'js'
97
+ };
98
+ }
99
+ catch (error) {
100
+ Console.error(`Erro ao processar CSS ${args.path}:`, error);
101
+ return {
102
+ contents: `export default "";`,
103
+ loader: 'js'
104
+ };
105
+ }
106
+ });
107
+ }
108
+ };
109
+ /**
110
+ * Plugin para resolver dependências npm no frontend
111
+ */
112
+ const npmDependenciesPlugin = {
113
+ name: 'npm-dependencies',
114
+ setup(build) {
115
+ // Permite que dependências npm sejam bundladas (não marcadas como external)
116
+ build.onResolve({ filter: /^[^./]/ }, (args) => {
117
+ // Se for um módulo built-in do Node.js, marca como external
118
+ if (nodeBuiltIns.includes(args.path)) {
119
+ return { path: args.path, external: true };
120
+ }
121
+ // Para dependências npm (axios, lodash, react, react-dom, etc), deixa o esbuild resolver normalmente
122
+ // Isso permite que sejam bundladas no frontend
123
+ return null;
124
+ });
125
+ }
126
+ };
127
+ /**
128
+ * Plugin para garantir que React seja corretamente resolvido
129
+ */
130
+ const reactResolvePlugin = {
131
+ name: 'react-resolve',
132
+ setup(build) {
133
+ // Força o uso de uma única instância do React do projeto
134
+ build.onResolve({ filter: /^react$/ }, (args) => {
135
+ const reactPath = require.resolve('react', { paths: [process.cwd()] });
136
+ return {
137
+ path: reactPath
138
+ };
139
+ });
140
+ build.onResolve({ filter: /^react-dom$/ }, (args) => {
141
+ const reactDomPath = require.resolve('react-dom', { paths: [process.cwd()] });
142
+ return {
143
+ path: reactDomPath
144
+ };
145
+ });
146
+ build.onResolve({ filter: /^react\/jsx-runtime$/ }, (args) => {
147
+ const jsxRuntimePath = require.resolve('react/jsx-runtime', { paths: [process.cwd()] });
148
+ return {
149
+ path: jsxRuntimePath
150
+ };
151
+ });
152
+ // Também resolve react-dom/client para React 18+
153
+ build.onResolve({ filter: /^react-dom\/client$/ }, (args) => {
154
+ const clientPath = require.resolve('react-dom/client', { paths: [process.cwd()] });
155
+ return {
156
+ path: clientPath
157
+ };
158
+ });
159
+ }
160
+ };
161
+ /**
162
+ * Builds with code splitting into multiple chunks based on module types.
163
+ * @param {string} entryPoint - The path to the entry file.
164
+ * @param {string} outdir - The directory for output files.
165
+ * @param {boolean} isProduction - Se está em modo produção ou não.
166
+ * @returns {Promise<void>}
167
+ */
168
+ async function buildWithChunks(entryPoint, outdir, isProduction = false) {
169
+ if (!isProduction) {
170
+ console.log(`Iniciando o build com chunks de \"${entryPoint}\"...`);
171
+ }
172
+ try {
173
+ await esbuild.build({
174
+ entryPoints: [entryPoint],
175
+ bundle: true,
176
+ minify: isProduction,
177
+ sourcemap: !isProduction,
178
+ platform: 'browser',
179
+ outdir: outdir,
180
+ loader: { '.js': 'jsx', '.ts': 'tsx' },
181
+ external: nodeBuiltIns,
182
+ plugins: [postcssPlugin, npmDependenciesPlugin, reactResolvePlugin],
183
+ format: 'esm', // ESM suporta melhor o code splitting
184
+ jsx: 'automatic',
185
+ define: {
186
+ 'process.env.NODE_ENV': isProduction ? '"production"' : '"development"'
187
+ },
188
+ conditions: ['development'],
189
+ mainFields: ['browser', 'module', 'main'],
190
+ resolveExtensions: ['.tsx', '.ts', '.jsx', '.js'],
191
+ splitting: true,
192
+ chunkNames: 'chunks/[name]-[hash]',
193
+ // Força o nome do entry para main(.js) ou main-[hash].js em prod
194
+ entryNames: isProduction ? 'main-[hash]' : 'main',
195
+ keepNames: true,
196
+ treeShaking: true,
197
+ });
198
+ if (!isProduction) {
199
+ console.log(`Build com chunks finalizado! Saída: \"${outdir}\".`);
200
+ }
201
+ }
202
+ catch (error) {
203
+ console.error('Ocorreu um erro durante o build com chunks:', error);
204
+ process.exit(1);
205
+ }
206
+ }
207
+ /**
208
+ * Watches with code splitting enabled
209
+ * @param {string} entryPoint - The path to the entry file.
210
+ * @param {string} outdir - The directory for output files.
211
+ * @param {Object} hotReloadManager - Manager de hot reload (opcional).
212
+ * @returns {Promise<void>}
213
+ */
214
+ async function watchWithChunks(entryPoint, outdir, hotReloadManager = null) {
215
+ try {
216
+ const context = await esbuild.context({
217
+ entryPoints: [entryPoint],
218
+ bundle: true,
219
+ minify: false,
220
+ sourcemap: true,
221
+ platform: 'browser',
222
+ outdir: outdir,
223
+ loader: { '.js': 'jsx', '.ts': 'tsx' },
224
+ external: nodeBuiltIns,
225
+ plugins: [postcssPlugin, npmDependenciesPlugin, reactResolvePlugin],
226
+ format: 'esm',
227
+ jsx: 'automatic',
228
+ define: {
229
+ 'process.env.NODE_ENV': '"development"'
230
+ },
231
+ conditions: ['development'],
232
+ mainFields: ['browser', 'module', 'main'],
233
+ resolveExtensions: ['.tsx', '.ts', '.jsx', '.js'],
234
+ splitting: true,
235
+ chunkNames: 'chunks/[name]-[hash]',
236
+ entryNames: 'main',
237
+ keepNames: true,
238
+ treeShaking: true,
239
+ });
240
+ await context.watch();
241
+ }
242
+ catch (error) {
243
+ console.error(error);
244
+ Console.error('Erro ao iniciar o modo watch com chunks:', error);
245
+ throw error;
246
+ }
247
+ }
248
+ /**
249
+ * Builds a single entry point into a single output file.
250
+ * @param {string} entryPoint - The path to the entry file.
251
+ * @param {string} outfile - The full path to the output file.
252
+ * @param {boolean} isProduction - Se está em modo produção ou não.
253
+ * @returns {Promise<void>}
254
+ */
255
+ async function build(entryPoint, outfile, isProduction = false) {
256
+ if (!isProduction) {
257
+ console.log(`Iniciando o build de \"${entryPoint}\"...`);
258
+ }
259
+ try {
260
+ await esbuild.build({
261
+ entryPoints: [entryPoint],
262
+ bundle: true,
263
+ minify: isProduction,
264
+ sourcemap: !isProduction, // Só gera sourcemap em dev
265
+ platform: 'browser',
266
+ outfile: outfile,
267
+ loader: { '.js': 'jsx', '.ts': 'tsx' },
268
+ external: nodeBuiltIns,
269
+ plugins: [postcssPlugin, npmDependenciesPlugin, reactResolvePlugin],
270
+ format: 'iife',
271
+ globalName: 'HwebApp',
272
+ jsx: 'automatic',
273
+ define: {
274
+ 'process.env.NODE_ENV': isProduction ? '"production"' : '"development"'
275
+ },
276
+ // Configurações específicas para React 19
277
+ conditions: ['development'],
278
+ mainFields: ['browser', 'module', 'main'],
279
+ resolveExtensions: ['.tsx', '.ts', '.jsx', '.js'],
280
+ // Garante que não há duplicação de dependências
281
+ splitting: false,
282
+ // Preserva nomes de funções e comportamento
283
+ keepNames: true,
284
+ // Remove otimizações que podem causar problemas com hooks
285
+ treeShaking: true,
286
+ drop: [], // Não remove nada automaticamente
287
+ });
288
+ if (!isProduction) {
289
+ console.log(`Build finalizado com sucesso! Saída: \"${outfile}\".`);
290
+ }
291
+ }
292
+ catch (error) {
293
+ console.error('Ocorreu um erro durante o build:', error);
294
+ process.exit(1);
295
+ }
296
+ }
297
+ /**
298
+ * Watches an entry point and its dependencies, rebuilding to a single output file.
299
+ * @param {string} entryPoint - The path to the entry file.
300
+ * @param {string} outfile - The full path to the output file.
301
+ * @param {Object} hotReloadManager - Manager de hot reload (opcional).
302
+ * @returns {Promise<void>}
303
+ */
304
+ async function watch(entryPoint, outfile, hotReloadManager = null) {
305
+ try {
306
+ const context = await esbuild.context({
307
+ entryPoints: [entryPoint],
308
+ bundle: true,
309
+ minify: false,
310
+ sourcemap: true,
311
+ platform: 'browser',
312
+ outfile: outfile,
313
+ loader: { '.js': 'jsx', '.ts': 'tsx' },
314
+ external: nodeBuiltIns,
315
+ plugins: [postcssPlugin, npmDependenciesPlugin, reactResolvePlugin],
316
+ format: 'iife',
317
+ globalName: 'HwebApp',
318
+ jsx: 'automatic',
319
+ define: {
320
+ 'process.env.NODE_ENV': '"development"'
321
+ },
322
+ // Configurações específicas para React 19 (mesmo que no build)
323
+ conditions: ['development'],
324
+ mainFields: ['browser', 'module', 'main'],
325
+ resolveExtensions: ['.tsx', '.ts', '.jsx', '.js'],
326
+ // Garante que não há duplicação de dependências
327
+ splitting: false,
328
+ // Preserva nomes de funções e comportamento
329
+ keepNames: true,
330
+ // Remove otimizações que podem causar problemas com hooks
331
+ treeShaking: true,
332
+ });
333
+ // Configura o watcher do esbuild
334
+ await context.watch();
335
+ }
336
+ catch (error) {
337
+ Console.error('Erro ao iniciar o modo watch:', error);
338
+ throw error;
339
+ }
340
+ }
341
+ module.exports = { build, watch, buildWithChunks, watchWithChunks };
@@ -0,0 +1 @@
1
+ export default function DefaultNotFound(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = DefaultNotFound;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ function DefaultNotFound() {
6
+ return ((0, jsx_runtime_1.jsx)("div", { style: {
7
+ fontFamily: 'system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"',
8
+ height: '100vh',
9
+ textAlign: 'center',
10
+ display: 'flex',
11
+ flexDirection: 'column',
12
+ alignItems: 'center',
13
+ justifyContent: 'center'
14
+ }, children: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("style", { dangerouslySetInnerHTML: {
15
+ __html: `
16
+ body {
17
+ color: #000;
18
+ /* Alterado de cor sólida para gradiente */
19
+ background: linear-gradient(to bottom, #e9e9e9, #ffffff);
20
+ margin: 0;
21
+ }
22
+
23
+ .next-error-h1 {
24
+ border-right: 1px solid rgba(0, 0, 0, .3);
25
+ }
26
+
27
+ @media (prefers-color-scheme: dark) {
28
+ body {
29
+ color: #fff;
30
+ /* Alterado de cor sólida para gradiente escuro */
31
+ background: linear-gradient(to bottom, #222, #000);
32
+ }
33
+
34
+ .next-error-h1 {
35
+ border-right: 1px solid rgba(255, 255, 255, .3);
36
+ }
37
+ }
38
+ `
39
+ } }), (0, jsx_runtime_1.jsx)("h1", { className: "next-error-h1", style: {
40
+ display: 'inline-block',
41
+ margin: '0px 20px 0px 0px',
42
+ padding: '0px 23px 0px 0px',
43
+ fontSize: '24px',
44
+ fontWeight: '500',
45
+ verticalAlign: 'top',
46
+ lineHeight: '49px'
47
+ }, children: "404" }), (0, jsx_runtime_1.jsx)("div", { style: { display: 'inline-block' }, children: (0, jsx_runtime_1.jsx)("h2", { style: {
48
+ fontSize: '14px',
49
+ fontWeight: '400',
50
+ lineHeight: '49px',
51
+ margin: '0px'
52
+ }, children: "Esta p\u00E1gina n\u00E3o pode ser achada." }) })] }) }));
53
+ }
@@ -0,0 +1,16 @@
1
+ import React, { Component, ErrorInfo, ReactNode } from 'react';
2
+ interface Props {
3
+ children: ReactNode;
4
+ }
5
+ interface State {
6
+ hasError: boolean;
7
+ error?: Error;
8
+ errorInfo?: ErrorInfo;
9
+ }
10
+ export declare class ErrorBoundary extends Component<Props, State> {
11
+ constructor(props: Props);
12
+ static getDerivedStateFromError(error: Error): State;
13
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
14
+ render(): string | number | boolean | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
15
+ }
16
+ export {};