@ui5/logger 5.0.0-alpha.5 → 5.0.0-alpha.7

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.
@@ -0,0 +1,218 @@
1
+ import chalk from "chalk";
2
+ import figures from "figures";
3
+ import prettyHrtime from "pretty-hrtime";
4
+ import {STATES} from "./state/build.js";
5
+ import {brand, accent, accentBold, arrow, placeholder} from "./format.js";
6
+ import {REMOTE_CONNECTIONS_WARNING_LINES} from "./remoteConnectionsWarning.js";
7
+
8
+ const SPINNER_FRAMES = ["◐", "◓", "◑", "◒"];
9
+ const STATE_LABEL_WIDTH = "building".length;
10
+ const pad = (s) => s.padEnd(STATE_LABEL_WIDTH);
11
+ // "1 project" / "2 projects" - shared by the stale (ready) and validating counts.
12
+ const projectCount = (n) => `${n} project${n === 1 ? "" : "s"}`;
13
+
14
+ // Align continuation lines (additional network URLs / extra placeholders)
15
+ // under the first URL slot. The arrow, single space, and "Network: " label
16
+ // are all fixed-width.
17
+ const NETWORK_INDENT = " ".repeat(`${figures.pointer} ${"Network:"} `.length);
18
+
19
+ // Order matters: header → project → server → build → status → log-above (log
20
+ // scrolls outside the live region). Each region emits an array of lines and
21
+ // is skipped entirely when it has no content, giving a stable layout that
22
+ // grows top-to-bottom as data arrives. Placeholders (activated by
23
+ // `ui5.tool-mode`) let a region occupy its final row count from the first
24
+ // frame — the layout stops growing once every region is present.
25
+ //
26
+ // Region blocks include a leading blank line, so joining them produces a
27
+ // blank separator between regions.
28
+
29
+ export function renderHeaderRegion(headerState) {
30
+ if (!headerState.tool) {
31
+ return [];
32
+ }
33
+ const version = headerState.tool.version ? chalk.dim("v" + headerState.tool.version) : "";
34
+ return [
35
+ "",
36
+ `${brand(headerState.tool.name || "UI5 CLI")} ${version}`,
37
+ ];
38
+ }
39
+
40
+ export function renderProjectRegion(projectState) {
41
+ if (!projectState.project && !projectState.showPlaceholders) {
42
+ return [];
43
+ }
44
+ const lines = [""];
45
+ if (projectState.project) {
46
+ const project = projectState.project;
47
+ const framework = projectState.framework;
48
+ const resolving = projectState.versionResolving;
49
+ const projectType = project.type ? chalk.dim(`(${project.type})`) : "";
50
+ // While a re-resolve is pending, the version is about to change: show a placeholder in
51
+ // its slot rather than the stale value. The name and type keep showing so the region
52
+ // does not collapse.
53
+ const projectVersion = resolving ?
54
+ placeholder("resolving…") :
55
+ (project.version ? chalk.dim("v" + project.version) : "");
56
+ lines.push(`${chalk.dim("Project")} ${chalk.bold(project.name)}` +
57
+ (projectType ? ` ${projectType}` : "") +
58
+ (projectVersion ? ` ${projectVersion}` : ""));
59
+ // Only emit a Framework row when the project actually declares one.
60
+ // For UI5 apps that get their framework from a runtime middleware
61
+ // (e.g. fiori-tools-proxy) the ui5.yaml has no framework config,
62
+ // making "(none)" misleading; omitting the row also avoids a stale
63
+ // "Framework resolving…" placeholder flashing before it disappears.
64
+ if (framework?.name) {
65
+ // The framework version goes stale alongside the project version on a branch
66
+ // switch: placeholder it too, keeping the name.
67
+ const frameworkVersion = resolving ?
68
+ ` ${placeholder("resolving…")}` :
69
+ (framework.version ? chalk.bold(` ${framework.version}`) : "");
70
+ lines.push(`${chalk.dim("Framework")} ${chalk.bold(framework.name)}${frameworkVersion}`);
71
+ }
72
+ } else {
73
+ // Placeholder mode: reserve only the Project row. The Framework row is
74
+ // deferred until framework resolution reveals a real framework name.
75
+ lines.push(`${chalk.dim("Project")} ${placeholder("resolving…")}`);
76
+ }
77
+ return lines;
78
+ }
79
+
80
+ export function renderServerRegion(serverState) {
81
+ if (!serverState.urls && !serverState.showPlaceholders) {
82
+ return [];
83
+ }
84
+ const lines = [""];
85
+
86
+ if (serverState.urls) {
87
+ // The event's `urls` list carries labels ("Local"/"Network") shaped by
88
+ // the server. Preserve the current two-line "Local" / "Network" layout
89
+ // by splitting labels here.
90
+ const local = [];
91
+ const network = [];
92
+ const other = [];
93
+ for (const entry of serverState.urls) {
94
+ if (entry.label === "Local") {
95
+ local.push(entry);
96
+ } else if (entry.label === "Network") {
97
+ network.push(entry);
98
+ } else {
99
+ other.push(entry);
100
+ }
101
+ }
102
+
103
+ if (local.length > 0) {
104
+ lines.push(`${arrow} ${accentBold("Local:")} ${accent(local[0].url)}`);
105
+ }
106
+ if (network.length > 0) {
107
+ lines.push(`${arrow} ${accentBold("Network:")} ${accent(network[0].url)}`);
108
+ for (let i = 1; i < network.length; i++) {
109
+ lines.push(`${NETWORK_INDENT}${accent(network[i].url)}`);
110
+ }
111
+ } else if (!serverState.acceptRemoteConnections && local.length > 0) {
112
+ lines.push(`${arrow} ${accentBold("Network:")} ` +
113
+ chalk.dim("use --accept-remote-connections to expose"));
114
+ }
115
+ for (const entry of other) {
116
+ lines.push(`${arrow} ${accentBold(entry.label + ":")} ${accent(entry.url)}`);
117
+ }
118
+ } else {
119
+ // Placeholder mode: reserve one "Local:" row plus either the
120
+ // remote-connections hint (when the flag isn't set) or a single
121
+ // "Network:" placeholder. The frame may grow by additional rows once
122
+ // the real URL list arrives; that's acceptable for this uncommon case.
123
+ lines.push(`${arrow} ${accentBold("Local:")} ${placeholder("binding…")}`);
124
+ if (serverState.acceptRemoteConnections) {
125
+ lines.push(`${arrow} ${accentBold("Network:")} ${placeholder("binding…")}`);
126
+ } else {
127
+ lines.push(`${arrow} ${accentBold("Network:")} ` +
128
+ chalk.dim("use --accept-remote-connections to expose"));
129
+ }
130
+ }
131
+
132
+ // `acceptRemoteConnections` reflects user intent, so the warning appears
133
+ // from the first frame even while URLs are still placeholders.
134
+ if (serverState.acceptRemoteConnections) {
135
+ lines.push("");
136
+ for (const line of REMOTE_CONNECTIONS_WARNING_LINES) {
137
+ lines.push(line);
138
+ }
139
+ }
140
+ return lines;
141
+ }
142
+
143
+ export function renderBuildRegion(buildState) {
144
+ if (buildState.state === STATES.INITIAL) {
145
+ return [];
146
+ }
147
+ return ["", renderStatusLine(buildState)];
148
+ }
149
+
150
+ function renderStatusLine(state) {
151
+ const label = `${chalk.dim("Status")} `;
152
+ switch (state.state) {
153
+ case STATES.STARTING:
154
+ return `${label}${chalk.dim(figures.circle)} ${chalk.dim(pad("starting"))}`;
155
+ case STATES.READY: {
156
+ let suffix = "";
157
+ if (state.lastBuildHrtime) {
158
+ suffix = ` ${chalk.dim("·")} ${chalk.dim("Time elapsed: " + prettyHrtime(state.lastBuildHrtime))}`;
159
+ }
160
+ // Append the stale count to the ready line.
161
+ const staleCount = state.staleProjects.length;
162
+ if (staleCount > 0) {
163
+ suffix += ` ${chalk.dim("·")} ` +
164
+ chalk.yellow(`${projectCount(staleCount)} stale`);
165
+ }
166
+ return `${label}${chalk.green(figures.bullet)} ${chalk.green(pad("ready"))}${suffix}`;
167
+ }
168
+ case STATES.SETTLING: {
169
+ const frame = SPINNER_FRAMES[state.spinFrame % SPINNER_FRAMES.length];
170
+ return `${label}${chalk.yellow(frame)} ${chalk.yellow(pad("settling"))} ` +
171
+ `${chalk.dim("· waiting for changes to settle")}`;
172
+ }
173
+ case STATES.VALIDATING: {
174
+ const frame = SPINNER_FRAMES[state.spinFrame % SPINNER_FRAMES.length];
175
+ const parts = [
176
+ `${chalk.cyan(frame)} ${chalk.cyan(pad("validating cache"))}`,
177
+ chalk.dim("·"),
178
+ chalk.dim("checking dependency caches"),
179
+ ];
180
+ const count = state.validatingProjects.length;
181
+ if (count > 0) {
182
+ parts.push(chalk.dim("·"), chalk.dim(projectCount(count)));
183
+ }
184
+ return `${label}${parts.join(" ")}`;
185
+ }
186
+ case STATES.BUILDING: {
187
+ const frame = SPINNER_FRAMES[state.spinFrame % SPINNER_FRAMES.length];
188
+ const parts = [
189
+ `${chalk.yellow(frame)} ${chalk.yellow(pad("building"))}`,
190
+ ];
191
+ if (state.totalProjects > 0 && state.currentProjectIndex > 0) {
192
+ const counterWidth = String(state.totalProjects).length;
193
+ const counter = `${String(state.currentProjectIndex).padStart(counterWidth)}` +
194
+ `/${state.totalProjects} projects`;
195
+ parts.push(chalk.dim("·"), chalk.dim(counter));
196
+ }
197
+ if (state.currentProjectName) {
198
+ const padded = state.projectNameWidth ?
199
+ state.currentProjectName.padEnd(state.projectNameWidth) :
200
+ state.currentProjectName;
201
+ parts.push(chalk.dim("·"), chalk.bold(padded));
202
+ }
203
+ if (state.currentTaskName) {
204
+ const padded = state.taskNameWidth ?
205
+ state.currentTaskName.padEnd(state.taskNameWidth) :
206
+ state.currentTaskName;
207
+ parts.push(chalk.dim("·"), chalk.dim(padded));
208
+ }
209
+ return `${label}${parts.join(" ")}`;
210
+ }
211
+ case STATES.ERROR: {
212
+ const msg = state.errorMessage ? ` · ${state.errorMessage}` : "";
213
+ return `${label}${chalk.red(figures.cross)} ${chalk.red(pad("error"))}${chalk.dim(msg)}`;
214
+ }
215
+ default:
216
+ return label;
217
+ }
218
+ }
@@ -0,0 +1,129 @@
1
+ // Region 5 — build. Populated by `ui5.build-metadata`, `ui5.build-status`,
2
+ // `ui5.project-build-metadata`, `ui5.project-build-status`, `ui5.serve-status`.
3
+
4
+ export const STATES = Object.freeze({
5
+ INITIAL: "initial",
6
+ STARTING: "starting", // pre-populated placeholder before the first real state arrives
7
+ READY: "ready",
8
+ SETTLING: "settling", // changes seen, rebuild deferred until they quiesce
9
+ BUILDING: "building",
10
+ VALIDATING: "validating",
11
+ ERROR: "error",
12
+ });
13
+
14
+ // States that animate a spinner. Consulted by both the tick scheduler in the
15
+ // interactive console writer and the status-line renderer, so a state either
16
+ // spins in both places or in neither.
17
+ export const SPINNING_STATES = new Set([STATES.SETTLING, STATES.BUILDING, STATES.VALIDATING]);
18
+
19
+ export function createBuildState() {
20
+ return {
21
+ state: STATES.INITIAL,
22
+ // During `building`: current project counter (1-based) and total projects.
23
+ // Both are reset by `ui5.build-metadata` and by `serve-building`.
24
+ currentProjectIndex: 0,
25
+ totalProjects: 0,
26
+ currentProjectName: "",
27
+ currentTaskName: "",
28
+ // Names of projects currently stale, reported via `serve-stale`. The renderer surfaces
29
+ // the count alongside the ready line.
30
+ staleProjects: [],
31
+ // Names of projects collected via `serve-validating` payloads — used to
32
+ // label the validating state if/when the renderer wants to.
33
+ validatingProjects: [],
34
+ // Names of projects collected via `serve-settling` payloads — used to
35
+ // label the settling state if/when the renderer wants to.
36
+ pendingProjects: [],
37
+ // Frame counter for the spinner (incremented by the tick loop).
38
+ spinFrame: 0,
39
+ // Most recent error captured by `serve-error`.
40
+ errorMessage: "",
41
+ // Duration of the most recent successful build, captured from the
42
+ // `serve-build-done` event as a [seconds, nanoseconds] tuple — the same
43
+ // shape that pretty-hrtime consumes, so the renderer can hand it
44
+ // straight through.
45
+ lastBuildHrtime: null,
46
+ // Layout hints derived from build-metadata: pad the project/task columns
47
+ // so status-line updates don't reflow.
48
+ projectNameWidth: 0,
49
+ taskNameWidth: 0,
50
+ // Ordered list of projects announced by build-metadata. Used to compute
51
+ // a stable 1-based `currentProjectIndex` when build-status events arrive.
52
+ projectOrder: [],
53
+ // True while the server is serving a last-good graph after a failed re-resolve (e.g. a
54
+ // branch switch to a config the tooling can't resolve). The status line reuses the ERROR
55
+ // rendering; this flag makes it sticky so the surviving BuildServer's `serve-ready` from
56
+ // source churn can't repaint "ready" over it. Set by `ui5.project-resolve-failed`, cleared
57
+ // by `ui5.project-resolve-succeeded`.
58
+ degraded: false,
59
+ };
60
+ }
61
+
62
+ // Zero the transient counters for a fresh build. Shared by `build-metadata`
63
+ // and the `serve-building` branch of `serve-status`; see doc item #7.
64
+ function resetBuildProgress(state) {
65
+ state.currentProjectIndex = 0;
66
+ state.currentProjectName = "";
67
+ state.currentTaskName = "";
68
+ state.spinFrame = 0;
69
+ }
70
+
71
+ export function beginBuild(state, projectOrder) {
72
+ state.projectOrder = Array.from(projectOrder);
73
+ state.totalProjects = state.projectOrder.length;
74
+ state.projectNameWidth = state.projectOrder.reduce(
75
+ (max, name) => Math.max(max, name.length), 0);
76
+ resetBuildProgress(state);
77
+ }
78
+
79
+ export function advanceToProject(state, projectName) {
80
+ const idx = state.projectOrder.indexOf(projectName);
81
+ state.currentProjectIndex = idx >= 0 ?
82
+ idx + 1 :
83
+ state.currentProjectIndex + 1;
84
+ state.currentProjectName = projectName;
85
+ state.currentTaskName = "";
86
+ }
87
+
88
+ export function setTask(state, taskName) {
89
+ state.currentTaskName = taskName;
90
+ if (taskName.length > state.taskNameWidth) {
91
+ state.taskNameWidth = taskName.length;
92
+ }
93
+ }
94
+
95
+ export function transitionTo(state, newState) {
96
+ state.state = newState;
97
+ state.spinFrame = 0;
98
+ }
99
+
100
+ // Record the current stale-project set, reported via `serve-stale`. Does not touch the
101
+ // activity `state` or reset the spinner: the count updates in place beneath the current status.
102
+ export function setStale(state, staleProjects) {
103
+ state.staleProjects = Array.isArray(staleProjects) ? staleProjects : [];
104
+ }
105
+
106
+ export function setError(state, message) {
107
+ state.errorMessage = message || "";
108
+ transitionTo(state, STATES.ERROR);
109
+ }
110
+
111
+ // Marks the server degraded after a failed re-resolve. The caller pairs this with `setError` to
112
+ // render the reason on the ERROR line; this flag keeps that line sticky against later `serve-ready`
113
+ // events from the surviving BuildServer until a successful re-resolve calls `clearDegraded`.
114
+ export function setDegraded(state) {
115
+ state.degraded = true;
116
+ }
117
+
118
+ export function clearDegraded(state) {
119
+ state.degraded = false;
120
+ }
121
+
122
+ // Advance the region into a "starting" placeholder state so the Status row is
123
+ // visible from the first frame. Called from `ui5.tool-mode`. Real state
124
+ // transitions (READY/BUILDING/…) replace it.
125
+ export function enableBuildPlaceholders(state) {
126
+ if (state.state === STATES.INITIAL) {
127
+ state.state = STATES.STARTING;
128
+ }
129
+ }
@@ -0,0 +1,10 @@
1
+ // Region 1 — header. Populated by `ui5.tool-info`. Set once, never changes.
2
+ export function createHeaderState() {
3
+ return {
4
+ tool: null, // {name, version} — null while unknown
5
+ };
6
+ }
7
+
8
+ export function setTool(state, tool) {
9
+ state.tool = tool ? {name: tool.name, version: tool.version} : null;
10
+ }
@@ -0,0 +1,47 @@
1
+ // Region 2 - root project. Populated by `ui5.project-resolve-succeeded` and, when
2
+ // framework usage is actually resolved for the current run, by
3
+ // `ui5.project-framework-resolved`.
4
+ export function createProjectState() {
5
+ return {
6
+ project: null, // {name, type, version}
7
+ framework: null, // {name, version} | null
8
+ // When true, the region renders dim "resolving…" placeholders in place
9
+ // of real data. Enabled by `ui5.tool-mode` before the graph is built so
10
+ // the layout is stable from the very first frame.
11
+ showPlaceholders: false,
12
+ // When true, the version slot(s) render a dim "resolving" placeholder while the project
13
+ // name and type keep showing. Enabled by `ui5.project-resolve-started` once a definition
14
+ // change is known to be coming (a `git checkout`, a ui5.yaml edit) and the resolved version
15
+ // is about to change. `setProject` clears it; a failed re-resolve releases it via
16
+ // `clearVersionResolving`.
17
+ versionResolving: false,
18
+ };
19
+ }
20
+
21
+ export function setProject(state, evt) {
22
+ state.project = {name: evt.name, type: evt.type, version: evt.version};
23
+ // A resolve completed: drop the placeholder in favour of the new version.
24
+ state.versionResolving = false;
25
+ }
26
+
27
+ export function setFramework(state, framework) {
28
+ state.framework = framework ? {
29
+ name: framework.name,
30
+ version: framework.version,
31
+ } : null;
32
+ }
33
+
34
+ export function enableProjectPlaceholders(state) {
35
+ state.showPlaceholders = true;
36
+ }
37
+
38
+ // Blanks the version slot(s) to a "resolving" placeholder: a re-resolve is coming.
39
+ export function setVersionResolving(state) {
40
+ state.versionResolving = true;
41
+ }
42
+
43
+ // Releases the placeholder back to the last-known version: a re-resolve was abandoned or failed
44
+ // with no `ui5.project-resolve-succeeded`.
45
+ export function clearVersionResolving(state) {
46
+ state.versionResolving = false;
47
+ }
@@ -0,0 +1,23 @@
1
+ // Region 4 — server. Populated by `ui5.server-listening`.
2
+ export function createServerState() {
3
+ return {
4
+ urls: null, // Array<{label, url}> | null
5
+ acceptRemoteConnections: false,
6
+ // When true, the region renders "binding…" placeholders in place of real
7
+ // URLs. Enabled by `ui5.tool-mode` so the section is visible from the
8
+ // first frame; `acceptRemoteConnections` fine-tunes what gets reserved.
9
+ showPlaceholders: false,
10
+ };
11
+ }
12
+
13
+ export function setListening(state, evt) {
14
+ state.urls = Array.isArray(evt.urls) ? evt.urls.map((u) => ({label: u.label, url: u.url})) : [];
15
+ state.acceptRemoteConnections = !!evt.acceptRemoteConnections;
16
+ }
17
+
18
+ export function enableServerPlaceholders(state, {acceptRemoteConnections} = {}) {
19
+ state.showPlaceholders = true;
20
+ if (typeof acceptRemoteConnections === "boolean") {
21
+ state.acceptRemoteConnections = acceptRemoteConnections;
22
+ }
23
+ }
@@ -0,0 +1,41 @@
1
+ import {chalkStderr as chalk} from "chalk";
2
+
3
+ // Shared message-formatting helpers used by every console-writing writer so
4
+ // scrolled log lines look identical regardless of which writer produced them.
5
+ // Kept as an internal helper module rather than a public export — the exact
6
+ // styling is an implementation detail of `writers/Console` and its siblings.
7
+
8
+ function getLevelPrefix(level) {
9
+ switch (level) {
10
+ case "silly":
11
+ return chalk.inverse(level);
12
+ case "verbose":
13
+ return chalk.cyan("verb");
14
+ case "perf":
15
+ return chalk.bgYellow.red(level);
16
+ case "info":
17
+ return chalk.green(level);
18
+ case "warn":
19
+ return chalk.yellow(level);
20
+ case "error":
21
+ return chalk.bgRed.white(level);
22
+ default:
23
+ // Log level silent does not produce messages
24
+ throw new Error(`writers/internal/format: Invalid message log level "${level}"`);
25
+ }
26
+ }
27
+
28
+ // Prepend the blue module name to a message when one is present. Both console
29
+ // writers render log messages as "<moduleName> <message>", omitting the module
30
+ // name when it is absent.
31
+ export function prefixModuleName(message, moduleName) {
32
+ return moduleName ? `${chalk.blue(moduleName)} ${message}` : message;
33
+ }
34
+
35
+ // Render a full log line as "<levelPrefix> <message>". The trailing newline is
36
+ // left to the caller: `writers/Console` writes straight to the stream and needs
37
+ // it, while `writers/InteractiveConsole` hands the line to log-update, which
38
+ // adds its own.
39
+ export function formatLogLine(level, message) {
40
+ return `${getLevelPrefix(level)} ${message}`;
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/logger",
3
- "version": "5.0.0-alpha.5",
3
+ "version": "5.0.0-alpha.7",
4
4
  "description": "UI5 CLI - Internal Logger",
5
5
  "author": {
6
6
  "name": "SAP SE",
@@ -50,13 +50,16 @@
50
50
  "dependencies": {
51
51
  "chalk": "^5.6.2",
52
52
  "cli-progress": "^3.12.0",
53
- "figures": "^6.1.0"
53
+ "figures": "^6.1.0",
54
+ "log-update": "^8.0.0",
55
+ "pretty-hrtime": "^1.0.3",
56
+ "slice-ansi": "^5.0.0"
54
57
  },
55
58
  "devDependencies": {
56
59
  "@istanbuljs/esm-loader-hook": "^0.3.0",
57
60
  "ava": "^6.4.1",
58
61
  "cross-env": "^10.1.0",
59
- "eslint": "^10.5.0",
62
+ "eslint": "^10.7.0",
60
63
  "nyc": "^18.0.0",
61
64
  "rimraf": "^6.1.3",
62
65
  "sinon": "^21.1.2",