Skip to content

Commit 28123ad

Browse files
committed
refactor(project): Defer initial build after watchers are ready
Triggering the initial build before initializing the watchers caused the perf logging of build/caching related tasks to be inaccurate as the watchers can delay the build significantly. In context of the improvements via #1400 this will likely not be a problem anymore, but it is still better to have a clear order defined and only start initial builds after the watchers are ready.
1 parent 7aff80b commit 28123ad

1 file changed

Lines changed: 27 additions & 27 deletions

File tree

packages/project/lib/build/BuildServer.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,15 @@ class BuildServer extends EventEmitter {
5252
/**
5353
* Creates a new BuildServer instance
5454
*
55-
* Initializes readers for different project combinations and optionally enqueues an
56-
* initial build of specified dependencies. File watching is set up separately via
57-
* {@link BuildServer.create}, which awaits watcher readiness before returning.
55+
* Initializes readers for different project combinations. File watching and any initial
56+
* builds are set up separately via {@link BuildServer.create}, which awaits watcher
57+
* readiness before enqueueing initial builds and returning.
5858
*
5959
* @private
6060
* @param {@ui5/project/graph/ProjectGraph} graph Project graph containing all projects
6161
* @param {@ui5/project/build/ProjectBuilder} projectBuilder Builder instance for executing builds
62-
* @param {boolean} initialBuildRootProject Whether to build the root project in the initial build
63-
* @param {string[]} initialBuildIncludedDependencies Project names to include in initial build
64-
* @param {string[]} initialBuildExcludedDependencies Project names to exclude from initial build
6562
*/
66-
constructor(
67-
graph, projectBuilder,
68-
initialBuildRootProject, initialBuildIncludedDependencies, initialBuildExcludedDependencies
69-
) {
63+
constructor(graph, projectBuilder) {
7064
super();
7165
this.#graph = graph;
7266
this.#rootProjectName = graph.getRoot().getName();
@@ -94,20 +88,6 @@ class BuildServer extends EventEmitter {
9488
for (const dep of dependencies) {
9589
this.#projectBuildStatus.set(dep.getName(), new ProjectBuildStatus());
9690
}
97-
98-
if (initialBuildRootProject) {
99-
log.verbose("Enqueueing root project for initial build");
100-
this.#enqueueBuild(this.#rootProjectName);
101-
}
102-
if (initialBuildIncludedDependencies.length > 0) {
103-
// Enqueue initial build dependencies
104-
for (const projectName of initialBuildIncludedDependencies) {
105-
if (!initialBuildExcludedDependencies.includes(projectName)) {
106-
log.verbose(`Enqueueing project '${projectName}' for initial build`);
107-
this.#enqueueBuild(projectName);
108-
}
109-
}
110-
}
11191
}
11292

11393
/**
@@ -118,6 +98,9 @@ class BuildServer extends EventEmitter {
11898
* Windows, where chokidar's <code>ReadDirectoryChangesW</code> backend has noticeably
11999
* higher startup latency than inotify/FSEvents.
120100
*
101+
* Initial builds are enqueued only after the watcher is ready, so any source changes
102+
* occurring during those builds are reliably detected.
103+
*
121104
* @public
122105
* @param {@ui5/project/graph/ProjectGraph} graph Project graph containing all projects
123106
* @param {@ui5/project/build/ProjectBuilder} projectBuilder Builder instance for executing builds
@@ -130,14 +113,31 @@ class BuildServer extends EventEmitter {
130113
graph, projectBuilder,
131114
initialBuildRootProject, initialBuildIncludedDependencies, initialBuildExcludedDependencies
132115
) {
133-
const buildServer = new BuildServer(
134-
graph, projectBuilder,
116+
const buildServer = new BuildServer(graph, projectBuilder);
117+
await buildServer.#initWatcher();
118+
buildServer.#enqueueInitialBuilds(
135119
initialBuildRootProject, initialBuildIncludedDependencies, initialBuildExcludedDependencies
136120
);
137-
await buildServer.#initWatcher();
138121
return buildServer;
139122
}
140123

124+
#enqueueInitialBuilds(
125+
initialBuildRootProject, initialBuildIncludedDependencies, initialBuildExcludedDependencies
126+
) {
127+
if (initialBuildRootProject) {
128+
log.verbose("Enqueueing root project for initial build");
129+
this.#enqueueBuild(this.#rootProjectName);
130+
}
131+
if (initialBuildIncludedDependencies.length > 0) {
132+
for (const projectName of initialBuildIncludedDependencies) {
133+
if (!initialBuildExcludedDependencies.includes(projectName)) {
134+
log.verbose(`Enqueueing project '${projectName}' for initial build`);
135+
this.#enqueueBuild(projectName);
136+
}
137+
}
138+
}
139+
}
140+
141141
async #initWatcher() {
142142
const watchHandler = new WatchHandler();
143143
this.#watchHandler = watchHandler;

0 commit comments

Comments
 (0)