elit 3.2.4 → 3.2.6

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.
@@ -13,6 +13,7 @@ declare class Database {
13
13
  private _registerModules;
14
14
  private _config;
15
15
  constructor(config: DatabaseConfig);
16
+ private _initTranspiler;
16
17
  set config(config: DatabaseConfig);
17
18
  private register;
18
19
  plugin(moduleName: string, moduleContent: any): void;
@@ -12,6 +12,7 @@ export declare class Database {
12
12
  private _registerModules;
13
13
  private _config;
14
14
  constructor(config: DatabaseConfig);
15
+ private _initTranspiler;
15
16
  set config(config: DatabaseConfig);
16
17
  private register;
17
18
  plugin(moduleName: string, moduleContent: any): void;
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAMzB,MAAM,WAAW,cAAc;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,eAAe,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CAC5C;AAED,qBAAa,QAAQ;IACjB,OAAO,CAAC,WAAW,CAAiB;IACpC,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,gBAAgB,CAAyB;IACjD,OAAO,CAAC,OAAO,CAEb;gBAEU,MAAM,EAAE,cAAc;IASlC,IAAI,MAAM,CAAC,MAAM,EAAE,cAAc,EAEhC;IAED,OAAO,CAAC,QAAQ;IAMhB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG;IAI7C,OAAO,CAAC,WAAW;YAwBL,YAAY;YA6BZ,KAAK;IAsInB;;OAEG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,kBAAkB,GAAG,MAAM;;;;C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,QAAQ;IAMhB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG;IAI7C,OAAO,CAAC,WAAW;YAwBL,YAAY;YA6BZ,KAAK;IAwInB;;OAEG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,kBAAkB,GAAG,MAAM;;;;CAIlF;AAkVD,wBAAgB,QAAQ,aAIvB;AAED,MAAM,WAAW,eAAgB,SAAQ,OAAO;IAC5C,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAAC;IACvD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC;IAC5C,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACjD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,GAAG,GAAG,IAAI,CAAC;IAC1D,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,GAAG,CAAC;CACxE;AAED,eAAO,MAAM,SAAS,EAAE,eAQvB,CAAA;AACD,eAAe,QAAQ,CAAC"}
package/dist/database.js CHANGED
@@ -267,7 +267,6 @@ function resolve(...paths) {
267
267
  // src/database.ts
268
268
  var import_node_path = __toESM(require("path"));
269
269
  var import_node_fs = __toESM(require("fs"));
270
- var import_bun = __toESM(require("bun"));
271
270
  var Database = class {
272
271
  constructor(config) {
273
272
  this._config = {
@@ -276,9 +275,33 @@ var Database = class {
276
275
  this._config = { ...this._config, ...config };
277
276
  this._registerModules = config.registerModules || {};
278
277
  this._ctx = import_node_vm.default.createContext(this._registerModules);
279
- this._transpiler = new import_bun.default.Transpiler({
280
- loader: config?.language || "ts"
281
- });
278
+ this._initTranspiler();
279
+ }
280
+ async _initTranspiler() {
281
+ if (!this._transpiler) {
282
+ try {
283
+ const BunModule = await import("bun");
284
+ this._transpiler = new BunModule.default.Transpiler({
285
+ loader: this._config.language || "ts"
286
+ });
287
+ } catch {
288
+ const { buildSync } = await import("esbuild");
289
+ this._transpiler = {
290
+ transformSync: (code) => {
291
+ const result = buildSync({
292
+ stdin: { contents: code },
293
+ loader: this._config.language === "ts" ? "ts" : "js",
294
+ format: "esm",
295
+ platform: "node",
296
+ target: "es2020",
297
+ bundle: false
298
+ });
299
+ return result.outputFiles?.[0]?.text || "";
300
+ }
301
+ };
302
+ }
303
+ }
304
+ return this._transpiler;
282
305
  }
283
306
  set config(config) {
284
307
  this._config = { ...this._config, ...config };
@@ -412,7 +435,8 @@ var Database = class {
412
435
  } else {
413
436
  stringCode = code;
414
437
  }
415
- const js = this._transpiler.transformSync(stringCode);
438
+ const transpiler = await this._initTranspiler();
439
+ const js = transpiler.transformSync(stringCode);
416
440
  const mod = new import_node_vm.default.SourceTextModule(js, { context: this._ctx, identifier: import_node_path.default.join(this._config.dir || resolve(process.cwd(), "databases"), "virtual-entry.js") });
417
441
  await mod.link(this.moduleLinker.bind(this));
418
442
  await mod.evaluate();
package/dist/database.mjs CHANGED
@@ -232,7 +232,6 @@ function resolve(...paths) {
232
232
  // src/database.ts
233
233
  import path from "path";
234
234
  import fs from "fs";
235
- import Bun2 from "bun";
236
235
  var Database = class {
237
236
  constructor(config) {
238
237
  this._config = {
@@ -241,9 +240,33 @@ var Database = class {
241
240
  this._config = { ...this._config, ...config };
242
241
  this._registerModules = config.registerModules || {};
243
242
  this._ctx = vm.createContext(this._registerModules);
244
- this._transpiler = new Bun2.Transpiler({
245
- loader: config?.language || "ts"
246
- });
243
+ this._initTranspiler();
244
+ }
245
+ async _initTranspiler() {
246
+ if (!this._transpiler) {
247
+ try {
248
+ const BunModule = await import("bun");
249
+ this._transpiler = new BunModule.default.Transpiler({
250
+ loader: this._config.language || "ts"
251
+ });
252
+ } catch {
253
+ const { buildSync } = await import("esbuild");
254
+ this._transpiler = {
255
+ transformSync: (code) => {
256
+ const result = buildSync({
257
+ stdin: { contents: code },
258
+ loader: this._config.language === "ts" ? "ts" : "js",
259
+ format: "esm",
260
+ platform: "node",
261
+ target: "es2020",
262
+ bundle: false
263
+ });
264
+ return result.outputFiles?.[0]?.text || "";
265
+ }
266
+ };
267
+ }
268
+ }
269
+ return this._transpiler;
247
270
  }
248
271
  set config(config) {
249
272
  this._config = { ...this._config, ...config };
@@ -377,7 +400,8 @@ var Database = class {
377
400
  } else {
378
401
  stringCode = code;
379
402
  }
380
- const js = this._transpiler.transformSync(stringCode);
403
+ const transpiler = await this._initTranspiler();
404
+ const js = transpiler.transformSync(stringCode);
381
405
  const mod = new vm.SourceTextModule(js, { context: this._ctx, identifier: path.join(this._config.dir || resolve(process.cwd(), "databases"), "virtual-entry.js") });
382
406
  await mod.link(this.moduleLinker.bind(this));
383
407
  await mod.evaluate();
@@ -180,6 +180,38 @@ interface BuildResult {
180
180
  /** Output file size in bytes */
181
181
  size: number;
182
182
  }
183
+ interface PreviewOptions {
184
+ /** Port to run the preview server on (default: 4173) */
185
+ port?: number;
186
+ /** Host to bind to (default: 'localhost') */
187
+ host?: string;
188
+ /** Domain to map (e.g., 'idevcoder.com') - redirects domain traffic to this server's port */
189
+ domain?: string;
190
+ /** Root directory to serve files from (default: dist or build.outDir) */
191
+ root?: string;
192
+ /** Base path for the application (e.g., '/app') */
193
+ basePath?: string;
194
+ /** Custom index file path (relative to root, e.g., './public/index.html') */
195
+ index?: string;
196
+ /** Array of client configurations - allows multiple clients on same port */
197
+ clients?: ClientConfig[];
198
+ /** Enable HTTPS (default: false) */
199
+ https?: boolean;
200
+ /** Open browser automatically (default: true) */
201
+ open?: boolean;
202
+ /** Enable logging (default: true) */
203
+ logging?: boolean;
204
+ /** API router for REST endpoints */
205
+ api?: Router;
206
+ /** SSR render function - returns HTML VNode or string */
207
+ ssr?: () => Child | string;
208
+ /** Proxy configuration for API requests */
209
+ proxy?: ProxyConfig[];
210
+ /** Global worker scripts (applies to all clients) */
211
+ worker?: WorkerConfig[];
212
+ /** Environment variables to inject (prefix with VITE_ for client access) */
213
+ env?: Record<string, string>;
214
+ }
183
215
 
184
216
  /**
185
217
  * Development server with HMR support
@@ -300,4 +332,4 @@ declare class StateManager {
300
332
  }
301
333
  declare function createDevServer(options: DevServerOptions): DevServer;
302
334
 
303
- export { type BuildOptions as B, type ElitRequest as E, type HttpMethod as H, type Middleware as M, type ServerRouteContext as S, type BuildResult as a, type ElitResponse as b, type ServerRouteHandler as c, ServerRouter as d, clearImportMapCache as e, cors as f, errorHandler as g, html as h, bodyLimit as i, json as j, cacheControl as k, logger as l, compress as m, security as n, createProxyHandler as o, type StateChangeHandler as p, type SharedStateOptions as q, rateLimit as r, status as s, text as t, SharedState as u, StateManager as v, createDevServer as w };
335
+ export { type BuildOptions as B, type DevServerOptions as D, type ElitRequest as E, type HttpMethod as H, type Middleware as M, type PreviewOptions as P, type ServerRouteContext as S, type BuildResult as a, type ElitResponse as b, type ServerRouteHandler as c, ServerRouter as d, clearImportMapCache as e, cors as f, errorHandler as g, html as h, bodyLimit as i, json as j, cacheControl as k, logger as l, compress as m, security as n, createProxyHandler as o, type StateChangeHandler as p, type SharedStateOptions as q, rateLimit as r, status as s, text as t, SharedState as u, StateManager as v, createDevServer as w };
@@ -180,6 +180,38 @@ interface BuildResult {
180
180
  /** Output file size in bytes */
181
181
  size: number;
182
182
  }
183
+ interface PreviewOptions {
184
+ /** Port to run the preview server on (default: 4173) */
185
+ port?: number;
186
+ /** Host to bind to (default: 'localhost') */
187
+ host?: string;
188
+ /** Domain to map (e.g., 'idevcoder.com') - redirects domain traffic to this server's port */
189
+ domain?: string;
190
+ /** Root directory to serve files from (default: dist or build.outDir) */
191
+ root?: string;
192
+ /** Base path for the application (e.g., '/app') */
193
+ basePath?: string;
194
+ /** Custom index file path (relative to root, e.g., './public/index.html') */
195
+ index?: string;
196
+ /** Array of client configurations - allows multiple clients on same port */
197
+ clients?: ClientConfig[];
198
+ /** Enable HTTPS (default: false) */
199
+ https?: boolean;
200
+ /** Open browser automatically (default: true) */
201
+ open?: boolean;
202
+ /** Enable logging (default: true) */
203
+ logging?: boolean;
204
+ /** API router for REST endpoints */
205
+ api?: Router;
206
+ /** SSR render function - returns HTML VNode or string */
207
+ ssr?: () => Child | string;
208
+ /** Proxy configuration for API requests */
209
+ proxy?: ProxyConfig[];
210
+ /** Global worker scripts (applies to all clients) */
211
+ worker?: WorkerConfig[];
212
+ /** Environment variables to inject (prefix with VITE_ for client access) */
213
+ env?: Record<string, string>;
214
+ }
183
215
 
184
216
  /**
185
217
  * Development server with HMR support
@@ -300,4 +332,4 @@ declare class StateManager {
300
332
  }
301
333
  declare function createDevServer(options: DevServerOptions): DevServer;
302
334
 
303
- export { type BuildOptions as B, type ElitRequest as E, type HttpMethod as H, type Middleware as M, type ServerRouteContext as S, type BuildResult as a, type ElitResponse as b, type ServerRouteHandler as c, ServerRouter as d, clearImportMapCache as e, cors as f, errorHandler as g, html as h, bodyLimit as i, json as j, cacheControl as k, logger as l, compress as m, security as n, createProxyHandler as o, type StateChangeHandler as p, type SharedStateOptions as q, rateLimit as r, status as s, text as t, SharedState as u, StateManager as v, createDevServer as w };
335
+ export { type BuildOptions as B, type DevServerOptions as D, type ElitRequest as E, type HttpMethod as H, type Middleware as M, type PreviewOptions as P, type ServerRouteContext as S, type BuildResult as a, type ElitResponse as b, type ServerRouteHandler as c, ServerRouter as d, clearImportMapCache as e, cors as f, errorHandler as g, html as h, bodyLimit as i, json as j, cacheControl as k, logger as l, compress as m, security as n, createProxyHandler as o, type StateChangeHandler as p, type SharedStateOptions as q, rateLimit as r, status as s, text as t, SharedState as u, StateManager as v, createDevServer as w };
package/dist/server.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import './http.mjs';
2
2
  import './ws.mjs';
3
- export { E as ElitRequest, b as ElitResponse, H as HttpMethod, M as Middleware, S as ServerRouteContext, c as ServerRouteHandler, d as ServerRouter, u as SharedState, q as SharedStateOptions, p as StateChangeHandler, v as StateManager, i as bodyLimit, k as cacheControl, e as clearImportMapCache, m as compress, f as cors, w as createDevServer, o as createProxyHandler, g as errorHandler, h as html, j as json, l as logger, r as rateLimit, n as security, s as status, t as text } from './server-SjfPJEWf.mjs';
3
+ export { E as ElitRequest, b as ElitResponse, H as HttpMethod, M as Middleware, S as ServerRouteContext, c as ServerRouteHandler, d as ServerRouter, u as SharedState, q as SharedStateOptions, p as StateChangeHandler, v as StateManager, i as bodyLimit, k as cacheControl, e as clearImportMapCache, m as compress, f as cors, w as createDevServer, o as createProxyHandler, g as errorHandler, h as html, j as json, l as logger, r as rateLimit, n as security, s as status, t as text } from './server-U0JYnJFs.mjs';
4
4
  import 'node:events';
5
5
  import 'events';
6
6
  import 'http';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elit",
3
- "version": "3.2.4",
3
+ "version": "3.2.6",
4
4
  "description": "Optimized lightweight library for creating DOM elements with reactive state",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/config.ts CHANGED
@@ -144,14 +144,44 @@ async function loadConfigFile(configPath: string): Promise<ElitConfig> {
144
144
  // Load TypeScript config by transpiling it with esbuild
145
145
  try {
146
146
  const { build } = await import('esbuild');
147
- const { tmpdir } = await import('os');
148
147
  const { join, dirname } = await import('./path');
149
148
 
150
- // Create temporary output file
151
- const tempFile = join(tmpdir(), `elit-config-${Date.now()}.mjs`);
152
-
153
- // Bundle the TypeScript config with proper path resolution
149
+ // Create temporary output file in the same directory as the config
150
+ // This ensures that imports like 'elit/server' can be resolved correctly
154
151
  const configDir = dirname(configPath);
152
+ const tempFile = join(configDir, `.elit-config-${Date.now()}.mjs`);
153
+
154
+ // Custom plugin to external all dependencies
155
+ const externalAllPlugin = {
156
+ name: 'external-all',
157
+ setup(build: any) {
158
+ build.onResolve({ filter: /.*/ }, (args: any) => {
159
+ // Skip relative imports (local files)
160
+ if (args.path.startsWith('./') || args.path.startsWith('../')) {
161
+ return undefined;
162
+ }
163
+
164
+ // External everything in node_modules
165
+ if (args.path.includes('node_modules') || args.resolveDir?.includes('node_modules')) {
166
+ return { path: args.path, external: true };
167
+ }
168
+
169
+ // External known packages by exact match or prefix
170
+ const knownPackages = ['esbuild', 'elit', 'fs', 'path', 'os', 'vm', 'crypto', 'http', 'https', 'url', 'bun'];
171
+ if (knownPackages.some(pkg => args.path === pkg || args.path.startsWith(pkg + '/'))) {
172
+ return { path: args.path, external: true };
173
+ }
174
+
175
+ // External any imports from dist directory (elit package)
176
+ if (args.resolveDir?.includes('elit/dist') || args.path.includes('elit/dist')) {
177
+ return { path: args.path, external: true };
178
+ }
179
+
180
+ return undefined;
181
+ });
182
+ }
183
+ };
184
+
155
185
  await build({
156
186
  entryPoints: [configPath],
157
187
  bundle: true,
@@ -160,14 +190,12 @@ async function loadConfigFile(configPath: string): Promise<ElitConfig> {
160
190
  outfile: tempFile,
161
191
  write: true,
162
192
  target: 'es2020',
163
- // Bundle everything including elit/* so config can use elit modules
164
- // Only mark Node.js built-ins and runtime-specific packages as external
193
+ plugins: [externalAllPlugin],
194
+ // External Node.js built-ins and runtime-specific packages
165
195
  external: [
166
196
  'node:*',
167
- 'bun',
168
- 'bun:*',
169
- 'deno',
170
- 'deno:*'
197
+ 'fs', 'path', 'os', 'vm', 'crypto', 'http', 'https',
198
+ 'bun', 'bun:*', 'deno', 'deno:*'
171
199
  ],
172
200
  // Use the config directory as the working directory for resolution
173
201
  absWorkingDir: configDir,
package/src/database.ts CHANGED
@@ -2,7 +2,6 @@ import vm from "node:vm";
2
2
  import { resolve } from "./path";
3
3
  import path from "node:path";
4
4
  import fs from "node:fs";
5
- import Bun from "bun";
6
5
 
7
6
  export interface DatabaseConfig {
8
7
  dir?: string;
@@ -11,7 +10,7 @@ export interface DatabaseConfig {
11
10
  }
12
11
 
13
12
  export class Database {
14
- private _transpiler: Bun.Transpiler;
13
+ private _transpiler: any;
15
14
  private _ctx: vm.Context;
16
15
  private _registerModules: { [key: string]: any };
17
16
  private _config: DatabaseConfig = {
@@ -22,9 +21,37 @@ export class Database {
22
21
  this._config = { ...this._config, ...config };
23
22
  this._registerModules = config.registerModules || {};
24
23
  this._ctx = vm.createContext(this._registerModules);
25
- this._transpiler = new Bun.Transpiler({
26
- loader: config?.language || 'ts',
27
- });
24
+ // Initialize transpiler lazily
25
+ this._initTranspiler();
26
+ }
27
+
28
+ private async _initTranspiler() {
29
+ if (!this._transpiler) {
30
+ try {
31
+ // Dynamic import Bun to avoid esbuild bundling issues
32
+ const BunModule = await import('bun');
33
+ this._transpiler = new BunModule.default.Transpiler({
34
+ loader: this._config.language || 'ts',
35
+ });
36
+ } catch {
37
+ // Bun not available, will use esbuild fallback
38
+ const { buildSync } = await import('esbuild');
39
+ this._transpiler = {
40
+ transformSync: (code: string) => {
41
+ const result = buildSync({
42
+ stdin: { contents: code },
43
+ loader: (this._config.language === 'ts' ? 'ts' : 'js') as any,
44
+ format: 'esm',
45
+ platform: 'node',
46
+ target: 'es2020',
47
+ bundle: false,
48
+ });
49
+ return result.outputFiles?.[0]?.text || '';
50
+ }
51
+ };
52
+ }
53
+ }
54
+ return this._transpiler;
28
55
  }
29
56
 
30
57
  set config(config: DatabaseConfig) {
@@ -217,7 +244,9 @@ export class Database {
217
244
  stringCode = code;
218
245
  }
219
246
 
220
- const js = this._transpiler.transformSync(stringCode);
247
+ // Ensure transpiler is initialized
248
+ const transpiler = await this._initTranspiler();
249
+ const js = transpiler.transformSync(stringCode);
221
250
 
222
251
  const mod = new vm.SourceTextModule(js, { context: this._ctx, identifier: path.join(this._config.dir || resolve(process.cwd(), 'databases'), 'virtual-entry.js') });
223
252
  await mod.link(this.moduleLinker.bind(this));