(sourceBatches)
| 1251 | |
| 1252 | // Returns a map from package names to arrays of JS output files. |
| 1253 | static computeJsOutputFilesMap(sourceBatches) { |
| 1254 | const map = new Map; |
| 1255 | |
| 1256 | sourceBatches.forEach(batch => { |
| 1257 | const name = batch.unibuild.pkg.name || null; |
| 1258 | const inputFiles = []; |
| 1259 | |
| 1260 | batch.resourceSlots.forEach(slot => { |
| 1261 | inputFiles.push(...slot.jsOutputResources); |
| 1262 | }); |
| 1263 | |
| 1264 | map.set(name, { |
| 1265 | files: inputFiles, |
| 1266 | mainModule: _.find(inputFiles, file => file.mainModule) || null, |
| 1267 | batch, |
| 1268 | importScannerWatchSet: new WatchSet(), |
| 1269 | }); |
| 1270 | }); |
| 1271 | |
| 1272 | if (! map.has("modules")) { |
| 1273 | // In the unlikely event that no package is using the modules |
| 1274 | // package, then the map is already complete, and we don't need to |
| 1275 | // do any import scanning. |
| 1276 | return this._watchOutputFiles(map); |
| 1277 | } |
| 1278 | |
| 1279 | // Append install(<name>) calls to the install-packages.js file in the |
| 1280 | // modules package for every Meteor package name used. |
| 1281 | map.get("modules").files.some(file => { |
| 1282 | if (file.sourcePath !== "install-packages.js") { |
| 1283 | return false; |
| 1284 | } |
| 1285 | |
| 1286 | const meteorPackageInstalls = []; |
| 1287 | |
| 1288 | map.forEach((info, name) => { |
| 1289 | if (! name) return; |
| 1290 | |
| 1291 | const mainModule = info.mainModule && |
| 1292 | `meteor/${name}/${info.mainModule.targetPath}`; |
| 1293 | |
| 1294 | meteorPackageInstalls.push( |
| 1295 | "install(" + JSON.stringify(name) + |
| 1296 | (mainModule ? ", " + JSON.stringify(mainModule) : '') + |
| 1297 | ");\n" |
| 1298 | ); |
| 1299 | }); |
| 1300 | |
| 1301 | if (meteorPackageInstalls.length === 0) { |
| 1302 | return false; |
| 1303 | } |
| 1304 | |
| 1305 | file.data = Buffer.from( |
| 1306 | file.data.toString("utf8") + "\n" + |
| 1307 | meteorPackageInstalls.join(""), |
| 1308 | "utf8" |
| 1309 | ); |
| 1310 |
no test coverage detected