Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

get-dependency.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env node
  2. "use strict";
  3. /* -----------------------------------------------------------------------------
  4. | Copyright (c) Jupyter Development Team.
  5. | Distributed under the terms of the Modified BSD License.
  6. |----------------------------------------------------------------------------*/
  7. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  8. if (k2 === undefined) k2 = k;
  9. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  10. }) : (function(o, m, k, k2) {
  11. if (k2 === undefined) k2 = k;
  12. o[k2] = m[k];
  13. }));
  14. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  15. Object.defineProperty(o, "default", { enumerable: true, value: v });
  16. }) : function(o, v) {
  17. o["default"] = v;
  18. });
  19. var __importStar = (this && this.__importStar) || function (mod) {
  20. if (mod && mod.__esModule) return mod;
  21. var result = {};
  22. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  23. __setModuleDefault(result, mod);
  24. return result;
  25. };
  26. var __importDefault = (this && this.__importDefault) || function (mod) {
  27. return (mod && mod.__esModule) ? mod : { "default": mod };
  28. };
  29. Object.defineProperty(exports, "__esModule", { value: true });
  30. exports.getDependency = void 0;
  31. const path = __importStar(require("path"));
  32. const utils = __importStar(require("./utils"));
  33. const package_json_1 = __importDefault(require("package-json"));
  34. let allDeps = [];
  35. let allDevDeps = [];
  36. /**
  37. * Get the appropriate dependency for a given package name.
  38. *
  39. * @param name - The name of the package.
  40. *
  41. * @returns The dependency version specifier.
  42. */
  43. async function getDependency(name) {
  44. let version = '';
  45. const versions = {};
  46. allDeps = [];
  47. allDevDeps = [];
  48. utils.getLernaPaths().forEach(pkgRoot => {
  49. // Read in the package.json.
  50. const packagePath = path.join(pkgRoot, 'package.json');
  51. let data;
  52. try {
  53. data = utils.readJSONFile(packagePath);
  54. }
  55. catch (e) {
  56. return;
  57. }
  58. if (data.name === name) {
  59. version = '^' + data.version;
  60. return;
  61. }
  62. const deps = data.dependencies || {};
  63. const devDeps = data.devDependencies || {};
  64. if (deps[name]) {
  65. allDeps.push(data.name);
  66. if (deps[name] in versions) {
  67. versions[deps[name]]++;
  68. }
  69. else {
  70. versions[deps[name]] = 1;
  71. }
  72. }
  73. if (devDeps[name]) {
  74. allDevDeps.push(data.name);
  75. if (devDeps[name] in versions) {
  76. versions[devDeps[name]]++;
  77. }
  78. else {
  79. versions[devDeps[name]] = 1;
  80. }
  81. }
  82. });
  83. if (version) {
  84. return version;
  85. }
  86. if (Object.keys(versions).length > 0) {
  87. // Get the most common version.
  88. version = Object.keys(versions).reduce((a, b) => {
  89. return versions[a] > versions[b] ? a : b;
  90. });
  91. }
  92. else {
  93. const releaseData = await package_json_1.default(name);
  94. version = '~' + releaseData.version;
  95. }
  96. return Promise.resolve(version);
  97. }
  98. exports.getDependency = getDependency;
  99. if (require.main === module) {
  100. // Make sure we have required command line arguments.
  101. if (process.argv.length < 3) {
  102. const msg = '** Must supply a target library name\n';
  103. process.stderr.write(msg);
  104. process.exit(1);
  105. }
  106. const name = process.argv[2];
  107. void getDependency(name).then(version => {
  108. console.debug('dependency of: ', allDeps);
  109. console.debug('devDependency of:', allDevDeps);
  110. console.debug(`\n "${name}": "${version}"`);
  111. });
  112. }
  113. //# sourceMappingURL=get-dependency.js.map