Skip to content

Commit b9b9dc5

Browse files
committed
[INTERNAL] Adopt ui5-project changes III
1 parent 91677c9 commit b9b9dc5

File tree

3 files changed

+42
-31
lines changed

3 files changed

+42
-31
lines changed

lib/tasks/TaskUtil.js

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const ProjectResource = require("@ui5/fs").ProjectResource;
2-
31
/**
42
* Convenience functions for UI5 Builder tasks.
53
* An instance of this class is passed to every standard UI5 Builder task that requires it.
@@ -37,11 +35,20 @@ class TaskUtil {
3735
constructor({projectBuildContext}) {
3836
this._projectBuildContext = projectBuildContext;
3937

38+
this.GLOBAL_TAGS = Object.freeze({
39+
IsDebugVariant: "ui5:IsDebugVariant",
40+
HasDebugVariant: "ui5:HasDebugVariant"
41+
});
42+
4043
/**
4144
* @member {module:@ui5/builder.tasks.TaskUtil~StandardBuildTags}
4245
* @public
4346
*/
44-
this.STANDARD_TAGS = this._projectBuildContext.STANDARD_TAGS;
47+
this.STANDARD_TAGS = Object.freeze({
48+
OmitFromBuildResult: "ui5:OmitFromBuildResult",
49+
IsBundle: "ui5:IsBundle",
50+
...this.GLOBAL_TAGS
51+
});
4552
}
4653

4754
/**
@@ -53,26 +60,20 @@ class TaskUtil {
5360
* This method is only available to custom task extensions defining
5461
* <b>Specification Version 2.2 and above</b>.
5562
*
56-
* @param {module:@ui5/fs.ProjectResource} resource Resource-instance the tag should be stored for
63+
* @param {module:@ui5/fs.Resource} resource Resource-instance the tag should be stored for
5764
* @param {string} tag Name of the tag.
5865
* Currently only the [STANDARD_TAGS]{@link module:@ui5/builder.tasks.TaskUtil#STANDARD_TAGS} are allowed
5966
* @param {string|boolean|integer} [value=true] Tag value. Must be primitive
6067
* @public
6168
*/
6269
setTag(resource, tag, value) {
6370
if (typeof resource === "string") {
64-
throw new Error("TODO 3.0: Deprecated");
65-
}
66-
if (!(resource instanceof ProjectResource)) {
67-
throw new Error("Resource must be an instance of ProjectResource");
71+
throw new Error("Deprecated parameter: " +
72+
"Since UI5 Tooling 3.0, setTag requires a resource instance. Strings are no longer accepted");
6873
}
69-
const project = resource.getProject();
70-
if (project !== this._projectBuildContext.getProject()) {
71-
throw new Error(
72-
`Unable to set tag for project ${project.getName()} ` +
73-
`while building project ${this._projectBuildContext.getProject().getName()}`);
74-
}
75-
return project.setTag(resource.getPath(), tag, value);
74+
75+
const collection = this._projectBuildContext.getResourceTagCollection(resource, tag);
76+
return collection.setTag(resource.getPath(), tag, value);
7677
}
7778

7879
/**
@@ -82,20 +83,19 @@ class TaskUtil {
8283
* This method is only available to custom task extensions defining
8384
* <b>Specification Version 2.2 and above</b>.
8485
*
85-
* @param {module:@ui5/fs.ProjectResource} resource Resource-instance the tag should be retrieved for
86+
* @param {module:@ui5/fs.Resource} resource Resource-instance the tag should be retrieved for
8687
* @param {string} tag Name of the tag
8788
* @returns {string|boolean|integer|undefined} Tag value for the given resource.
8889
* <code>undefined</code> if no value is available
8990
* @public
9091
*/
9192
getTag(resource, tag) {
9293
if (typeof resource === "string") {
93-
throw new Error("TODO 3.0: Deprecated");
94-
}
95-
if (!(resource instanceof ProjectResource)) {
96-
throw new Error("Resource must be an instance of ProjectResource");
94+
throw new Error("Deprecated parameter: " +
95+
"Since UI5 Tooling 3.0, getTag requires a resource instance. Strings are no longer accepted");
9796
}
98-
return resource.getProject().getTag(resource.getPath(), tag);
97+
const collection = this._projectBuildContext.getResourceTagCollection(resource, tag);
98+
return collection.getTag(resource.getPath(), tag);
9999
}
100100

