@rspack/dev-middleware 0.2.12 → 2.0.0-beta.0
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/LICENSE +17 -19
- package/README.md +735 -10
- package/dist/index.js +9291 -15
- package/dist/index.js.LICENSE.txt +19 -0
- package/dist/rslib-runtime.js +29 -0
- package/package.json +70 -19
- package/types/index.d.ts +487 -0
- package/types/middleware.d.ts +43 -0
- package/types/utils/compatibleAPI.d.ts +261 -0
- package/types/utils/escapeHtml.d.ts +6 -0
- package/types/utils/etag.d.ts +12 -0
- package/types/utils/getFilenameFromUrl.d.ts +46 -0
- package/types/utils/getPaths.d.ts +31 -0
- package/types/utils/memorize.d.ts +33 -0
- package/types/utils/parseTokenList.d.ts +7 -0
- package/types/utils/ready.d.ts +23 -0
- package/types/utils/setupHooks.d.ts +40 -0
- package/types/utils/setupOutputFileSystem.d.ts +23 -0
- package/types/utils/setupWriteToDisk.d.ts +21 -0
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/index.cjs +0 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ee-first
|
|
3
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
4
|
+
* MIT Licensed
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/*!
|
|
8
|
+
* on-finished
|
|
9
|
+
* Copyright(c) 2013 Jonathan Ong
|
|
10
|
+
* Copyright(c) 2014 Douglas Christopher Wilson
|
|
11
|
+
* MIT Licensed
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/*!
|
|
15
|
+
* range-parser
|
|
16
|
+
* Copyright(c) 2012-2014 TJ Holowaychuk
|
|
17
|
+
* Copyright(c) 2015-2016 Douglas Christopher Wilson
|
|
18
|
+
* MIT Licensed
|
|
19
|
+
*/
|
|
@@ -0,0 +1,29 @@
|
|
|
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__ };
|
package/package.json
CHANGED
|
@@ -1,27 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/dev-middleware",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
|
+
"description": "A development middleware for Rspack",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rspack",
|
|
7
|
+
"middleware",
|
|
8
|
+
"development"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/rstackjs/rspack-dev-middleware",
|
|
11
|
+
"bugs": "https://github.com/rstackjs/rspack-dev-middleware/issues",
|
|
12
|
+
"repository": "rstackjs/rspack-dev-middleware",
|
|
4
13
|
"license": "MIT",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
14
|
+
"author": "Tobias Koppers @sokra",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "types/index.d.ts",
|
|
8
18
|
"files": [
|
|
9
|
-
"
|
|
10
|
-
"
|
|
19
|
+
"dist",
|
|
20
|
+
"types"
|
|
11
21
|
],
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "rslib --syntax es2023 && pnpm run build:types",
|
|
24
|
+
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write",
|
|
25
|
+
"lint": "npm-run-all -l -p \"lint:**\"",
|
|
26
|
+
"lint:prettier": "prettier --cache --list-different .",
|
|
27
|
+
"lint:spelling": "cspell --cache --no-must-find-files --quiet \"**/*.*\"",
|
|
28
|
+
"lint:types": "tsc --pretty --noEmit",
|
|
29
|
+
"prepare": "pnpm run build",
|
|
30
|
+
"test": "rstest",
|
|
31
|
+
"test:watch": "rstest -w",
|
|
32
|
+
"bump": "npx bumpp"
|
|
18
33
|
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"@
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@fastify/express": "^4.0.2",
|
|
36
|
+
"@hapi/hapi": "^21.3.7",
|
|
37
|
+
"@hono/node-server": "^1.12.0",
|
|
38
|
+
"@rslib/core": "^0.20.0",
|
|
39
|
+
"@rspack/core": "2.0.0-beta.5",
|
|
40
|
+
"@rstest/core": "0.9.2",
|
|
41
|
+
"@types/connect": "^3.4.35",
|
|
42
|
+
"@types/express": "^5.0.2",
|
|
43
|
+
"@types/node": "^22.3.0",
|
|
44
|
+
"@types/on-finished": "^2.3.4",
|
|
45
|
+
"@types/range-parser": "^1.2.7",
|
|
46
|
+
"connect": "^3.7.0",
|
|
47
|
+
"cspell": "^9.6.2",
|
|
48
|
+
"deepmerge": "^4.2.2",
|
|
49
|
+
"execa": "^5.1.1",
|
|
50
|
+
"express": "^5.1.0",
|
|
51
|
+
"fastify": "^5.2.1",
|
|
52
|
+
"file-loader": "^6.2.0",
|
|
53
|
+
"finalhandler": "^2.1.0",
|
|
54
|
+
"hono": "^4.4.13",
|
|
55
|
+
"koa": "^3.0.0",
|
|
56
|
+
"memfs": "^4.43.1",
|
|
57
|
+
"mrmime": "^2.0.1",
|
|
58
|
+
"npm-run-all": "^4.1.5",
|
|
59
|
+
"on-finished": "^2.4.1",
|
|
60
|
+
"prettier": "^3.6.0",
|
|
61
|
+
"range-parser": "^1.2.1",
|
|
62
|
+
"router": "^2.2.0",
|
|
63
|
+
"supertest": "^7.0.0",
|
|
64
|
+
"typescript": "^5.3.3"
|
|
22
65
|
},
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"@rspack/core": "^2.0.0-0"
|
|
68
|
+
},
|
|
69
|
+
"peerDependenciesMeta": {
|
|
70
|
+
"@rspack/core": {
|
|
71
|
+
"optional": true
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"packageManager": "pnpm@10.21.0",
|
|
75
|
+
"engines": {
|
|
76
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
26
77
|
}
|
|
27
|
-
}
|
|
78
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
/** @typedef {import("@rspack/core").Compiler} Compiler */
|
|
2
|
+
/** @typedef {import("@rspack/core").MultiCompiler} MultiCompiler */
|
|
3
|
+
/** @typedef {import("@rspack/core").Configuration} Configuration */
|
|
4
|
+
/** @typedef {import("@rspack/core").Stats} Stats */
|
|
5
|
+
/** @typedef {import("@rspack/core").MultiStats} MultiStats */
|
|
6
|
+
/** @typedef {import("fs").ReadStream} ReadStream */
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {object} ExtendedServerResponse
|
|
9
|
+
* @property {{ rspack?: { devMiddleware?: Context<IncomingMessage, ServerResponse> }, webpack?: { devMiddleware?: Context<IncomingMessage, ServerResponse> } }=} locals locals
|
|
10
|
+
*/
|
|
11
|
+
/** @typedef {import("http").IncomingMessage} IncomingMessage */
|
|
12
|
+
/** @typedef {import("http").ServerResponse & ExtendedServerResponse} ServerResponse */
|
|
13
|
+
/** @typedef {any} EXPECTED_ANY */
|
|
14
|
+
/** @typedef {Function} EXPECTED_FUNCTION */
|
|
15
|
+
/**
|
|
16
|
+
* @callback NextFunction
|
|
17
|
+
* @param {EXPECTED_ANY=} err error
|
|
18
|
+
* @returns {void}
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {NonNullable<Configuration["watchOptions"]>} WatchOptions
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {boolean | Configuration["devServer"] | undefined} DevServerOption
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {Compiler["watching"]} Watching
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {ReturnType<MultiCompiler["watch"]>} MultiWatching
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* @typedef {import("@rspack/core").OutputFileSystem & { createReadStream?: import("fs").createReadStream, statSync: import("fs").statSync, readFileSync: import("fs").readFileSync }} OutputFileSystem
|
|
34
|
+
*/
|
|
35
|
+
/** @typedef {ReturnType<Compiler["getInfrastructureLogger"]>} Logger */
|
|
36
|
+
/** @typedef {{ close(callback: (err?: Error | null | undefined) => void): void }} ClosableWatching */
|
|
37
|
+
/**
|
|
38
|
+
* @callback Callback
|
|
39
|
+
* @param {(Stats | MultiStats)=} stats
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* @typedef {object} ResponseData
|
|
43
|
+
* @property {Buffer | ReadStream} data data
|
|
44
|
+
* @property {number} byteLength byte length
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
|
48
|
+
* @template {ServerResponse} [ResponseInternal=ServerResponse]
|
|
49
|
+
* @callback ModifyResponseData
|
|
50
|
+
* @param {RequestInternal} req req
|
|
51
|
+
* @param {ResponseInternal} res res
|
|
52
|
+
* @param {Buffer | ReadStream} data data
|
|
53
|
+
* @param {number} byteLength byte length
|
|
54
|
+
* @returns {ResponseData}
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
|
58
|
+
* @template {ServerResponse} [ResponseInternal=ServerResponse]
|
|
59
|
+
* @typedef {object} Context
|
|
60
|
+
* @property {boolean} state state
|
|
61
|
+
* @property {Stats | MultiStats | undefined} stats stats
|
|
62
|
+
* @property {Callback[]} callbacks callbacks
|
|
63
|
+
* @property {Options<RequestInternal, ResponseInternal>} options options
|
|
64
|
+
* @property {Compiler | MultiCompiler} compiler compiler
|
|
65
|
+
* @property {Watching | MultiWatching | undefined} watching watching
|
|
66
|
+
* @property {Logger} logger logger
|
|
67
|
+
* @property {OutputFileSystem} outputFileSystem output file system
|
|
68
|
+
*/
|
|
69
|
+
/**
|
|
70
|
+
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
|
71
|
+
* @template {ServerResponse} [ResponseInternal=ServerResponse]
|
|
72
|
+
* @typedef {WithoutUndefined<Context<RequestInternal, ResponseInternal>, "watching">} FilledContext
|
|
73
|
+
*/
|
|
74
|
+
/** @typedef {Record<string, string | number> | { key: string, value: number | string }[]} NormalizedHeaders */
|
|
75
|
+
/**
|
|
76
|
+
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
|
77
|
+
* @template {ServerResponse} [ResponseInternal=ServerResponse]
|
|
78
|
+
* @typedef {NormalizedHeaders | ((req: RequestInternal, res: ResponseInternal, context: Context<RequestInternal, ResponseInternal>) => void | undefined | NormalizedHeaders) | undefined} Headers
|
|
79
|
+
*/
|
|
80
|
+
/**
|
|
81
|
+
* @template {IncomingMessage} [RequestInternal = IncomingMessage]
|
|
82
|
+
* @template {ServerResponse} [ResponseInternal = ServerResponse]
|
|
83
|
+
* @typedef {object} Options
|
|
84
|
+
* @property {{ [key: string]: string }=} mimeTypes mime types
|
|
85
|
+
* @property {(string | undefined)=} mimeTypeDefault mime type default
|
|
86
|
+
* @property {(boolean | ((targetPath: string) => boolean))=} writeToDisk write to disk
|
|
87
|
+
* @property {string[]=} methods methods
|
|
88
|
+
* @property {Headers<RequestInternal, ResponseInternal>=} headers headers
|
|
89
|
+
* @property {NonNullable<Configuration["output"]>["publicPath"]=} publicPath public path
|
|
90
|
+
* @property {Configuration["stats"]=} stats stats
|
|
91
|
+
* @property {boolean=} serverSideRender is server side render
|
|
92
|
+
* @property {OutputFileSystem=} outputFileSystem output file system
|
|
93
|
+
* @property {(boolean | string)=} index index
|
|
94
|
+
* @property {ModifyResponseData<RequestInternal, ResponseInternal>=} modifyResponseData modify response data
|
|
95
|
+
* @property {"weak" | "strong"=} etag options to generate etag header
|
|
96
|
+
* @property {boolean=} lastModified options to generate last modified header
|
|
97
|
+
* @property {(boolean | number | string | { maxAge?: number, immutable?: boolean })=} cacheControl options to generate cache headers
|
|
98
|
+
* @property {boolean=} cacheImmutable is cache immutable
|
|
99
|
+
*/
|
|
100
|
+
/**
|
|
101
|
+
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
|
102
|
+
* @template {ServerResponse} [ResponseInternal=ServerResponse]
|
|
103
|
+
* @callback Middleware
|
|
104
|
+
* @param {RequestInternal} req
|
|
105
|
+
* @param {ResponseInternal} res
|
|
106
|
+
* @param {NextFunction} next
|
|
107
|
+
* @returns {Promise<void>}
|
|
108
|
+
*/
|
|
109
|
+
/** @typedef {import("./utils/getFilenameFromUrl").Extra} Extra */
|
|
110
|
+
/**
|
|
111
|
+
* @callback GetFilenameFromUrl
|
|
112
|
+
* @param {string} url
|
|
113
|
+
* @param {Extra=} extra
|
|
114
|
+
* @returns {string | undefined}
|
|
115
|
+
*/
|
|
116
|
+
/**
|
|
117
|
+
* @callback WaitUntilValid
|
|
118
|
+
* @param {Callback} callback
|
|
119
|
+
*/
|
|
120
|
+
/**
|
|
121
|
+
* @callback Invalidate
|
|
122
|
+
* @param {Callback} callback
|
|
123
|
+
*/
|
|
124
|
+
/**
|
|
125
|
+
* @callback Close
|
|
126
|
+
* @param {(err: Error | null | undefined) => void} callback
|
|
127
|
+
*/
|
|
128
|
+
/**
|
|
129
|
+
* @template {IncomingMessage} RequestInternal
|
|
130
|
+
* @template {ServerResponse} ResponseInternal
|
|
131
|
+
* @typedef {object} AdditionalMethods
|
|
132
|
+
* @property {GetFilenameFromUrl} getFilenameFromUrl get filename from url
|
|
133
|
+
* @property {WaitUntilValid} waitUntilValid wait until valid
|
|
134
|
+
* @property {Invalidate} invalidate invalidate
|
|
135
|
+
* @property {Close} close close
|
|
136
|
+
* @property {Context<RequestInternal, ResponseInternal>} context context
|
|
137
|
+
*/
|
|
138
|
+
/**
|
|
139
|
+
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
|
140
|
+
* @template {ServerResponse} [ResponseInternal=ServerResponse]
|
|
141
|
+
* @typedef {Middleware<RequestInternal, ResponseInternal> & AdditionalMethods<RequestInternal, ResponseInternal>} API
|
|
142
|
+
*/
|
|
143
|
+
/**
|
|
144
|
+
* @template T
|
|
145
|
+
* @template {keyof T} K
|
|
146
|
+
* @typedef {Omit<T, K> & Partial<T>} WithOptional
|
|
147
|
+
*/
|
|
148
|
+
/**
|
|
149
|
+
* @template T
|
|
150
|
+
* @template {keyof T} K
|
|
151
|
+
* @typedef {T & { [P in K]: NonNullable<T[P]> }} WithoutUndefined
|
|
152
|
+
*/
|
|
153
|
+
/**
|
|
154
|
+
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
|
155
|
+
* @template {ServerResponse} [ResponseInternal=ServerResponse]
|
|
156
|
+
* @param {Compiler | MultiCompiler} compiler compiler
|
|
157
|
+
* @param {Options<RequestInternal, ResponseInternal>=} options options
|
|
158
|
+
* @returns {API<RequestInternal, ResponseInternal>} rspack dev middleware
|
|
159
|
+
*/
|
|
160
|
+
export function devMiddleware<
|
|
161
|
+
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
|
162
|
+
ResponseInternal extends ServerResponse = ServerResponse,
|
|
163
|
+
>(
|
|
164
|
+
compiler: Compiler | MultiCompiler,
|
|
165
|
+
options?: Options<RequestInternal, ResponseInternal> | undefined,
|
|
166
|
+
): API<RequestInternal, ResponseInternal>;
|
|
167
|
+
export namespace devMiddleware {
|
|
168
|
+
export { hapiWrapper };
|
|
169
|
+
export { koaWrapper };
|
|
170
|
+
export { honoWrapper };
|
|
171
|
+
}
|
|
172
|
+
export type Compiler = import("@rspack/core").Compiler;
|
|
173
|
+
export type MultiCompiler = import("@rspack/core").MultiCompiler;
|
|
174
|
+
export type Configuration = import("@rspack/core").Configuration;
|
|
175
|
+
export type Stats = import("@rspack/core").Stats;
|
|
176
|
+
export type MultiStats = import("@rspack/core").MultiStats;
|
|
177
|
+
export type ReadStream = import("fs").ReadStream;
|
|
178
|
+
export type ExtendedServerResponse = {
|
|
179
|
+
/**
|
|
180
|
+
* locals
|
|
181
|
+
*/
|
|
182
|
+
locals?:
|
|
183
|
+
| {
|
|
184
|
+
rspack?: {
|
|
185
|
+
devMiddleware?: Context<IncomingMessage, ServerResponse>;
|
|
186
|
+
};
|
|
187
|
+
webpack?: {
|
|
188
|
+
devMiddleware?: Context<IncomingMessage, ServerResponse>;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
| undefined;
|
|
192
|
+
};
|
|
193
|
+
export type IncomingMessage = import("http").IncomingMessage;
|
|
194
|
+
export type ServerResponse = import("http").ServerResponse &
|
|
195
|
+
ExtendedServerResponse;
|
|
196
|
+
export type EXPECTED_ANY = any;
|
|
197
|
+
export type EXPECTED_FUNCTION = Function;
|
|
198
|
+
export type NextFunction = (err?: EXPECTED_ANY | undefined) => void;
|
|
199
|
+
export type WatchOptions = NonNullable<Configuration["watchOptions"]>;
|
|
200
|
+
export type DevServerOption = boolean | Configuration["devServer"] | undefined;
|
|
201
|
+
export type Watching = Compiler["watching"];
|
|
202
|
+
export type MultiWatching = ReturnType<MultiCompiler["watch"]>;
|
|
203
|
+
export type OutputFileSystem = import("@rspack/core").OutputFileSystem & {
|
|
204
|
+
createReadStream?: typeof import("fs").createReadStream;
|
|
205
|
+
statSync: import("fs").StatSyncFn;
|
|
206
|
+
readFileSync: typeof import("fs").readFileSync;
|
|
207
|
+
};
|
|
208
|
+
export type Logger = ReturnType<Compiler["getInfrastructureLogger"]>;
|
|
209
|
+
export type ClosableWatching = {
|
|
210
|
+
close(callback: (err?: Error | null | undefined) => void): void;
|
|
211
|
+
};
|
|
212
|
+
export type Callback = (stats?: (Stats | MultiStats) | undefined) => any;
|
|
213
|
+
export type ResponseData = {
|
|
214
|
+
/**
|
|
215
|
+
* data
|
|
216
|
+
*/
|
|
217
|
+
data: Buffer | ReadStream;
|
|
218
|
+
/**
|
|
219
|
+
* byte length
|
|
220
|
+
*/
|
|
221
|
+
byteLength: number;
|
|
222
|
+
};
|
|
223
|
+
export type ModifyResponseData<
|
|
224
|
+
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
|
225
|
+
ResponseInternal extends ServerResponse = ServerResponse,
|
|
226
|
+
> = (
|
|
227
|
+
req: RequestInternal,
|
|
228
|
+
res: ResponseInternal,
|
|
229
|
+
data: Buffer | ReadStream,
|
|
230
|
+
byteLength: number,
|
|
231
|
+
) => ResponseData;
|
|
232
|
+
export type Context<
|
|
233
|
+
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
|
234
|
+
ResponseInternal extends ServerResponse = ServerResponse,
|
|
235
|
+
> = {
|
|
236
|
+
/**
|
|
237
|
+
* state
|
|
238
|
+
*/
|
|
239
|
+
state: boolean;
|
|
240
|
+
/**
|
|
241
|
+
* stats
|
|
242
|
+
*/
|
|
243
|
+
stats: Stats | MultiStats | undefined;
|
|
244
|
+
/**
|
|
245
|
+
* callbacks
|
|
246
|
+
*/
|
|
247
|
+
callbacks: Callback[];
|
|
248
|
+
/**
|
|
249
|
+
* options
|
|
250
|
+
*/
|
|
251
|
+
options: Options<RequestInternal, ResponseInternal>;
|
|
252
|
+
/**
|
|
253
|
+
* compiler
|
|
254
|
+
*/
|
|
255
|
+
compiler: Compiler | MultiCompiler;
|
|
256
|
+
/**
|
|
257
|
+
* watching
|
|
258
|
+
*/
|
|
259
|
+
watching: Watching | MultiWatching | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* logger
|
|
262
|
+
*/
|
|
263
|
+
logger: Logger;
|
|
264
|
+
/**
|
|
265
|
+
* output file system
|
|
266
|
+
*/
|
|
267
|
+
outputFileSystem: OutputFileSystem;
|
|
268
|
+
};
|
|
269
|
+
export type FilledContext<
|
|
270
|
+
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
|
271
|
+
ResponseInternal extends ServerResponse = ServerResponse,
|
|
272
|
+
> = WithoutUndefined<Context<RequestInternal, ResponseInternal>, "watching">;
|
|
273
|
+
export type NormalizedHeaders =
|
|
274
|
+
| Record<string, string | number>
|
|
275
|
+
| {
|
|
276
|
+
key: string;
|
|
277
|
+
value: number | string;
|
|
278
|
+
}[];
|
|
279
|
+
export type Headers<
|
|
280
|
+
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
|
281
|
+
ResponseInternal extends ServerResponse = ServerResponse,
|
|
282
|
+
> =
|
|
283
|
+
| NormalizedHeaders
|
|
284
|
+
| ((
|
|
285
|
+
req: RequestInternal,
|
|
286
|
+
res: ResponseInternal,
|
|
287
|
+
context: Context<RequestInternal, ResponseInternal>,
|
|
288
|
+
) => void | undefined | NormalizedHeaders)
|
|
289
|
+
| undefined;
|
|
290
|
+
export type Options<
|
|
291
|
+
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
|
292
|
+
ResponseInternal extends ServerResponse = ServerResponse,
|
|
293
|
+
> = {
|
|
294
|
+
/**
|
|
295
|
+
* mime types
|
|
296
|
+
*/
|
|
297
|
+
mimeTypes?:
|
|
298
|
+
| {
|
|
299
|
+
[key: string]: string;
|
|
300
|
+
}
|
|
301
|
+
| undefined;
|
|
302
|
+
/**
|
|
303
|
+
* mime type default
|
|
304
|
+
*/
|
|
305
|
+
mimeTypeDefault?: (string | undefined) | undefined;
|
|
306
|
+
/**
|
|
307
|
+
* write to disk
|
|
308
|
+
*/
|
|
309
|
+
writeToDisk?: (boolean | ((targetPath: string) => boolean)) | undefined;
|
|
310
|
+
/**
|
|
311
|
+
* methods
|
|
312
|
+
*/
|
|
313
|
+
methods?: string[] | undefined;
|
|
314
|
+
/**
|
|
315
|
+
* headers
|
|
316
|
+
*/
|
|
317
|
+
headers?: Headers<RequestInternal, ResponseInternal> | undefined;
|
|
318
|
+
/**
|
|
319
|
+
* public path
|
|
320
|
+
*/
|
|
321
|
+
publicPath?: NonNullable<Configuration["output"]>["publicPath"] | undefined;
|
|
322
|
+
/**
|
|
323
|
+
* stats
|
|
324
|
+
*/
|
|
325
|
+
stats?: Configuration["stats"] | undefined;
|
|
326
|
+
/**
|
|
327
|
+
* is server side render
|
|
328
|
+
*/
|
|
329
|
+
serverSideRender?: boolean | undefined;
|
|
330
|
+
/**
|
|
331
|
+
* output file system
|
|
332
|
+
*/
|
|
333
|
+
outputFileSystem?: OutputFileSystem | undefined;
|
|
334
|
+
/**
|
|
335
|
+
* index
|
|
336
|
+
*/
|
|
337
|
+
index?: (boolean | string) | undefined;
|
|
338
|
+
/**
|
|
339
|
+
* modify response data
|
|
340
|
+
*/
|
|
341
|
+
modifyResponseData?:
|
|
342
|
+
| ModifyResponseData<RequestInternal, ResponseInternal>
|
|
343
|
+
| undefined;
|
|
344
|
+
/**
|
|
345
|
+
* options to generate etag header
|
|
346
|
+
*/
|
|
347
|
+
etag?: ("weak" | "strong") | undefined;
|
|
348
|
+
/**
|
|
349
|
+
* options to generate last modified header
|
|
350
|
+
*/
|
|
351
|
+
lastModified?: boolean | undefined;
|
|
352
|
+
/**
|
|
353
|
+
* options to generate cache headers
|
|
354
|
+
*/
|
|
355
|
+
cacheControl?:
|
|
356
|
+
| (
|
|
357
|
+
| boolean
|
|
358
|
+
| number
|
|
359
|
+
| string
|
|
360
|
+
| {
|
|
361
|
+
maxAge?: number;
|
|
362
|
+
immutable?: boolean;
|
|
363
|
+
}
|
|
364
|
+
)
|
|
365
|
+
| undefined;
|
|
366
|
+
/**
|
|
367
|
+
* is cache immutable
|
|
368
|
+
*/
|
|
369
|
+
cacheImmutable?: boolean | undefined;
|
|
370
|
+
};
|
|
371
|
+
export type Middleware<
|
|
372
|
+
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
|
373
|
+
ResponseInternal extends ServerResponse = ServerResponse,
|
|
374
|
+
> = (
|
|
375
|
+
req: RequestInternal,
|
|
376
|
+
res: ResponseInternal,
|
|
377
|
+
next: NextFunction,
|
|
378
|
+
) => Promise<void>;
|
|
379
|
+
export type Extra = import("./utils/getFilenameFromUrl").Extra;
|
|
380
|
+
export type GetFilenameFromUrl = (
|
|
381
|
+
url: string,
|
|
382
|
+
extra?: Extra | undefined,
|
|
383
|
+
) => string | undefined;
|
|
384
|
+
export type WaitUntilValid = (callback: Callback) => any;
|
|
385
|
+
export type Invalidate = (callback: Callback) => any;
|
|
386
|
+
export type Close = (callback: (err: Error | null | undefined) => void) => any;
|
|
387
|
+
export type AdditionalMethods<
|
|
388
|
+
RequestInternal extends IncomingMessage,
|
|
389
|
+
ResponseInternal extends ServerResponse,
|
|
390
|
+
> = {
|
|
391
|
+
/**
|
|
392
|
+
* get filename from url
|
|
393
|
+
*/
|
|
394
|
+
getFilenameFromUrl: GetFilenameFromUrl;
|
|
395
|
+
/**
|
|
396
|
+
* wait until valid
|
|
397
|
+
*/
|
|
398
|
+
waitUntilValid: WaitUntilValid;
|
|
399
|
+
/**
|
|
400
|
+
* invalidate
|
|
401
|
+
*/
|
|
402
|
+
invalidate: Invalidate;
|
|
403
|
+
/**
|
|
404
|
+
* close
|
|
405
|
+
*/
|
|
406
|
+
close: Close;
|
|
407
|
+
/**
|
|
408
|
+
* context
|
|
409
|
+
*/
|
|
410
|
+
context: Context<RequestInternal, ResponseInternal>;
|
|
411
|
+
};
|
|
412
|
+
export type API<
|
|
413
|
+
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
|
414
|
+
ResponseInternal extends ServerResponse = ServerResponse,
|
|
415
|
+
> = Middleware<RequestInternal, ResponseInternal> &
|
|
416
|
+
AdditionalMethods<RequestInternal, ResponseInternal>;
|
|
417
|
+
export type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
|
418
|
+
export type WithoutUndefined<T, K extends keyof T> = T & {
|
|
419
|
+
[P in K]: NonNullable<T[P]>;
|
|
420
|
+
};
|
|
421
|
+
export type HapiPluginBase<S, O> = {
|
|
422
|
+
/**
|
|
423
|
+
* register
|
|
424
|
+
*/
|
|
425
|
+
register: (server: S, options: O) => void | Promise<void>;
|
|
426
|
+
};
|
|
427
|
+
export type HapiPlugin<S, O> = HapiPluginBase<S, O> & {
|
|
428
|
+
pkg: {
|
|
429
|
+
name: string;
|
|
430
|
+
};
|
|
431
|
+
multiple: boolean;
|
|
432
|
+
};
|
|
433
|
+
export type HapiOptions = Options & {
|
|
434
|
+
compiler: Compiler | MultiCompiler;
|
|
435
|
+
};
|
|
436
|
+
/**
|
|
437
|
+
* @template S
|
|
438
|
+
* @template O
|
|
439
|
+
* @typedef {object} HapiPluginBase
|
|
440
|
+
* @property {(server: S, options: O) => void | Promise<void>} register register
|
|
441
|
+
*/
|
|
442
|
+
/**
|
|
443
|
+
* @template S
|
|
444
|
+
* @template O
|
|
445
|
+
* @typedef {HapiPluginBase<S, O> & { pkg: { name: string }, multiple: boolean }} HapiPlugin
|
|
446
|
+
*/
|
|
447
|
+
/**
|
|
448
|
+
* @typedef {Options & { compiler: Compiler | MultiCompiler }} HapiOptions
|
|
449
|
+
*/
|
|
450
|
+
/**
|
|
451
|
+
* @template HapiServer
|
|
452
|
+
* @template {HapiOptions} HapiOptionsInternal
|
|
453
|
+
* @returns {HapiPlugin<HapiServer, HapiOptionsInternal>} hapi wrapper
|
|
454
|
+
*/
|
|
455
|
+
declare function hapiWrapper<
|
|
456
|
+
HapiServer,
|
|
457
|
+
HapiOptionsInternal extends HapiOptions,
|
|
458
|
+
>(): HapiPlugin<HapiServer, HapiOptionsInternal>;
|
|
459
|
+
/**
|
|
460
|
+
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
|
461
|
+
* @template {ServerResponse} [ResponseInternal=ServerResponse]
|
|
462
|
+
* @param {Compiler | MultiCompiler} compiler compiler
|
|
463
|
+
* @param {Options<RequestInternal, ResponseInternal>=} options options
|
|
464
|
+
* @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise<void> | void} kow wrapper
|
|
465
|
+
*/
|
|
466
|
+
declare function koaWrapper<
|
|
467
|
+
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
|
468
|
+
ResponseInternal extends ServerResponse = ServerResponse,
|
|
469
|
+
>(
|
|
470
|
+
compiler: Compiler | MultiCompiler,
|
|
471
|
+
options?: Options<RequestInternal, ResponseInternal> | undefined,
|
|
472
|
+
): (ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise<void> | void;
|
|
473
|
+
/**
|
|
474
|
+
* @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
|
475
|
+
* @template {ServerResponse} [ResponseInternal=ServerResponse]
|
|
476
|
+
* @param {Compiler | MultiCompiler} compiler compiler
|
|
477
|
+
* @param {Options<RequestInternal, ResponseInternal>=} options options
|
|
478
|
+
* @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise<void> | void} hono wrapper
|
|
479
|
+
*/
|
|
480
|
+
declare function honoWrapper<
|
|
481
|
+
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
|
482
|
+
ResponseInternal extends ServerResponse = ServerResponse,
|
|
483
|
+
>(
|
|
484
|
+
compiler: Compiler | MultiCompiler,
|
|
485
|
+
options?: Options<RequestInternal, ResponseInternal> | undefined,
|
|
486
|
+
): (ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise<void> | void;
|
|
487
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export default wrapper;
|
|
2
|
+
/**
|
|
3
|
+
* send error options
|
|
4
|
+
*/
|
|
5
|
+
export type SendErrorOptions<
|
|
6
|
+
Request extends IncomingMessage,
|
|
7
|
+
Response extends ServerResponse,
|
|
8
|
+
> = {
|
|
9
|
+
/**
|
|
10
|
+
* headers
|
|
11
|
+
*/
|
|
12
|
+
headers?: Record<string, number | string | string[] | undefined> | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* modify response data callback
|
|
15
|
+
*/
|
|
16
|
+
modifyResponseData?:
|
|
17
|
+
| import("./index").ModifyResponseData<Request, Response>
|
|
18
|
+
| undefined;
|
|
19
|
+
};
|
|
20
|
+
export type NextFunction = import("./index.js").NextFunction;
|
|
21
|
+
export type IncomingMessage = import("./index.js").IncomingMessage;
|
|
22
|
+
export type ServerResponse = import("./index.js").ServerResponse;
|
|
23
|
+
export type NormalizedHeaders = import("./index.js").NormalizedHeaders;
|
|
24
|
+
export type ReadStream = import("fs").ReadStream;
|
|
25
|
+
/**
|
|
26
|
+
* @template {IncomingMessage} Request
|
|
27
|
+
* @template {ServerResponse} Response
|
|
28
|
+
* @typedef {object} SendErrorOptions send error options
|
|
29
|
+
* @property {Record<string, number | string | string[] | undefined>=} headers headers
|
|
30
|
+
* @property {import("./index").ModifyResponseData<Request, Response>=} modifyResponseData modify response data callback
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* @template {IncomingMessage} Request
|
|
34
|
+
* @template {ServerResponse} Response
|
|
35
|
+
* @param {import("./index.js").FilledContext<Request, Response>} context context
|
|
36
|
+
* @returns {import("./index.js").Middleware<Request, Response>} wrapper
|
|
37
|
+
*/
|
|
38
|
+
declare function wrapper<
|
|
39
|
+
Request extends IncomingMessage,
|
|
40
|
+
Response extends ServerResponse,
|
|
41
|
+
>(
|
|
42
|
+
context: import("./index.js").FilledContext<Request, Response>,
|
|
43
|
+
): import("./index.js").Middleware<Request, Response>;
|