@scalar/cli 2.12.2 → 2.13.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.
Files changed (94) hide show
  1. package/README.md +221 -2
  2. package/chunks/{action-JXCU2JKC.js → action-27BJMHFD.js} +38 -6
  3. package/chunks/{action-WLPCBFRE.js → action-4EJA6UEB.js} +16 -16
  4. package/chunks/{action-JDXGQSQN.js → action-5MJTAO5X.js} +36 -23
  5. package/chunks/{action-H5XQIZKX.js → action-6FPGU5SY.js} +51 -24
  6. package/chunks/{action-HMPATNVE.js → action-6RQDLMOM.js} +53 -30
  7. package/chunks/{action-Y7EBKCUU.js → action-ASBFLTOA.js} +1 -1
  8. package/chunks/{action-HRRNN33O.js → action-AWHBOHGW.js} +68 -89
  9. package/chunks/{action-UOH5L2JF.js → action-ENN7KFBZ.js} +93 -54
  10. package/chunks/{action-ZNBXKA7T.js → action-ESVI46KE.js} +4 -4
  11. package/chunks/{action-LCTTNNFD.js → action-EVNUUWR5.js} +33 -17
  12. package/chunks/{action-OWWGJ34K.js → action-F6JSCBEU.js} +34 -16
  13. package/chunks/{action-2RIPHL6V.js → action-FZNFBX6U.js} +23 -6
  14. package/chunks/{action-DJ6FLPXH.js → action-GNYNOFDK.js} +15 -5
  15. package/chunks/{action-HOLFCPUY.js → action-JSYHIEYP.js} +12 -12
  16. package/chunks/action-KTY5ICV5.js +55 -0
  17. package/chunks/{action-IIQMZVRJ.js → action-LRR52RXL.js} +10 -8
  18. package/chunks/{action-Z3UXS5KI.js → action-LVYFHK4D.js} +6 -4
  19. package/chunks/{action-XBTIONQD.js → action-NN7QF6MI.js} +9 -6
  20. package/chunks/{action-2GIOY3HU.js → action-OD4GNHM3.js} +48 -28
  21. package/chunks/{action-OY5LI7TW.js → action-OZWRV54F.js} +9 -8
  22. package/chunks/{action-AZNY2B7G.js → action-QZV6IPK4.js} +26 -11
  23. package/chunks/action-S7PMEFCE.js +423 -0
  24. package/chunks/{action-6IL6KE3L.js → action-SZ6SG3RB.js} +16 -16
  25. package/chunks/{action-PRLW546C.js → action-U3MQZ5ZQ.js} +12 -12
  26. package/chunks/action-UAGYB4ZS.js +48 -0
  27. package/chunks/{action-U3R6AXJY.js → action-UVAYACFA.js} +6 -6
  28. package/chunks/{action-7OJTNQRM.js → action-VXEJNBNR.js} +9 -8
  29. package/chunks/{action-KE53K5EJ.js → action-W24B4YT5.js} +14 -14
  30. package/chunks/{action-QA5ATGWB.js → action-WQICTF7K.js} +67 -45
  31. package/chunks/{action-SFRYHYTZ.js → action-WUWWJGRJ.js} +6 -4
  32. package/chunks/{action-II3OJSGP.js → action-Y4YLWZHL.js} +12 -12
  33. package/chunks/{action-2NJJO35T.js → action-YEAOKB6V.js} +13 -11
  34. package/chunks/{action-LGNWFVEG.js → action-YFTRHKOK.js} +63 -48
  35. package/chunks/{action-QEYNGQXG.js → action-YQSSXJAX.js} +10 -7
  36. package/chunks/{action-IYUOT7XX.js → action-ZL2CXRJR.js} +8 -6
  37. package/chunks/{actions-DKQERAKZ.js → actions-GHHWF4Q2.js} +20 -18
  38. package/chunks/{agent-KQKNJZKK.js → agent-XAHNA4MB.js} +3 -3
  39. package/chunks/{asyncapi-MKBEQYBV.js → asyncapi-TICSLZRM.js} +52 -42
  40. package/chunks/{build.action-EGAOPKSX.js → build.action-AURC6QZ6.js} +37 -20
  41. package/chunks/{chunk-ZZTCEMCG.js → chunk-2AK5O3NQ.js} +2 -2
  42. package/chunks/chunk-2I6V7AI3.js +68 -0
  43. package/chunks/chunk-2XWUFFEZ.js +133 -0
  44. package/chunks/{chunk-7GOHWSPA.js → chunk-62OOT7FY.js} +5 -2
  45. package/chunks/{chunk-W2JGSGIQ.js → chunk-7K6I2GUG.js} +15 -9
  46. package/chunks/{chunk-5VZSFLRO.js → chunk-7O5H2SQP.js} +2 -2
  47. package/chunks/{chunk-FJREFWEE.js → chunk-7S34K2P3.js} +1 -1
  48. package/chunks/{chunk-PIWBFJX3.js → chunk-AOZQPCWI.js} +2 -0
  49. package/chunks/{chunk-EBNFCIKS.js → chunk-APX65SRT.js} +2 -1
  50. package/chunks/{chunk-GZA7GEZW.js → chunk-B3XOSR6W.js} +2 -2
  51. package/chunks/{chunk-VJAVNG6U.js → chunk-CSJIKXUD.js} +1 -1
  52. package/chunks/{chunk-MLBEF6MB.js → chunk-DDDYR2HF.js} +1 -1
  53. package/chunks/{chunk-TQL55CUG.js → chunk-EXJUFF6G.js} +1 -1
  54. package/chunks/{chunk-W6FLDNRM.js → chunk-IRA5BW2J.js} +2 -2
  55. package/chunks/chunk-IRQJDPZE.js +34 -0
  56. package/chunks/{chunk-ZK76AK3B.js → chunk-KPLWZIOV.js} +22 -3
  57. package/chunks/chunk-LK2ZIDHH.js +32 -0
  58. package/chunks/{chunk-3DKOVKCV.js → chunk-M2MMGSLK.js} +5 -5
  59. package/chunks/{chunk-FD364GM7.js → chunk-NRHHB3YY.js} +1 -1
  60. package/chunks/{chunk-W3Y5X3X3.js → chunk-OVKTA5CX.js} +12 -5
  61. package/chunks/chunk-PVDORWEM.js +167 -0
  62. package/chunks/chunk-RAJM56L7.js +60 -0
  63. package/chunks/{chunk-UJU2ORWU.js → chunk-RAU5KE6F.js} +1 -1
  64. package/chunks/{chunk-V6LUKXBV.js → chunk-RE5Z56QD.js} +2 -2
  65. package/chunks/chunk-SNQFFEYH.js +11 -0
  66. package/chunks/{chunk-GUF4PKDL.js → chunk-TI4NDKQC.js} +6 -5
  67. package/chunks/{chunk-VRZRTOZF.js → chunk-TKT5UW3G.js} +2 -2
  68. package/chunks/{chunk-A27OERJM.js → chunk-TVPVXL73.js} +7 -7
  69. package/chunks/{chunk-4RF2NKQN.js → chunk-TYNF7ROW.js} +1 -1
  70. package/chunks/{chunk-HDNCXPCZ.js → chunk-VNF2GRZA.js} +2 -2
  71. package/chunks/chunk-WDFZ7WYJ.js +16 -0
  72. package/chunks/{chunk-672Y6REB.js → chunk-WKW5W2ZP.js} +1 -1
  73. package/chunks/chunk-XUX6JXU5.js +58 -0
  74. package/chunks/{chunk-6YOXEMMX.js → chunk-Y2OQOAY7.js} +1 -1
  75. package/chunks/{create.action-UUDVWZ3F.js → create.action-O3HN6GV2.js} +32 -23
  76. package/chunks/{delete.action-XRP3VU5C.js → delete.action-2L2RWLPI.js} +36 -22
  77. package/chunks/{delete.action-EUQ4ESLJ.js → delete.action-KEBI2QCS.js} +38 -22
  78. package/chunks/{get.action-IYA5Q3RI.js → get.action-BUNTDW54.js} +13 -11
  79. package/chunks/{get.action-UHCFOKUQ.js → get.action-WDMTCZZR.js} +14 -14
  80. package/chunks/{list.action-3CCWEEAM.js → list.action-JNSEJVHX.js} +14 -14
  81. package/chunks/{list.action-D3GHA6S5.js → list.action-NSK7OBRH.js} +16 -16
  82. package/chunks/{publish.action-HIVWJ7QE.js → publish.action-ZRZQUL7S.js} +49 -29
  83. package/chunks/{update.action-NSKVEZES.js → update.action-7TA46AE6.js} +36 -22
  84. package/chunks/{update.action-VOZNA7BV.js → update.action-O2R5ODGG.js} +47 -27
  85. package/index.js +226 -149
  86. package/package.json +1 -1
  87. package/skills/scalar-cli/SKILL.md +4 -2
  88. package/template.md +220 -1
  89. package/chunks/action-RNVV27ET.js +0 -165
  90. package/chunks/action-ZHDGAUGG.js +0 -38
  91. package/chunks/chunk-AC62V47N.js +0 -38
  92. package/chunks/chunk-EGOXR5FB.js +0 -15
  93. package/chunks/chunk-JFIXNSPP.js +0 -26
  94. package/chunks/{action-UHXBY3RD.js → action-3P66ZSL3.js} +1 -1
