Skip to content

Commit

Permalink
Add included/excludedDependencies to builder
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Kristian Kraljic committed Dec 11, 2019
1 parent b7d4aad commit 48cd30d
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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);
}
Expand All @@ -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 {
Expand Down

0 comments on commit 48cd30d

Please sign in to comment.