Skip to content

Commit d6ac24a

Browse files
kristianRandomByte
authored andcommitted
[FEATURE] Add included/excludedDependencies parameter (#380)
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 dependencies to include into or exclude from the build. This is also useful for self-contained builds to include the built dependency into the bundle, instead of the unbuilt source read from the file system (e.g. in case a transpile task is present). Default behavior is unchanged. Parameter "buildDependencies" still needs to be set before dependencies can be excluded or included. * Allow RegExp for included/excludedTasks This comes in handy, e.g. in case all UI5 libraries should be excluded from the build (excludedDependencies=[/^sap\.ui\./]) * Add tests for builder w/ buildDeps & selfContained This change adds tests to builder for building bundles using parameters buildDependencies, included/excludedDependencies, selfContained and a combination thereof. All these have previously been untested.
1 parent 8a2e651 commit d6ac24a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+574
-97
lines changed

lib/builder/builder.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ module.exports = {
207207
* @param {string} parameters.destPath Target path
208208
* @param {boolean} [parameters.cleanDest=false] Decides whether project should clean the target path before build
209209
* @param {boolean} [parameters.buildDependencies=false] Decides whether project dependencies are built as well
210+
* @param {Array.<string|RegExp>} [parameters.includedDependencies=[]] List of build dependencies to be included if buildDependencies is true
211+
* @param {Array.<string|RegExp>} [parameters.excludedDependencies=[]] List of build dependencies to be excluded if buildDependencies is true. If the wildcard '*' is provided, only the included dependencies will be built.
210212
* @param {boolean} [parameters.dev=false] Decides whether a development build should be activated (skips non-essential and time-intensive tasks)
211213
* @param {boolean} [parameters.selfContained=false] Flag to activate self contained build
212214
* @param {boolean} [parameters.jsdoc=false] Flag to activate JSDoc build
@@ -217,7 +219,8 @@ module.exports = {
217219
*/
218220
async build({
219221
tree, destPath, cleanDest = false,
220-
buildDependencies = false, dev = false, selfContained = false, jsdoc = false,
222+
buildDependencies = false, includedDependencies = [], excludedDependencies = [],
223+
dev = false, selfContained = false, jsdoc = false,
221224
includedTasks = [], excludedTasks = [], devExcludeProject = []
222225
}) {
223226
const startTime = process.hrtime();
@@ -237,11 +240,30 @@ module.exports = {
237240

238241
const projects = {}; // Unique project index to prevent building the same project multiple times
239242
const projectWriters = {}; // Collection of memory adapters of already built libraries
243+
function projectFilter(project) {
244+
function projectMatchesAny(deps) {
245+
return deps.some((dep) => dep instanceof RegExp ?
246+
dep.test(project.metadata.name) : dep === project.metadata.name);
247+
}
248+
249+
// if everything is included, this overrules exclude lists
250+
if (includedDependencies.includes("*")) return true;
251+
let test = !excludedDependencies.includes("*"); // exclude everything?
252+
253+
if (test && projectMatchesAny(excludedDependencies)) {
254+
test = false;
255+
}
256+
if (!test && projectMatchesAny(includedDependencies)) {
257+
test = true;
258+
}
259+
260+
return test;
261+
}
240262

241263
const projectCountMarker = {};
242264
function projectCount(project, count = 0) {
243265
if (buildDependencies) {
244-
count = project.dependencies.reduce((depCount, depProject) => {
266+
count = project.dependencies.filter(projectFilter).reduce((depCount, depProject) => {
245267
return projectCount(depProject, depCount);
246268
}, count);
247269
}
@@ -251,21 +273,22 @@ module.exports = {
251273
}
252274
return count;
253275
}
254-
const iProjectCount = projectCount(tree);
255-
const buildLogger = log.createTaskLogger("🛠 ", iProjectCount);
276+
const buildLogger = log.createTaskLogger("🛠 ", projectCount(tree));
256277

257278
function buildProject(project) {
258279
let depPromise;
259280
let projectTasks = selectedTasks;
281+
282+
// Build dependencies in sequence as it is far easier to detect issues and reduces
283+
// side effects or other issues such as too many open files
260284
if (buildDependencies) {
261-
// Build dependencies in sequence as it is far easier to detect issues and reduces
262-
// side effects or other issues such as too many open files
263-
depPromise = project.dependencies.reduce(function(p, depProject) {
285+
depPromise = project.dependencies.filter(projectFilter).reduce(function(p, depProject) {
264286
return p.then(() => buildProject(depProject));
265287
}, Promise.resolve());
266288
} else {
267289
depPromise = Promise.resolve();
268290
}
291+
269292
// Build the project after all dependencies have been built
270293
return depPromise.then(() => {
271294
if (projects[project.metadata.name]) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Application A</title>
5+
<script id="sap-ui-bootstrap" src="test.js">
6+
</script>
7+
</head>
8+
<body>
9+
10+
</body>
11+
</html>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >
3+
4+
<name>library.a</name>
5+
<vendor>SAP SE</vendor>
6+
<copyright>Some fancy copyright ${currentYear}</copyright>
7+
<version>1.0.0</version>
8+
9+
<documentation>Library A</documentation>
10+
11+
<dependencies>
12+
<dependency>
13+
<libraryName>library.d</libraryName>
14+
</dependency>
15+
</dependencies>
16+
17+
</library>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.library-a-foo{color:#fafad2;padding:1px 4px 3px 2px}
2+
/* Inline theming parameters */
3+
#sap-ui-theme-library\.a{background-image:url('data:text/plain;utf-8,%7B%22libraryAColor1%22%3A%22%23fafad2%22%7D')}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"libraryAColor1":"#fafad2"}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.library-a-foo{color:#fafad2;padding:1px 2px 3px 4px}
2+
/* Inline theming parameters */
3+
#sap-ui-theme-library\.a{background-image:url('data:text/plain;utf-8,%7B%22libraryAColor1%22%3A%22%23fafad2%22%7D')}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@libraryAColor1: lightgoldenrodyellow;
2+
3+
.library-a-foo {
4+
color: @libraryAColor1;
5+
padding: 1px 2px 3px 4px;
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >
3+
4+
<name>library.b</name>
5+
<vendor>SAP SE</vendor>
6+
<copyright>Some fancy copyright ${currentYear}</copyright>
7+
<version>1.0.0</version>
8+
9+
<documentation>Library B</documentation>
10+
11+
<dependencies>
12+
<dependency>
13+
<libraryName>library.d</libraryName>
14+
</dependency>
15+
</dependencies>
16+
17+
</library>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >
3+
4+
<name>library.c</name>
5+
<vendor>SAP SE</vendor>
6+
<copyright>${copyright}</copyright>
7+
<version>1.0.0</version>
8+
9+
<documentation>Library C</documentation>
10+
11+
<dependencies>
12+
<dependency>
13+
<libraryName>library.d</libraryName>
14+
</dependency>
15+
</dependencies>
16+
17+
</library>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sap.ui.define([
2+
"library/d/some"
3+
], function(someObject) {
4+
function test(paramA) {
5+
var variableA = paramA;
6+
console.log(variableA);
7+
}
8+
test();
9+
});

0 commit comments

Comments
 (0)