vaderjs 1.3.3-alpha-91 → 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.
- package/package.json +1 -1
- package/vader.js +71 -75
package/package.json
CHANGED
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())
|
|
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 =
|
|
193
|
-
if(e.length < 1) return
|
|
194
|
-
if(e.length > 0){
|
|
195
|
-
index == 0 ?
|
|
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) => {
|
|
@@ -578,12 +576,12 @@ function Compiler(func, file) {
|
|
|
578
576
|
case path && path.includes('module.css'):
|
|
579
577
|
let css = await fs.readFileSync(process.cwd() + path, 'utf8')
|
|
580
578
|
css = css.replaceAll('.', '')
|
|
581
|
-
|
|
579
|
+
|
|
582
580
|
if (!name) {
|
|
583
581
|
throw new Error('Could not find name for css module ' + path + ' at' + beforeimport + ' file' + file)
|
|
584
582
|
}
|
|
585
583
|
newImport = `let ${name} = ${JSON.stringify(parse(css.replaceAll('.', '').replace(/\s+/g, " ")))}`
|
|
586
|
-
|
|
584
|
+
|
|
587
585
|
break;
|
|
588
586
|
default:
|
|
589
587
|
let deep = path.split('/').length - 1
|
|
@@ -595,8 +593,8 @@ function Compiler(func, file) {
|
|
|
595
593
|
// remove double / from path
|
|
596
594
|
path = path.split('//').join('/')
|
|
597
595
|
if (!path.startsWith('./') && !path.includes('/vader.js') && !path.startsWith('src')
|
|
598
|
-
|
|
599
|
-
) {
|
|
596
|
+
&& !path.startsWith('/public')
|
|
597
|
+
) {
|
|
600
598
|
path = '/src/' + path
|
|
601
599
|
}
|
|
602
600
|
|
|
@@ -611,13 +609,13 @@ function Compiler(func, file) {
|
|
|
611
609
|
|
|
612
610
|
if (regularimportMatch) {
|
|
613
611
|
for (let match of regularimportMatch) {
|
|
614
|
-
let beforeimport = match
|
|
615
|
-
// import {name} from 'path' or import 'path'
|
|
612
|
+
let beforeimport = match
|
|
616
613
|
let path = match.split('from')[1] ? match.split('from')[1].trim() : match.split('import')[1].trim()
|
|
614
|
+
|
|
617
615
|
let newImport = ''
|
|
618
616
|
let name = match.split('import')[1].split('from')[0].trim()
|
|
619
|
-
|
|
620
|
-
|
|
617
|
+
|
|
618
|
+
|
|
621
619
|
switch (true) {
|
|
622
620
|
case path && path.includes('json'):
|
|
623
621
|
path = path.replace(';', '')
|
|
@@ -625,20 +623,19 @@ function Compiler(func, file) {
|
|
|
625
623
|
|
|
626
624
|
break;
|
|
627
625
|
case path && path.includes('module.css'):
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
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)
|
|
639
637
|
break;
|
|
640
|
-
case path && path.
|
|
641
|
-
console.log(path)
|
|
638
|
+
case path && path.includes('.css'):
|
|
642
639
|
string = string.replace(beforeimport, '')
|
|
643
640
|
newImport = ``
|
|
644
641
|
break;
|
|
@@ -651,30 +648,29 @@ function Compiler(func, file) {
|
|
|
651
648
|
}
|
|
652
649
|
path = path.replace(/'/g, '').trim().replace(/"/g, '').trim()
|
|
653
650
|
// remove double / from path
|
|
654
|
-
path = path.split('//').join('/')
|
|
651
|
+
path = path.split('//').join('/')
|
|
655
652
|
if (!path.startsWith('./') && !path.includes('/vader.js') && !path.startsWith('src') && !path.startsWith('public')) {
|
|
656
653
|
path.includes('src') ? path.split('src')[1] : null
|
|
657
654
|
path = '/src/' + path
|
|
658
655
|
} else if (path.startsWith('src') || path.startsWith('public')) {
|
|
659
656
|
path = '/' + path
|
|
660
|
-
}
|
|
657
|
+
}
|
|
661
658
|
path = path.replaceAll('.jsx', '.js');
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
string = string.replace(beforePath, path)
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
string = string.replace(beforePath, "'" + path + "'")
|
|
665
662
|
break;
|
|
666
|
-
|
|
663
|
+
|
|
667
664
|
}
|
|
668
|
-
|
|
665
|
+
|
|
669
666
|
let html = fs.existsSync(process.cwd() + '/dist/index.html') ? fs.readFileSync(process.cwd() + '/dist/index.html', 'utf8') : ''
|
|
670
667
|
if (!html.includes(`<link rel="preload" href="${path.replace(/'/g, '').trim()}" as="${path.replace(/'/g, '').trim().includes('.css') ? 'style' : 'script'}">`)
|
|
671
|
-
|
|
672
|
-
) {
|
|
668
|
+
&& !path.includes('.module.css')
|
|
669
|
+
) {
|
|
673
670
|
let preload = `
|
|
674
|
-
${
|
|
675
|
-
|
|
676
|
-
}
|
|
677
|
-
${!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'}">`
|
|
678
674
|
html = html.replace('</head>', `${preload}\n</head>`)
|
|
679
675
|
|
|
680
676
|
fs.writeFileSync(process.cwd() + '/dist/index.html', html)
|
|
@@ -694,9 +690,9 @@ function Compiler(func, file) {
|
|
|
694
690
|
|
|
695
691
|
return string
|
|
696
692
|
}
|
|
697
|
-
|
|
693
|
+
|
|
698
694
|
globalThis.isBuilding = false
|
|
699
|
-
globalThis.isWriting =
|
|
695
|
+
globalThis.isWriting = null
|
|
700
696
|
async function Build() {
|
|
701
697
|
globalThis.isBuilding = true
|
|
702
698
|
console.log('Compiling......')
|
|
@@ -706,16 +702,16 @@ async function Build() {
|
|
|
706
702
|
};
|
|
707
703
|
|
|
708
704
|
let writer = async (file, data) => {
|
|
709
|
-
globalThis.isWriting =
|
|
705
|
+
globalThis.isWriting = file
|
|
710
706
|
switch (true) {
|
|
711
707
|
case !fs.existsSync(file):
|
|
712
708
|
fs.mkdirSync(file.split('/').slice(0, -1).join('/'), { recursive: true })
|
|
713
709
|
break;
|
|
714
710
|
}
|
|
715
|
-
if(globalThis.isWriting !== file){
|
|
711
|
+
if (globalThis.isWriting !== file) {
|
|
716
712
|
return
|
|
717
713
|
}
|
|
718
|
-
await
|
|
714
|
+
await fs.writeFileSync(file, data);
|
|
719
715
|
|
|
720
716
|
globalThis.isWriting = null
|
|
721
717
|
return { _written: true };
|
|
@@ -772,18 +768,18 @@ async function Build() {
|
|
|
772
768
|
await writer(process.cwd() + "/dist/pages/" + fileName.replace('.jsx', '.js'), data).then(async () => {
|
|
773
769
|
|
|
774
770
|
let { minify } = await import('terser')
|
|
775
|
-
|
|
771
|
+
|
|
776
772
|
try {
|
|
777
773
|
let minified = await minify(data, {
|
|
778
774
|
toplevel: true,
|
|
779
|
-
ecma:2016,
|
|
780
|
-
enclose:false,
|
|
775
|
+
ecma: 2016,
|
|
776
|
+
enclose: false,
|
|
781
777
|
module: true,
|
|
782
778
|
compress: true,
|
|
783
779
|
keep_fnames: true,
|
|
784
780
|
|
|
785
781
|
})
|
|
786
|
-
|
|
782
|
+
|
|
787
783
|
await writer(process.cwd() + "/dist/pages/" + fileName.replace('.jsx', '.js'), minified.code)
|
|
788
784
|
} catch (error) {
|
|
789
785
|
console.log(error)
|
|
@@ -887,7 +883,7 @@ async function Build() {
|
|
|
887
883
|
|
|
888
884
|
scannedFiles.forEach(async (file) => {
|
|
889
885
|
file = file.split(process.cwd() + '/runtime/')[1]
|
|
890
|
-
|
|
886
|
+
|
|
891
887
|
let objCase = {
|
|
892
888
|
...file == "app.js" ? { exit: true } : null,
|
|
893
889
|
...file.includes("index.html") && fs.existsSync(process.cwd() + "/runtime/" + file) ? { exit: true } : null,
|
|
@@ -898,11 +894,11 @@ async function Build() {
|
|
|
898
894
|
return
|
|
899
895
|
}
|
|
900
896
|
bundleSize += fs.statSync(process.cwd() + "/runtime/" + file).size;
|
|
901
|
-
let data = await reader(process.cwd() + "/runtime/" + file)
|
|
897
|
+
let data = await reader(process.cwd() + "/runtime/" + file)
|
|
902
898
|
await writer(process.cwd() + "/dist/" + file, data);
|
|
903
899
|
});
|
|
904
900
|
|
|
905
|
-
}
|
|
901
|
+
}
|
|
906
902
|
|
|
907
903
|
globalThis.isBuilding = false
|
|
908
904
|
console.log(`Build complete! ${Math.round(bundleSize / 1000)}${bundleSize > 1000 ? 'kb' : 'bytes'} written to ./dist`)
|
|
@@ -925,13 +921,13 @@ Vader.js v1.3.3
|
|
|
925
921
|
|
|
926
922
|
|
|
927
923
|
Array.from(Array(3).keys()).forEach((i) => {
|
|
928
|
-
let p = `${process.cwd()}${i == 0 ? '/pages/' : i == 1 ? '/src/' : '/public/'}`
|
|
924
|
+
let p = `${process.cwd()}${i == 0 ? '/pages/' : i == 1 ? '/src/' : '/public/'}`
|
|
929
925
|
watch(p
|
|
930
926
|
, { recursive: true }, (event, filename) => {
|
|
931
927
|
if (event == 'change'
|
|
932
928
|
&& !globalThis.isBuilding
|
|
933
929
|
) {
|
|
934
|
-
|
|
930
|
+
|
|
935
931
|
Build()
|
|
936
932
|
}
|
|
937
933
|
}).on('error', (err) => console.log(err))
|