@@ -2,6 +2,8 @@ import path from "node:path";
22import os from "node:os" ;
33import chalk from "chalk" ;
44import baseMiddleware from "../middlewares/base.js" ;
5+ import { getLogger } from "@ui5/logger" ;
6+ const log = getLogger ( "cli:commands:serve" ) ;
57
68// Serve
79const serve = {
@@ -61,19 +63,54 @@ serve.builder = function(cli) {
6163 default : false ,
6264 type : "boolean"
6365 } )
66+ . option ( "cache" , {
67+ describe :
68+ "Cache mode to use for building UI5 projects. " +
69+ "The 'Default' behavior is to always use the build-cache if available. 'Force' uses the cache only. " +
70+ "If the build-cache is unavailable or invalid, the server will fail to build the project. " +
71+ "'ReadOnly' does not create or update any cache but makes use of a cache if available. " +
72+ "'Off' does not use any build-cache and always triggers a rebuild of the project" ,
73+ type : "string" ,
74+ default : "Default" ,
75+ choices : [ "Default" , "Force" , "ReadOnly" , "Off" ] ,
76+ } )
77+ . coerce ( "cache" , ( opt ) => {
78+ const lower = opt . toLowerCase ( ) ;
79+ if ( lower === "readonly" || lower === "read-only" ) {
80+ return "ReadOnly" ;
81+ }
82+ return lower . charAt ( 0 ) . toUpperCase ( ) + lower . slice ( 1 ) ;
83+ } )
6484 . option ( "framework-version" , {
6585 describe : "Overrides the framework version defined by the project. " +
6686 "Takes the same value as the version part of \"ui5 use\"" ,
6787 type : "string"
6888 } )
6989 . option ( "cache-mode" , {
90+ // Deprecated
91+ hidden : true ,
92+ describe :
93+ "As of UI5 CLI version 5, renamed to '--snapshot-cache'. " +
94+ "Use '--snapshot-cache' to control this behavior." ,
95+ type : "string" ,
96+ choices : [ "Default" , "Force" , "Off" ] ,
97+ } )
98+ . coerce ( "cache-mode" , ( opt ) => {
99+ // Log a warning if this option is used
100+ if ( opt !== undefined ) {
101+ log . warn ( "As of UI5 CLI version 5, '--cache-mode' is renamed to '--snapshot-cache'. " +
102+ "Use '--snapshot-cache' to control this behavior." ) ;
103+ }
104+ return opt ;
105+ } )
106+ . option ( "snapshot-cache" , {
70107 describe :
71108 "Cache mode to use when consuming SNAPSHOT versions of framework dependencies. " +
72109 "The 'Default' behavior is to invalidate the cache after 9 hours. 'Force' uses the cache only and " +
73110 "does not create any requests. 'Off' invalidates any existing cache and updates from the repository" ,
74111 type : "string" ,
75- default : "Default" ,
76- choices : [ "Default" , "Force" , "Off" ]
112+ defaultDescription : "Default" , // Use "defaultdescription" to allow undefined (needed for evaluation)
113+ choices : [ "Default" , "Force" , "Off" ] ,
77114 } )
78115 . example ( "ui5 serve" , "Start a web server for the current project" )
79116 . example ( "ui5 serve --h2" , "Enable the HTTP/2 protocol for the web server (requires SSL certificate)" )
@@ -95,13 +132,13 @@ serve.handler = async function(argv) {
95132 filePath : argv . dependencyDefinition ,
96133 rootConfigPath : argv . config ,
97134 versionOverride : argv . frameworkVersion ,
98- cacheMode : argv . cacheMode ,
135+ snapshotCache : argv . snapshotCache ?? argv . cacheMode ?? "Default" , // Use cacheMode as fallback
99136 } ) ;
100137 } else {
101138 graph = await graphFromPackageDependencies ( {
102139 rootConfigPath : argv . config ,
103140 versionOverride : argv . frameworkVersion ,
104- cacheMode : argv . cacheMode ,
141+ snapshotCache : argv . snapshotCache ?? argv . cacheMode ?? "Default" , // Use cacheMode as fallback
105142 workspaceConfigPath : argv . workspaceConfig ,
106143 workspaceName : argv . workspace === false ? null : argv . workspace ,
107144 } ) ;
@@ -137,7 +174,8 @@ serve.handler = async function(argv) {
137174 cert : argv . h2 ? argv . cert : undefined ,
138175 key : argv . h2 ? argv . key : undefined ,
139176 sendSAPTargetCSP : ! ! argv . sapCspPolicies ,
140- serveCSPReports : ! ! argv . serveCspReports
177+ serveCSPReports : ! ! argv . serveCspReports ,
178+ cache : argv . cache ,
141179 } ;
142180
143181 if ( serverConfig . h2 ) {
@@ -146,7 +184,10 @@ serve.handler = async function(argv) {
146184 serverConfig . cert = cert ;
147185 }
148186
149- const { h2, port : actualPort } = await serverServe ( graph , serverConfig ) ;
187+ const { promise : pOnError , reject} = Promise . withResolvers ( ) ;
188+ const { h2, port : actualPort } = await serverServe ( graph , serverConfig , function ( err ) {
189+ reject ( err ) ;
190+ } ) ;
150191
151192 const protocol = h2 ? "https" : "http" ;
152193 let browserUrl = protocol + "://localhost:" + actualPort ;
@@ -183,6 +224,7 @@ serve.handler = async function(argv) {
183224 const { default : open } = await import ( "open" ) ;
184225 open ( browserUrl ) ;
185226 }
227+ await pOnError ; // Await errors that should bubble into the yargs handler
186228} ;
187229
188230export default serve ;
0 commit comments