Repository navigation
Merge upstream emulate main into github-only #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: github-only
Are you sure you want to change the base?
Changes from all commits
b75beb7
617916f
9cb8659
8bfe994
26a8fe7
5bbb9c4
5cec11a
6ccd8b7
03e096a
2df53fc
f0452a4
d0158be
d995de5
9505d95
7732130
b230f29
8024425
ad7b0de
13b5c70
9b8b376
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| { | ||
| "$schema": "./node_modules/oxlint/configuration_schema.json", | ||
| "plugins": [ | ||
| "typescript" | ||
| ], | ||
| "rules": { | ||
| "no-array-constructor": "error", | ||
| "no-unused-expressions": [ | ||
| "error", | ||
| { | ||
| "allowShortCircuit": false, | ||
| "allowTaggedTemplates": false, | ||
| "allowTernary": false | ||
| } | ||
| ], | ||
| "no-unused-vars": [ | ||
| "warn", | ||
| { | ||
| "argsIgnorePattern": "^_", | ||
| "varsIgnorePattern": "^_" | ||
| } | ||
| ], | ||
| "no-var": "error", | ||
| "prefer-const": [ | ||
| "error", | ||
| { | ||
| "destructuring": "any", | ||
| "ignoreReadBeforeAssign": false | ||
| } | ||
| ], | ||
| "prefer-rest-params": "error", | ||
| "prefer-spread": "error", | ||
| "typescript/ban-ts-comment": "error", | ||
| "typescript/no-duplicate-enum-values": "error", | ||
| "typescript/no-extra-non-null-assertion": "error", | ||
| "typescript/no-misused-new": "error", | ||
| "typescript/no-namespace": "error", | ||
| "typescript/no-non-null-asserted-optional-chain": "error", | ||
| "typescript/no-this-alias": "error", | ||
| "typescript/no-unnecessary-type-constraint": "error", | ||
| "typescript/no-unsafe-declaration-merging": "error", | ||
| "typescript/no-unsafe-function-type": "error", | ||
| "typescript/no-wrapper-object-types": "error", | ||
| "typescript/prefer-as-const": "error", | ||
| "typescript/prefer-namespace-keyword": "error", | ||
| "typescript/triple-slash-reference": "error" | ||
| }, | ||
| "ignorePatterns": [ | ||
| "**/dist/**", | ||
| "**/node_modules/**", | ||
| "**/.next/**", | ||
| "apps/**", | ||
| "examples/**" | ||
| ] | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |||||
| * Copyright (c) 2021 - present, Yusuke Wada and Hono contributors | ||||||
| * MIT license: see THIRD_PARTY_NOTICES.md in the repository and npm packages. | ||||||
| */ | ||||||
| import { lookup } from "node:dns/promises"; | ||||||
| import { connect, isIP } from "node:net"; | ||||||
| import { createServer as createNodeServer, type IncomingMessage, type Server, type ServerResponse } from "node:http"; | ||||||
|
|
||||||
| type BodyInit = ConstructorParameters<typeof Response>[0]; | ||||||
|
|
@@ -443,40 +445,85 @@ export function serve(options: ServeOptions): Server { | |||||
| return server; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Rejects with an EADDRINUSE error when something already accepts connections on the address a listener is about to | ||||||
| * bind. Await it before `serve`: macOS lets a specific address bind a port another process holds on the wildcard | ||||||
| * address. The other process sees one short connection. | ||||||
| */ | ||||||
| export async function assertPortFree(hostname: string | undefined, port: number): Promise<void> { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 assertPortFree probes only one resolved address.
Suggested change
🤖 Fix with your agentWhy this mattersassertPortFree resolves the hostname once and probes a single address. For 'localhost', dns.lookup often returns ::1 first while another process holds the port on 127.0.0.1: the probe to [::1] fails, the function resolves, serve() binds the IPv6 address, and traffic sent to 127.0.0.1:port silently reaches the foreign listener — exactly the split-listener condition the helper was added to prevent. Same gap for hostnames with multiple A records. Only affects callers passing a DNS hostname (createGitHubEmulator defaults to the literal 127.0.0.1, which skips lookup). export async function assertPortFree(hostname: string | undefined, port: number): Promise<void> {
const host = hostname ?? "127.0.0.1";
if (port === 0 || host === "0.0.0.0" || host === "::") return;
const address = isIP(host)
? host
: await lookup(host).then(
(r) => r.address,
() => undefined,
);
if (!address) return;
const taken = await new Promise<boolean>((resolve) => {
try {
const socket = connect({ host: address, port, timeout: 300 }); |
||||||
| const host = hostname ?? "127.0.0.1"; | ||||||
| if (port === 0 || host === "0.0.0.0" || host === "::") return; | ||||||
| const address = isIP(host) | ||||||
| ? host | ||||||
| : await lookup(host).then( | ||||||
| (r) => r.address, | ||||||
| () => undefined, | ||||||
| ); | ||||||
| if (!address) return; | ||||||
| const taken = await new Promise<boolean>((resolve) => { | ||||||
| try { | ||||||
| const socket = connect({ host: address, port, timeout: 300 }); | ||||||
| const settle = (value: boolean) => { | ||||||
| socket.destroy(); | ||||||
| resolve(value); | ||||||
| }; | ||||||
| socket.once("connect", () => settle(true)); | ||||||
| socket.once("timeout", () => settle(false)); | ||||||
| socket.once("error", () => settle(false)); | ||||||
| } catch { | ||||||
| resolve(false); | ||||||
| } | ||||||
| }); | ||||||
| if (!taken) return; | ||||||
| throw Object.assign(new Error(`listen EADDRINUSE: address already in use ${address}:${port}`), { | ||||||
| code: "EADDRINUSE", | ||||||
| errno: -48, | ||||||
| syscall: "listen", | ||||||
| address, | ||||||
| port, | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| function compilePath(pattern: string): CompiledPath { | ||||||
| if (pattern === "*" || pattern === "/*") { | ||||||
| return { pattern, regex: /^.*$/, paramNames: [] }; | ||||||
| } | ||||||
|
|
||||||
| const prefix = pattern.endsWith("/*"); | ||||||
| const body = prefix ? pattern.slice(0, -2) : pattern; | ||||||
| const paramNames: string[] = []; | ||||||
| let source = "^"; | ||||||
| for (let i = 0; i < pattern.length; i++) { | ||||||
| const char = pattern[i]; | ||||||
| for (let i = 0; i < body.length; i++) { | ||||||
| const char = body[i]; | ||||||
| if (char === "*" && body[i - 1] === "/" && (i + 1 === body.length || body[i + 1] === "/")) { | ||||||
| source += "[^/]+"; | ||||||
| continue; | ||||||
| } | ||||||
| if (char !== ":") { | ||||||
| source += escapeRegex(char); | ||||||
| continue; | ||||||
| } | ||||||
|
|
||||||
| let name = ""; | ||||||
| i++; | ||||||
| while (i < pattern.length && /[A-Za-z0-9_]/.test(pattern[i])) { | ||||||
| name += pattern[i]; | ||||||
| while (i < body.length && /[A-Za-z0-9_]/.test(body[i])) { | ||||||
| name += body[i]; | ||||||
| i++; | ||||||
| } | ||||||
| i--; | ||||||
| paramNames.push(name); | ||||||
|
|
||||||
| if (pattern[i + 1] === "{") { | ||||||
| const close = pattern.indexOf("}", i + 2); | ||||||
| if (body[i + 1] === "{") { | ||||||
| const close = body.indexOf("}", i + 2); | ||||||
| if (close < 0) throw new Error(`Invalid route pattern: ${pattern}`); | ||||||
| const expr = pattern.slice(i + 2, close); | ||||||
| const expr = body.slice(i + 2, close); | ||||||
| source += `(${expr})`; | ||||||
| i = close; | ||||||
| } else { | ||||||
| source += "([^/]+)"; | ||||||
| } | ||||||
| } | ||||||
| source += "$"; | ||||||
| source += prefix ? "(?:/.*)?$" : "$"; | ||||||
| return { pattern, regex: new RegExp(source), paramNames }; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "rootDir": "./src", | ||
| "outDir": "./dist", | ||
| "emitDeclarationOnly": true, | ||
| "declarationMap": false | ||
| }, | ||
| "exclude": ["node_modules", "dist", "src/**/*.test.ts", "src/**/__tests__/**"] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Changelog omits 0.13.1 auth behavior changes.
🤖 Fix with your agent
Why this matters
The 0.13.1 entry documents only the toolchain upgrade, but this PR also ships user-observable auth behavior changes with no entry anywhere: (1)
createGitHubEmulatornow defaultsstrict_scopesto true, so tokens the emulator never issued get 401 Bad credentials instead of silently acting as the fallback user — a breaking change for existing consumers of the published package; (2) newDELETE /applications/:client_id/{token,grant}revocation endpoints; (3) OAuth authorization codes are now bound to the client_id they were issued to; (4) private repositories now answer 404 (not 401/403) to callers who cannot see them (orgs.test.ts expectation changed 403→404). Thestrict_scopesseed option is also absent from the docs. Users upgrading 0.13.0→0.13.1 get silent behavior flips.