vaderjs 1.3.3-6124766be812 → 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.
- package/package.json +1 -1
- package/vader.js +162 -170
package/package.json
CHANGED
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 =
|
|
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:
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
e
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
295
|
-
}
|
|
278
|
+
return e;
|
|
279
|
+
});
|
|
296
280
|
|
|
297
|
-
return e.trim();
|
|
298
|
-
});
|
|
299
281
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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(
|
|
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,13 +511,12 @@ function Compiler(func, file) {
|
|
|
531
511
|
|
|
532
512
|
}
|
|
533
513
|
else if (prop.includes('${')) {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
prop = prop.replace('="', ':').replace('}"', '}')
|
|
537
|
-
if (prop.includes('${')) {
|
|
538
|
-
prop = prop.replace('="', ':')
|
|
539
|
-
prop = prop.replace('${', '')
|
|
540
514
|
|
|
515
|
+
|
|
516
|
+
prop = prop.replace('="', ':')
|
|
517
|
+
if (prop.includes('${')) {
|
|
518
|
+
prop = prop.replace('="', ':')
|
|
519
|
+
prop = prop.replace('${', '')
|
|
541
520
|
}
|
|
542
521
|
if (prop.includes('="${{')) {
|
|
543
522
|
prop = prop.replace('${{', '{')
|
|
@@ -547,19 +526,21 @@ function Compiler(func, file) {
|
|
|
547
526
|
}
|
|
548
527
|
|
|
549
528
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
if(value.endsWith('}')){
|
|
557
|
-
value = value.slice(0, -1)
|
|
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*$/, '')
|
|
558
535
|
}
|
|
559
|
-
|
|
536
|
+
|
|
537
|
+
if (value[0] == 'style' && isObj) {
|
|
538
|
+
value[1] = `this.parseStyle(${value[1]})`
|
|
539
|
+
}
|
|
540
|
+
prop = `${value[0]}:${value[1]}`
|
|
560
541
|
}
|
|
561
542
|
|
|
562
|
-
if (prop.includes('function')) {
|
|
543
|
+
if (prop.includes('function') || prop.includes('=>')) {
|
|
563
544
|
// parse 'function' to function
|
|
564
545
|
prop = prop.replace("'", '')
|
|
565
546
|
|
|
@@ -570,13 +551,13 @@ function Compiler(func, file) {
|
|
|
570
551
|
|
|
571
552
|
prop = prop.replace('=function', ':function')
|
|
572
553
|
}
|
|
573
|
-
|
|
554
|
+
|
|
574
555
|
filteredProps.push(prop);
|
|
575
556
|
|
|
576
557
|
|
|
577
558
|
|
|
578
|
-
}else if (isWithinComponent && prop.includes('}')) {
|
|
579
|
-
|
|
559
|
+
} else if (isWithinComponent && prop.includes('}')) {
|
|
560
|
+
|
|
580
561
|
}
|
|
581
562
|
|
|
582
563
|
|
|
@@ -683,10 +664,10 @@ function Compiler(func, file) {
|
|
|
683
664
|
let text = fs.readFileSync(file, "utf8");
|
|
684
665
|
if (!file.endsWith('.js') && file.endsWith('.jsx')) {
|
|
685
666
|
text = Compiler(text, file);
|
|
686
|
-
|
|
667
|
+
|
|
687
668
|
}
|
|
688
669
|
let dest = file.split('node_modules')[1]
|
|
689
|
-
dest = dest.split(baseFolder)[1]
|
|
670
|
+
dest = dest.split(baseFolder)[1]
|
|
690
671
|
writer(process.cwd() + '/dist/src/' + baseFolder + dest, text)
|
|
691
672
|
let importname = match.split('import')[1].split('from')[0].trim()
|
|
692
673
|
let oldImportstring = match.split('from')[1].trim().replace(/'/g, '').replace(/"/g, '').trim()
|
|
@@ -895,7 +876,7 @@ const glb = await glob("**/**/**/**.{jsx,js}", {
|
|
|
895
876
|
async function Build() {
|
|
896
877
|
globalThis.isBuilding = true
|
|
897
878
|
console.log(globalThis.isProduction ? 'Creating Optimized Production Build\n' : '')
|
|
898
|
-
let str = `Page \t\t\t\t Size\n`
|
|
879
|
+
let str = `Page \t\t\t\t Size\n`
|
|
899
880
|
globalThis.isProduction ? console.log('\x1b[32m%s\x1b[0m', str) : null
|
|
900
881
|
let reader = async (file) => {
|
|
901
882
|
let text = await fs.readFileSync(file, "utf8");
|
|
@@ -903,11 +884,11 @@ async function Build() {
|
|
|
903
884
|
};
|
|
904
885
|
|
|
905
886
|
|
|
906
|
-
|
|
887
|
+
|
|
907
888
|
function ssg(routes = []) {
|
|
908
|
-
globalThis.isBuilding = true
|
|
889
|
+
globalThis.isBuilding = true
|
|
909
890
|
routes.forEach(async (route) => {
|
|
910
|
-
if (route.url.includes(':')) {
|
|
891
|
+
if (route.url.includes(':')) {
|
|
911
892
|
return
|
|
912
893
|
}
|
|
913
894
|
let equalparamroute = routes.map((e) => {
|
|
@@ -927,7 +908,7 @@ async function Build() {
|
|
|
927
908
|
<html lang="en">
|
|
928
909
|
<head>
|
|
929
910
|
<script>
|
|
930
|
-
window.routes = JSON.parse('${JSON.stringify(routes)}')
|
|
911
|
+
window.routes = JSON.parse('${JSON.stringify(routes)}')
|
|
931
912
|
</script>
|
|
932
913
|
<script id="isServer">
|
|
933
914
|
window.isServer = true
|
|
@@ -935,8 +916,7 @@ async function Build() {
|
|
|
935
916
|
<meta charset="UTF-8">
|
|
936
917
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
937
918
|
<script type="module" id="meta">
|
|
938
|
-
window.history.pushState({}, '', '${route.url}')
|
|
939
|
-
|
|
919
|
+
window.history.pushState({}, '', '${route.url}')
|
|
940
920
|
</script>
|
|
941
921
|
<script type="module" id="router">
|
|
942
922
|
import VaderRouter from '/router.js'
|
|
@@ -950,8 +930,16 @@ async function Build() {
|
|
|
950
930
|
res.render(module, req, res, module.$metadata)
|
|
951
931
|
}
|
|
952
932
|
catch(error){
|
|
953
|
-
|
|
954
|
-
|
|
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)
|
|
955
943
|
}
|
|
956
944
|
})
|
|
957
945
|
${equalparamroute.length > 0 ? equalparamroute.map((e) => {
|
|
@@ -964,7 +952,7 @@ async function Build() {
|
|
|
964
952
|
})\n`
|
|
965
953
|
}) : ''}
|
|
966
954
|
router.listen(3000)
|
|
967
|
-
|
|
955
|
+
|
|
968
956
|
</script>
|
|
969
957
|
</head>
|
|
970
958
|
<body>
|
|
@@ -1015,28 +1003,26 @@ async function Build() {
|
|
|
1015
1003
|
const browser = await puppeteer.launch({
|
|
1016
1004
|
headless: "new", args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
1017
1005
|
warning: false,
|
|
1018
|
-
})
|
|
1006
|
+
})
|
|
1019
1007
|
try {
|
|
1020
1008
|
|
|
1021
1009
|
route.url = route.url.replaceAll(/\/:[a-zA-Z0-9_-]+/gs, '')
|
|
1022
1010
|
let page = await browser.newPage();
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
console.error('BROWSER ERROR:', err);
|
|
1011
|
+
// Handle browser errors
|
|
1012
|
+
page.on('error', (err) => {
|
|
1013
|
+
console.error('BROWSER ERROR:', JSON.parse(err));
|
|
1026
1014
|
});
|
|
1027
|
-
|
|
1028
|
-
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
|
1029
|
-
console.log(msg, url, lineNo, columnNo, error)
|
|
1030
|
-
}
|
|
1031
|
-
})
|
|
1015
|
+
|
|
1032
1016
|
try {
|
|
1033
1017
|
page.on('pageerror', async err => {
|
|
1034
|
-
let errorObj =
|
|
1035
|
-
console.log('\x1b[31m%s\x1b[0m', '
|
|
1036
|
-
|
|
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
|
+
}
|
|
1037
1023
|
});
|
|
1038
1024
|
} catch (error) {
|
|
1039
|
-
|
|
1025
|
+
browser.close()
|
|
1040
1026
|
}
|
|
1041
1027
|
// Handle page crashes
|
|
1042
1028
|
page.on('crash', () => {
|
|
@@ -1045,14 +1031,14 @@ async function Build() {
|
|
|
1045
1031
|
page.on('requestfailed', request => {
|
|
1046
1032
|
console.error('REQUEST FAILED:', request.url(), request.failure().errorText);
|
|
1047
1033
|
});
|
|
1048
|
-
|
|
1049
|
-
|
|
1034
|
+
await page.goto(`http://localhost:${port}/`, { waitUntil: 'networkidle2' });
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1050
1040
|
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
1041
|
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
1042
|
await page.evaluate(() => {
|
|
1057
1043
|
document.getElementById('meta').remove()
|
|
1058
1044
|
document.querySelector('#isServer').innerHTML = 'window.isServer = false'
|
|
@@ -1060,29 +1046,29 @@ async function Build() {
|
|
|
1060
1046
|
document.querySelector('#root').innerHTML = ''
|
|
1061
1047
|
console.log(`Disabled prerendering for ${window.location.pathname}`)
|
|
1062
1048
|
}
|
|
1063
|
-
})
|
|
1049
|
+
})
|
|
1064
1050
|
let html = await page.content();
|
|
1065
1051
|
|
|
1066
|
-
html = await prettier.format(html, { parser: "html" })
|
|
1067
|
-
|
|
1068
|
-
|
|
1052
|
+
html = await prettier.format(html, { parser: "html" })
|
|
1053
|
+
|
|
1054
|
+
|
|
1069
1055
|
await writer(process.cwd() + '/dist/' + (route.url === '/' ? 'index.html' : `${route.url}/` + 'index.html'), html)
|
|
1070
|
-
|
|
1056
|
+
|
|
1071
1057
|
|
|
1072
1058
|
} catch (error) {
|
|
1073
|
-
console.log(error)
|
|
1074
|
-
}
|
|
1059
|
+
console.log(error)
|
|
1060
|
+
}
|
|
1075
1061
|
|
|
1076
1062
|
finally {
|
|
1077
|
-
|
|
1078
|
-
server.close()
|
|
1063
|
+
browser.close()
|
|
1064
|
+
server.close()
|
|
1079
1065
|
}
|
|
1080
1066
|
})
|
|
1081
1067
|
|
|
1082
1068
|
let timeout = setTimeout(() => {
|
|
1083
1069
|
globalThis.isBuilding = false
|
|
1084
1070
|
clearTimeout(timeout)
|
|
1085
|
-
}, 1000)
|
|
1071
|
+
}, 1000)
|
|
1086
1072
|
}
|
|
1087
1073
|
|
|
1088
1074
|
globalThis.routes = []
|
|
@@ -1114,14 +1100,15 @@ async function Build() {
|
|
|
1114
1100
|
|
|
1115
1101
|
|
|
1116
1102
|
let data = await fs.readFileSync(origin, "utf8");
|
|
1117
|
-
|
|
1118
|
-
|
|
1103
|
+
|
|
1104
|
+
// gen sourcemap if not production
|
|
1119
1105
|
let size = fs.statSync(origin).size;
|
|
1120
|
-
if(!globalThis.isProduction){
|
|
1121
|
-
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}`
|
|
1122
1109
|
await writer(process.cwd() + "/dist/src/maps/" + fileName.replace('.jsx', '.js.map'), JSON.stringify(sourceMap, null, 2))
|
|
1123
1110
|
}
|
|
1124
|
-
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))
|
|
1125
1112
|
|
|
1126
1113
|
// configure routing for each page
|
|
1127
1114
|
|
|
@@ -1185,17 +1172,18 @@ async function Build() {
|
|
|
1185
1172
|
|
|
1186
1173
|
globalThis.routes.push({ fileName: fileName, url: obj.url, html: '/' + (isBasePath ? 'index.html' : `${obj.url}/` + 'index.html') })
|
|
1187
1174
|
|
|
1188
|
-
|
|
1189
|
-
let stats = {
|
|
1175
|
+
|
|
1176
|
+
let stats = {
|
|
1177
|
+
route: obj.url.padEnd(30),
|
|
1190
1178
|
size: Math.round(size / 1000) + 'kb',
|
|
1191
1179
|
letParentFolder: obj.url.split('/').slice(0, -1).join('/'),
|
|
1192
1180
|
isChildRoute: obj.url.split('/').slice(0, -1).join('/').includes(':') ? true : false,
|
|
1193
1181
|
parentRoute: obj.url.split('/').slice(0, -1).join('/').split(':')[0],
|
|
1194
|
-
|
|
1195
|
-
}
|
|
1182
|
+
|
|
1183
|
+
}
|
|
1196
1184
|
stats.isChildRoute ? stats.route = `? ${obj.url}` : null
|
|
1197
1185
|
let string = `${isBasePath ? '+' : '+'} ${stats.route.padEnd(30)} ${stats.size}`
|
|
1198
|
-
|
|
1186
|
+
|
|
1199
1187
|
globalThis.isProduction ? console.log(string) : null
|
|
1200
1188
|
}
|
|
1201
1189
|
|
|
@@ -1231,9 +1219,13 @@ async function Build() {
|
|
|
1231
1219
|
|
|
1232
1220
|
let data = await reader(process.cwd() + "/src/" + name)
|
|
1233
1221
|
if (name.includes('.jsx')) {
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
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))
|
|
1237
1229
|
return
|
|
1238
1230
|
}
|
|
1239
1231
|
bundleSize += fs.statSync(process.cwd() + "/src/" + name).size;
|
|
@@ -1378,7 +1370,7 @@ const s = () => {
|
|
|
1378
1370
|
console.log(`Server is running on port ${PORT}`);
|
|
1379
1371
|
globalThis.ws = ws
|
|
1380
1372
|
});
|
|
1381
|
-
|
|
1373
|
+
|
|
1382
1374
|
|
|
1383
1375
|
}
|
|
1384
1376
|
|
|
@@ -1404,7 +1396,7 @@ Vader.js v1.3.3
|
|
|
1404
1396
|
if (event == 'change'
|
|
1405
1397
|
&& !globalThis.isBuilding
|
|
1406
1398
|
) {
|
|
1407
|
-
if(globalThis.ws && !globalThis.isWriting){
|
|
1399
|
+
if (globalThis.ws && !globalThis.isWriting) {
|
|
1408
1400
|
globalThis.ws.clients.forEach((client) => {
|
|
1409
1401
|
console.log('Reloading...')
|
|
1410
1402
|
client.send('reload')
|
|
@@ -1432,7 +1424,7 @@ Vader.js v1.3.3
|
|
|
1432
1424
|
Vader.js v1.3.3
|
|
1433
1425
|
Building to ./dist
|
|
1434
1426
|
`)
|
|
1435
|
-
if(fs.existsSync(process.cwd() + '/dist/src/maps')){
|
|
1427
|
+
if (fs.existsSync(process.cwd() + '/dist/src/maps')) {
|
|
1436
1428
|
fs.rmSync(process.cwd() + '/dist/src/maps', { recursive: true })
|
|
1437
1429
|
}
|
|
1438
1430
|
Build()
|