@sprlab/wccompiler 0.11.4 → 0.11.6

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/bin/wcc.js CHANGED
@@ -35,6 +35,7 @@ async function build(config, cwd) {
35
35
 
36
36
  const { code, usesSharedRuntime } = await compile(file, {
37
37
  standalone: config.standalone,
38
+ minify: config.minify,
38
39
  runtimeImportPath,
39
40
  });
40
41
 
@@ -209,6 +210,9 @@ async function main() {
209
210
  const cwd = process.cwd();
210
211
  const config = await loadConfig(cwd);
211
212
 
213
+ // CLI flags override config
214
+ if (process.argv.includes('--minify')) config.minify = true;
215
+
212
216
  if (command === 'build') {
213
217
  const errors = await build(config, cwd);
214
218
  if (errors > 0) process.exit(1);
@@ -236,6 +240,7 @@ async function main() {
236
240
 
237
241
  const { code, usesSharedRuntime } = await compile(filePath, {
238
242
  standalone: config.standalone,
243
+ minify: config.minify,
239
244
  runtimeImportPath,
240
245
  });
241
246
 
package/lib/compiler.js CHANGED
@@ -118,11 +118,11 @@ async function compileSFC(filePath, config) {
118
118
  const style = descriptor.style;
119
119
 
120
120
  // 7. Extract lifecycle hooks (before other extractions)
121
- const { onMountHooks, onDestroyHooks } = extractLifecycleHooks(source);
121
+ const { onMountHooks, onDestroyHooks, onAdoptHooks } = extractLifecycleHooks(source);
122
122
 
123
123
  // 7b. Strip lifecycle/watcher blocks from source for extraction
124
124
  let sourceForExtraction = source;
125
- const hookLinePattern = /\bonMount\s*\(|\bonDestroy\s*\(|\bwatch\s*\(/;
125
+ const hookLinePattern = /\bonMount\s*\(|\bonDestroy\s*\(|\bonAdopt\s*\(|\bwatch\s*\(/;
126
126
  const sourceLines = sourceForExtraction.split('\n');
127
127
  const filteredLines = [];
128
128
  let skipDepth = 0;
@@ -276,6 +276,7 @@ async function compileSFC(filePath, config) {
276
276
  forBlocks: [],
277
277
  onMountHooks,
278
278
  onDestroyHooks,
279
+ onAdoptHooks,
279
280
  modelBindings: [],
280
281
  modelPropBindings: [],
281
282
  attrBindings: [],
@@ -485,5 +486,21 @@ export function resolveStandalone(componentValue, globalValue) {
485
486
  */
486
487
  export async function compile(filePath, config) {
487
488
  const result = await compileSFC(filePath, config);
489
+
490
+ if (config?.minify) {
491
+ const { transform } = await import('esbuild');
492
+ try {
493
+ const minified = await transform(result.code, {
494
+ minify: true,
495
+ loader: 'js',
496
+ target: 'esnext',
497
+ });
498
+ result.code = minified.code;
499
+ } catch {
500
+ // If minification fails (e.g., edge-case syntax), return unminified code
501
+ // This is a graceful fallback — the code still works at runtime
502
+ }
503
+ }
504
+
488
505
  return result;
489
506
  }
package/lib/config.js CHANGED
@@ -19,7 +19,7 @@ import { pathToFileURL } from 'node:url';
19
19
  * @returns {Promise<WccConfig>}
20
20
  */
21
21
  export async function loadConfig(projectRoot) {
22
- const defaults = { port: 4100, input: 'src', output: 'dist', standalone: false };
22
+ const defaults = { port: 4100, input: 'src', output: 'dist', standalone: false, minify: false };
23
23
  const configPath = resolve(projectRoot, 'wcc.config.js');
24
24
 
25
25
  if (!existsSync(configPath)) return defaults;
@@ -56,6 +56,11 @@ export async function loadConfig(projectRoot) {
56
56
  error.code = 'INVALID_CONFIG';
57
57
  throw error;
58
58
  }
59
+ if (typeof config.minify !== 'boolean') {
60
+ const error = new Error(`Error en wcc.config.js: minify debe ser un booleano`);
61
+ error.code = 'INVALID_CONFIG';
62
+ throw error;
63
+ }
59
64
 
60
65
  return config;
61
66
  }
@@ -890,6 +890,14 @@ export function extractFunctions(source) {
890
890
  if (j === i) {
891
891
  // First line: capture everything after the opening brace
892
892
  const afterBrace = l.substring(l.indexOf('{') + 1);
893
+ // Single-line function: depth already closed on first line
894
+ if (depth <= 0) {
895
+ const lastBraceIdx = afterBrace.lastIndexOf('}');
896
+ const inner = lastBraceIdx >= 0 ? afterBrace.substring(0, lastBraceIdx) : afterBrace;
897
+ if (inner.trim()) bodyLines.push(inner);
898
+ i = j;
899
+ break;
900
+ }
893
901
  if (afterBrace.trim()) bodyLines.push(afterBrace);
894
902
  } else if (depth <= 0) {
895
903
  // Last line: capture everything before the closing brace
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprlab/wccompiler",
3
- "version": "0.11.4",
3
+ "version": "0.11.6",
4
4
  "description": "Zero-runtime compiler that transforms .wcc single-file components into native web components with signals-based reactivity",
5
5
  "type": "module",
6
6
  "exports": {