@scalar/cli 2.12.1 → 2.12.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/README.md +2 -0
- package/chunks/{action-JT6C472I.js → action-4ESHWOAM.js} +4 -4
- package/chunks/{action-7HXYZPOT.js → action-5BJL72JE.js} +4 -4
- package/chunks/{action-UTFRCKGE.js → action-6A4NM5WS.js} +4 -4
- package/chunks/{action-KWFAMQN5.js → action-6I2PWENU.js} +19 -19
- package/chunks/{action-D52JJ3NL.js → action-7CUPRYNA.js} +13 -13
- package/chunks/{action-6IHAGCNR.js → action-AYKKHH7A.js} +13 -13
- package/chunks/{action-AOKHLTZ6.js → action-B74PPGKB.js} +5 -5
- package/chunks/{action-NY2MGVBS.js → action-BDDXF4YV.js} +13 -13
- package/chunks/{action-T2I4TFLU.js → action-BYYKW4S6.js} +8 -8
- package/chunks/action-D7L757PX.js +422 -0
- package/chunks/{action-HJSRU322.js → action-ED4TSPRZ.js} +13 -13
- package/chunks/{action-IASJWF5P.js → action-EPGS3U3T.js} +14 -14
- package/chunks/{action-D3IVCY24.js → action-EWDQOX5B.js} +4 -4
- package/chunks/{action-TH3TYR2A.js → action-EWZLVN45.js} +21 -21
- package/chunks/{action-A2GXYB2K.js → action-FBOTIFVC.js} +10 -10
- package/chunks/{action-YL3CEKE7.js → action-FBQAU5LV.js} +13 -13
- package/chunks/{action-4G23NFVD.js → action-GJHOZ6Q5.js} +66 -46
- package/chunks/{action-GZKDPO3N.js → action-GMJJMZXY.js} +13 -13
- package/chunks/{action-XPJFCCAT.js → action-H4GW3KAI.js} +17 -17
- package/chunks/{action-6IZYBY5P.js → action-HAKFAXTQ.js} +4 -4
- package/chunks/{action-4B3MNNEG.js → action-I2IV4VLL.js} +18 -18
- package/chunks/{action-6UOTMYQ4.js → action-JXCU2JKC.js} +2 -2
- package/chunks/{action-KDT6H6ML.js → action-KIOYSVKX.js} +4 -4
- package/chunks/{action-IIQMZVRJ.js → action-LRR52RXL.js} +10 -8
- package/chunks/{action-INB2R2NQ.js → action-M5OUEDV2.js} +4 -4
- package/chunks/{action-AQ7BSPBE.js → action-O7ROX6NF.js} +89 -51
- package/chunks/{action-JHPUNA7Z.js → action-Q3DI54OW.js} +17 -17
- package/chunks/{action-6KP6KOYC.js → action-RPTLQBMK.js} +6 -6
- package/chunks/{action-RDXVIAS3.js → action-T4MM4OUS.js} +19 -19
- package/chunks/{action-S7SONQ5E.js → action-UHXBY3RD.js} +2 -2
- package/chunks/{action-ENZGEP4Y.js → action-VVKMUOKR.js} +8 -6
- package/chunks/{action-O757TFA2.js → action-YXRCGKCK.js} +4 -4
- package/chunks/{action-HA3CMV3P.js → action-ZBEOLJJR.js} +4 -4
- package/chunks/{action-5I763IT2.js → action-ZOYQBWGD.js} +16 -16
- package/chunks/{actions-LNIEIP7C.js → actions-EXQNVV4T.js} +13 -13
- package/chunks/{agent-F2A4UROF.js → agent-XAHNA4MB.js} +4 -4
- package/chunks/{asyncapi-HASQNFWS.js → asyncapi-FNOWXSKB.js} +51 -43
- package/chunks/{build.action-XKJ4ET3G.js → build.action-TIKRZPQ5.js} +17 -17
- package/chunks/{chunk-N645RGAB.js → chunk-2AK5O3NQ.js} +33 -33
- package/chunks/{chunk-LWIAFTKX.js → chunk-2GKXAGSH.js} +55 -10
- package/chunks/chunk-2I6V7AI3.js +68 -0
- package/chunks/{chunk-CFI5GBAK.js → chunk-4YQVGOHX.js} +1 -1
- package/chunks/{chunk-ZW62VYJW.js → chunk-62OOT7FY.js} +5 -5
- package/chunks/{chunk-KWLAZV7P.js → chunk-7S34K2P3.js} +1 -1
- package/chunks/{chunk-U764PQUA.js → chunk-AOZQPCWI.js} +2 -0
- package/chunks/{chunk-BHWUD65X.js → chunk-BDNCJLJP.js} +1 -1
- package/chunks/{chunk-WZJTV4ET.js → chunk-BOPEAS7H.js} +1 -1
- package/chunks/{chunk-D5YZ3FXG.js → chunk-CUHVXHIV.js} +1 -1
- package/chunks/{chunk-PU5UIHAF.js → chunk-EUFK4MVX.js} +2 -2
- package/chunks/{chunk-V3MYP5SQ.js → chunk-EXJUFF6G.js} +13 -2
- package/chunks/{chunk-7M44FQHX.js → chunk-F3TQHNSQ.js} +139 -95
- package/chunks/{chunk-NTRWXCXD.js → chunk-FI7UKPRF.js} +2 -2
- package/chunks/{chunk-LLZDQXYS.js → chunk-FYMDIB7J.js} +1 -1
- package/chunks/{chunk-SNOAL2C5.js → chunk-I7ZVWF57.js} +1 -1
- package/chunks/{chunk-DKZ3PS3X.js → chunk-IOW726L2.js} +1 -1
- package/chunks/{chunk-7TSQ7ZGU.js → chunk-IRA5BW2J.js} +7 -5
- package/chunks/{chunk-4BE7UCJO.js → chunk-JWNWOK2M.js} +2 -2
- package/chunks/{chunk-JLNHOA5Z.js → chunk-KPLWZIOV.js} +36 -4
- package/chunks/{chunk-EJSGWV2K.js → chunk-KWIY2QZY.js} +1 -1
- package/chunks/{chunk-GPQXLA43.js → chunk-LEECPQZN.js} +2 -2
- package/chunks/{chunk-YLZP3W37.js → chunk-MQ65WBVF.js} +22 -1
- package/chunks/{chunk-IZVRYC2N.js → chunk-OZQPMMTA.js} +3 -3
- package/chunks/{chunk-V6LUKXBV.js → chunk-RE5Z56QD.js} +2 -2
- package/chunks/{chunk-XLZEIIPW.js → chunk-TI4NDKQC.js} +40 -7
- package/chunks/{chunk-VUNOOPEG.js → chunk-TYNF7ROW.js} +1 -1
- package/chunks/{chunk-YMRRFDEQ.js → chunk-UN2AAVO5.js} +2 -2
- package/chunks/chunk-V7RTDFHK.js +56 -0
- package/chunks/{chunk-PERC34BV.js → chunk-WKW5W2ZP.js} +1 -1
- package/chunks/{chunk-RYWXF3LO.js → chunk-Y2OQOAY7.js} +1 -1
- package/chunks/{chunk-E57QCEAV.js → chunk-YTTDYTVB.js} +1 -1
- package/chunks/{create.action-XXOLILUS.js → create.action-K7GTWYST.js} +17 -17
- package/chunks/{delete.action-R5KGPLDG.js → delete.action-E4XRGKQW.js} +16 -16
- package/chunks/{delete.action-TQJOZRV7.js → delete.action-JKLXBYRD.js} +17 -17
- package/chunks/{get.action-IQMOL4WM.js → get.action-2AKMD4W3.js} +10 -10
- package/chunks/{get.action-46OBVOQQ.js → get.action-IY7WSJMX.js} +16 -16
- package/chunks/{list.action-RIS7Q4OU.js → list.action-44YVCWKN.js} +16 -16
- package/chunks/{list.action-GXTKKVHY.js → list.action-NRL2DDL5.js} +17 -17
- package/chunks/{publish.action-A4T4BT3F.js → publish.action-E76MHLCN.js} +21 -21
- package/chunks/{update.action-TK5L4PXB.js → update.action-FTTVWVAB.js} +16 -16
- package/chunks/{update.action-IZ5GULPY.js → update.action-LZCAHAWW.js} +17 -17
- package/index.js +223 -117
- package/package.json +1 -1
- package/skills/scalar-cli/SKILL.md +1 -1
- package/template.md +2 -0
- package/chunks/action-VK5HZHSC.js +0 -165
- package/chunks/chunk-JFIXNSPP.js +0 -26
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
downloadIsolate
|
|
4
|
+
} from "./chunk-EUFK4MVX.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-CUHVXHIV.js";
|
|
17
|
+
import "./chunk-5ENKYZA4.js";
|
|
18
|
+
import "./chunk-RE5Z56QD.js";
|
|
19
|
+
import "./chunk-VUXPDHTQ.js";
|
|
20
|
+
import {
|
|
21
|
+
getAuthData
|
|
22
|
+
} from "./chunk-FI7UKPRF.js";
|
|
23
|
+
import {
|
|
24
|
+
config
|
|
25
|
+
} from "./chunk-FYMDIB7J.js";
|
|
26
|
+
import "./chunk-IOW726L2.js";
|
|
27
|
+
import "./chunk-F3TQHNSQ.js";
|
|
28
|
+
import {
|
|
29
|
+
ConfigVersion
|
|
30
|
+
} from "./chunk-VRZSDUZK.js";
|
|
31
|
+
import {
|
|
32
|
+
requireInteractive
|
|
33
|
+
} from "./chunk-EGOXR5FB.js";
|
|
34
|
+
import "./chunk-4ORL4MST.js";
|
|
35
|
+
import {
|
|
36
|
+
output
|
|
37
|
+
} from "./chunk-T5HJUAWB.js";
|
|
38
|
+
import "./chunk-Q26DFKTY.js";
|
|
39
|
+
import "./chunk-I57ID5K7.js";
|
|
40
|
+
import "./chunk-3MZYUBJ6.js";
|
|
41
|
+
|
|
42
|
+
// src/domains/project/preview/action.ts
|
|
43
|
+
import { isCancel, text } from "@clack/prompts";
|
|
44
|
+
import as from "ansis";
|
|
45
|
+
|
|
46
|
+
// src/domains/project/preview/v2.ts
|
|
47
|
+
import path2 from "node:path";
|
|
48
|
+
|
|
49
|
+
// src/domains/project/preview/run-preview-process.ts
|
|
50
|
+
import { execFile, spawn } from "node:child_process";
|
|
51
|
+
import { constants } from "node:os";
|
|
52
|
+
import path from "node:path";
|
|
53
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
54
|
+
import { promisify } from "node:util";
|
|
55
|
+
|
|
56
|
+
// src/domains/project/preview/windows-preview-job.ts
|
|
57
|
+
function windowsPreviewJob(executable) {
|
|
58
|
+
const script = `
|
|
59
|
+
$ErrorActionPreference = 'Stop'
|
|
60
|
+
Add-Type -TypeDefinition @'
|
|
61
|
+
using System;
|
|
62
|
+
using System.ComponentModel;
|
|
63
|
+
using System.Runtime.InteropServices;
|
|
64
|
+
using System.Text;
|
|
65
|
+
|
|
66
|
+
public static class ScalarPreviewJob {
|
|
67
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
68
|
+
struct BasicLimits {
|
|
69
|
+
public long PerProcessUserTimeLimit, PerJobUserTimeLimit;
|
|
70
|
+
public uint LimitFlags;
|
|
71
|
+
public UIntPtr MinimumWorkingSetSize, MaximumWorkingSetSize;
|
|
72
|
+
public uint ActiveProcessLimit;
|
|
73
|
+
public UIntPtr Affinity;
|
|
74
|
+
public uint PriorityClass, SchedulingClass;
|
|
75
|
+
}
|
|
76
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
77
|
+
struct IoCounters {
|
|
78
|
+
public ulong ReadOperationCount, WriteOperationCount, OtherOperationCount;
|
|
79
|
+
public ulong ReadTransferCount, WriteTransferCount, OtherTransferCount;
|
|
80
|
+
}
|
|
81
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
82
|
+
struct ExtendedLimits {
|
|
83
|
+
public BasicLimits BasicLimitInformation;
|
|
84
|
+
public IoCounters IoInfo;
|
|
85
|
+
public UIntPtr ProcessMemoryLimit, JobMemoryLimit, PeakProcessMemoryUsed, PeakJobMemoryUsed;
|
|
86
|
+
}
|
|
87
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
88
|
+
struct StartupInfo {
|
|
89
|
+
public uint cb;
|
|
90
|
+
public IntPtr lpReserved, lpDesktop, lpTitle;
|
|
91
|
+
public uint dwX, dwY, dwXSize, dwYSize, dwXCountChars, dwYCountChars, dwFillAttribute, dwFlags;
|
|
92
|
+
public ushort wShowWindow, cbReserved2;
|
|
93
|
+
public IntPtr lpReserved2, hStdInput, hStdOutput, hStdError;
|
|
94
|
+
}
|
|
95
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
96
|
+
struct ProcessInformation {
|
|
97
|
+
public IntPtr Process, Thread;
|
|
98
|
+
public uint ProcessId, ThreadId;
|
|
99
|
+
}
|
|
100
|
+
[DllImport("kernel32.dll", SetLastError = true)]
|
|
101
|
+
static extern IntPtr CreateJobObject(IntPtr attributes, string name);
|
|
102
|
+
[DllImport("kernel32.dll", SetLastError = true)]
|
|
103
|
+
static extern bool SetInformationJobObject(IntPtr job, int infoClass, ref ExtendedLimits limits, uint length);
|
|
104
|
+
[DllImport("kernel32.dll", SetLastError = true)]
|
|
105
|
+
static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
|
|
106
|
+
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
107
|
+
static extern bool CreateProcess(string application, StringBuilder command, IntPtr processAttributes,
|
|
108
|
+
IntPtr threadAttributes, bool inheritHandles, uint flags, IntPtr environment, string directory,
|
|
109
|
+
ref StartupInfo startup, out ProcessInformation process);
|
|
110
|
+
[DllImport("kernel32.dll", SetLastError = true)]
|
|
111
|
+
static extern IntPtr OpenProcess(uint access, bool inherit, uint pid);
|
|
112
|
+
[DllImport("kernel32.dll")]
|
|
113
|
+
static extern IntPtr GetStdHandle(int handle);
|
|
114
|
+
[DllImport("kernel32.dll", SetLastError = true)]
|
|
115
|
+
static extern uint ResumeThread(IntPtr thread);
|
|
116
|
+
[DllImport("kernel32.dll", SetLastError = true)]
|
|
117
|
+
static extern uint WaitForSingleObject(IntPtr handle, uint milliseconds);
|
|
118
|
+
[DllImport("kernel32.dll", SetLastError = true)]
|
|
119
|
+
static extern uint WaitForMultipleObjects(uint count, IntPtr[] handles, bool all, uint milliseconds);
|
|
120
|
+
[DllImport("kernel32.dll", SetLastError = true)]
|
|
121
|
+
static extern bool GetExitCodeProcess(IntPtr process, out uint code);
|
|
122
|
+
[DllImport("kernel32.dll")]
|
|
123
|
+
static extern bool TerminateProcess(IntPtr process, uint code);
|
|
124
|
+
[DllImport("kernel32.dll")]
|
|
125
|
+
static extern bool CloseHandle(IntPtr handle);
|
|
126
|
+
|
|
127
|
+
public static int Run(string executable, uint ownerPid) {
|
|
128
|
+
IntPtr owner = OpenProcess(0x00100000, false, ownerPid);
|
|
129
|
+
if (owner == IntPtr.Zero) {
|
|
130
|
+
if (Marshal.GetLastWin32Error() == 87) return 143;
|
|
131
|
+
throw new Win32Exception();
|
|
132
|
+
}
|
|
133
|
+
IntPtr job = IntPtr.Zero;
|
|
134
|
+
ProcessInformation child = new ProcessInformation();
|
|
135
|
+
try {
|
|
136
|
+
uint ownerState = WaitForSingleObject(owner, 0);
|
|
137
|
+
if (ownerState == 0) return 143;
|
|
138
|
+
if (ownerState != 258) throw new Win32Exception();
|
|
139
|
+
job = CreateJobObject(IntPtr.Zero, null);
|
|
140
|
+
if (job == IntPtr.Zero) throw new Win32Exception();
|
|
141
|
+
ExtendedLimits limits = new ExtendedLimits();
|
|
142
|
+
// JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE also covers an abruptly terminated supervisor.
|
|
143
|
+
limits.BasicLimitInformation.LimitFlags = 0x00002000;
|
|
144
|
+
if (!SetInformationJobObject(job, 9, ref limits, (uint)Marshal.SizeOf(limits))) throw new Win32Exception();
|
|
145
|
+
StartupInfo startup = new StartupInfo();
|
|
146
|
+
startup.cb = (uint)Marshal.SizeOf(startup);
|
|
147
|
+
startup.dwFlags = 0x00000100;
|
|
148
|
+
startup.hStdInput = GetStdHandle(-10);
|
|
149
|
+
startup.hStdOutput = GetStdHandle(-11);
|
|
150
|
+
startup.hStdError = GetStdHandle(-12);
|
|
151
|
+
// CREATE_SUSPENDED prevents the isolate from spawning outside the job before assignment.
|
|
152
|
+
if (!CreateProcess(executable, new StringBuilder("\\"" + executable + "\\" dist/isolate-entry.js"),
|
|
153
|
+
IntPtr.Zero, IntPtr.Zero, true, 4, IntPtr.Zero, null, ref startup, out child)) throw new Win32Exception();
|
|
154
|
+
if (!AssignProcessToJobObject(job, child.Process)) throw new Win32Exception();
|
|
155
|
+
if (ResumeThread(child.Thread) == 0xffffffff) throw new Win32Exception();
|
|
156
|
+
uint completed = WaitForMultipleObjects(2, new IntPtr[] { child.Process, owner }, false, 0xffffffff);
|
|
157
|
+
if (completed == 1) return 143;
|
|
158
|
+
if (completed != 0) throw new Win32Exception();
|
|
159
|
+
uint code;
|
|
160
|
+
if (!GetExitCodeProcess(child.Process, out code)) throw new Win32Exception();
|
|
161
|
+
return (int)code;
|
|
162
|
+
} finally {
|
|
163
|
+
// The suspended child may not have been assigned if job setup failed.
|
|
164
|
+
if (child.Process != IntPtr.Zero) TerminateProcess(child.Process, 1);
|
|
165
|
+
if (job != IntPtr.Zero) CloseHandle(job);
|
|
166
|
+
if (child.Thread != IntPtr.Zero) CloseHandle(child.Thread);
|
|
167
|
+
if (child.Process != IntPtr.Zero) CloseHandle(child.Process);
|
|
168
|
+
CloseHandle(owner);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
'@
|
|
173
|
+
exit [ScalarPreviewJob]::Run('${executable.replaceAll("'", "''")}', ${process.pid})
|
|
174
|
+
`;
|
|
175
|
+
return Buffer.from(script, "utf16le").toString("base64");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// src/domains/project/preview/run-preview-process.ts
|
|
179
|
+
async function runPreviewProcess({
|
|
180
|
+
executable,
|
|
181
|
+
cwd,
|
|
182
|
+
env,
|
|
183
|
+
input
|
|
184
|
+
}) {
|
|
185
|
+
const processGroup = process.platform !== "win32";
|
|
186
|
+
const powershell = path.join(
|
|
187
|
+
process.env.SystemRoot ?? "C:\\Windows",
|
|
188
|
+
"System32",
|
|
189
|
+
"WindowsPowerShell",
|
|
190
|
+
"v1.0",
|
|
191
|
+
"powershell.exe"
|
|
192
|
+
);
|
|
193
|
+
const languageMode = processGroup ? void 0 : await promisify(execFile)(
|
|
194
|
+
powershell,
|
|
195
|
+
[
|
|
196
|
+
"-NoProfile",
|
|
197
|
+
"-NonInteractive",
|
|
198
|
+
"-Command",
|
|
199
|
+
"$ExecutionContext.SessionState.LanguageMode"
|
|
200
|
+
],
|
|
201
|
+
{ env, windowsHide: true, timeout: 5e3 }
|
|
202
|
+
).catch(() => void 0);
|
|
203
|
+
const useWindowsJob = !processGroup && languageMode?.stdout.trim() === "FullLanguage";
|
|
204
|
+
if (!processGroup && !useWindowsJob) {
|
|
205
|
+
console.error(
|
|
206
|
+
"Docs preview is starting without Windows job cleanup because PowerShell is unavailable or restricted. Child processes may need to be stopped manually."
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
const command = !useWindowsJob ? executable : powershell;
|
|
210
|
+
const args = !useWindowsJob ? ["dist/isolate-entry.js"] : [
|
|
211
|
+
"-NoProfile",
|
|
212
|
+
"-NonInteractive",
|
|
213
|
+
"-EncodedCommand",
|
|
214
|
+
windowsPreviewJob(executable)
|
|
215
|
+
];
|
|
216
|
+
const child = spawn(command, args, {
|
|
217
|
+
cwd,
|
|
218
|
+
env,
|
|
219
|
+
detached: processGroup,
|
|
220
|
+
windowsHide: true,
|
|
221
|
+
stdio: "pipe"
|
|
222
|
+
});
|
|
223
|
+
const closed = new Promise(
|
|
224
|
+
(resolve) => child.once("close", () => resolve())
|
|
225
|
+
);
|
|
226
|
+
return new Promise((resolve) => {
|
|
227
|
+
let terminationSignal;
|
|
228
|
+
let failed = false;
|
|
229
|
+
let cleaning = false;
|
|
230
|
+
const terminate = (signal) => {
|
|
231
|
+
if (!child.pid) return;
|
|
232
|
+
if (!processGroup) {
|
|
233
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
234
|
+
child.kill("SIGKILL");
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
process.kill(-child.pid, signal);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
if (error.code !== "ESRCH") {
|
|
241
|
+
failed = true;
|
|
242
|
+
console.error(`Could not stop docs preview: ${String(error)}`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
const groupExists = () => {
|
|
247
|
+
if (!child.pid || !processGroup) return false;
|
|
248
|
+
try {
|
|
249
|
+
process.kill(-child.pid, 0);
|
|
250
|
+
return true;
|
|
251
|
+
} catch (error) {
|
|
252
|
+
return error.code !== "ESRCH";
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
const finish = async (code, signal) => {
|
|
256
|
+
if (cleaning) return;
|
|
257
|
+
cleaning = true;
|
|
258
|
+
terminate(terminationSignal ?? "SIGTERM");
|
|
259
|
+
const deadline = Date.now() + 500;
|
|
260
|
+
while (groupExists() && Date.now() < deadline) await delay(25);
|
|
261
|
+
if (groupExists()) terminate("SIGKILL");
|
|
262
|
+
await Promise.race([closed, delay(500, void 0, { ref: false })]);
|
|
263
|
+
process.off("SIGTERM", onTerm);
|
|
264
|
+
process.off("SIGINT", onInt);
|
|
265
|
+
process.off("SIGHUP", onHup);
|
|
266
|
+
process.off("SIGQUIT", onQuit);
|
|
267
|
+
child.stdin.destroy();
|
|
268
|
+
child.stdout.destroy();
|
|
269
|
+
child.stderr.destroy();
|
|
270
|
+
const finalSignal = terminationSignal ?? signal;
|
|
271
|
+
resolve(
|
|
272
|
+
failed ? 1 : finalSignal ? 128 + constants.signals[finalSignal] : code ?? 1
|
|
273
|
+
);
|
|
274
|
+
};
|
|
275
|
+
const onSignal = (signal) => {
|
|
276
|
+
if (terminationSignal) {
|
|
277
|
+
terminate("SIGKILL");
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
terminationSignal = signal;
|
|
281
|
+
void finish(null, signal);
|
|
282
|
+
};
|
|
283
|
+
const onTerm = () => onSignal("SIGTERM");
|
|
284
|
+
const onInt = () => onSignal("SIGINT");
|
|
285
|
+
const onHup = () => onSignal("SIGHUP");
|
|
286
|
+
const onQuit = () => onSignal("SIGQUIT");
|
|
287
|
+
process.on("SIGTERM", onTerm);
|
|
288
|
+
process.on("SIGINT", onInt);
|
|
289
|
+
if (processGroup) {
|
|
290
|
+
process.on("SIGHUP", onHup);
|
|
291
|
+
process.on("SIGQUIT", onQuit);
|
|
292
|
+
}
|
|
293
|
+
child.on("error", (error) => {
|
|
294
|
+
failed = true;
|
|
295
|
+
console.error(`Could not start docs preview: ${error.message}`);
|
|
296
|
+
void finish(1, null);
|
|
297
|
+
});
|
|
298
|
+
child.on("exit", (code, signal) => {
|
|
299
|
+
console.log(
|
|
300
|
+
`Process exited with code ${code}${signal ? ` (signal ${signal})` : ""}.`
|
|
301
|
+
);
|
|
302
|
+
void finish(code, signal);
|
|
303
|
+
});
|
|
304
|
+
child.stdin.on("error", (error) => {
|
|
305
|
+
if (error.code !== "EPIPE" && error.code !== "ERR_STREAM_DESTROYED") {
|
|
306
|
+
failed = true;
|
|
307
|
+
console.error(`Could not configure docs preview: ${error.message}`);
|
|
308
|
+
void finish(1, null);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
child.stdout.pipe(process.stdout);
|
|
312
|
+
child.stderr.pipe(process.stderr);
|
|
313
|
+
child.stdin.end(input);
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/domains/project/preview/v2.ts
|
|
318
|
+
async function runIsolate(isolateOptions) {
|
|
319
|
+
const executable = process.env.SCALAR_CLI_DISTRIBUTION === "portable" ? path2.join(
|
|
320
|
+
path2.dirname(process.execPath),
|
|
321
|
+
"runtime",
|
|
322
|
+
process.platform === "win32" ? "node.exe" : "node"
|
|
323
|
+
) : process.execPath;
|
|
324
|
+
process.exitCode = await runPreviewProcess({
|
|
325
|
+
executable,
|
|
326
|
+
cwd: ISOLATE_DIR,
|
|
327
|
+
env: {
|
|
328
|
+
...process.env,
|
|
329
|
+
PATH: `${path2.dirname(executable)}${path2.delimiter}${process.env.PATH ?? ""}`
|
|
330
|
+
},
|
|
331
|
+
input: JSON.stringify(isolateOptions)
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
async function getAccessToken() {
|
|
335
|
+
try {
|
|
336
|
+
const { accessToken } = await getAuthData({ noExit: true });
|
|
337
|
+
return accessToken;
|
|
338
|
+
} catch {
|
|
339
|
+
output.info().message(
|
|
340
|
+
"You're not logged in. Private Scalar content will not be fetched."
|
|
341
|
+
).print();
|
|
342
|
+
return "";
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
async function previewV2Project({
|
|
346
|
+
logLevel,
|
|
347
|
+
configPath,
|
|
348
|
+
port,
|
|
349
|
+
config: config2,
|
|
350
|
+
host,
|
|
351
|
+
openBrowser
|
|
352
|
+
}) {
|
|
353
|
+
const root = path2.resolve(path2.dirname(configPath), config2.root ?? "./");
|
|
354
|
+
const relativeConfigPath = path2.relative(root, configPath);
|
|
355
|
+
const accessToken = await getAccessToken();
|
|
356
|
+
await downloadIsolate();
|
|
357
|
+
output.info().message("Starting preview\u2026").print();
|
|
358
|
+
await runIsolate({
|
|
359
|
+
configPath: relativeConfigPath,
|
|
360
|
+
projectDir: root,
|
|
361
|
+
logLevel,
|
|
362
|
+
domain: "localhost",
|
|
363
|
+
mode: "preview",
|
|
364
|
+
previewServerPort: port,
|
|
365
|
+
registryBaseUrl: config.projects.registry,
|
|
366
|
+
baseUrl: config.services.api,
|
|
367
|
+
token: accessToken,
|
|
368
|
+
host,
|
|
369
|
+
openBrowser
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// src/domains/project/preview/action.ts
|
|
374
|
+
async function previewAction(__configPath, options) {
|
|
375
|
+
const _port = Number.parseInt(options.port || "7970", 10);
|
|
376
|
+
if (Number.isNaN(_port)) {
|
|
377
|
+
return output.error().title("Invalid port").message("Provide a valid port number").exit("error");
|
|
378
|
+
}
|
|
379
|
+
if (_port < 0 || _port > 65535) {
|
|
380
|
+
return output.error().title("Invalid port").message("Port number must be between 0 and 65535").exit("error");
|
|
381
|
+
}
|
|
382
|
+
let configPath = __configPath || findConfig();
|
|
383
|
+
if (!configPath) {
|
|
384
|
+
requireInteractive(
|
|
385
|
+
"Pass the path to your Scalar configuration file to preview non-interactively."
|
|
386
|
+
);
|
|
387
|
+
const response = await text({
|
|
388
|
+
message: "Where is your configuration file located?",
|
|
389
|
+
defaultValue: CONFIG_FILE_DEFAULT,
|
|
390
|
+
placeholder: CONFIG_FILE_DEFAULT
|
|
391
|
+
});
|
|
392
|
+
if (isCancel(response)) return;
|
|
393
|
+
configPath = response;
|
|
394
|
+
}
|
|
395
|
+
const parseConfigResult = readAndParseConfig(configPath);
|
|
396
|
+
if (!parseConfigResult.success) {
|
|
397
|
+
renderConfigError(parseConfigResult.error);
|
|
398
|
+
}
|
|
399
|
+
if (parseConfigResult.success) {
|
|
400
|
+
output.info().line(
|
|
401
|
+
`${as.green("[SUCCESS]")} ${as.green("Configuration is valid:")} ${as.green(parseConfigResult.filePath)}`
|
|
402
|
+
).print();
|
|
403
|
+
}
|
|
404
|
+
const { config: config2 } = parseConfigResult;
|
|
405
|
+
if (config2.version === ConfigVersion.V1) {
|
|
406
|
+
return output.error().title("Version 1 previews are no longer supported").message("Run `scalar project upgrade` to upgrade your project.").exit("error");
|
|
407
|
+
}
|
|
408
|
+
if (config2.version === ConfigVersion.V2) {
|
|
409
|
+
await previewV2Project({
|
|
410
|
+
logLevel: options.logLevel,
|
|
411
|
+
configPath,
|
|
412
|
+
config: config2,
|
|
413
|
+
port: _port,
|
|
414
|
+
host: options.host,
|
|
415
|
+
openBrowser: (options.open ?? true) && Boolean(process.stdin.isTTY) && !process.env.CI
|
|
416
|
+
});
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
export {
|
|
421
|
+
previewAction
|
|
422
|
+
};
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
BaseCollections
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-TI4NDKQC.js";
|
|
5
5
|
import {
|
|
6
6
|
getDatabaseClient
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-JWNWOK2M.js";
|
|
8
|
+
import "./chunk-KPLWZIOV.js";
|
|
9
|
+
import "./chunk-YTTDYTVB.js";
|
|
10
|
+
import "./chunk-Y2OQOAY7.js";
|
|
10
11
|
import "./chunk-5ENKYZA4.js";
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-V6LUKXBV.js";
|
|
12
|
+
import "./chunk-EXJUFF6G.js";
|
|
13
|
+
import "./chunk-RE5Z56QD.js";
|
|
14
14
|
import "./chunk-VUXPDHTQ.js";
|
|
15
15
|
import {
|
|
16
16
|
getAuthData
|
|
17
|
-
} from "./chunk-
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-
|
|
17
|
+
} from "./chunk-FI7UKPRF.js";
|
|
18
|
+
import "./chunk-FYMDIB7J.js";
|
|
19
|
+
import "./chunk-IOW726L2.js";
|
|
20
20
|
import {
|
|
21
21
|
teamSchema
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-F3TQHNSQ.js";
|
|
23
23
|
import "./chunk-VRZSDUZK.js";
|
|
24
24
|
import "./chunk-4ORL4MST.js";
|
|
25
|
-
import "./chunk-
|
|
25
|
+
import "./chunk-TYNF7ROW.js";
|
|
26
26
|
import {
|
|
27
27
|
output
|
|
28
28
|
} from "./chunk-T5HJUAWB.js";
|
|
29
|
-
import "./chunk-
|
|
29
|
+
import "./chunk-AOZQPCWI.js";
|
|
30
30
|
import "./chunk-Q26DFKTY.js";
|
|
31
31
|
import "./chunk-I57ID5K7.js";
|
|
32
32
|
import "./chunk-3MZYUBJ6.js";
|
|
@@ -6,34 +6,34 @@ import {
|
|
|
6
6
|
findConfig,
|
|
7
7
|
getCurrentFolderName,
|
|
8
8
|
scalarConfigSchema
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-MQ65WBVF.js";
|
|
10
10
|
import {
|
|
11
11
|
apiService
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-2GKXAGSH.js";
|
|
13
|
+
import "./chunk-2AK5O3NQ.js";
|
|
14
|
+
import "./chunk-KPLWZIOV.js";
|
|
15
|
+
import "./chunk-YTTDYTVB.js";
|
|
16
|
+
import "./chunk-Y2OQOAY7.js";
|
|
16
17
|
import "./chunk-5ENKYZA4.js";
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-V3MYP5SQ.js";
|
|
18
|
+
import "./chunk-IRA5BW2J.js";
|
|
19
|
+
import "./chunk-EXJUFF6G.js";
|
|
20
20
|
import {
|
|
21
21
|
getMetadata
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-FI7UKPRF.js";
|
|
23
23
|
import {
|
|
24
24
|
config
|
|
25
|
-
} from "./chunk-
|
|
26
|
-
import "./chunk-
|
|
27
|
-
import "./chunk-
|
|
25
|
+
} from "./chunk-FYMDIB7J.js";
|
|
26
|
+
import "./chunk-IOW726L2.js";
|
|
27
|
+
import "./chunk-F3TQHNSQ.js";
|
|
28
28
|
import "./chunk-VRZSDUZK.js";
|
|
29
29
|
import {
|
|
30
30
|
requireInteractive
|
|
31
31
|
} from "./chunk-EGOXR5FB.js";
|
|
32
|
-
import "./chunk-
|
|
32
|
+
import "./chunk-TYNF7ROW.js";
|
|
33
33
|
import {
|
|
34
34
|
output
|
|
35
35
|
} from "./chunk-T5HJUAWB.js";
|
|
36
|
-
import "./chunk-
|
|
36
|
+
import "./chunk-AOZQPCWI.js";
|
|
37
37
|
import "./chunk-Q26DFKTY.js";
|
|
38
38
|
import {
|
|
39
39
|
slugify
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
getFileOrUrl
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-I7ZVWF57.js";
|
|
5
|
+
import "./chunk-WKW5W2ZP.js";
|
|
6
6
|
import "./chunk-4ORL4MST.js";
|
|
7
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-TYNF7ROW.js";
|
|
8
8
|
import {
|
|
9
9
|
output
|
|
10
10
|
} from "./chunk-T5HJUAWB.js";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-AOZQPCWI.js";
|
|
12
12
|
import "./chunk-Q26DFKTY.js";
|
|
13
13
|
import "./chunk-I57ID5K7.js";
|
|
14
14
|
import "./chunk-3MZYUBJ6.js";
|
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
registry
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-62OOT7FY.js";
|
|
5
5
|
import {
|
|
6
6
|
dashboardUrl,
|
|
7
7
|
registryUrl
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-LEECPQZN.js";
|
|
9
9
|
import {
|
|
10
10
|
getFileOrUrl,
|
|
11
11
|
isDocument
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-I7ZVWF57.js";
|
|
13
13
|
import {
|
|
14
14
|
safeNormalize
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-WKW5W2ZP.js";
|
|
16
16
|
import {
|
|
17
17
|
DEFAULT_FETCH_CONCURRENCY
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-KWIY2QZY.js";
|
|
19
19
|
import "./chunk-DFOZG7ZV.js";
|
|
20
20
|
import {
|
|
21
21
|
BaseCollections
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-TI4NDKQC.js";
|
|
23
23
|
import {
|
|
24
24
|
getDatabaseClient
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-JWNWOK2M.js";
|
|
26
26
|
import {
|
|
27
27
|
apiService
|
|
28
|
-
} from "./chunk-
|
|
29
|
-
import "./chunk-
|
|
30
|
-
import "./chunk-
|
|
31
|
-
import "./chunk-
|
|
28
|
+
} from "./chunk-2GKXAGSH.js";
|
|
29
|
+
import "./chunk-2AK5O3NQ.js";
|
|
30
|
+
import "./chunk-KPLWZIOV.js";
|
|
31
|
+
import "./chunk-YTTDYTVB.js";
|
|
32
|
+
import "./chunk-Y2OQOAY7.js";
|
|
32
33
|
import "./chunk-5ENKYZA4.js";
|
|
33
|
-
import "./chunk-
|
|
34
|
-
import "./chunk-
|
|
35
|
-
import "./chunk-
|
|
36
|
-
import "./chunk-V6LUKXBV.js";
|
|
34
|
+
import "./chunk-IRA5BW2J.js";
|
|
35
|
+
import "./chunk-EXJUFF6G.js";
|
|
36
|
+
import "./chunk-RE5Z56QD.js";
|
|
37
37
|
import "./chunk-VUXPDHTQ.js";
|
|
38
38
|
import {
|
|
39
39
|
getAuthData
|
|
40
|
-
} from "./chunk-
|
|
41
|
-
import "./chunk-
|
|
42
|
-
import "./chunk-
|
|
40
|
+
} from "./chunk-FI7UKPRF.js";
|
|
41
|
+
import "./chunk-FYMDIB7J.js";
|
|
42
|
+
import "./chunk-IOW726L2.js";
|
|
43
43
|
import {
|
|
44
44
|
teamSchema
|
|
45
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-F3TQHNSQ.js";
|
|
46
46
|
import "./chunk-VRZSDUZK.js";
|
|
47
47
|
import {
|
|
48
48
|
requireInteractive
|
|
@@ -52,11 +52,11 @@ import {
|
|
|
52
52
|
} from "./chunk-4ORL4MST.js";
|
|
53
53
|
import {
|
|
54
54
|
RegistryAsset
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-TYNF7ROW.js";
|
|
56
56
|
import {
|
|
57
57
|
output
|
|
58
58
|
} from "./chunk-T5HJUAWB.js";
|
|
59
|
-
import "./chunk-
|
|
59
|
+
import "./chunk-AOZQPCWI.js";
|
|
60
60
|
import "./chunk-Q26DFKTY.js";
|
|
61
61
|
import {
|
|
62
62
|
docVersionSchema,
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
fetchFromRegistry
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-BOPEAS7H.js";
|
|
5
5
|
import {
|
|
6
6
|
registry
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-62OOT7FY.js";
|
|
8
|
+
import "./chunk-LEECPQZN.js";
|
|
9
9
|
import {
|
|
10
10
|
DOCUMENT_FORMATS
|
|
11
11
|
} from "./chunk-NAC63XJF.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-RE5Z56QD.js";
|
|
13
13
|
import "./chunk-VUXPDHTQ.js";
|
|
14
14
|
import {
|
|
15
15
|
getAuthData
|
|
16
|
-
} from "./chunk-
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-
|
|
16
|
+
} from "./chunk-FI7UKPRF.js";
|
|
17
|
+
import "./chunk-FYMDIB7J.js";
|
|
18
|
+
import "./chunk-IOW726L2.js";
|
|
19
|
+
import "./chunk-F3TQHNSQ.js";
|
|
20
20
|
import "./chunk-VRZSDUZK.js";
|
|
21
21
|
import "./chunk-4ORL4MST.js";
|
|
22
|
-
import "./chunk-
|
|
22
|
+
import "./chunk-TYNF7ROW.js";
|
|
23
23
|
import {
|
|
24
24
|
output
|
|
25
25
|
} from "./chunk-T5HJUAWB.js";
|
|
26
|
-
import "./chunk-
|
|
26
|
+
import "./chunk-AOZQPCWI.js";
|
|
27
27
|
import "./chunk-Q26DFKTY.js";
|
|
28
28
|
import {
|
|
29
29
|
docVersionSchema,
|