@wenathlan/getry 2.0.164 → 2.0.166

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/nodeshim.ts ADDED
@@ -0,0 +1,265 @@
1
+ /**
2
+ * @file nodeshim.ts
3
+ * @module engine/nodeshim
4
+ * @description
5
+ * The browser surface of the multi-mode engines. The shared core graph
6
+ * (constants, models, fingerprint, core, the provider lineage) is authored
7
+ * once for node, bun AND the browser bundle, and the browser answers the
8
+ * neutral stubs the doctrine always described: vite's default
9
+ * browser-external proxy throws on the first property binding, which killed
10
+ * the whole module graph at import time and blanked the OS. The vite
11
+ * resolve.alias maps every node: builtin the graph speaks onto this one
12
+ * module, so the identifiers answer neutral values, the filesystem answers
13
+ * absent and inert, and the crypto-strong draws ride the platform
14
+ * randomness. Nothing server-only is faked: dns probes, readline and the
15
+ * scrypt/timing-safe lanes throw the same way they would on a host without
16
+ * them, and every caller in the browser graph already carries its guarded
17
+ * fallback.
18
+ *
19
+ * @section os — the neutral identifiers (node:os)
20
+ * @section path — the pure string posix grammar (node:path)
21
+ * @section fs — the absent-and-inert filesystem (node:fs, node:fs/promises)
22
+ * @section process — the neutral process surface (node:process)
23
+ * @section crypto — the platform randomness surface (node:crypto)
24
+ * @section url — the file url converters (node:url)
25
+ * @section util — the inspection stubs (node:util)
26
+ * @depends-on the vite resolve.alias in vite.config.ts
27
+ * @consumed-by every engine module the browser graph links
28
+ */
29
+
30
+ // ---------------------------------------------------------------------------
31
+ // @section os — the neutral identifiers
32
+ // ---------------------------------------------------------------------------
33
+
34
+ export const EOL = "\n";
35
+ export const arch = (): string => "wasm";
36
+ export const platform = (): string => "browser";
37
+ export const release = (): string => "";
38
+ export const type = (): string => "Browser";
39
+ export const hostname = (): string => "localhost";
40
+ export const homedir = (): string => "/";
41
+ export const tmpdir = (): string => "/tmp";
42
+ export const cpus = (): unknown[] => [];
43
+ export const totalmem = (): number => 0;
44
+ export const freemem = (): number => 0;
45
+ export const uptime = (): number => 0;
46
+ export const loadavg = (): number[] => [0, 0, 0];
47
+ export const networkInterfaces = (): unknown[] => [];
48
+ export const userInfo = (): unknown => ({ username: "devthink", uid: -1, gid: -1, homedir: "/", shell: null });
49
+ export const constants: Record<string, never> = {};
50
+
51
+ // ---------------------------------------------------------------------------
52
+ // @section path — the pure string posix grammar
53
+ // ---------------------------------------------------------------------------
54
+
55
+ const normalizeone = (value: string): string => value.replace(/\/{2,}/g, "/").replace(/\/$/, "") || "/";
56
+
57
+ export const sep = "/";
58
+ export const delimiter = ":";
59
+ export const isAbsolute = (value: string): boolean => value.startsWith("/");
60
+ export const normalize = (value: string): string => normalizeone(value);
61
+ export const join = (...parts: string[]): string => normalizeone(parts.filter(Boolean).join("/"));
62
+ export const resolve = (...parts: string[]): string => normalizeone(parts.filter(Boolean).join("/"));
63
+ export const dirname = (value: string): string => {
64
+ const cut = normalizeone(value).lastIndexOf("/");
65
+ return cut <= 0 ? "/" : normalizeone(value).slice(0, cut);
66
+ };
67
+ export const basename = (value: string, ext?: string): string => {
68
+ const base = normalizeone(value).split("/").pop() ?? "";
69
+ return ext && base.endsWith(ext) ? base.slice(0, -ext.length) : base;
70
+ };
71
+ export const extname = (value: string): string => {
72
+ const base = normalizeone(value).split("/").pop() ?? "";
73
+ const dot = base.lastIndexOf(".");
74
+ return dot > 0 ? base.slice(dot) : "";
75
+ };
76
+ export const relative = (from: string, to: string): string =>
77
+ normalizeone(to).replace(normalizeone(from), "").replace(/^\//, "") || ".";
78
+ export const posix = { sep, delimiter, isAbsolute, normalize, join, resolve, dirname, basename, extname, relative };
79
+ export const win32 = { sep: "\\", delimiter: ";", isAbsolute, normalize, join, resolve, dirname, basename, extname, relative };
80
+
81
+ // ---------------------------------------------------------------------------
82
+ // @section fs — the absent-and-inert filesystem
83
+ // ---------------------------------------------------------------------------
84
+
85
+ const absent = (name: string): never => {
86
+ throw new Error(`[devthink browser bundle] ${name} is absent on this host`);
87
+ };
88
+
89
+ export const existsSync = (_path: string): boolean => false;
90
+ export const mkdirSync = (_path: string): undefined => undefined;
91
+ export const copyFileSync = (_from: string, _to: string): undefined => undefined;
92
+ export const cpSync = (_from: string, _to: string): undefined => undefined;
93
+ export const rmSync = (_path: string): undefined => undefined;
94
+ export const mkdtempSync = (_prefix: string): string => "/tmp";
95
+ export const writeFileSync = (_path: string, _data: string): undefined => undefined;
96
+ export const appendFileSync = (_path: string, _data: string): undefined => undefined;
97
+ export const renameSync = (_from: string, _to: string): undefined => undefined;
98
+ export const chmodSync = (_path: string, _mode: number): undefined => undefined;
99
+ export const unlinkSync = (_path: string): undefined => undefined;
100
+ export const statSync = (_path: string): never => absent("node:fs statSync");
101
+ export const readFileSync = (_path: string): never => absent("node:fs readFileSync");
102
+ /* the stream read the moved transport's static file middleware speaks at
103
+ * module scope (the @hono/node-server family the ownership wave's config
104
+ * bridge inlines into the browser graph) — the serve lane never runs on a
105
+ * browser host, so the binding answers the same honest refusal the stat
106
+ * and read lanes above carry. */
107
+ export const createReadStream = (_path: string): never => absent("node:fs createReadStream");
108
+ export const truncateSync = (_path: string, _len?: number): never => absent("node:fs truncateSync");
109
+ export const readdirSync = (_path: string): string[] => [];
110
+
111
+ export const mkdir = (_path: string): Promise<undefined> => Promise.resolve(undefined);
112
+ export const writeFile = (_path: string, _data: string): Promise<undefined> => Promise.resolve(undefined);
113
+ export const rename = (_from: string, _to: string): Promise<undefined> => Promise.resolve(undefined);
114
+ export const copyFile = (_from: string, _to: string): Promise<undefined> => Promise.resolve(undefined);
115
+ export const cp = (_from: string, _to: string): Promise<undefined> => Promise.resolve(undefined);
116
+ export const rm = (_path: string): Promise<undefined> => Promise.resolve(undefined);
117
+ export const mkdtemp = (_prefix: string): Promise<string> => Promise.resolve("/tmp");
118
+ export const appendFile = (_path: string, _data: string): Promise<undefined> => Promise.resolve(undefined);
119
+ export const access = (_path: string): Promise<undefined> => Promise.resolve(undefined);
120
+ export const readFile = (_path: string): Promise<never> => Promise.reject(absent("node:fs/promises readFile"));
121
+ export const stat = (_path: string): Promise<never> => Promise.reject(absent("node:fs/promises stat"));
122
+ export const readdir = (_path: string): Promise<string[]> => Promise.resolve([]);
123
+
124
+ // ---------------------------------------------------------------------------
125
+ // @section process — the neutral process surface
126
+ // ---------------------------------------------------------------------------
127
+
128
+ /* the version table the moved transport's node adapter speaks at module
129
+ * scope (the @hono/node-server family the ownership wave's config bridge
130
+ * inlines into the browser graph) — the adapter never serves on a browser
131
+ * host, so the table answers the neutral record the identifiers doctrine
132
+ * carries, never a faked host report: the node key rides an EMPTY string —
133
+ * the honest "no node runtime on this host" answer — so the module-scope
134
+ * version gate of the inlined adapter (`versions.node.split('.')` then the
135
+ * 23 / 22.7 / 20.18 ladder) parses the empty rung, reads NaN on every
136
+ * comparison and resolves the unsupported lane without ever throwing on
137
+ * the undefined read that used to kill the whole workbench boot (the
138
+ * white-screen law: one record's shape decides whether the os renders). */
139
+ export const versions: Record<string, string> = { node: "" };
140
+
141
+ // ---------------------------------------------------------------------------
142
+ // @section dns — the resolution refusal (node:dns/promises)
143
+ // ---------------------------------------------------------------------------
144
+
145
+ export const lookup = (_host: string): Promise<never> => Promise.reject(absent("node:dns/promises lookup"));
146
+
147
+ // ---------------------------------------------------------------------------
148
+ // @section crypto — the platform randomness surface
149
+ // ---------------------------------------------------------------------------
150
+
151
+ export const randomUUID = (): string => globalThis.crypto.randomUUID();
152
+ export const randomBytes = (size: number): Uint8Array => globalThis.crypto.getRandomValues(new Uint8Array(size));
153
+ export const randomInt = (min: number, max: number): number => Math.floor(Math.random() * (max - min)) + min;
154
+ export const createHash = (): never => absent("node:crypto createHash");
155
+ export const createHmac = (): never => absent("node:crypto createHmac");
156
+ export const scryptSync = (): never => absent("node:crypto scryptSync");
157
+ export const timingSafeEqual = (): never => absent("node:crypto timingSafeEqual");
158
+
159
+ // ---------------------------------------------------------------------------
160
+ // @section url — the file url converters
161
+ // ---------------------------------------------------------------------------
162
+
163
+ export const pathToFileURL = (value: string): URL => new URL(`file://${value}`);
164
+ export const fileURLToPath = (value: URL | string): string => String(value).replace(/^file:\/\//, "");
165
+
166
+ // ---------------------------------------------------------------------------
167
+ // @section util — the inspection stubs
168
+ // ---------------------------------------------------------------------------
169
+
170
+ export const inspect = (value: unknown): string => String(value);
171
+ export const format = (...parts: unknown[]): string =>
172
+ parts.map((part) => (typeof part === "string" ? part : String(part))).join(" ");
173
+ export const promisify = <T>(fn: T): T => fn;
174
+
175
+ // ---------------------------------------------------------------------------
176
+ // @section zlib — the compression refusal (node:zlib)
177
+ // ---------------------------------------------------------------------------
178
+
179
+ /* the honest refusal the family doctrine pins: the compression lanes ride
180
+ * the node hosts (the png encoder's real deflate, the tar.xz lanes), and a
181
+ * browser graph that links the surface reads the functions without a call
182
+ * — the import stays linkable, the call throws the same way a host without
183
+ * the module would. every caller in the browser graph carries its guarded
184
+ * fallback or routes the workload through the engine's own edge seats. */
185
+
186
+ export const deflateSync = (): never => absent("node:zlib deflateSync");
187
+ export const inflateSync = (): never => absent("node:zlib inflateSync");
188
+ export const gzipSync = (): never => absent("node:zlib gzipSync");
189
+ export const gunzipSync = (): never => absent("node:zlib gunzipSync");
190
+ export const deflate = (_input: unknown, _options: unknown, callback?: (error: Error) => void): void => {
191
+ if (typeof callback === "function") callback(new Error("[getry browser face] node:zlib deflate is absent on this host"));
192
+ };
193
+ export const inflate = (_input: unknown, _options: unknown, callback?: (error: Error) => void): void => {
194
+ if (typeof callback === "function") callback(new Error("[getry browser face] node:zlib inflate is absent on this host"));
195
+ };
196
+ export const zlibconstants: Record<string, never> = {};
197
+
198
+ // ---------------------------------------------------------------------------
199
+ // @section default — the combined surface every builtin specifier shares
200
+ // ---------------------------------------------------------------------------
201
+
202
+ export default {
203
+ EOL,
204
+ arch,
205
+ platform,
206
+ release,
207
+ type,
208
+ hostname,
209
+ homedir,
210
+ tmpdir,
211
+ cpus,
212
+ totalmem,
213
+ freemem,
214
+ uptime,
215
+ loadavg,
216
+ networkInterfaces,
217
+ userInfo,
218
+ constants,
219
+ sep,
220
+ delimiter,
221
+ isAbsolute,
222
+ normalize,
223
+ join,
224
+ resolve,
225
+ dirname,
226
+ basename,
227
+ extname,
228
+ relative,
229
+ posix,
230
+ win32,
231
+ existsSync,
232
+ mkdirSync,
233
+ writeFileSync,
234
+ appendFileSync,
235
+ renameSync,
236
+ chmodSync,
237
+ unlinkSync,
238
+ statSync,
239
+ readFileSync,
240
+ readdirSync,
241
+ mkdir,
242
+ writeFile,
243
+ rename,
244
+ readFile,
245
+ stat,
246
+ readdir,
247
+ randomUUID,
248
+ randomBytes,
249
+ randomInt,
250
+ createHash,
251
+ createHmac,
252
+ scryptSync,
253
+ timingSafeEqual,
254
+ pathToFileURL,
255
+ fileURLToPath,
256
+ inspect,
257
+ format,
258
+ promisify,
259
+ deflateSync,
260
+ inflateSync,
261
+ gzipSync,
262
+ gunzipSync,
263
+ deflate,
264
+ inflate,
265
+ };