101101
/**
@@ -106,18 +106,17 @@ class TaskUtil {
106106
* This method is only available to custom task extensions defining
107107
* <b>Specification Version 2.2 and above</b>.
108108
*
109-
* @param {module:@ui5/fs.ProjectResource} resource Resource-instance the tag should be cleared for
109+
* @param {module:@ui5/fs.Resource} resource Resource-instance the tag should be cleared for
110110
* @param {string} tag Tag
111111
* @public
112112
*/
113113
clearTag(resource, tag) {
114114
if (typeof resource === "string") {
115-
throw new Error("TODO 3.0: Deprecated");
115+
throw new Error("Deprecated parameter: " +
116+
"Since UI5 Tooling 3.0, clearTag requires a resource instance. Strings are no longer accepted");
116117
}
117-
if (!(resource instanceof ProjectResource)) {
118-
throw new Error("Resource must be an instance of ProjectResource");
119-
}
120-
return resource.getProject().clearTag(resource.getPath(), tag);
118+
const collection = this._projectBuildContext.getResourceTagCollection(resource, tag);
119+
return collection.clearTag(resource.getPath(), tag);
121120
}
122121

123122
/**
@@ -174,6 +173,18 @@ class TaskUtil {
174173
return this._projectBuildContext.getProject(projectName);
175174
}
176175

176+
createResource(parameters) {
177+
if (!parameters.project) {
178+
parameters.project = this.getProject();
179+
}
180+
const Resource = require("@ui5/fs").Resource;
181+
return new Resource(parameters);
182+
}
183+
184+
getCreateResourceFn() {
185+
return this.createResource.bind(this);
186+
}
187+
177188
/**
178189
* Get an interface to an instance of this class that only provides those functions
179190
* that are supported by the given custom task extension specification version.

lib/tasks/bundlers/utils/createModuleNameMapping.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ const ModuleName = require("../../../lbt/utils/ModuleName");
1717
module.exports = function({resources, taskUtil}) {
1818
const moduleNameMapping = {};
1919
for (let i = resources.length - 1; i >= 0; i--) {
20-
const resourcePath = resources[i].getPath();
21-
if (taskUtil.getTag(resourcePath, taskUtil.STANDARD_TAGS.IsDebugVariant)) {
20+
const resource = resources[i];
21+
if (taskUtil.getTag(resource, taskUtil.STANDARD_TAGS.IsDebugVariant)) {
22+
const resourcePath = resource.getPath();
2223
const nonDbgPath = ModuleName.getNonDebugName(resourcePath);
2324
if (!nonDbgPath) {
2425
throw new Error(`Failed to resolve non-debug name for ${resourcePath}`);

lib/tasks/generateCachebusterInfo.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ function getSigner(type) {
3535
* @alias module:@ui5/builder.tasks.generateCachebusterInfo
3636
* @param {object} parameters Parameters
3737
* @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
38-
* @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
3938
* @param {object} parameters.options Options
4039
* @param {string} parameters.options.namespace Namespace of the application
4140
* @param {string} [parameters.options.signatureType='time'] Type of signature to be used ('time' or 'hash')
4241
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
4342
*/
44-
module.exports = function({workspace, dependencies, options: {namespace, signatureType}}) {
43+
module.exports = function({workspace, options: {namespace, signatureType}}) {
4544
const basePath = `/resources/${namespace}/`;
4645
return workspace.byGlob(`/resources/${namespace}/**/*`)
4746
.then(async (resources) => {

0 commit comments

Comments
 (0)