@@ -4,23 +4,24 @@ import {
4
4
  } from "./chunk-KHDYYVYF.js";
5
5
  import {
6
6
  isDocument
7
- } from "./chunk-W2JGSGIQ.js";
7
+ } from "./chunk-7K6I2GUG.js";
8
8
  import {
9
9
  isAsyncApiDocument,
10
10
  safeNormalize
11
- } from "./chunk-672Y6REB.js";
12
- import {
13
- err,
14
- ok
15
- } from "./chunk-5ENKYZA4.js";
11
+ } from "./chunk-WKW5W2ZP.js";
12
+ import "./chunk-2XWUFFEZ.js";
16
13
  import {
17
14
  isYamlFileName
18
15
  } from "./chunk-4ORL4MST.js";
19
- import "./chunk-4RF2NKQN.js";
16
+ import "./chunk-TYNF7ROW.js";
20
17
  import {
21
18
  output
22
19
  } from "./chunk-T5HJUAWB.js";
23
- import "./chunk-PIWBFJX3.js";
20
+ import {
21
+ err,
22
+ ok
23
+ } from "./chunk-5ENKYZA4.js";
24
+ import "./chunk-AOZQPCWI.js";
24
25
  import "./chunk-Q26DFKTY.js";
25
26
  import {
26
27
  external_exports
@@ -2,23 +2,28 @@ import { createRequire as $$cR } from "node:module"; const require = $$cR(import
2
2
  import {
3
3
  getUserTeams
4
4
  } from "./chunk-BDNCJLJP.js";
5
+ import {
6
+ writeJson
7
+ } from "./chunk-SNQFFEYH.js";
5
8
  import {
6
9
  getDatabaseClient
7
- } from "./chunk-W3Y5X3X3.js";
10
+ } from "./chunk-OVKTA5CX.js";
8
11
  import "./chunk-YTTDYTVB.js";
9
- import "./chunk-V6LUKXBV.js";
12
+ import "./chunk-RE5Z56QD.js";
10
13
  import "./chunk-VUXPDHTQ.js";
11
14
  import {
12
15
  getAuthData,
13
16
  refreshToken
14
- } from "./chunk-MLBEF6MB.js";
15
- import "./chunk-VJAVNG6U.js";
16
- import "./chunk-FD364GM7.js";
17
+ } from "./chunk-DDDYR2HF.js";
18
+ import "./chunk-CSJIKXUD.js";
19
+ import "./chunk-NRHHB3YY.js";
17
20
  import "./chunk-F3TQHNSQ.js";
