Skip to content
Closed
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
2 changes: 1 addition & 1 deletion packages/builder/lib/processors/nonAsciiEscaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ async function nonAsciiEscaper({resources, options: {encoding}}) {
// only modify the resource's string if it was changed
if (escaped.modified) {
resource.setString(escaped.string);
return resource;
}
return resource;
}

return Promise.all(resources.map(processResource));
Expand Down
3 changes: 2 additions & 1 deletion packages/builder/lib/processors/stringReplacer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default function({resources, options: {pattern, replacement}}) {
const newContent = content.replaceAll(pattern, replacement);
if (content !== newContent) {
resource.setString(newContent);
return resource;
}
return resource;
// return resource;
}));
}
11 changes: 8 additions & 3 deletions packages/builder/lib/tasks/escapeNonAsciiCharacters.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@
* @module @ui5/builder/tasks/escapeNonAsciiCharacters
*/

/**

Check failure on line 8 in packages/builder/lib/tasks/escapeNonAsciiCharacters.js

View workflow job for this annotation

GitHub Actions / General checks and tests

Missing JSDoc @param "parameters.invalidatedResources" declaration
* Task to escape non ascii characters in properties files resources.
*
* @public
* @function default
* @static
*
* @param {object} parameters Parameters

Check failure on line 15 in packages/builder/lib/tasks/escapeNonAsciiCharacters.js

View workflow job for this annotation

GitHub Actions / General checks and tests

Missing @param "parameters.invalidatedResources"
* @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
* @param {object} parameters.options Options
* @param {string} parameters.options.pattern Glob pattern to locate the files to be processed
* @param {string} parameters.options.encoding source file encoding either "UTF-8" or "ISO-8859-1"
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
*/
export default async function({workspace, options: {pattern, encoding}}) {
export default async function({workspace, invalidatedResources, options: {pattern, encoding}}) {
if (!encoding) {
throw new Error("[escapeNonAsciiCharacters] Mandatory option 'encoding' not provided");
}

const allResources = await workspace.byGlob(pattern);
let allResources;
if (invalidatedResources) {
allResources = await Promise.all(invalidatedResources.map((resource) => workspace.byPath(resource)));
} else {
allResources = await workspace.byGlob(pattern);
}

const processedResources = await nonAsciiEscaper({
resources: allResources,
Expand All @@ -33,5 +38,5 @@
}
});

await Promise.all(processedResources.map((resource) => workspace.write(resource)));
await Promise.all(processedResources.map((resource) => resource && workspace.write(resource)));
}
14 changes: 11 additions & 3 deletions packages/builder/lib/tasks/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
* @module @ui5/builder/tasks/minify
*/

