vatts 1.2.0-test.0 → 1.2.0-test.2
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.d.ts +1 -0
- package/dist/loaders.js +55 -72
- package/package.json +1 -1
package/dist/loaders.d.ts
CHANGED
package/dist/loaders.js
CHANGED
|
@@ -13,15 +13,11 @@ let esbuild;
|
|
|
13
13
|
try {
|
|
14
14
|
sfcCompiler = require('vue/compiler-sfc');
|
|
15
15
|
}
|
|
16
|
-
catch (e) {
|
|
17
|
-
// Vue não instalado ou não encontrado
|
|
18
|
-
}
|
|
16
|
+
catch (e) { }
|
|
19
17
|
try {
|
|
20
18
|
esbuild = require('esbuild');
|
|
21
19
|
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
// Esbuild não instalado
|
|
24
|
-
}
|
|
20
|
+
catch (e) { }
|
|
25
21
|
const { loadTsConfigPaths, resolveTsConfigAlias, resolveWithNodeStyleExtensions } = require('./tsconfigPaths');
|
|
26
22
|
/**
|
|
27
23
|
* Carrega e processa o tsconfig.json para obter os aliases
|
|
@@ -76,12 +72,10 @@ function registerLoaders(options = {}) {
|
|
|
76
72
|
}
|
|
77
73
|
// --- File Handlers ---
|
|
78
74
|
require.extensions['.md'] = function (module, filename) {
|
|
79
|
-
|
|
80
|
-
module.exports = content;
|
|
75
|
+
module.exports = fs.readFileSync(filename, 'utf8');
|
|
81
76
|
};
|
|
82
77
|
require.extensions['.txt'] = function (module, filename) {
|
|
83
|
-
|
|
84
|
-
module.exports = content;
|
|
78
|
+
module.exports = fs.readFileSync(filename, 'utf8');
|
|
85
79
|
};
|
|
86
80
|
const styleExtensions = ['.css', '.scss', '.sass', '.less'];
|
|
87
81
|
styleExtensions.forEach(ext => {
|
|
@@ -101,7 +95,6 @@ function registerLoaders(options = {}) {
|
|
|
101
95
|
throw new Error('Para carregar arquivos .vue no servidor, você precisa instalar "vue" e "esbuild".');
|
|
102
96
|
}
|
|
103
97
|
const source = fs.readFileSync(filename, 'utf8');
|
|
104
|
-
// Variável para armazenar o código final para fins de debug
|
|
105
98
|
let finalEsm = '';
|
|
106
99
|
try {
|
|
107
100
|
// 1. Parse do SFC
|
|
@@ -112,75 +105,66 @@ function registerLoaders(options = {}) {
|
|
|
112
105
|
if (errors.length > 0) {
|
|
113
106
|
console.error(`Erro ao parsear ${filename}:`, errors);
|
|
114
107
|
}
|
|
115
|
-
// 2. Compilação do Script
|
|
116
|
-
let scriptContent = '
|
|
108
|
+
// 2. Compilação do Script
|
|
109
|
+
let scriptContent = '';
|
|
117
110
|
let bindings = undefined;
|
|
118
111
|
if (descriptor.script || descriptor.scriptSetup) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// mas precisamos garantir que _sfc_main exista.
|
|
133
|
-
scriptContent = compiledScript.content + '\nconst _sfc_main = {};';
|
|
134
|
-
}
|
|
135
|
-
bindings = compiledScript.bindings;
|
|
112
|
+
const compiledScript = sfcCompiler.compileScript(descriptor, {
|
|
113
|
+
id: filename,
|
|
114
|
+
isProd: false,
|
|
115
|
+
inlineTemplate: false
|
|
116
|
+
});
|
|
117
|
+
scriptContent = compiledScript.content;
|
|
118
|
+
bindings = compiledScript.bindings;
|
|
119
|
+
const hasSfcMain = /\bconst\s+_sfc_main\b/.test(scriptContent) ||
|
|
120
|
+
/\blet\s+_sfc_main\b/.test(scriptContent) ||
|
|
121
|
+
/\bvar\s+_sfc_main\b/.test(scriptContent);
|
|
122
|
+
// Caso tenha "export default"
|
|
123
|
+
if (/export\s+default/.test(scriptContent)) {
|
|
124
|
+
scriptContent = scriptContent.replace(/export\s+default/, 'const _sfc_main =');
|
|
136
125
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
126
|
+
// Caso NÃO tenha export default e NÃO tenha _sfc_main
|
|
127
|
+
else if (!hasSfcMain) {
|
|
128
|
+
scriptContent += '\nconst _sfc_main = {};';
|
|
140
129
|
}
|
|
141
130
|
}
|
|
131
|
+
else {
|
|
132
|
+
// Sem script nenhum
|
|
133
|
+
scriptContent = 'const _sfc_main = {};';
|
|
134
|
+
}
|
|
142
135
|
// 3. Compilação do Template para SSR
|
|
143
136
|
let templateContent = '';
|
|
144
137
|
if (descriptor.template) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
templateContent = templateResult.code;
|
|
157
|
-
}
|
|
158
|
-
catch (e) {
|
|
159
|
-
console.error(`Erro ao compilar template Vue em ${filename}:`, e.message);
|
|
160
|
-
}
|
|
138
|
+
const templateResult = sfcCompiler.compileTemplate({
|
|
139
|
+
source: descriptor.template.content,
|
|
140
|
+
filename,
|
|
141
|
+
id: filename,
|
|
142
|
+
ssr: true,
|
|
143
|
+
compilerOptions: {
|
|
144
|
+
bindingMetadata: bindings
|
|
145
|
+
},
|
|
146
|
+
ssrCssVars: descriptor.cssVars || []
|
|
147
|
+
});
|
|
148
|
+
templateContent = templateResult.code;
|
|
161
149
|
}
|
|
162
|
-
// 4. Montagem do Código Final
|
|
150
|
+
// 4. Montagem do Código Final
|
|
163
151
|
finalEsm = `
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
export default _sfc_main;
|
|
182
|
-
`;
|
|
183
|
-
// 5. Transformação final para CommonJS (Node.js) via Esbuild
|
|
152
|
+
${scriptContent}
|
|
153
|
+
${templateContent}
|
|
154
|
+
|
|
155
|
+
// Anexa render ao componente
|
|
156
|
+
if (typeof _sfc_main !== 'undefined') {
|
|
157
|
+
if (typeof ssrRender !== 'undefined') {
|
|
158
|
+
_sfc_main.ssrRender = ssrRender;
|
|
159
|
+
}
|
|
160
|
+
if (typeof render !== 'undefined') {
|
|
161
|
+
_sfc_main.render = render;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default _sfc_main;
|
|
166
|
+
`;
|
|
167
|
+
// 5. Transformação para CJS
|
|
184
168
|
const result = esbuild.transformSync(finalEsm, {
|
|
185
169
|
loader: 'ts',
|
|
186
170
|
format: 'cjs',
|
|
@@ -194,10 +178,9 @@ function registerLoaders(options = {}) {
|
|
|
194
178
|
console.error(`\n--- Vatts Loader Debug ---`);
|
|
195
179
|
console.error(`Falha fatal ao carregar: ${filename}`);
|
|
196
180
|
console.error(`Erro original: ${err.message}`);
|
|
197
|
-
// Mostra um snippet do código gerado para facilitar a correção
|
|
198
181
|
if (finalEsm) {
|
|
199
182
|
console.error(`\n[DEBUG] Código gerado (Snippet):`);
|
|
200
|
-
console.error(finalEsm.split('\n').slice(0,
|
|
183
|
+
console.error(finalEsm.split('\n').slice(0, 40).join('\n') + '\n...');
|
|
201
184
|
}
|
|
202
185
|
console.error(`--------------------------\n`);
|
|
203
186
|
throw err;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vatts",
|
|
3
|
-
"version": "1.2.0-test.
|
|
3
|
+
"version": "1.2.0-test.2",
|
|
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",
|