@rip-lang/server 0.7.8 → 0.7.10

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/package.json +1 -1
  2. package/server.rip +61 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rip-lang/server",
3
- "version": "0.7.8",
3
+ "version": "0.7.10",
4
4
  "description": "Pure Rip application server — multi-worker, hot reload, HTTPS, mDNS",
5
5
  "type": "module",
6
6
  "main": "server.rip",
package/server.rip CHANGED
@@ -188,6 +188,11 @@ parseFlags = (argv) ->
188
188
  appPathInput = null
189
189
  appAliases = []
190
190
 
191
+ # Check if token looks like a flag
192
+ isFlag = (tok) ->
193
+ tok.startsWith('-') or tok.startsWith('--') or /^\d+$/.test(tok) or tok in ['http', 'https']
194
+
195
+ # Try to resolve a token as an app path
191
196
  tryResolveApp = (tok) ->
192
197
  looksLikePath = tok.includes('/') or tok.startsWith('.') or isAbsolute(tok) or tok.endsWith('.rip') or tok.endsWith('.ts')
193
198
  return undefined unless looksLikePath
@@ -200,23 +205,46 @@ parseFlags = (argv) ->
200
205
  for i in [2...argv.length]
201
206
  tok = argv[i]
202
207
  unless appPathInput
203
- if tok.includes('@')
208
+ # Handle path@alias syntax
209
+ if tok.includes('@') and not tok.startsWith('-')
204
210
  [pathPart, aliasesPart] = tok.split('@')
205
211
  maybe = tryResolveApp(pathPart)
206
212
  if maybe
207
213
  appPathInput = maybe
208
214
  appAliases = aliasesPart.split(',').map((a) -> a.trim()).filter((a) -> a)
209
215
  continue
216
+ # pathPart might be an alias, not a path - check if entry exists in cwd
217
+ else if not pathPart.includes('/') and not pathPart.startsWith('.')
218
+ appAliases = [pathPart].concat(aliasesPart.split(',').map((a) -> a.trim()).filter((a) -> a))
219
+ continue
220
+
221
+ # Try as path first
210
222
  maybe = tryResolveApp(tok)
211
223
  if maybe
212
224
  appPathInput = maybe
213
225
  continue
226
+
227
+ # If not a flag and not a path, treat as app name/alias
228
+ unless isFlag(tok)
229
+ appAliases.push(tok)
230
+ continue
231
+
214
232
  rawFlags.add(tok)
215
233
 
234
+ # Default to current directory if no path specified
216
235
  unless appPathInput
217
- console.error 'Usage: bun server.rip [flags] <app-path>'
218
- console.error ' bun server.rip [flags] <app-path>@<alias1>,<alias2>,...'
219
- process.exit(2)
236
+ cwd = process.cwd()
237
+ indexRip = join(cwd, 'index.rip')
238
+ indexTs = join(cwd, 'index.ts')
239
+ if existsSync(indexRip)
240
+ appPathInput = indexRip
241
+ else if existsSync(indexTs)
242
+ appPathInput = indexTs
243
+ else
244
+ console.error 'No app entry found. Looked for index.rip or index.ts in current directory.'
245
+ console.error 'Usage: rip-server [flags] [app-path] [app-name]'
246
+ console.error ' rip-server [flags] [app-path]@<alias1>,<alias2>,...'
247
+ process.exit(2)
220
248
 
221
249
  getKV = (prefix) ->
222
250
  for f from rawFlags
@@ -281,6 +309,13 @@ parseFlags = (argv) ->
281
309
  # Debug mode
282
310
  _debugMode = has('--debug')
283
311
 
312
+ # Watch mode: -w, --watch, -w=glob, --watch=glob
313
+ watchGlob = do ->
314
+ return getKV('-w=') if getKV('-w=')?
315
+ return getKV('--watch=') if getKV('--watch=')?
316
+ return '*.rip' if has('-w') or has('--watch')
317
+ null
318
+
284
319
  httpsPort = do ->
285
320
  kv = getKV('--https-port=')
286
321
  return coerceInt(kv, 443) if kv?
@@ -310,6 +345,7 @@ parseFlags = (argv) ->
310
345
  readTimeoutMs: coerceInt(getKV('--read-timeout-ms='), coerceInt(process.env.RIP_READ_TIMEOUT_MS, 5000))
311
346
  jsonLogging: has('--json-logging')
312
347
  accessLog: not has('--no-access-log')
348
+ watchGlob: watchGlob
313
349
  }
314
350
 
315
351
  # ==============================================================================
@@ -476,20 +512,27 @@ class Manager
476
512
  @rollingRestart!.finally => @isRolling = false
477
513
  , 50
478
514
 
479
- # Watch all .rip files in app directory - touch entry file on changes
480
- entryFile = @flags.appEntry
481
- entryBase = basename(entryFile)
482
- try
483
- watch @flags.appBaseDir, { recursive: true }, (event, filename) =>
484
- return unless filename?.endsWith('.rip')
485
- return if filename is entryBase or filename.endsWith("/#{entryBase}")
486
- try
487
- now = new Date()
488
- utimesSync(entryFile, now, now)
489
- catch
490
- null
491
- catch e
492
- console.warn "rip-server: directory watch failed: #{e.message}"
515
+ # Watch files in app directory - touch entry file on changes (opt-in via -w/--watch)
516
+ if @flags.watchGlob
517
+ entryFile = @flags.appEntry
518
+ entryBase = basename(entryFile)
519
+ watchExt = if @flags.watchGlob.startsWith('*.') then @flags.watchGlob.slice(1) else null
520
+ try
521
+ watch @flags.appBaseDir, { recursive: true }, (event, filename) =>
522
+ return unless filename
523
+ # Match by extension (e.g., *.rip) or exact glob
524
+ if watchExt
525
+ return unless filename.endsWith(watchExt)
526
+ else
527
+ return unless filename is @flags.watchGlob or filename.endsWith("/#{@flags.watchGlob}")
528
+ return if filename is entryBase or filename.endsWith("/#{entryBase}")
529
+ try
530
+ now = new Date()
531
+ utimesSync(entryFile, now, now)
532
+ catch
533
+ null
534
+ catch e
535
+ console.warn "rip-server: directory watch failed: #{e.message}"
493
536
 
494
537
  stop: ->
495
538
  for w in @workers