@flakiness/sdk 0.145.0 → 0.146.0

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.
@@ -1,199 +0,0 @@
1
- // src/flakinessConfig.ts
2
- import fs from "fs";
3
- import path2 from "path";
4
-
5
- // src/utils.ts
6
- import { ReportUtils } from "@flakiness/report";
7
- import assert from "assert";
8
- import { spawnSync } from "child_process";
9
- import http from "http";
10
- import https from "https";
11
- import path, { posix as posixPath, win32 as win32Path } from "path";
12
- var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
13
- function errorText(error) {
14
- return FLAKINESS_DBG ? error.stack : error.message;
15
- }
16
- async function retryWithBackoff(job, backoff = []) {
17
- for (const timeout of backoff) {
18
- try {
19
- return await job();
20
- } catch (e) {
21
- if (e instanceof AggregateError)
22
- console.error(`[flakiness.io err]`, errorText(e.errors[0]));
23
- else if (e instanceof Error)
24
- console.error(`[flakiness.io err]`, errorText(e));
25
- else
26
- console.error(`[flakiness.io err]`, e);
27
- await new Promise((x) => setTimeout(x, timeout));
28
- }
29
- }
30
- return await job();
31
- }
32
- var httpUtils;
33
- ((httpUtils2) => {
34
- function createRequest({ url, method = "get", headers = {} }) {
35
- let resolve;
36
- let reject;
37
- const responseDataPromise = new Promise((a, b) => {
38
- resolve = a;
39
- reject = b;
40
- });
41
- const protocol = url.startsWith("https") ? https : http;
42
- headers = Object.fromEntries(Object.entries(headers).filter(([key, value]) => value !== void 0));
43
- const request = protocol.request(url, { method, headers }, (res) => {
44
- const chunks = [];
45
- res.on("data", (chunk) => chunks.push(chunk));
46
- res.on("end", () => {
47
- if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
48
- resolve(Buffer.concat(chunks));
49
- else
50
- reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
51
- });
52
- res.on("error", (error) => reject(error));
53
- });
54
- request.on("error", reject);
55
- return { request, responseDataPromise };
56
- }
57
- httpUtils2.createRequest = createRequest;
58
- async function getBuffer(url, backoff) {
59
- return await retryWithBackoff(async () => {
60
- const { request, responseDataPromise } = createRequest({ url });
61
- request.end();
62
- return await responseDataPromise;
63
- }, backoff);
64
- }
65
- httpUtils2.getBuffer = getBuffer;
66
- async function getText(url, backoff) {
67
- const buffer = await getBuffer(url, backoff);
68
- return buffer.toString("utf-8");
69
- }
70
- httpUtils2.getText = getText;
71
- async function getJSON(url) {
72
- return JSON.parse(await getText(url));
73
- }
74
- httpUtils2.getJSON = getJSON;
75
- async function postText(url, text, backoff) {
76
- const headers = {
77
- "Content-Type": "application/json",
78
- "Content-Length": Buffer.byteLength(text) + ""
79
- };
80
- return await retryWithBackoff(async () => {
81
- const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
82
- request.write(text);
83
- request.end();
84
- return await responseDataPromise;
85
- }, backoff);
86
- }
87
- httpUtils2.postText = postText;
88
- async function postJSON(url, json, backoff) {
89
- const buffer = await postText(url, JSON.stringify(json), backoff);
90
- return JSON.parse(buffer.toString("utf-8"));
91
- }
92
- httpUtils2.postJSON = postJSON;
93
- })(httpUtils || (httpUtils = {}));
94
- var ansiRegex = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
95
- function shell(command, args, options) {
96
- try {
97
- const result = spawnSync(command, args, { encoding: "utf-8", ...options });
98
- if (result.status !== 0) {
99
- return void 0;
100
- }
101
- return result.stdout.trim();
102
- } catch (e) {
103
- console.error(e);
104
- return void 0;
105
- }
106
- }
107
- function computeGitRoot(somePathInsideGitRepo) {
108
- const root = shell(`git`, ["rev-parse", "--show-toplevel"], {
109
- cwd: somePathInsideGitRepo,
110
- encoding: "utf-8"
111
- });
112
- assert(root, `FAILED: git rev-parse --show-toplevel HEAD @ ${somePathInsideGitRepo}`);
113
- return normalizePath(root);
114
- }
115
- var IS_WIN32_PATH = new RegExp("^[a-zA-Z]:\\\\", "i");
116
- var IS_ALMOST_POSIX_PATH = new RegExp("^[a-zA-Z]:/", "i");
117
- function normalizePath(aPath) {
118
- if (IS_WIN32_PATH.test(aPath)) {
119
- aPath = aPath.split(win32Path.sep).join(posixPath.sep);
120
- }
121
- if (IS_ALMOST_POSIX_PATH.test(aPath))
122
- return "/" + aPath[0] + aPath.substring(2);
123
- return aPath;
124
- }
125
-
126
- // src/flakinessConfig.ts
127
- function createConfigPath(dir) {
128
- return path2.join(dir, ".flakiness", "config.json");
129
- }
130
- var gConfigPath;
131
- function ensureConfigPath() {
132
- if (!gConfigPath)
133
- gConfigPath = computeConfigPath();
134
- return gConfigPath;
135
- }
136
- function computeConfigPath() {
137
- for (let p = process.cwd(); p !== path2.resolve(p, ".."); p = path2.resolve(p, "..")) {
138
- const configPath = createConfigPath(p);
139
- if (fs.existsSync(configPath))
140
- return configPath;
141
- }
142
- try {
143
- const gitRoot = computeGitRoot(process.cwd());
144
- return createConfigPath(gitRoot);
145
- } catch (e) {
146
- return createConfigPath(process.cwd());
147
- }
148
- }
149
- var FlakinessConfig = class _FlakinessConfig {
150
- constructor(_configPath, _config) {
151
- this._configPath = _configPath;
152
- this._config = _config;
153
- }
154
- static async load() {
155
- const configPath = ensureConfigPath();
156
- const data = await fs.promises.readFile(configPath, "utf-8").catch((e) => void 0);
157
- const json = data ? JSON.parse(data) : {};
158
- return new _FlakinessConfig(configPath, json);
159
- }
160
- static async projectOrDie(session) {
161
- const config = await _FlakinessConfig.load();
162
- const projectPublicId = config.projectPublicId();
163
- if (!projectPublicId)
164
- throw new Error(`Please link to flakiness project with 'npx flakiness link'`);
165
- const project = await session.api.project.getProject.GET({ projectPublicId }).catch((e) => void 0);
166
- if (!project)
167
- throw new Error(`Failed to fetch linked project; please re-link with 'npx flakiness link'`);
168
- return project;
169
- }
170
- static createEmpty() {
171
- return new _FlakinessConfig(ensureConfigPath(), {});
172
- }
173
- path() {
174
- return this._configPath;
175
- }
176
- projectPublicId() {
177
- return this._config.projectPublicId;
178
- }
179
- setProjectPublicId(projectId) {
180
- this._config.projectPublicId = projectId;
181
- }
182
- async save() {
183
- await fs.promises.mkdir(path2.dirname(this._configPath), { recursive: true });
184
- await fs.promises.writeFile(this._configPath, JSON.stringify(this._config, null, 2));
185
- }
186
- };
187
-
188
- // src/cli/cmd-unlink.ts
189
- async function cmdUnlink() {
190
- const config = await FlakinessConfig.load();
191
- if (!config.projectPublicId())
192
- return;
193
- config.setProjectPublicId(void 0);
194
- await config.save();
195
- }
196
- export {
197
- cmdUnlink
198
- };
199
- //# sourceMappingURL=cmd-unlink.js.map