18
21
  import "./chunk-VRZSDUZK.js";
19
22
  import {
20
- requireInteractive
21
- } from "./chunk-EGOXR5FB.js";
23
+ requireInteractive,
24
+ select
25
+ } from "./chunk-XUX6JXU5.js";
26
+ import "./chunk-IRQJDPZE.js";
22
27
  import "./chunk-4ORL4MST.js";
23
28
  import {
24
29
  output
@@ -28,9 +33,11 @@ import "./chunk-I57ID5K7.js";
28
33
  import "./chunk-3MZYUBJ6.js";
29
34
 
30
35
  // src/domains/team/set/action.ts
31
- import { select } from "@clack/prompts";
32
36
  import as from "ansis";
33
- async function setAction({ team }) {
37
+ async function setAction({
38
+ team,
39
+ json
40
+ }) {
34
41
  const auth = await getAuthData();
35
42
  auth.addEventListener((state) => Object.assign(auth, state));
36
43
  if (!("refreshToken" in auth)) {
@@ -45,7 +52,7 @@ async function setAction({ team }) {
45
52
  }
46
53
  let teamValue = team;
47
54
  if (!teamValue) {
48
- requireInteractive("Provide --team with a valid team ID.");
55
+ requireInteractive("Provide --team with a valid team ID.", json);
49
56
  teamValue = await select({
50
57
  message: "Select a team",
51
58
  options: userTeams.data.map((it) => ({
@@ -60,7 +67,15 @@ async function setAction({ team }) {
60
67
  "Provide a valid team ID. Run `scalar team list` to see available teams."
61
68
  ).exit("error");
62
69
  }
63
- await refreshToken(auth.refreshToken, teamValue);
70
+ await refreshToken(auth.refreshToken, selectedTeam.teamUid);
71
+ if (json) {
72
+ writeJson({
73
+ uid: selectedTeam.teamUid,
74
+ name: selectedTeam.teamName,
75
+ current: true
76
+ });
77
+ return;
78
+ }
64
79
  output.info().message(`Current team: ${as.cyan(selectedTeam.teamName)}.`).print();
65
80
  }
66
81
  export {
@@ -0,0 +1,423 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ downloadIsolate
4
+ } from "./chunk-TKT5UW3G.js";
5
+ import "./chunk-ORCUZITN.js";
6
+ import {
7
+ readAndParseConfig,
8
+ renderConfigError
9
+ } from "./chunk-4YQVGOHX.js";
10
+ import {
11
+ CONFIG_FILE_DEFAULT,
12
+ findConfig
13
+ } from "./chunk-MQ65WBVF.js";
14
+ import {
15
+ ISOLATE_DIR
16
+ } from "./chunk-RAU5KE6F.js";
17
+ import "./chunk-RE5Z56QD.js";
18
+ import "./chunk-VUXPDHTQ.js";
19
+ import {
20
+ getAuthData
21
+ } from "./chunk-DDDYR2HF.js";
22
+ import {
23
+ config
24
+ } from "./chunk-CSJIKXUD.js";
25
+ import "./chunk-NRHHB3YY.js";
26
+ import "./chunk-F3TQHNSQ.js";
27
+ import {
28
+ ConfigVersion
29
+ } from "./chunk-VRZSDUZK.js";
30
+ import {
31
+ canPrompt,
32
+ requireInteractive,
33
+ text
34
+ } from "./chunk-XUX6JXU5.js";
35
+ import "./chunk-IRQJDPZE.js";
36
+ import "./chunk-4ORL4MST.js";
37
+ import {
38
+ output
39
+ } from "./chunk-T5HJUAWB.js";
40
+ import "./chunk-5ENKYZA4.js";
41
+ import "./chunk-Q26DFKTY.js";
42
+ import "./chunk-I57ID5K7.js";
43
+ import "./chunk-3MZYUBJ6.js";
44
+
45
+ // src/domains/project/preview/action.ts
46
+ import as from "ansis";
47
+
48
+ // src/domains/project/preview/v2.ts
49
+ import path2 from "node:path";
50
+
51
+ // src/domains/project/preview/run-preview-process.ts
52
+ import { execFile, spawn } from "node:child_process";
53
+ import { constants } from "node:os";
54
+ import path from "node:path";
55
+ import { setTimeout as delay } from "node:timers/promises";
56
+ import { promisify } from "node:util";
57
+
58
+ // src/domains/project/preview/windows-preview-job.ts
59
+ function windowsPreviewJob(executable) {
60
+ const script = `
61
+ $ErrorActionPreference = 'Stop'
62
+ Add-Type -TypeDefinition @'
63
+ using System;
64
+ using System.ComponentModel;
65
+ using System.Runtime.InteropServices;
66
+ using System.Text;
67
+
68
+ public static class ScalarPreviewJob {
69
+ [StructLayout(LayoutKind.Sequential)]
70
+ struct BasicLimits {
71
+ public long PerProcessUserTimeLimit, PerJobUserTimeLimit;
72
+ public uint LimitFlags;
73
+ public UIntPtr MinimumWorkingSetSize, MaximumWorkingSetSize;
74
+ public uint ActiveProcessLimit;
75
+ public UIntPtr Affinity;
76
+ public uint PriorityClass, SchedulingClass;
77
+ }
78
+ [StructLayout(LayoutKind.Sequential)]
79
+ struct IoCounters {
80
+ public ulong ReadOperationCount, WriteOperationCount, OtherOperationCount;
81
+ public ulong ReadTransferCount, WriteTransferCount, OtherTransferCount;
82
+ }
83
+ [StructLayout(LayoutKind.Sequential)]
84
+ struct ExtendedLimits {
85
+ public BasicLimits BasicLimitInformation;
86
+ public IoCounters IoInfo;
87
+ public UIntPtr ProcessMemoryLimit, JobMemoryLimit, PeakProcessMemoryUsed, PeakJobMemoryUsed;
88
+ }
89
+ [StructLayout(LayoutKind.Sequential)]
90
+ struct StartupInfo {
91
+ public uint cb;
92
+ public IntPtr lpReserved, lpDesktop, lpTitle;
93
+ public uint dwX, dwY, dwXSize, dwYSize, dwXCountChars, dwYCountChars, dwFillAttribute, dwFlags;
94
+ public ushort wShowWindow, cbReserved2;
95
+ public IntPtr lpReserved2, hStdInput, hStdOutput, hStdError;
96
+ }
97
+ [StructLayout(LayoutKind.Sequential)]
98
+ struct ProcessInformation {
99
+ public IntPtr Process, Thread;
100
+ public uint ProcessId, ThreadId;
101
+ }
102
+ [DllImport("kernel32.dll", SetLastError = true)]
103
+ static extern IntPtr CreateJobObject(IntPtr attributes, string name);
104
+ [DllImport("kernel32.dll", SetLastError = true)]
105
+ static extern bool SetInformationJobObject(IntPtr job, int infoClass, ref ExtendedLimits limits, uint length);
106
+ [DllImport("kernel32.dll", SetLastError = true)]
107
+ static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
108
+ [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
109
+ static extern bool CreateProcess(string application, StringBuilder command, IntPtr processAttributes,
110
+ IntPtr threadAttributes, bool inheritHandles, uint flags, IntPtr environment, string directory,
111
+ ref StartupInfo startup, out ProcessInformation process);
112
+ [DllImport("kernel32.dll", SetLastError = true)]
113
+ static extern IntPtr OpenProcess(uint access, bool inherit, uint pid);
114
+ [DllImport("kernel32.dll")]
115
+ static extern IntPtr GetStdHandle(int handle);
116
+ [DllImport("kernel32.dll", SetLastError = true)]
117
+ static extern uint ResumeThread(IntPtr thread);
118
+ [DllImport("kernel32.dll", SetLastError = true)]
119
+ static extern uint WaitForSingleObject(IntPtr handle, uint milliseconds);
120
+ [DllImport("kernel32.dll", SetLastError = true)]
121
+ static extern uint WaitForMultipleObjects(uint count, IntPtr[] handles, bool all, uint milliseconds);
122
+ [DllImport("kernel32.dll", SetLastError = true)]
123
+ static extern bool GetExitCodeProcess(IntPtr process, out uint code);
124
+ [DllImport("kernel32.dll")]
125
+ static extern bool TerminateProcess(IntPtr process, uint code);
126
+ [DllImport("kernel32.dll")]
127
+ static extern bool CloseHandle(IntPtr handle);
128
+
129
+ public static int Run(string executable, uint ownerPid) {
130
+ IntPtr owner = OpenProcess(0x00100000, false, ownerPid);
131
+ if (owner == IntPtr.Zero) {
132
+ if (Marshal.GetLastWin32Error() == 87) return 143;
133
+ throw new Win32Exception();
134
+ }
135
+ IntPtr job = IntPtr.Zero;
136
+ ProcessInformation child = new ProcessInformation();
137
+ try {
138
+ uint ownerState = WaitForSingleObject(owner, 0);
139
+ if (ownerState == 0) return 143;
140
+ if (ownerState != 258) throw new Win32Exception();
141
+ job = CreateJobObject(IntPtr.Zero, null);
142
+ if (job == IntPtr.Zero) throw new Win32Exception();
143
+ ExtendedLimits limits = new ExtendedLimits();
144
+ // JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE also covers an abruptly terminated supervisor.
145
+ limits.BasicLimitInformation.LimitFlags = 0x00002000;
146
+ if (!SetInformationJobObject(job, 9, ref limits, (uint)Marshal.SizeOf(limits))) throw new Win32Exception();
147
+ StartupInfo startup = new StartupInfo();
148
+ startup.cb = (uint)Marshal.SizeOf(startup);
149
+ startup.dwFlags = 0x00000100;
150
+ startup.hStdInput = GetStdHandle(-10);
151
+ startup.hStdOutput = GetStdHandle(-11);
152
+ startup.hStdError = GetStdHandle(-12);
153
+ // CREATE_SUSPENDED prevents the isolate from spawning outside the job before assignment.
154
+ if (!CreateProcess(executable, new StringBuilder("\\"" + executable + "\\" dist/isolate-entry.js"),
155
+ IntPtr.Zero, IntPtr.Zero, true, 4, IntPtr.Zero, null, ref startup, out child)) throw new Win32Exception();
156
+ if (!AssignProcessToJobObject(job, child.Process)) throw new Win32Exception();
157
+ if (ResumeThread(child.Thread) == 0xffffffff) throw new Win32Exception();
158
+ uint completed = WaitForMultipleObjects(2, new IntPtr[] { child.Process, owner }, false, 0xffffffff);
159
+ if (completed == 1) return 143;
160
+ if (completed != 0) throw new Win32Exception();
161
+ uint code;
162
+ if (!GetExitCodeProcess(child.Process, out code)) throw new Win32Exception();
163
+ return (int)code;
164
+ } finally {
165
+ // The suspended child may not have been assigned if job setup failed.
166
+ if (child.Process != IntPtr.Zero) TerminateProcess(child.Process, 1);
167
+ if (job != IntPtr.Zero) CloseHandle(job);
168
+ if (child.Thread != IntPtr.Zero) CloseHandle(child.Thread);
169
+ if (child.Process != IntPtr.Zero) CloseHandle(child.Process);
170
+ CloseHandle(owner);
171
+ }
172
+ }
173
+ }
174
+ '@
175
+ exit [ScalarPreviewJob]::Run('${executable.replaceAll("'", "''")}', ${process.pid})
176
+ `;
177
+ return Buffer.from(script, "utf16le").toString("base64");
178
+ }
179
+
180
+ // src/domains/project/preview/run-preview-process.ts
181
+ async function runPreviewProcess({
182
+ executable,
183
+ cwd,
184
+ env,
185
+ input
186
+ }) {
187
+ const processGroup = process.platform !== "win32";
188
+ const powershell = path.join(
189
+ process.env.SystemRoot ?? "C:\\Windows",
190
+ "System32",
191
+ "WindowsPowerShell",
192
+ "v1.0",
193
+ "powershell.exe"
194
+ );
195
+ const languageMode = processGroup ? void 0 : await promisify(execFile)(
196
+ powershell,
197
+ [
198
+ "-NoProfile",
199
+ "-NonInteractive",
200
+ "-Command",
201
+ "$ExecutionContext.SessionState.LanguageMode"
202
+ ],
203
+ { env, windowsHide: true, timeout: 5e3 }
204
+ ).catch(() => void 0);
205
+ const useWindowsJob = !processGroup && languageMode?.stdout.trim() === "FullLanguage";
206
+ if (!processGroup && !useWindowsJob) {
207
+ console.error(
208
+ "Docs preview is starting without Windows job cleanup because PowerShell is unavailable or restricted. Child processes may need to be stopped manually."
209
+ );
210
+ }
211
+ const command = !useWindowsJob ? executable : powershell;
212
+ const args = !useWindowsJob ? ["dist/isolate-entry.js"] : [
213
+ "-NoProfile",
214
+ "-NonInteractive",
215
+ "-EncodedCommand",
216
+ windowsPreviewJob(executable)
217
+ ];
218
+ const child = spawn(command, args, {
219
+ cwd,
220
+ env,
221
+ detached: processGroup,
222
+ windowsHide: true,
223
+ stdio: "pipe"
224
+ });
225
+ const closed = new Promise(
226
+ (resolve) => child.once("close", () => resolve())
227
+ );
228
+ return new Promise((resolve) => {
229
+ let terminationSignal;
230
+ let failed = false;
231
+ let cleaning = false;
232
+ const terminate = (signal) => {
233
+ if (!child.pid) return;
234
+ if (!processGroup) {
235
+ if (child.exitCode === null && child.signalCode === null)
236
+ child.kill("SIGKILL");
237
+ return;
238
+ }
239
+ try {
240
+ process.kill(-child.pid, signal);
241
+ } catch (error) {
242
+ if (error.code !== "ESRCH") {
243
+ failed = true;
244
+ console.error(`Could not stop docs preview: ${String(error)}`);
245
+ }
246
+ }
247
+ };
248
+ const groupExists = () => {
249
+ if (!child.pid || !processGroup) return false;
250
+ try {
251
+ process.kill(-child.pid, 0);
252
+ return true;
253
+ } catch (error) {
254
+ return error.code !== "ESRCH";
255
+ }
256
+ };
257
+ const finish = async (code, signal) => {
258
+ if (cleaning) return;
259
+ cleaning = true;
260
+ terminate(terminationSignal ?? "SIGTERM");
261
+ const deadline = Date.now() + 500;
262
+ while (groupExists() && Date.now() < deadline) await delay(25);
263
+ if (groupExists()) terminate("SIGKILL");
264
+ await Promise.race([closed, delay(500, void 0, { ref: false })]);
265
+ process.off("SIGTERM", onTerm);
266
+ process.off("SIGINT", onInt);
267
+ process.off("SIGHUP", onHup);
268
+ process.off("SIGQUIT", onQuit);
269
+ child.stdin.destroy();
270
+ child.stdout.destroy();
271
+ child.stderr.destroy();
272
+ const finalSignal = terminationSignal ?? signal;
273
+ resolve(
274
+ failed ? 1 : finalSignal ? 128 + constants.signals[finalSignal] : code ?? 1
275
+ );
276
+ };
277
+ const onSignal = (signal) => {
278
+ if (terminationSignal) {
279
+ terminate("SIGKILL");
280
+ return;
281
+ }
282
+ terminationSignal = signal;
283
+ void finish(null, signal);
284
+ };
285
+ const onTerm = () => onSignal("SIGTERM");
286
+ const onInt = () => onSignal("SIGINT");
287
+ const onHup = () => onSignal("SIGHUP");
288
+ const onQuit = () => onSignal("SIGQUIT");
289
+ process.on("SIGTERM", onTerm);
290
+ process.on("SIGINT", onInt);
291
+ if (processGroup) {
292
+ process.on("SIGHUP", onHup);
293
+ process.on("SIGQUIT", onQuit);
294
+ }
295
+ child.on("error", (error) => {
296
+ failed = true;
297
+ console.error(`Could not start docs preview: ${error.message}`);
298
+ void finish(1, null);
299
+ });
300
+ child.on("exit", (code, signal) => {
301
+ console.log(
302
+ `Process exited with code ${code}${signal ? ` (signal ${signal})` : ""}.`
303
+ );
304
+ void finish(code, signal);
305
+ });
306
+ child.stdin.on("error", (error) => {
307
+ if (error.code !== "EPIPE" && error.code !== "ERR_STREAM_DESTROYED") {
308
+ failed = true;
309
+ console.error(`Could not configure docs preview: ${error.message}`);
310
+ void finish(1, null);
311
+ }
312
+ });
313
+ child.stdout.pipe(process.stdout);
314
+ child.stderr.pipe(process.stderr);
315
+ child.stdin.end(input);
316
+ });
317
+ }
318
+
319
+ // src/domains/project/preview/v2.ts
320
+ async function runIsolate(isolateOptions) {
321
+ const executable = process.env.SCALAR_CLI_DISTRIBUTION === "portable" ? path2.join(
322
+ path2.dirname(process.execPath),
323
+ "runtime",
324
+ process.platform === "win32" ? "node.exe" : "node"
325
+ ) : process.execPath;
326
+ process.exitCode = await runPreviewProcess({
327
+ executable,
328
+ cwd: ISOLATE_DIR,
329
+ env: {
330
+ ...process.env,
331
+ PATH: `${path2.dirname(executable)}${path2.delimiter}${process.env.PATH ?? ""}`
332
+ },
333
+ input: JSON.stringify(isolateOptions)
334
+ });
335
+ }
336
+ async function getAccessToken() {
337
+ try {
338
+ const { accessToken } = await getAuthData({ noExit: true });
339
+ return accessToken;
340
+ } catch {
341
+ output.info().message(
342
+ "You're not logged in. Private Scalar content will not be fetched."
343
+ ).print();
344
+ return "";
345
+ }
346
+ }
347
+ async function previewV2Project({
348
+ logLevel,
349
+ configPath,
350
+ port,
351
+ config: config2,
352
+ host,
353
+ openBrowser
354
+ }) {
355
+ const root = path2.resolve(path2.dirname(configPath), config2.root ?? "./");
356
+ const relativeConfigPath = path2.relative(root, configPath);
357
+ const accessToken = await getAccessToken();
358
+ await downloadIsolate();
359
+ output.info().message("Starting preview\u2026").print();
360
+ await runIsolate({
361
+ configPath: relativeConfigPath,
362
+ projectDir: root,
363
+ logLevel,
364
+ domain: "localhost",
365
+ mode: "preview",
366
+ previewServerPort: port,
367
+ registryBaseUrl: config.projects.registry,
368
+ baseUrl: config.services.api,
369
+ token: accessToken,
370
+ host,
371
+ openBrowser
372
+ });
373
+ }
374
+
375
+ // src/domains/project/preview/action.ts
376
+ async function previewAction(__configPath, options) {
377
+ const _port = Number.parseInt(options.port || "7970", 10);
378
+ if (Number.isNaN(_port)) {
379
+ return output.error().title("Invalid port").message("Provide a valid port number").exit("error");
380
+ }
381
+ if (_port < 0 || _port > 65535) {
382
+ return output.error().title("Invalid port").message("Port number must be between 0 and 65535").exit("error");
383
+ }
384
+ let configPath = __configPath || findConfig();
385
+ if (!configPath) {
386
+ requireInteractive(
387
+ "Pass the path to your Scalar configuration file to preview non-interactively."
388
+ );
389
+ const response = await text({
390
+ message: "Where is your configuration file located?",
391
+ defaultValue: CONFIG_FILE_DEFAULT,
392
+ placeholder: CONFIG_FILE_DEFAULT
393
+ });
394
+ configPath = response;
395
+ }
396
+ const parseConfigResult = readAndParseConfig(configPath);
397
+ if (!parseConfigResult.success) {
398
+ renderConfigError(parseConfigResult.error);
399
+ }
400
+ if (parseConfigResult.success) {
401
+ output.info().line(
402
+ `${as.green("[SUCCESS]")} ${as.green("Configuration is valid:")} ${as.green(parseConfigResult.filePath)}`
403
+ ).print();
404
+ }
405
+ const { config: config2 } = parseConfigResult;
406
+ if (config2.version === ConfigVersion.V1) {
407
+ return output.error().title("Version 1 previews are no longer supported").message("Run `scalar project upgrade` to upgrade your project.").exit("error");
408
+ }
409
+ if (config2.version === ConfigVersion.V2) {
410
+ await previewV2Project({
411
+ logLevel: options.logLevel,
412
+ configPath: parseConfigResult.filePath,
413
+ config: config2,
414
+ port: _port,
415
+ host: options.host,
416
+ openBrowser: (options.open ?? true) && Boolean(canPrompt()) && !process.env.CI
417
+ });
418
+ return;
419
+ }
420
+ }
421
+ export {
422
+ previewAction
423
+ };
@@ -8,41 +8,41 @@ import {
8
8
  import "./chunk-AEFPCC4U.js";
9
9
  import {
10
10
  getPublishUrl
11
- } from "./chunk-7GOHWSPA.js";
11
+ } from "./chunk-62OOT7FY.js";
12
12
  import {
13
13
  BaseCollections
14
- } from "./chunk-GUF4PKDL.js";
14
+ } from "./chunk-TI4NDKQC.js";
15
15
  import {
16
16
  getDatabaseClient
17
- } from "./chunk-W3Y5X3X3.js";
17
+ } from "./chunk-OVKTA5CX.js";
18
18
  import {
19
19
  apiService
20
- } from "./chunk-A27OERJM.js";
21
- import "./chunk-ZZTCEMCG.js";
22
- import "./chunk-ZK76AK3B.js";
20
+ } from "./chunk-TVPVXL73.js";
21
+ import "./chunk-2AK5O3NQ.js";
22
+ import "./chunk-KPLWZIOV.js";
23
23
  import "./chunk-YTTDYTVB.js";
24
- import "./chunk-6YOXEMMX.js";
25
- import "./chunk-5ENKYZA4.js";
26
- import "./chunk-W6FLDNRM.js";
27
- import "./chunk-TQL55CUG.js";
28
- import "./chunk-V6LUKXBV.js";
24
+ import "./chunk-Y2OQOAY7.js";
25
+ import "./chunk-IRA5BW2J.js";
26
+ import "./chunk-EXJUFF6G.js";
27
+ import "./chunk-RE5Z56QD.js";
29
28
  import "./chunk-VUXPDHTQ.js";
30
29
  import {
31
30
  getAuthData
32
- } from "./chunk-MLBEF6MB.js";
33
- import "./chunk-VJAVNG6U.js";
34
- import "./chunk-FD364GM7.js";
31
+ } from "./chunk-DDDYR2HF.js";
32
+ import "./chunk-CSJIKXUD.js";
33
+ import "./chunk-NRHHB3YY.js";
35
34
  import "./chunk-F3TQHNSQ.js";
36
35
  import {
37
36
  publishRecordSchema
38
37
  } from "./chunk-VRZSDUZK.js";
39
38
  import "./chunk-4ORL4MST.js";
40
- import "./chunk-4RF2NKQN.js";
39
+ import "./chunk-TYNF7ROW.js";
41
40
  import {
42
41
  output,
43
42
  printTable
44
43
  } from "./chunk-T5HJUAWB.js";
45
- import "./chunk-PIWBFJX3.js";
44
+ import "./chunk-5ENKYZA4.js";
45
+ import "./chunk-AOZQPCWI.js";
46
46
  import "./chunk-Q26DFKTY.js";
47
47
  import "./chunk-I57ID5K7.js";
48
48
  import "./chunk-3MZYUBJ6.js";
@@ -10,24 +10,24 @@ import {
10
10
  } from "./chunk-AEFPCC4U.js";
11
11
  import {
12
12
  apiService
13
- } from "./chunk-A27OERJM.js";
14
- import "./chunk-ZZTCEMCG.js";
15
- import "./chunk-ZK76AK3B.js";
13
+ } from "./chunk-TVPVXL73.js";
14
+ import "./chunk-2AK5O3NQ.js";
15
+ import "./chunk-KPLWZIOV.js";
16
16
  import "./chunk-YTTDYTVB.js";
17
- import "./chunk-6YOXEMMX.js";
18
- import "./chunk-5ENKYZA4.js";
19
- import "./chunk-W6FLDNRM.js";
20
- import "./chunk-TQL55CUG.js";
21
- import "./chunk-MLBEF6MB.js";
22
- import "./chunk-VJAVNG6U.js";
23
- import "./chunk-FD364GM7.js";
17
+ import "./chunk-Y2OQOAY7.js";
18
+ import "./chunk-IRA5BW2J.js";
19
+ import "./chunk-EXJUFF6G.js";
20
+ import "./chunk-DDDYR2HF.js";
21
+ import "./chunk-CSJIKXUD.js";
22
+ import "./chunk-NRHHB3YY.js";
24
23
  import "./chunk-F3TQHNSQ.js";
25
24
  import "./chunk-VRZSDUZK.js";
26
- import "./chunk-4RF2NKQN.js";
25
+ import "./chunk-TYNF7ROW.js";
27
26
  import {
28
27
  output
29
28
  } from "./chunk-T5HJUAWB.js";
30
- import "./chunk-PIWBFJX3.js";
29
+ import "./chunk-5ENKYZA4.js";
30
+ import "./chunk-AOZQPCWI.js";
31
31
  import "./chunk-Q26DFKTY.js";
32
32
  import {
33
33
  slugSchema
@@ -0,0 +1,48 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ writeJson
4
+ } from "./chunk-SNQFFEYH.js";
5
+ import {
6
+ apiService
7
+ } from "./chunk-TVPVXL73.js";
8
+ import "./chunk-2AK5O3NQ.js";
9
+ import "./chunk-KPLWZIOV.js";
10
+ import "./chunk-YTTDYTVB.js";
11
+ import "./chunk-Y2OQOAY7.js";
12
+ import "./chunk-IRA5BW2J.js";
13
+ import "./chunk-EXJUFF6G.js";
14
+ import "./chunk-DDDYR2HF.js";
15
+ import "./chunk-CSJIKXUD.js";
16
+ import "./chunk-NRHHB3YY.js";
17
+ import "./chunk-F3TQHNSQ.js";
18
+ import "./chunk-VRZSDUZK.js";
19
+ import "./chunk-TYNF7ROW.js";
20
+ import {
21
+ output
22
+ } from "./chunk-T5HJUAWB.js";
23
+ import "./chunk-5ENKYZA4.js";
24
+ import "./chunk-AOZQPCWI.js";
25
+ import "./chunk-Q26DFKTY.js";
26
+ import "./chunk-I57ID5K7.js";
27
+ import "./chunk-3MZYUBJ6.js";
28
+
29
+ // src/domains/registry/delete/action.ts
30
+ async function deleteAction(namespace, slug, args = {}) {
31
+ if (!namespace || !slug) {
32
+ return output.error().title("Invalid input").message("Provide the team namespace and API description slug.").exit("error");
33
+ }
34
+ const client = await apiService();
35
+ const logger = args.json ? void 0 : output.info().line().loader("Deleting the API description\u2026");
36
+ const deleteDocument = await client.managedDocs.delete(namespace, slug);
37
+ if (deleteDocument.error) {
38
+ return output.error().title(deleteDocument.message).exit("error");
39
+ }
40
+ if (args.json) {
41
+ writeJson({ namespace, slug, deleted: true });
42
+ return;
43
+ }
44
+ logger?.update("loader", 0, { content: "API description deleted." }).print();
45
+ }
46
+ export {
47
+ deleteAction
48
+ };