codeport 0.0.0-stage → 0.3.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.
- package/README.md +63 -2
- package/index.js +2579 -0
- package/package.json +30 -4
package/index.js
ADDED
|
@@ -0,0 +1,2579 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __cpRequire } from "node:module"; const require = __cpRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// apps/mcp/src/index.ts
|
|
5
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
|
|
7
|
+
// apps/mcp/src/api.ts
|
|
8
|
+
var ApiError = class extends Error {
|
|
9
|
+
constructor(status, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.status = status;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var CodeportApi = class {
|
|
15
|
+
constructor(baseUrl, fetchImpl = fetch) {
|
|
16
|
+
this.baseUrl = baseUrl;
|
|
17
|
+
this.fetchImpl = fetchImpl;
|
|
18
|
+
}
|
|
19
|
+
async post(p, body) {
|
|
20
|
+
return this.fetchImpl(new URL(p, this.baseUrl), {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: { "content-type": "application/json", origin: this.baseUrl },
|
|
23
|
+
body: JSON.stringify(body)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async sendCode(email) {
|
|
27
|
+
const res = await this.post("/api/auth/email-otp/send-verification-otp", { email, type: "sign-in" });
|
|
28
|
+
if (!res.ok) throw new ApiError(res.status, await errorText(res, "could not send the code"));
|
|
29
|
+
}
|
|
30
|
+
/** Exchanges the emailed code for a session token. The token must never be shown to the model. */
|
|
31
|
+
async verifyCode(email, otp) {
|
|
32
|
+
const res = await this.post("/api/auth/sign-in/email-otp", { email, otp });
|
|
33
|
+
if (!res.ok) throw new ApiError(res.status, await errorText(res, "the code is wrong or expired"));
|
|
34
|
+
const token = res.headers.get("set-auth-token");
|
|
35
|
+
if (!token) throw new ApiError(500, "server did not return a session token");
|
|
36
|
+
return token;
|
|
37
|
+
}
|
|
38
|
+
async me(token) {
|
|
39
|
+
const res = await this.fetchImpl(new URL("/v1/me", this.baseUrl), {
|
|
40
|
+
headers: { authorization: `Bearer ${token}` }
|
|
41
|
+
});
|
|
42
|
+
if (!res.ok)
|
|
43
|
+
throw new ApiError(
|
|
44
|
+
res.status,
|
|
45
|
+
res.status === 401 ? "not signed in" : await errorText(res, "request failed")
|
|
46
|
+
);
|
|
47
|
+
return await res.json();
|
|
48
|
+
}
|
|
49
|
+
/** Authenticated JSON call to the Core API. Errors carry the status; 401 means the session is gone. */
|
|
50
|
+
async call(token, method, p, body) {
|
|
51
|
+
const res = await this.fetchImpl(new URL(p, this.baseUrl), {
|
|
52
|
+
method,
|
|
53
|
+
headers: {
|
|
54
|
+
authorization: `Bearer ${token}`,
|
|
55
|
+
...body === void 0 ? {} : { "content-type": "application/json" }
|
|
56
|
+
},
|
|
57
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
58
|
+
});
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
let detail = "";
|
|
61
|
+
try {
|
|
62
|
+
const j = await res.json();
|
|
63
|
+
detail = [j.error, ...(j.issues ?? []).map((i) => `${i.path}: ${i.message}`)].filter(Boolean).join("; ");
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
throw new ApiError(res.status, detail || `HTTP ${res.status}`);
|
|
67
|
+
}
|
|
68
|
+
return await res.json();
|
|
69
|
+
}
|
|
70
|
+
async signOut(token) {
|
|
71
|
+
await this.fetchImpl(new URL("/api/auth/sign-out", this.baseUrl), {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: { authorization: `Bearer ${token}`, origin: this.baseUrl, "content-type": "application/json" },
|
|
74
|
+
body: "{}"
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
async function errorText(res, fallback) {
|
|
79
|
+
try {
|
|
80
|
+
const j = await res.json();
|
|
81
|
+
return j.message ?? fallback;
|
|
82
|
+
} catch {
|
|
83
|
+
return fallback;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// apps/mcp/src/auth-flow.ts
|
|
88
|
+
import { z } from "zod";
|
|
89
|
+
var Email = z.string().trim().toLowerCase().email();
|
|
90
|
+
var Code = z.string().trim().regex(/^\d{6}$/, "the code has 6 digits");
|
|
91
|
+
function describeOrg(me) {
|
|
92
|
+
const o = me.organizations[0];
|
|
93
|
+
if (!o) return `Signed in as ${me.user.email}.`;
|
|
94
|
+
const where = o.personal ? "a personal workspace" : `organization ${o.name}`;
|
|
95
|
+
const pending = o.status === "pending" ? " Your membership is waiting for an admin to approve it." : "";
|
|
96
|
+
return `Signed in as ${me.user.email} in ${where} (role: ${o.role}).${pending}`;
|
|
97
|
+
}
|
|
98
|
+
var AuthFlow = class {
|
|
99
|
+
constructor(api2, store2) {
|
|
100
|
+
this.api = api2;
|
|
101
|
+
this.store = store2;
|
|
102
|
+
}
|
|
103
|
+
pendingEmail = null;
|
|
104
|
+
async start(rawEmail) {
|
|
105
|
+
const email = Email.parse(rawEmail);
|
|
106
|
+
await this.api.sendCode(email);
|
|
107
|
+
this.pendingEmail = email;
|
|
108
|
+
return `A 6-digit code was sent to ${email}. Ask the user to paste it here; it expires in 10 minutes.`;
|
|
109
|
+
}
|
|
110
|
+
async verify(rawCode, rawEmail) {
|
|
111
|
+
const code = Code.parse(rawCode);
|
|
112
|
+
const email = rawEmail ? Email.parse(rawEmail) : this.pendingEmail;
|
|
113
|
+
if (!email) return "No sign-in in progress. Call auth_start with the user's email first.";
|
|
114
|
+
try {
|
|
115
|
+
const token = await this.api.verifyCode(email, code);
|
|
116
|
+
await this.store.save({ apiUrl: this.api.baseUrl, email, token });
|
|
117
|
+
this.pendingEmail = null;
|
|
118
|
+
return describeOrg(await this.api.me(token));
|
|
119
|
+
} catch (e) {
|
|
120
|
+
if (e instanceof ApiError && e.status < 500)
|
|
121
|
+
return "That code did not work. Check it, or call auth_start again to get a new one.";
|
|
122
|
+
throw e;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async whoami() {
|
|
126
|
+
const c = await this.store.load();
|
|
127
|
+
if (!c) return "Not signed in. Call auth_start with the user's work email.";
|
|
128
|
+
try {
|
|
129
|
+
return describeOrg(await this.api.me(c.token));
|
|
130
|
+
} catch (e) {
|
|
131
|
+
if (e instanceof ApiError && e.status === 401) {
|
|
132
|
+
await this.store.clear();
|
|
133
|
+
return "The saved session has expired. Call auth_start to sign in again.";
|
|
134
|
+
}
|
|
135
|
+
throw e;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async signOut() {
|
|
139
|
+
const c = await this.store.load();
|
|
140
|
+
if (c) {
|
|
141
|
+
await this.api.signOut(c.token).catch(() => void 0);
|
|
142
|
+
await this.store.clear();
|
|
143
|
+
}
|
|
144
|
+
return "Signed out of Codeport on this machine.";
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// apps/mcp/src/credentials.ts
|
|
149
|
+
import { mkdir, readFile, rm, writeFile, chmod } from "node:fs/promises";
|
|
150
|
+
import { homedir } from "node:os";
|
|
151
|
+
import path from "node:path";
|
|
152
|
+
var SERVICE = "codeport";
|
|
153
|
+
var ACCOUNT = "default";
|
|
154
|
+
var KeyringStore = class _KeyringStore {
|
|
155
|
+
constructor(entry) {
|
|
156
|
+
this.entry = entry;
|
|
157
|
+
}
|
|
158
|
+
kind = "keychain";
|
|
159
|
+
/** Returns null when no usable keychain exists (e.g. a headless Linux box). */
|
|
160
|
+
static async tryCreate() {
|
|
161
|
+
try {
|
|
162
|
+
const { Entry } = await import("@napi-rs/keyring");
|
|
163
|
+
const probe = new Entry(SERVICE, "__probe__");
|
|
164
|
+
probe.setPassword("ok");
|
|
165
|
+
const ok = probe.getPassword() === "ok";
|
|
166
|
+
probe.deletePassword();
|
|
167
|
+
return ok ? new _KeyringStore(new Entry(SERVICE, ACCOUNT)) : null;
|
|
168
|
+
} catch {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async load() {
|
|
173
|
+
const raw = this.entry.getPassword();
|
|
174
|
+
return raw ? JSON.parse(raw) : null;
|
|
175
|
+
}
|
|
176
|
+
async save(c) {
|
|
177
|
+
this.entry.setPassword(JSON.stringify(c));
|
|
178
|
+
}
|
|
179
|
+
async clear() {
|
|
180
|
+
try {
|
|
181
|
+
this.entry.deletePassword();
|
|
182
|
+
} catch {
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var FileStore = class {
|
|
187
|
+
constructor(file = path.join(homedir(), ".codeport", "credentials.json")) {
|
|
188
|
+
this.file = file;
|
|
189
|
+
}
|
|
190
|
+
kind = "file";
|
|
191
|
+
async load() {
|
|
192
|
+
try {
|
|
193
|
+
return JSON.parse(await readFile(this.file, "utf8"));
|
|
194
|
+
} catch {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async save(c) {
|
|
199
|
+
await mkdir(path.dirname(this.file), { recursive: true, mode: 448 });
|
|
200
|
+
await writeFile(this.file, JSON.stringify(c, null, 2), { mode: 384 });
|
|
201
|
+
await chmod(this.file, 384);
|
|
202
|
+
}
|
|
203
|
+
async clear() {
|
|
204
|
+
await rm(this.file, { force: true });
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
async function defaultStore() {
|
|
208
|
+
if (process.env.CODEPORT_CREDENTIALS_FILE) return new FileStore(process.env.CODEPORT_CREDENTIALS_FILE);
|
|
209
|
+
return await KeyringStore.tryCreate() ?? new FileStore();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// apps/mcp/src/server.ts
|
|
213
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
214
|
+
import { z as z2 } from "zod";
|
|
215
|
+
var text = (t) => ({ content: [{ type: "text", text: t }] });
|
|
216
|
+
function createServer(flow2, tools, version) {
|
|
217
|
+
const server2 = new McpServer({ name: "codeport", version });
|
|
218
|
+
server2.registerTool(
|
|
219
|
+
"auth_start",
|
|
220
|
+
{
|
|
221
|
+
title: "Sign in to Codeport",
|
|
222
|
+
description: "Start signing the user in to Codeport (or creating their account) without a browser. Ask the user for their work email first. Codeport emails them a 6-digit code.",
|
|
223
|
+
inputSchema: { email: z2.string().describe("The user's work email address") }
|
|
224
|
+
},
|
|
225
|
+
async ({ email }) => text(await flow2.start(email))
|
|
226
|
+
);
|
|
227
|
+
server2.registerTool(
|
|
228
|
+
"auth_verify",
|
|
229
|
+
{
|
|
230
|
+
title: "Finish Codeport sign-in",
|
|
231
|
+
description: "Finish sign-in with the 6-digit code the user received by email. The session is stored securely on this machine and is never returned to you.",
|
|
232
|
+
inputSchema: {
|
|
233
|
+
code: z2.string().describe("The 6-digit code from the email"),
|
|
234
|
+
email: z2.string().optional().describe("Only needed if auth_start was called in another session")
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
async ({ code, email }) => text(await flow2.verify(code, email))
|
|
238
|
+
);
|
|
239
|
+
server2.registerTool(
|
|
240
|
+
"whoami",
|
|
241
|
+
{
|
|
242
|
+
title: "Current Codeport account",
|
|
243
|
+
description: "Show which Codeport account and organization are signed in."
|
|
244
|
+
},
|
|
245
|
+
async () => text(await flow2.whoami())
|
|
246
|
+
);
|
|
247
|
+
server2.registerTool(
|
|
248
|
+
"sign_out",
|
|
249
|
+
{
|
|
250
|
+
title: "Sign out of Codeport",
|
|
251
|
+
description: "Sign out and remove the stored session from this machine."
|
|
252
|
+
},
|
|
253
|
+
async () => text(await flow2.signOut())
|
|
254
|
+
);
|
|
255
|
+
const load = {
|
|
256
|
+
path: z2.string().optional().describe("Project folder; defaults to the current working directory"),
|
|
257
|
+
scenario: z2.enum(["team", "department", "company"]).optional().describe(
|
|
258
|
+
"Team: 50 users, 1k requests/day, 1 GB. Department: 500, 20k, 10 GB. Company: 5,000, 200k, 50 GB. Default team"
|
|
259
|
+
),
|
|
260
|
+
users: z2.number().int().positive().optional().describe("Own numbers instead of a scenario"),
|
|
261
|
+
requestsPerDay: z2.number().int().positive().optional(),
|
|
262
|
+
dataGb: z2.number().nonnegative().optional().describe("Data kept in the database, GB"),
|
|
263
|
+
geo: z2.enum(["eu", "us"]).optional().describe("Price in Europe (Frankfurt, default) or US East")
|
|
264
|
+
};
|
|
265
|
+
server2.registerTool(
|
|
266
|
+
"analyze_project",
|
|
267
|
+
{
|
|
268
|
+
title: "Analyze this project with Codeport",
|
|
269
|
+
description: "Detect the project's stack (apps, frameworks, databases, services, required secrets) on this machine, save it in the organization's Codeport catalog and give a first cost estimate. Source code and secret values never leave the machine; only the stack profile is sent. Run this first for a new project.",
|
|
270
|
+
inputSchema: {
|
|
271
|
+
path: load.path,
|
|
272
|
+
name: z2.string().optional().describe("App name in the catalog; defaults to the repo or folder name"),
|
|
273
|
+
geo: load.geo
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
async (a) => text(await tools.analyze(a))
|
|
277
|
+
);
|
|
278
|
+
server2.registerTool(
|
|
279
|
+
"estimate_cost",
|
|
280
|
+
{
|
|
281
|
+
title: "Estimate monthly hosting cost",
|
|
282
|
+
description: "Monthly cost range of hosting this project on AWS, Vercel, Azure, Google Cloud, Render, Railway, Fly.io, Netlify and Cloudflare, for a load scenario or the user's own numbers. Give `platform` for an itemized bill with unit prices and their sources.",
|
|
283
|
+
inputSchema: {
|
|
284
|
+
...load,
|
|
285
|
+
platform: z2.string().optional().describe("e.g. aws, vercel, render: itemized bill for one platform")
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
async (a) => text(await tools.estimate(a))
|
|
289
|
+
);
|
|
290
|
+
server2.registerTool(
|
|
291
|
+
"recommend_target",
|
|
292
|
+
{
|
|
293
|
+
title: "Recommend where to host",
|
|
294
|
+
description: "Rank hosting platforms for this project by simplicity, cost and fit, with reasons for and against. The best fit may be a platform Codeport cannot deploy to yet; the answer then also names the best one it can.",
|
|
295
|
+
inputSchema: load
|
|
296
|
+
},
|
|
297
|
+
async (a) => text(await tools.recommend(a))
|
|
298
|
+
);
|
|
299
|
+
return server2;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// apps/mcp/src/project-tools.ts
|
|
303
|
+
import path6 from "node:path";
|
|
304
|
+
import { stat as stat2 } from "node:fs/promises";
|
|
305
|
+
|
|
306
|
+
// packages/detectors/dist/files.js
|
|
307
|
+
import { readdir, readFile as readFile2, stat } from "node:fs/promises";
|
|
308
|
+
import path2 from "node:path";
|
|
309
|
+
var IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
310
|
+
".git",
|
|
311
|
+
"node_modules",
|
|
312
|
+
".next",
|
|
313
|
+
".nuxt",
|
|
314
|
+
".svelte-kit",
|
|
315
|
+
".turbo",
|
|
316
|
+
".vercel",
|
|
317
|
+
".output",
|
|
318
|
+
"dist",
|
|
319
|
+
"build",
|
|
320
|
+
"out",
|
|
321
|
+
"coverage",
|
|
322
|
+
"venv",
|
|
323
|
+
".venv",
|
|
324
|
+
"env",
|
|
325
|
+
"__pycache__",
|
|
326
|
+
".pytest_cache",
|
|
327
|
+
".mypy_cache",
|
|
328
|
+
"target",
|
|
329
|
+
"vendor"
|
|
330
|
+
]);
|
|
331
|
+
var MAX_FILES = 2e4;
|
|
332
|
+
var MAX_READ_BYTES = 512 * 1024;
|
|
333
|
+
async function fromDirectory(root) {
|
|
334
|
+
const all = [];
|
|
335
|
+
async function walk(dir, rel) {
|
|
336
|
+
if (all.length >= MAX_FILES)
|
|
337
|
+
return;
|
|
338
|
+
let entries;
|
|
339
|
+
try {
|
|
340
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
341
|
+
} catch {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const dotnetDir = entries.some((x) => /\.(cs|fs)proj$/.test(x.name));
|
|
345
|
+
for (const e of entries) {
|
|
346
|
+
if (all.length >= MAX_FILES)
|
|
347
|
+
return;
|
|
348
|
+
if (e.isSymbolicLink())
|
|
349
|
+
continue;
|
|
350
|
+
const childRel = rel ? `${rel}/${e.name}` : e.name;
|
|
351
|
+
if (e.isDirectory()) {
|
|
352
|
+
if (IGNORED_DIRS.has(e.name))
|
|
353
|
+
continue;
|
|
354
|
+
if ((e.name === "bin" || e.name === "obj") && dotnetDir)
|
|
355
|
+
continue;
|
|
356
|
+
await walk(path2.join(dir, e.name), childRel);
|
|
357
|
+
} else if (e.isFile()) {
|
|
358
|
+
all.push(childRel);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
await walk(root, "");
|
|
363
|
+
all.sort();
|
|
364
|
+
const cache = /* @__PURE__ */ new Map();
|
|
365
|
+
await Promise.all(all.filter(isInteresting).map(async (rel) => {
|
|
366
|
+
const abs = path2.join(root, rel);
|
|
367
|
+
try {
|
|
368
|
+
const s = await stat(abs);
|
|
369
|
+
if (s.size <= MAX_READ_BYTES)
|
|
370
|
+
cache.set(rel, await readFile2(abs, "utf8"));
|
|
371
|
+
} catch {
|
|
372
|
+
}
|
|
373
|
+
}));
|
|
374
|
+
return { list: () => all, read: (rel) => cache.get(rel) ?? null };
|
|
375
|
+
}
|
|
376
|
+
var INTERESTING_EXT = /\.(json|ya?ml|toml|txt|cfg|ini|js|cjs|mjs|ts|tsx|jsx|mts|cts|py|prisma|vue|svelte|astro|cs|fs|csproj|fsproj|esproj|props)$/i;
|
|
377
|
+
var INTERESTING_NAMES = /(^|\/)(Dockerfile|Procfile|\.nvmrc|\.node-version|\.python-version|\.env\.(example|sample|template|local\.example))$/;
|
|
378
|
+
function isInteresting(rel) {
|
|
379
|
+
return INTERESTING_EXT.test(rel) || INTERESTING_NAMES.test(rel);
|
|
380
|
+
}
|
|
381
|
+
function subdir(files, dir) {
|
|
382
|
+
if (!dir)
|
|
383
|
+
return files;
|
|
384
|
+
const prefix = dir.endsWith("/") ? dir : `${dir}/`;
|
|
385
|
+
const keys = files.list().filter((f) => f.startsWith(prefix)).map((f) => f.slice(prefix.length));
|
|
386
|
+
return { list: () => keys, read: (rel) => files.read(prefix + rel) };
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// packages/detectors/dist/analyze.js
|
|
390
|
+
import path4 from "node:path";
|
|
391
|
+
|
|
392
|
+
// packages/app-profile/dist/schema.js
|
|
393
|
+
import { z as z3 } from "zod";
|
|
394
|
+
var Source = z3.enum(["detector", "llm", "user"]);
|
|
395
|
+
var AppKind = z3.enum(["web", "api", "worker", "static", "fullstack"]);
|
|
396
|
+
var Runtime = z3.object({
|
|
397
|
+
language: z3.string().min(1),
|
|
398
|
+
version: z3.string().optional(),
|
|
399
|
+
framework: z3.string().optional(),
|
|
400
|
+
source: Source
|
|
401
|
+
});
|
|
402
|
+
var ServiceType = z3.enum([
|
|
403
|
+
"database",
|
|
404
|
+
"cache",
|
|
405
|
+
"object_storage",
|
|
406
|
+
"queue",
|
|
407
|
+
"auth",
|
|
408
|
+
"email",
|
|
409
|
+
"cron",
|
|
410
|
+
"external_api",
|
|
411
|
+
"llm_api"
|
|
412
|
+
]);
|
|
413
|
+
var Service = z3.object({
|
|
414
|
+
type: ServiceType,
|
|
415
|
+
/** e.g. postgres, redis, s3, openai */
|
|
416
|
+
engine: z3.string().optional(),
|
|
417
|
+
source: Source,
|
|
418
|
+
/** Files (and optionally lines) that prove the service is used, e.g. "package.json: pg". */
|
|
419
|
+
evidence: z3.array(z3.string()).default([])
|
|
420
|
+
});
|
|
421
|
+
var Build = z3.object({
|
|
422
|
+
packageManager: z3.string().optional(),
|
|
423
|
+
buildCommand: z3.string().optional(),
|
|
424
|
+
startCommand: z3.string().optional(),
|
|
425
|
+
dockerfile: z3.boolean().optional(),
|
|
426
|
+
port: z3.number().int().min(1).max(65535).optional()
|
|
427
|
+
});
|
|
428
|
+
var EnvVar = z3.object({
|
|
429
|
+
name: z3.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/),
|
|
430
|
+
secret: z3.boolean()
|
|
431
|
+
});
|
|
432
|
+
var Load = z3.object({
|
|
433
|
+
expectedUsers: z3.number().int().nonnegative().optional(),
|
|
434
|
+
requestsPerDay: z3.number().int().nonnegative().optional(),
|
|
435
|
+
source: Source
|
|
436
|
+
});
|
|
437
|
+
var SCHEMA_VERSION = "1.0";
|
|
438
|
+
var AppProfile = z3.object({
|
|
439
|
+
schemaVersion: z3.literal(SCHEMA_VERSION),
|
|
440
|
+
app: z3.object({ name: z3.string().min(1), kind: AppKind }),
|
|
441
|
+
runtimes: z3.array(Runtime).default([]),
|
|
442
|
+
services: z3.array(Service).default([]),
|
|
443
|
+
build: Build.default({}),
|
|
444
|
+
env: z3.array(EnvVar).default([]),
|
|
445
|
+
load: Load.default({ source: "detector" })
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
// packages/detectors/dist/common.js
|
|
449
|
+
var ServiceSet = class {
|
|
450
|
+
map = /* @__PURE__ */ new Map();
|
|
451
|
+
add(hit, evidence) {
|
|
452
|
+
const key = `${hit.type}:${hit.engine}`;
|
|
453
|
+
const s = this.map.get(key);
|
|
454
|
+
if (s) {
|
|
455
|
+
if (!s.evidence.includes(evidence))
|
|
456
|
+
s.evidence.push(evidence);
|
|
457
|
+
} else {
|
|
458
|
+
this.map.set(key, { type: hit.type, engine: hit.engine, source: "detector", evidence: [evidence] });
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
values() {
|
|
462
|
+
return [...this.map.values()].sort((a, b) => `${a.type}:${a.engine}`.localeCompare(`${b.type}:${b.engine}`));
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
function dockerPort(files) {
|
|
466
|
+
const df = files.read("Dockerfile");
|
|
467
|
+
const m = df?.match(/^\s*EXPOSE\s+(\d+)/im);
|
|
468
|
+
return m ? Number(m[1]) : void 0;
|
|
469
|
+
}
|
|
470
|
+
function procfileWeb(files) {
|
|
471
|
+
const pf = files.read("Procfile");
|
|
472
|
+
const m = pf?.match(/^web:\s*(.+)$/m);
|
|
473
|
+
return m?.[1]?.trim();
|
|
474
|
+
}
|
|
475
|
+
function firstExisting(files, candidates) {
|
|
476
|
+
const set = new Set(files.list());
|
|
477
|
+
return candidates.find((c) => set.has(c));
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// packages/detectors/dist/catalog.js
|
|
481
|
+
var NPM_SERVICES = {
|
|
482
|
+
pg: [{ type: "database", engine: "postgres" }],
|
|
483
|
+
postgres: [{ type: "database", engine: "postgres" }],
|
|
484
|
+
"@neondatabase/serverless": [{ type: "database", engine: "postgres" }],
|
|
485
|
+
"@vercel/postgres": [{ type: "database", engine: "postgres" }],
|
|
486
|
+
mysql2: [{ type: "database", engine: "mysql" }],
|
|
487
|
+
mysql: [{ type: "database", engine: "mysql" }],
|
|
488
|
+
"@planetscale/database": [{ type: "database", engine: "mysql" }],
|
|
489
|
+
"better-sqlite3": [{ type: "database", engine: "sqlite" }],
|
|
490
|
+
sqlite3: [{ type: "database", engine: "sqlite" }],
|
|
491
|
+
"@libsql/client": [{ type: "database", engine: "sqlite" }],
|
|
492
|
+
mongodb: [{ type: "database", engine: "mongodb" }],
|
|
493
|
+
mongoose: [{ type: "database", engine: "mongodb" }],
|
|
494
|
+
redis: [{ type: "cache", engine: "redis" }],
|
|
495
|
+
ioredis: [{ type: "cache", engine: "redis" }],
|
|
496
|
+
"@upstash/redis": [{ type: "cache", engine: "redis" }],
|
|
497
|
+
"@supabase/supabase-js": [{ type: "database", engine: "supabase" }],
|
|
498
|
+
"@supabase/ssr": [{ type: "database", engine: "supabase" }],
|
|
499
|
+
firebase: [{ type: "database", engine: "firebase" }],
|
|
500
|
+
"firebase-admin": [{ type: "database", engine: "firebase" }],
|
|
501
|
+
convex: [{ type: "database", engine: "convex" }],
|
|
502
|
+
"@clerk/nextjs": [{ type: "auth", engine: "clerk" }],
|
|
503
|
+
"@clerk/clerk-react": [{ type: "auth", engine: "clerk" }],
|
|
504
|
+
"@clerk/express": [{ type: "auth", engine: "clerk" }],
|
|
505
|
+
"next-auth": [{ type: "auth", engine: "authjs" }],
|
|
506
|
+
"@auth/core": [{ type: "auth", engine: "authjs" }],
|
|
507
|
+
"better-auth": [{ type: "auth", engine: "better-auth" }],
|
|
508
|
+
"@aws-sdk/client-s3": [{ type: "object_storage", engine: "s3" }],
|
|
509
|
+
"@vercel/blob": [{ type: "object_storage", engine: "vercel-blob" }],
|
|
510
|
+
uploadthing: [{ type: "object_storage", engine: "uploadthing" }],
|
|
511
|
+
openai: [{ type: "llm_api", engine: "openai" }],
|
|
512
|
+
"@ai-sdk/openai": [{ type: "llm_api", engine: "openai" }],
|
|
513
|
+
"@langchain/openai": [{ type: "llm_api", engine: "openai" }],
|
|
514
|
+
"@anthropic-ai/sdk": [{ type: "llm_api", engine: "anthropic" }],
|
|
515
|
+
"@ai-sdk/anthropic": [{ type: "llm_api", engine: "anthropic" }],
|
|
516
|
+
"@langchain/anthropic": [{ type: "llm_api", engine: "anthropic" }],
|
|
517
|
+
"@google/generative-ai": [{ type: "llm_api", engine: "gemini" }],
|
|
518
|
+
"@google/genai": [{ type: "llm_api", engine: "gemini" }],
|
|
519
|
+
"@ai-sdk/google": [{ type: "llm_api", engine: "gemini" }],
|
|
520
|
+
"@mistralai/mistralai": [{ type: "llm_api", engine: "mistral" }],
|
|
521
|
+
"@ai-sdk/mistral": [{ type: "llm_api", engine: "mistral" }],
|
|
522
|
+
"@ai-sdk/gateway": [{ type: "llm_api", engine: "vercel-ai-gateway" }],
|
|
523
|
+
stripe: [{ type: "external_api", engine: "stripe" }],
|
|
524
|
+
twilio: [{ type: "external_api", engine: "twilio" }],
|
|
525
|
+
resend: [{ type: "email", engine: "resend" }],
|
|
526
|
+
"@sendgrid/mail": [{ type: "email", engine: "sendgrid" }],
|
|
527
|
+
nodemailer: [{ type: "email", engine: "smtp" }],
|
|
528
|
+
postmark: [{ type: "email", engine: "postmark" }],
|
|
529
|
+
bullmq: [{ type: "queue", engine: "bullmq" }],
|
|
530
|
+
bull: [{ type: "queue", engine: "bullmq" }],
|
|
531
|
+
inngest: [{ type: "queue", engine: "inngest" }],
|
|
532
|
+
"@trigger.dev/sdk": [{ type: "queue", engine: "trigger.dev" }],
|
|
533
|
+
"node-cron": [{ type: "cron", engine: "node-cron" }],
|
|
534
|
+
cron: [{ type: "cron", engine: "node-cron" }]
|
|
535
|
+
};
|
|
536
|
+
var PY_SERVICES = {
|
|
537
|
+
psycopg2: [{ type: "database", engine: "postgres" }],
|
|
538
|
+
"psycopg2-binary": [{ type: "database", engine: "postgres" }],
|
|
539
|
+
psycopg: [{ type: "database", engine: "postgres" }],
|
|
540
|
+
asyncpg: [{ type: "database", engine: "postgres" }],
|
|
541
|
+
pymysql: [{ type: "database", engine: "mysql" }],
|
|
542
|
+
mysqlclient: [{ type: "database", engine: "mysql" }],
|
|
543
|
+
pymongo: [{ type: "database", engine: "mongodb" }],
|
|
544
|
+
motor: [{ type: "database", engine: "mongodb" }],
|
|
545
|
+
redis: [{ type: "cache", engine: "redis" }],
|
|
546
|
+
supabase: [{ type: "database", engine: "supabase" }],
|
|
547
|
+
"firebase-admin": [{ type: "database", engine: "firebase" }],
|
|
548
|
+
boto3: [{ type: "external_api", engine: "aws" }],
|
|
549
|
+
openai: [{ type: "llm_api", engine: "openai" }],
|
|
550
|
+
"langchain-openai": [{ type: "llm_api", engine: "openai" }],
|
|
551
|
+
anthropic: [{ type: "llm_api", engine: "anthropic" }],
|
|
552
|
+
"langchain-anthropic": [{ type: "llm_api", engine: "anthropic" }],
|
|
553
|
+
"google-generativeai": [{ type: "llm_api", engine: "gemini" }],
|
|
554
|
+
"google-genai": [{ type: "llm_api", engine: "gemini" }],
|
|
555
|
+
mistralai: [{ type: "llm_api", engine: "mistral" }],
|
|
556
|
+
stripe: [{ type: "external_api", engine: "stripe" }],
|
|
557
|
+
twilio: [{ type: "external_api", engine: "twilio" }],
|
|
558
|
+
sendgrid: [{ type: "email", engine: "sendgrid" }],
|
|
559
|
+
postmarker: [{ type: "email", engine: "postmark" }],
|
|
560
|
+
resend: [{ type: "email", engine: "resend" }],
|
|
561
|
+
celery: [{ type: "queue", engine: "celery" }],
|
|
562
|
+
rq: [{ type: "queue", engine: "rq" }],
|
|
563
|
+
apscheduler: [{ type: "cron", engine: "apscheduler" }]
|
|
564
|
+
};
|
|
565
|
+
var NUGET_SERVICES = Object.fromEntries([
|
|
566
|
+
[
|
|
567
|
+
"database",
|
|
568
|
+
"postgres",
|
|
569
|
+
[
|
|
570
|
+
"npgsql",
|
|
571
|
+
"npgsql.entityframeworkcore.postgresql",
|
|
572
|
+
"aspire.npgsql",
|
|
573
|
+
"aspire.npgsql.entityframeworkcore.postgresql",
|
|
574
|
+
"marten"
|
|
575
|
+
]
|
|
576
|
+
],
|
|
577
|
+
[
|
|
578
|
+
"database",
|
|
579
|
+
"sqlserver",
|
|
580
|
+
[
|
|
581
|
+
"microsoft.entityframeworkcore.sqlserver",
|
|
582
|
+
"microsoft.data.sqlclient",
|
|
583
|
+
"system.data.sqlclient",
|
|
584
|
+
"aspire.microsoft.data.sqlclient",
|
|
585
|
+
"aspire.microsoft.entityframeworkcore.sqlserver"
|
|
586
|
+
]
|
|
587
|
+
],
|
|
588
|
+
[
|
|
589
|
+
"database",
|
|
590
|
+
"mysql",
|
|
591
|
+
[
|
|
592
|
+
"pomelo.entityframeworkcore.mysql",
|
|
593
|
+
"mysqlconnector",
|
|
594
|
+
"mysql.data",
|
|
595
|
+
"mysql.entityframeworkcore",
|
|
596
|
+
"aspire.pomelo.entityframeworkcore.mysql",
|
|
597
|
+
"aspire.mysqlconnector"
|
|
598
|
+
]
|
|
599
|
+
],
|
|
600
|
+
[
|
|
601
|
+
"database",
|
|
602
|
+
"sqlite",
|
|
603
|
+
["microsoft.entityframeworkcore.sqlite", "microsoft.data.sqlite", "system.data.sqlite"]
|
|
604
|
+
],
|
|
605
|
+
["database", "mongodb", ["mongodb.driver", "mongodb.entityframeworkcore", "aspire.mongodb.driver"]],
|
|
606
|
+
[
|
|
607
|
+
"database",
|
|
608
|
+
"cosmosdb",
|
|
609
|
+
["microsoft.azure.cosmos", "microsoft.entityframeworkcore.cosmos", "aspire.microsoft.azure.cosmos"]
|
|
610
|
+
],
|
|
611
|
+
["database", "supabase", ["supabase"]],
|
|
612
|
+
["database", "firebase", ["firebaseadmin", "google.cloud.firestore"]],
|
|
613
|
+
[
|
|
614
|
+
"cache",
|
|
615
|
+
"redis",
|
|
616
|
+
[
|
|
617
|
+
"stackexchange.redis",
|
|
618
|
+
"microsoft.extensions.caching.stackexchangeredis",
|
|
619
|
+
"aspire.stackexchange.redis",
|
|
620
|
+
"aspire.stackexchange.redis.outputcaching",
|
|
621
|
+
"aspire.stackexchange.redis.distributedcaching"
|
|
622
|
+
]
|
|
623
|
+
],
|
|
624
|
+
["object_storage", "s3", ["awssdk.s3"]],
|
|
625
|
+
["object_storage", "azure-blob", ["azure.storage.blobs", "aspire.azure.storage.blobs"]],
|
|
626
|
+
["queue", "hangfire", ["hangfire.core", "hangfire.aspnetcore"]],
|
|
627
|
+
["queue", "rabbitmq", ["rabbitmq.client", "masstransit.rabbitmq", "aspire.rabbitmq.client"]],
|
|
628
|
+
[
|
|
629
|
+
"queue",
|
|
630
|
+
"azure-service-bus",
|
|
631
|
+
[
|
|
632
|
+
"azure.messaging.servicebus",
|
|
633
|
+
"masstransit.azure.servicebus.core",
|
|
634
|
+
"aspire.azure.messaging.servicebus"
|
|
635
|
+
]
|
|
636
|
+
],
|
|
637
|
+
["queue", "sqs", ["awssdk.sqs", "masstransit.amazonsqs"]],
|
|
638
|
+
["queue", "kafka", ["confluent.kafka", "aspire.confluent.kafka"]],
|
|
639
|
+
["cron", "quartz", ["quartz", "quartz.extensions.hosting", "quartz.aspnetcore"]],
|
|
640
|
+
["auth", "aspnetcore-identity", ["microsoft.aspnetcore.identity.entityframeworkcore"]],
|
|
641
|
+
["auth", "entra-id", ["microsoft.identity.web"]],
|
|
642
|
+
["auth", "auth0", ["auth0.aspnetcore.authentication"]],
|
|
643
|
+
["auth", "duende-identityserver", ["duende.identityserver"]],
|
|
644
|
+
["auth", "openiddict", ["openiddict.aspnetcore"]],
|
|
645
|
+
[
|
|
646
|
+
"llm_api",
|
|
647
|
+
"openai",
|
|
648
|
+
["openai", "microsoft.semantickernel.connectors.openai", "microsoft.extensions.ai.openai"]
|
|
649
|
+
],
|
|
650
|
+
[
|
|
651
|
+
"llm_api",
|
|
652
|
+
"azure-openai",
|
|
653
|
+
["azure.ai.openai", "aspire.azure.ai.openai", "microsoft.semantickernel.connectors.azureopenai"]
|
|
654
|
+
],
|
|
655
|
+
["llm_api", "anthropic", ["anthropic", "anthropic.sdk"]],
|
|
656
|
+
["llm_api", "gemini", ["google.genai", "mscc.generativeai"]],
|
|
657
|
+
["email", "sendgrid", ["sendgrid", "sendgrid.extensions.dependencyinjection"]],
|
|
658
|
+
["email", "smtp", ["mailkit"]],
|
|
659
|
+
["email", "postmark", ["postmark"]],
|
|
660
|
+
["email", "resend", ["resend"]],
|
|
661
|
+
["email", "ses", ["awssdk.simpleemail", "awssdk.simpleemailv2"]],
|
|
662
|
+
["external_api", "stripe", ["stripe.net"]],
|
|
663
|
+
["external_api", "twilio", ["twilio"]]
|
|
664
|
+
].flatMap(([type, engine, pkgs]) => pkgs.map((pkg) => [pkg, [{ type, engine }]])));
|
|
665
|
+
var DOTNET_FRAMEWORK_PACKAGES = [
|
|
666
|
+
{ pkg: "giraffe", name: "giraffe" },
|
|
667
|
+
{ pkg: "saturn", name: "saturn" },
|
|
668
|
+
{ pkg: "falco", name: "falco" },
|
|
669
|
+
{ pkg: "servicestack", name: "servicestack" }
|
|
670
|
+
];
|
|
671
|
+
var PRISMA_PROVIDERS = {
|
|
672
|
+
postgresql: "postgres",
|
|
673
|
+
postgres: "postgres",
|
|
674
|
+
mysql: "mysql",
|
|
675
|
+
sqlite: "sqlite",
|
|
676
|
+
mongodb: "mongodb",
|
|
677
|
+
sqlserver: "sqlserver",
|
|
678
|
+
cockroachdb: "postgres"
|
|
679
|
+
};
|
|
680
|
+
var NODE_FRAMEWORKS = [
|
|
681
|
+
{ pkg: "next", name: "nextjs", role: "meta", port: 3e3 },
|
|
682
|
+
{ pkg: "@remix-run/node", name: "remix", role: "meta", port: 3e3 },
|
|
683
|
+
{ pkg: "@remix-run/react", name: "remix", role: "meta", port: 3e3 },
|
|
684
|
+
{ pkg: "@react-router/dev", name: "react-router", role: "meta", port: 3e3 },
|
|
685
|
+
{ pkg: "nuxt", name: "nuxt", role: "meta", port: 3e3 },
|
|
686
|
+
{ pkg: "@sveltejs/kit", name: "sveltekit", role: "meta", port: 3e3 },
|
|
687
|
+
{ pkg: "astro", name: "astro", role: "meta", port: 4321 },
|
|
688
|
+
{ pkg: "@nestjs/core", name: "nestjs", role: "server", port: 3e3 },
|
|
689
|
+
{ pkg: "fastify", name: "fastify", role: "server", port: 3e3 },
|
|
690
|
+
{ pkg: "hono", name: "hono", role: "server", port: 3e3 },
|
|
691
|
+
{ pkg: "express", name: "express", role: "server", port: 3e3 },
|
|
692
|
+
{ pkg: "koa", name: "koa", role: "server", port: 3e3 },
|
|
693
|
+
{ pkg: "vite", name: "vite", role: "frontend" },
|
|
694
|
+
{ pkg: "react-scripts", name: "create-react-app", role: "frontend" }
|
|
695
|
+
];
|
|
696
|
+
var PY_FRAMEWORKS = [
|
|
697
|
+
{ pkg: "fastapi", name: "fastapi", kind: "api", port: 8e3 },
|
|
698
|
+
{ pkg: "django", name: "django", kind: "web", port: 8e3 },
|
|
699
|
+
{ pkg: "flask", name: "flask", kind: "web", port: 5e3 },
|
|
700
|
+
{ pkg: "streamlit", name: "streamlit", kind: "web", port: 8501 },
|
|
701
|
+
{ pkg: "gradio", name: "gradio", kind: "web", port: 7860 }
|
|
702
|
+
];
|
|
703
|
+
var SECRET_HINT = /(SECRET|TOKEN|PASSWORD|PASSWD|PRIVATE|API_?KEY|_KEY$|^KEY$|DATABASE_URL|_DSN$|CREDENTIAL|SERVICE_ROLE|WEBHOOK_?URL$|CONNECTION_?STRING|CONNECTION$)/;
|
|
704
|
+
var CONNECTION_URL = /^(POSTGRES(QL)?|PG|MYSQL|MARIADB|MONGO(DB)?|REDIS|KV|DATABASE|DB|AMQP|RABBITMQ)_(URL|URI)$|_(DATABASE|DB)_(URL|URI)$/;
|
|
705
|
+
var PUBLIC_PREFIX = /^(NEXT_PUBLIC_|VITE_|PUBLIC_|NUXT_PUBLIC_|EXPO_PUBLIC_|REACT_APP_)/;
|
|
706
|
+
function isSecretName(name) {
|
|
707
|
+
return !PUBLIC_PREFIX.test(name) && (SECRET_HINT.test(name) || CONNECTION_URL.test(name));
|
|
708
|
+
}
|
|
709
|
+
var IGNORED_ENV = /* @__PURE__ */ new Set([
|
|
710
|
+
"NODE_ENV",
|
|
711
|
+
"PORT",
|
|
712
|
+
"HOST",
|
|
713
|
+
"HOSTNAME",
|
|
714
|
+
"PWD",
|
|
715
|
+
"HOME",
|
|
716
|
+
"PATH",
|
|
717
|
+
"CI",
|
|
718
|
+
"DEBUG",
|
|
719
|
+
"TZ",
|
|
720
|
+
"APPDATA",
|
|
721
|
+
"LOCALAPPDATA",
|
|
722
|
+
"USERPROFILE"
|
|
723
|
+
]);
|
|
724
|
+
var TEST_ENV = /^(PLAYWRIGHT|CYPRESS|VITEST|JEST|CI_|GITHUB_)/;
|
|
725
|
+
|
|
726
|
+
// packages/detectors/dist/env.js
|
|
727
|
+
var ENV_FILES = /(^|\/)\.env\.(example|sample|template|local\.example)$/;
|
|
728
|
+
var SOURCE = /\.(js|cjs|mjs|jsx|ts|tsx|mts|cts|py|vue|svelte|astro)$/;
|
|
729
|
+
var TEST_PATH = /(^|\/)(tests?|__tests__|e2e|cypress|playwright|spec)\/|\.(test|spec)\.[a-z]+$|(^|\/)(playwright|vitest|jest|cypress)\.config\./i;
|
|
730
|
+
var VITE_BUILTINS = /* @__PURE__ */ new Set(["MODE", "DEV", "PROD", "SSR", "BASE_URL"]);
|
|
731
|
+
var CODE_PATTERNS = [
|
|
732
|
+
/process\.env\.([A-Z_][A-Z0-9_]*)/g,
|
|
733
|
+
/process\.env\[\s*['"]([A-Z_][A-Z0-9_]*)['"]\s*\]/g,
|
|
734
|
+
/import\.meta\.env\.([A-Z_][A-Z0-9_]*)/g,
|
|
735
|
+
/os\.environ\[\s*['"]([A-Z_][A-Z0-9_]*)['"]\s*\]/g,
|
|
736
|
+
/os\.environ\.get\(\s*['"]([A-Z_][A-Z0-9_]*)['"]/g,
|
|
737
|
+
/os\.getenv\(\s*['"]([A-Z_][A-Z0-9_]*)['"]/g
|
|
738
|
+
];
|
|
739
|
+
function detectEnv(files) {
|
|
740
|
+
const found = /* @__PURE__ */ new Map();
|
|
741
|
+
for (const f of files.list()) {
|
|
742
|
+
if (ENV_FILES.test(f)) {
|
|
743
|
+
for (const line of (files.read(f) ?? "").split(/\r?\n/)) {
|
|
744
|
+
const m = line.match(/^\s*(?:export\s+)?([A-Z_][A-Z0-9_]*)\s*=/);
|
|
745
|
+
if (m && !found.has(m[1]))
|
|
746
|
+
found.set(m[1], f);
|
|
747
|
+
}
|
|
748
|
+
} else if (SOURCE.test(f) && !TEST_PATH.test(f)) {
|
|
749
|
+
const src = files.read(f);
|
|
750
|
+
if (!src)
|
|
751
|
+
continue;
|
|
752
|
+
for (const re of CODE_PATTERNS) {
|
|
753
|
+
for (const m of src.matchAll(re)) {
|
|
754
|
+
const name = m[1];
|
|
755
|
+
if (!found.has(name))
|
|
756
|
+
found.set(name, f);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
const env = [];
|
|
762
|
+
for (const name of [...found.keys()].sort()) {
|
|
763
|
+
if (IGNORED_ENV.has(name) || VITE_BUILTINS.has(name) || TEST_ENV.test(name))
|
|
764
|
+
continue;
|
|
765
|
+
env.push({ name, secret: isSecretName(name) });
|
|
766
|
+
}
|
|
767
|
+
return { env, evidence: found };
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// packages/detectors/dist/node.js
|
|
771
|
+
function readPackageJson(files, rel = "package.json") {
|
|
772
|
+
const raw = files.read(rel);
|
|
773
|
+
if (!raw)
|
|
774
|
+
return null;
|
|
775
|
+
try {
|
|
776
|
+
return JSON.parse(raw);
|
|
777
|
+
} catch {
|
|
778
|
+
return null;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
function nodePackageManager(files, pkg) {
|
|
782
|
+
const declared = pkg?.packageManager?.split("@")[0];
|
|
783
|
+
if (declared)
|
|
784
|
+
return declared;
|
|
785
|
+
const lock = firstExisting(files, [
|
|
786
|
+
"pnpm-lock.yaml",
|
|
787
|
+
"yarn.lock",
|
|
788
|
+
"bun.lockb",
|
|
789
|
+
"bun.lock",
|
|
790
|
+
"package-lock.json"
|
|
791
|
+
]);
|
|
792
|
+
return lock ? {
|
|
793
|
+
"pnpm-lock.yaml": "pnpm",
|
|
794
|
+
"yarn.lock": "yarn",
|
|
795
|
+
"bun.lockb": "bun",
|
|
796
|
+
"bun.lock": "bun",
|
|
797
|
+
"package-lock.json": "npm"
|
|
798
|
+
}[lock] : void 0;
|
|
799
|
+
}
|
|
800
|
+
function detectNode(files, fallbackName, inheritedPm) {
|
|
801
|
+
const pkg = readPackageJson(files);
|
|
802
|
+
if (!pkg)
|
|
803
|
+
return null;
|
|
804
|
+
const warnings = [];
|
|
805
|
+
const runtimeDeps = pkg.dependencies ?? {};
|
|
806
|
+
const allDeps = { ...pkg.devDependencies ?? {}, ...runtimeDeps };
|
|
807
|
+
const has = (d) => d in allDeps;
|
|
808
|
+
const present = NODE_FRAMEWORKS.filter((f) => has(f.pkg));
|
|
809
|
+
const meta = present.find((f) => f.role === "meta");
|
|
810
|
+
const server2 = present.find((f) => f.role === "server");
|
|
811
|
+
const frontend = present.find((f) => f.role === "frontend");
|
|
812
|
+
let framework;
|
|
813
|
+
let kind;
|
|
814
|
+
let defaultPort;
|
|
815
|
+
const viteFlavor = () => has("react") ? "vite-react" : has("vue") ? "vite-vue" : has("svelte") ? "vite-svelte" : has("solid-js") ? "vite-solid" : "vite";
|
|
816
|
+
if (meta) {
|
|
817
|
+
framework = meta.name;
|
|
818
|
+
defaultPort = meta.port;
|
|
819
|
+
kind = "fullstack";
|
|
820
|
+
if (meta.name === "nextjs") {
|
|
821
|
+
const cfg = firstExisting(files, [
|
|
822
|
+
"next.config.js",
|
|
823
|
+
"next.config.mjs",
|
|
824
|
+
"next.config.ts",
|
|
825
|
+
"next.config.cjs"
|
|
826
|
+
]);
|
|
827
|
+
if (cfg && /output\s*:\s*['"]export['"]/.test(files.read(cfg) ?? "")) {
|
|
828
|
+
kind = "static";
|
|
829
|
+
defaultPort = void 0;
|
|
830
|
+
}
|
|
831
|
+
} else if (meta.name === "astro") {
|
|
832
|
+
const cfg = firstExisting(files, ["astro.config.mjs", "astro.config.ts", "astro.config.js"]);
|
|
833
|
+
const text2 = cfg ? files.read(cfg) ?? "" : "";
|
|
834
|
+
const ssr = /output\s*:\s*['"](server|hybrid)['"]/.test(text2) || Object.keys(allDeps).some((d) => d.startsWith("@astrojs/") && /node|vercel|netlify|cloudflare/.test(d));
|
|
835
|
+
if (!ssr) {
|
|
836
|
+
kind = "static";
|
|
837
|
+
defaultPort = void 0;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
} else if (server2 && frontend) {
|
|
841
|
+
framework = server2.name;
|
|
842
|
+
defaultPort = server2.port;
|
|
843
|
+
kind = "fullstack";
|
|
844
|
+
} else if (server2) {
|
|
845
|
+
framework = server2.name;
|
|
846
|
+
defaultPort = server2.port;
|
|
847
|
+
kind = "api";
|
|
848
|
+
} else if (frontend) {
|
|
849
|
+
framework = frontend.name === "vite" ? viteFlavor() : frontend.name;
|
|
850
|
+
kind = "static";
|
|
851
|
+
} else {
|
|
852
|
+
const hasWorkerDeps = ["bullmq", "bull", "inngest", "@trigger.dev/sdk", "node-cron", "cron"].some(has);
|
|
853
|
+
if (hasWorkerDeps && (pkg.scripts?.start || pkg.main)) {
|
|
854
|
+
kind = "worker";
|
|
855
|
+
} else if (pkg.scripts?.start) {
|
|
856
|
+
kind = "api";
|
|
857
|
+
warnings.push("no known web framework; assuming an HTTP service from the start script");
|
|
858
|
+
} else {
|
|
859
|
+
kind = "static";
|
|
860
|
+
warnings.push("no framework or start script found");
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
const isApp = Boolean(framework) || Boolean(pkg.scripts?.start);
|
|
864
|
+
const language = has("typescript") || files.list().includes("tsconfig.json") ? "typescript" : "javascript";
|
|
865
|
+
const versionFile = files.read(".nvmrc") ?? files.read(".node-version");
|
|
866
|
+
const version = (pkg.engines?.node ?? versionFile ?? "").trim().replace(/^v/, "") || void 0;
|
|
867
|
+
const runtime = {
|
|
868
|
+
language,
|
|
869
|
+
source: "detector",
|
|
870
|
+
...version ? { version } : {},
|
|
871
|
+
...framework ? { framework } : {}
|
|
872
|
+
};
|
|
873
|
+
const services = new ServiceSet();
|
|
874
|
+
for (const dep of Object.keys(allDeps)) {
|
|
875
|
+
for (const hit of NPM_SERVICES[dep] ?? [])
|
|
876
|
+
services.add(hit, `package.json: ${dep}`);
|
|
877
|
+
}
|
|
878
|
+
if (has("ai") && !services.values().some((x) => x.type === "llm_api")) {
|
|
879
|
+
services.add({ type: "llm_api", engine: "vercel-ai-gateway" }, "package.json: ai");
|
|
880
|
+
}
|
|
881
|
+
if (has("@prisma/client") || has("prisma")) {
|
|
882
|
+
const schemaPath = pkg.prisma?.schema ?? firstExisting(files, ["prisma/schema.prisma", "schema.prisma", "prisma/schema/schema.prisma"]);
|
|
883
|
+
const schema = schemaPath ? files.read(schemaPath) : null;
|
|
884
|
+
const provider = schema?.match(/datasource\s+\w+\s*\{[^}]*provider\s*=\s*"(\w+)"/s)?.[1];
|
|
885
|
+
const engine = provider ? PRISMA_PROVIDERS[provider] : void 0;
|
|
886
|
+
if (engine)
|
|
887
|
+
services.add({ type: "database", engine }, `${schemaPath}: provider = "${provider}"`);
|
|
888
|
+
else
|
|
889
|
+
warnings.push("Prisma found but its datasource provider could not be read");
|
|
890
|
+
}
|
|
891
|
+
const drizzleCfg = firstExisting(files, ["drizzle.config.ts", "drizzle.config.js", "drizzle.config.mjs"]);
|
|
892
|
+
const dialect = drizzleCfg ? (files.read(drizzleCfg) ?? "").match(/dialect\s*:\s*['"](\w+)['"]/)?.[1] : void 0;
|
|
893
|
+
if (dialect) {
|
|
894
|
+
const engine = { postgresql: "postgres", mysql: "mysql", sqlite: "sqlite", turso: "sqlite" }[dialect];
|
|
895
|
+
if (engine)
|
|
896
|
+
services.add({ type: "database", engine }, `${drizzleCfg}: dialect "${dialect}"`);
|
|
897
|
+
}
|
|
898
|
+
if (files.list().includes("supabase/config.toml"))
|
|
899
|
+
services.add({ type: "database", engine: "supabase" }, "supabase/config.toml");
|
|
900
|
+
if (files.list().includes("firebase.json"))
|
|
901
|
+
services.add({ type: "database", engine: "firebase" }, "firebase.json");
|
|
902
|
+
const vercelJson = files.read("vercel.json");
|
|
903
|
+
if (vercelJson && /"crons"\s*:/.test(vercelJson))
|
|
904
|
+
services.add({ type: "cron", engine: "vercel-cron" }, "vercel.json: crons");
|
|
905
|
+
const pm = nodePackageManager(files, pkg) ?? inheritedPm;
|
|
906
|
+
const run = (script) => pm === "npm" || !pm ? `npm run ${script}` : `${pm} run ${script}`;
|
|
907
|
+
const dockerfile = files.list().includes("Dockerfile");
|
|
908
|
+
const port = dockerPort(files) ?? defaultPort;
|
|
909
|
+
const build = {
|
|
910
|
+
...pm ? { packageManager: pm } : {},
|
|
911
|
+
...pkg.scripts?.build ? { buildCommand: run("build") } : {},
|
|
912
|
+
...pkg.scripts?.start ? { startCommand: run("start") } : {},
|
|
913
|
+
...dockerfile ? { dockerfile } : {},
|
|
914
|
+
...port ? { port } : {}
|
|
915
|
+
};
|
|
916
|
+
const name = (pkg.name ?? fallbackName).replace(/^@[^/]+\//, "") || fallbackName;
|
|
917
|
+
return {
|
|
918
|
+
profile: { app: { name, kind }, runtimes: [runtime], services: services.values(), build },
|
|
919
|
+
isApp,
|
|
920
|
+
warnings
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/error.js
|
|
925
|
+
function getLineColFromPtr(string, ptr) {
|
|
926
|
+
let lines = string.slice(0, ptr).split(/\r?\n/);
|
|
927
|
+
return [lines.length, lines.pop().length + 1];
|
|
928
|
+
}
|
|
929
|
+
function makeCodeBlock(string, line, column) {
|
|
930
|
+
let lines = string.split(/\r?\n/);
|
|
931
|
+
let codeblock = "";
|
|
932
|
+
let numberLen = (Math.log10(line + 1) | 0) + 1;
|
|
933
|
+
for (let i = line - 1; i <= line + 1; i++) {
|
|
934
|
+
let l = lines[i - 1];
|
|
935
|
+
if (!l)
|
|
936
|
+
continue;
|
|
937
|
+
codeblock += i.toString().padEnd(numberLen, " ");
|
|
938
|
+
codeblock += ": ";
|
|
939
|
+
codeblock += l;
|
|
940
|
+
codeblock += "\n";
|
|
941
|
+
if (i === line) {
|
|
942
|
+
codeblock += " ".repeat(numberLen + column + 2);
|
|
943
|
+
codeblock += "^\n";
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return codeblock;
|
|
947
|
+
}
|
|
948
|
+
var TomlError = class _TomlError extends Error {
|
|
949
|
+
line;
|
|
950
|
+
column;
|
|
951
|
+
codeblock;
|
|
952
|
+
constructor(message, options) {
|
|
953
|
+
const [line, column] = getLineColFromPtr(options.toml, options.ptr);
|
|
954
|
+
const codeblock = makeCodeBlock(options.toml, line, column);
|
|
955
|
+
super(`Invalid TOML document: ${message}
|
|
956
|
+
|
|
957
|
+
${codeblock}`, options);
|
|
958
|
+
this.line = line;
|
|
959
|
+
this.column = column;
|
|
960
|
+
this.codeblock = codeblock;
|
|
961
|
+
}
|
|
962
|
+
/** @internal */
|
|
963
|
+
static x(message, ctx, ptr) {
|
|
964
|
+
throw new _TomlError(message, { toml: ctx.s, ptr: ptr ?? ctx.p });
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/primitive.js
|
|
969
|
+
function parseString(ctx) {
|
|
970
|
+
let startPtr = ctx.p;
|
|
971
|
+
let c = ctx.s.charCodeAt(ctx.p++);
|
|
972
|
+
let first = c;
|
|
973
|
+
let isLiteral = c === 39;
|
|
974
|
+
let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
|
|
975
|
+
if (isMultiline) {
|
|
976
|
+
if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 10)
|
|
977
|
+
ctx.p++;
|
|
978
|
+
else if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)
|
|
979
|
+
ctx.p += 2;
|
|
980
|
+
}
|
|
981
|
+
let parsed = "";
|
|
982
|
+
let sliceStart = ctx.p;
|
|
983
|
+
let state = 0;
|
|
984
|
+
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
985
|
+
c = ctx.s.charCodeAt(ctx.p);
|
|
986
|
+
if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) {
|
|
987
|
+
state = state && 3;
|
|
988
|
+
} else if (c < 32 && c !== 9 || c === 127) {
|
|
989
|
+
TomlError.x("control characters are not allowed in strings", ctx);
|
|
990
|
+
} else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
|
|
991
|
+
if (isMultiline) {
|
|
992
|
+
if (ctx.s.charCodeAt(ctx.p + 3) === first)
|
|
993
|
+
ctx.p++;
|
|
994
|
+
if (ctx.s.charCodeAt(ctx.p + 3) === first)
|
|
995
|
+
ctx.p++;
|
|
996
|
+
}
|
|
997
|
+
if (!state) {
|
|
998
|
+
let s = ctx.s.slice(sliceStart, ctx.p);
|
|
999
|
+
parsed = parsed ? parsed + s : s;
|
|
1000
|
+
}
|
|
1001
|
+
ctx.p += isMultiline ? 3 : 1;
|
|
1002
|
+
return parsed;
|
|
1003
|
+
} else if (!state) {
|
|
1004
|
+
if (!isLiteral && c === 92) {
|
|
1005
|
+
parsed += ctx.s.slice(sliceStart, sliceStart = ctx.p);
|
|
1006
|
+
state = 1;
|
|
1007
|
+
}
|
|
1008
|
+
} else if (state === 1) {
|
|
1009
|
+
if (c === 120 || c === 117 || c === 85) {
|
|
1010
|
+
let errPtr = ctx.p++ - 1;
|
|
1011
|
+
let value = 0;
|
|
1012
|
+
let len = c === 120 ? 2 : c === 117 ? 4 : 8;
|
|
1013
|
+
for (let j = 0; j < len; j++, ctx.p++) {
|
|
1014
|
+
let hex = ctx.s.charCodeAt(ctx.p);
|
|
1015
|
+
let digit = (
|
|
1016
|
+
/* 0-9 */
|
|
1017
|
+
hex >= 48 && hex <= 57 ? hex - 48 : (
|
|
1018
|
+
/* A-F */
|
|
1019
|
+
hex >= 65 && hex <= 70 ? hex - 65 + 10 : (
|
|
1020
|
+
/* a-f */
|
|
1021
|
+
hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1
|
|
1022
|
+
)
|
|
1023
|
+
)
|
|
1024
|
+
);
|
|
1025
|
+
if (digit < 0)
|
|
1026
|
+
TomlError.x("invalid non-hex character in unicode escape", ctx);
|
|
1027
|
+
value = value << 4 | digit;
|
|
1028
|
+
}
|
|
1029
|
+
if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) {
|
|
1030
|
+
TomlError.x("invalid unicode escape", ctx, errPtr);
|
|
1031
|
+
}
|
|
1032
|
+
parsed += String.fromCodePoint(value);
|
|
1033
|
+
sliceStart = ctx.p--;
|
|
1034
|
+
state = 0;
|
|
1035
|
+
} else if (isMultiline && (c === 32 || c === 9)) {
|
|
1036
|
+
state = 2;
|
|
1037
|
+
} else {
|
|
1038
|
+
if (c === 98)
|
|
1039
|
+
parsed += "\b";
|
|
1040
|
+
else if (c === 116)
|
|
1041
|
+
parsed += " ";
|
|
1042
|
+
else if (c === 110)
|
|
1043
|
+
parsed += "\n";
|
|
1044
|
+
else if (c === 102)
|
|
1045
|
+
parsed += "\f";
|
|
1046
|
+
else if (c === 114)
|
|
1047
|
+
parsed += "\r";
|
|
1048
|
+
else if (c === 101)
|
|
1049
|
+
parsed += "\x1B";
|
|
1050
|
+
else if (c === 34)
|
|
1051
|
+
parsed += '"';
|
|
1052
|
+
else if (c === 92)
|
|
1053
|
+
parsed += "\\";
|
|
1054
|
+
else
|
|
1055
|
+
TomlError.x("unrecognised escape sequence", ctx);
|
|
1056
|
+
sliceStart = ctx.p + 1;
|
|
1057
|
+
state = 0;
|
|
1058
|
+
}
|
|
1059
|
+
} else if (c !== 32 && c !== 9) {
|
|
1060
|
+
if (state === 2)
|
|
1061
|
+
TomlError.x("invalid escape: only line-ending whitespace may be escaped", ctx, sliceStart);
|
|
1062
|
+
state = !isLiteral && c === 92 ? 1 : 0;
|
|
1063
|
+
sliceStart = ctx.p;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
TomlError.x("unfinished string", ctx, startPtr);
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/date.js
|
|
1070
|
+
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
|
|
1071
|
+
var TomlDate = class _TomlDate extends Date {
|
|
1072
|
+
#hasDate = false;
|
|
1073
|
+
#hasTime = false;
|
|
1074
|
+
#offset = null;
|
|
1075
|
+
constructor(date, fasttype, unsafeDelim) {
|
|
1076
|
+
let hasDate = true;
|
|
1077
|
+
let hasTime = true;
|
|
1078
|
+
let offset = "Z";
|
|
1079
|
+
let c;
|
|
1080
|
+
if (typeof date === "string") {
|
|
1081
|
+
if (fasttype)
|
|
1082
|
+
prep: {
|
|
1083
|
+
if (fasttype < 3) {
|
|
1084
|
+
if (+date.slice(11, 13) > 23) {
|
|
1085
|
+
date = "";
|
|
1086
|
+
break prep;
|
|
1087
|
+
}
|
|
1088
|
+
if (fasttype === 2) {
|
|
1089
|
+
offset = null;
|
|
1090
|
+
date += "Z";
|
|
1091
|
+
} else if ((c = date.charCodeAt(date.length - 1)) !== 90 && c !== 122) {
|
|
1092
|
+
offset = date.slice(date.length - 6);
|
|
1093
|
+
}
|
|
1094
|
+
if (unsafeDelim)
|
|
1095
|
+
date = date.slice(0, 10) + "T" + date.slice(11);
|
|
1096
|
+
} else if (fasttype === 4) {
|
|
1097
|
+
date = +date.slice(0, 2) > 23 ? "" : `0000-01-01T${date}Z`;
|
|
1098
|
+
}
|
|
1099
|
+
hasDate = fasttype !== 4;
|
|
1100
|
+
hasTime = fasttype !== 3;
|
|
1101
|
+
}
|
|
1102
|
+
else {
|
|
1103
|
+
let match = date.match(DATE_TIME_RE);
|
|
1104
|
+
if (match) {
|
|
1105
|
+
if (!match[1]) {
|
|
1106
|
+
hasDate = false;
|
|
1107
|
+
date = `0000-01-01T${date}`;
|
|
1108
|
+
}
|
|
1109
|
+
hasTime = !!match[2];
|
|
1110
|
+
hasTime && date[10] === " " && (date = date.replace(" ", "T"));
|
|
1111
|
+
if (match[2] && +match[2] > 23) {
|
|
1112
|
+
date = "";
|
|
1113
|
+
} else {
|
|
1114
|
+
offset = match[3] || null;
|
|
1115
|
+
if (!offset && hasTime)
|
|
1116
|
+
date += "Z";
|
|
1117
|
+
}
|
|
1118
|
+
} else {
|
|
1119
|
+
date = "";
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
super(date);
|
|
1124
|
+
if (!isNaN(this.getTime())) {
|
|
1125
|
+
this.#hasDate = hasDate;
|
|
1126
|
+
this.#hasTime = hasTime;
|
|
1127
|
+
this.#offset = offset;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
isDateTime() {
|
|
1131
|
+
return this.#hasDate && this.#hasTime;
|
|
1132
|
+
}
|
|
1133
|
+
isLocal() {
|
|
1134
|
+
return !this.#hasDate || !this.#hasTime || !this.#offset;
|
|
1135
|
+
}
|
|
1136
|
+
isDate() {
|
|
1137
|
+
return this.#hasDate && !this.#hasTime;
|
|
1138
|
+
}
|
|
1139
|
+
isTime() {
|
|
1140
|
+
return this.#hasTime && !this.#hasDate;
|
|
1141
|
+
}
|
|
1142
|
+
isValid() {
|
|
1143
|
+
return this.#hasDate || this.#hasTime;
|
|
1144
|
+
}
|
|
1145
|
+
toISOString() {
|
|
1146
|
+
let iso = super.toISOString();
|
|
1147
|
+
if (this.isDate())
|
|
1148
|
+
return iso.slice(0, 10);
|
|
1149
|
+
if (this.isTime())
|
|
1150
|
+
return iso.slice(11, 23);
|
|
1151
|
+
if (this.#offset === null)
|
|
1152
|
+
return iso.slice(0, -1);
|
|
1153
|
+
if (this.#offset === "Z" || this.#offset === "z")
|
|
1154
|
+
return iso;
|
|
1155
|
+
let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
|
|
1156
|
+
offset = this.#offset[0] === "-" ? offset : -offset;
|
|
1157
|
+
let offsetDate = new Date(this.getTime() - offset * 6e4);
|
|
1158
|
+
return offsetDate.toISOString().slice(0, -1) + this.#offset;
|
|
1159
|
+
}
|
|
1160
|
+
static wrapAsOffsetDateTime(jsDate, offset = "Z") {
|
|
1161
|
+
let date = new _TomlDate(jsDate);
|
|
1162
|
+
date.#offset = offset;
|
|
1163
|
+
return date;
|
|
1164
|
+
}
|
|
1165
|
+
static wrapAsLocalDateTime(jsDate) {
|
|
1166
|
+
let date = new _TomlDate(jsDate);
|
|
1167
|
+
date.#offset = null;
|
|
1168
|
+
return date;
|
|
1169
|
+
}
|
|
1170
|
+
static wrapAsLocalDate(jsDate) {
|
|
1171
|
+
let date = new _TomlDate(jsDate);
|
|
1172
|
+
date.#hasTime = false;
|
|
1173
|
+
date.#offset = null;
|
|
1174
|
+
return date;
|
|
1175
|
+
}
|
|
1176
|
+
static wrapAsLocalTime(jsDate) {
|
|
1177
|
+
let date = new _TomlDate(jsDate);
|
|
1178
|
+
date.#hasDate = false;
|
|
1179
|
+
date.#offset = null;
|
|
1180
|
+
return date;
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1184
|
+
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/extract.js
|
|
1185
|
+
function isDigit(char, base = 10) {
|
|
1186
|
+
return base === 16 ? char > 47 && char < 58 || char > 64 && char < 71 || char > 96 && char < 103 : char > 47 && char < 48 + base;
|
|
1187
|
+
}
|
|
1188
|
+
function isEndOfValue(char, delim) {
|
|
1189
|
+
return char === 32 || char === 9 || char === 10 || char === 13 || // Structure end or next value delimiter
|
|
1190
|
+
delim && (char === delim || char === 44) || // Comment
|
|
1191
|
+
char === 35;
|
|
1192
|
+
}
|
|
1193
|
+
function extractValue(ctx, end) {
|
|
1194
|
+
let errPtr = ctx.p;
|
|
1195
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
1196
|
+
if (c === 91 || c === 123) {
|
|
1197
|
+
ctx.d-- || TomlError.x("document contains excessively nested structures. aborting.", ctx);
|
|
1198
|
+
let value = c === 91 ? parseArray(ctx) : parseInlineTable(ctx);
|
|
1199
|
+
ctx.d++;
|
|
1200
|
+
return value;
|
|
1201
|
+
}
|
|
1202
|
+
if (c === 34 || c === 39) {
|
|
1203
|
+
return parseString(ctx);
|
|
1204
|
+
}
|
|
1205
|
+
if (c === 116) {
|
|
1206
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101)
|
|
1207
|
+
TomlError.x("invalid value", ctx, errPtr);
|
|
1208
|
+
return ctx.p++, true;
|
|
1209
|
+
}
|
|
1210
|
+
if (c === 102) {
|
|
1211
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101)
|
|
1212
|
+
TomlError.x("invalid value", ctx, errPtr);
|
|
1213
|
+
return ctx.p++, false;
|
|
1214
|
+
}
|
|
1215
|
+
if (c === 43 || c === 45) {
|
|
1216
|
+
return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 44 - c, end);
|
|
1217
|
+
}
|
|
1218
|
+
if (ctx.s.charCodeAt(ctx.p + 4) === 45 && ctx.s.charCodeAt(ctx.p + 7) === 45) {
|
|
1219
|
+
return parseDate(ctx, c, end);
|
|
1220
|
+
}
|
|
1221
|
+
if (ctx.s.charCodeAt(ctx.p + 2) === 58) {
|
|
1222
|
+
return parseTime(ctx, c, end);
|
|
1223
|
+
}
|
|
1224
|
+
return parseNumber(ctx, ctx.p, c, 0, end);
|
|
1225
|
+
}
|
|
1226
|
+
function parseNumber(ctx, startPtr, startChr, sign, endChr) {
|
|
1227
|
+
let c = startChr;
|
|
1228
|
+
let state = 0;
|
|
1229
|
+
let hasUnderscores = false;
|
|
1230
|
+
if (c === 105) {
|
|
1231
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 110 || ctx.s.charCodeAt(++ctx.p) !== 102)
|
|
1232
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
1233
|
+
return ctx.p++, (sign || 1) / 0;
|
|
1234
|
+
}
|
|
1235
|
+
if (c === 110) {
|
|
1236
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 110)
|
|
1237
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
1238
|
+
return ctx.p++, NaN;
|
|
1239
|
+
}
|
|
1240
|
+
if (c === 48) {
|
|
1241
|
+
if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr))
|
|
1242
|
+
return ctx.bi === true ? 0n : 0;
|
|
1243
|
+
if (!sign) {
|
|
1244
|
+
if (c === 120)
|
|
1245
|
+
return parseIntegerBaseN(ctx, startPtr, 16, endChr);
|
|
1246
|
+
else if (c === 98)
|
|
1247
|
+
return parseIntegerBaseN(ctx, startPtr, 2, endChr);
|
|
1248
|
+
else if (c === 111)
|
|
1249
|
+
return parseIntegerBaseN(ctx, startPtr, 8, endChr);
|
|
1250
|
+
}
|
|
1251
|
+
if (c === 46)
|
|
1252
|
+
state = 2;
|
|
1253
|
+
else if (c === 101 || c === 69)
|
|
1254
|
+
state = 4;
|
|
1255
|
+
else
|
|
1256
|
+
TomlError.x("illegal leading zero", ctx, startPtr);
|
|
1257
|
+
} else if (!isDigit(c))
|
|
1258
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
1259
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
1260
|
+
if (!state)
|
|
1261
|
+
state = 1;
|
|
1262
|
+
if (c === 95) {
|
|
1263
|
+
if (!(state & 1))
|
|
1264
|
+
TomlError.x("illegal underscore", ctx);
|
|
1265
|
+
state += 11;
|
|
1266
|
+
hasUnderscores = true;
|
|
1267
|
+
} else if (state === 1 && c === 46)
|
|
1268
|
+
state = 2;
|
|
1269
|
+
else if ((state === 1 || state === 3) && (c === 101 || c === 69))
|
|
1270
|
+
state = 4;
|
|
1271
|
+
else if (state === 4 && (c === 43 || c === 45)) {
|
|
1272
|
+
state = 6;
|
|
1273
|
+
} else if (!isDigit(c))
|
|
1274
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
1275
|
+
else if (state > 9)
|
|
1276
|
+
state -= 11;
|
|
1277
|
+
else if (!(state & 1))
|
|
1278
|
+
state++;
|
|
1279
|
+
}
|
|
1280
|
+
if (!state) {
|
|
1281
|
+
let val = (startChr - 48) * (sign || 1);
|
|
1282
|
+
return ctx.bi === true ? BigInt(val) : val;
|
|
1283
|
+
}
|
|
1284
|
+
if (!(state & 1))
|
|
1285
|
+
TomlError.x("unfinished numeric value", ctx, startPtr);
|
|
1286
|
+
let str = ctx.s.slice(startPtr, ctx.p);
|
|
1287
|
+
if (hasUnderscores)
|
|
1288
|
+
str = str.replaceAll("_", "");
|
|
1289
|
+
return state > 1 ? parseFloat(str) : parseInteger(ctx, str, 10, startPtr);
|
|
1290
|
+
}
|
|
1291
|
+
function parseIntegerBaseN(ctx, startPtr, base, endChr) {
|
|
1292
|
+
let c, underscore = 1;
|
|
1293
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
1294
|
+
if (c === 95) {
|
|
1295
|
+
if (underscore & 1)
|
|
1296
|
+
TomlError.x("illegal underscore", ctx);
|
|
1297
|
+
underscore = 3;
|
|
1298
|
+
} else if (!isDigit(c, base))
|
|
1299
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
1300
|
+
else if (underscore & 1)
|
|
1301
|
+
underscore--;
|
|
1302
|
+
}
|
|
1303
|
+
if (underscore & 1)
|
|
1304
|
+
TomlError.x("unfinished numeric value", ctx);
|
|
1305
|
+
let str = ctx.s.slice(startPtr + 2, ctx.p);
|
|
1306
|
+
if (underscore)
|
|
1307
|
+
str = str.replaceAll("_", "");
|
|
1308
|
+
return parseInteger(ctx, str, base, startPtr);
|
|
1309
|
+
}
|
|
1310
|
+
function parseInteger(ctx, str, base, startPtr) {
|
|
1311
|
+
if (ctx.bi !== true)
|
|
1312
|
+
int: {
|
|
1313
|
+
let val = parseInt(str, base);
|
|
1314
|
+
if (!Number.isSafeInteger(val)) {
|
|
1315
|
+
if (ctx.bi)
|
|
1316
|
+
break int;
|
|
1317
|
+
TomlError.x("integer value cannot be represented losslessly", ctx, startPtr);
|
|
1318
|
+
}
|
|
1319
|
+
return val;
|
|
1320
|
+
}
|
|
1321
|
+
return base === 10 ? BigInt(str) : BigInt((base === 2 ? "0b" : base === 8 ? "0o" : "0x") + str);
|
|
1322
|
+
}
|
|
1323
|
+
function parseDate(ctx, c, endChr) {
|
|
1324
|
+
let startPtr = ctx.p++, unsafeSeparator;
|
|
1325
|
+
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++))) {
|
|
1326
|
+
return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
|
|
1327
|
+
}
|
|
1328
|
+
ctx.p += 5;
|
|
1329
|
+
if (!isDigit(ctx.s.charCodeAt(ctx.p++)))
|
|
1330
|
+
TomlError.x("invalid date-time: date part is malformed", ctx, startPtr);
|
|
1331
|
+
if (ctx.p >= ctx.s.length || ((c = ctx.s.charCodeAt(ctx.p)) !== 32 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 84 && c !== 116) {
|
|
1332
|
+
let t2 = ctx.s.slice(startPtr, ctx.p);
|
|
1333
|
+
return readDate(ctx, t2, 3, false, startPtr);
|
|
1334
|
+
}
|
|
1335
|
+
if (ctx.s.charCodeAt(ctx.p += 3) !== 58)
|
|
1336
|
+
TomlError.x("invalid date-time: time part is malformed", ctx, startPtr);
|
|
1337
|
+
if (ctx.s.charCodeAt(ctx.p += 3) === 58)
|
|
1338
|
+
ctx.p += 3;
|
|
1339
|
+
if (ctx.s.charCodeAt(ctx.p) === 46)
|
|
1340
|
+
while (isDigit(ctx.s.charCodeAt(++ctx.p)))
|
|
1341
|
+
;
|
|
1342
|
+
if (c = ctx.s.charCodeAt(ctx.p)) {
|
|
1343
|
+
if (c === 90 || c === 122) {
|
|
1344
|
+
let t2 = ctx.s.slice(startPtr, ++ctx.p);
|
|
1345
|
+
return readDate(ctx, t2, 1, unsafeSeparator, startPtr, "[+00:00]");
|
|
1346
|
+
}
|
|
1347
|
+
if (c === 43 || c === 45) {
|
|
1348
|
+
let t2 = ctx.s.slice(startPtr, ctx.p += 6);
|
|
1349
|
+
return readDate(ctx, t2, 1, unsafeSeparator, startPtr, !ctx.ld && "[" + ctx.s.slice(ctx.p - 6, ctx.p) + "]");
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
let t = ctx.s.slice(startPtr, ctx.p);
|
|
1353
|
+
return readDate(ctx, t, 2, unsafeSeparator, startPtr);
|
|
1354
|
+
}
|
|
1355
|
+
function parseTime(ctx, c, endChr) {
|
|
1356
|
+
let start = ctx.p;
|
|
1357
|
+
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(++ctx.p))) {
|
|
1358
|
+
return parseNumber(ctx, --ctx.p, c, 0, endChr);
|
|
1359
|
+
}
|
|
1360
|
+
if (ctx.s.charCodeAt(ctx.p += 4) === 58)
|
|
1361
|
+
ctx.p += 3;
|
|
1362
|
+
if (ctx.s.charCodeAt(ctx.p) === 46)
|
|
1363
|
+
while (isDigit(ctx.s.charCodeAt(++ctx.p)))
|
|
1364
|
+
;
|
|
1365
|
+
let t = ctx.s.slice(start, ctx.p);
|
|
1366
|
+
return readDate(ctx, t, 4, false, start);
|
|
1367
|
+
}
|
|
1368
|
+
function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
|
|
1369
|
+
if (ctx.ld) {
|
|
1370
|
+
let date = new TomlDate(str, type, unsafeDelim);
|
|
1371
|
+
if (!date.isValid())
|
|
1372
|
+
TomlError.x("invalid date", ctx, errPtr);
|
|
1373
|
+
return date;
|
|
1374
|
+
}
|
|
1375
|
+
try {
|
|
1376
|
+
if (temporalSuffix)
|
|
1377
|
+
str += temporalSuffix;
|
|
1378
|
+
switch (type) {
|
|
1379
|
+
case 1:
|
|
1380
|
+
return Temporal.ZonedDateTime.from(str);
|
|
1381
|
+
case 2:
|
|
1382
|
+
return Temporal.PlainDateTime.from(str);
|
|
1383
|
+
case 3:
|
|
1384
|
+
return Temporal.PlainDate.from(str);
|
|
1385
|
+
case 4:
|
|
1386
|
+
return Temporal.PlainTime.from(str);
|
|
1387
|
+
}
|
|
1388
|
+
} catch (e) {
|
|
1389
|
+
TomlError.x(e instanceof Error ? e.message : "" + e, ctx, errPtr);
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/util.js
|
|
1394
|
+
function skipComment(ctx) {
|
|
1395
|
+
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
1396
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
1397
|
+
if (c === 10)
|
|
1398
|
+
break;
|
|
1399
|
+
if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
|
|
1400
|
+
ctx.p++;
|
|
1401
|
+
break;
|
|
1402
|
+
}
|
|
1403
|
+
if (c < 32 && c !== 9 || c === 127) {
|
|
1404
|
+
TomlError.x("control characters are not allowed in comments", ctx);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
function skipVoid(ctx, banNewLines, banComments) {
|
|
1409
|
+
let c;
|
|
1410
|
+
while (ctx.p < ctx.s.length) {
|
|
1411
|
+
while (ctx.p < ctx.s.length && ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)))
|
|
1412
|
+
ctx.p++;
|
|
1413
|
+
if (banComments || c !== 35)
|
|
1414
|
+
break;
|
|
1415
|
+
skipComment(ctx);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/struct.js
|
|
1420
|
+
function parseKey(ctx, end = 61) {
|
|
1421
|
+
let startPtr;
|
|
1422
|
+
let state = 0;
|
|
1423
|
+
let parsed = [];
|
|
1424
|
+
let sliceStart;
|
|
1425
|
+
let c = ctx.s.charCodeAt(startPtr = ctx.p);
|
|
1426
|
+
do {
|
|
1427
|
+
if (c === end) {
|
|
1428
|
+
if (!state)
|
|
1429
|
+
TomlError.x("unexpected end of key", ctx);
|
|
1430
|
+
if (state === 1)
|
|
1431
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
1432
|
+
return ctx.p++, parsed;
|
|
1433
|
+
} else if (c === 46) {
|
|
1434
|
+
if (!state)
|
|
1435
|
+
TomlError.x("illegal empty bare key", ctx);
|
|
1436
|
+
if (state === 1)
|
|
1437
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
1438
|
+
state = 0;
|
|
1439
|
+
} else if (!state && (c === 34 || c === 39)) {
|
|
1440
|
+
if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2))
|
|
1441
|
+
TomlError.x("illegal quoted key: multiline strings are not allowed", ctx);
|
|
1442
|
+
parsed.push(parseString(ctx));
|
|
1443
|
+
state = 2;
|
|
1444
|
+
ctx.p--;
|
|
1445
|
+
} else if (c === 32 || c === 9) {
|
|
1446
|
+
if (state === 1) {
|
|
1447
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
1448
|
+
state = 2;
|
|
1449
|
+
}
|
|
1450
|
+
} else if (state === 2 || c < 48 && c !== 45 || c > 57 && c < 65 || c > 90 && c < 97 && c !== 95 || c > 122) {
|
|
1451
|
+
TomlError.x("illegal character in key", ctx);
|
|
1452
|
+
} else if (!state) {
|
|
1453
|
+
state = 1;
|
|
1454
|
+
sliceStart = ctx.p;
|
|
1455
|
+
}
|
|
1456
|
+
} while (c = ctx.s.charCodeAt(++ctx.p));
|
|
1457
|
+
TomlError.x("incomplete key-value: cannot find end of key", ctx, startPtr);
|
|
1458
|
+
}
|
|
1459
|
+
function parseInlineTable(ctx) {
|
|
1460
|
+
let startPtr = ctx.p++;
|
|
1461
|
+
let res = /* @__PURE__ */ Object.create(null);
|
|
1462
|
+
let seen = /* @__PURE__ */ new Set();
|
|
1463
|
+
let c;
|
|
1464
|
+
while (ctx.p < ctx.s.length) {
|
|
1465
|
+
skipVoid(ctx);
|
|
1466
|
+
if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
|
|
1467
|
+
ctx.p++;
|
|
1468
|
+
return res;
|
|
1469
|
+
}
|
|
1470
|
+
let k;
|
|
1471
|
+
let t = res;
|
|
1472
|
+
let hasOwn = false;
|
|
1473
|
+
let errPtr = ctx.p;
|
|
1474
|
+
let key = parseKey(ctx);
|
|
1475
|
+
for (let i = 0; i < key.length; i++) {
|
|
1476
|
+
if (i)
|
|
1477
|
+
t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
|
|
1478
|
+
k = key[i];
|
|
1479
|
+
if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) {
|
|
1480
|
+
TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
1481
|
+
}
|
|
1482
|
+
let unsafe = k === "__proto__";
|
|
1483
|
+
if (ctx.uk && (unsafe || k === "constructor")) {
|
|
1484
|
+
t = ctx.uk !== 1 && TomlError.x("document contains an unsafe property", ctx, errPtr);
|
|
1485
|
+
break;
|
|
1486
|
+
}
|
|
1487
|
+
if (!hasOwn && unsafe) {
|
|
1488
|
+
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
if (hasOwn) {
|
|
1492
|
+
TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
1493
|
+
}
|
|
1494
|
+
skipVoid(ctx, true, true);
|
|
1495
|
+
let value = extractValue(
|
|
1496
|
+
ctx,
|
|
1497
|
+
125
|
|
1498
|
+
/* } */
|
|
1499
|
+
);
|
|
1500
|
+
if (t && typeof (t[k] = value) === "object")
|
|
1501
|
+
seen.add(value);
|
|
1502
|
+
skipVoid(ctx);
|
|
1503
|
+
if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) {
|
|
1504
|
+
return res;
|
|
1505
|
+
}
|
|
1506
|
+
if (c !== 44)
|
|
1507
|
+
TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
1508
|
+
}
|
|
1509
|
+
TomlError.x("unfinished table", ctx, startPtr);
|
|
1510
|
+
}
|
|
1511
|
+
function parseArray(ctx) {
|
|
1512
|
+
let startPtr = ctx.p++;
|
|
1513
|
+
let res = [];
|
|
1514
|
+
let c;
|
|
1515
|
+
while (ctx.p < ctx.s.length) {
|
|
1516
|
+
skipVoid(ctx);
|
|
1517
|
+
if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
|
|
1518
|
+
ctx.p++;
|
|
1519
|
+
return res;
|
|
1520
|
+
}
|
|
1521
|
+
res.push(extractValue(
|
|
1522
|
+
ctx,
|
|
1523
|
+
93
|
|
1524
|
+
/* ] */
|
|
1525
|
+
));
|
|
1526
|
+
skipVoid(ctx);
|
|
1527
|
+
if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) {
|
|
1528
|
+
return res;
|
|
1529
|
+
}
|
|
1530
|
+
if (c !== 44)
|
|
1531
|
+
TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
1532
|
+
}
|
|
1533
|
+
TomlError.x("unfinished array", ctx, startPtr);
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/parse.js
|
|
1537
|
+
function peekTable(ctx, key, table, meta, type) {
|
|
1538
|
+
let t = table;
|
|
1539
|
+
let m = meta;
|
|
1540
|
+
let k;
|
|
1541
|
+
let hasOwn = false;
|
|
1542
|
+
let state;
|
|
1543
|
+
for (let i = 0; i < key.length; i++) {
|
|
1544
|
+
if (i) {
|
|
1545
|
+
t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
|
|
1546
|
+
m = (state = m[k]).c;
|
|
1547
|
+
if (type === 0 && (state.t === 1 || state.t === 2)) {
|
|
1548
|
+
return null;
|
|
1549
|
+
}
|
|
1550
|
+
if (state.t === 2) {
|
|
1551
|
+
let l = t.length - 1;
|
|
1552
|
+
t = t[l];
|
|
1553
|
+
m = m[l].c;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
k = key[i];
|
|
1557
|
+
if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) {
|
|
1558
|
+
return null;
|
|
1559
|
+
}
|
|
1560
|
+
if (!hasOwn) {
|
|
1561
|
+
let unsafe = k === "__proto__";
|
|
1562
|
+
if (ctx.uk && (unsafe || k === "constructor"))
|
|
1563
|
+
return false;
|
|
1564
|
+
if (unsafe) {
|
|
1565
|
+
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
|
|
1566
|
+
Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
|
|
1567
|
+
}
|
|
1568
|
+
m[k] = {
|
|
1569
|
+
t: i < key.length - 1 && type === 2 ? 3 : type,
|
|
1570
|
+
d: false,
|
|
1571
|
+
i: 0,
|
|
1572
|
+
c: /* @__PURE__ */ Object.create(null)
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
state = m[k];
|
|
1577
|
+
if (state.t !== type && !(type === 1 && state.t === 3)) {
|
|
1578
|
+
return null;
|
|
1579
|
+
}
|
|
1580
|
+
if (type === 2) {
|
|
1581
|
+
if (!state.d) {
|
|
1582
|
+
state.d = true;
|
|
1583
|
+
t[k] = [];
|
|
1584
|
+
}
|
|
1585
|
+
t[k].push(t = /* @__PURE__ */ Object.create(null));
|
|
1586
|
+
state.c[state.i++] = state = { t: 1, d: false, i: 0, c: /* @__PURE__ */ Object.create(null) };
|
|
1587
|
+
}
|
|
1588
|
+
if (state.d) {
|
|
1589
|
+
return null;
|
|
1590
|
+
}
|
|
1591
|
+
state.d = true;
|
|
1592
|
+
if (type === 1) {
|
|
1593
|
+
t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
|
|
1594
|
+
} else if (type === 0 && hasOwn) {
|
|
1595
|
+
return null;
|
|
1596
|
+
}
|
|
1597
|
+
return [k, t, state.c];
|
|
1598
|
+
}
|
|
1599
|
+
function validateTablePeek(ctx, peek, ptr) {
|
|
1600
|
+
if (peek === null || ctx.uk === 2)
|
|
1601
|
+
TomlError.x(peek === null ? "trying to redefine an already defined table or value" : "document contains an unsafe property", ctx, ptr);
|
|
1602
|
+
}
|
|
1603
|
+
function parse(toml, options = {}) {
|
|
1604
|
+
let ctx = {
|
|
1605
|
+
s: toml,
|
|
1606
|
+
p: 0,
|
|
1607
|
+
d: options.maxDepth ?? 1e3,
|
|
1608
|
+
bi: options.integersAsBigInt ?? false,
|
|
1609
|
+
ld: options.useLegacyDate ?? true,
|
|
1610
|
+
uk: options.unsafeKeyBehaviour === "throw" ? 2 : options.unsafeKeyBehaviour === "drop" ? 1 : 0
|
|
1611
|
+
};
|
|
1612
|
+
let res = /* @__PURE__ */ Object.create(null);
|
|
1613
|
+
let meta = /* @__PURE__ */ Object.create(null);
|
|
1614
|
+
let tmp;
|
|
1615
|
+
let skipping = false;
|
|
1616
|
+
let tbl = res;
|
|
1617
|
+
let m = meta;
|
|
1618
|
+
if (toml.charCodeAt(0) === 65279)
|
|
1619
|
+
ctx.p++;
|
|
1620
|
+
skipVoid(ctx);
|
|
1621
|
+
while (ctx.p < toml.length) {
|
|
1622
|
+
if (toml.charCodeAt(ctx.p) === 91) {
|
|
1623
|
+
let isTableArray = toml.charCodeAt(++ctx.p) === 91;
|
|
1624
|
+
tmp = ctx.p += +isTableArray;
|
|
1625
|
+
skipping = false;
|
|
1626
|
+
let k = parseKey(
|
|
1627
|
+
ctx,
|
|
1628
|
+
93
|
|
1629
|
+
/* ] */
|
|
1630
|
+
);
|
|
1631
|
+
if (isTableArray) {
|
|
1632
|
+
if (toml.charCodeAt(ctx.p) !== 93) {
|
|
1633
|
+
TomlError.x("expected end of table array declaration", ctx);
|
|
1634
|
+
}
|
|
1635
|
+
ctx.p++;
|
|
1636
|
+
}
|
|
1637
|
+
let p = peekTable(
|
|
1638
|
+
ctx,
|
|
1639
|
+
k,
|
|
1640
|
+
res,
|
|
1641
|
+
meta,
|
|
1642
|
+
isTableArray ? 2 : 1
|
|
1643
|
+
/* Type.EXPLICIT */
|
|
1644
|
+
);
|
|
1645
|
+
if (!p) {
|
|
1646
|
+
validateTablePeek(ctx, p, tmp);
|
|
1647
|
+
skipping = true;
|
|
1648
|
+
} else {
|
|
1649
|
+
m = p[2];
|
|
1650
|
+
tbl = p[1];
|
|
1651
|
+
}
|
|
1652
|
+
} else {
|
|
1653
|
+
tmp = ctx.p;
|
|
1654
|
+
let k = parseKey(ctx);
|
|
1655
|
+
let p = peekTable(
|
|
1656
|
+
ctx,
|
|
1657
|
+
k,
|
|
1658
|
+
tbl,
|
|
1659
|
+
m,
|
|
1660
|
+
0
|
|
1661
|
+
/* Type.DOTTED */
|
|
1662
|
+
);
|
|
1663
|
+
if (!p && !skipping)
|
|
1664
|
+
validateTablePeek(ctx, p, tmp);
|
|
1665
|
+
skipVoid(ctx, true, true);
|
|
1666
|
+
let v = extractValue(ctx, void 0);
|
|
1667
|
+
if (p && !skipping)
|
|
1668
|
+
p[1][p[0]] = v;
|
|
1669
|
+
}
|
|
1670
|
+
skipVoid(ctx, true);
|
|
1671
|
+
if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && (tmp !== 13 || toml.charCodeAt(ctx.p + 1) !== 10)) {
|
|
1672
|
+
TomlError.x("each key-value declaration must be followed by an end-of-line", ctx);
|
|
1673
|
+
}
|
|
1674
|
+
skipVoid(ctx);
|
|
1675
|
+
}
|
|
1676
|
+
return res;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/stringify.js
|
|
1680
|
+
var HAS_WELLFORMED = !!"".isWellFormed;
|
|
1681
|
+
|
|
1682
|
+
// packages/detectors/dist/python.js
|
|
1683
|
+
var DOC_TOOLS = /^(sphinx|mkdocs|alabaster|furo|myst-parser|pydata-sphinx-theme|docutils|recommonmark)/;
|
|
1684
|
+
function normalizePyName(spec) {
|
|
1685
|
+
const m = spec.trim().match(/^([A-Za-z0-9][A-Za-z0-9._-]*)/);
|
|
1686
|
+
return m ? m[1].toLowerCase().replace(/[._]/g, "-") : null;
|
|
1687
|
+
}
|
|
1688
|
+
function requirementsDeps(text2) {
|
|
1689
|
+
const out = [];
|
|
1690
|
+
for (const raw of text2.split(/\r?\n/)) {
|
|
1691
|
+
const line = raw.replace(/#.*/, "").trim();
|
|
1692
|
+
if (!line || line.startsWith("-"))
|
|
1693
|
+
continue;
|
|
1694
|
+
const n = normalizePyName(line);
|
|
1695
|
+
if (n)
|
|
1696
|
+
out.push(n);
|
|
1697
|
+
}
|
|
1698
|
+
return out;
|
|
1699
|
+
}
|
|
1700
|
+
function pythonManifests(files) {
|
|
1701
|
+
return files.list().filter((f) => /^(requirements[^/]*\.txt|requirements\/[^/]+\.txt|pyproject\.toml|Pipfile)$/.test(f));
|
|
1702
|
+
}
|
|
1703
|
+
function detectPython(files, fallbackName, inheritedLock) {
|
|
1704
|
+
const manifests = pythonManifests(files);
|
|
1705
|
+
if (manifests.length === 0)
|
|
1706
|
+
return null;
|
|
1707
|
+
const warnings = [];
|
|
1708
|
+
const deps = /* @__PURE__ */ new Map();
|
|
1709
|
+
let name;
|
|
1710
|
+
let requiresPython;
|
|
1711
|
+
for (const m of manifests) {
|
|
1712
|
+
const text2 = files.read(m) ?? "";
|
|
1713
|
+
if (m.endsWith(".txt")) {
|
|
1714
|
+
for (const d of requirementsDeps(text2))
|
|
1715
|
+
if (!deps.has(d))
|
|
1716
|
+
deps.set(d, m);
|
|
1717
|
+
continue;
|
|
1718
|
+
}
|
|
1719
|
+
let toml;
|
|
1720
|
+
try {
|
|
1721
|
+
toml = parse(text2);
|
|
1722
|
+
} catch {
|
|
1723
|
+
warnings.push(`could not parse ${m}`);
|
|
1724
|
+
continue;
|
|
1725
|
+
}
|
|
1726
|
+
if (m === "Pipfile") {
|
|
1727
|
+
for (const d of Object.keys(toml.packages ?? {})) {
|
|
1728
|
+
const n = normalizePyName(d);
|
|
1729
|
+
if (n && !deps.has(n))
|
|
1730
|
+
deps.set(n, m);
|
|
1731
|
+
}
|
|
1732
|
+
continue;
|
|
1733
|
+
}
|
|
1734
|
+
name ??= toml.project?.name ?? toml.tool?.poetry?.name;
|
|
1735
|
+
requiresPython ??= toml.project?.["requires-python"];
|
|
1736
|
+
for (const spec of toml.project?.dependencies ?? []) {
|
|
1737
|
+
const n = normalizePyName(spec);
|
|
1738
|
+
if (n && !deps.has(n))
|
|
1739
|
+
deps.set(n, m);
|
|
1740
|
+
}
|
|
1741
|
+
for (const d of Object.keys(toml.tool?.poetry?.dependencies ?? {})) {
|
|
1742
|
+
if (d === "python") {
|
|
1743
|
+
const v = toml.tool.poetry.dependencies[d];
|
|
1744
|
+
if (typeof v === "string")
|
|
1745
|
+
requiresPython ??= v;
|
|
1746
|
+
continue;
|
|
1747
|
+
}
|
|
1748
|
+
const n = normalizePyName(d);
|
|
1749
|
+
if (n && !deps.has(n))
|
|
1750
|
+
deps.set(n, m);
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
const fw = PY_FRAMEWORKS.find((f) => deps.has(f.pkg));
|
|
1754
|
+
if (!fw && deps.size > 0 && [...deps.keys()].every((d) => DOC_TOOLS.test(d)))
|
|
1755
|
+
return null;
|
|
1756
|
+
let kind;
|
|
1757
|
+
if (fw)
|
|
1758
|
+
kind = fw.kind;
|
|
1759
|
+
else if (deps.has("celery") || deps.has("rq"))
|
|
1760
|
+
kind = "worker";
|
|
1761
|
+
else {
|
|
1762
|
+
kind = "api";
|
|
1763
|
+
warnings.push("no known Python web framework; assuming an HTTP service");
|
|
1764
|
+
}
|
|
1765
|
+
const versionFile = files.read(".python-version")?.trim();
|
|
1766
|
+
const version = versionFile || requiresPython?.match(/(\d+\.\d+)/)?.[1];
|
|
1767
|
+
const runtime = {
|
|
1768
|
+
language: "python",
|
|
1769
|
+
source: "detector",
|
|
1770
|
+
...version ? { version } : {},
|
|
1771
|
+
...fw ? { framework: fw.name } : {}
|
|
1772
|
+
};
|
|
1773
|
+
const services = new ServiceSet();
|
|
1774
|
+
for (const [d, file] of deps)
|
|
1775
|
+
for (const hit of PY_SERVICES[d] ?? [])
|
|
1776
|
+
services.add(hit, `${file}: ${d}`);
|
|
1777
|
+
const lock = firstExisting(files, ["uv.lock", "poetry.lock", "Pipfile.lock"]) ?? inheritedLock;
|
|
1778
|
+
const pm = lock === "uv.lock" ? "uv" : lock === "poetry.lock" ? "poetry" : lock === "Pipfile.lock" ? "pipenv" : manifests.includes("Pipfile") ? "pipenv" : "pip";
|
|
1779
|
+
const port = dockerPort(files) ?? (kind === "worker" ? void 0 : fw?.port);
|
|
1780
|
+
const start = procfileWeb(files);
|
|
1781
|
+
const build = {
|
|
1782
|
+
packageManager: pm,
|
|
1783
|
+
...start ? { startCommand: start } : {},
|
|
1784
|
+
...files.list().includes("Dockerfile") ? { dockerfile: true } : {},
|
|
1785
|
+
...port ? { port } : {}
|
|
1786
|
+
};
|
|
1787
|
+
return {
|
|
1788
|
+
profile: {
|
|
1789
|
+
app: { name: name ?? fallbackName, kind },
|
|
1790
|
+
runtimes: [runtime],
|
|
1791
|
+
services: services.values(),
|
|
1792
|
+
build
|
|
1793
|
+
},
|
|
1794
|
+
warnings
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
// packages/detectors/dist/dotnet.js
|
|
1799
|
+
import path3 from "node:path";
|
|
1800
|
+
var PROJECT_FILE = /\.(cs|fs)proj$/;
|
|
1801
|
+
function properties(xml) {
|
|
1802
|
+
const props = /* @__PURE__ */ new Map();
|
|
1803
|
+
for (const group of xml.matchAll(/<PropertyGroup[^>]*>([\s\S]*?)<\/PropertyGroup>/g)) {
|
|
1804
|
+
for (const m of group[1].matchAll(/<([A-Za-z][\w.]*)\s*>([^<]*)<\/\1>/g)) {
|
|
1805
|
+
if (!props.has(m[1]))
|
|
1806
|
+
props.set(m[1], m[2].trim());
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
return props;
|
|
1810
|
+
}
|
|
1811
|
+
function resolveRel(dir, include) {
|
|
1812
|
+
return path3.posix.normalize(path3.posix.join(dir, include.replace(/\\/g, "/"))).replace(/^\.\//, "");
|
|
1813
|
+
}
|
|
1814
|
+
function inheritedProps(files, dir) {
|
|
1815
|
+
const out = /* @__PURE__ */ new Map();
|
|
1816
|
+
let d = dir;
|
|
1817
|
+
for (; ; ) {
|
|
1818
|
+
for (const name of ["Directory.Build.props", "Directory.Packages.props"]) {
|
|
1819
|
+
const xml = files.read(d ? `${d}/${name}` : name);
|
|
1820
|
+
if (xml) {
|
|
1821
|
+
for (const [k, v] of properties(xml))
|
|
1822
|
+
if (!out.has(k))
|
|
1823
|
+
out.set(k, v);
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
if (!d)
|
|
1827
|
+
break;
|
|
1828
|
+
d = d.includes("/") ? d.slice(0, d.lastIndexOf("/")) : "";
|
|
1829
|
+
}
|
|
1830
|
+
return out;
|
|
1831
|
+
}
|
|
1832
|
+
function parseProject(files, file) {
|
|
1833
|
+
const xml = files.read(file);
|
|
1834
|
+
if (!xml)
|
|
1835
|
+
return null;
|
|
1836
|
+
const dir = file.includes("/") ? file.slice(0, file.lastIndexOf("/")) : "";
|
|
1837
|
+
const sdks = [
|
|
1838
|
+
...[...xml.matchAll(/<Project\b[^>]*\bSdk="([^"]+)"/g)].map((m) => m[1]),
|
|
1839
|
+
...[...xml.matchAll(/<(?:Sdk|Import)\b[^>]*\b(?:Name|Sdk)="([^"]+)"/g)].map((m) => m[1])
|
|
1840
|
+
].map((s) => s.split("/")[0].trim());
|
|
1841
|
+
const packages = [...xml.matchAll(/<PackageReference\b[^>]*?\bInclude="([^"]+)"/g)].map((m) => m[1].toLowerCase());
|
|
1842
|
+
const references = [...xml.matchAll(/<ProjectReference\b[^>]*?\bInclude="([^"]+)"/g)].map((m) => resolveRel(dir, m[1]));
|
|
1843
|
+
const props = properties(xml);
|
|
1844
|
+
for (const [k, v] of inheritedProps(files, dir))
|
|
1845
|
+
if (!props.has(k))
|
|
1846
|
+
props.set(k, v);
|
|
1847
|
+
return {
|
|
1848
|
+
file,
|
|
1849
|
+
dir,
|
|
1850
|
+
language: file.endsWith(".fsproj") ? "fsharp" : "csharp",
|
|
1851
|
+
sdks,
|
|
1852
|
+
packages,
|
|
1853
|
+
references,
|
|
1854
|
+
props
|
|
1855
|
+
};
|
|
1856
|
+
}
|
|
1857
|
+
function dotnetVersion(p) {
|
|
1858
|
+
const tfs = (p.props.get("TargetFramework") ?? p.props.get("TargetFrameworks") ?? "").split(";").map((t) => t.trim().match(/^net(?:coreapp)?(\d+\.\d+)/)?.[1]).filter((v) => Boolean(v));
|
|
1859
|
+
return tfs.sort((a, b) => Number(b.split(".")[0]) - Number(a.split(".")[0]))[0];
|
|
1860
|
+
}
|
|
1861
|
+
var isTrue = (v) => v?.toLowerCase() === "true";
|
|
1862
|
+
var hasPkg = (p, ...names) => names.some((n) => p.packages.includes(n));
|
|
1863
|
+
var hasPkgPrefix = (p, prefix) => p.packages.some((n) => n.startsWith(prefix));
|
|
1864
|
+
function projectSources(files, dir, exts) {
|
|
1865
|
+
return subdir(files, dir).list().filter((f) => exts.test(f)).map((f) => dir ? `${dir}/${f}` : f);
|
|
1866
|
+
}
|
|
1867
|
+
function sourceText(files, p) {
|
|
1868
|
+
return projectSources(files, p.dir, /\.(cs|fs)$/).map((f) => files.read(f) ?? "").join("\n");
|
|
1869
|
+
}
|
|
1870
|
+
function classify(files, p) {
|
|
1871
|
+
const sdk = (name) => p.sdks.some((s) => s.toLowerCase() === name.toLowerCase());
|
|
1872
|
+
const tf = `${p.props.get("TargetFramework") ?? ""};${p.props.get("TargetFrameworks") ?? ""}`;
|
|
1873
|
+
const outputExe = /^(Exe|WinExe)$/i.test(p.props.get("OutputType") ?? "");
|
|
1874
|
+
if (isTrue(p.props.get("IsTestProject")) || sdk("MSTest.Sdk") || p.packages.some((n) => /^(microsoft\.net\.test\.sdk|xunit|nunit|mstest\.testframework|tunit)/.test(n)))
|
|
1875
|
+
return { deployable: false, reason: "test project" };
|
|
1876
|
+
if (sdk("Aspire.AppHost.Sdk") || hasPkg(p, "aspire.hosting.apphost") || isTrue(p.props.get("IsAspireHost")))
|
|
1877
|
+
return { deployable: false, reason: "Aspire AppHost (local orchestration)" };
|
|
1878
|
+
if (isTrue(p.props.get("UseMaui")) || isTrue(p.props.get("UseWPF")) || isTrue(p.props.get("UseWindowsForms")) || /-(android|ios|maccatalyst|windows|tvos)/.test(tf) || sdk("Microsoft.NET.Sdk.WindowsDesktop"))
|
|
1879
|
+
return { deployable: false, reason: "desktop or mobile app" };
|
|
1880
|
+
if (sdk("Microsoft.NET.Sdk.BlazorWebAssembly"))
|
|
1881
|
+
return { deployable: true, framework: "blazor-wasm", kind: "static" };
|
|
1882
|
+
if (sdk("Microsoft.NET.Sdk.Functions") || hasPkg(p, "microsoft.azure.functions.worker", "microsoft.azure.webjobs")) {
|
|
1883
|
+
const http = /\bHttpTrigger\b/.test(sourceText(files, p));
|
|
1884
|
+
return { deployable: true, framework: "azure-functions", kind: http ? "api" : "worker" };
|
|
1885
|
+
}
|
|
1886
|
+
if (sdk("Microsoft.NET.Sdk.Web")) {
|
|
1887
|
+
const fw = DOTNET_FRAMEWORK_PACKAGES.find((f) => hasPkg(p, f.pkg));
|
|
1888
|
+
if (fw)
|
|
1889
|
+
return { deployable: true, framework: fw.name, kind: "api" };
|
|
1890
|
+
const src = sourceText(files, p);
|
|
1891
|
+
if (/\b(AddRazorComponents|AddServerSideBlazor|MapBlazorHub)\s*\(/.test(src))
|
|
1892
|
+
return { deployable: true, framework: "blazor", kind: "web" };
|
|
1893
|
+
const views = projectSources(files, p.dir, /(^|\/)(Views|Pages)\/.+\.cshtml$/).length > 0;
|
|
1894
|
+
if (views || /\b(AddControllersWithViews|AddRazorPages|AddMvc|MapRazorPages|MapControllerRoute)\s*\(/.test(src))
|
|
1895
|
+
return { deployable: true, framework: "aspnetcore", kind: "web" };
|
|
1896
|
+
return { deployable: true, framework: "aspnetcore", kind: "api" };
|
|
1897
|
+
}
|
|
1898
|
+
if (hasPkg(p, "amazon.lambda.core", "amazon.lambda.runtimesupport"))
|
|
1899
|
+
return { deployable: true, framework: "aws-lambda", kind: "api" };
|
|
1900
|
+
if (sdk("Microsoft.NET.Sdk.Worker"))
|
|
1901
|
+
return { deployable: true, framework: "dotnet-worker", kind: "worker" };
|
|
1902
|
+
if (outputExe && (hasPkg(p, "microsoft.extensions.hosting") || hasPkgPrefix(p, "microsoft.extensions.hosting.")))
|
|
1903
|
+
return { deployable: true, framework: "dotnet-worker", kind: "worker" };
|
|
1904
|
+
if (outputExe)
|
|
1905
|
+
return { deployable: true, kind: "worker" };
|
|
1906
|
+
return { deployable: false };
|
|
1907
|
+
}
|
|
1908
|
+
function closure(byFile, root) {
|
|
1909
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1910
|
+
const out = [];
|
|
1911
|
+
const stack = [root.file];
|
|
1912
|
+
while (stack.length) {
|
|
1913
|
+
const f = stack.pop();
|
|
1914
|
+
if (seen.has(f))
|
|
1915
|
+
continue;
|
|
1916
|
+
seen.add(f);
|
|
1917
|
+
const p = byFile.get(f);
|
|
1918
|
+
if (!p)
|
|
1919
|
+
continue;
|
|
1920
|
+
out.push(p);
|
|
1921
|
+
stack.push(...p.references);
|
|
1922
|
+
}
|
|
1923
|
+
return out;
|
|
1924
|
+
}
|
|
1925
|
+
function parseJsonc(text2) {
|
|
1926
|
+
let out = "";
|
|
1927
|
+
let inStr = false;
|
|
1928
|
+
for (let i = 0; i < text2.length; i++) {
|
|
1929
|
+
const c = text2[i];
|
|
1930
|
+
if (inStr) {
|
|
1931
|
+
out += c;
|
|
1932
|
+
if (c === "\\")
|
|
1933
|
+
out += text2[++i] ?? "";
|
|
1934
|
+
else if (c === '"')
|
|
1935
|
+
inStr = false;
|
|
1936
|
+
} else if (c === '"') {
|
|
1937
|
+
inStr = true;
|
|
1938
|
+
out += c;
|
|
1939
|
+
} else if (c === "/" && text2[i + 1] === "/") {
|
|
1940
|
+
while (i < text2.length && text2[i] !== "\n")
|
|
1941
|
+
i++;
|
|
1942
|
+
out += "\n";
|
|
1943
|
+
} else if (c === "/" && text2[i + 1] === "*") {
|
|
1944
|
+
i = text2.indexOf("*/", i + 2);
|
|
1945
|
+
if (i < 0)
|
|
1946
|
+
break;
|
|
1947
|
+
i++;
|
|
1948
|
+
} else
|
|
1949
|
+
out += c;
|
|
1950
|
+
}
|
|
1951
|
+
return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
|
|
1952
|
+
}
|
|
1953
|
+
var ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
1954
|
+
var DOTNET_RUNTIME_ENV = /^(ASPNETCORE_|DOTNET_|AzureWebJobs|FUNCTIONS_|WEBSITE_|APPLICATIONINSIGHTS_CONNECTION_STRING$|GITHUB_|(APPDATA|LOCALAPPDATA|USERPROFILE|COMPUTERNAME|USERNAME|TEMP|TMP)$)/;
|
|
1955
|
+
var IGNORED_SECTIONS = /* @__PURE__ */ new Set(["Logging", "AllowedHosts", "Kestrel", "Serilog", "DetailedErrors"]);
|
|
1956
|
+
var configToEnv = (key) => key.replace(/:/g, "__");
|
|
1957
|
+
function dotnetSecret(name) {
|
|
1958
|
+
return /^ConnectionStrings__/i.test(name) || isSecretName(name.toUpperCase().replace(/__/g, "_"));
|
|
1959
|
+
}
|
|
1960
|
+
function walkSettings(node, prefix, add) {
|
|
1961
|
+
if (!node || typeof node !== "object" || Array.isArray(node))
|
|
1962
|
+
return;
|
|
1963
|
+
for (const [k, v] of Object.entries(node)) {
|
|
1964
|
+
if (!prefix && IGNORED_SECTIONS.has(k))
|
|
1965
|
+
continue;
|
|
1966
|
+
const name = prefix ? `${prefix}__${k}` : k;
|
|
1967
|
+
if (v && typeof v === "object")
|
|
1968
|
+
walkSettings(v, name, add);
|
|
1969
|
+
else if (typeof v === "string" || v === null)
|
|
1970
|
+
add(name);
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
var CODE_PATTERNS2 = [
|
|
1974
|
+
[/Environment\.GetEnvironmentVariable\s*\(?\s*"([^"]+)"/g, (m) => m],
|
|
1975
|
+
[/\bGetConnectionString\s*\(?\s*"([^"]+)"/g, (m) => `ConnectionStrings__${m}`],
|
|
1976
|
+
[/\b(?:[Cc]onfiguration|[Cc]onfig|_config(?:uration)?)\s*\[\s*"([^"]+)"\s*\]/g, configToEnv],
|
|
1977
|
+
[/\bGetValue<[^>]+>\s*\(\s*"([^"]+)"/g, configToEnv],
|
|
1978
|
+
// .NET Aspire client integrations read ConnectionStrings__<name>.
|
|
1979
|
+
[
|
|
1980
|
+
/\.Add(?:Npgsql|SqlServer|Redis|MongoDB|RabbitMQ|MySql|Kafka|Azure\w+?|Qdrant|Milvus)\w*(?:<[^>()]*>)?\(\s*(?:connectionName:\s*)?"([^"]+)"/g,
|
|
1981
|
+
(m) => `ConnectionStrings__${m}`
|
|
1982
|
+
]
|
|
1983
|
+
];
|
|
1984
|
+
function detectDotnetEnv(files, projects) {
|
|
1985
|
+
const byLower = /* @__PURE__ */ new Map();
|
|
1986
|
+
const add = (n) => {
|
|
1987
|
+
if (ENV_NAME.test(n) && !DOTNET_RUNTIME_ENV.test(n) && !byLower.has(n.toLowerCase()))
|
|
1988
|
+
byLower.set(n.toLowerCase(), n);
|
|
1989
|
+
};
|
|
1990
|
+
for (const p of projects) {
|
|
1991
|
+
const view = subdir(files, p.dir);
|
|
1992
|
+
for (const f of view.list()) {
|
|
1993
|
+
const full = p.dir ? `${p.dir}/${f}` : f;
|
|
1994
|
+
if (/^appsettings(\.[\w-]+)?\.json$/.test(f) || f === "local.settings.json") {
|
|
1995
|
+
let json;
|
|
1996
|
+
try {
|
|
1997
|
+
json = parseJsonc(files.read(full) ?? "");
|
|
1998
|
+
} catch {
|
|
1999
|
+
continue;
|
|
2000
|
+
}
|
|
2001
|
+
if (f === "local.settings.json") {
|
|
2002
|
+
const values = json ?? {};
|
|
2003
|
+
for (const k of Object.keys(values.Values ?? {}))
|
|
2004
|
+
add(configToEnv(k));
|
|
2005
|
+
walkSettings({ ConnectionStrings: values.ConnectionStrings }, "", (n) => add(n));
|
|
2006
|
+
} else {
|
|
2007
|
+
walkSettings(json, "", (n) => {
|
|
2008
|
+
if (dotnetSecret(n))
|
|
2009
|
+
add(n);
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
} else if (/\.(cs|fs)$/.test(f) && !/(^|\/)(bin|obj)\//.test(f)) {
|
|
2013
|
+
const src = files.read(full);
|
|
2014
|
+
if (!src)
|
|
2015
|
+
continue;
|
|
2016
|
+
for (const [re, map] of CODE_PATTERNS2)
|
|
2017
|
+
for (const m of src.matchAll(re))
|
|
2018
|
+
add(map(m[1]));
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
return [...byLower.values()].sort().map((name) => ({ name, secret: dotnetSecret(name) }));
|
|
2023
|
+
}
|
|
2024
|
+
function dotnetProjectFiles(files) {
|
|
2025
|
+
return files.list().filter((f) => PROJECT_FILE.test(f) && !/(^|\/)(bin|obj)\//.test(f));
|
|
2026
|
+
}
|
|
2027
|
+
function detectDotnet(files) {
|
|
2028
|
+
const warnings = [];
|
|
2029
|
+
const projects = dotnetProjectFiles(files).map((f) => parseProject(files, f)).filter((p) => p !== null);
|
|
2030
|
+
if (projects.length === 0)
|
|
2031
|
+
return { apps: [], warnings };
|
|
2032
|
+
const byFile = new Map(projects.map((p) => [p.file, p]));
|
|
2033
|
+
const roles = new Map(projects.map((p) => [p.file, classify(files, p)]));
|
|
2034
|
+
const hostedClients = /* @__PURE__ */ new Set();
|
|
2035
|
+
for (const p of projects) {
|
|
2036
|
+
const role = roles.get(p.file);
|
|
2037
|
+
if (!role.deployable || role.kind === "static")
|
|
2038
|
+
continue;
|
|
2039
|
+
for (const r of p.references) {
|
|
2040
|
+
const rr = roles.get(r);
|
|
2041
|
+
if (rr?.deployable && rr.framework === "blazor-wasm")
|
|
2042
|
+
hostedClients.add(r);
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
const apps = [];
|
|
2046
|
+
const usedDirs = /* @__PURE__ */ new Set();
|
|
2047
|
+
for (const p of projects) {
|
|
2048
|
+
const role = roles.get(p.file);
|
|
2049
|
+
if (!role.deployable) {
|
|
2050
|
+
if (role.reason && role.reason !== "test project")
|
|
2051
|
+
warnings.push(`${p.file}: skipped (${role.reason})`);
|
|
2052
|
+
continue;
|
|
2053
|
+
}
|
|
2054
|
+
if (hostedClients.has(p.file) || usedDirs.has(p.dir))
|
|
2055
|
+
continue;
|
|
2056
|
+
usedDirs.add(p.dir);
|
|
2057
|
+
let { kind, framework } = role;
|
|
2058
|
+
if (p.references.some((r) => hostedClients.has(r))) {
|
|
2059
|
+
framework = "blazor";
|
|
2060
|
+
kind = "web";
|
|
2061
|
+
}
|
|
2062
|
+
const all = closure(byFile, p);
|
|
2063
|
+
const services = new ServiceSet();
|
|
2064
|
+
for (const q of all)
|
|
2065
|
+
for (const pkg of q.packages)
|
|
2066
|
+
for (const hit of NUGET_SERVICES[pkg] ?? [])
|
|
2067
|
+
services.add(hit, `${q.file}: ${pkg}`);
|
|
2068
|
+
const embeddedDirs = [];
|
|
2069
|
+
const spaRoot = p.props.get("SpaRoot");
|
|
2070
|
+
if (spaRoot)
|
|
2071
|
+
embeddedDirs.push(resolveRel(p.dir, spaRoot).replace(/\/$/, ""));
|
|
2072
|
+
const xml = files.read(p.file) ?? "";
|
|
2073
|
+
for (const m of xml.matchAll(/<ProjectReference\b[^>]*?\bInclude="([^"]+\.esproj)"/g)) {
|
|
2074
|
+
const ref = resolveRel(p.dir, m[1]);
|
|
2075
|
+
embeddedDirs.push(ref.includes("/") ? ref.slice(0, ref.lastIndexOf("/")) : "");
|
|
2076
|
+
}
|
|
2077
|
+
if (embeddedDirs.length > 0 && kind !== "static" && kind !== "worker")
|
|
2078
|
+
kind = "fullstack";
|
|
2079
|
+
const version = dotnetVersion(p);
|
|
2080
|
+
const runtime = {
|
|
2081
|
+
language: p.language,
|
|
2082
|
+
source: "detector",
|
|
2083
|
+
...version ? { version } : {},
|
|
2084
|
+
...framework ? { framework } : {}
|
|
2085
|
+
};
|
|
2086
|
+
const view = subdir(files, p.dir);
|
|
2087
|
+
const major = Number(version?.split(".")[0] ?? 8);
|
|
2088
|
+
const serves = kind === "api" || kind === "web" || kind === "fullstack";
|
|
2089
|
+
const port = dockerPort(view) ?? (serves && framework !== "azure-functions" && framework !== "aws-lambda" ? major >= 8 ? 8080 : 80 : void 0);
|
|
2090
|
+
const assembly = p.props.get("AssemblyName") ?? path3.posix.basename(p.file).replace(PROJECT_FILE, "");
|
|
2091
|
+
const build = {
|
|
2092
|
+
packageManager: "nuget",
|
|
2093
|
+
buildCommand: `dotnet publish ${path3.posix.basename(p.file)} -c Release`,
|
|
2094
|
+
...kind === "static" || framework === "azure-functions" || framework === "aws-lambda" ? {} : { startCommand: `dotnet ${assembly}.dll` },
|
|
2095
|
+
...view.list().includes("Dockerfile") ? { dockerfile: true } : {},
|
|
2096
|
+
...port ? { port } : {}
|
|
2097
|
+
};
|
|
2098
|
+
const appWarnings = [];
|
|
2099
|
+
if (!framework)
|
|
2100
|
+
appWarnings.push(`${p.file}: console app; assuming a background process`);
|
|
2101
|
+
apps.push({
|
|
2102
|
+
path: p.dir,
|
|
2103
|
+
profile: {
|
|
2104
|
+
app: { name: assembly, kind },
|
|
2105
|
+
runtimes: [runtime],
|
|
2106
|
+
services: services.values(),
|
|
2107
|
+
build,
|
|
2108
|
+
env: detectDotnetEnv(files, all)
|
|
2109
|
+
},
|
|
2110
|
+
warnings: appWarnings,
|
|
2111
|
+
embeddedDirs
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
return { apps, warnings };
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
// packages/detectors/dist/analyze.js
|
|
2118
|
+
function hasManifest(files, dir) {
|
|
2119
|
+
const view = subdir(files, dir);
|
|
2120
|
+
return view.list().includes("package.json") || pythonManifests(view).length > 0;
|
|
2121
|
+
}
|
|
2122
|
+
function workspaceGlobs(files) {
|
|
2123
|
+
const globs = [];
|
|
2124
|
+
const pnpm = files.read("pnpm-workspace.yaml");
|
|
2125
|
+
if (pnpm)
|
|
2126
|
+
for (const m of pnpm.matchAll(/^\s*-\s*['"]?([^'"\s#]+)['"]?/gm))
|
|
2127
|
+
globs.push(m[1]);
|
|
2128
|
+
const ws = readPackageJson(files)?.workspaces;
|
|
2129
|
+
if (Array.isArray(ws))
|
|
2130
|
+
globs.push(...ws);
|
|
2131
|
+
else if (ws?.packages)
|
|
2132
|
+
globs.push(...ws.packages);
|
|
2133
|
+
return globs.filter((g) => !g.startsWith("!"));
|
|
2134
|
+
}
|
|
2135
|
+
function expandGlob(files, glob) {
|
|
2136
|
+
const g = glob.replace(/\/+$/, "").replace(/\/\*\*$/, "/*");
|
|
2137
|
+
if (!g.includes("*"))
|
|
2138
|
+
return [g];
|
|
2139
|
+
const base = g.slice(0, g.indexOf("*")).replace(/\/$/, "");
|
|
2140
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
2141
|
+
for (const f of files.list()) {
|
|
2142
|
+
if (base && !f.startsWith(`${base}/`))
|
|
2143
|
+
continue;
|
|
2144
|
+
const rest = base ? f.slice(base.length + 1) : f;
|
|
2145
|
+
const first = rest.split("/")[0];
|
|
2146
|
+
if (first && rest.includes("/"))
|
|
2147
|
+
dirs.add(base ? `${base}/${first}` : first);
|
|
2148
|
+
}
|
|
2149
|
+
return [...dirs];
|
|
2150
|
+
}
|
|
2151
|
+
function topLevelDirs(files) {
|
|
2152
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
2153
|
+
for (const f of files.list()) {
|
|
2154
|
+
const i = f.indexOf("/");
|
|
2155
|
+
if (i > 0 && !IGNORED_DIRS.has(f.slice(0, i)))
|
|
2156
|
+
dirs.add(f.slice(0, i));
|
|
2157
|
+
}
|
|
2158
|
+
return [...dirs];
|
|
2159
|
+
}
|
|
2160
|
+
function findAppRoots(files) {
|
|
2161
|
+
const globs = workspaceGlobs(files);
|
|
2162
|
+
if (globs.length > 0) {
|
|
2163
|
+
const roots2 = new Set(globs.flatMap((g) => expandGlob(files, g)).filter((d) => hasManifest(files, d)));
|
|
2164
|
+
for (const dir of topLevelDirs(files)) {
|
|
2165
|
+
if (!roots2.has(dir) && pythonManifests(subdir(files, dir)).length > 0)
|
|
2166
|
+
roots2.add(dir);
|
|
2167
|
+
}
|
|
2168
|
+
return { roots: [...roots2].sort(), workspace: true };
|
|
2169
|
+
}
|
|
2170
|
+
if (hasManifest(files, ""))
|
|
2171
|
+
return { roots: [""], workspace: false };
|
|
2172
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
2173
|
+
for (const f of files.list()) {
|
|
2174
|
+
const parts = f.split("/");
|
|
2175
|
+
for (const depth of [1, 2]) {
|
|
2176
|
+
if (parts.length > depth) {
|
|
2177
|
+
const dir = parts.slice(0, depth).join("/");
|
|
2178
|
+
if (parts.slice(0, depth).some((p) => IGNORED_DIRS.has(p)))
|
|
2179
|
+
continue;
|
|
2180
|
+
candidates.add(dir);
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
const roots = [...candidates].filter((d) => hasManifest(files, d)).sort();
|
|
2185
|
+
return {
|
|
2186
|
+
roots: roots.filter((d) => !roots.some((o) => o !== d && d.startsWith(`${o}/`))),
|
|
2187
|
+
workspace: false
|
|
2188
|
+
};
|
|
2189
|
+
}
|
|
2190
|
+
function analyzeFiles(files, projectName = "app") {
|
|
2191
|
+
const { roots, workspace } = findAppRoots(files);
|
|
2192
|
+
const warnings = [];
|
|
2193
|
+
const rootPm = nodePackageManager(files, readPackageJson(files));
|
|
2194
|
+
const rootPyLock = firstExisting(files, ["uv.lock", "poetry.lock", "Pipfile.lock"]);
|
|
2195
|
+
const apps = [];
|
|
2196
|
+
const dotnet = detectDotnet(files);
|
|
2197
|
+
warnings.push(...dotnet.warnings);
|
|
2198
|
+
const dotnetDirs = dotnet.apps.map((a) => a.path);
|
|
2199
|
+
const embedded = new Set(dotnet.apps.flatMap((a) => a.embeddedDirs));
|
|
2200
|
+
const insideDotnet = (dir) => embedded.has(dir) || dotnetDirs.some((d) => d === dir || d !== "" && dir.startsWith(`${d}/`));
|
|
2201
|
+
for (const a of dotnet.apps) {
|
|
2202
|
+
const view = subdir(files, a.path);
|
|
2203
|
+
const extra = [...a.embeddedDirs.map((d) => subdir(files, d)), view].flatMap((v) => detectEnv(v).env);
|
|
2204
|
+
const env = [...a.profile.env];
|
|
2205
|
+
for (const e of extra)
|
|
2206
|
+
if (!env.some((x) => x.name === e.name))
|
|
2207
|
+
env.push(e);
|
|
2208
|
+
env.sort((x, y) => x.name.localeCompare(y.name));
|
|
2209
|
+
const profile = AppProfile.parse({
|
|
2210
|
+
schemaVersion: SCHEMA_VERSION,
|
|
2211
|
+
...a.profile,
|
|
2212
|
+
env,
|
|
2213
|
+
load: { source: "detector" }
|
|
2214
|
+
});
|
|
2215
|
+
apps.push({ path: a.path, profile, warnings: a.warnings });
|
|
2216
|
+
}
|
|
2217
|
+
for (const root of roots) {
|
|
2218
|
+
if (insideDotnet(root))
|
|
2219
|
+
continue;
|
|
2220
|
+
const view = subdir(files, root);
|
|
2221
|
+
const fallbackName = root ? path4.posix.basename(root) : projectName;
|
|
2222
|
+
const node = detectNode(view, fallbackName, rootPm);
|
|
2223
|
+
const py = detectPython(view, fallbackName, rootPyLock);
|
|
2224
|
+
if ((workspace || dotnet.apps.length > 0) && node && !node.isApp && !py)
|
|
2225
|
+
continue;
|
|
2226
|
+
const base = node?.profile ?? py?.profile;
|
|
2227
|
+
if (!base)
|
|
2228
|
+
continue;
|
|
2229
|
+
const runtimes = [...base.runtimes, ...node && py ? py.profile.runtimes : []];
|
|
2230
|
+
const services = [...base.services, ...node && py ? py.profile.services : []];
|
|
2231
|
+
const { env } = detectEnv(view);
|
|
2232
|
+
const profile = AppProfile.parse({
|
|
2233
|
+
schemaVersion: SCHEMA_VERSION,
|
|
2234
|
+
...base,
|
|
2235
|
+
runtimes,
|
|
2236
|
+
services,
|
|
2237
|
+
env,
|
|
2238
|
+
load: { source: "detector" }
|
|
2239
|
+
});
|
|
2240
|
+
apps.push({ path: root, profile, warnings: [...node?.warnings ?? [], ...py?.warnings ?? []] });
|
|
2241
|
+
}
|
|
2242
|
+
apps.sort((a, b) => a.path.localeCompare(b.path));
|
|
2243
|
+
if (apps.length === 0)
|
|
2244
|
+
warnings.push("no app found: no package.json, requirements.txt, pyproject.toml, Pipfile or deployable .csproj/.fsproj");
|
|
2245
|
+
return { apps, warnings };
|
|
2246
|
+
}
|
|
2247
|
+
async function analyzeDirectory(dir) {
|
|
2248
|
+
return analyzeFiles(await fromDirectory(dir), path4.basename(path4.resolve(dir)));
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
// apps/mcp/src/format.ts
|
|
2252
|
+
var runtimeName = (lang) => lang === "typescript" || lang === "javascript" ? "Node.js" : lang === "python" ? "Python" : lang === "csharp" || lang === "fsharp" ? ".NET" : lang;
|
|
2253
|
+
var money = (v) => v >= 100 ? `$${Math.round(v).toLocaleString("en-US")}` : `$${v.toFixed(2)}`;
|
|
2254
|
+
var range = (r) => Math.abs(r.high - r.low) < 5e-3 ? money(r.low) : `${money(r.low)}\u2013${money(r.high)}`;
|
|
2255
|
+
var SCENARIO = {
|
|
2256
|
+
team: "Team (up to 50 users, ~1,000 requests a day, 1 GB of data)",
|
|
2257
|
+
department: "Department (up to 500 users, ~20,000 requests a day, 10 GB)",
|
|
2258
|
+
company: "Company (up to 5,000 users, ~200,000 requests a day, 50 GB)"
|
|
2259
|
+
};
|
|
2260
|
+
function formatStack(apps, warnings) {
|
|
2261
|
+
const out = [];
|
|
2262
|
+
for (const a of apps) {
|
|
2263
|
+
const p = a.profile;
|
|
2264
|
+
const rt = p.runtimes[0];
|
|
2265
|
+
out.push(`### ${p.app.name}${a.path ? ` (\`${a.path}\`)` : ""}`);
|
|
2266
|
+
out.push(
|
|
2267
|
+
`- Kind: ${p.app.kind}; ${rt?.language ?? "unknown"}${rt?.framework ? `, ${rt.framework}` : ""}${rt?.version ? ` (${runtimeName(rt.language)} ${rt.version})` : ""}${p.build.packageManager ? `; ${p.build.packageManager}` : ""}${p.build.port ? `; port ${p.build.port}` : ""}`
|
|
2268
|
+
);
|
|
2269
|
+
if (p.services.length)
|
|
2270
|
+
out.push(
|
|
2271
|
+
`- Services: ${p.services.map((s) => `${s.type}${s.engine ? ` (${s.engine})` : ""}`).join(", ")}`
|
|
2272
|
+
);
|
|
2273
|
+
const secrets = p.env.filter((e) => e.secret).map((e) => e.name);
|
|
2274
|
+
const plain = p.env.filter((e) => !e.secret).map((e) => e.name);
|
|
2275
|
+
if (secrets.length) out.push(`- Secrets it needs: ${secrets.join(", ")}`);
|
|
2276
|
+
if (plain.length) out.push(`- Other settings: ${plain.join(", ")}`);
|
|
2277
|
+
for (const w of a.warnings) out.push(`- Note: ${w}`);
|
|
2278
|
+
}
|
|
2279
|
+
for (const w of warnings) out.push(`- Note: ${w}`);
|
|
2280
|
+
return out.join("\n");
|
|
2281
|
+
}
|
|
2282
|
+
function scenarioLine(r) {
|
|
2283
|
+
return `Load: ${SCENARIO[r.scenario] ?? "custom numbers"}. Region: ${r.geo === "us" ? "US East" : "Europe (Frankfurt)"}. Monthly USD.`;
|
|
2284
|
+
}
|
|
2285
|
+
function asOf(r) {
|
|
2286
|
+
const d = Object.entries(r.pricesAsOf).map(([p, day]) => `${p} ${day}`);
|
|
2287
|
+
return d.length ? `Prices as of: ${d.join(", ")}.` : "";
|
|
2288
|
+
}
|
|
2289
|
+
function formatCosts(r) {
|
|
2290
|
+
const ok = r.ranking.filter((p) => !p.excluded).sort((a, b) => a.monthlyUsd.low + a.monthlyUsd.high - (b.monthlyUsd.low + b.monthlyUsd.high));
|
|
2291
|
+
const out = [scenarioLine(r), "", "| Platform | Per month | Codeport deploys here |", "|---|---|---|"];
|
|
2292
|
+
for (const p of ok)
|
|
2293
|
+
out.push(`| ${p.name} | ${range(p.monthlyUsd)} | ${p.deployable ? "yes" : "not yet"} |`);
|
|
2294
|
+
const ex = r.ranking.filter((p) => p.excluded);
|
|
2295
|
+
if (ex.length) out.push("", "Not suitable or not priced:", ...ex.map((p) => `- ${p.name}: ${p.excluded}`));
|
|
2296
|
+
const missing = [...new Set(ok.flatMap((p) => p.notIncluded.map((n) => n.item)))];
|
|
2297
|
+
if (missing.length)
|
|
2298
|
+
out.push("", `Not in these totals (billed by their own providers): ${missing.join(", ")}.`);
|
|
2299
|
+
out.push("", asOf(r), "Ask for one platform's breakdown to see every line, its unit price and source.");
|
|
2300
|
+
return out.filter((l, i, a) => !(l === "" && a[i - 1] === "")).join("\n");
|
|
2301
|
+
}
|
|
2302
|
+
function formatBreakdown(p, r) {
|
|
2303
|
+
if (p.excluded) return `${p.name}: ${p.excluded}`;
|
|
2304
|
+
const out = [
|
|
2305
|
+
`## ${p.name}: ${range(p.monthlyUsd)} per month${p.region === "global" ? "" : ` (prices for ${p.region})`}`,
|
|
2306
|
+
scenarioLine(r),
|
|
2307
|
+
"",
|
|
2308
|
+
"| Item | Quantity | Unit price | Cost | Source |",
|
|
2309
|
+
"|---|---|---|---|---|"
|
|
2310
|
+
];
|
|
2311
|
+
for (const l of p.lines) {
|
|
2312
|
+
const q = Math.abs(l.quantity.high - l.quantity.low) < 1e-9 ? fmtQty(l.quantity.low) : `${fmtQty(l.quantity.low)}\u2013${fmtQty(l.quantity.high)}`;
|
|
2313
|
+
const unit = l.unitPrice ? `$${l.unitPrice.usd} / ${l.unitPrice.per === 1 ? "" : `${l.unitPrice.per.toLocaleString("en-US")} `}${l.unitPrice.unit}` : "";
|
|
2314
|
+
const src = !l.source ? "" : l.source.kind === "aws-price-list" ? `AWS Price List, SKU ${l.source.sku}, ${l.source.publishedAt.slice(0, 10)}` : l.source.kind === "manual" ? `[${new URL(l.source.url).hostname}](${l.source.url}), checked ${l.source.verifiedAt}` : l.source.kind === "azure-retail-prices" ? `Azure Retail Prices, meter ${l.source.meterId}` : `Google Cloud Billing, SKU ${l.source.skuId}`;
|
|
2315
|
+
const note = [l.vendor ? `billed by ${l.vendor}` : "", l.note ?? ""].filter(Boolean).join("; ");
|
|
2316
|
+
out.push(
|
|
2317
|
+
`| ${l.label}${note ? ` (${note})` : ""} | ${l.unitPrice ? q : `${q} ${l.unit}`} | ${unit} | ${range(l.usd)} | ${src} |`
|
|
2318
|
+
);
|
|
2319
|
+
}
|
|
2320
|
+
if (p.notIncluded.length)
|
|
2321
|
+
out.push("", "Not included:", ...p.notIncluded.map((n) => `- ${n.item}: ${n.reason}`));
|
|
2322
|
+
return out.join("\n");
|
|
2323
|
+
}
|
|
2324
|
+
var fmtQty = (v) => v >= 1e3 ? Math.round(v).toLocaleString("en-US") : Number(v.toFixed(3)).toString();
|
|
2325
|
+
function formatRecommendation(r) {
|
|
2326
|
+
const ok = r.ranking.filter((p) => !p.excluded);
|
|
2327
|
+
const best = ok[0];
|
|
2328
|
+
if (!best)
|
|
2329
|
+
return "No platform can run this project as it is: " + r.ranking.map((p) => `${p.name}: ${p.excluded}`).join("; ");
|
|
2330
|
+
const out = [scenarioLine(r), ""];
|
|
2331
|
+
const dep = ok.find((p) => p.deployable);
|
|
2332
|
+
out.push(`**Best fit: ${best.name}** (${range(best.monthlyUsd)} per month, score ${best.score}).`);
|
|
2333
|
+
if (!best.deployable && dep)
|
|
2334
|
+
out.push(
|
|
2335
|
+
`Codeport cannot deploy to ${best.name} yet. The best option it deploys to today is **${dep.name}** (${range(dep.monthlyUsd)} per month).`
|
|
2336
|
+
);
|
|
2337
|
+
if (!best.deployable && !dep) {
|
|
2338
|
+
const why = r.ranking.filter((p) => p.deployable).map((p) => `${p.name}: ${p.excluded ?? "not suitable"}`);
|
|
2339
|
+
out.push(`Codeport cannot deploy this project anywhere yet (${why.join("; ")}).`);
|
|
2340
|
+
}
|
|
2341
|
+
out.push("", "| # | Platform | Per month | Score | For | Against |", "|---|---|---|---|---|---|");
|
|
2342
|
+
ok.forEach(
|
|
2343
|
+
(p, i) => out.push(
|
|
2344
|
+
`| ${i + 1} | ${p.name}${p.deployable ? "" : " (estimate only)"} | ${range(p.monthlyUsd)} | ${p.score} | ${p.pros.join("; ")} | ${p.cons.join("; ")} |`
|
|
2345
|
+
)
|
|
2346
|
+
);
|
|
2347
|
+
const ex = r.ranking.filter((p) => p.excluded);
|
|
2348
|
+
if (ex.length) out.push("", "Ruled out:", ...ex.map((p) => `- ${p.name}: ${p.excluded}`));
|
|
2349
|
+
out.push("", "Score = 0.45 simplicity + 0.35 cost + 0.2 fit with the stack.", asOf(r));
|
|
2350
|
+
return out.join("\n");
|
|
2351
|
+
}
|
|
2352
|
+
|
|
2353
|
+
// apps/mcp/src/projects.ts
|
|
2354
|
+
import { mkdir as mkdir2, readFile as readFile3, writeFile as writeFile2 } from "node:fs/promises";
|
|
2355
|
+
import { homedir as homedir2 } from "node:os";
|
|
2356
|
+
import path5 from "node:path";
|
|
2357
|
+
var ProjectMap = class {
|
|
2358
|
+
constructor(file = path5.join(homedir2(), ".codeport", "projects.json")) {
|
|
2359
|
+
this.file = file;
|
|
2360
|
+
}
|
|
2361
|
+
async read() {
|
|
2362
|
+
try {
|
|
2363
|
+
return JSON.parse(await readFile3(this.file, "utf8"));
|
|
2364
|
+
} catch {
|
|
2365
|
+
return {};
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
async get(apiUrl2, dir) {
|
|
2369
|
+
return (await this.read())[`${apiUrl2}|${dir}`];
|
|
2370
|
+
}
|
|
2371
|
+
async set(apiUrl2, dir, appId) {
|
|
2372
|
+
const all = await this.read();
|
|
2373
|
+
all[`${apiUrl2}|${dir}`] = appId;
|
|
2374
|
+
await mkdir2(path5.dirname(this.file), { recursive: true, mode: 448 });
|
|
2375
|
+
await writeFile2(this.file, JSON.stringify(all, null, 2), { mode: 384 });
|
|
2376
|
+
}
|
|
2377
|
+
};
|
|
2378
|
+
async function repoOf(dir) {
|
|
2379
|
+
try {
|
|
2380
|
+
const config = await readFile3(path5.join(dir, ".git", "config"), "utf8");
|
|
2381
|
+
const url = config.match(/\[remote "origin"\][^[]*?url\s*=\s*(\S+)/)?.[1] ?? "";
|
|
2382
|
+
const gh = url.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?$/);
|
|
2383
|
+
let commitSha;
|
|
2384
|
+
const head = (await readFile3(path5.join(dir, ".git", "HEAD"), "utf8")).trim();
|
|
2385
|
+
if (/^[0-9a-f]{40}$/.test(head)) commitSha = head;
|
|
2386
|
+
else {
|
|
2387
|
+
const ref = head.match(/^ref: (.+)$/)?.[1];
|
|
2388
|
+
if (ref)
|
|
2389
|
+
commitSha = (await readFile3(path5.join(dir, ".git", ref), "utf8").catch(() => "")).trim() || void 0;
|
|
2390
|
+
}
|
|
2391
|
+
return {
|
|
2392
|
+
repo: gh ? `github:${gh[1]}/${gh[2]}` : "local",
|
|
2393
|
+
...commitSha && /^[0-9a-f]{40}$/.test(commitSha) ? { commitSha } : {}
|
|
2394
|
+
};
|
|
2395
|
+
} catch {
|
|
2396
|
+
return { repo: "local" };
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2400
|
+
// apps/mcp/src/project-tools.ts
|
|
2401
|
+
var NOT_SIGNED_IN = "Not signed in to Codeport. Ask the user for their work email and call auth_start.";
|
|
2402
|
+
var ProjectTools = class {
|
|
2403
|
+
constructor(api2, store2, projects = new ProjectMap(), cwd = () => process.cwd()) {
|
|
2404
|
+
this.api = api2;
|
|
2405
|
+
this.store = store2;
|
|
2406
|
+
this.projects = projects;
|
|
2407
|
+
this.cwd = cwd;
|
|
2408
|
+
}
|
|
2409
|
+
async dir(p) {
|
|
2410
|
+
const d = path6.resolve(this.cwd(), p ?? ".");
|
|
2411
|
+
const s = await stat2(d).catch(() => null);
|
|
2412
|
+
if (!s?.isDirectory()) throw new UserError(`${d} is not a folder on this machine.`);
|
|
2413
|
+
return d;
|
|
2414
|
+
}
|
|
2415
|
+
async token() {
|
|
2416
|
+
const c = await this.store.load();
|
|
2417
|
+
return c && c.apiUrl === this.api.baseUrl ? c.token : null;
|
|
2418
|
+
}
|
|
2419
|
+
async analyzeLocal(dir) {
|
|
2420
|
+
const r = await analyzeDirectory(dir);
|
|
2421
|
+
if (r.apps.length === 0) throw new UserError(`No app found in ${dir}. ${r.warnings.join(" ")}`);
|
|
2422
|
+
return r;
|
|
2423
|
+
}
|
|
2424
|
+
scenario(a) {
|
|
2425
|
+
if (a.users || a.requestsPerDay || a.dataGb)
|
|
2426
|
+
return {
|
|
2427
|
+
id: "custom",
|
|
2428
|
+
users: a.users ?? 100,
|
|
2429
|
+
requestsPerDay: a.requestsPerDay ?? 5e3,
|
|
2430
|
+
dataGb: a.dataGb ?? 5
|
|
2431
|
+
};
|
|
2432
|
+
return a.scenario ?? "team";
|
|
2433
|
+
}
|
|
2434
|
+
async run(fn) {
|
|
2435
|
+
const token = await this.token();
|
|
2436
|
+
if (!token) return NOT_SIGNED_IN;
|
|
2437
|
+
try {
|
|
2438
|
+
return await fn(token);
|
|
2439
|
+
} catch (e) {
|
|
2440
|
+
if (e instanceof UserError) return e.message;
|
|
2441
|
+
if (e instanceof ApiError && e.status === 401) {
|
|
2442
|
+
await this.store.clear();
|
|
2443
|
+
return "The Codeport session has expired. Call auth_start to sign in again.";
|
|
2444
|
+
}
|
|
2445
|
+
if (e instanceof ApiError) return `Codeport could not do that (${e.status}: ${e.message}).`;
|
|
2446
|
+
throw e;
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
/** Detect the stack, save the app in the organization's catalog, and give a first estimate. */
|
|
2450
|
+
async analyze(args) {
|
|
2451
|
+
return this.run(async (token) => {
|
|
2452
|
+
const dir = await this.dir(args.path);
|
|
2453
|
+
const result = await this.analyzeLocal(dir);
|
|
2454
|
+
const { repo, commitSha } = await repoOf(dir);
|
|
2455
|
+
let appId = await this.projects.get(this.api.baseUrl, dir);
|
|
2456
|
+
if (appId) {
|
|
2457
|
+
const ok = await this.api.call(token, "GET", `/v1/apps/${appId}`).then(
|
|
2458
|
+
() => true,
|
|
2459
|
+
(e) => e instanceof ApiError && e.status === 404 ? false : Promise.reject(e)
|
|
2460
|
+
);
|
|
2461
|
+
if (!ok) appId = void 0;
|
|
2462
|
+
}
|
|
2463
|
+
let created = false;
|
|
2464
|
+
if (!appId) {
|
|
2465
|
+
const name = args.name ?? (repo.startsWith("github:") ? repo.split("/").pop() : path6.basename(dir));
|
|
2466
|
+
const r2 = await this.api.call(token, "POST", "/v1/apps", { name, repo });
|
|
2467
|
+
appId = r2.app.id;
|
|
2468
|
+
created = true;
|
|
2469
|
+
await this.projects.set(this.api.baseUrl, dir, appId);
|
|
2470
|
+
}
|
|
2471
|
+
const sent = await this.api.call(
|
|
2472
|
+
token,
|
|
2473
|
+
"POST",
|
|
2474
|
+
`/v1/apps/${appId}/profiles`,
|
|
2475
|
+
{
|
|
2476
|
+
apps: result.apps.map((a) => ({ path: a.path, profile: a.profile })),
|
|
2477
|
+
...commitSha ? { commitSha } : {},
|
|
2478
|
+
scenario: "team",
|
|
2479
|
+
geo: args.geo ?? "eu"
|
|
2480
|
+
}
|
|
2481
|
+
);
|
|
2482
|
+
const r = sent.recommendation;
|
|
2483
|
+
const best = r.ranking.find((p) => p.platform === r.best);
|
|
2484
|
+
const dep = r.ranking.find((p) => p.platform === r.bestDeployable);
|
|
2485
|
+
return [
|
|
2486
|
+
`${created ? "Added" : "Updated"} this project in the organization's Codeport catalog (${result.apps.length} app${result.apps.length > 1 ? "s" : ""}). Only the stack profile was sent; no source code or secret values.`,
|
|
2487
|
+
"",
|
|
2488
|
+
"## Stack",
|
|
2489
|
+
formatStack(result.apps, result.warnings),
|
|
2490
|
+
"",
|
|
2491
|
+
"## First estimate (Team load)",
|
|
2492
|
+
best ? `Best fit: ${best.name}, ${usd(best.monthlyUsd)} per month.` : "No platform can run it as it is.",
|
|
2493
|
+
dep && dep.platform !== best?.platform ? `Best that Codeport deploys to: ${dep.name}, ${usd(dep.monthlyUsd)} per month.` : "",
|
|
2494
|
+
"Use estimate_cost for all platforms and loads, or recommend_target for the full ranking."
|
|
2495
|
+
].filter((l, i, a) => l !== "" || a[i - 1] !== "").join("\n");
|
|
2496
|
+
});
|
|
2497
|
+
}
|
|
2498
|
+
async recommendation(token, a) {
|
|
2499
|
+
const result = await this.analyzeLocal(await this.dir(a.path));
|
|
2500
|
+
const r = await this.api.call(token, "POST", "/v1/estimate", {
|
|
2501
|
+
apps: result.apps.map((x) => ({ path: x.path, profile: x.profile })),
|
|
2502
|
+
scenario: this.scenario(a),
|
|
2503
|
+
geo: a.geo ?? "eu"
|
|
2504
|
+
});
|
|
2505
|
+
return r.recommendation;
|
|
2506
|
+
}
|
|
2507
|
+
async estimate(a) {
|
|
2508
|
+
return this.run(async (token) => {
|
|
2509
|
+
const r = await this.recommendation(token, a);
|
|
2510
|
+
if (!a.platform) return formatCosts(r);
|
|
2511
|
+
const want = a.platform.toLowerCase().replace(/[^a-z]/g, "");
|
|
2512
|
+
const p = r.ranking.find(
|
|
2513
|
+
(x) => x.platform === want || x.name.toLowerCase().replace(/[^a-z]/g, "") === want
|
|
2514
|
+
);
|
|
2515
|
+
if (!p)
|
|
2516
|
+
return `Unknown platform "${a.platform}". Choose one of: ${r.ranking.map((x) => x.name).join(", ")}.`;
|
|
2517
|
+
return formatBreakdown(p, r);
|
|
2518
|
+
});
|
|
2519
|
+
}
|
|
2520
|
+
async recommend(a) {
|
|
2521
|
+
return this.run(async (token) => formatRecommendation(await this.recommendation(token, a)));
|
|
2522
|
+
}
|
|
2523
|
+
};
|
|
2524
|
+
var UserError = class extends Error {
|
|
2525
|
+
};
|
|
2526
|
+
var usd = (r) => {
|
|
2527
|
+
const f = (v) => v >= 100 ? `$${Math.round(v)}` : `$${v.toFixed(2)}`;
|
|
2528
|
+
return Math.abs(r.high - r.low) < 5e-3 ? f(r.low) : `${f(r.low)}\u2013${f(r.high)}`;
|
|
2529
|
+
};
|
|
2530
|
+
|
|
2531
|
+
// apps/mcp/src/version.ts
|
|
2532
|
+
var VERSION = "0.3.0";
|
|
2533
|
+
|
|
2534
|
+
// apps/mcp/src/index.ts
|
|
2535
|
+
var apiUrl = process.env.CODEPORT_API_URL ?? "https://api.codeport.diy";
|
|
2536
|
+
var api = new CodeportApi(apiUrl);
|
|
2537
|
+
var store = await defaultStore();
|
|
2538
|
+
var flow = new AuthFlow(api, store);
|
|
2539
|
+
var server = createServer(flow, new ProjectTools(api, store), VERSION);
|
|
2540
|
+
await server.connect(new StdioServerTransport());
|
|
2541
|
+
/*! Bundled license information:
|
|
2542
|
+
|
|
2543
|
+
smol-toml/dist/error.js:
|
|
2544
|
+
smol-toml/dist/primitive.js:
|
|
2545
|
+
smol-toml/dist/date.js:
|
|
2546
|
+
smol-toml/dist/extract.js:
|
|
2547
|
+
smol-toml/dist/util.js:
|
|
2548
|
+
smol-toml/dist/struct.js:
|
|
2549
|
+
smol-toml/dist/parse.js:
|
|
2550
|
+
smol-toml/dist/stringify.js:
|
|
2551
|
+
smol-toml/dist/index.js:
|
|
2552
|
+
(*!
|
|
2553
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
2554
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
2555
|
+
*
|
|
2556
|
+
* Redistribution and use in source and binary forms, with or without
|
|
2557
|
+
* modification, are permitted provided that the following conditions are met:
|
|
2558
|
+
*
|
|
2559
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
2560
|
+
* list of conditions and the following disclaimer.
|
|
2561
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
2562
|
+
* this list of conditions and the following disclaimer in the
|
|
2563
|
+
* documentation and/or other materials provided with the distribution.
|
|
2564
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
2565
|
+
* may be used to endorse or promote products derived from this software without
|
|
2566
|
+
* specific prior written permission.
|
|
2567
|
+
*
|
|
2568
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
2569
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
2570
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
2571
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
2572
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
2573
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
2574
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
2575
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
2576
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
2577
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2578
|
+
*)
|
|
2579
|
+
*/
|