@visulima/vis 1.0.0-alpha.10 → 1.0.0-alpha.11

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.
Files changed (120) hide show
  1. package/CHANGELOG.md +95 -42
  2. package/LICENSE.md +213 -0
  3. package/README.md +8 -4
  4. package/dist/bin.js +9 -1
  5. package/dist/config/index.d.ts +1818 -0
  6. package/dist/config/index.js +2 -0
  7. package/dist/generate/index.d.ts +1 -1
  8. package/dist/generate/index.js +3 -1
  9. package/dist/packem_chunks/applyDefaults.js +336 -0
  10. package/dist/packem_chunks/bin.js +9554 -64
  11. package/dist/packem_chunks/doctor-probe.js +112 -0
  12. package/dist/packem_chunks/fix.js +229 -48
  13. package/dist/packem_chunks/handler.js +99 -1
  14. package/dist/packem_chunks/handler10.js +53 -1
  15. package/dist/packem_chunks/handler11.js +32 -1
  16. package/dist/packem_chunks/handler12.js +100 -2
  17. package/dist/packem_chunks/handler13.js +25 -1
  18. package/dist/packem_chunks/handler14.js +916 -5
  19. package/dist/packem_chunks/handler15.js +206 -1
  20. package/dist/packem_chunks/handler16.js +122 -18
  21. package/dist/packem_chunks/handler17.js +13 -1
  22. package/dist/packem_chunks/handler18.js +106 -1
  23. package/dist/packem_chunks/handler19.js +19 -1
  24. package/dist/packem_chunks/handler2.js +75 -1
  25. package/dist/packem_chunks/handler20.js +29 -1
  26. package/dist/packem_chunks/handler21.js +222 -1
  27. package/dist/packem_chunks/handler22.js +237 -5
  28. package/dist/packem_chunks/handler23.js +101 -1
  29. package/dist/packem_chunks/handler24.js +110 -1
  30. package/dist/packem_chunks/handler25.js +402 -5
  31. package/dist/packem_chunks/handler26.js +13 -1
  32. package/dist/packem_chunks/handler27.js +63 -3
  33. package/dist/packem_chunks/handler28.js +34 -1
  34. package/dist/packem_chunks/handler29.js +458 -7
  35. package/dist/packem_chunks/handler3.js +95 -2
  36. package/dist/packem_chunks/handler30.js +168 -21
  37. package/dist/packem_chunks/handler31.js +530 -3
  38. package/dist/packem_chunks/handler32.js +214 -2
  39. package/dist/packem_chunks/handler33.js +119 -24
  40. package/dist/packem_chunks/handler34.js +630 -2
  41. package/dist/packem_chunks/handler35.js +283 -19
  42. package/dist/packem_chunks/handler36.js +521 -407
  43. package/dist/packem_chunks/handler37.js +762 -22
  44. package/dist/packem_chunks/handler38.js +989 -22
  45. package/dist/packem_chunks/handler39.js +574 -22
  46. package/dist/packem_chunks/handler4.js +90 -4
  47. package/dist/packem_chunks/handler40.js +1685 -3
  48. package/dist/packem_chunks/handler41.js +1088 -10
  49. package/dist/packem_chunks/handler42.js +785 -141
  50. package/dist/packem_chunks/handler43.js +2658 -42
  51. package/dist/packem_chunks/handler44.js +3886 -3
  52. package/dist/packem_chunks/handler45.js +2568 -21
  53. package/dist/packem_chunks/handler46.js +3769 -0
  54. package/dist/packem_chunks/handler47.js +1491 -0
  55. package/dist/packem_chunks/handler5.js +174 -2
  56. package/dist/packem_chunks/handler6.js +95 -13
  57. package/dist/packem_chunks/handler7.js +115 -8
  58. package/dist/packem_chunks/handler8.js +12 -1
  59. package/dist/packem_chunks/handler9.js +29 -1
  60. package/dist/packem_chunks/heal-accept.js +522 -0
  61. package/dist/packem_chunks/heal.js +673 -0
  62. package/dist/packem_chunks/index.js +873 -7
  63. package/dist/packem_chunks/loader.js +23 -1
  64. package/dist/packem_shared/VisUpdateApp-D-Yz_wvg.js +1316 -0
  65. package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +5 -0
  66. package/dist/packem_shared/ai-analysis-CHeB1joD.js +367 -0
  67. package/dist/packem_shared/ai-cache-Be_jexe4.js +142 -0
  68. package/dist/packem_shared/ai-fix-B9iQVcD2.js +379 -0
  69. package/dist/packem_shared/cache-directory-2qvs4goY.js +98 -0
  70. package/dist/packem_shared/catalog-BJTtyi-O.js +1371 -0
  71. package/dist/packem_shared/dependency-scan-A0KSklpG.js +188 -0
  72. package/dist/packem_shared/docker-2iZzc280.js +181 -0
  73. package/dist/packem_shared/failure-log-Cz3Z4SKL.js +100 -0
  74. package/dist/packem_shared/flakiness-goTxXuCX.js +180 -0
  75. package/dist/packem_shared/otel-DCvqCTz_.js +158 -0
  76. package/dist/packem_shared/otelPlugin-DFaLDvJf.js +3 -0
  77. package/dist/packem_shared/registry-CbqXI0rc.js +272 -0
  78. package/dist/packem_shared/run-summary-utils-PVMl4aIh.js +130 -0
  79. package/dist/packem_shared/runtime-check-Cobi3p6l.js +127 -0
  80. package/dist/packem_shared/selectors-SM69TfqC.js +194 -0
  81. package/dist/packem_shared/symbols-Ta7g2nU-.js +14 -0
  82. package/dist/packem_shared/toolchain-BdZd9eBi.js +975 -0
  83. package/dist/packem_shared/typosquats-C-bCh3PX.js +1210 -0
  84. package/dist/packem_shared/use-measured-height-CNP0vT4M.js +20 -0
  85. package/dist/packem_shared/utils-CthVdBPS.js +40 -0
  86. package/dist/packem_shared/xxh3-Ck8mXNg1.js +239 -0
  87. package/index.js +727 -555
  88. package/package.json +35 -17
  89. package/schemas/project.schema.json +8 -10
  90. package/schemas/vis-config.schema.json +132 -8
  91. package/skills/vis/SKILL.md +96 -0
  92. package/templates/buildkite-ci/.buildkite/pipeline.yml.tera +85 -0
  93. package/templates/buildkite-ci/template.yml +20 -0
  94. package/dist/errors/index.d.ts +0 -26
  95. package/dist/errors/index.js +0 -1
  96. package/dist/packem_chunks/config.js +0 -2
  97. package/dist/packem_shared/VisConfigCycleError-CAYNC7d-.js +0 -1
  98. package/dist/packem_shared/VisConfigError-B5LP1zRf.js +0 -1
  99. package/dist/packem_shared/VisConfigLoadError-CeqBSd2Z.js +0 -2
  100. package/dist/packem_shared/VisConfigNotFoundError-DZ9KC527.js +0 -5
  101. package/dist/packem_shared/VisUpdateApp-D-L4_-Iu.js +0 -1
  102. package/dist/packem_shared/_commonjsHelpers-D6W6KoPK.js +0 -1
  103. package/dist/packem_shared/ai-analysis-CGuy7dfE.js +0 -67
  104. package/dist/packem_shared/ai-cache-Bynt6Y9x.js +0 -1
  105. package/dist/packem_shared/cache-directory-D72ZEag2.js +0 -1
  106. package/dist/packem_shared/catalog-BVPerCwG.js +0 -12
  107. package/dist/packem_shared/dependency-scan-Du0tBu64.js +0 -2
  108. package/dist/packem_shared/docker-BcfqH4Av.js +0 -2
  109. package/dist/packem_shared/failure-log-DqYen0LC.js +0 -2
  110. package/dist/packem_shared/flakiness-DSIHZGBT.js +0 -1
  111. package/dist/packem_shared/run-summary-utils-C24Aaf9E.js +0 -1
  112. package/dist/packem_shared/runtime-check-CGHal8SO.js +0 -1
  113. package/dist/packem_shared/selectors-CfH9ZY08.js +0 -3
  114. package/dist/packem_shared/symbols-CQmER5MT.js +0 -1
  115. package/dist/packem_shared/target-merge-DNa-6eWu.js +0 -1
  116. package/dist/packem_shared/toolchain-DQfTQY8E.js +0 -5
  117. package/dist/packem_shared/typosquats-DOR8izpX.js +0 -1
  118. package/dist/packem_shared/use-measured-height-DjYgUOKk.js +0 -1
  119. package/dist/packem_shared/utils-DrNg0XTR.js +0 -1
  120. package/dist/packem_shared/xxh3-DrAUNq4n.js +0 -1
