No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gomod.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.parseModule = void 0;
  4. const logger_1 = require("../../../../logger");
  5. function parseModule(mod) {
  6. const module = {
  7. module: "",
  8. version: "",
  9. dependencies: {},
  10. replaces: {},
  11. };
  12. const lines = mod.split("\n");
  13. let inBlock = undefined;
  14. for (const line of lines) {
  15. if (inBlock) {
  16. const endRequireMatch = /\)/.exec(line);
  17. if (endRequireMatch) {
  18. inBlock = undefined;
  19. continue;
  20. }
  21. let regex;
  22. if (inBlock === module.dependencies) {
  23. regex = /([^ ]+) ([^ ]+)/;
  24. }
  25. else {
  26. regex = /([^ ]+) => ([^ ]+)/;
  27. }
  28. const mapping = regex.exec(line);
  29. if (mapping) {
  30. inBlock[mapping[1]] = mapping[2];
  31. continue;
  32. }
  33. if (line.trim()) {
  34. logger_1.logger.debug("Don't know how to handle line", line, "inside a mod.go require block");
  35. }
  36. continue;
  37. }
  38. const modMatch = /^module (.*)$/.exec(line);
  39. if (modMatch) {
  40. module.module = modMatch[1];
  41. continue;
  42. }
  43. const versionMatch = /^go (\d+\.\d+)$/.exec(line);
  44. if (versionMatch) {
  45. module.version = versionMatch[1];
  46. continue;
  47. }
  48. const requireMatch = /^require ([^ ]+) ([^ ]+)/.exec(line);
  49. if (requireMatch) {
  50. module.dependencies[requireMatch[1]] = requireMatch[2];
  51. continue;
  52. }
  53. const replaceMatch = /^replace ([^ ]+) => ([^ ]+)$/.exec(line);
  54. if (replaceMatch) {
  55. module.replaces[replaceMatch[1]] = replaceMatch[2];
  56. continue;
  57. }
  58. const requireBlockMatch = /^require +\(/.exec(line);
  59. if (requireBlockMatch) {
  60. inBlock = module.dependencies;
  61. continue;
  62. }
  63. const replaceBlockMatch = /^replace +\(/.exec(line);
  64. if (replaceBlockMatch) {
  65. inBlock = module.replaces;
  66. continue;
  67. }
  68. if (line.trim()) {
  69. logger_1.logger.debug("Don't know how to handle line", line, "in mod.go");
  70. }
  71. }
  72. return module;
  73. }
  74. exports.parseModule = parseModule;