@rip-lang/server 1.3.1 → 1.3.3

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/middleware.rip CHANGED
@@ -521,31 +521,31 @@ export serve = (opts = {}) ->
521
521
  name = c.req.path.slice("#{prefix}/components/".length)
522
522
  c.send "#{routesDir}/#{name}", 'text/plain; charset=UTF-8'
523
523
 
524
- # Route: {prefix}/bundle — all components + app data as JSON
525
- get "#{prefix}/bundle", (c) ->
524
+ # Route: {prefix}/bundle — all components + app data as JSON (cached, rebuilt on file change)
525
+ bundleCache = { json: null, etag: null }
526
+
527
+ buildBundle = ->
526
528
  glob = new Bun.Glob("**/*.rip")
527
529
  components = {}
528
- paths = Array.from(glob.scanSync(routesDir)).sort()
529
- for path in paths
530
+ for path in Array.from(glob.scanSync(routesDir)).sort()
530
531
  components["components/#{path}"] = Bun.file("#{routesDir}/#{path}").text!
531
-
532
532
  for dir in componentDirs
533
- incPaths = Array.from(glob.scanSync(dir)).sort()
534
- for path in incPaths
533
+ for path in Array.from(glob.scanSync(dir)).sort()
535
534
  key = "components/_lib/#{path}"
536
535
  components[key] = Bun.file("#{dir}/#{path}").text! unless components[key]
537
-
538
536
  data = {}
539
537
  data.title = appTitle if appTitle
540
538
  data.watch = enableWatch
541
539
  if appState
542
540
  data[k] = v for k, v of appState
541
+ bundleCache.json = JSON.stringify({ components, data })
542
+ bundleCache.etag = "W/\"#{Bun.hash(bundleCache.json).toString(36)}\""
543
543
 
544
- json = JSON.stringify({ components, data })
545
- etag = "W/\"#{Bun.hash(json).toString(36)}\""
546
- if c.req.header('if-none-match') is etag
547
- return new Response(null, { status: 304, headers: { 'ETag': etag } })
548
- new Response json, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', 'ETag': etag }
544
+ get "#{prefix}/bundle", (c) ->
545
+ buildBundle! unless bundleCache.json
546
+ if c.req.header('if-none-match') is bundleCache.etag
547
+ return new Response(null, { status: 304, headers: { 'ETag': bundleCache.etag, 'Cache-Control': 'no-cache' } })
548
+ new Response bundleCache.json, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', 'ETag': bundleCache.etag }
549
549
 
550
550
  # Register watch directories with rip-server via control socket
551
551
  if enableWatch and process.env.SOCKET_PREFIX
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rip-lang/server",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Pure Rip web framework and application server",
5
5
  "type": "module",
6
6
  "main": "api.rip",
package/server.rip CHANGED
@@ -591,7 +591,8 @@ class Manager
591
591
  broadcast('css')
592
592
  watchers.push(w)
593
593
  catch e
594
- console.warn "rip-server: watch failed for #{dir}:\n #{e.message}"
594
+ rel = dir.replace(process.cwd() + '/', '')
595
+ console.warn "rip-server: watch skipped (#{e.code or 'error'}): #{rel}"
595
596
  @appWatchers.set prefix, { watchers, timer }
596
597
 
597
598
  spawnWorker: (version) ->