revojs 0.1.21 → 0.1.23

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.
@@ -109,15 +109,12 @@ function useQuery(scope, schema) {
109
109
  }
110
110
  function withQuery(input, query) {
111
111
  const url = new URL(input);
112
- for (const name in query) {
113
- const value = query[name];
114
- if (value) url.searchParams.set(name, value);
115
- }
112
+ for (const name in query) url.searchParams.set(name, query[name]);
116
113
  return url.href;
117
114
  }
118
115
  function useCookies(scope, schema) {
119
116
  const { request } = useServer(scope);
120
- const entries = (import.meta.client ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
117
+ const entries = (isClient ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
121
118
  const [name, value] = cookie.split("=");
122
119
  if (name && value) result[name] = decodeURIComponent(value);
123
120
  return result;
@@ -144,11 +141,11 @@ function setCookie(scope, name, value, options) {
144
141
  if (options?.priority) cookie += `; Priority=${options.priority}`;
145
142
  if (options?.sameSite) cookie += `; SameSite=${options.sameSite}`;
146
143
  if (options?.secure) cookie += `; Secure`;
147
- if (import.meta.server) response.headers.append("Set-Cookie", cookie);
144
+ if (isServer) response.headers.append("Set-Cookie", cookie);
148
145
  else document.cookie = cookie;
149
146
  }
150
147
  function getState(scope, name) {
151
- if (import.meta.server) {
148
+ if (isServer) {
152
149
  const { states } = useServer(scope);
153
150
  return states[name];
154
151
  } else {
@@ -160,7 +157,7 @@ function getState(scope, name) {
160
157
  }
161
158
  }
162
159
  function setState(scope, name, value) {
163
- if (import.meta.server) {
160
+ if (isServer) {
164
161
  const { states } = useServer(scope);
165
162
  states[name] = value;
166
163
  } else {
@@ -230,6 +227,7 @@ async function createServer() {
230
227
  return await invoke(scope, middlewares);
231
228
  } catch (value) {
232
229
  if (value instanceof Response) return value;
230
+ throw value;
233
231
  }
234
232
  }
235
233
  };
@@ -284,21 +282,38 @@ const mimeTypes = {
284
282
  exe: "application/vnd.microsoft.portable-executable",
285
283
  apk: "application/vnd.android.package-archive"
286
284
  };
285
+ const isServer = import.meta.server ?? globalThis?.import?.meta?.server;
286
+ const isClient = import.meta.client ?? globalThis?.import?.meta?.client;
287
287
 
288
288
  //#endregion
289
289
  //#region src/shared/index.ts
290
- var StopEvent = class extends Event {
290
+ var Hookable = class {
291
+ hooks;
291
292
  constructor() {
292
- super("stop");
293
+ this.hooks = {};
294
+ }
295
+ registerHook(name, invoke$1) {
296
+ const targets = this.hooks[name] ?? [];
297
+ targets.push(invoke$1);
298
+ this.hooks[name] = targets;
299
+ return () => {
300
+ const index = this.hooks[name]?.indexOf(invoke$1);
301
+ if (index && index >= 0) this.hooks[name]?.splice(index, 1);
302
+ if (this.hooks[name]?.length === 0) delete this.hooks[name];
303
+ };
304
+ }
305
+ async dispatchHook(name, ...inputs) {
306
+ const results = new Array();
307
+ for (const invoke$1 of this.hooks[name] ?? []) results.push(await invoke$1(...inputs));
308
+ return results;
293
309
  }
294
310
  };
295
- var Scope = class extends EventTarget {
311
+ var Scope = class extends Hookable {
296
312
  parentScope;
297
313
  context;
298
314
  constructor(parentScope) {
299
315
  super();
300
316
  this.parentScope = parentScope;
301
- this.parentScope?.onStop(() => this.stop());
302
317
  this.context = {};
303
318
  }
304
319
  getContext(input) {
@@ -312,13 +327,10 @@ var Scope = class extends EventTarget {
312
327
  setContext(input, value) {
313
328
  this.context[input] = value;
314
329
  }
315
- onStop(input) {
316
- this.addEventListener("stop", input, { once: true });
317
- }
318
- stop() {
319
- return this.dispatchEvent(new StopEvent());
320
- }
321
330
  };
331
+ function defineHook(name) {
332
+ return name;
333
+ }
322
334
  function defineContext(name) {
323
335
  return name;
324
336
  }
@@ -327,7 +339,7 @@ function isFailure(result) {
327
339
  }
328
340
  function parseSchema(scope, schema, value) {
329
341
  const result = schema["~standard"].validate(value);
330
- if (isFailure(result)) throw sendBadRequest(scope, result.issues.map((issue) => issue.message).join(", "));
342
+ if (isFailure(result)) throw sendJson(scope, result, { status: 400 });
331
343
  return result.value;
332
344
  }
333
345
  function mergeObjects(base, input) {
@@ -346,25 +358,28 @@ function mergeObjects(base, input) {
346
358
 
347
359
  //#endregion
348
360
  //#region src/app/index.ts
349
- function createApp(inputConfig) {
350
- let config = mergeObjects(inputConfig, {
351
- modules: [],
352
- sources: { routes: {
353
- match: "**/*.{get,head,post,put,delete,connect,options,trace,patch}.{js,ts}",
354
- entries: ["./routes"]
355
- } },
356
- development: { middlewares: [] },
357
- build: { externals: [] }
358
- });
359
- for (const module of config.modules) config = mergeObjects(config, module.config);
360
- return {
361
- config,
362
- virtuals: {},
363
- alias: {}
364
- };
365
- }
361
+ var App = class extends Hookable {
362
+ config;
363
+ constructor(inputConfig) {
364
+ super();
365
+ this.config = mergeObjects(inputConfig, {
366
+ modules: [],
367
+ sources: { routes: {
368
+ match: "**/*.{get,head,post,put,delete,connect,options,trace,patch}.{js,ts}",
369
+ entries: ["./routes"]
370
+ } },
371
+ development: { middlewares: [] },
372
+ build: {
373
+ externals: [],
374
+ virtuals: {},
375
+ alias: {}
376
+ }
377
+ });
378
+ for (const module of this.config.modules) this.config = mergeObjects(this.config, module.config);
379
+ }
380
+ };
366
381
  const SERVER = "ssr";
367
382
  const CLIENT = "client";
368
383
 
369
384
  //#endregion
370
- export { CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, StopEvent, WILDCARD, createApp, createServer, defineContext, defineMiddleware, defineRoute, getState, invoke, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
385
+ export { App, CLIENT, Hookable, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, WILDCARD, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
@@ -2,7 +2,8 @@
2
2
  type Descriptor<T> = string & {
3
3
  [descriptor]: T;
4
4
  };
5
- type Context = Record<string, unknown>;
5
+ type Invoke = (...inputs: Array<any>) => any;
6
+ type Context = Record<string, any>;
6
7
  type Output<T> = Success<T> | Failure;
7
8
  type InferInput<T extends Schema> = NonNullable<T["~standard"]["types"]>["input"];
8
9
  type InferOutput<T extends Schema> = NonNullable<T["~standard"]["types"]>["output"];
@@ -25,28 +26,25 @@ interface Schema<T = unknown, TOutput = T> {
25
26
  };
26
27
  };
27
28
  }
28
- declare class StopEvent extends Event {
29
+ declare class Hookable {
30
+ private readonly hooks;
29
31
  constructor();
32
+ registerHook<T extends Invoke>(name: Descriptor<T>, invoke: T): () => void;
33
+ dispatchHook<T extends Invoke>(name: Descriptor<T>, ...inputs: Parameters<T>): Promise<Awaited<ReturnType<T>>[]>;
30
34
  }
31
- declare class Scope extends EventTarget {
32
- parentScope?: Scope;
33
- readonly context: Context;
35
+ declare class Scope extends Hookable {
36
+ private parentScope?;
37
+ private readonly context;
34
38
  constructor(parentScope?: Scope);
35
39
  getContext<T>(input: Descriptor<T>): T;
36
40
  setContext<T>(input: Descriptor<T>, value: T): void;
37
- onStop(input: (event: StopEvent) => void): void;
38
- stop(): boolean;
39
41
  }
42
+ declare function defineHook<T extends Invoke>(name: string): Descriptor<T>;
40
43
  declare function defineContext<T>(name: string): Descriptor<T>;
41
44
  declare function isFailure<T>(result: Output<T>): result is Failure;
42
45
  declare function parseSchema<T extends Schema>(scope: Scope, schema: T, value: unknown): InferOutput<T>;
43
46
  declare function mergeObjects<TBase, TInput>(base: TBase, input: TInput): TBase & TInput;
44
47
  declare const descriptor: unique symbol;
45
- declare global {
46
- interface ElementEventMap {
47
- stop: StopEvent;
48
- }
49
- }
50
48
  //#endregion
51
49
  //#region src/server/index.d.ts
52
50
  type CookiePriority = "Low" | "Medium" | "High";
@@ -152,6 +150,8 @@ declare const WILDCARD = "$";
152
150
  declare const PARAMETER = ":";
153
151
  declare let STATES: States;
154
152
  declare const mimeTypes: Record<string, MimeType>;
153
+ declare const isServer: boolean;
154
+ declare const isClient: boolean;
155
155
  //#endregion
156
156
  //#region src/app/index.d.ts
157
157
  type Environment = typeof CLIENT | typeof SERVER;
@@ -161,6 +161,8 @@ interface DevelopmentConfig {
161
161
  }
162
162
  interface BuildConfig {
163
163
  externals: Array<string>;
164
+ virtuals: Record<string, Virtual>;
165
+ alias: Record<string, string>;
164
166
  }
165
167
  interface Config {
166
168
  modules: Array<Module>;
@@ -179,16 +181,14 @@ interface Source {
179
181
  entries: Array<string>;
180
182
  resolve?: (path: string) => string;
181
183
  }
182
- interface App {
184
+ declare class App extends Hookable {
183
185
  config: Config;
184
- virtuals: Record<string, Virtual>;
185
- alias: Record<string, string>;
186
+ constructor(inputConfig?: Mergeable<Config>);
186
187
  }
187
- declare function createApp(inputConfig?: Mergeable<Config>): App;
188
188
  declare const SERVER = "ssr";
189
189
  declare const CLIENT = "client";
190
190
  //#endregion
191
191
  //#region src/client/index.d.ts
192
192
  declare function $fetch<T>(scope: Scope, input: string | URL, options?: RequestInit): Promise<T>;
193
193
  //#endregion
194
- export { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, HttpMethod, InferInput, InferOutput, Issue, Mergeable, Middleware, MimeType, Module, Node, Output, PARAMETER, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode, StopEvent, Success, Virtual, WILDCARD, WildcardNode, createApp, createServer, defineContext, defineMiddleware, defineRoute, getState, invoke, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
194
+ export { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, Hookable, HttpMethod, InferInput, InferOutput, Invoke, Issue, Mergeable, Middleware, MimeType, Module, Node, Output, PARAMETER, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode, Success, Virtual, WILDCARD, WildcardNode, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, HttpMethod, InferInput, InferOutput, Issue, Mergeable, Middleware, MimeType, Module, Node, Output, PARAMETER, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode, StopEvent, Success, Virtual, WILDCARD, WildcardNode, createApp, createServer, defineContext, defineMiddleware, defineRoute, getState, invoke, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery } from "./index-D6BvOWjN.js";
2
- export { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, HttpMethod, InferInput, InferOutput, Issue, Mergeable, Middleware, MimeType, Module, Node, Output, PARAMETER, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode, StopEvent, Success, Virtual, WILDCARD, WildcardNode, createApp, createServer, defineContext, defineMiddleware, defineRoute, getState, invoke, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
1
+ import { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, Hookable, HttpMethod, InferInput, InferOutput, Invoke, Issue, Mergeable, Middleware, MimeType, Module, Node, Output, PARAMETER, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode, Success, Virtual, WILDCARD, WildcardNode, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery } from "./index-DSP2l2h5.js";
2
+ export { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, Hookable, HttpMethod, InferInput, InferOutput, Invoke, Issue, Mergeable, Middleware, MimeType, Module, Node, Output, PARAMETER, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode, Success, Virtual, WILDCARD, WildcardNode, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, StopEvent, WILDCARD, createApp, createServer, defineContext, defineMiddleware, defineRoute, getState, invoke, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery } from "./app-gPmc1xyv.js";
1
+ import { App, CLIENT, Hookable, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, WILDCARD, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery } from "./app-COQSSDHs.js";
2
2
 
3
3
  //#region src/client/index.ts
4
4
  async function $fetch(scope, input, options) {
5
5
  let response;
6
- if (import.meta.server) {
6
+ if (isServer) {
7
7
  const { states, request, variables } = useServer(scope);
8
8
  const next = new Scope();
9
9
  const url = new URL(input.toString(), request.url);
@@ -25,4 +25,4 @@ async function $fetch(scope, input, options) {
25
25
  }
26
26
 
27
27
  //#endregion
28
- export { $fetch, CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, StopEvent, WILDCARD, createApp, createServer, defineContext, defineMiddleware, defineRoute, getState, invoke, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
28
+ export { $fetch, App, CLIENT, Hookable, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, WILDCARD, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
@@ -1,12 +1,11 @@
1
- import { App, Virtual } from "../index-D6BvOWjN.js";
1
+ import { App, Virtual } from "../index-DSP2l2h5.js";
2
2
 
3
3
  //#region src/kit/index.d.ts
4
- declare function useKit(app: App, source: string | URL): {
5
- source: string;
6
- toPath: (...paths: Array<string>) => string;
7
- addVirtual: (name: string, virtual: Virtual) => void;
8
- addAlias: (name: string, path: string) => void;
4
+ declare function useKit(source: string | URL): {
5
+ fromModule(...paths: Array<string>): string;
9
6
  };
7
+ declare function addAlias(app: App, name: string, path: string): void;
8
+ declare function addVirtual(app: App, name: string, virtual: Virtual): void;
10
9
  declare function addRoutes(app: App, path: string): void;
11
10
  //#endregion
12
- export { addRoutes, useKit };
11
+ export { addAlias, addRoutes, addVirtual, useKit };
package/dist/kit/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { addRoutes, useKit } from "../kit-Bzr1NqHb.js";
1
+ import { addAlias, addRoutes, addVirtual, useKit } from "../kit-CUuTaZz2.js";
2
2
 
3
- export { addRoutes, useKit };
3
+ export { addAlias, addRoutes, addVirtual, useKit };
@@ -0,0 +1,23 @@
1
+ import { dirname, join, posix, win32 } from "path";
2
+ import { fileURLToPath } from "url";
3
+
4
+ //#region src/kit/index.ts
5
+ function useKit(source) {
6
+ source = source.toString();
7
+ if (source.startsWith("file://")) source = dirname(fileURLToPath(source));
8
+ return { fromModule(...paths) {
9
+ return join(source, ...paths).split(win32.sep).join(posix.sep);
10
+ } };
11
+ }
12
+ function addAlias(app, name, path) {
13
+ app.config.build.alias["#alias/" + name] = path;
14
+ }
15
+ function addVirtual(app, name, virtual) {
16
+ app.config.build.virtuals["#virtual/" + name] = virtual;
17
+ }
18
+ function addRoutes(app, path) {
19
+ app.config.sources.routes?.entries.push(path);
20
+ }
21
+
22
+ //#endregion
23
+ export { addAlias, addRoutes, addVirtual, useKit };
@@ -1,4 +1,4 @@
1
- import { Config, Mergeable } from "../index-D6BvOWjN.js";
1
+ import { Config, Mergeable } from "../index-DSP2l2h5.js";
2
2
  import { Plugin } from "vite";
3
3
 
4
4
  //#region src/vite/index.d.ts
@@ -1,6 +1,6 @@
1
- import { CLIENT, SERVER, SERVER_CONTEXT, Scope, createApp, invoke } from "../app-gPmc1xyv.js";
2
- import { useKit } from "../kit-Bzr1NqHb.js";
3
- import { basename, dirname, isAbsolute, join, posix, relative, win32 } from "path";
1
+ import { App, CLIENT, SERVER, SERVER_CONTEXT, Scope, invoke } from "../app-COQSSDHs.js";
2
+ import { addVirtual } from "../kit-CUuTaZz2.js";
3
+ import { basename, dirname, isAbsolute, join, posix, relative, resolve, win32 } from "path";
4
4
  import { isRunnableDevEnvironment } from "vite";
5
5
  import { once } from "events";
6
6
  import { Readable, Stream } from "stream";
@@ -175,7 +175,7 @@ function client() {
175
175
  const path = key.substring(0, key.length - 7);
176
176
  if (bundle) for (const name$1 in bundle) {
177
177
  const file = bundle[name$1];
178
- if (file && file.type === "asset" && file.fileName === basename(path)) return file.source.toString();
178
+ if (file.type === "asset" && file.fileName === basename(path)) return file.source.toString();
179
179
  }
180
180
  return readFileSync(path, "utf-8");
181
181
  }
@@ -307,28 +307,27 @@ function virtuals(virtuals$1) {
307
307
  //#endregion
308
308
  //#region package.json
309
309
  var name = "revojs";
310
- var version = "0.1.21";
310
+ var version = "0.1.23";
311
311
 
312
312
  //#endregion
313
313
  //#region src/vite/index.ts
314
314
  function revojs(config) {
315
- const app = createApp(config);
315
+ const app = new App(config);
316
316
  return [
317
317
  {
318
318
  name,
319
319
  version,
320
320
  sharedDuringBuild: true,
321
321
  async config() {
322
- const { toPath, addVirtual } = useKit(app, process.cwd());
323
322
  for (const module of app.config.modules) await module.setup?.(app);
324
- if (app.config.client) addVirtual("client", () => `import client from "${app.config.client}?client"; export default client`);
325
- if (app.config.server) addVirtual("server", () => `import { createServer } from "revojs"; export default await createServer()`);
323
+ if (app.config.client) addVirtual(app, "client", () => `import client from "${app.config.client}?client"; export default client`);
324
+ if (app.config.server) addVirtual(app, "server", () => `import { createServer } from "revojs"; export default await createServer()`);
326
325
  for (const name$1 in app.config.sources) {
327
326
  const source = app.config.sources[name$1];
328
- if (source) addVirtual(name$1, () => {
327
+ addVirtual(app, name$1, () => {
329
328
  const entries = {};
330
329
  for (let path of source.entries) {
331
- path = isAbsolute(path) ? path : toPath(path);
330
+ path = isAbsolute(path) ? path : resolve(path);
332
331
  for (const asset of globSync(source.match, { cwd: path })) entries[asset] = join(path, asset).split(win32.sep).join(posix.sep);
333
332
  }
334
333
  const content = Object.values(entries).reduce((content$1, path, index) => content$1 + `import $${index} from "${source.resolve?.(path) ?? path}" \n`, "");
@@ -341,7 +340,7 @@ function revojs(config) {
341
340
  return {
342
341
  appType: "custom",
343
342
  optimizeDeps: { exclude: ["revojs"] },
344
- resolve: { alias: app.alias },
343
+ resolve: { alias: app.config.build.alias },
345
344
  build: {
346
345
  emptyOutDir: false,
347
346
  assetsInlineLimit: 4096 * 4,
@@ -356,7 +355,8 @@ function revojs(config) {
356
355
  });
357
356
  for (const key in builder.environments) {
358
357
  const environment = builder.environments[key];
359
- if (environment) await builder.build(environment);
358
+ await builder.build(environment);
359
+ if (environment.name === CLIENT && typeof environment.config.build.rollupOptions.input === "string") await rm(resolve(environment.config.build.outDir, basename(environment.config.build.rollupOptions.input)));
360
360
  }
361
361
  }
362
362
  },
@@ -365,7 +365,7 @@ function revojs(config) {
365
365
  consumer: "client",
366
366
  resolve: { noExternal: true },
367
367
  build: {
368
- rollupOptions: { input: { index: app.config.client } },
368
+ rollupOptions: { input: app.config.client },
369
369
  outDir: "./dist/public",
370
370
  copyPublicDir: true
371
371
  },
@@ -382,7 +382,7 @@ function revojs(config) {
382
382
  externalConditions: ["import"]
383
383
  },
384
384
  build: {
385
- rollupOptions: { input: { index: app.config.server } },
385
+ rollupOptions: { input: app.config.server },
386
386
  outDir: "./dist",
387
387
  copyPublicDir: false
388
388
  },
@@ -406,25 +406,21 @@ function revojs(config) {
406
406
  if (server) {
407
407
  request.url = request.originalUrl;
408
408
  const scope = new Scope();
409
- try {
410
- scope.setContext(SERVER_CONTEXT, {
411
- states: {},
412
- request: fromNodeRequest(request, response),
413
- response: { headers: new Headers() },
414
- variables: process.env
415
- });
416
- var result = await invoke(scope, app.config.development.middlewares.concat({ fetch: server.fetch }));
417
- if (result) await toNodeRequest(result, response);
418
- } finally {
419
- scope.stop();
420
- }
409
+ scope.setContext(SERVER_CONTEXT, {
410
+ states: {},
411
+ request: fromNodeRequest(request, response),
412
+ response: { headers: new Headers() },
413
+ variables: process.env
414
+ });
415
+ var result = await invoke(scope, app.config.development.middlewares.concat({ fetch: server.fetch }));
416
+ if (result) await toNodeRequest(result, response);
421
417
  }
422
418
  next();
423
419
  });
424
420
  };
425
421
  }
426
422
  },
427
- virtuals(app.virtuals),
423
+ virtuals(app.config.build.virtuals),
428
424
  client(),
429
425
  entry(),
430
426
  css()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",
@@ -1,26 +0,0 @@
1
- import { dirname, join, posix, win32 } from "path";
2
- import { fileURLToPath } from "url";
3
-
4
- //#region src/kit/index.ts
5
- function useKit(app, source) {
6
- source = source.toString();
7
- if (source.startsWith("file://")) source = dirname(fileURLToPath(source));
8
- return {
9
- source,
10
- toPath: (...paths) => {
11
- return join(source, ...paths).split(win32.sep).join(posix.sep);
12
- },
13
- addVirtual: (name, virtual) => {
14
- app.virtuals["#virtual/" + name] = virtual;
15
- },
16
- addAlias: (name, path) => {
17
- app.alias["#alias/" + name] = join(source, path).split(win32.sep).join(posix.sep);
18
- }
19
- };
20
- }
21
- function addRoutes(app, path) {
22
- app.config.sources.routes?.entries.push(path);
23
- }
24
-
25
- //#endregion
26
- export { addRoutes, useKit };