/**

Check failure on line 9 in packages/builder/lib/tasks/minify.js

View workflow job for this annotation

GitHub Actions / General checks and tests

Missing JSDoc @param "parameters.buildCache" declaration
* Task to minify resources.
*
* @public
* @function default
* @static
*
* @param {object} parameters Parameters

Check failure on line 16 in packages/builder/lib/tasks/minify.js

View workflow job for this annotation

GitHub Actions / General checks and tests

Missing @param "parameters.buildCache"
* @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
* @param {@ui5/project/build/helpers/TaskUtil|object} [parameters.taskUtil] TaskUtil
* @param {object} parameters.options Options
Expand All @@ -26,9 +26,17 @@
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
*/
export default async function({
workspace, taskUtil, options: {pattern, omitSourceMapResources = false, useInputSourceMaps = true
}}) {
const resources = await workspace.byGlob(pattern);
workspace, taskUtil, buildCache,
options: {pattern, omitSourceMapResources = false, useInputSourceMaps = true}
}) {
let resources = await workspace.byGlob(pattern);
if (buildCache.hasCache()) {
const changedPaths = buildCache.getChangedProjectResourcePaths();
resources = resources.filter((resource) => changedPaths.has(resource.getPath()));
}
if (resources.length === 0) {
return;
}
const processedResources = await minifier({
resources,
fs: fsInterface(workspace),
Expand Down
36 changes: 19 additions & 17 deletions packages/builder/lib/tasks/replaceBuildtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,37 @@
* @module @ui5/builder/tasks/replaceBuildtime
*/

/**

Check failure on line 22 in packages/builder/lib/tasks/replaceBuildtime.js

View workflow job for this annotation

GitHub Actions / General checks and tests

Missing JSDoc @param "parameters.buildCache" declaration
* Task to replace the buildtime <code>${buildtime}</code>.
*
* @public
* @function default
* @static
*
* @param {object} parameters Parameters

Check failure on line 29 in packages/builder/lib/tasks/replaceBuildtime.js

View workflow job for this annotation

GitHub Actions / General checks and tests

Missing @param "parameters.buildCache"
* @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
* @param {object} parameters.options Options
* @param {string} parameters.options.pattern Pattern to locate the files to be processed
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
*/
export default function({workspace, options: {pattern}}) {
const timestamp = getTimestamp();
export default async function({workspace, buildCache, options: {pattern}}) {
let resources = await workspace.byGlob(pattern);

return workspace.byGlob(pattern)
.then((processedResources) => {
return stringReplacer({
resources: processedResources,
options: {
pattern: "${buildtime}",
replacement: timestamp
}
});
})
.then((processedResources) => {
return Promise.all(processedResources.map((resource) => {
return workspace.write(resource);
}));
});
if (buildCache.hasCache()) {
const changedPaths = buildCache.getChangedProjectResourcePaths();
resources = resources.filter((resource) => changedPaths.has(resource.getPath()));
}
const timestamp = getTimestamp();
const processedResources = await stringReplacer({
resources,
options: {
pattern: "${buildtime}",
replacement: timestamp
}
});
return Promise.all(processedResources.map((resource) => {
if (resource) {
return workspace.write(resource);
}
}));
}
37 changes: 20 additions & 17 deletions packages/builder/lib/tasks/replaceCopyright.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module @ui5/builder/tasks/replaceCopyright
*/

/**

Check failure on line 8 in packages/builder/lib/tasks/replaceCopyright.js

View workflow job for this annotation

GitHub Actions / General checks and tests

Missing JSDoc @param "parameters.buildCache" declaration
* Task to to replace the copyright.
*
* The following placeholders are replaced with corresponding values:
Expand All @@ -22,34 +22,37 @@
* @function default
* @static
*
* @param {object} parameters Parameters

Check failure on line 25 in packages/builder/lib/tasks/replaceCopyright.js

View workflow job for this annotation

GitHub Actions / General checks and tests

Missing @param "parameters.buildCache"
* @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
* @param {object} parameters.options Options
* @param {string} parameters.options.copyright Replacement copyright
* @param {string} parameters.options.pattern Pattern to locate the files to be processed
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
*/
export default function({workspace, options: {copyright, pattern}}) {
export default async function({workspace, buildCache, options: {copyright, pattern}}) {
if (!copyright) {
return Promise.resolve();
return;
}

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

return workspace.byGlob(pattern)
.then((processedResources) => {
return stringReplacer({
resources: processedResources,
options: {
pattern: /(?:\$\{copyright\}|@copyright@)/g,
replacement: copyright
}
});
})
.then((processedResources) => {
return Promise.all(processedResources.map((resource) => {
return workspace.write(resource);
}));
});
let resources = await workspace.byGlob(pattern);
if (buildCache.hasCache()) {
const changedPaths = buildCache.getChangedProjectResourcePaths();
resources = resources.filter((resource) => changedPaths.has(resource.getPath()));
}

const processedResources = await stringReplacer({
resources,
options: {
pattern: /(?:\$\{copyright\}|@copyright@)/g,
replacement: copyright
}
});
return Promise.all(processedResources.map((resource) => {
if (resource) {
return workspace.write(resource);
}
}));
}
35 changes: 19 additions & 16 deletions packages/builder/lib/tasks/replaceVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,37 @@
* @module @ui5/builder/tasks/replaceVersion
*/

/**

Check failure on line 8 in packages/builder/lib/tasks/replaceVersion.js

View workflow job for this annotation

GitHub Actions / General checks and tests

Missing JSDoc @param "parameters.buildCache" declaration
* Task to replace the version <code>${version}</code>.
*
* @public
* @function default
* @static
*
* @param {object} parameters Parameters

Check failure on line 15 in packages/builder/lib/tasks/replaceVersion.js

View workflow job for this annotation

GitHub Actions / General checks and tests

Missing @param "parameters.buildCache"
* @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
* @param {object} parameters.options Options
* @param {string} parameters.options.pattern Pattern to locate the files to be processed
* @param {string} parameters.options.version Replacement version
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
*/
export default function({workspace, options: {pattern, version}}) {
return workspace.byGlob(pattern)
.then((allResources) => {
return stringReplacer({
resources: allResources,
options: {
pattern: /\$\{(?:project\.)?version\}/g,
replacement: version
}
});
})
.then((processedResources) => {
return Promise.all(processedResources.map((resource) => {
return workspace.write(resource);
}));
});
export default async function({workspace, buildCache, options: {pattern, version}}) {
let resources = await workspace.byGlob(pattern);

if (buildCache.hasCache()) {
const changedPaths = buildCache.getChangedProjectResourcePaths();
resources = resources.filter((resource) => changedPaths.has(resource.getPath()));
}
const processedResources = await stringReplacer({
resources,
options: {
pattern: /\$\{(?:project\.)?version\}/g,
replacement: version
}
});
await Promise.all(processedResources.map((resource) => {
if (resource) {
return workspace.write(resource);
}
}));
}
2 changes: 2 additions & 0 deletions packages/cli/lib/cli/commands/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import baseMiddleware from "../middlewares/base.js";
import path from "node:path";

const build = {
command: "build",
Expand Down Expand Up @@ -173,6 +174,7 @@ async function handleBuild(argv) {
const buildSettings = graph.getRoot().getBuilderSettings() || {};
await graph.build({
graph,
cacheDir: path.join(graph.getRoot().getRootPath(), ".ui5-cache"),
destPath: argv.dest,
cleanDest: argv["clean-dest"],
createBuildManifest: argv["create-build-manifest"],
Expand Down
84 changes: 84 additions & 0 deletions packages/fs/lib/DuplexTracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import AbstractReaderWriter from "./AbstractReaderWriter.js";

// TODO: Alternative name: Inspector/Interceptor/...

export default class Trace extends AbstractReaderWriter {
#readerWriter;
#sealed = false;
#pathsRead = [];
#patterns = [];
#resourcesRead = Object.create(null);
#resourcesWritten = Object.create(null);

constructor(readerWriter) {
super(readerWriter.getName());
this.#readerWriter = readerWriter;
}

getResults() {
this.#sealed = true;
return {
requests: {
pathsRead: this.#pathsRead,
patterns: this.#patterns,
},
resourcesRead: this.#resourcesRead,
resourcesWritten: this.#resourcesWritten,
};
}

async _byGlob(virPattern, options, trace) {
if (this.#sealed) {
throw new Error(`Unexpected read operation after reader has been sealed`);
}
if (this.#readerWriter.resolvePattern) {
const resolvedPattern = this.#readerWriter.resolvePattern(virPattern);
this.#patterns.push(resolvedPattern);
} else if (virPattern instanceof Array) {
for (const pattern of virPattern) {
this.#patterns.push(pattern);
}
} else {
this.#patterns.push(virPattern);
}
const resources = await this.#readerWriter._byGlob(virPattern, options, trace);
for (const resource of resources) {
if (!resource.getStatInfo()?.isDirectory()) {
this.#resourcesRead[resource.getOriginalPath()] = resource;
}
}
return resources;
}

async _byPath(virPath, options, trace) {
if (this.#sealed) {
throw new Error(`Unexpected read operation after reader has been sealed`);
}
if (this.#readerWriter.resolvePath) {
const resolvedPath = this.#readerWriter.resolvePath(virPath);
if (resolvedPath) {
this.#pathsRead.push(resolvedPath);
}
} else {
this.#pathsRead.push(virPath);
}
const resource = await this.#readerWriter._byPath(virPath, options, trace);
if (resource) {
if (!resource.getStatInfo()?.isDirectory()) {
this.#resourcesRead[resource.getOriginalPath()] = resource;
}
}
return resource;
}

async _write(resource, options) {
if (this.#sealed) {
throw new Error(`Unexpected write operation after writer has been sealed`);
}
if (!resource) {
throw new Error(`Cannot write undefined resource`);
}
this.#resourcesWritten[resource.getOriginalPath()] = resource;
return this.#readerWriter.write(resource, options);
}
}
2 changes: 1 addition & 1 deletion packages/fs/lib/ReaderCollectionPrioritized.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ReaderCollectionPrioritized extends AbstractReader {
* @returns {Promise<@ui5/fs/Resource|null>}
* Promise resolving to a single resource or <code>null</code> if no resource is found
*/
_byPath(virPath, options, trace) {
async _byPath(virPath, options, trace) {
const that = this;
const byPath = (i) => {
if (i > this._readers.length - 1) {
Expand Down
Loading
Loading