@utoo/pack-shared 1.3.3 → 1.3.4
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 +41 -0
- package/cjs/utils.d.ts +14 -1
- package/cjs/utils.js +35 -0
- package/esm/config.d.ts +41 -0
- package/esm/utils.d.ts +14 -1
- package/esm/utils.js +34 -0
- package/package.json +2 -1
package/cjs/config.d.ts
CHANGED
|
@@ -57,6 +57,45 @@ export type TurbopackRuleConfigCollection = TurbopackRuleConfigItem | (Turbopack
|
|
|
57
57
|
export interface ModuleOptions {
|
|
58
58
|
rules?: Record<string, TurbopackRuleConfigCollection>;
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Path rewrite: object form applies first matching regex→replacement;
|
|
62
|
+
* function form receives path and returns new path (sync only).
|
|
63
|
+
*/
|
|
64
|
+
export type PathRewrite = {
|
|
65
|
+
[regexp: string]: string;
|
|
66
|
+
} | ((path: string) => string);
|
|
67
|
+
/**
|
|
68
|
+
* Proxy rule for dev server HTTP/WS proxying.
|
|
69
|
+
* Mostly aligned with webpack-dev-server / http-proxy-middleware options.
|
|
70
|
+
*/
|
|
71
|
+
export interface ProxyRule {
|
|
72
|
+
/**
|
|
73
|
+
* Path(s) to match for proxying.
|
|
74
|
+
* When starts with `^`, will be treated as RegExp source.
|
|
75
|
+
* Otherwise, simple prefix match is used.
|
|
76
|
+
*/
|
|
77
|
+
context: string | string[];
|
|
78
|
+
/** Target server URL. */
|
|
79
|
+
target: string;
|
|
80
|
+
/**
|
|
81
|
+
* Path rewrite. Object: first matching regex is replaced (http-proxy-middleware style).
|
|
82
|
+
* Function: (path) => new path.
|
|
83
|
+
*/
|
|
84
|
+
pathRewrite?: PathRewrite;
|
|
85
|
+
/**
|
|
86
|
+
* Whether to change the Host header to match the target.
|
|
87
|
+
* Defaults to true.
|
|
88
|
+
*/
|
|
89
|
+
changeOrigin?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Whether to verify the SSL certificate of the target.
|
|
92
|
+
* Set to false to accept self-signed certificates.
|
|
93
|
+
*/
|
|
94
|
+
secure?: boolean;
|
|
95
|
+
}
|
|
96
|
+
export type DevServerProxy = ProxyRule[];
|
|
97
|
+
/** Object style proxy options without `context`. */
|
|
98
|
+
export type ProxyOptions = Omit<ProxyRule, "context">;
|
|
60
99
|
export interface ResolveOptions {
|
|
61
100
|
alias?: Record<string, string | string[] | Record<string, string | string[]>>;
|
|
62
101
|
extensions?: string[];
|
|
@@ -96,6 +135,8 @@ export interface DevServerConfig {
|
|
|
96
135
|
host?: string;
|
|
97
136
|
/** Use HTTPS; when true without a certificate, a self-signed cert may be generated. */
|
|
98
137
|
https?: boolean;
|
|
138
|
+
/** HTTP proxy rules for Hono dev server (HTTP only; no generic WS proxy in this layer). */
|
|
139
|
+
proxy?: DevServerProxy;
|
|
99
140
|
}
|
|
100
141
|
export interface ConfigComplete {
|
|
101
142
|
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
|
@@ -57,6 +57,45 @@ export type TurbopackRuleConfigCollection = TurbopackRuleConfigItem | (Turbopack
|
|
|
57
57
|
export interface ModuleOptions {
|
|
58
58
|
rules?: Record<string, TurbopackRuleConfigCollection>;
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Path rewrite: object form applies first matching regex→replacement;
|
|
62
|
+
* function form receives path and returns new path (sync only).
|
|
63
|
+
*/
|
|
64
|
+
export type PathRewrite = {
|
|
65
|
+
[regexp: string]: string;
|
|
66
|
+
} | ((path: string) => string);
|
|
67
|
+
/**
|
|
68
|
+
* Proxy rule for dev server HTTP/WS proxying.
|
|
69
|
+
* Mostly aligned with webpack-dev-server / http-proxy-middleware options.
|
|
70
|
+
*/
|
|
71
|
+
export interface ProxyRule {
|
|
72
|
+
/**
|
|
73
|
+
* Path(s) to match for proxying.
|
|
74
|
+
* When starts with `^`, will be treated as RegExp source.
|
|
75
|
+
* Otherwise, simple prefix match is used.
|
|
76
|
+
*/
|
|
77
|
+
context: string | string[];
|
|
78
|
+
/** Target server URL. */
|
|
79
|
+
target: string;
|
|
80
|
+
/**
|
|
81
|
+
* Path rewrite. Object: first matching regex is replaced (http-proxy-middleware style).
|
|
82
|
+
* Function: (path) => new path.
|
|
83
|
+
*/
|
|
84
|
+
pathRewrite?: PathRewrite;
|
|
85
|
+
/**
|
|
86
|
+
* Whether to change the Host header to match the target.
|
|
87
|
+
* Defaults to true.
|
|
88
|
+
*/
|
|
89
|
+
changeOrigin?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Whether to verify the SSL certificate of the target.
|
|
92
|
+
* Set to false to accept self-signed certificates.
|
|
93
|
+
*/
|
|
94
|
+
secure?: boolean;
|
|
95
|
+
}
|
|
96
|
+
export type DevServerProxy = ProxyRule[];
|
|
97
|
+
/** Object style proxy options without `context`. */
|
|
98
|
+
export type ProxyOptions = Omit<ProxyRule, "context">;
|
|
60
99
|
export interface ResolveOptions {
|
|
61
100
|
alias?: Record<string, string | string[] | Record<string, string | string[]>>;
|
|
62
101
|
extensions?: string[];
|
|
@@ -96,6 +135,8 @@ export interface DevServerConfig {
|
|
|
96
135
|
host?: string;
|
|
97
136
|
/** Use HTTPS; when true without a certificate, a self-signed cert may be generated. */
|
|
98
137
|
https?: boolean;
|
|
138
|
+
/** HTTP proxy rules for Hono dev server (HTTP only; no generic WS proxy in this layer). */
|
|
139
|
+
proxy?: DevServerProxy;
|
|
99
140
|
}
|
|
100
141
|
export interface ConfigComplete {
|
|
101
142
|
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.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"types": "esm/index.d.ts",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"build:cjs": "rm -rf cjs && tsc -p ./tsconfig.json --module commonjs --outDir cjs",
|
|
23
23
|
"build:esm": "rm -rf esm && tsc -p ./tsconfig.json --module esnext --outDir esm && node ../../scripts/add-esm-extensions.cjs",
|
|
24
24
|
"build": "npm run build:cjs && npm run build:esm",
|
|
25
|
+
"test": "vitest run",
|
|
25
26
|
"clean": "rm -rf cjs esm",
|
|
26
27
|
"prepublishOnly": "turbo run build --filter=@utoo/pack-shared"
|
|
27
28
|
},
|