@dxgjs/generators 0.0.0 → 0.1.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/LICENSE +21 -0
- package/README.md +16 -34
- package/dist/generators/database/templates/prisma-client-lib-mysql.tmpl +14 -0
- package/dist/generators/database/templates/prisma-client-lib-planetscale.tmpl +21 -0
- package/dist/generators/database/templates/prisma-client-lib-sqlite.tmpl +20 -0
- package/dist/generators/database/templates/prisma-client-lib-sqlserver.tmpl +24 -0
- package/dist/generators/database/templates/prisma-client-lib.tmpl +20 -0
- package/dist/generators/database/templates/prisma-seed.tmpl +24 -0
- package/dist/index.d.ts +509 -0
- package/dist/index.js +5950 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -7
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import * as _dxgjs_fs from '@dxgjs/fs';
|
|
2
|
+
import { PackageManagerAgent as PackageManagerAgent$1 } from '@dxgjs/fs';
|
|
3
|
+
import { ProjectAwareness } from '@dxgjs/workspace';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Normalized dependency-installation contract shared by every generator.
|
|
7
|
+
*
|
|
8
|
+
* The core principle this module encodes: **package-manager exit code 0 does
|
|
9
|
+
* NOT mean the resulting project is operational.** Modern package managers
|
|
10
|
+
* (pnpm ≥10, npm ≥12, yarn berry, bun) block dependency lifecycle scripts
|
|
11
|
+
* by default or per-config — silently on some, loudly on others — so a
|
|
12
|
+
* native addon can end up installed-but-unbuilt. The types below separate
|
|
13
|
+
* the layers that used to be conflated under "did `install` exit 0":
|
|
14
|
+
*
|
|
15
|
+
* dependency resolution → installation → lifecycle execution →
|
|
16
|
+
* generated artifacts → post-install verification
|
|
17
|
+
*
|
|
18
|
+
* Domain-local to @dxgjs/generators on purpose (no generic framework, no
|
|
19
|
+
* new public package): the database generator is the current consumer, and
|
|
20
|
+
* generators own their own dependency plans.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A single dependency spec as a generator plans it.
|
|
25
|
+
* `requiresBuild` marks packages whose install lifecycle scripts produce
|
|
26
|
+
* native artifacts (or that a package manager's build approval gate may
|
|
27
|
+
* block) — the installer pre-approves exactly these, by name, never
|
|
28
|
+
* globally.
|
|
29
|
+
*/
|
|
30
|
+
interface DependencySpec {
|
|
31
|
+
/** npm spec, e.g. "better-sqlite3@^12.6.0" or "prisma@^7.10.1" */
|
|
32
|
+
spec: string;
|
|
33
|
+
/** Whether this package's install scripts must be allowed to run. */
|
|
34
|
+
requiresBuild: boolean;
|
|
35
|
+
/** Domain reason surfaced in UX when the approval is written. */
|
|
36
|
+
reason?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Approval-only entry: the name is included in the build approvals but
|
|
39
|
+
* NEVER passed to the install command (it is not a direct dependency —
|
|
40
|
+
* e.g. @prisma/engines arrives transitively, yet its postinstall is what
|
|
41
|
+
* the approval gates must cover). Installers must filter these out of
|
|
42
|
+
* their install batches while keeping them in the pre-approval union.
|
|
43
|
+
*/
|
|
44
|
+
approvalOnly?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* What a generator asks the installer to do. Split by dependency section
|
|
48
|
+
* because package managers record dev/regular installs differently.
|
|
49
|
+
*/
|
|
50
|
+
interface DependencyPlan {
|
|
51
|
+
devDependencies: DependencySpec[];
|
|
52
|
+
dependencies: DependencySpec[];
|
|
53
|
+
}
|
|
54
|
+
/** The package managers DXG's installer supports (base agents). */
|
|
55
|
+
type PackageManagerName = PackageManagerAgent$1;
|
|
56
|
+
/**
|
|
57
|
+
* Fine-grained agent identity. Yarn classic and berry need different
|
|
58
|
+
* approval mechanics (classic runs scripts by default; berry gates them
|
|
59
|
+
* behind dependenciesMeta when enableScripts is false), so the installer
|
|
60
|
+
* distinguishes them — unlike `ProjectAwareness.packageManager`, which
|
|
61
|
+
* stays a coarse display name.
|
|
62
|
+
*/
|
|
63
|
+
type PackageManagerAgent = "npm" | "pnpm" | "yarn" | "yarn@berry" | "bun";
|
|
64
|
+
/** Why an install failed, when we can tell. Union of normalized kinds. */
|
|
65
|
+
type DependencyInstallFailureReason =
|
|
66
|
+
/**
|
|
67
|
+
* The package manager resolved and installed everything, then refused to
|
|
68
|
+
* complete because dependency build scripts were not approved
|
|
69
|
+
* (pnpm ≥11's ERR_PNPM_IGNORED_BUILDS is a HARD error: exit 1 while the
|
|
70
|
+
* dependency tree IS populated). Not an installation failure — a policy
|
|
71
|
+
* outcome.
|
|
72
|
+
*/
|
|
73
|
+
"build-script-blocked"
|
|
74
|
+
/**
|
|
75
|
+
* Resolution/installation itself failed: package not found (E404 /
|
|
76
|
+
* ERR_PNPM_FETCH_404), peer conflicts, network…
|
|
77
|
+
*/
|
|
78
|
+
| "installation-failed"
|
|
79
|
+
/**
|
|
80
|
+
* An APPROVED dependency lifecycle script ran and failed (node-gyp /
|
|
81
|
+
* prebuild-install). pnpm/npm propagate the script's own exit code; yarn
|
|
82
|
+
* berry normalizes to 1.
|
|
83
|
+
*/
|
|
84
|
+
| "native-build-failed"
|
|
85
|
+
/**
|
|
86
|
+
* Install exited 0 (or was classified recoverable) but a required
|
|
87
|
+
* artifact the plan promised is missing on disk — the silent-drift
|
|
88
|
+
* hazard npm/bun/yarn-berry create when they block scripts with a
|
|
89
|
+
* warning and exit 0.
|
|
90
|
+
*/
|
|
91
|
+
| "missing-binary"
|
|
92
|
+
/**
|
|
93
|
+
* The post-install artifact checks failed (generated client absent,
|
|
94
|
+
* expected file not written) — the project is not operational yet.
|
|
95
|
+
*/
|
|
96
|
+
| "verification-failed"
|
|
97
|
+
/**
|
|
98
|
+
* The lockfile-only refresh that follows a manifest reconciliation
|
|
99
|
+
* failed: package.json states the commanded specs again, but the
|
|
100
|
+
* lockfile still records the manager's rewritten specifier — an
|
|
101
|
+
* incoherent pair that `npm ci` / `pnpm install --frozen-lockfile`
|
|
102
|
+
* hard-fail on (ERR_PNPM_OUTDATED_LOCKFILE). Surfaced, never
|
|
103
|
+
* silently skipped: a drifted lockfile is a CI-breaking landmine.
|
|
104
|
+
*/
|
|
105
|
+
| "lockfile-sync"
|
|
106
|
+
/** Non-zero exit we could not map to a known signature. */
|
|
107
|
+
| "unknown";
|
|
108
|
+
/**
|
|
109
|
+
* Normalized result of ONE install command (a dev-deps or deps batch).
|
|
110
|
+
* Discriminated on `success`; failures carry a machine-usable reason plus
|
|
111
|
+
* the captured output (stdout+stderr interleaved) so the caller can render
|
|
112
|
+
* the manager's own guidance without re-running anything.
|
|
113
|
+
*/
|
|
114
|
+
type DependencyInstallResult = {
|
|
115
|
+
success: true;
|
|
116
|
+
/** Names the plan asked to be approved (for UX echo). */
|
|
117
|
+
approvedBuilds: string[];
|
|
118
|
+
/**
|
|
119
|
+
* Packages whose scripts the manager reported as blocked/skipped
|
|
120
|
+
* despite exit 0 (npm `warn install-scripts`, bun `Blocked N
|
|
121
|
+
* postinstall`, yarn-berry YN0004). Empty on a healthy install.
|
|
122
|
+
*/
|
|
123
|
+
blockedBuilds: string[];
|
|
124
|
+
/** Captured combined output, for verbose/debug display. */
|
|
125
|
+
output: string;
|
|
126
|
+
} | {
|
|
127
|
+
success: false;
|
|
128
|
+
reason: DependencyInstallFailureReason;
|
|
129
|
+
/** Captured combined output (the classification input). */
|
|
130
|
+
output: string;
|
|
131
|
+
/** Exit code when the process ran to completion, else undefined. */
|
|
132
|
+
exitCode?: number;
|
|
133
|
+
/** Human-readable hint for the failure (see DXGError). */
|
|
134
|
+
hint?: string;
|
|
135
|
+
/** Suggested remediation command(s), manager-appropriate. */
|
|
136
|
+
suggestion?: string;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Verifier contract: a cheap, meaningful post-install check. Receives the
|
|
140
|
+
* project root; returns what is missing (empty array = operational).
|
|
141
|
+
* Verifiers own their domain knowledge (e.g. the database generator knows
|
|
142
|
+
* where prisma-client writes its output) — this is deliberately NOT a
|
|
143
|
+
* generic framework, just a function shape.
|
|
144
|
+
*/
|
|
145
|
+
type DependencyArtifactVerifier = (projectRoot: string) => Promise<string[]>;
|
|
146
|
+
/**
|
|
147
|
+
* The installer seam exposed (optionally) on GeneratorContext. Generators
|
|
148
|
+
* describe WHAT they need (a DependencyPlan + verifiers); the installer
|
|
149
|
+
* decides HOW per package manager. Optional so existing generators keep
|
|
150
|
+
* compiling unchanged until they adopt it.
|
|
151
|
+
*/
|
|
152
|
+
interface DependencyInstaller {
|
|
153
|
+
/** The fine-grained agent the install commands will run through. */
|
|
154
|
+
readonly agent: PackageManagerAgent;
|
|
155
|
+
/**
|
|
156
|
+
* Install one batch. Resolves the command via @antfu/ni
|
|
157
|
+
* (`programmatic: true` — never interactive), pre-writes the manager's
|
|
158
|
+
* build approvals for exactly the `requiresBuild` specs (by name, never
|
|
159
|
+
* globally), executes with buffered output, then classifies the result.
|
|
160
|
+
*/
|
|
161
|
+
install(plan: DependencyPlan, options: DependencyInstallOptions): Promise<DependencyInstallResult>;
|
|
162
|
+
}
|
|
163
|
+
interface DependencyInstallOptions {
|
|
164
|
+
/** Project root the install runs in. */
|
|
165
|
+
cwd: string;
|
|
166
|
+
/** Skip the actual execution (dry-run) — approvals are not written. */
|
|
167
|
+
dryRun?: boolean;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
type FS = typeof _dxgjs_fs;
|
|
171
|
+
interface FSInterface {
|
|
172
|
+
pathExists: FS["pathExists"];
|
|
173
|
+
readFile: FS["readFile"];
|
|
174
|
+
writeFile: FS["writeFile"];
|
|
175
|
+
stat: FS["stat"];
|
|
176
|
+
mkdir: FS["mkdir"];
|
|
177
|
+
readdir: FS["readdir"];
|
|
178
|
+
readJson: FS["readJson"];
|
|
179
|
+
writeJson: FS["writeJson"];
|
|
180
|
+
}
|
|
181
|
+
interface GeneratorContext {
|
|
182
|
+
fs: FSInterface;
|
|
183
|
+
templates: {
|
|
184
|
+
render: (template: string, data: Record<string, unknown>) => string;
|
|
185
|
+
};
|
|
186
|
+
awareness: ProjectAwareness;
|
|
187
|
+
/** Whether to run in dry-run mode (no filesystem changes) */
|
|
188
|
+
dryRun?: boolean;
|
|
189
|
+
/** Whether to force overwrite conflicting files */
|
|
190
|
+
force?: boolean;
|
|
191
|
+
/** Whether to run in non-interactive mode (no prompts) */
|
|
192
|
+
nonInteractive?: boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Dependency-installation seam (optional — additive, existing generators
|
|
195
|
+
* keep working without it). Built by the CLI in prepareContext: resolves
|
|
196
|
+
* the package-manager command via @antfu/ni, pre-writes build approvals
|
|
197
|
+
* for exactly the packages a generator's plan marks requiresBuild, and
|
|
198
|
+
* normalizes the outcome so "install exited 0" can be told apart from
|
|
199
|
+
* "the project is operational". Generators describe WHAT they need; this
|
|
200
|
+
* owns the per-manager HOW.
|
|
201
|
+
*/
|
|
202
|
+
installer?: DependencyInstaller;
|
|
203
|
+
}
|
|
204
|
+
interface GeneratorPrompt {
|
|
205
|
+
type: "input" | "confirm" | "select";
|
|
206
|
+
name: string;
|
|
207
|
+
message: string;
|
|
208
|
+
default?: string | (() => string) | boolean;
|
|
209
|
+
initialValue?: unknown;
|
|
210
|
+
choices?: Array<{
|
|
211
|
+
name: string;
|
|
212
|
+
value: string;
|
|
213
|
+
}>;
|
|
214
|
+
validate?: (input: unknown) => boolean | string;
|
|
215
|
+
}
|
|
216
|
+
interface Generator {
|
|
217
|
+
name: string;
|
|
218
|
+
description: string;
|
|
219
|
+
prompts: GeneratorPrompt[];
|
|
220
|
+
run(answers: Record<string, unknown>, context: GeneratorContext): Promise<void>;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Database generator – satisfies the Generator interface.
|
|
225
|
+
* The run method executes the full pipeline: validate → plan → execute → verify → summarize.
|
|
226
|
+
*/
|
|
227
|
+
declare const databaseGenerator: Generator;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Failure classification: maps raw package-manager output + exit code to a
|
|
231
|
+
* normalized `DependencyInstallFailureReason`.
|
|
232
|
+
*
|
|
233
|
+
* Every signature below was captured empirically (lab runs against the
|
|
234
|
+
* real pnpm 11.18.0 / npm 12.0.1 / bun 1.3.14 / yarn classic 1.22.22 /
|
|
235
|
+
* yarn berry 4.1.1 on this machine). Matching is anchored on stable
|
|
236
|
+
* machine markers (error CODES, manager-owned line prefixes), never on
|
|
237
|
+
* full prose, so a reworded message cannot silently break detection.
|
|
238
|
+
*
|
|
239
|
+
* Critical asymmetry this module exists for:
|
|
240
|
+
* - pnpm ≥11 BLOCKS LOUDLY: exit 1 + ERR_PNPM_IGNORED_BUILDS on stdout,
|
|
241
|
+
* while the dependency tree IS installed (resolutions succeeded).
|
|
242
|
+
* - npm 12 / bun / yarn-berry BLOCK SILENTLY: exit 0 + a warning line
|
|
243
|
+
* (npm warn install-scripts / bun "Blocked N postinstall" / YN0004).
|
|
244
|
+
* So both branches must classify: exit≠0 needs a reason, and exit==0 needs
|
|
245
|
+
* a blocked-builds scan.
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
/** Extracts the bare package name from an npm spec ("a@^1" → "a", "@x/y@2" → "@x/y"). */
|
|
249
|
+
declare function packageNameFromSpec(spec: string): string;
|
|
250
|
+
/**
|
|
251
|
+
* pnpm ≥11 hard-error signature (exit 1, printed on STDOUT while stderr is
|
|
252
|
+
* empty). The dependency tree IS installed at this point — only the build
|
|
253
|
+
* scripts were skipped, so this is "build-script-blocked", NOT an
|
|
254
|
+
* installation failure. Format captured in lab e2r/e5:
|
|
255
|
+
* [ERR_PNPM_IGNORED_BUILDS] Ignored build scripts: @prisma/engines@7.10.0, prisma@7.10.0
|
|
256
|
+
*/
|
|
257
|
+
declare function isPnpmIgnoredBuilds(output: string): boolean;
|
|
258
|
+
/**
|
|
259
|
+
* Parses the pnpm ignored-builds package list. Deduplicated names, each
|
|
260
|
+
* potentially versioned ("@prisma/engines@7.10.0").
|
|
261
|
+
*/
|
|
262
|
+
declare function parsePnpmIgnoredBuilds(output: string): string[];
|
|
263
|
+
/**
|
|
264
|
+
* npm ≥12 blocked-scripts notice (exit 0, STDERR). Captured in lab e6:
|
|
265
|
+
* npm warn install-scripts 2 packages had install scripts blocked because they are not covered by allowScripts:
|
|
266
|
+
* npm warn install-scripts prisma@7.10.0 (preinstall: node scripts/preinstall-entry.js)
|
|
267
|
+
*/
|
|
268
|
+
declare function isNpmInstallScriptsWarning(output: string): boolean;
|
|
269
|
+
/** Parses the npm blocked-scripts package names from the notice lines. */
|
|
270
|
+
declare function parseNpmBlockedScripts(output: string): string[];
|
|
271
|
+
/**
|
|
272
|
+
* bun blocked postinstall notice (exit 0, STDOUT — verified: the notice
|
|
273
|
+
* rides the install summary stream, not stderr). Captured in lab e8-vfy:
|
|
274
|
+
* Blocked 1 postinstall. Run `bun pm untrusted` for details.
|
|
275
|
+
* `bun pm untrusted` itself proved UNRELIABLE for this (it reported 0
|
|
276
|
+
* right after an install printed "Blocked 1") — never depend on it.
|
|
277
|
+
*/
|
|
278
|
+
declare function isBunBlockedPostinstall(output: string): boolean;
|
|
279
|
+
/**
|
|
280
|
+
* yarn berry disabled-build warning (exit 0): YN0004 — "…lists build
|
|
281
|
+
* scripts, but all build scripts have been disabled". Verified locally
|
|
282
|
+
* (yarn 4.1.1, lab adversarial): enableScripts:false blocks OUT-OF-PLAN
|
|
283
|
+
* packages (sharp stayed YN0004-blocked) while dependenciesMeta built:true
|
|
284
|
+
* entries keep the plan's own packages building.
|
|
285
|
+
*/
|
|
286
|
+
declare function isYarnDisabledBuildScripts(output: string): boolean;
|
|
287
|
+
/** Registry 404 signatures (exit 1): pnpm ERR_PNPM_FETCH_404 (stdout), npm E404 (stderr), bun "GET … - 404" (stderr). */
|
|
288
|
+
declare function isPackageNotFound(output: string): boolean;
|
|
289
|
+
/**
|
|
290
|
+
* A dependency lifecycle script that RAN and failed. pnpm/npm propagate the
|
|
291
|
+
* script's own exit code under ELIFECYCLE / "Command failed with exit code
|
|
292
|
+
* N"; yarn berry reports "couldn't be built successfully (exit code N)".
|
|
293
|
+
*/
|
|
294
|
+
declare function isNativeBuildFailed(output: string): boolean;
|
|
295
|
+
/**
|
|
296
|
+
* Classifies a non-zero exit into a normalized failure reason.
|
|
297
|
+
* Order matters: the most specific, recoverable signatures are tested
|
|
298
|
+
* before the generic ones, so "install ran, only the build approval is
|
|
299
|
+
* missing" never reads as a broken install.
|
|
300
|
+
*/
|
|
301
|
+
declare function classifyInstallFailure(output: string, exitCode: number | undefined, agent: PackageManagerAgent): {
|
|
302
|
+
reason: DependencyInstallFailureReason;
|
|
303
|
+
hint?: string;
|
|
304
|
+
suggestion?: string;
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* Scans a SUCCESS (exit 0) install output for silently-blocked build
|
|
308
|
+
* scripts — the silent-drift hazard. npm warns on stderr, bun on stdout,
|
|
309
|
+
* yarn berry emits YN0004; pnpm never reaches here silently (it hard-fails
|
|
310
|
+
* instead).
|
|
311
|
+
*/
|
|
312
|
+
declare function scanBlockedBuilds(output: string, agent: PackageManagerAgent): string[];
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* The dependency installer: resolves the package-manager command via
|
|
316
|
+
* @antfu/ni, pre-writes build approvals for exactly the plan's
|
|
317
|
+
* `requiresBuild` packages, executes with buffered output, then normalizes
|
|
318
|
+
* the outcome.
|
|
319
|
+
*
|
|
320
|
+
* Output handling — the deliberate deviation from DXG's `stdio: "inherit"`
|
|
321
|
+
* convention for installs ONLY: the silent blockers (npm 12, bun, yarn
|
|
322
|
+
* berry) print their "scripts blocked" notices on stdout/stderr while
|
|
323
|
+
* exiting 0. Inherit would stream those straight past the Clack spinner
|
|
324
|
+
* AND make them invisible to classification. So installs run piped; the
|
|
325
|
+
* spinner stays alive (the Clack convention survives). The captured
|
|
326
|
+
* output rides the result: on failure the caller embeds the tail in the
|
|
327
|
+
* thrown error, on success the blocked-builds note names the affected
|
|
328
|
+
* packages. `prisma init`/`prisma generate` keep `inherit` — they are
|
|
329
|
+
* tool output the user wants live.
|
|
330
|
+
*
|
|
331
|
+
* Non-interactivity: every getCliCommand call passes `programmatic: true`
|
|
332
|
+
* — verified in ni's source: the "Would you like to globally install yarn?"
|
|
333
|
+
* prompt exists ONLY on the non-programmatic path (`if (name &&
|
|
334
|
+
* !cmdExists(name) && !programmatic)`), and CI=1 exits 1 instead. No
|
|
335
|
+
* hidden prompts can ever spawn from here.
|
|
336
|
+
*/
|
|
337
|
+
|
|
338
|
+
/** Options for createDependencyInstaller. */
|
|
339
|
+
interface CreateInstallerOptions {
|
|
340
|
+
/** Agent detected via @antfu/ni (fine-grained: yarn vs yarn@berry). */
|
|
341
|
+
agent: PackageManagerAgent;
|
|
342
|
+
/** Filesystem seam (GeneratorContext.fs). */
|
|
343
|
+
fs: FSInterface;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Builds the installer bound to a detected agent. The agent (not
|
|
347
|
+
* `awareness.packageManager`) decides the approval mechanics, so the
|
|
348
|
+
* generator never branches on the package manager.
|
|
349
|
+
*/
|
|
350
|
+
declare function createDependencyInstaller(options: CreateInstallerOptions): DependencyInstaller;
|
|
351
|
+
/**
|
|
352
|
+
* Detects the fine-grained agent for a project directory via @antfu/ni's
|
|
353
|
+
* detect (same detector getCliCommand uses, so the approval mechanics can
|
|
354
|
+
* never diverge from the command actually run). Returns null when no agent
|
|
355
|
+
* is detectable — callers surface an explicit error rather than guessing.
|
|
356
|
+
*/
|
|
357
|
+
declare function detectPackageManagerAgent(cwd: string): Promise<PackageManagerAgent | null>;
|
|
358
|
+
/**
|
|
359
|
+
* Maps an install failure to a DXG-presentable hint. Kept separate from
|
|
360
|
+
* the installer so the CLI layer (which owns DXGError) stays the only
|
|
361
|
+
* place that formats errors.
|
|
362
|
+
*/
|
|
363
|
+
declare function installerFailureHint(result: Extract<DependencyInstallResult, {
|
|
364
|
+
success: false;
|
|
365
|
+
}>): string;
|
|
366
|
+
/** Convenience: project-root-relative paths of the approval files. */
|
|
367
|
+
declare function approvalPaths(projectRoot: string): {
|
|
368
|
+
workspaceYaml: string;
|
|
369
|
+
packageJson: string;
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Build-approval policy: the per-manager mechanics for allowing EXACTLY the
|
|
374
|
+
* packages a plan marked `requiresBuild` to run their install scripts.
|
|
375
|
+
*
|
|
376
|
+
* Security contract (non-negotiable):
|
|
377
|
+
* - Approvals are per-package-name. NEVER a global "allow everything"
|
|
378
|
+
* (no dangerouslyAllowAllBuilds / --dangerously-allow-all-scripts /
|
|
379
|
+
* enableScripts:true / --ignore-scripts).
|
|
380
|
+
* - Approvals are written BEFORE the install, additively — existing
|
|
381
|
+
* entries are preserved, never removed or flipped to false.
|
|
382
|
+
* - Nothing outside the plan's requiresBuild names is touched.
|
|
383
|
+
*
|
|
384
|
+
* Every mechanic below was validated empirically on this machine (pnpm
|
|
385
|
+
* 11.18.0, npm 12.0.1, bun 1.3.14, yarn classic 1.22.22, yarn berry 4.1.1):
|
|
386
|
+
* - pnpm 11: `allowBuilds` map in pnpm-workspace.yaml, name → true|false.
|
|
387
|
+
* Pre-writing {pkg: true} BEFORE install = scripts run inline, exit 0.
|
|
388
|
+
* (Lab e2e-pnpm: full database plan, zero ERR_PNPM_IGNORED_BUILDS.)
|
|
389
|
+
* Keys starting with "@" MUST be single-quoted or pnpm's YAML parser
|
|
390
|
+
* fails with "bad indentation of a mapping entry" (lab-observed).
|
|
391
|
+
* - npm 12: `allowScripts` map in package.json. Name-only entries work
|
|
392
|
+
* pre-written (lab npm-nameonly: script ran, binding created, no
|
|
393
|
+
* warning) — the pkg@version pinning npm's CLI applies by default is
|
|
394
|
+
* NOT required for pre-approval. NOTE (live-verified, npm 12): when
|
|
395
|
+
* the map is ABSENT, npm silently blocks scripts with a warn line and
|
|
396
|
+
* exit 0 — DXG pre-writes the map for exactly the plan's packages.
|
|
397
|
+
* - yarn berry: `dependenciesMeta` {pkg: {built: true}} in package.json
|
|
398
|
+
* is the documented allow-list path when enableScripts is false.
|
|
399
|
+
* Verified live on yarn 4.1.1: it overrides enableScripts:false
|
|
400
|
+
* PER PACKAGE (the plan's prisma/engines built while out-of-plan sharp
|
|
401
|
+
* stayed YN0004-blocked), and enableScripts defaults to TRUE for fresh
|
|
402
|
+
* projects — the map is written so the plan's builds survive either
|
|
403
|
+
* default. Classic (v1): scripts run by default, nothing to write
|
|
404
|
+
* (verified live: full sqlite plan, binding + engines binary on disk,
|
|
405
|
+
* zero approval config written by DXG).
|
|
406
|
+
* - bun: its default-trusted list covers the packages DXG's database plan
|
|
407
|
+
* needs (lab bun-full: zero blocked). Writing `trustedDependencies`
|
|
408
|
+
* would REPLACE the default list (bun semantics) — a hazard — so the
|
|
409
|
+
* adapter writes nothing.
|
|
410
|
+
*/
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Minimal YAML writer/patcher for the single map pnpm 11 needs. Not a
|
|
414
|
+
* general YAML library: pnpm-workspace.yaml is user-owned, so edits are
|
|
415
|
+
* byte-preserving text transforms on the `allowBuilds:` block only —
|
|
416
|
+
* comments, ordering, and every other key survive untouched.
|
|
417
|
+
*
|
|
418
|
+
* Format matches what pnpm itself writes (observed in lab m2/e5):
|
|
419
|
+
* allowBuilds:
|
|
420
|
+
* better-sqlite3: true
|
|
421
|
+
* '@prisma/engines': true
|
|
422
|
+
*/
|
|
423
|
+
declare function applyPnpmAllowBuilds(fs: FSInterface, projectRoot: string, packageNames: string[]): Promise<void>;
|
|
424
|
+
/**
|
|
425
|
+
* Pure transform (exported for tests): merges names into the allowBuilds
|
|
426
|
+
* map, preserving the rest of the document byte-for-byte.
|
|
427
|
+
*/
|
|
428
|
+
declare function mergeAllowBuildsBlock(yaml: string, packageNames: string[]): string;
|
|
429
|
+
/**
|
|
430
|
+
* npm 12: pre-write `allowScripts` {name: true} into package.json.
|
|
431
|
+
* Name-only entries. STRICTLY ADDITIVE — the same rule as the pnpm merge:
|
|
432
|
+
* a name that already has an entry is never touched, so an explicit user
|
|
433
|
+
* denial (`false`) stands. The install then blocks/skips that package's
|
|
434
|
+
* scripts and the blocked-builds scan (or artifact verification) surfaces
|
|
435
|
+
* it honestly — never a silent flip.
|
|
436
|
+
*/
|
|
437
|
+
declare function applyNpmAllowScripts(fs: FSInterface, projectRoot: string, packageNames: string[]): Promise<void>;
|
|
438
|
+
/**
|
|
439
|
+
* yarn berry: pre-write `dependenciesMeta` {name: {built: true}} into
|
|
440
|
+
* package.json — the documented allow-list when enableScripts is false
|
|
441
|
+
* (per-package override, live-verified on yarn 4.1.1: the plan's packages
|
|
442
|
+
* built while out-of-plan sharp stayed YN0004-blocked). STRICTLY ADDITIVE
|
|
443
|
+
* — same rule as pnpm/npm: `built` is set ONLY when the field is absent.
|
|
444
|
+
* An explicit denial (`built: false`) stands; other meta fields on an
|
|
445
|
+
* existing entry are always preserved. NEVER `onlyBuiltDependencies`
|
|
446
|
+
* (pnpm-only name; and writing unknown keys into berry's .yarnrc.yml would
|
|
447
|
+
* abort under enableStrictSettings).
|
|
448
|
+
*/
|
|
449
|
+
declare function applyYarnBerryDependenciesMeta(fs: FSInterface, projectRoot: string, packageNames: string[]): Promise<void>;
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* dlx build-approval adapter: the command-line side of the same
|
|
453
|
+
* per-package approval contract approvals.ts writes into project files.
|
|
454
|
+
*
|
|
455
|
+
* Two DIFFERENT install scopes exist for `dxg add database` under pnpm:
|
|
456
|
+
*
|
|
457
|
+
* 1. PROJECT install (`pnpm add`) — governed by the `allowBuilds` map
|
|
458
|
+
* pnpm-workspace.yaml holds. The installer seam pre-writes it
|
|
459
|
+
* (applyPnpmAllowBuilds) for exactly the plan's requiresBuild
|
|
460
|
+
* packages. This scope is NOT where the interactive prompt came
|
|
461
|
+
* from.
|
|
462
|
+
*
|
|
463
|
+
* 2. DLX CACHE install (`pnpm dlx prisma@7 ...`) — `prisma init` and
|
|
464
|
+
* `prisma generate` resolve through dlx, so prisma AND its
|
|
465
|
+
* transitive deps are installed into an isolated
|
|
466
|
+
* `<pnpm-cache>/dlx/<cacheKey>/pkg` directory the project files
|
|
467
|
+
* never mention. pnpm 11 pre-approves only the dlx alias itself
|
|
468
|
+
* (verified in pnpm 11.18.0 source: `allowBuilds = fromEntries(...
|
|
469
|
+
* resolvedPkgAliases)`); every TRANSITIVE package with a build
|
|
470
|
+
* script lands in `ignoredBuilds`. On a TTY, `promptApproveDlxBuilds`
|
|
471
|
+
* then runs the `approve-builds` handler — the multiselect
|
|
472
|
+
* "Choose which packages to build" — INSIDE DXG's init spinner. On a
|
|
473
|
+
* non-TTY the prompt is skipped silently: @prisma/engines' postinstall
|
|
474
|
+
* (the schema-engine binary download) never runs and a cold-cache
|
|
475
|
+
* machine is left without the binary that db:push/db:migrate (the
|
|
476
|
+
* scripts DXG itself writes) require.
|
|
477
|
+
*
|
|
478
|
+
* `--allow-build=<name>` is pnpm dlx's OFFICIAL narrow approval channel
|
|
479
|
+
* (dlx cliOptionsTypes: `{"allow-build": [String, Array]}`), validated
|
|
480
|
+
* empirically: with the flag, the dlx cache's .modules.yaml records
|
|
481
|
+
* `allowBuilds: {prisma: true, "@prisma/engines": true}` and
|
|
482
|
+
* `ignoredBuilds: []` — the prompt's precondition (non-empty
|
|
483
|
+
* ignoredBuilds) is gone, so it can never appear in EITHER mode, and the
|
|
484
|
+
* postinstall DOES run (binary delivered).
|
|
485
|
+
*
|
|
486
|
+
* Scope discipline (same security contract as approvals.ts):
|
|
487
|
+
* - ONLY pnpm: `pnpm dlx` is the only resolution with this approval
|
|
488
|
+
* gate. npx runs scripts by default; yarn v1 maps dlx execution to
|
|
489
|
+
* npx; yarn berry's dlx and `bun x` have no build-approval prompt
|
|
490
|
+
* (bun's default-trusted list covers the plan). The `command ===
|
|
491
|
+
* "pnpm"` check (not just `args[0] === "dlx"` — yarn berry also
|
|
492
|
+
* resolves to `["dlx", ...]`) is what keeps the flag pnpm-only.
|
|
493
|
+
* - ONLY the names the plan itself marked approvalOnly — the packages
|
|
494
|
+
* DXG intentionally installs (transitively) and whose build scripts
|
|
495
|
+
* it needs. No global allow-all flag exists here, and nothing
|
|
496
|
+
* outside the plan is approved.
|
|
497
|
+
* - The flag changes the dlx cacheKey, so it must ride the SAME
|
|
498
|
+
* resolution call as the command — never a separate one.
|
|
499
|
+
*/
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Inserts pnpm dlx build-approval flags into a RESOLVED command line.
|
|
503
|
+
* Returns the args unchanged for every other command shape — npx, yarn
|
|
504
|
+
* (classic and berry dlx), and bun x executions never receive a
|
|
505
|
+
* pnpm-only flag.
|
|
506
|
+
*/
|
|
507
|
+
declare function withDlxBuildApprovals(command: string, args: string[], plan: DependencyPlan): string[];
|
|
508
|
+
|
|
509
|
+
export { type DependencyArtifactVerifier, type DependencyInstallFailureReason, type DependencyInstallOptions, type DependencyInstallResult, type DependencyInstaller, type DependencyPlan, type DependencySpec, type Generator, type GeneratorContext, type PackageManagerAgent, type PackageManagerName, applyNpmAllowScripts, applyPnpmAllowBuilds, applyYarnBerryDependenciesMeta, approvalPaths, classifyInstallFailure, createDependencyInstaller, databaseGenerator, databaseGenerator as default, detectPackageManagerAgent, installerFailureHint, isBunBlockedPostinstall, isNativeBuildFailed, isNpmInstallScriptsWarning, isPackageNotFound, isPnpmIgnoredBuilds, isYarnDisabledBuildScripts, mergeAllowBuildsBlock, packageNameFromSpec, parseNpmBlockedScripts, parsePnpmIgnoredBuilds, scanBlockedBuilds, withDlxBuildApprovals };
|