Skip to content

Commit

Permalink
[INTERNAL] resourceFactory: Mix-in virtual reader of dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Mar 12, 2019
1 parent 3e9eef1 commit 5dd313b
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lib/resourceFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require("path");
const FsAdapter = require("./adapters/FileSystem");
const MemAdapter = require("./adapters/Memory");
const ReaderCollection = require("./ReaderCollection");
const ReaderCollectionPrioritized = require("./ReaderCollectionPrioritized");
const DuplexCollection = require("./DuplexCollection");
const Resource = require("./Resource");

Expand All @@ -28,14 +29,21 @@ const resourceFactory = {
* @param {boolean} [parameters.useNamespaces=false] Use project namespaces as path prefixes
* @returns {Object} Object containing <code>source</code> and <code>dependencies</code> resource readers
*/
createCollectionsForTree(tree, {useNamespaces=false} = {}) {
createCollectionsForTree(tree, {useNamespaces=false, virtualReaders={}} = {}) {
// TODO: virtualReaders is private API. The virtual reader of a project should be stored on the
// project itself. This requires projects to become objects independent from the dependency tree.
// Also see: https://github.com/SAP/ui5-project/issues/122

const dependencyCollection = [];
const dependencyPathIndex = {};
const virtualReaderIndex = {};
const sourceResourceLocators = [];

function processDependencies(project) {
if (project.resources && project.resources.pathMappings) {
const fsReaders = [];
for (let virBasePath in project.resources.pathMappings) {
// Create an fs reader for every path mapping
if (project.resources.pathMappings.hasOwnProperty(virBasePath)) {
const fsPath = project.resources.pathMappings[virBasePath];
const fsBasePath = path.join(project.path, fsPath);
Expand All @@ -51,9 +59,23 @@ const resourceFactory = {
}
dependencyPathIndex[key] = true;

dependencyCollection.push(resourceFactory.createAdapter({fsBasePath, virBasePath, project}));
const fsReader = resourceFactory.createAdapter({fsBasePath, virBasePath, project});
fsReaders.push(fsReader);
}
}

if (!virtualReaderIndex[project.metadata.name] && virtualReaders[project.metadata.name]) {
// Mix-in virtual reader of dependency if available and not already added
virtualReaderIndex[project.metadata.name] = true;
const virtualReader = virtualReaders[project.metadata.name];
const readerCollection = new ReaderCollectionPrioritized({
name: `fs & vir reader collection for project ${project.metadata.name}`,
readers: [virtualReader, ...fsReaders]
});
dependencyCollection.push(readerCollection);
} else {
dependencyCollection.push(...fsReaders);
}
}

project.dependencies.forEach(function(depProject) {
Expand Down

0 comments on commit 5dd313b

Please sign in to comment.