@cedarjs/pg 0.1.0-alpha.1 → 0.2.0-beta.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 +361 -89
- package/dist/cli.cjs +131 -35
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +118 -22
- package/dist/cli.mjs.map +1 -1
- package/dist/dev-env.cjs +12 -0
- package/dist/dev-env.cjs.map +1 -0
- package/dist/dev-env.d.cts +1 -0
- package/dist/dev-env.d.mts +1 -0
- package/dist/dev-env.mjs +14 -0
- package/dist/dev-env.mjs.map +1 -0
- package/dist/index.cjs +51 -10
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +198 -84
- package/dist/index.d.mts +198 -84
- package/dist/index.mjs +32 -2
- package/dist/index.mjs.map +1 -0
- package/dist/jest-teardown.cjs +18 -0
- package/dist/jest-teardown.cjs.map +1 -0
- package/dist/jest-teardown.d.cts +13 -0
- package/dist/jest-teardown.d.mts +14 -0
- package/dist/jest-teardown.mjs +18 -0
- package/dist/jest-teardown.mjs.map +1 -0
- package/dist/jest-template.cjs +44 -0
- package/dist/jest-template.cjs.map +1 -0
- package/dist/jest-template.d.cts +31 -0
- package/dist/jest-template.d.mts +31 -0
- package/dist/jest-template.mjs +38 -0
- package/dist/jest-template.mjs.map +1 -0
- package/dist/jest.cjs +12 -15
- package/dist/jest.cjs.map +1 -1
- package/dist/jest.d.cts +10 -7
- package/dist/jest.d.mts +10 -6
- package/dist/jest.mjs +12 -10
- package/dist/jest.mjs.map +1 -1
- package/dist/lease-B3TuX92y.d.mts +24 -0
- package/dist/lease-DS1SX8U_.mjs +221 -0
- package/dist/lease-DS1SX8U_.mjs.map +1 -0
- package/dist/lease-WlmOnNDi.cjs +310 -0
- package/dist/lease-WlmOnNDi.cjs.map +1 -0
- package/dist/lease-t4I9JahV.d.cts +24 -0
- package/dist/lifecycle-BbrvFQvg.cjs +953 -0
- package/dist/lifecycle-BbrvFQvg.cjs.map +1 -0
- package/dist/lifecycle-BvIx0xqq.mjs +781 -0
- package/dist/lifecycle-BvIx0xqq.mjs.map +1 -0
- package/dist/load-dev-env-BULkXyen.mjs +10 -0
- package/dist/load-dev-env-BULkXyen.mjs.map +1 -0
- package/dist/load-dev-env-Bl6Ddv1U.cjs +15 -0
- package/dist/load-dev-env-Bl6Ddv1U.cjs.map +1 -0
- package/dist/load-mode-env-CX9vd56X.cjs +39 -0
- package/dist/load-mode-env-CX9vd56X.cjs.map +1 -0
- package/dist/load-mode-env-Ce9ujisN.mjs +28 -0
- package/dist/load-mode-env-Ce9ujisN.mjs.map +1 -0
- package/dist/load-test-env-BqtA6V-d.mjs +18 -0
- package/dist/load-test-env-BqtA6V-d.mjs.map +1 -0
- package/dist/load-test-env-Dcgh6YHV.cjs +23 -0
- package/dist/load-test-env-Dcgh6YHV.cjs.map +1 -0
- package/dist/naming-C2nGVxPk.d.cts +39 -0
- package/dist/naming-C2nGVxPk.d.mts +39 -0
- package/dist/nx.cjs +25 -18
- package/dist/nx.cjs.map +1 -1
- package/dist/nx.d.cts +9 -20
- package/dist/nx.d.mts +9 -20
- package/dist/nx.mjs +18 -18
- package/dist/nx.mjs.map +1 -1
- package/dist/status-4Uz6A3LB.cjs +31 -0
- package/dist/status-4Uz6A3LB.cjs.map +1 -0
- package/dist/status-Dcnpgnlz.mjs +26 -0
- package/dist/status-Dcnpgnlz.mjs.map +1 -0
- package/dist/studio-DIFw1qWC.mjs +173 -0
- package/dist/studio-DIFw1qWC.mjs.map +1 -0
- package/dist/studio-oJE30_PO.cjs +208 -0
- package/dist/studio-oJE30_PO.cjs.map +1 -0
- package/dist/tasks-CNHvvlsN.cjs +67 -0
- package/dist/tasks-CNHvvlsN.cjs.map +1 -0
- package/dist/tasks-CjaZRi_G.d.mts +19 -0
- package/dist/tasks-D5iWIdlo.mjs +38 -0
- package/dist/tasks-D5iWIdlo.mjs.map +1 -0
- package/dist/tasks-DdQoP9We.d.cts +19 -0
- package/dist/template-BiJ-0TIF.mjs +88 -0
- package/dist/template-BiJ-0TIF.mjs.map +1 -0
- package/dist/template-CXMpODzK.cjs +105 -0
- package/dist/template-CXMpODzK.cjs.map +1 -0
- package/dist/template-mode-BTUsdBtA.mjs +94 -0
- package/dist/template-mode-BTUsdBtA.mjs.map +1 -0
- package/dist/template-mode-CzyVwHsi.d.cts +31 -0
- package/dist/template-mode-CzyVwHsi.d.mts +31 -0
- package/dist/template-mode-JTOxrEgE.cjs +105 -0
- package/dist/template-mode-JTOxrEgE.cjs.map +1 -0
- package/dist/test-env.cjs +16 -0
- package/dist/test-env.cjs.map +1 -0
- package/dist/test-env.d.cts +1 -0
- package/dist/test-env.d.mts +1 -0
- package/dist/test-env.mjs +18 -0
- package/dist/test-env.mjs.map +1 -0
- package/dist/vite-plus.cjs +113 -35
- package/dist/vite-plus.cjs.map +1 -1
- package/dist/vite-plus.d.cts +26 -46
- package/dist/vite-plus.d.mts +26 -46
- package/dist/vite-plus.mjs +110 -32
- package/dist/vite-plus.mjs.map +1 -1
- package/dist/vitest-template.cjs +48 -0
- package/dist/vitest-template.cjs.map +1 -0
- package/dist/vitest-template.d.cts +31 -0
- package/dist/vitest-template.d.mts +31 -0
- package/dist/vitest-template.mjs +42 -0
- package/dist/vitest-template.mjs.map +1 -0
- package/dist/vitest.cjs +10 -10
- package/dist/vitest.cjs.map +1 -1
- package/dist/vitest.d.cts +7 -3
- package/dist/vitest.d.mts +7 -2
- package/dist/vitest.mjs +10 -5
- package/dist/vitest.mjs.map +1 -1
- package/package.json +46 -13
- package/scripts/autopg-version +1 -0
- package/scripts/ci-install-autopg.sh +73 -0
- package/scripts/postinstall.js +35 -9
- package/dist/constants-BY97wXjA.mjs +0 -24
- package/dist/constants-BY97wXjA.mjs.map +0 -1
- package/dist/constants-CNZn5Xro.cjs +0 -41
- package/dist/constants-CNZn5Xro.cjs.map +0 -1
- package/dist/lifecycle-BGYtVXtx.cjs +0 -743
- package/dist/lifecycle-BGYtVXtx.cjs.map +0 -1
- package/dist/lifecycle-CT_8AWPv.mjs +0 -577
- package/dist/lifecycle-CT_8AWPv.mjs.map +0 -1
- package/dist/tasks-13P6tMth.mjs +0 -16
- package/dist/tasks-13P6tMth.mjs.map +0 -1
- package/dist/tasks-B8ryV9xo.cjs +0 -21
- package/dist/tasks-B8ryV9xo.cjs.map +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const require_lifecycle = require("./lifecycle-BbrvFQvg.cjs");
|
|
2
|
+
const require_lease = require("./lease-WlmOnNDi.cjs");
|
|
3
|
+
//#region src/core/status.ts
|
|
4
|
+
/** Read-only lease snapshot for CLI / Vite panel (no acquire, no host). */
|
|
5
|
+
function resolveDevStatus(options = {}) {
|
|
6
|
+
const mode = options.mode ?? "dev";
|
|
7
|
+
const root = require_lease.resolveRoot(options.root);
|
|
8
|
+
const lease = require_lease.readLease(root, mode);
|
|
9
|
+
if (!lease) return {
|
|
10
|
+
ok: false,
|
|
11
|
+
mode,
|
|
12
|
+
root
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
ok: true,
|
|
16
|
+
mode,
|
|
17
|
+
root,
|
|
18
|
+
lease,
|
|
19
|
+
databaseUrl: require_lifecycle.urlFromLease(lease),
|
|
20
|
+
envPath: require_lease.envPath(root, mode)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
Object.defineProperty(exports, "resolveDevStatus", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function() {
|
|
27
|
+
return resolveDevStatus;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=status-4Uz6A3LB.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status-4Uz6A3LB.cjs","names":["resolveRoot","readLease","urlFromLease","envPath"],"sources":["../src/core/status.ts"],"sourcesContent":["import { envPath, readLease, type Lease } from \"./lease.ts\";\nimport { urlFromLease } from \"./lifecycle.ts\";\nimport type { DbMode } from \"./naming.ts\";\nimport { resolveRoot } from \"./worktree.ts\";\n\nexport type ResolveDevStatusOptions = {\n root?: string;\n mode?: DbMode;\n};\n\nexport type DevStatus =\n | {\n ok: true;\n mode: DbMode;\n root: string;\n lease: Lease;\n databaseUrl: string;\n envPath: string;\n }\n | {\n ok: false;\n mode: DbMode;\n root: string;\n };\n\n/** Read-only lease snapshot for CLI / Vite panel (no acquire, no host). */\nexport function resolveDevStatus(options: ResolveDevStatusOptions = {}): DevStatus {\n const mode = options.mode ?? \"dev\";\n const root = resolveRoot(options.root);\n const lease = readLease(root, mode);\n if (!lease) {\n return { ok: false, mode, root };\n }\n return {\n ok: true,\n mode,\n root,\n lease,\n databaseUrl: urlFromLease(lease),\n envPath: envPath(root, mode),\n };\n}\n"],"mappings":";;;;AA0BA,SAAgB,iBAAiB,UAAmC,CAAC,GAAc;CACjF,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,OAAOA,cAAAA,YAAY,QAAQ,IAAI;CACrC,MAAM,QAAQC,cAAAA,UAAU,MAAM,IAAI;CAClC,IAAI,CAAC,OACH,OAAO;EAAE,IAAI;EAAO;EAAM;CAAK;CAEjC,OAAO;EACL,IAAI;EACJ;EACA;EACA;EACA,aAAaC,kBAAAA,aAAa,KAAK;EAC/B,SAASC,cAAAA,QAAQ,MAAM,IAAI;CAC7B;AACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { a as urlFromLease } from "./lifecycle-BvIx0xqq.mjs";
|
|
2
|
+
import { d as resolveRoot, l as readLease, n as envPath } from "./lease-DS1SX8U_.mjs";
|
|
3
|
+
//#region src/core/status.ts
|
|
4
|
+
/** Read-only lease snapshot for CLI / Vite panel (no acquire, no host). */
|
|
5
|
+
function resolveDevStatus(options = {}) {
|
|
6
|
+
const mode = options.mode ?? "dev";
|
|
7
|
+
const root = resolveRoot(options.root);
|
|
8
|
+
const lease = readLease(root, mode);
|
|
9
|
+
if (!lease) return {
|
|
10
|
+
ok: false,
|
|
11
|
+
mode,
|
|
12
|
+
root
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
ok: true,
|
|
16
|
+
mode,
|
|
17
|
+
root,
|
|
18
|
+
lease,
|
|
19
|
+
databaseUrl: urlFromLease(lease),
|
|
20
|
+
envPath: envPath(root, mode)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { resolveDevStatus as t };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=status-Dcnpgnlz.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status-Dcnpgnlz.mjs","names":[],"sources":["../src/core/status.ts"],"sourcesContent":["import { envPath, readLease, type Lease } from \"./lease.ts\";\nimport { urlFromLease } from \"./lifecycle.ts\";\nimport type { DbMode } from \"./naming.ts\";\nimport { resolveRoot } from \"./worktree.ts\";\n\nexport type ResolveDevStatusOptions = {\n root?: string;\n mode?: DbMode;\n};\n\nexport type DevStatus =\n | {\n ok: true;\n mode: DbMode;\n root: string;\n lease: Lease;\n databaseUrl: string;\n envPath: string;\n }\n | {\n ok: false;\n mode: DbMode;\n root: string;\n };\n\n/** Read-only lease snapshot for CLI / Vite panel (no acquire, no host). */\nexport function resolveDevStatus(options: ResolveDevStatusOptions = {}): DevStatus {\n const mode = options.mode ?? \"dev\";\n const root = resolveRoot(options.root);\n const lease = readLease(root, mode);\n if (!lease) {\n return { ok: false, mode, root };\n }\n return {\n ok: true,\n mode,\n root,\n lease,\n databaseUrl: urlFromLease(lease),\n envPath: envPath(root, mode),\n };\n}\n"],"mappings":";;;;AA0BA,SAAgB,iBAAiB,UAAmC,CAAC,GAAc;CACjF,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,OAAO,YAAY,QAAQ,IAAI;CACrC,MAAM,QAAQ,UAAU,MAAM,IAAI;CAClC,IAAI,CAAC,OACH,OAAO;EAAE,IAAI;EAAO;EAAM;CAAK;CAEjC,OAAO;EACL,IAAI;EACJ;EACA;EACA;EACA,aAAa,aAAa,KAAK;EAC/B,SAAS,QAAQ,MAAM,IAAI;CAC7B;AACF"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { p as CLI_NAME } from "./lease-DS1SX8U_.mjs";
|
|
2
|
+
import { n as CEDAR_PG_TASK_ACQUIRE_TEST, t as CEDAR_PG_TASK_ACQUIRE_DEV } from "./tasks-D5iWIdlo.mjs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
//#region src/adapters/child.ts
|
|
9
|
+
/** Attached child: inherit stdio, resolve with exit code (signal → 1). */
|
|
10
|
+
function runAttached(command, args, options = {}) {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const child = spawn(command, args, {
|
|
13
|
+
stdio: "inherit",
|
|
14
|
+
cwd: options.cwd,
|
|
15
|
+
env: options.env,
|
|
16
|
+
shell: options.shell
|
|
17
|
+
});
|
|
18
|
+
child.once("error", reject);
|
|
19
|
+
child.once("exit", (code, signal) => {
|
|
20
|
+
resolve(signal ? 1 : code ?? 1);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/adapters/status-format.ts
|
|
26
|
+
/** Human-readable lines for the Vite panel / `cedarpg status`. */
|
|
27
|
+
function formatDevStatus(status) {
|
|
28
|
+
if (!status.ok) {
|
|
29
|
+
const task = status.mode === "test" ? CEDAR_PG_TASK_ACQUIRE_TEST : CEDAR_PG_TASK_ACQUIRE_DEV;
|
|
30
|
+
return [`${CLI_NAME}: no ${status.mode} lease at ${status.root}`, ` run \`${CLI_NAME} acquire --mode=${status.mode}\` (or depend on ${task})`];
|
|
31
|
+
}
|
|
32
|
+
const { lease, databaseUrl, envPath } = status;
|
|
33
|
+
return [
|
|
34
|
+
`${CLI_NAME}: ${lease.databaseName} (${lease.repoSlug}/${lease.worktreeSlug} ${lease.mode})`,
|
|
35
|
+
` port ${lease.port}`,
|
|
36
|
+
` DATABASE_URL ${databaseUrl}`,
|
|
37
|
+
` env ${envPath}`
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/adapters/studio.ts
|
|
42
|
+
const STUDIO_PACKAGE = {
|
|
43
|
+
prisma: "prisma",
|
|
44
|
+
drizzle: "drizzle-kit"
|
|
45
|
+
};
|
|
46
|
+
const AUTO_ORDER = ["prisma", "drizzle"];
|
|
47
|
+
function readPackageJson(dir) {
|
|
48
|
+
const file = join(dir, "package.json");
|
|
49
|
+
if (!existsSync(file)) return null;
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function hasDep(pkg, name) {
|
|
57
|
+
if (!pkg) return false;
|
|
58
|
+
return Boolean(pkg.dependencies?.[name] || pkg.devDependencies?.[name] || pkg.optionalDependencies?.[name]);
|
|
59
|
+
}
|
|
60
|
+
function tryResolveBin(dir, packageName) {
|
|
61
|
+
try {
|
|
62
|
+
const pkgJsonPath = createRequire(pathToFileURL(join(dir, "package.json")).href).resolve(`${packageName}/package.json`);
|
|
63
|
+
const binField = JSON.parse(readFileSync(pkgJsonPath, "utf8")).bin;
|
|
64
|
+
let rel;
|
|
65
|
+
if (typeof binField === "string") rel = binField;
|
|
66
|
+
else if (binField && typeof binField === "object") rel = binField[packageName] ?? Object.values(binField)[0];
|
|
67
|
+
if (!rel) return null;
|
|
68
|
+
const abs = join(dirname(pkgJsonPath), rel);
|
|
69
|
+
return existsSync(abs) ? abs : null;
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function npxStudio(kind, cwd) {
|
|
75
|
+
return {
|
|
76
|
+
kind,
|
|
77
|
+
command: "npx",
|
|
78
|
+
args: [STUDIO_PACKAGE[kind], "studio"],
|
|
79
|
+
cwd,
|
|
80
|
+
shell: true
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** Local bin, else declared dep → npx, else null. Resolves the bin at most once. */
|
|
84
|
+
function studioAt(kind, dir) {
|
|
85
|
+
const pkg = STUDIO_PACKAGE[kind];
|
|
86
|
+
const bin = tryResolveBin(dir, pkg);
|
|
87
|
+
if (bin) return {
|
|
88
|
+
kind,
|
|
89
|
+
command: bin,
|
|
90
|
+
args: ["studio"],
|
|
91
|
+
cwd: dir,
|
|
92
|
+
shell: false
|
|
93
|
+
};
|
|
94
|
+
if (hasDep(readPackageJson(dir), pkg)) return npxStudio(kind, dir);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
function isInside(dir, ancestor) {
|
|
98
|
+
const rel = relative(ancestor, dir);
|
|
99
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
|
|
100
|
+
}
|
|
101
|
+
/** `start` up to `stop` (inclusive) when `start` is inside the worktree; otherwise only `start`. */
|
|
102
|
+
function searchDirs(start, stop) {
|
|
103
|
+
if (!isInside(start, stop)) return [start];
|
|
104
|
+
const dirs = [];
|
|
105
|
+
let dir = start;
|
|
106
|
+
for (;;) {
|
|
107
|
+
dirs.push(dir);
|
|
108
|
+
if (dir === stop) return dirs;
|
|
109
|
+
const parent = dirname(dir);
|
|
110
|
+
if (parent === dir) return dirs;
|
|
111
|
+
dir = parent;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Detect Prisma Studio or Drizzle Kit Studio, walking from `cwd` up to the worktree `root`.
|
|
116
|
+
*
|
|
117
|
+
* Auto: nearest directory wins, prisma before drizzle in that directory; no npx fallback.
|
|
118
|
+
* Forced `prefer`: same nearest walk for that kind only, then npx at `cwd`.
|
|
119
|
+
*/
|
|
120
|
+
function detectStudio(options) {
|
|
121
|
+
const stop = resolve(options.root);
|
|
122
|
+
const start = resolve(options.cwd ?? options.root);
|
|
123
|
+
const dirs = searchDirs(start, stop);
|
|
124
|
+
const kinds = options.prefer ? [options.prefer] : AUTO_ORDER;
|
|
125
|
+
for (const dir of dirs) for (const kind of kinds) {
|
|
126
|
+
const hit = studioAt(kind, dir);
|
|
127
|
+
if (hit) return hit;
|
|
128
|
+
}
|
|
129
|
+
return options.prefer ? npxStudio(options.prefer, start) : null;
|
|
130
|
+
}
|
|
131
|
+
function spawnStudio(options, spawnOpts) {
|
|
132
|
+
const { databaseUrl, studio } = options;
|
|
133
|
+
return spawn(studio.command, studio.args, {
|
|
134
|
+
cwd: studio.cwd,
|
|
135
|
+
env: {
|
|
136
|
+
...process.env,
|
|
137
|
+
DATABASE_URL: databaseUrl
|
|
138
|
+
},
|
|
139
|
+
...spawnOpts,
|
|
140
|
+
shell: studio.shell
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Detached Studio for the Vite shortcut. Caller attaches `error` / `exit` on the
|
|
145
|
+
* returned process (spawn failures emit on a later tick).
|
|
146
|
+
*/
|
|
147
|
+
function openStudio(options) {
|
|
148
|
+
const child = spawnStudio(options, {
|
|
149
|
+
detached: true,
|
|
150
|
+
stdio: "ignore"
|
|
151
|
+
});
|
|
152
|
+
child.unref();
|
|
153
|
+
return child;
|
|
154
|
+
}
|
|
155
|
+
/** Attached Studio for `cedarpg studio`: inherit stdio, resolve with the child's exit code. */
|
|
156
|
+
function runStudio(options) {
|
|
157
|
+
const { databaseUrl, studio } = options;
|
|
158
|
+
return runAttached(studio.command, studio.args, {
|
|
159
|
+
cwd: studio.cwd,
|
|
160
|
+
env: {
|
|
161
|
+
...process.env,
|
|
162
|
+
DATABASE_URL: databaseUrl
|
|
163
|
+
},
|
|
164
|
+
shell: studio.shell
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function studioChildRunning(child) {
|
|
168
|
+
return Boolean(child && child.exitCode === null && !child.killed);
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
export { formatDevStatus as a, studioChildRunning as i, openStudio as n, runAttached as o, runStudio as r, detectStudio as t };
|
|
172
|
+
|
|
173
|
+
//# sourceMappingURL=studio-DIFw1qWC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio-DIFw1qWC.mjs","names":[],"sources":["../src/adapters/child.ts","../src/adapters/status-format.ts","../src/adapters/studio.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\n\nexport type RunAttachedOptions = {\n cwd?: string;\n env?: NodeJS.ProcessEnv;\n shell?: boolean;\n};\n\n/** Attached child: inherit stdio, resolve with exit code (signal → 1). */\nexport function runAttached(\n command: string,\n args: string[],\n options: RunAttachedOptions = {},\n): Promise<number> {\n return new Promise((resolve, reject) => {\n const child = spawn(command, args, {\n stdio: \"inherit\",\n cwd: options.cwd,\n env: options.env,\n shell: options.shell,\n });\n child.once(\"error\", reject);\n child.once(\"exit\", (code, signal) => {\n resolve(signal ? 1 : (code ?? 1));\n });\n });\n}\n","import { CLI_NAME } from \"../core/constants.ts\";\nimport type { DevStatus } from \"../core/status.ts\";\nimport { CEDAR_PG_TASK_ACQUIRE_DEV, CEDAR_PG_TASK_ACQUIRE_TEST } from \"./tasks.ts\";\n\n/** Human-readable lines for the Vite panel / `cedarpg status`. */\nexport function formatDevStatus(status: DevStatus): string[] {\n if (!status.ok) {\n const task = status.mode === \"test\" ? CEDAR_PG_TASK_ACQUIRE_TEST : CEDAR_PG_TASK_ACQUIRE_DEV;\n return [\n `${CLI_NAME}: no ${status.mode} lease at ${status.root}`,\n ` run \\`${CLI_NAME} acquire --mode=${status.mode}\\` (or depend on ${task})`,\n ];\n }\n const { lease, databaseUrl, envPath } = status;\n return [\n `${CLI_NAME}: ${lease.databaseName} (${lease.repoSlug}/${lease.worktreeSlug} ${lease.mode})`,\n ` port ${lease.port}`,\n ` DATABASE_URL ${databaseUrl}`,\n ` env ${envPath}`,\n ];\n}\n","import { createRequire } from \"node:module\";\nimport { spawn, type ChildProcess, type SpawnOptions } from \"node:child_process\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, relative, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { runAttached } from \"./child.ts\";\n\nexport type StudioKind = \"prisma\" | \"drizzle\";\n\nconst STUDIO_PACKAGE: Record<StudioKind, string> = {\n prisma: \"prisma\",\n drizzle: \"drizzle-kit\",\n};\n\nconst AUTO_ORDER: StudioKind[] = [\"prisma\", \"drizzle\"];\n\nexport type DetectStudioOptions = {\n /** Worktree / lease root — directory walk stops here. */\n root: string;\n /** App package to start the walk (Nx `apps/…`). Defaults to `root`. */\n cwd?: string;\n /** Force a kind. Omit to auto-detect (nearest package; prisma if both). */\n prefer?: StudioKind;\n};\n\nexport type DetectedStudio = {\n kind: StudioKind;\n command: string;\n args: string[];\n /** Directory to spawn in (where the ORM package / config was found). */\n cwd: string;\n /** True when falling back to `npx`. */\n shell: boolean;\n};\n\ntype PkgJson = {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n optionalDependencies?: Record<string, string>;\n};\n\nfunction readPackageJson(dir: string): PkgJson | null {\n const file = join(dir, \"package.json\");\n if (!existsSync(file)) return null;\n try {\n return JSON.parse(readFileSync(file, \"utf8\")) as PkgJson;\n } catch {\n return null;\n }\n}\n\nfunction hasDep(pkg: PkgJson | null, name: string): boolean {\n if (!pkg) return false;\n return Boolean(\n pkg.dependencies?.[name] || pkg.devDependencies?.[name] || pkg.optionalDependencies?.[name],\n );\n}\n\nfunction tryResolveBin(dir: string, packageName: string): string | null {\n try {\n const require = createRequire(pathToFileURL(join(dir, \"package.json\")).href);\n const pkgJsonPath = require.resolve(`${packageName}/package.json`);\n const pkg = JSON.parse(readFileSync(pkgJsonPath, \"utf8\")) as {\n bin?: string | Record<string, string>;\n };\n const binField = pkg.bin;\n let rel: string | undefined;\n if (typeof binField === \"string\") rel = binField;\n else if (binField && typeof binField === \"object\") {\n rel = binField[packageName] ?? Object.values(binField)[0];\n }\n if (!rel) return null;\n const abs = join(dirname(pkgJsonPath), rel);\n return existsSync(abs) ? abs : null;\n } catch {\n return null;\n }\n}\n\nfunction npxStudio(kind: StudioKind, cwd: string): DetectedStudio {\n return {\n kind,\n command: \"npx\",\n args: [STUDIO_PACKAGE[kind], \"studio\"],\n cwd,\n shell: true,\n };\n}\n\n/** Local bin, else declared dep → npx, else null. Resolves the bin at most once. */\nfunction studioAt(kind: StudioKind, dir: string): DetectedStudio | null {\n const pkg = STUDIO_PACKAGE[kind];\n const bin = tryResolveBin(dir, pkg);\n if (bin) return { kind, command: bin, args: [\"studio\"], cwd: dir, shell: false };\n if (hasDep(readPackageJson(dir), pkg)) return npxStudio(kind, dir);\n return null;\n}\n\nfunction isInside(dir: string, ancestor: string): boolean {\n const rel = relative(ancestor, dir);\n return rel === \"\" || (!rel.startsWith(\"..\") && !isAbsolute(rel));\n}\n\n/** `start` up to `stop` (inclusive) when `start` is inside the worktree; otherwise only `start`. */\nfunction searchDirs(start: string, stop: string): string[] {\n if (!isInside(start, stop)) return [start];\n const dirs: string[] = [];\n let dir = start;\n for (;;) {\n dirs.push(dir);\n if (dir === stop) return dirs;\n const parent = dirname(dir);\n if (parent === dir) return dirs;\n dir = parent;\n }\n}\n\n/**\n * Detect Prisma Studio or Drizzle Kit Studio, walking from `cwd` up to the worktree `root`.\n *\n * Auto: nearest directory wins, prisma before drizzle in that directory; no npx fallback.\n * Forced `prefer`: same nearest walk for that kind only, then npx at `cwd`.\n */\nexport function detectStudio(options: DetectStudioOptions): DetectedStudio | null {\n const stop = resolve(options.root);\n const start = resolve(options.cwd ?? options.root);\n const dirs = searchDirs(start, stop);\n const kinds = options.prefer ? [options.prefer] : AUTO_ORDER;\n\n for (const dir of dirs) {\n for (const kind of kinds) {\n const hit = studioAt(kind, dir);\n if (hit) return hit;\n }\n }\n return options.prefer ? npxStudio(options.prefer, start) : null;\n}\n\nexport type SpawnStudioOptions = {\n databaseUrl: string;\n studio: DetectedStudio;\n};\n\nfunction spawnStudio(options: SpawnStudioOptions, spawnOpts: SpawnOptions): ChildProcess {\n const { databaseUrl, studio } = options;\n return spawn(studio.command, studio.args, {\n cwd: studio.cwd,\n env: { ...process.env, DATABASE_URL: databaseUrl },\n ...spawnOpts,\n shell: studio.shell,\n });\n}\n\n/**\n * Detached Studio for the Vite shortcut. Caller attaches `error` / `exit` on the\n * returned process (spawn failures emit on a later tick).\n */\nexport function openStudio(options: SpawnStudioOptions): ChildProcess {\n const child = spawnStudio(options, { detached: true, stdio: \"ignore\" });\n child.unref();\n return child;\n}\n\n/** Attached Studio for `cedarpg studio`: inherit stdio, resolve with the child's exit code. */\nexport function runStudio(options: SpawnStudioOptions): Promise<number> {\n const { databaseUrl, studio } = options;\n return runAttached(studio.command, studio.args, {\n cwd: studio.cwd,\n env: { ...process.env, DATABASE_URL: databaseUrl },\n shell: studio.shell,\n });\n}\n\nexport function studioChildRunning(child: ChildProcess | undefined): boolean {\n return Boolean(child && child.exitCode === null && !child.killed);\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,YACd,SACA,MACA,UAA8B,CAAC,GACd;CACjB,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,QAAQ,MAAM,SAAS,MAAM;GACjC,OAAO;GACP,KAAK,QAAQ;GACb,KAAK,QAAQ;GACb,OAAO,QAAQ;EACjB,CAAC;EACD,MAAM,KAAK,SAAS,MAAM;EAC1B,MAAM,KAAK,SAAS,MAAM,WAAW;GACnC,QAAQ,SAAS,IAAK,QAAQ,CAAE;EAClC,CAAC;CACH,CAAC;AACH;;;;ACrBA,SAAgB,gBAAgB,QAA6B;CAC3D,IAAI,CAAC,OAAO,IAAI;EACd,MAAM,OAAO,OAAO,SAAS,SAAS,6BAA6B;EACnE,OAAO,CACL,GAAG,SAAS,OAAO,OAAO,KAAK,YAAY,OAAO,QAClD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AY,SAA6B,WAAuC;CACvF,MAAM,EAAE,aAAa,WAAW;CAChC,OAAO,MAAM,OAAO,SAAS,OAAO,MAAM;EACxC,KAAK,OAAO;EACZ,KAAK;GAAE,GAAG,QAAQ;GAAK,cAAc;EAAY;EACjD,GAAG;EACH,OAAO,OAAO;CAChB,CAAC;AACH;;;;;AAMA,SAAgB,WAAW,SAA2C;CACpE,MAAM,QAAQ,YAAY,SAAS;EAAE,UAAU;EAAM,OAAO;CAAS,CAAC;CACtE,MAAM,MAAM;CACZ,OAAO;AACT;;AAGA,SAAgB,UAAU,SAA8C;CACtE,MAAM,EAAE,aAAa,WAAW;CAChC,OAAO,YAAY,OAAO,SAAS,OAAO,MAAM;EAC9C,KAAK,OAAO;EACZ,KAAK;GAAE,GAAG,QAAQ;GAAK,cAAc;EAAY;EACjD,OAAO,OAAO;CAChB,CAAC;AACH;AAEA,SAAgB,mBAAmB,OAA0C;CAC3E,OAAO,QAAQ,SAAS,MAAM,aAAa,QAAQ,CAAC,MAAM,MAAM;AAClE"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
const require_lease = require("./lease-WlmOnNDi.cjs");
|
|
2
|
+
const require_tasks = require("./tasks-CNHvvlsN.cjs");
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
let node_child_process = require("node:child_process");
|
|
6
|
+
let node_module = require("node:module");
|
|
7
|
+
let node_url = require("node:url");
|
|
8
|
+
//#region src/adapters/child.ts
|
|
9
|
+
/** Attached child: inherit stdio, resolve with exit code (signal → 1). */
|
|
10
|
+
function runAttached(command, args, options = {}) {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const child = (0, node_child_process.spawn)(command, args, {
|
|
13
|
+
stdio: "inherit",
|
|
14
|
+
cwd: options.cwd,
|
|
15
|
+
env: options.env,
|
|
16
|
+
shell: options.shell
|
|
17
|
+
});
|
|
18
|
+
child.once("error", reject);
|
|
19
|
+
child.once("exit", (code, signal) => {
|
|
20
|
+
resolve(signal ? 1 : code ?? 1);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/adapters/status-format.ts
|
|
26
|
+
/** Human-readable lines for the Vite panel / `cedarpg status`. */
|
|
27
|
+
function formatDevStatus(status) {
|
|
28
|
+
if (!status.ok) {
|
|
29
|
+
const task = status.mode === "test" ? require_tasks.CEDAR_PG_TASK_ACQUIRE_TEST : require_tasks.CEDAR_PG_TASK_ACQUIRE_DEV;
|
|
30
|
+
return [`${require_lease.CLI_NAME}: no ${status.mode} lease at ${status.root}`, ` run \`${require_lease.CLI_NAME} acquire --mode=${status.mode}\` (or depend on ${task})`];
|
|
31
|
+
}
|
|
32
|
+
const { lease, databaseUrl, envPath } = status;
|
|
33
|
+
return [
|
|
34
|
+
`${require_lease.CLI_NAME}: ${lease.databaseName} (${lease.repoSlug}/${lease.worktreeSlug} ${lease.mode})`,
|
|
35
|
+
` port ${lease.port}`,
|
|
36
|
+
` DATABASE_URL ${databaseUrl}`,
|
|
37
|
+
` env ${envPath}`
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/adapters/studio.ts
|
|
42
|
+
const STUDIO_PACKAGE = {
|
|
43
|
+
prisma: "prisma",
|
|
44
|
+
drizzle: "drizzle-kit"
|
|
45
|
+
};
|
|
46
|
+
const AUTO_ORDER = ["prisma", "drizzle"];
|
|
47
|
+
function readPackageJson(dir) {
|
|
48
|
+
const file = (0, node_path.join)(dir, "package.json");
|
|
49
|
+
if (!(0, node_fs.existsSync)(file)) return null;
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse((0, node_fs.readFileSync)(file, "utf8"));
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function hasDep(pkg, name) {
|
|
57
|
+
if (!pkg) return false;
|
|
58
|
+
return Boolean(pkg.dependencies?.[name] || pkg.devDependencies?.[name] || pkg.optionalDependencies?.[name]);
|
|
59
|
+
}
|
|
60
|
+
function tryResolveBin(dir, packageName) {
|
|
61
|
+
try {
|
|
62
|
+
const pkgJsonPath = (0, node_module.createRequire)((0, node_url.pathToFileURL)((0, node_path.join)(dir, "package.json")).href).resolve(`${packageName}/package.json`);
|
|
63
|
+
const binField = JSON.parse((0, node_fs.readFileSync)(pkgJsonPath, "utf8")).bin;
|
|
64
|
+
let rel;
|
|
65
|
+
if (typeof binField === "string") rel = binField;
|
|
66
|
+
else if (binField && typeof binField === "object") rel = binField[packageName] ?? Object.values(binField)[0];
|
|
67
|
+
if (!rel) return null;
|
|
68
|
+
const abs = (0, node_path.join)((0, node_path.dirname)(pkgJsonPath), rel);
|
|
69
|
+
return (0, node_fs.existsSync)(abs) ? abs : null;
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function npxStudio(kind, cwd) {
|
|
75
|
+
return {
|
|
76
|
+
kind,
|
|
77
|
+
command: "npx",
|
|
78
|
+
args: [STUDIO_PACKAGE[kind], "studio"],
|
|
79
|
+
cwd,
|
|
80
|
+
shell: true
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** Local bin, else declared dep → npx, else null. Resolves the bin at most once. */
|
|
84
|
+
function studioAt(kind, dir) {
|
|
85
|
+
const pkg = STUDIO_PACKAGE[kind];
|
|
86
|
+
const bin = tryResolveBin(dir, pkg);
|
|
87
|
+
if (bin) return {
|
|
88
|
+
kind,
|
|
89
|
+
command: bin,
|
|
90
|
+
args: ["studio"],
|
|
91
|
+
cwd: dir,
|
|
92
|
+
shell: false
|
|
93
|
+
};
|
|
94
|
+
if (hasDep(readPackageJson(dir), pkg)) return npxStudio(kind, dir);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
function isInside(dir, ancestor) {
|
|
98
|
+
const rel = (0, node_path.relative)(ancestor, dir);
|
|
99
|
+
return rel === "" || !rel.startsWith("..") && !(0, node_path.isAbsolute)(rel);
|
|
100
|
+
}
|
|
101
|
+
/** `start` up to `stop` (inclusive) when `start` is inside the worktree; otherwise only `start`. */
|
|
102
|
+
function searchDirs(start, stop) {
|
|
103
|
+
if (!isInside(start, stop)) return [start];
|
|
104
|
+
const dirs = [];
|
|
105
|
+
let dir = start;
|
|
106
|
+
for (;;) {
|
|
107
|
+
dirs.push(dir);
|
|
108
|
+
if (dir === stop) return dirs;
|
|
109
|
+
const parent = (0, node_path.dirname)(dir);
|
|
110
|
+
if (parent === dir) return dirs;
|
|
111
|
+
dir = parent;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Detect Prisma Studio or Drizzle Kit Studio, walking from `cwd` up to the worktree `root`.
|
|
116
|
+
*
|
|
117
|
+
* Auto: nearest directory wins, prisma before drizzle in that directory; no npx fallback.
|
|
118
|
+
* Forced `prefer`: same nearest walk for that kind only, then npx at `cwd`.
|
|
119
|
+
*/
|
|
120
|
+
function detectStudio(options) {
|
|
121
|
+
const stop = (0, node_path.resolve)(options.root);
|
|
122
|
+
const start = (0, node_path.resolve)(options.cwd ?? options.root);
|
|
123
|
+
const dirs = searchDirs(start, stop);
|
|
124
|
+
const kinds = options.prefer ? [options.prefer] : AUTO_ORDER;
|
|
125
|
+
for (const dir of dirs) for (const kind of kinds) {
|
|
126
|
+
const hit = studioAt(kind, dir);
|
|
127
|
+
if (hit) return hit;
|
|
128
|
+
}
|
|
129
|
+
return options.prefer ? npxStudio(options.prefer, start) : null;
|
|
130
|
+
}
|
|
131
|
+
function spawnStudio(options, spawnOpts) {
|
|
132
|
+
const { databaseUrl, studio } = options;
|
|
133
|
+
return (0, node_child_process.spawn)(studio.command, studio.args, {
|
|
134
|
+
cwd: studio.cwd,
|
|
135
|
+
env: {
|
|
136
|
+
...process.env,
|
|
137
|
+
DATABASE_URL: databaseUrl
|
|
138
|
+
},
|
|
139
|
+
...spawnOpts,
|
|
140
|
+
shell: studio.shell
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Detached Studio for the Vite shortcut. Caller attaches `error` / `exit` on the
|
|
145
|
+
* returned process (spawn failures emit on a later tick).
|
|
146
|
+
*/
|
|
147
|
+
function openStudio(options) {
|
|
148
|
+
const child = spawnStudio(options, {
|
|
149
|
+
detached: true,
|
|
150
|
+
stdio: "ignore"
|
|
151
|
+
});
|
|
152
|
+
child.unref();
|
|
153
|
+
return child;
|
|
154
|
+
}
|
|
155
|
+
/** Attached Studio for `cedarpg studio`: inherit stdio, resolve with the child's exit code. */
|
|
156
|
+
function runStudio(options) {
|
|
157
|
+
const { databaseUrl, studio } = options;
|
|
158
|
+
return runAttached(studio.command, studio.args, {
|
|
159
|
+
cwd: studio.cwd,
|
|
160
|
+
env: {
|
|
161
|
+
...process.env,
|
|
162
|
+
DATABASE_URL: databaseUrl
|
|
163
|
+
},
|
|
164
|
+
shell: studio.shell
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function studioChildRunning(child) {
|
|
168
|
+
return Boolean(child && child.exitCode === null && !child.killed);
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
Object.defineProperty(exports, "detectStudio", {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
get: function() {
|
|
174
|
+
return detectStudio;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
Object.defineProperty(exports, "formatDevStatus", {
|
|
178
|
+
enumerable: true,
|
|
179
|
+
get: function() {
|
|
180
|
+
return formatDevStatus;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
Object.defineProperty(exports, "openStudio", {
|
|
184
|
+
enumerable: true,
|
|
185
|
+
get: function() {
|
|
186
|
+
return openStudio;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
Object.defineProperty(exports, "runAttached", {
|
|
190
|
+
enumerable: true,
|
|
191
|
+
get: function() {
|
|
192
|
+
return runAttached;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
Object.defineProperty(exports, "runStudio", {
|
|
196
|
+
enumerable: true,
|
|
197
|
+
get: function() {
|
|
198
|
+
return runStudio;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
Object.defineProperty(exports, "studioChildRunning", {
|
|
202
|
+
enumerable: true,
|
|
203
|
+
get: function() {
|
|
204
|
+
return studioChildRunning;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
//# sourceMappingURL=studio-oJE30_PO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio-oJE30_PO.cjs","names":["CEDAR_PG_TASK_ACQUIRE_TEST","CEDAR_PG_TASK_ACQUIRE_DEV","CLI_NAME"],"sources":["../src/adapters/child.ts","../src/adapters/status-format.ts","../src/adapters/studio.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\n\nexport type RunAttachedOptions = {\n cwd?: string;\n env?: NodeJS.ProcessEnv;\n shell?: boolean;\n};\n\n/** Attached child: inherit stdio, resolve with exit code (signal → 1). */\nexport function runAttached(\n command: string,\n args: string[],\n options: RunAttachedOptions = {},\n): Promise<number> {\n return new Promise((resolve, reject) => {\n const child = spawn(command, args, {\n stdio: \"inherit\",\n cwd: options.cwd,\n env: options.env,\n shell: options.shell,\n });\n child.once(\"error\", reject);\n child.once(\"exit\", (code, signal) => {\n resolve(signal ? 1 : (code ?? 1));\n });\n });\n}\n","import { CLI_NAME } from \"../core/constants.ts\";\nimport type { DevStatus } from \"../core/status.ts\";\nimport { CEDAR_PG_TASK_ACQUIRE_DEV, CEDAR_PG_TASK_ACQUIRE_TEST } from \"./tasks.ts\";\n\n/** Human-readable lines for the Vite panel / `cedarpg status`. */\nexport function formatDevStatus(status: DevStatus): string[] {\n if (!status.ok) {\n const task = status.mode === \"test\" ? CEDAR_PG_TASK_ACQUIRE_TEST : CEDAR_PG_TASK_ACQUIRE_DEV;\n return [\n `${CLI_NAME}: no ${status.mode} lease at ${status.root}`,\n ` run \\`${CLI_NAME} acquire --mode=${status.mode}\\` (or depend on ${task})`,\n ];\n }\n const { lease, databaseUrl, envPath } = status;\n return [\n `${CLI_NAME}: ${lease.databaseName} (${lease.repoSlug}/${lease.worktreeSlug} ${lease.mode})`,\n ` port ${lease.port}`,\n ` DATABASE_URL ${databaseUrl}`,\n ` env ${envPath}`,\n ];\n}\n","import { createRequire } from \"node:module\";\nimport { spawn, type ChildProcess, type SpawnOptions } from \"node:child_process\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, relative, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { runAttached } from \"./child.ts\";\n\nexport type StudioKind = \"prisma\" | \"drizzle\";\n\nconst STUDIO_PACKAGE: Record<StudioKind, string> = {\n prisma: \"prisma\",\n drizzle: \"drizzle-kit\",\n};\n\nconst AUTO_ORDER: StudioKind[] = [\"prisma\", \"drizzle\"];\n\nexport type DetectStudioOptions = {\n /** Worktree / lease root — directory walk stops here. */\n root: string;\n /** App package to start the walk (Nx `apps/…`). Defaults to `root`. */\n cwd?: string;\n /** Force a kind. Omit to auto-detect (nearest package; prisma if both). */\n prefer?: StudioKind;\n};\n\nexport type DetectedStudio = {\n kind: StudioKind;\n command: string;\n args: string[];\n /** Directory to spawn in (where the ORM package / config was found). */\n cwd: string;\n /** True when falling back to `npx`. */\n shell: boolean;\n};\n\ntype PkgJson = {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n optionalDependencies?: Record<string, string>;\n};\n\nfunction readPackageJson(dir: string): PkgJson | null {\n const file = join(dir, \"package.json\");\n if (!existsSync(file)) return null;\n try {\n return JSON.parse(readFileSync(file, \"utf8\")) as PkgJson;\n } catch {\n return null;\n }\n}\n\nfunction hasDep(pkg: PkgJson | null, name: string): boolean {\n if (!pkg) return false;\n return Boolean(\n pkg.dependencies?.[name] || pkg.devDependencies?.[name] || pkg.optionalDependencies?.[name],\n );\n}\n\nfunction tryResolveBin(dir: string, packageName: string): string | null {\n try {\n const require = createRequire(pathToFileURL(join(dir, \"package.json\")).href);\n const pkgJsonPath = require.resolve(`${packageName}/package.json`);\n const pkg = JSON.parse(readFileSync(pkgJsonPath, \"utf8\")) as {\n bin?: string | Record<string, string>;\n };\n const binField = pkg.bin;\n let rel: string | undefined;\n if (typeof binField === \"string\") rel = binField;\n else if (binField && typeof binField === \"object\") {\n rel = binField[packageName] ?? Object.values(binField)[0];\n }\n if (!rel) return null;\n const abs = join(dirname(pkgJsonPath), rel);\n return existsSync(abs) ? abs : null;\n } catch {\n return null;\n }\n}\n\nfunction npxStudio(kind: StudioKind, cwd: string): DetectedStudio {\n return {\n kind,\n command: \"npx\",\n args: [STUDIO_PACKAGE[kind], \"studio\"],\n cwd,\n shell: true,\n };\n}\n\n/** Local bin, else declared dep → npx, else null. Resolves the bin at most once. */\nfunction studioAt(kind: StudioKind, dir: string): DetectedStudio | null {\n const pkg = STUDIO_PACKAGE[kind];\n const bin = tryResolveBin(dir, pkg);\n if (bin) return { kind, command: bin, args: [\"studio\"], cwd: dir, shell: false };\n if (hasDep(readPackageJson(dir), pkg)) return npxStudio(kind, dir);\n return null;\n}\n\nfunction isInside(dir: string, ancestor: string): boolean {\n const rel = relative(ancestor, dir);\n return rel === \"\" || (!rel.startsWith(\"..\") && !isAbsolute(rel));\n}\n\n/** `start` up to `stop` (inclusive) when `start` is inside the worktree; otherwise only `start`. */\nfunction searchDirs(start: string, stop: string): string[] {\n if (!isInside(start, stop)) return [start];\n const dirs: string[] = [];\n let dir = start;\n for (;;) {\n dirs.push(dir);\n if (dir === stop) return dirs;\n const parent = dirname(dir);\n if (parent === dir) return dirs;\n dir = parent;\n }\n}\n\n/**\n * Detect Prisma Studio or Drizzle Kit Studio, walking from `cwd` up to the worktree `root`.\n *\n * Auto: nearest directory wins, prisma before drizzle in that directory; no npx fallback.\n * Forced `prefer`: same nearest walk for that kind only, then npx at `cwd`.\n */\nexport function detectStudio(options: DetectStudioOptions): DetectedStudio | null {\n const stop = resolve(options.root);\n const start = resolve(options.cwd ?? options.root);\n const dirs = searchDirs(start, stop);\n const kinds = options.prefer ? [options.prefer] : AUTO_ORDER;\n\n for (const dir of dirs) {\n for (const kind of kinds) {\n const hit = studioAt(kind, dir);\n if (hit) return hit;\n }\n }\n return options.prefer ? npxStudio(options.prefer, start) : null;\n}\n\nexport type SpawnStudioOptions = {\n databaseUrl: string;\n studio: DetectedStudio;\n};\n\nfunction spawnStudio(options: SpawnStudioOptions, spawnOpts: SpawnOptions): ChildProcess {\n const { databaseUrl, studio } = options;\n return spawn(studio.command, studio.args, {\n cwd: studio.cwd,\n env: { ...process.env, DATABASE_URL: databaseUrl },\n ...spawnOpts,\n shell: studio.shell,\n });\n}\n\n/**\n * Detached Studio for the Vite shortcut. Caller attaches `error` / `exit` on the\n * returned process (spawn failures emit on a later tick).\n */\nexport function openStudio(options: SpawnStudioOptions): ChildProcess {\n const child = spawnStudio(options, { detached: true, stdio: \"ignore\" });\n child.unref();\n return child;\n}\n\n/** Attached Studio for `cedarpg studio`: inherit stdio, resolve with the child's exit code. */\nexport function runStudio(options: SpawnStudioOptions): Promise<number> {\n const { databaseUrl, studio } = options;\n return runAttached(studio.command, studio.args, {\n cwd: studio.cwd,\n env: { ...process.env, DATABASE_URL: databaseUrl },\n shell: studio.shell,\n });\n}\n\nexport function studioChildRunning(child: ChildProcess | undefined): boolean {\n return Boolean(child && child.exitCode === null && !child.killed);\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,YACd,SACA,MACA,UAA8B,CAAC,GACd;CACjB,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,SAAA,GAAA,mBAAA,MAAA,CAAc,SAAS,MAAM;GACjC,OAAO;GACP,KAAK,QAAQ;GACb,KAAK,QAAQ;GACb,OAAO,QAAQ;EACjB,CAAC;EACD,MAAM,KAAK,SAAS,MAAM;EAC1B,MAAM,KAAK,SAAS,MAAM,WAAW;GACnC,QAAQ,SAAS,IAAK,QAAQ,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ease-WlmOnNDi.cjs");
|
|
2
|
+
//#region src/adapters/tasks.ts
|
|
3
|
+
/** Shared CLI command strings and lifecycle target defs for Vite+ / Nx. */
|
|
4
|
+
const CEDAR_PG_TASK_ACQUIRE_DEV = "db:acquire";
|
|
5
|
+
const CEDAR_PG_TASK_ACQUIRE_TEST = "db:acquire-test";
|
|
6
|
+
const CEDAR_PG_TASK_DISPOSE_TEST = "db:dispose-test";
|
|
7
|
+
function cedarPgCommands(bin = require_lease.CLI_NAME) {
|
|
8
|
+
return {
|
|
9
|
+
acquireDev: `${bin} acquire --mode=dev`,
|
|
10
|
+
acquireTest: `${bin} acquire --mode=test --print-env`,
|
|
11
|
+
disposeTest: `${bin} dispose --mode=test`
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function cedarPgLifecycleTargets(options = {}) {
|
|
15
|
+
const cmds = cedarPgCommands(options.bin ?? "cedarpg");
|
|
16
|
+
const targets = {
|
|
17
|
+
[CEDAR_PG_TASK_ACQUIRE_DEV]: {
|
|
18
|
+
command: cmds.acquireDev,
|
|
19
|
+
cache: false
|
|
20
|
+
},
|
|
21
|
+
[CEDAR_PG_TASK_ACQUIRE_TEST]: {
|
|
22
|
+
command: cmds.acquireTest,
|
|
23
|
+
cache: false
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
if (options.includeDisposeTest !== false) targets[CEDAR_PG_TASK_DISPOSE_TEST] = {
|
|
27
|
+
command: cmds.disposeTest,
|
|
28
|
+
cache: false
|
|
29
|
+
};
|
|
30
|
+
return targets;
|
|
31
|
+
}
|
|
32
|
+
function cedarPgRunCommand(mode, command, bin = require_lease.CLI_NAME) {
|
|
33
|
+
return `${bin} run --mode=${mode} -- ${command}`;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
Object.defineProperty(exports, "CEDAR_PG_TASK_ACQUIRE_DEV", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function() {
|
|
39
|
+
return CEDAR_PG_TASK_ACQUIRE_DEV;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "CEDAR_PG_TASK_ACQUIRE_TEST", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function() {
|
|
45
|
+
return CEDAR_PG_TASK_ACQUIRE_TEST;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "CEDAR_PG_TASK_DISPOSE_TEST", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function() {
|
|
51
|
+
return CEDAR_PG_TASK_DISPOSE_TEST;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "cedarPgLifecycleTargets", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function() {
|
|
57
|
+
return cedarPgLifecycleTargets;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "cedarPgRunCommand", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function() {
|
|
63
|
+
return cedarPgRunCommand;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=tasks-CNHvvlsN.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks-CNHvvlsN.cjs","names":["CLI_NAME"],"sources":["../src/adapters/tasks.ts"],"sourcesContent":["/** Shared CLI command strings and lifecycle target defs for Vite+ / Nx. */\n\nimport { CLI_NAME } from \"../core/constants.ts\";\nimport type { DbMode } from \"../core/naming.ts\";\n\nexport const CEDAR_PG_TASK_ACQUIRE_DEV = \"db:acquire\";\nexport const CEDAR_PG_TASK_ACQUIRE_TEST = \"db:acquire-test\";\nexport const CEDAR_PG_TASK_DISPOSE_TEST = \"db:dispose-test\";\n\nexport type CedarPgCommands = {\n acquireDev: string;\n acquireTest: string;\n disposeTest: string;\n};\n\nexport type CedarPgLifecycleTarget = {\n command: string;\n cache?: boolean;\n};\n\nexport type CedarPgLifecycleTargetsOptions = {\n bin?: string;\n /** Include dispose-test target (default: true). */\n includeDisposeTest?: boolean;\n};\n\nexport function cedarPgCommands(bin = CLI_NAME): CedarPgCommands {\n return {\n acquireDev: `${bin} acquire --mode=dev`,\n acquireTest: `${bin} acquire --mode=test --print-env`,\n disposeTest: `${bin} dispose --mode=test`,\n };\n}\n\nexport function cedarPgLifecycleTargets(\n options: CedarPgLifecycleTargetsOptions = {},\n): Record<string, CedarPgLifecycleTarget> {\n const cmds = cedarPgCommands(options.bin ?? CLI_NAME);\n const targets: Record<string, CedarPgLifecycleTarget> = {\n [CEDAR_PG_TASK_ACQUIRE_DEV]: { command: cmds.acquireDev, cache: false },\n [CEDAR_PG_TASK_ACQUIRE_TEST]: { command: cmds.acquireTest, cache: false },\n };\n if (options.includeDisposeTest !== false) {\n targets[CEDAR_PG_TASK_DISPOSE_TEST] = { command: cmds.disposeTest, cache: false };\n }\n return targets;\n}\n\nexport function cedarPgRunCommand(mode: DbMode, command: string, bin = CLI_NAME): string {\n return `${bin} run --mode=${mode} -- ${command}`;\n}\n"],"mappings":";;;AAKA,MAAa,4BAA4B;AACzC,MAAa,6BAA6B;AAC1C,MAAa,6BAA6B;AAmB1C,SAAgB,gBAAgB,MAAMA,cAAAA,UAA2B;CAC/D,OAAO;EACL,YAAY,GAAG,IAAI;EACnB,aAAa,GAAG,IAAI;EACpB,aAAa,GAAG,IAAI;CACtB;AACF;AAEA,SAAgB,wBACd,UAA0C,CAAC,GACH;CACxC,MAAM,OAAO,gBAAgB,QAAQ,OAAA,SAAe;CACpD,MAAM,UAAkD;GACrD,4BAA4B;GAAE,SAAS,KAAK;GAAY,OAAO;EAAM;GACrE,6BAA6B;GAAE,SAAS,KAAK;GAAa,OAAO;EAAM;CAC1E;CACA,IAAI,QAAQ,uBAAuB,OACjC,QAAQ,8BAA8B;EAAE,SAAS,KAAK;EAAa,OAAO;CAAM;CAElF,OAAO;AACT;AAEA,SAAgB,kBAAkB,MAAc,SAAiB,MAAMA,cAAAA,UAAkB;CACvF,OAAO,GAAG,IAAI,cAAc,KAAK,MAAM;AACzC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { t as DbMode } from "./naming-C2nGVxPk.mjs";
|
|
2
|
+
//#region src/adapters/tasks.d.ts
|
|
3
|
+
declare const CEDAR_PG_TASK_ACQUIRE_DEV = "db:acquire";
|
|
4
|
+
declare const CEDAR_PG_TASK_ACQUIRE_TEST = "db:acquire-test";
|
|
5
|
+
declare const CEDAR_PG_TASK_DISPOSE_TEST = "db:dispose-test";
|
|
6
|
+
type CedarPgLifecycleTarget = {
|
|
7
|
+
command: string;
|
|
8
|
+
cache?: boolean;
|
|
9
|
+
};
|
|
10
|
+
type CedarPgLifecycleTargetsOptions = {
|
|
11
|
+
bin?: string;
|
|
12
|
+
/** Include dispose-test target (default: true). */
|
|
13
|
+
includeDisposeTest?: boolean;
|
|
14
|
+
};
|
|
15
|
+
declare function cedarPgLifecycleTargets(options?: CedarPgLifecycleTargetsOptions): Record<string, CedarPgLifecycleTarget>;
|
|
16
|
+
declare function cedarPgRunCommand(mode: DbMode, command: string, bin?: string): string;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { CedarPgLifecycleTargetsOptions as a, CedarPgLifecycleTarget as i, CEDAR_PG_TASK_ACQUIRE_TEST as n, cedarPgLifecycleTargets as o, CEDAR_PG_TASK_DISPOSE_TEST as r, cedarPgRunCommand as s, CEDAR_PG_TASK_ACQUIRE_DEV as t };
|
|
19
|
+
//# sourceMappingURL=tasks-CjaZRi_G.d.mts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { p as CLI_NAME } from "./lease-DS1SX8U_.mjs";
|
|
2
|
+
//#region src/adapters/tasks.ts
|
|
3
|
+
/** Shared CLI command strings and lifecycle target defs for Vite+ / Nx. */
|
|
4
|
+
const CEDAR_PG_TASK_ACQUIRE_DEV = "db:acquire";
|
|
5
|
+
const CEDAR_PG_TASK_ACQUIRE_TEST = "db:acquire-test";
|
|
6
|
+
const CEDAR_PG_TASK_DISPOSE_TEST = "db:dispose-test";
|
|
7
|
+
function cedarPgCommands(bin = CLI_NAME) {
|
|
8
|
+
return {
|
|
9
|
+
acquireDev: `${bin} acquire --mode=dev`,
|
|
10
|
+
acquireTest: `${bin} acquire --mode=test --print-env`,
|
|
11
|
+
disposeTest: `${bin} dispose --mode=test`
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function cedarPgLifecycleTargets(options = {}) {
|
|
15
|
+
const cmds = cedarPgCommands(options.bin ?? "cedarpg");
|
|
16
|
+
const targets = {
|
|
17
|
+
[CEDAR_PG_TASK_ACQUIRE_DEV]: {
|
|
18
|
+
command: cmds.acquireDev,
|
|
19
|
+
cache: false
|
|
20
|
+
},
|
|
21
|
+
[CEDAR_PG_TASK_ACQUIRE_TEST]: {
|
|
22
|
+
command: cmds.acquireTest,
|
|
23
|
+
cache: false
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
if (options.includeDisposeTest !== false) targets[CEDAR_PG_TASK_DISPOSE_TEST] = {
|
|
27
|
+
command: cmds.disposeTest,
|
|
28
|
+
cache: false
|
|
29
|
+
};
|
|
30
|
+
return targets;
|
|
31
|
+
}
|
|
32
|
+
function cedarPgRunCommand(mode, command, bin = CLI_NAME) {
|
|
33
|
+
return `${bin} run --mode=${mode} -- ${command}`;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { cedarPgRunCommand as a, cedarPgLifecycleTargets as i, CEDAR_PG_TASK_ACQUIRE_TEST as n, CEDAR_PG_TASK_DISPOSE_TEST as r, CEDAR_PG_TASK_ACQUIRE_DEV as t };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=tasks-D5iWIdlo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks-D5iWIdlo.mjs","names":[],"sources":["../src/adapters/tasks.ts"],"sourcesContent":["/** Shared CLI command strings and lifecycle target defs for Vite+ / Nx. */\n\nimport { CLI_NAME } from \"../core/constants.ts\";\nimport type { DbMode } from \"../core/naming.ts\";\n\nexport const CEDAR_PG_TASK_ACQUIRE_DEV = \"db:acquire\";\nexport const CEDAR_PG_TASK_ACQUIRE_TEST = \"db:acquire-test\";\nexport const CEDAR_PG_TASK_DISPOSE_TEST = \"db:dispose-test\";\n\nexport type CedarPgCommands = {\n acquireDev: string;\n acquireTest: string;\n disposeTest: string;\n};\n\nexport type CedarPgLifecycleTarget = {\n command: string;\n cache?: boolean;\n};\n\nexport type CedarPgLifecycleTargetsOptions = {\n bin?: string;\n /** Include dispose-test target (default: true). */\n includeDisposeTest?: boolean;\n};\n\nexport function cedarPgCommands(bin = CLI_NAME): CedarPgCommands {\n return {\n acquireDev: `${bin} acquire --mode=dev`,\n acquireTest: `${bin} acquire --mode=test --print-env`,\n disposeTest: `${bin} dispose --mode=test`,\n };\n}\n\nexport function cedarPgLifecycleTargets(\n options: CedarPgLifecycleTargetsOptions = {},\n): Record<string, CedarPgLifecycleTarget> {\n const cmds = cedarPgCommands(options.bin ?? CLI_NAME);\n const targets: Record<string, CedarPgLifecycleTarget> = {\n [CEDAR_PG_TASK_ACQUIRE_DEV]: { command: cmds.acquireDev, cache: false },\n [CEDAR_PG_TASK_ACQUIRE_TEST]: { command: cmds.acquireTest, cache: false },\n };\n if (options.includeDisposeTest !== false) {\n targets[CEDAR_PG_TASK_DISPOSE_TEST] = { command: cmds.disposeTest, cache: false };\n }\n return targets;\n}\n\nexport function cedarPgRunCommand(mode: DbMode, command: string, bin = CLI_NAME): string {\n return `${bin} run --mode=${mode} -- ${command}`;\n}\n"],"mappings":";;;AAKA,MAAa,4BAA4B;AACzC,MAAa,6BAA6B;AAC1C,MAAa,6BAA6B;AAmB1C,SAAgB,gBAAgB,MAAM,UAA2B;CAC/D,OAAO;EACL,YAAY,GAAG,IAAI;EACnB,aAAa,GAAG,IAAI;EACpB,aAAa,GAAG,IAAI;CACtB;AACF;AAEA,SAAgB,wBACd,UAA0C,CAAC,GACH;CACxC,MAAM,OAAO,gBAAgB,QAAQ,OAAA,SAAe;CACpD,MAAM,UAAkD;GACrD,4BAA4B;GAAE,SAAS,KAAK;GAAY,OAAO;EAAM;GACrE,6BAA6B;GAAE,SAAS,KAAK;GAAa,OAAO;EAAM;CAC1E;CACA,IAAI,QAAQ,uBAAuB,OACjC,QAAQ,8BAA8B;EAAE,SAAS,KAAK;EAAa,OAAO;CAAM;CAElF,OAAO;AACT;AAEA,SAAgB,kBAAkB,MAAc,SAAiB,MAAM,UAAkB;CACvF,OAAO,GAAG,IAAI,cAAc,KAAK,MAAM;AACzC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { t as DbMode } from "./naming-C2nGVxPk.cjs";
|
|
2
|
+
//#region src/adapters/tasks.d.ts
|
|
3
|
+
declare const CEDAR_PG_TASK_ACQUIRE_DEV = "db:acquire";
|
|
4
|
+
declare const CEDAR_PG_TASK_ACQUIRE_TEST = "db:acquire-test";
|
|
5
|
+
declare const CEDAR_PG_TASK_DISPOSE_TEST = "db:dispose-test";
|
|
6
|
+
type CedarPgLifecycleTarget = {
|
|
7
|
+
command: string;
|
|
8
|
+
cache?: boolean;
|
|
9
|
+
};
|
|
10
|
+
type CedarPgLifecycleTargetsOptions = {
|
|
11
|
+
bin?: string;
|
|
12
|
+
/** Include dispose-test target (default: true). */
|
|
13
|
+
includeDisposeTest?: boolean;
|
|
14
|
+
};
|
|
15
|
+
declare function cedarPgLifecycleTargets(options?: CedarPgLifecycleTargetsOptions): Record<string, CedarPgLifecycleTarget>;
|
|
16
|
+
declare function cedarPgRunCommand(mode: DbMode, command: string, bin?: string): string;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { CedarPgLifecycleTargetsOptions as a, CedarPgLifecycleTarget as i, CEDAR_PG_TASK_ACQUIRE_TEST as n, cedarPgLifecycleTargets as o, CEDAR_PG_TASK_DISPOSE_TEST as r, cedarPgRunCommand as s, CEDAR_PG_TASK_ACQUIRE_DEV as t };
|
|
19
|
+
//# sourceMappingURL=tasks-DdQoP9We.d.cts.map
|