@askdb/studio 0.2.0-beta.41 → 0.2.0-beta.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,86 +0,0 @@
1
- /**
2
- * Package-manager helpers shared by the setup wizard (`setup.ts`) and the
3
- * execute-driver install endpoint (`server.ts`).
4
- *
5
- * Only allowlisted package names ever reach these helpers — never
6
- * browser-supplied strings — but {@link packageManagerSpawnSpec} re-checks
7
- * every argument anyway because Windows needs `shell: true` (see below).
8
- */
9
- import { spawnSync } from "node:child_process";
10
- import { existsSync } from "node:fs";
11
- import { join } from "node:path";
12
- /** The package manager implied by a lockfile directly inside `dir`, if any. */
13
- export function lockfilePackageManager(dir) {
14
- if (existsSync(join(dir, "pnpm-lock.yaml")))
15
- return "pnpm";
16
- if (existsSync(join(dir, "bun.lockb")) || existsSync(join(dir, "bun.lock")))
17
- return "bun";
18
- if (existsSync(join(dir, "yarn.lock")))
19
- return "yarn";
20
- if (existsSync(join(dir, "package-lock.json")))
21
- return "npm";
22
- return null;
23
- }
24
- /**
25
- * Arguments that add `packages` as dependencies with the given package manager.
26
- * `allowBuilds` are dependencies whose install scripts pnpm must be told to run
27
- * (`--allow-build=<name>`; pnpm 11 exits 1 on an unapproved one). npm and Yarn
28
- * run install scripts, and Bun skips untrusted ones without failing, so only
29
- * pnpm gets them.
30
- */
31
- export function packageManagerAddArgs(pm, packages, allowBuilds = []) {
32
- if (pm === "npm")
33
- return ["install", "--save", ...packages];
34
- if (pm === "pnpm")
35
- return ["add", ...allowBuilds.map((name) => `--allow-build=${name}`), ...packages];
36
- return ["add", ...packages];
37
- }
38
- /**
39
- * The build approvals to pass `pm` in `dir`: `allowBuilds`, or none for a pnpm older
40
- * than 10.4.0, whose `add` rejects `--allow-build` (pnpm 9 runs install scripts, and
41
- * 10.0 to 10.3 skip unapproved ones without failing). A pnpm whose version can't be
42
- * read keeps them. `askdb init` applies the same rule (`apps/cli/src/init.ts`).
43
- */
44
- export function supportedBuildApprovals(pm, dir, allowBuilds) {
45
- if (pm !== "pnpm" || allowBuilds.length === 0)
46
- return [...allowBuilds];
47
- const match = /^(\d+)\.(\d+)\./.exec(pnpmVersion(dir) ?? "");
48
- if (!match)
49
- return [...allowBuilds];
50
- const [major, minor] = [Number(match[1]), Number(match[2])];
51
- return major > 10 || (major === 10 && minor >= 4) ? [...allowBuilds] : [];
52
- }
53
- function pnpmVersion(dir) {
54
- const { command, args, shell } = packageManagerSpawnSpec("pnpm", ["--version"]);
55
- const result = spawnSync(command, args, { cwd: dir, encoding: "utf8", shell, stdio: ["ignore", "pipe", "ignore"], timeout: 15_000 });
56
- return result.status === 0 ? result.stdout.trim() : null;
57
- }
58
- /** Human-readable install command, e.g. `pnpm add pg`. */
59
- export function formatInstallCommand(pm, packages, allowBuilds = []) {
60
- return [pm, ...packageManagerAddArgs(pm, packages, allowBuilds)].join(" ");
61
- }
62
- // npm package names (optionally scoped, optionally with a version/range suffix),
63
- // simple `--flag` arguments, and pnpm's `--allow-build=<package name>`. Nothing a
64
- // shell would interpret.
65
- const SAFE_ARG = /^(?:--[a-z][a-z-]*|--allow-build=(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*|(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*(?:@[a-z0-9.^~<>=*_-]+)?|add|install)$/i;
66
- /**
67
- * How to spawn a package manager on this platform.
68
- *
69
- * On Windows, package managers are `.cmd` shims, and Node refuses to spawn
70
- * `.cmd`/`.bat` files without a shell (EINVAL since Node 18.20.2 / 20.12.2,
71
- * CVE-2024-27980). So Windows gets `shell: true` with the bare command name.
72
- * Arguments are validated against a strict allowlist pattern first, so the
73
- * shell never sees anything it could interpret.
74
- */
75
- export function packageManagerSpawnSpec(pm, args, platform = process.platform) {
76
- for (const arg of args) {
77
- if (!SAFE_ARG.test(arg)) {
78
- throw new Error(`Refusing to pass unsafe argument to ${pm}: ${JSON.stringify(arg)}`);
79
- }
80
- }
81
- if (platform === "win32") {
82
- return { command: pm, args: [...args], shell: true };
83
- }
84
- return { command: pm, args: [...args], shell: false };
85
- }
86
- //# sourceMappingURL=package-manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-manager.js","sourceRoot":"","sources":["../src/package-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,+EAA+E;AAC/E,MAAM,UAAU,sBAAsB,CAAC,GAAW;IAChD,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;QAAE,OAAO,MAAM,CAAC;IAC3D,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC1F,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAAE,OAAO,MAAM,CAAC;IACtD,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7D,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,EAAkB,EAClB,QAA2B,EAC3B,cAAiC,EAAE;IAEnC,IAAI,EAAE,KAAK,KAAK;QAAE,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC;IAC5D,IAAI,EAAE,KAAK,MAAM;QAAE,OAAO,CAAC,KAAK,EAAE,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,iBAAiB,IAAI,EAAE,CAAC,EAA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