Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,179 changes: 1,893 additions & 1,286 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 2 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,23 @@
"@babel/cli": "^7.16.7",
"@babel/core": "^7.16.7",
"@babel/preset-env": "^7.16.7",
"@eslint/js": "^9.28.0",
"@eslint/markdown": "^7.1.0",
"@commitlint/cli": "^20.2.0",
"@commitlint/config-conventional": "^20.2.0",
"@fastify/express": "^4.0.2",
"@hapi/hapi": "^21.3.7",
"@hono/node-server": "^1.12.0",
"@stylistic/eslint-plugin": "^5.3.1",
"@types/connect": "^3.4.35",
"@types/express": "^5.0.2",
"@types/mime-types": "^3.0.1",
"@types/node": "^22.3.0",
"@types/on-finished": "^2.3.4",
"babel-jest": "^30.1.2",
"connect": "^3.7.0",
"cspell": "^8.3.2",
"cspell": "^9.6.2",
"deepmerge": "^4.2.2",
"del-cli": "^6.0.0",
"globals": "^16.2.0",
"eslint": "^9.28.0",
"eslint-config-webpack": "^4.5.0",
"eslint-config-prettier": "^10.1.5",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^29.0.1",
"eslint-plugin-jsdoc": "^61.5.0",
"eslint-plugin-n": "^17.19.0",
"eslint-plugin-prettier": "^5.4.1",
"eslint-plugin-unicorn": "^62.0.0",
"execa": "^5.1.1",
"express-4": "npm:express@^4",
"express": "^5.1.0",
Expand All @@ -96,7 +85,7 @@
"husky": "^9.1.3",
"jest": "^30.1.3",
"koa": "^3.0.0",
"lint-staged": "^15.2.0",
"lint-staged": "^16.2.7",
"npm-run-all": "^4.1.5",
"prettier": "^3.6.0",
"router": "^2.2.0",
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ const noop = () => {};
* @typedef {WithoutUndefined<Context<RequestInternal, ResponseInternal>, "watching">} FilledContext
*/

/** @typedef {Record<string, string | number> | Array<{ key: string, value: number | string }>} NormalizedHeaders */
/** @typedef {Record<string, string | number> | { key: string, value: number | string }[]} NormalizedHeaders */

/**
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
* @template {ServerResponse} [ResponseInternal=ServerResponse]
* @typedef {NormalizedHeaders | ((req: RequestInternal, res: ResponseInternal, context: Context<RequestInternal, ResponseInternal>) => void | undefined | NormalizedHeaders) | undefined} Headers
* @typedef {NormalizedHeaders | ((req: RequestInternal, res: ResponseInternal, context: Context<RequestInternal, ResponseInternal>) => void | undefined | NormalizedHeaders) | undefined} Headers
*/

/**
Expand Down Expand Up @@ -401,7 +401,7 @@ function koaWrapper(compiler, options) {
const devMiddleware = wdm(compiler, options);

/**
* @param {{req: RequestInternal, res: ResponseInternal & import("./utils/compatibleAPI").ExpectedServerResponse, status: number, body: string | Buffer | import("fs").ReadStream | {message: string}, state: object}} ctx context
* @param {{ req: RequestInternal, res: ResponseInternal & import("./utils/compatibleAPI").ExpectedServerResponse, status: number, body: string | Buffer | import("fs").ReadStream | { message: string }, state: object }} ctx context
* @param {EXPECTED_FUNCTION} next next
* @returns {Promise<void>}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ function wrapper(context) {
}

/**
* @type {{key: string, value: string | number}[]}
* @type {{ key: string, value: string | number }[]}
*/
const allHeaders = [];

Expand Down
5 changes: 5 additions & 0 deletions src/utils/compatibleAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @property {((name: string) => string | string[] | undefined)=} getHeader get header extra method
* @property {(() => string | undefined)=} getMethod get method extra method
* @property {(() => string | undefined)=} getURL get URL extra method
* @property {string=} originalUrl an extra option for `fastify` (and `@fastify/express`) to get original URL
*/

/**
Expand Down Expand Up @@ -65,6 +66,10 @@ function getRequestURL(req) {
if (typeof req.getURL === "function") {
return req.getURL();
}
// Fastify decodes URI by default, Our logic is based on encoded URI
else if (typeof req.originalUrl !== "undefined") {
return req.originalUrl;
}

return req.url;
}
Expand Down
4 changes: 2 additions & 2 deletions test/middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5366,10 +5366,10 @@ describe.each([

isDirectory = jest
.spyOn(instance.context.outputFileSystem, "statSync")
.mockImplementation(() => ({
.mockReturnValue({
isFile: () => false,
isDirectory: () => false,
}));
});
});

afterAll(async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/utils/setupOutputFileSystem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import setupOutputFileSystem from "../../src/utils/setupOutputFileSystem";

const createFsFromVolume = jest.spyOn(memfs, "createFsFromVolume");

createFsFromVolume.mockImplementation(() => ({
createFsFromVolume.mockReturnValue({
testFs: true,
}));
});

describe("setupOutputFileSystem", () => {
afterEach(() => {
Expand Down
8 changes: 4 additions & 4 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ export = wdm;
* @template {ServerResponse} [ResponseInternal=ServerResponse]
* @typedef {WithoutUndefined<Context<RequestInternal, ResponseInternal>, "watching">} FilledContext
*/
/** @typedef {Record<string, string | number> | Array<{ key: string, value: number | string }>} NormalizedHeaders */
/** @typedef {Record<string, string | number> | { key: string, value: number | string }[]} NormalizedHeaders */
/**
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
* @template {ServerResponse} [ResponseInternal=ServerResponse]
* @typedef {NormalizedHeaders | ((req: RequestInternal, res: ResponseInternal, context: Context<RequestInternal, ResponseInternal>) => void | undefined | NormalizedHeaders) | undefined} Headers
* @typedef {NormalizedHeaders | ((req: RequestInternal, res: ResponseInternal, context: Context<RequestInternal, ResponseInternal>) => void | undefined | NormalizedHeaders) | undefined} Headers
*/
/**
* @template {IncomingMessage} [RequestInternal = IncomingMessage]
Expand Down Expand Up @@ -355,10 +355,10 @@ type FilledContext<
> = WithoutUndefined<Context<RequestInternal, ResponseInternal>, "watching">;
type NormalizedHeaders =
| Record<string, string | number>
| Array<{
| {
key: string;
value: number | string;
}>;
}[];
type Headers<
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
ResponseInternal extends ServerResponse = ServerResponse,
Expand Down
5 changes: 5 additions & 0 deletions types/utils/compatibleAPI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export type ExpectedIncomingMessage = {
* get URL extra method
*/
getURL?: (() => string | undefined) | undefined;
/**
* an extra option for `fastify` (and `@fastify/express`) to get original URL
*/
originalUrl?: string | undefined;
};
export type ExpectedServerResponse = {
/**
Expand Down Expand Up @@ -120,6 +124,7 @@ export function getOutgoing<
* @property {((name: string) => string | string[] | undefined)=} getHeader get header extra method
* @property {(() => string | undefined)=} getMethod get method extra method
* @property {(() => string | undefined)=} getURL get URL extra method
* @property {string=} originalUrl an extra option for `fastify` (and `@fastify/express`) to get original URL
*/
/**
* @typedef {object} ExpectedServerResponse
Expand Down