Skip to content

Commit a9b68df

Browse files
committed
test(project): Update ProjectBuilder tests and JSDoc
1 parent 8c84c4e commit a9b68df

2 files changed

Lines changed: 162 additions & 127 deletions

File tree

packages/project/lib/build/ProjectBuilder.js

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,33 @@ class ProjectBuilder {
120120
this.#log = new BuildLogger("ProjectBuilder");
121121
}
122122

123+
/**
124+
* Propagate resource changes through the build context
125+
*
126+
* @public
127+
* @param {Array} changes Array of resource changes to propagate
128+
* @returns {Promise<void>} Promise resolving when changes have been propagated
129+
* @throws {Error} If a build is currently running
130+
*/
123131
resourcesChanged(changes) {
124132
if (this.#buildIsRunning) {
125133
throw new Error(`Unable to safely propagate resource changes. Build is currently running.`);
126134
}
127135
return this._buildContext.propagateResourceChanges(changes);
128136
}
129137

138+
/**
139+
* Build projects without writing to a target directory
140+
*
141+
* @public
142+
* @param {object} parameters Parameters
143+
* @param {boolean} [parameters.includeRootProject=true] Whether to include the root project
144+
* @param {Array.<string|RegExp>} [parameters.includedDependencies=[]] List of dependencies to include
145+
* @param {Array.<string|RegExp>} [parameters.excludedDependencies=[]] List of dependencies to exclude
146+
* @param {AbortSignal} [parameters.signal] Signal to abort the build
147+
* @param {Function} [projectBuiltCallback] Callback invoked after each project is built
148+
* @returns {Promise<string[]>} Promise resolving with array of processed project names
149+
*/
130150
async build({
131151
includeRootProject = true,
132152
includedDependencies = [], excludedDependencies = [],
@@ -201,6 +221,17 @@ class ProjectBuilder {
201221
await Promise.all(pWrites);
202222
}
203223

224+
/**
225+
* Determine which projects should be built based on filter criteria
226+
*
227+
* @param {boolean} includeRootProject Whether to include the root project
228+
* @param {Array.<string|RegExp>} includedDependencies Dependencies to include
229+
* @param {Array.<string|RegExp>} excludedDependencies Dependencies to exclude
230+
* @param {@ui5/project/build/ProjectBuilder~DependencyIncludes} [dependencyIncludes]
231+
* Alternative dependency configuration
232+
* @returns {string[]} Array of project names to build
233+
* @throws {Error} If creating a build manifest with multiple projects
234+
*/
204235
_determineRequestedProjects(includeRootProject, includedDependencies, excludedDependencies, dependencyIncludes) {
205236
// Get project filter function based on include/exclude params
206237
// (also logs some info to console)
@@ -228,6 +259,15 @@ class ProjectBuilder {
228259
return requestedProjects;
229260
}
230261

262+
/**
263+
* Internal build implementation that orchestrates the actual build process
264+
*
265+
* @param {string[]} requestedProjects Array of project names to build
266+
* @param {Function} [projectBuiltCallback] Callback invoked after each project is built
267+
* @param {AbortSignal} [signal] Signal to abort the build
268+
* @returns {Promise<string[]>} Promise resolving with array of processed project names
269+
* @throws {Error} If a build is already running
270+
*/
231271
async #build(requestedProjects, projectBuiltCallback, signal) {
232272
if (this.#buildIsRunning) {
233273
throw new Error("A build is already running");
@@ -314,6 +354,13 @@ class ProjectBuilder {
314354
return processedProjectNames;
315355
}
316356

357+
/**
358+
* Build a single project
359+
*
360+
* @param {object} projectBuildContext Build context for the project
361+
* @param {AbortSignal} [signal] Signal to abort the build
362+
* @returns {Promise<Array>} Promise resolving with array of changed resources
363+
*/
317364
async _buildProject(projectBuildContext, signal) {
318365
const project = projectBuildContext.getProject();
319366
const projectName = project.getName();
@@ -326,6 +373,17 @@ class ProjectBuilder {
326373
return changedResources;
327374
}
328375

376+
/**
377+
* Create a filter function to determine which projects should be built
378+
*
379+
* @param {object} parameters Parameters
380+
* @param {boolean} [parameters.includeRootProject=true] Whether to include the root project
381+
* @param {@ui5/project/build/ProjectBuilder~DependencyIncludes} [parameters.dependencyIncludes]
382+
* Dependency configuration
383+
* @param {Array.<string|RegExp>} [parameters.explicitIncludes] Explicit dependencies to include
384+
* @param {Array.<string|RegExp>} [parameters.explicitExcludes] Explicit dependencies to exclude
385+
* @returns {Function} Filter function that takes a project name and returns boolean
386+
*/
329387
_createProjectFilter({
330388
includeRootProject = true,
331389
dependencyIncludes,
@@ -375,6 +433,13 @@ class ProjectBuilder {
375433
};
376434
}
377435

436+
/**
437+
* Write build results for a project to the target destination
438+
*
439+
* @param {object} projectBuildContext Build context for the project
440+
* @param {@ui5/fs/adapters/FileSystem} target Target adapter to write to
441+
* @returns {Promise<void>} Promise resolving when write is complete
442+
*/
378443
async _writeResults(projectBuildContext, target) {
379444
const project = projectBuildContext.getProject();
380445
const taskUtil = projectBuildContext.getTaskUtil();
@@ -458,12 +523,23 @@ class ProjectBuilder {
458523
}
459524
}
460525

526+
/**
527+
* Execute cleanup tasks for all build contexts
528+
*
529+
* @param {boolean} [force] Whether to force cleanup execution
530+
* @returns {Promise<void>} Promise resolving when cleanup is complete
531+
*/
461532
async _executeCleanupTasks(force) {
462533
this.#log.info("Executing cleanup tasks...");
463534

464535
await this._buildContext.executeCleanupTasks(force);
465536
}
466537

538+
/**
539+
* Register signal handlers for cleanup on process termination
540+
*
541+
* @returns {object} Map of signal names to their handlers
542+
*/
467543
_registerCleanupSigHooks() {
468544
const that = this;
469545
function createListener(exitCode) {
@@ -505,6 +581,11 @@ class ProjectBuilder {
505581
return processSignals;
506582
}
507583

584+
/**
585+
* Remove previously registered signal handlers
586+
*
587+
* @param {object} signals Map of signal names to their handlers
588+
*/
508589
_deregisterCleanupSigHooks(signals) {
509590
for (const signal of Object.keys(signals)) {
510591
process.removeListener(signal, signals[signal]);
@@ -514,7 +595,6 @@ class ProjectBuilder {
514595
/**
515596
* Calculates the elapsed build time and returns a prettified output
516597
*
517-
* @private
518598
* @param {Array} startTime Array provided by <code>process.hrtime()</code>
519599
* @returns {string} Difference between now and the provided time array as formatted string
520600
*/

0 commit comments

Comments
 (0)