Skip to content
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

fix(types): proxy #5101

Merged
merged 1 commit into from Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 34 additions & 42 deletions lib/Server.js
Expand Up @@ -126,10 +126,6 @@
* @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray
*/

/**
* @typedef {{ [url: string]: string | ProxyConfigArrayItem }} ProxyConfigMap
*/

/**
* @typedef {Object} OpenApp
* @property {string} [name]
Expand Down Expand Up @@ -198,7 +194,7 @@
* @property {boolean} [http2]
* @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server]
* @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer]
* @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy]
* @property {ProxyConfigArray} [proxy]
* @property {boolean | string | Open | Array<string | Open>} [open]
* @property {boolean} [setupExitSignals]
* @property {boolean | ClientConfiguration} [client]
Expand Down Expand Up @@ -1317,48 +1313,45 @@
* }
*/
if (typeof options.proxy !== "undefined") {
/** @type {ProxyConfigArray} */
(options.proxy) =
/** @type {ProxyConfigArray} */
(options.proxy).map((item) => {
if (typeof item === "function") {
return item;
}
options.proxy = options.proxy.map((item) => {
if (typeof item === "function") {
return item;
}

/**
* @param {"info" | "warn" | "error" | "debug" | "silent" | undefined | "none" | "log" | "verbose"} level
* @returns {"info" | "warn" | "error" | "debug" | "silent" | undefined}
*/
const getLogLevelForProxy = (level) => {
if (level === "none") {
return "silent";
}
/**
* @param {"info" | "warn" | "error" | "debug" | "silent" | undefined | "none" | "log" | "verbose"} level
* @returns {"info" | "warn" | "error" | "debug" | "silent" | undefined}
*/
const getLogLevelForProxy = (level) => {
if (level === "none") {
return "silent";
}

if (level === "log") {
return "info";
}
if (level === "log") {
return "info";

Check warning on line 1331 in lib/Server.js

View check run for this annotation

Codecov / codecov/patch

lib/Server.js#L1331

Added line #L1331 was not covered by tests
}

if (level === "verbose") {
return "debug";
}
if (level === "verbose") {
return "debug";

Check warning on line 1335 in lib/Server.js

View check run for this annotation

Codecov / codecov/patch

lib/Server.js#L1335

Added line #L1335 was not covered by tests
}

return level;
};
return level;
};

if (typeof item.logLevel === "undefined") {
item.logLevel = getLogLevelForProxy(
compilerOptions.infrastructureLogging
? compilerOptions.infrastructureLogging.level
: "info",
);
}
if (typeof item.logLevel === "undefined") {
item.logLevel = getLogLevelForProxy(
compilerOptions.infrastructureLogging
? compilerOptions.infrastructureLogging.level
: "info",

Check warning on line 1345 in lib/Server.js

View check run for this annotation

Codecov / codecov/patch

lib/Server.js#L1345

Added line #L1345 was not covered by tests
);
}

if (typeof item.logProvider === "undefined") {
item.logProvider = () => this.logger;
}
if (typeof item.logProvider === "undefined") {
item.logProvider = () => this.logger;
}

return item;
});
return item;
});
}

