@orchestraai/agent-tools 0.10.16 → 0.10.17
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/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/.devin/adapter.json +1 -1
- package/.hermes/adapter.json +1 -1
- package/.opencode/adapter.json +1 -1
- package/dist/commands/claude-setup.d.ts +1 -1
- package/dist/runtime/conversation/command-guard.js +1023 -63
- package/dist/runtime/conversation/command-guard.js.map +1 -1
- package/dist/runtime/conversation/shell-parse.d.ts +42 -0
- package/dist/runtime/conversation/shell-parse.js +517 -0
- package/dist/runtime/conversation/shell-parse.js.map +1 -0
- package/docs/security.md +11 -2
- package/node_modules/@hono/node-server/dist/index.cjs +63 -17
- package/node_modules/@hono/node-server/dist/index.mjs +63 -17
- package/node_modules/@hono/node-server/dist/serve-static.cjs +1 -1
- package/node_modules/@hono/node-server/dist/serve-static.mjs +1 -1
- package/node_modules/@hono/node-server/package.json +1 -1
- package/node_modules/cross-spawn/README.md +19 -3
- package/node_modules/cross-spawn/lib/parse.js +38 -10
- package/node_modules/cross-spawn/lib/util/escape.js +84 -25
- package/node_modules/cross-spawn/lib/util/readShebang.js +8 -2
- package/node_modules/cross-spawn/lib/util/resolveCommand.js +8 -1
- package/node_modules/cross-spawn/package.json +21 -24
- package/node_modules/hono/README.md +2 -3
- package/node_modules/hono/dist/adapter/aws-lambda/handler.js +2 -2
- package/node_modules/hono/dist/adapter/bun/websocket.js +19 -4
- package/node_modules/hono/dist/adapter/lambda-edge/handler.js +5 -1
- package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +2 -2
- package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +19 -4
- package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +5 -1
- package/node_modules/hono/dist/cjs/client/fetch-result-please.js +1 -1
- package/node_modules/hono/dist/cjs/client/utils.js +9 -5
- package/node_modules/hono/dist/cjs/context.js +1 -1
- package/node_modules/hono/dist/cjs/helper/accepts/accepts.js +7 -1
- package/node_modules/hono/dist/cjs/helper/css/common.js +11 -8
- package/node_modules/hono/dist/cjs/helper/css/index.js +1 -1
- package/node_modules/hono/dist/cjs/helper/proxy/index.js +2 -0
- package/node_modules/hono/dist/cjs/helper/route/index.js +3 -1
- package/node_modules/hono/dist/cjs/helper/ssg/ssg.js +5 -3
- package/node_modules/hono/dist/cjs/helper/streaming/sse.js +6 -2
- package/node_modules/hono/dist/cjs/hono-base.js +9 -10
- package/node_modules/hono/dist/cjs/hono.js +0 -1
- package/node_modules/hono/dist/cjs/jsx/base.js +51 -32
- package/node_modules/hono/dist/cjs/jsx/components.js +2 -2
- package/node_modules/hono/dist/cjs/jsx/constants.js +2 -0
- package/node_modules/hono/dist/cjs/jsx/context.js +15 -2
- package/node_modules/hono/dist/cjs/jsx/dom/components.js +1 -1
- package/node_modules/hono/dist/cjs/jsx/dom/hooks/index.js +38 -8
- package/node_modules/hono/dist/cjs/jsx/dom/intrinsic-element/components.js +8 -5
- package/node_modules/hono/dist/cjs/jsx/dom/render.js +9 -3
- package/node_modules/hono/dist/cjs/jsx/jsx-runtime.js +13 -17
- package/node_modules/hono/dist/cjs/middleware/basic-auth/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/bearer-auth/index.js +9 -1
- package/node_modules/hono/dist/cjs/middleware/body-limit/index.js +9 -10
- package/node_modules/hono/dist/cjs/middleware/combine/index.js +4 -0
- package/node_modules/hono/dist/cjs/middleware/compress/index.js +2 -3
- package/node_modules/hono/dist/cjs/middleware/csrf/index.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/etag/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/method-override/index.js +35 -12
- package/node_modules/hono/dist/cjs/middleware/mount/index.js +5 -4
- package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +1 -0
- package/node_modules/hono/dist/cjs/middleware/request-id/request-id.js +3 -3
- package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +4 -2
- package/node_modules/hono/dist/cjs/middleware/timing/timing.js +4 -3
- package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +13 -11
- package/node_modules/hono/dist/cjs/router/reg-exp-router/prepared-router.js +4 -4
- package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +39 -51
- package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +15 -5
- package/node_modules/hono/dist/cjs/router/trie-router/node.js +6 -4
- package/node_modules/hono/dist/cjs/utils/body.js +2 -1
- package/node_modules/hono/dist/cjs/utils/cookie.js +3 -3
- package/node_modules/hono/dist/cjs/utils/html.js +5 -0
- package/node_modules/hono/dist/cjs/utils/jwt/jwt.js +8 -5
- package/node_modules/hono/dist/cjs/utils/mime.js +3 -2
- package/node_modules/hono/dist/cjs/utils/mount.js +59 -0
- package/node_modules/hono/dist/cjs/utils/url.js +23 -11
- package/node_modules/hono/dist/cjs/validator/validator.js +5 -5
- package/node_modules/hono/dist/client/fetch-result-please.js +1 -1
- package/node_modules/hono/dist/client/utils.js +9 -5
- package/node_modules/hono/dist/context.js +1 -1
- package/node_modules/hono/dist/helper/accepts/accepts.js +7 -1
- package/node_modules/hono/dist/helper/css/common.js +11 -8
- package/node_modules/hono/dist/helper/css/index.js +1 -1
- package/node_modules/hono/dist/helper/proxy/index.js +2 -0
- package/node_modules/hono/dist/helper/route/index.js +3 -1
- package/node_modules/hono/dist/helper/ssg/ssg.js +5 -3
- package/node_modules/hono/dist/helper/streaming/sse.js +6 -2
- package/node_modules/hono/dist/hono-base.js +9 -10
- package/node_modules/hono/dist/hono.js +0 -1
- package/node_modules/hono/dist/jsx/base.js +51 -34
- package/node_modules/hono/dist/jsx/components.js +2 -2
- package/node_modules/hono/dist/jsx/constants.js +2 -1
- package/node_modules/hono/dist/jsx/context.js +15 -2
- package/node_modules/hono/dist/jsx/dom/components.js +2 -2
- package/node_modules/hono/dist/jsx/dom/hooks/index.js +39 -9
- package/node_modules/hono/dist/jsx/dom/intrinsic-element/components.js +8 -5
- package/node_modules/hono/dist/jsx/dom/render.js +9 -3
- package/node_modules/hono/dist/jsx/jsx-runtime.js +15 -19
- package/node_modules/hono/dist/middleware/basic-auth/index.js +3 -1
- package/node_modules/hono/dist/middleware/bearer-auth/index.js +9 -1
- package/node_modules/hono/dist/middleware/body-limit/index.js +9 -10
- package/node_modules/hono/dist/middleware/combine/index.js +4 -0
- package/node_modules/hono/dist/middleware/compress/index.js +2 -3
- package/node_modules/hono/dist/middleware/csrf/index.js +2 -2
- package/node_modules/hono/dist/middleware/etag/index.js +3 -1
- package/node_modules/hono/dist/middleware/jwk/jwk.js +2 -2
- package/node_modules/hono/dist/middleware/jwt/jwt.js +2 -2
- package/node_modules/hono/dist/middleware/method-not-allowed/index.js +1 -1
- package/node_modules/hono/dist/middleware/method-override/index.js +35 -12
- package/node_modules/hono/dist/middleware/mount/index.js +5 -4
- package/node_modules/hono/dist/middleware/pretty-json/index.js +1 -0
- package/node_modules/hono/dist/middleware/request-id/request-id.js +3 -3
- package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/middleware/serve-static/index.js +4 -2
- package/node_modules/hono/dist/middleware/timing/timing.js +4 -3
- package/node_modules/hono/dist/router/reg-exp-router/node.js +13 -11
- package/node_modules/hono/dist/router/reg-exp-router/prepared-router.js +5 -5
- package/node_modules/hono/dist/router/reg-exp-router/router.js +40 -52
- package/node_modules/hono/dist/router/reg-exp-router/trie.js +15 -5
- package/node_modules/hono/dist/router/trie-router/node.js +6 -4
- package/node_modules/hono/dist/types/adapter/aws-lambda/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/bun/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/bun/ssg.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-pages/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-workers/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/deno/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/deno/ssg.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/lambda-edge/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/netlify/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/vercel/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/accepts/accepts.d.ts +5 -0
- package/node_modules/hono/dist/types/helper/factory/index.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/ssg/ssg.d.ts +6 -1
- package/node_modules/hono/dist/types/helper/streaming/sse.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/streaming/stream.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/streaming/text.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/testing/index.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/websocket/index.d.ts +13 -3
- package/node_modules/hono/dist/types/hono-base.d.ts +23 -9
- package/node_modules/hono/dist/types/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/base.d.ts +6 -3
- package/node_modules/hono/dist/types/jsx/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/constants.d.ts +1 -0
- package/node_modules/hono/dist/types/jsx/context.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/css.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/hooks/index.d.ts +5 -3
- package/node_modules/hono/dist/types/jsx/dom/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/dom/server.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/jsx-runtime.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/streaming.d.ts +4 -3
- package/node_modules/hono/dist/types/middleware/basic-auth/index.d.ts +1 -0
- package/node_modules/hono/dist/types/middleware/bearer-auth/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/ip-restriction/index.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/mount/index.d.ts +2 -0
- package/node_modules/hono/dist/types/middleware/request-id/request-id.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/secure-headers/secure-headers.d.ts +2 -0
- package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +3 -3
- package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/cookie.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/ipaddr.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/jwt/jwt.d.ts +4 -2
- package/node_modules/hono/dist/types/utils/mount.d.ts +4 -0
- package/node_modules/hono/dist/types/utils/types.d.ts +12 -2
- package/node_modules/hono/dist/utils/body.js +2 -1
- package/node_modules/hono/dist/utils/cookie.js +3 -3
- package/node_modules/hono/dist/utils/html.js +5 -0
- package/node_modules/hono/dist/utils/jwt/jwt.js +8 -5
- package/node_modules/hono/dist/utils/mime.js +3 -2
- package/node_modules/hono/dist/utils/mount.js +58 -0
- package/node_modules/hono/dist/utils/url.js +23 -11
- package/node_modules/hono/dist/validator/validator.js +5 -5
- package/node_modules/hono/package.json +1 -1
- package/package.json +1 -1
|
@@ -1,47 +1,106 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// See http://www.robvanderwoude.com/escapechars.php
|
|
4
|
-
|
|
4
|
+
// Note that % is not included because escaping it with ^ doesn't prevent %VAR% expansion if
|
|
5
|
+
// a variable named `VAR^` exists, see `escapePercent()` below
|
|
6
|
+
const metaCharsRegExp = /([()\][!^"`<>&|;, *?])/g;
|
|
7
|
+
|
|
8
|
+
// cmd.exe treats CR and LF as command separators and there's no way to escape them
|
|
9
|
+
// Allowing them would enable command injection, so we reject them instead
|
|
10
|
+
const lineBreakRegExp = /[\r\n]/;
|
|
11
|
+
|
|
12
|
+
function assertNoLineBreaks(arg) {
|
|
13
|
+
if (lineBreakRegExp.test(arg)) {
|
|
14
|
+
throw new TypeError('The command and its arguments cannot contain line breaks when executed through cmd.exe');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// %VAR% is expanded even inside double quotes or when escaped with ^, so we replace % with %%cd:~,%
|
|
19
|
+
// The latter is an empty substring of the %cd% dynamic variable, which interrupts the expansion
|
|
20
|
+
// This must be done after escaping meta chars, as the replacement must not be escaped itself
|
|
21
|
+
function escapePercent(arg) {
|
|
22
|
+
return arg.replace(/%/g, '%%cd:~,%');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Quotes an argument so that it's parsed back verbatim by programs following the Microsoft C runtime rules,
|
|
26
|
+
// where backslashes are only special when they precede a double quote
|
|
27
|
+
// Algorithm below is based on https://qntm.org/cmd, but implemented with a loop instead of regular expressions,
|
|
28
|
+
// which runs in linear time and correctly handles any number of backslashes
|
|
29
|
+
function quoteArgument(arg, escapedQuote) {
|
|
30
|
+
let quoted = '"';
|
|
31
|
+
let backslashes = 0;
|
|
32
|
+
|
|
33
|
+
for (const char of arg) {
|
|
34
|
+
if (char === '\\') {
|
|
35
|
+
backslashes += 1;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (char === '"') {
|
|
40
|
+
// Sequence of backslashes followed by a double quote:
|
|
41
|
+
// double up all the backslashes and escape the double quote
|
|
42
|
+
quoted += '\\'.repeat(backslashes * 2) + escapedQuote;
|
|
43
|
+
} else {
|
|
44
|
+
// All other backslashes occur literally
|
|
45
|
+
quoted += '\\'.repeat(backslashes) + char;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
backslashes = 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Sequence of backslashes followed by the end of the string (which will become a double quote):
|
|
52
|
+
// double up all the backslashes
|
|
53
|
+
return `${quoted}${'\\'.repeat(backslashes * 2)}"`;
|
|
54
|
+
}
|
|
5
55
|
|
|
6
56
|
function escapeCommand(arg) {
|
|
7
|
-
|
|
8
|
-
arg = arg.replace(metaCharsRegExp, '^$1');
|
|
57
|
+
assertNoLineBreaks(arg);
|
|
9
58
|
|
|
10
|
-
|
|
59
|
+
// Quote the command, so that cmd.exe treats it as a single name
|
|
60
|
+
// Otherwise cmd.exe would end the name at the first space, tab, `,`, `;` or `=`, even if escaped with ^,
|
|
61
|
+
// and run whatever it finds with that name, e.g. a batch file, with the rest as extra arguments
|
|
62
|
+
// Command names can't contain double quotes, see `parse.js`, and meta chars are literal inside quotes
|
|
63
|
+
return `"${escapePercent(arg)}"`;
|
|
11
64
|
}
|
|
12
65
|
|
|
13
|
-
function escapeArgument(arg
|
|
66
|
+
function escapeArgument(arg) {
|
|
14
67
|
// Convert to string
|
|
15
68
|
arg = `${arg}`;
|
|
16
69
|
|
|
17
|
-
|
|
18
|
-
// It's slightly altered to disable JS backtracking to avoid hanging on specially crafted input
|
|
19
|
-
// Please see https://github.com/moxystudio/node-cross-spawn/pull/160 for more information
|
|
70
|
+
assertNoLineBreaks(arg);
|
|
20
71
|
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
arg = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"');
|
|
72
|
+
// Quote the whole thing, escaping double quotes with a backslash
|
|
73
|
+
arg = quoteArgument(arg, '\\"');
|
|
24
74
|
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
// double up all the backslashes
|
|
28
|
-
arg = arg.replace(/(?=(\\+?)?)\1$/, '$1$1');
|
|
75
|
+
// Escape meta chars and neutralize %VAR% expansion
|
|
76
|
+
arg = escapePercent(arg.replace(metaCharsRegExp, '^$1'));
|
|
29
77
|
|
|
30
|
-
|
|
78
|
+
return arg;
|
|
79
|
+
}
|
|
31
80
|
|
|
32
|
-
|
|
33
|
-
|
|
81
|
+
// Batch files (.bat and .cmd) usually proxy their arguments with %* or read them with "%~1",
|
|
82
|
+
// which makes cmd.exe parse them a second time, after ^ escapes have already been consumed
|
|
83
|
+
// Instead of escaping meta chars with ^, we rely on double quotes, which keep meta chars literal in both parses
|
|
84
|
+
// This is the same approach taken by Rust after BatBadBut (CVE-2024-24576)
|
|
34
85
|
|
|
35
|
-
|
|
36
|
-
arg
|
|
86
|
+
function escapeBatchCommand(arg) {
|
|
87
|
+
assertNoLineBreaks(arg);
|
|
37
88
|
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
89
|
+
// Command names can't contain double quotes, so we just need to quote it
|
|
90
|
+
return `"${escapePercent(arg)}"`;
|
|
91
|
+
}
|
|
42
92
|
|
|
43
|
-
|
|
93
|
+
function escapeBatchArgument(arg) {
|
|
94
|
+
// Convert to string
|
|
95
|
+
arg = `${arg}`;
|
|
96
|
+
|
|
97
|
+
assertNoLineBreaks(arg);
|
|
98
|
+
|
|
99
|
+
// Quote the whole thing, escaping double quotes by doubling them, which keeps cmd.exe's quoting balanced
|
|
100
|
+
return escapePercent(quoteArgument(arg, '""'));
|
|
44
101
|
}
|
|
45
102
|
|
|
46
103
|
module.exports.command = escapeCommand;
|
|
47
104
|
module.exports.argument = escapeArgument;
|
|
105
|
+
module.exports.batchCommand = escapeBatchCommand;
|
|
106
|
+
module.exports.batchArgument = escapeBatchArgument;
|
|
@@ -13,8 +13,14 @@ function readShebang(command) {
|
|
|
13
13
|
try {
|
|
14
14
|
fd = fs.openSync(command, 'r');
|
|
15
15
|
fs.readSync(fd, buffer, 0, size, 0);
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
} catch (e) { /* Empty */ } finally {
|
|
17
|
+
// Always close the file descriptor, even if reading failed
|
|
18
|
+
if (fd !== undefined) {
|
|
19
|
+
try {
|
|
20
|
+
fs.closeSync(fd);
|
|
21
|
+
} catch (e) { /* Empty */ }
|
|
22
|
+
}
|
|
23
|
+
}
|
|
18
24
|
|
|
19
25
|
// Attempt to extract shebang (null is returned if not a shebang)
|
|
20
26
|
return shebangCommand(buffer.toString());
|
|
@@ -4,6 +4,13 @@ const path = require('path');
|
|
|
4
4
|
const which = require('which');
|
|
5
5
|
const getPathKey = require('path-key');
|
|
6
6
|
|
|
7
|
+
// Returns the child's PATHEXT, which cmd.exe will use to find the command
|
|
8
|
+
function getPathExt(env) {
|
|
9
|
+
const key = Object.keys(env).find((name) => name.toUpperCase() === 'PATHEXT');
|
|
10
|
+
|
|
11
|
+
return key ? env[key] : undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
function resolveCommandAttempt(parsed, withoutPathExt) {
|
|
8
15
|
const env = parsed.options.env || process.env;
|
|
9
16
|
const cwd = process.cwd();
|
|
@@ -26,7 +33,7 @@ function resolveCommandAttempt(parsed, withoutPathExt) {
|
|
|
26
33
|
try {
|
|
27
34
|
resolved = which.sync(parsed.command, {
|
|
28
35
|
path: env[getPathKey({ env })],
|
|
29
|
-
pathExt: withoutPathExt ? path.delimiter :
|
|
36
|
+
pathExt: withoutPathExt ? path.delimiter : getPathExt(env),
|
|
30
37
|
});
|
|
31
38
|
} catch (e) {
|
|
32
39
|
/* Empty */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cross-spawn",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.2",
|
|
4
4
|
"description": "Cross platform child_process#spawn and child_process#spawnSync",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"spawn",
|
|
@@ -21,26 +21,26 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"main": "index.js",
|
|
23
23
|
"files": [
|
|
24
|
-
"lib"
|
|
24
|
+
"lib",
|
|
25
|
+
"!lib/**/*.test.js"
|
|
25
26
|
],
|
|
26
27
|
"scripts": {
|
|
27
28
|
"lint": "eslint .",
|
|
28
29
|
"test": "jest --env node --coverage",
|
|
29
30
|
"prerelease": "npm t && npm run lint",
|
|
30
31
|
"release": "standard-version",
|
|
31
|
-
"postrelease": "git push --follow-tags origin HEAD && npm publish"
|
|
32
|
+
"postrelease": "git push --follow-tags origin HEAD && npm publish",
|
|
33
|
+
"prepare": "husky"
|
|
32
34
|
},
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
35
|
+
"jest": {
|
|
36
|
+
"collectCoverageFrom": [
|
|
37
|
+
"index.js",
|
|
38
|
+
"lib/**/*.js",
|
|
39
|
+
"!lib/**/*.test.js"
|
|
40
|
+
]
|
|
38
41
|
},
|
|
39
42
|
"lint-staged": {
|
|
40
|
-
"*.js":
|
|
41
|
-
"eslint --fix",
|
|
42
|
-
"git add"
|
|
43
|
-
]
|
|
43
|
+
"*.js": "eslint --fix"
|
|
44
44
|
},
|
|
45
45
|
"commitlint": {
|
|
46
46
|
"extends": [
|
|
@@ -53,18 +53,15 @@
|
|
|
53
53
|
"which": "^2.0.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@commitlint/cli": "^
|
|
57
|
-
"@commitlint/config-conventional": "^
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"lint-staged": "^9.2.5",
|
|
66
|
-
"mkdirp": "^0.5.1",
|
|
67
|
-
"rimraf": "^3.0.0",
|
|
56
|
+
"@commitlint/cli": "^20.5.3",
|
|
57
|
+
"@commitlint/config-conventional": "^20.5.3",
|
|
58
|
+
"@eslint/js": "^9.39.5",
|
|
59
|
+
"eslint": "^9.39.5",
|
|
60
|
+
"eslint-plugin-jest": "^28.14.0",
|
|
61
|
+
"globals": "^16.5.0",
|
|
62
|
+
"husky": "^9.1.7",
|
|
63
|
+
"jest": "^30.5.2",
|
|
64
|
+
"lint-staged": "^15.5.2",
|
|
68
65
|
"standard-version": "^9.5.0"
|
|
69
66
|
},
|
|
70
67
|
"engines": {
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
[](https://github.com/honojs/hono/commits/main)
|
|
18
18
|
[](https://codecov.io/github/honojs/hono)
|
|
19
19
|
[](https://discord.gg/KMh2eNSdxV)
|
|
20
|
-
[](https://deepwiki.com/honojs/hono)
|
|
21
20
|
|
|
22
21
|
Hono - _**means flame🔥 in Japanese**_ - is a small, simple, and ultrafast web framework built on Web Standards. It works on any JavaScript runtime: Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, AWS Lambda, Lambda@Edge, and Node.js.
|
|
23
22
|
|
|
@@ -63,9 +62,9 @@ The migration guide is available on [docs/MIGRATION.md](docs/MIGRATION.md).
|
|
|
63
62
|
Contributions Welcome! You can contribute in the following ways.
|
|
64
63
|
|
|
65
64
|
- Create an Issue - Propose a new feature. Report a bug.
|
|
66
|
-
-
|
|
67
|
-
- Create third-party middleware - See [Third-party middleware](docs/CONTRIBUTING.md#third-party-middleware).
|
|
65
|
+
- Build middleware and libraries - Grow the Hono ecosystem.
|
|
68
66
|
- Share - Share your thoughts on the Blog, X, and others.
|
|
67
|
+
- Sponsor - Support the maintainers through GitHub Sponsors: [@yusukebe](https://github.com/sponsors/yusukebe) and [@usualoma](https://github.com/sponsors/usualoma).
|
|
69
68
|
- Make your application - Please try to use Hono.
|
|
70
69
|
|
|
71
70
|
For more details, see [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md).
|
|
@@ -152,7 +152,7 @@ var EventProcessor = class {
|
|
|
152
152
|
isBase64Encoded = isContentEncodingBinary(contentEncoding);
|
|
153
153
|
}
|
|
154
154
|
const result = {
|
|
155
|
-
body: isBase64Encoded ? encodeBase64(await res.arrayBuffer()) : await res.
|
|
155
|
+
body: isBase64Encoded ? encodeBase64(await res.arrayBuffer()) : new TextDecoder("utf-8", { ignoreBOM: true }).decode(await res.arrayBuffer()),
|
|
156
156
|
statusCode: res.status,
|
|
157
157
|
isBase64Encoded,
|
|
158
158
|
..."multiValueHeaders" in event && event.multiValueHeaders ? { multiValueHeaders: {} } : { headers: {} }
|
|
@@ -199,7 +199,7 @@ var EventV2Processor = class extends EventProcessor {
|
|
|
199
199
|
const headers = new Headers();
|
|
200
200
|
this.getCookies(event, headers);
|
|
201
201
|
if (event.headers) {
|
|
202
|
-
for (const [k, v] of Object.entries(event.headers)) if (v) headers.set(k, v);
|
|
202
|
+
for (const [k, v] of Object.entries(event.headers)) if (v) headers.set(k, sanitizeHeaderValue(v));
|
|
203
203
|
}
|
|
204
204
|
return headers;
|
|
205
205
|
}
|
|
@@ -31,26 +31,41 @@ const upgradeWebSocket = defineWebSocketHelper((c, events) => {
|
|
|
31
31
|
protocol: c.req.header("sec-websocket-protocol")?.split(",")[0]?.trim() ?? ""
|
|
32
32
|
} })) return new Response(null);
|
|
33
33
|
});
|
|
34
|
+
const runHandler = (ws, handler) => {
|
|
35
|
+
const handleError = (error) => {
|
|
36
|
+
const onError = ws.data.events.onError;
|
|
37
|
+
if (!onError) throw error;
|
|
38
|
+
const event = new Event("error");
|
|
39
|
+
event.error = error;
|
|
40
|
+
onError(event, createWSContext(ws));
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
const result = handler();
|
|
44
|
+
if (result instanceof Promise) result.catch(handleError);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
handleError(error);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
34
49
|
/**
|
|
35
50
|
* @deprecated `hono/bun` will be removed in v5. Install `@hono/bun` and import from there instead.
|
|
36
51
|
*/
|
|
37
52
|
const websocket = {
|
|
38
53
|
open(ws) {
|
|
39
54
|
const websocketListeners = ws.data.events;
|
|
40
|
-
if (websocketListeners.onOpen) websocketListeners.onOpen(new Event("open"), createWSContext(ws));
|
|
55
|
+
if (websocketListeners.onOpen) runHandler(ws, () => websocketListeners.onOpen(new Event("open"), createWSContext(ws)));
|
|
41
56
|
},
|
|
42
57
|
close(ws, code, reason) {
|
|
43
58
|
const websocketListeners = ws.data.events;
|
|
44
|
-
if (websocketListeners.onClose) websocketListeners.onClose(new CloseEvent("close", {
|
|
59
|
+
if (websocketListeners.onClose) runHandler(ws, () => websocketListeners.onClose(new CloseEvent("close", {
|
|
45
60
|
code,
|
|
46
61
|
reason
|
|
47
|
-
}), createWSContext(ws));
|
|
62
|
+
}), createWSContext(ws)));
|
|
48
63
|
},
|
|
49
64
|
message(ws, message) {
|
|
50
65
|
const websocketListeners = ws.data.events;
|
|
51
66
|
if (websocketListeners.onMessage) {
|
|
52
67
|
const normalizedReceiveData = typeof message === "string" ? message : message.buffer;
|
|
53
|
-
websocketListeners.onMessage(createWSMessageEvent(normalizedReceiveData), createWSContext(ws));
|
|
68
|
+
runHandler(ws, () => websocketListeners.onMessage(createWSMessageEvent(normalizedReceiveData), createWSContext(ws)));
|
|
54
69
|
}
|
|
55
70
|
}
|
|
56
71
|
};
|
|
@@ -44,9 +44,13 @@ const handle = (app) => {
|
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
46
|
const createResult = async (res) => {
|
|
47
|
+
if (res.status === 204) return {
|
|
48
|
+
status: "204",
|
|
49
|
+
headers: convertHeaders(res.headers)
|
|
50
|
+
};
|
|
47
51
|
const contentEncoding = res.headers.get("content-encoding");
|
|
48
52
|
const isBase64Encoded = isContentTypeBinary(res.headers.get("content-type") || "") || !!contentEncoding && !/^identity$/i.test(contentEncoding);
|
|
49
|
-
const body = isBase64Encoded ? encodeBase64(await res.arrayBuffer()) : await res.
|
|
53
|
+
const body = isBase64Encoded ? encodeBase64(await res.arrayBuffer()) : new TextDecoder("utf-8", { ignoreBOM: true }).decode(await res.arrayBuffer());
|
|
50
54
|
return {
|
|
51
55
|
status: res.status.toString(),
|
|
52
56
|
headers: convertHeaders(res.headers),
|
|
@@ -153,7 +153,7 @@ var EventProcessor = class {
|
|
|
153
153
|
isBase64Encoded = isContentEncodingBinary(contentEncoding);
|
|
154
154
|
}
|
|
155
155
|
const result = {
|
|
156
|
-
body: isBase64Encoded ? require_utils_encode.encodeBase64(await res.arrayBuffer()) : await res.
|
|
156
|
+
body: isBase64Encoded ? require_utils_encode.encodeBase64(await res.arrayBuffer()) : new TextDecoder("utf-8", { ignoreBOM: true }).decode(await res.arrayBuffer()),
|
|
157
157
|
statusCode: res.status,
|
|
158
158
|
isBase64Encoded,
|
|
159
159
|
..."multiValueHeaders" in event && event.multiValueHeaders ? { multiValueHeaders: {} } : { headers: {} }
|
|
@@ -200,7 +200,7 @@ var EventV2Processor = class extends EventProcessor {
|
|
|
200
200
|
const headers = new Headers();
|
|
201
201
|
this.getCookies(event, headers);
|
|
202
202
|
if (event.headers) {
|
|
203
|
-
for (const [k, v] of Object.entries(event.headers)) if (v) headers.set(k, v);
|
|
203
|
+
for (const [k, v] of Object.entries(event.headers)) if (v) headers.set(k, sanitizeHeaderValue(v));
|
|
204
204
|
}
|
|
205
205
|
return headers;
|
|
206
206
|
}
|
|
@@ -32,26 +32,41 @@ const upgradeWebSocket = require_helper_websocket_index.defineWebSocketHelper((c
|
|
|
32
32
|
protocol: c.req.header("sec-websocket-protocol")?.split(",")[0]?.trim() ?? ""
|
|
33
33
|
} })) return new Response(null);
|
|
34
34
|
});
|
|
35
|
+
const runHandler = (ws, handler) => {
|
|
36
|
+
const handleError = (error) => {
|
|
37
|
+
const onError = ws.data.events.onError;
|
|
38
|
+
if (!onError) throw error;
|
|
39
|
+
const event = new Event("error");
|
|
40
|
+
event.error = error;
|
|
41
|
+
onError(event, createWSContext(ws));
|
|
42
|
+
};
|
|
43
|
+
try {
|
|
44
|
+
const result = handler();
|
|
45
|
+
if (result instanceof Promise) result.catch(handleError);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
handleError(error);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
35
50
|
/**
|
|
36
51
|
* @deprecated `hono/bun` will be removed in v5. Install `@hono/bun` and import from there instead.
|
|
37
52
|
*/
|
|
38
53
|
const websocket = {
|
|
39
54
|
open(ws) {
|
|
40
55
|
const websocketListeners = ws.data.events;
|
|
41
|
-
if (websocketListeners.onOpen) websocketListeners.onOpen(new Event("open"), createWSContext(ws));
|
|
56
|
+
if (websocketListeners.onOpen) runHandler(ws, () => websocketListeners.onOpen(new Event("open"), createWSContext(ws)));
|
|
42
57
|
},
|
|
43
58
|
close(ws, code, reason) {
|
|
44
59
|
const websocketListeners = ws.data.events;
|
|
45
|
-
if (websocketListeners.onClose) websocketListeners.onClose(new CloseEvent("close", {
|
|
60
|
+
if (websocketListeners.onClose) runHandler(ws, () => websocketListeners.onClose(new CloseEvent("close", {
|
|
46
61
|
code,
|
|
47
62
|
reason
|
|
48
|
-
}), createWSContext(ws));
|
|
63
|
+
}), createWSContext(ws)));
|
|
49
64
|
},
|
|
50
65
|
message(ws, message) {
|
|
51
66
|
const websocketListeners = ws.data.events;
|
|
52
67
|
if (websocketListeners.onMessage) {
|
|
53
68
|
const normalizedReceiveData = typeof message === "string" ? message : message.buffer;
|
|
54
|
-
websocketListeners.onMessage(require_helper_websocket_index.createWSMessageEvent(normalizedReceiveData), createWSContext(ws));
|
|
69
|
+
runHandler(ws, () => websocketListeners.onMessage(require_helper_websocket_index.createWSMessageEvent(normalizedReceiveData), createWSContext(ws)));
|
|
55
70
|
}
|
|
56
71
|
}
|
|
57
72
|
};
|
|
@@ -47,9 +47,13 @@ const handle = (app) => {
|
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
49
|
const createResult = async (res) => {
|
|
50
|
+
if (res.status === 204) return {
|
|
51
|
+
status: "204",
|
|
52
|
+
headers: convertHeaders(res.headers)
|
|
53
|
+
};
|
|
50
54
|
const contentEncoding = res.headers.get("content-encoding");
|
|
51
55
|
const isBase64Encoded = isContentTypeBinary(res.headers.get("content-type") || "") || !!contentEncoding && !/^identity$/i.test(contentEncoding);
|
|
52
|
-
const body = isBase64Encoded ? require_utils_encode.encodeBase64(await res.arrayBuffer()) : await res.
|
|
56
|
+
const body = isBase64Encoded ? require_utils_encode.encodeBase64(await res.arrayBuffer()) : new TextDecoder("utf-8", { ignoreBOM: true }).decode(await res.arrayBuffer());
|
|
53
57
|
return {
|
|
54
58
|
status: res.status.toString(),
|
|
55
59
|
headers: convertHeaders(res.headers),
|
|
@@ -58,7 +58,7 @@ const jsonRegex = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(?:;.+)?$/i;
|
|
|
58
58
|
function detectResponseType(response) {
|
|
59
59
|
const _contentType = response.headers.get("content-type");
|
|
60
60
|
if (!_contentType) return "text";
|
|
61
|
-
const contentType = _contentType.split(";").shift();
|
|
61
|
+
const contentType = _contentType.split(";").shift().trim();
|
|
62
62
|
if (jsonRegex.test(contentType)) return "json";
|
|
63
63
|
return "text";
|
|
64
64
|
}
|
|
@@ -2,17 +2,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_client_fetch_result_please = require("./fetch-result-please.js");
|
|
3
3
|
//#region src/client/utils.ts
|
|
4
4
|
const mergePath = (base, path) => {
|
|
5
|
-
|
|
6
|
-
base
|
|
5
|
+
let end = base.length;
|
|
6
|
+
while (base[end - 1] === "/") end--;
|
|
7
7
|
path = path.replace(/^\/+/, "");
|
|
8
|
-
return base + path;
|
|
8
|
+
return base.slice(0, end) + "/" + path;
|
|
9
9
|
};
|
|
10
|
+
const networkPathRegExp = /^(?:[/\\][\t\n\r]*){2}/;
|
|
10
11
|
const replaceUrlParam = (urlString, params) => {
|
|
12
|
+
const isNetworkPath = networkPathRegExp.test(urlString);
|
|
11
13
|
for (const [k, v] of Object.entries(params)) {
|
|
12
14
|
const reg = new RegExp("/:" + k + "(?:{[^/]+})?\\??(?=/|$)");
|
|
13
15
|
urlString = urlString.replace(reg, () => v ? `/${v}` : "");
|
|
14
16
|
}
|
|
15
|
-
return urlString;
|
|
17
|
+
return !isNetworkPath && networkPathRegExp.test(urlString) ? urlString.replace(/^[/\\\t\n\r]+/, "/") : urlString;
|
|
16
18
|
};
|
|
17
19
|
const buildSearchParams = (query) => {
|
|
18
20
|
const searchParams = new URLSearchParams();
|
|
@@ -37,7 +39,9 @@ const removeIndexString = (urlString) => {
|
|
|
37
39
|
return urlString.replace(/\/index(?=\?|$)/, "");
|
|
38
40
|
};
|
|
39
41
|
function isObject(item) {
|
|
40
|
-
|
|
42
|
+
if (typeof item !== "object" || item === null) return false;
|
|
43
|
+
const proto = Object.getPrototypeOf(item);
|
|
44
|
+
return proto === null || Object.getPrototypeOf(proto) === null;
|
|
41
45
|
}
|
|
42
46
|
function deepMerge(target, source) {
|
|
43
47
|
if (!isObject(target) && !isObject(source)) return source;
|
|
@@ -198,7 +198,7 @@ var Context = class {
|
|
|
198
198
|
* ```
|
|
199
199
|
*/
|
|
200
200
|
header = (name, value, options) => {
|
|
201
|
-
if (this.finalized) this.#res = createResponseInstance(this.#res.body, this.#res);
|
|
201
|
+
if (this.finalized && !this.#res.bodyUsed) this.#res = createResponseInstance(this.#res.body, this.#res);
|
|
202
202
|
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
|
|
203
203
|
if (value === void 0) headers.delete(name);
|
|
204
204
|
else if (options?.append) headers.append(name, value);
|
|
@@ -20,18 +20,24 @@ const getSpecificity = (type) => {
|
|
|
20
20
|
};
|
|
21
21
|
const defaultMatch = (accepts, config) => {
|
|
22
22
|
const { supports, default: defaultSupport } = config;
|
|
23
|
+
const exactTypes = new Set(accepts.filter((accept) => getSpecificity(accept.type) === 3).map((accept) => accept.type.toLowerCase()));
|
|
23
24
|
const sortedAccepts = accepts.filter((accept) => accept.q > 0).sort((a, b) => {
|
|
24
25
|
if (b.q !== a.q) return b.q - a.q;
|
|
25
26
|
return getSpecificity(b.type) - getSpecificity(a.type);
|
|
26
27
|
});
|
|
27
28
|
for (const accept of sortedAccepts) {
|
|
28
|
-
const matched = supports.find((supported) => matchType(accept.type, supported));
|
|
29
|
+
const matched = supports.find((supported) => matchType(accept.type, supported) && (getSpecificity(accept.type) !== 2 || !exactTypes.has(supported.toLowerCase())));
|
|
29
30
|
if (matched) return matched;
|
|
30
31
|
}
|
|
31
32
|
return defaultSupport;
|
|
32
33
|
};
|
|
33
34
|
/**
|
|
34
35
|
* Match the accept header with the given options.
|
|
36
|
+
*
|
|
37
|
+
* @param {Context} c - The context of the request.
|
|
38
|
+
* @param {acceptsOptions} options - The options for matching the accept header.
|
|
39
|
+
* @returns {string} The matched supported value or the default value.
|
|
40
|
+
*
|
|
35
41
|
* @example
|
|
36
42
|
* ```ts
|
|
37
43
|
* app.get('/users', (c) => {
|
|
@@ -46,7 +46,11 @@ const isValidKeyframeName = (name) => isValidClassName(name) && !RESERVED_KEYFRA
|
|
|
46
46
|
const defaultOnInvalidSlug = (slug) => {
|
|
47
47
|
console.warn(`Invalid slug: ${slug}`);
|
|
48
48
|
};
|
|
49
|
-
const cssStringReStr = [
|
|
49
|
+
const cssStringReStr = [
|
|
50
|
+
"\"(?:(?:\\\\[\\s\\S]|[^\"\\\\])*)\"",
|
|
51
|
+
"'(?:(?:\\\\[\\s\\S]|[^'\\\\])*)'",
|
|
52
|
+
"url\\(\\s*[^)\"'\\s]*\\s*\\)"
|
|
53
|
+
].join("|");
|
|
50
54
|
const minifyCssRe = new RegExp([
|
|
51
55
|
"(" + cssStringReStr + ")",
|
|
52
56
|
"(?:" + [
|
|
@@ -56,11 +60,12 @@ const minifyCssRe = new RegExp([
|
|
|
56
60
|
"\\s+$"
|
|
57
61
|
].join("|") + ")",
|
|
58
62
|
"\\s*;\\s*(}|$)\\s*",
|
|
59
|
-
"\\s*([{}
|
|
63
|
+
"\\s*([{};,])\\s*",
|
|
64
|
+
"(:)\\s*",
|
|
60
65
|
"(\\s)\\s+"
|
|
61
66
|
].join("|"), "g");
|
|
62
67
|
const minify = (css) => {
|
|
63
|
-
return css.replace(minifyCssRe, (_, $1, $2, $3, $4) => $1 || $2 || $3 || $4 || "");
|
|
68
|
+
return css.replace(minifyCssRe, (_, $1, $2, $3, $4, $5) => $1 || $2 || $3 || $4 || $5 || "");
|
|
64
69
|
};
|
|
65
70
|
const buildStyleString = (strings, values) => {
|
|
66
71
|
const selectors = [];
|
|
@@ -75,10 +80,8 @@ const buildStyleString = (strings, values) => {
|
|
|
75
80
|
for (let j = 0, len = vArray.length; j < len; j++) {
|
|
76
81
|
let value = vArray[j];
|
|
77
82
|
if (typeof value === "boolean" || value === null || value === void 0) continue;
|
|
78
|
-
if (typeof value === "string")
|
|
79
|
-
|
|
80
|
-
else styleString += value;
|
|
81
|
-
} else if (typeof value === "number") styleString += value;
|
|
83
|
+
if (typeof value === "string") styleString += value.replace(/[\\"']/g, "\\$&");
|
|
84
|
+
else if (typeof value === "number") styleString += value;
|
|
82
85
|
else if (value[CSS_ESCAPED]) styleString += value[CSS_ESCAPED];
|
|
83
86
|
else if (value[CLASS_NAME].startsWith("@keyframes ")) {
|
|
84
87
|
selectors.push(value);
|
|
@@ -103,7 +106,7 @@ const buildStyleString = (strings, values) => {
|
|
|
103
106
|
}
|
|
104
107
|
return [
|
|
105
108
|
label,
|
|
106
|
-
minify(styleString),
|
|
109
|
+
minify(styleString).replace(/<\//g, "<\\/"),
|
|
107
110
|
selectors,
|
|
108
111
|
externalClassNames
|
|
109
112
|
];
|
|
@@ -21,7 +21,7 @@ const createCssContext = ({ id, classNameSlug, onInvalidSlug }) => {
|
|
|
21
21
|
const [cssJsxDomObject, StyleRenderToDom] = require_jsx_dom_css.createCssJsxDomObjects({ id });
|
|
22
22
|
const contextMap = /* @__PURE__ */ new WeakMap();
|
|
23
23
|
const nonceMap = /* @__PURE__ */ new WeakMap();
|
|
24
|
-
const replaceStyleRe = new RegExp(`(<style id="${id}"(?: nonce="[^"]*")?>.*?)(</style>)
|
|
24
|
+
const replaceStyleRe = new RegExp(`(<style id="${id}"(?: nonce="[^"]*")?>.*?)(</style>)`, "s");
|
|
25
25
|
const newCssClassNameObject = (cssClassName) => {
|
|
26
26
|
const appendStyle = ({ buffer, context }) => {
|
|
27
27
|
const [toAdd, added] = contextMap.get(context);
|
|
@@ -100,6 +100,8 @@ const proxy = async (input, proxyInit) => {
|
|
|
100
100
|
...buildRequestInitFromRequest(raw, strictConnectionProcessing),
|
|
101
101
|
...preprocessRequestInit(requestInit)
|
|
102
102
|
});
|
|
103
|
+
req.headers.delete("transfer-encoding");
|
|
104
|
+
req.headers.delete("keep-alive");
|
|
103
105
|
req.headers.delete("accept-encoding");
|
|
104
106
|
const res = await (customFetch || fetch)(req);
|
|
105
107
|
const resHeaders = new Headers(res.headers);
|
|
@@ -111,7 +111,9 @@ const basePath = (c, index) => {
|
|
|
111
111
|
const pattern = require_utils_url.getPattern(paths[i], paths[i + 1]);
|
|
112
112
|
if (pattern) {
|
|
113
113
|
const re = pattern[2] === true || pattern === "*" ? /[^\/]+/ : pattern[2];
|
|
114
|
-
|
|
114
|
+
const restPath = reqPath.substring(basePathLength + 1);
|
|
115
|
+
const segment = restPath.split("/", 1)[0];
|
|
116
|
+
basePathLength += (restPath.match(re)?.[0] ?? (re.test(segment) ? segment : "")).length;
|
|
115
117
|
} else basePathLength += paths[i].length;
|
|
116
118
|
basePathLength += 1;
|
|
117
119
|
}
|
|
@@ -39,6 +39,8 @@ const defaultExtensionMap = {
|
|
|
39
39
|
const determineExtension = (mimeType, userExtensionMap) => {
|
|
40
40
|
const extensionMap = userExtensionMap || defaultExtensionMap;
|
|
41
41
|
if (mimeType in extensionMap) return extensionMap[mimeType];
|
|
42
|
+
const lowerCasedMimeType = mimeType.toLowerCase();
|
|
43
|
+
if (lowerCasedMimeType in extensionMap) return extensionMap[lowerCasedMimeType];
|
|
42
44
|
return require_utils_mime.getExtension(mimeType) || "html";
|
|
43
45
|
};
|
|
44
46
|
const combineBeforeRequestHooks = (hooks) => {
|
|
@@ -142,8 +144,7 @@ const fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook,
|
|
|
142
144
|
* `saveContentToFile` is an experimental feature.
|
|
143
145
|
* The API might be changed.
|
|
144
146
|
*/
|
|
145
|
-
const createdDirs = /* @__PURE__ */ new Set()
|
|
146
|
-
const saveContentToFile = async (data, fsModule, outDir, extensionMap) => {
|
|
147
|
+
const saveContentToFile = async (data, fsModule, outDir, extensionMap, createdDirs = /* @__PURE__ */ new Set()) => {
|
|
147
148
|
const awaitedData = await data;
|
|
148
149
|
if (!awaitedData) return;
|
|
149
150
|
const { routePath, content, mimeType } = awaitedData;
|
|
@@ -183,10 +184,11 @@ const toSSG = async (app, fs, options) => {
|
|
|
183
184
|
const concurrency = options?.concurrency ?? DEFAULT_CONCURRENCY;
|
|
184
185
|
const combinedBeforeRequestHook = combineBeforeRequestHooks(beforeRequestHooks.length > 0 ? beforeRequestHooks : [(req) => req]);
|
|
185
186
|
const combinedAfterResponseHook = combineAfterResponseHooks(afterResponseHooks.length > 0 ? afterResponseHooks : [(req) => req]);
|
|
187
|
+
const createdDirs = /* @__PURE__ */ new Set();
|
|
186
188
|
const getInfoGen = fetchRoutesContent(app, combinedBeforeRequestHook, combinedAfterResponseHook, concurrency);
|
|
187
189
|
for (const getInfo of getInfoGen) getInfoPromises.push(getInfo.then((getContentGen) => {
|
|
188
190
|
if (!getContentGen) return;
|
|
189
|
-
for (const content of getContentGen) savePromises.push(saveContentToFile(content, fs, outputDir, options?.extensionMap).catch((e) => e));
|
|
191
|
+
for (const content of getContentGen) savePromises.push(saveContentToFile(content, fs, outputDir, options?.extensionMap, createdDirs).catch((e) => e));
|
|
190
192
|
}));
|
|
191
193
|
await Promise.all(getInfoPromises);
|
|
192
194
|
const files = [];
|
|
@@ -11,9 +11,13 @@ var SSEStreamingApi = class extends require_utils_stream.StreamingApi {
|
|
|
11
11
|
const dataLines = (await require_utils_html.resolveCallback(message.data, require_utils_html.HtmlEscapedCallbackPhase.Stringify, false, {})).split(/\r\n|\r|\n/).map((line) => {
|
|
12
12
|
return `data: ${line}`;
|
|
13
13
|
}).join("\n");
|
|
14
|
-
for (const key of [
|
|
14
|
+
for (const key of [
|
|
15
|
+
"event",
|
|
16
|
+
"id",
|
|
17
|
+
"retry"
|
|
18
|
+
]) {
|
|
15
19
|
const value = message[key];
|
|
16
|
-
if (value && /[\r\n]/.test(value)) throw new Error(`${key} must not contain "\\r" or "\\n"`);
|
|
20
|
+
if (value && /[\r\n]/.test(String(value))) throw new Error(`${key} must not contain "\\r" or "\\n"`);
|
|
17
21
|
}
|
|
18
22
|
const sseData = [
|
|
19
23
|
message.event && `event: ${message.event}`,
|