From 22a05ead94dfdd0115fb75172a7aedb15c925e73 Mon Sep 17 00:00:00 2001 From: robertrmartinez Date: Tue, 23 Aug 2022 14:19:36 -0700 Subject: [PATCH] resolve libraries from depndencies.json --- src/packageBuilder.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/packageBuilder.js b/src/packageBuilder.js index 18ea7da..15f1a74 100644 --- a/src/packageBuilder.js +++ b/src/packageBuilder.js @@ -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 => { @@ -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)); }