revojs 0.0.87 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +176 -9
- package/dist/index.js +212 -902
- package/dist/vite/index.d.ts +53 -0
- package/dist/vite/index.js +460 -0
- package/package.json +11 -10
- package/src/types/index.d.ts +20 -16
- package/dist/app/index.d.ts +0 -36
- package/dist/html/index.d.ts +0 -110
- package/dist/http/index.d.ts +0 -36
- package/dist/jsx/index.d.ts +0 -371
- package/dist/jsx/index.js +0 -160
- package/dist/locale/index.d.ts +0 -26
- package/dist/radix/index.d.ts +0 -12
- package/dist/router/index.d.ts +0 -45
- package/dist/runtime/index.d.ts +0 -55
- package/dist/schema/index.d.ts +0 -22
- package/dist/signals/index.d.ts +0 -44
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
|
|
3
|
+
//#region src/shared/index.d.ts
|
|
4
|
+
|
|
5
|
+
type Mergeable<T> = { [P in keyof T]?: Mergeable<T[P]> };
|
|
6
|
+
declare class StopEvent extends Event {
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
declare global {
|
|
10
|
+
interface ElementEventMap {
|
|
11
|
+
stop: StopEvent;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/app/index.d.ts
|
|
16
|
+
type Environment = typeof CLIENT | typeof SERVER;
|
|
17
|
+
type Virtual = (environment: Environment) => undefined | string | Promise<string>;
|
|
18
|
+
interface Config {
|
|
19
|
+
modules: Array<Module>;
|
|
20
|
+
client?: string;
|
|
21
|
+
server?: string;
|
|
22
|
+
sources: Record<string, Source>;
|
|
23
|
+
}
|
|
24
|
+
interface Module {
|
|
25
|
+
config?: Mergeable<Config>;
|
|
26
|
+
setup?: (app: App) => void | Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
interface Source {
|
|
29
|
+
match: string;
|
|
30
|
+
entries: Array<string>;
|
|
31
|
+
suffix?: string;
|
|
32
|
+
}
|
|
33
|
+
interface App {
|
|
34
|
+
config: Config;
|
|
35
|
+
virtuals: Record<string, Virtual>;
|
|
36
|
+
alias: Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
declare const SERVER = "ssr";
|
|
39
|
+
declare const CLIENT = "client";
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/vite/index.d.ts
|
|
42
|
+
declare function useKit(app: App, source: string | URL): {
|
|
43
|
+
source: string;
|
|
44
|
+
toPath: (...paths: Array<string>) => string;
|
|
45
|
+
addVirtual: (name: string, virtual: Virtual) => void;
|
|
46
|
+
addAlias: (name: string, path: string) => void;
|
|
47
|
+
};
|
|
48
|
+
declare function addRoutes(app: App, path: string): void;
|
|
49
|
+
declare function addAssets(app: App, path: string): void;
|
|
50
|
+
declare function addMiddlewares(app: App, path: string): void;
|
|
51
|
+
declare function revojs(config?: Mergeable<Config>): Array<Plugin>;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { addAssets, addMiddlewares, addRoutes, revojs, useKit };
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
import { basename, dirname, isAbsolute, join, posix, win32 } from "path";
|
|
2
|
+
import { globSync } from "tinyglobby";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { isRunnableDevEnvironment } from "vite";
|
|
5
|
+
import { once } from "node:events";
|
|
6
|
+
import { Readable, Stream } from "node:stream";
|
|
7
|
+
import { existsSync, readFileSync } from "fs";
|
|
8
|
+
|
|
9
|
+
//#region package.json
|
|
10
|
+
var name = "revojs";
|
|
11
|
+
var version = "0.1.0";
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/server/index.ts
|
|
15
|
+
const ROUTER_CONTEXT = defineContext("ROUTER_CONTEXT");
|
|
16
|
+
const SERVER_CONTEXT = defineContext("SERVER_CONTEXT");
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/shared/index.ts
|
|
20
|
+
var StopEvent = class extends Event {
|
|
21
|
+
constructor() {
|
|
22
|
+
super("stop");
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var Scope = class extends EventTarget {
|
|
26
|
+
parentScope;
|
|
27
|
+
context;
|
|
28
|
+
constructor(parentScope) {
|
|
29
|
+
super();
|
|
30
|
+
this.parentScope = parentScope;
|
|
31
|
+
this.parentScope?.onStop(() => this.stop());
|
|
32
|
+
this.context = {};
|
|
33
|
+
}
|
|
34
|
+
getContext(input) {
|
|
35
|
+
let scope = this;
|
|
36
|
+
while (scope) {
|
|
37
|
+
if (scope.context[input]) return scope.context[input];
|
|
38
|
+
scope = scope.parentScope;
|
|
39
|
+
}
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
setContext(input, value) {
|
|
43
|
+
this.context[input] = value;
|
|
44
|
+
}
|
|
45
|
+
onStop(input) {
|
|
46
|
+
this.addEventListener("stop", input, { once: true });
|
|
47
|
+
}
|
|
48
|
+
stop() {
|
|
49
|
+
return this.dispatchEvent(new StopEvent());
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
function defineContext(name$1) {
|
|
53
|
+
return name$1;
|
|
54
|
+
}
|
|
55
|
+
function mergeObjects(base, input) {
|
|
56
|
+
if (input === null || input === void 0) return mergeObjects(base, {});
|
|
57
|
+
const object = structuredClone(input);
|
|
58
|
+
for (const key in base) {
|
|
59
|
+
if (key === "__proto__" || key === "constructor") continue;
|
|
60
|
+
const value = base[key];
|
|
61
|
+
if (value === null || value === void 0) continue;
|
|
62
|
+
if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
|
|
63
|
+
else if (typeof value === "object" && typeof object[key] === "object") object[key] = mergeObjects(value, object[key]);
|
|
64
|
+
else object[key] = value;
|
|
65
|
+
}
|
|
66
|
+
return object;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/app/index.ts
|
|
71
|
+
function createApp(inputConfig) {
|
|
72
|
+
let config = mergeObjects(inputConfig, {
|
|
73
|
+
modules: [],
|
|
74
|
+
sources: {
|
|
75
|
+
assets: {
|
|
76
|
+
match: "**/*",
|
|
77
|
+
entries: ["./public"],
|
|
78
|
+
suffix: "?raw"
|
|
79
|
+
},
|
|
80
|
+
routes: {
|
|
81
|
+
match: "**/*.{js,ts}",
|
|
82
|
+
entries: ["./routes"]
|
|
83
|
+
},
|
|
84
|
+
middlewares: {
|
|
85
|
+
match: "**/*.{js,ts}",
|
|
86
|
+
entries: ["./middlewares"]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
for (const module of config.modules) config = mergeObjects(config, module.config);
|
|
91
|
+
return {
|
|
92
|
+
config,
|
|
93
|
+
virtuals: {},
|
|
94
|
+
alias: {}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const SERVER = "ssr";
|
|
98
|
+
const CLIENT = "client";
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/vite/node/index.ts
|
|
102
|
+
function splitSetCookieString(cookiesString) {
|
|
103
|
+
if (Array.isArray(cookiesString)) return cookiesString.flatMap((c) => splitSetCookieString(c));
|
|
104
|
+
if (typeof cookiesString !== "string") return [];
|
|
105
|
+
const cookiesStrings = [];
|
|
106
|
+
let pos = 0;
|
|
107
|
+
let start;
|
|
108
|
+
let ch;
|
|
109
|
+
let lastComma;
|
|
110
|
+
let nextStart;
|
|
111
|
+
let cookiesSeparatorFound;
|
|
112
|
+
const skipWhitespace = () => {
|
|
113
|
+
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) pos += 1;
|
|
114
|
+
return pos < cookiesString.length;
|
|
115
|
+
};
|
|
116
|
+
const notSpecialChar = () => {
|
|
117
|
+
ch = cookiesString.charAt(pos);
|
|
118
|
+
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
119
|
+
};
|
|
120
|
+
while (pos < cookiesString.length) {
|
|
121
|
+
start = pos;
|
|
122
|
+
cookiesSeparatorFound = false;
|
|
123
|
+
while (skipWhitespace()) {
|
|
124
|
+
ch = cookiesString.charAt(pos);
|
|
125
|
+
if (ch === ",") {
|
|
126
|
+
lastComma = pos;
|
|
127
|
+
pos += 1;
|
|
128
|
+
skipWhitespace();
|
|
129
|
+
nextStart = pos;
|
|
130
|
+
while (pos < cookiesString.length && notSpecialChar()) pos += 1;
|
|
131
|
+
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
132
|
+
cookiesSeparatorFound = true;
|
|
133
|
+
pos = nextStart;
|
|
134
|
+
cookiesStrings.push(cookiesString.slice(start, lastComma));
|
|
135
|
+
start = pos;
|
|
136
|
+
} else pos = lastComma + 1;
|
|
137
|
+
} else pos += 1;
|
|
138
|
+
}
|
|
139
|
+
if (!cookiesSeparatorFound || pos >= cookiesString.length) cookiesStrings.push(cookiesString.slice(start));
|
|
140
|
+
}
|
|
141
|
+
return cookiesStrings;
|
|
142
|
+
}
|
|
143
|
+
function createReadableStreamFromReadable(source) {
|
|
144
|
+
let pump = new StreamPump(source);
|
|
145
|
+
return new ReadableStream(pump, pump);
|
|
146
|
+
}
|
|
147
|
+
var StreamPump = class {
|
|
148
|
+
highWaterMark;
|
|
149
|
+
accumalatedSize;
|
|
150
|
+
stream;
|
|
151
|
+
controller;
|
|
152
|
+
constructor(stream) {
|
|
153
|
+
this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
|
|
154
|
+
this.accumalatedSize = 0;
|
|
155
|
+
this.stream = stream;
|
|
156
|
+
this.enqueue = this.enqueue.bind(this);
|
|
157
|
+
this.error = this.error.bind(this);
|
|
158
|
+
this.close = this.close.bind(this);
|
|
159
|
+
}
|
|
160
|
+
size(chunk) {
|
|
161
|
+
return chunk?.byteLength || 0;
|
|
162
|
+
}
|
|
163
|
+
start(controller) {
|
|
164
|
+
this.controller = controller;
|
|
165
|
+
this.stream.on("data", this.enqueue);
|
|
166
|
+
this.stream.once("error", this.error);
|
|
167
|
+
this.stream.once("end", this.close);
|
|
168
|
+
this.stream.once("close", this.close);
|
|
169
|
+
}
|
|
170
|
+
pull() {
|
|
171
|
+
this.resume();
|
|
172
|
+
}
|
|
173
|
+
cancel(reason) {
|
|
174
|
+
if (this.stream.destroy) this.stream.destroy(reason);
|
|
175
|
+
this.stream.off("data", this.enqueue);
|
|
176
|
+
this.stream.off("error", this.error);
|
|
177
|
+
this.stream.off("end", this.close);
|
|
178
|
+
this.stream.off("close", this.close);
|
|
179
|
+
}
|
|
180
|
+
enqueue(chunk) {
|
|
181
|
+
if (this.controller) try {
|
|
182
|
+
let bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
|
|
183
|
+
let available = (this.controller.desiredSize || 0) - bytes.byteLength;
|
|
184
|
+
this.controller.enqueue(bytes);
|
|
185
|
+
if (available <= 0) this.pause();
|
|
186
|
+
} catch (error) {
|
|
187
|
+
this.controller.error(/* @__PURE__ */ new Error("Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"));
|
|
188
|
+
this.cancel();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
pause() {
|
|
192
|
+
if (this.stream.pause) this.stream.pause();
|
|
193
|
+
}
|
|
194
|
+
resume() {
|
|
195
|
+
if (this.stream.readable && this.stream.resume) this.stream.resume();
|
|
196
|
+
}
|
|
197
|
+
close() {
|
|
198
|
+
if (this.controller) {
|
|
199
|
+
this.controller.close();
|
|
200
|
+
delete this.controller;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
error(error) {
|
|
204
|
+
if (this.controller) {
|
|
205
|
+
this.controller.error(error);
|
|
206
|
+
delete this.controller;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
function fromNodeHeaders(nodeHeaders) {
|
|
211
|
+
let headers = new Headers();
|
|
212
|
+
for (let [key, values] of Object.entries(nodeHeaders)) if (values) if (Array.isArray(values)) for (let value of values) headers.append(key, value);
|
|
213
|
+
else headers.set(key, values);
|
|
214
|
+
return headers;
|
|
215
|
+
}
|
|
216
|
+
function fromNodeRequest(nodeReq, nodeRes) {
|
|
217
|
+
let origin = nodeReq.headers.origin && "null" !== nodeReq.headers.origin ? nodeReq.headers.origin : `http://${nodeReq.headers.host}`;
|
|
218
|
+
let url = new URL(nodeReq.url ?? "", origin);
|
|
219
|
+
let controller = new AbortController();
|
|
220
|
+
let init = {
|
|
221
|
+
method: nodeReq.method,
|
|
222
|
+
headers: fromNodeHeaders(nodeReq.headers),
|
|
223
|
+
signal: controller.signal
|
|
224
|
+
};
|
|
225
|
+
if (nodeReq.method !== "GET" && nodeReq.method !== "HEAD") {
|
|
226
|
+
init.body = createReadableStreamFromReadable(nodeReq);
|
|
227
|
+
init.duplex = "half";
|
|
228
|
+
}
|
|
229
|
+
nodeRes.on("finish", () => controller = null);
|
|
230
|
+
nodeRes.on("close", () => controller?.abort());
|
|
231
|
+
return new Request(url.href, init);
|
|
232
|
+
}
|
|
233
|
+
async function toNodeRequest(res, nodeRes) {
|
|
234
|
+
nodeRes.statusCode = res.status;
|
|
235
|
+
nodeRes.statusMessage = res.statusText;
|
|
236
|
+
let cookiesStrings = [];
|
|
237
|
+
for (let [name$1, value] of res.headers) if (name$1 === "set-cookie") cookiesStrings.push(...splitSetCookieString(value));
|
|
238
|
+
else nodeRes.setHeader(name$1, value);
|
|
239
|
+
if (cookiesStrings.length) nodeRes.setHeader("set-cookie", cookiesStrings);
|
|
240
|
+
if (res.body) {
|
|
241
|
+
let responseBody = res.body;
|
|
242
|
+
let readable = Readable.from(responseBody);
|
|
243
|
+
readable.pipe(nodeRes);
|
|
244
|
+
await once(readable, "end");
|
|
245
|
+
} else nodeRes.end();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/vite/plugins/client.ts
|
|
250
|
+
const SUFFIX = "?client";
|
|
251
|
+
function client() {
|
|
252
|
+
let server;
|
|
253
|
+
return {
|
|
254
|
+
name: "client",
|
|
255
|
+
sharedDuringBuild: true,
|
|
256
|
+
configureServer(devServer) {
|
|
257
|
+
server = devServer;
|
|
258
|
+
},
|
|
259
|
+
load(key) {
|
|
260
|
+
if (key.endsWith(SUFFIX)) {
|
|
261
|
+
const path = key.substring(0, key.length - 7);
|
|
262
|
+
return readFileSync(path, "utf-8");
|
|
263
|
+
}
|
|
264
|
+
return null;
|
|
265
|
+
},
|
|
266
|
+
async transform(code, key) {
|
|
267
|
+
if (key.endsWith(SUFFIX)) {
|
|
268
|
+
code = server ? await server.transformIndexHtml(key, code) : code;
|
|
269
|
+
return { code: `export default \`${code}\`` };
|
|
270
|
+
}
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/vite/plugins/entry.ts
|
|
278
|
+
function entry() {
|
|
279
|
+
let entryName;
|
|
280
|
+
let entryPath;
|
|
281
|
+
return {
|
|
282
|
+
name: "entry",
|
|
283
|
+
enforce: "pre",
|
|
284
|
+
sharedDuringBuild: true,
|
|
285
|
+
resolveId(source, importer, options) {
|
|
286
|
+
if (source === "vite/modulepreload-polyfill") return null;
|
|
287
|
+
if (this.environment.name === CLIENT) {
|
|
288
|
+
if (importer && entryPath) {
|
|
289
|
+
const path = join(dirname(importer), source);
|
|
290
|
+
if (existsSync(path)) return path;
|
|
291
|
+
}
|
|
292
|
+
if (options.isEntry) {
|
|
293
|
+
entryName = basename(source);
|
|
294
|
+
entryPath = source;
|
|
295
|
+
return entryName;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return null;
|
|
299
|
+
},
|
|
300
|
+
load(source) {
|
|
301
|
+
if (entryName && entryPath && source === entryName) return readFileSync(entryPath, {
|
|
302
|
+
encoding: "utf-8",
|
|
303
|
+
flag: "r"
|
|
304
|
+
});
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/vite/plugins/virtuals.ts
|
|
312
|
+
function virtuals(virtuals$1) {
|
|
313
|
+
const cache = /* @__PURE__ */ new Set();
|
|
314
|
+
return {
|
|
315
|
+
name: "virtuals",
|
|
316
|
+
enforce: "pre",
|
|
317
|
+
sharedDuringBuild: true,
|
|
318
|
+
resolveId(key, importer) {
|
|
319
|
+
if (cache.has(key)) return key;
|
|
320
|
+
if (key.startsWith("#")) {
|
|
321
|
+
const path = "/" + key.slice(1);
|
|
322
|
+
cache.add(path);
|
|
323
|
+
return path;
|
|
324
|
+
}
|
|
325
|
+
return null;
|
|
326
|
+
},
|
|
327
|
+
load(key) {
|
|
328
|
+
const virtual = virtuals$1["#" + key.slice(1)];
|
|
329
|
+
if (typeof virtual === "string") return readFileSync(virtual, {
|
|
330
|
+
encoding: "utf-8",
|
|
331
|
+
flag: "r"
|
|
332
|
+
});
|
|
333
|
+
var code = virtual?.(this.environment.name);
|
|
334
|
+
if (code) return code;
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/vite/index.ts
|
|
342
|
+
function useKit(app, source) {
|
|
343
|
+
source = source.toString();
|
|
344
|
+
if (source.startsWith("file://")) source = dirname(fileURLToPath(source));
|
|
345
|
+
return {
|
|
346
|
+
source,
|
|
347
|
+
toPath: (...paths) => {
|
|
348
|
+
return join(source, ...paths).split(win32.sep).join(posix.sep);
|
|
349
|
+
},
|
|
350
|
+
addVirtual: (name$1, virtual) => {
|
|
351
|
+
app.virtuals["#virtual/" + name$1] = virtual;
|
|
352
|
+
},
|
|
353
|
+
addAlias: (name$1, path) => {
|
|
354
|
+
app.alias["#alias/" + name$1] = join(source, path).split(win32.sep).join(posix.sep);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function addRoutes(app, path) {
|
|
359
|
+
app.config.sources.routes?.entries.push(path);
|
|
360
|
+
}
|
|
361
|
+
function addAssets(app, path) {
|
|
362
|
+
app.config.sources.assets?.entries.push(path);
|
|
363
|
+
}
|
|
364
|
+
function addMiddlewares(app, path) {
|
|
365
|
+
app.config.sources.middlewares?.entries.push(path);
|
|
366
|
+
}
|
|
367
|
+
function revojs(config) {
|
|
368
|
+
const app = createApp(config);
|
|
369
|
+
return [
|
|
370
|
+
{
|
|
371
|
+
name,
|
|
372
|
+
version,
|
|
373
|
+
sharedDuringBuild: true,
|
|
374
|
+
async config() {
|
|
375
|
+
const { toPath, addVirtual } = useKit(app, process.cwd());
|
|
376
|
+
for (const module of app.config.modules) await module.setup?.(app);
|
|
377
|
+
if (app.config.client) addVirtual("client", () => `import client from "${app.config.client}?client"; export default client`);
|
|
378
|
+
if (app.config.server) addVirtual("server", () => `import { createServer } from "revojs"; export default await createServer()`);
|
|
379
|
+
for (const name$1 in app.config.sources) {
|
|
380
|
+
const source = app.config.sources[name$1];
|
|
381
|
+
if (source) addVirtual(name$1, () => {
|
|
382
|
+
const entries = {};
|
|
383
|
+
for (let path of source.entries) {
|
|
384
|
+
path = isAbsolute(path) ? path : toPath(path);
|
|
385
|
+
for (const asset of globSync(source.match, { cwd: path })) entries[asset] = join(path, asset).split(win32.sep).join(posix.sep);
|
|
386
|
+
}
|
|
387
|
+
return `export default {${Object.keys(entries).map((name$2) => `"${name$2}": await import("${entries[name$2] + (source.suffix ?? "")}").then(module => module.default)`)}}`;
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
appType: "custom",
|
|
392
|
+
resolve: { alias: app.alias },
|
|
393
|
+
environments: {
|
|
394
|
+
...app.config.client && { [CLIENT]: {
|
|
395
|
+
consumer: "client",
|
|
396
|
+
resolve: { noExternal: true },
|
|
397
|
+
build: {
|
|
398
|
+
rollupOptions: { input: { index: app.config.client } },
|
|
399
|
+
outDir: "./dist/client",
|
|
400
|
+
copyPublicDir: true,
|
|
401
|
+
emptyOutDir: true
|
|
402
|
+
},
|
|
403
|
+
define: {
|
|
404
|
+
"import.meta.server": false,
|
|
405
|
+
"import.meta.client": true
|
|
406
|
+
}
|
|
407
|
+
} },
|
|
408
|
+
...app.config.server && { [SERVER]: {
|
|
409
|
+
consumer: "server",
|
|
410
|
+
resolve: {
|
|
411
|
+
noExternal: true,
|
|
412
|
+
conditions: ["import"],
|
|
413
|
+
externalConditions: ["import"]
|
|
414
|
+
},
|
|
415
|
+
build: {
|
|
416
|
+
rollupOptions: { input: { index: app.config.server } },
|
|
417
|
+
outDir: "./dist/server",
|
|
418
|
+
copyPublicDir: false,
|
|
419
|
+
emptyOutDir: true
|
|
420
|
+
},
|
|
421
|
+
define: {
|
|
422
|
+
"import.meta.server": true,
|
|
423
|
+
"import.meta.client": false
|
|
424
|
+
}
|
|
425
|
+
} }
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
},
|
|
429
|
+
configResolved(config$1) {
|
|
430
|
+
if (app.config.client === void 0) delete config$1.environments[CLIENT];
|
|
431
|
+
if (app.config.server === void 0) delete config$1.environments[SERVER];
|
|
432
|
+
},
|
|
433
|
+
async configureServer(devServer) {
|
|
434
|
+
const target = devServer.environments[SERVER];
|
|
435
|
+
if (isRunnableDevEnvironment(target)) return () => {
|
|
436
|
+
devServer.middlewares.use(async (request, response, next) => {
|
|
437
|
+
const server = await target.runner.import("#virtual/server").then((module) => module.default);
|
|
438
|
+
if (server) {
|
|
439
|
+
request.url = request.originalUrl;
|
|
440
|
+
const scope = new Scope();
|
|
441
|
+
scope.setContext(SERVER_CONTEXT, {
|
|
442
|
+
request: fromNodeRequest(request, response),
|
|
443
|
+
response: { headers: new Headers() },
|
|
444
|
+
variables: process.env
|
|
445
|
+
});
|
|
446
|
+
await toNodeRequest(await server.fetch(scope), response).finally(() => scope.stop());
|
|
447
|
+
}
|
|
448
|
+
next();
|
|
449
|
+
});
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
virtuals(app.virtuals),
|
|
454
|
+
client(),
|
|
455
|
+
entry()
|
|
456
|
+
];
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
//#endregion
|
|
460
|
+
export { addAssets, addMiddlewares, addRoutes, revojs, useKit };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "revojs",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": "coverbase/revojs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"import": "./dist/index.js"
|
|
11
11
|
},
|
|
12
|
-
"./
|
|
13
|
-
"types": "./dist/
|
|
14
|
-
"import": "./dist/
|
|
12
|
+
"./vite": {
|
|
13
|
+
"types": "./dist/vite/index.d.ts",
|
|
14
|
+
"import": "./dist/vite/index.js"
|
|
15
15
|
},
|
|
16
16
|
"./types": {
|
|
17
17
|
"types": "./src/types/index.d.ts"
|
|
@@ -25,15 +25,16 @@
|
|
|
25
25
|
"src/types"
|
|
26
26
|
],
|
|
27
27
|
"scripts": {
|
|
28
|
-
"build": "
|
|
29
|
-
"watch": "
|
|
28
|
+
"build": "tsdown",
|
|
29
|
+
"watch": "tsdown -w"
|
|
30
30
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"tinyglobby": "^0.2.14",
|
|
33
|
+
"vite": "^7.1.3"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@revojs/rolldown": "*",
|
|
36
36
|
"@revojs/tsconfig": "*",
|
|
37
|
-
"
|
|
37
|
+
"@types/node": "^24.3.0",
|
|
38
|
+
"tsdown": "^0.15.1"
|
|
38
39
|
}
|
|
39
40
|
}
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
|
-
declare module "#virtual/
|
|
2
|
-
|
|
1
|
+
declare module "#virtual/client" {
|
|
2
|
+
const client: string;
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export default client;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
declare module "#virtual/
|
|
8
|
-
import type {
|
|
7
|
+
declare module "#virtual/server" {
|
|
8
|
+
import type { Server } from "revojs";
|
|
9
|
+
|
|
10
|
+
const server: Server;
|
|
11
|
+
|
|
12
|
+
export default server;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare module "#virtual/assets" {
|
|
16
|
+
const assets: Record<string, string>;
|
|
9
17
|
|
|
10
|
-
export
|
|
18
|
+
export default assets;
|
|
11
19
|
}
|
|
12
20
|
|
|
13
21
|
declare module "#virtual/routes" {
|
|
14
|
-
import type { Route
|
|
22
|
+
import type { Route } from "revojs";
|
|
15
23
|
|
|
16
|
-
const routes: Record<string, Route
|
|
24
|
+
const routes: Record<string, Route>;
|
|
17
25
|
|
|
18
26
|
export default routes;
|
|
19
27
|
}
|
|
20
28
|
|
|
21
|
-
declare module "#virtual/
|
|
22
|
-
|
|
29
|
+
declare module "#virtual/middlewares" {
|
|
30
|
+
import type { Middleware } from "revojs";
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
}
|
|
32
|
+
const middlewares: Record<string, Middleware>;
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
const assets: Record<string, string>;
|
|
29
|
-
|
|
30
|
-
export default assets;
|
|
34
|
+
export default middlewares;
|
|
31
35
|
}
|
package/dist/app/index.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Middleware } from "../runtime";
|
|
2
|
-
export type Mergeable<T> = {
|
|
3
|
-
[P in keyof T]?: Mergeable<T[P]>;
|
|
4
|
-
};
|
|
5
|
-
export type Environment = typeof CLIENT | typeof SERVER;
|
|
6
|
-
export type Virtual = (environment: Environment) => void | string;
|
|
7
|
-
export type ClientEntry = "index.html" | (string & {});
|
|
8
|
-
export type ServerEntry = "@revojs/bun/runtime" | "@revojs/cloudflare/runtime" | (string & {});
|
|
9
|
-
export type Module = {
|
|
10
|
-
setup: (app: App) => void | Promise<void>;
|
|
11
|
-
};
|
|
12
|
-
export type ClientConfig = {
|
|
13
|
-
entry: ClientEntry;
|
|
14
|
-
externals: Array<string>;
|
|
15
|
-
};
|
|
16
|
-
export type ServerConfig = {
|
|
17
|
-
entry: ServerEntry;
|
|
18
|
-
externals: Array<string>;
|
|
19
|
-
};
|
|
20
|
-
export type DevelopmentConfig = {
|
|
21
|
-
middleware: Array<Middleware>;
|
|
22
|
-
};
|
|
23
|
-
export type Config = {
|
|
24
|
-
modules: Array<Module>;
|
|
25
|
-
client: ClientConfig;
|
|
26
|
-
server: ServerConfig;
|
|
27
|
-
dev: DevelopmentConfig;
|
|
28
|
-
};
|
|
29
|
-
export type App = {
|
|
30
|
-
config: Config;
|
|
31
|
-
virtuals: Record<string, Virtual>;
|
|
32
|
-
};
|
|
33
|
-
export declare function mergeObjects<TBase, TInput>(base: TBase, input: TInput): TBase & TInput;
|
|
34
|
-
export declare function createApp(config?: Mergeable<Config>): App;
|
|
35
|
-
export declare const SERVER = "ssr";
|
|
36
|
-
export declare const CLIENT = "client";
|