vitend 0.0.0 → 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/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/@types/node.d.ts +16 -0
- package/dist/@types/options/complete.d.ts +119 -0
- package/dist/@types/options/default.d.ts +39 -0
- package/dist/@types/server.d.ts +32 -0
- package/dist/_virtual/rolldown_runtime.js +27 -0
- package/dist/functions/define.d.ts +21 -0
- package/dist/functions/define.js +22 -0
- package/dist/functions/define.js.map +1 -0
- package/dist/functions/define.mjs +21 -0
- package/dist/functions/define.mjs.map +1 -0
- package/dist/functions/entry.js +20 -0
- package/dist/functions/entry.js.map +1 -0
- package/dist/functions/entry.mjs +17 -0
- package/dist/functions/entry.mjs.map +1 -0
- package/dist/functions/options.js +30 -0
- package/dist/functions/options.js.map +1 -0
- package/dist/functions/options.mjs +29 -0
- package/dist/functions/options.mjs.map +1 -0
- package/dist/functions/package-json.js +15 -0
- package/dist/functions/package-json.js.map +1 -0
- package/dist/functions/package-json.mjs +12 -0
- package/dist/functions/package-json.mjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.mjs +3 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.js +9 -0
- package/dist/node.mjs +3 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.js +9 -0
- package/dist/runtime.mjs +3 -0
- package/dist/vite/build.js +67 -0
- package/dist/vite/build.js.map +1 -0
- package/dist/vite/build.mjs +66 -0
- package/dist/vite/build.mjs.map +1 -0
- package/dist/vite/dev.js +90 -0
- package/dist/vite/dev.js.map +1 -0
- package/dist/vite/dev.mjs +89 -0
- package/dist/vite/dev.mjs.map +1 -0
- package/dist/vite/vitend.d.ts +23 -0
- package/dist/vite/vitend.js +45 -0
- package/dist/vite/vitend.js.map +1 -0
- package/dist/vite/vitend.mjs +42 -0
- package/dist/vite/vitend.mjs.map +1 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.js +3 -0
- package/dist/vite.mjs +3 -0
- package/package.json +65 -1
- package/justfile +0 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present, Alpheus
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Vitend
|
|
2
|
+
|
|
3
|
+
A library for backend development with Vite.
|
|
4
|
+
|
|
5
|
+
- 🌍 Runtime agnostic
|
|
6
|
+
- 🧩 Seamlessly integrates with different frameworks
|
|
7
|
+
- ⚡️ Vite & srvx ecosystem compatibility
|
|
8
|
+
|
|
9
|
+
Vitend brings a frontend-grade developer experience to backend development. It allows you to focus on backend logic without worrying about compatibility and configuration overhead.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Add the Vitend plugin into the Vite config:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { defineConfig } from "vite";
|
|
17
|
+
import { vitend } from "vitend/vite";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [
|
|
21
|
+
vitend(),
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Export the application:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
export default {
|
|
30
|
+
fetch: (req: Request): Response => {
|
|
31
|
+
switch (new URL(req.url).pathname) {
|
|
32
|
+
case "/":
|
|
33
|
+
return new Response("Hello, World!");
|
|
34
|
+
default:
|
|
35
|
+
return new Response("Not Found", {
|
|
36
|
+
status: 404,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Then run `vite` to start the server.
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
This project is licensed under the terms of the MIT license.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FetchHandler, NodeHttpHandler } from "srvx";
|
|
2
|
+
import { AdapterMeta } from "srvx/node";
|
|
3
|
+
/**
|
|
4
|
+
* Node HTTP handler based on Node.js implementation.
|
|
5
|
+
*/
|
|
6
|
+
type NodeHttpHandler$1 = NodeHttpHandler;
|
|
7
|
+
/**
|
|
8
|
+
* Fetch handler based on Web API.
|
|
9
|
+
*/
|
|
10
|
+
type FetchHandler$1 = FetchHandler;
|
|
11
|
+
/**
|
|
12
|
+
* Adapter meta.
|
|
13
|
+
*/
|
|
14
|
+
type AdapterMeta$1 = AdapterMeta;
|
|
15
|
+
export { type AdapterMeta$1 as AdapterMeta, type FetchHandler$1 as FetchHandler, type NodeHttpHandler$1 as NodeHttpHandler };
|
|
16
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Complete HTTPS server options.
|
|
3
|
+
*/
|
|
4
|
+
type CompleteHttpsOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* File path or inlined TLS certificate in PEM format (required).
|
|
7
|
+
*/
|
|
8
|
+
cert: string;
|
|
9
|
+
/**
|
|
10
|
+
* File path or inlined TLS private key in PEM format (required).
|
|
11
|
+
*/
|
|
12
|
+
key: string;
|
|
13
|
+
/**
|
|
14
|
+
* Passphrase for the private key (optional).
|
|
15
|
+
*/
|
|
16
|
+
passphrase: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Complete development server options.
|
|
20
|
+
*/
|
|
21
|
+
type CompleteDevOptions = {
|
|
22
|
+
/**
|
|
23
|
+
* The host for the development server.
|
|
24
|
+
*
|
|
25
|
+
* By default, it is `localhost`.
|
|
26
|
+
*/
|
|
27
|
+
host: string;
|
|
28
|
+
/**
|
|
29
|
+
* The port number for the development server.
|
|
30
|
+
*
|
|
31
|
+
* By default, it is `3001`.
|
|
32
|
+
*/
|
|
33
|
+
port: number;
|
|
34
|
+
/**
|
|
35
|
+
* HTTPS server options.
|
|
36
|
+
*/
|
|
37
|
+
https: CompleteHttpsOptions;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Complete build server options.
|
|
41
|
+
*/
|
|
42
|
+
type CompleteBuildOptions = {
|
|
43
|
+
/**
|
|
44
|
+
* The host for the production server.
|
|
45
|
+
*
|
|
46
|
+
* By default, it is `localhost`.
|
|
47
|
+
*/
|
|
48
|
+
host: string;
|
|
49
|
+
/**
|
|
50
|
+
* The port number for the production server.
|
|
51
|
+
*
|
|
52
|
+
* By default, it is `3000`.
|
|
53
|
+
*/
|
|
54
|
+
port: number;
|
|
55
|
+
/**
|
|
56
|
+
* HTTPS server options.
|
|
57
|
+
*/
|
|
58
|
+
https: CompleteHttpsOptions;
|
|
59
|
+
/**
|
|
60
|
+
* The output directory for the application.
|
|
61
|
+
*
|
|
62
|
+
* By default, it is `./dist`.
|
|
63
|
+
*/
|
|
64
|
+
outputDir: string;
|
|
65
|
+
/**
|
|
66
|
+
* The output file name for the application.
|
|
67
|
+
*
|
|
68
|
+
* By default, it is `index.js`.
|
|
69
|
+
*/
|
|
70
|
+
outputFile: string;
|
|
71
|
+
/**
|
|
72
|
+
* Whether to minify the output.
|
|
73
|
+
*
|
|
74
|
+
* By default, it is `false`.
|
|
75
|
+
*/
|
|
76
|
+
minify: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* The public directory for the application.
|
|
79
|
+
*
|
|
80
|
+
* By default, it is `./public`.
|
|
81
|
+
*/
|
|
82
|
+
publicDir: string;
|
|
83
|
+
/**
|
|
84
|
+
* Whether to copy the public directory to the output directory.
|
|
85
|
+
*
|
|
86
|
+
* When this is `true`, the public directory will be copied
|
|
87
|
+
* into the directory with same name inside the output directory.
|
|
88
|
+
*
|
|
89
|
+
* By default, it is `false`.
|
|
90
|
+
*/
|
|
91
|
+
copyPublicDir: boolean;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Complete options for the `vitend` plugin.
|
|
95
|
+
*/
|
|
96
|
+
type CompleteVitendOptions = {
|
|
97
|
+
/**
|
|
98
|
+
* The current working directory.
|
|
99
|
+
*
|
|
100
|
+
* By default, it is `process.cwd()`.
|
|
101
|
+
*/
|
|
102
|
+
cwd: string;
|
|
103
|
+
/**
|
|
104
|
+
* The entry file for the application.
|
|
105
|
+
*
|
|
106
|
+
* By default, it is `./src/index.ts` or `./src/index.js`.
|
|
107
|
+
*/
|
|
108
|
+
entry: string;
|
|
109
|
+
/**
|
|
110
|
+
* The options for the development server.
|
|
111
|
+
*/
|
|
112
|
+
dev: CompleteDevOptions;
|
|
113
|
+
/**
|
|
114
|
+
* The options for the production server.
|
|
115
|
+
*/
|
|
116
|
+
build: CompleteBuildOptions;
|
|
117
|
+
};
|
|
118
|
+
export { type CompleteBuildOptions, type CompleteDevOptions, type CompleteHttpsOptions, type CompleteVitendOptions };
|
|
119
|
+
//# sourceMappingURL=complete.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CompleteBuildOptions, CompleteDevOptions, CompleteHttpsOptions, CompleteVitendOptions } from "./complete.js";
|
|
2
|
+
import { Format, Omit, Partial } from "ts-vista";
|
|
3
|
+
/**
|
|
4
|
+
* HTTPS server options.
|
|
5
|
+
*/
|
|
6
|
+
type HttpsOptions = Format<Partial<CompleteHttpsOptions>>;
|
|
7
|
+
/**
|
|
8
|
+
* Development server options.
|
|
9
|
+
*/
|
|
10
|
+
type DevOptions = Format<Partial<Omit<CompleteDevOptions, "https">> & {
|
|
11
|
+
/**
|
|
12
|
+
* HTTPS server options.
|
|
13
|
+
*/
|
|
14
|
+
https?: HttpsOptions;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Build server options.
|
|
18
|
+
*/
|
|
19
|
+
type BuildOptions = Format<Partial<Omit<CompleteBuildOptions, "https">> & {
|
|
20
|
+
/**
|
|
21
|
+
* HTTPS server options.
|
|
22
|
+
*/
|
|
23
|
+
https?: HttpsOptions;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Options for the `vitend` plugin.
|
|
27
|
+
*/
|
|
28
|
+
type VitendOptions = Format<Partial<Omit<CompleteVitendOptions, "dev" | "build">> & {
|
|
29
|
+
/**
|
|
30
|
+
* The options for the development server.
|
|
31
|
+
*/
|
|
32
|
+
dev?: DevOptions;
|
|
33
|
+
/**
|
|
34
|
+
* The options for the production server.
|
|
35
|
+
*/
|
|
36
|
+
build?: BuildOptions;
|
|
37
|
+
}>;
|
|
38
|
+
export { type BuildOptions, type DevOptions, type HttpsOptions, type VitendOptions };
|
|
39
|
+
//# sourceMappingURL=default.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ErrorHandler, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest } from "srvx";
|
|
2
|
+
import { Format, Omit } from "ts-vista";
|
|
3
|
+
/**
|
|
4
|
+
* Server request extended from `Request`.
|
|
5
|
+
*/
|
|
6
|
+
type ServerRequest$1 = ServerRequest;
|
|
7
|
+
/**
|
|
8
|
+
* Server handler based on Web API.
|
|
9
|
+
*/
|
|
10
|
+
type ServerHandler$1 = ServerHandler;
|
|
11
|
+
/**
|
|
12
|
+
* Error handler for the server.
|
|
13
|
+
*/
|
|
14
|
+
type ErrorHandler$1 = ErrorHandler;
|
|
15
|
+
/**
|
|
16
|
+
* Server middleware for extending the server.
|
|
17
|
+
*/
|
|
18
|
+
type ServerMiddleware$1 = ServerMiddleware;
|
|
19
|
+
/**
|
|
20
|
+
* Server type.
|
|
21
|
+
*/
|
|
22
|
+
type Server$1 = Server;
|
|
23
|
+
/**
|
|
24
|
+
* Server plugin for extending the server.
|
|
25
|
+
*/
|
|
26
|
+
type ServerPlugin$1 = ServerPlugin;
|
|
27
|
+
/**
|
|
28
|
+
* Server options.
|
|
29
|
+
*/
|
|
30
|
+
type ServerOptions$1 = Format<Omit<ServerOptions, "manual" | "hostname" | "port" | "protocol" | "tls">>;
|
|
31
|
+
export { type ErrorHandler$1 as ErrorHandler, type Server$1 as Server, type ServerHandler$1 as ServerHandler, type ServerMiddleware$1 as ServerMiddleware, type ServerOptions$1 as ServerOptions, type ServerPlugin$1 as ServerPlugin, type ServerRequest$1 as ServerRequest };
|
|
32
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
+
value: mod,
|
|
23
|
+
enumerable: true
|
|
24
|
+
}) : target, mod));
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
exports.__toESM = __toESM;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ServerOptions } from "../@types/server.js";
|
|
2
|
+
/**
|
|
3
|
+
* A function to define server options.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* // ./src/index.ts
|
|
9
|
+
*
|
|
10
|
+
* import { defineServer } from "vitend";
|
|
11
|
+
*
|
|
12
|
+
* export default defineServer({
|
|
13
|
+
* fetch: (req: Request): Response => {
|
|
14
|
+
* return new Response("Hello, World!");
|
|
15
|
+
* },
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare const defineServer: (options: ServerOptions) => ServerOptions;
|
|
20
|
+
export { defineServer };
|
|
21
|
+
//# sourceMappingURL=define.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* A function to define server options.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* // ./src/index.ts
|
|
9
|
+
*
|
|
10
|
+
* import { defineServer } from "vitend";
|
|
11
|
+
*
|
|
12
|
+
* export default defineServer({
|
|
13
|
+
* fetch: (req: Request): Response => {
|
|
14
|
+
* return new Response("Hello, World!");
|
|
15
|
+
* },
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
const defineServer = (options) => options;
|
|
20
|
+
|
|
21
|
+
exports.defineServer = defineServer;
|
|
22
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","names":[],"sources":["../../src/functions/define.ts"],"sourcesContent":["import type { ServerOptions } from \"#/@types/server\";\n\n/**\n * A function to define server options.\n *\n * ### Example\n *\n * ```ts\n * // ./src/index.ts\n *\n * import { defineServer } from \"vitend\";\n *\n * export default defineServer({\n * fetch: (req: Request): Response => {\n * return new Response(\"Hello, World!\");\n * },\n * });\n * ```\n */\nconst defineServer = (options: ServerOptions): ServerOptions => options;\n\nexport { defineServer };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAM,gBAAgB,YAA0C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function to define server options.
|
|
3
|
+
*
|
|
4
|
+
* ### Example
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* // ./src/index.ts
|
|
8
|
+
*
|
|
9
|
+
* import { defineServer } from "vitend";
|
|
10
|
+
*
|
|
11
|
+
* export default defineServer({
|
|
12
|
+
* fetch: (req: Request): Response => {
|
|
13
|
+
* return new Response("Hello, World!");
|
|
14
|
+
* },
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
const defineServer = (options) => options;
|
|
19
|
+
|
|
20
|
+
export { defineServer };
|
|
21
|
+
//# sourceMappingURL=define.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.mjs","names":[],"sources":["../../src/functions/define.ts"],"sourcesContent":["import type { ServerOptions } from \"#/@types/server\";\n\n/**\n * A function to define server options.\n *\n * ### Example\n *\n * ```ts\n * // ./src/index.ts\n *\n * import { defineServer } from \"vitend\";\n *\n * export default defineServer({\n * fetch: (req: Request): Response => {\n * return new Response(\"Hello, World!\");\n * },\n * });\n * ```\n */\nconst defineServer = (options: ServerOptions): ServerOptions => options;\n\nexport { defineServer };\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,MAAM,gBAAgB,YAA0C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
4
|
+
let node_fs = require("node:fs");
|
|
5
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs);
|
|
6
|
+
|
|
7
|
+
const ENTRY_DEFAULT = ["./src/index.ts", "./src/index.js"];
|
|
8
|
+
const getEntry = (cwd, entry) => {
|
|
9
|
+
if (!entry) {
|
|
10
|
+
for (const ent of ENTRY_DEFAULT) if (node_fs.existsSync(node_path.resolve(cwd, ent))) {
|
|
11
|
+
entry = ent;
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
if (!entry) throw new Error("No entry file found");
|
|
15
|
+
}
|
|
16
|
+
return node_path.resolve(cwd, entry);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.getEntry = getEntry;
|
|
20
|
+
//# sourceMappingURL=entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.js","names":["Fs","Path"],"sources":["../../src/functions/entry.ts"],"sourcesContent":["import * as Fs from \"node:fs\";\nimport * as Path from \"node:path\";\n\nconst ENTRY_DEFAULT: string[] = [\n \"./src/index.ts\",\n \"./src/index.js\",\n];\n\nconst getEntry = (cwd: string, entry?: string): string => {\n if (!entry) {\n for (const ent of ENTRY_DEFAULT) {\n if (Fs.existsSync(Path.resolve(cwd, ent))) {\n entry = ent;\n break;\n }\n }\n\n if (!entry) {\n throw new Error(\"No entry file found\");\n }\n }\n\n return Path.resolve(cwd, entry);\n};\n\nexport { getEntry };\n"],"mappings":";;;;;;AAGA,MAAM,gBAA0B,CAC5B,kBACA,iBACH;AAED,MAAM,YAAY,KAAa,UAA2B;AACtD,KAAI,CAAC,OAAO;AACR,OAAK,MAAM,OAAO,cACd,KAAIA,QAAG,WAAWC,UAAK,QAAQ,KAAK,IAAI,CAAC,EAAE;AACvC,WAAQ;AACR;;AAIR,MAAI,CAAC,MACD,OAAM,IAAI,MAAM,sBAAsB;;AAI9C,QAAOA,UAAK,QAAQ,KAAK,MAAM"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as Path from "node:path";
|
|
2
|
+
import * as Fs from "node:fs";
|
|
3
|
+
|
|
4
|
+
const ENTRY_DEFAULT = ["./src/index.ts", "./src/index.js"];
|
|
5
|
+
const getEntry = (cwd, entry) => {
|
|
6
|
+
if (!entry) {
|
|
7
|
+
for (const ent of ENTRY_DEFAULT) if (Fs.existsSync(Path.resolve(cwd, ent))) {
|
|
8
|
+
entry = ent;
|
|
9
|
+
break;
|
|
10
|
+
}
|
|
11
|
+
if (!entry) throw new Error("No entry file found");
|
|
12
|
+
}
|
|
13
|
+
return Path.resolve(cwd, entry);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { getEntry };
|
|
17
|
+
//# sourceMappingURL=entry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.mjs","names":[],"sources":["../../src/functions/entry.ts"],"sourcesContent":["import * as Fs from \"node:fs\";\nimport * as Path from \"node:path\";\n\nconst ENTRY_DEFAULT: string[] = [\n \"./src/index.ts\",\n \"./src/index.js\",\n];\n\nconst getEntry = (cwd: string, entry?: string): string => {\n if (!entry) {\n for (const ent of ENTRY_DEFAULT) {\n if (Fs.existsSync(Path.resolve(cwd, ent))) {\n entry = ent;\n break;\n }\n }\n\n if (!entry) {\n throw new Error(\"No entry file found\");\n }\n }\n\n return Path.resolve(cwd, entry);\n};\n\nexport { getEntry };\n"],"mappings":";;;AAGA,MAAM,gBAA0B,CAC5B,kBACA,iBACH;AAED,MAAM,YAAY,KAAa,UAA2B;AACtD,KAAI,CAAC,OAAO;AACR,OAAK,MAAM,OAAO,cACd,KAAI,GAAG,WAAW,KAAK,QAAQ,KAAK,IAAI,CAAC,EAAE;AACvC,WAAQ;AACR;;AAIR,MAAI,CAAC,MACD,OAAM,IAAI,MAAM,sBAAsB;;AAI9C,QAAO,KAAK,QAAQ,KAAK,MAAM"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_entry = require('./entry.js');
|
|
3
|
+
let es_toolkit = require("es-toolkit");
|
|
4
|
+
|
|
5
|
+
const OPTIONS_DEFAULT = {
|
|
6
|
+
cwd: process.cwd(),
|
|
7
|
+
dev: {
|
|
8
|
+
host: "localhost",
|
|
9
|
+
port: 3001
|
|
10
|
+
},
|
|
11
|
+
build: {
|
|
12
|
+
host: "localhost",
|
|
13
|
+
port: 3e3,
|
|
14
|
+
outputDir: "./dist",
|
|
15
|
+
outputFile: "index.js",
|
|
16
|
+
minify: false,
|
|
17
|
+
publicDir: "./public",
|
|
18
|
+
copyPublicDir: false
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const createOptions = (options) => {
|
|
22
|
+
const merged = (0, es_toolkit.toMerged)(OPTIONS_DEFAULT, options ?? {});
|
|
23
|
+
return {
|
|
24
|
+
...merged,
|
|
25
|
+
entry: require_entry.getEntry(merged.cwd, options?.entry)
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.createOptions = createOptions;
|
|
30
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","names":["getEntry"],"sources":["../../src/functions/options.ts"],"sourcesContent":["import type { Omit } from \"ts-vista\";\n\nimport type { VitendOptions } from \"#/@types/options/default\";\nimport type { ResolvedVitendOptions } from \"#/@types/options/resolved\";\n\nimport { toMerged } from \"es-toolkit\";\n\nimport { getEntry } from \"#/functions/entry\";\n\nconst OPTIONS_DEFAULT: Omit<ResolvedVitendOptions, \"entry\"> = {\n cwd: process.cwd(),\n dev: {\n host: \"localhost\",\n port: 3001,\n },\n build: {\n host: \"localhost\",\n port: 3000,\n outputDir: \"./dist\",\n outputFile: \"index.js\",\n minify: false,\n publicDir: \"./public\",\n copyPublicDir: false,\n },\n};\n\nconst createOptions = (options?: VitendOptions): ResolvedVitendOptions => {\n const merged = toMerged(OPTIONS_DEFAULT, options ?? {});\n\n return {\n ...merged,\n entry: getEntry(merged.cwd, options?.entry),\n };\n};\n\nexport { createOptions };\n"],"mappings":";;;;AASA,MAAM,kBAAwD;CAC1D,KAAK,QAAQ,KAAK;CAClB,KAAK;EACD,MAAM;EACN,MAAM;EACT;CACD,OAAO;EACH,MAAM;EACN,MAAM;EACN,WAAW;EACX,YAAY;EACZ,QAAQ;EACR,WAAW;EACX,eAAe;EAClB;CACJ;AAED,MAAM,iBAAiB,YAAmD;CACtE,MAAM,kCAAkB,iBAAiB,WAAW,EAAE,CAAC;AAEvD,QAAO;EACH,GAAG;EACH,OAAOA,uBAAS,OAAO,KAAK,SAAS,MAAM;EAC9C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getEntry } from "./entry.mjs";
|
|
2
|
+
import { toMerged } from "es-toolkit";
|
|
3
|
+
|
|
4
|
+
const OPTIONS_DEFAULT = {
|
|
5
|
+
cwd: process.cwd(),
|
|
6
|
+
dev: {
|
|
7
|
+
host: "localhost",
|
|
8
|
+
port: 3001
|
|
9
|
+
},
|
|
10
|
+
build: {
|
|
11
|
+
host: "localhost",
|
|
12
|
+
port: 3e3,
|
|
13
|
+
outputDir: "./dist",
|
|
14
|
+
outputFile: "index.js",
|
|
15
|
+
minify: false,
|
|
16
|
+
publicDir: "./public",
|
|
17
|
+
copyPublicDir: false
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const createOptions = (options) => {
|
|
21
|
+
const merged = toMerged(OPTIONS_DEFAULT, options ?? {});
|
|
22
|
+
return {
|
|
23
|
+
...merged,
|
|
24
|
+
entry: getEntry(merged.cwd, options?.entry)
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { createOptions };
|
|
29
|
+
//# sourceMappingURL=options.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.mjs","names":[],"sources":["../../src/functions/options.ts"],"sourcesContent":["import type { Omit } from \"ts-vista\";\n\nimport type { VitendOptions } from \"#/@types/options/default\";\nimport type { ResolvedVitendOptions } from \"#/@types/options/resolved\";\n\nimport { toMerged } from \"es-toolkit\";\n\nimport { getEntry } from \"#/functions/entry\";\n\nconst OPTIONS_DEFAULT: Omit<ResolvedVitendOptions, \"entry\"> = {\n cwd: process.cwd(),\n dev: {\n host: \"localhost\",\n port: 3001,\n },\n build: {\n host: \"localhost\",\n port: 3000,\n outputDir: \"./dist\",\n outputFile: \"index.js\",\n minify: false,\n publicDir: \"./public\",\n copyPublicDir: false,\n },\n};\n\nconst createOptions = (options?: VitendOptions): ResolvedVitendOptions => {\n const merged = toMerged(OPTIONS_DEFAULT, options ?? {});\n\n return {\n ...merged,\n entry: getEntry(merged.cwd, options?.entry),\n };\n};\n\nexport { createOptions };\n"],"mappings":";;;AASA,MAAM,kBAAwD;CAC1D,KAAK,QAAQ,KAAK;CAClB,KAAK;EACD,MAAM;EACN,MAAM;EACT;CACD,OAAO;EACH,MAAM;EACN,MAAM;EACN,WAAW;EACX,YAAY;EACZ,QAAQ;EACR,WAAW;EACX,eAAe;EAClB;CACJ;AAED,MAAM,iBAAiB,YAAmD;CACtE,MAAM,SAAS,SAAS,iBAAiB,WAAW,EAAE,CAAC;AAEvD,QAAO;EACH,GAAG;EACH,OAAO,SAAS,OAAO,KAAK,SAAS,MAAM;EAC9C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
4
|
+
let node_fs = require("node:fs");
|
|
5
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs);
|
|
6
|
+
|
|
7
|
+
const getPackageJson = (cwd) => {
|
|
8
|
+
const path = node_path.resolve(cwd, "package.json");
|
|
9
|
+
if (!node_fs.existsSync(path)) throw new Error("Failed to find package.json");
|
|
10
|
+
const rawPackageJson = node_fs.readFileSync(path, "utf-8");
|
|
11
|
+
return JSON.parse(rawPackageJson);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.getPackageJson = getPackageJson;
|
|
15
|
+
//# sourceMappingURL=package-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json.js","names":["Path","Fs"],"sources":["../../src/functions/package-json.ts"],"sourcesContent":["import type { Format, Partial } from \"ts-vista\";\n\nimport * as Fs from \"node:fs\";\nimport * as Path from \"node:path\";\n\ntype CompletePackageJson = {\n type: \"module\" | \"commonjs\";\n dependencies: Record<string, string>;\n devDependencies: Record<string, string>;\n peerDependencies: Record<string, string>;\n};\n\ntype PackageJson = Format<Partial<CompletePackageJson>>;\n\nconst getPackageJson = (cwd: string): PackageJson => {\n const path: string = Path.resolve(cwd, \"package.json\");\n\n if (!Fs.existsSync(path)) {\n throw new Error(\"Failed to find package.json\");\n }\n\n const rawPackageJson: string = Fs.readFileSync(path, \"utf-8\");\n\n return JSON.parse(rawPackageJson);\n};\n\nexport type { CompletePackageJson, PackageJson };\nexport { getPackageJson };\n"],"mappings":";;;;;;AAcA,MAAM,kBAAkB,QAA6B;CACjD,MAAM,OAAeA,UAAK,QAAQ,KAAK,eAAe;AAEtD,KAAI,CAACC,QAAG,WAAW,KAAK,CACpB,OAAM,IAAI,MAAM,8BAA8B;CAGlD,MAAM,iBAAyBA,QAAG,aAAa,MAAM,QAAQ;AAE7D,QAAO,KAAK,MAAM,eAAe"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as Path from "node:path";
|
|
2
|
+
import * as Fs from "node:fs";
|
|
3
|
+
|
|
4
|
+
const getPackageJson = (cwd) => {
|
|
5
|
+
const path = Path.resolve(cwd, "package.json");
|
|
6
|
+
if (!Fs.existsSync(path)) throw new Error("Failed to find package.json");
|
|
7
|
+
const rawPackageJson = Fs.readFileSync(path, "utf-8");
|
|
8
|
+
return JSON.parse(rawPackageJson);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { getPackageJson };
|
|
12
|
+
//# sourceMappingURL=package-json.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json.mjs","names":[],"sources":["../../src/functions/package-json.ts"],"sourcesContent":["import type { Format, Partial } from \"ts-vista\";\n\nimport * as Fs from \"node:fs\";\nimport * as Path from \"node:path\";\n\ntype CompletePackageJson = {\n type: \"module\" | \"commonjs\";\n dependencies: Record<string, string>;\n devDependencies: Record<string, string>;\n peerDependencies: Record<string, string>;\n};\n\ntype PackageJson = Format<Partial<CompletePackageJson>>;\n\nconst getPackageJson = (cwd: string): PackageJson => {\n const path: string = Path.resolve(cwd, \"package.json\");\n\n if (!Fs.existsSync(path)) {\n throw new Error(\"Failed to find package.json\");\n }\n\n const rawPackageJson: string = Fs.readFileSync(path, \"utf-8\");\n\n return JSON.parse(rawPackageJson);\n};\n\nexport type { CompletePackageJson, PackageJson };\nexport { getPackageJson };\n"],"mappings":";;;AAcA,MAAM,kBAAkB,QAA6B;CACjD,MAAM,OAAe,KAAK,QAAQ,KAAK,eAAe;AAEtD,KAAI,CAAC,GAAG,WAAW,KAAK,CACpB,OAAM,IAAI,MAAM,8BAA8B;CAGlD,MAAM,iBAAyB,GAAG,aAAa,MAAM,QAAQ;AAE7D,QAAO,KAAK,MAAM,eAAe"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ErrorHandler, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest } from "./@types/server.js";
|
|
2
|
+
import { defineServer } from "./functions/define.js";
|
|
3
|
+
export { type ErrorHandler, type Server, type ServerHandler, type ServerMiddleware, type ServerOptions, type ServerPlugin, type ServerRequest, defineServer };
|
package/dist/index.js
ADDED
package/dist/index.mjs
ADDED
package/dist/node.d.ts
ADDED
package/dist/node.js
ADDED
package/dist/node.mjs
ADDED
package/dist/runtime.js
ADDED
package/dist/runtime.mjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_package_json = require('../functions/package-json.js');
|
|
3
|
+
let es_toolkit = require("es-toolkit");
|
|
4
|
+
let node_module = require("node:module");
|
|
5
|
+
|
|
6
|
+
const VIRTUAL_ENTRY = "virtual:vitend-entry";
|
|
7
|
+
const VIRTUAL_ENTRY_RESOLVED = `\0${VIRTUAL_ENTRY}`;
|
|
8
|
+
const buildPlugin = (opts) => {
|
|
9
|
+
const build = opts.build;
|
|
10
|
+
const packageJson = require_package_json.getPackageJson(opts.cwd);
|
|
11
|
+
return {
|
|
12
|
+
name: "vitend/build",
|
|
13
|
+
apply: "build",
|
|
14
|
+
config: (config) => {
|
|
15
|
+
let result = {};
|
|
16
|
+
result = (0, es_toolkit.toMerged)({
|
|
17
|
+
ssr: {
|
|
18
|
+
external: true,
|
|
19
|
+
noExternal: void 0,
|
|
20
|
+
target: "webworker"
|
|
21
|
+
},
|
|
22
|
+
build: { copyPublicDir: false }
|
|
23
|
+
}, config);
|
|
24
|
+
const overrideConfig = { build: {
|
|
25
|
+
ssr: true,
|
|
26
|
+
outDir: build.outputDir,
|
|
27
|
+
rollupOptions: {
|
|
28
|
+
input: VIRTUAL_ENTRY,
|
|
29
|
+
output: {
|
|
30
|
+
entryFileNames: build.outputFile,
|
|
31
|
+
format: packageJson.type === "module" ? "esm" : "cjs"
|
|
32
|
+
},
|
|
33
|
+
external: [...node_module.builtinModules, /^node:/]
|
|
34
|
+
},
|
|
35
|
+
minify: build.minify
|
|
36
|
+
} };
|
|
37
|
+
result = (0, es_toolkit.toMerged)(result, overrideConfig);
|
|
38
|
+
return result;
|
|
39
|
+
},
|
|
40
|
+
resolveId: (id) => {
|
|
41
|
+
if (id !== VIRTUAL_ENTRY) return void 0;
|
|
42
|
+
return VIRTUAL_ENTRY_RESOLVED;
|
|
43
|
+
},
|
|
44
|
+
load: async (id) => {
|
|
45
|
+
if (id !== VIRTUAL_ENTRY_RESOLVED) return void 0;
|
|
46
|
+
let code = "";
|
|
47
|
+
code += `import app from "${opts.entry}";`;
|
|
48
|
+
code += `import { serve } from "vitend/runtime";`;
|
|
49
|
+
code += `serve({`;
|
|
50
|
+
code += `...app,`;
|
|
51
|
+
if (build.host !== "localhost") code += `hostname: "${build.host}",`;
|
|
52
|
+
if (build.port !== 3e3) code += `port: ${build.port},`;
|
|
53
|
+
if (build.https) {
|
|
54
|
+
code += `tls: {`;
|
|
55
|
+
if (build.https.cert) code += `cert: "${build.https.cert}",`;
|
|
56
|
+
if (build.https.key) code += `key: "${build.https.key}",`;
|
|
57
|
+
if (build.https.passphrase) code += `passphrase: "${build.https.passphrase}",`;
|
|
58
|
+
code += `},`;
|
|
59
|
+
}
|
|
60
|
+
code += `});`;
|
|
61
|
+
return code;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
exports.buildPlugin = buildPlugin;
|
|
67
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","names":["getPackageJson","builtinModules"],"sources":["../../src/vite/build.ts"],"sourcesContent":["import type { LoadResult, ResolveIdResult } from \"rollup\";\nimport type { Plugin, UserConfig } from \"vite\";\n\nimport type {\n ResolvedBuildOptions,\n ResolvedVitendOptions,\n} from \"#/@types/options/resolved\";\nimport type { PackageJson } from \"#/functions/package-json\";\n\nimport { builtinModules } from \"node:module\";\n\nimport { toMerged } from \"es-toolkit\";\n\nimport { getPackageJson } from \"#/functions/package-json\";\n\nconst VIRTUAL_ENTRY = \"virtual:vitend-entry\" as const;\n\nconst VIRTUAL_ENTRY_RESOLVED = `\\0${VIRTUAL_ENTRY}` as const;\n\nconst buildPlugin = (opts: ResolvedVitendOptions): Plugin => {\n const build: ResolvedBuildOptions = opts.build;\n\n const packageJson: PackageJson = getPackageJson(opts.cwd);\n\n return {\n name: \"vitend/build\",\n apply: \"build\",\n config: (config: UserConfig): UserConfig => {\n let result: UserConfig = {};\n\n const baseConfig: UserConfig = {\n ssr: {\n external: true,\n noExternal: void 0,\n target: \"webworker\",\n },\n build: {\n copyPublicDir: false,\n },\n };\n\n result = toMerged(baseConfig, config);\n\n const overrideConfig: UserConfig = {\n build: {\n ssr: true,\n outDir: build.outputDir,\n rollupOptions: {\n input: VIRTUAL_ENTRY,\n output: {\n entryFileNames: build.outputFile,\n format:\n packageJson.type === \"module\" ? \"esm\" : \"cjs\",\n },\n external: [\n ...builtinModules,\n /^node:/,\n ],\n },\n minify: build.minify,\n },\n };\n\n result = toMerged(result, overrideConfig);\n\n return result;\n },\n resolveId: (id: string): ResolveIdResult => {\n if (id !== VIRTUAL_ENTRY) return void 0;\n return VIRTUAL_ENTRY_RESOLVED;\n },\n load: async (id: string): Promise<LoadResult> => {\n if (id !== VIRTUAL_ENTRY_RESOLVED) return void 0;\n\n let code: string = \"\";\n\n code += `import app from \"${opts.entry}\";`;\n code += `import { serve } from \"vitend/runtime\";`;\n code += `serve({`;\n code += `...app,`;\n\n if (build.host !== \"localhost\")\n code += `hostname: \"${build.host}\",`;\n if (build.port !== 3000) code += `port: ${build.port},`;\n\n if (build.https) {\n code += `tls: {`;\n if (build.https.cert) code += `cert: \"${build.https.cert}\",`;\n if (build.https.key) code += `key: \"${build.https.key}\",`;\n if (build.https.passphrase)\n code += `passphrase: \"${build.https.passphrase}\",`;\n code += `},`;\n }\n\n code += `});`;\n\n return code;\n },\n };\n};\n\nexport { buildPlugin };\n"],"mappings":";;;;;AAeA,MAAM,gBAAgB;AAEtB,MAAM,yBAAyB,KAAK;AAEpC,MAAM,eAAe,SAAwC;CACzD,MAAM,QAA8B,KAAK;CAEzC,MAAM,cAA2BA,oCAAe,KAAK,IAAI;AAEzD,QAAO;EACH,MAAM;EACN,OAAO;EACP,SAAS,WAAmC;GACxC,IAAI,SAAqB,EAAE;AAa3B,qCAX+B;IAC3B,KAAK;KACD,UAAU;KACV,YAAY,KAAK;KACjB,QAAQ;KACX;IACD,OAAO,EACH,eAAe,OAClB;IACJ,EAE6B,OAAO;GAErC,MAAM,iBAA6B,EAC/B,OAAO;IACH,KAAK;IACL,QAAQ,MAAM;IACd,eAAe;KACX,OAAO;KACP,QAAQ;MACJ,gBAAgB,MAAM;MACtB,QACI,YAAY,SAAS,WAAW,QAAQ;MAC/C;KACD,UAAU,CACN,GAAGC,4BACH,SACH;KACJ;IACD,QAAQ,MAAM;IACjB,EACJ;AAED,qCAAkB,QAAQ,eAAe;AAEzC,UAAO;;EAEX,YAAY,OAAgC;AACxC,OAAI,OAAO,cAAe,QAAO,KAAK;AACtC,UAAO;;EAEX,MAAM,OAAO,OAAoC;AAC7C,OAAI,OAAO,uBAAwB,QAAO,KAAK;GAE/C,IAAI,OAAe;AAEnB,WAAQ,oBAAoB,KAAK,MAAM;AACvC,WAAQ;AACR,WAAQ;AACR,WAAQ;AAER,OAAI,MAAM,SAAS,YACf,SAAQ,cAAc,MAAM,KAAK;AACrC,OAAI,MAAM,SAAS,IAAM,SAAQ,SAAS,MAAM,KAAK;AAErD,OAAI,MAAM,OAAO;AACb,YAAQ;AACR,QAAI,MAAM,MAAM,KAAM,SAAQ,UAAU,MAAM,MAAM,KAAK;AACzD,QAAI,MAAM,MAAM,IAAK,SAAQ,SAAS,MAAM,MAAM,IAAI;AACtD,QAAI,MAAM,MAAM,WACZ,SAAQ,gBAAgB,MAAM,MAAM,WAAW;AACnD,YAAQ;;AAGZ,WAAQ;AAER,UAAO;;EAEd"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { getPackageJson } from "../functions/package-json.mjs";
|
|
2
|
+
import { builtinModules } from "node:module";
|
|
3
|
+
import { toMerged } from "es-toolkit";
|
|
4
|
+
|
|
5
|
+
const VIRTUAL_ENTRY = "virtual:vitend-entry";
|
|
6
|
+
const VIRTUAL_ENTRY_RESOLVED = `\0${VIRTUAL_ENTRY}`;
|
|
7
|
+
const buildPlugin = (opts) => {
|
|
8
|
+
const build = opts.build;
|
|
9
|
+
const packageJson = getPackageJson(opts.cwd);
|
|
10
|
+
return {
|
|
11
|
+
name: "vitend/build",
|
|
12
|
+
apply: "build",
|
|
13
|
+
config: (config) => {
|
|
14
|
+
let result = {};
|
|
15
|
+
result = toMerged({
|
|
16
|
+
ssr: {
|
|
17
|
+
external: true,
|
|
18
|
+
noExternal: void 0,
|
|
19
|
+
target: "webworker"
|
|
20
|
+
},
|
|
21
|
+
build: { copyPublicDir: false }
|
|
22
|
+
}, config);
|
|
23
|
+
const overrideConfig = { build: {
|
|
24
|
+
ssr: true,
|
|
25
|
+
outDir: build.outputDir,
|
|
26
|
+
rollupOptions: {
|
|
27
|
+
input: VIRTUAL_ENTRY,
|
|
28
|
+
output: {
|
|
29
|
+
entryFileNames: build.outputFile,
|
|
30
|
+
format: packageJson.type === "module" ? "esm" : "cjs"
|
|
31
|
+
},
|
|
32
|
+
external: [...builtinModules, /^node:/]
|
|
33
|
+
},
|
|
34
|
+
minify: build.minify
|
|
35
|
+
} };
|
|
36
|
+
result = toMerged(result, overrideConfig);
|
|
37
|
+
return result;
|
|
38
|
+
},
|
|
39
|
+
resolveId: (id) => {
|
|
40
|
+
if (id !== VIRTUAL_ENTRY) return void 0;
|
|
41
|
+
return VIRTUAL_ENTRY_RESOLVED;
|
|
42
|
+
},
|
|
43
|
+
load: async (id) => {
|
|
44
|
+
if (id !== VIRTUAL_ENTRY_RESOLVED) return void 0;
|
|
45
|
+
let code = "";
|
|
46
|
+
code += `import app from "${opts.entry}";`;
|
|
47
|
+
code += `import { serve } from "vitend/runtime";`;
|
|
48
|
+
code += `serve({`;
|
|
49
|
+
code += `...app,`;
|
|
50
|
+
if (build.host !== "localhost") code += `hostname: "${build.host}",`;
|
|
51
|
+
if (build.port !== 3e3) code += `port: ${build.port},`;
|
|
52
|
+
if (build.https) {
|
|
53
|
+
code += `tls: {`;
|
|
54
|
+
if (build.https.cert) code += `cert: "${build.https.cert}",`;
|
|
55
|
+
if (build.https.key) code += `key: "${build.https.key}",`;
|
|
56
|
+
if (build.https.passphrase) code += `passphrase: "${build.https.passphrase}",`;
|
|
57
|
+
code += `},`;
|
|
58
|
+
}
|
|
59
|
+
code += `});`;
|
|
60
|
+
return code;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { buildPlugin };
|
|
66
|
+
//# sourceMappingURL=build.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.mjs","names":[],"sources":["../../src/vite/build.ts"],"sourcesContent":["import type { LoadResult, ResolveIdResult } from \"rollup\";\nimport type { Plugin, UserConfig } from \"vite\";\n\nimport type {\n ResolvedBuildOptions,\n ResolvedVitendOptions,\n} from \"#/@types/options/resolved\";\nimport type { PackageJson } from \"#/functions/package-json\";\n\nimport { builtinModules } from \"node:module\";\n\nimport { toMerged } from \"es-toolkit\";\n\nimport { getPackageJson } from \"#/functions/package-json\";\n\nconst VIRTUAL_ENTRY = \"virtual:vitend-entry\" as const;\n\nconst VIRTUAL_ENTRY_RESOLVED = `\\0${VIRTUAL_ENTRY}` as const;\n\nconst buildPlugin = (opts: ResolvedVitendOptions): Plugin => {\n const build: ResolvedBuildOptions = opts.build;\n\n const packageJson: PackageJson = getPackageJson(opts.cwd);\n\n return {\n name: \"vitend/build\",\n apply: \"build\",\n config: (config: UserConfig): UserConfig => {\n let result: UserConfig = {};\n\n const baseConfig: UserConfig = {\n ssr: {\n external: true,\n noExternal: void 0,\n target: \"webworker\",\n },\n build: {\n copyPublicDir: false,\n },\n };\n\n result = toMerged(baseConfig, config);\n\n const overrideConfig: UserConfig = {\n build: {\n ssr: true,\n outDir: build.outputDir,\n rollupOptions: {\n input: VIRTUAL_ENTRY,\n output: {\n entryFileNames: build.outputFile,\n format:\n packageJson.type === \"module\" ? \"esm\" : \"cjs\",\n },\n external: [\n ...builtinModules,\n /^node:/,\n ],\n },\n minify: build.minify,\n },\n };\n\n result = toMerged(result, overrideConfig);\n\n return result;\n },\n resolveId: (id: string): ResolveIdResult => {\n if (id !== VIRTUAL_ENTRY) return void 0;\n return VIRTUAL_ENTRY_RESOLVED;\n },\n load: async (id: string): Promise<LoadResult> => {\n if (id !== VIRTUAL_ENTRY_RESOLVED) return void 0;\n\n let code: string = \"\";\n\n code += `import app from \"${opts.entry}\";`;\n code += `import { serve } from \"vitend/runtime\";`;\n code += `serve({`;\n code += `...app,`;\n\n if (build.host !== \"localhost\")\n code += `hostname: \"${build.host}\",`;\n if (build.port !== 3000) code += `port: ${build.port},`;\n\n if (build.https) {\n code += `tls: {`;\n if (build.https.cert) code += `cert: \"${build.https.cert}\",`;\n if (build.https.key) code += `key: \"${build.https.key}\",`;\n if (build.https.passphrase)\n code += `passphrase: \"${build.https.passphrase}\",`;\n code += `},`;\n }\n\n code += `});`;\n\n return code;\n },\n };\n};\n\nexport { buildPlugin };\n"],"mappings":";;;;AAeA,MAAM,gBAAgB;AAEtB,MAAM,yBAAyB,KAAK;AAEpC,MAAM,eAAe,SAAwC;CACzD,MAAM,QAA8B,KAAK;CAEzC,MAAM,cAA2B,eAAe,KAAK,IAAI;AAEzD,QAAO;EACH,MAAM;EACN,OAAO;EACP,SAAS,WAAmC;GACxC,IAAI,SAAqB,EAAE;AAa3B,YAAS,SAXsB;IAC3B,KAAK;KACD,UAAU;KACV,YAAY,KAAK;KACjB,QAAQ;KACX;IACD,OAAO,EACH,eAAe,OAClB;IACJ,EAE6B,OAAO;GAErC,MAAM,iBAA6B,EAC/B,OAAO;IACH,KAAK;IACL,QAAQ,MAAM;IACd,eAAe;KACX,OAAO;KACP,QAAQ;MACJ,gBAAgB,MAAM;MACtB,QACI,YAAY,SAAS,WAAW,QAAQ;MAC/C;KACD,UAAU,CACN,GAAG,gBACH,SACH;KACJ;IACD,QAAQ,MAAM;IACjB,EACJ;AAED,YAAS,SAAS,QAAQ,eAAe;AAEzC,UAAO;;EAEX,YAAY,OAAgC;AACxC,OAAI,OAAO,cAAe,QAAO,KAAK;AACtC,UAAO;;EAEX,MAAM,OAAO,OAAoC;AAC7C,OAAI,OAAO,uBAAwB,QAAO,KAAK;GAE/C,IAAI,OAAe;AAEnB,WAAQ,oBAAoB,KAAK,MAAM;AACvC,WAAQ;AACR,WAAQ;AACR,WAAQ;AAER,OAAI,MAAM,SAAS,YACf,SAAQ,cAAc,MAAM,KAAK;AACrC,OAAI,MAAM,SAAS,IAAM,SAAQ,SAAS,MAAM,KAAK;AAErD,OAAI,MAAM,OAAO;AACb,YAAQ;AACR,QAAI,MAAM,MAAM,KAAM,SAAQ,UAAU,MAAM,MAAM,KAAK;AACzD,QAAI,MAAM,MAAM,IAAK,SAAQ,SAAS,MAAM,MAAM,IAAI;AACtD,QAAI,MAAM,MAAM,WACZ,SAAQ,gBAAgB,MAAM,MAAM,WAAW;AACnD,YAAQ;;AAGZ,WAAQ;AAER,UAAO;;EAEd"}
|
package/dist/vite/dev.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
+
let es_toolkit = require("es-toolkit");
|
|
3
|
+
let srvx = require("srvx");
|
|
4
|
+
|
|
5
|
+
const createMiddleware = ({ vite, server }) => {
|
|
6
|
+
return async (req, res, _next) => {
|
|
7
|
+
const protocol = `http${vite.config.server.https !== void 0 ? "s" : ""}`;
|
|
8
|
+
const host = process.env.HOST ?? "localhost";
|
|
9
|
+
const port = vite.config.server.port;
|
|
10
|
+
const path = req.url ?? "";
|
|
11
|
+
const url = new URL(`${protocol}://${host}:${port}${path}`);
|
|
12
|
+
const body = req.method !== "GET" && req.method !== "HEAD" ? req : void 0;
|
|
13
|
+
const request = new Request(url, {
|
|
14
|
+
method: req.method,
|
|
15
|
+
headers: req.headers,
|
|
16
|
+
body,
|
|
17
|
+
duplex: "half"
|
|
18
|
+
});
|
|
19
|
+
const response = await server.fetch(request);
|
|
20
|
+
res.statusCode = response.status;
|
|
21
|
+
response.headers.forEach((value, key) => {
|
|
22
|
+
res.setHeader(key, value);
|
|
23
|
+
});
|
|
24
|
+
if (!response.body) {
|
|
25
|
+
res.end();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const reader = response.body.getReader();
|
|
29
|
+
const stream = async () => {
|
|
30
|
+
try {
|
|
31
|
+
while (true) {
|
|
32
|
+
const { done, value } = await reader.read();
|
|
33
|
+
if (done) break;
|
|
34
|
+
res.write(value);
|
|
35
|
+
}
|
|
36
|
+
res.end();
|
|
37
|
+
} catch {
|
|
38
|
+
res.end();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
await stream();
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const devPlugin = (opts) => {
|
|
45
|
+
const dev = opts.dev;
|
|
46
|
+
const https = opts.dev.https ?? {};
|
|
47
|
+
return {
|
|
48
|
+
name: "vitend/dev",
|
|
49
|
+
apply: "serve",
|
|
50
|
+
config(config) {
|
|
51
|
+
return (0, es_toolkit.toMerged)(config, {
|
|
52
|
+
build: {
|
|
53
|
+
ssr: true,
|
|
54
|
+
rollupOptions: { input: opts.entry }
|
|
55
|
+
},
|
|
56
|
+
server: {
|
|
57
|
+
host: dev.host,
|
|
58
|
+
port: dev.port,
|
|
59
|
+
https: {
|
|
60
|
+
cert: https.cert,
|
|
61
|
+
key: https.key,
|
|
62
|
+
passphrase: https.passphrase
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
configureServer: async (vite) => {
|
|
68
|
+
const serverOptions = (await vite.ssrLoadModule(opts.entry)).default;
|
|
69
|
+
const middleware = createMiddleware({
|
|
70
|
+
vite,
|
|
71
|
+
server: (0, srvx.serve)({
|
|
72
|
+
gracefulShutdown: false,
|
|
73
|
+
...serverOptions,
|
|
74
|
+
manual: true,
|
|
75
|
+
hostname: dev.host,
|
|
76
|
+
port: dev.port,
|
|
77
|
+
tls: {
|
|
78
|
+
cert: https.cert,
|
|
79
|
+
key: https.key,
|
|
80
|
+
passphrase: https.passphrase
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
});
|
|
84
|
+
vite.middlewares.use(middleware);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
exports.devPlugin = devPlugin;
|
|
90
|
+
//# sourceMappingURL=dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.js","names":[],"sources":["../../src/vite/dev.ts"],"sourcesContent":["import type HTTP from \"node:http\";\n\nimport type { Server, ServerHandler, ServerOptions } from \"srvx\";\nimport type { Connect, Plugin, UserConfig, ViteDevServer } from \"vite\";\n\nimport type {\n ResolvedDevOptions,\n ResolvedHttpsOptions,\n ResolvedVitendOptions,\n} from \"#/@types/options/resolved\";\n\nimport { toMerged } from \"es-toolkit\";\nimport { serve } from \"srvx\";\n\ntype CreateMiddlewareOptions = {\n vite: ViteDevServer;\n server: Server;\n};\n\nconst createMiddleware = ({ vite, server }: CreateMiddlewareOptions) => {\n return async (\n req: Connect.IncomingMessage,\n res: HTTP.ServerResponse,\n _next: Connect.NextFunction,\n ): Promise<void> => {\n const isHttps: boolean = vite.config.server.https !== undefined;\n\n const protocol: string = `http${isHttps ? \"s\" : \"\"}`;\n\n const host: string = process.env.HOST ?? \"localhost\";\n\n const port: number = vite.config.server.port;\n\n const path: string = req.url ?? \"\";\n\n const url: URL = new URL(`${protocol}://${host}:${port}${path}`);\n\n const body: Connect.IncomingMessage | undefined =\n req.method !== \"GET\" && req.method !== \"HEAD\" ? req : void 0;\n\n const request: Request = new Request(url, {\n method: req.method,\n headers: req.headers,\n body,\n duplex: \"half\",\n } as RequestInit);\n\n const response: Response = await server.fetch(request);\n\n res.statusCode = response.status;\n\n response.headers.forEach((value: string, key: string): void => {\n res.setHeader(key, value);\n });\n\n if (!response.body) {\n res.end();\n return void 0;\n }\n\n const reader: ReadableStreamDefaultReader<Uint8Array<ArrayBuffer>> =\n response.body.getReader();\n\n const stream = async (): Promise<void> => {\n try {\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) break;\n\n res.write(value);\n }\n\n res.end();\n } catch {\n res.end();\n }\n };\n\n await stream();\n };\n};\n\ntype Middleware = ReturnType<typeof createMiddleware>;\n\nconst devPlugin = (opts: ResolvedVitendOptions): Plugin => {\n const dev: ResolvedDevOptions = opts.dev;\n const https: ResolvedHttpsOptions = opts.dev.https ?? {};\n\n return {\n name: \"vitend/dev\",\n apply: \"serve\",\n config(config: UserConfig): UserConfig {\n const devConfig: UserConfig = {\n build: {\n ssr: true,\n rollupOptions: {\n input: opts.entry,\n },\n },\n server: {\n host: dev.host,\n port: dev.port,\n https: {\n cert: https.cert,\n key: https.key,\n passphrase: https.passphrase,\n },\n },\n };\n\n return toMerged(config, devConfig);\n },\n configureServer: async (vite: ViteDevServer): Promise<void> => {\n const serverOptions: ServerOptions = (\n await vite.ssrLoadModule(opts.entry)\n ).default;\n\n const server: Server<ServerHandler> = serve({\n // base\n gracefulShutdown: false,\n // user\n ...serverOptions,\n // override\n manual: true,\n hostname: dev.host,\n port: dev.port,\n tls: {\n cert: https.cert,\n key: https.key,\n passphrase: https.passphrase,\n },\n });\n\n const middleware: Middleware = createMiddleware({\n vite,\n server,\n });\n\n vite.middlewares.use(middleware);\n },\n };\n};\n\nexport { devPlugin };\n"],"mappings":";;;;AAmBA,MAAM,oBAAoB,EAAE,MAAM,aAAsC;AACpE,QAAO,OACH,KACA,KACA,UACgB;EAGhB,MAAM,WAAmB,OAFA,KAAK,OAAO,OAAO,UAAU,SAEZ,MAAM;EAEhD,MAAM,OAAe,QAAQ,IAAI,QAAQ;EAEzC,MAAM,OAAe,KAAK,OAAO,OAAO;EAExC,MAAM,OAAe,IAAI,OAAO;EAEhC,MAAM,MAAW,IAAI,IAAI,GAAG,SAAS,KAAK,KAAK,GAAG,OAAO,OAAO;EAEhE,MAAM,OACF,IAAI,WAAW,SAAS,IAAI,WAAW,SAAS,MAAM,KAAK;EAE/D,MAAM,UAAmB,IAAI,QAAQ,KAAK;GACtC,QAAQ,IAAI;GACZ,SAAS,IAAI;GACb;GACA,QAAQ;GACX,CAAgB;EAEjB,MAAM,WAAqB,MAAM,OAAO,MAAM,QAAQ;AAEtD,MAAI,aAAa,SAAS;AAE1B,WAAS,QAAQ,SAAS,OAAe,QAAsB;AAC3D,OAAI,UAAU,KAAK,MAAM;IAC3B;AAEF,MAAI,CAAC,SAAS,MAAM;AAChB,OAAI,KAAK;AACT;;EAGJ,MAAM,SACF,SAAS,KAAK,WAAW;EAE7B,MAAM,SAAS,YAA2B;AACtC,OAAI;AACA,WAAO,MAAM;KACT,MAAM,EAAE,MAAM,UAAU,MAAM,OAAO,MAAM;AAE3C,SAAI,KAAM;AAEV,SAAI,MAAM,MAAM;;AAGpB,QAAI,KAAK;WACL;AACJ,QAAI,KAAK;;;AAIjB,QAAM,QAAQ;;;AAMtB,MAAM,aAAa,SAAwC;CACvD,MAAM,MAA0B,KAAK;CACrC,MAAM,QAA8B,KAAK,IAAI,SAAS,EAAE;AAExD,QAAO;EACH,MAAM;EACN,OAAO;EACP,OAAO,QAAgC;AAmBnC,mCAAgB,QAlBc;IAC1B,OAAO;KACH,KAAK;KACL,eAAe,EACX,OAAO,KAAK,OACf;KACJ;IACD,QAAQ;KACJ,MAAM,IAAI;KACV,MAAM,IAAI;KACV,OAAO;MACH,MAAM,MAAM;MACZ,KAAK,MAAM;MACX,YAAY,MAAM;MACrB;KACJ;IACJ,CAEiC;;EAEtC,iBAAiB,OAAO,SAAuC;GAC3D,MAAM,iBACF,MAAM,KAAK,cAAc,KAAK,MAAM,EACtC;GAkBF,MAAM,aAAyB,iBAAiB;IAC5C;IACA,wBAlBwC;KAExC,kBAAkB;KAElB,GAAG;KAEH,QAAQ;KACR,UAAU,IAAI;KACd,MAAM,IAAI;KACV,KAAK;MACD,MAAM,MAAM;MACZ,KAAK,MAAM;MACX,YAAY,MAAM;MACrB;KACJ,CAAC;IAKD,CAAC;AAEF,QAAK,YAAY,IAAI,WAAW;;EAEvC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { toMerged } from "es-toolkit";
|
|
2
|
+
import { serve } from "srvx";
|
|
3
|
+
|
|
4
|
+
const createMiddleware = ({ vite, server }) => {
|
|
5
|
+
return async (req, res, _next) => {
|
|
6
|
+
const protocol = `http${vite.config.server.https !== void 0 ? "s" : ""}`;
|
|
7
|
+
const host = process.env.HOST ?? "localhost";
|
|
8
|
+
const port = vite.config.server.port;
|
|
9
|
+
const path = req.url ?? "";
|
|
10
|
+
const url = new URL(`${protocol}://${host}:${port}${path}`);
|
|
11
|
+
const body = req.method !== "GET" && req.method !== "HEAD" ? req : void 0;
|
|
12
|
+
const request = new Request(url, {
|
|
13
|
+
method: req.method,
|
|
14
|
+
headers: req.headers,
|
|
15
|
+
body,
|
|
16
|
+
duplex: "half"
|
|
17
|
+
});
|
|
18
|
+
const response = await server.fetch(request);
|
|
19
|
+
res.statusCode = response.status;
|
|
20
|
+
response.headers.forEach((value, key) => {
|
|
21
|
+
res.setHeader(key, value);
|
|
22
|
+
});
|
|
23
|
+
if (!response.body) {
|
|
24
|
+
res.end();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const reader = response.body.getReader();
|
|
28
|
+
const stream = async () => {
|
|
29
|
+
try {
|
|
30
|
+
while (true) {
|
|
31
|
+
const { done, value } = await reader.read();
|
|
32
|
+
if (done) break;
|
|
33
|
+
res.write(value);
|
|
34
|
+
}
|
|
35
|
+
res.end();
|
|
36
|
+
} catch {
|
|
37
|
+
res.end();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
await stream();
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const devPlugin = (opts) => {
|
|
44
|
+
const dev = opts.dev;
|
|
45
|
+
const https = opts.dev.https ?? {};
|
|
46
|
+
return {
|
|
47
|
+
name: "vitend/dev",
|
|
48
|
+
apply: "serve",
|
|
49
|
+
config(config) {
|
|
50
|
+
return toMerged(config, {
|
|
51
|
+
build: {
|
|
52
|
+
ssr: true,
|
|
53
|
+
rollupOptions: { input: opts.entry }
|
|
54
|
+
},
|
|
55
|
+
server: {
|
|
56
|
+
host: dev.host,
|
|
57
|
+
port: dev.port,
|
|
58
|
+
https: {
|
|
59
|
+
cert: https.cert,
|
|
60
|
+
key: https.key,
|
|
61
|
+
passphrase: https.passphrase
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
configureServer: async (vite) => {
|
|
67
|
+
const serverOptions = (await vite.ssrLoadModule(opts.entry)).default;
|
|
68
|
+
const middleware = createMiddleware({
|
|
69
|
+
vite,
|
|
70
|
+
server: serve({
|
|
71
|
+
gracefulShutdown: false,
|
|
72
|
+
...serverOptions,
|
|
73
|
+
manual: true,
|
|
74
|
+
hostname: dev.host,
|
|
75
|
+
port: dev.port,
|
|
76
|
+
tls: {
|
|
77
|
+
cert: https.cert,
|
|
78
|
+
key: https.key,
|
|
79
|
+
passphrase: https.passphrase
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
});
|
|
83
|
+
vite.middlewares.use(middleware);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export { devPlugin };
|
|
89
|
+
//# sourceMappingURL=dev.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.mjs","names":[],"sources":["../../src/vite/dev.ts"],"sourcesContent":["import type HTTP from \"node:http\";\n\nimport type { Server, ServerHandler, ServerOptions } from \"srvx\";\nimport type { Connect, Plugin, UserConfig, ViteDevServer } from \"vite\";\n\nimport type {\n ResolvedDevOptions,\n ResolvedHttpsOptions,\n ResolvedVitendOptions,\n} from \"#/@types/options/resolved\";\n\nimport { toMerged } from \"es-toolkit\";\nimport { serve } from \"srvx\";\n\ntype CreateMiddlewareOptions = {\n vite: ViteDevServer;\n server: Server;\n};\n\nconst createMiddleware = ({ vite, server }: CreateMiddlewareOptions) => {\n return async (\n req: Connect.IncomingMessage,\n res: HTTP.ServerResponse,\n _next: Connect.NextFunction,\n ): Promise<void> => {\n const isHttps: boolean = vite.config.server.https !== undefined;\n\n const protocol: string = `http${isHttps ? \"s\" : \"\"}`;\n\n const host: string = process.env.HOST ?? \"localhost\";\n\n const port: number = vite.config.server.port;\n\n const path: string = req.url ?? \"\";\n\n const url: URL = new URL(`${protocol}://${host}:${port}${path}`);\n\n const body: Connect.IncomingMessage | undefined =\n req.method !== \"GET\" && req.method !== \"HEAD\" ? req : void 0;\n\n const request: Request = new Request(url, {\n method: req.method,\n headers: req.headers,\n body,\n duplex: \"half\",\n } as RequestInit);\n\n const response: Response = await server.fetch(request);\n\n res.statusCode = response.status;\n\n response.headers.forEach((value: string, key: string): void => {\n res.setHeader(key, value);\n });\n\n if (!response.body) {\n res.end();\n return void 0;\n }\n\n const reader: ReadableStreamDefaultReader<Uint8Array<ArrayBuffer>> =\n response.body.getReader();\n\n const stream = async (): Promise<void> => {\n try {\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) break;\n\n res.write(value);\n }\n\n res.end();\n } catch {\n res.end();\n }\n };\n\n await stream();\n };\n};\n\ntype Middleware = ReturnType<typeof createMiddleware>;\n\nconst devPlugin = (opts: ResolvedVitendOptions): Plugin => {\n const dev: ResolvedDevOptions = opts.dev;\n const https: ResolvedHttpsOptions = opts.dev.https ?? {};\n\n return {\n name: \"vitend/dev\",\n apply: \"serve\",\n config(config: UserConfig): UserConfig {\n const devConfig: UserConfig = {\n build: {\n ssr: true,\n rollupOptions: {\n input: opts.entry,\n },\n },\n server: {\n host: dev.host,\n port: dev.port,\n https: {\n cert: https.cert,\n key: https.key,\n passphrase: https.passphrase,\n },\n },\n };\n\n return toMerged(config, devConfig);\n },\n configureServer: async (vite: ViteDevServer): Promise<void> => {\n const serverOptions: ServerOptions = (\n await vite.ssrLoadModule(opts.entry)\n ).default;\n\n const server: Server<ServerHandler> = serve({\n // base\n gracefulShutdown: false,\n // user\n ...serverOptions,\n // override\n manual: true,\n hostname: dev.host,\n port: dev.port,\n tls: {\n cert: https.cert,\n key: https.key,\n passphrase: https.passphrase,\n },\n });\n\n const middleware: Middleware = createMiddleware({\n vite,\n server,\n });\n\n vite.middlewares.use(middleware);\n },\n };\n};\n\nexport { devPlugin };\n"],"mappings":";;;AAmBA,MAAM,oBAAoB,EAAE,MAAM,aAAsC;AACpE,QAAO,OACH,KACA,KACA,UACgB;EAGhB,MAAM,WAAmB,OAFA,KAAK,OAAO,OAAO,UAAU,SAEZ,MAAM;EAEhD,MAAM,OAAe,QAAQ,IAAI,QAAQ;EAEzC,MAAM,OAAe,KAAK,OAAO,OAAO;EAExC,MAAM,OAAe,IAAI,OAAO;EAEhC,MAAM,MAAW,IAAI,IAAI,GAAG,SAAS,KAAK,KAAK,GAAG,OAAO,OAAO;EAEhE,MAAM,OACF,IAAI,WAAW,SAAS,IAAI,WAAW,SAAS,MAAM,KAAK;EAE/D,MAAM,UAAmB,IAAI,QAAQ,KAAK;GACtC,QAAQ,IAAI;GACZ,SAAS,IAAI;GACb;GACA,QAAQ;GACX,CAAgB;EAEjB,MAAM,WAAqB,MAAM,OAAO,MAAM,QAAQ;AAEtD,MAAI,aAAa,SAAS;AAE1B,WAAS,QAAQ,SAAS,OAAe,QAAsB;AAC3D,OAAI,UAAU,KAAK,MAAM;IAC3B;AAEF,MAAI,CAAC,SAAS,MAAM;AAChB,OAAI,KAAK;AACT;;EAGJ,MAAM,SACF,SAAS,KAAK,WAAW;EAE7B,MAAM,SAAS,YAA2B;AACtC,OAAI;AACA,WAAO,MAAM;KACT,MAAM,EAAE,MAAM,UAAU,MAAM,OAAO,MAAM;AAE3C,SAAI,KAAM;AAEV,SAAI,MAAM,MAAM;;AAGpB,QAAI,KAAK;WACL;AACJ,QAAI,KAAK;;;AAIjB,QAAM,QAAQ;;;AAMtB,MAAM,aAAa,SAAwC;CACvD,MAAM,MAA0B,KAAK;CACrC,MAAM,QAA8B,KAAK,IAAI,SAAS,EAAE;AAExD,QAAO;EACH,MAAM;EACN,OAAO;EACP,OAAO,QAAgC;AAmBnC,UAAO,SAAS,QAlBc;IAC1B,OAAO;KACH,KAAK;KACL,eAAe,EACX,OAAO,KAAK,OACf;KACJ;IACD,QAAQ;KACJ,MAAM,IAAI;KACV,MAAM,IAAI;KACV,OAAO;MACH,MAAM,MAAM;MACZ,KAAK,MAAM;MACX,YAAY,MAAM;MACrB;KACJ;IACJ,CAEiC;;EAEtC,iBAAiB,OAAO,SAAuC;GAC3D,MAAM,iBACF,MAAM,KAAK,cAAc,KAAK,MAAM,EACtC;GAkBF,MAAM,aAAyB,iBAAiB;IAC5C;IACA,QAlBkC,MAAM;KAExC,kBAAkB;KAElB,GAAG;KAEH,QAAQ;KACR,UAAU,IAAI;KACd,MAAM,IAAI;KACV,KAAK;MACD,MAAM,MAAM;MACZ,KAAK,MAAM;MACX,YAAY,MAAM;MACrB;KACJ,CAAC;IAKD,CAAC;AAEF,QAAK,YAAY,IAAI,WAAW;;EAEvC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { VitendOptions } from "../@types/options/default.js";
|
|
2
|
+
import { Plugin } from "vite";
|
|
3
|
+
/**
|
|
4
|
+
* The `vitend` plugin.
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* // ./vite.config.ts
|
|
10
|
+
*
|
|
11
|
+
* import { defineConfig } from "vite";
|
|
12
|
+
* import { vitend } from "vitend/vite";
|
|
13
|
+
*
|
|
14
|
+
* export default defineConfig({
|
|
15
|
+
* plugins: [
|
|
16
|
+
* vitend(),
|
|
17
|
+
* ],
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare const vitend: (options?: VitendOptions) => Plugin[];
|
|
22
|
+
export { vitend };
|
|
23
|
+
//# sourceMappingURL=vitend.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_options = require('../functions/options.js');
|
|
3
|
+
const require_build = require('./build.js');
|
|
4
|
+
const require_dev = require('./dev.js');
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
7
|
+
let rollup_plugin_copy = require("rollup-plugin-copy");
|
|
8
|
+
rollup_plugin_copy = require_rolldown_runtime.__toESM(rollup_plugin_copy);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The `vitend` plugin.
|
|
12
|
+
*
|
|
13
|
+
* ### Example
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* // ./vite.config.ts
|
|
17
|
+
*
|
|
18
|
+
* import { defineConfig } from "vite";
|
|
19
|
+
* import { vitend } from "vitend/vite";
|
|
20
|
+
*
|
|
21
|
+
* export default defineConfig({
|
|
22
|
+
* plugins: [
|
|
23
|
+
* vitend(),
|
|
24
|
+
* ],
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
const vitend = (options) => {
|
|
29
|
+
const opts = require_options.createOptions(options);
|
|
30
|
+
const build = opts.build;
|
|
31
|
+
return [
|
|
32
|
+
require_dev.devPlugin({ ...opts }),
|
|
33
|
+
require_build.buildPlugin({ ...opts }),
|
|
34
|
+
...build?.copyPublicDir ? [(0, rollup_plugin_copy.default)({
|
|
35
|
+
hook: "closeBundle",
|
|
36
|
+
targets: [{
|
|
37
|
+
src: node_path.resolve(build.publicDir, "**", "*"),
|
|
38
|
+
dest: node_path.resolve(build.outputDir, build.publicDir)
|
|
39
|
+
}]
|
|
40
|
+
})] : []
|
|
41
|
+
];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.vitend = vitend;
|
|
45
|
+
//# sourceMappingURL=vitend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitend.js","names":["createOptions","devPlugin","buildPlugin","Path"],"sources":["../../src/vite/vitend.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\n\nimport type { VitendOptions } from \"#/@types/options/default\";\nimport type {\n ResolvedBuildOptions,\n ResolvedVitendOptions,\n} from \"#/@types/options/resolved\";\n\nimport * as Path from \"node:path\";\n\nimport copy from \"rollup-plugin-copy\";\n\nimport { createOptions } from \"#/functions/options\";\nimport { buildPlugin } from \"#/vite/build\";\nimport { devPlugin } from \"#/vite/dev\";\n\n/**\n * The `vitend` plugin.\n *\n * ### Example\n *\n * ```ts\n * // ./vite.config.ts\n *\n * import { defineConfig } from \"vite\";\n * import { vitend } from \"vitend/vite\";\n *\n * export default defineConfig({\n * plugins: [\n * vitend(),\n * ],\n * });\n * ```\n */\nconst vitend = (options?: VitendOptions): Plugin[] => {\n const opts: ResolvedVitendOptions = createOptions(options);\n\n const build: ResolvedBuildOptions = opts.build;\n\n return [\n devPlugin({\n ...opts,\n }),\n buildPlugin({\n ...opts,\n }),\n ...(build?.copyPublicDir\n ? [\n copy({\n hook: \"closeBundle\",\n targets: [\n {\n src: Path.resolve(build.publicDir, \"**\", \"*\"),\n dest: Path.resolve(\n build.outputDir,\n build.publicDir,\n ),\n },\n ],\n }),\n ]\n : []),\n ];\n};\n\nexport { vitend };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,UAAU,YAAsC;CAClD,MAAM,OAA8BA,8BAAc,QAAQ;CAE1D,MAAM,QAA8B,KAAK;AAEzC,QAAO;EACHC,sBAAU,EACN,GAAG,MACN,CAAC;EACFC,0BAAY,EACR,GAAG,MACN,CAAC;EACF,GAAI,OAAO,gBACL,iCACS;GACD,MAAM;GACN,SAAS,CACL;IACI,KAAKC,UAAK,QAAQ,MAAM,WAAW,MAAM,IAAI;IAC7C,MAAMA,UAAK,QACP,MAAM,WACN,MAAM,UACT;IACJ,CACJ;GACJ,CAAC,CACL,GACD,EAAE;EACX"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createOptions } from "../functions/options.mjs";
|
|
2
|
+
import { buildPlugin } from "./build.mjs";
|
|
3
|
+
import { devPlugin } from "./dev.mjs";
|
|
4
|
+
import * as Path from "node:path";
|
|
5
|
+
import copy from "rollup-plugin-copy";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The `vitend` plugin.
|
|
9
|
+
*
|
|
10
|
+
* ### Example
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* // ./vite.config.ts
|
|
14
|
+
*
|
|
15
|
+
* import { defineConfig } from "vite";
|
|
16
|
+
* import { vitend } from "vitend/vite";
|
|
17
|
+
*
|
|
18
|
+
* export default defineConfig({
|
|
19
|
+
* plugins: [
|
|
20
|
+
* vitend(),
|
|
21
|
+
* ],
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
const vitend = (options) => {
|
|
26
|
+
const opts = createOptions(options);
|
|
27
|
+
const build = opts.build;
|
|
28
|
+
return [
|
|
29
|
+
devPlugin({ ...opts }),
|
|
30
|
+
buildPlugin({ ...opts }),
|
|
31
|
+
...build?.copyPublicDir ? [copy({
|
|
32
|
+
hook: "closeBundle",
|
|
33
|
+
targets: [{
|
|
34
|
+
src: Path.resolve(build.publicDir, "**", "*"),
|
|
35
|
+
dest: Path.resolve(build.outputDir, build.publicDir)
|
|
36
|
+
}]
|
|
37
|
+
})] : []
|
|
38
|
+
];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { vitend };
|
|
42
|
+
//# sourceMappingURL=vitend.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitend.mjs","names":[],"sources":["../../src/vite/vitend.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\n\nimport type { VitendOptions } from \"#/@types/options/default\";\nimport type {\n ResolvedBuildOptions,\n ResolvedVitendOptions,\n} from \"#/@types/options/resolved\";\n\nimport * as Path from \"node:path\";\n\nimport copy from \"rollup-plugin-copy\";\n\nimport { createOptions } from \"#/functions/options\";\nimport { buildPlugin } from \"#/vite/build\";\nimport { devPlugin } from \"#/vite/dev\";\n\n/**\n * The `vitend` plugin.\n *\n * ### Example\n *\n * ```ts\n * // ./vite.config.ts\n *\n * import { defineConfig } from \"vite\";\n * import { vitend } from \"vitend/vite\";\n *\n * export default defineConfig({\n * plugins: [\n * vitend(),\n * ],\n * });\n * ```\n */\nconst vitend = (options?: VitendOptions): Plugin[] => {\n const opts: ResolvedVitendOptions = createOptions(options);\n\n const build: ResolvedBuildOptions = opts.build;\n\n return [\n devPlugin({\n ...opts,\n }),\n buildPlugin({\n ...opts,\n }),\n ...(build?.copyPublicDir\n ? [\n copy({\n hook: \"closeBundle\",\n targets: [\n {\n src: Path.resolve(build.publicDir, \"**\", \"*\"),\n dest: Path.resolve(\n build.outputDir,\n build.publicDir,\n ),\n },\n ],\n }),\n ]\n : []),\n ];\n};\n\nexport { vitend };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,UAAU,YAAsC;CAClD,MAAM,OAA8B,cAAc,QAAQ;CAE1D,MAAM,QAA8B,KAAK;AAEzC,QAAO;EACH,UAAU,EACN,GAAG,MACN,CAAC;EACF,YAAY,EACR,GAAG,MACN,CAAC;EACF,GAAI,OAAO,gBACL,CACI,KAAK;GACD,MAAM;GACN,SAAS,CACL;IACI,KAAK,KAAK,QAAQ,MAAM,WAAW,MAAM,IAAI;IAC7C,MAAM,KAAK,QACP,MAAM,WACN,MAAM,UACT;IACJ,CACJ;GACJ,CAAC,CACL,GACD,EAAE;EACX"}
|
package/dist/vite.d.ts
ADDED
package/dist/vite.js
ADDED
package/dist/vite.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,4 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A library for backend development with Vite",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vite",
|
|
7
|
+
"plugin",
|
|
8
|
+
"backend",
|
|
9
|
+
"development",
|
|
10
|
+
"ts",
|
|
11
|
+
"typescript",
|
|
12
|
+
"js",
|
|
13
|
+
"javascript"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/alpheusday/vitend",
|
|
16
|
+
"bugs": "https://github.com/alpheusday/vitend/issues",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/alpheusday/vitend.git",
|
|
20
|
+
"directory": "package"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "Alpheus",
|
|
25
|
+
"email": "contact@alphe.us"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"require": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./node": {
|
|
34
|
+
"types": "./dist/node.d.ts",
|
|
35
|
+
"import": "./dist/node.mjs",
|
|
36
|
+
"require": "./dist/node.js"
|
|
37
|
+
},
|
|
38
|
+
"./vite": {
|
|
39
|
+
"types": "./dist/vite.d.ts",
|
|
40
|
+
"import": "./dist/vite.mjs",
|
|
41
|
+
"require": "./dist/vite.js"
|
|
42
|
+
},
|
|
43
|
+
"./runtime": {
|
|
44
|
+
"types": "./dist/runtime.d.ts",
|
|
45
|
+
"import": "./dist/runtime.mjs",
|
|
46
|
+
"require": "./dist/runtime.js"
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json"
|
|
49
|
+
},
|
|
50
|
+
"main": "./dist/index.js",
|
|
51
|
+
"module": "./dist/index.mjs",
|
|
52
|
+
"types": "./dist/index.d.ts",
|
|
53
|
+
"files": [
|
|
54
|
+
"dist"
|
|
55
|
+
],
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"es-toolkit": "^1.40.0",
|
|
58
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
59
|
+
"srvx": "~0.10.0",
|
|
60
|
+
"ts-vista": "~0.2.3"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"vite": "7.0.0"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"vite": "^7.0.0"
|
|
67
|
+
}
|
|
4
68
|
}
|