if (typeof options.setupExitSignals === "undefined") {
Expand Down Expand Up @@ -2045,8 +2038,7 @@
* }
* ]
*/
/** @type {ProxyConfigArray} */
(this.options.proxy).forEach((proxyConfigOrCallback) => {
this.options.proxy.forEach((proxyConfigOrCallback) => {
/**
* @type {RequestHandler}
*/
Expand Down
124 changes: 40 additions & 84 deletions types/lib/Server.d.ts
Expand Up @@ -153,9 +153,6 @@ declare class Server {
/**
* @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray
*/
/**
* @typedef {{ [url: string]: string | ProxyConfigArrayItem }} ProxyConfigMap
*/
/**
* @typedef {Object} OpenApp
* @property {string} [name]
Expand Down Expand Up @@ -216,7 +213,7 @@ declare class Server {
* @property {boolean} [http2]
* @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server]
* @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer]
* @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy]
* @property {ProxyConfigArray} [proxy]
* @property {boolean | string | Open | Array<string | Open>} [open]
* @property {boolean} [setupExitSignals]
* @property {boolean | ClientConfiguration} [client]
Expand Down Expand Up @@ -323,69 +320,6 @@ declare class Server {
)[];
};
trustedTypesPolicyName: {
/**
* @typedef {Object} Open
* @property {string | string[] | OpenApp} [app]
* @property {string | string[]} [target]
*/
/**
* @typedef {Object} NormalizedOpen
* @property {string} target
* @property {import("open").Options} options
*/
/**
* @typedef {Object} WebSocketURL
* @property {string} [hostname]
* @property {string} [password]
* @property {string} [pathname]
* @property {number | string} [port]
* @property {string} [protocol]
* @property {string} [username]
*/
/**
* @typedef {boolean | ((error: Error) => void)} OverlayMessageOptions
*/
/**
* @typedef {Object} ClientConfiguration
* @property {"log" | "info" | "warn" | "error" | "none" | "verbose"} [logging]
* @property {boolean | { warnings?: OverlayMessageOptions, errors?: OverlayMessageOptions, runtimeErrors?: OverlayMessageOptions }} [overlay]
* @property {boolean} [progress]
* @property {boolean | number} [reconnect]
* @property {"ws" | "sockjs" | string} [webSocketTransport]
* @property {string | WebSocketURL} [webSocketURL]
*/
/**
* @typedef {Array<{ key: string; value: string }> | Record<string, string | string[]>} Headers
*/
/**
* @typedef {{ name?: string, path?: string, middleware: ExpressRequestHandler | ExpressErrorRequestHandler } | ExpressRequestHandler | ExpressErrorRequestHandler} Middleware
*/
/**
* @typedef {Object} Configuration
* @property {boolean | string} [ipc]
* @property {Host} [host]
* @property {Port} [port]
* @property {boolean | "only"} [hot]
* @property {boolean} [liveReload]
* @property {DevMiddlewareOptions<Request, Response>} [devMiddleware]
* @property {boolean} [compress]
* @property {"auto" | "all" | string | string[]} [allowedHosts]
* @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback]
* @property {boolean | Record<string, never> | BonjourOptions} [bonjour]
* @property {string | string[] | WatchFiles | Array<string | WatchFiles>} [watchFiles]
* @property {boolean | string | Static | Array<string | Static>} [static]
* @property {boolean | ServerOptions} [https]
* @property {boolean} [http2]
* @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server]
* @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer]
* @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy]
* @property {boolean | string | Open | Array<string | Open>} [open]
* @property {boolean} [setupExitSignals]
* @property {boolean | ClientConfiguration} [client]
* @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext<Request, Response>) => Headers)} [headers]
* @property {(devServer: Server) => void} [onListening]
* @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares]
*/
description: string;
type: string;
};
Expand Down Expand Up @@ -423,6 +357,35 @@ declare class Server {
)[];
};
ClientWebSocketTransport: {
/**
* @typedef {{ name?: string, path?: string, middleware: ExpressRequestHandler | ExpressErrorRequestHandler } | ExpressRequestHandler | ExpressErrorRequestHandler} Middleware
*/
/**
* @typedef {Object} Configuration
* @property {boolean | string} [ipc]
* @property {Host} [host]
* @property {Port} [port]
* @property {boolean | "only"} [hot]
* @property {boolean} [liveReload]
* @property {DevMiddlewareOptions<Request, Response>} [devMiddleware]
* @property {boolean} [compress]
* @property {"auto" | "all" | string | string[]} [allowedHosts]
* @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback]
* @property {boolean | Record<string, never> | BonjourOptions} [bonjour]
* @property {string | string[] | WatchFiles | Array<string | WatchFiles>} [watchFiles]
* @property {boolean | string | Static | Array<string | Static>} [static]
* @property {boolean | ServerOptions} [https]
* @property {boolean} [http2]
* @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server]
* @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer]
* @property {ProxyConfigArray} [proxy]
* @property {boolean | string | Open | Array<string | Open>} [open]
* @property {boolean} [setupExitSignals]
* @property {boolean | ClientConfiguration} [client]
* @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext<Request, Response>) => Headers)} [headers]
* @property {(devServer: Server) => void} [onListening]
* @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares]
*/
anyOf: {
$ref: string;
}[];
Expand Down Expand Up @@ -516,6 +479,9 @@ declare class Server {
};
HeaderObject: {
type: string;
/**
* @type {FSWatcher[]}
*/
additionalProperties: boolean;
properties: {
key: {
Expand All @@ -539,9 +505,6 @@ declare class Server {
$ref: string;
};
minItems: number;
/**
* @type {Socket[]}
*/
instanceof?: undefined;
}
| {
Expand Down Expand Up @@ -641,11 +604,6 @@ declare class Server {
OnListening: {
instanceof: string;
description: string;
/**
* @param {Port} port
* @param {string} host
* @returns {Promise<number | string>}
*/
link: string;
};
Open: {
Expand Down Expand Up @@ -773,19 +731,20 @@ declare class Server {
}
)[];
description: string;
link: string;
link: string /** @type {WebSocketURL} */;
};
Proxy: {
type: string;
items: {
anyOf: (
| {
type: string;
/** @type {WebSocketURL} */ instanceof?: undefined;
instanceof?: undefined;
}
| {
instanceof: string;
/** @type {ClientConfiguration} */ type?: undefined;
/** @type {{ type: WebSocketServerConfiguration["type"], options: NonNullable<WebSocketServerConfiguration["options"]> }} */
type?: undefined;
}
)[];
};
Expand All @@ -811,6 +770,7 @@ declare class Server {
ServerString: {
type: string;
minLength: number;
/** @type {string} */
cli: {
exclude: boolean;
};
Expand Down Expand Up @@ -1190,7 +1150,7 @@ declare class Server {
};
WatchFilesString: {
type: string;
/** @type {NormalizedStatic} */ minLength: number;
minLength: number;
};
WebSocketServer: {
anyOf: {
Expand Down Expand Up @@ -1652,7 +1612,6 @@ declare namespace Server {
ByPass,
ProxyConfigArrayItem,
ProxyConfigArray,
ProxyConfigMap,
OpenApp,
Open,
NormalizedOpen,
Expand Down Expand Up @@ -1810,9 +1769,6 @@ type ProxyConfigArray = (
next?: NextFunction | undefined,
) => ProxyConfigArrayItem)
)[];
type ProxyConfigMap = {
[url: string]: string | ProxyConfigArrayItem;
};
type OpenApp = {
name?: string | undefined;
arguments?: string[] | undefined;
Expand Down Expand Up @@ -1903,7 +1859,7 @@ type Configuration = {
http2?: boolean | undefined;
server?: string | ServerConfiguration | undefined;
webSocketServer?: string | boolean | WebSocketServerConfiguration | undefined;
proxy?: ProxyConfigArrayItem | ProxyConfigMap | ProxyConfigArray | undefined;
proxy?: ProxyConfigArray | undefined;
open?: string | boolean | Open | (string | Open)[] | undefined;
setupExitSignals?: boolean | undefined;
client?: boolean | ClientConfiguration | undefined;
Expand Down