Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Console: Add module filtering #480

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/loggers/ProjectBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ class ProjectBuild extends Logger {
this._log(level, `${this.#projectName}: Finished task ${taskName}`);
}
}

skipTask(taskName) {
if (!this.#tasksToRun || !this.#tasksToRun.includes(taskName)) {
throw new Error(`loggers/ProjectBuild#skipTask: Unknown task ${taskName}`);
}
const level = "info";
const hasListeners = this._emit(ProjectBuild.PROJECT_BUILD_STATUS_EVENT_NAME, {
level,
projectName: this.#projectName,
projectType: this.#projectType,
taskName,
status: "task-skip",
});

if (!hasListeners) {
this._log(level, `${this.#projectName}: Skipping task ${taskName}`);
}
}
}

export default ProjectBuild;
86 changes: 85 additions & 1 deletion lib/writers/Console.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Console {
#progressBarContainer;
#progressBar;
#progressProjectWeight;
#moduleFilter;

constructor() {
this._handleLogEvent = this.#handleLogEvent.bind(this);
Expand All @@ -29,6 +30,66 @@ class Console {
this._handleBuildMetadataEvent = this.#handleBuildMetadataEvent.bind(this);
this._handleProjectBuildMetadataEvent = this.#handleProjectBuildMetadataEvent.bind(this);
this._handleStop = this.disable.bind(this);
this.#initFiters();
}

#initFiters() {
const modulesPatterns = process.env.UI5_LOG_MODULES;
if (!modulesPatterns) {
this.#moduleFilter = null;
return;
}
const enabledModules = [];
const enabledNamespaces = [];
const disabledModules = [];
const disabledNamespaces = [];
// Example of modulePattern: "module1,module2:submodule:subsubmodule,module3:*:-module3:submodule"
modulesPatterns.split(",").forEach((modulePattern) => {
const pattern = modulePattern.trim();
if (pattern.startsWith("-")) {
if (pattern.endsWith(":*")) {
disabledNamespaces.push(pattern.substring(1, pattern.length - 2));
} else {
disabledModules.push(pattern.substring(1));
}
} else {
if (pattern.endsWith(":*")) {
enabledNamespaces.push(pattern.substring(0, pattern.length - 2));
} else {
enabledModules.push(pattern);
}
}
});

this.#moduleFilter = {
enabledModules,
enabledNamespaces,
disabledModules,
disabledNamespaces,
};
}

#filterModule(moduleName) {
if (!this.#moduleFilter) {
return true;
}
if (this.#moduleFilter.disabledModules.includes(moduleName)) {
return false;
}
if (this.#moduleFilter.enabledModules.includes(moduleName)) {
return true;
}
const moduleParts = moduleName.split(":");
for (let i = moduleParts.length - 1; i > 0; i--) {
const namespace = moduleParts.slice(0, i).join(":");
if (this.#moduleFilter.disabledNamespaces.includes(namespace)) {
return false;
}
if (this.#moduleFilter.enabledNamespaces.includes(namespace)) {
return true;
}
}
return false;
}

/**
Expand Down Expand Up @@ -137,7 +198,9 @@ class Console {
}

#handleLogEvent({level, message, moduleName}) {
this.#writeMessage(level, `${chalk.blue(moduleName)} ${message}`);
if (this.#filterModule(moduleName)) {
this.#writeMessage(level, `${chalk.blue(moduleName)} ${message}`);
}
}

#handleBuildMetadataEvent({projectsToBuild}) {
Expand Down Expand Up @@ -328,6 +391,27 @@ class Console {
taskMetadata.executionEnded = true;
message = `${chalk.green(figures.tick)} Finished task ${chalk.bold(taskName)}`;

// Update progress bar (if used)
this._getProgressBar()?.increment(1);
break;
case "task-skip":
if (taskMetadata.executionSkipped) {
throw new Error(`writers/Console: ` +
`Unexpected duplicate task-skip event for project ${projectName}, task ${taskName}`);
}
if (taskMetadata.executionStarted) {
throw new Error(`writers/Console: ` +
`Unexpected task-skip event for project ${projectName}, task ${taskName}. ` +
`Task execution already started`);
}
if (taskMetadata.executionEnded) {
throw new Error(`writers/Console: ` +
`Unexpected task-skip event for project ${projectName}, task ${taskName}. ` +
`Task execution already ended`);
}
taskMetadata.executionEnded = true;
message = `${chalk.green(figures.tick)} Skipping task ${chalk.bold(taskName)}`;

// Update progress bar (if used)
this._getProgressBar()?.increment(1);
break;
Expand Down
Loading