@utoo/pack-shared 1.3.0 → 1.3.2-alpha.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/cjs/config.d.ts CHANGED
@@ -69,6 +69,45 @@ export type TurbopackRuleConfigCollection = TurbopackRuleConfigItem | (Turbopack
69
69
  export interface ModuleOptions {
70
70
  rules?: Record<string, TurbopackRuleConfigCollection>;
71
71
  }
72
+ /**
73
+ * Path rewrite: object form applies first matching regex→replacement;
74
+ * function form receives path and returns new path (sync only).
75
+ */
76
+ export type PathRewrite = {
77
+ [regexp: string]: string;
78
+ } | ((path: string) => string);
79
+ /**
80
+ * Proxy rule for dev server HTTP/WS proxying.
81
+ * Mostly aligned with webpack-dev-server / http-proxy-middleware options.
82
+ */
83
+ export interface ProxyRule {
84
+ /**
85
+ * Path(s) to match for proxying.
86
+ * When starts with `^`, will be treated as RegExp source.
87
+ * Otherwise, simple prefix match is used.
88
+ */
89
+ context: string | string[];
90
+ /** Target server URL. */
91
+ target: string;
92
+ /**
93
+ * Path rewrite. Object: first matching regex is replaced (http-proxy-middleware style).
94
+ * Function: (path) => new path.
95
+ */
96
+ pathRewrite?: PathRewrite;
97
+ /**
98
+ * Whether to change the Host header to match the target.
99
+ * Defaults to true.
100
+ */
101
+ changeOrigin?: boolean;
102
+ /**
103
+ * Whether to verify the SSL certificate of the target.
104
+ * Set to false to accept self-signed certificates.
105
+ */
106
+ secure?: boolean;
107
+ }
108
+ export type DevServerProxy = ProxyRule[];
109
+ /** Object style proxy options without `context`. */
110
+ export type ProxyOptions = Omit<ProxyRule, "context">;
72
111
  export interface ResolveOptions {
73
112
  alias?: Record<string, string | string[] | Record<string, string | string[]>>;
74
113
  extensions?: string[];
@@ -108,6 +147,8 @@ export interface DevServerConfig {
108
147
  host?: string;
109
148
  /** Use HTTPS; when true without a certificate, a self-signed cert may be generated. */
110
149
  https?: boolean;
150
+ /** HTTP proxy rules for Hono dev server (HTTP only; no generic WS proxy in this layer). */
151
+ proxy?: DevServerProxy;
111
152
  }
112
153
  export interface ConfigComplete {
113
154
  entry: EntryOptions[];
package/cjs/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RustifiedEnv } from "./config";
1
+ import { DevServerProxy, ProxyOptions, RustifiedEnv } from "./config";
2
2
  import { Issue } from "./issue";
3
3
  export declare class ModuleBuildError extends Error {
4
4
  name: string;
@@ -9,6 +9,19 @@ export interface ResultWithIssues {
9
9
  export declare function processIssues(result: ResultWithIssues, throwIssue: boolean, logErrors: boolean): void;
10
10
  export declare function isWellKnownError(issue: Issue): boolean;
11
11
  export declare function rustifyEnv(env: Record<string, string>): RustifiedEnv;
12
+ /**
13
+ * Convert object-style proxy config into DevServerProxy array.
14
+ * Object keys become context; string value → target + default changeOrigin; object value merged into ProxyRule.
15
+ *
16
+ * @example
17
+ * proxy: [
18
+ * ...proxyFromObject({
19
+ * "/api": "http://localhost:3000",
20
+ * "/auth": { target: "http://localhost:5000", changeOrigin: true },
21
+ * }),
22
+ * ];
23
+ */
24
+ export declare function proxyFromObject(obj: Record<string, string | ProxyOptions>): DevServerProxy;
12
25
  type AnyFunc<T> = (this: T, ...args: any) => any;
13
26
  export declare function debounce<T, F extends AnyFunc<T>>(fn: F, ms: number, maxWait?: number): (this: T, ...passedArgs: Parameters<F>) => void;
14
27
  export {};
package/cjs/utils.js CHANGED
@@ -4,6 +4,7 @@ exports.ModuleBuildError = void 0;
4
4
  exports.processIssues = processIssues;
5
5
  exports.isWellKnownError = isWellKnownError;
6
6
  exports.rustifyEnv = rustifyEnv;
7
+ exports.proxyFromObject = proxyFromObject;
7
8
  exports.debounce = debounce;
8
9
  const issue_1 = require("./issue");
9
10
  const styledString_1 = require("./styledString");
@@ -55,6 +56,40 @@ function rustifyEnv(env) {
55
56
  value,
56
57
  }));
57
58
  }
59
+ /**
60
+ * Convert object-style proxy config into DevServerProxy array.
61
+ * Object keys become context; string value → target + default changeOrigin; object value merged into ProxyRule.
62
+ *
63
+ * @example
64
+ * proxy: [
65
+ * ...proxyFromObject({
66
+ * "/api": "http://localhost:3000",
67
+ * "/auth": { target: "http://localhost:5000", changeOrigin: true },
68
+ * }),
69
+ * ];
70
+ */
71
+ function proxyFromObject(obj) {
72
+ const rules = [];
73
+ for (const [context, value] of Object.entries(obj)) {
74
+ if (!value)
75
+ continue;
76
+ if (typeof value === "string") {
77
+ rules.push({
78
+ context,
79
+ target: value,
80
+ changeOrigin: true,
81
+ });
82
+ }
83
+ else {
84
+ rules.push({
85
+ context,
86
+ changeOrigin: true,
87
+ ...value,
88
+ });
89
+ }
90
+ }
91
+ return rules;
92
+ }
58
93
  function debounce(fn, ms, maxWait = Infinity) {
59
94
  let timeoutId;
60
95
  // The time the debouncing function was first called during this debounce queue.
package/esm/config.d.ts CHANGED
@@ -69,6 +69,45 @@ export type TurbopackRuleConfigCollection = TurbopackRuleConfigItem | (Turbopack
69
69
  export interface ModuleOptions {
70
70
  rules?: Record<string, TurbopackRuleConfigCollection>;
71
71
  }
72
+ /**
73
+ * Path rewrite: object form applies first matching regex→replacement;
74
+ * function form receives path and returns new path (sync only).
75
+ */
76
+ export type PathRewrite = {
77
+ [regexp: string]: string;
78
+ } | ((path: string) => string);
79
+ /**
80
+ * Proxy rule for dev server HTTP/WS proxying.
81
+ * Mostly aligned with webpack-dev-server / http-proxy-middleware options.
82
+ */
83
+ export interface ProxyRule {
84
+ /**
85
+ * Path(s) to match for proxying.
86
+ * When starts with `^`, will be treated as RegExp source.
87
+ * Otherwise, simple prefix match is used.
88
+ */
89
+ context: string | string[];
90
+ /** Target server URL. */
91
+ target: string;
92
+ /**
93
+ * Path rewrite. Object: first matching regex is replaced (http-proxy-middleware style).
94
+ * Function: (path) => new path.
95
+ */
96
+ pathRewrite?: PathRewrite;
97
+ /**
98
+ * Whether to change the Host header to match the target.
99
+ * Defaults to true.
100
+ */
101
+ changeOrigin?: boolean;
102
+ /**
103
+ * Whether to verify the SSL certificate of the target.
104
+ * Set to false to accept self-signed certificates.
105
+ */
106
+ secure?: boolean;
107
+ }
108
+ export type DevServerProxy = ProxyRule[];
109
+ /** Object style proxy options without `context`. */
110
+ export type ProxyOptions = Omit<ProxyRule, "context">;
72
111
  export interface ResolveOptions {
73
112
  alias?: Record<string, string | string[] | Record<string, string | string[]>>;
74
113
  extensions?: string[];
@@ -108,6 +147,8 @@ export interface DevServerConfig {
108
147
  host?: string;
109
148
  /** Use HTTPS; when true without a certificate, a self-signed cert may be generated. */
110
149
  https?: boolean;
150
+ /** HTTP proxy rules for Hono dev server (HTTP only; no generic WS proxy in this layer). */
151
+ proxy?: DevServerProxy;
111
152
  }
112
153
  export interface ConfigComplete {
113
154
  entry: EntryOptions[];
package/esm/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RustifiedEnv } from "./config";
1
+ import { DevServerProxy, ProxyOptions, RustifiedEnv } from "./config";
2
2
  import { Issue } from "./issue";
3
3
  export declare class ModuleBuildError extends Error {
4
4
  name: string;
@@ -9,6 +9,19 @@ export interface ResultWithIssues {
9
9
  export declare function processIssues(result: ResultWithIssues, throwIssue: boolean, logErrors: boolean): void;
10
10
  export declare function isWellKnownError(issue: Issue): boolean;
11
11
  export declare function rustifyEnv(env: Record<string, string>): RustifiedEnv;
12
+ /**
13
+ * Convert object-style proxy config into DevServerProxy array.
14
+ * Object keys become context; string value → target + default changeOrigin; object value merged into ProxyRule.
15
+ *
16
+ * @example
17
+ * proxy: [
18
+ * ...proxyFromObject({
19
+ * "/api": "http://localhost:3000",
20
+ * "/auth": { target: "http://localhost:5000", changeOrigin: true },
21
+ * }),
22
+ * ];
23
+ */
24
+ export declare function proxyFromObject(obj: Record<string, string | ProxyOptions>): DevServerProxy;
12
25
  type AnyFunc<T> = (this: T, ...args: any) => any;
13
26
  export declare function debounce<T, F extends AnyFunc<T>>(fn: F, ms: number, maxWait?: number): (this: T, ...passedArgs: Parameters<F>) => void;
14
27
  export {};
package/esm/utils.js CHANGED
@@ -47,6 +47,40 @@ export function rustifyEnv(env) {
47
47
  value,
48
48
  }));
49
49
  }
50
+ /**
51
+ * Convert object-style proxy config into DevServerProxy array.
52
+ * Object keys become context; string value → target + default changeOrigin; object value merged into ProxyRule.
53
+ *
54
+ * @example
55
+ * proxy: [
56
+ * ...proxyFromObject({
57
+ * "/api": "http://localhost:3000",
58
+ * "/auth": { target: "http://localhost:5000", changeOrigin: true },
59
+ * }),
60
+ * ];
61
+ */
62
+ export function proxyFromObject(obj) {
63
+ const rules = [];
64
+ for (const [context, value] of Object.entries(obj)) {
65
+ if (!value)
66
+ continue;
67
+ if (typeof value === "string") {
68
+ rules.push({
69
+ context,
70
+ target: value,
71
+ changeOrigin: true,
72
+ });
73
+ }
74
+ else {
75
+ rules.push({
76
+ context,
77
+ changeOrigin: true,
78
+ ...value,
79
+ });
80
+ }
81
+ }
82
+ return rules;
83
+ }
50
84
  export function debounce(fn, ms, maxWait = Infinity) {
51
85
  let timeoutId;
52
86
  // The time the debouncing function was first called during this debounce queue.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack-shared",
3
- "version": "1.3.0",
3
+ "version": "1.3.2-alpha.0",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "types": "esm/index.d.ts",