From 48cd30d0b38610e32625d9da951d53696881d3c6 Mon Sep 17 00:00:00 2001 From: Kristian Kraljic <(none)> Date: Wed, 11 Dec 2019 16:06:05 +0100 Subject: [PATCH] Add included/excludedDependencies to builder When setting the buildDependencies parameter to "true" builder used to build all dependencies of the project. By adding two new parameters includedDependencies and excludedDependencies, similar to the existing included/excludedTasks parameters, one can now choose which depenendencies to include into the build. This is also useful for self-contained builds to include the built depenendy into the bundle, instead of the unbuilt source read from the file system (e.g. in case a transpile task is present). --- lib/builder/builder.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/builder/builder.js b/lib/builder/builder.js index 5392cdfd1..8516e3f79 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -207,6 +207,8 @@ module.exports = { * @param {string} parameters.destPath Target path * @param {boolean} [parameters.cleanDest=false] Decides whether project should clean the target path before build * @param {boolean} [parameters.buildDependencies=false] Decides whether project dependencies are built as well + * @param {Array} [parameters.includedDependencies=[]] List of build dependencies to be included + * @param {Array} [parameters.excludedDependencies=[]] List of build dependencies to be excluded. If the wildcard '*' is provided, only the included dependencies will be built. * @param {boolean} [parameters.dev=false] Decides whether a development build should be activated (skips non-essential and time-intensive tasks) * @param {boolean} [parameters.selfContained=false] Flag to activate self contained build * @param {boolean} [parameters.jsdoc=false] Flag to activate JSDoc build @@ -217,7 +219,8 @@ module.exports = { */ async build({ tree, destPath, cleanDest = false, - buildDependencies = false, dev = false, selfContained = false, jsdoc = false, + buildDependencies = false, includedDependencies = [], excludedDependencies = [], + dev = false, selfContained = false, jsdoc = false, includedTasks = [], excludedTasks = [], devExcludeProject = [] }) { const startTime = process.hrtime(); @@ -237,11 +240,25 @@ module.exports = { const projects = {}; // Unique project index to prevent building the same project multiple times const projectWriters = {}; // Collection of memory adapters of already built libraries + function projectFilter(project) { + // if everything is included, this overrules exclude lists + if (includedDependencies.includes("*")) return true; + let test = !excludedDependencies.includes("*"); // exclude everything? + + if (test && excludedDependencies.includes(project.metadata.name)) { + test = false; + } + if (!test && includedDependencies.includes(project.metadata.name)) { + test = true; + } + + return test; + } const projectCountMarker = {}; function projectCount(project, count = 0) { if (buildDependencies) { - count = project.dependencies.reduce((depCount, depProject) => { + count = project.dependencies.filter(projectFilter).reduce((depCount, depProject) => { return projectCount(depProject, depCount); }, count); } @@ -260,7 +277,7 @@ module.exports = { if (buildDependencies) { // Build dependencies in sequence as it is far easier to detect issues and reduces // side effects or other issues such as too many open files - depPromise = project.dependencies.reduce(function(p, depProject) { + depPromise = project.dependencies.filter(projectFilter).reduce(function(p, depProject) { return p.then(() => buildProject(depProject)); }, Promise.resolve()); } else {