vatts 1.2.0-alpha.2 → 1.2.0-test.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 (2) hide show
  1. package/dist/loaders.js +25 -13
  2. package/package.json +1 -1
package/dist/loaders.js CHANGED
@@ -101,6 +101,8 @@ function registerLoaders(options = {}) {
101
101
  throw new Error('Para carregar arquivos .vue no servidor, você precisa instalar "vue" e "esbuild".');
102
102
  }
103
103
  const source = fs.readFileSync(filename, 'utf8');
104
+ // Variável para armazenar o código final para fins de debug
105
+ let finalEsm = '';
104
106
  try {
105
107
  // 1. Parse do SFC
106
108
  const { descriptor, errors } = sfcCompiler.parse(source, {
@@ -111,6 +113,7 @@ function registerLoaders(options = {}) {
111
113
  console.error(`Erro ao parsear ${filename}:`, errors);
112
114
  }
113
115
  // 2. Compilação do Script (<script> ou <script setup>)
116
+ // Padrão: Se não houver script, definimos um objeto vazio
114
117
  let scriptContent = 'const _sfc_main = {};';
115
118
  let bindings = undefined;
116
119
  if (descriptor.script || descriptor.scriptSetup) {
@@ -120,10 +123,16 @@ function registerLoaders(options = {}) {
120
123
  isProd: false,
121
124
  inlineTemplate: false
122
125
  });
123
- // Truque: Substitui "export default" por uma variável local para podermos
124
- // anexar a função render antes de exportar tudo no final.
125
- // Isso é necessário pois estamos criando um arquivo único virtual.
126
- scriptContent = compiledScript.content.replace('export default', 'const _sfc_main =');
126
+ // Lógica de substituição do export default
127
+ // 1. Procura por "export default" (com ou sem espaços extras)
128
+ if (compiledScript.content.match(/export\s+default/)) {
129
+ scriptContent = compiledScript.content.replace(/export\s+default/, 'const _sfc_main =');
130
+ }
131
+ else {
132
+ // 2. Se não achou export default (ex: arquivo só tem "export const config"),
133
+ // mantemos o conteúdo original e ADICIONAMOS a definição do _sfc_main manualmente.
134
+ scriptContent = compiledScript.content + '\nconst _sfc_main = {};';
135
+ }
127
136
  bindings = compiledScript.bindings;
128
137
  }
129
138
  catch (e) {
@@ -132,7 +141,6 @@ function registerLoaders(options = {}) {
132
141
  }
133
142
  }
134
143
  // 3. Compilação do Template para SSR
135
- // Isso gera a função `ssrRender` necessária para o @vue/server-renderer
136
144
  let templateContent = '';
137
145
  if (descriptor.template) {
138
146
  try {
@@ -140,11 +148,10 @@ function registerLoaders(options = {}) {
140
148
  source: descriptor.template.content,
141
149
  filename: filename,
142
150
  id: filename,
143
- ssr: true, // IMPORTANTE: Gera código otimizado para servidor (string concatenation)
151
+ ssr: true,
144
152
  compilerOptions: {
145
- bindingMetadata: bindings // Otimiza bindings baseados no script setup
153
+ bindingMetadata: bindings
146
154
  },
147
- // CORREÇÃO: Passa as variáveis CSS detectadas no parse para o compilador de template
148
155
  ssrCssVars: descriptor.cssVars || []
149
156
  });
150
157
  templateContent = templateResult.code;
@@ -154,8 +161,7 @@ function registerLoaders(options = {}) {
154
161
  }
155
162
  }
156
163
  // 4. Montagem do Código Final (ESM Virtual)
157
- // Combinamos o script compilado com o template compilado e unimos as partes.
158
- const finalEsm = `
164
+ finalEsm = `
159
165
  ${scriptContent}
160
166
  ${templateContent}
161
167
 
@@ -164,7 +170,6 @@ function registerLoaders(options = {}) {
164
170
  if (typeof ssrRender !== 'undefined') {
165
171
  _sfc_main.ssrRender = ssrRender;
166
172
  }
167
- // Fallback para renderização cliente/hidratação se necessário (opcional no server)
168
173
  if (typeof render !== 'undefined') {
169
174
  _sfc_main.render = render;
170
175
  }
@@ -174,7 +179,7 @@ function registerLoaders(options = {}) {
174
179
  `;
175
180
  // 5. Transformação final para CommonJS (Node.js) via Esbuild
176
181
  const result = esbuild.transformSync(finalEsm, {
177
- loader: 'ts', // Suporta TS e JS
182
+ loader: 'ts',
178
183
  format: 'cjs',
179
184
  target: 'node16',
180
185
  sourcefile: filename
@@ -183,7 +188,14 @@ function registerLoaders(options = {}) {
183
188
  module._compile(result.code, filename);
184
189
  }
185
190
  catch (err) {
186
- console.error(`Falha fatal ao carregar .vue: ${filename}`);
191
+ console.error(`\n--- Vatts Loader Debug ---`);
192
+ console.error(`Falha fatal ao carregar: ${filename}`);
193
+ console.error(`Erro original: ${err.message}`);
194
+ if (finalEsm) {
195
+ console.error(`\n[DEBUG] Código gerado (Snippet):`);
196
+ console.error(finalEsm.split('\n').slice(0, 30).join('\n') + '\n...');
197
+ }
198
+ console.error(`--------------------------\n`);
187
199
  throw err;
188
200
  }
189
201
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vatts",
3
- "version": "1.2.0-alpha.2",
3
+ "version": "1.2.0-test.1",
4
4
  "description": "Vatts.js 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
  "types": "dist/index.d.ts",
6
6
  "author": "itsmuzin",