|
8 | 8 | #include "uv.h"
|
9 | 9 | #include "v8.h"
|
10 | 10 | #include "zlib.h"
|
| 11 | +#include "fstream" |
| 12 | +#include "sstream" |
| 13 | +#include "filesystem" |
11 | 14 |
|
12 | 15 | #if HAVE_OPENSSL
|
13 | 16 | #include <openssl/opensslv.h>
|
|
27 | 30 | #include <unicode/uvernum.h>
|
28 | 31 | #include <unicode/uversion.h>
|
29 | 32 | #endif // NODE_HAVE_I18N_SUPPORT
|
| 33 | +#include <iostream> |
30 | 34 |
|
31 | 35 | namespace node {
|
32 | 36 |
|
@@ -68,6 +72,7 @@ void Metadata::Versions::InitializeIntlVersions() {
|
68 | 72 | #endif // NODE_HAVE_I18N_SUPPORT
|
69 | 73 |
|
70 | 74 | Metadata::Versions::Versions() {
|
| 75 | + undici = Metadata::Versions::GetDependencyVersionFromPackageJson("undici"); |
71 | 76 | node = NODE_VERSION_STRING;
|
72 | 77 | v8 = v8::V8::GetVersion();
|
73 | 78 | uv = uv_version_string();
|
@@ -105,6 +110,48 @@ Metadata::Versions::Versions() {
|
105 | 110 | #endif
|
106 | 111 | }
|
107 | 112 |
|
| 113 | +bool hasEnding(std::string const& fullString, std::string const& ending) { |
| 114 | + if (fullString.length() >= ending.length()) { |
| 115 | + return (0 == fullString.compare(fullString.length() - ending.length(), |
| 116 | + ending.length(), |
| 117 | + ending)); |
| 118 | + } else { |
| 119 | + return false; |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +std::string Metadata::Versions::GetDependencyVersionFromPackageJson( |
| 124 | + std::string packageName) { |
| 125 | + |
| 126 | + // get current path and find parent which has ending 'node' |
| 127 | + std::filesystem::path cwd = std::filesystem::current_path(); |
| 128 | + while (!hasEnding(cwd.parent_path().string(), "node")) { |
| 129 | + cwd = cwd.parent_path(); |
| 130 | + } |
| 131 | + std::ifstream myFile(cwd.parent_path().string()+"\\deps\\" + packageName + "\\src\\package.json"); |
| 132 | + std::ostringstream tmp; |
| 133 | + tmp << myFile.rdbuf(); |
| 134 | + std::string fileString = tmp.str(); |
| 135 | + |
| 136 | + // 9 is character count of \"version\" and plus 1" |
| 137 | + int ix10 = fileString.find("\"version\"") + 9; |
| 138 | + std::string version = ""; |
| 139 | + bool startAdding = false; |
| 140 | + for (int i = ix10; i < fileString.length(); i++) { |
| 141 | + |
| 142 | + if (fileString[i] == '\"' && !startAdding) { |
| 143 | + startAdding = true; |
| 144 | + }else if (fileString[i] == '\"' && startAdding) { |
| 145 | + break; |
| 146 | + } |
| 147 | + if (fileString[i] != '\"' && startAdding) { |
| 148 | + version = version + fileString[i]; |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + return version; |
| 153 | +} |
| 154 | + |
108 | 155 | Metadata::Release::Release() : name(NODE_RELEASE) {
|
109 | 156 | #if NODE_VERSION_IS_LTS
|
110 | 157 | lts = NODE_VERSION_LTS_CODENAME;
|
|
0 commit comments