Skip to content

Conversation

@n0th1ng-else
Copy link
Contributor

@n0th1ng-else n0th1ng-else commented May 29, 2025

Summary

It will be convenient to have the Dev Server Middleware types exported from the rspack. All our middleware is written in separate modules and annotated with JSDoc types.
By exporting the type, we can ge rid of webpack-dev-server mentions in the annotation and use import('@rspack/core').DevServerMiddleware to type the middleware we have.

I have also made an effort to narrow the Middleware type so it is aligned with the one in the webpack-dev-middleware.

(see https://github.com/webpack/webpack-dev-middleware/blob/master/types/index.d.ts#L370)

Example

/**
 * @return {import('@rspack/core').DevServerMiddleware}
 */
module.exports = function DevServerPreflightRequestsMiddleware() {
	return {
		name: 'DevServerPreflightRequestsMiddleware',
		middleware: (req, res, next) => {
			if (req.method === 'OPTIONS') {
				res.statusCode = 204
				res.setHeader('Content-Length', '0')
				res.end()
				return
			}
			next()
		},
	}
}
image

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

It will be convenient to have the Dev Server Middleware types exported from
the rspack. All our middleware is written in separate modules and annotated
with JSDoc types.
By exporting the type, we can ge rid of webpack-dev-server mentions in the
annotation and use `import('@rspack/core').DevServerMiddleware` to type
the middleware we have.

I have also made an effort to narrow the Middleware type so it is aligned
with the one in the webpack-dev-middleware.

(see https://github.com/webpack/webpack-dev-middleware/blob/master/types/index.d.ts#L370)
@netlify
Copy link

netlify bot commented May 29, 2025

Deploy Preview for rspack canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 6adc201
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6838ead988406e0008a58104

@github-actions github-actions bot added the release: bug fix release: bug related release(mr only) label May 29, 2025
@n0th1ng-else n0th1ng-else marked this pull request as ready for review May 29, 2025 23:18
@codspeed-hq
Copy link

codspeed-hq bot commented May 29, 2025

CodSpeed Performance Report

Merging #10522 will not alter performance

Comparing n0th1ng-else:middleware-type (6adc201) with main (8450da9)

Summary

✅ 12 untouched benchmarks

@chenjiahan chenjiahan requested a review from LingyuCoder May 30, 2025 02:21
@chenjiahan
Copy link
Member

@LingyuCoder cc~

@chenjiahan
Copy link
Member

@LingyuCoder Pin again..

Copy link
Contributor

@LingyuCoder LingyuCoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@LingyuCoder LingyuCoder merged commit a96879e into web-infra-dev:main Jun 10, 2025
45 checks passed
@n0th1ng-else n0th1ng-else deleted the middleware-type branch June 10, 2025 14:56
@n0th1ng-else
Copy link
Contributor Author

Thank you both! Appreciate your time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants