vaderjs 1.3.3-alpha-92 → 1.3.3-alpha-93

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 +70 -84
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-alpha-92",
5
+ "version": "1.3.3-alpha-93",
6
6
  "bin": {
7
7
  "vader": "./vader.js"
8
8
  },
package/vader.js CHANGED
@@ -25,7 +25,7 @@ Object.keys(dirs).map((key, index) => {
25
25
  }
26
26
  }).filter(Boolean)[0]
27
27
 
28
- if(process.env.isCloudflare){
28
+ if (process.env.isCloudflare) {
29
29
  let htmlFile = fs.readFileSync(process.cwd() + "/node_modules/vaderjs/runtime/index.html", 'utf8')
30
30
  fs.writeFileSync(process.cwd() + "/dist/index.html", htmlFile)
31
31
  }
@@ -33,7 +33,7 @@ if(process.env.isCloudflare){
33
33
  function Compiler(func, file) {
34
34
  let string = func;
35
35
  // Remove block comments
36
-
36
+
37
37
  let returns = []
38
38
  let comments = string.match(/\{\s*\/\*.*\*\/\s*}/gs)?.map((comment) => comment.trim());
39
39
 
@@ -124,9 +124,9 @@ function Compiler(func, file) {
124
124
  // remove comments
125
125
  ps = ps.match(/\/\*.*\*\//gs)
126
126
  ? ps.replace(ps.match(/\/\*.*\*\//gs)[0], "")
127
- : ps;
127
+ : ps;
128
128
  functionparams.push({ ref: ref, name: name, params: ps });
129
-
129
+
130
130
  }
131
131
  });
132
132
  });
@@ -141,16 +141,16 @@ function Compiler(func, file) {
141
141
  .split(" ")[0];
142
142
  isJSXComponent = elementTag.match(/^[A-Z]/) ? true : false;
143
143
  }
144
- });
144
+ });
145
145
  let newvalue = attributeValue.includes('=>') ? attributeValue.split("=>").slice(1).join("=>").trim() : attributeValue.split("function").slice(1).join("function").trim()
146
-
146
+
147
147
 
148
148
  newvalue = newvalue.trim();
149
149
 
150
150
  //remove starting {
151
151
  newvalue = newvalue.replace("{", "");
152
152
 
153
-
153
+
154
154
  let params = attributeValue
155
155
  .split("=>")[0]
156
156
  .split("(")[1]
