@veloxts/router 0.6.29 → 0.6.31
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/CHANGELOG.md +18 -0
- package/dist/contracts.d.ts +0 -1
- package/dist/contracts.js +0 -1
- package/dist/discovery/errors.d.ts +0 -1
- package/dist/discovery/errors.js +0 -1
- package/dist/discovery/index.d.ts +0 -1
- package/dist/discovery/index.js +0 -1
- package/dist/discovery/loader.d.ts +0 -1
- package/dist/discovery/loader.js +0 -1
- package/dist/discovery/types.d.ts +0 -1
- package/dist/discovery/types.js +0 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js +0 -1
- package/dist/expose.d.ts +0 -1
- package/dist/expose.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/procedure/builder.d.ts +0 -1
- package/dist/procedure/builder.js +0 -1
- package/dist/procedure/factory.d.ts +0 -1
- package/dist/procedure/factory.js +0 -1
- package/dist/procedure/types.d.ts +0 -1
- package/dist/procedure/types.js +0 -1
- package/dist/rest/adapter.d.ts +0 -1
- package/dist/rest/adapter.js +0 -1
- package/dist/rest/index.d.ts +0 -1
- package/dist/rest/index.js +0 -1
- package/dist/rest/naming.d.ts +0 -1
- package/dist/rest/naming.js +0 -1
- package/dist/rest/routes.d.ts +0 -1
- package/dist/rest/routes.js +0 -1
- package/dist/trpc/adapter.d.ts +0 -1
- package/dist/trpc/adapter.js +0 -1
- package/dist/trpc/index.d.ts +0 -1
- package/dist/trpc/index.js +0 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -1
- package/dist/warnings.d.ts +0 -1
- package/dist/warnings.js +0 -1
- package/package.json +3 -3
- package/dist/client-types.d.ts.map +0 -1
- package/dist/client-types.js.map +0 -1
- package/dist/contracts.d.ts.map +0 -1
- package/dist/contracts.js.map +0 -1
- package/dist/discovery/errors.d.ts.map +0 -1
- package/dist/discovery/errors.js.map +0 -1
- package/dist/discovery/index.d.ts.map +0 -1
- package/dist/discovery/index.js.map +0 -1
- package/dist/discovery/loader.d.ts.map +0 -1
- package/dist/discovery/loader.js.map +0 -1
- package/dist/discovery/types.d.ts.map +0 -1
- package/dist/discovery/types.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/expose.d.ts.map +0 -1
- package/dist/expose.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/procedure/builder.d.ts.map +0 -1
- package/dist/procedure/builder.js.map +0 -1
- package/dist/procedure/factory.d.ts.map +0 -1
- package/dist/procedure/factory.js.map +0 -1
- package/dist/procedure/types.d.ts.map +0 -1
- package/dist/procedure/types.js.map +0 -1
- package/dist/rest/adapter.d.ts.map +0 -1
- package/dist/rest/adapter.js.map +0 -1
- package/dist/rest/index.d.ts.map +0 -1
- package/dist/rest/index.js.map +0 -1
- package/dist/rest/naming.d.ts.map +0 -1
- package/dist/rest/naming.js.map +0 -1
- package/dist/rest/routes.d.ts.map +0 -1
- package/dist/rest/routes.js.map +0 -1
- package/dist/trpc/adapter.d.ts.map +0 -1
- package/dist/trpc/adapter.js.map +0 -1
- package/dist/trpc/index.d.ts.map +0 -1
- package/dist/trpc/index.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/vite/index.d.ts +0 -70
- package/dist/vite/index.d.ts.map +0 -1
- package/dist/vite/index.js +0 -599
- package/dist/vite/index.js.map +0 -1
- package/dist/warnings.d.ts.map +0 -1
- package/dist/warnings.js.map +0 -1
package/dist/vite/index.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vite Plugin for VeloxTS Router
|
|
3
|
-
*
|
|
4
|
-
* Provides browser-compatible stubs for Node.js built-in modules.
|
|
5
|
-
* This is necessary because Vite scans the entire import graph during
|
|
6
|
-
* development and production builds, including type-only imports that
|
|
7
|
-
* lead to @veloxts packages using Node.js modules.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* // vite.config.ts
|
|
12
|
-
* import { veloxNodeStubs } from '@veloxts/router/vite';
|
|
13
|
-
*
|
|
14
|
-
* export default defineConfig({
|
|
15
|
-
* plugins: [veloxNodeStubs(), react()],
|
|
16
|
-
* });
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @module @veloxts/router/vite
|
|
20
|
-
*/
|
|
21
|
-
import type { Plugin } from 'vite';
|
|
22
|
-
/**
|
|
23
|
-
* Vite plugin that stubs Node.js built-in modules for browser builds.
|
|
24
|
-
*
|
|
25
|
-
* When the frontend imports types from the API (e.g., AppRouter), Vite follows
|
|
26
|
-
* the import chain and encounters Node.js modules from @veloxts/* packages.
|
|
27
|
-
* This plugin provides empty stubs so the build completes.
|
|
28
|
-
*
|
|
29
|
-
* **How it works:**
|
|
30
|
-
*
|
|
31
|
-
* 1. **Pre-bundling phase (esbuild):** Configures `optimizeDeps.esbuildOptions.plugins`
|
|
32
|
-
* to intercept Node.js built-in imports during dependency optimization.
|
|
33
|
-
* This also allows @veloxts/* packages to be pre-bundled normally, which
|
|
34
|
-
* converts their CommonJS dependencies (fastify-plugin, pino, etc.) to ESM.
|
|
35
|
-
*
|
|
36
|
-
* 2. **Application code (Vite/Rollup):** Uses `resolveId` and `load` hooks to
|
|
37
|
-
* provide virtual modules for any Node.js imports in application code.
|
|
38
|
-
*
|
|
39
|
-
* 3. **Resolve aliases:** Configures `resolve.alias` to intercept Node.js builtins
|
|
40
|
-
* before Vite's normal resolution, ensuring stubs are used consistently.
|
|
41
|
-
*
|
|
42
|
-
* **Important:** These stubs never execute in the browser - they only exist to
|
|
43
|
-
* satisfy Vite/Rollup's bundle analysis. The actual code paths using these
|
|
44
|
-
* modules are server-only.
|
|
45
|
-
*
|
|
46
|
-
* **Note:** We intentionally allow Vite to pre-bundle @veloxts/* packages.
|
|
47
|
-
* This is critical because it allows Vite to convert CommonJS dependencies
|
|
48
|
-
* to ESM format. Previously, excluding @veloxts/* from pre-bundling caused
|
|
49
|
-
* a "whack-a-mole" problem where each CJS package (dotenv, fastify-plugin,
|
|
50
|
-
* picocolors, etc.) needed manual ESM stubs.
|
|
51
|
-
*
|
|
52
|
-
* @returns Vite plugin configuration
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* import { veloxNodeStubs } from '@veloxts/router/vite';
|
|
57
|
-
* import react from '@vitejs/plugin-react';
|
|
58
|
-
* import { defineConfig } from 'vite';
|
|
59
|
-
*
|
|
60
|
-
* export default defineConfig({
|
|
61
|
-
* plugins: [
|
|
62
|
-
* veloxNodeStubs(), // Must be first
|
|
63
|
-
* react(),
|
|
64
|
-
* ],
|
|
65
|
-
* });
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
export declare function veloxNodeStubs(): Plugin;
|
|
69
|
-
export { veloxNodeStubs as nodeStubs };
|
|
70
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/vite/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAyd/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAmFvC;AAGD,OAAO,EAAE,cAAc,IAAI,SAAS,EAAE,CAAC"}
|
package/dist/vite/index.js
DELETED
|
@@ -1,599 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vite Plugin for VeloxTS Router
|
|
3
|
-
*
|
|
4
|
-
* Provides browser-compatible stubs for Node.js built-in modules.
|
|
5
|
-
* This is necessary because Vite scans the entire import graph during
|
|
6
|
-
* development and production builds, including type-only imports that
|
|
7
|
-
* lead to @veloxts packages using Node.js modules.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* // vite.config.ts
|
|
12
|
-
* import { veloxNodeStubs } from '@veloxts/router/vite';
|
|
13
|
-
*
|
|
14
|
-
* export default defineConfig({
|
|
15
|
-
* plugins: [veloxNodeStubs(), react()],
|
|
16
|
-
* });
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @module @veloxts/router/vite
|
|
20
|
-
*/
|
|
21
|
-
// ============================================================================
|
|
22
|
-
// Stub Definitions
|
|
23
|
-
// ============================================================================
|
|
24
|
-
/**
|
|
25
|
-
* Stub implementations for Node.js built-in modules.
|
|
26
|
-
*
|
|
27
|
-
* These minimal stubs satisfy module resolution during Vite's bundle analysis.
|
|
28
|
-
* They never execute in the browser - the actual code paths using these modules
|
|
29
|
-
* are server-only and tree-shaken away.
|
|
30
|
-
*
|
|
31
|
-
* Note: Only Node.js built-ins need stubs here. NPM packages (fastify, pino, etc.)
|
|
32
|
-
* are handled by Vite's pre-bundling which automatically converts CJS to ESM.
|
|
33
|
-
*/
|
|
34
|
-
const NODE_STUBS = {
|
|
35
|
-
// =========================================================================
|
|
36
|
-
// NPM packages that execute at import time and crash in browser
|
|
37
|
-
// These need stubs because they run code that accesses Node.js globals
|
|
38
|
-
// =========================================================================
|
|
39
|
-
dotenv: `
|
|
40
|
-
export const config = () => ({ parsed: {} });
|
|
41
|
-
export const configDotenv = () => ({ parsed: {} });
|
|
42
|
-
export const parse = () => ({});
|
|
43
|
-
export const populate = () => {};
|
|
44
|
-
export default { config, configDotenv, parse, populate };
|
|
45
|
-
`,
|
|
46
|
-
'dotenv/config': `
|
|
47
|
-
export {};
|
|
48
|
-
`,
|
|
49
|
-
// =========================================================================
|
|
50
|
-
// Fastify ecosystem - server-only packages that should never run in browser
|
|
51
|
-
// These packages are pulled in via typeof import() chains from @veloxts/velox
|
|
52
|
-
// =========================================================================
|
|
53
|
-
fastify: `
|
|
54
|
-
const fastify = () => ({
|
|
55
|
-
register: () => Promise.resolve(),
|
|
56
|
-
get: () => {},
|
|
57
|
-
post: () => {},
|
|
58
|
-
put: () => {},
|
|
59
|
-
delete: () => {},
|
|
60
|
-
patch: () => {},
|
|
61
|
-
listen: () => Promise.resolve(),
|
|
62
|
-
ready: () => Promise.resolve(),
|
|
63
|
-
close: () => Promise.resolve(),
|
|
64
|
-
});
|
|
65
|
-
fastify.fastify = fastify;
|
|
66
|
-
export default fastify;
|
|
67
|
-
export { fastify };
|
|
68
|
-
`,
|
|
69
|
-
avvio: `
|
|
70
|
-
export default function avvio() { return { use: () => {}, ready: () => Promise.resolve(), close: () => Promise.resolve() }; }
|
|
71
|
-
`,
|
|
72
|
-
'fast-json-stringify': `
|
|
73
|
-
export default function build() { return () => '{}'; }
|
|
74
|
-
`,
|
|
75
|
-
'find-my-way': `
|
|
76
|
-
export default function Router() { return { on: () => {}, lookup: () => {}, find: () => null }; }
|
|
77
|
-
`,
|
|
78
|
-
'@fastify/error': `
|
|
79
|
-
export default function createError() { return class extends Error {}; }
|
|
80
|
-
`,
|
|
81
|
-
'light-my-request': `
|
|
82
|
-
export const inject = () => Promise.resolve({});
|
|
83
|
-
export default { inject };
|
|
84
|
-
`,
|
|
85
|
-
pino: `
|
|
86
|
-
const logger = { info: () => {}, error: () => {}, warn: () => {}, debug: () => {}, trace: () => {}, fatal: () => {}, child: () => logger };
|
|
87
|
-
export default () => logger;
|
|
88
|
-
export const pino = () => logger;
|
|
89
|
-
`,
|
|
90
|
-
'pino-pretty': `
|
|
91
|
-
export default () => ({ write: () => {} });
|
|
92
|
-
`,
|
|
93
|
-
'abstract-logging': `
|
|
94
|
-
export default { info: () => {}, error: () => {}, warn: () => {}, debug: () => {}, trace: () => {}, fatal: () => {} };
|
|
95
|
-
`,
|
|
96
|
-
'sonic-boom': `
|
|
97
|
-
export default class SonicBoom { write() {} end() {} destroy() {} }
|
|
98
|
-
`,
|
|
99
|
-
'thread-stream': `
|
|
100
|
-
export default class ThreadStream { write() {} end() {} destroy() {} }
|
|
101
|
-
`,
|
|
102
|
-
'process-warning': `
|
|
103
|
-
export default function processWarning() { return { create: () => () => {}, emit: () => {} }; }
|
|
104
|
-
`,
|
|
105
|
-
rfdc: `
|
|
106
|
-
export default function rfdc() { return (obj) => JSON.parse(JSON.stringify(obj)); }
|
|
107
|
-
`,
|
|
108
|
-
// =========================================================================
|
|
109
|
-
// Node.js built-in modules (prefixed versions: node:*)
|
|
110
|
-
// =========================================================================
|
|
111
|
-
'node:util': `
|
|
112
|
-
export const promisify = (fn) => fn;
|
|
113
|
-
export const deprecate = (fn) => fn;
|
|
114
|
-
export const inspect = () => '';
|
|
115
|
-
export const format = (...args) => args.join(' ');
|
|
116
|
-
export const inherits = () => {};
|
|
117
|
-
export const isDeepStrictEqual = () => false;
|
|
118
|
-
export const debuglog = () => () => {};
|
|
119
|
-
export const types = { isPromise: () => false, isAsyncFunction: () => false };
|
|
120
|
-
export default { promisify, deprecate, inspect, format, inherits, isDeepStrictEqual, debuglog, types };
|
|
121
|
-
`,
|
|
122
|
-
'node:crypto': `
|
|
123
|
-
export const randomBytes = (size) => new Uint8Array(size || 0);
|
|
124
|
-
export const scrypt = (password, salt, keylen, options, callback) => {
|
|
125
|
-
if (typeof options === 'function') callback = options;
|
|
126
|
-
if (callback) callback(null, new Uint8Array(keylen));
|
|
127
|
-
};
|
|
128
|
-
export const timingSafeEqual = () => true;
|
|
129
|
-
export const createHmac = () => ({ update: () => ({ digest: () => "" }) });
|
|
130
|
-
export const createHash = () => ({ update: () => ({ digest: () => "" }) });
|
|
131
|
-
export const randomUUID = () => 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
132
|
-
const r = Math.random() * 16 | 0;
|
|
133
|
-
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
|
|
134
|
-
});
|
|
135
|
-
export default { randomBytes, scrypt, timingSafeEqual, createHmac, createHash, randomUUID };
|
|
136
|
-
`,
|
|
137
|
-
'node:module': `
|
|
138
|
-
export const createRequire = () => () => ({});
|
|
139
|
-
export const builtinModules = [];
|
|
140
|
-
export default { createRequire, builtinModules };
|
|
141
|
-
`,
|
|
142
|
-
'node:fs': `
|
|
143
|
-
export const readFileSync = () => "";
|
|
144
|
-
export const writeFileSync = () => {};
|
|
145
|
-
export const existsSync = () => false;
|
|
146
|
-
export const mkdirSync = () => {};
|
|
147
|
-
export const readdirSync = () => [];
|
|
148
|
-
export const statSync = () => ({ isFile: () => false, isDirectory: () => false });
|
|
149
|
-
export const promises = {
|
|
150
|
-
readFile: async () => "",
|
|
151
|
-
writeFile: async () => {},
|
|
152
|
-
mkdir: async () => {},
|
|
153
|
-
readdir: async () => [],
|
|
154
|
-
stat: async () => ({ isFile: () => false, isDirectory: () => false }),
|
|
155
|
-
};
|
|
156
|
-
export default { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync, statSync, promises };
|
|
157
|
-
`,
|
|
158
|
-
'node:fs/promises': `
|
|
159
|
-
export const readFile = async () => "";
|
|
160
|
-
export const writeFile = async () => {};
|
|
161
|
-
export const mkdir = async () => {};
|
|
162
|
-
export const readdir = async () => [];
|
|
163
|
-
export const stat = async () => ({ isFile: () => false, isDirectory: () => false });
|
|
164
|
-
export const access = async () => {};
|
|
165
|
-
export const unlink = async () => {};
|
|
166
|
-
export const rmdir = async () => {};
|
|
167
|
-
export const rm = async () => {};
|
|
168
|
-
export const copyFile = async () => {};
|
|
169
|
-
export const rename = async () => {};
|
|
170
|
-
export default { readFile, writeFile, mkdir, readdir, stat, access, unlink, rmdir, rm, copyFile, rename };
|
|
171
|
-
`,
|
|
172
|
-
'node:path': `
|
|
173
|
-
export const join = (...args) => args.filter(Boolean).join("/").replace(/\\/+/g, "/");
|
|
174
|
-
export const resolve = (...args) => args.filter(Boolean).join("/").replace(/\\/+/g, "/");
|
|
175
|
-
export const dirname = (p) => p ? p.split("/").slice(0, -1).join("/") || "/" : ".";
|
|
176
|
-
export const basename = (p, ext) => { const base = p ? p.split("/").pop() || "" : ""; return ext && base.endsWith(ext) ? base.slice(0, -ext.length) : base; };
|
|
177
|
-
export const extname = (p) => { const base = p ? p.split("/").pop() || "" : ""; const idx = base.lastIndexOf("."); return idx > 0 ? base.slice(idx) : ""; };
|
|
178
|
-
export const parse = (p) => ({ root: "", dir: dirname(p), base: basename(p), ext: extname(p), name: basename(p, extname(p)) });
|
|
179
|
-
export const relative = (from, to) => to;
|
|
180
|
-
export const isAbsolute = (p) => p ? p.startsWith("/") : false;
|
|
181
|
-
export const normalize = (p) => p;
|
|
182
|
-
export const sep = "/";
|
|
183
|
-
export const delimiter = ":";
|
|
184
|
-
export default { join, resolve, dirname, basename, extname, parse, relative, isAbsolute, normalize, sep, delimiter };
|
|
185
|
-
`,
|
|
186
|
-
'node:url': `
|
|
187
|
-
export const fileURLToPath = (u) => typeof u === 'string' ? u.replace('file://', '') : u.pathname || '';
|
|
188
|
-
export const pathToFileURL = (p) => new URL("file://" + p);
|
|
189
|
-
export const URL = globalThis.URL;
|
|
190
|
-
export const URLSearchParams = globalThis.URLSearchParams;
|
|
191
|
-
export default { fileURLToPath, pathToFileURL, URL, URLSearchParams };
|
|
192
|
-
`,
|
|
193
|
-
'node:os': `
|
|
194
|
-
export const homedir = () => "/";
|
|
195
|
-
export const tmpdir = () => "/tmp";
|
|
196
|
-
export const platform = () => "browser";
|
|
197
|
-
export const hostname = () => "localhost";
|
|
198
|
-
export const type = () => "Browser";
|
|
199
|
-
export const arch = () => "wasm";
|
|
200
|
-
export const cpus = () => [];
|
|
201
|
-
export const EOL = "\\n";
|
|
202
|
-
export default { homedir, tmpdir, platform, hostname, type, arch, cpus, EOL };
|
|
203
|
-
`,
|
|
204
|
-
'node:buffer': `
|
|
205
|
-
const BufferImpl = {
|
|
206
|
-
from: (data) => new Uint8Array(typeof data === 'string' ? new TextEncoder().encode(data) : data || 0),
|
|
207
|
-
alloc: (size) => new Uint8Array(size),
|
|
208
|
-
allocUnsafe: (size) => new Uint8Array(size),
|
|
209
|
-
isBuffer: (obj) => obj instanceof Uint8Array,
|
|
210
|
-
concat: (list) => { const total = list.reduce((acc, buf) => acc + buf.length, 0); const result = new Uint8Array(total); let offset = 0; for (const buf of list) { result.set(buf, offset); offset += buf.length; } return result; },
|
|
211
|
-
byteLength: (str) => new TextEncoder().encode(str).length,
|
|
212
|
-
};
|
|
213
|
-
export const Buffer = BufferImpl;
|
|
214
|
-
export default { Buffer: BufferImpl };
|
|
215
|
-
`,
|
|
216
|
-
'node:events': `
|
|
217
|
-
export class EventEmitter {
|
|
218
|
-
constructor() { this._events = {}; }
|
|
219
|
-
on(event, listener) { (this._events[event] = this._events[event] || []).push(listener); return this; }
|
|
220
|
-
off(event, listener) { const arr = this._events[event]; if (arr) { const idx = arr.indexOf(listener); if (idx >= 0) arr.splice(idx, 1); } return this; }
|
|
221
|
-
emit(event, ...args) { const arr = this._events[event]; if (arr) arr.forEach(fn => fn(...args)); return !!arr; }
|
|
222
|
-
once(event, listener) { const wrapped = (...args) => { this.off(event, wrapped); listener(...args); }; return this.on(event, wrapped); }
|
|
223
|
-
addListener(event, listener) { return this.on(event, listener); }
|
|
224
|
-
removeListener(event, listener) { return this.off(event, listener); }
|
|
225
|
-
removeAllListeners(event) { if (event) delete this._events[event]; else this._events = {}; return this; }
|
|
226
|
-
listeners(event) { return this._events[event] || []; }
|
|
227
|
-
listenerCount(event) { return (this._events[event] || []).length; }
|
|
228
|
-
}
|
|
229
|
-
export default EventEmitter;
|
|
230
|
-
`,
|
|
231
|
-
'node:stream': `
|
|
232
|
-
export class Readable { pipe() { return this; } on() { return this; } }
|
|
233
|
-
export class Writable { write() { return true; } end() {} on() { return this; } }
|
|
234
|
-
export class Transform extends Writable { pipe() { return this; } }
|
|
235
|
-
export class Duplex extends Writable { pipe() { return this; } }
|
|
236
|
-
export class PassThrough extends Transform {}
|
|
237
|
-
export const pipeline = (...args) => { const cb = args[args.length - 1]; if (typeof cb === 'function') cb(null); };
|
|
238
|
-
export const finished = (stream, cb) => { if (typeof cb === 'function') cb(null); };
|
|
239
|
-
export default { Readable, Writable, Transform, Duplex, PassThrough, pipeline, finished };
|
|
240
|
-
`,
|
|
241
|
-
'node:http': `
|
|
242
|
-
export const createServer = () => ({ listen: () => {}, close: () => {}, on: () => {} });
|
|
243
|
-
export const request = () => ({ on: () => {}, write: () => {}, end: () => {} });
|
|
244
|
-
export const get = () => ({ on: () => {} });
|
|
245
|
-
export class Agent {}
|
|
246
|
-
export const STATUS_CODES = { 200: 'OK', 404: 'Not Found', 500: 'Internal Server Error' };
|
|
247
|
-
export const METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
|
|
248
|
-
export default { createServer, request, get, Agent, STATUS_CODES, METHODS };
|
|
249
|
-
`,
|
|
250
|
-
'node:https': `
|
|
251
|
-
export const createServer = () => ({ listen: () => {}, close: () => {}, on: () => {} });
|
|
252
|
-
export const request = () => ({ on: () => {}, write: () => {}, end: () => {} });
|
|
253
|
-
export const get = () => ({ on: () => {} });
|
|
254
|
-
export class Agent {}
|
|
255
|
-
export default { createServer, request, get, Agent };
|
|
256
|
-
`,
|
|
257
|
-
'node:net': `
|
|
258
|
-
export const createServer = () => ({ listen: () => {}, close: () => {}, on: () => {} });
|
|
259
|
-
export const createConnection = () => ({ on: () => {}, write: () => {}, end: () => {} });
|
|
260
|
-
export const connect = createConnection;
|
|
261
|
-
export class Socket { on() { return this; } write() { return true; } end() {} destroy() {} }
|
|
262
|
-
export const isIP = () => 0;
|
|
263
|
-
export const isIPv4 = () => false;
|
|
264
|
-
export const isIPv6 = () => false;
|
|
265
|
-
export default { createServer, createConnection, connect, Socket, isIP, isIPv4, isIPv6 };
|
|
266
|
-
`,
|
|
267
|
-
'node:async_hooks': `
|
|
268
|
-
export const createHook = () => ({ enable: () => {}, disable: () => {} });
|
|
269
|
-
export const executionAsyncId = () => 0;
|
|
270
|
-
export const triggerAsyncId = () => 0;
|
|
271
|
-
export class AsyncResource { runInAsyncScope(fn, thisArg, ...args) { return fn.apply(thisArg, args); } }
|
|
272
|
-
export class AsyncLocalStorage { getStore() { return undefined; } run(store, fn, ...args) { return fn(...args); } enterWith() {} disable() {} }
|
|
273
|
-
export default { createHook, executionAsyncId, triggerAsyncId, AsyncResource, AsyncLocalStorage };
|
|
274
|
-
`,
|
|
275
|
-
'node:assert': `
|
|
276
|
-
const assert = (value, message) => { if (!value) throw new Error(message || 'Assertion failed'); };
|
|
277
|
-
assert.ok = assert;
|
|
278
|
-
assert.equal = (a, b, msg) => { if (a != b) throw new Error(msg || 'Not equal'); };
|
|
279
|
-
assert.strictEqual = (a, b, msg) => { if (a !== b) throw new Error(msg || 'Not strictly equal'); };
|
|
280
|
-
assert.deepEqual = () => {};
|
|
281
|
-
assert.deepStrictEqual = () => {};
|
|
282
|
-
assert.notEqual = (a, b, msg) => { if (a == b) throw new Error(msg || 'Equal'); };
|
|
283
|
-
assert.notStrictEqual = (a, b, msg) => { if (a === b) throw new Error(msg || 'Strictly equal'); };
|
|
284
|
-
assert.throws = (fn, expected, msg) => { try { fn(); throw new Error(msg || 'Did not throw'); } catch {} };
|
|
285
|
-
assert.doesNotThrow = (fn) => { fn(); };
|
|
286
|
-
assert.fail = (msg) => { throw new Error(msg || 'Failed'); };
|
|
287
|
-
export default assert;
|
|
288
|
-
export { assert };
|
|
289
|
-
`,
|
|
290
|
-
'node:diagnostics_channel': `
|
|
291
|
-
export const channel = (name) => ({ name, subscribe: () => {}, unsubscribe: () => {}, publish: () => {}, hasSubscribers: false });
|
|
292
|
-
export const hasSubscribers = () => false;
|
|
293
|
-
export const subscribe = () => {};
|
|
294
|
-
export const unsubscribe = () => {};
|
|
295
|
-
export class Channel { constructor(name) { this.name = name; } subscribe() {} unsubscribe() {} publish() {} hasSubscribers = false; }
|
|
296
|
-
export default { channel, hasSubscribers, subscribe, unsubscribe, Channel };
|
|
297
|
-
`,
|
|
298
|
-
'node:http2': `
|
|
299
|
-
export const createServer = () => ({ listen: () => {}, close: () => {}, on: () => {} });
|
|
300
|
-
export const createSecureServer = () => ({ listen: () => {}, close: () => {}, on: () => {} });
|
|
301
|
-
export const connect = () => ({ on: () => {}, request: () => ({ on: () => {} }) });
|
|
302
|
-
export const constants = {};
|
|
303
|
-
export default { createServer, createSecureServer, connect, constants };
|
|
304
|
-
`,
|
|
305
|
-
'node:dns': `
|
|
306
|
-
export const lookup = (hostname, opts, cb) => { if (typeof opts === 'function') cb = opts; if (cb) cb(null, '127.0.0.1', 4); };
|
|
307
|
-
export const resolve = (hostname, rrtype, cb) => { if (typeof rrtype === 'function') cb = rrtype; if (cb) cb(null, []); };
|
|
308
|
-
export const promises = { lookup: async () => ({ address: '127.0.0.1', family: 4 }), resolve: async () => [] };
|
|
309
|
-
export default { lookup, resolve, promises };
|
|
310
|
-
`,
|
|
311
|
-
'node:string_decoder': `
|
|
312
|
-
export class StringDecoder {
|
|
313
|
-
constructor(encoding) { this.encoding = encoding || 'utf8'; }
|
|
314
|
-
write(buffer) { return new TextDecoder(this.encoding).decode(buffer); }
|
|
315
|
-
end(buffer) { return buffer ? this.write(buffer) : ''; }
|
|
316
|
-
}
|
|
317
|
-
export default { StringDecoder };
|
|
318
|
-
`,
|
|
319
|
-
'node:zlib': `
|
|
320
|
-
export const gzip = (buf, cb) => { if (cb) cb(null, buf); };
|
|
321
|
-
export const gunzip = (buf, cb) => { if (cb) cb(null, buf); };
|
|
322
|
-
export const deflate = (buf, cb) => { if (cb) cb(null, buf); };
|
|
323
|
-
export const inflate = (buf, cb) => { if (cb) cb(null, buf); };
|
|
324
|
-
export const createGzip = () => ({ on: () => {}, write: () => {}, end: () => {} });
|
|
325
|
-
export const createGunzip = () => ({ on: () => {}, write: () => {}, end: () => {} });
|
|
326
|
-
export default { gzip, gunzip, deflate, inflate, createGzip, createGunzip };
|
|
327
|
-
`,
|
|
328
|
-
'node:querystring': `
|
|
329
|
-
export const parse = (str) => Object.fromEntries(new URLSearchParams(str));
|
|
330
|
-
export const stringify = (obj) => new URLSearchParams(obj).toString();
|
|
331
|
-
export const encode = stringify;
|
|
332
|
-
export const decode = parse;
|
|
333
|
-
export default { parse, stringify, encode, decode };
|
|
334
|
-
`,
|
|
335
|
-
'node:child_process': `
|
|
336
|
-
export const spawn = () => ({ on: () => {}, stdout: { on: () => {} }, stderr: { on: () => {} }, kill: () => {} });
|
|
337
|
-
export const exec = (cmd, opts, cb) => { if (typeof opts === 'function') cb = opts; if (cb) cb(new Error('Not supported in browser')); };
|
|
338
|
-
export const execSync = () => { throw new Error('Not supported in browser'); };
|
|
339
|
-
export const fork = () => ({ on: () => {}, send: () => {} });
|
|
340
|
-
export default { spawn, exec, execSync, fork };
|
|
341
|
-
`,
|
|
342
|
-
'node:worker_threads': `
|
|
343
|
-
export const isMainThread = true;
|
|
344
|
-
export const parentPort = null;
|
|
345
|
-
export const workerData = null;
|
|
346
|
-
export class Worker { constructor() { throw new Error('Workers not supported in browser stub'); } }
|
|
347
|
-
export class MessageChannel { constructor() { this.port1 = {}; this.port2 = {}; } }
|
|
348
|
-
export default { isMainThread, parentPort, workerData, Worker, MessageChannel };
|
|
349
|
-
`,
|
|
350
|
-
'node:tty': `
|
|
351
|
-
export const isatty = () => false;
|
|
352
|
-
export class ReadStream {}
|
|
353
|
-
export class WriteStream { get isTTY() { return false; } }
|
|
354
|
-
export default { isatty, ReadStream, WriteStream };
|
|
355
|
-
`,
|
|
356
|
-
'node:readline': `
|
|
357
|
-
export const createInterface = () => ({ on: () => {}, close: () => {}, question: (q, cb) => cb('') });
|
|
358
|
-
export default { createInterface };
|
|
359
|
-
`,
|
|
360
|
-
'node:perf_hooks': `
|
|
361
|
-
export const performance = globalThis.performance || { now: () => Date.now() };
|
|
362
|
-
export class PerformanceObserver { observe() {} disconnect() {} }
|
|
363
|
-
export default { performance, PerformanceObserver };
|
|
364
|
-
`,
|
|
365
|
-
'node:process': `
|
|
366
|
-
const proc = {
|
|
367
|
-
env: {},
|
|
368
|
-
cwd: () => '/',
|
|
369
|
-
chdir: () => {},
|
|
370
|
-
exit: () => {},
|
|
371
|
-
pid: 1,
|
|
372
|
-
platform: 'browser',
|
|
373
|
-
version: 'v0.0.0',
|
|
374
|
-
versions: {},
|
|
375
|
-
argv: [],
|
|
376
|
-
execPath: '',
|
|
377
|
-
on: () => proc,
|
|
378
|
-
off: () => proc,
|
|
379
|
-
emit: () => false,
|
|
380
|
-
nextTick: (fn, ...args) => queueMicrotask(() => fn(...args)),
|
|
381
|
-
stdout: { write: () => true, isTTY: false },
|
|
382
|
-
stderr: { write: () => true, isTTY: false },
|
|
383
|
-
stdin: { on: () => {}, isTTY: false },
|
|
384
|
-
};
|
|
385
|
-
export default proc;
|
|
386
|
-
export const env = proc.env;
|
|
387
|
-
export const cwd = proc.cwd;
|
|
388
|
-
export const platform = proc.platform;
|
|
389
|
-
export const argv = proc.argv;
|
|
390
|
-
export const exit = proc.exit;
|
|
391
|
-
export const nextTick = proc.nextTick;
|
|
392
|
-
`,
|
|
393
|
-
};
|
|
394
|
-
/**
|
|
395
|
-
* Get all stubs including non-prefixed versions (e.g., 'util' in addition to 'node:util')
|
|
396
|
-
*/
|
|
397
|
-
function getAllStubs() {
|
|
398
|
-
const nonPrefixedStubs = {};
|
|
399
|
-
for (const key of Object.keys(NODE_STUBS)) {
|
|
400
|
-
if (key.startsWith('node:')) {
|
|
401
|
-
// Create non-prefixed version: node:fs -> fs, node:fs/promises -> fs/promises
|
|
402
|
-
nonPrefixedStubs[key.replace('node:', '')] = NODE_STUBS[key];
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
return { ...NODE_STUBS, ...nonPrefixedStubs };
|
|
406
|
-
}
|
|
407
|
-
// ============================================================================
|
|
408
|
-
// esbuild Plugin for Pre-bundling
|
|
409
|
-
// ============================================================================
|
|
410
|
-
/**
|
|
411
|
-
* Creates an esbuild plugin configuration object for Vite's optimizeDeps.
|
|
412
|
-
* This is used during Vite's pre-bundling phase to stub Node.js built-ins.
|
|
413
|
-
*/
|
|
414
|
-
function createEsbuildNodeStubsPlugin() {
|
|
415
|
-
const allStubs = getAllStubs();
|
|
416
|
-
return {
|
|
417
|
-
name: 'velox-esbuild-node-stubs',
|
|
418
|
-
setup(build) {
|
|
419
|
-
// Match all Node.js built-in module patterns, including subpaths like fs/promises
|
|
420
|
-
// This regex matches: node:fs, fs, node:fs/promises, fs/promises, etc.
|
|
421
|
-
const nodeBuiltinFilter = /^(node:)?(util|crypto|module|fs|path|url|os|buffer|events|stream|http|https|net|async_hooks|assert|diagnostics_channel|http2|dns|string_decoder|zlib|querystring|child_process|worker_threads|tty|readline|perf_hooks|process)(\/.*)?$/;
|
|
422
|
-
// Match packages that should never run in browser
|
|
423
|
-
// - dotenv: executes at import time, crashes on process.argv
|
|
424
|
-
// - Fastify ecosystem: server-only, crashes on Node.js APIs
|
|
425
|
-
const serverPackagesFilter = /^(dotenv|fastify|avvio|fast-json-stringify|find-my-way|@fastify\/error|light-my-request|pino|pino-pretty|abstract-logging|sonic-boom|thread-stream|process-warning|rfdc)(\/.*)?$/;
|
|
426
|
-
build.onResolve({ filter: serverPackagesFilter }, (args) => {
|
|
427
|
-
// Check if we have a stub for this package
|
|
428
|
-
if (args.path in allStubs) {
|
|
429
|
-
return {
|
|
430
|
-
path: args.path,
|
|
431
|
-
namespace: 'velox-node-stubs',
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
return null;
|
|
435
|
-
});
|
|
436
|
-
build.onResolve({ filter: nodeBuiltinFilter }, (args) => {
|
|
437
|
-
// Normalize to node: prefixed form for lookup
|
|
438
|
-
const moduleName = args.path.startsWith('node:') ? args.path : `node:${args.path}`;
|
|
439
|
-
if (moduleName in allStubs || args.path in allStubs) {
|
|
440
|
-
return {
|
|
441
|
-
path: moduleName, // Always use node: prefixed form
|
|
442
|
-
namespace: 'velox-node-stubs',
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
return null;
|
|
446
|
-
});
|
|
447
|
-
// Also intercept velox-virtual: paths that may come from Vite's alias resolution
|
|
448
|
-
build.onResolve({ filter: /^(\x00)?velox-virtual:/ }, (args) => {
|
|
449
|
-
// Strip the velox-virtual: prefix to get the original module name
|
|
450
|
-
const moduleName = args.path.replace(/^(\x00)?velox-virtual:/, '');
|
|
451
|
-
if (moduleName in allStubs) {
|
|
452
|
-
return {
|
|
453
|
-
path: moduleName,
|
|
454
|
-
namespace: 'velox-node-stubs',
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
return null;
|
|
458
|
-
});
|
|
459
|
-
build.onLoad({ filter: /.*/, namespace: 'velox-node-stubs' }, (args) => {
|
|
460
|
-
// Try exact match, then with node: prefix, then without
|
|
461
|
-
const content = allStubs[args.path] ??
|
|
462
|
-
allStubs[`node:${args.path}`] ??
|
|
463
|
-
allStubs[args.path.replace('node:', '')] ??
|
|
464
|
-
'export default {};';
|
|
465
|
-
return {
|
|
466
|
-
contents: content,
|
|
467
|
-
loader: 'js',
|
|
468
|
-
};
|
|
469
|
-
});
|
|
470
|
-
},
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
// ============================================================================
|
|
474
|
-
// Main Vite Plugin
|
|
475
|
-
// ============================================================================
|
|
476
|
-
/**
|
|
477
|
-
* Vite plugin that stubs Node.js built-in modules for browser builds.
|
|
478
|
-
*
|
|
479
|
-
* When the frontend imports types from the API (e.g., AppRouter), Vite follows
|
|
480
|
-
* the import chain and encounters Node.js modules from @veloxts/* packages.
|
|
481
|
-
* This plugin provides empty stubs so the build completes.
|
|
482
|
-
*
|
|
483
|
-
* **How it works:**
|
|
484
|
-
*
|
|
485
|
-
* 1. **Pre-bundling phase (esbuild):** Configures `optimizeDeps.esbuildOptions.plugins`
|
|
486
|
-
* to intercept Node.js built-in imports during dependency optimization.
|
|
487
|
-
* This also allows @veloxts/* packages to be pre-bundled normally, which
|
|
488
|
-
* converts their CommonJS dependencies (fastify-plugin, pino, etc.) to ESM.
|
|
489
|
-
*
|
|
490
|
-
* 2. **Application code (Vite/Rollup):** Uses `resolveId` and `load` hooks to
|
|
491
|
-
* provide virtual modules for any Node.js imports in application code.
|
|
492
|
-
*
|
|
493
|
-
* 3. **Resolve aliases:** Configures `resolve.alias` to intercept Node.js builtins
|
|
494
|
-
* before Vite's normal resolution, ensuring stubs are used consistently.
|
|
495
|
-
*
|
|
496
|
-
* **Important:** These stubs never execute in the browser - they only exist to
|
|
497
|
-
* satisfy Vite/Rollup's bundle analysis. The actual code paths using these
|
|
498
|
-
* modules are server-only.
|
|
499
|
-
*
|
|
500
|
-
* **Note:** We intentionally allow Vite to pre-bundle @veloxts/* packages.
|
|
501
|
-
* This is critical because it allows Vite to convert CommonJS dependencies
|
|
502
|
-
* to ESM format. Previously, excluding @veloxts/* from pre-bundling caused
|
|
503
|
-
* a "whack-a-mole" problem where each CJS package (dotenv, fastify-plugin,
|
|
504
|
-
* picocolors, etc.) needed manual ESM stubs.
|
|
505
|
-
*
|
|
506
|
-
* @returns Vite plugin configuration
|
|
507
|
-
*
|
|
508
|
-
* @example
|
|
509
|
-
* ```typescript
|
|
510
|
-
* import { veloxNodeStubs } from '@veloxts/router/vite';
|
|
511
|
-
* import react from '@vitejs/plugin-react';
|
|
512
|
-
* import { defineConfig } from 'vite';
|
|
513
|
-
*
|
|
514
|
-
* export default defineConfig({
|
|
515
|
-
* plugins: [
|
|
516
|
-
* veloxNodeStubs(), // Must be first
|
|
517
|
-
* react(),
|
|
518
|
-
* ],
|
|
519
|
-
* });
|
|
520
|
-
* ```
|
|
521
|
-
*/
|
|
522
|
-
export function veloxNodeStubs() {
|
|
523
|
-
const allStubs = getAllStubs();
|
|
524
|
-
return {
|
|
525
|
-
name: 'velox-node-stubs',
|
|
526
|
-
enforce: 'pre',
|
|
527
|
-
config(config, { command }) {
|
|
528
|
-
// Only apply browser stubs for client builds, not SSR
|
|
529
|
-
const isSsr = config.build?.ssr === true;
|
|
530
|
-
if (isSsr) {
|
|
531
|
-
return {};
|
|
532
|
-
}
|
|
533
|
-
// Build the resolve.alias configuration
|
|
534
|
-
// This ensures Node.js builtins are replaced with our stubs BEFORE
|
|
535
|
-
// Vite's externalization logic kicks in
|
|
536
|
-
const aliasEntries = {};
|
|
537
|
-
for (const moduleName of Object.keys(allStubs)) {
|
|
538
|
-
aliasEntries[moduleName] = `\0velox-virtual:${moduleName}`;
|
|
539
|
-
}
|
|
540
|
-
return {
|
|
541
|
-
// Define process.env for browser - Vite handles most cases but we ensure it exists
|
|
542
|
-
define: {
|
|
543
|
-
'process.env': '{}',
|
|
544
|
-
},
|
|
545
|
-
// Use resolve.alias to intercept Node.js builtins BEFORE externalization
|
|
546
|
-
// This is more reliable than resolveId for pre-bundled dependencies
|
|
547
|
-
resolve: {
|
|
548
|
-
alias: aliasEntries,
|
|
549
|
-
},
|
|
550
|
-
// Configure dependency optimization (pre-bundling)
|
|
551
|
-
optimizeDeps: {
|
|
552
|
-
// IMPORTANT: Do NOT exclude @veloxts/* packages from pre-bundling!
|
|
553
|
-
//
|
|
554
|
-
// Why? Pre-bundling serves two critical purposes:
|
|
555
|
-
// 1. Converts CommonJS dependencies to ESM (picocolors, fastify-plugin, etc.)
|
|
556
|
-
// 2. Allows our esbuild plugin to stub Node.js built-ins
|
|
557
|
-
//
|
|
558
|
-
// If we exclude @veloxts/*, their CJS dependencies are served as-is,
|
|
559
|
-
// causing "does not provide an export named 'default'" errors.
|
|
560
|
-
//
|
|
561
|
-
// The esbuild plugin handles Node.js built-ins during pre-bundling,
|
|
562
|
-
// while resolve.alias handles them during Vite's resolution phase.
|
|
563
|
-
esbuildOptions: {
|
|
564
|
-
plugins: [createEsbuildNodeStubsPlugin()],
|
|
565
|
-
},
|
|
566
|
-
},
|
|
567
|
-
// Configure SSR settings to prevent Node.js module issues
|
|
568
|
-
// When not in SSR mode, ensure Node.js builtins are not externalized
|
|
569
|
-
ssr: {
|
|
570
|
-
// In browser builds, we want to bundle (and stub) these modules
|
|
571
|
-
// rather than externalizing them
|
|
572
|
-
noExternal: command === 'build' ? [] : undefined,
|
|
573
|
-
},
|
|
574
|
-
};
|
|
575
|
-
},
|
|
576
|
-
resolveId(id) {
|
|
577
|
-
// Handle virtual module resolution
|
|
578
|
-
// Also intercept direct Node.js builtin imports as a fallback
|
|
579
|
-
if (id in allStubs) {
|
|
580
|
-
return `\0velox-virtual:${id}`;
|
|
581
|
-
}
|
|
582
|
-
// Handle the virtual module prefix from resolve.alias
|
|
583
|
-
if (id.startsWith('\0velox-virtual:')) {
|
|
584
|
-
return id;
|
|
585
|
-
}
|
|
586
|
-
return null;
|
|
587
|
-
},
|
|
588
|
-
load(id) {
|
|
589
|
-
if (id.startsWith('\0velox-virtual:')) {
|
|
590
|
-
const moduleName = id.replace('\0velox-virtual:', '');
|
|
591
|
-
return allStubs[moduleName] ?? 'export default {};';
|
|
592
|
-
}
|
|
593
|
-
return null;
|
|
594
|
-
},
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
// Re-export for convenience
|
|
598
|
-
export { veloxNodeStubs as nodeStubs };
|
|
599
|
-
//# sourceMappingURL=index.js.map
|