@ohos-ports/rsbuild-core 1.1.14-beta.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.
Files changed (244) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -0
  3. package/bin/rsbuild.js +20 -0
  4. package/compiled/chokidar/index.d.ts +345 -0
  5. package/compiled/chokidar/index.js +1778 -0
  6. package/compiled/chokidar/license +21 -0
  7. package/compiled/chokidar/package.json +1 -0
  8. package/compiled/connect/index.d.ts +90 -0
  9. package/compiled/connect/index.js +1240 -0
  10. package/compiled/connect/license +25 -0
  11. package/compiled/connect/package.json +1 -0
  12. package/compiled/connect-history-api-fallback/index.d.ts +1 -0
  13. package/compiled/connect-history-api-fallback/index.js +149 -0
  14. package/compiled/connect-history-api-fallback/license +21 -0
  15. package/compiled/connect-history-api-fallback/package.json +1 -0
  16. package/compiled/cors/index.d.ts +1 -0
  17. package/compiled/cors/index.js +371 -0
  18. package/compiled/cors/license +22 -0
  19. package/compiled/cors/package.json +1 -0
  20. package/compiled/css-loader/api.js +85 -0
  21. package/compiled/css-loader/getUrl.js +26 -0
  22. package/compiled/css-loader/index.d.ts +1 -0
  23. package/compiled/css-loader/index.js +8008 -0
  24. package/compiled/css-loader/license +20 -0
  25. package/compiled/css-loader/noSourceMaps.js +5 -0
  26. package/compiled/css-loader/package.json +1 -0
  27. package/compiled/css-loader/sourceMaps.js +16 -0
  28. package/compiled/html-rspack-plugin/default_index.ejs +9 -0
  29. package/compiled/html-rspack-plugin/index.d.ts +289 -0
  30. package/compiled/html-rspack-plugin/index.js +1583 -0
  31. package/compiled/html-rspack-plugin/license +20 -0
  32. package/compiled/html-rspack-plugin/loader.js +162 -0
  33. package/compiled/html-rspack-plugin/package.json +1 -0
  34. package/compiled/http-proxy-middleware/index.d.ts +318 -0
  35. package/compiled/http-proxy-middleware/index.js +5280 -0
  36. package/compiled/http-proxy-middleware/license +22 -0
  37. package/compiled/http-proxy-middleware/package.json +1 -0
  38. package/compiled/jiti/index.d.ts +1 -0
  39. package/compiled/jiti/index.js +416 -0
  40. package/compiled/jiti/license +21 -0
  41. package/compiled/jiti/package.json +1 -0
  42. package/compiled/launch-editor-middleware/index.d.ts +1 -0
  43. package/compiled/launch-editor-middleware/index.js +694 -0
  44. package/compiled/launch-editor-middleware/license +21 -0
  45. package/compiled/launch-editor-middleware/package.json +1 -0
  46. package/compiled/mrmime/index.d.ts +4 -0
  47. package/compiled/mrmime/index.js +452 -0
  48. package/compiled/mrmime/package.json +1 -0
  49. package/compiled/on-finished/index.d.ts +13 -0
  50. package/compiled/on-finished/index.js +197 -0
  51. package/compiled/on-finished/license +23 -0
  52. package/compiled/on-finished/package.json +1 -0
  53. package/compiled/open/index.d.ts +153 -0
  54. package/compiled/open/index.js +409 -0
  55. package/compiled/open/package.json +1 -0
  56. package/compiled/open/xdg-open +1066 -0
  57. package/compiled/picocolors/index.d.ts +55 -0
  58. package/compiled/picocolors/index.js +108 -0
  59. package/compiled/picocolors/license +15 -0
  60. package/compiled/picocolors/package.json +1 -0
  61. package/compiled/postcss/index.d.ts +1 -0
  62. package/compiled/postcss/index.js +5997 -0
  63. package/compiled/postcss/license +20 -0
  64. package/compiled/postcss/package.json +1 -0
  65. package/compiled/postcss-load-config/index.d.ts +1 -0
  66. package/compiled/postcss-load-config/index.js +739 -0
  67. package/compiled/postcss-load-config/license +20 -0
  68. package/compiled/postcss-load-config/package.json +1 -0
  69. package/compiled/postcss-loader/index.d.ts +1 -0
  70. package/compiled/postcss-loader/index.js +741 -0
  71. package/compiled/postcss-loader/license +20 -0
  72. package/compiled/postcss-loader/package.json +1 -0
  73. package/compiled/rsbuild-dev-middleware/index.d.ts +1 -0
  74. package/compiled/rsbuild-dev-middleware/index.js +6158 -0
  75. package/compiled/rsbuild-dev-middleware/license +20 -0
  76. package/compiled/rsbuild-dev-middleware/package.json +1 -0
  77. package/compiled/rslog/index.d.ts +66 -0
  78. package/compiled/rslog/index.js +334 -0
  79. package/compiled/rslog/license +21 -0
  80. package/compiled/rslog/package.json +1 -0
  81. package/compiled/rspack-chain/index.d.ts +611 -0
  82. package/compiled/rspack-chain/index.js +1740 -0
  83. package/compiled/rspack-chain/license +373 -0
  84. package/compiled/rspack-chain/package.json +1 -0
  85. package/compiled/rspack-manifest-plugin/index.d.ts +44 -0
  86. package/compiled/rspack-manifest-plugin/index.js +394 -0
  87. package/compiled/rspack-manifest-plugin/license +21 -0
  88. package/compiled/rspack-manifest-plugin/package.json +1 -0
  89. package/compiled/sirv/index.d.ts +1 -0
  90. package/compiled/sirv/index.js +709 -0
  91. package/compiled/sirv/package.json +1 -0
  92. package/compiled/style-loader/index.d.ts +1 -0
  93. package/compiled/style-loader/index.js +427 -0
  94. package/compiled/style-loader/license +20 -0
  95. package/compiled/style-loader/package.json +1 -0
  96. package/compiled/style-loader/runtime/injectStylesIntoLinkTag.js +29 -0
  97. package/compiled/style-loader/runtime/injectStylesIntoStyleTag.js +84 -0
  98. package/compiled/style-loader/runtime/insertBySelector.js +34 -0
  99. package/compiled/style-loader/runtime/insertStyleElement.js +10 -0
  100. package/compiled/style-loader/runtime/isEqualLocals.js +28 -0
  101. package/compiled/style-loader/runtime/isOldIE.js +17 -0
  102. package/compiled/style-loader/runtime/setAttributesWithAttributes.js +13 -0
  103. package/compiled/style-loader/runtime/setAttributesWithAttributesAndNonce.js +9 -0
  104. package/compiled/style-loader/runtime/setAttributesWithoutAttributes.js +10 -0
  105. package/compiled/style-loader/runtime/singletonStyleDomAPI.js +86 -0
  106. package/compiled/style-loader/runtime/styleDomAPI.js +61 -0
  107. package/compiled/style-loader/runtime/styleTagTransform.js +14 -0
  108. package/compiled/tinyglobby/index.d.ts +25 -0
  109. package/compiled/tinyglobby/index.js +2749 -0
  110. package/compiled/tinyglobby/index1.js +17 -0
  111. package/compiled/tinyglobby/license +21 -0
  112. package/compiled/tinyglobby/package.json +1 -0
  113. package/compiled/webpack-bundle-analyzer/index.d.ts +160 -0
  114. package/compiled/webpack-bundle-analyzer/index.js +13480 -0
  115. package/compiled/webpack-bundle-analyzer/license +20 -0
  116. package/compiled/webpack-bundle-analyzer/package.json +1 -0
  117. package/compiled/webpack-bundle-analyzer/public/viewer.js +16 -0
  118. package/compiled/webpack-bundle-analyzer/public/viewer.js.LICENSE.txt +10 -0
  119. package/compiled/webpack-merge/index.d.ts +31 -0
  120. package/compiled/webpack-merge/index.js +1200 -0
  121. package/compiled/webpack-merge/license +20 -0
  122. package/compiled/webpack-merge/package.json +1 -0
  123. package/compiled/ws/index.d.ts +401 -0
  124. package/compiled/ws/index.js +3153 -0
  125. package/compiled/ws/license +20 -0
  126. package/compiled/ws/package.json +1 -0
  127. package/dist/client/hmr.js +143 -0
  128. package/dist/client/overlay.js +210 -0
  129. package/dist/ignoreCssLoader.mjs +4 -0
  130. package/dist/index.cjs +7251 -0
  131. package/dist/index.js +7118 -0
  132. package/dist/transformLoader.mjs +22 -0
  133. package/dist/transformRawLoader.mjs +22 -0
  134. package/dist-types/cli/commands.d.ts +23 -0
  135. package/dist-types/cli/index.d.ts +1 -0
  136. package/dist-types/cli/init.d.ts +7 -0
  137. package/dist-types/cli/prepare.d.ts +1 -0
  138. package/dist-types/client/hmr.d.ts +1 -0
  139. package/dist-types/client/overlay.d.ts +1 -0
  140. package/dist-types/config.d.ts +90 -0
  141. package/dist-types/configChain.d.ts +139 -0
  142. package/dist-types/constants.d.ts +37 -0
  143. package/dist-types/createContext.d.ts +11 -0
  144. package/dist-types/createRsbuild.d.ts +2 -0
  145. package/dist-types/helpers/format.d.ts +5 -0
  146. package/dist-types/helpers/fs.d.ts +13 -0
  147. package/dist-types/helpers/index.d.ts +47 -0
  148. package/dist-types/helpers/path.d.ts +11 -0
  149. package/dist-types/helpers/stats.d.ts +9 -0
  150. package/dist-types/hooks.d.ts +48 -0
  151. package/dist-types/index.d.ts +26 -0
  152. package/dist-types/initPlugins.d.ts +6 -0
  153. package/dist-types/internal.d.ts +6 -0
  154. package/dist-types/loadEnv.d.ts +50 -0
  155. package/dist-types/loader/ignoreCssLoader.d.ts +2 -0
  156. package/dist-types/loader/transformLoader.d.ts +7 -0
  157. package/dist-types/loader/transformRawLoader.d.ts +3 -0
  158. package/dist-types/logger.d.ts +4 -0
  159. package/dist-types/mergeConfig.d.ts +2 -0
  160. package/dist-types/package.json +1 -0
  161. package/dist-types/pluginHelper.d.ts +12 -0
  162. package/dist-types/pluginManager.d.ts +9 -0
  163. package/dist-types/plugins/appIcon.d.ts +2 -0
  164. package/dist-types/plugins/asset.d.ts +3 -0
  165. package/dist-types/plugins/basic.d.ts +5 -0
  166. package/dist-types/plugins/bundleAnalyzer.d.ts +2 -0
  167. package/dist-types/plugins/cache.d.ts +2 -0
  168. package/dist-types/plugins/cleanOutput.d.ts +3 -0
  169. package/dist-types/plugins/css.d.ts +3 -0
  170. package/dist-types/plugins/define.d.ts +2 -0
  171. package/dist-types/plugins/entry.d.ts +2 -0
  172. package/dist-types/plugins/externals.d.ts +2 -0
  173. package/dist-types/plugins/fileSize.d.ts +4 -0
  174. package/dist-types/plugins/html.d.ts +9 -0
  175. package/dist-types/plugins/inlineChunk.d.ts +2 -0
  176. package/dist-types/plugins/lazyCompilation.d.ts +2 -0
  177. package/dist-types/plugins/manifest.d.ts +2 -0
  178. package/dist-types/plugins/minimize.d.ts +10 -0
  179. package/dist-types/plugins/moduleFederation.d.ts +2 -0
  180. package/dist-types/plugins/moment.d.ts +2 -0
  181. package/dist-types/plugins/nodeAddons.d.ts +2 -0
  182. package/dist-types/plugins/nonce.d.ts +2 -0
  183. package/dist-types/plugins/output.d.ts +2 -0
  184. package/dist-types/plugins/performance.d.ts +5 -0
  185. package/dist-types/plugins/progress.d.ts +2 -0
  186. package/dist-types/plugins/resolve.d.ts +2 -0
  187. package/dist-types/plugins/resourceHints.d.ts +2 -0
  188. package/dist-types/plugins/rsdoctor.d.ts +2 -0
  189. package/dist-types/plugins/rspackProfile.d.ts +2 -0
  190. package/dist-types/plugins/server.d.ts +2 -0
  191. package/dist-types/plugins/splitChunks.d.ts +4 -0
  192. package/dist-types/plugins/sri.d.ts +2 -0
  193. package/dist-types/plugins/swc.d.ts +7 -0
  194. package/dist-types/plugins/target.d.ts +2 -0
  195. package/dist-types/plugins/wasm.d.ts +2 -0
  196. package/dist-types/provider/build.d.ts +3 -0
  197. package/dist-types/provider/createCompiler.d.ts +27 -0
  198. package/dist-types/provider/helpers.d.ts +12 -0
  199. package/dist-types/provider/initConfigs.d.ts +10 -0
  200. package/dist-types/provider/inspectConfig.d.ts +6 -0
  201. package/dist-types/provider/provider.d.ts +2 -0
  202. package/dist-types/provider/rspackConfig.d.ts +8 -0
  203. package/dist-types/rspack/RsbuildHtmlPlugin.d.ts +37 -0
  204. package/dist-types/rspack/preload/HtmlPreloadOrPrefetchPlugin.d.ts +29 -0
  205. package/dist-types/rspack/preload/helpers/determineAsValue.d.ts +22 -0
  206. package/dist-types/rspack/preload/helpers/doesChunkBelongToHtml.d.ts +29 -0
  207. package/dist-types/rspack/preload/helpers/extractChunks.d.ts +28 -0
  208. package/dist-types/rspack/preload/helpers/index.d.ts +4 -0
  209. package/dist-types/rspack/preload/helpers/type.d.ts +13 -0
  210. package/dist-types/server/ansiHTML.d.ts +12 -0
  211. package/dist-types/server/cliShortcuts.d.ts +10 -0
  212. package/dist-types/server/compilerDevMiddleware.d.ts +31 -0
  213. package/dist-types/server/devMiddleware.d.ts +27 -0
  214. package/dist-types/server/devServer.d.ts +60 -0
  215. package/dist-types/server/environment.d.ts +8 -0
  216. package/dist-types/server/getDevMiddlewares.d.ts +25 -0
  217. package/dist-types/server/gzipMiddleware.d.ts +4 -0
  218. package/dist-types/server/helper.d.ts +71 -0
  219. package/dist-types/server/httpServer.d.ts +8 -0
  220. package/dist-types/server/middlewares.d.ts +34 -0
  221. package/dist-types/server/open.d.ts +10 -0
  222. package/dist-types/server/prodServer.d.ts +25 -0
  223. package/dist-types/server/proxy.d.ts +6 -0
  224. package/dist-types/server/restart.d.ts +14 -0
  225. package/dist-types/server/runner/asModule.d.ts +2 -0
  226. package/dist-types/server/runner/basic.d.ts +25 -0
  227. package/dist-types/server/runner/cjs.d.ts +10 -0
  228. package/dist-types/server/runner/esm.d.ts +6 -0
  229. package/dist-types/server/runner/index.d.ts +8 -0
  230. package/dist-types/server/runner/type.d.ts +36 -0
  231. package/dist-types/server/socketServer.d.ts +26 -0
  232. package/dist-types/server/watchFiles.d.ts +14 -0
  233. package/dist-types/types/config.d.ts +1309 -0
  234. package/dist-types/types/context.d.ts +52 -0
  235. package/dist-types/types/hooks.d.ts +146 -0
  236. package/dist-types/types/index.d.ts +8 -0
  237. package/dist-types/types/plugin.d.ts +329 -0
  238. package/dist-types/types/rsbuild.d.ts +156 -0
  239. package/dist-types/types/rspack.d.ts +16 -0
  240. package/dist-types/types/thirdParty.d.ts +176 -0
  241. package/dist-types/types/utils.d.ts +12 -0
  242. package/package.json +61 -0
  243. package/static/openChrome.applescript +95 -0
  244. package/types.d.ts +221 -0
