vaderjs 1.8.3 → 1.8.4
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/main.js +95 -93
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -180,7 +180,7 @@ const handleReplacements = (code) => {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
if (!fs.existsSync(process.cwd() + '/dev/bundler.js')) {
|
|
183
|
-
fs.copyFileSync(
|
|
183
|
+
fs.copyFileSync(process.cwd() + '/node_modules/vaderjs/dev/bundler.js', process.cwd() + '/dev/bundler.js')
|
|
184
184
|
}
|
|
185
185
|
let start = Date.now()
|
|
186
186
|
async function generateApp() {
|
|
@@ -457,103 +457,105 @@ else if (mode == 'production') {
|
|
|
457
457
|
}
|
|
458
458
|
else {
|
|
459
459
|
if (isBuilding) console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
c.send(message)
|
|
471
|
-
})
|
|
472
|
-
},
|
|
473
|
-
|
|
460
|
+
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (mode == 'development' || mode == 'serve') {
|
|
464
|
+
let server = Bun.serve({
|
|
465
|
+
port: port || 8080,
|
|
466
|
+
websocket: {
|
|
467
|
+
open(ws) {
|
|
468
|
+
globalThis.clients.push(ws)
|
|
469
|
+
ws.send('Connected')
|
|
474
470
|
},
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
let url = new URL(req.url)
|
|
481
|
-
if (url.pathname.includes('.')) {
|
|
482
|
-
let p = url.pathname.replaceAll("%5B", "[").replaceAll("%5D", "]")
|
|
483
|
-
let file = await Bun.file(path.join(process.cwd() + '/dist' + p))
|
|
484
|
-
if (!await file.exists()) return new Response('Not found', { status: 404 })
|
|
485
|
-
let imageTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/webp', 'image/tiff', 'image/bmp', 'image/ico', 'image/cur', 'image/jxr', 'image/jpg']
|
|
486
|
-
|
|
487
|
-
return new Response(imageTypes.includes(file.type) ? await file.arrayBuffer() : await file.text(), {
|
|
488
|
-
headers: {
|
|
489
|
-
'Content-Type': file.type,
|
|
490
|
-
'Cache-Control': imageTypes.includes(file.type) ? 'max-age=31536000' : 'no-cache',
|
|
491
|
-
'Access-Control-Allow-Origin': '*'
|
|
492
|
-
}
|
|
493
|
-
})
|
|
494
|
-
}
|
|
495
|
-
let router = new Bun.FileSystemRouter({
|
|
496
|
-
dir: process.cwd() + '/app',
|
|
497
|
-
style: 'nextjs'
|
|
471
|
+
message(ws, message) {
|
|
472
|
+
globalThis.clients.forEach(c => {
|
|
473
|
+
c.send(message)
|
|
498
474
|
})
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
<p>Route not found</p>
|
|
520
|
-
</body>
|
|
521
|
-
`, { status: 404 }, {
|
|
522
|
-
headers: {
|
|
523
|
-
'Content-Type': 'text/html'
|
|
524
|
-
}
|
|
525
|
-
})
|
|
526
|
-
}
|
|
527
|
-
let data = await Bun.file(path.join(base, 'index.html')).text()
|
|
528
|
-
if (mode == "development") {
|
|
529
|
-
return new Response(data + `
|
|
530
|
-
<script>
|
|
531
|
-
let ws = new WebSocket('ws://localhost:${server.port}')
|
|
532
|
-
ws.onmessage = (e) => {
|
|
533
|
-
if(e.data === 'reload'){
|
|
534
|
-
console.log('Reloading to display changes from server')
|
|
535
|
-
window.location.reload()
|
|
475
|
+
},
|
|
476
|
+
|
|
477
|
+
},
|
|
478
|
+
async fetch(req, res) {
|
|
479
|
+
if (res.upgrade(req)) {
|
|
480
|
+
return new Response('Upgraded', { status: 101 })
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
let url = new URL(req.url)
|
|
484
|
+
if (url.pathname.includes('.')) {
|
|
485
|
+
let p = url.pathname.replaceAll("%5B", "[").replaceAll("%5D", "]")
|
|
486
|
+
let file = await Bun.file(path.join(process.cwd() + '/dist' + p))
|
|
487
|
+
if (!await file.exists()) return new Response('Not found', { status: 404 })
|
|
488
|
+
let imageTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/webp', 'image/tiff', 'image/bmp', 'image/ico', 'image/cur', 'image/jxr', 'image/jpg']
|
|
489
|
+
|
|
490
|
+
return new Response(imageTypes.includes(file.type) ? await file.arrayBuffer() : await file.text(), {
|
|
491
|
+
headers: {
|
|
492
|
+
'Content-Type': file.type,
|
|
493
|
+
'Cache-Control': imageTypes.includes(file.type) ? 'max-age=31536000' : 'no-cache',
|
|
494
|
+
'Access-Control-Allow-Origin': '*'
|
|
536
495
|
}
|
|
496
|
+
})
|
|
497
|
+
}
|
|
498
|
+
let router = new Bun.FileSystemRouter({
|
|
499
|
+
dir: process.cwd() + '/app',
|
|
500
|
+
style: 'nextjs'
|
|
501
|
+
})
|
|
502
|
+
router.reload()
|
|
503
|
+
let route = router.match(url.pathname)
|
|
504
|
+
if (!route) {
|
|
505
|
+
return new Response('Not found', { status: 404 })
|
|
506
|
+
}
|
|
507
|
+
let p = route.pathname;
|
|
508
|
+
let base = path.dirname(route.filePath)
|
|
509
|
+
base = base.replace(/\\/g, '/')
|
|
510
|
+
base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '')
|
|
511
|
+
base = base.replace(/\\/g, '/').replace('/app', '/dist')
|
|
512
|
+
base = process.cwd() + "/dist/" + base
|
|
513
|
+
if(!fs.existsSync(path.join(base, 'index.html'))){
|
|
514
|
+
return new Response(`
|
|
515
|
+
<html>
|
|
516
|
+
<head>
|
|
517
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
518
|
+
<meta http-equiv="refresh" content="5">
|
|
519
|
+
</head>
|
|
520
|
+
<body>
|
|
521
|
+
<h1>404 Not Found</h1>
|
|
522
|
+
<p>Route not found</p>
|
|
523
|
+
</body>
|
|
524
|
+
`, { status: 404 }, {
|
|
525
|
+
headers: {
|
|
526
|
+
'Content-Type': 'text/html'
|
|
527
|
+
}
|
|
528
|
+
})
|
|
529
|
+
}
|
|
530
|
+
let data = await Bun.file(path.join(base, 'index.html')).text()
|
|
531
|
+
if (mode == "development") {
|
|
532
|
+
return new Response(data + `
|
|
533
|
+
<script>
|
|
534
|
+
let ws = new WebSocket('ws://localhost:${server.port}')
|
|
535
|
+
ws.onmessage = (e) => {
|
|
536
|
+
if(e.data === 'reload'){
|
|
537
|
+
console.log('Reloading to display changes from server')
|
|
538
|
+
window.location.reload()
|
|
537
539
|
}
|
|
538
|
-
</script>
|
|
539
|
-
`, {
|
|
540
|
-
headers: {
|
|
541
|
-
'Content-Type': 'text/html'
|
|
542
|
-
}
|
|
543
|
-
})
|
|
544
|
-
} else {
|
|
545
|
-
return new Response(data, {
|
|
546
|
-
headers: {
|
|
547
|
-
'Content-Type': 'text/html'
|
|
548
|
-
}
|
|
549
|
-
})
|
|
550
|
-
}
|
|
551
|
-
|
|
552
540
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
541
|
+
</script>
|
|
542
|
+
`, {
|
|
543
|
+
headers: {
|
|
544
|
+
'Content-Type': 'text/html'
|
|
545
|
+
}
|
|
546
|
+
})
|
|
547
|
+
} else {
|
|
548
|
+
return new Response(data, {
|
|
549
|
+
headers: {
|
|
550
|
+
'Content-Type': 'text/html'
|
|
551
|
+
}
|
|
552
|
+
})
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
}
|
|
556
|
+
})
|
|
557
|
+
|
|
558
|
+
console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
|
|
557
559
|
}
|
|
558
560
|
|
|
559
561
|
|