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.
Files changed (2) hide show
  1. package/main.js +95 -93
  2. 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(require.resolve('vaderjs/bundler/index.js'), process.cwd() + '/dev/bundler.js')
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
- if (mode == 'development' || mode == 'serve') {
461
- let server = Bun.serve({
462
- port: port || 8080,
463
- websocket: {
464
- open(ws) {
465
- globalThis.clients.push(ws)
466
- ws.send('Connected')
467
- },
468
- message(ws, message) {
469
- globalThis.clients.forEach(c => {
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
- async fetch(req, res) {
476
- if (res.upgrade(req)) {
477
- return new Response('Upgraded', { status: 101 })
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
- router.reload()
500
- let route = router.match(url.pathname)
501
- if (!route) {
502
- return new Response('Not found', { status: 404 })
503
- }
504
- let p = route.pathname;
505
- let base = path.dirname(route.filePath)
506
- base = base.replace(/\\/g, '/')
507
- base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '')
508
- base = base.replace(/\\/g, '/').replace('/app', '/dist')
509
- base = process.cwd() + "/dist/" + base
510
- if(!fs.existsSync(path.join(base, 'index.html'))){
511
- return new Response(`
512
- <html>
513
- <head>
514
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
515
- <meta http-equiv="refresh" content="5">
516
- </head>
517
- <body>
518
- <h1>404 Not Found</h1>
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
- console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "1.8.3",
3
+ "version": "1.8.4",
4
4
  "description": "A simple and powerful JavaScript library for building modern web applications.",
5
5
  "bin": {
6
6
  "vaderjs": "./main.js"