@@ -160,7 +160,7 @@ function Compiler(func, file) {
160
160
  // remove comments
161
161
  params = params.match(/\/\*.*\*\//gs)
162
162
  ? params.replace(params.match(/\/\*.*\*\//gs)[0], "")
163
- : params;
163
+ : params;
164
164
  // split first {}
165
165
  newvalue = newvalue.trim();
166
166
 
@@ -175,28 +175,28 @@ function Compiler(func, file) {
175
175
  case newvalue.endsWith("}"):
176
176
  newvalue = newvalue.replace("}", "");
177
177
  break;
178
- }
178
+ }
179
179
  // replace trailing }
180
180
  newvalue = newvalue.trim();
181
181
  if (newvalue.endsWith("}")) {
182
182
  newvalue = newvalue.replace("}", "");
183
- }
184
- functionparams.length > 0 ? params = params + ',' + functionparams.map((e) => e.name).join(',') : null
183
+ }
184
+ functionparams.length > 0 ? params = params + ',' + functionparams.map((e) => e.name).join(',') : null
185
185
  newvalue = newvalue.split('\n').map(line => line.trim() ? line.trim() + ';' : line).join('\n');
186
186
  newvalue = newvalue.replaceAll(',,', ',')
187
- let paramnames = params ? params.split(',').map((e) => e.trim()) : null
187
+ let paramnames = params ? params.split(',').map((e) => e.trim()) : null
188
188
  paramnames = paramnames ? paramnames.filter((e) => e.length > 0) : null
189
189
  // remove comments
190
190
  paramnames = paramnames ? paramnames.map((e) => e.match(/\/\*.*\*\//gs) ? e.replace(e.match(/\/\*.*\*\//gs)[0], "") : e) : null
191
-
192
- let bind = isJSXComponent ? `${attributeName}=function(${params}){${newvalue}}.bind(this)` : `${attributeName} = "\$\{this.bind("${newvalue.replace(/\s+g/, " ")}", ${isJSXComponent}, "${ref}", "${paramnames ? paramnames.map((e, index)=> {
193
- if(e.length < 1) return ''
194
- if(e.length > 0){
195
- index == 0 ? e : ',' + e
196
- }
191
+
192
+ let bind = isJSXComponent ? `${attributeName}=function(${params}){${newvalue}}.bind(this)` : `${attributeName} = "\$\{this.bind("${newvalue.replace(/\s+g/, " ")}", ${isJSXComponent}, "${ref}", "${paramnames ? paramnames.map((e, index) => {
193
+ if (e.length < 1) return ''
194
+ if (e.length > 0) {
195
+ index == 0 ? e : ',' + e
196
+ }
197
197
  return e
198
198
  }) : ''}" ${params ? params.split(',').map((e) => e.trim()).filter(Boolean).map((e) => `,${e}`).join('') : ''})}"`
199
- bind = bind.replaceAll(/\s+/g, " ");
199
+ bind = bind.replaceAll(/\s+/g, " ");
200
200
  string = string.replace(old, bind);
201
201
  }
202
202
  }
@@ -505,31 +505,31 @@ function Compiler(func, file) {
505
505
 
506
506
 
507
507
  // replace all comments
508
-
508
+
509
509
  string = string.replaceAll('vaderjs/client', '/vader.js')
510
510
  // replace ${... with ${
511
-
511
+
512
512
  string = string.replaceAll(/\$\{[^{]*\.{3}/gs, (match) => {
513
513
  if (match.includes('...')) {
514
514
  // Your logic for replacement goes here
515
515
  // For example, you can replace '...' with some other string
516
516
  return match.replace('...', '');
517
517
  }
518
-
518
+
519
519
  return match;
520
520
  });
521
-
521
+
522
522
  string = string.replaceAll(/\$\{\/\*.*\*\/\}/gs, "");
523
523
  string = string.replaceAll("<>", "`").replaceAll("</>", "`");
524
524
  string = parseComponents(string);
525
525
 
526
526
  string = string
527
527
  .replaceAll("className", "class")
528
- .replaceAll("classname", "class");
528
+ .replaceAll("classname", "class");
529
529
 
530
530
  string = string.replaceAll('../src', './src')
531
531
  string += `\n\n //wascompiled`;
532
-
532
+
533
533
 
534
534
  string = string.replaceAll("undefined", "");
535
535
  const parse = (css) => {
@@ -559,9 +559,7 @@ function Compiler(func, file) {
559
559
  if (line.includes('import')) {
560
560
  // Regular expression for matching import() statements
561
561
  let asyncimportMatch = line.match(/import\s*\((.*)\)/gs);
562
- // handle named imports and unnamed import 'path'
563
562
  let regularimportMatch = line.match(/import\s*([a-zA-Z0-9_-]+)?\s*from\s*('(.*)'|"(.*)")|import\s*('(.*)'|"(.*)")/gs);
564
-
565
563
 
566
564
  if (asyncimportMatch) {
567
565
  asyncimportMatch.forEach(async (match) => {
@@ -576,17 +574,14 @@ function Compiler(func, file) {
576
574
 
577
575
  break;
578
576
  case path && path.includes('module.css'):
579
-
580
-
581
-
582
577
  let css = await fs.readFileSync(process.cwd() + path, 'utf8')
583
578
  css = css.replaceAll('.', '')
584
-
579
+
585
580
  if (!name) {
586
581
  throw new Error('Could not find name for css module ' + path + ' at' + beforeimport + ' file' + file)
587
582
  }
588
583
  newImport = `let ${name} = ${JSON.stringify(parse(css.replaceAll('.', '').replace(/\s+/g, " ")))}`
589
-
584
+
590
585
  break;
591
586
  default:
592
587
  let deep = path.split('/').length - 1
@@ -598,8 +593,8 @@ function Compiler(func, file) {
598
593
  // remove double / from path
599
594
  path = path.split('//').join('/')
600
595
  if (!path.startsWith('./') && !path.includes('/vader.js') && !path.startsWith('src')
601
- && !path.startsWith('/public')
602
- ) {
596
+ && !path.startsWith('/public')
597
+ ) {
603
598
  path = '/src/' + path
604
599
  }
605
600
 
@@ -614,21 +609,12 @@ function Compiler(func, file) {
614
609
 
615
610
  if (regularimportMatch) {
616
611
  for (let match of regularimportMatch) {
617
- let beforeimport = match
618
- // import {name} from 'path' or import 'path'
612
+ let beforeimport = match
619
613
  let path = match.split('from')[1] ? match.split('from')[1].trim() : match.split('import')[1].trim()
614
+
620
615
  let newImport = ''
621
616
  let name = match.split('import')[1].split('from')[0].trim()
622
-
623
- path = path.replace(/'/g, '').trim().replace(/"/g, '').trim()
624
- let deep = path.split('/').length - 1
625
- for (let i = 0; i < deep; i++) {
626
- path = path.split('../').join('')
627
- path = path.split('./').join('')
628
- }
629
- path = path.replace(/'/g, '').trim().replace(/"/g, '').trim()
630
- // remove double / from path
631
- path = path.split('//').join('/')
617
+
632
618
 
633
619
  switch (true) {
634
620
  case path && path.includes('json'):
@@ -637,18 +623,19 @@ function Compiler(func, file) {
637
623
 
638
624
  break;
639
625
  case path && path.includes('module.css'):
640
-
641
- path = path.replace(';', '')
642
- path = path.replace(/'/g, '').trim().replace(/"/g, '').trim()
643
- path = path.replaceAll('.jsx', '.js');
644
-
645
- let css = fs.readFileSync(process.cwd() + '/' + path, 'utf8')
646
-
647
- css = css.replaceAll('.', '')
648
- newImport = `let ${name} = ${JSON.stringify(parse(css))}`
649
- string = string.replace(beforeimport, newImport)
626
+
627
+ path = path.replace(';', '')
628
+ path = path.replace(/'/g, '').trim().replace(/"/g, '').trim()
629
+ path = path.replaceAll('.jsx', '.js');
630
+ path = path.replaceAll('../', '');
631
+
632
+ let css = fs.readFileSync(process.cwd() + '/' + path, 'utf8')
633
+
634
+ css = css.replaceAll('.', '')
635
+ newImport = `let ${name} = ${JSON.stringify(parse(css))}`
636
+ string = string.replace(beforeimport, newImport)
650
637
  break;
651
- case path && path.endsWith('.css'):
638
+ case path && path.includes('.css'):
652
639
  string = string.replace(beforeimport, '')
653
640
  newImport = ``
654
641
  break;
@@ -661,30 +648,29 @@ function Compiler(func, file) {
661
648
  }
662
649
  path = path.replace(/'/g, '').trim().replace(/"/g, '').trim()
663
650
  // remove double / from path
664
- path = path.split('//').join('/')
651
+ path = path.split('//').join('/')
665
652
  if (!path.startsWith('./') && !path.includes('/vader.js') && !path.startsWith('src') && !path.startsWith('public')) {
666
653
  path.includes('src') ? path.split('src')[1] : null
667
654
  path = '/src/' + path
668
655
  } else if (path.startsWith('src') || path.startsWith('public')) {
669
656
  path = '/' + path
670
- }
657
+ }
671
658
  path = path.replaceAll('.jsx', '.js');
672
-
673
-
674
- string = string.replace(beforePath, path)
659
+
660
+
661
+ string = string.replace(beforePath, "'" + path + "'")
675
662
  break;
676
-
663
+
677
664
  }
678
-
665
+
679
666
  let html = fs.existsSync(process.cwd() + '/dist/index.html') ? fs.readFileSync(process.cwd() + '/dist/index.html', 'utf8') : ''
680
667
  if (!html.includes(`<link rel="preload" href="${path.replace(/'/g, '').trim()}" as="${path.replace(/'/g, '').trim().includes('.css') ? 'style' : 'script'}">`)
681
- && !path.includes('.module.css')
682
- ) {
668
+ && !path.includes('.module.css')
669
+ ) {
683
670
  let preload = `
684
- ${
685
- path.trim().includes('.css') ? `<link rel="stylesheet" href="${path.trim()}">` : ''
686
- }
687
- ${!path.trim().includes('.css') ? `<link rel="modulepreload" href="${path.trim()}">` : ''}<link rel="preload" href="${path.trim()}" as="${path.trim().includes('.css') ? 'style' : 'script'}">`
671
+ ${path.trim().includes('.css') ? `<link rel="stylesheet" href="${path.trim().replace(/'/g, '').trim()}">` : ''
672
+ }
673
+ ${!path.trim().includes('.css') ? `<link rel="modulepreload" href="${path.trim().replace(/'/g, '').trim()}">` : ''}<link rel="preload" href="${path.trim().replace(/'/g, '').trim()}" as="${path.trim().includes('.css') ? 'style' : 'script'}">`
688
674
  html = html.replace('</head>', `${preload}\n</head>`)
689
675
 
690
676
  fs.writeFileSync(process.cwd() + '/dist/index.html', html)
@@ -704,9 +690,9 @@ function Compiler(func, file) {
704
690
 
705
691
  return string
706
692
  }
707
-
693
+
708
694
  globalThis.isBuilding = false
709
- globalThis.isWriting = null
695
+ globalThis.isWriting = null
710
696
  async function Build() {
711
697
  globalThis.isBuilding = true
712
698
  console.log('Compiling......')
@@ -716,16 +702,16 @@ async function Build() {
716
702
  };
717
703
 
718
704
  let writer = async (file, data) => {
719
- globalThis.isWriting = file
705
+ globalThis.isWriting = file
720
706
  switch (true) {
721
707
  case !fs.existsSync(file):
722
708
  fs.mkdirSync(file.split('/').slice(0, -1).join('/'), { recursive: true })
723
709
  break;
724
710
  }
725
- if(globalThis.isWriting !== file){
711
+ if (globalThis.isWriting !== file) {
726
712
  return
727
713
  }
728
- await fs.writeFileSync(file, data);
714
+ await fs.writeFileSync(file, data);
729
715
 
730
716
  globalThis.isWriting = null
731
717
  return { _written: true };
@@ -782,18 +768,18 @@ async function Build() {
782
768
  await writer(process.cwd() + "/dist/pages/" + fileName.replace('.jsx', '.js'), data).then(async () => {
783
769
 
784
770
  let { minify } = await import('terser')
785
-
771
+
786
772
  try {
787
773
  let minified = await minify(data, {
788
774
  toplevel: true,
789
- ecma:2016,
790
- enclose:false,
775
+ ecma: 2016,
776
+ enclose: false,
791
777
  module: true,
792
778
  compress: true,
793
779
  keep_fnames: true,
794
780
 
795
781
  })
796
-
782
+
797
783
  await writer(process.cwd() + "/dist/pages/" + fileName.replace('.jsx', '.js'), minified.code)
798
784
  } catch (error) {
799
785
  console.log(error)
@@ -897,7 +883,7 @@ async function Build() {
897
883
 
898
884
  scannedFiles.forEach(async (file) => {
899
885
  file = file.split(process.cwd() + '/runtime/')[1]
900
-
886
+
901
887
  let objCase = {
902
888
  ...file == "app.js" ? { exit: true } : null,
903
889
  ...file.includes("index.html") && fs.existsSync(process.cwd() + "/runtime/" + file) ? { exit: true } : null,
@@ -908,11 +894,11 @@ async function Build() {
908
894
  return
909
895
  }
910
896
  bundleSize += fs.statSync(process.cwd() + "/runtime/" + file).size;
911
- let data = await reader(process.cwd() + "/runtime/" + file)
897
+ let data = await reader(process.cwd() + "/runtime/" + file)
912
898
  await writer(process.cwd() + "/dist/" + file, data);
913
899
  });
914
900
 
915
- }
901
+ }
916
902
 
917
903
  globalThis.isBuilding = false
918
904
  console.log(`Build complete! ${Math.round(bundleSize / 1000)}${bundleSize > 1000 ? 'kb' : 'bytes'} written to ./dist`)
@@ -935,13 +921,13 @@ Vader.js v1.3.3
935
921
 
936
922
 
937
923
  Array.from(Array(3).keys()).forEach((i) => {
938
- let p = `${process.cwd()}${i == 0 ? '/pages/' : i == 1 ? '/src/' : '/public/'}`
924
+ let p = `${process.cwd()}${i == 0 ? '/pages/' : i == 1 ? '/src/' : '/public/'}`
939
925
  watch(p
940
926
  , { recursive: true }, (event, filename) => {
941
927
  if (event == 'change'
942
928
  && !globalThis.isBuilding
943
929
  ) {
944
-
930
+
945
931
  Build()
946
932
  }
947
933
  }).on('error', (err) => console.log(err))