@prisma/cli-engine 0.3.0 → 0.5.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 +2 -0
- package/dist/{engine-CPLGpHh5.js → engine-DaES-DtJ.js} +820 -190
- package/dist/index.d.ts +19 -7
- package/dist/index.js +7 -6
- package/dist/{report-DR2h7YIG.d.ts → report-CCIboNYr.d.ts} +124 -28
- package/dist/testing.d.ts +11 -2
- package/dist/testing.js +11 -5
- package/package.json +3 -3
|
@@ -3,8 +3,8 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import { Buffer } from "node:buffer";
|
|
4
4
|
import { FlagNotFoundError, buildApplication, buildCommand, buildRouteMap, run, text_en } from "@stricli/core";
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
6
|
-
import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from "node:fs";
|
|
7
|
-
import { dirname, join, resolve } from "node:path";
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
8
8
|
import { detect } from "package-manager-detector/detect";
|
|
9
9
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
10
10
|
import { createColors } from "colorette";
|
|
@@ -1477,7 +1477,7 @@ function endpointVerdict(message) {
|
|
|
1477
1477
|
//#endregion
|
|
1478
1478
|
//#region src/runtime.ts
|
|
1479
1479
|
/**
|
|
1480
|
-
* The config contract version
|
|
1480
|
+
* The config contract version definePrismaConfig writes as the structural
|
|
1481
1481
|
* `$prismaConfig` marker; the loader checks it before interpreting
|
|
1482
1482
|
* anything.
|
|
1483
1483
|
*/
|
|
@@ -1485,33 +1485,48 @@ const PRISMA_CONFIG_VERSION = 1;
|
|
|
1485
1485
|
//#endregion
|
|
1486
1486
|
//#region src/config-loader.ts
|
|
1487
1487
|
/**
|
|
1488
|
-
* The prisma.config.ts loader behind Runtime.loadConfig: resolve
|
|
1489
|
-
*
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
1488
|
+
* The prisma.config.ts loader behind Runtime.loadConfig: resolve an
|
|
1489
|
+
* ordered chain of config files, evaluate each, check every one for the
|
|
1490
|
+
* definePrismaConfig version marker, and produce LoadedConfig.
|
|
1491
|
+
*
|
|
1492
|
+
* Without `--config`, discovery starts at cwd and walks upward
|
|
1493
|
+
* collecting every prisma.config.ts, stopping at the repository
|
|
1494
|
+
* boundary: the first directory containing `.git`. With `--config`,
|
|
1495
|
+
* the named file is the first chain link and discovery resumes
|
|
1496
|
+
* strictly above its directory — a prisma.config.ts beside the named
|
|
1497
|
+
* file is never collected. No `.git` at or above the anchor means
|
|
1498
|
+
* the anchor directory only — every file on the chain is executed
|
|
1499
|
+
* TypeScript, and nothing outside the repository runs without explicit
|
|
1500
|
+
* consent. A file may end collection itself with `parent: false`, or
|
|
1501
|
+
* name its parent explicitly with `parent: "path"` (resolved against
|
|
1502
|
+
* the declaring file's directory); an explicit parent may cross the
|
|
1503
|
+
* repository boundary — naming it is the consent — and the chain is
|
|
1504
|
+
* cycle-checked. After an explicit link, automatic discovery resumes
|
|
1505
|
+
* from the parent file's own directory.
|
|
1492
1506
|
*
|
|
1493
1507
|
* Which section names a CLI recognises is not this module's business:
|
|
1494
|
-
* it hands back every top-level key
|
|
1508
|
+
* it hands back every top-level key each file had, and the engine — not
|
|
1495
1509
|
* a Runtime member a host can replace — checks them against the
|
|
1496
1510
|
* sections the mounted commands declare.
|
|
1497
1511
|
*
|
|
1498
|
-
*
|
|
1499
|
-
*
|
|
1500
|
-
* diagnostics.
|
|
1512
|
+
* Finding no file is not an error: section validators own absence, so
|
|
1513
|
+
* a chain with no files yields no sections and no diagnostics.
|
|
1501
1514
|
* Absence of a file the user NAMED with --config is an error — they
|
|
1502
1515
|
* said which file to read and it was not there. An evaluated file
|
|
1503
1516
|
* WITHOUT the marker (a classic Prisma 7 config, which uses the same
|
|
1504
|
-
* filename) fails early with one typed diagnostic
|
|
1505
|
-
* partially interprets an unmarked file, and never
|
|
1517
|
+
* filename) fails early with one typed diagnostic naming that file —
|
|
1518
|
+
* the loader never partially interprets an unmarked file, and never
|
|
1519
|
+
* guesses. A broken file anywhere on the chain fails resolution.
|
|
1506
1520
|
*
|
|
1507
1521
|
* Evaluation goes through c12, the same loader prisma/prisma and
|
|
1508
1522
|
* prisma/composer use, because the shipped CLI runs on ordinary Node,
|
|
1509
1523
|
* which cannot import a .ts file. c12 transpiles it with jiti first.
|
|
1510
1524
|
* Every c12 feature beyond "evaluate this one file" is switched off
|
|
1511
|
-
* below
|
|
1525
|
+
* below — chain discovery is this loader's, never c12's.
|
|
1512
1526
|
*/
|
|
1513
1527
|
const CONFIG_FILE_NAME = "prisma.config.ts";
|
|
1514
1528
|
const MARKER_KEY = "$prismaConfig";
|
|
1529
|
+
const PARENT_KEY = "parent";
|
|
1515
1530
|
/**
|
|
1516
1531
|
* Top-level keys the config file format keeps for itself, so no
|
|
1517
1532
|
* section may be named one of them; buildCommandTree rejects the
|
|
@@ -1520,19 +1535,21 @@ const MARKER_KEY = "$prismaConfig";
|
|
|
1520
1535
|
* `$`-prefixed keys are metadata: `$prismaConfig` is the version
|
|
1521
1536
|
* marker, and config loaders read `$env`, `$<NODE_ENV>` and `$meta` —
|
|
1522
1537
|
* c12 deletes `$meta` from the config object whatever else it is told.
|
|
1538
|
+
* `parent` is the engine's chain directive: the loader reads it to
|
|
1539
|
+
* follow or end the chain and strips it from the sections, like the
|
|
1540
|
+
* marker.
|
|
1523
1541
|
* `extends` is the key config loaders take as "merge another file into
|
|
1524
1542
|
* this one". This loader switches that off (`extend: false`), so a key
|
|
1525
1543
|
* by that name does reach the config object. It stays reserved anyway:
|
|
1526
|
-
*
|
|
1527
|
-
* would
|
|
1528
|
-
* disappear the moment anything switched merging back on.
|
|
1544
|
+
* `parent` is this format's layering, and a section called `extends`
|
|
1545
|
+
* would disappear the moment anything switched c12's merging back on.
|
|
1529
1546
|
*
|
|
1530
1547
|
* `__proto__` is reserved for the reason `$meta` is: c12 merges layers
|
|
1531
1548
|
* with defu, which drops the key rather than let a config file reach an
|
|
1532
1549
|
* object's prototype, so a section by that name could never be read.
|
|
1533
1550
|
*/
|
|
1534
1551
|
function reservedConfigSectionName(name) {
|
|
1535
|
-
return name === "extends" || name === "__proto__" || name.startsWith("$");
|
|
1552
|
+
return name === "extends" || name === PARENT_KEY || name === "__proto__" || name.startsWith("$");
|
|
1536
1553
|
}
|
|
1537
1554
|
/**
|
|
1538
1555
|
* Attaches the version marker to a prisma.config.ts export. Each
|
|
@@ -1547,16 +1564,12 @@ function definePrismaConfig(config) {
|
|
|
1547
1564
|
$prismaConfig: 1
|
|
1548
1565
|
});
|
|
1549
1566
|
}
|
|
1550
|
-
/** @deprecated Renamed to {@link definePrismaConfig}: every family's
|
|
1551
|
-
* config helper carries a unique name, so none needs an import alias. */
|
|
1552
|
-
const defineConfig = definePrismaConfig;
|
|
1553
1567
|
function hasVersionMarker(value) {
|
|
1554
1568
|
return typeof value === "object" && value !== null && typeof value[MARKER_KEY] === "number";
|
|
1555
1569
|
}
|
|
1556
|
-
function
|
|
1570
|
+
function failedChain(files, diagnostic) {
|
|
1557
1571
|
return {
|
|
1558
|
-
|
|
1559
|
-
sections: {},
|
|
1572
|
+
files,
|
|
1560
1573
|
diagnostics: [{
|
|
1561
1574
|
section: null,
|
|
1562
1575
|
diagnostic
|
|
@@ -1600,11 +1613,59 @@ function missingNamedFileDiagnostic(path) {
|
|
|
1600
1613
|
why: "A config file found by discovery may be absent — the section validators supply their defaults. A config file named on the command line may not: the CLI would otherwise run against different settings than the ones asked for.",
|
|
1601
1614
|
nextActions: [{
|
|
1602
1615
|
kind: "user-choice",
|
|
1603
|
-
label: "Correct the path passed to --config, or drop the flag to
|
|
1616
|
+
label: "Correct the path passed to --config, or drop the flag to let the CLI discover prisma.config.ts from the current directory."
|
|
1617
|
+
}],
|
|
1618
|
+
where: { path }
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
/** JSON where it can (true, null, 42, {}); String for what JSON has no
|
|
1622
|
+
* spelling for (undefined cannot reach here, but bigint or a symbol
|
|
1623
|
+
* can). */
|
|
1624
|
+
function showParentValue(value) {
|
|
1625
|
+
try {
|
|
1626
|
+
return JSON.stringify(value) ?? String(value);
|
|
1627
|
+
} catch {
|
|
1628
|
+
return String(value);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
function invalidParentDiagnostic(path, value) {
|
|
1632
|
+
return {
|
|
1633
|
+
code: "CLI.CONFIG_PARENT_INVALID",
|
|
1634
|
+
severity: "error",
|
|
1635
|
+
summary: `${path} declares parent: ${showParentValue(value)}, but parent must be false or a path string.`,
|
|
1636
|
+
why: "'parent' controls config discovery: false makes this file the last on the chain, and a path names the next file explicitly. Any other value is a mistake the CLI stops on rather than guesses about.",
|
|
1637
|
+
nextActions: [{
|
|
1638
|
+
kind: "user-choice",
|
|
1639
|
+
label: "Set parent to false or to the path of the parent config file, or remove it to let discovery continue upward."
|
|
1604
1640
|
}],
|
|
1605
1641
|
where: { path }
|
|
1606
1642
|
};
|
|
1607
1643
|
}
|
|
1644
|
+
function missingParentDiagnostic(declaring, target) {
|
|
1645
|
+
return {
|
|
1646
|
+
code: "CLI.CONFIG_PARENT_NOT_FOUND",
|
|
1647
|
+
severity: "error",
|
|
1648
|
+
summary: `${declaring} names ${target} as its parent config, and there is no file there.`,
|
|
1649
|
+
nextActions: [{
|
|
1650
|
+
kind: "user-choice",
|
|
1651
|
+
label: "Correct the parent path, set parent to false, or remove it to let discovery continue upward."
|
|
1652
|
+
}],
|
|
1653
|
+
where: { path: declaring }
|
|
1654
|
+
};
|
|
1655
|
+
}
|
|
1656
|
+
function parentCycleDiagnostic(declaring, target) {
|
|
1657
|
+
return {
|
|
1658
|
+
code: "CLI.CONFIG_PARENT_CYCLE",
|
|
1659
|
+
severity: "error",
|
|
1660
|
+
summary: `${declaring} names ${target} as its parent config, but that file is already on the config chain.`,
|
|
1661
|
+
why: "Following the link again would loop forever, so resolution stops here.",
|
|
1662
|
+
nextActions: [{
|
|
1663
|
+
kind: "user-choice",
|
|
1664
|
+
label: "Break the cycle: point parent elsewhere or set it to false."
|
|
1665
|
+
}],
|
|
1666
|
+
where: { path: declaring }
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1608
1669
|
/** jiti reports an unresolvable import as "Cannot find module", Node's
|
|
1609
1670
|
* own resolver as "Cannot find package"; either can appear in the
|
|
1610
1671
|
* evaluation error chain depending on how the file is loaded. Node's
|
|
@@ -1701,55 +1762,161 @@ async function evaluateConfigFile(path) {
|
|
|
1701
1762
|
* creating an own property, so that one key would disappear from
|
|
1702
1763
|
* Object.keys and never be reported as unrecognised. */
|
|
1703
1764
|
function sectionsOf(exported) {
|
|
1704
|
-
return Object.fromEntries(Object.entries(exported).filter(([key]) => key !== MARKER_KEY));
|
|
1765
|
+
return Object.fromEntries(Object.entries(exported).filter(([key]) => key !== MARKER_KEY && key !== PARENT_KEY));
|
|
1705
1766
|
}
|
|
1706
|
-
/**
|
|
1707
|
-
*
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
* file that is not there, and jiti cannot import a relative specifier
|
|
1715
|
-
* at all. Resolving here also makes the file's path in every diagnostic
|
|
1716
|
-
* absolute, and makes the loaded-file comparison compare like with
|
|
1717
|
-
* like.
|
|
1718
|
-
*/
|
|
1719
|
-
function fileToRead(cwd, configPath) {
|
|
1720
|
-
const root = resolve(cwd);
|
|
1721
|
-
return configPath === void 0 ? join(root, CONFIG_FILE_NAME) : resolve(root, configPath);
|
|
1767
|
+
/** realpath where the path exists; the path itself where it does not
|
|
1768
|
+
* (a cwd that is gone, a comparison candidate that was just checked). */
|
|
1769
|
+
function realpathOr(path) {
|
|
1770
|
+
try {
|
|
1771
|
+
return realpathSync(path);
|
|
1772
|
+
} catch {
|
|
1773
|
+
return path;
|
|
1774
|
+
}
|
|
1722
1775
|
}
|
|
1723
|
-
/**
|
|
1724
|
-
*
|
|
1725
|
-
*
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1776
|
+
/** The first directory at or above `dir` containing a `.git` entry —
|
|
1777
|
+
* a directory in an ordinary checkout, a file in worktrees and
|
|
1778
|
+
* submodules — or null when there is none all the way up. */
|
|
1779
|
+
function repositoryBoundary(dir) {
|
|
1780
|
+
let current = dir;
|
|
1781
|
+
while (true) {
|
|
1782
|
+
if (existsSync(join(current, ".git"))) return current;
|
|
1783
|
+
const parent = dirname(current);
|
|
1784
|
+
if (parent === current) return null;
|
|
1785
|
+
current = parent;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
/** The directories automatic discovery scans from `start`: upward to
|
|
1789
|
+
* the repository boundary inclusive, or `start` alone when no `.git`
|
|
1790
|
+
* exists at or above it. */
|
|
1791
|
+
function discoveryDirs(start) {
|
|
1792
|
+
const boundary = repositoryBoundary(start);
|
|
1793
|
+
const dirs = [start];
|
|
1794
|
+
let current = start;
|
|
1795
|
+
while (boundary !== null && current !== boundary) {
|
|
1796
|
+
current = dirname(current);
|
|
1797
|
+
dirs.push(current);
|
|
1798
|
+
}
|
|
1799
|
+
return dirs;
|
|
1800
|
+
}
|
|
1801
|
+
/** Where discovery continues after the file in `dir`: the directories
|
|
1802
|
+
* strictly above it, still inside its repository. Outside any
|
|
1803
|
+
* repository, nothing above it is scanned. */
|
|
1804
|
+
function dirsAbove(dir) {
|
|
1805
|
+
return discoveryDirs(dir).slice(1);
|
|
1806
|
+
}
|
|
1807
|
+
/** A directory named prisma.config.ts is not a config file, for
|
|
1808
|
+
* discovery and explicit `parent` links alike. */
|
|
1809
|
+
function isFileAt(path) {
|
|
1810
|
+
return existsSync(path) && statSync(path).isFile();
|
|
1811
|
+
}
|
|
1812
|
+
function nextDiscoveredFile(dirs, collected) {
|
|
1813
|
+
for (const dir of dirs) {
|
|
1814
|
+
const candidate = join(dir, CONFIG_FILE_NAME);
|
|
1815
|
+
if (isFileAt(candidate) && !collected.has(realpathOr(candidate))) return candidate;
|
|
1816
|
+
}
|
|
1817
|
+
return null;
|
|
1818
|
+
}
|
|
1819
|
+
/** One file's evaluation and marker/version classification, every
|
|
1820
|
+
* outcome carrying the diagnostic that names this file. */
|
|
1821
|
+
async function evaluateChainFile(path, cliVersion) {
|
|
1738
1822
|
let exported;
|
|
1739
1823
|
try {
|
|
1740
1824
|
exported = await evaluateConfigFile(path);
|
|
1741
1825
|
} catch (cause) {
|
|
1742
|
-
return
|
|
1826
|
+
return {
|
|
1827
|
+
ok: false,
|
|
1828
|
+
diagnostic: importsMissingPrismaPackage(cause) ? prismaConfigUnresolvedDiagnostic(path, cliVersion) : unreadableDiagnostic(path, cause)
|
|
1829
|
+
};
|
|
1743
1830
|
}
|
|
1744
|
-
if (!hasVersionMarker(exported)) return
|
|
1831
|
+
if (!hasVersionMarker(exported)) return {
|
|
1832
|
+
ok: false,
|
|
1833
|
+
diagnostic: missingMarkerDiagnostic(path)
|
|
1834
|
+
};
|
|
1745
1835
|
const version = exported[MARKER_KEY];
|
|
1746
|
-
if (version !== 1) return
|
|
1836
|
+
if (version !== 1) return {
|
|
1837
|
+
ok: false,
|
|
1838
|
+
diagnostic: unsupportedVersionDiagnostic(path, version)
|
|
1839
|
+
};
|
|
1747
1840
|
return {
|
|
1748
|
-
|
|
1749
|
-
|
|
1841
|
+
ok: true,
|
|
1842
|
+
exported
|
|
1843
|
+
};
|
|
1844
|
+
}
|
|
1845
|
+
/** Where the chain goes after the file at `path` declared `parent`:
|
|
1846
|
+
* false ends it, a path names the next file (checked to exist and to
|
|
1847
|
+
* not close a cycle), absence resumes automatic discovery above. */
|
|
1848
|
+
function followParent(path, parent, collected) {
|
|
1849
|
+
if (parent === false) return { next: null };
|
|
1850
|
+
if (typeof parent === "string") {
|
|
1851
|
+
const target = resolve(dirname(path), parent);
|
|
1852
|
+
if (!isFileAt(target)) return { diagnostic: missingParentDiagnostic(path, target) };
|
|
1853
|
+
const real = realpathOr(target);
|
|
1854
|
+
if (collected.has(real)) return { diagnostic: parentCycleDiagnostic(path, target) };
|
|
1855
|
+
return { next: {
|
|
1856
|
+
kind: "file",
|
|
1857
|
+
path: real
|
|
1858
|
+
} };
|
|
1859
|
+
}
|
|
1860
|
+
if (parent !== void 0) return { diagnostic: invalidParentDiagnostic(path, parent) };
|
|
1861
|
+
return { next: {
|
|
1862
|
+
kind: "scan",
|
|
1863
|
+
dirs: dirsAbove(realpathOr(dirname(path)))
|
|
1864
|
+
} };
|
|
1865
|
+
}
|
|
1866
|
+
async function collectChain(first, cliVersion) {
|
|
1867
|
+
const files = [];
|
|
1868
|
+
const collected = /* @__PURE__ */ new Set();
|
|
1869
|
+
let next = first;
|
|
1870
|
+
while (next !== null) {
|
|
1871
|
+
const path = next.kind === "file" ? next.path : nextDiscoveredFile(next.dirs, collected);
|
|
1872
|
+
if (path === null) break;
|
|
1873
|
+
const evaluated = await evaluateChainFile(path, cliVersion);
|
|
1874
|
+
if (!evaluated.ok) return failedChain(files, evaluated.diagnostic);
|
|
1875
|
+
files.push({
|
|
1876
|
+
path,
|
|
1877
|
+
sections: sectionsOf(evaluated.exported)
|
|
1878
|
+
});
|
|
1879
|
+
collected.add(realpathOr(path));
|
|
1880
|
+
const link = followParent(path, evaluated.exported[PARENT_KEY], collected);
|
|
1881
|
+
if ("diagnostic" in link) return failedChain(files, link.diagnostic);
|
|
1882
|
+
next = link.next;
|
|
1883
|
+
}
|
|
1884
|
+
return {
|
|
1885
|
+
files,
|
|
1750
1886
|
diagnostics: []
|
|
1751
1887
|
};
|
|
1752
1888
|
}
|
|
1889
|
+
/**
|
|
1890
|
+
* The real-disk loader behind Runtime.loadConfig. The bin binds it to
|
|
1891
|
+
* the process cwd and its own version; tests hand in fixtures.
|
|
1892
|
+
* `cliVersion` names the exact prisma version in the install guidance
|
|
1893
|
+
* when the 'prisma/config' entry point cannot be resolved; absent, the
|
|
1894
|
+
* guidance names no version rather than an example that installs the
|
|
1895
|
+
* wrong one.
|
|
1896
|
+
*
|
|
1897
|
+
* Every path handed onward is absolute — one more thing than either
|
|
1898
|
+
* reference repository does, since both are handed an absolute path
|
|
1899
|
+
* before they reach c12. Given a relative path, c12 resolves it a
|
|
1900
|
+
* second time against its own cwd and looks for a file that is not
|
|
1901
|
+
* there, and jiti cannot import a relative specifier at all. Resolving
|
|
1902
|
+
* here also makes the file's path in every diagnostic absolute, and
|
|
1903
|
+
* makes every chain-path comparison compare like with like. The anchor
|
|
1904
|
+
* directory is additionally resolved through symlinks, so discovered
|
|
1905
|
+
* files and the errors about them name real paths.
|
|
1906
|
+
*/
|
|
1907
|
+
async function loadConfig(cwd, configPath, cliVersion) {
|
|
1908
|
+
const root = resolve(cwd);
|
|
1909
|
+
if (configPath === void 0) return collectChain({
|
|
1910
|
+
kind: "scan",
|
|
1911
|
+
dirs: discoveryDirs(realpathOr(root))
|
|
1912
|
+
}, cliVersion);
|
|
1913
|
+
const named = resolve(root, configPath);
|
|
1914
|
+
if (!existsSync(named)) return failedChain([], missingNamedFileDiagnostic(named));
|
|
1915
|
+
return collectChain({
|
|
1916
|
+
kind: "file",
|
|
1917
|
+
path: realpathOr(named)
|
|
1918
|
+
}, cliVersion);
|
|
1919
|
+
}
|
|
1753
1920
|
//#endregion
|
|
1754
1921
|
//#region src/execution/pre-parse-argv.ts
|
|
1755
1922
|
function flagTokens$1(argv) {
|
|
@@ -1777,18 +1944,51 @@ function versionFlagGiven(argv) {
|
|
|
1777
1944
|
function configFlagGivenNoValue(argv) {
|
|
1778
1945
|
return flagTokens$1(argv).includes("--config=");
|
|
1779
1946
|
}
|
|
1947
|
+
const FORMATS = [
|
|
1948
|
+
"human",
|
|
1949
|
+
"json",
|
|
1950
|
+
"markdown"
|
|
1951
|
+
];
|
|
1952
|
+
function isFormat(value) {
|
|
1953
|
+
return value !== void 0 && FORMATS.includes(value);
|
|
1954
|
+
}
|
|
1955
|
+
/** argv with the format-selection tokens removed: `--json`,
|
|
1956
|
+
* `--format=<value>`, and `--format` with the value after it, only
|
|
1957
|
+
* when the value is a recognised format. Nothing after a bare `--` is
|
|
1958
|
+
* a flag, so the scan stops there and keeps the rest. */
|
|
1959
|
+
function withoutFormatFlags(argv) {
|
|
1960
|
+
const terminator = argv.indexOf("--");
|
|
1961
|
+
const tokens = terminator === -1 ? argv : argv.slice(0, terminator);
|
|
1962
|
+
const rest = terminator === -1 ? [] : argv.slice(terminator);
|
|
1963
|
+
const kept = [];
|
|
1964
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
1965
|
+
const token = tokens[index];
|
|
1966
|
+
if (token === "--json") continue;
|
|
1967
|
+
if (token.startsWith("--format=") && isFormat(token.slice(9))) continue;
|
|
1968
|
+
if (token === "--format" && isFormat(tokens[index + 1])) {
|
|
1969
|
+
index += 1;
|
|
1970
|
+
continue;
|
|
1971
|
+
}
|
|
1972
|
+
kept.push(token);
|
|
1973
|
+
}
|
|
1974
|
+
return [...kept, ...rest];
|
|
1975
|
+
}
|
|
1780
1976
|
/** The format requested by --json / --format / --format=<value>, if
|
|
1781
|
-
* any.
|
|
1977
|
+
* any. An explicit `--format` wins over `--json` whichever comes
|
|
1978
|
+
* first, as applySharedFlags decides it after parsing. */
|
|
1782
1979
|
function formatFlagGiven(argv) {
|
|
1783
1980
|
const tokens = flagTokens$1(argv);
|
|
1784
1981
|
for (const [index, token] of tokens.entries()) {
|
|
1785
|
-
if (token
|
|
1786
|
-
|
|
1982
|
+
if (token.startsWith("--format=")) {
|
|
1983
|
+
const value = token.slice(9);
|
|
1984
|
+
if (isFormat(value)) return value;
|
|
1985
|
+
}
|
|
1787
1986
|
if (token === "--format") {
|
|
1788
1987
|
const value = tokens[index + 1];
|
|
1789
|
-
if (value
|
|
1988
|
+
if (isFormat(value)) return value;
|
|
1790
1989
|
}
|
|
1791
1990
|
}
|
|
1991
|
+
return tokens.includes("--json") ? "json" : void 0;
|
|
1792
1992
|
}
|
|
1793
1993
|
//#endregion
|
|
1794
1994
|
//#region src/execution/shared-flags.ts
|
|
@@ -1818,7 +2018,11 @@ const RESERVED_ALIASES = new Set([
|
|
|
1818
2018
|
const SHARED_FLAG_PARAMETERS = {
|
|
1819
2019
|
format: {
|
|
1820
2020
|
kind: "enum",
|
|
1821
|
-
values: [
|
|
2021
|
+
values: [
|
|
2022
|
+
"human",
|
|
2023
|
+
"json",
|
|
2024
|
+
"markdown"
|
|
2025
|
+
],
|
|
1822
2026
|
optional: true,
|
|
1823
2027
|
brief: "Output format"
|
|
1824
2028
|
},
|
|
@@ -1916,7 +2120,7 @@ function applySharedFlags(state, shared, runtime) {
|
|
|
1916
2120
|
state.confirmValues = [...shared.confirm ?? []];
|
|
1917
2121
|
state.interactive = shared.interactive ?? defaultInteractive(runtime);
|
|
1918
2122
|
state.logLevel = resolveLogLevel(shared);
|
|
1919
|
-
state.colorEnabled = resolveColorEnabled(shared, runtime);
|
|
2123
|
+
state.colorEnabled = state.format === "markdown" ? false : resolveColorEnabled(shared, runtime);
|
|
1920
2124
|
state.configPath = shared.config;
|
|
1921
2125
|
}
|
|
1922
2126
|
/**
|
|
@@ -2037,17 +2241,19 @@ function validateSectionOwnership(spec, path, def) {
|
|
|
2037
2241
|
* a section may only be named something the file format leaves free:
|
|
2038
2242
|
* not `$`-prefixed (those are metadata — $prismaConfig is the version
|
|
2039
2243
|
* marker, and a $meta key is deleted before the loader ever sees it),
|
|
2040
|
-
*
|
|
2041
|
-
*
|
|
2042
|
-
*
|
|
2043
|
-
*
|
|
2244
|
+
* not `parent` (the engine's chain directive, read and stripped by
|
|
2245
|
+
* the loader), and not `extends` (the key config loaders take as an
|
|
2246
|
+
* instruction to merge another file in). Both the families and the
|
|
2247
|
+
* commands mounted without one are checked: whoever declares the
|
|
2248
|
+
* section, claiming a reserved name is broken at build time, not at a
|
|
2249
|
+
* user's runtime. */
|
|
2044
2250
|
function validateConfigSectionNames(spec) {
|
|
2045
2251
|
for (const commandFamily of spec.commandFamilies) rejectReservedSectionName("command family", commandFamily.configSection);
|
|
2046
2252
|
for (const [path, def] of Object.entries(spec.commands)) rejectReservedSectionName(`command '${path}'`, def.needs.config);
|
|
2047
2253
|
}
|
|
2048
2254
|
function rejectReservedSectionName(owner, section) {
|
|
2049
2255
|
if (section === void 0 || !reservedConfigSectionName(section.name)) return;
|
|
2050
|
-
throw constructionError(`${owner} declares config section '${section.name}', a name the config file reserves ('extends' is a config loader's merge directive, and '$'-prefixed keys are metadata)`);
|
|
2256
|
+
throw constructionError(`${owner} declares config section '${section.name}', a name the config file reserves ('parent' is the engine's chain directive, 'extends' is a config loader's merge directive, and '$'-prefixed keys are metadata)`);
|
|
2051
2257
|
}
|
|
2052
2258
|
function validateDocsBaseUrls(spec) {
|
|
2053
2259
|
for (const commandFamily of spec.commandFamilies) {
|
|
@@ -2139,6 +2345,122 @@ function matchFlagRedirect(table, commandPath, typedFlags) {
|
|
|
2139
2345
|
}
|
|
2140
2346
|
}
|
|
2141
2347
|
//#endregion
|
|
2348
|
+
//#region src/config-merge.ts
|
|
2349
|
+
/**
|
|
2350
|
+
* Per-key resolution of one config section over the loaded chain, and
|
|
2351
|
+
* the provenance that survives it: which files contributed the resolved
|
|
2352
|
+
* value, and which file wrote each of its top-level keys, so
|
|
2353
|
+
* diagnostics name the file to fix and relative paths resolve against
|
|
2354
|
+
* the file that declared them.
|
|
2355
|
+
*
|
|
2356
|
+
* A section's value is user code — a property getter can throw or side
|
|
2357
|
+
* effect — so each contributor's value is read exactly once, inside a
|
|
2358
|
+
* guard that turns a throw into a config error naming that file.
|
|
2359
|
+
*/
|
|
2360
|
+
function isPlainObject(value) {
|
|
2361
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
2362
|
+
const proto = Object.getPrototypeOf(value);
|
|
2363
|
+
return proto === Object.prototype || proto === null;
|
|
2364
|
+
}
|
|
2365
|
+
function snapshotContribution(file, name) {
|
|
2366
|
+
if (!Object.hasOwn(file.sections, name)) return null;
|
|
2367
|
+
const raw = file.sections[name];
|
|
2368
|
+
if (raw === void 0) return null;
|
|
2369
|
+
if (!isPlainObject(raw)) return {
|
|
2370
|
+
file,
|
|
2371
|
+
value: raw,
|
|
2372
|
+
keys: null
|
|
2373
|
+
};
|
|
2374
|
+
const entries = Object.entries(raw).filter(([, value]) => value !== void 0);
|
|
2375
|
+
return {
|
|
2376
|
+
file,
|
|
2377
|
+
value: Object.fromEntries(entries),
|
|
2378
|
+
keys: new Set(entries.map(([key]) => key))
|
|
2379
|
+
};
|
|
2380
|
+
}
|
|
2381
|
+
/** The engine's default merge: per key at the section's top level, the
|
|
2382
|
+
* child's key winning, replacement below. fromEntries rather than
|
|
2383
|
+
* key-by-key assignment: assigning a key named `__proto__` would run
|
|
2384
|
+
* the prototype setter instead of creating an own property. */
|
|
2385
|
+
function mergePerKey(parent, child) {
|
|
2386
|
+
if (!isPlainObject(parent) || !isPlainObject(child)) return child;
|
|
2387
|
+
return Object.fromEntries([...Object.entries(parent), ...Object.entries(child)]);
|
|
2388
|
+
}
|
|
2389
|
+
function provenanceOf(value, contributions) {
|
|
2390
|
+
const files = contributions.map((contribution) => contribution.file.path);
|
|
2391
|
+
return {
|
|
2392
|
+
files,
|
|
2393
|
+
keys: isPlainObject(value) ? Object.fromEntries(Object.keys(value).map((key) => [key, contributions.find((contribution) => contribution.keys?.has(key))?.file.path ?? files[0]])) : {}
|
|
2394
|
+
};
|
|
2395
|
+
}
|
|
2396
|
+
/**
|
|
2397
|
+
* Resolves `section` over the chain, nearest first: the farthest
|
|
2398
|
+
* declaring file's value, folded under each nearer one with the
|
|
2399
|
+
* section's own merge or the engine default. A plain-object result is
|
|
2400
|
+
* always a fresh, frozen object — the files' exports are never
|
|
2401
|
+
* mutated — and the result carries the provenance resolveSectionPath
|
|
2402
|
+
* consumes.
|
|
2403
|
+
*/
|
|
2404
|
+
function resolveSectionOverChain(section, files) {
|
|
2405
|
+
const contributions = [];
|
|
2406
|
+
for (const file of files) {
|
|
2407
|
+
let contribution;
|
|
2408
|
+
try {
|
|
2409
|
+
contribution = snapshotContribution(file, section.name);
|
|
2410
|
+
} catch (cause) {
|
|
2411
|
+
return {
|
|
2412
|
+
ok: false,
|
|
2413
|
+
file: file.path,
|
|
2414
|
+
cause
|
|
2415
|
+
};
|
|
2416
|
+
}
|
|
2417
|
+
if (contribution !== null) contributions.push(contribution);
|
|
2418
|
+
}
|
|
2419
|
+
const contributors = contributions.map((contribution) => contribution.file);
|
|
2420
|
+
if (contributions.length === 0) return {
|
|
2421
|
+
ok: true,
|
|
2422
|
+
value: void 0,
|
|
2423
|
+
contributors,
|
|
2424
|
+
provenance: {
|
|
2425
|
+
files: [],
|
|
2426
|
+
keys: {}
|
|
2427
|
+
}
|
|
2428
|
+
};
|
|
2429
|
+
const merge = section.merge ?? mergePerKey;
|
|
2430
|
+
let merged;
|
|
2431
|
+
try {
|
|
2432
|
+
merged = contributions.map((contribution) => contribution.value).reduceRight((parent, child) => merge(parent, child));
|
|
2433
|
+
} catch (cause) {
|
|
2434
|
+
return {
|
|
2435
|
+
ok: false,
|
|
2436
|
+
file: contributions[0].file.path,
|
|
2437
|
+
cause
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
const value = isPlainObject(merged) ? Object.freeze(merged) : merged;
|
|
2441
|
+
return {
|
|
2442
|
+
ok: true,
|
|
2443
|
+
value,
|
|
2444
|
+
contributors,
|
|
2445
|
+
provenance: provenanceOf(value, contributions)
|
|
2446
|
+
};
|
|
2447
|
+
}
|
|
2448
|
+
/**
|
|
2449
|
+
* Resolves a path found under a TOP-LEVEL `key` of a resolved section
|
|
2450
|
+
* value against the file that declared that key — never against cwd or
|
|
2451
|
+
* the nearest config file. The intended caller is a section validator,
|
|
2452
|
+
* which receives the provenance as its second argument and returns the
|
|
2453
|
+
* resolved absolute path in its validated value; an absolute path comes
|
|
2454
|
+
* back unchanged. Throws on a key the resolved value does not carry at its
|
|
2455
|
+
* top level — a silent fallback could resolve against the wrong file,
|
|
2456
|
+
* which is the mistake this helper exists to prevent.
|
|
2457
|
+
*/
|
|
2458
|
+
function resolveSectionPath(provenance, key, path) {
|
|
2459
|
+
if (isAbsolute(path)) return path;
|
|
2460
|
+
if (!Object.hasOwn(provenance.keys, key)) throw new Error(`@prisma/cli-engine: resolveSectionPath resolves only top-level section keys, and '${key}' is not a top-level key of the resolved section`);
|
|
2461
|
+
return resolve(dirname(provenance.keys[key]), path);
|
|
2462
|
+
}
|
|
2463
|
+
//#endregion
|
|
2142
2464
|
//#region src/execution/palette.ts
|
|
2143
2465
|
/**
|
|
2144
2466
|
* Tones into bytes, and text into a display width. Basic 16-colour SGR
|
|
@@ -2240,16 +2562,21 @@ function renderEventHuman(invocation, event) {
|
|
|
2240
2562
|
return;
|
|
2241
2563
|
case "remediation": return;
|
|
2242
2564
|
case "endpoint":
|
|
2243
|
-
stderr.write(`${event.name}: ${event.url}\n`);
|
|
2244
|
-
return;
|
|
2245
2565
|
case "status":
|
|
2246
|
-
stderr.write(`${event.subject}: ${event.from === void 0 ? "" : `${event.from} → `}${event.status}\n`);
|
|
2247
|
-
return;
|
|
2248
2566
|
case "artifact":
|
|
2249
|
-
stderr.write(`${event
|
|
2567
|
+
stderr.write(`${commentaryLine(event)}\n`);
|
|
2250
2568
|
return;
|
|
2251
2569
|
}
|
|
2252
2570
|
}
|
|
2571
|
+
/** The one line an endpoint, status, or artifact event prints, in
|
|
2572
|
+
* every text format. */
|
|
2573
|
+
function commentaryLine(event) {
|
|
2574
|
+
switch (event.kind) {
|
|
2575
|
+
case "endpoint": return `${event.name}: ${event.url}`;
|
|
2576
|
+
case "status": return `${event.subject}: ${event.from === void 0 ? "" : `${event.from} → `}${event.status}`;
|
|
2577
|
+
case "artifact": return `${event.path}${event.description === void 0 ? "" : ` — ${event.description}`}`;
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2253
2580
|
/**
|
|
2254
2581
|
* The four Status glyphs. The step-outcome map above and the
|
|
2255
2582
|
* diagnostic-severity map below answer different questions, but the
|
|
@@ -2334,7 +2661,7 @@ function toned(text, tone) {
|
|
|
2334
2661
|
function writeFields(rows, rail, paint, write) {
|
|
2335
2662
|
const cells = rows.map((row) => ({
|
|
2336
2663
|
label: toned(extend(row.label, ":"), "heading"),
|
|
2337
|
-
value: row.sensitive === true ? MASK : orPlaceholder(row.value)
|
|
2664
|
+
value: row.sensitive === true ? MASK : orPlaceholder$1(row.value)
|
|
2338
2665
|
}));
|
|
2339
2666
|
const width = Math.max(0, ...cells.map((cell) => textWidth(cell.label)));
|
|
2340
2667
|
const prefix = rail ? `${paint("structure", RAIL$1)}${COLUMN_GAP}` : "";
|
|
@@ -2351,17 +2678,16 @@ function sentenceCase(text) {
|
|
|
2351
2678
|
if (typeof text !== "string" || text === "") return text;
|
|
2352
2679
|
return `${text[0].toUpperCase()}${text.slice(1)}`;
|
|
2353
2680
|
}
|
|
2354
|
-
const PLACEHOLDER = "—";
|
|
2355
2681
|
/** An absent value renders as a dim em dash rather than invented prose
|
|
2356
2682
|
* ("none", "n/a") in data tone. */
|
|
2357
|
-
function orPlaceholder(cell) {
|
|
2683
|
+
function orPlaceholder$1(cell) {
|
|
2358
2684
|
return cell === "" || typeof cell !== "string" && textWidth(cell) === 0 ? [{
|
|
2359
|
-
text:
|
|
2685
|
+
text: "—",
|
|
2360
2686
|
tone: "placeholder"
|
|
2361
2687
|
}] : cell;
|
|
2362
2688
|
}
|
|
2363
2689
|
function writeTable(columns, rows, paint, write) {
|
|
2364
|
-
const all = [columns.map((column) => toned(sentenceCase(column), "heading")), ...rows.map((row) => row.map(orPlaceholder))];
|
|
2690
|
+
const all = [columns.map((column) => toned(sentenceCase(column), "heading")), ...rows.map((row) => row.map(orPlaceholder$1))];
|
|
2365
2691
|
const widths = [];
|
|
2366
2692
|
for (const row of all) for (const [index, cell] of row.entries()) widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
2367
2693
|
for (const row of all) write(row.map((cell, index) => renderText(index === row.length - 1 ? cell : padTo(cell, widths[index]), paint)).join(COLUMN_GAP).replace(TRAILING_SPACES, ""));
|
|
@@ -2463,6 +2789,184 @@ function renderCompletedHuman(invocation, presented) {
|
|
|
2463
2789
|
writeSections(sections, runtime.stderr);
|
|
2464
2790
|
if (!(runtime.isTty.stdout && runtime.isTty.stderr && runtime.outputStreamsShareDevice !== false)) for (const line of presented.presentation.stdout) runtime.stdout.write(`${line}\n`);
|
|
2465
2791
|
}
|
|
2792
|
+
//#endregion
|
|
2793
|
+
//#region src/execution/markdown.ts
|
|
2794
|
+
const BACKSLASH = /\\/g;
|
|
2795
|
+
const PIPE = /\|/g;
|
|
2796
|
+
const NEWLINE = /\n/g;
|
|
2797
|
+
const BACKTICK_RUN = /`+/g;
|
|
2798
|
+
function longestBacktickRun(text) {
|
|
2799
|
+
let longest = 0;
|
|
2800
|
+
for (const run of text.match(BACKTICK_RUN) ?? []) longest = Math.max(longest, run.length);
|
|
2801
|
+
return longest;
|
|
2802
|
+
}
|
|
2803
|
+
/** An inline code span whose delimiter is one backtick longer than any
|
|
2804
|
+
* run inside it, padded when the content starts or ends with one. */
|
|
2805
|
+
function codeSpan(text) {
|
|
2806
|
+
const delimiter = "`".repeat(longestBacktickRun(text) + 1);
|
|
2807
|
+
return `${delimiter}${text.startsWith("`") || text.endsWith("`") ? ` ${text} ` : text}${delimiter}`;
|
|
2808
|
+
}
|
|
2809
|
+
/** A fenced block whose fence is one backtick longer than any run in
|
|
2810
|
+
* its lines, and at least three. */
|
|
2811
|
+
function fenced(lines, language = "") {
|
|
2812
|
+
const longest = Math.max(0, ...lines.map(longestBacktickRun));
|
|
2813
|
+
const delimiter = "`".repeat(Math.max(3, longest + 1));
|
|
2814
|
+
return [
|
|
2815
|
+
`${delimiter}${language}`,
|
|
2816
|
+
...lines,
|
|
2817
|
+
delimiter
|
|
2818
|
+
];
|
|
2819
|
+
}
|
|
2820
|
+
function orPlaceholder(text) {
|
|
2821
|
+
const plain = plainText(text);
|
|
2822
|
+
return plain === "" ? "—" : plain;
|
|
2823
|
+
}
|
|
2824
|
+
/**
|
|
2825
|
+
* Plain Markdown, for a reader that is a model rather than a terminal:
|
|
2826
|
+
* every value labelled, nothing padded, wrapped, aligned, or coloured.
|
|
2827
|
+
*/
|
|
2828
|
+
function renderBlockMarkdown(block) {
|
|
2829
|
+
switch (block.kind) {
|
|
2830
|
+
case "summary": return [`[${block.status}] ${plainText(block.text)}`];
|
|
2831
|
+
case "fields": return block.rows.map((row) => `${plainText(row.label)}: ${row.sensitive === true ? MASK : orPlaceholder(row.value)}`);
|
|
2832
|
+
case "table": return renderTable(block.columns, block.rows);
|
|
2833
|
+
case "list": return block.items.map((item) => `- ${plainText(item)}`);
|
|
2834
|
+
case "tree": return block.roots.flatMap((root) => renderTreeNode(root, 0));
|
|
2835
|
+
case "drawing": return fenced(block.lines.map(plainText));
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
function escapeCell(text) {
|
|
2839
|
+
return text.replace(BACKSLASH, "\\\\").replace(PIPE, "\\|").replace(NEWLINE, " ");
|
|
2840
|
+
}
|
|
2841
|
+
function cell(text) {
|
|
2842
|
+
return escapeCell(orPlaceholder(text));
|
|
2843
|
+
}
|
|
2844
|
+
function pipeRow(cells) {
|
|
2845
|
+
return `| ${cells.join(" | ")} |`;
|
|
2846
|
+
}
|
|
2847
|
+
function renderTable(columns, rows) {
|
|
2848
|
+
const lines = [
|
|
2849
|
+
pipeRow(columns.map((column) => cell(sentenceCase(column)))),
|
|
2850
|
+
pipeRow(columns.map(() => "---")),
|
|
2851
|
+
...rows.map((row) => pipeRow(row.map(cell)))
|
|
2852
|
+
];
|
|
2853
|
+
return rows.length === 0 ? [...lines, "(no rows)"] : lines;
|
|
2854
|
+
}
|
|
2855
|
+
function renderTreeNode(node, depth) {
|
|
2856
|
+
const indent = " ".repeat(depth);
|
|
2857
|
+
const label = plainText(node.label);
|
|
2858
|
+
return [node.status === void 0 ? `${indent}- ${label}` : `${indent}- [${node.status}] ${label}`, ...(node.children ?? []).flatMap((child) => renderTreeNode(child, depth + 1))];
|
|
2859
|
+
}
|
|
2860
|
+
function renderNextActionMarkdown(action) {
|
|
2861
|
+
const target = action.command ?? action.url;
|
|
2862
|
+
if (target === void 0 && action.commands !== void 0) return [`- ${action.label}`, ...action.commands.map((command) => ` - ${codeSpan(command)}`)];
|
|
2863
|
+
if (target === void 0 || target === action.label) return [action.command !== void 0 ? `- ${codeSpan(action.label)}` : `- ${action.label}`];
|
|
2864
|
+
return [action.command !== void 0 ? `- ${action.label}: ${codeSpan(target)}` : `- ${action.label}: ${target}`];
|
|
2865
|
+
}
|
|
2866
|
+
function whereLine(where) {
|
|
2867
|
+
if (where === void 0) return;
|
|
2868
|
+
if (where.path !== void 0 && where.line !== void 0) return `where: ${where.path}:${where.line}`;
|
|
2869
|
+
if (where.path !== void 0) return `where: ${where.path}`;
|
|
2870
|
+
if (where.line !== void 0) return `where: line ${where.line}`;
|
|
2871
|
+
}
|
|
2872
|
+
function renderDiagnosticMarkdown(diagnostic) {
|
|
2873
|
+
const lines = [`[${diagnostic.severity}] ${diagnostic.code}: ${diagnostic.summary}`];
|
|
2874
|
+
if (diagnostic.why !== void 0) lines.push(`why: ${diagnostic.why}`);
|
|
2875
|
+
const where = whereLine(diagnostic.where);
|
|
2876
|
+
if (where !== void 0) lines.push(where);
|
|
2877
|
+
for (const action of diagnostic.nextActions) lines.push(...renderNextActionMarkdown(action));
|
|
2878
|
+
if (diagnostic.docsUrl !== void 0) lines.push(`docs: ${diagnostic.docsUrl}`);
|
|
2879
|
+
return lines;
|
|
2880
|
+
}
|
|
2881
|
+
/** Joins sections with one blank line each, dropping empty ones, and
|
|
2882
|
+
* ends with exactly one newline; nothing when there is nothing. */
|
|
2883
|
+
function joinSections(sections) {
|
|
2884
|
+
const kept = sections.filter((section) => section.length > 0);
|
|
2885
|
+
if (kept.length === 0) return "";
|
|
2886
|
+
return `${kept.map((section) => section.join("\n")).join("\n\n")}\n`;
|
|
2887
|
+
}
|
|
2888
|
+
function diagnosticsSection(diagnostics) {
|
|
2889
|
+
if (diagnostics.length === 0) return [];
|
|
2890
|
+
return ["### Diagnostics", ...diagnostics.flatMap((diagnostic, index) => [...index === 0 ? [] : [""], ...renderDiagnosticMarkdown(diagnostic)])];
|
|
2891
|
+
}
|
|
2892
|
+
/** Everything on stdout: the blocks, then `### Next`, then
|
|
2893
|
+
* `### Diagnostics`. The `stdout` presentation lines are never
|
|
2894
|
+
* printed; the table already carries them. */
|
|
2895
|
+
function renderCompletedMarkdown(invocation, presented) {
|
|
2896
|
+
const { runtime, state } = invocation;
|
|
2897
|
+
const sections = presented.presentation.human.map(renderBlockMarkdown);
|
|
2898
|
+
if (presented.presentation.next.length > 0) sections.push(["### Next", ...presented.presentation.next.flatMap(renderNextActionMarkdown)]);
|
|
2899
|
+
sections.push(diagnosticsSection(presented.diagnostics.map((diagnostic) => withDocsUrl(state, diagnostic))));
|
|
2900
|
+
runtime.stdout.write(joinSections(sections));
|
|
2901
|
+
}
|
|
2902
|
+
/** The error in the diagnostic shape, then the accompanying findings
|
|
2903
|
+
* under `### Diagnostics`. The envelope's top-level `nextActions`
|
|
2904
|
+
* duplicate the error's and are not printed again. */
|
|
2905
|
+
function renderErroredMarkdown(invocation, envelope) {
|
|
2906
|
+
invocation.runtime.stdout.write(joinSections([renderDiagnosticMarkdown(envelope.error), diagnosticsSection(envelope.diagnostics)]));
|
|
2907
|
+
}
|
|
2908
|
+
/** Config-section warnings of an OK run, ahead of whatever the run
|
|
2909
|
+
* prints next, with one blank line between. */
|
|
2910
|
+
function renderWarningsMarkdown(invocation, diagnostics) {
|
|
2911
|
+
const section = joinSections(diagnostics.map(renderDiagnosticMarkdown));
|
|
2912
|
+
if (section !== "") invocation.runtime.stdout.write(`${section}\n`);
|
|
2913
|
+
}
|
|
2914
|
+
function renderChildNextActionsMarkdown(invocation, actions) {
|
|
2915
|
+
invocation.runtime.stdout.write(joinSections([actions.flatMap(renderNextActionMarkdown)]));
|
|
2916
|
+
}
|
|
2917
|
+
/** One line per event on stdout as it happens. A step starting, its
|
|
2918
|
+
* progress, and a remediation are not printed. */
|
|
2919
|
+
function renderEventMarkdown(invocation, event) {
|
|
2920
|
+
const { stdout } = invocation.runtime;
|
|
2921
|
+
switch (event.kind) {
|
|
2922
|
+
case "message":
|
|
2923
|
+
stdout.write(`${event.text}\n`);
|
|
2924
|
+
return;
|
|
2925
|
+
case "output":
|
|
2926
|
+
stdout.write(`${event.line}\n`);
|
|
2927
|
+
return;
|
|
2928
|
+
case "step-finished":
|
|
2929
|
+
stdout.write(`[${event.outcome}] ${event.step}\n`);
|
|
2930
|
+
return;
|
|
2931
|
+
case "endpoint":
|
|
2932
|
+
case "status":
|
|
2933
|
+
case "artifact":
|
|
2934
|
+
stdout.write(`${commentaryLine(event)}\n`);
|
|
2935
|
+
return;
|
|
2936
|
+
case "step-started":
|
|
2937
|
+
case "progress":
|
|
2938
|
+
case "remediation": return;
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
function parenthesized(suffix) {
|
|
2942
|
+
return suffix.startsWith("(") ? suffix : `(${suffix})`;
|
|
2943
|
+
}
|
|
2944
|
+
function helpTable(headers, rows) {
|
|
2945
|
+
return [
|
|
2946
|
+
pipeRow(headers),
|
|
2947
|
+
pipeRow(["---", "---"]),
|
|
2948
|
+
...rows.map((row) => pipeRow([escapeCell(codeSpan(row.name.trimStart())), escapeCell(row.suffix === void 0 || row.suffix === "" ? row.brief : `${row.brief} ${parenthesized(row.suffix)}`)]))
|
|
2949
|
+
];
|
|
2950
|
+
}
|
|
2951
|
+
function helpSection(heading, headers, rows) {
|
|
2952
|
+
return rows.length === 0 ? [] : [[`## ${heading}`], helpTable(headers, rows)];
|
|
2953
|
+
}
|
|
2954
|
+
/** The help card as Markdown: headings, paragraphs, pipe tables, and
|
|
2955
|
+
* bash fences, one blank line between everything. */
|
|
2956
|
+
function renderHelpMarkdown(card) {
|
|
2957
|
+
const sections = [[`# ${card.name}`]];
|
|
2958
|
+
if (card.tagline !== void 0 && card.tagline !== "") sections.push([card.tagline]);
|
|
2959
|
+
if (card.usage !== void 0) sections.push(["## Usage"], fenced([card.usage], "bash"));
|
|
2960
|
+
if (card.description !== void 0) sections.push([card.description]);
|
|
2961
|
+
sections.push(...helpSection("Commands", ["Command", "Description"], card.commands), ...helpSection("Workflow", ["Run", "Purpose"], card.workflow.map((step) => ({
|
|
2962
|
+
name: step.run,
|
|
2963
|
+
brief: step.brief
|
|
2964
|
+
}))), ...helpSection("Arguments", ["Argument", "Description"], card.arguments), ...helpSection("Options", ["Flag", "Description"], card.options), ...helpSection("Global options", ["Flag", "Description"], card.globalOptions));
|
|
2965
|
+
if (card.note !== void 0) sections.push([card.note]);
|
|
2966
|
+
if (card.examples.length > 0) sections.push(["## Examples"], fenced(card.examples, "bash"));
|
|
2967
|
+
if (card.docsUrl !== void 0) sections.push([`Docs: ${card.docsUrl}`]);
|
|
2968
|
+
return joinSections(sections);
|
|
2969
|
+
}
|
|
2466
2970
|
const SEVERITY_RANK = {
|
|
2467
2971
|
error: 0,
|
|
2468
2972
|
warn: 1,
|
|
@@ -2509,6 +3013,10 @@ function reportEvent(invocation, event) {
|
|
|
2509
3013
|
});
|
|
2510
3014
|
return;
|
|
2511
3015
|
}
|
|
3016
|
+
if (state.format === "markdown") {
|
|
3017
|
+
renderEventMarkdown(invocation, event);
|
|
3018
|
+
return;
|
|
3019
|
+
}
|
|
2512
3020
|
renderEventHuman(invocation, event);
|
|
2513
3021
|
}
|
|
2514
3022
|
function flushBufferedEvents(invocation, terminal) {
|
|
@@ -2561,6 +3069,7 @@ async function checkNeeds(def, invocation) {
|
|
|
2561
3069
|
return {
|
|
2562
3070
|
kind: "ok",
|
|
2563
3071
|
config: void 0,
|
|
3072
|
+
configFiles: [],
|
|
2564
3073
|
spawnCredential: credentials.spawnCredential
|
|
2565
3074
|
};
|
|
2566
3075
|
}
|
|
@@ -2646,9 +3155,11 @@ function unknownSectionDiagnostic(path, key, configSections) {
|
|
|
2646
3155
|
where: { path }
|
|
2647
3156
|
};
|
|
2648
3157
|
}
|
|
3158
|
+
/** Every file on the chain is checked — a typo'd key in a nested file
|
|
3159
|
+
* errors even when the command's section resolved elsewhere. */
|
|
2649
3160
|
function unknownSections(loaded, configSections) {
|
|
2650
3161
|
const declared = new Set(configSections);
|
|
2651
|
-
return Object.keys(
|
|
3162
|
+
return loaded.files.flatMap((file) => Object.keys(file.sections).filter((key) => !declared.has(key)).map((key) => unknownSectionDiagnostic(file.path, key, configSections)));
|
|
2652
3163
|
}
|
|
2653
3164
|
/** The config file is read HERE and nowhere else, so a command with no
|
|
2654
3165
|
* needs.config never touches it. The file `--config` named travels on
|
|
@@ -2660,45 +3171,80 @@ async function checkConfiguration(section, invocation) {
|
|
|
2660
3171
|
const loaded = await invocation.runtime.loadConfig(configPath);
|
|
2661
3172
|
const fileLevel = [...loaded.diagnostics.filter((entry) => entry.section === null).map((entry) => entry.diagnostic), ...unknownSections(loaded, invocation.configSections)];
|
|
2662
3173
|
if (fileLevel.length > 0) return needsErrored(structuredErrorFromDiagnostic(fileLevel[0]), fileLevel.slice(1));
|
|
2663
|
-
return validateConfigSection(section, loaded, invocation
|
|
2664
|
-
}
|
|
2665
|
-
/** Validates the command's needed config section
|
|
2666
|
-
* owns absence (it receives
|
|
2667
|
-
*
|
|
2668
|
-
*
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
3174
|
+
return validateConfigSection(section, loaded, invocation);
|
|
3175
|
+
}
|
|
3176
|
+
/** Validates the command's needed config section, resolved per key over
|
|
3177
|
+
* the chain nearest-first. The validator owns absence (it receives
|
|
3178
|
+
* undefined when no file declares the section) and never throws — a
|
|
3179
|
+
* throw is an engine-boundary bug, settled as one. */
|
|
3180
|
+
function validateConfigSection(section, loaded, invocation) {
|
|
3181
|
+
const resolved = resolveSectionOverChain(section, loaded.files);
|
|
3182
|
+
if (!resolved.ok) return needsErrored(sectionUnreadableError(section.name, resolved.file, resolved.cause));
|
|
2672
3183
|
let validation;
|
|
2673
3184
|
try {
|
|
2674
|
-
validation = section.validate(
|
|
3185
|
+
validation = section.validate(resolved.value, resolved.provenance);
|
|
2675
3186
|
} catch (cause) {
|
|
2676
3187
|
return {
|
|
2677
3188
|
kind: "bug",
|
|
2678
3189
|
cause: new Error(`@prisma/cli-engine: the '${section.name}' config section validator threw instead of returning diagnostics (a validator never throws)`, { cause })
|
|
2679
3190
|
};
|
|
2680
3191
|
}
|
|
2681
|
-
if (!validation.ok) return needsErrored(
|
|
2682
|
-
kind: "user-choice",
|
|
2683
|
-
label: "Fix the reported problems in that section, then run the command again."
|
|
2684
|
-
}] }), validation.diagnostics);
|
|
3192
|
+
if (!validation.ok) return needsErrored(sectionInvalidError(section.name, resolved.contributors, loaded.files), validation.diagnostics);
|
|
2685
3193
|
writeSectionWarnings(invocation, validation.diagnostics);
|
|
2686
3194
|
return {
|
|
2687
3195
|
kind: "ok",
|
|
2688
3196
|
config: validation.value,
|
|
3197
|
+
configFiles: Object.freeze(loaded.files),
|
|
2689
3198
|
spawnCredential: void 0
|
|
2690
3199
|
};
|
|
2691
3200
|
}
|
|
3201
|
+
/** A section value's property getters and a section's custom merge are
|
|
3202
|
+
* user code alike; a throw from either is a config error naming the
|
|
3203
|
+
* file, never an engine bug. */
|
|
3204
|
+
function sectionUnreadableError(name, file, cause) {
|
|
3205
|
+
return new CliStructuredError("CLI.CONFIG_SECTION_INVALID", `The '${name}' section of ${file} is invalid: resolving its value threw '${(cause instanceof Error ? cause.message : String(cause)).split("\n", 1)[0].trim()}'.`, { nextActions: [{
|
|
3206
|
+
kind: "user-choice",
|
|
3207
|
+
label: "Fix the reported problems in that section, then run the command again."
|
|
3208
|
+
}] });
|
|
3209
|
+
}
|
|
3210
|
+
/** Provenance decides which file the error names: the one declaring
|
|
3211
|
+
* file, the nearest of several with the chain listed, or — when no
|
|
3212
|
+
* file declares the section at all — the fact that it is missing. */
|
|
3213
|
+
function sectionInvalidError(name, contributors, files) {
|
|
3214
|
+
const fix = {
|
|
3215
|
+
kind: "user-choice",
|
|
3216
|
+
label: "Fix the reported problems in that section, then run the command again."
|
|
3217
|
+
};
|
|
3218
|
+
if (contributors.length === 1) return new CliStructuredError("CLI.CONFIG_SECTION_INVALID", `The '${name}' section of ${contributors[0].path} is invalid.`, { nextActions: [fix] });
|
|
3219
|
+
if (contributors.length > 1) {
|
|
3220
|
+
const paths = contributors.map((file) => file.path);
|
|
3221
|
+
const parents = paths.length === 2 ? "its parent config file" : "its parent config files";
|
|
3222
|
+
return new CliStructuredError("CLI.CONFIG_SECTION_INVALID", `The '${name}' section, merged from ${paths[0]} and ${parents}, is invalid.`, {
|
|
3223
|
+
why: `The resolved section combines these files, nearest first: ${paths.join(", ")}.`,
|
|
3224
|
+
nextActions: [fix]
|
|
3225
|
+
});
|
|
3226
|
+
}
|
|
3227
|
+
const target = files[0]?.path ?? "prisma.config.ts";
|
|
3228
|
+
return new CliStructuredError("CLI.CONFIG_SECTION_INVALID", `The '${name}' section is missing: ${files.length === 0 ? "no config file was found" : "no loaded config file declares it"}.`, {
|
|
3229
|
+
why: files.length === 0 ? void 0 : `Config files loaded, nearest first: ${files.map((file) => file.path).join(", ")}.`,
|
|
3230
|
+
nextActions: [{
|
|
3231
|
+
kind: "user-choice",
|
|
3232
|
+
label: `Declare the '${name}' section in ${target}, then run the command again.`
|
|
3233
|
+
}]
|
|
3234
|
+
});
|
|
3235
|
+
}
|
|
2692
3236
|
/** Diagnostics on an OK validation are warnings: written to stderr as
|
|
2693
3237
|
* commentary in both formats (stderr is free for commentary in json
|
|
2694
3238
|
* mode), filtered by the active log level, never added to the stream
|
|
2695
3239
|
* or the envelope. */
|
|
2696
3240
|
function writeSectionWarnings(invocation, diagnostics) {
|
|
2697
3241
|
const state = invocation.state;
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
3242
|
+
const shown = diagnostics.filter((diagnostic) => SEVERITY_RANK[diagnostic.severity] <= SEVERITY_RANK[state.logLevel]).map((diagnostic) => withDocsUrl(state, diagnostic));
|
|
3243
|
+
if (state.format === "markdown") {
|
|
3244
|
+
renderWarningsMarkdown(invocation, shown);
|
|
3245
|
+
return;
|
|
2701
3246
|
}
|
|
3247
|
+
for (const diagnostic of shown) writeDiagnostic(invocation.runtime.stderr, diagnostic, makePaint(state.colorEnabled));
|
|
2702
3248
|
}
|
|
2703
3249
|
function dependencyResolvable(specifier, cwd) {
|
|
2704
3250
|
try {
|
|
@@ -3543,10 +4089,18 @@ function availableWidth(stream) {
|
|
|
3543
4089
|
* are stderr's. `width` is a getter because the contract reads it per
|
|
3544
4090
|
* render rather than caching it. */
|
|
3545
4091
|
function makeUi(colorEnabled, stderr) {
|
|
4092
|
+
return uiWith(colorEnabled, () => availableWidth(stderr));
|
|
4093
|
+
}
|
|
4094
|
+
/** Markdown is read as text, never on a terminal: no colour, no
|
|
4095
|
+
* width. */
|
|
4096
|
+
function unboundedUi() {
|
|
4097
|
+
return uiWith(false, () => Number.POSITIVE_INFINITY);
|
|
4098
|
+
}
|
|
4099
|
+
function uiWith(colorEnabled, width) {
|
|
3546
4100
|
const paint = makePaint(colorEnabled);
|
|
3547
4101
|
return {
|
|
3548
4102
|
get width() {
|
|
3549
|
-
return
|
|
4103
|
+
return width();
|
|
3550
4104
|
},
|
|
3551
4105
|
emphasize: (text) => paint("emphasis", text),
|
|
3552
4106
|
dim: (text) => paint("muted", text),
|
|
@@ -3582,6 +4136,12 @@ function materializePresentation(state, ui, presentations) {
|
|
|
3582
4136
|
json: presentations.json(),
|
|
3583
4137
|
next: presentations.next?.() ?? []
|
|
3584
4138
|
};
|
|
4139
|
+
if (state.format === "markdown") return {
|
|
4140
|
+
human: presentations.human(ui),
|
|
4141
|
+
stdout: [],
|
|
4142
|
+
json: void 0,
|
|
4143
|
+
next: presentations.next?.() ?? []
|
|
4144
|
+
};
|
|
3585
4145
|
return {
|
|
3586
4146
|
human: presentations.human(ui),
|
|
3587
4147
|
stdout: presentations.stdout?.() ?? [],
|
|
@@ -3589,9 +4149,9 @@ function materializePresentation(state, ui, presentations) {
|
|
|
3589
4149
|
next: presentations.next?.() ?? []
|
|
3590
4150
|
};
|
|
3591
4151
|
}
|
|
3592
|
-
function makeContext(invocation, def, config, capabilities) {
|
|
4152
|
+
function makeContext(invocation, def, config, configFiles, capabilities) {
|
|
3593
4153
|
const state = invocation.state;
|
|
3594
|
-
const ui = makeUi(state.colorEnabled, invocation.runtime.stderr);
|
|
4154
|
+
const ui = state.format === "markdown" ? unboundedUi() : makeUi(state.colorEnabled, invocation.runtime.stderr);
|
|
3595
4155
|
const present = (outcome, presentations) => {
|
|
3596
4156
|
if (state.delegatedTerminal !== void 0) throw constructionError(`command '${state.commandId}' called ctx.present while a child owned the terminal`);
|
|
3597
4157
|
const exitCode = outcome.exitCode ?? 0;
|
|
@@ -3608,6 +4168,8 @@ function makeContext(invocation, def, config, capabilities) {
|
|
|
3608
4168
|
let api;
|
|
3609
4169
|
const context = {
|
|
3610
4170
|
config,
|
|
4171
|
+
configFiles,
|
|
4172
|
+
configPath: state.configPath,
|
|
3611
4173
|
present,
|
|
3612
4174
|
activeCredential: () => invocation.runtime.credentialManager?.activeCredential() ?? Promise.resolve(null),
|
|
3613
4175
|
get api() {
|
|
@@ -3939,6 +4501,7 @@ function helpFlagGiven(argv) {
|
|
|
3939
4501
|
* render through this; applySharedFlags re-resolves once a command
|
|
3940
4502
|
* actually parses. */
|
|
3941
4503
|
function preParseColorEnabled(argv, runtime, stream) {
|
|
4504
|
+
if (formatFlagGiven(argv) === "markdown") return false;
|
|
3942
4505
|
const tokens = flagTokens(argv);
|
|
3943
4506
|
if (tokens.includes("--no-color")) return false;
|
|
3944
4507
|
if (tokens.includes("--color")) return true;
|
|
@@ -3986,27 +4549,123 @@ function resolveTarget(root, segments) {
|
|
|
3986
4549
|
* is a help request; anything carrying flags or extra tokens is not —
|
|
3987
4550
|
* `cli --unknown` and `cli project --frobnicate` must reach routing
|
|
3988
4551
|
* and usage validation, not exit 0 with a help card. A bare leaf is a
|
|
3989
|
-
* command run and is left alone.
|
|
3990
|
-
|
|
4552
|
+
* command run and is left alone. The format-selection flags do not
|
|
4553
|
+
* count: `cli project --format markdown` asks for the group's help in
|
|
4554
|
+
* Markdown. */
|
|
4555
|
+
function bareGroupInvocation(root, rawArgv) {
|
|
4556
|
+
const argv = withoutFormatFlags(rawArgv);
|
|
3991
4557
|
const segments = helpPath(argv);
|
|
3992
4558
|
if (segments.length !== argv.length) return false;
|
|
3993
4559
|
if (segments.length === 0) return true;
|
|
3994
4560
|
const { target, path } = resolveTarget(root, segments);
|
|
3995
4561
|
return target.kind === "node" && path.length === segments.length;
|
|
3996
4562
|
}
|
|
3997
|
-
function renderHelp(spec, root, argv,
|
|
3998
|
-
const
|
|
4563
|
+
function renderHelp(spec, root, argv, options, out) {
|
|
4564
|
+
const card = helpCard(spec, root, argv);
|
|
4565
|
+
if (options.format === "markdown") {
|
|
4566
|
+
out.write(renderHelpMarkdown(card));
|
|
4567
|
+
return;
|
|
4568
|
+
}
|
|
4569
|
+
out.write(renderHelpTerminal(card, makePaint(options.colorEnabled)));
|
|
4570
|
+
}
|
|
4571
|
+
function helpCard(spec, root, argv) {
|
|
3999
4572
|
const { target, path } = resolveTarget(root, helpPath(argv));
|
|
4573
|
+
return target.kind === "leaf" ? leafCard(spec, target.entry, path) : nodeCard(spec, target.node, path);
|
|
4574
|
+
}
|
|
4575
|
+
function nodeCard(spec, node, path) {
|
|
4576
|
+
const atRoot = path.length === 0;
|
|
4577
|
+
const groupPath = path.join(" ");
|
|
4578
|
+
const group = spec.groups[groupPath];
|
|
4579
|
+
return {
|
|
4580
|
+
kind: atRoot ? "root" : "group",
|
|
4581
|
+
name: [spec.name, ...path].join(" "),
|
|
4582
|
+
tagline: atRoot ? spec.help?.tagline : group?.brief,
|
|
4583
|
+
usage: void 0,
|
|
4584
|
+
description: atRoot ? spec.help?.description : group?.description,
|
|
4585
|
+
commands: nodeRows(spec, node, path),
|
|
4586
|
+
workflow: resolvedSteps((atRoot ? spec.help?.workflow : group?.workflow) ?? [], spec.name),
|
|
4587
|
+
arguments: [],
|
|
4588
|
+
options: [],
|
|
4589
|
+
globalOptions: atRoot ? sharedFlagRows() : [],
|
|
4590
|
+
note: atRoot ? void 0 : `Run '${spec.name} ${groupPath} <command> --help' for details on a command.`,
|
|
4591
|
+
examples: resolvedExamples(atRoot ? spec.help?.examples : [], spec.name),
|
|
4592
|
+
docsUrl: atRoot ? spec.help?.docsUrl : void 0
|
|
4593
|
+
};
|
|
4594
|
+
}
|
|
4595
|
+
function leafCard(spec, entry, path) {
|
|
4596
|
+
const def = entry.def;
|
|
4597
|
+
const usage = [
|
|
4598
|
+
spec.name,
|
|
4599
|
+
...path,
|
|
4600
|
+
requiredFlagUsage(def),
|
|
4601
|
+
"[options]",
|
|
4602
|
+
positionalUsage(def)
|
|
4603
|
+
].filter((part) => part !== "").join(" ");
|
|
4604
|
+
const sharedNames = Object.keys(SHARED_FLAG_PARAMETERS).map((key) => `--${kebabCase(key)}`).join(", ");
|
|
4605
|
+
return {
|
|
4606
|
+
kind: "leaf",
|
|
4607
|
+
name: [spec.name, ...path].join(" "),
|
|
4608
|
+
tagline: def.help.summary,
|
|
4609
|
+
usage,
|
|
4610
|
+
description: def.help.description,
|
|
4611
|
+
commands: [],
|
|
4612
|
+
workflow: [],
|
|
4613
|
+
arguments: Object.values(def.args.positionals).map((spec) => positionalRuntime(spec)).map((runtime) => ({
|
|
4614
|
+
name: runtime.placeholder,
|
|
4615
|
+
brief: runtime.brief,
|
|
4616
|
+
suffix: runtime.type === "optionalString" ? "(optional)" : void 0
|
|
4617
|
+
})),
|
|
4618
|
+
options: declaredFlagRows(def),
|
|
4619
|
+
globalOptions: [],
|
|
4620
|
+
note: def.kind === "server-command" ? void 0 : `Global options also apply: ${sharedNames}. Run '${spec.name} --help' for details.`,
|
|
4621
|
+
examples: resolvedExamples(def.help.examples, spec.name),
|
|
4622
|
+
docsUrl: entry.docsBaseUrl
|
|
4623
|
+
};
|
|
4624
|
+
}
|
|
4625
|
+
function resolvedSteps(steps, cliName) {
|
|
4626
|
+
return steps.map((step) => ({
|
|
4627
|
+
run: resolveExample(step.run, cliName),
|
|
4628
|
+
brief: step.brief
|
|
4629
|
+
}));
|
|
4630
|
+
}
|
|
4631
|
+
function resolvedExamples(examples, cliName) {
|
|
4632
|
+
return (examples ?? []).map((example) => resolveExample(example, cliName));
|
|
4633
|
+
}
|
|
4634
|
+
function renderHelpTerminal(card, paint) {
|
|
4000
4635
|
const lines = [];
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4636
|
+
lines.push(header(card, paint));
|
|
4637
|
+
lines.push("");
|
|
4638
|
+
if (card.kind === "leaf") {
|
|
4639
|
+
lines.push(sectionLabel(paint, "Usage"));
|
|
4640
|
+
lines.push(rail(paint, `${GAP}${paint("muted", "$")} ${paint("emphasis", card.usage ?? "")}`));
|
|
4641
|
+
} else railRows(card.commands, paint, lines);
|
|
4642
|
+
if (card.description !== void 0) {
|
|
4643
|
+
lines.push(rail(paint));
|
|
4644
|
+
proseLines(card.description, paint, lines);
|
|
4645
|
+
}
|
|
4646
|
+
workflowLines(card.workflow, paint, lines);
|
|
4647
|
+
rowSection("Arguments", card.arguments, paint, lines);
|
|
4648
|
+
rowSection("Options", card.options, paint, lines);
|
|
4649
|
+
if (card.kind === "root") {
|
|
4650
|
+
lines.push(rail(paint));
|
|
4651
|
+
lines.push(sectionLabel(paint, "Global options"));
|
|
4652
|
+
railRows(card.globalOptions, paint, lines);
|
|
4653
|
+
}
|
|
4654
|
+
if (card.note !== void 0) {
|
|
4655
|
+
lines.push(rail(paint));
|
|
4656
|
+
if (card.kind === "leaf") proseLines(card.note, paint, lines, "muted");
|
|
4657
|
+
else lines.push(rail(paint, paint("muted", card.note)));
|
|
4658
|
+
}
|
|
4659
|
+
exampleLines(card.examples, paint, lines);
|
|
4660
|
+
docsLine(card.docsUrl, paint, lines);
|
|
4661
|
+
lines.push("");
|
|
4662
|
+
return `${lines.join("\n")}\n`;
|
|
4004
4663
|
}
|
|
4005
4664
|
/** `prisma-cli project → Manage and inspect your Prisma projects` */
|
|
4006
|
-
function header(
|
|
4007
|
-
const name = paint("emphasis",
|
|
4008
|
-
if (tagline === void 0 || tagline === "") return name;
|
|
4009
|
-
return `${name} ${paint("muted", `→ ${tagline}`)}`;
|
|
4665
|
+
function header(card, paint) {
|
|
4666
|
+
const name = paint("emphasis", card.name);
|
|
4667
|
+
if (card.tagline === void 0 || card.tagline === "") return name;
|
|
4668
|
+
return `${name} ${paint("muted", `→ ${card.tagline}`)}`;
|
|
4010
4669
|
}
|
|
4011
4670
|
function rail(paint, rest = "") {
|
|
4012
4671
|
return rest === "" ? paint("structure", RAIL) : `${paint("structure", RAIL)}${GAP}${rest}`;
|
|
@@ -4014,6 +4673,12 @@ function rail(paint, rest = "") {
|
|
|
4014
4673
|
function sectionLabel(paint, label) {
|
|
4015
4674
|
return rail(paint, paint("muted", label));
|
|
4016
4675
|
}
|
|
4676
|
+
function rowSection(label, rows, paint, lines) {
|
|
4677
|
+
if (rows.length === 0) return;
|
|
4678
|
+
lines.push(rail(paint));
|
|
4679
|
+
lines.push(sectionLabel(paint, label));
|
|
4680
|
+
railRows(rows, paint, lines);
|
|
4681
|
+
}
|
|
4017
4682
|
/** Two-column rows under the rail: name in the accent, brief plain. */
|
|
4018
4683
|
function railRows(rows, paint, lines) {
|
|
4019
4684
|
const width = Math.max(0, ...rows.map((row) => textWidth(row.name)));
|
|
@@ -4042,11 +4707,23 @@ function wrap(text, width) {
|
|
|
4042
4707
|
function proseLines(text, paint, lines, tone = "plain") {
|
|
4043
4708
|
for (const line of wrap(text, WRAP_WIDTH)) lines.push(rail(paint, tone === "muted" ? paint("muted", line) : line));
|
|
4044
4709
|
}
|
|
4045
|
-
function exampleLines(examples,
|
|
4710
|
+
function exampleLines(examples, paint, lines) {
|
|
4046
4711
|
if (examples.length === 0) return;
|
|
4047
4712
|
lines.push(rail(paint));
|
|
4048
4713
|
lines.push(sectionLabel(paint, "Examples"));
|
|
4049
|
-
for (const example of examples) lines.push(rail(paint, `${GAP}${paint("muted", "$")} ${
|
|
4714
|
+
for (const example of examples) lines.push(rail(paint, `${GAP}${paint("muted", "$")} ${example}`));
|
|
4715
|
+
}
|
|
4716
|
+
/** The group's common path: `$`-prefixed copy-pastable steps in mount
|
|
4717
|
+
* order, purpose column muted, aligned like every other row block. */
|
|
4718
|
+
function workflowLines(steps, paint, lines) {
|
|
4719
|
+
if (steps.length === 0) return;
|
|
4720
|
+
lines.push(rail(paint));
|
|
4721
|
+
lines.push(sectionLabel(paint, "Workflow"));
|
|
4722
|
+
const width = Math.max(...steps.map((step) => textWidth(step.run)));
|
|
4723
|
+
for (const step of steps) {
|
|
4724
|
+
const pad = " ".repeat(width - textWidth(step.run));
|
|
4725
|
+
lines.push(rail(paint, `${GAP}${paint("muted", "$")} ${step.run}${pad}${GAP}${paint("muted", step.brief)}`));
|
|
4726
|
+
}
|
|
4050
4727
|
}
|
|
4051
4728
|
function docsLine(url, paint, lines) {
|
|
4052
4729
|
if (url === void 0) return;
|
|
@@ -4147,78 +4824,12 @@ function nodeRows(spec, node, path) {
|
|
|
4147
4824
|
}
|
|
4148
4825
|
return rows;
|
|
4149
4826
|
}
|
|
4150
|
-
function renderNodeHelp(spec, node, path, paint, lines) {
|
|
4151
|
-
const atRoot = path.length === 0;
|
|
4152
|
-
const groupPath = path.join(" ");
|
|
4153
|
-
const tagline = atRoot ? spec.help?.tagline : spec.groups[groupPath]?.brief;
|
|
4154
|
-
lines.push(header(spec, path, tagline, paint));
|
|
4155
|
-
lines.push("");
|
|
4156
|
-
railRows(nodeRows(spec, node, path), paint, lines);
|
|
4157
|
-
const description = atRoot ? spec.help?.description : spec.groups[groupPath]?.description;
|
|
4158
|
-
if (description !== void 0) {
|
|
4159
|
-
lines.push(rail(paint));
|
|
4160
|
-
proseLines(description, paint, lines);
|
|
4161
|
-
}
|
|
4162
|
-
if (atRoot) {
|
|
4163
|
-
lines.push(rail(paint));
|
|
4164
|
-
lines.push(sectionLabel(paint, "Global options"));
|
|
4165
|
-
railRows(sharedFlagRows(), paint, lines);
|
|
4166
|
-
exampleLines(spec.help?.examples ?? [], spec.name, paint, lines);
|
|
4167
|
-
docsLine(spec.help?.docsUrl, paint, lines);
|
|
4168
|
-
} else {
|
|
4169
|
-
lines.push(rail(paint));
|
|
4170
|
-
lines.push(rail(paint, paint("muted", `Run '${spec.name} ${groupPath} <command> --help' for details on a command.`)));
|
|
4171
|
-
}
|
|
4172
|
-
lines.push("");
|
|
4173
|
-
}
|
|
4174
4827
|
/** `link [id-or-name]` — the row a group lists for a leaf: name plus
|
|
4175
4828
|
* positional shape, briefs carry the rest. */
|
|
4176
4829
|
function usageName(name, def) {
|
|
4177
4830
|
const positionals = positionalUsage(def);
|
|
4178
4831
|
return positionals === "" ? name : `${name} ${positionals}`;
|
|
4179
4832
|
}
|
|
4180
|
-
function renderLeafHelp(spec, entry, path, paint, lines) {
|
|
4181
|
-
const def = entry.def;
|
|
4182
|
-
lines.push(header(spec, path, def.help.summary, paint));
|
|
4183
|
-
lines.push("");
|
|
4184
|
-
const usageParts = [
|
|
4185
|
-
spec.name,
|
|
4186
|
-
...path,
|
|
4187
|
-
requiredFlagUsage(def),
|
|
4188
|
-
"[options]",
|
|
4189
|
-
positionalUsage(def)
|
|
4190
|
-
].filter((part) => part !== "");
|
|
4191
|
-
lines.push(sectionLabel(paint, "Usage"));
|
|
4192
|
-
lines.push(rail(paint, `${GAP}${paint("muted", "$")} ${paint("emphasis", usageParts.join(" "))}`));
|
|
4193
|
-
if (def.help.description !== void 0) {
|
|
4194
|
-
lines.push(rail(paint));
|
|
4195
|
-
proseLines(def.help.description, paint, lines);
|
|
4196
|
-
}
|
|
4197
|
-
const positionalEntries = Object.values(def.args.positionals).map((spec) => positionalRuntime(spec));
|
|
4198
|
-
if (positionalEntries.length > 0) {
|
|
4199
|
-
lines.push(rail(paint));
|
|
4200
|
-
lines.push(sectionLabel(paint, "Arguments"));
|
|
4201
|
-
railRows(positionalEntries.map((runtime) => ({
|
|
4202
|
-
name: runtime.placeholder,
|
|
4203
|
-
brief: runtime.brief,
|
|
4204
|
-
suffix: runtime.type === "optionalString" ? "(optional)" : void 0
|
|
4205
|
-
})), paint, lines);
|
|
4206
|
-
}
|
|
4207
|
-
const flagRows = declaredFlagRows(def);
|
|
4208
|
-
if (flagRows.length > 0) {
|
|
4209
|
-
lines.push(rail(paint));
|
|
4210
|
-
lines.push(sectionLabel(paint, "Options"));
|
|
4211
|
-
railRows(flagRows, paint, lines);
|
|
4212
|
-
}
|
|
4213
|
-
if (def.kind !== "server-command") {
|
|
4214
|
-
const sharedNames = [...Object.keys(SHARED_FLAG_PARAMETERS).map((key) => `--${kebabCase(key)}`)].join(", ");
|
|
4215
|
-
lines.push(rail(paint));
|
|
4216
|
-
proseLines(`Global options also apply: ${sharedNames}. Run '${spec.name} --help' for details.`, paint, lines, "muted");
|
|
4217
|
-
}
|
|
4218
|
-
exampleLines(def.help.examples, spec.name, paint, lines);
|
|
4219
|
-
docsLine(entry.docsBaseUrl, paint, lines);
|
|
4220
|
-
lines.push("");
|
|
4221
|
-
}
|
|
4222
4833
|
//#endregion
|
|
4223
4834
|
//#region src/execution/settlement.ts
|
|
4224
4835
|
function undocumentedExitCode(def, exitCode) {
|
|
@@ -4256,6 +4867,10 @@ function settleCompleted(invocation, def, presented) {
|
|
|
4256
4867
|
});
|
|
4257
4868
|
return;
|
|
4258
4869
|
}
|
|
4870
|
+
if (state.format === "markdown") {
|
|
4871
|
+
renderCompletedMarkdown(invocation, presented);
|
|
4872
|
+
return;
|
|
4873
|
+
}
|
|
4259
4874
|
renderCompletedHuman(invocation, presented);
|
|
4260
4875
|
}
|
|
4261
4876
|
function diagnosticOf(error) {
|
|
@@ -4365,9 +4980,17 @@ function settleChildStatus(invocation, def, settlement) {
|
|
|
4365
4980
|
settleStructuredChildStatus(invocation, settlement, child, exitCode);
|
|
4366
4981
|
return;
|
|
4367
4982
|
}
|
|
4368
|
-
if (child.signal === null)
|
|
4983
|
+
if (child.signal === null) renderChildNextActions(invocation, settlement.nextActions);
|
|
4369
4984
|
settleVerbatimExitCode(invocation, exitCode);
|
|
4370
4985
|
}
|
|
4986
|
+
function renderChildNextActions(invocation, actions) {
|
|
4987
|
+
if (invocation.state.format === "markdown") {
|
|
4988
|
+
renderChildNextActionsMarkdown(invocation, actions);
|
|
4989
|
+
return;
|
|
4990
|
+
}
|
|
4991
|
+
const paint = makePaint(invocation.state.colorEnabled);
|
|
4992
|
+
for (const action of actions) invocation.runtime.stderr.write(`${renderNextAction(action, paint)}\n`);
|
|
4993
|
+
}
|
|
4371
4994
|
function settleStructuredChildStatus(invocation, settlement, child, exitCode) {
|
|
4372
4995
|
settleVerbatimExitCode(invocation, exitCode);
|
|
4373
4996
|
const nextActions = child.signal === null ? settlement.nextActions : [];
|
|
@@ -4461,6 +5084,10 @@ function emitErrored(invocation, raw) {
|
|
|
4461
5084
|
});
|
|
4462
5085
|
return;
|
|
4463
5086
|
}
|
|
5087
|
+
if (state.format === "markdown") {
|
|
5088
|
+
renderErroredMarkdown(invocation, envelope);
|
|
5089
|
+
return;
|
|
5090
|
+
}
|
|
4464
5091
|
const paint = makePaint(invocation.state.colorEnabled);
|
|
4465
5092
|
writeSections([envelope.error, ...envelope.diagnostics].map((diagnostic) => diagnosticSection(diagnostic, paint)), invocation.runtime.stderr);
|
|
4466
5093
|
}
|
|
@@ -4468,7 +5095,7 @@ function emitErrored(invocation, raw) {
|
|
|
4468
5095
|
* version travels as the run's single result frame. */
|
|
4469
5096
|
function settleVersion(spec, invocation) {
|
|
4470
5097
|
const { runtime, state } = invocation;
|
|
4471
|
-
if (state.format
|
|
5098
|
+
if (state.format !== "json") {
|
|
4472
5099
|
runtime.stdout.write(`${spec.version}\n`);
|
|
4473
5100
|
return 0;
|
|
4474
5101
|
}
|
|
@@ -4707,14 +5334,17 @@ var EngineImpl = class {
|
|
|
4707
5334
|
/** Help prose follows stricli's channel rule: stdout in human
|
|
4708
5335
|
* mode, stderr in json mode so stdout stays a clean frame
|
|
4709
5336
|
* stream. Never fires telemetry, like --version. */
|
|
4710
|
-
const stream = format === "
|
|
4711
|
-
renderHelp(this.spec, this.tree, argv,
|
|
5337
|
+
const stream = format === "json" ? runtime.stderr : runtime.stdout;
|
|
5338
|
+
renderHelp(this.spec, this.tree, argv, {
|
|
5339
|
+
format,
|
|
5340
|
+
colorEnabled: preParseColorEnabled(argv, runtime, format === "json" ? "stderr" : "stdout")
|
|
5341
|
+
}, stream);
|
|
4712
5342
|
return 0;
|
|
4713
5343
|
}
|
|
4714
5344
|
const stricliProcess = {
|
|
4715
5345
|
/** stricli writes only help text here. In json mode stdout carries
|
|
4716
5346
|
* exactly the frame stream, so help prose goes to stderr instead. */
|
|
4717
|
-
stdout: { write: (text) => (state.format === "
|
|
5347
|
+
stdout: { write: (text) => (state.format === "json" ? runtime.stderr : runtime.stdout).write(text) },
|
|
4718
5348
|
stderr: { write: (text) => {
|
|
4719
5349
|
state.stricliStderr += text;
|
|
4720
5350
|
} },
|
|
@@ -4874,7 +5504,7 @@ var EngineImpl = class {
|
|
|
4874
5504
|
flags: declaredFlags(entry.def, rawFlags),
|
|
4875
5505
|
positionals: distributePositionals(entry.def, values)
|
|
4876
5506
|
};
|
|
4877
|
-
const ctx = makeContext(invocation, entry.def, needsOutcome.config, declaredCapabilities(entry.def));
|
|
5507
|
+
const ctx = makeContext(invocation, entry.def, needsOutcome.config, needsOutcome.configFiles, declaredCapabilities(entry.def));
|
|
4878
5508
|
if (entry.def.kind === "session-command") {
|
|
4879
5509
|
await this.settleHandlerOutcome(invocation, entry, () => handler(args, ctx), () => settleSessionCompleted(invocation));
|
|
4880
5510
|
return;
|
|
@@ -4989,4 +5619,4 @@ function distributePositionals(def, values) {
|
|
|
4989
5619
|
return positionals;
|
|
4990
5620
|
}
|
|
4991
5621
|
//#endregion
|
|
4992
|
-
export {
|
|
5622
|
+
export { credentialWorkspaceId as C, credentialsRequiredError as D, credentialWorkspaceMismatchError as E, emptyServiceTokenError as O, claimedIdentity as S, credentialRejectedError as T, detectCI as _, definePrismaConfig as a, readActiveAccessToken as b, PRISMA_CONFIG_VERSION as c, PRESENTED as d, readUserConfig as f, exitWithChildStatus as g, resolveGating as h, CONFIG_FILE_NAME as i, noSessionForWorkspaceError as k, SERVICE_TOKEN_ENV_VAR as l, writeUserConfig as m, resolveSectionOverChain as n, loadConfig as o, userConfigPath as p, resolveSectionPath as r, realpathOr as s, buildEngine as t, WORKSPACE_ID_ENV_VAR as u, flag as v, authServiceError as w, claimedExpiresAt as x, positional as y };
|