@@ -0,0 +1,20 @@
1
+ Copyright JS Foundation and other contributors
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,162 @@
1
+ /* This loader renders the template with lodash.template if no other loader was found */
2
+ // @ts-nocheck
3
+
4
+ /**
5
+ * This is a minimal implementation of `lodash.template`
6
+ * Modified based on lodash v4.17.21
7
+ * License: https://github.com/lodash/lodash/blob/main/LICENSE
8
+ */
9
+ /** Used to match template delimiters. */
10
+ const reEscape = /<%-([\s\S]+?)%>/g;
11
+ /** Used to match template delimiters. */
12
+ const reEvaluate = /<%([\s\S]+?)%>/g;
13
+ /** Used to match template delimiters. */
14
+ const reInterpolate = /<%=([\s\S]+?)%>/g;
15
+ /** Used to match empty string literals in compiled template source. */
16
+ const reEmptyStringLeading = /\b__p \+= '';/g,
17
+ reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
18
+ reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
19
+
20
+ /** Used to match unescaped characters in compiled string literals. */
21
+ const reUnescapedString = /['\n\r\u2028\u2029\\]/g;
22
+
23
+ /** Used to escape characters for inclusion in compiled string literals. */
24
+ const stringEscapes = {
25
+ '\\': '\\',
26
+ "'": "'",
27
+ '\n': 'n',
28
+ '\r': 'r',
29
+ '\u2028': 'u2028',
30
+ '\u2029': 'u2029',
31
+ };
32
+
33
+ const escapeStringChar = (chr) => '\\' + stringEscapes[chr];
34
+
35
+ function template(string) {
36
+ let isEscaping;
37
+ let isEvaluating;
38
+ let index = 0;
39
+ let source = "__p += '";
40
+
41
+ // Compile the regexp to match each delimiter.
42
+ const reDelimiters = RegExp(
43
+ reEscape.source +
44
+ '|' +
45
+ reInterpolate.source +
46
+ '|' +
47
+ reEvaluate.source +
48
+ '|$',
49
+ 'g',
50
+ );
51
+
52
+ string.replace(
53
+ reDelimiters,
54
+ function (
55
+ match,
56
+ escapeValue,
57
+ interpolateValue,
58
+ evaluateValue,
59
+ offset,
60
+ ) {
61
+ // Escape characters that can't be included in string literals.
62
+ source += string
63
+ .slice(index, offset)
64
+ .replace(reUnescapedString, escapeStringChar);
65
+
66
+ // Replace delimiters with snippets.
67
+ if (escapeValue) {
68
+ isEscaping = true;
69
+ source += "' +\n__e(" + escapeValue + ") +\n'";
70
+ }
71
+ if (evaluateValue) {
72
+ isEvaluating = true;
73
+ source += "';\n" + evaluateValue + ";\n__p += '";
74
+ }
75
+ if (interpolateValue) {
76
+ source +=
77
+ "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
78
+ }
79
+ index = offset + match.length;
80
+
81
+ // The JS engine embedded in Adobe products needs `match` returned in
82
+ // order to produce the correct `offset` value.
83
+ return match;
84
+ },
85
+ );
86
+
87
+ source += "';\n";
88
+
89
+ // Cleanup code by stripping empty strings.
90
+ source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
91
+ .replace(reEmptyStringMiddle, '$1')
92
+ .replace(reEmptyStringTrailing, '$1;');
93
+
94
+ // Frame code as the function body.
95
+ source =
96
+ 'function(' +
97
+ 'data' +
98
+ ') {\n' +
99
+ "let __t, __p = ''" +
100
+ (isEscaping ? ', __e = lodashEscape' : '') +
101
+ (isEvaluating
102
+ ? ', __j = Array.prototype.join;\n' +
103
+ "function print() { __p += __j.call(arguments, '') }\n"
104
+ : ';\n') +
105
+ source +
106
+ 'return __p\n}';
107
+
108
+ return { compiled: source, isEscaping };
109
+ }
110
+
111
+ module.exports = function (source) {
112
+ const allLoadersButThisOne = this.loaders.filter(
113
+ (loader) => loader.normal !== module.exports,
114
+ );
115
+
116
+ // This loader shouldn't kick in if there is any other loader
117
+ if (allLoadersButThisOne.length > 0) {
118
+ return source;
119
+ }
120
+
121
+ // Allow only one html-webpack-plugin loader to allow loader options in the webpack config
122
+ const htmlWebpackPluginLoaders = this.loaders.filter(
123
+ (loader) => loader.normal === module.exports,
124
+ );
125
+ const lastHtmlRspackPluginLoader =
126
+ htmlWebpackPluginLoaders[htmlWebpackPluginLoaders.length - 1];
127
+ if (this.loaders[this.loaderIndex] !== lastHtmlRspackPluginLoader) {
128
+ return source;
129
+ }
130
+
131
+ if (/\.(c|m)?js$/.test(this.resourcePath)) {
132
+ return source;
133
+ }
134
+
135
+ const escapeCode = `const htmlEscapes = {
136
+ "&": "&amp;",
137
+ "<": "&lt;",
138
+ ">": "&gt;",
139
+ '"': "&quot;",
140
+ "'": "&#39;",
141
+ };
142
+ const escapeHtmlChar = (key) => htmlEscapes[key];
143
+ const reUnescapedHtml = /[&<>"']/g, reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
144
+
145
+ function lodashEscape(string) {
146
+ string = string.toString();
147
+ return string && reHasUnescapedHtml.test(string)
148
+ ? string.replace(reUnescapedHtml, escapeHtmlChar)
149
+ : string;
150
+ };`;
151
+
152
+ // The following part renders the template with lodash as a minimalistic loader
153
+ const { compiled, isEscaping } = template(source);
154
+ // Use `eval("require")("lodash")` to enforce using the native nodejs require
155
+ // during template execution
156
+ return `
157
+ module.exports = function (templateParams) { with(templateParams) {
158
+ ${isEscaping ? escapeCode : ''}
159
+ // Execute the lodash template
160
+ return (${compiled})();
161
+ }}`;
162
+ };
@@ -0,0 +1 @@
1
+ {"name":"html-rspack-plugin","author":"Jan Nicklas <j.nicklas@me.com> (https://github.com/jantimon)","version":"6.0.2","funding":{"type":"opencollective","url":"https://opencollective.com/html-webpack-plugin"},"license":"MIT","types":"index.d.ts","type":"commonjs"}
@@ -0,0 +1,318 @@
1
+ /// <reference types="node" />
2
+ import * as express from 'express';
3
+ import * as http from 'http';
4
+ import * as events from 'events';
5
+ import * as net from 'net';
6
+ import * as stream from 'stream';
7
+ import * as url from 'url';
8
+
9
+ interface ProxyTargetDetailed {
10
+ host: string;
11
+ port: number;
12
+ protocol?: string | undefined;
13
+ hostname?: string | undefined;
14
+ socketPath?: string | undefined;
15
+ key?: string | undefined;
16
+ passphrase?: string | undefined;
17
+ pfx?: Buffer | string | undefined;
18
+ cert?: string | undefined;
19
+ ca?: string | undefined;
20
+ ciphers?: string | undefined;
21
+ secureProtocol?: string | undefined;
22
+ }
23
+
24
+ declare class Server<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse>
25
+ extends events.EventEmitter
26
+ {
27
+ /**
28
+ * Creates the proxy server with specified options.
29
+ * @param options - Config object passed to the proxy
30
+ */
31
+ constructor(options?: Server.ServerOptions);
32
+
33
+ /**
34
+ * Used for proxying regular HTTP(S) requests
35
+ * @param req - Client request.
36
+ * @param res - Client response.
37
+ * @param options - Additional options.
38
+ */
39
+ web(
40
+ req: http.IncomingMessage,
41
+ res: http.ServerResponse,
42
+ options?: Server.ServerOptions,
43
+ callback?: Server.ErrorCallback,
44
+ ): void;
45
+
46
+ /**
47
+ * Used for proxying regular HTTP(S) requests
48
+ * @param req - Client request.
49
+ * @param socket - Client socket.
50
+ * @param head - Client head.
51
+ * @param options - Additionnal options.
52
+ */
53
+ ws(
54
+ req: http.IncomingMessage,
55
+ socket: any,
56
+ head: any,
57
+ options?: Server.ServerOptions,
58
+ callback?: Server.ErrorCallback,
59
+ ): void;
60
+
61
+ /**
62
+ * A function that wraps the object in a webserver, for your convenience
63
+ * @param port - Port to listen on
64
+ * @param hostname - The hostname to listen on
65
+ */
66
+ listen(port: number, hostname?: string): Server<TIncomingMessage, TServerResponse>;
67
+
68
+ /**
69
+ * A function that closes the inner webserver and stops listening on given port
70
+ */
71
+ close(callback?: () => void): void;
72
+
73
+ /**
74
+ * Creates the proxy server with specified options.
75
+ * @param options Config object passed to the proxy
76
+ * @returns Proxy object with handlers for `ws` and `web` requests
77
+ */
78
+ // tslint:disable:no-unnecessary-generics
79
+ static createProxyServer<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse>(
80
+ options?: Server.ServerOptions,
81
+ ): Server<TIncomingMessage, TServerResponse>;
82
+
83
+ /**
84
+ * Creates the proxy server with specified options.
85
+ * @param options Config object passed to the proxy
86
+ * @returns Proxy object with handlers for `ws` and `web` requests
87
+ */
88
+ // tslint:disable:no-unnecessary-generics
89
+ static createServer<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse>(
90
+ options?: Server.ServerOptions,
91
+ ): Server<TIncomingMessage, TServerResponse>;
92
+
93
+ /**
94
+ * Creates the proxy server with specified options.
95
+ * @param options Config object passed to the proxy
96
+ * @returns Proxy object with handlers for `ws` and `web` requests
97
+ */
98
+ // tslint:disable:no-unnecessary-generics
99
+ static createProxy<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse>(
100
+ options?: Server.ServerOptions,
101
+ ): Server<TIncomingMessage, TServerResponse>;
102
+
103
+ addListener(event: string, listener: () => void): this;
104
+ on(event: string, listener: () => void): this;
105
+ on(event: "error", listener: Server.ErrorCallback<Error, TIncomingMessage, TServerResponse>): this;
106
+ on(event: "start", listener: Server.StartCallback<TIncomingMessage, TServerResponse>): this;
107
+ on(
108
+ event: "proxyReq",
109
+ listener: Server.ProxyReqCallback<http.ClientRequest, TIncomingMessage, TServerResponse>,
110
+ ): this;
111
+ on(event: "proxyRes", listener: Server.ProxyResCallback<TIncomingMessage, TServerResponse>): this;
112
+ on(event: "proxyReqWs", listener: Server.ProxyReqWsCallback<http.ClientRequest, TIncomingMessage>): this;
113
+ on(event: "econnreset", listener: Server.EconnresetCallback<Error, TIncomingMessage, TServerResponse>): this;
114
+ on(event: "end", listener: Server.EndCallback<TIncomingMessage, TServerResponse>): this;
115
+ on(event: "open", listener: Server.OpenCallback): this;
116
+ on(event: "close", listener: Server.CloseCallback<TIncomingMessage>): this;
117
+
118
+ once(event: string, listener: () => void): this;
119
+ once(event: "error", listener: Server.ErrorCallback<Error, TIncomingMessage, TServerResponse>): this;
120
+ once(event: "start", listener: Server.StartCallback<TIncomingMessage, TServerResponse>): this;
121
+ once(
122
+ event: "proxyReq",
123
+ listener: Server.ProxyReqCallback<http.ClientRequest, TIncomingMessage, TServerResponse>,
124
+ ): this;
125
+ once(event: "proxyRes", listener: Server.ProxyResCallback<TIncomingMessage, TServerResponse>): this;
126
+ once(event: "proxyReqWs", listener: Server.ProxyReqWsCallback<http.ClientRequest, TIncomingMessage>): this;
127
+ once(event: "econnreset", listener: Server.EconnresetCallback<Error, TIncomingMessage, TServerResponse>): this;
128
+ once(event: "end", listener: Server.EndCallback<TIncomingMessage, TServerResponse>): this;
129
+ once(event: "open", listener: Server.OpenCallback): this;
130
+ once(event: "close", listener: Server.CloseCallback<TIncomingMessage>): this;
131
+ removeListener(event: string, listener: () => void): this;
132
+ removeAllListeners(event?: string): this;
133
+ getMaxListeners(): number;
134
+ setMaxListeners(n: number): this;
135
+ listeners(event: string): Array<() => void>;
136
+ emit(event: string, ...args: any[]): boolean;
137
+ listenerCount(type: string): number;
138
+ }
139
+
140
+ declare namespace Server {
141
+ type ProxyTarget = ProxyTargetUrl | ProxyTargetDetailed;
142
+ type ProxyTargetUrl = string | Partial<url.Url>;
143
+
144
+ interface ServerOptions {
145
+ /** URL string to be parsed with the url module. */
146
+ target?: ProxyTarget | undefined;
147
+ /** URL string to be parsed with the url module. */
148
+ forward?: ProxyTargetUrl | undefined;
149
+ /** Object to be passed to http(s).request. */
150
+ agent?: any;
151
+ /** Object to be passed to https.createServer(). */
152
+ ssl?: any;
153
+ /** If you want to proxy websockets. */
154
+ ws?: boolean | undefined;
155
+ /** Adds x- forward headers. */
156
+ xfwd?: boolean | undefined;
157
+ /** Verify SSL certificate. */
158
+ secure?: boolean | undefined;
159
+ /** Explicitly specify if we are proxying to another proxy. */
160
+ toProxy?: boolean | undefined;
161
+ /** Specify whether you want to prepend the target's path to the proxy path. */
162
+ prependPath?: boolean | undefined;
163
+ /** Specify whether you want to ignore the proxy path of the incoming request. */
164
+ ignorePath?: boolean | undefined;
165
+ /** Local interface string to bind for outgoing connections. */
166
+ localAddress?: string | undefined;
167
+ /** Changes the origin of the host header to the target URL. */
168
+ changeOrigin?: boolean | undefined;
169
+ /** specify whether you want to keep letter case of response header key */
170
+ preserveHeaderKeyCase?: boolean | undefined;
171
+ /** Basic authentication i.e. 'user:password' to compute an Authorization header. */
172
+ auth?: string | undefined;
173
+ /** Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null. */
174
+ hostRewrite?: string | undefined;
175
+ /** Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false. */
176
+ autoRewrite?: boolean | undefined;
177
+ /** Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null. */
178
+ protocolRewrite?: string | undefined;
179
+ /** rewrites domain of set-cookie headers. */
180
+ cookieDomainRewrite?: false | string | { [oldDomain: string]: string } | undefined;
181
+ /** rewrites path of set-cookie headers. Default: false */
182
+ cookiePathRewrite?: false | string | { [oldPath: string]: string } | undefined;
183
+ /** object with extra headers to be added to target requests. */
184
+ headers?: { [header: string]: string } | undefined;
185
+ /** Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes) */
186
+ proxyTimeout?: number | undefined;
187
+ /** Timeout (in milliseconds) for incoming requests */
188
+ timeout?: number | undefined;
189
+ /** Specify whether you want to follow redirects. Default: false */
190
+ followRedirects?: boolean | undefined;
191
+ /** If set to true, none of the webOutgoing passes are called and it's your responsibility to appropriately return the response by listening and acting on the proxyRes event */
192
+ selfHandleResponse?: boolean | undefined;
193
+ /** Buffer */
194
+ buffer?: stream.Stream | undefined;
195
+ /** Explicitly set the method type of the ProxyReq */
196
+ method?: string | undefined;
197
+ }
198
+
199
+ type StartCallback<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse> = (
200
+ req: TIncomingMessage,
201
+ res: TServerResponse,
202
+ target: ProxyTargetUrl,
203
+ ) => void;
204
+ type ProxyReqCallback<
205
+ TClientRequest = http.ClientRequest,
206
+ TIncomingMessage = http.IncomingMessage,
207
+ TServerResponse = http.ServerResponse,
208
+ > = (proxyReq: TClientRequest, req: TIncomingMessage, res: TServerResponse, options: ServerOptions) => void;
209
+ type ProxyResCallback<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse> = (
210
+ proxyRes: TIncomingMessage,
211
+ req: TIncomingMessage,
212
+ res: TServerResponse,
213
+ ) => void;
214
+ type ProxyReqWsCallback<TClientRequest = http.ClientRequest, TIncomingMessage = http.IncomingMessage> = (
215
+ proxyReq: TClientRequest,
216
+ req: TIncomingMessage,
217
+ socket: net.Socket,
218
+ options: ServerOptions,
219
+ head: any,
220
+ ) => void;
221
+ type EconnresetCallback<
222
+ TError = Error,
223
+ TIncomingMessage = http.IncomingMessage,
224
+ TServerResponse = http.ServerResponse,
225
+ > = (
226
+ err: TError,
227
+ req: TIncomingMessage,
228
+ res: TServerResponse,
229
+ target: ProxyTargetUrl,
230
+ ) => void;
231
+ type EndCallback<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse> = (
232
+ req: TIncomingMessage,
233
+ res: TServerResponse,
234
+ proxyRes: TIncomingMessage,
235
+ ) => void;
236
+ type OpenCallback = (proxySocket: net.Socket) => void;
237
+ type CloseCallback<TIncomingMessage = http.IncomingMessage> = (
238
+ proxyRes: TIncomingMessage,
239
+ proxySocket: net.Socket,
240
+ proxyHead: any,
241
+ ) => void;
242
+ type ErrorCallback<TError = Error, TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse> =
243
+ (
244
+ err: TError,
245
+ req: TIncomingMessage,
246
+ res: TServerResponse | net.Socket,
247
+ target?: ProxyTargetUrl,
248
+ ) => void;
249
+ }
250
+
251
+ /**
252
+ * Based on definition by DefinitelyTyped:
253
+ * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts
254
+ */
255
+
256
+ interface Request extends http.IncomingMessage {
257
+ }
258
+ interface Response extends http.ServerResponse {
259
+ }
260
+ interface RequestHandler {
261
+ (req: Request, res: Response, next?: (err?: any) => void): void | Promise<void>;
262
+ upgrade?: (req: Request, socket: net.Socket, head: any) => void;
263
+ }
264
+ declare type Filter = string | string[] | ((pathname: string, req: Request) => boolean);
265
+ interface Options extends Server.ServerOptions {
266
+ pathRewrite?: {
267
+ [regexp: string]: string;
268
+ } | ((path: string, req: Request) => string) | ((path: string, req: Request) => Promise<string>);
269
+ router?: {
270
+ [hostOrPath: string]: Server.ServerOptions['target'];
271
+ } | ((req: Request) => Server.ServerOptions['target']) | ((req: Request) => Promise<Server.ServerOptions['target']>);
272
+ logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
273
+ logProvider?: LogProviderCallback;
274
+ onError?: OnErrorCallback;
275
+ onProxyRes?: OnProxyResCallback;
276
+ onProxyReq?: OnProxyReqCallback;
277
+ onProxyReqWs?: OnProxyReqWsCallback;
278
+ onOpen?: OnOpenCallback;
279
+ onClose?: OnCloseCallback;
280
+ }
281
+ interface LogProvider {
282
+ log: Logger;
283
+ debug?: Logger;
284
+ info?: Logger;
285
+ warn?: Logger;
286
+ error?: Logger;
287
+ }
288
+ declare type Logger = (...args: any[]) => void;
289
+ declare type LogProviderCallback = (provider: LogProvider) => LogProvider;
290
+ /**
291
+ * Use types based on the events listeners from http-proxy
292
+ * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/51504fd999031b7f025220fab279f1b2155cbaff/types/http-proxy/index.d.ts
293
+ */
294
+ declare type OnErrorCallback = (err: Error, req: Request, res: Response, target?: string | Partial<url.Url>) => void;
295
+ declare type OnProxyResCallback = (proxyRes: http.IncomingMessage, req: Request, res: Response) => void;
296
+ declare type OnProxyReqCallback = (proxyReq: http.ClientRequest, req: Request, res: Response, options: Server.ServerOptions) => void;
297
+ declare type OnProxyReqWsCallback = (proxyReq: http.ClientRequest, req: Request, socket: net.Socket, options: Server.ServerOptions, head: any) => void;
298
+ declare type OnCloseCallback = (proxyRes: Response, proxySocket: net.Socket, proxyHead: any) => void;
299
+ declare type OnOpenCallback = (proxySocket: net.Socket) => void;
300
+
301
+ declare type Interceptor = (buffer: Buffer, proxyRes: http.IncomingMessage, req: http.IncomingMessage, res: http.ServerResponse) => Promise<Buffer | string>;
302
+ /**
303
+ * Intercept responses from upstream.
304
+ * Automatically decompress (deflate, gzip, brotli).
305
+ * Give developer the opportunity to modify intercepted Buffer and http.ServerResponse
306
+ *
307
+ * NOTE: must set options.selfHandleResponse=true (prevent automatic call of res.end())
308
+ */
309
+ declare function responseInterceptor(interceptor: Interceptor): (proxyRes: http.IncomingMessage, req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
310
+
311
+ /**
312
+ * Fix proxied body if bodyParser is involved.
313
+ */
314
+ declare function fixRequestBody(proxyReq: http.ClientRequest, req: http.IncomingMessage): void;
315
+
316
+ declare function createProxyMiddleware(context: Filter | Options, options?: Options): RequestHandler;
317
+
318
+ export { type Filter, type Options, type RequestHandler, createProxyMiddleware, fixRequestBody, responseInterceptor };