browser-rpc 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1305 -574
- package/package.json +6 -5
- package/web-dist/assets/{add-CSurud0_.js → add-C9K-4E1n.js} +1 -1
- package/web-dist/assets/{all-wallets-CuPxktej.js → all-wallets-BvDaD556.js} +1 -1
- package/web-dist/assets/{app-store-Bh7SMjK6.js → app-store-BLIgBbq_.js} +1 -1
- package/web-dist/assets/{apple-C4EgoShq.js → apple-CGjwxXCd.js} +1 -1
- package/web-dist/assets/{arrow-bottom-CzdtCJaR.js → arrow-bottom-3E84C8kS.js} +1 -1
- package/web-dist/assets/{arrow-bottom-circle-CzKcAzTC.js → arrow-bottom-circle-NFod99fa.js} +1 -1
- package/web-dist/assets/{arrow-left-DCA-23-P.js → arrow-left-Oy1455UY.js} +1 -1
- package/web-dist/assets/{arrow-right-DjWMZCbU.js → arrow-right-Bc6X8rPs.js} +1 -1
- package/web-dist/assets/{arrow-top-DdmR7t9T.js → arrow-top-D9hwKB_J.js} +1 -1
- package/web-dist/assets/{bank-C_5L-YDS.js → bank-BmZ38pW6.js} +1 -1
- package/web-dist/assets/{basic-CqHaUvPy.js → basic-lblDM3KX.js} +1 -1
- package/web-dist/assets/{browser-DrecPVgr.js → browser-C_AwFCsD.js} +1 -1
- package/web-dist/assets/{card-B8Kpmq0P.js → card-DCs8IJra.js} +1 -1
- package/web-dist/assets/{ccip-DULOFBuD.js → ccip--_RYV1LW.js} +1 -1
- package/web-dist/assets/{ccip-JXkAn6l_.js → ccip-W6qN6zfs.js} +1 -1
- package/web-dist/assets/{checkmark-pd5FsFzg.js → checkmark-Df1-yuZC.js} +1 -1
- package/web-dist/assets/{checkmark-bold-C5CQv-Aa.js → checkmark-bold-JWkgfAmQ.js} +1 -1
- package/web-dist/assets/{chevron-bottom-BLvDr8vF.js → chevron-bottom-DzEhL8FN.js} +1 -1
- package/web-dist/assets/{chevron-left-Bn5fXcit.js → chevron-left-DeO4b6if.js} +1 -1
- package/web-dist/assets/{chevron-right-Bp7Npo8k.js → chevron-right-5IVLcDWf.js} +1 -1
- package/web-dist/assets/{chevron-top-DC_l4mwZ.js → chevron-top-C2yNiV5t.js} +1 -1
- package/web-dist/assets/{chrome-store-B0wZ3pqA.js → chrome-store-xz4b7c1B.js} +1 -1
- package/web-dist/assets/{clock-l4cNQcqu.js → clock-BxUbzSBP.js} +1 -1
- package/web-dist/assets/{close-DGUe_y81.js → close-DYLvabb7.js} +1 -1
- package/web-dist/assets/{coinPlaceholder-BP01UQKP.js → coinPlaceholder-k2rqkGyl.js} +1 -1
- package/web-dist/assets/{compass-o-R_PR5i.js → compass-PZRf7Un5.js} +1 -1
- package/web-dist/assets/{copy-BAr81PLi.js → copy-BMBlEjDD.js} +1 -1
- package/web-dist/assets/{core-D7szIsgf.js → core-BdMeFnPD.js} +4 -4
- package/web-dist/assets/{cursor-D3GZTRrk.js → cursor-BxgEfal7.js} +1 -1
- package/web-dist/assets/{cursor-transparent-DljOOQBY.js → cursor-transparent-c4VD5_tf.js} +1 -1
- package/web-dist/assets/{desktop-jiAHOLvJ.js → desktop-DdLnyis-.js} +1 -1
- package/web-dist/assets/{disconnect-CS8uxHay.js → disconnect-DP7_baek.js} +1 -1
- package/web-dist/assets/{discord-DHnKyemy.js → discord-C-mJr1Ol.js} +1 -1
- package/web-dist/assets/{etherscan-CVkxPkFS.js → etherscan-BdfNkRk4.js} +1 -1
- package/web-dist/assets/{exclamation-triangle-CS4ruWfK.js → exclamation-triangle-11qDqGvW.js} +1 -1
- package/web-dist/assets/{extension-DnLfOwO6.js → extension-DoYjQPf5.js} +1 -1
- package/web-dist/assets/{external-link-D-P_33dB.js → external-link-CGR8Qs7H.js} +1 -1
- package/web-dist/assets/{facebook-jLzamRKN.js → facebook-CFf_zmfW.js} +1 -1
- package/web-dist/assets/{farcaster-B4A0ZZeM.js → farcaster-Crwnh2Sb.js} +1 -1
- package/web-dist/assets/{filters-2IeJyFyu.js → filters-DiOjYgDF.js} +1 -1
- package/web-dist/assets/{github-CYDpN-_e.js → github-C9BVUtnE.js} +1 -1
- package/web-dist/assets/{google-BZkNEgmj.js → google-CEM5GuYr.js} +1 -1
- package/web-dist/assets/{help-circle-DMZ8-Cna.js → help-circle-CPZYemzh.js} +1 -1
- package/web-dist/assets/{id-38gfBvri.js → id-Cc-Rxw-7.js} +1 -1
- package/web-dist/assets/{image-C9_OStLn.js → image-nTDeviw4.js} +1 -1
- package/web-dist/assets/{index-dCn6axXg.js → index-B1hodanr.js} +1 -1
- package/web-dist/assets/{index-QgYpnbyq.js → index-BwiFhWWO.js} +1 -1
- package/web-dist/assets/{index-CiTEL--Y.js → index-C1-ohU6K.js} +1 -1
- package/web-dist/assets/{index--LSQjR_2.js → index-CJWDjemb.js} +4 -4
- package/web-dist/assets/{index-Cg8hiVbn.js → index-CktUZeh3.js} +3 -3
- package/web-dist/assets/{index-Ccy1t-C4.js → index-D_-GJPnC.js} +4 -4
- package/web-dist/assets/{index.es-C1H8G2CD.js → index.es-D4tIsh3x.js} +4 -4
- package/web-dist/assets/{info-n2qoFrAe.js → info-C7qRI-3s.js} +1 -1
- package/web-dist/assets/{info-circle-BTNeoxa6.js → info-circle-JRgRAB8H.js} +1 -1
- package/web-dist/assets/{lightbulb-Clk-Jmgu.js → lightbulb-DskWPdSm.js} +1 -1
- package/web-dist/assets/{mail-Cds1jWOG.js → mail-5lByEFT0.js} +1 -1
- package/web-dist/assets/{mobile-3m8bvDwV.js → mobile-DdR1V3H3.js} +1 -1
- package/web-dist/assets/{more-D4wapBmR.js → more-C0iIhdhY.js} +1 -1
- package/web-dist/assets/{network-placeholder-Byofvks3.js → network-placeholder-h13C95Mf.js} +1 -1
- package/web-dist/assets/{nftPlaceholder-CZSQO35I.js → nftPlaceholder-CU6ww27s.js} +1 -1
- package/web-dist/assets/{off-BwFiGI61.js → off-DZnRG_ed.js} +1 -1
- package/web-dist/assets/{play-store-BGBmqVQP.js → play-store--U2RkkQJ.js} +1 -1
- package/web-dist/assets/{plus-CuD4QENc.js → plus-CjH_YXtn.js} +1 -1
- package/web-dist/assets/{qr-code-CmkeyQ3q.js → qr-code-CwgWH0j1.js} +1 -1
- package/web-dist/assets/{recycle-horizontal-Bro_qysx.js → recycle-horizontal-Bof6BLou.js} +1 -1
- package/web-dist/assets/{refresh-Edry900n.js → refresh-u_nzo4Ji.js} +1 -1
- package/web-dist/assets/{reown-logo-BMZ4Cq9x.js → reown-logo-ytA9tHN5.js} +1 -1
- package/web-dist/assets/{search-AVAp5Fyx.js → search-B07VZgEc.js} +1 -1
- package/web-dist/assets/{secp256k1-DekXzlV8.js → secp256k1-D6Vhpivn.js} +1 -1
- package/web-dist/assets/{secp256k1-BgQIr3rN.js → secp256k1-DuIy3CvU.js} +1 -1
- package/web-dist/assets/{send-4MYVLgeW.js → send-BNVZQueo.js} +1 -1
- package/web-dist/assets/{swapHorizontal-cVSOFLpi.js → swapHorizontal-BevbAgZX.js} +1 -1
- package/web-dist/assets/{swapHorizontalBold-Bw-7VNbr.js → swapHorizontalBold-RPW3yLF4.js} +1 -1
- package/web-dist/assets/{swapHorizontalMedium-mcrKCBp-.js → swapHorizontalMedium-ssZWvpw-.js} +1 -1
- package/web-dist/assets/{swapHorizontalRoundedBold-BDxAi3q4.js → swapHorizontalRoundedBold-DcsmqoAE.js} +1 -1
- package/web-dist/assets/{swapVertical-BcwB3ulc.js → swapVertical-7hDuCvGI.js} +1 -1
- package/web-dist/assets/{telegram-DuHUM8tr.js → telegram-yBnByypq.js} +1 -1
- package/web-dist/assets/{three-dots-Aq6TxP_i.js → three-dots-DxRhDx45.js} +1 -1
- package/web-dist/assets/{twitch-C3_nAU2s.js → twitch-DYRNUbX0.js} +1 -1
- package/web-dist/assets/{twitterIcon-xVvhgLtz.js → twitterIcon-Cgj8kWW2.js} +1 -1
- package/web-dist/assets/{verify-Bk6Q4N8f.js → verify-BLoTSn32.js} +1 -1
- package/web-dist/assets/{verify-filled-P4SRtWaq.js → verify-filled-BZRBppdU.js} +1 -1
- package/web-dist/assets/{w3m-modal-BV8xYuAk.js → w3m-modal-CDSns-xi.js} +1 -1
- package/web-dist/assets/{wallet-Cwos8iS9.js → wallet-DtpSyptI.js} +1 -1
- package/web-dist/assets/{wallet-placeholder-DZOZgWPG.js → wallet-placeholder-Cy4dKWPL.js} +1 -1
- package/web-dist/assets/{walletconnect-BEXWbbOU.js → walletconnect-Kxwaha8s.js} +1 -1
- package/web-dist/assets/{warning-circle-BjUwobMn.js → warning-circle-DyBJXNHQ.js} +1 -1
- package/web-dist/assets/{x-CwzeXSXa.js → x-CHcx8FOR.js} +1 -1
- package/web-dist/index.html +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
// @bun
|
|
1
|
+
#!/usr/bin/env node
|
|
3
2
|
import { createRequire } from "node:module";
|
|
4
3
|
var __create = Object.create;
|
|
5
4
|
var __getProtoOf = Object.getPrototypeOf;
|
|
@@ -70,7 +69,7 @@ var require_argument = __commonJS((exports) => {
|
|
|
70
69
|
this._name = name;
|
|
71
70
|
break;
|
|
72
71
|
}
|
|
73
|
-
if (this._name.
|
|
72
|
+
if (this._name.endsWith("...")) {
|
|
74
73
|
this.variadic = true;
|
|
75
74
|
this._name = this._name.slice(0, -3);
|
|
76
75
|
}
|
|
@@ -78,11 +77,12 @@ var require_argument = __commonJS((exports) => {
|
|
|
78
77
|
name() {
|
|
79
78
|
return this._name;
|
|
80
79
|
}
|
|
81
|
-
|
|
80
|
+
_collectValue(value, previous) {
|
|
82
81
|
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
83
82
|
return [value];
|
|
84
83
|
}
|
|
85
|
-
|
|
84
|
+
previous.push(value);
|
|
85
|
+
return previous;
|
|
86
86
|
}
|
|
87
87
|
default(value, description) {
|
|
88
88
|
this.defaultValue = value;
|
|
@@ -100,7 +100,7 @@ var require_argument = __commonJS((exports) => {
|
|
|
100
100
|
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
101
101
|
}
|
|
102
102
|
if (this.variadic) {
|
|
103
|
-
return this.
|
|
103
|
+
return this._collectValue(arg, previous);
|
|
104
104
|
}
|
|
105
105
|
return arg;
|
|
106
106
|
};
|
|
@@ -130,10 +130,14 @@ var require_help = __commonJS((exports) => {
|
|
|
130
130
|
class Help {
|
|
131
131
|
constructor() {
|
|
132
132
|
this.helpWidth = undefined;
|
|
133
|
+
this.minWidthToWrap = 40;
|
|
133
134
|
this.sortSubcommands = false;
|
|
134
135
|
this.sortOptions = false;
|
|
135
136
|
this.showGlobalOptions = false;
|
|
136
137
|
}
|
|
138
|
+
prepareContext(contextOptions) {
|
|
139
|
+
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
140
|
+
}
|
|
137
141
|
visibleCommands(cmd) {
|
|
138
142
|
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
139
143
|
const helpCommand = cmd._getHelpCommand();
|
|
@@ -208,22 +212,22 @@ var require_help = __commonJS((exports) => {
|
|
|
208
212
|
}
|
|
209
213
|
longestSubcommandTermLength(cmd, helper) {
|
|
210
214
|
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
211
|
-
return Math.max(max, helper.subcommandTerm(command)
|
|
215
|
+
return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
|
|
212
216
|
}, 0);
|
|
213
217
|
}
|
|
214
218
|
longestOptionTermLength(cmd, helper) {
|
|
215
219
|
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
216
|
-
return Math.max(max, helper.optionTerm(option)
|
|
220
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
217
221
|
}, 0);
|
|
218
222
|
}
|
|
219
223
|
longestGlobalOptionTermLength(cmd, helper) {
|
|
220
224
|
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
221
|
-
return Math.max(max, helper.optionTerm(option)
|
|
225
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
222
226
|
}, 0);
|
|
223
227
|
}
|
|
224
228
|
longestArgumentTermLength(cmd, helper) {
|
|
225
229
|
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
226
|
-
return Math.max(max, helper.argumentTerm(argument)
|
|
230
|
+
return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
|
|
227
231
|
}, 0);
|
|
228
232
|
}
|
|
229
233
|
commandUsage(cmd) {
|
|
@@ -261,7 +265,11 @@ var require_help = __commonJS((exports) => {
|
|
|
261
265
|
extraInfo.push(`env: ${option.envVar}`);
|
|
262
266
|
}
|
|
263
267
|
if (extraInfo.length > 0) {
|
|
264
|
-
|
|
268
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
269
|
+
if (option.description) {
|
|
270
|
+
return `${option.description} ${extraDescription}`;
|
|
271
|
+
}
|
|
272
|
+
return extraDescription;
|
|
265
273
|
}
|
|
266
274
|
return option.description;
|
|
267
275
|
}
|
|
@@ -274,102 +282,202 @@ var require_help = __commonJS((exports) => {
|
|
|
274
282
|
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
275
283
|
}
|
|
276
284
|
if (extraInfo.length > 0) {
|
|
277
|
-
const
|
|
285
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
278
286
|
if (argument.description) {
|
|
279
|
-
return `${argument.description} ${
|
|
287
|
+
return `${argument.description} ${extraDescription}`;
|
|
280
288
|
}
|
|
281
|
-
return
|
|
289
|
+
return extraDescription;
|
|
282
290
|
}
|
|
283
291
|
return argument.description;
|
|
284
292
|
}
|
|
293
|
+
formatItemList(heading, items, helper) {
|
|
294
|
+
if (items.length === 0)
|
|
295
|
+
return [];
|
|
296
|
+
return [helper.styleTitle(heading), ...items, ""];
|
|
297
|
+
}
|
|
298
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
299
|
+
const result = new Map;
|
|
300
|
+
unsortedItems.forEach((item) => {
|
|
301
|
+
const group = getGroup(item);
|
|
302
|
+
if (!result.has(group))
|
|
303
|
+
result.set(group, []);
|
|
304
|
+
});
|
|
305
|
+
visibleItems.forEach((item) => {
|
|
306
|
+
const group = getGroup(item);
|
|
307
|
+
if (!result.has(group)) {
|
|
308
|
+
result.set(group, []);
|
|
309
|
+
}
|
|
310
|
+
result.get(group).push(item);
|
|
311
|
+
});
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
285
314
|
formatHelp(cmd, helper) {
|
|
286
315
|
const termWidth = helper.padWidth(cmd, helper);
|
|
287
|
-
const helpWidth = helper.helpWidth
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
function formatItem(term, description) {
|
|
291
|
-
if (description) {
|
|
292
|
-
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
293
|
-
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
294
|
-
}
|
|
295
|
-
return term;
|
|
296
|
-
}
|
|
297
|
-
function formatList(textArray) {
|
|
298
|
-
return textArray.join(`
|
|
299
|
-
`).replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
316
|
+
const helpWidth = helper.helpWidth ?? 80;
|
|
317
|
+
function callFormatItem(term, description) {
|
|
318
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
300
319
|
}
|
|
301
|
-
let output = [
|
|
320
|
+
let output = [
|
|
321
|
+
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
322
|
+
""
|
|
323
|
+
];
|
|
302
324
|
const commandDescription = helper.commandDescription(cmd);
|
|
303
325
|
if (commandDescription.length > 0) {
|
|
304
326
|
output = output.concat([
|
|
305
|
-
helper.
|
|
327
|
+
helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
|
|
306
328
|
""
|
|
307
329
|
]);
|
|
308
330
|
}
|
|
309
331
|
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
310
|
-
return
|
|
332
|
+
return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
|
|
311
333
|
});
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
334
|
+
output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
|
|
335
|
+
const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
|
|
336
|
+
optionGroups.forEach((options, group) => {
|
|
337
|
+
const optionList = options.map((option) => {
|
|
338
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
339
|
+
});
|
|
340
|
+
output = output.concat(this.formatItemList(group, optionList, helper));
|
|
317
341
|
});
|
|
318
|
-
if (
|
|
319
|
-
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
320
|
-
}
|
|
321
|
-
if (this.showGlobalOptions) {
|
|
342
|
+
if (helper.showGlobalOptions) {
|
|
322
343
|
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
323
|
-
return
|
|
344
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
324
345
|
});
|
|
325
|
-
|
|
326
|
-
output = output.concat([
|
|
327
|
-
"Global Options:",
|
|
328
|
-
formatList(globalOptionList),
|
|
329
|
-
""
|
|
330
|
-
]);
|
|
331
|
-
}
|
|
346
|
+
output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
|
|
332
347
|
}
|
|
333
|
-
const
|
|
334
|
-
|
|
348
|
+
const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
|
|
349
|
+
commandGroups.forEach((commands, group) => {
|
|
350
|
+
const commandList = commands.map((sub) => {
|
|
351
|
+
return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
|
|
352
|
+
});
|
|
353
|
+
output = output.concat(this.formatItemList(group, commandList, helper));
|
|
335
354
|
});
|
|
336
|
-
if (commandList.length > 0) {
|
|
337
|
-
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
338
|
-
}
|
|
339
355
|
return output.join(`
|
|
340
356
|
`);
|
|
341
357
|
}
|
|
358
|
+
displayWidth(str) {
|
|
359
|
+
return stripColor(str).length;
|
|
360
|
+
}
|
|
361
|
+
styleTitle(str) {
|
|
362
|
+
return str;
|
|
363
|
+
}
|
|
364
|
+
styleUsage(str) {
|
|
365
|
+
return str.split(" ").map((word) => {
|
|
366
|
+
if (word === "[options]")
|
|
367
|
+
return this.styleOptionText(word);
|
|
368
|
+
if (word === "[command]")
|
|
369
|
+
return this.styleSubcommandText(word);
|
|
370
|
+
if (word[0] === "[" || word[0] === "<")
|
|
371
|
+
return this.styleArgumentText(word);
|
|
372
|
+
return this.styleCommandText(word);
|
|
373
|
+
}).join(" ");
|
|
374
|
+
}
|
|
375
|
+
styleCommandDescription(str) {
|
|
376
|
+
return this.styleDescriptionText(str);
|
|
377
|
+
}
|
|
378
|
+
styleOptionDescription(str) {
|
|
379
|
+
return this.styleDescriptionText(str);
|
|
380
|
+
}
|
|
381
|
+
styleSubcommandDescription(str) {
|
|
382
|
+
return this.styleDescriptionText(str);
|
|
383
|
+
}
|
|
384
|
+
styleArgumentDescription(str) {
|
|
385
|
+
return this.styleDescriptionText(str);
|
|
386
|
+
}
|
|
387
|
+
styleDescriptionText(str) {
|
|
388
|
+
return str;
|
|
389
|
+
}
|
|
390
|
+
styleOptionTerm(str) {
|
|
391
|
+
return this.styleOptionText(str);
|
|
392
|
+
}
|
|
393
|
+
styleSubcommandTerm(str) {
|
|
394
|
+
return str.split(" ").map((word) => {
|
|
395
|
+
if (word === "[options]")
|
|
396
|
+
return this.styleOptionText(word);
|
|
397
|
+
if (word[0] === "[" || word[0] === "<")
|
|
398
|
+
return this.styleArgumentText(word);
|
|
399
|
+
return this.styleSubcommandText(word);
|
|
400
|
+
}).join(" ");
|
|
401
|
+
}
|
|
402
|
+
styleArgumentTerm(str) {
|
|
403
|
+
return this.styleArgumentText(str);
|
|
404
|
+
}
|
|
405
|
+
styleOptionText(str) {
|
|
406
|
+
return str;
|
|
407
|
+
}
|
|
408
|
+
styleArgumentText(str) {
|
|
409
|
+
return str;
|
|
410
|
+
}
|
|
411
|
+
styleSubcommandText(str) {
|
|
412
|
+
return str;
|
|
413
|
+
}
|
|
414
|
+
styleCommandText(str) {
|
|
415
|
+
return str;
|
|
416
|
+
}
|
|
342
417
|
padWidth(cmd, helper) {
|
|
343
418
|
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
344
419
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
if (
|
|
420
|
+
preformatted(str) {
|
|
421
|
+
return /\n[^\S\r\n]/.test(str);
|
|
422
|
+
}
|
|
423
|
+
formatItem(term, termWidth, description, helper) {
|
|
424
|
+
const itemIndent = 2;
|
|
425
|
+
const itemIndentStr = " ".repeat(itemIndent);
|
|
426
|
+
if (!description)
|
|
427
|
+
return itemIndentStr + term;
|
|
428
|
+
const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
|
|
429
|
+
const spacerWidth = 2;
|
|
430
|
+
const helpWidth = this.helpWidth ?? 80;
|
|
431
|
+
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
432
|
+
let formattedDescription;
|
|
433
|
+
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
434
|
+
formattedDescription = description;
|
|
435
|
+
} else {
|
|
436
|
+
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
437
|
+
formattedDescription = wrappedDescription.replace(/\n/g, `
|
|
438
|
+
` + " ".repeat(termWidth + spacerWidth));
|
|
439
|
+
}
|
|
440
|
+
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
441
|
+
${itemIndentStr}`);
|
|
442
|
+
}
|
|
443
|
+
boxWrap(str, width) {
|
|
444
|
+
if (width < this.minWidthToWrap)
|
|
352
445
|
return str;
|
|
353
|
-
const
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
446
|
+
const rawLines = str.split(/\r\n|\n/);
|
|
447
|
+
const chunkPattern = /[\s]*[^\s]+/g;
|
|
448
|
+
const wrappedLines = [];
|
|
449
|
+
rawLines.forEach((line) => {
|
|
450
|
+
const chunks = line.match(chunkPattern);
|
|
451
|
+
if (chunks === null) {
|
|
452
|
+
wrappedLines.push("");
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
let sumChunks = [chunks.shift()];
|
|
456
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
457
|
+
chunks.forEach((chunk) => {
|
|
458
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
459
|
+
if (sumWidth + visibleWidth <= width) {
|
|
460
|
+
sumChunks.push(chunk);
|
|
461
|
+
sumWidth += visibleWidth;
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
wrappedLines.push(sumChunks.join(""));
|
|
465
|
+
const nextChunk = chunk.trimStart();
|
|
466
|
+
sumChunks = [nextChunk];
|
|
467
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
468
|
+
});
|
|
469
|
+
wrappedLines.push(sumChunks.join(""));
|
|
470
|
+
});
|
|
471
|
+
return wrappedLines.join(`
|
|
369
472
|
`);
|
|
370
473
|
}
|
|
371
474
|
}
|
|
475
|
+
function stripColor(str) {
|
|
476
|
+
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
477
|
+
return str.replace(sgrPattern, "");
|
|
478
|
+
}
|
|
372
479
|
exports.Help = Help;
|
|
480
|
+
exports.stripColor = stripColor;
|
|
373
481
|
});
|
|
374
482
|
|
|
375
483
|
// ../../node_modules/commander/lib/option.js
|
|
@@ -400,6 +508,7 @@ var require_option = __commonJS((exports) => {
|
|
|
400
508
|
this.argChoices = undefined;
|
|
401
509
|
this.conflictsWith = [];
|
|
402
510
|
this.implied = undefined;
|
|
511
|
+
this.helpGroupHeading = undefined;
|
|
403
512
|
}
|
|
404
513
|
default(value, description) {
|
|
405
514
|
this.defaultValue = value;
|
|
@@ -438,11 +547,12 @@ var require_option = __commonJS((exports) => {
|
|
|
438
547
|
this.hidden = !!hide;
|
|
439
548
|
return this;
|
|
440
549
|
}
|
|
441
|
-
|
|
550
|
+
_collectValue(value, previous) {
|
|
442
551
|
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
443
552
|
return [value];
|
|
444
553
|
}
|
|
445
|
-
|
|
554
|
+
previous.push(value);
|
|
555
|
+
return previous;
|
|
446
556
|
}
|
|
447
557
|
choices(values) {
|
|
448
558
|
this.argChoices = values.slice();
|
|
@@ -451,7 +561,7 @@ var require_option = __commonJS((exports) => {
|
|
|
451
561
|
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
452
562
|
}
|
|
453
563
|
if (this.variadic) {
|
|
454
|
-
return this.
|
|
564
|
+
return this._collectValue(arg, previous);
|
|
455
565
|
}
|
|
456
566
|
return arg;
|
|
457
567
|
};
|
|
@@ -464,7 +574,14 @@ var require_option = __commonJS((exports) => {
|
|
|
464
574
|
return this.short.replace(/^-/, "");
|
|
465
575
|
}
|
|
466
576
|
attributeName() {
|
|
467
|
-
|
|
577
|
+
if (this.negate) {
|
|
578
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
579
|
+
}
|
|
580
|
+
return camelcase(this.name());
|
|
581
|
+
}
|
|
582
|
+
helpGroup(heading) {
|
|
583
|
+
this.helpGroupHeading = heading;
|
|
584
|
+
return this;
|
|
468
585
|
}
|
|
469
586
|
is(arg) {
|
|
470
587
|
return this.short === arg || this.long === arg;
|
|
@@ -509,14 +626,38 @@ var require_option = __commonJS((exports) => {
|
|
|
509
626
|
function splitOptionFlags(flags) {
|
|
510
627
|
let shortFlag;
|
|
511
628
|
let longFlag;
|
|
512
|
-
const
|
|
513
|
-
|
|
629
|
+
const shortFlagExp = /^-[^-]$/;
|
|
630
|
+
const longFlagExp = /^--[^-]/;
|
|
631
|
+
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
632
|
+
if (shortFlagExp.test(flagParts[0]))
|
|
514
633
|
shortFlag = flagParts.shift();
|
|
515
|
-
|
|
516
|
-
|
|
634
|
+
if (longFlagExp.test(flagParts[0]))
|
|
635
|
+
longFlag = flagParts.shift();
|
|
636
|
+
if (!shortFlag && shortFlagExp.test(flagParts[0]))
|
|
637
|
+
shortFlag = flagParts.shift();
|
|
638
|
+
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
517
639
|
shortFlag = longFlag;
|
|
518
|
-
longFlag =
|
|
519
|
-
}
|
|
640
|
+
longFlag = flagParts.shift();
|
|
641
|
+
}
|
|
642
|
+
if (flagParts[0].startsWith("-")) {
|
|
643
|
+
const unsupportedFlag = flagParts[0];
|
|
644
|
+
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
645
|
+
if (/^-[^-][^-]/.test(unsupportedFlag))
|
|
646
|
+
throw new Error(`${baseError}
|
|
647
|
+
- a short flag is a single dash and a single character
|
|
648
|
+
- either use a single dash and a single character (for a short flag)
|
|
649
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
|
|
650
|
+
if (shortFlagExp.test(unsupportedFlag))
|
|
651
|
+
throw new Error(`${baseError}
|
|
652
|
+
- too many short flags`);
|
|
653
|
+
if (longFlagExp.test(unsupportedFlag))
|
|
654
|
+
throw new Error(`${baseError}
|
|
655
|
+
- too many long flags`);
|
|
656
|
+
throw new Error(`${baseError}
|
|
657
|
+
- unrecognised flag format`);
|
|
658
|
+
}
|
|
659
|
+
if (shortFlag === undefined && longFlag === undefined)
|
|
660
|
+
throw new Error(`option creation failed due to no flags found in '${flags}'.`);
|
|
520
661
|
return { shortFlag, longFlag };
|
|
521
662
|
}
|
|
522
663
|
exports.Option = Option;
|
|
@@ -605,7 +746,7 @@ var require_command = __commonJS((exports) => {
|
|
|
605
746
|
var process2 = __require("node:process");
|
|
606
747
|
var { Argument, humanReadableArgName } = require_argument();
|
|
607
748
|
var { CommanderError } = require_error();
|
|
608
|
-
var { Help } = require_help();
|
|
749
|
+
var { Help, stripColor } = require_help();
|
|
609
750
|
var { Option, DualOptions } = require_option();
|
|
610
751
|
var { suggestSimilar } = require_suggestSimilar();
|
|
611
752
|
|
|
@@ -616,7 +757,7 @@ var require_command = __commonJS((exports) => {
|
|
|
616
757
|
this.options = [];
|
|
617
758
|
this.parent = null;
|
|
618
759
|
this._allowUnknownOption = false;
|
|
619
|
-
this._allowExcessArguments =
|
|
760
|
+
this._allowExcessArguments = false;
|
|
620
761
|
this.registeredArguments = [];
|
|
621
762
|
this._args = this.registeredArguments;
|
|
622
763
|
this.args = [];
|
|
@@ -643,18 +784,25 @@ var require_command = __commonJS((exports) => {
|
|
|
643
784
|
this._lifeCycleHooks = {};
|
|
644
785
|
this._showHelpAfterError = false;
|
|
645
786
|
this._showSuggestionAfterError = true;
|
|
787
|
+
this._savedState = null;
|
|
646
788
|
this._outputConfiguration = {
|
|
647
789
|
writeOut: (str) => process2.stdout.write(str),
|
|
648
790
|
writeErr: (str) => process2.stderr.write(str),
|
|
791
|
+
outputError: (str, write) => write(str),
|
|
649
792
|
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
650
793
|
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
651
|
-
|
|
794
|
+
getOutHasColors: () => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()),
|
|
795
|
+
getErrHasColors: () => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()),
|
|
796
|
+
stripColor: (str) => stripColor(str)
|
|
652
797
|
};
|
|
653
798
|
this._hidden = false;
|
|
654
799
|
this._helpOption = undefined;
|
|
655
800
|
this._addImplicitHelpCommand = undefined;
|
|
656
801
|
this._helpCommand = undefined;
|
|
657
802
|
this._helpConfiguration = {};
|
|
803
|
+
this._helpGroupHeading = undefined;
|
|
804
|
+
this._defaultCommandGroup = undefined;
|
|
805
|
+
this._defaultOptionGroup = undefined;
|
|
658
806
|
}
|
|
659
807
|
copyInheritedSettings(sourceCommand) {
|
|
660
808
|
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
@@ -719,7 +867,10 @@ var require_command = __commonJS((exports) => {
|
|
|
719
867
|
configureOutput(configuration) {
|
|
720
868
|
if (configuration === undefined)
|
|
721
869
|
return this._outputConfiguration;
|
|
722
|
-
|
|
870
|
+
this._outputConfiguration = {
|
|
871
|
+
...this._outputConfiguration,
|
|
872
|
+
...configuration
|
|
873
|
+
};
|
|
723
874
|
return this;
|
|
724
875
|
}
|
|
725
876
|
showHelpAfterError(displayHelp = true) {
|
|
@@ -750,12 +901,12 @@ var require_command = __commonJS((exports) => {
|
|
|
750
901
|
createArgument(name, description) {
|
|
751
902
|
return new Argument(name, description);
|
|
752
903
|
}
|
|
753
|
-
argument(name, description,
|
|
904
|
+
argument(name, description, parseArg, defaultValue) {
|
|
754
905
|
const argument = this.createArgument(name, description);
|
|
755
|
-
if (typeof
|
|
756
|
-
argument.default(defaultValue).argParser(
|
|
906
|
+
if (typeof parseArg === "function") {
|
|
907
|
+
argument.default(defaultValue).argParser(parseArg);
|
|
757
908
|
} else {
|
|
758
|
-
argument.default(
|
|
909
|
+
argument.default(parseArg);
|
|
759
910
|
}
|
|
760
911
|
this.addArgument(argument);
|
|
761
912
|
return this;
|
|
@@ -768,7 +919,7 @@ var require_command = __commonJS((exports) => {
|
|
|
768
919
|
}
|
|
769
920
|
addArgument(argument) {
|
|
770
921
|
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
771
|
-
if (previousArgument
|
|
922
|
+
if (previousArgument?.variadic) {
|
|
772
923
|
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
773
924
|
}
|
|
774
925
|
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
@@ -780,10 +931,13 @@ var require_command = __commonJS((exports) => {
|
|
|
780
931
|
helpCommand(enableOrNameAndArgs, description) {
|
|
781
932
|
if (typeof enableOrNameAndArgs === "boolean") {
|
|
782
933
|
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
934
|
+
if (enableOrNameAndArgs && this._defaultCommandGroup) {
|
|
935
|
+
this._initCommandGroup(this._getHelpCommand());
|
|
936
|
+
}
|
|
783
937
|
return this;
|
|
784
938
|
}
|
|
785
|
-
|
|
786
|
-
const [, helpName, helpArgs] =
|
|
939
|
+
const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
940
|
+
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
787
941
|
const helpDescription = description ?? "display help for command";
|
|
788
942
|
const helpCommand = this.createCommand(helpName);
|
|
789
943
|
helpCommand.helpOption(false);
|
|
@@ -793,6 +947,8 @@ var require_command = __commonJS((exports) => {
|
|
|
793
947
|
helpCommand.description(helpDescription);
|
|
794
948
|
this._addImplicitHelpCommand = true;
|
|
795
949
|
this._helpCommand = helpCommand;
|
|
950
|
+
if (enableOrNameAndArgs || description)
|
|
951
|
+
this._initCommandGroup(helpCommand);
|
|
796
952
|
return this;
|
|
797
953
|
}
|
|
798
954
|
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
@@ -802,6 +958,7 @@ var require_command = __commonJS((exports) => {
|
|
|
802
958
|
}
|
|
803
959
|
this._addImplicitHelpCommand = true;
|
|
804
960
|
this._helpCommand = helpCommand;
|
|
961
|
+
this._initCommandGroup(helpCommand);
|
|
805
962
|
return this;
|
|
806
963
|
}
|
|
807
964
|
_getHelpCommand() {
|
|
@@ -881,6 +1038,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
881
1038
|
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
882
1039
|
- already used by option '${matchingOption.flags}'`);
|
|
883
1040
|
}
|
|
1041
|
+
this._initOptionGroup(option);
|
|
884
1042
|
this.options.push(option);
|
|
885
1043
|
}
|
|
886
1044
|
_registerCommand(command) {
|
|
@@ -893,6 +1051,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
893
1051
|
const newCmd = knownBy(command).join("|");
|
|
894
1052
|
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
895
1053
|
}
|
|
1054
|
+
this._initCommandGroup(command);
|
|
896
1055
|
this.commands.push(command);
|
|
897
1056
|
}
|
|
898
1057
|
addOption(option) {
|
|
@@ -915,7 +1074,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
915
1074
|
if (val !== null && option.parseArg) {
|
|
916
1075
|
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
917
1076
|
} else if (val !== null && option.variadic) {
|
|
918
|
-
val = option.
|
|
1077
|
+
val = option._collectValue(val, oldValue);
|
|
919
1078
|
}
|
|
920
1079
|
if (val == null) {
|
|
921
1080
|
if (option.negate) {
|
|
@@ -1080,15 +1239,53 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1080
1239
|
return userArgs;
|
|
1081
1240
|
}
|
|
1082
1241
|
parse(argv, parseOptions) {
|
|
1242
|
+
this._prepareForParse();
|
|
1083
1243
|
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1084
1244
|
this._parseCommand([], userArgs);
|
|
1085
1245
|
return this;
|
|
1086
1246
|
}
|
|
1087
1247
|
async parseAsync(argv, parseOptions) {
|
|
1248
|
+
this._prepareForParse();
|
|
1088
1249
|
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1089
1250
|
await this._parseCommand([], userArgs);
|
|
1090
1251
|
return this;
|
|
1091
1252
|
}
|
|
1253
|
+
_prepareForParse() {
|
|
1254
|
+
if (this._savedState === null) {
|
|
1255
|
+
this.saveStateBeforeParse();
|
|
1256
|
+
} else {
|
|
1257
|
+
this.restoreStateBeforeParse();
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
saveStateBeforeParse() {
|
|
1261
|
+
this._savedState = {
|
|
1262
|
+
_name: this._name,
|
|
1263
|
+
_optionValues: { ...this._optionValues },
|
|
1264
|
+
_optionValueSources: { ...this._optionValueSources }
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
restoreStateBeforeParse() {
|
|
1268
|
+
if (this._storeOptionsAsProperties)
|
|
1269
|
+
throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
1270
|
+
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
1271
|
+
this._name = this._savedState._name;
|
|
1272
|
+
this._scriptPath = null;
|
|
1273
|
+
this.rawArgs = [];
|
|
1274
|
+
this._optionValues = { ...this._savedState._optionValues };
|
|
1275
|
+
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
1276
|
+
this.args = [];
|
|
1277
|
+
this.processedArgs = [];
|
|
1278
|
+
}
|
|
1279
|
+
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
1280
|
+
if (fs.existsSync(executableFile))
|
|
1281
|
+
return;
|
|
1282
|
+
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
1283
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1284
|
+
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1285
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1286
|
+
- ${executableDirMessage}`;
|
|
1287
|
+
throw new Error(executableMissing);
|
|
1288
|
+
}
|
|
1092
1289
|
_executeSubCommand(subcommand, args) {
|
|
1093
1290
|
args = args.slice();
|
|
1094
1291
|
let launchWithNode = false;
|
|
@@ -1112,7 +1309,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1112
1309
|
let resolvedScriptPath;
|
|
1113
1310
|
try {
|
|
1114
1311
|
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1115
|
-
} catch
|
|
1312
|
+
} catch {
|
|
1116
1313
|
resolvedScriptPath = this._scriptPath;
|
|
1117
1314
|
}
|
|
1118
1315
|
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
@@ -1138,6 +1335,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1138
1335
|
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1139
1336
|
}
|
|
1140
1337
|
} else {
|
|
1338
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
1141
1339
|
args.unshift(executableFile);
|
|
1142
1340
|
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1143
1341
|
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
@@ -1163,12 +1361,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1163
1361
|
});
|
|
1164
1362
|
proc.on("error", (err) => {
|
|
1165
1363
|
if (err.code === "ENOENT") {
|
|
1166
|
-
|
|
1167
|
-
const executableMissing = `'${executableFile}' does not exist
|
|
1168
|
-
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1169
|
-
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1170
|
-
- ${executableDirMessage}`;
|
|
1171
|
-
throw new Error(executableMissing);
|
|
1364
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
1172
1365
|
} else if (err.code === "EACCES") {
|
|
1173
1366
|
throw new Error(`'${executableFile}' not executable`);
|
|
1174
1367
|
}
|
|
@@ -1186,6 +1379,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1186
1379
|
const subCommand = this._findCommand(commandName);
|
|
1187
1380
|
if (!subCommand)
|
|
1188
1381
|
this.help({ error: true });
|
|
1382
|
+
subCommand._prepareForParse();
|
|
1189
1383
|
let promiseChain;
|
|
1190
1384
|
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
1191
1385
|
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
@@ -1255,7 +1449,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1255
1449
|
this.processedArgs = processedArgs;
|
|
1256
1450
|
}
|
|
1257
1451
|
_chainOrCall(promise, fn) {
|
|
1258
|
-
if (promise
|
|
1452
|
+
if (promise?.then && typeof promise.then === "function") {
|
|
1259
1453
|
return promise.then(() => fn());
|
|
1260
1454
|
}
|
|
1261
1455
|
return fn();
|
|
@@ -1332,7 +1526,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1332
1526
|
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
1333
1527
|
return promiseChain;
|
|
1334
1528
|
}
|
|
1335
|
-
if (this.parent
|
|
1529
|
+
if (this.parent?.listenerCount(commandEvent)) {
|
|
1336
1530
|
checkForUnknownOptions();
|
|
1337
1531
|
this._processArguments();
|
|
1338
1532
|
this.parent.emit(commandEvent, operands, unknown);
|
|
@@ -1394,24 +1588,31 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1394
1588
|
cmd._checkForConflictingLocalOptions();
|
|
1395
1589
|
});
|
|
1396
1590
|
}
|
|
1397
|
-
parseOptions(
|
|
1591
|
+
parseOptions(args) {
|
|
1398
1592
|
const operands = [];
|
|
1399
1593
|
const unknown = [];
|
|
1400
1594
|
let dest = operands;
|
|
1401
|
-
const args = argv.slice();
|
|
1402
1595
|
function maybeOption(arg) {
|
|
1403
1596
|
return arg.length > 1 && arg[0] === "-";
|
|
1404
1597
|
}
|
|
1598
|
+
const negativeNumberArg = (arg) => {
|
|
1599
|
+
if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg))
|
|
1600
|
+
return false;
|
|
1601
|
+
return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
|
|
1602
|
+
};
|
|
1405
1603
|
let activeVariadicOption = null;
|
|
1406
|
-
|
|
1407
|
-
|
|
1604
|
+
let activeGroup = null;
|
|
1605
|
+
let i = 0;
|
|
1606
|
+
while (i < args.length || activeGroup) {
|
|
1607
|
+
const arg = activeGroup ?? args[i++];
|
|
1608
|
+
activeGroup = null;
|
|
1408
1609
|
if (arg === "--") {
|
|
1409
1610
|
if (dest === unknown)
|
|
1410
1611
|
dest.push(arg);
|
|
1411
|
-
dest.push(...args);
|
|
1612
|
+
dest.push(...args.slice(i));
|
|
1412
1613
|
break;
|
|
1413
1614
|
}
|
|
1414
|
-
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1615
|
+
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
1415
1616
|
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1416
1617
|
continue;
|
|
1417
1618
|
}
|
|
@@ -1420,14 +1621,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1420
1621
|
const option = this._findOption(arg);
|
|
1421
1622
|
if (option) {
|
|
1422
1623
|
if (option.required) {
|
|
1423
|
-
const value = args
|
|
1624
|
+
const value = args[i++];
|
|
1424
1625
|
if (value === undefined)
|
|
1425
1626
|
this.optionMissingArgument(option);
|
|
1426
1627
|
this.emit(`option:${option.name()}`, value);
|
|
1427
1628
|
} else if (option.optional) {
|
|
1428
1629
|
let value = null;
|
|
1429
|
-
if (args.length
|
|
1430
|
-
value = args
|
|
1630
|
+
if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
|
|
1631
|
+
value = args[i++];
|
|
1431
1632
|
}
|
|
1432
1633
|
this.emit(`option:${option.name()}`, value);
|
|
1433
1634
|
} else {
|
|
@@ -1444,7 +1645,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1444
1645
|
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1445
1646
|
} else {
|
|
1446
1647
|
this.emit(`option:${option.name()}`);
|
|
1447
|
-
|
|
1648
|
+
activeGroup = `-${arg.slice(2)}`;
|
|
1448
1649
|
}
|
|
1449
1650
|
continue;
|
|
1450
1651
|
}
|
|
@@ -1457,31 +1658,24 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1457
1658
|
continue;
|
|
1458
1659
|
}
|
|
1459
1660
|
}
|
|
1460
|
-
if (maybeOption(arg)) {
|
|
1661
|
+
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
1461
1662
|
dest = unknown;
|
|
1462
1663
|
}
|
|
1463
1664
|
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1464
1665
|
if (this._findCommand(arg)) {
|
|
1465
1666
|
operands.push(arg);
|
|
1466
|
-
|
|
1467
|
-
unknown.push(...args);
|
|
1667
|
+
unknown.push(...args.slice(i));
|
|
1468
1668
|
break;
|
|
1469
1669
|
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
1470
|
-
operands.push(arg);
|
|
1471
|
-
if (args.length > 0)
|
|
1472
|
-
operands.push(...args);
|
|
1670
|
+
operands.push(arg, ...args.slice(i));
|
|
1473
1671
|
break;
|
|
1474
1672
|
} else if (this._defaultCommandName) {
|
|
1475
|
-
unknown.push(arg);
|
|
1476
|
-
if (args.length > 0)
|
|
1477
|
-
unknown.push(...args);
|
|
1673
|
+
unknown.push(arg, ...args.slice(i));
|
|
1478
1674
|
break;
|
|
1479
1675
|
}
|
|
1480
1676
|
}
|
|
1481
1677
|
if (this._passThroughOptions) {
|
|
1482
|
-
dest.push(arg);
|
|
1483
|
-
if (args.length > 0)
|
|
1484
|
-
dest.push(...args);
|
|
1678
|
+
dest.push(arg, ...args.slice(i));
|
|
1485
1679
|
break;
|
|
1486
1680
|
}
|
|
1487
1681
|
dest.push(arg);
|
|
@@ -1692,6 +1886,32 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1692
1886
|
this._name = str;
|
|
1693
1887
|
return this;
|
|
1694
1888
|
}
|
|
1889
|
+
helpGroup(heading) {
|
|
1890
|
+
if (heading === undefined)
|
|
1891
|
+
return this._helpGroupHeading ?? "";
|
|
1892
|
+
this._helpGroupHeading = heading;
|
|
1893
|
+
return this;
|
|
1894
|
+
}
|
|
1895
|
+
commandsGroup(heading) {
|
|
1896
|
+
if (heading === undefined)
|
|
1897
|
+
return this._defaultCommandGroup ?? "";
|
|
1898
|
+
this._defaultCommandGroup = heading;
|
|
1899
|
+
return this;
|
|
1900
|
+
}
|
|
1901
|
+
optionsGroup(heading) {
|
|
1902
|
+
if (heading === undefined)
|
|
1903
|
+
return this._defaultOptionGroup ?? "";
|
|
1904
|
+
this._defaultOptionGroup = heading;
|
|
1905
|
+
return this;
|
|
1906
|
+
}
|
|
1907
|
+
_initOptionGroup(option) {
|
|
1908
|
+
if (this._defaultOptionGroup && !option.helpGroupHeading)
|
|
1909
|
+
option.helpGroup(this._defaultOptionGroup);
|
|
1910
|
+
}
|
|
1911
|
+
_initCommandGroup(cmd) {
|
|
1912
|
+
if (this._defaultCommandGroup && !cmd.helpGroup())
|
|
1913
|
+
cmd.helpGroup(this._defaultCommandGroup);
|
|
1914
|
+
}
|
|
1695
1915
|
nameFromFilename(filename) {
|
|
1696
1916
|
this._name = path.basename(filename, path.extname(filename));
|
|
1697
1917
|
return this;
|
|
@@ -1704,23 +1924,38 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1704
1924
|
}
|
|
1705
1925
|
helpInformation(contextOptions) {
|
|
1706
1926
|
const helper = this.createHelp();
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1927
|
+
const context = this._getOutputContext(contextOptions);
|
|
1928
|
+
helper.prepareContext({
|
|
1929
|
+
error: context.error,
|
|
1930
|
+
helpWidth: context.helpWidth,
|
|
1931
|
+
outputHasColors: context.hasColors
|
|
1932
|
+
});
|
|
1933
|
+
const text = helper.formatHelp(this, helper);
|
|
1934
|
+
if (context.hasColors)
|
|
1935
|
+
return text;
|
|
1936
|
+
return this._outputConfiguration.stripColor(text);
|
|
1711
1937
|
}
|
|
1712
|
-
|
|
1938
|
+
_getOutputContext(contextOptions) {
|
|
1713
1939
|
contextOptions = contextOptions || {};
|
|
1714
|
-
const
|
|
1715
|
-
let
|
|
1716
|
-
|
|
1717
|
-
|
|
1940
|
+
const error = !!contextOptions.error;
|
|
1941
|
+
let baseWrite;
|
|
1942
|
+
let hasColors;
|
|
1943
|
+
let helpWidth;
|
|
1944
|
+
if (error) {
|
|
1945
|
+
baseWrite = (str) => this._outputConfiguration.writeErr(str);
|
|
1946
|
+
hasColors = this._outputConfiguration.getErrHasColors();
|
|
1947
|
+
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
1718
1948
|
} else {
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1949
|
+
baseWrite = (str) => this._outputConfiguration.writeOut(str);
|
|
1950
|
+
hasColors = this._outputConfiguration.getOutHasColors();
|
|
1951
|
+
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
1952
|
+
}
|
|
1953
|
+
const write = (str) => {
|
|
1954
|
+
if (!hasColors)
|
|
1955
|
+
str = this._outputConfiguration.stripColor(str);
|
|
1956
|
+
return baseWrite(str);
|
|
1957
|
+
};
|
|
1958
|
+
return { error, write, hasColors, helpWidth };
|
|
1724
1959
|
}
|
|
1725
1960
|
outputHelp(contextOptions) {
|
|
1726
1961
|
let deprecatedCallback;
|
|
@@ -1728,35 +1963,44 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1728
1963
|
deprecatedCallback = contextOptions;
|
|
1729
1964
|
contextOptions = undefined;
|
|
1730
1965
|
}
|
|
1731
|
-
const
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1966
|
+
const outputContext = this._getOutputContext(contextOptions);
|
|
1967
|
+
const eventContext = {
|
|
1968
|
+
error: outputContext.error,
|
|
1969
|
+
write: outputContext.write,
|
|
1970
|
+
command: this
|
|
1971
|
+
};
|
|
1972
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
1973
|
+
this.emit("beforeHelp", eventContext);
|
|
1974
|
+
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
1735
1975
|
if (deprecatedCallback) {
|
|
1736
1976
|
helpInformation = deprecatedCallback(helpInformation);
|
|
1737
1977
|
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
1738
1978
|
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
1739
1979
|
}
|
|
1740
1980
|
}
|
|
1741
|
-
|
|
1981
|
+
outputContext.write(helpInformation);
|
|
1742
1982
|
if (this._getHelpOption()?.long) {
|
|
1743
1983
|
this.emit(this._getHelpOption().long);
|
|
1744
1984
|
}
|
|
1745
|
-
this.emit("afterHelp",
|
|
1746
|
-
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp",
|
|
1985
|
+
this.emit("afterHelp", eventContext);
|
|
1986
|
+
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
|
|
1747
1987
|
}
|
|
1748
1988
|
helpOption(flags, description) {
|
|
1749
1989
|
if (typeof flags === "boolean") {
|
|
1750
1990
|
if (flags) {
|
|
1751
|
-
|
|
1991
|
+
if (this._helpOption === null)
|
|
1992
|
+
this._helpOption = undefined;
|
|
1993
|
+
if (this._defaultOptionGroup) {
|
|
1994
|
+
this._initOptionGroup(this._getHelpOption());
|
|
1995
|
+
}
|
|
1752
1996
|
} else {
|
|
1753
1997
|
this._helpOption = null;
|
|
1754
1998
|
}
|
|
1755
1999
|
return this;
|
|
1756
2000
|
}
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
2001
|
+
this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
|
|
2002
|
+
if (flags || description)
|
|
2003
|
+
this._initOptionGroup(this._helpOption);
|
|
1760
2004
|
return this;
|
|
1761
2005
|
}
|
|
1762
2006
|
_getHelpOption() {
|
|
@@ -1767,11 +2011,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1767
2011
|
}
|
|
1768
2012
|
addHelpOption(option) {
|
|
1769
2013
|
this._helpOption = option;
|
|
2014
|
+
this._initOptionGroup(option);
|
|
1770
2015
|
return this;
|
|
1771
2016
|
}
|
|
1772
2017
|
help(contextOptions) {
|
|
1773
2018
|
this.outputHelp(contextOptions);
|
|
1774
|
-
let exitCode = process2.exitCode
|
|
2019
|
+
let exitCode = Number(process2.exitCode ?? 0);
|
|
1775
2020
|
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
1776
2021
|
exitCode = 1;
|
|
1777
2022
|
}
|
|
@@ -1836,7 +2081,15 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1836
2081
|
return arg;
|
|
1837
2082
|
});
|
|
1838
2083
|
}
|
|
2084
|
+
function useColor() {
|
|
2085
|
+
if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
|
|
2086
|
+
return false;
|
|
2087
|
+
if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== undefined)
|
|
2088
|
+
return true;
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
1839
2091
|
exports.Command = Command;
|
|
2092
|
+
exports.useColor = useColor;
|
|
1840
2093
|
});
|
|
1841
2094
|
|
|
1842
2095
|
// ../../node_modules/commander/index.js
|
|
@@ -1859,150 +2112,897 @@ var require_commander = __commonJS((exports) => {
|
|
|
1859
2112
|
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
1860
2113
|
});
|
|
1861
2114
|
|
|
1862
|
-
// ../../node_modules/
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
2115
|
+
// ../../node_modules/@hono/node-server/dist/index.mjs
|
|
2116
|
+
import { createServer as createServerHTTP } from "http";
|
|
2117
|
+
import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
|
|
2118
|
+
import { Http2ServerRequest } from "http2";
|
|
2119
|
+
import { Readable } from "stream";
|
|
2120
|
+
import crypto from "crypto";
|
|
2121
|
+
var RequestError = class extends Error {
|
|
2122
|
+
constructor(message, options) {
|
|
2123
|
+
super(message, options);
|
|
2124
|
+
this.name = "RequestError";
|
|
2125
|
+
}
|
|
2126
|
+
};
|
|
2127
|
+
var toRequestError = (e) => {
|
|
2128
|
+
if (e instanceof RequestError) {
|
|
2129
|
+
return e;
|
|
2130
|
+
}
|
|
2131
|
+
return new RequestError(e.message, { cause: e });
|
|
2132
|
+
};
|
|
2133
|
+
var GlobalRequest = global.Request;
|
|
2134
|
+
var Request2 = class extends GlobalRequest {
|
|
2135
|
+
constructor(input, options) {
|
|
2136
|
+
if (typeof input === "object" && getRequestCache in input) {
|
|
2137
|
+
input = input[getRequestCache]();
|
|
2138
|
+
}
|
|
2139
|
+
if (typeof options?.body?.getReader !== "undefined") {
|
|
2140
|
+
options.duplex ??= "half";
|
|
2141
|
+
}
|
|
2142
|
+
super(input, options);
|
|
2143
|
+
}
|
|
2144
|
+
};
|
|
2145
|
+
var newHeadersFromIncoming = (incoming) => {
|
|
2146
|
+
const headerRecord = [];
|
|
2147
|
+
const rawHeaders = incoming.rawHeaders;
|
|
2148
|
+
for (let i = 0;i < rawHeaders.length; i += 2) {
|
|
2149
|
+
const { [i]: key, [i + 1]: value } = rawHeaders;
|
|
2150
|
+
if (key.charCodeAt(0) !== 58) {
|
|
2151
|
+
headerRecord.push([key, value]);
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
return new Headers(headerRecord);
|
|
2155
|
+
};
|
|
2156
|
+
var wrapBodyStream = Symbol("wrapBodyStream");
|
|
2157
|
+
var newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
|
|
2158
|
+
const init = {
|
|
2159
|
+
method,
|
|
2160
|
+
headers,
|
|
2161
|
+
signal: abortController.signal
|
|
2162
|
+
};
|
|
2163
|
+
if (method === "TRACE") {
|
|
2164
|
+
init.method = "GET";
|
|
2165
|
+
const req = new Request2(url, init);
|
|
2166
|
+
Object.defineProperty(req, "method", {
|
|
2167
|
+
get() {
|
|
2168
|
+
return "TRACE";
|
|
1899
2169
|
}
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
throw err;
|
|
1910
|
-
}
|
|
2170
|
+
});
|
|
2171
|
+
return req;
|
|
2172
|
+
}
|
|
2173
|
+
if (!(method === "GET" || method === "HEAD")) {
|
|
2174
|
+
if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
|
|
2175
|
+
init.body = new ReadableStream({
|
|
2176
|
+
start(controller) {
|
|
2177
|
+
controller.enqueue(incoming.rawBody);
|
|
2178
|
+
controller.close();
|
|
1911
2179
|
}
|
|
1912
|
-
}
|
|
1913
|
-
|
|
1914
|
-
|
|
2180
|
+
});
|
|
2181
|
+
} else if (incoming[wrapBodyStream]) {
|
|
2182
|
+
let reader;
|
|
2183
|
+
init.body = new ReadableStream({
|
|
2184
|
+
async pull(controller) {
|
|
2185
|
+
try {
|
|
2186
|
+
reader ||= Readable.toWeb(incoming).getReader();
|
|
2187
|
+
const { done, value } = await reader.read();
|
|
2188
|
+
if (done) {
|
|
2189
|
+
controller.close();
|
|
2190
|
+
} else {
|
|
2191
|
+
controller.enqueue(value);
|
|
2192
|
+
}
|
|
2193
|
+
} catch (error) {
|
|
2194
|
+
controller.error(error);
|
|
2195
|
+
}
|
|
1915
2196
|
}
|
|
1916
|
-
}
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
}
|
|
1920
|
-
return context;
|
|
2197
|
+
});
|
|
2198
|
+
} else {
|
|
2199
|
+
init.body = Readable.toWeb(incoming);
|
|
1921
2200
|
}
|
|
1922
|
-
};
|
|
1923
|
-
};
|
|
1924
|
-
|
|
1925
|
-
// ../../node_modules/hono/dist/request/constants.js
|
|
1926
|
-
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
1927
|
-
|
|
1928
|
-
// ../../node_modules/hono/dist/utils/body.js
|
|
1929
|
-
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
1930
|
-
const { all = false, dot = false } = options;
|
|
1931
|
-
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
1932
|
-
const contentType = headers.get("Content-Type");
|
|
1933
|
-
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
1934
|
-
return parseFormData(request, { all, dot });
|
|
1935
2201
|
}
|
|
1936
|
-
return
|
|
2202
|
+
return new Request2(url, init);
|
|
1937
2203
|
};
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
2204
|
+
var getRequestCache = Symbol("getRequestCache");
|
|
2205
|
+
var requestCache = Symbol("requestCache");
|
|
2206
|
+
var incomingKey = Symbol("incomingKey");
|
|
2207
|
+
var urlKey = Symbol("urlKey");
|
|
2208
|
+
var headersKey = Symbol("headersKey");
|
|
2209
|
+
var abortControllerKey = Symbol("abortControllerKey");
|
|
2210
|
+
var getAbortController = Symbol("getAbortController");
|
|
2211
|
+
var requestPrototype = {
|
|
2212
|
+
get method() {
|
|
2213
|
+
return this[incomingKey].method || "GET";
|
|
2214
|
+
},
|
|
2215
|
+
get url() {
|
|
2216
|
+
return this[urlKey];
|
|
2217
|
+
},
|
|
2218
|
+
get headers() {
|
|
2219
|
+
return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
|
|
2220
|
+
},
|
|
2221
|
+
[getAbortController]() {
|
|
2222
|
+
this[getRequestCache]();
|
|
2223
|
+
return this[abortControllerKey];
|
|
2224
|
+
},
|
|
2225
|
+
[getRequestCache]() {
|
|
2226
|
+
this[abortControllerKey] ||= new AbortController;
|
|
2227
|
+
return this[requestCache] ||= newRequestFromIncoming(this.method, this[urlKey], this.headers, this[incomingKey], this[abortControllerKey]);
|
|
1942
2228
|
}
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
2229
|
+
};
|
|
2230
|
+
[
|
|
2231
|
+
"body",
|
|
2232
|
+
"bodyUsed",
|
|
2233
|
+
"cache",
|
|
2234
|
+
"credentials",
|
|
2235
|
+
"destination",
|
|
2236
|
+
"integrity",
|
|
2237
|
+
"mode",
|
|
2238
|
+
"redirect",
|
|
2239
|
+
"referrer",
|
|
2240
|
+
"referrerPolicy",
|
|
2241
|
+
"signal",
|
|
2242
|
+
"keepalive"
|
|
2243
|
+
].forEach((k) => {
|
|
2244
|
+
Object.defineProperty(requestPrototype, k, {
|
|
2245
|
+
get() {
|
|
2246
|
+
return this[getRequestCache]()[k];
|
|
1953
2247
|
}
|
|
1954
2248
|
});
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
2249
|
+
});
|
|
2250
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
2251
|
+
Object.defineProperty(requestPrototype, k, {
|
|
2252
|
+
value: function() {
|
|
2253
|
+
return this[getRequestCache]()[k]();
|
|
2254
|
+
}
|
|
2255
|
+
});
|
|
2256
|
+
});
|
|
2257
|
+
Object.setPrototypeOf(requestPrototype, Request2.prototype);
|
|
2258
|
+
var newRequest = (incoming, defaultHostname) => {
|
|
2259
|
+
const req = Object.create(requestPrototype);
|
|
2260
|
+
req[incomingKey] = incoming;
|
|
2261
|
+
const incomingUrl = incoming.url || "";
|
|
2262
|
+
if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
2263
|
+
if (incoming instanceof Http2ServerRequest) {
|
|
2264
|
+
throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
|
|
2265
|
+
}
|
|
2266
|
+
try {
|
|
2267
|
+
const url2 = new URL(incomingUrl);
|
|
2268
|
+
req[urlKey] = url2.href;
|
|
2269
|
+
} catch (e) {
|
|
2270
|
+
throw new RequestError("Invalid absolute URL", { cause: e });
|
|
2271
|
+
}
|
|
2272
|
+
return req;
|
|
1963
2273
|
}
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
2274
|
+
const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
|
|
2275
|
+
if (!host) {
|
|
2276
|
+
throw new RequestError("Missing host header");
|
|
2277
|
+
}
|
|
2278
|
+
let scheme;
|
|
2279
|
+
if (incoming instanceof Http2ServerRequest) {
|
|
2280
|
+
scheme = incoming.scheme;
|
|
2281
|
+
if (!(scheme === "http" || scheme === "https")) {
|
|
2282
|
+
throw new RequestError("Unsupported scheme");
|
|
1972
2283
|
}
|
|
1973
2284
|
} else {
|
|
1974
|
-
|
|
1975
|
-
form[key] = value;
|
|
1976
|
-
} else {
|
|
1977
|
-
form[key] = [value];
|
|
1978
|
-
}
|
|
2285
|
+
scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
|
|
1979
2286
|
}
|
|
2287
|
+
const url = new URL(`${scheme}://${host}${incomingUrl}`);
|
|
2288
|
+
if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
|
|
2289
|
+
throw new RequestError("Invalid host header");
|
|
2290
|
+
}
|
|
2291
|
+
req[urlKey] = url.href;
|
|
2292
|
+
return req;
|
|
1980
2293
|
};
|
|
1981
|
-
var
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
2294
|
+
var responseCache = Symbol("responseCache");
|
|
2295
|
+
var getResponseCache = Symbol("getResponseCache");
|
|
2296
|
+
var cacheKey = Symbol("cache");
|
|
2297
|
+
var GlobalResponse = global.Response;
|
|
2298
|
+
var Response2 = class _Response {
|
|
2299
|
+
#body;
|
|
2300
|
+
#init;
|
|
2301
|
+
[getResponseCache]() {
|
|
2302
|
+
delete this[cacheKey];
|
|
2303
|
+
return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
|
|
2304
|
+
}
|
|
2305
|
+
constructor(body, init) {
|
|
2306
|
+
let headers;
|
|
2307
|
+
this.#body = body;
|
|
2308
|
+
if (init instanceof _Response) {
|
|
2309
|
+
const cachedGlobalResponse = init[responseCache];
|
|
2310
|
+
if (cachedGlobalResponse) {
|
|
2311
|
+
this.#init = cachedGlobalResponse;
|
|
2312
|
+
this[getResponseCache]();
|
|
2313
|
+
return;
|
|
2314
|
+
} else {
|
|
2315
|
+
this.#init = init.#init;
|
|
2316
|
+
headers = new Headers(init.#init.headers);
|
|
2317
|
+
}
|
|
1987
2318
|
} else {
|
|
1988
|
-
|
|
1989
|
-
|
|
2319
|
+
this.#init = init;
|
|
2320
|
+
}
|
|
2321
|
+
if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
|
|
2322
|
+
headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
|
|
2323
|
+
this[cacheKey] = [init?.status || 200, body, headers];
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
get headers() {
|
|
2327
|
+
const cache = this[cacheKey];
|
|
2328
|
+
if (cache) {
|
|
2329
|
+
if (!(cache[2] instanceof Headers)) {
|
|
2330
|
+
cache[2] = new Headers(cache[2]);
|
|
1990
2331
|
}
|
|
1991
|
-
|
|
2332
|
+
return cache[2];
|
|
1992
2333
|
}
|
|
1993
|
-
|
|
1994
|
-
}
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2334
|
+
return this[getResponseCache]().headers;
|
|
2335
|
+
}
|
|
2336
|
+
get status() {
|
|
2337
|
+
return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
|
|
2338
|
+
}
|
|
2339
|
+
get ok() {
|
|
2340
|
+
const status = this.status;
|
|
2341
|
+
return status >= 200 && status < 300;
|
|
2001
2342
|
}
|
|
2002
|
-
return paths;
|
|
2003
2343
|
};
|
|
2004
|
-
|
|
2005
|
-
|
|
2344
|
+
["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
|
|
2345
|
+
Object.defineProperty(Response2.prototype, k, {
|
|
2346
|
+
get() {
|
|
2347
|
+
return this[getResponseCache]()[k];
|
|
2348
|
+
}
|
|
2349
|
+
});
|
|
2350
|
+
});
|
|
2351
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
2352
|
+
Object.defineProperty(Response2.prototype, k, {
|
|
2353
|
+
value: function() {
|
|
2354
|
+
return this[getResponseCache]()[k]();
|
|
2355
|
+
}
|
|
2356
|
+
});
|
|
2357
|
+
});
|
|
2358
|
+
Object.setPrototypeOf(Response2, GlobalResponse);
|
|
2359
|
+
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
|
|
2360
|
+
async function readWithoutBlocking(readPromise) {
|
|
2361
|
+
return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(undefined))]);
|
|
2362
|
+
}
|
|
2363
|
+
function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) {
|
|
2364
|
+
const cancel = (error) => {
|
|
2365
|
+
reader.cancel(error).catch(() => {});
|
|
2366
|
+
};
|
|
2367
|
+
writable.on("close", cancel);
|
|
2368
|
+
writable.on("error", cancel);
|
|
2369
|
+
(currentReadPromise ?? reader.read()).then(flow, handleStreamError);
|
|
2370
|
+
return reader.closed.finally(() => {
|
|
2371
|
+
writable.off("close", cancel);
|
|
2372
|
+
writable.off("error", cancel);
|
|
2373
|
+
});
|
|
2374
|
+
function handleStreamError(error) {
|
|
2375
|
+
if (error) {
|
|
2376
|
+
writable.destroy(error);
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
function onDrain() {
|
|
2380
|
+
reader.read().then(flow, handleStreamError);
|
|
2381
|
+
}
|
|
2382
|
+
function flow({ done, value }) {
|
|
2383
|
+
try {
|
|
2384
|
+
if (done) {
|
|
2385
|
+
writable.end();
|
|
2386
|
+
} else if (!writable.write(value)) {
|
|
2387
|
+
writable.once("drain", onDrain);
|
|
2388
|
+
} else {
|
|
2389
|
+
return reader.read().then(flow, handleStreamError);
|
|
2390
|
+
}
|
|
2391
|
+
} catch (e) {
|
|
2392
|
+
handleStreamError(e);
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
function writeFromReadableStream(stream, writable) {
|
|
2397
|
+
if (stream.locked) {
|
|
2398
|
+
throw new TypeError("ReadableStream is locked.");
|
|
2399
|
+
} else if (writable.destroyed) {
|
|
2400
|
+
return;
|
|
2401
|
+
}
|
|
2402
|
+
return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
|
|
2403
|
+
}
|
|
2404
|
+
var buildOutgoingHttpHeaders = (headers) => {
|
|
2405
|
+
const res = {};
|
|
2406
|
+
if (!(headers instanceof Headers)) {
|
|
2407
|
+
headers = new Headers(headers ?? undefined);
|
|
2408
|
+
}
|
|
2409
|
+
const cookies = [];
|
|
2410
|
+
for (const [k, v] of headers) {
|
|
2411
|
+
if (k === "set-cookie") {
|
|
2412
|
+
cookies.push(v);
|
|
2413
|
+
} else {
|
|
2414
|
+
res[k] = v;
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
if (cookies.length > 0) {
|
|
2418
|
+
res["set-cookie"] = cookies;
|
|
2419
|
+
}
|
|
2420
|
+
res["content-type"] ??= "text/plain; charset=UTF-8";
|
|
2421
|
+
return res;
|
|
2422
|
+
};
|
|
2423
|
+
var X_ALREADY_SENT = "x-hono-already-sent";
|
|
2424
|
+
var webFetch = global.fetch;
|
|
2425
|
+
if (typeof global.crypto === "undefined") {
|
|
2426
|
+
global.crypto = crypto;
|
|
2427
|
+
}
|
|
2428
|
+
global.fetch = (info, init) => {
|
|
2429
|
+
init = {
|
|
2430
|
+
compress: false,
|
|
2431
|
+
...init
|
|
2432
|
+
};
|
|
2433
|
+
return webFetch(info, init);
|
|
2434
|
+
};
|
|
2435
|
+
var outgoingEnded = Symbol("outgoingEnded");
|
|
2436
|
+
var handleRequestError = () => new Response(null, {
|
|
2437
|
+
status: 400
|
|
2438
|
+
});
|
|
2439
|
+
var handleFetchError = (e) => new Response(null, {
|
|
2440
|
+
status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500
|
|
2441
|
+
});
|
|
2442
|
+
var handleResponseError = (e, outgoing) => {
|
|
2443
|
+
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
2444
|
+
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
2445
|
+
console.info("The user aborted a request.");
|
|
2446
|
+
} else {
|
|
2447
|
+
console.error(e);
|
|
2448
|
+
if (!outgoing.headersSent) {
|
|
2449
|
+
outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
2450
|
+
}
|
|
2451
|
+
outgoing.end(`Error: ${err.message}`);
|
|
2452
|
+
outgoing.destroy(err);
|
|
2453
|
+
}
|
|
2454
|
+
};
|
|
2455
|
+
var flushHeaders = (outgoing) => {
|
|
2456
|
+
if ("flushHeaders" in outgoing && outgoing.writable) {
|
|
2457
|
+
outgoing.flushHeaders();
|
|
2458
|
+
}
|
|
2459
|
+
};
|
|
2460
|
+
var responseViaCache = async (res, outgoing) => {
|
|
2461
|
+
let [status, body, header] = res[cacheKey];
|
|
2462
|
+
if (header instanceof Headers) {
|
|
2463
|
+
header = buildOutgoingHttpHeaders(header);
|
|
2464
|
+
}
|
|
2465
|
+
if (typeof body === "string") {
|
|
2466
|
+
header["Content-Length"] = Buffer.byteLength(body);
|
|
2467
|
+
} else if (body instanceof Uint8Array) {
|
|
2468
|
+
header["Content-Length"] = body.byteLength;
|
|
2469
|
+
} else if (body instanceof Blob) {
|
|
2470
|
+
header["Content-Length"] = body.size;
|
|
2471
|
+
}
|
|
2472
|
+
outgoing.writeHead(status, header);
|
|
2473
|
+
if (typeof body === "string" || body instanceof Uint8Array) {
|
|
2474
|
+
outgoing.end(body);
|
|
2475
|
+
} else if (body instanceof Blob) {
|
|
2476
|
+
outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
2477
|
+
} else {
|
|
2478
|
+
flushHeaders(outgoing);
|
|
2479
|
+
await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
|
|
2480
|
+
}
|
|
2481
|
+
outgoing[outgoingEnded]?.();
|
|
2482
|
+
};
|
|
2483
|
+
var isPromise = (res) => typeof res.then === "function";
|
|
2484
|
+
var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
2485
|
+
if (isPromise(res)) {
|
|
2486
|
+
if (options.errorHandler) {
|
|
2487
|
+
try {
|
|
2488
|
+
res = await res;
|
|
2489
|
+
} catch (err) {
|
|
2490
|
+
const errRes = await options.errorHandler(err);
|
|
2491
|
+
if (!errRes) {
|
|
2492
|
+
return;
|
|
2493
|
+
}
|
|
2494
|
+
res = errRes;
|
|
2495
|
+
}
|
|
2496
|
+
} else {
|
|
2497
|
+
res = await res.catch(handleFetchError);
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
if (cacheKey in res) {
|
|
2501
|
+
return responseViaCache(res, outgoing);
|
|
2502
|
+
}
|
|
2503
|
+
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
2504
|
+
if (res.body) {
|
|
2505
|
+
const reader = res.body.getReader();
|
|
2506
|
+
const values = [];
|
|
2507
|
+
let done = false;
|
|
2508
|
+
let currentReadPromise = undefined;
|
|
2509
|
+
if (resHeaderRecord["transfer-encoding"] !== "chunked") {
|
|
2510
|
+
let maxReadCount = 2;
|
|
2511
|
+
for (let i = 0;i < maxReadCount; i++) {
|
|
2512
|
+
currentReadPromise ||= reader.read();
|
|
2513
|
+
const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
|
|
2514
|
+
console.error(e);
|
|
2515
|
+
done = true;
|
|
2516
|
+
});
|
|
2517
|
+
if (!chunk) {
|
|
2518
|
+
if (i === 1) {
|
|
2519
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
2520
|
+
maxReadCount = 3;
|
|
2521
|
+
continue;
|
|
2522
|
+
}
|
|
2523
|
+
break;
|
|
2524
|
+
}
|
|
2525
|
+
currentReadPromise = undefined;
|
|
2526
|
+
if (chunk.value) {
|
|
2527
|
+
values.push(chunk.value);
|
|
2528
|
+
}
|
|
2529
|
+
if (chunk.done) {
|
|
2530
|
+
done = true;
|
|
2531
|
+
break;
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
if (done && !("content-length" in resHeaderRecord)) {
|
|
2535
|
+
resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
2539
|
+
values.forEach((value) => {
|
|
2540
|
+
outgoing.write(value);
|
|
2541
|
+
});
|
|
2542
|
+
if (done) {
|
|
2543
|
+
outgoing.end();
|
|
2544
|
+
} else {
|
|
2545
|
+
if (values.length === 0) {
|
|
2546
|
+
flushHeaders(outgoing);
|
|
2547
|
+
}
|
|
2548
|
+
await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
|
|
2549
|
+
}
|
|
2550
|
+
} else if (resHeaderRecord[X_ALREADY_SENT]) {} else {
|
|
2551
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
2552
|
+
outgoing.end();
|
|
2553
|
+
}
|
|
2554
|
+
outgoing[outgoingEnded]?.();
|
|
2555
|
+
};
|
|
2556
|
+
var getRequestListener = (fetchCallback, options = {}) => {
|
|
2557
|
+
const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
|
|
2558
|
+
if (options.overrideGlobalObjects !== false && global.Request !== Request2) {
|
|
2559
|
+
Object.defineProperty(global, "Request", {
|
|
2560
|
+
value: Request2
|
|
2561
|
+
});
|
|
2562
|
+
Object.defineProperty(global, "Response", {
|
|
2563
|
+
value: Response2
|
|
2564
|
+
});
|
|
2565
|
+
}
|
|
2566
|
+
return async (incoming, outgoing) => {
|
|
2567
|
+
let res, req;
|
|
2568
|
+
try {
|
|
2569
|
+
req = newRequest(incoming, options.hostname);
|
|
2570
|
+
let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD";
|
|
2571
|
+
if (!incomingEnded) {
|
|
2572
|
+
incoming[wrapBodyStream] = true;
|
|
2573
|
+
incoming.on("end", () => {
|
|
2574
|
+
incomingEnded = true;
|
|
2575
|
+
});
|
|
2576
|
+
if (incoming instanceof Http2ServerRequest2) {
|
|
2577
|
+
outgoing[outgoingEnded] = () => {
|
|
2578
|
+
if (!incomingEnded) {
|
|
2579
|
+
setTimeout(() => {
|
|
2580
|
+
if (!incomingEnded) {
|
|
2581
|
+
setTimeout(() => {
|
|
2582
|
+
incoming.destroy();
|
|
2583
|
+
outgoing.destroy();
|
|
2584
|
+
});
|
|
2585
|
+
}
|
|
2586
|
+
});
|
|
2587
|
+
}
|
|
2588
|
+
};
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
outgoing.on("close", () => {
|
|
2592
|
+
const abortController = req[abortControllerKey];
|
|
2593
|
+
if (abortController) {
|
|
2594
|
+
if (incoming.errored) {
|
|
2595
|
+
req[abortControllerKey].abort(incoming.errored.toString());
|
|
2596
|
+
} else if (!outgoing.writableFinished) {
|
|
2597
|
+
req[abortControllerKey].abort("Client connection prematurely closed.");
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
if (!incomingEnded) {
|
|
2601
|
+
setTimeout(() => {
|
|
2602
|
+
if (!incomingEnded) {
|
|
2603
|
+
setTimeout(() => {
|
|
2604
|
+
incoming.destroy();
|
|
2605
|
+
});
|
|
2606
|
+
}
|
|
2607
|
+
});
|
|
2608
|
+
}
|
|
2609
|
+
});
|
|
2610
|
+
res = fetchCallback(req, { incoming, outgoing });
|
|
2611
|
+
if (cacheKey in res) {
|
|
2612
|
+
return responseViaCache(res, outgoing);
|
|
2613
|
+
}
|
|
2614
|
+
} catch (e) {
|
|
2615
|
+
if (!res) {
|
|
2616
|
+
if (options.errorHandler) {
|
|
2617
|
+
res = await options.errorHandler(req ? e : toRequestError(e));
|
|
2618
|
+
if (!res) {
|
|
2619
|
+
return;
|
|
2620
|
+
}
|
|
2621
|
+
} else if (!req) {
|
|
2622
|
+
res = handleRequestError();
|
|
2623
|
+
} else {
|
|
2624
|
+
res = handleFetchError(e);
|
|
2625
|
+
}
|
|
2626
|
+
} else {
|
|
2627
|
+
return handleResponseError(e, outgoing);
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
try {
|
|
2631
|
+
return await responseViaResponseObject(res, outgoing, options);
|
|
2632
|
+
} catch (e) {
|
|
2633
|
+
return handleResponseError(e, outgoing);
|
|
2634
|
+
}
|
|
2635
|
+
};
|
|
2636
|
+
};
|
|
2637
|
+
var createAdaptorServer = (options) => {
|
|
2638
|
+
const fetchCallback = options.fetch;
|
|
2639
|
+
const requestListener = getRequestListener(fetchCallback, {
|
|
2640
|
+
hostname: options.hostname,
|
|
2641
|
+
overrideGlobalObjects: options.overrideGlobalObjects,
|
|
2642
|
+
autoCleanupIncoming: options.autoCleanupIncoming
|
|
2643
|
+
});
|
|
2644
|
+
const createServer = options.createServer || createServerHTTP;
|
|
2645
|
+
const server = createServer(options.serverOptions || {}, requestListener);
|
|
2646
|
+
return server;
|
|
2647
|
+
};
|
|
2648
|
+
var serve = (options, listeningListener) => {
|
|
2649
|
+
const server = createAdaptorServer(options);
|
|
2650
|
+
server.listen(options?.port ?? 3000, options.hostname, () => {
|
|
2651
|
+
const serverInfo = server.address();
|
|
2652
|
+
listeningListener && listeningListener(serverInfo);
|
|
2653
|
+
});
|
|
2654
|
+
return server;
|
|
2655
|
+
};
|
|
2656
|
+
|
|
2657
|
+
// src/index.ts
|
|
2658
|
+
import { spawn } from "child_process";
|
|
2659
|
+
|
|
2660
|
+
// ../../node_modules/commander/esm.mjs
|
|
2661
|
+
var import__ = __toESM(require_commander(), 1);
|
|
2662
|
+
var {
|
|
2663
|
+
program,
|
|
2664
|
+
createCommand,
|
|
2665
|
+
createArgument,
|
|
2666
|
+
createOption,
|
|
2667
|
+
CommanderError,
|
|
2668
|
+
InvalidArgumentError,
|
|
2669
|
+
InvalidOptionArgumentError,
|
|
2670
|
+
Command,
|
|
2671
|
+
Argument,
|
|
2672
|
+
Option,
|
|
2673
|
+
Help
|
|
2674
|
+
} = import__.default;
|
|
2675
|
+
|
|
2676
|
+
// ../../node_modules/hono/dist/utils/mime.js
|
|
2677
|
+
var getMimeType = (filename, mimes = baseMimes) => {
|
|
2678
|
+
const regexp = /\.([a-zA-Z0-9]+?)$/;
|
|
2679
|
+
const match = filename.match(regexp);
|
|
2680
|
+
if (!match) {
|
|
2681
|
+
return;
|
|
2682
|
+
}
|
|
2683
|
+
let mimeType = mimes[match[1]];
|
|
2684
|
+
if (mimeType && mimeType.startsWith("text")) {
|
|
2685
|
+
mimeType += "; charset=utf-8";
|
|
2686
|
+
}
|
|
2687
|
+
return mimeType;
|
|
2688
|
+
};
|
|
2689
|
+
var _baseMimes = {
|
|
2690
|
+
aac: "audio/aac",
|
|
2691
|
+
avi: "video/x-msvideo",
|
|
2692
|
+
avif: "image/avif",
|
|
2693
|
+
av1: "video/av1",
|
|
2694
|
+
bin: "application/octet-stream",
|
|
2695
|
+
bmp: "image/bmp",
|
|
2696
|
+
css: "text/css",
|
|
2697
|
+
csv: "text/csv",
|
|
2698
|
+
eot: "application/vnd.ms-fontobject",
|
|
2699
|
+
epub: "application/epub+zip",
|
|
2700
|
+
gif: "image/gif",
|
|
2701
|
+
gz: "application/gzip",
|
|
2702
|
+
htm: "text/html",
|
|
2703
|
+
html: "text/html",
|
|
2704
|
+
ico: "image/x-icon",
|
|
2705
|
+
ics: "text/calendar",
|
|
2706
|
+
jpeg: "image/jpeg",
|
|
2707
|
+
jpg: "image/jpeg",
|
|
2708
|
+
js: "text/javascript",
|
|
2709
|
+
json: "application/json",
|
|
2710
|
+
jsonld: "application/ld+json",
|
|
2711
|
+
map: "application/json",
|
|
2712
|
+
mid: "audio/x-midi",
|
|
2713
|
+
midi: "audio/x-midi",
|
|
2714
|
+
mjs: "text/javascript",
|
|
2715
|
+
mp3: "audio/mpeg",
|
|
2716
|
+
mp4: "video/mp4",
|
|
2717
|
+
mpeg: "video/mpeg",
|
|
2718
|
+
oga: "audio/ogg",
|
|
2719
|
+
ogv: "video/ogg",
|
|
2720
|
+
ogx: "application/ogg",
|
|
2721
|
+
opus: "audio/opus",
|
|
2722
|
+
otf: "font/otf",
|
|
2723
|
+
pdf: "application/pdf",
|
|
2724
|
+
png: "image/png",
|
|
2725
|
+
rtf: "application/rtf",
|
|
2726
|
+
svg: "image/svg+xml",
|
|
2727
|
+
tif: "image/tiff",
|
|
2728
|
+
tiff: "image/tiff",
|
|
2729
|
+
ts: "video/mp2t",
|
|
2730
|
+
ttf: "font/ttf",
|
|
2731
|
+
txt: "text/plain",
|
|
2732
|
+
wasm: "application/wasm",
|
|
2733
|
+
webm: "video/webm",
|
|
2734
|
+
weba: "audio/webm",
|
|
2735
|
+
webmanifest: "application/manifest+json",
|
|
2736
|
+
webp: "image/webp",
|
|
2737
|
+
woff: "font/woff",
|
|
2738
|
+
woff2: "font/woff2",
|
|
2739
|
+
xhtml: "application/xhtml+xml",
|
|
2740
|
+
xml: "application/xml",
|
|
2741
|
+
zip: "application/zip",
|
|
2742
|
+
"3gp": "video/3gpp",
|
|
2743
|
+
"3g2": "video/3gpp2",
|
|
2744
|
+
gltf: "model/gltf+json",
|
|
2745
|
+
glb: "model/gltf-binary"
|
|
2746
|
+
};
|
|
2747
|
+
var baseMimes = _baseMimes;
|
|
2748
|
+
|
|
2749
|
+
// ../../node_modules/@hono/node-server/dist/serve-static.mjs
|
|
2750
|
+
import { createReadStream, statSync, existsSync } from "fs";
|
|
2751
|
+
import { join } from "path";
|
|
2752
|
+
import { versions } from "process";
|
|
2753
|
+
import { Readable as Readable2 } from "stream";
|
|
2754
|
+
var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
2755
|
+
var ENCODINGS = {
|
|
2756
|
+
br: ".br",
|
|
2757
|
+
zstd: ".zst",
|
|
2758
|
+
gzip: ".gz"
|
|
2759
|
+
};
|
|
2760
|
+
var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
2761
|
+
var pr54206Applied = () => {
|
|
2762
|
+
const [major, minor] = versions.node.split(".").map((component) => parseInt(component));
|
|
2763
|
+
return major >= 23 || major === 22 && minor >= 7 || major === 20 && minor >= 18;
|
|
2764
|
+
};
|
|
2765
|
+
var useReadableToWeb = pr54206Applied();
|
|
2766
|
+
var createStreamBody = (stream) => {
|
|
2767
|
+
if (useReadableToWeb) {
|
|
2768
|
+
return Readable2.toWeb(stream);
|
|
2769
|
+
}
|
|
2770
|
+
const body = new ReadableStream({
|
|
2771
|
+
start(controller) {
|
|
2772
|
+
stream.on("data", (chunk) => {
|
|
2773
|
+
controller.enqueue(chunk);
|
|
2774
|
+
});
|
|
2775
|
+
stream.on("error", (err) => {
|
|
2776
|
+
controller.error(err);
|
|
2777
|
+
});
|
|
2778
|
+
stream.on("end", () => {
|
|
2779
|
+
controller.close();
|
|
2780
|
+
});
|
|
2781
|
+
},
|
|
2782
|
+
cancel() {
|
|
2783
|
+
stream.destroy();
|
|
2784
|
+
}
|
|
2785
|
+
});
|
|
2786
|
+
return body;
|
|
2787
|
+
};
|
|
2788
|
+
var getStats = (path) => {
|
|
2789
|
+
let stats;
|
|
2790
|
+
try {
|
|
2791
|
+
stats = statSync(path);
|
|
2792
|
+
} catch {}
|
|
2793
|
+
return stats;
|
|
2794
|
+
};
|
|
2795
|
+
var serveStatic = (options = { root: "" }) => {
|
|
2796
|
+
const root = options.root || "";
|
|
2797
|
+
const optionPath = options.path;
|
|
2798
|
+
if (root !== "" && !existsSync(root)) {
|
|
2799
|
+
console.error(`serveStatic: root path '${root}' is not found, are you sure it's correct?`);
|
|
2800
|
+
}
|
|
2801
|
+
return async (c, next) => {
|
|
2802
|
+
if (c.finalized) {
|
|
2803
|
+
return next();
|
|
2804
|
+
}
|
|
2805
|
+
let filename;
|
|
2806
|
+
if (optionPath) {
|
|
2807
|
+
filename = optionPath;
|
|
2808
|
+
} else {
|
|
2809
|
+
try {
|
|
2810
|
+
filename = decodeURIComponent(c.req.path);
|
|
2811
|
+
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
|
|
2812
|
+
throw new Error;
|
|
2813
|
+
}
|
|
2814
|
+
} catch {
|
|
2815
|
+
await options.onNotFound?.(c.req.path, c);
|
|
2816
|
+
return next();
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
let path = join(root, !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename);
|
|
2820
|
+
let stats = getStats(path);
|
|
2821
|
+
if (stats && stats.isDirectory()) {
|
|
2822
|
+
const indexFile = options.index ?? "index.html";
|
|
2823
|
+
path = join(path, indexFile);
|
|
2824
|
+
stats = getStats(path);
|
|
2825
|
+
}
|
|
2826
|
+
if (!stats) {
|
|
2827
|
+
await options.onNotFound?.(path, c);
|
|
2828
|
+
return next();
|
|
2829
|
+
}
|
|
2830
|
+
const mimeType = getMimeType(path);
|
|
2831
|
+
c.header("Content-Type", mimeType || "application/octet-stream");
|
|
2832
|
+
if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
2833
|
+
const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim()));
|
|
2834
|
+
for (const encoding of ENCODINGS_ORDERED_KEYS) {
|
|
2835
|
+
if (!acceptEncodingSet.has(encoding)) {
|
|
2836
|
+
continue;
|
|
2837
|
+
}
|
|
2838
|
+
const precompressedStats = getStats(path + ENCODINGS[encoding]);
|
|
2839
|
+
if (precompressedStats) {
|
|
2840
|
+
c.header("Content-Encoding", encoding);
|
|
2841
|
+
c.header("Vary", "Accept-Encoding", { append: true });
|
|
2842
|
+
stats = precompressedStats;
|
|
2843
|
+
path = path + ENCODINGS[encoding];
|
|
2844
|
+
break;
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
let result;
|
|
2849
|
+
const size = stats.size;
|
|
2850
|
+
const range = c.req.header("range") || "";
|
|
2851
|
+
if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
|
|
2852
|
+
c.header("Content-Length", size.toString());
|
|
2853
|
+
c.status(200);
|
|
2854
|
+
result = c.body(null);
|
|
2855
|
+
} else if (!range) {
|
|
2856
|
+
c.header("Content-Length", size.toString());
|
|
2857
|
+
result = c.body(createStreamBody(createReadStream(path)), 200);
|
|
2858
|
+
} else {
|
|
2859
|
+
c.header("Accept-Ranges", "bytes");
|
|
2860
|
+
c.header("Date", stats.birthtime.toUTCString());
|
|
2861
|
+
const parts = range.replace(/bytes=/, "").split("-", 2);
|
|
2862
|
+
const start = parseInt(parts[0], 10) || 0;
|
|
2863
|
+
let end = parseInt(parts[1], 10) || size - 1;
|
|
2864
|
+
if (size < end - start + 1) {
|
|
2865
|
+
end = size - 1;
|
|
2866
|
+
}
|
|
2867
|
+
const chunksize = end - start + 1;
|
|
2868
|
+
const stream = createReadStream(path, { start, end });
|
|
2869
|
+
c.header("Content-Length", chunksize.toString());
|
|
2870
|
+
c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
|
2871
|
+
result = c.body(createStreamBody(stream), 206);
|
|
2872
|
+
}
|
|
2873
|
+
await options.onFound?.(path, c);
|
|
2874
|
+
return result;
|
|
2875
|
+
};
|
|
2876
|
+
};
|
|
2877
|
+
|
|
2878
|
+
// src/server.ts
|
|
2879
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
2880
|
+
|
|
2881
|
+
// ../../node_modules/hono/dist/compose.js
|
|
2882
|
+
var compose = (middleware, onError, onNotFound) => {
|
|
2883
|
+
return (context, next) => {
|
|
2884
|
+
let index = -1;
|
|
2885
|
+
return dispatch(0);
|
|
2886
|
+
async function dispatch(i) {
|
|
2887
|
+
if (i <= index) {
|
|
2888
|
+
throw new Error("next() called multiple times");
|
|
2889
|
+
}
|
|
2890
|
+
index = i;
|
|
2891
|
+
let res;
|
|
2892
|
+
let isError = false;
|
|
2893
|
+
let handler;
|
|
2894
|
+
if (middleware[i]) {
|
|
2895
|
+
handler = middleware[i][0][0];
|
|
2896
|
+
context.req.routeIndex = i;
|
|
2897
|
+
} else {
|
|
2898
|
+
handler = i === middleware.length && next || undefined;
|
|
2899
|
+
}
|
|
2900
|
+
if (handler) {
|
|
2901
|
+
try {
|
|
2902
|
+
res = await handler(context, () => dispatch(i + 1));
|
|
2903
|
+
} catch (err) {
|
|
2904
|
+
if (err instanceof Error && onError) {
|
|
2905
|
+
context.error = err;
|
|
2906
|
+
res = await onError(err, context);
|
|
2907
|
+
isError = true;
|
|
2908
|
+
} else {
|
|
2909
|
+
throw err;
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
} else {
|
|
2913
|
+
if (context.finalized === false && onNotFound) {
|
|
2914
|
+
res = await onNotFound(context);
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
if (res && (context.finalized === false || isError)) {
|
|
2918
|
+
context.res = res;
|
|
2919
|
+
}
|
|
2920
|
+
return context;
|
|
2921
|
+
}
|
|
2922
|
+
};
|
|
2923
|
+
};
|
|
2924
|
+
|
|
2925
|
+
// ../../node_modules/hono/dist/request/constants.js
|
|
2926
|
+
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
2927
|
+
|
|
2928
|
+
// ../../node_modules/hono/dist/utils/body.js
|
|
2929
|
+
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
2930
|
+
const { all = false, dot = false } = options;
|
|
2931
|
+
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
2932
|
+
const contentType = headers.get("Content-Type");
|
|
2933
|
+
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
2934
|
+
return parseFormData(request, { all, dot });
|
|
2935
|
+
}
|
|
2936
|
+
return {};
|
|
2937
|
+
};
|
|
2938
|
+
async function parseFormData(request, options) {
|
|
2939
|
+
const formData = await request.formData();
|
|
2940
|
+
if (formData) {
|
|
2941
|
+
return convertFormDataToBodyData(formData, options);
|
|
2942
|
+
}
|
|
2943
|
+
return {};
|
|
2944
|
+
}
|
|
2945
|
+
function convertFormDataToBodyData(formData, options) {
|
|
2946
|
+
const form = /* @__PURE__ */ Object.create(null);
|
|
2947
|
+
formData.forEach((value, key) => {
|
|
2948
|
+
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
2949
|
+
if (!shouldParseAllValues) {
|
|
2950
|
+
form[key] = value;
|
|
2951
|
+
} else {
|
|
2952
|
+
handleParsingAllValues(form, key, value);
|
|
2953
|
+
}
|
|
2954
|
+
});
|
|
2955
|
+
if (options.dot) {
|
|
2956
|
+
Object.entries(form).forEach(([key, value]) => {
|
|
2957
|
+
const shouldParseDotValues = key.includes(".");
|
|
2958
|
+
if (shouldParseDotValues) {
|
|
2959
|
+
handleParsingNestedValues(form, key, value);
|
|
2960
|
+
delete form[key];
|
|
2961
|
+
}
|
|
2962
|
+
});
|
|
2963
|
+
}
|
|
2964
|
+
return form;
|
|
2965
|
+
}
|
|
2966
|
+
var handleParsingAllValues = (form, key, value) => {
|
|
2967
|
+
if (form[key] !== undefined) {
|
|
2968
|
+
if (Array.isArray(form[key])) {
|
|
2969
|
+
form[key].push(value);
|
|
2970
|
+
} else {
|
|
2971
|
+
form[key] = [form[key], value];
|
|
2972
|
+
}
|
|
2973
|
+
} else {
|
|
2974
|
+
if (!key.endsWith("[]")) {
|
|
2975
|
+
form[key] = value;
|
|
2976
|
+
} else {
|
|
2977
|
+
form[key] = [value];
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
};
|
|
2981
|
+
var handleParsingNestedValues = (form, key, value) => {
|
|
2982
|
+
let nestedForm = form;
|
|
2983
|
+
const keys = key.split(".");
|
|
2984
|
+
keys.forEach((key2, index) => {
|
|
2985
|
+
if (index === keys.length - 1) {
|
|
2986
|
+
nestedForm[key2] = value;
|
|
2987
|
+
} else {
|
|
2988
|
+
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
2989
|
+
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
2990
|
+
}
|
|
2991
|
+
nestedForm = nestedForm[key2];
|
|
2992
|
+
}
|
|
2993
|
+
});
|
|
2994
|
+
};
|
|
2995
|
+
|
|
2996
|
+
// ../../node_modules/hono/dist/utils/url.js
|
|
2997
|
+
var splitPath = (path) => {
|
|
2998
|
+
const paths = path.split("/");
|
|
2999
|
+
if (paths[0] === "") {
|
|
3000
|
+
paths.shift();
|
|
3001
|
+
}
|
|
3002
|
+
return paths;
|
|
3003
|
+
};
|
|
3004
|
+
var splitRoutingPath = (routePath) => {
|
|
3005
|
+
const { groups, path } = extractGroupsFromPath(routePath);
|
|
2006
3006
|
const paths = splitPath(path);
|
|
2007
3007
|
return replaceGroupMarks(paths, groups);
|
|
2008
3008
|
};
|
|
@@ -2034,15 +3034,15 @@ var getPattern = (label, next) => {
|
|
|
2034
3034
|
}
|
|
2035
3035
|
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
2036
3036
|
if (match) {
|
|
2037
|
-
const
|
|
2038
|
-
if (!patternCache[
|
|
3037
|
+
const cacheKey2 = `${label}#${next}`;
|
|
3038
|
+
if (!patternCache[cacheKey2]) {
|
|
2039
3039
|
if (match[2]) {
|
|
2040
|
-
patternCache[
|
|
3040
|
+
patternCache[cacheKey2] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey2, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)];
|
|
2041
3041
|
} else {
|
|
2042
|
-
patternCache[
|
|
3042
|
+
patternCache[cacheKey2] = [label, match[1], true];
|
|
2043
3043
|
}
|
|
2044
3044
|
}
|
|
2045
|
-
return patternCache[
|
|
3045
|
+
return patternCache[cacheKey2];
|
|
2046
3046
|
}
|
|
2047
3047
|
return null;
|
|
2048
3048
|
};
|
|
@@ -3395,277 +4395,6 @@ var Hono2 = class extends Hono {
|
|
|
3395
4395
|
}
|
|
3396
4396
|
};
|
|
3397
4397
|
|
|
3398
|
-
// ../../node_modules/hono/dist/adapter/bun/serve-static.js
|
|
3399
|
-
import { stat } from "node:fs/promises";
|
|
3400
|
-
import { join } from "node:path";
|
|
3401
|
-
|
|
3402
|
-
// ../../node_modules/hono/dist/utils/compress.js
|
|
3403
|
-
var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
3404
|
-
|
|
3405
|
-
// ../../node_modules/hono/dist/utils/mime.js
|
|
3406
|
-
var getMimeType = (filename, mimes = baseMimes) => {
|
|
3407
|
-
const regexp = /\.([a-zA-Z0-9]+?)$/;
|
|
3408
|
-
const match2 = filename.match(regexp);
|
|
3409
|
-
if (!match2) {
|
|
3410
|
-
return;
|
|
3411
|
-
}
|
|
3412
|
-
let mimeType = mimes[match2[1]];
|
|
3413
|
-
if (mimeType && mimeType.startsWith("text")) {
|
|
3414
|
-
mimeType += "; charset=utf-8";
|
|
3415
|
-
}
|
|
3416
|
-
return mimeType;
|
|
3417
|
-
};
|
|
3418
|
-
var _baseMimes = {
|
|
3419
|
-
aac: "audio/aac",
|
|
3420
|
-
avi: "video/x-msvideo",
|
|
3421
|
-
avif: "image/avif",
|
|
3422
|
-
av1: "video/av1",
|
|
3423
|
-
bin: "application/octet-stream",
|
|
3424
|
-
bmp: "image/bmp",
|
|
3425
|
-
css: "text/css",
|
|
3426
|
-
csv: "text/csv",
|
|
3427
|
-
eot: "application/vnd.ms-fontobject",
|
|
3428
|
-
epub: "application/epub+zip",
|
|
3429
|
-
gif: "image/gif",
|
|
3430
|
-
gz: "application/gzip",
|
|
3431
|
-
htm: "text/html",
|
|
3432
|
-
html: "text/html",
|
|
3433
|
-
ico: "image/x-icon",
|
|
3434
|
-
ics: "text/calendar",
|
|
3435
|
-
jpeg: "image/jpeg",
|
|
3436
|
-
jpg: "image/jpeg",
|
|
3437
|
-
js: "text/javascript",
|
|
3438
|
-
json: "application/json",
|
|
3439
|
-
jsonld: "application/ld+json",
|
|
3440
|
-
map: "application/json",
|
|
3441
|
-
mid: "audio/x-midi",
|
|
3442
|
-
midi: "audio/x-midi",
|
|
3443
|
-
mjs: "text/javascript",
|
|
3444
|
-
mp3: "audio/mpeg",
|
|
3445
|
-
mp4: "video/mp4",
|
|
3446
|
-
mpeg: "video/mpeg",
|
|
3447
|
-
oga: "audio/ogg",
|
|
3448
|
-
ogv: "video/ogg",
|
|
3449
|
-
ogx: "application/ogg",
|
|
3450
|
-
opus: "audio/opus",
|
|
3451
|
-
otf: "font/otf",
|
|
3452
|
-
pdf: "application/pdf",
|
|
3453
|
-
png: "image/png",
|
|
3454
|
-
rtf: "application/rtf",
|
|
3455
|
-
svg: "image/svg+xml",
|
|
3456
|
-
tif: "image/tiff",
|
|
3457
|
-
tiff: "image/tiff",
|
|
3458
|
-
ts: "video/mp2t",
|
|
3459
|
-
ttf: "font/ttf",
|
|
3460
|
-
txt: "text/plain",
|
|
3461
|
-
wasm: "application/wasm",
|
|
3462
|
-
webm: "video/webm",
|
|
3463
|
-
weba: "audio/webm",
|
|
3464
|
-
webmanifest: "application/manifest+json",
|
|
3465
|
-
webp: "image/webp",
|
|
3466
|
-
woff: "font/woff",
|
|
3467
|
-
woff2: "font/woff2",
|
|
3468
|
-
xhtml: "application/xhtml+xml",
|
|
3469
|
-
xml: "application/xml",
|
|
3470
|
-
zip: "application/zip",
|
|
3471
|
-
"3gp": "video/3gpp",
|
|
3472
|
-
"3g2": "video/3gpp2",
|
|
3473
|
-
gltf: "model/gltf+json",
|
|
3474
|
-
glb: "model/gltf-binary"
|
|
3475
|
-
};
|
|
3476
|
-
var baseMimes = _baseMimes;
|
|
3477
|
-
|
|
3478
|
-
// ../../node_modules/hono/dist/middleware/serve-static/path.js
|
|
3479
|
-
var defaultJoin = (...paths) => {
|
|
3480
|
-
let result = paths.filter((p) => p !== "").join("/");
|
|
3481
|
-
result = result.replace(/(?<=\/)\/+/g, "");
|
|
3482
|
-
const segments = result.split("/");
|
|
3483
|
-
const resolved = [];
|
|
3484
|
-
for (const segment of segments) {
|
|
3485
|
-
if (segment === ".." && resolved.length > 0 && resolved.at(-1) !== "..") {
|
|
3486
|
-
resolved.pop();
|
|
3487
|
-
} else if (segment !== ".") {
|
|
3488
|
-
resolved.push(segment);
|
|
3489
|
-
}
|
|
3490
|
-
}
|
|
3491
|
-
return resolved.join("/") || ".";
|
|
3492
|
-
};
|
|
3493
|
-
|
|
3494
|
-
// ../../node_modules/hono/dist/middleware/serve-static/index.js
|
|
3495
|
-
var ENCODINGS = {
|
|
3496
|
-
br: ".br",
|
|
3497
|
-
zstd: ".zst",
|
|
3498
|
-
gzip: ".gz"
|
|
3499
|
-
};
|
|
3500
|
-
var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
3501
|
-
var DEFAULT_DOCUMENT = "index.html";
|
|
3502
|
-
var serveStatic = (options) => {
|
|
3503
|
-
const root = options.root ?? "./";
|
|
3504
|
-
const optionPath = options.path;
|
|
3505
|
-
const join = options.join ?? defaultJoin;
|
|
3506
|
-
return async (c, next) => {
|
|
3507
|
-
if (c.finalized) {
|
|
3508
|
-
return next();
|
|
3509
|
-
}
|
|
3510
|
-
let filename;
|
|
3511
|
-
if (options.path) {
|
|
3512
|
-
filename = options.path;
|
|
3513
|
-
} else {
|
|
3514
|
-
try {
|
|
3515
|
-
filename = decodeURIComponent(c.req.path);
|
|
3516
|
-
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
|
|
3517
|
-
throw new Error;
|
|
3518
|
-
}
|
|
3519
|
-
} catch {
|
|
3520
|
-
await options.onNotFound?.(c.req.path, c);
|
|
3521
|
-
return next();
|
|
3522
|
-
}
|
|
3523
|
-
}
|
|
3524
|
-
let path = join(root, !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename);
|
|
3525
|
-
if (options.isDir && await options.isDir(path)) {
|
|
3526
|
-
path = join(path, DEFAULT_DOCUMENT);
|
|
3527
|
-
}
|
|
3528
|
-
const getContent = options.getContent;
|
|
3529
|
-
let content = await getContent(path, c);
|
|
3530
|
-
if (content instanceof Response) {
|
|
3531
|
-
return c.newResponse(content.body, content);
|
|
3532
|
-
}
|
|
3533
|
-
if (content) {
|
|
3534
|
-
const mimeType = options.mimes && getMimeType(path, options.mimes) || getMimeType(path);
|
|
3535
|
-
c.header("Content-Type", mimeType || "application/octet-stream");
|
|
3536
|
-
if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
3537
|
-
const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim()));
|
|
3538
|
-
for (const encoding of ENCODINGS_ORDERED_KEYS) {
|
|
3539
|
-
if (!acceptEncodingSet.has(encoding)) {
|
|
3540
|
-
continue;
|
|
3541
|
-
}
|
|
3542
|
-
const compressedContent = await getContent(path + ENCODINGS[encoding], c);
|
|
3543
|
-
if (compressedContent) {
|
|
3544
|
-
content = compressedContent;
|
|
3545
|
-
c.header("Content-Encoding", encoding);
|
|
3546
|
-
c.header("Vary", "Accept-Encoding", { append: true });
|
|
3547
|
-
break;
|
|
3548
|
-
}
|
|
3549
|
-
}
|
|
3550
|
-
}
|
|
3551
|
-
await options.onFound?.(path, c);
|
|
3552
|
-
return c.body(content);
|
|
3553
|
-
}
|
|
3554
|
-
await options.onNotFound?.(path, c);
|
|
3555
|
-
await next();
|
|
3556
|
-
return;
|
|
3557
|
-
};
|
|
3558
|
-
};
|
|
3559
|
-
|
|
3560
|
-
// ../../node_modules/hono/dist/adapter/bun/serve-static.js
|
|
3561
|
-
var serveStatic2 = (options) => {
|
|
3562
|
-
return async function serveStatic2(c, next) {
|
|
3563
|
-
const getContent = async (path) => {
|
|
3564
|
-
const file = Bun.file(path);
|
|
3565
|
-
return await file.exists() ? file : null;
|
|
3566
|
-
};
|
|
3567
|
-
const isDir = async (path) => {
|
|
3568
|
-
let isDir2;
|
|
3569
|
-
try {
|
|
3570
|
-
const stats = await stat(path);
|
|
3571
|
-
isDir2 = stats.isDirectory();
|
|
3572
|
-
} catch {}
|
|
3573
|
-
return isDir2;
|
|
3574
|
-
};
|
|
3575
|
-
return serveStatic({
|
|
3576
|
-
...options,
|
|
3577
|
-
getContent,
|
|
3578
|
-
join,
|
|
3579
|
-
isDir
|
|
3580
|
-
})(c, next);
|
|
3581
|
-
};
|
|
3582
|
-
};
|
|
3583
|
-
|
|
3584
|
-
// ../../node_modules/hono/dist/helper/ssg/middleware.js
|
|
3585
|
-
var X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
|
|
3586
|
-
var SSG_DISABLED_RESPONSE = (() => {
|
|
3587
|
-
try {
|
|
3588
|
-
return new Response("SSG is disabled", {
|
|
3589
|
-
status: 404,
|
|
3590
|
-
headers: { [X_HONO_DISABLE_SSG_HEADER_KEY]: "true" }
|
|
3591
|
-
});
|
|
3592
|
-
} catch {
|
|
3593
|
-
return null;
|
|
3594
|
-
}
|
|
3595
|
-
})();
|
|
3596
|
-
// ../../node_modules/hono/dist/adapter/bun/ssg.js
|
|
3597
|
-
var { write } = Bun;
|
|
3598
|
-
|
|
3599
|
-
// ../../node_modules/hono/dist/helper/websocket/index.js
|
|
3600
|
-
var WSContext = class {
|
|
3601
|
-
#init;
|
|
3602
|
-
constructor(init) {
|
|
3603
|
-
this.#init = init;
|
|
3604
|
-
this.raw = init.raw;
|
|
3605
|
-
this.url = init.url ? new URL(init.url) : null;
|
|
3606
|
-
this.protocol = init.protocol ?? null;
|
|
3607
|
-
}
|
|
3608
|
-
send(source, options) {
|
|
3609
|
-
this.#init.send(source, options ?? {});
|
|
3610
|
-
}
|
|
3611
|
-
raw;
|
|
3612
|
-
binaryType = "arraybuffer";
|
|
3613
|
-
get readyState() {
|
|
3614
|
-
return this.#init.readyState;
|
|
3615
|
-
}
|
|
3616
|
-
url;
|
|
3617
|
-
protocol;
|
|
3618
|
-
close(code, reason) {
|
|
3619
|
-
this.#init.close(code, reason);
|
|
3620
|
-
}
|
|
3621
|
-
};
|
|
3622
|
-
var defineWebSocketHelper = (handler) => {
|
|
3623
|
-
return (...args) => {
|
|
3624
|
-
if (typeof args[0] === "function") {
|
|
3625
|
-
const [createEvents, options] = args;
|
|
3626
|
-
return async function upgradeWebSocket(c, next) {
|
|
3627
|
-
const events = await createEvents(c);
|
|
3628
|
-
const result = await handler(c, events, options);
|
|
3629
|
-
if (result) {
|
|
3630
|
-
return result;
|
|
3631
|
-
}
|
|
3632
|
-
await next();
|
|
3633
|
-
};
|
|
3634
|
-
} else {
|
|
3635
|
-
const [c, events, options] = args;
|
|
3636
|
-
return (async () => {
|
|
3637
|
-
const upgraded = await handler(c, events, options);
|
|
3638
|
-
if (!upgraded) {
|
|
3639
|
-
throw new Error("Failed to upgrade WebSocket");
|
|
3640
|
-
}
|
|
3641
|
-
return upgraded;
|
|
3642
|
-
})();
|
|
3643
|
-
}
|
|
3644
|
-
};
|
|
3645
|
-
};
|
|
3646
|
-
|
|
3647
|
-
// ../../node_modules/hono/dist/adapter/bun/server.js
|
|
3648
|
-
var getBunServer = (c) => ("server" in c.env) ? c.env.server : c.env;
|
|
3649
|
-
|
|
3650
|
-
// ../../node_modules/hono/dist/adapter/bun/websocket.js
|
|
3651
|
-
var upgradeWebSocket = defineWebSocketHelper((c, events) => {
|
|
3652
|
-
const server = getBunServer(c);
|
|
3653
|
-
if (!server) {
|
|
3654
|
-
throw new TypeError("env has to include the 2nd argument of fetch.");
|
|
3655
|
-
}
|
|
3656
|
-
const upgradeResult = server.upgrade(c.req.raw, {
|
|
3657
|
-
data: {
|
|
3658
|
-
events,
|
|
3659
|
-
url: new URL(c.req.url),
|
|
3660
|
-
protocol: c.req.url
|
|
3661
|
-
}
|
|
3662
|
-
});
|
|
3663
|
-
if (upgradeResult) {
|
|
3664
|
-
return new Response(null);
|
|
3665
|
-
}
|
|
3666
|
-
return;
|
|
3667
|
-
});
|
|
3668
|
-
|
|
3669
4398
|
// ../../node_modules/hono/dist/middleware/cors/index.js
|
|
3670
4399
|
var cors = (options) => {
|
|
3671
4400
|
const defaults = {
|
|
@@ -3753,6 +4482,7 @@ var cors = (options) => {
|
|
|
3753
4482
|
|
|
3754
4483
|
// src/server.ts
|
|
3755
4484
|
import path from "path";
|
|
4485
|
+
import { fileURLToPath } from "url";
|
|
3756
4486
|
|
|
3757
4487
|
// src/pending/store.ts
|
|
3758
4488
|
import { randomUUID } from "crypto";
|
|
@@ -4080,10 +4810,11 @@ async function forwardToUpstream(request, upstreamUrl) {
|
|
|
4080
4810
|
}
|
|
4081
4811
|
|
|
4082
4812
|
// src/server.ts
|
|
4813
|
+
var __dirname2 = path.dirname(fileURLToPath(import.meta.url));
|
|
4083
4814
|
function resolveWebDistPath() {
|
|
4084
|
-
const bundledPath = path.resolve(
|
|
4085
|
-
const devPath = path.resolve(
|
|
4086
|
-
if (
|
|
4815
|
+
const bundledPath = path.resolve(__dirname2, "../web-dist");
|
|
4816
|
+
const devPath = path.resolve(__dirname2, "../../web/dist");
|
|
4817
|
+
if (existsSync2(bundledPath))
|
|
4087
4818
|
return bundledPath;
|
|
4088
4819
|
return devPath;
|
|
4089
4820
|
}
|
|
@@ -4134,12 +4865,12 @@ function createServer(config) {
|
|
|
4134
4865
|
app.get("/api/config", (c) => c.json({
|
|
4135
4866
|
fromAddress: config.fromAddress || null
|
|
4136
4867
|
}));
|
|
4137
|
-
app.use("/assets/*",
|
|
4138
|
-
app.get("*",
|
|
4868
|
+
app.use("/assets/*", serveStatic({ root: webDistPath }));
|
|
4869
|
+
app.get("*", (c) => {
|
|
4139
4870
|
const indexPath = path.join(webDistPath, "index.html");
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
return c.html(
|
|
4871
|
+
if (existsSync2(indexPath)) {
|
|
4872
|
+
const html = readFileSync(indexPath, "utf-8");
|
|
4873
|
+
return c.html(html);
|
|
4143
4874
|
}
|
|
4144
4875
|
return c.text("Web UI not found. Run 'bun run build' in packages/web first.", 404);
|
|
4145
4876
|
});
|
|
@@ -4149,9 +4880,9 @@ function createServer(config) {
|
|
|
4149
4880
|
// src/index.ts
|
|
4150
4881
|
if (process.argv.length <= 2) {
|
|
4151
4882
|
console.log(`
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4883
|
+
╔═══════════════════════════════════════════════════════════════╗
|
|
4884
|
+
║ browser-rpc ║
|
|
4885
|
+
╚═══════════════════════════════════════════════════════════════╝
|
|
4155
4886
|
|
|
4156
4887
|
\x1B[1mUSAGE\x1B[0m
|
|
4157
4888
|
|
|
@@ -4178,7 +4909,7 @@ if (process.argv.length <= 2) {
|
|
|
4178
4909
|
program.name("browser-rpc").description("Local RPC proxy for secure transaction signing via browser wallet").requiredOption("-r, --rpc <url>", "Upstream RPC URL for read calls").option("-p, --port <number>", "Server port", "8545").option("-f, --from <address>", "Default wallet address (returned for eth_accounts)").option("--no-open", "Disable auto-opening browser for transactions").parse();
|
|
4179
4910
|
var options = program.opts();
|
|
4180
4911
|
var port = parseInt(options.port, 10);
|
|
4181
|
-
|
|
4912
|
+
function openBrowser(url) {
|
|
4182
4913
|
const args = [url];
|
|
4183
4914
|
let command;
|
|
4184
4915
|
if (process.platform === "darwin") {
|
|
@@ -4190,7 +4921,7 @@ async function openBrowser(url) {
|
|
|
4190
4921
|
command = "xdg-open";
|
|
4191
4922
|
}
|
|
4192
4923
|
try {
|
|
4193
|
-
|
|
4924
|
+
spawn(command, args, { detached: true, stdio: "ignore" }).unref();
|
|
4194
4925
|
} catch (error) {
|
|
4195
4926
|
console.error(`Failed to open browser: ${error}`);
|
|
4196
4927
|
}
|
|
@@ -4201,20 +4932,20 @@ var server = createServer({
|
|
|
4201
4932
|
fromAddress: options.from,
|
|
4202
4933
|
onPendingRequest: (id, url) => {
|
|
4203
4934
|
console.log(`
|
|
4204
|
-
\x1B[33m
|
|
4935
|
+
\x1B[33m⏳ Awaiting approval:\x1B[0m ${url}`);
|
|
4205
4936
|
if (options.open) {
|
|
4206
4937
|
openBrowser(url);
|
|
4207
4938
|
}
|
|
4208
4939
|
}
|
|
4209
4940
|
});
|
|
4210
|
-
|
|
4941
|
+
serve({
|
|
4211
4942
|
fetch: server.fetch,
|
|
4212
4943
|
port
|
|
4213
4944
|
});
|
|
4214
4945
|
console.log(`
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4946
|
+
╔═══════════════════════════════════════════════════════════════╗
|
|
4947
|
+
║ browser-rpc ║
|
|
4948
|
+
╚═══════════════════════════════════════════════════════════════╝
|
|
4218
4949
|
|
|
4219
4950
|
Server: http://localhost:${port}
|
|
4220
4951
|
Upstream: ${options.rpc}
|
|
@@ -4227,6 +4958,6 @@ console.log(`
|
|
|
4227
4958
|
forge script script/Deploy.s.sol --rpc-url http://localhost:${port} \\
|
|
4228
4959
|
--broadcast --unlocked --sender 0xYourWallet
|
|
4229
4960
|
${!options.from ? `
|
|
4230
|
-
\x1B[33m
|
|
4961
|
+
\x1B[33m⚠ Warning: No --from address specified, which may cause issues in Hardhat.\x1B[0m
|
|
4231
4962
|
` : ""}
|
|
4232
4963
|
`);
|