diff --git a/lib/projectPreprocessor.js b/lib/projectPreprocessor.js index fdcf7112e..835a6839b 100644 --- a/lib/projectPreprocessor.js +++ b/lib/projectPreprocessor.js @@ -336,6 +336,9 @@ class ProjectPreprocessor { case "project-shim": this.handleShim(extension); break; + case "task": + this.handleTask(extension); + break; default: throw new Error(`Unknown extension type '${extension.type}' for ${extension.id}`); } @@ -349,6 +352,9 @@ class ProjectPreprocessor { } handleShim(extension) { + if (!extension.shims) { + throw new Error(`Project shim extension ${extension.id} is missing 'shim' configuration`); + } const {configurations, dependencies, collections} = extension.shims; if (configurations) { @@ -465,6 +471,21 @@ class ProjectPreprocessor { } } } + + handleTask(extension) { + if (!extension.metadata && !extension.metadata.name) { + throw new Error(`Task extension ${extension.id} is missing 'metadata.name' configuration`); + } + if (!extension.task) { + throw new Error(`Task extension ${extension.id} is missing 'task' configuration`); + } + const taskRepository = require("@ui5/builder").tasks.taskRepository; + + const taskPath = path.join(extension.path, extension.task.path); + const task = require(taskPath); // throws if not found + + taskRepository.addTask(extension.metadata.name, task); + } } /** diff --git a/test/lib/extensions.js b/test/lib/extensions.js index 3ce6c4d88..4013c665f 100644 --- a/test/lib/extensions.js +++ b/test/lib/extensions.js @@ -505,3 +505,54 @@ test("Project with unknown extension dependency inline configuration", (t) => { return t.throws(projectPreprocessor.processTree(tree), "Unknown extension type 'phony-pony' for extension.a", "Rejected with error"); }); + +test("Project with task extension dependency", (t) => { + // "project-type" extension handling not yet implemented => test currently checks for error + const tree = { + id: "application.a", + path: applicationAPath, + dependencies: [{ + id: "ext.task.a", + path: applicationAPath, + dependencies: [], + version: "1.0.0", + specVersion: "0.1", + kind: "extension", + type: "task", + metadata: { + name: "task.a" + } + }], + version: "1.0.0", + specVersion: "0.1", + type: "z", + metadata: { + name: "xy" + } + }; + return t.throws(projectPreprocessor.processTree(tree).then((parsedTree) => { + t.deepEqual(parsedTree, { + _level: 0, + type: "z", + metadata: { + name: "xy", + }, + resources: { + configuration: { + paths: { + root: "" + } + }, + pathMappings: { + "/": "", + } + }, + dependencies: [], + id: "application.a", + kind: "project", + version: "1.0.0", + specVersion: "0.1", + path: applicationAPath + }, "Parsed correctly"); + }), "Unknown extension type 'project-type' for extension.a", "Rejected with error"); +});