Skip to content

Commit

Permalink
Merge pull request #4 from prebid/useDependenciesFile
Browse files Browse the repository at this point in the history
Resolve included libraries from dependencies.json
  • Loading branch information
robertrmartinez committed Aug 23, 2022
2 parents 7d75134 + 22a05ea commit 355dc5e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/packageBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ function write(dir, manifestsObj) {
);
}

function getDependenciesFile(depPath) {
try {
return JSON.parse(fs.readFileSync(depPath));
} catch (error) {
console.log(`No Dependencies File found at ${depPath}`);

}
}

function generatePackageManifests(config, prebidManifest, codeManifest, relativeTo = '.') {
return _.reduce(config, (manifests, config) => {
config.packages.forEach(pkg => {
Expand All @@ -55,6 +64,19 @@ function generatePackageManifests(config, prebidManifest, codeManifest, relative
}

if (Array.isArray(pkg.modules)) {
const depFile = manifest.modules['dependencies.json'] || '';
const dependencies = getDependenciesFile(path.join(relativeTo, depFile));
if (dependencies) {
const librariesToAdd = new Set();
pkg.modules.forEach(mod => {
if (Array.isArray(dependencies[`${mod}.js`])) {
dependencies[`${mod}.js`].forEach(lib => librariesToAdd.add(lib));
}
});
if (librariesToAdd.size) {
pkg.modules.push(...librariesToAdd);
}
}
manifest.moduleList = pkg.modules;
manifest.modules = _.filter(manifest.modules, (modulePath, module) => pkg.modules.includes(module));
}
Expand Down

0 comments on commit 355dc5e

Please sign in to comment.