Skip to content

Commit 9c6fd13

Browse files
committed
feat(builder): Adapt tasks for incremental build
Cherry-picked from: SAP/ui5-builder@ef5a3b2 JIRA: CPOUI5FOUNDATION-1174
1 parent 64b741d commit 9c6fd13

7 files changed

Lines changed: 80 additions & 58 deletions

File tree

packages/builder/lib/processors/nonAsciiEscaper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ async function nonAsciiEscaper({resources, options: {encoding}}) {
8383
// only modify the resource's string if it was changed
8484
if (escaped.modified) {
8585
resource.setString(escaped.string);
86+
return resource;
8687
}
87-
return resource;
8888
}
8989

9090
return Promise.all(resources.map(processResource));

packages/builder/lib/processors/stringReplacer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export default function({resources, options: {pattern, replacement}}) {
2323
const newContent = content.replaceAll(pattern, replacement);
2424
if (content !== newContent) {
2525
resource.setString(newContent);
26+
return resource;
2627
}
27-
return resource;
28+
// return resource;
2829
}));
2930
}

packages/builder/lib/tasks/escapeNonAsciiCharacters.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ import nonAsciiEscaper from "../processors/nonAsciiEscaper.js";
1919
* @param {string} parameters.options.encoding source file encoding either "UTF-8" or "ISO-8859-1"
2020
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
2121
*/
22-
export default async function({workspace, options: {pattern, encoding}}) {
22+
export default async function({workspace, invalidatedResources, options: {pattern, encoding}}) {
2323
if (!encoding) {
2424
throw new Error("[escapeNonAsciiCharacters] Mandatory option 'encoding' not provided");
2525
}
2626

27-
const allResources = await workspace.byGlob(pattern);
27+
let allResources;
28+
if (invalidatedResources) {
29+
allResources = await Promise.all(invalidatedResources.map((resource) => workspace.byPath(resource)));
30+
} else {
31+
allResources = await workspace.byGlob(pattern);
32+
}
2833

2934
const processedResources = await nonAsciiEscaper({
3035
resources: allResources,
@@ -33,5 +38,5 @@ export default async function({workspace, options: {pattern, encoding}}) {
3338
}
3439
});
3540

36-
await Promise.all(processedResources.map((resource) => workspace.write(resource)));
41+
await Promise.all(processedResources.map((resource) => resource && workspace.write(resource)));
3742
}

packages/builder/lib/tasks/minify.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@ import fsInterface from "@ui5/fs/fsInterface";
2626
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
2727
*/
2828
export default async function({
29-
workspace, taskUtil, options: {pattern, omitSourceMapResources = false, useInputSourceMaps = true
30-
}}) {
31-
const resources = await workspace.byGlob(pattern);
29+
workspace, taskUtil, buildCache,
30+
options: {pattern, omitSourceMapResources = false, useInputSourceMaps = true}
31+
}) {
32+
let resources = await workspace.byGlob(pattern);
33+
if (buildCache.hasCache()) {
34+
const changedPaths = buildCache.getChangedProjectResourcePaths();
35+
resources = resources.filter((resource) => changedPaths.has(resource.getPath()));
36+
}
37+
if (resources.length === 0) {
38+
return;
39+
}
3240
const processedResources = await minifier({
3341
resources,
3442
fs: fsInterface(workspace),

packages/builder/lib/tasks/replaceBuildtime.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,24 @@ function getTimestamp() {
3232
* @param {string} parameters.options.pattern Pattern to locate the files to be processed
3333
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
3434
*/
35-
export default function({workspace, options: {pattern}}) {
36-
const timestamp = getTimestamp();
35+
export default async function({workspace, buildCache, options: {pattern}}) {
36+
let resources = await workspace.byGlob(pattern);
3737

38-
return workspace.byGlob(pattern)
39-
.then((processedResources) => {
40-
return stringReplacer({
41-
resources: processedResources,
42-
options: {
43-
pattern: "${buildtime}",
44-
replacement: timestamp
45-
}
46-
});
47-
})
48-
.then((processedResources) => {
49-
return Promise.all(processedResources.map((resource) => {
50-
return workspace.write(resource);
51-
}));
52-
});
38+
if (buildCache.hasCache()) {
39+
const changedPaths = buildCache.getChangedProjectResourcePaths();
40+
resources = resources.filter((resource) => changedPaths.has(resource.getPath()));
41+
}
42+
const timestamp = getTimestamp();
43+
const processedResources = await stringReplacer({
44+
resources,
45+
options: {
46+
pattern: "${buildtime}",
47+
replacement: timestamp
48+
}
49+
});
50+
return Promise.all(processedResources.map((resource) => {
51+
if (resource) {
52+
return workspace.write(resource);
53+
}
54+
}));
5355
}

packages/builder/lib/tasks/replaceCopyright.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,30 @@ import stringReplacer from "../processors/stringReplacer.js";
2929
* @param {string} parameters.options.pattern Pattern to locate the files to be processed
3030
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
3131
*/
32-
export default function({workspace, options: {copyright, pattern}}) {
32+
export default async function({workspace, buildCache, options: {copyright, pattern}}) {
3333
if (!copyright) {
34-
return Promise.resolve();
34+
return;
3535
}
3636

3737
// Replace optional placeholder ${currentYear} with the current year
3838
copyright = copyright.replace(/(?:\$\{currentYear\})/, new Date().getFullYear());
3939

40-
return workspace.byGlob(pattern)
41-
.then((processedResources) => {
42-
return stringReplacer({
43-
resources: processedResources,
44-
options: {
45-
pattern: /(?:\$\{copyright\}|@copyright@)/g,
46-
replacement: copyright
47-
}
48-
});
49-
})
50-
.then((processedResources) => {
51-
return Promise.all(processedResources.map((resource) => {
52-
return workspace.write(resource);
53-
}));
54-
});
40+
let resources = await workspace.byGlob(pattern);
41+
if (buildCache.hasCache()) {
42+
const changedPaths = buildCache.getChangedProjectResourcePaths();
43+
resources = resources.filter((resource) => changedPaths.has(resource.getPath()));
44+
}
45+
46+
const processedResources = await stringReplacer({
47+
resources,
48+
options: {
49+
pattern: /(?:\$\{copyright\}|@copyright@)/g,
50+
replacement: copyright
51+
}
52+
});
53+
return Promise.all(processedResources.map((resource) => {
54+
if (resource) {
55+
return workspace.write(resource);
56+
}
57+
}));
5558
}

packages/builder/lib/tasks/replaceVersion.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,23 @@ import stringReplacer from "../processors/stringReplacer.js";
1919
* @param {string} parameters.options.version Replacement version
2020
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
2121
*/
22-
export default function({workspace, options: {pattern, version}}) {
23-
return workspace.byGlob(pattern)
24-
.then((allResources) => {
25-
return stringReplacer({
26-
resources: allResources,
27-
options: {
28-
pattern: /\$\{(?:project\.)?version\}/g,
29-
replacement: version
30-
}
31-
});
32-
})
33-
.then((processedResources) => {
34-
return Promise.all(processedResources.map((resource) => {
35-
return workspace.write(resource);
36-
}));
37-
});
22+
export default async function({workspace, buildCache, options: {pattern, version}}) {
23+
let resources = await workspace.byGlob(pattern);
24+
25+
if (buildCache.hasCache()) {
26+
const changedPaths = buildCache.getChangedProjectResourcePaths();
27+
resources = resources.filter((resource) => changedPaths.has(resource.getPath()));
28+
}
29+
const processedResources = await stringReplacer({
30+
resources,
31+
options: {
32+
pattern: /\$\{(?:project\.)?version\}/g,
33+
replacement: version
34+
}
35+
});
36+
await Promise.all(processedResources.map((resource) => {
37+
if (resource) {
38+
return workspace.write(resource);
39+
}
40+
}));
3841
}

0 commit comments

Comments
 (0)