@rspack/core 2.0.8 → 2.1.0-rc.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/compiled/@swc/types/index.d.ts +131 -2
- package/compiled/@swc/types/package.json +1 -1
- package/compiled/http-proxy-middleware/index.d.ts +80 -8
- package/compiled/http-proxy-middleware/package.json +1 -1
- package/compiled/watchpack/index.js +474 -235
- package/compiled/watchpack/package.json +1 -1
- package/compiled/watchpack/types/DirectoryWatcher.d.ts +2 -0
- package/compiled/watchpack/types/index.d.ts +121 -113
- package/compiled/watchpack/types/util/globToRegExp.d.ts +2 -0
- package/compiled/watchpack/types/watchpack.d.ts +1 -1
- package/compiled/webpack-sources/index.js +953 -351
- package/compiled/webpack-sources/package.json +1 -1
- package/compiled/webpack-sources/types.d.ts +40 -1
- package/dist/ModuleGraph.d.ts +1 -0
- package/dist/RuntimeGlobals.d.ts +7 -6
- package/dist/builtin-plugin/RsdoctorPlugin.d.ts +1 -0
- package/dist/config/adapterRuleUse.d.ts +1 -1
- package/dist/config/defaults.d.ts +1 -1
- package/dist/config/normalization.d.ts +11 -8
- package/dist/config/types.d.ts +27 -8
- package/dist/index.js +1974 -1891
- package/dist/loader-runner/index.d.ts +9 -10
- package/dist/moduleFederationDefaultRuntime.js +1 -1
- package/dist/node/NodeWatchFileSystem.d.ts +3 -1
- package/dist/rspack.d.ts +1 -1
- package/dist/trace/index.d.ts +1 -0
- package/dist/util/identifier.d.ts +0 -1
- package/dist/worker.js +23 -6
- package/package.json +11 -11
|
@@ -113,6 +113,13 @@ interface JsMinifyOptions {
|
|
|
113
113
|
safari10?: boolean;
|
|
114
114
|
toplevel?: boolean;
|
|
115
115
|
sourceMap?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Serializable subset of terser-webpack-plugin's `extractComments`.
|
|
118
|
+
* `true` behaves like `'some'`.
|
|
119
|
+
*/
|
|
120
|
+
extractComments?: boolean | "some" | "all" | {
|
|
121
|
+
regex: string;
|
|
122
|
+
};
|
|
116
123
|
outputPath?: string;
|
|
117
124
|
inlineSourcesContent?: boolean;
|
|
118
125
|
}
|
|
@@ -654,7 +661,7 @@ interface JscConfig {
|
|
|
654
661
|
};
|
|
655
662
|
}
|
|
656
663
|
type JscTarget = "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "es2023" | "es2024" | "esnext";
|
|
657
|
-
type ParserConfig = TsParserConfig | EsParserConfig;
|
|
664
|
+
type ParserConfig = TsParserConfig | EsParserConfig | FlowParserConfig;
|
|
658
665
|
interface TsParserConfig {
|
|
659
666
|
syntax: "typescript";
|
|
660
667
|
/**
|
|
@@ -670,6 +677,37 @@ interface TsParserConfig {
|
|
|
670
677
|
*/
|
|
671
678
|
dynamicImport?: boolean;
|
|
672
679
|
}
|
|
680
|
+
interface FlowParserConfig {
|
|
681
|
+
syntax: "flow";
|
|
682
|
+
/**
|
|
683
|
+
* Defaults to `false`.
|
|
684
|
+
*/
|
|
685
|
+
jsx?: boolean;
|
|
686
|
+
/**
|
|
687
|
+
* Defaults to `false`.
|
|
688
|
+
*/
|
|
689
|
+
all?: boolean;
|
|
690
|
+
/**
|
|
691
|
+
* Defaults to `false`.
|
|
692
|
+
*/
|
|
693
|
+
requireDirective?: boolean;
|
|
694
|
+
/**
|
|
695
|
+
* Defaults to `false`.
|
|
696
|
+
*/
|
|
697
|
+
enums?: boolean;
|
|
698
|
+
/**
|
|
699
|
+
* Defaults to `false`.
|
|
700
|
+
*/
|
|
701
|
+
decorators?: boolean;
|
|
702
|
+
/**
|
|
703
|
+
* Defaults to `false`.
|
|
704
|
+
*/
|
|
705
|
+
components?: boolean;
|
|
706
|
+
/**
|
|
707
|
+
* Defaults to `false`.
|
|
708
|
+
*/
|
|
709
|
+
patternMatching?: boolean;
|
|
710
|
+
}
|
|
673
711
|
interface EsParserConfig {
|
|
674
712
|
syntax: "ecmascript";
|
|
675
713
|
/**
|
|
@@ -765,6 +803,7 @@ interface TransformConfig {
|
|
|
765
803
|
* Effective only if `syntax` supports ƒ.
|
|
766
804
|
*/
|
|
767
805
|
react?: ReactConfig;
|
|
806
|
+
reactCompiler?: boolean | ReactCompilerOptions;
|
|
768
807
|
constModules?: ConstModulesConfig;
|
|
769
808
|
/**
|
|
770
809
|
* Defaults to null, which skips optimizer pass.
|
|
@@ -793,6 +832,92 @@ interface TransformConfig {
|
|
|
793
832
|
verbatimModuleSyntax?: boolean;
|
|
794
833
|
tsEnumIsMutable?: boolean;
|
|
795
834
|
}
|
|
835
|
+
interface ReactCompilerOptions {
|
|
836
|
+
/**
|
|
837
|
+
* Which functions to compile.
|
|
838
|
+
*
|
|
839
|
+
* Defaults to `"infer"`.
|
|
840
|
+
*/
|
|
841
|
+
compilationMode?: "infer" | "syntax" | "annotation" | "all";
|
|
842
|
+
/**
|
|
843
|
+
* What to do when a function cannot be compiled.
|
|
844
|
+
*
|
|
845
|
+
* Defaults to `"none"`.
|
|
846
|
+
*/
|
|
847
|
+
panicThreshold?: "none" | "critical_errors" | "all_errors";
|
|
848
|
+
/**
|
|
849
|
+
* React runtime version target.
|
|
850
|
+
*
|
|
851
|
+
* Defaults to `"19"`.
|
|
852
|
+
*/
|
|
853
|
+
target?: "17" | "18" | "19";
|
|
854
|
+
/**
|
|
855
|
+
* Analyze and report diagnostics only; emit no transformed code.
|
|
856
|
+
*
|
|
857
|
+
* Defaults to `false`.
|
|
858
|
+
*/
|
|
859
|
+
noEmit?: boolean;
|
|
860
|
+
/**
|
|
861
|
+
* Defaults to `"client"`.
|
|
862
|
+
*/
|
|
863
|
+
outputMode?: "client" | "ssr" | "lint";
|
|
864
|
+
/**
|
|
865
|
+
* Compile even functions marked with opt-out directives.
|
|
866
|
+
*
|
|
867
|
+
* Defaults to `false`.
|
|
868
|
+
*/
|
|
869
|
+
ignoreUseNoForget?: boolean;
|
|
870
|
+
/**
|
|
871
|
+
* Treat Flow suppression comments as opt-outs.
|
|
872
|
+
*
|
|
873
|
+
* Defaults to `true`.
|
|
874
|
+
*/
|
|
875
|
+
flowSuppressions?: boolean;
|
|
876
|
+
/**
|
|
877
|
+
* Enable react-native-reanimated support.
|
|
878
|
+
*
|
|
879
|
+
* Defaults to `false`.
|
|
880
|
+
*/
|
|
881
|
+
enableReanimated?: boolean;
|
|
882
|
+
/**
|
|
883
|
+
* Development mode.
|
|
884
|
+
*
|
|
885
|
+
* Defaults to `false`.
|
|
886
|
+
*/
|
|
887
|
+
isDev?: boolean;
|
|
888
|
+
/**
|
|
889
|
+
* ESLint rules whose suppressions opt a function out of compilation.
|
|
890
|
+
*/
|
|
891
|
+
eslintSuppressionRules?: string[];
|
|
892
|
+
/**
|
|
893
|
+
* Extra directives that opt a function out of compilation.
|
|
894
|
+
*/
|
|
895
|
+
customOptOutDirectives?: string[];
|
|
896
|
+
/**
|
|
897
|
+
* Emit a gated version of each compiled function.
|
|
898
|
+
*/
|
|
899
|
+
gating?: ReactCompilerGatingConfig;
|
|
900
|
+
/**
|
|
901
|
+
* Dynamically-gated compilation.
|
|
902
|
+
*/
|
|
903
|
+
dynamicGating?: ReactCompilerDynamicGatingConfig;
|
|
904
|
+
}
|
|
905
|
+
interface ReactCompilerGatingConfig {
|
|
906
|
+
/**
|
|
907
|
+
* Module the gating import comes from.
|
|
908
|
+
*/
|
|
909
|
+
source: string;
|
|
910
|
+
/**
|
|
911
|
+
* Imported specifier used as the gate.
|
|
912
|
+
*/
|
|
913
|
+
importSpecifierName: string;
|
|
914
|
+
}
|
|
915
|
+
interface ReactCompilerDynamicGatingConfig {
|
|
916
|
+
/**
|
|
917
|
+
* Module the gating import comes from.
|
|
918
|
+
*/
|
|
919
|
+
source: string;
|
|
920
|
+
}
|
|
796
921
|
interface ReactConfig {
|
|
797
922
|
/**
|
|
798
923
|
* Replace the function used when compiling JSX expressions.
|
|
@@ -1123,6 +1248,10 @@ interface Output {
|
|
|
1123
1248
|
* Sourcemap (**not** base64 encoded)
|
|
1124
1249
|
*/
|
|
1125
1250
|
map?: string;
|
|
1251
|
+
/**
|
|
1252
|
+
* Extracted comments collected during minification.
|
|
1253
|
+
*/
|
|
1254
|
+
extractedComments?: string[];
|
|
1126
1255
|
}
|
|
1127
1256
|
interface MatchPattern {
|
|
1128
1257
|
}
|
|
@@ -2137,4 +2266,4 @@ type WasmAnalysisOptions = {
|
|
|
2137
2266
|
};
|
|
2138
2267
|
type WasmPlugin = [wasmPackage: string, config: Record<string, any>];
|
|
2139
2268
|
|
|
2140
|
-
export type { Accessibility, AmdConfig, Argument, ArrayExpression, ArrayPattern, ArrowFunctionExpression, AssignmentExpression, AssignmentOperator, AssignmentPattern, AssignmentPatternProperty, AssignmentProperty, AwaitExpression, BaseModuleConfig, BigIntLiteral, BinaryExpression, BinaryOperator, BindingIdentifier, BlockStatement, BooleanLiteral, BreakStatement, CallExpression, CallerOptions, CatchClause, Class, ClassDeclaration, ClassExpression, ClassMember, ClassMethod, ClassMethodBase, ClassProperty, ClassPropertyBase, CommonJsConfig, ComputedPropName, ConditionalExpression, Config, ConstModulesConfig, Constructor, ContinueStatement, DebuggerStatement, Declaration, Decorator, DefaultDecl, DoWhileStatement, EmptyStatement, EnvConfig, Es6Config, EsParserConfig, ExportAllDeclaration, ExportDeclaration, ExportDefaultDeclaration, ExportDefaultExpression, ExportDefaultSpecifier, ExportNamedDeclaration, ExportNamespaceSpecifier, ExportSpecifier, ExprOrSpread, Expression, ExpressionStatement, Fn, ForInStatement, ForOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, GetterProperty, GlobalPassOption, HasDecorator, HasSpan, Identifier, IfStatement, Import, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier, Invalid, JSXAttrValue, JSXAttribute, JSXAttributeName, JSXAttributeOrSpread, JSXClosingElement, JSXClosingFragment, JSXElement, JSXElementChild, JSXElementName, JSXEmptyExpression, JSXExpression, JSXExpressionContainer, JSXFragment, JSXMemberExpression, JSXNamespacedName, JSXObject, JSXOpeningElement, JSXOpeningFragment, JSXSpreadChild, JSXText, JsFormatOptions, JsMinifyOptions, JscConfig, JscTarget, KeyValuePatternProperty, KeyValueProperty, LabeledStatement, Literal, MatchPattern, MemberExpression, MetaProperty, MethodKind, MethodProperty, Module, ModuleConfig, ModuleDeclaration, ModuleExportName, ModuleItem, NamedExportSpecifier, NamedImportSpecifier, NewExpression, Node, NodeNextConfig, NullLiteral, NumericLiteral, ObjectExpression, ObjectPattern, ObjectPatternProperty, OptimizerConfig, OptionalChainingCall, OptionalChainingExpression, Options, Output, Param, ParenthesisExpression, ParseOptions, ParserConfig, Pattern, Plugin, PrivateMethod, PrivateName, PrivateProperty, Program, Property, PropertyName, ReactConfig, RegExpLiteral, RestElement, ReturnStatement, Script, SequenceExpression, SetterProperty, Span, SpreadElement, Statement, StaticBlock, StringLiteral, Super, SuperPropExpression, Swcrc, SwitchCase, SwitchStatement, SystemjsConfig, TaggedTemplateExpression, TemplateElement, TemplateLiteral, TerserCompressOptions, TerserEcmaVersion, TerserMangleOptions, TerserManglePropertiesOptions, ThisExpression, ThrowStatement, TransformConfig, TruePlusMinus, TryStatement, TsArrayType, TsAsExpression, TsCallSignatureDeclaration, TsConditionalType, TsConstAssertion, TsConstructSignatureDeclaration, TsConstructorType, TsEntityName, TsEnumDeclaration, TsEnumMember, TsEnumMemberId, TsExportAssignment, TsExpressionWithTypeArguments, TsExternalModuleReference, TsFnOrConstructorType, TsFnParameter, TsFunctionType, TsGetterSignature, TsImportEqualsDeclaration, TsImportType, TsIndexSignature, TsIndexedAccessType, TsInferType, TsInstantiation, TsInterfaceBody, TsInterfaceDeclaration, TsIntersectionType, TsKeywordType, TsKeywordTypeKind, TsLiteral, TsLiteralType, TsMappedType, TsMethodSignature, TsModuleBlock, TsModuleDeclaration, TsModuleName, TsModuleReference, TsNamespaceBody, TsNamespaceDeclaration, TsNamespaceExportDeclaration, TsNonNullExpression, TsOptionalType, TsParameterProperty, TsParameterPropertyParameter, TsParenthesizedType, TsParserConfig, TsPropertySignature, TsQualifiedName, TsRestType, TsSatisfiesExpression, TsSetterSignature, TsTemplateLiteralType, TsThisType, TsThisTypeOrIdent, TsTupleElement, TsTupleType, TsType, TsTypeAliasDeclaration, TsTypeAnnotation, TsTypeAssertion, TsTypeElement, TsTypeLiteral, TsTypeOperator, TsTypeOperatorOp, TsTypeParameter, TsTypeParameterDeclaration, TsTypeParameterInstantiation, TsTypePredicate, TsTypeQuery, TsTypeQueryExpr, TsTypeReference, TsUnionOrIntersectionType, TsUnionType, UmdConfig, UnaryExpression, UnaryOperator, UpdateExpression, UpdateOperator, VariableDeclaration, VariableDeclarationKind, VariableDeclarator, WasmAnalysisOptions, WasmPlugin, WhileStatement, WithStatement, YieldExpression };
|
|
2269
|
+
export type { Accessibility, AmdConfig, Argument, ArrayExpression, ArrayPattern, ArrowFunctionExpression, AssignmentExpression, AssignmentOperator, AssignmentPattern, AssignmentPatternProperty, AssignmentProperty, AwaitExpression, BaseModuleConfig, BigIntLiteral, BinaryExpression, BinaryOperator, BindingIdentifier, BlockStatement, BooleanLiteral, BreakStatement, CallExpression, CallerOptions, CatchClause, Class, ClassDeclaration, ClassExpression, ClassMember, ClassMethod, ClassMethodBase, ClassProperty, ClassPropertyBase, CommonJsConfig, ComputedPropName, ConditionalExpression, Config, ConstModulesConfig, Constructor, ContinueStatement, DebuggerStatement, Declaration, Decorator, DefaultDecl, DoWhileStatement, EmptyStatement, EnvConfig, Es6Config, EsParserConfig, ExportAllDeclaration, ExportDeclaration, ExportDefaultDeclaration, ExportDefaultExpression, ExportDefaultSpecifier, ExportNamedDeclaration, ExportNamespaceSpecifier, ExportSpecifier, ExprOrSpread, Expression, ExpressionStatement, FlowParserConfig, Fn, ForInStatement, ForOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, GetterProperty, GlobalPassOption, HasDecorator, HasSpan, Identifier, IfStatement, Import, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier, Invalid, JSXAttrValue, JSXAttribute, JSXAttributeName, JSXAttributeOrSpread, JSXClosingElement, JSXClosingFragment, JSXElement, JSXElementChild, JSXElementName, JSXEmptyExpression, JSXExpression, JSXExpressionContainer, JSXFragment, JSXMemberExpression, JSXNamespacedName, JSXObject, JSXOpeningElement, JSXOpeningFragment, JSXSpreadChild, JSXText, JsFormatOptions, JsMinifyOptions, JscConfig, JscTarget, KeyValuePatternProperty, KeyValueProperty, LabeledStatement, Literal, MatchPattern, MemberExpression, MetaProperty, MethodKind, MethodProperty, Module, ModuleConfig, ModuleDeclaration, ModuleExportName, ModuleItem, NamedExportSpecifier, NamedImportSpecifier, NewExpression, Node, NodeNextConfig, NullLiteral, NumericLiteral, ObjectExpression, ObjectPattern, ObjectPatternProperty, OptimizerConfig, OptionalChainingCall, OptionalChainingExpression, Options, Output, Param, ParenthesisExpression, ParseOptions, ParserConfig, Pattern, Plugin, PrivateMethod, PrivateName, PrivateProperty, Program, Property, PropertyName, ReactCompilerDynamicGatingConfig, ReactCompilerGatingConfig, ReactCompilerOptions, ReactConfig, RegExpLiteral, RestElement, ReturnStatement, Script, SequenceExpression, SetterProperty, Span, SpreadElement, Statement, StaticBlock, StringLiteral, Super, SuperPropExpression, Swcrc, SwitchCase, SwitchStatement, SystemjsConfig, TaggedTemplateExpression, TemplateElement, TemplateLiteral, TerserCompressOptions, TerserEcmaVersion, TerserMangleOptions, TerserManglePropertiesOptions, ThisExpression, ThrowStatement, TransformConfig, TruePlusMinus, TryStatement, TsArrayType, TsAsExpression, TsCallSignatureDeclaration, TsConditionalType, TsConstAssertion, TsConstructSignatureDeclaration, TsConstructorType, TsEntityName, TsEnumDeclaration, TsEnumMember, TsEnumMemberId, TsExportAssignment, TsExpressionWithTypeArguments, TsExternalModuleReference, TsFnOrConstructorType, TsFnParameter, TsFunctionType, TsGetterSignature, TsImportEqualsDeclaration, TsImportType, TsIndexSignature, TsIndexedAccessType, TsInferType, TsInstantiation, TsInterfaceBody, TsInterfaceDeclaration, TsIntersectionType, TsKeywordType, TsKeywordTypeKind, TsLiteral, TsLiteralType, TsMappedType, TsMethodSignature, TsModuleBlock, TsModuleDeclaration, TsModuleName, TsModuleReference, TsNamespaceBody, TsNamespaceDeclaration, TsNamespaceExportDeclaration, TsNonNullExpression, TsOptionalType, TsParameterProperty, TsParameterPropertyParameter, TsParenthesizedType, TsParserConfig, TsPropertySignature, TsQualifiedName, TsRestType, TsSatisfiesExpression, TsSetterSignature, TsTemplateLiteralType, TsThisType, TsThisTypeOrIdent, TsTupleElement, TsTupleType, TsType, TsTypeAliasDeclaration, TsTypeAnnotation, TsTypeAssertion, TsTypeElement, TsTypeLiteral, TsTypeOperator, TsTypeOperatorOp, TsTypeParameter, TsTypeParameterDeclaration, TsTypeParameterInstantiation, TsTypePredicate, TsTypeQuery, TsTypeQueryExpr, TsTypeReference, TsUnionOrIntersectionType, TsUnionType, UmdConfig, UnaryExpression, UnaryOperator, UpdateExpression, UpdateOperator, VariableDeclaration, VariableDeclarationKind, VariableDeclarator, WasmAnalysisOptions, WasmPlugin, WhileStatement, WithStatement, YieldExpression };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@swc/types","author":"강동윤 <kdy1997.dev@gmail.com>","version":"0.1.
|
|
1
|
+
{"name":"@swc/types","author":"강동윤 <kdy1997.dev@gmail.com>","version":"0.1.27","license":"Apache-2.0","types":"index.d.ts","type":"commonjs"}
|
|
@@ -140,7 +140,10 @@ interface RequestHandler<TReq extends http.IncomingMessage = http.IncomingMessag
|
|
|
140
140
|
(req: TReq, res: TRes, next?: TNext): Promise<void>;
|
|
141
141
|
upgrade: (req: TReq, socket: net.Socket, head: Buffer) => void;
|
|
142
142
|
}
|
|
143
|
-
type Filter<TReq extends http.IncomingMessage = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean);
|
|
143
|
+
type Filter<TReq extends http.IncomingMessage = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean | string | RegExpMatchArray | null);
|
|
144
|
+
/**
|
|
145
|
+
* @see {@link https://github.com/chimurai/http-proxy-middleware/tree/master#defineplugin-helper `definePlugin()`} to define a http-proxy-middleware plugin.
|
|
146
|
+
*/
|
|
144
147
|
interface Plugin<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> {
|
|
145
148
|
(proxyServer: ProxyServer<TReq, TRes>, options: Options<TReq, TRes>): void;
|
|
146
149
|
}
|
|
@@ -156,9 +159,13 @@ interface OnProxyEvent<TReq extends http.IncomingMessage = http.IncomingMessage,
|
|
|
156
159
|
econnreset?: (err: Error, req: TReq, res: TRes, target: string | Partial<URL>) => void;
|
|
157
160
|
}
|
|
158
161
|
type Logger = Pick<Console, 'info' | 'warn' | 'error'>;
|
|
159
|
-
type PathRewriteConfig<TReq extends http.IncomingMessage = http.IncomingMessage> = {
|
|
162
|
+
type PathRewriteConfig<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> = {
|
|
160
163
|
[regexp: string]: string;
|
|
161
|
-
} | ((path: string, req: TReq
|
|
164
|
+
} | ((path: string, req: TReq,
|
|
165
|
+
/** `res` is undefined in WebSocket upgrade flows. */
|
|
166
|
+
res?: TRes | undefined, options?: Options<TReq, TRes>) => string | undefined) | ((path: string, req: TReq,
|
|
167
|
+
/** `res` is undefined in WebSocket upgrade flows. */
|
|
168
|
+
res?: TRes | undefined, options?: Options<TReq, TRes>) => Promise<string | undefined>);
|
|
162
169
|
interface Options<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> extends ProxyServerOptions {
|
|
163
170
|
/**
|
|
164
171
|
* Narrow down requests to proxy or not.
|
|
@@ -178,9 +185,13 @@ interface Options<TReq extends http.IncomingMessage = http.IncomingMessage, TRes
|
|
|
178
185
|
* }
|
|
179
186
|
* });
|
|
180
187
|
* ```
|
|
188
|
+
* @since v0.15.0
|
|
189
|
+
* @since v0.21.0 - support `async` function
|
|
190
|
+
* @since v4.1.0 - `res` and `options` parameters added to custom function
|
|
191
|
+
*
|
|
181
192
|
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathRewrite.md
|
|
182
193
|
*/
|
|
183
|
-
pathRewrite?: PathRewriteConfig<TReq>;
|
|
194
|
+
pathRewrite?: PathRewriteConfig<TReq, TRes>;
|
|
184
195
|
/**
|
|
185
196
|
* Access the internal `httpxy` server instance to customize behavior
|
|
186
197
|
*
|
|
@@ -225,17 +236,24 @@ interface Options<TReq extends http.IncomingMessage = http.IncomingMessage, TRes
|
|
|
225
236
|
on?: OnProxyEvent<TReq, TRes>;
|
|
226
237
|
/**
|
|
227
238
|
* Dynamically set the {@link Options.target `options.target`}.
|
|
239
|
+
*
|
|
228
240
|
* @example
|
|
229
241
|
* ```js
|
|
230
242
|
* createProxyMiddleware({
|
|
231
|
-
* router: async (req) => {
|
|
243
|
+
* router: async (req, res, options) => {
|
|
232
244
|
* return 'http://127:0.0.1:3000';
|
|
233
245
|
* }
|
|
234
246
|
* });
|
|
235
247
|
* ```
|
|
248
|
+
*
|
|
249
|
+
* @since v0.16.0
|
|
250
|
+
* @since v4.1.0 - `res` and `options` parameters added to router function signature
|
|
251
|
+
*
|
|
252
|
+
* NOTE: `res` is undefined in WebSocket upgrade flows.
|
|
253
|
+
*
|
|
236
254
|
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/router.md
|
|
237
255
|
*/
|
|
238
|
-
router?: Record<string, ProxyServerOptions['target']> | ((req: TReq) => ProxyServerOptions['target']) | ((req: TReq) => Promise<ProxyServerOptions['target']>);
|
|
256
|
+
router?: Record<string, ProxyServerOptions['target']> | ((req: TReq, res: TRes | undefined, options: Options<TReq, TRes>) => ProxyServerOptions['target']) | ((req: TReq, res: TRes | undefined, options: Options<TReq, TRes>) => Promise<ProxyServerOptions['target']>);
|
|
239
257
|
/**
|
|
240
258
|
* Log information from http-proxy-middleware
|
|
241
259
|
* @example
|
|
@@ -331,10 +349,26 @@ declare function createProxyMiddleware<TReq extends http.IncomingMessage = http.
|
|
|
331
349
|
type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buffer: Buffer, proxyRes: http.IncomingMessage, req: TReq, res: TRes) => Promise<Buffer | string>;
|
|
332
350
|
/**
|
|
333
351
|
* Intercept responses from upstream.
|
|
334
|
-
* Automatically decompress (deflate, gzip, brotli).
|
|
352
|
+
* Automatically decompress (deflate, gzip, brotli, zstd).
|
|
335
353
|
* Give developer the opportunity to modify intercepted Buffer and http.ServerResponse
|
|
336
354
|
*
|
|
337
355
|
* NOTE: must set options.selfHandleResponse=true (prevent automatic call of res.end())
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
*
|
|
359
|
+
* ```ts
|
|
360
|
+
* createProxyMiddleware({
|
|
361
|
+
* target: 'http://example.com',
|
|
362
|
+
* selfHandleResponse: true, // MUST set selfHandleResponse=true
|
|
363
|
+
* on: {
|
|
364
|
+
* proxyRes: responseInterceptor(async (buffer, proxyRes, req, res) => {
|
|
365
|
+
* // modify intercepted buffer and return modified buffer
|
|
366
|
+
* const modifiedBuffer = Buffer.from(buffer.toString().replace(/Example/g, 'Demo'), 'utf8');
|
|
367
|
+
* return modifiedBuffer;
|
|
368
|
+
* }),
|
|
369
|
+
* }
|
|
370
|
+
* });
|
|
371
|
+
* ```
|
|
338
372
|
*/
|
|
339
373
|
declare function responseInterceptor<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse>(interceptor: Interceptor<TReq, TRes>): (proxyRes: http.IncomingMessage, req: TReq, res: TRes) => Promise<void>;
|
|
340
374
|
|
|
@@ -343,9 +377,47 @@ type BodyParserLikeRequest = http.IncomingMessage & {
|
|
|
343
377
|
};
|
|
344
378
|
/**
|
|
345
379
|
* Fix proxied body if bodyParser is involved.
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```ts
|
|
383
|
+
* createProxyMiddleware({
|
|
384
|
+
* target: 'http://example.com',
|
|
385
|
+
* on: {
|
|
386
|
+
* proxyReq: fixRequestBody,
|
|
387
|
+
* }
|
|
388
|
+
* });
|
|
389
|
+
* ```
|
|
390
|
+
*
|
|
391
|
+
* Alternative solution without using `fixRequestBody()`: put `http-proxy-middleware` before `bodyParser` in the middleware stack.
|
|
392
|
+
*
|
|
393
|
+
* @see {@link https://github.com/chimurai/http-proxy-middleware/issues/40 Github issue #40 - POST request body is not proxied}
|
|
346
394
|
*/
|
|
347
395
|
declare function fixRequestBody<TReq extends BodyParserLikeRequest = BodyParserLikeRequest>(proxyReq: http.ClientRequest, req: TReq): void;
|
|
348
396
|
|
|
397
|
+
/**
|
|
398
|
+
* Helper function to define a http-proxy-middleware plugin
|
|
399
|
+
* @see proxyServer {@link ProxyServer} - proxy server instance to which the plugin is being applied
|
|
400
|
+
* @see options {@link Options} - options object passed to `createProxyMiddleware`
|
|
401
|
+
*
|
|
402
|
+
* @example defining a plugin
|
|
403
|
+
* ```js
|
|
404
|
+
* export const myPlugin = definePlugin((proxyServer, options) => {
|
|
405
|
+
* // plugin implementation
|
|
406
|
+
* });
|
|
407
|
+
* ```
|
|
408
|
+
*
|
|
409
|
+
* @example using a plugin
|
|
410
|
+
* ```js
|
|
411
|
+
* createProxyMiddleware({
|
|
412
|
+
* target: 'http://example.com',
|
|
413
|
+
* plugins: [myPlugin],
|
|
414
|
+
* });
|
|
415
|
+
* ```
|
|
416
|
+
*
|
|
417
|
+
* @since 4.1.0
|
|
418
|
+
*/
|
|
419
|
+
declare function definePlugin<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse>(fn: Plugin<TReq, TRes>): Plugin<TReq, TRes>;
|
|
420
|
+
|
|
349
421
|
/**
|
|
350
422
|
* Subscribe to {@link https://github.com/unjs/httpxy#events `httpxy` error events} to prevent server from crashing.
|
|
351
423
|
* Errors are logged with {@link https://www.npmjs.com/package/debug debug} library.
|
|
@@ -378,5 +450,5 @@ declare const loggerPlugin: Plugin;
|
|
|
378
450
|
*/
|
|
379
451
|
declare const proxyEventsPlugin: Plugin;
|
|
380
452
|
|
|
381
|
-
export { createProxyMiddleware, debugProxyErrorsPlugin, errorResponsePlugin, fixRequestBody, loggerPlugin, proxyEventsPlugin, responseInterceptor };
|
|
453
|
+
export { createProxyMiddleware, debugProxyErrorsPlugin, definePlugin, errorResponsePlugin, fixRequestBody, loggerPlugin, proxyEventsPlugin, responseInterceptor };
|
|
382
454
|
export type { Filter, Options, Plugin, RequestHandler };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"http-proxy-middleware","author":"Steven Chim","version":"4.
|
|
1
|
+
{"name":"http-proxy-middleware","author":"Steven Chim","version":"4.1.1","license":"MIT","types":"index.d.ts","type":"module"}
|