@datadog/datadog-ci-base 3.21.0 → 3.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/README.md +2 -2
  2. package/dist/cli.d.ts +41 -0
  3. package/dist/cli.js +46 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/commands/aas/common.d.ts +51 -0
  6. package/dist/commands/aas/common.js +129 -0
  7. package/dist/commands/aas/common.js.map +1 -0
  8. package/dist/commands/aas/instrument.d.ts +18 -0
  9. package/dist/commands/aas/instrument.js +80 -0
  10. package/dist/commands/aas/instrument.js.map +1 -0
  11. package/dist/commands/aas/uninstrument.d.ts +6 -0
  12. package/dist/commands/aas/uninstrument.js +29 -0
  13. package/dist/commands/aas/uninstrument.js.map +1 -0
  14. package/dist/commands/cloud-run/constants.d.ts +3 -0
  15. package/dist/commands/cloud-run/constants.js +24 -0
  16. package/dist/commands/cloud-run/constants.js.map +1 -0
  17. package/dist/commands/cloud-run/flare.d.ts +18 -0
  18. package/dist/commands/cloud-run/flare.js +42 -0
  19. package/dist/commands/cloud-run/flare.js.map +1 -0
  20. package/dist/commands/cloud-run/instrument.d.ts +30 -0
  21. package/dist/commands/cloud-run/instrument.js +88 -0
  22. package/dist/commands/cloud-run/instrument.js.map +1 -0
  23. package/dist/commands/cloud-run/uninstrument.d.ts +15 -0
  24. package/dist/commands/cloud-run/uninstrument.js +53 -0
  25. package/dist/commands/cloud-run/uninstrument.js.map +1 -0
  26. package/dist/commands/deployment/correlate-command.d.ts +17 -0
  27. package/dist/commands/deployment/correlate-command.js +57 -0
  28. package/dist/commands/deployment/correlate-command.js.map +1 -0
  29. package/dist/commands/deployment/correlate-image-command.d.ts +12 -0
  30. package/dist/commands/deployment/correlate-image-command.js +38 -0
  31. package/dist/commands/deployment/correlate-image-command.js.map +1 -0
  32. package/dist/commands/deployment/gate-command.d.ts +21 -0
  33. package/dist/commands/deployment/gate-command.js +119 -0
  34. package/dist/commands/deployment/gate-command.js.map +1 -0
  35. package/dist/commands/deployment/mark-command.d.ts +18 -0
  36. package/dist/commands/deployment/mark-command.js +63 -0
  37. package/dist/commands/deployment/mark-command.js.map +1 -0
  38. package/dist/commands/dora/deployment-command.d.ts +20 -0
  39. package/dist/commands/dora/deployment-command.js +118 -0
  40. package/dist/commands/dora/deployment-command.js.map +1 -0
  41. package/dist/commands/gate/evaluate-command.d.ts +15 -0
  42. package/dist/commands/gate/evaluate-command.js +98 -0
  43. package/dist/commands/gate/evaluate-command.js.map +1 -0
  44. package/dist/commands/git-metadata/api.d.ts +3 -0
  45. package/dist/commands/git-metadata/api.js +13 -0
  46. package/dist/commands/git-metadata/api.js.map +1 -0
  47. package/dist/commands/git-metadata/git.d.ts +18 -0
  48. package/dist/commands/git-metadata/git.js +188 -0
  49. package/dist/commands/git-metadata/git.js.map +1 -0
  50. package/dist/commands/git-metadata/gitdb.d.ts +7 -0
  51. package/dist/commands/git-metadata/gitdb.js +334 -0
  52. package/dist/commands/git-metadata/gitdb.js.map +1 -0
  53. package/dist/commands/git-metadata/index.d.ts +1 -0
  54. package/dist/commands/git-metadata/index.js +18 -0
  55. package/dist/commands/git-metadata/index.js.map +1 -0
  56. package/dist/commands/git-metadata/interfaces.d.ts +10 -0
  57. package/dist/commands/git-metadata/interfaces.js +56 -0
  58. package/dist/commands/git-metadata/interfaces.js.map +1 -0
  59. package/dist/commands/git-metadata/library.d.ts +7 -0
  60. package/dist/commands/git-metadata/library.js +102 -0
  61. package/dist/commands/git-metadata/library.js.map +1 -0
  62. package/dist/commands/git-metadata/renderer.d.ts +7 -0
  63. package/dist/commands/git-metadata/renderer.js +29 -0
  64. package/dist/commands/git-metadata/renderer.js.map +1 -0
  65. package/dist/commands/git-metadata/upload.d.ts +20 -0
  66. package/dist/commands/git-metadata/upload.js +209 -0
  67. package/dist/commands/git-metadata/upload.js.map +1 -0
  68. package/dist/commands/lambda/flare.d.ts +16 -0
  69. package/dist/commands/lambda/flare.js +41 -0
  70. package/dist/commands/lambda/flare.js.map +1 -0
  71. package/dist/commands/lambda/instrument.d.ts +35 -0
  72. package/dist/commands/lambda/instrument.js +60 -0
  73. package/dist/commands/lambda/instrument.js.map +1 -0
  74. package/dist/commands/lambda/uninstrument.d.ts +33 -0
  75. package/dist/commands/lambda/uninstrument.js +58 -0
  76. package/dist/commands/lambda/uninstrument.js.map +1 -0
  77. package/dist/commands/plugin/check-command.d.ts +7 -0
  78. package/dist/commands/plugin/check-command.js +48 -0
  79. package/dist/commands/plugin/check-command.js.map +1 -0
  80. package/dist/commands/sarif/upload-command.d.ts +17 -0
  81. package/dist/commands/sarif/upload-command.js +62 -0
  82. package/dist/commands/sarif/upload-command.js.map +1 -0
  83. package/dist/commands/sbom/upload-command.d.ts +15 -0
  84. package/dist/commands/sbom/upload-command.js +46 -0
  85. package/dist/commands/sbom/upload-command.js.map +1 -0
  86. package/dist/commands/stepfunctions/instrument.d.ts +15 -0
  87. package/dist/commands/stepfunctions/instrument.js +55 -0
  88. package/dist/commands/stepfunctions/instrument.js.map +1 -0
  89. package/dist/commands/stepfunctions/uninstrument.d.ts +14 -0
  90. package/dist/commands/stepfunctions/uninstrument.js +56 -0
  91. package/dist/commands/stepfunctions/uninstrument.js.map +1 -0
  92. package/dist/commands/synthetics/deploy-tests-command.d.ts +16 -0
  93. package/dist/commands/synthetics/deploy-tests-command.js +79 -0
  94. package/dist/commands/synthetics/deploy-tests-command.js.map +1 -0
  95. package/dist/commands/synthetics/import-tests-command.d.ts +15 -0
  96. package/dist/commands/synthetics/import-tests-command.js +77 -0
  97. package/dist/commands/synthetics/import-tests-command.js.map +1 -0
  98. package/dist/commands/synthetics/run-tests-command.d.ts +28 -0
  99. package/dist/commands/synthetics/run-tests-command.js +158 -0
  100. package/dist/commands/synthetics/run-tests-command.js.map +1 -0
  101. package/dist/commands/synthetics/upload-application-command.d.ts +16 -0
  102. package/dist/commands/synthetics/upload-application-command.js +77 -0
  103. package/dist/commands/synthetics/upload-application-command.js.map +1 -0
  104. package/dist/commands/tag/cli.d.ts +1 -0
  105. package/dist/commands/tag/cli.js +5 -0
  106. package/dist/commands/tag/cli.js.map +1 -0
  107. package/dist/commands/tag/tag-command.d.ts +20 -0
  108. package/dist/commands/tag/tag-command.js +162 -0
  109. package/dist/commands/tag/tag-command.js.map +1 -0
  110. package/dist/constants.d.ts +39 -0
  111. package/dist/constants.js +105 -0
  112. package/dist/constants.js.map +1 -0
  113. package/dist/helpers/api.d.ts +5 -0
  114. package/dist/helpers/api.js +16 -0
  115. package/dist/helpers/api.js.map +1 -0
  116. package/dist/helpers/apikey.d.ts +15 -0
  117. package/dist/helpers/apikey.js +85 -0
  118. package/dist/helpers/apikey.js.map +1 -0
  119. package/dist/helpers/app.d.ts +5 -0
  120. package/dist/helpers/app.js +38 -0
  121. package/dist/helpers/app.js.map +1 -0
  122. package/dist/helpers/base-intake-url.d.ts +1 -0
  123. package/dist/helpers/base-intake-url.js +14 -0
  124. package/dist/helpers/base-intake-url.js.map +1 -0
  125. package/dist/helpers/ci.d.ts +71 -0
  126. package/dist/helpers/ci.js +671 -0
  127. package/dist/helpers/ci.js.map +1 -0
  128. package/dist/helpers/concurrency.d.ts +1 -0
  129. package/dist/helpers/concurrency.js +45 -0
  130. package/dist/helpers/concurrency.js.map +1 -0
  131. package/dist/helpers/config.d.ts +5 -0
  132. package/dist/helpers/config.js +3 -0
  133. package/dist/helpers/config.js.map +1 -0
  134. package/dist/helpers/env.d.ts +6 -0
  135. package/dist/helpers/env.js +50 -0
  136. package/dist/helpers/env.js.map +1 -0
  137. package/dist/helpers/errors.d.ts +2 -0
  138. package/dist/helpers/errors.js +7 -0
  139. package/dist/helpers/errors.js.map +1 -0
  140. package/dist/helpers/file-finder.d.ts +20 -0
  141. package/dist/helpers/file-finder.js +203 -0
  142. package/dist/helpers/file-finder.js.map +1 -0
  143. package/dist/helpers/filereader.d.ts +21 -0
  144. package/dist/helpers/filereader.js +59 -0
  145. package/dist/helpers/filereader.js.map +1 -0
  146. package/dist/helpers/fips.d.ts +1 -0
  147. package/dist/helpers/fips.js +24 -0
  148. package/dist/helpers/fips.js.map +1 -0
  149. package/dist/helpers/flare.d.ts +51 -0
  150. package/dist/helpers/flare.js +238 -0
  151. package/dist/helpers/flare.js.map +1 -0
  152. package/dist/helpers/formatting.d.ts +5 -0
  153. package/dist/helpers/formatting.js +13 -0
  154. package/dist/helpers/formatting.js.map +1 -0
  155. package/dist/helpers/fs.d.ts +31 -0
  156. package/dist/helpers/fs.js +117 -0
  157. package/dist/helpers/fs.js.map +1 -0
  158. package/dist/helpers/get-latest-version.d.ts +1 -0
  159. package/dist/helpers/get-latest-version.js +20 -0
  160. package/dist/helpers/get-latest-version.js.map +1 -0
  161. package/dist/helpers/git/format-git-sourcemaps-data.d.ts +16 -0
  162. package/dist/helpers/git/format-git-sourcemaps-data.js +178 -0
  163. package/dist/helpers/git/format-git-sourcemaps-data.js.map +1 -0
  164. package/dist/helpers/git/format-git-span-data.d.ts +2 -0
  165. package/dist/helpers/git/format-git-span-data.js +54 -0
  166. package/dist/helpers/git/format-git-span-data.js.map +1 -0
  167. package/dist/helpers/git/get-git-data.d.ts +13 -0
  168. package/dist/helpers/git/get-git-data.js +86 -0
  169. package/dist/helpers/git/get-git-data.js.map +1 -0
  170. package/dist/helpers/git/source-code-integration.d.ts +10 -0
  171. package/dist/helpers/git/source-code-integration.js +81 -0
  172. package/dist/helpers/git/source-code-integration.js.map +1 -0
  173. package/dist/helpers/glob.d.ts +12 -0
  174. package/dist/helpers/glob.js +70 -0
  175. package/dist/helpers/glob.js.map +1 -0
  176. package/dist/helpers/id.d.ts +2 -0
  177. package/dist/helpers/id.js +50 -0
  178. package/dist/helpers/id.js.map +1 -0
  179. package/dist/helpers/interfaces.d.ts +59 -0
  180. package/dist/helpers/interfaces.js +3 -0
  181. package/dist/helpers/interfaces.js.map +1 -0
  182. package/dist/helpers/is-standalone-binary.d.ts +1 -0
  183. package/dist/helpers/is-standalone-binary.js +25 -0
  184. package/dist/helpers/is-standalone-binary.js.map +1 -0
  185. package/dist/helpers/logger.d.ts +18 -0
  186. package/dist/helpers/logger.js +52 -0
  187. package/dist/helpers/logger.js.map +1 -0
  188. package/dist/helpers/message-box.d.ts +2 -0
  189. package/dist/helpers/message-box.js +28 -0
  190. package/dist/helpers/message-box.js.map +1 -0
  191. package/dist/helpers/metrics.d.ts +12 -0
  192. package/dist/helpers/metrics.js +36 -0
  193. package/dist/helpers/metrics.js.map +1 -0
  194. package/dist/helpers/plist.d.ts +44 -0
  195. package/dist/helpers/plist.js +93 -0
  196. package/dist/helpers/plist.js.map +1 -0
  197. package/dist/helpers/plugin.d.ts +10 -0
  198. package/dist/helpers/plugin.js +149 -0
  199. package/dist/helpers/plugin.js.map +1 -0
  200. package/dist/helpers/prompt.d.ts +9 -0
  201. package/dist/helpers/prompt.js +58 -0
  202. package/dist/helpers/prompt.js.map +1 -0
  203. package/dist/helpers/renderer.d.ts +60 -0
  204. package/dist/helpers/renderer.js +98 -0
  205. package/dist/helpers/renderer.js.map +1 -0
  206. package/dist/helpers/retry.d.ts +2 -0
  207. package/dist/helpers/retry.js +40 -0
  208. package/dist/helpers/retry.js.map +1 -0
  209. package/dist/helpers/tags.d.ts +82 -0
  210. package/dist/helpers/tags.js +244 -0
  211. package/dist/helpers/tags.js.map +1 -0
  212. package/dist/helpers/types.d.ts +3 -0
  213. package/dist/helpers/types.js +3 -0
  214. package/dist/helpers/types.js.map +1 -0
  215. package/dist/helpers/upload.d.ts +51 -0
  216. package/dist/helpers/upload.js +86 -0
  217. package/dist/helpers/upload.js.map +1 -0
  218. package/dist/helpers/user-provided-git.d.ts +2 -0
  219. package/dist/helpers/user-provided-git.js +49 -0
  220. package/dist/helpers/user-provided-git.js.map +1 -0
  221. package/dist/helpers/utils.d.ts +84 -0
  222. package/dist/helpers/utils.js +340 -0
  223. package/dist/helpers/utils.js.map +1 -0
  224. package/dist/helpers/validation.d.ts +19 -0
  225. package/dist/helpers/validation.js +77 -0
  226. package/dist/helpers/validation.js.map +1 -0
  227. package/dist/version.d.ts +1 -0
  228. package/dist/version.js +6 -0
  229. package/dist/version.js.map +1 -0
  230. package/package.json +19 -10
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+ /**
3
+ * @file Functions used by `lambda flare` and `cloud-run flare`.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __importDefault = (this && this.__importDefault) || function (mod) {
38
+ return (mod && mod.__esModule) ? mod : { "default": mod };
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.getUniqueFileNames = exports.validateCliVersion = exports.validateStartEndFlags = exports.validateFilePath = exports.getProjectFiles = exports.getEndpointUrl = exports.sendToDatadog = void 0;
42
+ const fs_1 = __importDefault(require("fs"));
43
+ const axios_1 = require("axios");
44
+ const form_data_1 = __importDefault(require("form-data"));
45
+ const upath_1 = __importDefault(require("upath"));
46
+ const constants_1 = require("../constants");
47
+ const fs_2 = require("./fs");
48
+ const get_latest_version_1 = require("./get-latest-version");
49
+ const helpersRenderer = __importStar(require("./renderer"));
50
+ const validation_1 = require("./validation");
51
+ /**
52
+ * Send the zip file to Datadog support
53
+ * @param zipPath
54
+ * @param caseId
55
+ * @param email
56
+ * @param apiKey
57
+ * @param rootFolderPath
58
+ * @throws Error if the request fails
59
+ */
60
+ const sendToDatadog = (zipPath, caseId, email, apiKey, rootFolderPath, cliVersion) => __awaiter(void 0, void 0, void 0, function* () {
61
+ var _a, _b, _c, _d;
62
+ const endpointUrl = (0, exports.getEndpointUrl)();
63
+ const form = new form_data_1.default();
64
+ form.append('case_id', caseId);
65
+ form.append('flare_file', fs_1.default.createReadStream(zipPath));
66
+ form.append('datadog_ci_version', cliVersion);
67
+ form.append('email', email);
68
+ const headerConfig = {
69
+ headers: Object.assign(Object.assign({}, form.getHeaders()), { 'DD-API-KEY': apiKey }),
70
+ };
71
+ try {
72
+ yield (0, axios_1.post)(endpointUrl, form, headerConfig);
73
+ }
74
+ catch (err) {
75
+ // Ensure the root folder is deleted if the request fails
76
+ (0, fs_2.deleteFolder)(rootFolderPath);
77
+ if ((0, axios_1.isAxiosError)(err)) {
78
+ const errResponse = (_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data.error) !== null && _b !== void 0 ? _b : '';
79
+ const errorMessage = (_c = err.message) !== null && _c !== void 0 ? _c : '';
80
+ let message = `Failed to send flare file to Datadog Support: ${errorMessage}. ${errResponse}\n`;
81
+ const code = (_d = err.response) === null || _d === void 0 ? void 0 : _d.status;
82
+ // The error message doesn't say why there was an error. All it says is:
83
+ // "[Error] Failed to send flare file to Datadog Support: Request failed with status code 500."
84
+ // Therefore, we need to add an explanation to clarify when the code is 500 or 403.
85
+ switch (code) {
86
+ case 500:
87
+ message += 'Are your case ID and email correct?\n';
88
+ break;
89
+ case 400:
90
+ case 403:
91
+ message += `Is your Datadog API key correct? Please follow this doc to set your API key:
92
+ https://docs.datadoghq.com/serverless/libraries_integrations/cli/#environment-variables\n`;
93
+ break;
94
+ }
95
+ throw Error(message);
96
+ }
97
+ throw err;
98
+ }
99
+ });
100
+ exports.sendToDatadog = sendToDatadog;
101
+ /**
102
+ * Calculates the full endpoint URL
103
+ * @throws Error if the site is invalid
104
+ * @returns the full endpoint URL
105
+ */
106
+ const getEndpointUrl = () => {
107
+ var _a, _b;
108
+ const baseUrl = (_b = (_a = process.env[constants_1.CI_SITE_ENV_VAR]) !== null && _a !== void 0 ? _a : process.env[constants_1.SITE_ENV_VAR]) !== null && _b !== void 0 ? _b : constants_1.DATADOG_SITE_US1;
109
+ // The DNS doesn't redirect to the proper endpoint when a subdomain is not present in the baseUrl.
110
+ // There is a DNS inconsistency
111
+ let endpointUrl = baseUrl;
112
+ if ([constants_1.DATADOG_SITE_US1, constants_1.DATADOG_SITE_EU1, constants_1.DATADOG_SITE_GOV].includes(baseUrl)) {
113
+ endpointUrl = 'app.' + baseUrl;
114
+ }
115
+ if (!(0, validation_1.isValidDatadogSite)(baseUrl)) {
116
+ throw Error(`Invalid site: ${baseUrl}. Must be one of: ${constants_1.DATADOG_SITES.join(', ')}`);
117
+ }
118
+ return 'https://' + endpointUrl + constants_1.FLARE_ENDPOINT_PATH;
119
+ };
120
+ exports.getEndpointUrl = getEndpointUrl;
121
+ /**
122
+ * Searches current directory for project files
123
+ * @returns a set of file paths of project files
124
+ */
125
+ const getProjectFiles = (projectFiles) => __awaiter(void 0, void 0, void 0, function* () {
126
+ const filePaths = new Set();
127
+ const cwd = process.cwd();
128
+ for (const fileName of projectFiles) {
129
+ const filePath = upath_1.default.join(cwd, fileName);
130
+ if (fs_1.default.existsSync(filePath)) {
131
+ filePaths.add(filePath);
132
+ }
133
+ }
134
+ return filePaths;
135
+ });
136
+ exports.getProjectFiles = getProjectFiles;
137
+ /**
138
+ * Validates a path to a file
139
+ * @param filePath path to the file
140
+ * @param projectFilePaths map of file names to file paths
141
+ * @param additionalFiles set of additional file paths
142
+ * @throws Error if the file path is invalid or the file was already added
143
+ * @returns the full path to the file
144
+ */
145
+ const validateFilePath = (filePath, projectFilePaths, additionalFiles) => {
146
+ const originalPath = filePath;
147
+ filePath = fs_1.default.existsSync(filePath) ? filePath : upath_1.default.join(process.cwd(), filePath);
148
+ if (!fs_1.default.existsSync(filePath)) {
149
+ throw Error(helpersRenderer.renderError(`File path '${originalPath}' not found. Please try again.`));
150
+ }
151
+ filePath = upath_1.default.resolve(filePath);
152
+ if (projectFilePaths.has(filePath) || additionalFiles.has(filePath)) {
153
+ throw Error(helpersRenderer.renderSoftWarning(`File '${filePath}' has already been added.`));
154
+ }
155
+ return filePath;
156
+ };
157
+ exports.validateFilePath = validateFilePath;
158
+ /**
159
+ * Validate the start and end flags and adds error messages if found
160
+ * @param start start time as a string
161
+ * @param end end time as a string
162
+ * @throws error if start or end are not valid numbers
163
+ * @returns [startMillis, endMillis] as numbers or [undefined, undefined] if both are undefined
164
+ */
165
+ const validateStartEndFlags = (start, end) => {
166
+ if (!start && !end) {
167
+ return [undefined, undefined];
168
+ }
169
+ if (!start) {
170
+ throw Error('Start time is required when end time is specified. [--start]');
171
+ }
172
+ if (!end) {
173
+ throw Error('End time is required when start time is specified. [--end]');
174
+ }
175
+ let startMillis = Number(start);
176
+ let endMillis = Number(end);
177
+ if (isNaN(startMillis)) {
178
+ throw Error(`Start time must be a time in milliseconds since Unix Epoch. '${start}' is not a number.`);
179
+ }
180
+ if (isNaN(endMillis)) {
181
+ throw Error(`End time must be a time in milliseconds since Unix Epoch. '${end}' is not a number.`);
182
+ }
183
+ // Required for AWS SDK to work correctly
184
+ startMillis = Math.min(startMillis, Date.now());
185
+ endMillis = Math.min(endMillis, Date.now());
186
+ if (startMillis >= endMillis) {
187
+ throw Error('Start time must be before end time.');
188
+ }
189
+ return [startMillis, endMillis];
190
+ };
191
+ exports.validateStartEndFlags = validateStartEndFlags;
192
+ const validateCliVersion = (cliVersion, stdout) => __awaiter(void 0, void 0, void 0, function* () {
193
+ try {
194
+ const latestVersion = yield (0, get_latest_version_1.getLatestVersion)();
195
+ if (latestVersion !== cliVersion) {
196
+ stdout.write(helpersRenderer.renderSoftWarning(`You are using an outdated version of datadog-ci (${cliVersion}). The latest version is ${latestVersion}. Please update for better support.`));
197
+ }
198
+ }
199
+ catch (_e) {
200
+ // Ignore Errors
201
+ }
202
+ });
203
+ exports.validateCliVersion = validateCliVersion;
204
+ /**
205
+ * Generate unique file names
206
+ * If the original file name is unique, keep it as is
207
+ * Otherwise, replace separators in the file path with dashes
208
+ * @param filePaths the list of file paths
209
+ * @returns a mapping of file paths to new file names
210
+ */
211
+ const getUniqueFileNames = (filePaths) => {
212
+ // Count occurrences of each filename
213
+ const fileNameCount = {};
214
+ filePaths.forEach((filePath) => {
215
+ const fileName = upath_1.default.basename(filePath);
216
+ const count = fileNameCount[fileName] || 0;
217
+ fileNameCount[fileName] = count + 1;
218
+ });
219
+ // Create new filenames
220
+ const filePathsToNewFileNames = new Map();
221
+ filePaths.forEach((filePath) => {
222
+ const fileName = upath_1.default.basename(filePath);
223
+ if (fileNameCount[fileName] > 1) {
224
+ // Trim leading and trailing '/'s and '\'s
225
+ const trimRegex = /^\/+|\/+$/g;
226
+ const filePathTrimmed = filePath.replace(trimRegex, '');
227
+ // Replace '/'s and '\'s with '-'s
228
+ const newFileName = filePathTrimmed.split('/').join('-');
229
+ filePathsToNewFileNames.set(filePath, newFileName);
230
+ }
231
+ else {
232
+ filePathsToNewFileNames.set(filePath, fileName);
233
+ }
234
+ });
235
+ return filePathsToNewFileNames;
236
+ };
237
+ exports.getUniqueFileNames = getUniqueFileNames;
238
+ //# sourceMappingURL=flare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flare.js","sourceRoot":"","sources":["../../src/helpers/flare.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4CAAmB;AAGnB,iCAAqD;AACrD,0DAAgC;AAChC,kDAAyB;AAEzB,4CAQqB;AAErB,6BAAiC;AACjC,6DAAqD;AACrD,4DAA6C;AAC7C,6CAA+C;AAE/C;;;;;;;;GAQG;AACI,MAAM,aAAa,GAAG,CAC3B,OAAe,EACf,MAAc,EACd,KAAa,EACb,MAAc,EACd,cAAsB,EACtB,UAAkB,EAClB,EAAE;;IACF,MAAM,WAAW,GAAG,IAAA,sBAAc,GAAE,CAAA;IACpC,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAA;IAC3B,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IAC9B,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,YAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAA;IACvD,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAA;IAC7C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC3B,MAAM,YAAY,GAAG;QACnB,OAAO,kCACF,IAAI,CAAC,UAAU,EAAE,KACpB,YAAY,EAAE,MAAM,GACrB;KACF,CAAA;IAED,IAAI;QACF,MAAM,IAAA,YAAS,EAAC,WAAW,EAAE,IAAI,EAAE,YAAY,CAAC,CAAA;KACjD;IAAC,OAAO,GAAG,EAAE;QACZ,yDAAyD;QACzD,IAAA,iBAAY,EAAC,cAAc,CAAC,CAAA;QAE5B,IAAI,IAAA,oBAAY,EAAC,GAAG,CAAC,EAAE;YACrB,MAAM,WAAW,GAAW,MAAC,MAAA,GAAG,CAAC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D;aAAM;YACL,uBAAuB,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;SAChD;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,uBAAuB,CAAA;AAChC,CAAC,CAAA;AA1BY,QAAA,kBAAkB,sBA0B9B"}
@@ -0,0 +1,5 @@
1
+ export declare const ICONS: {
2
+ FAILED: string;
3
+ SUCCESS: string;
4
+ WARNING: string;
5
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ICONS = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ exports.ICONS = {
9
+ FAILED: chalk_1.default.bold.red('❌'),
10
+ SUCCESS: chalk_1.default.bold.green('✅'),
11
+ WARNING: chalk_1.default.bold.green('⚠️'),
12
+ };
13
+ //# sourceMappingURL=formatting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../src/helpers/formatting.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AAEZ,QAAA,KAAK,GAAG;IACnB,MAAM,EAAE,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC3B,OAAO,EAAE,eAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;IAC9B,OAAO,EAAE,eAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;CAChC,CAAA"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @file Functions that interact with the file system.
3
+ * Functions have built-in error handling for more descriptive error messages.
4
+ */
5
+ /**
6
+ * Delete a folder and all its contents
7
+ * @param folderPath the folder to delete
8
+ * @throws Error if the deletion fails
9
+ */
10
+ export declare const deleteFolder: (folderPath: string) => void;
11
+ /**
12
+ * Write the data to a file
13
+ * @param filePath path to the file
14
+ * @param data the data to write
15
+ * @throws Error if the file cannot be written
16
+ */
17
+ export declare const writeFile: (filePath: string, data: string) => void;
18
+ /**
19
+ * Zip the entire contents of a folder
20
+ * @param rootFolderPath path to the root folder to zip
21
+ * @param zipPath path to save the zip file
22
+ * @throws Error if the zip fails
23
+ */
24
+ export declare const zipContents: (rootFolderPath: string, zipPath: string) => Promise<void>;
25
+ /**
26
+ * Creates the root folder and any subfolders
27
+ * @param rootFolderPath path to the root folder
28
+ * @param subFolders paths to any subfolders to be created
29
+ * @throws Error if the root folder cannot be deleted or folders cannot be created
30
+ */
31
+ export declare const createDirectories: (rootFolderPath: string, subFolders: string[]) => void;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ /**
3
+ * @file Functions that interact with the file system.
4
+ * Functions have built-in error handling for more descriptive error messages.
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.createDirectories = exports.zipContents = exports.writeFile = exports.deleteFolder = void 0;
20
+ const fs_1 = __importDefault(require("fs"));
21
+ const jszip_1 = __importDefault(require("jszip"));
22
+ const upath_1 = __importDefault(require("upath"));
23
+ /**
24
+ * Delete a folder and all its contents
25
+ * @param folderPath the folder to delete
26
+ * @throws Error if the deletion fails
27
+ */
28
+ const deleteFolder = (folderPath) => {
29
+ try {
30
+ fs_1.default.rmSync(folderPath, { recursive: true, force: true });
31
+ }
32
+ catch (err) {
33
+ if (err instanceof Error) {
34
+ throw Error(`Failed to delete files located at ${folderPath}: ${err.message}`);
35
+ }
36
+ }
37
+ };
38
+ exports.deleteFolder = deleteFolder;
39
+ /**
40
+ * Write the data to a file
41
+ * @param filePath path to the file
42
+ * @param data the data to write
43
+ * @throws Error if the file cannot be written
44
+ */
45
+ const writeFile = (filePath, data) => {
46
+ try {
47
+ fs_1.default.writeFileSync(filePath, data);
48
+ }
49
+ catch (err) {
50
+ if (err instanceof Error) {
51
+ throw Error(`Unable to write file: ${err.message}`);
52
+ }
53
+ }
54
+ };
55
+ exports.writeFile = writeFile;
56
+ /**
57
+ * Zip the entire contents of a folder
58
+ * @param rootFolderPath path to the root folder to zip
59
+ * @param zipPath path to save the zip file
60
+ * @throws Error if the zip fails
61
+ */
62
+ const zipContents = (rootFolderPath, zipPath) => __awaiter(void 0, void 0, void 0, function* () {
63
+ const zip = new jszip_1.default();
64
+ const addFolderToZip = (folderPath) => {
65
+ if (!fs_1.default.existsSync(folderPath)) {
66
+ throw Error(`Folder does not exist: ${folderPath}`);
67
+ }
68
+ const folder = fs_1.default.statSync(folderPath);
69
+ if (!folder.isDirectory()) {
70
+ throw Error(`Path is not a directory: ${folderPath}`);
71
+ }
72
+ const contents = fs_1.default.readdirSync(folderPath);
73
+ for (const item of contents) {
74
+ const fullPath = upath_1.default.join(folderPath, item);
75
+ const file = fs_1.default.statSync(fullPath);
76
+ if (file.isDirectory()) {
77
+ addFolderToZip(fullPath);
78
+ }
79
+ else {
80
+ const data = fs_1.default.readFileSync(fullPath);
81
+ zip.file(upath_1.default.relative(rootFolderPath, fullPath), data);
82
+ }
83
+ }
84
+ };
85
+ try {
86
+ addFolderToZip(rootFolderPath);
87
+ const zipContent = yield zip.generateAsync({ type: 'nodebuffer' });
88
+ fs_1.default.writeFileSync(zipPath, zipContent);
89
+ }
90
+ catch (err) {
91
+ if (err instanceof Error) {
92
+ throw Error(`Unable to zip files: ${err.message}`);
93
+ }
94
+ }
95
+ });
96
+ exports.zipContents = zipContents;
97
+ /**
98
+ * Creates the root folder and any subfolders
99
+ * @param rootFolderPath path to the root folder
100
+ * @param subFolders paths to any subfolders to be created
101
+ * @throws Error if the root folder cannot be deleted or folders cannot be created
102
+ */
103
+ const createDirectories = (rootFolderPath, subFolders) => {
104
+ try {
105
+ fs_1.default.mkdirSync(rootFolderPath);
106
+ for (const subFolder of subFolders) {
107
+ fs_1.default.mkdirSync(subFolder);
108
+ }
109
+ }
110
+ catch (err) {
111
+ if (err instanceof Error) {
112
+ throw Error(`Unable to create directories: ${err.message}`);
113
+ }
114
+ }
115
+ };
116
+ exports.createDirectories = createDirectories;
117
+ //# sourceMappingURL=fs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/helpers/fs.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;AAEH,4CAAmB;AAEnB,kDAAyB;AACzB,kDAAyB;AAEzB;;;;GAIG;AACI,MAAM,YAAY,GAAG,CAAC,UAAkB,EAAE,EAAE;IACjD,IAAI;QACF,YAAE,CAAC,MAAM,CAAC,UAAU,EAAE,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC,CAAA;KACtD;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,YAAY,KAAK,EAAE;YACxB,MAAM,KAAK,CAAC,qCAAqC,UAAU,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;SAC/E;KACF;AACH,CAAC,CAAA;AARY,QAAA,YAAY,gBAQxB;AAED;;;;;GAKG;AACI,MAAM,SAAS,GAAG,CAAC,QAAgB,EAAE,IAAY,EAAE,EAAE;IAC1D,IAAI;QACF,YAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;KACjC;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,YAAY,KAAK,EAAE;YACxB,MAAM,KAA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,CAAC,EAAC,IAAI,EAAE,YAAY,EAAC,CAAC,CAAA;QAChE,YAAE,CAAC,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;KACtC;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,YAAY,KAAK,EAAE;YACxB,MAAM,KAAK,CAAC,wBAAwB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;SACnD;KACF;AACH,CAAC,CAAA,CAAA;AApCY,QAAA,WAAW,eAoCvB;AAED;;;;;GAKG;AACI,MAAM,iBAAiB,GAAG,CAAC,cAAsB,EAAE,UAAoB,EAAE,EAAE;IAChF,IAAI;QACF,YAAE,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;QAC5B,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;YAClC,YAAE,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;SACxB;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,YAAY,KAAK,EAAE;YACxB,MAAM,KAAK,CAAC,iCAAiC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;SAC5D;KACF;AACH,CAAC,CAAA;AAXY,QAAA,iBAAiB,qBAW7B"}
@@ -0,0 +1 @@
1
+ export declare const getLatestVersion: () => Promise<string>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getLatestVersion = void 0;
13
+ const REGISTRY_URL = 'https://registry.npmjs.org/@datadog/datadog-ci';
14
+ const getLatestVersion = () => __awaiter(void 0, void 0, void 0, function* () {
15
+ const response = yield fetch(REGISTRY_URL);
16
+ const data = (yield response.json());
17
+ return data['dist-tags'].latest;
18
+ });
19
+ exports.getLatestVersion = getLatestVersion;
20
+ //# sourceMappingURL=get-latest-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-latest-version.js","sourceRoot":"","sources":["../../src/helpers/get-latest-version.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,YAAY,GAAG,gDAAgD,CAAA;AAE9D,MAAM,gBAAgB,GAAG,GAA0B,EAAE;IAC1D,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,CAAA;IAC1C,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAoC,CAAA;IAEvE,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAA;AACjC,CAAC,CAAA,CAAA;AALY,QAAA,gBAAgB,oBAK5B"}
@@ -0,0 +1,16 @@
1
+ import * as simpleGit from 'simple-git';
2
+ export declare const newSimpleGit: () => Promise<simpleGit.SimpleGit>;
3
+ export interface RepositoryData {
4
+ hash: string;
5
+ remote: string;
6
+ trackedFilesMatcher: TrackedFilesMatcher;
7
+ }
8
+ export declare const getRepositoryData: (git: simpleGit.SimpleGit, repositoryURL: string | undefined) => Promise<RepositoryData>;
9
+ export declare class TrackedFilesMatcher {
10
+ private trackedFilenames;
11
+ constructor(trackedFiles: string[]);
12
+ matchSourcemap(srcmapPath: string, onSourcesNotFound: () => void): string[] | undefined;
13
+ matchSources(sources: string[]): string[];
14
+ rawTrackedFilesList(): string[];
15
+ private getFilename;
16
+ }
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.TrackedFilesMatcher = exports.getRepositoryData = exports.newSimpleGit = void 0;
39
+ const fs_1 = __importDefault(require("fs"));
40
+ const simpleGit = __importStar(require("simple-git"));
41
+ const get_git_data_1 = require("./get-git-data");
42
+ // Returns a configured SimpleGit.
43
+ const newSimpleGit = () => __awaiter(void 0, void 0, void 0, function* () {
44
+ const options = {
45
+ baseDir: process.cwd(),
46
+ binary: 'git',
47
+ // We are invoking at most 3 git commands at the same time.
48
+ maxConcurrentProcesses: 3,
49
+ };
50
+ try {
51
+ // Attempt to set the baseDir to the root of the repository so the 'git ls-files' command
52
+ // returns the tracked files paths relative to the root of the repository.
53
+ const git = simpleGit.simpleGit(options);
54
+ const root = yield git.revparse('--show-toplevel');
55
+ options.baseDir = root;
56
+ }
57
+ catch (_a) {
58
+ // Ignore exception as it will fail if we are not inside a git repository.
59
+ }
60
+ return simpleGit.simpleGit(options);
61
+ });
62
+ exports.newSimpleGit = newSimpleGit;
63
+ // Returns the current hash and remote as well as a TrackedFilesMatcher.
64
+ //
65
+ // To obtain the list of tracked files paths tied to a specific sourcemap, invoke the 'matchSourcemap' method.
66
+ const getRepositoryData = (git, repositoryURL) => __awaiter(void 0, void 0, void 0, function* () {
67
+ // Invoke git commands to retrieve the remote, hash and tracked files.
68
+ // We're using Promise.all instead of Promise.allSettled since we want to fail early if
69
+ // any of the promises fails.
70
+ let remote;
71
+ let hash;
72
+ let trackedFiles;
73
+ if (repositoryURL) {
74
+ ;
75
+ [hash, trackedFiles] = yield Promise.all([(0, get_git_data_1.gitHash)(git), (0, get_git_data_1.gitTrackedFiles)(git)]);
76
+ remote = repositoryURL;
77
+ }
78
+ else {
79
+ ;
80
+ [remote, hash, trackedFiles] = yield Promise.all([(0, get_git_data_1.gitRemote)(git), (0, get_git_data_1.gitHash)(git), (0, get_git_data_1.gitTrackedFiles)(git)]);
81
+ }
82
+ const data = {
83
+ hash,
84
+ remote,
85
+ trackedFilesMatcher: new TrackedFilesMatcher(trackedFiles),
86
+ };
87
+ return data;
88
+ });
89
+ exports.getRepositoryData = getRepositoryData;
90
+ // TrackedFilesMatcher can compute the list of tracked files related to a particular sourcemap.
91
+ // The current implementation simply returns all tracked files whose filename is found inside
92
+ // the sourcemap 'sources' field.
93
+ // It is used so that we don't send every tracked files to the backend since most won't be of any use
94
+ // for a particular sourcemap.
95
+ class TrackedFilesMatcher {
96
+ constructor(trackedFiles) {
97
+ this.trackedFilenames = new Map();
98
+ for (const f of trackedFiles) {
99
+ const filename = this.getFilename(f);
100
+ const list = this.trackedFilenames.get(filename);
101
+ if (list) {
102
+ list.push(f);
103
+ }
104
+ else {
105
+ this.trackedFilenames.set(filename, new Array(f));
106
+ }
107
+ }
108
+ }
109
+ // Looks up the sources declared in the sourcemap and return a list of related tracked files.
110
+ matchSourcemap(srcmapPath, onSourcesNotFound) {
111
+ const buff = fs_1.default.readFileSync(srcmapPath, 'utf8');
112
+ const srcmapObj = JSON.parse(buff);
113
+ if (!srcmapObj.sources) {
114
+ return undefined;
115
+ }
116
+ const sources = srcmapObj.sources;
117
+ if (!sources || sources.length === 0) {
118
+ return undefined;
119
+ }
120
+ const filtered = this.matchSources(sources);
121
+ if (filtered.length === 0) {
122
+ onSourcesNotFound();
123
+ return undefined;
124
+ }
125
+ return filtered;
126
+ }
127
+ matchSources(sources) {
128
+ let filtered = [];
129
+ const filenameAlreadyMatched = new Set();
130
+ for (const source of sources) {
131
+ const filename = this.getFilename(source);
132
+ if (filenameAlreadyMatched.has(filename)) {
133
+ continue;
134
+ }
135
+ filenameAlreadyMatched.add(filename);
136
+ const trackedFiles = this.trackedFilenames.get(filename);
137
+ if (trackedFiles) {
138
+ filtered = filtered.concat(trackedFiles);
139
+ }
140
+ }
141
+ return filtered;
142
+ }
143
+ // Return a list of all tracked files
144
+ rawTrackedFilesList() {
145
+ let rawList = [];
146
+ this.trackedFilenames.forEach((value) => {
147
+ rawList = rawList.concat(value);
148
+ });
149
+ return rawList;
150
+ }
151
+ // Extract the filename from a path.
152
+ //
153
+ // We are removing any suffix that is after the character '?'. The only reason this is done
154
+ // is because we noticed that a non-negligible (~5%) amount of source paths from our customers
155
+ // source maps contained query parameters.
156
+ // We are assuming that the files may not actually be named with the interrogation mark but that
157
+ // it is only an artifact of the build process. The query parameters look random. It looks
158
+ // like it may be used as a trick to force a web browser to reload the file content.
159
+ // The only side effect of doing that operation is that more tracked files paths may be sent
160
+ // alongside the sourcemap which is not a problem.
161
+ // Example: webpack:///./src/folder/ui/select.vue?821e
162
+ getFilename(s) {
163
+ let start = s.lastIndexOf('/');
164
+ if (start === -1) {
165
+ start = 0;
166
+ }
167
+ else {
168
+ start++;
169
+ }
170
+ let end = s.lastIndexOf('?');
171
+ if (end === -1 || end <= start) {
172
+ end = s.length;
173
+ }
174
+ return s.substring(start, end);
175
+ }
176
+ }
177
+ exports.TrackedFilesMatcher = TrackedFilesMatcher;
178
+ //# sourceMappingURL=format-git-sourcemaps-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-git-sourcemaps-data.js","sourceRoot":"","sources":["../../../src/helpers/git/format-git-sourcemaps-data.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAmB;AAEnB,sDAAuC;AAEvC,iDAAkE;AAElE,kCAAkC;AAC3B,MAAM,YAAY,GAAG,GAAuC,EAAE;IACnE,MAAM,OAAO,GAAG;QACd,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;QACtB,MAAM,EAAE,KAAK;QACb,2DAA2D;QAC3D,sBAAsB,EAAE,CAAC;KAC1B,CAAA;IACD,IAAI;QACF,yFAAyF;QACzF,0EAA0E;QAC1E,MAAM,GAAG,GAAG,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;QACxC,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAA;QAClD,OAAO,CAAC,OAAO,GAAG,IAAI,CAAA;KACvB;IAAC,WAAM;QACN,0EAA0E;KAC3E;IAED,OAAO,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;AACrC,CAAC,CAAA,CAAA;AAlBY,QAAA,YAAY,gBAkBxB;AAQD,wEAAwE;AACxE,EAAE;AACF,8GAA8G;AACvG,MAAM,iBAAiB,GAAG,CAC/B,GAAwB,EACxB,aAAiC,EACR,EAAE;IAC3B,sEAAsE;IACtE,uFAAuF;IACvF,6BAA6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