@mednours/fronton 0.3.0 → 0.5.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/dist/backon/index.d.ts.map +1 -1
- package/dist/bundle-report/index.d.ts +27 -0
- package/dist/bundle-report/index.d.ts.map +1 -0
- package/dist/client.d.ts +50 -17
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +115 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +146 -16
- package/dist/obfuscate/rewrite-text.d.ts +6 -9
- package/dist/obfuscate/rewrite-text.d.ts.map +1 -1
- package/package.json +12 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/backon/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AASzC,MAAM,WAAW,kBAAkB;IACjC,wFAAwF;IACxF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;;;;;OAYG;IACH,EAAE,CAAC,EAAE,OAAO,CAAC;CACd;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/backon/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AASzC,MAAM,WAAW,kBAAkB;IACjC,wFAAwF;IACxF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;;;;;OAYG;IACH,EAAE,CAAC,EAAE,OAAO,CAAC;CACd;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAqB1G"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export interface BundleReportOptions {
|
|
3
|
+
/** Warn when an uncompressed JS/CSS asset exceeds this size in KB. Defaults to 250. */
|
|
4
|
+
warnThresholdKb?: number;
|
|
5
|
+
/** Disable console output while still collecting metrics (e.g. in custom reporters/tests). */
|
|
6
|
+
silent?: boolean;
|
|
7
|
+
/** Optional callback receiving the computed chunk entries sorted largest-first. */
|
|
8
|
+
onReport?: (entries: BundleAssetReport[]) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface BundleAssetReport {
|
|
11
|
+
fileName: string;
|
|
12
|
+
rawBytes: number;
|
|
13
|
+
gzipBytes: number;
|
|
14
|
+
oversized: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Computes raw and gzip byte sizes for every emitted JS/CSS bundle asset. */
|
|
17
|
+
export declare function summarizeBundleAssets(bundle: Record<string, {
|
|
18
|
+
type: string;
|
|
19
|
+
code?: string;
|
|
20
|
+
source?: string | Uint8Array;
|
|
21
|
+
}>, warnThresholdKb?: number): BundleAssetReport[];
|
|
22
|
+
/**
|
|
23
|
+
* Zero-dependency Vite plugin that logs a sorted raw + gzip bundle breakdown
|
|
24
|
+
* at the end of `vite build` and flags oversized chunks that need lazy splitting.
|
|
25
|
+
*/
|
|
26
|
+
export declare function bundleReport(options?: BundleReportOptions): Plugin;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundle-report/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,MAAM,WAAW,mBAAmB;IAClC,uFAAuF;IACvF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,8FAA8F;IAC9F,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,mFAAmF;IACnF,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,EAAE,KAAK,IAAI,CAAC;CACnD;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB;AAMD,8EAA8E;AAC9E,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,CAAC,EACrF,eAAe,SAAM,GACpB,iBAAiB,EAAE,CAuBrB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAmBtE"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,21 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reads
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* This exists to fix a real gap: a plain `process.env.API_BASE_URL` check
|
|
6
|
-
* (the pattern backon's own generated `generate-client` script uses,
|
|
7
|
-
* correctly, since that script runs under Node/Bun) does nothing useful in
|
|
8
|
-
* a Vite-built browser bundle — `process` isn't defined there, so the
|
|
9
|
-
* check just silently falls through. Vite's own env mechanism is
|
|
10
|
-
* `import.meta.env`, statically replaced at build time, and only
|
|
11
|
-
* `VITE_`-prefixed variables are ever exposed to client code (Vite drops
|
|
12
|
-
* everything else on purpose, so a backend secret sitting in the same
|
|
13
|
-
* .env file never leaks into the browser bundle).
|
|
14
|
-
*
|
|
15
|
-
* Returns "" (relative requests) when unset — correct for same-origin
|
|
16
|
-
* deployment or a dev-server proxy (see backonProxy in the root entry
|
|
17
|
-
* point); set VITE_API_BASE_URL explicitly when the frontend and backend
|
|
18
|
-
* are on different origins.
|
|
2
|
+
* Reads `import.meta.env.VITE_API_BASE_URL` at runtime in a Vite browser
|
|
3
|
+
* bundle, returning `""` when unset (for same-origin deploys or Vite dev proxy).
|
|
19
4
|
*/
|
|
20
5
|
export declare function resolveApiBaseUrl(): string;
|
|
6
|
+
/** Structured error thrown by `createApiClient()` on non-2xx responses, matching backon's error JSON shape. */
|
|
7
|
+
export declare class ApiError extends Error {
|
|
8
|
+
readonly status: number;
|
|
9
|
+
readonly code: string;
|
|
10
|
+
readonly details?: unknown;
|
|
11
|
+
constructor(status: number, code: string, message: string, details?: unknown);
|
|
12
|
+
}
|
|
13
|
+
export type ApiCredentials = NonNullable<RequestInit["credentials"]>;
|
|
14
|
+
export type ApiBodyInit = NonNullable<RequestInit["body"]>;
|
|
15
|
+
export interface ApiClientOptions {
|
|
16
|
+
/** Override base URL (defaults to `resolveApiBaseUrl() || (DEV ? "/api" : "")`). */
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
/** Default fetch credentials mode (defaults to `"same-origin"`). */
|
|
19
|
+
credentials?: ApiCredentials;
|
|
20
|
+
/** Default headers merged into every request. */
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
/** Optional custom fetch implementation (useful for tests or SSR). */
|
|
23
|
+
fetch?: typeof fetch;
|
|
24
|
+
}
|
|
25
|
+
export interface ApiRequestOptions extends Omit<RequestInit, "body"> {
|
|
26
|
+
/** Plain object/array is JSON-stringified automatically; BodyInit values pass through unchanged. */
|
|
27
|
+
body?: unknown;
|
|
28
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Lightweight typed fetch wrapper pre-wired for backon backends:
|
|
32
|
+
* resolves `VITE_API_BASE_URL` / dev `/api` proxy, serializes JSON bodies,
|
|
33
|
+
* and unwraps backon `{ error: { code, message, details } }` payloads into `ApiError`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createApiClient(options?: ApiClientOptions): {
|
|
36
|
+
request: <T = unknown>(path: string, init?: ApiRequestOptions) => Promise<T>;
|
|
37
|
+
get: <T = unknown>(path: string, init?: Omit<ApiRequestOptions, "method" | "body">) => Promise<T>;
|
|
38
|
+
post: <T = unknown>(path: string, body?: unknown, init?: Omit<ApiRequestOptions, "method" | "body">) => Promise<T>;
|
|
39
|
+
put: <T = unknown>(path: string, body?: unknown, init?: Omit<ApiRequestOptions, "method" | "body">) => Promise<T>;
|
|
40
|
+
patch: <T = unknown>(path: string, body?: unknown, init?: Omit<ApiRequestOptions, "method" | "body">) => Promise<T>;
|
|
41
|
+
delete: <T = unknown>(path: string, init?: Omit<ApiRequestOptions, "method">) => Promise<T>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Triggers a lazy route/component dynamic import once and caches the trigger
|
|
45
|
+
* so repeated hover/focus events are free. Ideal for declarative React Router links.
|
|
46
|
+
*/
|
|
47
|
+
export declare function preloadChunk(loader: () => Promise<unknown>): void;
|
|
48
|
+
/** Returns React event handlers (`onMouseEnter`, `onFocus`, `onTouchStart`) that preload a lazy chunk on intent. */
|
|
49
|
+
export declare function createPrefetchHandlers(loader: () => Promise<unknown>): {
|
|
50
|
+
onMouseEnter: () => void;
|
|
51
|
+
onFocus: () => void;
|
|
52
|
+
onTouchStart: () => void;
|
|
53
|
+
};
|
|
21
54
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAG1C;AAED,+GAA+G;AAC/G,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAE3B,YAAY,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAM3E;CACF;AAED,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;AACrE,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B,oFAAoF;IACpF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,WAAW,CAAC,EAAE,cAAc,CAAC;IAC7B,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,sEAAsE;IACtE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC;IAClE,oGAAoG;IACpG,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;CAC/D;AAmCD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB;cAIrC,CAAC,kBAAkB,MAAM,SAAQ,iBAAiB,KAAQ,OAAO,CAAC,CAAC,CAAC;UA2DnF,CAAC,GAAG,OAAO,QAAQ,MAAM,SAAS,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,MAAM,CAAC;WAE3E,CAAC,GAAG,OAAO,QAAQ,MAAM,SAAS,OAAO,SAAS,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,MAAM,CAAC;UAE7F,CAAC,GAAG,OAAO,QAAQ,MAAM,SAAS,OAAO,SAAS,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,MAAM,CAAC;YAE1F,CAAC,GAAG,OAAO,QAAQ,MAAM,SAAS,OAAO,SAAS,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,MAAM,CAAC;aAE3F,CAAC,GAAG,OAAO,QAAQ,MAAM,SAAS,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC;EAG/E;AAID;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAOjE;AAED,oHAAoH;AACpH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC;IAGjE,YAAY;IACZ,OAAO;IACP,YAAY;EAEf"}
|
package/dist/client.js
CHANGED
|
@@ -3,6 +3,121 @@ function resolveApiBaseUrl() {
|
|
|
3
3
|
const value = import.meta.env?.VITE_API_BASE_URL;
|
|
4
4
|
return typeof value === "string" && value.length > 0 ? value : "";
|
|
5
5
|
}
|
|
6
|
+
var ApiError = class extends Error {
|
|
7
|
+
status;
|
|
8
|
+
code;
|
|
9
|
+
details;
|
|
10
|
+
constructor(status, code, message, details) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "ApiError";
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.details = details;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function isBodyInit(value) {
|
|
19
|
+
return typeof value === "string" || value instanceof FormData || value instanceof URLSearchParams || value instanceof Blob || value instanceof ArrayBuffer || ArrayBuffer.isView(value) || typeof ReadableStream !== "undefined" && value instanceof ReadableStream;
|
|
20
|
+
}
|
|
21
|
+
function defaultClientBaseUrl() {
|
|
22
|
+
const configured = resolveApiBaseUrl();
|
|
23
|
+
if (configured) return configured;
|
|
24
|
+
return import.meta.env?.DEV ? "/api" : "";
|
|
25
|
+
}
|
|
26
|
+
function buildUrl(baseUrl, path, query) {
|
|
27
|
+
const normalizedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
28
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
29
|
+
let url = `${normalizedBase}${normalizedPath}`;
|
|
30
|
+
if (query) {
|
|
31
|
+
const params = new URLSearchParams();
|
|
32
|
+
for (const [k, v] of Object.entries(query)) {
|
|
33
|
+
if (v !== void 0) params.set(k, String(v));
|
|
34
|
+
}
|
|
35
|
+
const qs = params.toString();
|
|
36
|
+
if (qs) url += `${url.includes("?") ? "&" : "?"}${qs}`;
|
|
37
|
+
}
|
|
38
|
+
return url;
|
|
39
|
+
}
|
|
40
|
+
function createApiClient(options = {}) {
|
|
41
|
+
const baseUrl = options.baseUrl ?? defaultClientBaseUrl();
|
|
42
|
+
const fetchFn = options.fetch ?? fetch;
|
|
43
|
+
async function request(path, init = {}) {
|
|
44
|
+
const { body, query, headers, ...rest } = init;
|
|
45
|
+
const mergedHeaders = new Headers(options.headers);
|
|
46
|
+
if (headers) {
|
|
47
|
+
new Headers(headers).forEach((value, key) => mergedHeaders.set(key, value));
|
|
48
|
+
}
|
|
49
|
+
let preparedBody;
|
|
50
|
+
if (body !== void 0) {
|
|
51
|
+
if (isBodyInit(body)) {
|
|
52
|
+
preparedBody = body;
|
|
53
|
+
} else {
|
|
54
|
+
preparedBody = JSON.stringify(body);
|
|
55
|
+
if (!mergedHeaders.has("Content-Type")) {
|
|
56
|
+
mergedHeaders.set("Content-Type", "application/json");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const res = await fetchFn(buildUrl(baseUrl, path, query), {
|
|
61
|
+
credentials: options.credentials ?? "same-origin",
|
|
62
|
+
...rest,
|
|
63
|
+
headers: mergedHeaders,
|
|
64
|
+
body: preparedBody
|
|
65
|
+
});
|
|
66
|
+
if (!res.ok) {
|
|
67
|
+
let code = "http_error";
|
|
68
|
+
let message = res.statusText || `Request failed with status ${res.status}`;
|
|
69
|
+
let details;
|
|
70
|
+
const contentType2 = res.headers.get("content-type") ?? "";
|
|
71
|
+
if (contentType2.includes("application/json")) {
|
|
72
|
+
const parsed = await res.json().catch(() => void 0);
|
|
73
|
+
if (parsed?.error) {
|
|
74
|
+
code = parsed.error.code ?? code;
|
|
75
|
+
message = parsed.error.message ?? message;
|
|
76
|
+
details = parsed.error.details;
|
|
77
|
+
} else if (parsed?.message) {
|
|
78
|
+
message = parsed.message;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
throw new ApiError(res.status, code, message, details);
|
|
82
|
+
}
|
|
83
|
+
if (res.status === 204 || res.headers.get("content-length") === "0") {
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
87
|
+
if (contentType.includes("application/json")) {
|
|
88
|
+
return await res.json();
|
|
89
|
+
}
|
|
90
|
+
return await res.text();
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
request,
|
|
94
|
+
get: (path, init) => request(path, { ...init, method: "GET" }),
|
|
95
|
+
post: (path, body, init) => request(path, { ...init, method: "POST", body }),
|
|
96
|
+
put: (path, body, init) => request(path, { ...init, method: "PUT", body }),
|
|
97
|
+
patch: (path, body, init) => request(path, { ...init, method: "PATCH", body }),
|
|
98
|
+
delete: (path, init) => request(path, { ...init, method: "DELETE" })
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
var preloadedLoaders = /* @__PURE__ */ new WeakSet();
|
|
102
|
+
function preloadChunk(loader) {
|
|
103
|
+
if (preloadedLoaders.has(loader)) return;
|
|
104
|
+
preloadedLoaders.add(loader);
|
|
105
|
+
void loader().catch(() => {
|
|
106
|
+
preloadedLoaders.delete(loader);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function createPrefetchHandlers(loader) {
|
|
110
|
+
const trigger = () => preloadChunk(loader);
|
|
111
|
+
return {
|
|
112
|
+
onMouseEnter: trigger,
|
|
113
|
+
onFocus: trigger,
|
|
114
|
+
onTouchStart: trigger
|
|
115
|
+
};
|
|
116
|
+
}
|
|
6
117
|
export {
|
|
118
|
+
ApiError,
|
|
119
|
+
createApiClient,
|
|
120
|
+
createPrefetchHandlers,
|
|
121
|
+
preloadChunk,
|
|
7
122
|
resolveApiBaseUrl
|
|
8
123
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { frontonCompression } from "./compression/index";
|
|
|
4
4
|
export type { FrontonCompressionOptions } from "./compression/index";
|
|
5
5
|
export { backonProxy } from "./backon/index";
|
|
6
6
|
export type { BackonProxyOptions } from "./backon/index";
|
|
7
|
+
export { bundleReport } from "./bundle-report/index";
|
|
8
|
+
export type { BundleReportOptions, BundleAssetReport } from "./bundle-report/index";
|
|
7
9
|
export { compressImages } from "./media/images";
|
|
8
10
|
export type { CompressImagesOptions } from "./media/images";
|
|
9
11
|
export { compressVideos } from "./media/videos";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAOpF,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -95,10 +95,92 @@ function scanExpressionEnd(code, start) {
|
|
|
95
95
|
}
|
|
96
96
|
var QUOTE_CHARS = /* @__PURE__ */ new Set(['"', "'", "`"]);
|
|
97
97
|
var STRING_LITERAL_PATTERN = /(["'`])(?<lit>(?:\\.|(?!\1).)*)\1/gd;
|
|
98
|
+
function scanTemplateLiteral(code, openIdx) {
|
|
99
|
+
const quasis = [];
|
|
100
|
+
const expressions = [];
|
|
101
|
+
let i = openIdx + 1;
|
|
102
|
+
let quasiStart = i;
|
|
103
|
+
while (i < code.length) {
|
|
104
|
+
const ch = code[i];
|
|
105
|
+
if (ch === "\\") {
|
|
106
|
+
i += 2;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (ch === "`") {
|
|
110
|
+
quasis.push([quasiStart, i]);
|
|
111
|
+
return { end: i, quasis, expressions };
|
|
112
|
+
}
|
|
113
|
+
if (ch === "$" && code[i + 1] === "{") {
|
|
114
|
+
quasis.push([quasiStart, i]);
|
|
115
|
+
let exprSliceStart = i + 2;
|
|
116
|
+
let j = exprSliceStart;
|
|
117
|
+
let braceDepth = 1;
|
|
118
|
+
let inStr = null;
|
|
119
|
+
while (j < code.length && braceDepth > 0) {
|
|
120
|
+
const c = code[j];
|
|
121
|
+
if (inStr) {
|
|
122
|
+
if (c === "\\") {
|
|
123
|
+
j += 2;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (c === inStr) inStr = null;
|
|
127
|
+
j++;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (c === '"' || c === "'") {
|
|
131
|
+
inStr = c;
|
|
132
|
+
j++;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (c === "`") {
|
|
136
|
+
if (j > exprSliceStart) expressions.push([exprSliceStart, j]);
|
|
137
|
+
const nested = scanTemplateLiteral(code, j);
|
|
138
|
+
quasis.push(...nested.quasis);
|
|
139
|
+
expressions.push(...nested.expressions);
|
|
140
|
+
j = nested.end + 1;
|
|
141
|
+
exprSliceStart = j;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (c === "{") braceDepth++;
|
|
145
|
+
else if (c === "}") {
|
|
146
|
+
braceDepth--;
|
|
147
|
+
if (braceDepth === 0) break;
|
|
148
|
+
}
|
|
149
|
+
j++;
|
|
150
|
+
}
|
|
151
|
+
if (j > exprSliceStart) expressions.push([exprSliceStart, j]);
|
|
152
|
+
i = j + 1;
|
|
153
|
+
quasiStart = i;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
i++;
|
|
157
|
+
}
|
|
158
|
+
quasis.push([quasiStart, code.length]);
|
|
159
|
+
return { end: code.length, quasis, expressions };
|
|
160
|
+
}
|
|
161
|
+
function rewriteQuotedStringLiterals(code, rangeStart, rangeEnd, s, map) {
|
|
162
|
+
let count = 0;
|
|
163
|
+
const slice = code.slice(rangeStart, rangeEnd);
|
|
164
|
+
for (const litMatch of slice.matchAll(STRING_LITERAL_PATTERN)) {
|
|
165
|
+
const range = litMatch.indices.groups.lit;
|
|
166
|
+
if (!range) continue;
|
|
167
|
+
const [relStart, relEnd] = range;
|
|
168
|
+
const start = rangeStart + relStart;
|
|
169
|
+
const end = rangeStart + relEnd;
|
|
170
|
+
const { text, changed } = rewriteClassList(code.slice(start, end), map);
|
|
171
|
+
if (changed) {
|
|
172
|
+
s.overwrite(start, end, text);
|
|
173
|
+
count++;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return count;
|
|
177
|
+
}
|
|
98
178
|
function rewriteTextOutput(code, map) {
|
|
99
179
|
const s = new MagicString(code);
|
|
100
180
|
let count = 0;
|
|
181
|
+
let lastProcessedEnd = 0;
|
|
101
182
|
for (const match of code.matchAll(PROP_START)) {
|
|
183
|
+
if (match.index < lastProcessedEnd) continue;
|
|
102
184
|
let i = match.index + match[0].length;
|
|
103
185
|
while (i < code.length && /\s/.test(code[i])) i++;
|
|
104
186
|
if (code[i] === "{") {
|
|
@@ -106,6 +188,21 @@ function rewriteTextOutput(code, map) {
|
|
|
106
188
|
while (i < code.length && /\s/.test(code[i])) i++;
|
|
107
189
|
}
|
|
108
190
|
const ch = code[i];
|
|
191
|
+
if (ch === "`") {
|
|
192
|
+
const tpl = scanTemplateLiteral(code, i);
|
|
193
|
+
for (const [qStart, qEnd] of tpl.quasis) {
|
|
194
|
+
const { text, changed } = rewriteClassList(code.slice(qStart, qEnd), map);
|
|
195
|
+
if (changed) {
|
|
196
|
+
s.overwrite(qStart, qEnd, text);
|
|
197
|
+
count++;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
for (const [eStart, eEnd] of tpl.expressions) {
|
|
201
|
+
count += rewriteQuotedStringLiterals(code, eStart, eEnd, s, map);
|
|
202
|
+
}
|
|
203
|
+
lastProcessedEnd = tpl.end + 1;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
109
206
|
if (ch !== void 0 && QUOTE_CHARS.has(ch)) {
|
|
110
207
|
const quote = ch;
|
|
111
208
|
let j = i + 1;
|
|
@@ -121,24 +218,13 @@ function rewriteTextOutput(code, map) {
|
|
|
121
218
|
s.overwrite(start, end, text);
|
|
122
219
|
count++;
|
|
123
220
|
}
|
|
221
|
+
lastProcessedEnd = end + 1;
|
|
124
222
|
continue;
|
|
125
223
|
}
|
|
126
224
|
if (ch === void 0) continue;
|
|
127
225
|
const exprEnd = scanExpressionEnd(code, i);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const range = litMatch.indices.groups.lit;
|
|
131
|
-
if (!range) continue;
|
|
132
|
-
const [relStart, relEnd] = range;
|
|
133
|
-
const start = i + relStart;
|
|
134
|
-
const end = i + relEnd;
|
|
135
|
-
const list = code.slice(start, end);
|
|
136
|
-
const { text, changed } = rewriteClassList(list, map);
|
|
137
|
-
if (changed) {
|
|
138
|
-
s.overwrite(start, end, text);
|
|
139
|
-
count++;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
226
|
+
count += rewriteQuotedStringLiterals(code, i, exprEnd, s, map);
|
|
227
|
+
lastProcessedEnd = exprEnd;
|
|
142
228
|
}
|
|
143
229
|
return { code: s.toString(), count };
|
|
144
230
|
}
|
|
@@ -208,8 +294,10 @@ function frontonCompression(options = {}) {
|
|
|
208
294
|
// src/backon/index.ts
|
|
209
295
|
function backonProxy(target, options = {}) {
|
|
210
296
|
const { prefix = "/api", stripPrefix = true, ws = true } = options;
|
|
297
|
+
const normalizedPrefix = prefix === "/" ? "/" : prefix.replace(/\/+$/, "");
|
|
298
|
+
const escapedPrefix = normalizedPrefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
211
299
|
return {
|
|
212
|
-
[
|
|
300
|
+
[normalizedPrefix]: {
|
|
213
301
|
target,
|
|
214
302
|
changeOrigin: true,
|
|
215
303
|
ws,
|
|
@@ -218,12 +306,53 @@ function backonProxy(target, options = {}) {
|
|
|
218
306
|
// an empty path ("/api" -> ""), which is not a valid request
|
|
219
307
|
// target — fall back to "/" rather than relying on whatever the
|
|
220
308
|
// underlying HTTP client happens to coerce an empty string to.
|
|
221
|
-
rewrite: (path) => path.replace(new RegExp(`^${
|
|
309
|
+
rewrite: (path) => path.replace(new RegExp(`^${escapedPrefix}`), "") || "/"
|
|
222
310
|
} : {}
|
|
223
311
|
}
|
|
224
312
|
};
|
|
225
313
|
}
|
|
226
314
|
|
|
315
|
+
// src/bundle-report/index.ts
|
|
316
|
+
import { gzipSync } from "node:zlib";
|
|
317
|
+
function formatKb(bytes) {
|
|
318
|
+
return `${(bytes / 1024).toFixed(2)} kB`;
|
|
319
|
+
}
|
|
320
|
+
function summarizeBundleAssets(bundle, warnThresholdKb = 250) {
|
|
321
|
+
const thresholdBytes = warnThresholdKb * 1024;
|
|
322
|
+
const reports = [];
|
|
323
|
+
for (const [fileName, item] of Object.entries(bundle)) {
|
|
324
|
+
if (!/\.(?:m?js|css)$/.test(fileName)) continue;
|
|
325
|
+
const raw = item.type === "chunk" ? Buffer.from(item.code ?? "", "utf-8") : typeof item.source === "string" ? Buffer.from(item.source, "utf-8") : Buffer.from(item.source ?? new Uint8Array());
|
|
326
|
+
const gzipBytes = gzipSync(raw).length;
|
|
327
|
+
reports.push({
|
|
328
|
+
fileName,
|
|
329
|
+
rawBytes: raw.length,
|
|
330
|
+
gzipBytes,
|
|
331
|
+
oversized: raw.length > thresholdBytes
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
reports.sort((a, b) => b.rawBytes - a.rawBytes);
|
|
335
|
+
return reports;
|
|
336
|
+
}
|
|
337
|
+
function bundleReport(options = {}) {
|
|
338
|
+
const warnThresholdKb = options.warnThresholdKb ?? 250;
|
|
339
|
+
return {
|
|
340
|
+
name: "fronton:bundle-report",
|
|
341
|
+
apply: "build",
|
|
342
|
+
generateBundle(_outputOptions, bundle) {
|
|
343
|
+
const entries = summarizeBundleAssets(bundle, warnThresholdKb);
|
|
344
|
+
options.onReport?.(entries);
|
|
345
|
+
if (options.silent || entries.length === 0) return;
|
|
346
|
+
console.log("\n[fronton] Bundle report:");
|
|
347
|
+
for (const entry of entries) {
|
|
348
|
+
const flag = entry.oversized ? ` [> ${warnThresholdKb} kB \u2014 consider lazy()]` : "";
|
|
349
|
+
console.log(` ${entry.fileName.padEnd(38)} ${formatKb(entry.rawBytes).padStart(10)} (gzip ${formatKb(entry.gzipBytes)})${flag}`);
|
|
350
|
+
}
|
|
351
|
+
console.log();
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
227
356
|
// src/media/images.ts
|
|
228
357
|
import { readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
229
358
|
import { resolve } from "node:path";
|
|
@@ -458,6 +587,7 @@ function compressVideos(options = {}) {
|
|
|
458
587
|
}
|
|
459
588
|
export {
|
|
460
589
|
backonProxy,
|
|
590
|
+
bundleReport,
|
|
461
591
|
compressImages,
|
|
462
592
|
compressVideos,
|
|
463
593
|
frontonCompression,
|
|
@@ -2,20 +2,17 @@
|
|
|
2
2
|
* Rewrites known-safe class-bearing text in already-built JS/HTML output.
|
|
3
3
|
* For each `className`/`class` property found:
|
|
4
4
|
*
|
|
5
|
-
* - if its value is a single plain string/template literal (
|
|
6
|
-
*
|
|
5
|
+
* - if its value is a single plain string/template literal (including
|
|
6
|
+
* `${...}` interpolations), rewrite class tokens in static quasis and
|
|
7
|
+
* any string literals inside `${...}` expressions;
|
|
7
8
|
* - otherwise (a function call, ternary, logical expression — however a
|
|
8
9
|
* merge helper compiled down), scan the whole value expression for
|
|
9
10
|
* string literals and rewrite class tokens inside each one, without
|
|
10
11
|
* needing to know what produced the expression.
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* left exactly as it was. Only tokens present in `map` (i.e. provably
|
|
16
|
-
* real classes Tailwind actually generated, per rewrite-css.ts's
|
|
17
|
-
* collectClassesFromCss) are ever touched, so a miss here just means
|
|
18
|
-
* "not obfuscated", never a broken build.
|
|
13
|
+
* Only tokens present in `map` (i.e. provably real classes Tailwind actually
|
|
14
|
+
* generated, per rewrite-css.ts's collectClassesFromCss) are ever touched,
|
|
15
|
+
* so a miss here just means "not obfuscated", never a broken build.
|
|
19
16
|
*/
|
|
20
17
|
export declare function rewriteTextOutput(code: string, map: Map<string, string>): {
|
|
21
18
|
code: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rewrite-text.d.ts","sourceRoot":"","sources":["../../src/obfuscate/rewrite-text.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rewrite-text.d.ts","sourceRoot":"","sources":["../../src/obfuscate/rewrite-text.ts"],"names":[],"mappings":"AA8LA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAsEzG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mednours/fronton",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Opinionated runtime pieces for fronton-scaffolded Vite projects — Tailwind class obfuscation, gzip/brotli compression, and backon API wiring.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
|
-
"files": [
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
22
24
|
"exports": {
|
|
23
25
|
".": {
|
|
24
26
|
"types": "./dist/index.d.ts",
|
|
@@ -44,7 +46,7 @@
|
|
|
44
46
|
"sharp": "^0.35.0",
|
|
45
47
|
"fluent-ffmpeg": "^2.1.3",
|
|
46
48
|
"ffmpeg-static": "^5.3.0",
|
|
47
|
-
"motion": "^12.0.0"
|
|
49
|
+
"motion": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0"
|
|
48
50
|
},
|
|
49
51
|
"peerDependenciesMeta": {
|
|
50
52
|
"sharp": {
|
|
@@ -61,10 +63,10 @@
|
|
|
61
63
|
}
|
|
62
64
|
},
|
|
63
65
|
"dependencies": {
|
|
64
|
-
"magic-string": "^1.
|
|
65
|
-
"postcss": "^8.5.
|
|
66
|
+
"magic-string": "^1.4.5",
|
|
67
|
+
"postcss": "^8.5.34",
|
|
66
68
|
"postcss-selector-parser": "^7.1.5",
|
|
67
|
-
"vite-plugin-compression2": "^2.5.
|
|
69
|
+
"vite-plugin-compression2": "^2.5.4"
|
|
68
70
|
},
|
|
69
71
|
"devDependencies": {
|
|
70
72
|
"@types/bun": "latest",
|
|
@@ -72,10 +74,10 @@
|
|
|
72
74
|
"esbuild": "^0.28.2",
|
|
73
75
|
"ffmpeg-static": "^5.3.0",
|
|
74
76
|
"fluent-ffmpeg": "^2.1.3",
|
|
75
|
-
"motion": "^
|
|
76
|
-
"react": "^19.
|
|
77
|
-
"sharp": "^0.35.
|
|
77
|
+
"motion": "^15.0.1",
|
|
78
|
+
"react": "^19.3.1",
|
|
79
|
+
"sharp": "^0.35.6",
|
|
78
80
|
"typescript": "^7.0.2",
|
|
79
|
-
"vite": "^8.
|
|
81
|
+
"vite": "^8.4.1"
|
|
80
82
|
}
|
|
81
83
|
}
|