vatts 1.2.0-alpha.2 → 1.2.0-test.0
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/loaders.js +29 -13
- 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, {
|
|
@@ -120,10 +122,16 @@ function registerLoaders(options = {}) {
|
|
|
120
122
|
isProd: false,
|
|
121
123
|
inlineTemplate: false
|
|
122
124
|
});
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
// FIX: Uso de Regex para ser mais flexível com espaços
|
|
126
|
+
// Ex: aceita "export default" e "export default"
|
|
127
|
+
if (compiledScript.content.match(/export\s+default/)) {
|
|
128
|
+
scriptContent = compiledScript.content.replace(/export\s+default/, 'const _sfc_main =');
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// Fallback: Se não achou export default, assume que o script apenas roda side-effects ou define variáveis,
|
|
132
|
+
// mas precisamos garantir que _sfc_main exista.
|
|
133
|
+
scriptContent = compiledScript.content + '\nconst _sfc_main = {};';
|
|
134
|
+
}
|
|
127
135
|
bindings = compiledScript.bindings;
|
|
128
136
|
}
|
|
129
137
|
catch (e) {
|
|
@@ -132,7 +140,6 @@ function registerLoaders(options = {}) {
|
|
|
132
140
|
}
|
|
133
141
|
}
|
|
134
142
|
// 3. Compilação do Template para SSR
|
|
135
|
-
// Isso gera a função `ssrRender` necessária para o @vue/server-renderer
|
|
136
143
|
let templateContent = '';
|
|
137
144
|
if (descriptor.template) {
|
|
138
145
|
try {
|
|
@@ -140,11 +147,10 @@ function registerLoaders(options = {}) {
|
|
|
140
147
|
source: descriptor.template.content,
|
|
141
148
|
filename: filename,
|
|
142
149
|
id: filename,
|
|
143
|
-
ssr: true,
|
|
150
|
+
ssr: true,
|
|
144
151
|
compilerOptions: {
|
|
145
|
-
bindingMetadata: bindings
|
|
152
|
+
bindingMetadata: bindings
|
|
146
153
|
},
|
|
147
|
-
// CORREÇÃO: Passa as variáveis CSS detectadas no parse para o compilador de template
|
|
148
154
|
ssrCssVars: descriptor.cssVars || []
|
|
149
155
|
});
|
|
150
156
|
templateContent = templateResult.code;
|
|
@@ -154,27 +160,29 @@ function registerLoaders(options = {}) {
|
|
|
154
160
|
}
|
|
155
161
|
}
|
|
156
162
|
// 4. Montagem do Código Final (ESM Virtual)
|
|
157
|
-
|
|
158
|
-
const finalEsm = `
|
|
163
|
+
finalEsm = `
|
|
159
164
|
${scriptContent}
|
|
160
165
|
${templateContent}
|
|
161
166
|
|
|
162
167
|
// Anexa a função de renderização SSR ao componente principal
|
|
168
|
+
// Usa verificação de tipo segura para evitar ReferenceError na checagem
|
|
163
169
|
if (typeof _sfc_main !== 'undefined') {
|
|
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
|
}
|
|
176
|
+
} else {
|
|
177
|
+
// Safety net: Se _sfc_main não foi definido acima, define agora para não quebrar o export abaixo
|
|
178
|
+
var _sfc_main = {};
|
|
171
179
|
}
|
|
172
180
|
|
|
173
181
|
export default _sfc_main;
|
|
174
182
|
`;
|
|
175
183
|
// 5. Transformação final para CommonJS (Node.js) via Esbuild
|
|
176
184
|
const result = esbuild.transformSync(finalEsm, {
|
|
177
|
-
loader: 'ts',
|
|
185
|
+
loader: 'ts',
|
|
178
186
|
format: 'cjs',
|
|
179
187
|
target: 'node16',
|
|
180
188
|
sourcefile: filename
|
|
@@ -183,7 +191,15 @@ function registerLoaders(options = {}) {
|
|
|
183
191
|
module._compile(result.code, filename);
|
|
184
192
|
}
|
|
185
193
|
catch (err) {
|
|
186
|
-
console.error(
|
|
194
|
+
console.error(`\n--- Vatts Loader Debug ---`);
|
|
195
|
+
console.error(`Falha fatal ao carregar: ${filename}`);
|
|
196
|
+
console.error(`Erro original: ${err.message}`);
|
|
197
|
+
// Mostra um snippet do código gerado para facilitar a correção
|
|
198
|
+
if (finalEsm) {
|
|
199
|
+
console.error(`\n[DEBUG] Código gerado (Snippet):`);
|
|
200
|
+
console.error(finalEsm.split('\n').slice(0, 30).join('\n') + '\n...');
|
|
201
|
+
}
|
|
202
|
+
console.error(`--------------------------\n`);
|
|
187
203
|
throw err;
|
|
188
204
|
}
|
|
189
205
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vatts",
|
|
3
|
-
"version": "1.2.0-
|
|
3
|
+
"version": "1.2.0-test.0",
|
|
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",
|