vaderjs 1.3.3-612-hotfix → 1.3.3-662-hotfix

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/package.json +1 -1
  2. package/vader.js +163 -172
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "vaderjs",
3
3
  "description": "A Reactive library aimed to helping you build reactive applications inspired by react.js",
4
4
  "module": "vader.js",
5
- "version": "1.3.3-612-hotfix",
5
+ "version": "1.3.3-662-hotfix",
6
6
  "bin": {
7
7
  "vader": "./vader.js"
8
8
  },
package/vader.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import fs from "fs";
2
+ import fs, { fstatSync } from "fs";
3
3
  import { glob, globSync, globStream, globStreamSync, Glob, } from 'glob'
4
- import puppeteer from 'puppeteer';
4
+ import puppeteer from 'puppeteer';
5
5
  import http from 'http'
6
6
  import { SourceMapGenerator } from 'source-map'
7
7
 
@@ -9,19 +9,19 @@ import { WebSocketServer } from 'ws'
9
9
  import prettier from 'prettier'
10
10
  import { watch } from "fs";
11
11
  import path from 'path'
12
-
12
+
13
13
  globalThis.compiledFiles = []
14
14
 
15
15
  const sourceMapGen = (data, code) => {
16
- let { origin, fileName } = data
16
+ let { origin, fileName } = data
17
17
  const sourceMap = new SourceMapGenerator({ file: '/src/' + fileName.replace('.jsx', '.js') });
18
18
 
19
- const lines = fs.readFileSync(origin, "utf8").split("\n");
19
+ const lines = fs.readFileSync(origin, "utf8").split("\n");
20
20
  let line = 1;
21
21
  let column = 0;
22
- for (const l of lines) {
22
+ for (const l of lines) {
23
23
  sourceMap.addMapping({
24
- source: origin,
24
+ source: origin,
25
25
  sourceRoot: '/src',
26
26
  original: { line: line, column: 0 },
27
27
  generated: { line: line, column: 0 },
@@ -34,7 +34,7 @@ const sourceMapGen = (data, code) => {
34
34
  code = code + `\n//# sourceMappingURL=./src/maps/${fileName.replace('.jsx', '.js')}.map \n //#sourceURL=/src/maps/${fileName.replace('.jsx', '.js')}.map`
35
35
  return { code, sourceMap };
36
36
  }
37
-
37
+
38
38
  let config = await import('file://' + process.cwd() + '/vader.config.js').then((e) => e.default || e)
39
39
  let writer = async (file, data) => {
40
40
  globalThis.isWriting = file
@@ -80,20 +80,21 @@ function Compiler(func, file) {
80
80
  let childs = [];
81
81
 
82
82
 
83
- const spreadAttributeRegex = /\s*([a-zA-Z0-9_-]+)\s*(\$\s*=\s*\{\s*\{[^]*?\}\s*\})/gs;
84
-
83
+ // or : value boolean variable etc
84
+ const spreadAttributeRegex = /\s*([a-zA-Z0-9_-]+)\s*(\$\s*=\s*\{\s*\{(?:[^{}]|(?:\{(?:[^{}]|(?:\{[^{}]*\})*)*\})*)*\}\s*\})/gs;
85
+
85
86
 
86
87
 
87
88
 
88
89
  function extractAttributes(code) {
89
90
  // grab $={...} and ={...}
90
- const elementRegex = /<([a-zA-Z0-9_-]+)([^>]*)>/gs;
91
+ const elementRegex = /<([a-zA-Z0-9_-]+)([^>]*)>/gs;
91
92
 
92
93
  // Match attributes in an opening tag, including those with ={}
93
94
  // Match attributes in an opening tag, including those with ={...}
94
95
  const attributeRegex =
95
- /\s*([a-zA-Z0-9_-]+)(\s*=\s*("(?:[^"\\]*(?:\\.[^"\\]*)*)"|'(?:[^'\\]*(?:\\.[^'\\]*)*)'|\{(?:[^{}]|(?:\{(?:[^{}]|(?:\{[^{}]*\})*)*\})*)*\}|(?:\([^)]*\)|\{[^}]*\}|()=>\s*(?:\{[^}]*\})?)|\[[^\]]*\]))?/gs;
96
-
96
+ /\s*([a-zA-Z0-9_-]+)(\s*=\s*("(?:[^"\\]*(?:\\.[^"\\]*)*)"|'(?:[^'\\]*(?:\\.[^'\\]*)*)'|\{(?:[^{}]|(?:\{(?:[^{}]|(?:\{[^{}]*\})*)*\})*)*\}|(?:\([^)]*\)|\{[^}]*\}|()=>\s*(?:\{[^}]*\})?)|\[[^\]]*\]))?/gs;
97
+
97
98
 
98
99
 
99
100
  const functionAttributeRegex = /\s*([a-zA-Z0-9_-]+)\s*(=\s*{((?:[^{}]|(?:\{(?:[^{}]|(?:\{[^{}]*\})*)*\})*)*)})/gs;
@@ -101,7 +102,7 @@ function Compiler(func, file) {
101
102
  let attributesList = [];
102
103
 
103
104
  let spreadAttributes = [];
104
-
105
+
105
106
  /**
106
107
  * @search - handle spread for html elements
107
108
  * @keywords - spread, spread attributes, spread props, spread html attributes
@@ -214,10 +215,10 @@ function Compiler(func, file) {
214
215
  * @keywords - attributes, props, html attributes
215
216
  */
216
217
  let match;
217
- while ((match = elementRegex.exec(code)) !== null) {
218
+ while ((match = elementRegex.exec(string)) !== null) {
218
219
  let [, element, attributes] = match;
219
220
 
220
-
221
+
221
222
  let attributesMatch;
222
223
  let elementAttributes = {};
223
224
 
@@ -229,81 +230,60 @@ function Compiler(func, file) {
229
230
 
230
231
  attributesList.push({ element, attributes: elementAttributes });
231
232
  }
232
-
233
- let spreadMatch;
234
- while ((spreadMatch = spreadAttributeRegex.exec(string)) !== null) {
235
- let [, element, spread] = spreadMatch;
236
-
237
- let isJSXComponent = element.match(/[A-Z]/) ? true : false;
238
- if (isJSXComponent) {
239
- continue
240
-
241
- }
242
- let old = spread;
243
- // turn spread into attributes
244
- spread = spread.replace(/\s*$\s*=\s*/, "");
245
- spread = spread.replace(/\$\s*=\s*/, "");
246
- spread = spread.replace('{{', '')
247
- spread = spread.replace(/,$/, '');
248
233
 
249
-
250
-
251
- let splitByCommas = spread.split(/,(?![^{}]*})/gs).map((e) => {
252
-
253
-
254
-
255
- switch (true) {
256
- case e.includes('function') || e.includes('=>'):
257
- e = e.replace(/\,\s*$/, '');
258
- // replace commas
259
- e = e.replace(/,\s*/gs, ',');
260
- // remove space between (.*) =>
261
- e = e.replace(/\(\s*=>/gs, '=>');
262
- e = e.replace(/\s*=>\s*\{/gs, '=>{');
263
-
264
- // add ; after newlines
265
- e = e.replace(/\s*(\w+)\s*=>\s*\{/gs, '$1=>{');
266
- // turn (e) => {e} into function(e){e}
267
- e = e.replace(/\(([^)]*)\)\s*=>\s*\{/gs, 'function($1){\n');
268
- e = e.replace(/;/g, ';\n ');
269
- e = e.replace(/,\s*}\s*$/gs, '}');
270
-
271
-
272
-
273
- e = e.replace(/:(.*)/gs, '="\${this.bind($1, ' + false + ', "' + Math.random().toString(36).substring(2).split('').filter((e) => !Number(e)).join('') + '", "")}"');
274
-
275
- break;
276
- case e.includes('style'):
277
- e = e.replace(/,\s*$/gs, '');
278
- e = e.replace(/}\s*$/gs, '');
279
- e = e.replaceAll(/{\s*$/gs, '');
280
- e = e.replaceAll(/}\s*$/gs, '');
281
- e = e.replace(/style:(.*)/gs, 'style="\${this.parseStyle($1)}"');
282
-
234
+ let spreadMatch;
235
+ while ((spreadMatch = spreadAttributeRegex.exec(code)) !== null) {
236
+ let [, element, spread] = spreadMatch;
237
+ let isJSXComponent = element.match(/^[A-Z]/) ? true : false;
238
+ if (isJSXComponent) {
239
+ continue;
240
+ }
241
+ let old = spread;
242
+ spread = spread.trim().replace(/\s+/g, " ");
243
+ // re,pve $={ and }
244
+ spread = spread.replace(/\s*\$\s*=\s*{\s*{/gs, '')
245
+
246
+ // replace trailing }
247
+ spread = spread.replace(/}}\s*$/, '').replace(/}\s*}$/, '')
248
+ let splitByCommas = spread.split(/,(?![^{}]*})/gs)
249
+ // remove empty strings
250
+ splitByCommas = splitByCommas.filter((e) => e.split(':')[0].trim().length > 0)
251
+ splitByCommas = splitByCommas.map((e, index) => {
252
+ let key = e.split(':')[0].trim()
253
+ switch (true) {
254
+ case e.includes('function') && !e.includes('this.bind') || e && e.includes('=>') && !e.includes('this.bind'):
255
+ let value = e.split(':')[1].trim()
256
+ let ref = Math.random().toString(36).substring(2).split('').filter((e) => !Number(e)).join('');
257
+ value = `this.bind(${value}, false, "${ref}", "")`
258
+ e = `${key}="\${${value}}"`
259
+ break;
260
+ case e.includes('style:'):
261
+ let v2 = e.split('style:')[1].trim().replace(/,$/, '')
262
+ v2 = v2.replace(/,$/, '')
263
+ e = `${key}="\${this.parseStyle(${v2})}"`
264
+ break;
265
+
266
+ default:
267
+ let v = e.split(':')
268
+ key = v[0].trim()
269
+ // remove key from v
270
+ v.shift()
271
+ v = v.join(' ')
272
+ e = `${key}="\${${v}}"`
273
+
274
+ break;
275
+ }
283
276
 
284
- break;
285
- case e.includes('[') && e.includes(']'):
286
- e = e.replace(/:(.*)/gs, '={$1.join(" ")}');
287
- break;
288
- default:
289
- e = e.replace(/:(.*)/gs, '="${$1}"');
290
- e = e.replace(/,\s*$/gs, '');
291
- e = e.replace(/}\s*$/gs, '');
292
- e = e.replaceAll(/{\s*$/gs, '');
293
277
 
294
- break;
295
- }
278
+ return e;
279
+ });
296
280
 
297
- return e.trim();
298
- });
299
281
 
300
- let newSpread = splitByCommas.join(' ').trim().replace(/,$/, '');
301
-
302
- // remove trailing }
303
- newSpread = newSpread.replace(/}\s*$/, '')
304
- newSpread = newSpread.trim().replace(/{\s*$/gs, '')
305
- string = string.replace(old, newSpread);
306
- }
282
+ let newSpread = splitByCommas.join(' ').trim().replace(/,$/, '');
283
+
284
+ // remove trailing }
285
+ string = string.replace(old, newSpread);
286
+ }
307
287
 
308
288
  return attributesList;
309
289
  }
@@ -346,12 +326,12 @@ function Compiler(func, file) {
346
326
  }
347
327
  let usesBraces = returnStatement.match(/return\s*\(/gs) ? true : false;
348
328
 
349
- let attributes = extractAttributes(contents);
329
+ let attributes = extractAttributes(string);
350
330
  contents = contents.trim().replace(/\]$/, "")
351
331
  contents = contents.replace(/\)$/, "");
352
332
  usesBraces ? !contents.includes('<>') ? contents = `<>${contents}</>` : null : null
353
333
  updatedContents = contents;
354
-
334
+
355
335
 
356
336
  let newAttributes = [];
357
337
  let oldAttributes = [];
@@ -371,16 +351,16 @@ function Compiler(func, file) {
371
351
  let value = attributes[key];
372
352
  let oldvalue = value;
373
353
  if (value && !value.new) {
374
-
354
+
375
355
  if (value && value.includes("={")) {
376
-
356
+
377
357
  value = value.replace("=", "");
378
358
  value == "undefined" ? (value = '"') : (value = value);
379
359
 
380
360
  key == 'style'
381
361
  && value.includes("{{")
382
362
  ? value = `{this.parseStyle({${value.split('{{')[1].split('}}')[0]}})}` : null
383
-
363
+
384
364
 
385
365
 
386
366
  value = `="\$${value}",`;
@@ -504,7 +484,7 @@ function Compiler(func, file) {
504
484
 
505
485
 
506
486
  let props = component.match(dynamicAttributesRegex)
507
-
487
+
508
488
  let filteredProps = [];
509
489
  let isWithinComponent = false;
510
490
  let componentName = name
@@ -519,10 +499,10 @@ function Compiler(func, file) {
519
499
  isWithinComponent = true;
520
500
  filteredProps.push(prop);
521
501
  } else if (isWithinComponent && prop.includes('=')) {
522
-
502
+
523
503
  if (prop.startsWith('$=')) {
524
504
  let old = prop
525
- prop = prop.replace(/\$\s*=\s*\{\s*\{/, '').replace(/\}\s*\}/, '')
505
+ prop = prop.replace(/\$\s*=\s*\{\s*\{/, '').replace(/\}\s*\}/, '}').replace(/}\s*$/, '')
526
506
 
527
507
  component = component.replace(old, prop)
528
508
  componentAttributes = componentAttributes.replace(old, prop)
@@ -531,12 +511,12 @@ function Compiler(func, file) {
531
511
 
532
512
  }
533
513
  else if (prop.includes('${')) {
534
-
535
-
536
- prop = prop.replace('="', ':')
537
- if (prop.includes('${')) {
514
+
515
+
516
+ prop = prop.replace('="', ':')
517
+ if (prop.includes('${')) {
538
518
  prop = prop.replace('="', ':')
539
- prop = prop.replace('${', '')
519
+ prop = prop.replace('${', '')
540
520
  }
541
521
  if (prop.includes('="${{')) {
542
522
  prop = prop.replace('${{', '{')
@@ -546,21 +526,21 @@ function Compiler(func, file) {
546
526
  }
547
527
 
548
528
  }
549
- if (prop.includes('={')) {
550
- let value = prop.split('={')
551
- let isObj = value[1].match(/^{.*}$/gs) ? true : false
552
- if (!isObj) {
553
- // remove trailing }
554
- value[1] = value[1].replace(/}\s*$/, '')
555
- }
529
+ if (prop.includes('={')) {
530
+ let value = prop.split('={')
531
+ let isObj = value[1].match(/^{.*}$/gs) ? true : false
532
+ if (!isObj) {
533
+ // remove trailing }
534
+ value[1] = value[1].replace(/}\s*$/, '')
535
+ }
556
536
 
557
- if(value[0] == 'style' && isObj){
558
- value[1] = `this.parseStyle(${value[1]})`
559
- }
560
- prop = `${value[0]}:${value[1]}`
537
+ if (value[0] == 'style' && isObj) {
538
+ value[1] = `this.parseStyle(${value[1]})`
539
+ }
540
+ prop = `${value[0]}:${value[1]}`
561
541
  }
562
542
 
563
- if (prop.includes('function') || prop.includes('=>')){
543
+ if (prop.includes('function') || prop.includes('=>')) {
564
544
  // parse 'function' to function
565
545
  prop = prop.replace("'", '')
566
546
 
@@ -569,15 +549,15 @@ function Compiler(func, file) {
569
549
 
570
550
  }
571
551
 
572
- prop = prop.replace('=function', ':function')
552
+ prop = prop.replace('=function', ':function')
573
553
  }
574
-
554
+
575
555
  filteredProps.push(prop);
576
556
 
577
557
 
578
558
 
579
- }else if (isWithinComponent && prop.includes('}')) {
580
-
559
+ } else if (isWithinComponent && prop.includes('}')) {
560
+
581
561
  }
582
562
 
583
563
 
@@ -598,7 +578,7 @@ function Compiler(func, file) {
598
578
 
599
579
  let savedname = name;
600
580
 
601
-
581
+
602
582
 
603
583
  name = name + Math.random().toString(36).substring(2);
604
584
  if (children && children.match(componentRegex)) {
@@ -684,10 +664,10 @@ function Compiler(func, file) {
684
664
  let text = fs.readFileSync(file, "utf8");
685
665
  if (!file.endsWith('.js') && file.endsWith('.jsx')) {
686
666
  text = Compiler(text, file);
687
-
667
+
688
668
  }
689
669
  let dest = file.split('node_modules')[1]
690
- dest = dest.split(baseFolder)[1]
670
+ dest = dest.split(baseFolder)[1]
691
671
  writer(process.cwd() + '/dist/src/' + baseFolder + dest, text)
692
672
  let importname = match.split('import')[1].split('from')[0].trim()
693
673
  let oldImportstring = match.split('from')[1].trim().replace(/'/g, '').replace(/"/g, '').trim()
@@ -896,7 +876,7 @@ const glb = await glob("**/**/**/**.{jsx,js}", {
896
876
  async function Build() {
897
877
  globalThis.isBuilding = true
898
878
  console.log(globalThis.isProduction ? 'Creating Optimized Production Build\n' : '')
899
- let str = `Page \t\t\t\t Size\n`
879
+ let str = `Page \t\t\t\t Size\n`
900
880
  globalThis.isProduction ? console.log('\x1b[32m%s\x1b[0m', str) : null
901
881
  let reader = async (file) => {
902
882
  let text = await fs.readFileSync(file, "utf8");
@@ -904,11 +884,11 @@ async function Build() {
904
884
  };
905
885
 
906
886
 
907
-
887
+
908
888
  function ssg(routes = []) {
909
- globalThis.isBuilding = true
889
+ globalThis.isBuilding = true
910
890
  routes.forEach(async (route) => {
911
- if (route.url.includes(':')) {
891
+ if (route.url.includes(':')) {
912
892
  return
913
893
  }
914
894
  let equalparamroute = routes.map((e) => {
@@ -928,7 +908,7 @@ async function Build() {
928
908
  <html lang="en">
929
909
  <head>
930
910
  <script>
931
- window.routes = JSON.parse('${JSON.stringify(routes)}')
911
+ window.routes = JSON.parse('${JSON.stringify(routes)}')
932
912
  </script>
933
913
  <script id="isServer">
934
914
  window.isServer = true
@@ -936,8 +916,7 @@ async function Build() {
936
916
  <meta charset="UTF-8">
937
917
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
938
918
  <script type="module" id="meta">
939
- window.history.pushState({}, '', '${route.url}')
940
-
919
+ window.history.pushState({}, '', '${route.url}')
941
920
  </script>
942
921
  <script type="module" id="router">
943
922
  import VaderRouter from '/router.js'
@@ -951,8 +930,16 @@ async function Build() {
951
930
  res.render(module, req, res, module.$metadata)
952
931
  }
953
932
  catch(error){
954
- document.documentElement.setAttribute('error', JSON.stringify({stack: error.stack, message: error.message, at: '${route.fileName}', line: error.lineNumber}))
955
- throw new Error({stack: error.stack, message: error.message})
933
+ let errorMessage = {
934
+ message: error.message,
935
+ name: error.name,
936
+ stack: error.stack,
937
+ path: window.location.pathname
938
+ };
939
+
940
+
941
+ document.documentElement.setAttribute('error', JSON.stringify(errorMessage));
942
+ throw new Error(error)
956
943
  }
957
944
  })
958
945
  ${equalparamroute.length > 0 ? equalparamroute.map((e) => {
@@ -965,7 +952,7 @@ async function Build() {
965
952
  })\n`
966
953
  }) : ''}
967
954
  router.listen(3000)
968
-
955
+
969
956
  </script>
970
957
  </head>
971
958
  <body>
@@ -1014,27 +1001,25 @@ async function Build() {
1014
1001
  globalThis.listen = true;
1015
1002
 
1016
1003
  const browser = await puppeteer.launch({
1017
- headless: "new", args: ['--no-sandbox', '--disable-setuid-sandbox'],
1004
+ headless: "new", args: ['--no-sandbox', '--disable-setuid-sandbox'],
1018
1005
  warning: false,
1019
- })
1006
+ })
1020
1007
  try {
1021
1008
 
1022
1009
  route.url = route.url.replaceAll(/\/:[a-zA-Z0-9_-]+/gs, '')
1023
1010
  let page = await browser.newPage();
1024
- // Handle browser errors
1025
- page.on('error', (err) => {
1026
- console.error('BROWSER ERROR:', err);
1011
+ // Handle browser errors
1012
+ page.on('error', (err) => {
1013
+ console.error('BROWSER ERROR:', JSON.parse(err));
1027
1014
  });
1028
- await page.evaluate(() => {
1029
- window.onerror = function (msg, url, lineNo, columnNo, error) {
1030
- console.log(msg, url, lineNo, columnNo, error)
1031
- }
1032
- })
1015
+
1033
1016
  try {
1034
1017
  page.on('pageerror', async err => {
1035
- let errorObj = await page.evaluate(() => document.documentElement.getAttribute('error'))
1036
- console.log('\x1b[31m%s\x1b[0m', 'PAGE ERROR:', errorObj);
1037
-
1018
+ let errorObj = JSON.parse(await page.evaluate(() => document.documentElement.getAttribute('error')) || '{}')
1019
+ console.log('\x1b[31m%s\x1b[0m', 'Compiler Error:', errorObj)
1020
+ if(globalThis.isProduction){
1021
+ process.exit(1)
1022
+ }
1038
1023
  });
1039
1024
  } catch (error) {
1040
1025
  browser.close()
@@ -1046,14 +1031,14 @@ async function Build() {
1046
1031
  page.on('requestfailed', request => {
1047
1032
  console.error('REQUEST FAILED:', request.url(), request.failure().errorText);
1048
1033
  });
1049
- await page.goto(`http://localhost:${port}/`, { waitUntil: 'networkidle2' });
1050
-
1034
+ await page.goto(`http://localhost:${port}/`, { waitUntil: 'networkidle2' });
1035
+
1036
+
1037
+
1038
+
1039
+
1051
1040
 
1052
-
1053
-
1054
1041
 
1055
-
1056
-
1057
1042
  await page.evaluate(() => {
1058
1043
  document.getElementById('meta').remove()
1059
1044
  document.querySelector('#isServer').innerHTML = 'window.isServer = false'
@@ -1061,29 +1046,29 @@ async function Build() {
1061
1046
  document.querySelector('#root').innerHTML = ''
1062
1047
  console.log(`Disabled prerendering for ${window.location.pathname}`)
1063
1048
  }
1064
- })
1049
+ })
1065
1050
  let html = await page.content();
1066
1051
 
1067
- html = await prettier.format(html, { parser: "html" })
1068
-
1069
-
1052
+ html = await prettier.format(html, { parser: "html" })
1053
+
1054
+
1070
1055
  await writer(process.cwd() + '/dist/' + (route.url === '/' ? 'index.html' : `${route.url}/` + 'index.html'), html)
1071
-
1056
+
1072
1057
 
1073
1058
  } catch (error) {
1074
- console.log(error)
1075
- }
1059
+ console.log(error)
1060
+ }
1076
1061
 
1077
1062
  finally {
1078
1063
  browser.close()
1079
- server.close()
1064
+ server.close()
1080
1065
  }
1081
1066
  })
1082
1067
 
1083
1068
  let timeout = setTimeout(() => {
1084
1069
  globalThis.isBuilding = false
1085
1070
  clearTimeout(timeout)
1086
- }, 1000)
1071
+ }, 1000)
1087
1072
  }
1088
1073
 
1089
1074
  globalThis.routes = []
@@ -1115,14 +1100,15 @@ async function Build() {
1115
1100
 
1116
1101
 
1117
1102
  let data = await fs.readFileSync(origin, "utf8");
1118
-
1119
- // gen sourcemap if not production
1103
+
1104
+ // gen sourcemap if not production
1120
1105
  let size = fs.statSync(origin).size;
1121
- if(!globalThis.isProduction){
1122
- let { sourceMap } = sourceMapGen({origin:origin, fileName:fileName}, await Compiler(data, origin))
1106
+ if (!globalThis.isProduction) {
1107
+ let { sourceMap } = sourceMapGen({ origin: origin, fileName: fileName }, await Compiler(data, origin))
1108
+ data = data + `\n//# sourceMappingURL=/src/maps/${fileName.replace('.jsx', '.js.map')}\n //#sourceURL=${origin}`
1123
1109
  await writer(process.cwd() + "/dist/src/maps/" + fileName.replace('.jsx', '.js.map'), JSON.stringify(sourceMap, null, 2))
1124
1110
  }
1125
- await writer(process.cwd() + "/dist/" + fileName.replace('.jsx', '.js'), await Compiler(data, origin))
1111
+ await writer(process.cwd() + "/dist/" + fileName.replace('.jsx', '.js'), await Compiler(data, origin))
1126
1112
 
1127
1113
  // configure routing for each page
1128
1114
 
@@ -1186,17 +1172,18 @@ async function Build() {
1186
1172
 
1187
1173
  globalThis.routes.push({ fileName: fileName, url: obj.url, html: '/' + (isBasePath ? 'index.html' : `${obj.url}/` + 'index.html') })
1188
1174
 
1189
-
1190
- let stats = {route: obj.url.padEnd(30),
1175
+
1176
+ let stats = {
1177
+ route: obj.url.padEnd(30),
1191
1178
  size: Math.round(size / 1000) + 'kb',
1192
1179
  letParentFolder: obj.url.split('/').slice(0, -1).join('/'),
1193
1180
  isChildRoute: obj.url.split('/').slice(0, -1).join('/').includes(':') ? true : false,
1194
1181
  parentRoute: obj.url.split('/').slice(0, -1).join('/').split(':')[0],
1195
-
1196
- }
1182
+
1183
+ }
1197
1184
  stats.isChildRoute ? stats.route = `? ${obj.url}` : null
1198
1185
  let string = `${isBasePath ? '+' : '+'} ${stats.route.padEnd(30)} ${stats.size}`
1199
-
1186
+
1200
1187
  globalThis.isProduction ? console.log(string) : null
1201
1188
  }
1202
1189
 
@@ -1232,9 +1219,13 @@ async function Build() {
1232
1219
 
1233
1220
  let data = await reader(process.cwd() + "/src/" + name)
1234
1221
  if (name.includes('.jsx')) {
1235
- data = Compiler(data, process.cwd() + "/src/" + name);
1236
-
1237
- await writer(process.cwd() + "/dist/src/" + name.split('.jsx').join('.js'), data)
1222
+ let origin = process.cwd() + "/src/" + name
1223
+ if (!globalThis.isProduction) {
1224
+ let { sourceMap } = sourceMapGen({ origin: origin, fileName: name }, await Compiler(data, origin))
1225
+ data = data + `\n//# sourceMappingURL=/src/maps/${name.replace('.jsx', '.js.map')}\n //#sourceURL=${origin}`
1226
+ await writer(process.cwd() + "/dist/src/maps/" + name.replace('.jsx', '.js.map'), JSON.stringify(sourceMap, null, 2))
1227
+ }
1228
+ await writer(process.cwd() + "/dist/src/" + name.split('.jsx').join('.js'), await Compiler(data, origin))
1238
1229
  return
1239
1230
  }
1240
1231
  bundleSize += fs.statSync(process.cwd() + "/src/" + name).size;
@@ -1379,7 +1370,7 @@ const s = () => {
1379
1370
  console.log(`Server is running on port ${PORT}`);
1380
1371
  globalThis.ws = ws
1381
1372
  });
1382
-
1373
+
1383
1374
 
1384
1375
  }
1385
1376
 
@@ -1405,7 +1396,7 @@ Vader.js v1.3.3
1405
1396
  if (event == 'change'
1406
1397
  && !globalThis.isBuilding
1407
1398
  ) {
1408
- if(globalThis.ws && !globalThis.isWriting){
1399
+ if (globalThis.ws && !globalThis.isWriting) {
1409
1400
  globalThis.ws.clients.forEach((client) => {
1410
1401
  console.log('Reloading...')
1411
1402
  client.send('reload')
@@ -1433,7 +1424,7 @@ Vader.js v1.3.3
1433
1424
  Vader.js v1.3.3
1434
1425
  Building to ./dist
1435
1426
  `)
1436
- if(fs.existsSync(process.cwd() + '/dist/src/maps')){
1427
+ if (fs.existsSync(process.cwd() + '/dist/src/maps')) {
1437
1428
  fs.rmSync(process.cwd() + '/dist/src/maps', { recursive: true })
1438
1429
  }
1439
1430
  Build()