@rspack/dev-middleware 2.0.0-beta.2 → 2.0.1
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/README.md +99 -82
- package/dist/index.js +358 -337
- package/package.json +21 -21
- package/types/index.d.ts +15 -14
- package/types/middleware.d.ts +9 -2
- package/types/utils/compatibleAPI.d.ts +8 -8
- package/types/utils/getFilenameFromUrl.d.ts +23 -11
- package/types/utils/getPaths.d.ts +7 -4
- package/types/utils/memorize.d.ts +1 -1
- package/dist/rslib-runtime.js +0 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/dev-middleware",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A development middleware for Rspack",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rspack",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"build": "rslib --syntax es2023 && pnpm run build:types",
|
|
24
24
|
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write",
|
|
25
25
|
"lint": "npm-run-all -l -p \"lint:**\"",
|
|
26
|
+
"lint:rslint": "rslint",
|
|
26
27
|
"lint:prettier": "prettier --cache --list-different .",
|
|
27
28
|
"lint:spelling": "cspell --cache --no-must-find-files --quiet \"**/*.*\"",
|
|
28
29
|
"lint:types": "tsc --pretty --noEmit",
|
|
@@ -32,34 +33,33 @@
|
|
|
32
33
|
"bump": "npx bumpp"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@hapi/hapi": "^21.
|
|
36
|
-
"@hono/node-server": "^1.
|
|
37
|
-
"@rslib/core": "^0.
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@types/express": "^5.0.
|
|
36
|
+
"@hapi/hapi": "^21.4.8",
|
|
37
|
+
"@hono/node-server": "^1.19.14",
|
|
38
|
+
"@rslib/core": "^0.21.1",
|
|
39
|
+
"@rslint/core": "^0.4.2",
|
|
40
|
+
"@rspack/core": "2.0.0-rc.2",
|
|
41
|
+
"@rstest/core": "0.9.7",
|
|
42
|
+
"@types/express": "^5.0.6",
|
|
42
43
|
"@types/node": "^22.3.0",
|
|
43
|
-
"@types/on-finished": "^2.3.
|
|
44
|
+
"@types/on-finished": "^2.3.5",
|
|
44
45
|
"@types/range-parser": "^1.2.7",
|
|
45
|
-
"connect": "^
|
|
46
|
-
"cspell": "^
|
|
47
|
-
"deepmerge": "^4.
|
|
48
|
-
"execa": "^
|
|
49
|
-
"express": "^5.1
|
|
50
|
-
"
|
|
51
|
-
"finalhandler": "^2.1.0",
|
|
46
|
+
"connect-next": "^4.0.1",
|
|
47
|
+
"cspell": "^10.0.0",
|
|
48
|
+
"deepmerge": "^4.3.1",
|
|
49
|
+
"execa": "^9.6.1",
|
|
50
|
+
"express": "^5.2.1",
|
|
51
|
+
"finalhandler": "^2.1.1",
|
|
52
52
|
"hono": "^4.4.13",
|
|
53
|
-
"koa": "^3.
|
|
54
|
-
"memfs": "^4.
|
|
53
|
+
"koa": "^3.2.0",
|
|
54
|
+
"memfs": "^4.57.1",
|
|
55
55
|
"mrmime": "^2.0.1",
|
|
56
56
|
"npm-run-all": "^4.1.5",
|
|
57
57
|
"on-finished": "^2.4.1",
|
|
58
|
-
"prettier": "^3.
|
|
58
|
+
"prettier": "^3.8.3",
|
|
59
59
|
"range-parser": "^1.2.1",
|
|
60
60
|
"router": "^2.2.0",
|
|
61
|
-
"supertest": "^7.
|
|
62
|
-
"typescript": "^
|
|
61
|
+
"supertest": "^7.2.2",
|
|
62
|
+
"typescript": "^6.0.2"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"@rspack/core": "^2.0.0-0"
|
package/types/index.d.ts
CHANGED
|
@@ -95,23 +95,22 @@
|
|
|
95
95
|
* @property {"weak" | "strong"=} etag options to generate etag header
|
|
96
96
|
* @property {boolean=} lastModified options to generate last modified header
|
|
97
97
|
* @property {(boolean | number | string | { maxAge?: number, immutable?: boolean })=} cacheControl options to generate cache headers
|
|
98
|
-
* @property {boolean=} cacheImmutable
|
|
98
|
+
* @property {boolean=} cacheImmutable enable immutable cache headers for immutable assets (defaults to false when omitted)
|
|
99
99
|
*/
|
|
100
100
|
/**
|
|
101
101
|
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
|
102
102
|
* @template {ServerResponse} [ResponseInternal=ServerResponse]
|
|
103
103
|
* @callback Middleware
|
|
104
|
-
* @param {RequestInternal} req
|
|
105
|
-
* @param {ResponseInternal} res
|
|
106
|
-
* @param {NextFunction} next
|
|
104
|
+
* @param {RequestInternal} req request
|
|
105
|
+
* @param {ResponseInternal} res response
|
|
106
|
+
* @param {NextFunction} next next function
|
|
107
107
|
* @returns {Promise<void>}
|
|
108
108
|
*/
|
|
109
|
-
/** @typedef {import("./utils/getFilenameFromUrl").Extra} Extra */
|
|
109
|
+
/** @typedef {import("./utils/getFilenameFromUrl.js").Extra} Extra */
|
|
110
110
|
/**
|
|
111
111
|
* @callback GetFilenameFromUrl
|
|
112
|
-
* @param {string} url
|
|
113
|
-
* @
|
|
114
|
-
* @returns {string | undefined}
|
|
112
|
+
* @param {string} url request URL
|
|
113
|
+
* @returns {{ filename: string, extra: Extra } | undefined} a filename with additional information, or `undefined` if nothing is found
|
|
115
114
|
*/
|
|
116
115
|
/**
|
|
117
116
|
* @callback WaitUntilValid
|
|
@@ -364,7 +363,7 @@ export type Options<
|
|
|
364
363
|
)
|
|
365
364
|
| undefined;
|
|
366
365
|
/**
|
|
367
|
-
*
|
|
366
|
+
* enable immutable cache headers for immutable assets (defaults to false when omitted)
|
|
368
367
|
*/
|
|
369
368
|
cacheImmutable?: boolean | undefined;
|
|
370
369
|
};
|
|
@@ -376,11 +375,13 @@ export type Middleware<
|
|
|
376
375
|
res: ResponseInternal,
|
|
377
376
|
next: NextFunction,
|
|
378
377
|
) => Promise<void>;
|
|
379
|
-
export type Extra = import("./utils/getFilenameFromUrl").Extra;
|
|
380
|
-
export type GetFilenameFromUrl = (
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
378
|
+
export type Extra = import("./utils/getFilenameFromUrl.js").Extra;
|
|
379
|
+
export type GetFilenameFromUrl = (url: string) =>
|
|
380
|
+
| {
|
|
381
|
+
filename: string;
|
|
382
|
+
extra: Extra;
|
|
383
|
+
}
|
|
384
|
+
| undefined;
|
|
384
385
|
export type WaitUntilValid = (callback: Callback) => any;
|
|
385
386
|
export type Invalidate = (callback: Callback) => any;
|
|
386
387
|
export type Close = (callback: (err: Error | null | undefined) => void) => any;
|
package/types/middleware.d.ts
CHANGED
|
@@ -14,20 +14,27 @@ export type SendErrorOptions<
|
|
|
14
14
|
* modify response data callback
|
|
15
15
|
*/
|
|
16
16
|
modifyResponseData?:
|
|
17
|
-
| import("./index").ModifyResponseData<Request, Response>
|
|
17
|
+
| import("./index.js").ModifyResponseData<Request, Response>
|
|
18
18
|
| undefined;
|
|
19
19
|
};
|
|
20
20
|
export type NextFunction = import("./index.js").NextFunction;
|
|
21
21
|
export type IncomingMessage = import("./index.js").IncomingMessage;
|
|
22
22
|
export type ServerResponse = import("./index.js").ServerResponse;
|
|
23
23
|
export type NormalizedHeaders = import("./index.js").NormalizedHeaders;
|
|
24
|
+
export type FilenameError =
|
|
25
|
+
import("./utils/getFilenameFromUrl.js").FilenameError;
|
|
26
|
+
export type Extra = import("./utils/getFilenameFromUrl.js").Extra;
|
|
24
27
|
export type ReadStream = import("fs").ReadStream;
|
|
28
|
+
export type FilenameWithExtra = {
|
|
29
|
+
filename: string;
|
|
30
|
+
extra: Extra;
|
|
31
|
+
};
|
|
25
32
|
/**
|
|
26
33
|
* @template {IncomingMessage} Request
|
|
27
34
|
* @template {ServerResponse} Response
|
|
28
35
|
* @typedef {object} SendErrorOptions send error options
|
|
29
36
|
* @property {Record<string, number | string | string[] | undefined>=} headers headers
|
|
30
|
-
* @property {import("./index").ModifyResponseData<Request, Response>=} modifyResponseData modify response data callback
|
|
37
|
+
* @property {import("./index.js").ModifyResponseData<Request, Response>=} modifyResponseData modify response data callback
|
|
31
38
|
*/
|
|
32
39
|
/**
|
|
33
40
|
* @template {IncomingMessage} Request
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type IncomingMessage = import("../index").IncomingMessage;
|
|
2
|
-
export type ServerResponse = import("../index").ServerResponse;
|
|
3
|
-
export type OutputFileSystem = import("../index").OutputFileSystem;
|
|
4
|
-
export type EXPECTED_ANY = import("../index").EXPECTED_ANY;
|
|
1
|
+
export type IncomingMessage = import("../index.js").IncomingMessage;
|
|
2
|
+
export type ServerResponse = import("../index.js").ServerResponse;
|
|
3
|
+
export type OutputFileSystem = import("../index.js").OutputFileSystem;
|
|
4
|
+
export type EXPECTED_ANY = import("../index.js").EXPECTED_ANY;
|
|
5
5
|
export type ExpectedIncomingMessage = {
|
|
6
6
|
/**
|
|
7
7
|
* get header extra method
|
|
@@ -111,10 +111,10 @@ export function getHeadersSent<
|
|
|
111
111
|
export function getOutgoing<
|
|
112
112
|
Response extends ServerResponse & ExpectedServerResponse,
|
|
113
113
|
>(res: Response): Response;
|
|
114
|
-
/** @typedef {import("../index").IncomingMessage} IncomingMessage */
|
|
115
|
-
/** @typedef {import("../index").ServerResponse} ServerResponse */
|
|
116
|
-
/** @typedef {import("../index").OutputFileSystem} OutputFileSystem */
|
|
117
|
-
/** @typedef {import("../index").EXPECTED_ANY} EXPECTED_ANY */
|
|
114
|
+
/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
|
|
115
|
+
/** @typedef {import("../index.js").ServerResponse} ServerResponse */
|
|
116
|
+
/** @typedef {import("../index.js").OutputFileSystem} OutputFileSystem */
|
|
117
|
+
/** @typedef {import("../index.js").EXPECTED_ANY} EXPECTED_ANY */
|
|
118
118
|
/**
|
|
119
119
|
* @typedef {object} ExpectedIncomingMessage
|
|
120
120
|
* @property {((name: string) => string | string[] | undefined)=} getHeader get header extra method
|
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
export default getFilenameFromUrl;
|
|
2
2
|
export type IncomingMessage = import("../index.js").IncomingMessage;
|
|
3
|
+
export type OutputFileSystem = import("../index.js").OutputFileSystem;
|
|
3
4
|
export type ServerResponse = import("../index.js").ServerResponse;
|
|
5
|
+
export type FSStats = import("fs").Stats;
|
|
6
|
+
export type FilenameWithExtra = {
|
|
7
|
+
filename: string;
|
|
8
|
+
extra: Extra;
|
|
9
|
+
};
|
|
4
10
|
export type Extra = {
|
|
5
11
|
/**
|
|
6
12
|
* stats
|
|
7
13
|
*/
|
|
8
|
-
stats
|
|
9
|
-
/**
|
|
10
|
-
* error code
|
|
11
|
-
*/
|
|
12
|
-
errorCode?: number | undefined;
|
|
14
|
+
stats: FSStats;
|
|
13
15
|
/**
|
|
14
16
|
* true when immutable, otherwise false
|
|
15
17
|
*/
|
|
16
18
|
immutable?: boolean | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* output file system
|
|
21
|
+
*/
|
|
22
|
+
outputFileSystem: OutputFileSystem;
|
|
17
23
|
};
|
|
18
24
|
/**
|
|
19
25
|
* @typedef {object} Extra
|
|
20
|
-
* @property {
|
|
21
|
-
* @property {number=} errorCode error code
|
|
26
|
+
* @property {FSStats} stats stats
|
|
22
27
|
* @property {boolean=} immutable true when immutable, otherwise false
|
|
28
|
+
* @property {OutputFileSystem} outputFileSystem output file system
|
|
23
29
|
*/
|
|
24
30
|
/**
|
|
25
31
|
* decodeURIComponent.
|
|
@@ -28,13 +34,20 @@ export type Extra = {
|
|
|
28
34
|
* @param {string} input
|
|
29
35
|
* @returns {string}
|
|
30
36
|
*/
|
|
37
|
+
export class FilenameError extends Error {
|
|
38
|
+
/**
|
|
39
|
+
* @param {string} message message
|
|
40
|
+
* @param {number=} code error code
|
|
41
|
+
*/
|
|
42
|
+
constructor(message: string, code?: number | undefined);
|
|
43
|
+
statusCode: number | undefined;
|
|
44
|
+
}
|
|
31
45
|
/**
|
|
32
46
|
* @template {IncomingMessage} Request
|
|
33
47
|
* @template {ServerResponse} Response
|
|
34
48
|
* @param {import("../index.js").FilledContext<Request, Response>} context context
|
|
35
49
|
* @param {string} url url
|
|
36
|
-
* @
|
|
37
|
-
* @returns {string | undefined} filename
|
|
50
|
+
* @returns {FilenameWithExtra | undefined} result of get filename from url
|
|
38
51
|
*/
|
|
39
52
|
declare function getFilenameFromUrl<
|
|
40
53
|
Request extends IncomingMessage,
|
|
@@ -42,5 +55,4 @@ declare function getFilenameFromUrl<
|
|
|
42
55
|
>(
|
|
43
56
|
context: import("../index.js").FilledContext<Request, Response>,
|
|
44
57
|
url: string,
|
|
45
|
-
|
|
46
|
-
): string | undefined;
|
|
58
|
+
): FilenameWithExtra | undefined;
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
export default getPaths;
|
|
2
2
|
export type Compiler = import("@rspack/core").Compiler;
|
|
3
|
+
export type Compilation = import("@rspack/core").Compilation;
|
|
3
4
|
export type Stats = import("@rspack/core").Stats;
|
|
4
5
|
export type MultiStats = import("@rspack/core").MultiStats;
|
|
5
|
-
export type Asset = import("@rspack/core").Asset;
|
|
6
6
|
export type DevServerOption = import("../index.js").DevServerOption;
|
|
7
7
|
export type IncomingMessage = import("../index.js").IncomingMessage;
|
|
8
|
+
export type OutputFileSystem = import("../index.js").OutputFileSystem;
|
|
8
9
|
export type ServerResponse = import("../index.js").ServerResponse;
|
|
9
10
|
/** @typedef {import("@rspack/core").Compiler} Compiler */
|
|
11
|
+
/** @typedef {import("@rspack/core").Compilation} Compilation */
|
|
10
12
|
/** @typedef {import("@rspack/core").Stats} Stats */
|
|
11
13
|
/** @typedef {import("@rspack/core").MultiStats} MultiStats */
|
|
12
|
-
/** @typedef {import("@rspack/core").Asset} Asset */
|
|
13
14
|
/** @typedef {import("../index.js").DevServerOption} DevServerOption */
|
|
14
15
|
/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
|
|
16
|
+
/** @typedef {import("../index.js").OutputFileSystem} OutputFileSystem */
|
|
15
17
|
/** @typedef {import("../index.js").ServerResponse} ServerResponse */
|
|
16
18
|
/**
|
|
17
19
|
* @template {IncomingMessage} Request
|
|
18
20
|
* @template {ServerResponse} Response
|
|
19
21
|
* @param {import("../index.js").FilledContext<Request, Response>} context context
|
|
20
|
-
* @returns {{
|
|
22
|
+
* @returns {{ compilation: Compilation, outputPath: string, outputFileSystem: OutputFileSystem, publicPath: string }[]} paths
|
|
21
23
|
*/
|
|
22
24
|
declare function getPaths<
|
|
23
25
|
Request extends IncomingMessage,
|
|
@@ -25,7 +27,8 @@ declare function getPaths<
|
|
|
25
27
|
>(
|
|
26
28
|
context: import("../index.js").FilledContext<Request, Response>,
|
|
27
29
|
): {
|
|
30
|
+
compilation: Compilation;
|
|
28
31
|
outputPath: string;
|
|
32
|
+
outputFileSystem: OutputFileSystem;
|
|
29
33
|
publicPath: string;
|
|
30
|
-
assetsInfo: Map<string, Asset["info"]> | undefined;
|
|
31
34
|
}[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default memorize;
|
|
2
2
|
export type FunctionReturning<T> = (...args: EXPECTED_ANY) => T;
|
|
3
|
-
export type EXPECTED_ANY = import("../index").EXPECTED_ANY;
|
|
3
|
+
export type EXPECTED_ANY = import("../index.js").EXPECTED_ANY;
|
|
4
4
|
/**
|
|
5
5
|
* @template T
|
|
6
6
|
* @typedef {(...args: EXPECTED_ANY) => T} FunctionReturning
|
package/dist/rslib-runtime.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
var __webpack_modules__ = {};
|
|
2
|
-
var __webpack_module_cache__ = {};
|
|
3
|
-
function __webpack_require__(moduleId) {
|
|
4
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
5
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
6
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
7
|
-
exports: {}
|
|
8
|
-
};
|
|
9
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
10
|
-
return module.exports;
|
|
11
|
-
}
|
|
12
|
-
__webpack_require__.m = __webpack_modules__;
|
|
13
|
-
(()=>{
|
|
14
|
-
__webpack_require__.d = (exports, definition)=>{
|
|
15
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: definition[key]
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
})();
|
|
21
|
-
(()=>{
|
|
22
|
-
__webpack_require__.add = function(modules) {
|
|
23
|
-
Object.assign(__webpack_require__.m, modules);
|
|
24
|
-
};
|
|
25
|
-
})();
|
|
26
|
-
(()=>{
|
|
27
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
28
|
-
})();
|
|
29
|
-
export { __webpack_require__ };
|