has-necessary-dependencies.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.hasNecessaryDependencies = hasNecessaryDependencies;
  6. var _fs = require("fs");
  7. var _fileExists = require("./file-exists");
  8. var _resolveFrom = require("./resolve-from");
  9. var _path = require("path");
  10. async function hasNecessaryDependencies(baseDir, requiredPackages) {
  11. let resolutions = new Map();
  12. const missingPackages = [];
  13. await Promise.all(requiredPackages.map(async (p)=>{
  14. try {
  15. const pkgPath = await _fs.promises.realpath((0, _resolveFrom).resolveFrom(baseDir, `${p.pkg}/package.json`));
  16. const pkgDir = (0, _path).dirname(pkgPath);
  17. if (p.exportsRestrict) {
  18. const fileNameToVerify = (0, _path).relative(p.pkg, p.file);
  19. if (fileNameToVerify) {
  20. const fileToVerify = (0, _path).join(pkgDir, fileNameToVerify);
  21. if (await (0, _fileExists).fileExists(fileToVerify)) {
  22. resolutions.set(p.pkg, fileToVerify);
  23. } else {
  24. return missingPackages.push(p);
  25. }
  26. } else {
  27. resolutions.set(p.pkg, pkgPath);
  28. }
  29. } else {
  30. resolutions.set(p.pkg, (0, _resolveFrom).resolveFrom(baseDir, p.file));
  31. }
  32. } catch (_) {
  33. return missingPackages.push(p);
  34. }
  35. }));
  36. return {
  37. resolved: resolutions,
  38. missing: missingPackages
  39. };
  40. }
  41. //# sourceMappingURL=has-necessary-dependencies.js.map