@kubb/cli 5.15.1 → 5.15.3
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/dist/{Telemetry-C7Qwy2s7.js → Telemetry-BTeqnqie.js} +2 -2
- package/dist/{Telemetry-C7Qwy2s7.js.map → Telemetry-BTeqnqie.js.map} +1 -1
- package/dist/{Telemetry-B52pKz9i.cjs → Telemetry-DuO34wMx.cjs} +2 -2
- package/dist/{Telemetry-B52pKz9i.cjs.map → Telemetry-DuO34wMx.cjs.map} +1 -1
- package/dist/{background-CK2gQtTU.cjs → background-CdE3TOkv.cjs} +2 -2
- package/dist/{background-CK2gQtTU.cjs.map → background-CdE3TOkv.cjs.map} +1 -1
- package/dist/{background-BJCuXYuB.js → background-DxK8rpi2.js} +2 -2
- package/dist/{background-BJCuXYuB.js.map → background-DxK8rpi2.js.map} +1 -1
- package/dist/{background-D4mZCg-4.js → background-TT-XsxC2.js} +1 -1
- package/dist/{configFile-CoEpHdXG.cjs → configFile-CVfWdtKh.cjs} +4 -40
- package/dist/configFile-CVfWdtKh.cjs.map +1 -0
- package/dist/{configFile-C0DIXNMD.js → configFile-IHj8fRIw.js} +3 -39
- package/dist/configFile-IHj8fRIw.js.map +1 -0
- package/dist/{spinner-BZaln7O8.js → fs-Cf1FSRh9.js} +20 -41
- package/dist/fs-Cf1FSRh9.js.map +1 -0
- package/dist/index.cjs +14 -14
- package/dist/index.js +14 -14
- package/dist/{installWithSpinner-DpnpxHq5.js → installWithSpinner-BAlTSQlE.js} +3 -3
- package/dist/{installWithSpinner-DpnpxHq5.js.map → installWithSpinner-BAlTSQlE.js.map} +1 -1
- package/dist/{installWithSpinner-ONGfIVUJ.cjs → installWithSpinner-X9J7yxiR.cjs} +3 -3
- package/dist/{installWithSpinner-ONGfIVUJ.cjs.map → installWithSpinner-X9J7yxiR.cjs.map} +1 -1
- package/dist/intro-DRl-pwVs.js +72 -0
- package/dist/intro-DRl-pwVs.js.map +1 -0
- package/dist/intro-DuyzJ3Rb.cjs +102 -0
- package/dist/intro-DuyzJ3Rb.cjs.map +1 -0
- package/dist/{intro-9PB8sE8z.js → log-B-1vLxF1.js} +2 -66
- package/dist/log-B-1vLxF1.js.map +1 -0
- package/dist/{intro-YPaf1Imr.cjs → log-wv1OxLiq.cjs} +1 -95
- package/dist/log-wv1OxLiq.cjs.map +1 -0
- package/dist/{mascot-JSA0j3Q_.cjs → mascot-CC-D4ON2.cjs} +2 -2
- package/dist/{mascot-JSA0j3Q_.cjs.map → mascot-CC-D4ON2.cjs.map} +1 -1
- package/dist/{mascot--q1xjKw1.js → mascot-CmUUHLlx.js} +2 -2
- package/dist/{mascot--q1xjKw1.js.map → mascot-CmUUHLlx.js.map} +1 -1
- package/dist/{mcp-CcseJJwh.cjs → mcp-DMCyJrkw.cjs} +2 -2
- package/dist/{mcp-CcseJJwh.cjs.map → mcp-DMCyJrkw.cjs.map} +1 -1
- package/dist/{mcp-DUTsS8tR.js → mcp-DNMDPZOo.js} +2 -2
- package/dist/{mcp-DUTsS8tR.js.map → mcp-DNMDPZOo.js.map} +1 -1
- package/dist/{package-B1hUUjio.cjs → package-Bc9heh-c.cjs} +2 -2
- package/dist/package-Bc9heh-c.cjs.map +1 -0
- package/dist/package-Bm6L1D0Q.js +5 -0
- package/dist/package-Bm6L1D0Q.js.map +1 -0
- package/dist/{registry-B3eYk4LN.js → registry-Cy48PGdh.js} +3 -2
- package/dist/registry-Cy48PGdh.js.map +1 -0
- package/dist/{registry-YE1pFWL-.cjs → registry-Q77p5TZp.cjs} +3 -2
- package/dist/registry-Q77p5TZp.cjs.map +1 -0
- package/dist/reporters-9MqdcKPp.js +1 -0
- package/dist/{reporters-BM430HdQ.js → reporters-B_USHwD6.js} +297 -33
- package/dist/reporters-B_USHwD6.js.map +1 -0
- package/dist/{reporters-2cgjvXwR.cjs → reporters-DyjE3BzZ.cjs} +318 -20
- package/dist/reporters-DyjE3BzZ.cjs.map +1 -0
- package/dist/{run-CXVhxFfC.js → run-B4pveKq5.js} +10 -10
- package/dist/{run-CXVhxFfC.js.map → run-B4pveKq5.js.map} +1 -1
- package/dist/{run-CLiHI99L.js → run-B7p16C0S.js} +4 -4
- package/dist/{run-CLiHI99L.js.map → run-B7p16C0S.js.map} +1 -1
- package/dist/{run-dMTJfs4_.cjs → run-BBzw9B1L.cjs} +4 -4
- package/dist/{run-dMTJfs4_.cjs.map → run-BBzw9B1L.cjs.map} +1 -1
- package/dist/{run-DUwX6Icx.js → run-CBB5Hlgy.js} +10 -9
- package/dist/{run-DUwX6Icx.js.map → run-CBB5Hlgy.js.map} +1 -1
- package/dist/{run-CrM4jsix.cjs → run-CfumUZCl.cjs} +7 -6
- package/dist/{run-CrM4jsix.cjs.map → run-CfumUZCl.cjs.map} +1 -1
- package/dist/{run-D-nn9-Wq.js → run-Cgy4_JPy.js} +14 -18
- package/dist/run-Cgy4_JPy.js.map +1 -0
- package/dist/{run-1H9TGT8v.js → run-Ch7Uuu-u.js} +4 -3
- package/dist/{run-1H9TGT8v.js.map → run-Ch7Uuu-u.js.map} +1 -1
- package/dist/{run-BsrNfFIl.js → run-CkNLuV4M.js} +44 -38
- package/dist/run-CkNLuV4M.js.map +1 -0
- package/dist/{run-CyzKy-0p.cjs → run-CoPzxsoM.cjs} +20 -20
- package/dist/{run-CyzKy-0p.cjs.map → run-CoPzxsoM.cjs.map} +1 -1
- package/dist/{run-DTqMrPS9.js → run-CrDbD50I.js} +2 -2
- package/dist/{run-DTqMrPS9.js.map → run-CrDbD50I.js.map} +1 -1
- package/dist/{run-LY_UAYyM.cjs → run-Cxf3s3Ap.cjs} +48 -42
- package/dist/run-Cxf3s3Ap.cjs.map +1 -0
- package/dist/{run-BYP_t9dR.cjs → run-DCggecSY.cjs} +19 -24
- package/dist/run-DCggecSY.cjs.map +1 -0
- package/dist/{run-BrM7-NSV.js → run-DHfFHNfG.js} +13 -17
- package/dist/run-DHfFHNfG.js.map +1 -0
- package/dist/{run-DBnSbwtU.cjs → run-DQdcGuXL.cjs} +47 -61
- package/dist/run-DQdcGuXL.cjs.map +1 -0
- package/dist/{run-CvFakE3B.cjs → run-DT4hTOR2.cjs} +16 -21
- package/dist/run-DT4hTOR2.cjs.map +1 -0
- package/dist/{run-FEiyv6_U.js → run-DcEE0-8W.js} +40 -53
- package/dist/run-DcEE0-8W.js.map +1 -0
- package/dist/{run-Bq6gcfkS.js → run-MGGga_wU.js} +1 -1
- package/dist/{run-CQORv7Gq.cjs → run-S6Hkmn-h.cjs} +13 -12
- package/dist/{run-CQORv7Gq.cjs.map → run-S6Hkmn-h.cjs.map} +1 -1
- package/dist/{run-uPA5s3rI.cjs → run-UXFhmzzO.cjs} +2 -2
- package/dist/{run-uPA5s3rI.cjs.map → run-UXFhmzzO.cjs.map} +1 -1
- package/dist/shared-DcDHRtZx.js +58 -0
- package/dist/shared-DcDHRtZx.js.map +1 -0
- package/dist/shared-KKRMm1xX.cjs +87 -0
- package/dist/shared-KKRMm1xX.cjs.map +1 -0
- package/dist/{snapshot-CPF9zyZj.cjs → snapshot-BHFRCLgH.cjs} +7 -7
- package/dist/{snapshot-CPF9zyZj.cjs.map → snapshot-BHFRCLgH.cjs.map} +1 -1
- package/dist/{snapshot-CiV08NJr.js → snapshot-NH1AFDwz.js} +6 -6
- package/dist/{snapshot-CiV08NJr.js.map → snapshot-NH1AFDwz.js.map} +1 -1
- package/dist/spinner-DxsAllRI.js +48 -0
- package/dist/spinner-DxsAllRI.js.map +1 -0
- package/dist/{spinner-CfB0sIPy.cjs → spinner-RfMb7fd6.cjs} +50 -21
- package/dist/spinner-RfMb7fd6.cjs.map +1 -0
- package/dist/{status-C066YA-4.cjs → status-3A7fVPqb.cjs} +3 -3
- package/dist/{status-C066YA-4.cjs.map → status-3A7fVPqb.cjs.map} +1 -1
- package/dist/{status-Dj8tivag.js → status-BeJwJ7Xa.js} +3 -3
- package/dist/{status-Dj8tivag.js.map → status-BeJwJ7Xa.js.map} +1 -1
- package/dist/{studio-B4XsXgKj.js → studio-B-1AM1My.js} +12 -12
- package/dist/{studio-B4XsXgKj.js.map → studio-B-1AM1My.js.map} +1 -1
- package/dist/{studio-D9_-mKee.cjs → studio-BUhnJl4S.cjs} +12 -12
- package/dist/{studio-D9_-mKee.cjs.map → studio-BUhnJl4S.cjs.map} +1 -1
- package/dist/studioWorker.js +2 -2
- package/dist/{summary-Clvl5Hxs.cjs → summary-B2Apv5KO.cjs} +17 -2
- package/dist/summary-B2Apv5KO.cjs.map +1 -0
- package/dist/{summary-CbmQKA8l.js → summary-BQWHL_Ca.js} +12 -3
- package/dist/summary-BQWHL_Ca.js.map +1 -0
- package/dist/{text-Ep3AulAS.cjs → text-DMiX2dcG.cjs} +10 -1
- package/dist/text-DMiX2dcG.cjs.map +1 -0
- package/dist/{text-BmiI4s6N.js → text-EoYn04SX.js} +5 -2
- package/dist/text-EoYn04SX.js.map +1 -0
- package/dist/{utils-CbJ6hS_t.js → utils-CeMUE4P0.js} +90 -70
- package/dist/utils-CeMUE4P0.js.map +1 -0
- package/dist/{utils-CO89mxRU.cjs → utils-uSJAZuvP.cjs} +101 -69
- package/dist/utils-uSJAZuvP.cjs.map +1 -0
- package/dist/{validate-C5fyNF4v.js → validate--AEg1yAB.js} +3 -3
- package/dist/{validate-C5fyNF4v.js.map → validate--AEg1yAB.js.map} +1 -1
- package/dist/{validate-B3tLWYJU.cjs → validate-BVNrsXe2.cjs} +3 -3
- package/dist/{validate-B3tLWYJU.cjs.map → validate-BVNrsXe2.cjs.map} +1 -1
- package/package.json +8 -7
- package/dist/configFile-C0DIXNMD.js.map +0 -1
- package/dist/configFile-CoEpHdXG.cjs.map +0 -1
- package/dist/intro-9PB8sE8z.js.map +0 -1
- package/dist/intro-YPaf1Imr.cjs.map +0 -1
- package/dist/package-B1hUUjio.cjs.map +0 -1
- package/dist/package-MYPMnnTX.js +0 -5
- package/dist/package-MYPMnnTX.js.map +0 -1
- package/dist/registry-B3eYk4LN.js.map +0 -1
- package/dist/registry-YE1pFWL-.cjs.map +0 -1
- package/dist/reporters-2cgjvXwR.cjs.map +0 -1
- package/dist/reporters-BM430HdQ.js.map +0 -1
- package/dist/run-BYP_t9dR.cjs.map +0 -1
- package/dist/run-BrM7-NSV.js.map +0 -1
- package/dist/run-BsrNfFIl.js.map +0 -1
- package/dist/run-CvFakE3B.cjs.map +0 -1
- package/dist/run-D-nn9-Wq.js.map +0 -1
- package/dist/run-DBnSbwtU.cjs.map +0 -1
- package/dist/run-FEiyv6_U.js.map +0 -1
- package/dist/run-LY_UAYyM.cjs.map +0 -1
- package/dist/shared-C0EtrdUm.cjs +0 -123
- package/dist/shared-C0EtrdUm.cjs.map +0 -1
- package/dist/shared-Ct9stKpp.js +0 -94
- package/dist/shared-Ct9stKpp.js.map +0 -1
- package/dist/spinner-BZaln7O8.js.map +0 -1
- package/dist/spinner-CfB0sIPy.cjs.map +0 -1
- package/dist/summary-CbmQKA8l.js.map +0 -1
- package/dist/summary-Clvl5Hxs.cjs.map +0 -1
- package/dist/text-BmiI4s6N.js.map +0 -1
- package/dist/text-Ep3AulAS.cjs.map +0 -1
- package/dist/utils-BdibacYq.js +0 -244
- package/dist/utils-BdibacYq.js.map +0 -1
- package/dist/utils-CO89mxRU.cjs.map +0 -1
- package/dist/utils-CbJ6hS_t.js.map +0 -1
- package/dist/utils-CcARPB45.cjs +0 -286
- package/dist/utils-CcARPB45.cjs.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-C3-Zg-KD.cjs");
|
|
2
2
|
const require_errors = require("./errors-BponpdjN.cjs");
|
|
3
|
+
const require_text = require("./text-DMiX2dcG.cjs");
|
|
3
4
|
let node_process = require("node:process");
|
|
4
5
|
node_process = require_rolldown_runtime.__toESM(node_process, 1);
|
|
5
6
|
let _kubb_core = require("@kubb/core");
|
|
@@ -11,7 +12,7 @@ const ID = new RegExp(`^${SLUG}(\\/${SLUG})?$`);
|
|
|
11
12
|
/** The registry base URL: `KUBB_REGISTRY`, or kubb.dev. */
|
|
12
13
|
function registryUrl() {
|
|
13
14
|
const url = node_process.default.env.KUBB_REGISTRY || DEFAULT_REGISTRY;
|
|
14
|
-
if (
|
|
15
|
+
if (!require_text.isHttpUrl(url)) throw new _kubb_core.Diagnostics.Error({
|
|
15
16
|
code: _kubb_core.Diagnostics.code.unknown,
|
|
16
17
|
severity: "error",
|
|
17
18
|
message: `KUBB_REGISTRY must be an http(s) URL, got "${url}".`,
|
|
@@ -191,4 +192,4 @@ Object.defineProperty(exports, "toShortId", {
|
|
|
191
192
|
}
|
|
192
193
|
});
|
|
193
194
|
|
|
194
|
-
//# sourceMappingURL=registry-
|
|
195
|
+
//# sourceMappingURL=registry-Q77p5TZp.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-Q77p5TZp.cjs","names":["process","isHttpUrl","Diagnostics","getErrorMessage","toError","isRegistryEntry","isValid","isLessThan","difference"],"sources":["../src/utils/registry.ts"],"sourcesContent":["import process from 'node:process'\nimport { getErrorMessage, toError } from '@internals/utils'\nimport { checkCompatibility, Diagnostics, type ExtensionManifest, isRegistryEntry, type RegistryArtifact, type RegistryEntry } from '@kubb/core'\nimport { difference, isLessThan, isValid } from 'verkit'\nimport { isHttpUrl } from '../ui/text.ts'\n\nconst DEFAULT_REGISTRY = 'https://kubb.dev/registry'\n\nconst SLUG = '[a-z0-9]+(?:-[a-z0-9]+)*'\nconst ID = new RegExp(`^${SLUG}(\\\\/${SLUG})?$`)\n\n/** The registry base URL: `KUBB_REGISTRY`, or kubb.dev. */\nexport function registryUrl(): string {\n const url = process.env.KUBB_REGISTRY || DEFAULT_REGISTRY\n if (!isHttpUrl(url))\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `KUBB_REGISTRY must be an http(s) URL, got \"${url}\".`,\n help: 'Set `KUBB_REGISTRY` to an http(s) URL, or unset it to use https://kubb.dev/registry.',\n })\n return url.replace(/\\/+$/, '')\n}\n\n/**\n * Turns `owner/slug`, or a bare `slug` meaning `kubb-labs/<slug>`, into a registry id.\n *\n * @throws when the id has another shape, so it never reaches a URL unchecked.\n */\nexport function toRegistryId(input: string): string {\n if (!ID.test(input))\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `\"${input}\" is not a registry id. Use owner/slug, such as kubb-labs/plugin-zod, or a slug, such as plugin-zod.`,\n })\n return input.includes('/') ? input : `kubb-labs/${input}`\n}\n\n/** The shortest id `kubb add` and `kubb update` accept: the slug for an official extension, else `owner/slug`. */\nexport function toShortId(id: string): string {\n return id.startsWith('kubb-labs/') ? id.slice('kubb-labs/'.length) : id\n}\n\n/**\n * GETs `url` as JSON. A non-2xx answer or a body that is not JSON returns no `body`.\n * A network error throws with the URL.\n */\nasync function fetchJSON(url: string): Promise<{ status: number; body?: unknown }> {\n let response: Response\n try {\n response = await globalThis.fetch(url, { headers: { accept: 'application/json' } })\n } catch (cause) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.inputUnreachable,\n severity: 'error',\n message: `Could not read ${url}: ${getErrorMessage(cause)}`,\n help: 'Check your network connection and that the registry is reachable.',\n cause: toError(cause),\n })\n }\n if (!response.ok) return { status: response.status }\n return { status: response.status, body: await response.json().catch(() => undefined) }\n}\n\n/** Fetches the registry index, leaving out entries that fail validation. */\nexport async function fetchRegistryIndex({ registry }: { registry: string }): Promise<Array<RegistryEntry>> {\n const { status, body } = await fetchJSON(`${registry}/index.json`)\n const index = body as { version?: unknown; extensions?: unknown } | null | undefined\n if (status !== 200 || index?.version !== 1 || !Array.isArray(index.extensions)) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.inputRequestFailed,\n severity: 'error',\n message: `The registry at ${registry} sent an invalid index (HTTP ${status}).`,\n help: 'Try again later, or check that `KUBB_REGISTRY` points at a Kubb registry.',\n })\n }\n return index.extensions.filter(isRegistryEntry)\n}\n\n/** What the package manager installs: `<package>@<version>`, or a GitHub release's commit, so the install cannot move with the tag. */\nexport function installSpec(artifact: RegistryArtifact): string {\n return artifact.kind === 'github' ? `github:${artifact.owner}/${artifact.repo}#${artifact.commit}` : `${artifact.package}@${artifact.version}`\n}\n\n/** Why the running Kubb or Node.js version cannot use this extension, or `undefined` when it can. */\nexport function incompatibility(manifest: ExtensionManifest): string | undefined {\n try {\n checkCompatibility({ name: manifest.name, compatibility: manifest.compatibility })\n return undefined\n } catch (error) {\n return getErrorMessage(error)\n }\n}\n\n/**\n * Whether `latest` is newer than `installed`. An unknown installed version counts as outdated, and an\n * invalid `latest` never does.\n */\nexport function isOutdated({ installed, latest }: { installed: string | undefined; latest: string }): boolean {\n if (!isValid(latest)) return false\n return !installed || !isValid(installed) || isLessThan(installed, latest)\n}\n\n/** `major`, `minor`, or `patch` from `installed` to `latest`, or `undefined` when either is unknown or invalid. */\nexport function bumpOf({ installed, latest }: { installed: string | undefined; latest: string }): 'major' | 'minor' | 'patch' | undefined {\n if (!installed || !isValid(installed) || !isValid(latest)) return undefined\n const kind = difference(installed, latest)\n if (!kind) return undefined\n if (kind.endsWith('major')) return 'major'\n return kind.endsWith('minor') ? 'minor' : 'patch'\n}\n\nfunction editDistance(a: string, b: string): number {\n const row = Array.from({ length: b.length + 1 }, (_, index) => index)\n for (let i = 1; i <= a.length; i++) {\n let previous = row[0]!\n row[0] = i\n for (let j = 1; j <= b.length; j++) {\n const current = row[j]!\n row[j] = Math.min(row[j]! + 1, row[j - 1]! + 1, previous + (a[i - 1] === b[j - 1] ? 0 : 1))\n previous = current\n }\n }\n return row[b.length]!\n}\n\n/** Words every extension shares, so they never make two ids look alike. */\nconst COMMON_TOKENS = new Set(['kubb', 'plugin', 'adapter', 'parser'])\n\n/**\n * The ids closest to a mistyped `input`, best first, at most three: those within a few edits of it,\n * or sharing a word such as `zod` in any order. Compares slugs, so the owner may be left out.\n */\nexport function closestIds({ input, ids }: { input: string; ids: Array<string> }): Array<string> {\n const slug = (id: string) => id.slice(id.indexOf('/') + 1)\n const tokens = new Set(\n slug(input)\n .split('-')\n .filter((token) => !COMMON_TOKENS.has(token)),\n )\n return ids\n .map((id) => ({\n id,\n distance: editDistance(slug(input), slug(id)),\n shared: slug(id)\n .split('-')\n .some((token) => tokens.has(token)),\n }))\n .filter(({ distance, shared }) => shared || distance <= Math.max(2, Math.floor(slug(input).length / 4)))\n .sort((a, b) => Number(b.shared) - Number(a.shared) || a.distance - b.distance)\n .slice(0, 3)\n .map(({ id }) => id)\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as default, t as selectReporters } from "./reporters-B_USHwD6.js";
|
|
@@ -1,23 +1,39 @@
|
|
|
1
1
|
import "./rolldown-runtime-xo6NMXYd.js";
|
|
2
2
|
import { n as getElapsedMs, t as formatMs } from "./time-C-wU7VhC.js";
|
|
3
|
-
import { i as isPathInside,
|
|
4
|
-
import { a as readOutputFiles, r as diffOutput } from "./utils-BdibacYq.js";
|
|
3
|
+
import { i as read, n as isPathInside, r as matchesStored } from "./fs-Cf1FSRh9.js";
|
|
5
4
|
import { n as formatMsWithColor, t as formatBar } from "./banner-BdTTDFkG.js";
|
|
6
|
-
import {
|
|
7
|
-
import { n as
|
|
5
|
+
import { o as writer } from "./log-B-1vLxF1.js";
|
|
6
|
+
import { n as pluralize, r as toPermissionFlag } from "./text-EoYn04SX.js";
|
|
8
7
|
import { styleText } from "node:util";
|
|
9
8
|
import process from "node:process";
|
|
10
|
-
import { readFile } from "node:fs/promises";
|
|
11
|
-
import { relative, resolve } from "node:path";
|
|
12
|
-
import { Diagnostics, cacheStorage, createCliReporter, createOutputManifest, getInputKind, logLevel } from "@kubb/core";
|
|
9
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
10
|
+
import { join, relative, resolve } from "node:path";
|
|
11
|
+
import { Diagnostics, cacheStorage, createCliReporter, createOutputManifest, getInputKind, hasOutputPasses, logLevel } from "@kubb/core";
|
|
12
|
+
// ../../internals/utils/src/promise.ts
|
|
13
|
+
/**
|
|
14
|
+
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
15
|
+
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
async function inParallel({ items, limit, run }) {
|
|
23
|
+
const queue = items.entries();
|
|
24
|
+
const worker = async () => {
|
|
25
|
+
for (const [index, item] of queue) await run(item, index);
|
|
26
|
+
};
|
|
27
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
28
|
+
}
|
|
13
29
|
// src/loggers/features/context.ts
|
|
14
|
-
function createLoggerContext({ hooks, writer, logLevel: logLevel$
|
|
15
|
-
const text = (message) => logLevel$
|
|
30
|
+
function createLoggerContext({ hooks, writer, logLevel: logLevel$6 }) {
|
|
31
|
+
const text = (message) => logLevel$6 >= logLevel.verbose ? `${styleText("dim", `[${clock()}]`)} ${message}` : message;
|
|
16
32
|
const ctx = {
|
|
17
33
|
hooks,
|
|
18
34
|
writer,
|
|
19
|
-
logLevel: logLevel$
|
|
20
|
-
silent: logLevel$
|
|
35
|
+
logLevel: logLevel$6,
|
|
36
|
+
silent: logLevel$6 <= logLevel.silent,
|
|
21
37
|
human: writer.audience === "human",
|
|
22
38
|
session: false,
|
|
23
39
|
groupOpen: false,
|
|
@@ -141,7 +157,7 @@ function trimBlankEdges(lines) {
|
|
|
141
157
|
return lines.slice(start, lines.findLastIndex((line) => line.trim()) + 1);
|
|
142
158
|
}
|
|
143
159
|
/** The format, lint and post-generate phases, and the hooks and messages they buffer while their step owns the line. */
|
|
144
|
-
function createPhases({ writer, silent, logLevel: logLevel$
|
|
160
|
+
function createPhases({ writer, silent, logLevel: logLevel$5, text, line, onRun }, spinner) {
|
|
145
161
|
const state = {
|
|
146
162
|
phase: null,
|
|
147
163
|
hooks: /* @__PURE__ */ new Map()
|
|
@@ -217,7 +233,7 @@ function createPhases({ writer, silent, logLevel: logLevel$4, text, line, onRun
|
|
|
217
233
|
writer.info(formatted);
|
|
218
234
|
});
|
|
219
235
|
onRun("kubb:success", ({ message, info }) => {
|
|
220
|
-
const formatted = line(styleText("green", "✓"), message, logLevel$
|
|
236
|
+
const formatted = line(styleText("green", "✓"), message, logLevel$5 >= logLevel.info ? info : void 0);
|
|
221
237
|
if (spinner.message(formatted)) return;
|
|
222
238
|
writer.success(formatted);
|
|
223
239
|
});
|
|
@@ -255,18 +271,37 @@ function createPhases({ writer, silent, logLevel: logLevel$4, text, line, onRun
|
|
|
255
271
|
};
|
|
256
272
|
}
|
|
257
273
|
// src/loggers/specFrame.ts
|
|
274
|
+
let cached;
|
|
275
|
+
function lineStarts(source) {
|
|
276
|
+
if (cached?.source !== source) {
|
|
277
|
+
const starts = [0];
|
|
278
|
+
for (const match of source.matchAll(/\n/g)) starts.push(match.index + 1);
|
|
279
|
+
cached = {
|
|
280
|
+
source,
|
|
281
|
+
starts
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
return cached.starts;
|
|
285
|
+
}
|
|
286
|
+
/** The index of the last line start at or before `offset`, found by binary search. */
|
|
287
|
+
function lineIndex(starts, offset, low = 0, high = starts.length - 1) {
|
|
288
|
+
if (low >= high) return low;
|
|
289
|
+
const mid = low + high + 1 >> 1;
|
|
290
|
+
return starts[mid] <= offset ? lineIndex(starts, offset, mid, high) : lineIndex(starts, offset, low, mid - 1);
|
|
291
|
+
}
|
|
258
292
|
/**
|
|
259
293
|
* Where `location` sits in `source` according to its adapter, with a code frame. `undefined` when the adapter cannot place it.
|
|
260
294
|
*/
|
|
261
295
|
function locateInSpec({ adapter, source, location }) {
|
|
262
|
-
const lines = source.split(/\r?\n/);
|
|
263
296
|
try {
|
|
264
297
|
const range = adapter.locate?.(source, location);
|
|
265
298
|
if (!range) return void 0;
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
-
const
|
|
269
|
-
const
|
|
299
|
+
const starts = lineStarts(source);
|
|
300
|
+
const index = lineIndex(starts, range.start);
|
|
301
|
+
const lineText = (number) => source.slice(starts[number - 1], number < starts.length ? starts[number] - 1 : source.length).replace(/\r$/, "");
|
|
302
|
+
const line = index + 1;
|
|
303
|
+
const column = range.start - starts[index] + 1;
|
|
304
|
+
const text = lineText(line);
|
|
270
305
|
const width = String(line).length;
|
|
271
306
|
const gutter = (number) => styleText("dim", `${number === void 0 ? "".padStart(width) : String(number).padStart(width)} │`);
|
|
272
307
|
const carets = "^".repeat(Math.max(1, Math.min(range.end - range.start, text.length - column + 1)));
|
|
@@ -274,7 +309,7 @@ function locateInSpec({ adapter, source, location }) {
|
|
|
274
309
|
line,
|
|
275
310
|
column,
|
|
276
311
|
frame: [
|
|
277
|
-
...line > 1 ? [`${gutter(line - 1)} ${
|
|
312
|
+
...line > 1 ? [`${gutter(line - 1)} ${lineText(line - 1)}`] : [],
|
|
278
313
|
`${gutter(line)} ${text}`,
|
|
279
314
|
`${gutter()} ${" ".repeat(column - 1)}${styleText("red", carets)}`
|
|
280
315
|
]
|
|
@@ -286,11 +321,11 @@ function locateInSpec({ adapter, source, location }) {
|
|
|
286
321
|
// src/loggers/features/problems.ts
|
|
287
322
|
/** Warnings, errors and diagnostics: printed as they come, or held back and grouped by plugin once a human's build ends. */
|
|
288
323
|
function createProblems(ctx, spinner, progress, phases) {
|
|
289
|
-
const { writer, silent, human, logLevel: logLevel$
|
|
324
|
+
const { writer, silent, human, logLevel: logLevel$4, text, line, hooks } = ctx;
|
|
290
325
|
const { audience } = writer;
|
|
291
326
|
const formatOptions = {
|
|
292
327
|
audience,
|
|
293
|
-
verbose: logLevel$
|
|
328
|
+
verbose: logLevel$4 >= logLevel.verbose,
|
|
294
329
|
width: Math.min(process.stdout.columns || 80, 100) - (audience === "human" ? 4 : 2)
|
|
295
330
|
};
|
|
296
331
|
const state = {
|
|
@@ -338,8 +373,8 @@ function createProblems(ctx, spinner, progress, phases) {
|
|
|
338
373
|
writer.diagnostic(lines.slice(0, -1));
|
|
339
374
|
}
|
|
340
375
|
hooks.hook("kubb:warn", ({ message, info }) => {
|
|
341
|
-
if (logLevel$
|
|
342
|
-
writer.warn(line(styleText("yellow", "⚠"), message, logLevel$
|
|
376
|
+
if (logLevel$4 < logLevel.warn) return;
|
|
377
|
+
writer.warn(line(styleText("yellow", "⚠"), message, logLevel$4 >= logLevel.info ? info : void 0));
|
|
343
378
|
});
|
|
344
379
|
hooks.hook("kubb:error", ({ error }) => {
|
|
345
380
|
const phase = phases.phase;
|
|
@@ -418,7 +453,8 @@ function createProblems(ctx, spinner, progress, phases) {
|
|
|
418
453
|
}
|
|
419
454
|
// src/loggers/features/progress.ts
|
|
420
455
|
/** The progress bar over the file writes, and the counts the summary line shows. */
|
|
421
|
-
function createProgress({ writer, silent, text, onRun }, spinner) {
|
|
456
|
+
function createProgress({ writer, silent, human, logLevel: logLevel$3, text, onRun }, spinner) {
|
|
457
|
+
const nameFiles = human || logLevel$3 >= logLevel.verbose;
|
|
422
458
|
const state = {
|
|
423
459
|
progress: null,
|
|
424
460
|
totalFiles: 0,
|
|
@@ -443,7 +479,7 @@ function createProgress({ writer, silent, text, onRun }, spinner) {
|
|
|
443
479
|
onRun("kubb:files:processing:update", ({ files }) => {
|
|
444
480
|
for (const { file, config } of files) {
|
|
445
481
|
state.processedFiles++;
|
|
446
|
-
state.progress?.advance(`${state.inMemory ? "Generating" : "Writing"} ${relative(config.root, file.path)}`);
|
|
482
|
+
if (nameFiles) state.progress?.advance(`${state.inMemory ? "Generating" : "Writing"} ${relative(config.root, file.path)}`);
|
|
447
483
|
}
|
|
448
484
|
});
|
|
449
485
|
onRun("kubb:files:processing:end", ({ files, unchanged }) => {
|
|
@@ -691,9 +727,220 @@ function installLogger({ hooks, writer, logLevel }) {
|
|
|
691
727
|
problems
|
|
692
728
|
});
|
|
693
729
|
}
|
|
730
|
+
// src/runners/generate/utils.ts
|
|
731
|
+
/** Glob pattern for paths the file watcher ignores. */
|
|
732
|
+
const WATCHER_IGNORED_PATHS = "**/{.git,node_modules}/**";
|
|
733
|
+
/**
|
|
734
|
+
* Quiet window in milliseconds that collapses a burst of watcher events (an editor save emits several) into one rebuild.
|
|
735
|
+
* It outlasts chokidar's 100 ms atomic-save window, which holds back the event of a write-then-rename save.
|
|
736
|
+
*/
|
|
737
|
+
const WATCHER_DEBOUNCE_MS = 250;
|
|
738
|
+
/** `14:02:11 petStore.yaml changed`, the line a watcher prints when its input changes. */
|
|
739
|
+
function formatChange({ target, removed = false, now = /* @__PURE__ */ new Date() }) {
|
|
740
|
+
return `${styleText("dim", now.toTimeString().slice(0, 8))} ${styleText("bold", target)} ${removed ? "removed" : "changed"}`;
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Starts a file watcher on the given paths and calls `cb` on any change.
|
|
744
|
+
* Ignores `.git` and `node_modules` directories. Event bursts (an editor save emits several)
|
|
745
|
+
* are debounced into one call. `cb` must never reject: its result is not awaited, so the caller
|
|
746
|
+
* serializes and reports its own builds. Resolves to a function that stops watching.
|
|
747
|
+
*/
|
|
748
|
+
async function startWatcher(path, cb, log = {
|
|
749
|
+
info: console.log,
|
|
750
|
+
error: console.log
|
|
751
|
+
}) {
|
|
752
|
+
const { watch } = await import("chokidar");
|
|
753
|
+
const watcher = watch(path, {
|
|
754
|
+
ignorePermissionErrors: true,
|
|
755
|
+
ignored: WATCHER_IGNORED_PATHS,
|
|
756
|
+
ignoreInitial: true
|
|
757
|
+
});
|
|
758
|
+
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => void watcher.close());
|
|
759
|
+
let debounceTimer = null;
|
|
760
|
+
watcher.on("all", (type, file) => {
|
|
761
|
+
log.info(formatChange({
|
|
762
|
+
target: relative(process.cwd(), file),
|
|
763
|
+
removed: type === "unlink"
|
|
764
|
+
}));
|
|
765
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
766
|
+
debounceTimer = setTimeout(() => {
|
|
767
|
+
debounceTimer = null;
|
|
768
|
+
cb(path);
|
|
769
|
+
}, WATCHER_DEBOUNCE_MS);
|
|
770
|
+
});
|
|
771
|
+
return async () => {
|
|
772
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
773
|
+
await watcher.close();
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
function createSnapshot() {
|
|
777
|
+
return {
|
|
778
|
+
schemas: /* @__PURE__ */ new Set(),
|
|
779
|
+
operations: /* @__PURE__ */ new Set()
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Collects a {@link BuildSnapshot} from the hooks while a build runs. `take` hands back the finished
|
|
784
|
+
* build's snapshot and starts the next one.
|
|
785
|
+
*/
|
|
786
|
+
function trackBuild(hooks) {
|
|
787
|
+
let current = createSnapshot();
|
|
788
|
+
hooks.hook("kubb:generate:schema", (node) => {
|
|
789
|
+
if (node.name) current.schemas.add(node.name);
|
|
790
|
+
});
|
|
791
|
+
hooks.hook("kubb:generate:operation", (node) => {
|
|
792
|
+
current.operations.add(node.operationId);
|
|
793
|
+
});
|
|
794
|
+
return { take() {
|
|
795
|
+
const snapshot = current;
|
|
796
|
+
current = createSnapshot();
|
|
797
|
+
return snapshot;
|
|
798
|
+
} };
|
|
799
|
+
}
|
|
800
|
+
function diffNames(previous, next) {
|
|
801
|
+
return {
|
|
802
|
+
added: [...next].filter((name) => !previous.has(name)).length,
|
|
803
|
+
removed: [...previous].filter((name) => !next.has(name)).length
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* Compares two {@link BuildSnapshot}s by name.
|
|
808
|
+
*/
|
|
809
|
+
function diffBuilds(previous, next) {
|
|
810
|
+
return {
|
|
811
|
+
schemas: diffNames(previous.schemas, next.schemas),
|
|
812
|
+
operations: diffNames(previous.operations, next.operations)
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
function countLineChanges(before, after) {
|
|
816
|
+
const remaining = /* @__PURE__ */ new Map();
|
|
817
|
+
for (const line of before ? before.split("\n") : []) remaining.set(line, (remaining.get(line) ?? 0) + 1);
|
|
818
|
+
let added = 0;
|
|
819
|
+
for (const line of after ? after.split("\n") : []) {
|
|
820
|
+
const count = remaining.get(line) ?? 0;
|
|
821
|
+
if (count > 0) remaining.set(line, count - 1);
|
|
822
|
+
else added++;
|
|
823
|
+
}
|
|
824
|
+
const removed = [...remaining.values()].reduce((sum, count) => sum + count, 0);
|
|
825
|
+
return {
|
|
826
|
+
added,
|
|
827
|
+
removed
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Reads the output before generation, so cleaning the directory cannot erase the diff baseline.
|
|
832
|
+
* A missing directory or an unreadable file is skipped.
|
|
833
|
+
*/
|
|
834
|
+
async function readOutputFiles(outputPath) {
|
|
835
|
+
const entries = await readdir(outputPath, {
|
|
836
|
+
recursive: true,
|
|
837
|
+
withFileTypes: true
|
|
838
|
+
}).catch(() => []);
|
|
839
|
+
const files = /* @__PURE__ */ new Map();
|
|
840
|
+
await inParallel({
|
|
841
|
+
items: entries.filter((entry) => entry.isFile()).map((entry) => join(entry.parentPath, entry.name)),
|
|
842
|
+
limit: 50,
|
|
843
|
+
run: async (filePath) => {
|
|
844
|
+
const source = await read(filePath).catch(() => null);
|
|
845
|
+
if (source !== null) files.set(filePath, source);
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
return files;
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* How one generated file differs from its copy before generation: `undefined` when both hold the
|
|
852
|
+
* same output, otherwise the change with its line counts. The manifest recognizes output a
|
|
853
|
+
* formatter rewrote.
|
|
854
|
+
*/
|
|
855
|
+
function diffFile({ path, next, previous, manifest }) {
|
|
856
|
+
if (previous !== null && (matchesStored({
|
|
857
|
+
stored: previous,
|
|
858
|
+
source: next
|
|
859
|
+
}) || manifest?.isUpToDate({
|
|
860
|
+
key: path,
|
|
861
|
+
source: next,
|
|
862
|
+
disk: previous
|
|
863
|
+
}))) return;
|
|
864
|
+
return {
|
|
865
|
+
status: previous === null ? "A" : "M",
|
|
866
|
+
path,
|
|
867
|
+
...countLineChanges(previous?.trim() ?? "", previous === null ? next.trimEnd() : next.trim())
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Compares generated output with the files captured before generation. The manifest recognizes
|
|
872
|
+
* output rewritten by a formatter, and `clean` includes files the run would delete. `counted` holds
|
|
873
|
+
* changes already worked out while the files were written; any other path is read back.
|
|
874
|
+
*/
|
|
875
|
+
async function diffOutput({ storage, paths, clean, manifest, previousFiles, counted }) {
|
|
876
|
+
const generated = new Set(paths);
|
|
877
|
+
const changes = [];
|
|
878
|
+
let unchanged = 0;
|
|
879
|
+
await inParallel({
|
|
880
|
+
items: paths,
|
|
881
|
+
limit: 50,
|
|
882
|
+
run: async (filePath, index) => {
|
|
883
|
+
let change;
|
|
884
|
+
if (counted?.has(filePath)) change = counted.get(filePath);
|
|
885
|
+
else {
|
|
886
|
+
const next = await storage.readItem(filePath);
|
|
887
|
+
if (next === null) return;
|
|
888
|
+
change = diffFile({
|
|
889
|
+
path: filePath,
|
|
890
|
+
next,
|
|
891
|
+
previous: previousFiles.get(filePath) ?? null,
|
|
892
|
+
manifest
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
if (change) changes[index] = change;
|
|
896
|
+
else unchanged++;
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
const files = changes.filter((file) => file !== void 0);
|
|
900
|
+
if (clean) {
|
|
901
|
+
for (const [filePath, source] of previousFiles) if (!generated.has(filePath)) files.push({
|
|
902
|
+
status: "D",
|
|
903
|
+
path: filePath,
|
|
904
|
+
...countLineChanges(source.trimEnd(), "")
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
return {
|
|
908
|
+
files,
|
|
909
|
+
unchanged
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Reads `r` (rebuild) and `q` (quit) from an interactive stdin in raw mode, and keeps ctrl+c
|
|
914
|
+
* working. Returns `undefined` when stdin is not a TTY. Otherwise returns `arm`, which turns raw
|
|
915
|
+
* mode back on: a spinner restores the terminal when it stops, so call it after each build. Raw mode
|
|
916
|
+
* is restored on exit.
|
|
917
|
+
*/
|
|
918
|
+
function listenForKeys({ rebuild, quit, input = process.stdin }) {
|
|
919
|
+
if (!input.isTTY) return void 0;
|
|
920
|
+
const arm = () => {
|
|
921
|
+
input.setRawMode(true);
|
|
922
|
+
input.resume();
|
|
923
|
+
};
|
|
924
|
+
input.setEncoding("utf8");
|
|
925
|
+
input.on("data", (data) => {
|
|
926
|
+
const key = data.trim();
|
|
927
|
+
if (key === "r") {
|
|
928
|
+
rebuild();
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
if (key === "q" || data === "") {
|
|
932
|
+
input.setRawMode(false);
|
|
933
|
+
input.pause();
|
|
934
|
+
quit(key === "q" ? 0 : 130);
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
process.once("exit", () => input.setRawMode(false));
|
|
938
|
+
arm();
|
|
939
|
+
return arm;
|
|
940
|
+
}
|
|
694
941
|
// src/loggers/reporters.ts
|
|
695
942
|
/** Installs the live logger and wires the selected reporters. `cli` renders its summary through the logger, and is skipped when `json` owns stdout. */
|
|
696
|
-
function setupReporters(context, { logLevel: logLevel$1, reporters, writer: writer$1 = writer(), dryRun = false }) {
|
|
943
|
+
function setupReporters(context, { logLevel: logLevel$1, reporters, writer: writer$1 = writer(), dryRun = false, fileChanges = false }) {
|
|
697
944
|
const hasJson = reporters.some((reporter) => reporter.name === "json");
|
|
698
945
|
const selected = reporters.flatMap((reporter) => {
|
|
699
946
|
if (reporter.name !== "cli") return [reporter];
|
|
@@ -718,16 +965,23 @@ function setupReporters(context, { logLevel: logLevel$1, reporters, writer: writ
|
|
|
718
965
|
});
|
|
719
966
|
let filesUnchanged = 0;
|
|
720
967
|
let previous;
|
|
968
|
+
let reading;
|
|
969
|
+
let counted;
|
|
721
970
|
let paths = [];
|
|
722
971
|
let outputPath = "";
|
|
723
|
-
const trackChanges = selected.some((reporter) => reporter.name === "cli") && logLevel$1 > logLevel.silent;
|
|
724
|
-
context.hook("kubb:generation:start",
|
|
972
|
+
const trackChanges = (fileChanges || selected.some((reporter) => reporter.name === "cli")) && logLevel$1 > logLevel.silent;
|
|
973
|
+
context.hook("kubb:generation:start", ({ config }) => {
|
|
725
974
|
pluginFiles?.clear();
|
|
726
975
|
seen.clear();
|
|
727
976
|
filesUnchanged = 0;
|
|
728
977
|
paths = [];
|
|
729
978
|
outputPath = resolve(config.root, config.output.path);
|
|
730
|
-
previous =
|
|
979
|
+
previous = void 0;
|
|
980
|
+
reading = trackChanges && (dryRun || config.storage?.name === "fs") ? readOutputFiles(outputPath) : void 0;
|
|
981
|
+
counted = reading && !dryRun && !hasOutputPasses(config) ? /* @__PURE__ */ new Map() : void 0;
|
|
982
|
+
});
|
|
983
|
+
context.hook("kubb:plugins:end", async () => {
|
|
984
|
+
if (reading) previous = await reading;
|
|
731
985
|
});
|
|
732
986
|
context.hook("kubb:files:processing:start", async ({ files }) => {
|
|
733
987
|
if (!previous) return;
|
|
@@ -737,6 +991,15 @@ function setupReporters(context, { logLevel: logLevel$1, reporters, writer: writ
|
|
|
737
991
|
if (source !== null) previous.set(file.path, source);
|
|
738
992
|
}
|
|
739
993
|
});
|
|
994
|
+
context.hook("kubb:file:processed", ({ file, source }) => {
|
|
995
|
+
if (!counted || !previous) return;
|
|
996
|
+
const next = source.trim();
|
|
997
|
+
if (next) counted.set(file.path, diffFile({
|
|
998
|
+
path: file.path,
|
|
999
|
+
next,
|
|
1000
|
+
previous: previous.get(file.path) ?? null
|
|
1001
|
+
}));
|
|
1002
|
+
});
|
|
740
1003
|
context.hook("kubb:files:processing:end", ({ files, unchanged }) => {
|
|
741
1004
|
filesUnchanged = unchanged.length;
|
|
742
1005
|
paths = files.map((file) => file.path);
|
|
@@ -762,7 +1025,8 @@ function setupReporters(context, { logLevel: logLevel$1, reporters, writer: writ
|
|
|
762
1025
|
paths,
|
|
763
1026
|
clean: Boolean(config.output.clean),
|
|
764
1027
|
manifest,
|
|
765
|
-
previousFiles: previous
|
|
1028
|
+
previousFiles: previous,
|
|
1029
|
+
counted
|
|
766
1030
|
});
|
|
767
1031
|
const changes = {
|
|
768
1032
|
added: 0,
|
|
@@ -791,7 +1055,7 @@ function setupReporters(context, { logLevel: logLevel$1, reporters, writer: writ
|
|
|
791
1055
|
files: [...files]
|
|
792
1056
|
})) : void 0;
|
|
793
1057
|
await reporter.report({
|
|
794
|
-
...reporter.name === "cli" ? cliResult : result,
|
|
1058
|
+
...reporter.name === "cli" || fileChanges ? cliResult : result,
|
|
795
1059
|
pluginFiles: grouped
|
|
796
1060
|
}, ctx);
|
|
797
1061
|
}
|
|
@@ -804,6 +1068,6 @@ function setupReporters(context, { logLevel: logLevel$1, reporters, writer: writ
|
|
|
804
1068
|
function selectReporters(reporters, names) {
|
|
805
1069
|
return [...new Set(names)].flatMap((name) => reporters.find((reporter) => reporter.name === name) ?? []);
|
|
806
1070
|
}
|
|
807
|
-
export { setupReporters as n, selectReporters as t };
|
|
1071
|
+
export { startWatcher as a, listenForKeys as i, setupReporters as n, trackBuild as o, diffBuilds as r, selectReporters as t };
|
|
808
1072
|
|
|
809
|
-
//# sourceMappingURL=reporters-
|
|
1073
|
+
//# sourceMappingURL=reporters-B_USHwD6.js.map
|