@@ -1 +1,222 @@
1
- var f=Object.defineProperty;var t=(e,o)=>f(e,"name",{value:o,configurable:!0});import{J as p,Z as g}from"./bin.js";import{o as v}from"../packem_shared/utils-DrNg0XTR.js";var d=Object.defineProperty,k=t((e,o)=>d(e,"name",{value:o,configurable:!0}),"t");const b=k(async({argument:e,logger:o,options:a,visConfig:i,workspaceRoot:l})=>{const s=e;if(!s||s.length===0)throw new Error("No packages specified. Usage: vis remove <packages...>");const r=process.cwd(),n=p(l??r,{configBackend:i?.install?.backend}),c=g(n,{filter:v(a.filter),global:a.global||!1,packages:s,recursive:a.recursive||!1,saveDev:a.saveDev||!1,workspaceRoot:a.workspaceRoot||!1},r,o);c!==0&&(process.exitCode=c)},"execute");export{b as default};
1
+ import { readLastRunSummary } from '@visulima/task-runner';
2
+ import { p as pail } from './bin.js';
3
+ import { l as listRunSummaries, r as readRunSummaryById } from '../packem_shared/run-summary-utils-PVMl4aIh.js';
4
+
5
+ const VALID_FORMATS = /* @__PURE__ */ new Set(["json", "table"]);
6
+ const resolveWorkspaceRoot = (workspaceRoot) => workspaceRoot ?? process.cwd();
7
+ const formatDuration = (ms) => {
8
+ if (ms === void 0) {
9
+ return "-";
10
+ }
11
+ if (ms < 1e3) {
12
+ return `${String(ms)}ms`;
13
+ }
14
+ return `${(ms / 1e3).toFixed(2)}s`;
15
+ };
16
+ const formatStatus = (task) => {
17
+ if (task.exitCode === void 0) {
18
+ return task.cacheStatus;
19
+ }
20
+ if (task.exitCode === 0) {
21
+ return task.cacheStatus === "MISS" ? "OK" : task.cacheStatus;
22
+ }
23
+ return `FAIL(${String(task.exitCode)})`;
24
+ };
25
+ const padCell = (value, width) => {
26
+ if (value.length >= width) {
27
+ return value;
28
+ }
29
+ return value + " ".repeat(width - value.length);
30
+ };
31
+ const isFailedTask = (task) => task.exitCode !== void 0 && task.exitCode !== 0;
32
+ const renderRunHeader = (summary, logger) => {
33
+ logger.info(`Run ${summary.id}`);
34
+ logger.info(` start: ${summary.startTime}`);
35
+ logger.info(` end: ${summary.endTime}`);
36
+ logger.info(` duration: ${formatDuration(summary.duration)}`);
37
+ logger.info(
38
+ ` totals: ${String(summary.stats.total)} total · ${String(summary.stats.succeeded)} ok · ${String(summary.stats.cached)} cached · ${String(summary.stats.skipped)} skipped · ${String(summary.stats.failed)} failed`
39
+ );
40
+ logger.info(` env: node ${summary.environment.nodeVersion} · ${summary.environment.platform}/${summary.environment.arch}`);
41
+ logger.info("");
42
+ };
43
+ const renderTaskTable = (tasks, logger) => {
44
+ if (tasks.length === 0) {
45
+ logger.info("(no tasks match the current filter)");
46
+ return;
47
+ }
48
+ const rows = tasks.map((task) => ({
49
+ duration: formatDuration(task.duration),
50
+ hash: task.hash ? task.hash.slice(0, 12) : "-",
51
+ status: formatStatus(task),
52
+ taskId: task.taskId
53
+ }));
54
+ const widths = {
55
+ duration: Math.max("duration".length, ...rows.map((r) => r.duration.length)),
56
+ hash: Math.max("hash".length, ...rows.map((r) => r.hash.length)),
57
+ status: Math.max("status".length, ...rows.map((r) => r.status.length)),
58
+ taskId: Math.max("task".length, ...rows.map((r) => r.taskId.length))
59
+ };
60
+ logger.info(
61
+ ` ${padCell("task", widths.taskId)} ${padCell("status", widths.status)} ${padCell("duration", widths.duration)} ${padCell("hash", widths.hash)}`
62
+ );
63
+ logger.info(` ${"-".repeat(widths.taskId)} ${"-".repeat(widths.status)} ${"-".repeat(widths.duration)} ${"-".repeat(widths.hash)}`);
64
+ for (const row of rows) {
65
+ logger.info(
66
+ ` ${padCell(row.taskId, widths.taskId)} ${padCell(row.status, widths.status)} ${padCell(row.duration, widths.duration)} ${padCell(row.hash, widths.hash)}`
67
+ );
68
+ }
69
+ };
70
+ const renderTaskDetail = (summary, task, logger) => {
71
+ renderRunHeader(summary, logger);
72
+ logger.info(`Task ${task.taskId}`);
73
+ logger.info(` status: ${formatStatus(task)}`);
74
+ logger.info(` cache: ${task.cacheStatus}`);
75
+ logger.info(` duration: ${formatDuration(task.duration)}`);
76
+ logger.info(` exit: ${task.exitCode === void 0 ? "-" : String(task.exitCode)}`);
77
+ logger.info(` hash: ${task.hash ?? "(none)"}`);
78
+ logger.info(` start: ${task.startTime ?? "-"}`);
79
+ logger.info(` end: ${task.endTime ?? "-"}`);
80
+ if (task.dependencies.length > 0) {
81
+ logger.info(` deps: ${task.dependencies.join(", ")}`);
82
+ }
83
+ logger.info("");
84
+ pail.info(`Drill into hash inputs with: vis cache why ${task.taskId} --run ${summary.id}`);
85
+ };
86
+ const renderListJson = (entries) => {
87
+ process.stdout.write(
88
+ `${JSON.stringify(
89
+ entries.map((entry) => ({
90
+ id: entry.id,
91
+ mtime: new Date(entry.mtimeMs).toISOString(),
92
+ path: entry.path
93
+ })),
94
+ void 0,
95
+ 2
96
+ )}
97
+ `
98
+ );
99
+ };
100
+ const renderListTable = (entries, logger) => {
101
+ if (entries.length === 0) {
102
+ pail.info("No recorded runs found in .task-runner/runs/. Run with --summarize to record a run.");
103
+ return;
104
+ }
105
+ const widths = {
106
+ id: Math.max("id".length, ...entries.map((entry) => entry.id.length)),
107
+ mtime: 24
108
+ };
109
+ logger.info(` ${padCell("id", widths.id)} ${padCell("mtime", widths.mtime)}`);
110
+ logger.info(` ${"-".repeat(widths.id)} ${"-".repeat(widths.mtime)}`);
111
+ for (const entry of entries) {
112
+ logger.info(` ${padCell(entry.id, widths.id)} ${new Date(entry.mtimeMs).toISOString()}`);
113
+ }
114
+ };
115
+ const filterTasks = (summary, options) => {
116
+ let tasks = summary.tasks;
117
+ if (options.task !== void 0) {
118
+ tasks = tasks.filter((t) => t.taskId === options.task);
119
+ }
120
+ if (options.failed) {
121
+ tasks = tasks.filter((t) => isFailedTask(t));
122
+ }
123
+ return tasks;
124
+ };
125
+ const runReplay = async (options, logger) => {
126
+ const { failed, format, runId, task: taskFilter, workspaceRoot } = options;
127
+ const summary = runId === void 0 ? await readLastRunSummary(workspaceRoot) : await readRunSummaryById(workspaceRoot, runId);
128
+ if (!summary) {
129
+ if (format === "json") {
130
+ process.stdout.write(`${JSON.stringify({ error: "no-summary", runId: runId ?? null }, void 0, 2)}
131
+ `);
132
+ process.exitCode = 1;
133
+ return;
134
+ }
135
+ if (runId === void 0) {
136
+ pail.error("No previous run summary found. Run a task first to populate `.task-runner/last-summary.json`.");
137
+ } else {
138
+ pail.error(`Run summary "${runId}" not found in .task-runner/runs/.`);
139
+ }
140
+ process.exitCode = 1;
141
+ return;
142
+ }
143
+ const filteredTasks = filterTasks(summary, { failed, task: taskFilter });
144
+ if (taskFilter !== void 0 && filteredTasks.length === 0) {
145
+ if (format === "json") {
146
+ process.stdout.write(`${JSON.stringify({ error: "task-not-in-summary", runId: summary.id, taskId: taskFilter }, void 0, 2)}
147
+ `);
148
+ process.exitCode = 1;
149
+ return;
150
+ }
151
+ pail.error(`Task "${taskFilter}" was not part of run ${summary.id}.`);
152
+ process.exitCode = 1;
153
+ return;
154
+ }
155
+ if (summary.stats.failed > 0) {
156
+ process.exitCode = 1;
157
+ }
158
+ if (format === "json") {
159
+ process.stdout.write(
160
+ `${JSON.stringify(
161
+ {
162
+ duration: summary.duration,
163
+ endTime: summary.endTime,
164
+ environment: summary.environment,
165
+ runId: summary.id,
166
+ startTime: summary.startTime,
167
+ stats: summary.stats,
168
+ tasks: filteredTasks.map((t) => ({
169
+ cacheStatus: t.cacheStatus,
170
+ dependencies: t.dependencies,
171
+ duration: t.duration,
172
+ endTime: t.endTime,
173
+ exitCode: t.exitCode,
174
+ hash: t.hash ?? null,
175
+ startTime: t.startTime,
176
+ taskId: t.taskId
177
+ }))
178
+ },
179
+ void 0,
180
+ 2
181
+ )}
182
+ `
183
+ );
184
+ return;
185
+ }
186
+ if (taskFilter !== void 0) {
187
+ renderTaskDetail(summary, filteredTasks[0], logger);
188
+ return;
189
+ }
190
+ renderRunHeader(summary, logger);
191
+ renderTaskTable(filteredTasks, logger);
192
+ };
193
+ const replayExecute = async ({ logger, options, workspaceRoot: wsRoot }) => {
194
+ const workspaceRoot = resolveWorkspaceRoot(wsRoot);
195
+ const format = options.format ?? "table";
196
+ if (!VALID_FORMATS.has(format)) {
197
+ pail.error(`Invalid --format: ${format}. Expected "table" or "json".`);
198
+ process.exitCode = 1;
199
+ return;
200
+ }
201
+ if (options.list === true) {
202
+ const entries = await listRunSummaries(workspaceRoot);
203
+ if (format === "json") {
204
+ renderListJson(entries);
205
+ return;
206
+ }
207
+ renderListTable(entries, logger);
208
+ return;
209
+ }
210
+ await runReplay(
211
+ {
212
+ failed: options.failed === true,
213
+ format,
214
+ runId: options.run,
215
+ task: options.task,
216
+ workspaceRoot
217
+ },
218
+ logger
219
+ );
220
+ };
221
+
222
+ export { replayExecute as default, replayExecute, runReplay };
@@ -1,5 +1,237 @@
1
- var _=Object.defineProperty;var $=(e,r)=>_(e,"name",{value:r,configurable:!0});import{createRequire as N}from"node:module";import{isAccessibleSync as w,readFileSync as b}from"@visulima/fs";import{resolve as J,join as y,relative as F,basename as I}from"@visulima/path";import P from"zeptomatch";import{sortPackageJsonStringWithOptions as C}from"#native";import{D as M,f as k,p as d}from"./bin.js";import{f as O}from"../packem_shared/utils-DrNg0XTR.js";const A=N(import.meta.url),g=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,x=$(e=>{if(typeof g<"u"&&g.versions&&g.versions.node){const[r,s]=g.versions.node.split(".").map(Number);if(r>22||r===22&&s>=3||r===20&&s>=16)return g.getBuiltinModule(e)}return A(e)},"__cjs_getBuiltinModule"),{writeFileSync:E}=x("node:fs");var T=Object.defineProperty,a=$((e,r)=>T(e,"name",{value:r,configurable:!0}),"c");const q=a(e=>{const r=new Set,s=[],i=a(n=>{const o=J(n);!r.has(o)&&w(o)&&(r.add(o),s.push(o))},"addFile");i(y(e,"package.json"));const t=M(e);if(t){const n=k(e,t);for(const o of n)i(y(e,o,"package.json"))}else{const n=y(e,"package.json");if(w(n)){const o=JSON.parse(b(n)),l=Array.isArray(o.workspaces)?o.workspaces:o.workspaces?.packages;if(l){const m=k(e,l);for(const f of m)i(y(e,f,"package.json"))}}}return s},"findPackageJsonFiles"),B=a(e=>/\n([ \t]+)/.exec(e)?.[1]??" ","detectIndent"),D=a(e=>{if(!(e===void 0||e===""))return e==="tab"||e===String.raw`\t`?" ":/^\d+$/.test(e)?" ".repeat(Number.parseInt(e,10)):e},"resolveIndentOverride"),j=a(e=>e===void 0?[]:(Array.isArray(e)?e:[e]).flatMap(r=>r.split(",")).map(r=>r.trim()).filter(r=>r.length>0),"splitList"),L=a(e=>e.includes(`\r
2
- `)?"crlf":"lf","detectLineEnding"),R=new Set(["auto","crlf","lf"]),W=a(e=>{if(e===void 0||e==="")return"auto";if(R.has(e))return e;d.error(`--line-ending must be one of: auto, lf, crlf (got "${e}")`),process.exit(2)},"validateLineEnding"),z=a((e,r,s)=>r.length===0?e:e.filter(i=>{const t=F(s,i),n=I(i);return!r.some(o=>{const l=o.includes("/")?t:n;return P(o,l)})}),"filterByIgnore"),U=a((e,r)=>{if(r.length===0)return e;const s={},i=new Set;for(const t of r)Object.hasOwn(e,t)&&(s[t]=e[t],i.add(t));for(const t of Object.keys(e))i.has(t)||(s[t]=e[t]);return s},"applySortOrder"),G=a((e,r,s)=>{if(s.length===0)return e;const i={...e};for(const t of s)Object.hasOwn(r,t)&&(i[t]=r[t]);return i},"restoreUnsortedSections"),H=a((e,r)=>{const s=r.indent??B(e),i=r.lineEnding==="auto"?L(e):r.lineEnding,t=C(e,{pretty:!1,sortScripts:r.sortScripts});let n=JSON.parse(t);if(r.unsorted.length>0){const l=JSON.parse(e);n=G(n,l,r.unsorted)}n=U(n,r.sortOrder);let o=JSON.stringify(n,null,s);return r.finalNewline&&(o+=`
3
- `),i==="crlf"&&(o=o.replaceAll(`
4
- `,`\r
5
- `)),o},"sortContents"),te=a(async({options:e,visConfig:r,workspaceRoot:s})=>{const i=s??process.cwd(),t=r?.sortPackageJson,n=e.check||!1,o={finalNewline:e.finalNewline??t?.finalNewline??!0,ignore:[...j(e.ignore),...t?.ignore??[]],indent:D(e.indent??t?.indent),lineEnding:W(e.lineEnding??t?.lineEnding),sortOrder:[...j(e.sortOrder),...t?.sortOrder??[]],sortScripts:e.sortScripts||t?.sortScripts||!1,unsorted:[...j(e.unsorted),...t?.unsorted??[]]},l=q(i),m=z(l,o.ignore,i);if(m.length===0){d.info(l.length===0?"No package.json files found.":"All package.json files were excluded by --ignore.");return}let f=0,p=0,u=0;for(const c of m)try{const h=b(c);let S;try{S=H(h,o)}catch(v){d.error(`${c}: ${O(v)}`),u++;continue}if(h===S){p++;continue}f++,n?d.warn(`${c} is not sorted`):(E(c,S,"utf8"),d.success(`Sorted ${c}`))}catch(h){d.error(`${c}: ${O(h)}`),u++}if(n)f>0?(d.info(`${f} file${f===1?"":"s"} not sorted, ${p} already sorted`),process.exitCode=1):d.info(`All ${p} package.json file${p===1?" is":"s are"} sorted`);else{const c=[];f>0&&c.push(`sorted ${f} file${f===1?"":"s"}`),p>0&&c.push(`${p} already sorted`),u>0&&c.push(`${u} error${u===1?"":"s"}`),d.info(c.join(", "))}u>0&&(process.exitCode=1)},"execute");export{te as default};
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ writeFileSync
22
+ } = __cjs_getBuiltinModule("node:fs");
23
+ import { readFileSync, isAccessibleSync } from '@visulima/fs';
24
+ import { join, relative, basename, resolve } from '@visulima/path';
25
+ import zeptomatch from 'zeptomatch';
26
+ import { sortPackageJsonStringWithOptions } from '#native';
27
+ import { p as pail, q as readPnpmWorkspacePatterns, o as resolveWorkspacePatterns } from './bin.js';
28
+ import { e as errorMessage } from '../packem_shared/utils-CthVdBPS.js';
29
+
30
+ const findPackageJsonFiles = (root) => {
31
+ const seen = /* @__PURE__ */ new Set();
32
+ const results = [];
33
+ const addFile = (filePath) => {
34
+ const resolved = resolve(filePath);
35
+ if (!seen.has(resolved) && isAccessibleSync(resolved)) {
36
+ seen.add(resolved);
37
+ results.push(resolved);
38
+ }
39
+ };
40
+ addFile(join(root, "package.json"));
41
+ const pnpmPatterns = readPnpmWorkspacePatterns(root);
42
+ if (pnpmPatterns) {
43
+ const projectDirectories = resolveWorkspacePatterns(root, pnpmPatterns);
44
+ for (const dir of projectDirectories) {
45
+ addFile(join(root, dir, "package.json"));
46
+ }
47
+ } else {
48
+ const rootPkgPath = join(root, "package.json");
49
+ if (isAccessibleSync(rootPkgPath)) {
50
+ const rootPkg = JSON.parse(readFileSync(rootPkgPath));
51
+ const patterns = Array.isArray(rootPkg.workspaces) ? rootPkg.workspaces : rootPkg.workspaces?.packages;
52
+ if (patterns) {
53
+ const projectDirectories = resolveWorkspacePatterns(root, patterns);
54
+ for (const dir of projectDirectories) {
55
+ addFile(join(root, dir, "package.json"));
56
+ }
57
+ }
58
+ }
59
+ }
60
+ return results;
61
+ };
62
+ const detectIndent = (contents) => {
63
+ const match = /\n([ \t]+)/.exec(contents);
64
+ return match?.[1] ?? " ";
65
+ };
66
+ const resolveIndentOverride = (raw) => {
67
+ if (raw === void 0 || raw === "") {
68
+ return void 0;
69
+ }
70
+ if (raw === "tab" || raw === String.raw`\t`) {
71
+ return " ";
72
+ }
73
+ if (/^\d+$/.test(raw)) {
74
+ return " ".repeat(Number.parseInt(raw, 10));
75
+ }
76
+ return raw;
77
+ };
78
+ const splitList = (raw) => {
79
+ if (raw === void 0) {
80
+ return [];
81
+ }
82
+ const items = Array.isArray(raw) ? raw : [raw];
83
+ return items.flatMap((item) => item.split(",")).map((item) => item.trim()).filter((item) => item.length > 0);
84
+ };
85
+ const detectLineEnding = (contents) => contents.includes("\r\n") ? "crlf" : "lf";
86
+ const ALLOWED_LINE_ENDINGS = /* @__PURE__ */ new Set(["auto", "crlf", "lf"]);
87
+ const validateLineEnding = (raw) => {
88
+ if (raw === void 0 || raw === "") {
89
+ return "auto";
90
+ }
91
+ if (ALLOWED_LINE_ENDINGS.has(raw)) {
92
+ return raw;
93
+ }
94
+ pail.error(`--line-ending must be one of: auto, lf, crlf (got "${raw}")`);
95
+ process.exit(2);
96
+ };
97
+ const filterByIgnore = (files, patterns, cwd) => {
98
+ if (patterns.length === 0) {
99
+ return files;
100
+ }
101
+ return files.filter((absolute) => {
102
+ const relPath = relative(cwd, absolute);
103
+ const base = basename(absolute);
104
+ return !patterns.some((pattern) => {
105
+ const target = pattern.includes("/") ? relPath : base;
106
+ return zeptomatch(pattern, target);
107
+ });
108
+ });
109
+ };
110
+ const applySortOrder = (object, sortOrder) => {
111
+ if (sortOrder.length === 0) {
112
+ return object;
113
+ }
114
+ const result = {};
115
+ const consumed = /* @__PURE__ */ new Set();
116
+ for (const key of sortOrder) {
117
+ if (Object.hasOwn(object, key)) {
118
+ result[key] = object[key];
119
+ consumed.add(key);
120
+ }
121
+ }
122
+ for (const key of Object.keys(object)) {
123
+ if (!consumed.has(key)) {
124
+ result[key] = object[key];
125
+ }
126
+ }
127
+ return result;
128
+ };
129
+ const restoreUnsortedSections = (sorted, original, unsorted) => {
130
+ if (unsorted.length === 0) {
131
+ return sorted;
132
+ }
133
+ const result = { ...sorted };
134
+ for (const key of unsorted) {
135
+ if (Object.hasOwn(original, key)) {
136
+ result[key] = original[key];
137
+ }
138
+ }
139
+ return result;
140
+ };
141
+ const sortContents = (contents, config) => {
142
+ const indent = config.indent ?? detectIndent(contents);
143
+ const lineEnding = config.lineEnding === "auto" ? detectLineEnding(contents) : config.lineEnding;
144
+ const compact = sortPackageJsonStringWithOptions(contents, {
145
+ pretty: false,
146
+ sortScripts: config.sortScripts
147
+ });
148
+ let parsed = JSON.parse(compact);
149
+ if (config.unsorted.length > 0) {
150
+ const original = JSON.parse(contents);
151
+ parsed = restoreUnsortedSections(parsed, original, config.unsorted);
152
+ }
153
+ parsed = applySortOrder(parsed, config.sortOrder);
154
+ let output = JSON.stringify(parsed, null, indent);
155
+ if (config.finalNewline) {
156
+ output += "\n";
157
+ }
158
+ if (lineEnding === "crlf") {
159
+ output = output.replaceAll("\n", "\r\n");
160
+ }
161
+ return output;
162
+ };
163
+ const execute = async ({ options, visConfig, workspaceRoot: wsRoot }) => {
164
+ const cwd = wsRoot ?? process.cwd();
165
+ const config = visConfig?.["sortPackageJson"];
166
+ const check = options.check || false;
167
+ const normalized = {
168
+ finalNewline: options.finalNewline ?? config?.finalNewline ?? true,
169
+ ignore: [...splitList(options.ignore), ...config?.ignore ?? []],
170
+ indent: resolveIndentOverride(options.indent ?? config?.indent),
171
+ lineEnding: validateLineEnding(options.lineEnding ?? config?.lineEnding),
172
+ sortOrder: [...splitList(options.sortOrder), ...config?.sortOrder ?? []],
173
+ sortScripts: options.sortScripts || config?.sortScripts || false,
174
+ unsorted: [...splitList(options.unsorted), ...config?.unsorted ?? []]
175
+ };
176
+ const allFiles = findPackageJsonFiles(cwd);
177
+ const files = filterByIgnore(allFiles, normalized.ignore, cwd);
178
+ if (files.length === 0) {
179
+ pail.info(allFiles.length === 0 ? "No package.json files found." : "All package.json files were excluded by --ignore.");
180
+ return;
181
+ }
182
+ let unsortedCount = 0;
183
+ let sortedCount = 0;
184
+ let errorCount = 0;
185
+ for (const filePath of files) {
186
+ try {
187
+ const contents = readFileSync(filePath);
188
+ let sorted;
189
+ try {
190
+ sorted = sortContents(contents, normalized);
191
+ } catch (error) {
192
+ pail.error(`${filePath}: ${errorMessage(error)}`);
193
+ errorCount++;
194
+ continue;
195
+ }
196
+ if (contents === sorted) {
197
+ sortedCount++;
198
+ continue;
199
+ }
200
+ unsortedCount++;
201
+ if (check) {
202
+ pail.warn(`${filePath} is not sorted`);
203
+ } else {
204
+ writeFileSync(filePath, sorted, "utf8");
205
+ pail.success(`Sorted ${filePath}`);
206
+ }
207
+ } catch (error) {
208
+ pail.error(`${filePath}: ${errorMessage(error)}`);
209
+ errorCount++;
210
+ }
211
+ }
212
+ if (check) {
213
+ if (unsortedCount > 0) {
214
+ pail.info(`${unsortedCount} file${unsortedCount === 1 ? "" : "s"} not sorted, ${sortedCount} already sorted`);
215
+ process.exitCode = 1;
216
+ } else {
217
+ pail.info(`All ${sortedCount} package.json file${sortedCount === 1 ? " is" : "s are"} sorted`);
218
+ }
219
+ } else {
220
+ const parts = [];
221
+ if (unsortedCount > 0) {
222
+ parts.push(`sorted ${unsortedCount} file${unsortedCount === 1 ? "" : "s"}`);
223
+ }
224
+ if (sortedCount > 0) {
225
+ parts.push(`${sortedCount} already sorted`);
226
+ }
227
+ if (errorCount > 0) {
228
+ parts.push(`${errorCount} error${errorCount === 1 ? "" : "s"}`);
229
+ }
230
+ pail.info(parts.join(", "));
231
+ }
232
+ if (errorCount > 0) {
233
+ process.exitCode = 1;
234
+ }
235
+ };
236
+
237
+ export { execute as default };
@@ -1 +1,101 @@
1
- var T=Object.defineProperty;var j=(e,t)=>T(e,"name",{value:t,configurable:!0});import{createRequire as C}from"node:module";import{green as f,red as v,dim as J,yellow as _}from"@visulima/colorize";import{isAccessibleSync as M,readJsonSync as P}from"@visulima/fs";import{join as b}from"@visulima/path";import{enforceProjectConstraints as V}from"@visulima/task-runner";import{r as z,s as A}from"./bin.js";import{a as B}from"../packem_shared/flakiness-DSIHZGBT.js";import{c as I}from"../packem_shared/runtime-check-CGHal8SO.js";const q=C(import.meta.url),n=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,x=j(e=>{if(typeof n<"u"&&n.versions&&n.versions.node){const[t,i]=n.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return n.getBuiltinModule(e)}return q(e)},"__cjs_getBuiltinModule"),{readdirSync:F}=x("node:fs");var K=Object.defineProperty,O=j((e,t)=>K(e,"name",{value:t,configurable:!0}),"h");const r=O(e=>e?f("✓"):v("✗"),"icon"),X=O(async({logger:e,options:t,visConfig:i,workspaceRoot:s})=>{if(!s)throw new Error("Could not determine workspace root.");const{config:y,packageJsons:w,workspace:u}=z(s,i),R=A(s,u,w),$=Object.keys(u.projects).length,k=new Set(Object.values(u.projects).flatMap(p=>Object.keys(p.targets??{}))).size,a=I(s);let o=0;y.constraints&&(o=V(R,y.constraints).length);const c=B(s,{minRuns:2});let l;const g=b(s,".task-runner","runs");if(M(g)){const p=F(g).filter(d=>d.endsWith(".json")).sort();let m=0,S=0;for(const d of p.slice(-20))try{const h=P(b(g,d));h.stats&&(m+=h.stats.total??0,S+=h.stats.cached??0)}catch{continue}m>0&&(l=`${(S/m*100).toFixed(0)}%`)}if(t.json){e.info(JSON.stringify({cacheHitRate:l??null,constraintViolations:o,flakyTasks:c.length,projects:$,runtimeIssues:a.length,targets:k},null,2));return}e.info(""),e.info(` ${J("VIS STATUS")}`),e.info(""),e.info(` ${r(!0)} ${String($)} projects · ${String(k)} unique targets`),e.info(` ${r(a.length===0)} Runtime: ${a.length===0?f("OK"):_(`${String(a.length)} issue(s)`)}`),e.info(` ${r(o===0)} Constraints: ${o===0?f("OK"):v(`${String(o)} violation(s)`)}`),e.info(` ${r(c.length===0)} Flaky tasks: ${c.length===0?f("none"):_(String(c.length))}`),l&&e.info(` ${r(!0)} Cache hit rate: ${l} (last 20 runs)`),e.info("")},"execute");export{X as default};
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ readdirSync
22
+ } = __cjs_getBuiltinModule("node:fs");
23
+ import { dim, green, yellow, red } from '@visulima/colorize';
24
+ import { isAccessibleSync, readJsonSync } from '@visulima/fs';
25
+ import { join } from '@visulima/path';
26
+ import { enforceProjectConstraints } from '@visulima/task-runner';
27
+ import { d as discoverWorkspace, b as buildProjectGraph } from './bin.js';
28
+ import { a as analyzeFlakiness } from '../packem_shared/flakiness-goTxXuCX.js';
29
+ import { c as checkRuntimeVersions } from '../packem_shared/runtime-check-Cobi3p6l.js';
30
+
31
+ const icon = (ok) => ok ? green("✓") : red("✗");
32
+ const execute = async ({ logger, options, visConfig, workspaceRoot: wsRoot }) => {
33
+ if (!wsRoot) {
34
+ throw new Error("Could not determine workspace root.");
35
+ }
36
+ const { config, packageJsons, workspace } = discoverWorkspace(wsRoot, visConfig);
37
+ const projectGraph = buildProjectGraph(wsRoot, workspace, packageJsons);
38
+ const projectCount = Object.keys(workspace.projects).length;
39
+ const targetCount = new Set(Object.values(workspace.projects).flatMap((p) => Object.keys(p.targets ?? {}))).size;
40
+ const runtimeFindings = checkRuntimeVersions(wsRoot);
41
+ let constraintViolations = 0;
42
+ if (config.constraints) {
43
+ constraintViolations = enforceProjectConstraints(projectGraph, config.constraints).length;
44
+ }
45
+ const flakyStats = analyzeFlakiness(wsRoot, { minRuns: 2 });
46
+ let cacheHitRate;
47
+ const runsDir = join(wsRoot, ".task-runner", "runs");
48
+ if (isAccessibleSync(runsDir)) {
49
+ const files = readdirSync(runsDir).filter((f) => f.endsWith(".json")).sort();
50
+ let totalTasks = 0;
51
+ let cachedTasks = 0;
52
+ for (const file of files.slice(-20)) {
53
+ try {
54
+ const data = readJsonSync(join(runsDir, file));
55
+ if (data.stats) {
56
+ totalTasks += data.stats.total ?? 0;
57
+ cachedTasks += data.stats.cached ?? 0;
58
+ }
59
+ } catch {
60
+ continue;
61
+ }
62
+ }
63
+ if (totalTasks > 0) {
64
+ cacheHitRate = `${(cachedTasks / totalTasks * 100).toFixed(0)}%`;
65
+ }
66
+ }
67
+ if (options.json) {
68
+ logger.info(
69
+ JSON.stringify(
70
+ {
71
+ cacheHitRate: cacheHitRate ?? null,
72
+ constraintViolations,
73
+ flakyTasks: flakyStats.length,
74
+ projects: projectCount,
75
+ runtimeIssues: runtimeFindings.length,
76
+ targets: targetCount
77
+ },
78
+ null,
79
+ 2
80
+ )
81
+ );
82
+ return;
83
+ }
84
+ logger.info("");
85
+ logger.info(` ${dim("VIS STATUS")}`);
86
+ logger.info("");
87
+ logger.info(` ${icon(true)} ${String(projectCount)} projects · ${String(targetCount)} unique targets`);
88
+ logger.info(
89
+ ` ${icon(runtimeFindings.length === 0)} Runtime: ${runtimeFindings.length === 0 ? green("OK") : yellow(`${String(runtimeFindings.length)} issue(s)`)}`
90
+ );
91
+ logger.info(
92
+ ` ${icon(constraintViolations === 0)} Constraints: ${constraintViolations === 0 ? green("OK") : red(`${String(constraintViolations)} violation(s)`)}`
93
+ );
94
+ logger.info(` ${icon(flakyStats.length === 0)} Flaky tasks: ${flakyStats.length === 0 ? green("none") : yellow(String(flakyStats.length))}`);
95
+ if (cacheHitRate) {
96
+ logger.info(` ${icon(true)} Cache hit rate: ${cacheHitRate} (last 20 runs)`);
97
+ }
98
+ logger.info("");
99
+ };
100
+
101
+ export { execute as default };