75198e06927c55d6416762ae3916c379538beb40d470ecdee1d752a8b552139d3df242bf155add2e45132f9ba9e2c17386a26efbbd29bbde09ea698ed845d8 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.findPackageData = findPackageData;
  6. function _path() {
  7. const data = require("path");
  8. _path = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. var _utils = require("./utils.js");
  14. var _configError = require("../../errors/config-error.js");
  15. const PACKAGE_FILENAME = "package.json";
  16. const readConfigPackage = (0, _utils.makeStaticFileCache)((filepath, content) => {
  17. let options;
  18. try {
  19. options = JSON.parse(content);
  20. } catch (err) {
  21. throw new _configError.default(`Error while parsing JSON - ${err.message}`, filepath);
  22. }
  23. if (!options) throw new Error(`${filepath}: No config detected`);
  24. if (typeof options !== "object") {
  25. throw new _configError.default(`Config returned typeof ${typeof options}`, filepath);
  26. }
  27. if (Array.isArray(options)) {
  28. throw new _configError.default(`Expected config object but found array`, filepath);
  29. }
  30. return {
  31. filepath,
  32. dirname: _path().dirname(filepath),
  33. options
  34. };
  35. });
  36. function* findPackageData(filepath) {
  37. let pkg = null;
  38. const directories = [];
  39. let isPackage = true;
  40. let dirname = _path().dirname(filepath);
  41. while (!pkg && _path().basename(dirname) !== "node_modules") {
  42. directories.push(dirname);
  43. pkg = yield* readConfigPackage(_path().join(dirname, PACKAGE_FILENAME));
  44. const nextLoc = _path().dirname(dirname);
  45. if (dirname === nextLoc) {
  46. isPackage = false;
  47. break;
  48. }
  49. dirname = nextLoc;
  50. }
  51. return {
  52. filepath,
  53. directories,
  54. pkg,
  55. isPackage
  56. };
  57. }
  58. 0 && 0;
  59. //# sourceMappingURL=package.js.map