vitend 0.3.0 → 0.4.1
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/vite.d.ts +41 -1
- package/dist/vite.js +71 -24
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs +71 -24
- package/dist/vite.mjs.map +1 -1
- package/package.json +3 -2
package/dist/vite.d.ts
CHANGED
|
@@ -39,6 +39,22 @@ type CompleteDevOptions = {
|
|
|
39
39
|
https: CompleteHttpsOptions;
|
|
40
40
|
};
|
|
41
41
|
/**
|
|
42
|
+
* Runtime target for the application.
|
|
43
|
+
*
|
|
44
|
+
* - Node.js - `node`
|
|
45
|
+
* - Deno - `deno`
|
|
46
|
+
* - Bun - `bun`
|
|
47
|
+
* - Cloudflare Workers - `workerd`
|
|
48
|
+
*/
|
|
49
|
+
type Runtime = "node" | "deno" | "bun" | "workerd";
|
|
50
|
+
/**
|
|
51
|
+
* Bundle mode.
|
|
52
|
+
*
|
|
53
|
+
* - `external` - keeps all dependencies external.
|
|
54
|
+
* - `standalone` - bundles all dependencies into the output file.
|
|
55
|
+
*/
|
|
56
|
+
type BundleMode = "external" | "standalone";
|
|
57
|
+
/**
|
|
42
58
|
* Complete default build server options.
|
|
43
59
|
*/
|
|
44
60
|
type CompleteDefaultBuildOptions = {
|
|
@@ -65,6 +81,12 @@ type CompleteDefaultBuildOptions = {
|
|
|
65
81
|
*/
|
|
66
82
|
https: CompleteHttpsOptions;
|
|
67
83
|
/**
|
|
84
|
+
* Whether to bundle all dependencies into the output file.
|
|
85
|
+
*
|
|
86
|
+
* By default, it is `external`.
|
|
87
|
+
*/
|
|
88
|
+
bundle: BundleMode;
|
|
89
|
+
/**
|
|
68
90
|
* The output directory for the application.
|
|
69
91
|
*
|
|
70
92
|
* By default, it is `./dist`.
|
|
@@ -109,6 +131,12 @@ type CompleteVercelBuildOptions = {
|
|
|
109
131
|
*/
|
|
110
132
|
target: "vercel";
|
|
111
133
|
/**
|
|
134
|
+
* Whether to bundle all dependencies into the output file.
|
|
135
|
+
*
|
|
136
|
+
* By default, it is `external`.
|
|
137
|
+
*/
|
|
138
|
+
bundle: BundleMode;
|
|
139
|
+
/**
|
|
112
140
|
* The output directory for the application.
|
|
113
141
|
*
|
|
114
142
|
* By default, it is `./dist`.
|
|
@@ -142,6 +170,12 @@ type CompleteVitendOptions = {
|
|
|
142
170
|
*/
|
|
143
171
|
cwd: string;
|
|
144
172
|
/**
|
|
173
|
+
* Runtime target for the application.
|
|
174
|
+
*
|
|
175
|
+
* By default, it is `node`.
|
|
176
|
+
*/
|
|
177
|
+
runtime: Runtime;
|
|
178
|
+
/**
|
|
145
179
|
* The entry file for the application.
|
|
146
180
|
*
|
|
147
181
|
* By default, it is `./src/index.ts` or `./src/index.js`.
|
|
@@ -155,6 +189,12 @@ type CompleteVitendOptions = {
|
|
|
155
189
|
* The options for the production server.
|
|
156
190
|
*/
|
|
157
191
|
build: CompleteBuildOptions;
|
|
192
|
+
/**
|
|
193
|
+
* Whether to output log messages to the console.
|
|
194
|
+
*
|
|
195
|
+
* By default, it is `false`.
|
|
196
|
+
*/
|
|
197
|
+
verbose: boolean;
|
|
158
198
|
};
|
|
159
199
|
/**
|
|
160
200
|
* HTTPS server options.
|
|
@@ -210,5 +250,5 @@ type VitendOptions = Format<Partial<Omit<CompleteVitendOptions, "dev" | "build">
|
|
|
210
250
|
* ```
|
|
211
251
|
*/
|
|
212
252
|
declare const vitend: (options?: VitendOptions) => Plugin[];
|
|
213
|
-
export { type BuildOptions, type DevOptions, type HttpsOptions, type VitendOptions, vitend };
|
|
253
|
+
export { type BuildOptions, type BundleMode, type DevOptions, type HttpsOptions, type Runtime, type VitendOptions, vitend };
|
|
214
254
|
//# sourceMappingURL=vite.d.ts.map
|
package/dist/vite.js
CHANGED
|
@@ -27,12 +27,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
let node_path = require("node:path");
|
|
28
28
|
node_path = __toESM(node_path);
|
|
29
29
|
let rolldown_plugin_copy = require("rolldown-plugin-copy");
|
|
30
|
+
let consola = require("consola");
|
|
30
31
|
let es_toolkit = require("es-toolkit");
|
|
31
32
|
let node_fs = require("node:fs");
|
|
32
33
|
node_fs = __toESM(node_fs);
|
|
33
34
|
let node_module = require("node:module");
|
|
34
35
|
let srvx = require("srvx");
|
|
35
36
|
|
|
37
|
+
const log = (0, consola.createConsola)({ formatOptions: { date: false } });
|
|
38
|
+
|
|
36
39
|
const ENTRY_DEFAULT = ["./src/index.ts", "./src/index.js"];
|
|
37
40
|
const getEntry = (cwd, entry) => {
|
|
38
41
|
if (!entry) {
|
|
@@ -45,28 +48,32 @@ const getEntry = (cwd, entry) => {
|
|
|
45
48
|
return node_path.resolve(cwd, entry);
|
|
46
49
|
};
|
|
47
50
|
|
|
48
|
-
const OPTIONS_BUILD_VERCEL = {
|
|
49
|
-
target: "vercel",
|
|
50
|
-
outputDir: "./dist",
|
|
51
|
-
outputFile: "index.js",
|
|
52
|
-
minify: false
|
|
53
|
-
};
|
|
54
51
|
const OPTIONS_BUILD_DEFAULT = {
|
|
55
52
|
target: "default",
|
|
56
53
|
host: "localhost",
|
|
57
54
|
port: 3e3,
|
|
55
|
+
bundle: "external",
|
|
58
56
|
outputDir: "./dist",
|
|
59
57
|
outputFile: "index.js",
|
|
60
58
|
minify: false,
|
|
61
59
|
publicDir: "./public",
|
|
62
60
|
copyPublicDir: false
|
|
63
61
|
};
|
|
62
|
+
const OPTIONS_BUILD_VERCEL = {
|
|
63
|
+
target: "vercel",
|
|
64
|
+
bundle: "external",
|
|
65
|
+
outputDir: "./dist",
|
|
66
|
+
outputFile: "index.js",
|
|
67
|
+
minify: false
|
|
68
|
+
};
|
|
64
69
|
const OPTIONS_DEFAULT = {
|
|
65
70
|
cwd: process.cwd(),
|
|
71
|
+
runtime: "node",
|
|
66
72
|
dev: {
|
|
67
73
|
host: "localhost",
|
|
68
74
|
port: 3001
|
|
69
|
-
}
|
|
75
|
+
},
|
|
76
|
+
verbose: false
|
|
70
77
|
};
|
|
71
78
|
const getDefaultOptions = (isVercel) => {
|
|
72
79
|
return {
|
|
@@ -89,6 +96,17 @@ const getPackageJson = (cwd) => {
|
|
|
89
96
|
return JSON.parse(rawPackageJson);
|
|
90
97
|
};
|
|
91
98
|
|
|
99
|
+
const toPosix = (path) => {
|
|
100
|
+
return path.split(node_path.sep).join(node_path.posix.sep);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const getSsrTarget = (runtime) => {
|
|
104
|
+
switch (runtime) {
|
|
105
|
+
case "workerd": return "webworker";
|
|
106
|
+
default: return "node";
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
92
110
|
const VIRTUAL_ENTRY = "virtual:vitend-entry";
|
|
93
111
|
const VIRTUAL_ENTRY_RESOLVED = `\0${VIRTUAL_ENTRY}`;
|
|
94
112
|
const buildPlugin = (opts) => {
|
|
@@ -99,14 +117,20 @@ const buildPlugin = (opts) => {
|
|
|
99
117
|
apply: "build",
|
|
100
118
|
config: (config) => {
|
|
101
119
|
let result = {};
|
|
102
|
-
|
|
120
|
+
let baseConfig = {
|
|
121
|
+
resolve: { conditions: [opts.runtime] },
|
|
103
122
|
ssr: {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
target: "webworker"
|
|
123
|
+
target: getSsrTarget(opts.runtime),
|
|
124
|
+
resolve: { conditions: [opts.runtime] }
|
|
107
125
|
},
|
|
108
126
|
build: { copyPublicDir: false }
|
|
109
|
-
}
|
|
127
|
+
};
|
|
128
|
+
if (build.bundle === "external") baseConfig = (0, es_toolkit.toMerged)(baseConfig, { ssr: {
|
|
129
|
+
external: true,
|
|
130
|
+
noExternal: void 0
|
|
131
|
+
} });
|
|
132
|
+
if (build.bundle === "standalone") baseConfig = (0, es_toolkit.toMerged)(baseConfig, { ssr: { noExternal: true } });
|
|
133
|
+
result = (0, es_toolkit.toMerged)(baseConfig, config);
|
|
110
134
|
const overrideConfig = { build: {
|
|
111
135
|
ssr: true,
|
|
112
136
|
outDir: build.outputDir,
|
|
@@ -130,7 +154,7 @@ const buildPlugin = (opts) => {
|
|
|
130
154
|
load: async (id) => {
|
|
131
155
|
if (id !== VIRTUAL_ENTRY_RESOLVED) return void 0;
|
|
132
156
|
let code = "";
|
|
133
|
-
code += `import options from "${opts.entry}";`;
|
|
157
|
+
code += `import options from "${toPosix(opts.entry)}";`;
|
|
134
158
|
code += `import { serve } from "vitend/runtime";`;
|
|
135
159
|
if (build.target === "vercel") {
|
|
136
160
|
code += `const server = serve({ ...options, manual: true });`;
|
|
@@ -143,9 +167,9 @@ const buildPlugin = (opts) => {
|
|
|
143
167
|
if (build.port !== 3e3) code += `port: ${build.port},`;
|
|
144
168
|
if (build.https) {
|
|
145
169
|
code += `tls: {`;
|
|
146
|
-
if (build.https.cert) code += `cert: "${build.https.cert}",`;
|
|
147
|
-
if (build.https.key) code += `key: "${build.https.key}",`;
|
|
148
|
-
if (build.https.passphrase) code += `passphrase: "${build.https.passphrase}",`;
|
|
170
|
+
if (build.https.cert) code += `cert: "${toPosix(build.https.cert)}",`;
|
|
171
|
+
if (build.https.key) code += `key: "${toPosix(build.https.key)}",`;
|
|
172
|
+
if (build.https.passphrase) code += `passphrase: "${toPosix(build.https.passphrase)}",`;
|
|
149
173
|
code += `},`;
|
|
150
174
|
}
|
|
151
175
|
code += `});`;
|
|
@@ -219,6 +243,11 @@ const devPlugin = (opts) => {
|
|
|
219
243
|
apply: "serve",
|
|
220
244
|
config(config) {
|
|
221
245
|
return (0, es_toolkit.toMerged)(config, {
|
|
246
|
+
resolve: { conditions: [opts.runtime] },
|
|
247
|
+
ssr: {
|
|
248
|
+
target: getSsrTarget(opts.runtime),
|
|
249
|
+
resolve: { conditions: [opts.runtime] }
|
|
250
|
+
},
|
|
222
251
|
build: {
|
|
223
252
|
ssr: true,
|
|
224
253
|
rollupOptions: { input: opts.entry }
|
|
@@ -277,14 +306,32 @@ const devPlugin = (opts) => {
|
|
|
277
306
|
const vitend = (options) => {
|
|
278
307
|
const opts = createOptions(options);
|
|
279
308
|
const build = opts.build;
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
309
|
+
const plugins = [devPlugin({ ...opts }), buildPlugin({ ...opts })];
|
|
310
|
+
if (build.target === "default" && build.copyPublicDir) {
|
|
311
|
+
const copyOptions = { targets: [{
|
|
312
|
+
src: node_path.posix.join(build.publicDir, "**", "*"),
|
|
313
|
+
dest: node_path.posix.join(build.outputDir, build.publicDir)
|
|
314
|
+
}] };
|
|
315
|
+
if (opts.verbose) {
|
|
316
|
+
copyOptions.onStart = () => {
|
|
317
|
+
console.log("");
|
|
318
|
+
console.log("");
|
|
319
|
+
};
|
|
320
|
+
copyOptions.onCopy = (event) => {
|
|
321
|
+
let message = `${node_path.relative(opts.cwd, event.target.src)} → ${node_path.relative(opts.cwd, event.target.dest)}`;
|
|
322
|
+
const flags = [];
|
|
323
|
+
if (event.target.renamed) flags.push("R");
|
|
324
|
+
if (event.target.transformed) flags.push("T");
|
|
325
|
+
if (flags.length > 0) message += ` [${flags.join(",")}]`;
|
|
326
|
+
log.success(message);
|
|
327
|
+
};
|
|
328
|
+
copyOptions.onEnd = () => {
|
|
329
|
+
console.log("");
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
plugins.push((0, rolldown_plugin_copy.copy)(copyOptions));
|
|
333
|
+
}
|
|
334
|
+
return plugins;
|
|
288
335
|
};
|
|
289
336
|
|
|
290
337
|
exports.__toESM = __toESM;
|
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":["Fs","Path","Path","Fs","builtinModules","Path"],"sources":["../src/functions/entry.ts","../src/functions/options.ts","../src/functions/package-json.ts","../src/vite/build.ts","../src/vite/dev.ts","../src/vite/vitend.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","import type { Omit } from \"ts-vista\";\n\nimport type { VitendOptions } from \"#/@types/options/default\";\nimport type {\n ResolvedDefaultBuildOptions,\n ResolvedVercelBuildOptions,\n ResolvedVitendOptions,\n} from \"#/@types/options/resolved\";\n\nimport { toMerged } from \"es-toolkit\";\n\nimport { getEntry } from \"#/functions/entry\";\n\nconst OPTIONS_BUILD_VERCEL: ResolvedVercelBuildOptions = {\n target: \"vercel\",\n outputDir: \"./dist\",\n outputFile: \"index.js\",\n minify: false,\n};\n\nconst OPTIONS_BUILD_DEFAULT: ResolvedDefaultBuildOptions = {\n target: \"default\",\n host: \"localhost\",\n port: 3000,\n outputDir: \"./dist\",\n outputFile: \"index.js\",\n minify: false,\n publicDir: \"./public\",\n copyPublicDir: false,\n};\n\nconst OPTIONS_DEFAULT: Omit<ResolvedVitendOptions, \"entry\" | \"build\"> = {\n cwd: process.cwd(),\n dev: {\n host: \"localhost\",\n port: 3001,\n },\n};\n\nconst getDefaultOptions = (\n isVercel: boolean,\n): Omit<ResolvedVitendOptions, \"entry\"> => {\n return {\n ...OPTIONS_DEFAULT,\n build: isVercel ? OPTIONS_BUILD_VERCEL : OPTIONS_BUILD_DEFAULT,\n };\n};\n\nconst createOptions = (options?: VitendOptions): ResolvedVitendOptions => {\n const isVercel: boolean = options?.build?.target === \"vercel\";\n\n const merged = toMerged(getDefaultOptions(isVercel), options ?? {});\n\n return {\n ...merged,\n entry: getEntry(merged.cwd, options?.entry),\n };\n};\n\nexport { createOptions };\n","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","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 options from \"${opts.entry}\";`;\n code += `import { serve } from \"vitend/runtime\";`;\n\n // vercel export\n\n if (build.target === \"vercel\") {\n code += `const server = serve({ ...options, manual: true });`;\n code += `export default server;`;\n\n return code;\n }\n\n // default export\n\n code += `serve({`;\n code += `...options,`;\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","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 createRequestHeaders = (headers: HTTP.IncomingHttpHeaders): Headers => {\n const result: Headers = new Headers();\n\n const entries: [\n string,\n string | string[] | undefined,\n ][] = Object.entries(headers);\n\n for (let i: number = 0; i < entries.length; i++) {\n const entry:\n | [\n string,\n string | string[] | undefined,\n ]\n | undefined = entries[i];\n\n if (entry === void 0) continue;\n\n const [key, value] = entry;\n\n // ignore HTTP/2 pseudo-headers\n if (key.startsWith(\":\")) continue;\n\n if (value === void 0) continue;\n\n if (Array.isArray(value)) {\n for (let j: number = 0; j < value.length; j++) {\n const vl: string | undefined = value[j];\n\n if (vl === void 0) continue;\n\n result.append(key, vl);\n }\n } else {\n result.set(key, value);\n }\n }\n\n return result;\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 =\n vite.config.server.https?.cert !== void 0 &&\n vite.config.server.https?.key !== void 0;\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: createRequestHeaders(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.cert !== void 0 && https.key !== void 0\n ? {\n https: {\n cert: https.cert,\n key: https.key,\n passphrase: https.passphrase,\n },\n }\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","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 \"rolldown-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.target === \"default\" && build.copyPublicDir\n ? ([\n copy({\n targets: [\n {\n src: Path.resolve(build.publicDir, \"**\", \"*\"),\n dest: Path.resolve(\n build.outputDir,\n build.publicDir,\n ),\n },\n ],\n }),\n ] as Plugin[])\n : []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MACN,CAAC;EACF,GAAI,MAAM,WAAW,aAAa,MAAM,gBACjC,gCACQ,EACD,SAAS,CACL;GACI,KAAKC,UAAK,QAAQ,MAAM,WAAW,MAAM,IAAI;GAC7C,MAAMA,UAAK,QACP,MAAM,WACN,MAAM,UACT;GACJ,CACJ,EACJ,CAAC,CACL,GACD,EAAE;EACX"}
|
|
1
|
+
{"version":3,"file":"vite.js","names":["Fs","Path","Path","Fs","Path","builtinModules","Path"],"sources":["../src/configs/log.ts","../src/functions/entry.ts","../src/functions/options.ts","../src/functions/package-json.ts","../src/functions/posix.ts","../src/functions/ssr.ts","../src/vite/build.ts","../src/vite/dev.ts","../src/vite/vitend.ts"],"sourcesContent":["import type { ConsolaInstance } from \"consola\";\n\nimport { createConsola } from \"consola\";\n\nconst log: ConsolaInstance = createConsola({\n formatOptions: {\n date: false,\n },\n});\n\nexport { log };\n","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","import type { Omit } from \"ts-vista\";\n\nimport type { VitendOptions } from \"#/@types/options/default\";\nimport type {\n ResolvedDefaultBuildOptions,\n ResolvedVercelBuildOptions,\n ResolvedVitendOptions,\n} from \"#/@types/options/resolved\";\n\nimport { toMerged } from \"es-toolkit\";\n\nimport { getEntry } from \"#/functions/entry\";\n\nconst OPTIONS_BUILD_DEFAULT: ResolvedDefaultBuildOptions = {\n target: \"default\",\n host: \"localhost\",\n port: 3000,\n bundle: \"external\",\n outputDir: \"./dist\",\n outputFile: \"index.js\",\n minify: false,\n publicDir: \"./public\",\n copyPublicDir: false,\n};\n\nconst OPTIONS_BUILD_VERCEL: ResolvedVercelBuildOptions = {\n target: \"vercel\",\n bundle: \"external\",\n outputDir: \"./dist\",\n outputFile: \"index.js\",\n minify: false,\n};\n\nconst OPTIONS_DEFAULT: Omit<ResolvedVitendOptions, \"entry\" | \"build\"> = {\n cwd: process.cwd(),\n runtime: \"node\",\n dev: {\n host: \"localhost\",\n port: 3001,\n },\n verbose: false,\n};\n\nconst getDefaultOptions = (\n isVercel: boolean,\n): Omit<ResolvedVitendOptions, \"entry\"> => {\n return {\n ...OPTIONS_DEFAULT,\n build: isVercel ? OPTIONS_BUILD_VERCEL : OPTIONS_BUILD_DEFAULT,\n };\n};\n\nconst createOptions = (options?: VitendOptions): ResolvedVitendOptions => {\n const isVercel: boolean = options?.build?.target === \"vercel\";\n\n const merged = toMerged(getDefaultOptions(isVercel), options ?? {});\n\n return {\n ...merged,\n entry: getEntry(merged.cwd, options?.entry),\n };\n};\n\nexport { createOptions };\n","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","import * as Path from \"node:path\";\n\nconst toPosix = (path: string): string => {\n return path.split(Path.sep).join(Path.posix.sep);\n};\n\nexport { toPosix };\n","import type { SSRTarget } from \"vite\";\n\nimport type { Runtime } from \"#/@types/options/complete\";\n\nconst getSsrTarget = (runtime: Runtime): SSRTarget => {\n switch (runtime) {\n case \"workerd\":\n return \"webworker\";\n default:\n return \"node\";\n }\n};\n\nexport { getSsrTarget };\n","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\";\nimport { toPosix } from \"#/functions/posix\";\nimport { getSsrTarget } from \"#/functions/ssr\";\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 let baseConfig: UserConfig = {\n resolve: {\n conditions: [\n opts.runtime,\n ],\n },\n ssr: {\n target: getSsrTarget(opts.runtime),\n resolve: {\n conditions: [\n opts.runtime,\n ],\n },\n },\n build: {\n copyPublicDir: false,\n },\n };\n\n if (build.bundle === \"external\") {\n baseConfig = toMerged(baseConfig, {\n ssr: {\n external: true,\n noExternal: void 0,\n },\n });\n }\n\n if (build.bundle === \"standalone\") {\n baseConfig = toMerged(baseConfig, {\n ssr: {\n noExternal: true,\n },\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 options from \"${toPosix(opts.entry)}\";`;\n code += `import { serve } from \"vitend/runtime\";`;\n\n // vercel export\n\n if (build.target === \"vercel\") {\n code += `const server = serve({ ...options, manual: true });`;\n code += `export default server;`;\n\n return code;\n }\n\n // default export\n\n code += `serve({`;\n code += `...options,`;\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)\n code += `cert: \"${toPosix(build.https.cert)}\",`;\n if (build.https.key)\n code += `key: \"${toPosix(build.https.key)}\",`;\n if (build.https.passphrase)\n code += `passphrase: \"${toPosix(build.https.passphrase)}\",`;\n code += `},`;\n }\n\n code += `});`;\n\n return code;\n },\n };\n};\n\nexport { buildPlugin };\n","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\nimport { getSsrTarget } from \"#/functions/ssr\";\n\ntype CreateMiddlewareOptions = {\n vite: ViteDevServer;\n server: Server;\n};\n\nconst createRequestHeaders = (headers: HTTP.IncomingHttpHeaders): Headers => {\n const result: Headers = new Headers();\n\n const entries: [\n string,\n string | string[] | undefined,\n ][] = Object.entries(headers);\n\n for (let i: number = 0; i < entries.length; i++) {\n const entry:\n | [\n string,\n string | string[] | undefined,\n ]\n | undefined = entries[i];\n\n if (entry === void 0) continue;\n\n const [key, value] = entry;\n\n // ignore HTTP/2 pseudo-headers\n if (key.startsWith(\":\")) continue;\n\n if (value === void 0) continue;\n\n if (Array.isArray(value)) {\n for (let j: number = 0; j < value.length; j++) {\n const vl: string | undefined = value[j];\n\n if (vl === void 0) continue;\n\n result.append(key, vl);\n }\n } else {\n result.set(key, value);\n }\n }\n\n return result;\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 =\n vite.config.server.https?.cert !== void 0 &&\n vite.config.server.https?.key !== void 0;\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: createRequestHeaders(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 resolve: {\n conditions: [\n opts.runtime,\n ],\n },\n ssr: {\n target: getSsrTarget(opts.runtime),\n resolve: {\n conditions: [\n opts.runtime,\n ],\n },\n },\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.cert !== void 0 && https.key !== void 0\n ? {\n https: {\n cert: https.cert,\n key: https.key,\n passphrase: https.passphrase,\n },\n }\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","import type { CopyEvent, Options as CopyOptions } from \"rolldown-plugin-copy\";\nimport 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 \"rolldown-plugin-copy\";\n\nimport { log } from \"#/configs/log\";\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 const plugins: Plugin[] = [\n devPlugin({\n ...opts,\n }),\n buildPlugin({\n ...opts,\n }),\n ];\n\n if (build.target === \"default\" && build.copyPublicDir) {\n const copyOptions: CopyOptions = {\n targets: [\n {\n src: Path.posix.join(build.publicDir, \"**\", \"*\"),\n dest: Path.posix.join(build.outputDir, build.publicDir),\n },\n ],\n };\n\n if (opts.verbose) {\n copyOptions.onStart = (): void => {\n console.log(\"\");\n console.log(\"\");\n };\n\n copyOptions.onCopy = (event: CopyEvent): void => {\n const src: string = Path.relative(opts.cwd, event.target.src);\n\n const dest: string = Path.relative(opts.cwd, event.target.dest);\n\n let message: string = `${src} → ${dest}`;\n\n const flags: string[] = [];\n\n if (event.target.renamed) {\n flags.push(\"R\");\n }\n\n if (event.target.transformed) {\n flags.push(\"T\");\n }\n\n if (flags.length > 0) {\n message += ` [${flags.join(\",\")}]`;\n }\n\n log.success(message);\n };\n\n copyOptions.onEnd = (): void => {\n console.log(\"\");\n };\n }\n\n plugins.push(copy(copyOptions) as Plugin);\n }\n\n return plugins;\n};\n\nexport { vitend };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,iCAAqC,EACvC,eAAe,EACX,MAAM,OACT,EACJ,CAAC;;ACLF,MAAM,gBAA0B,CAC5B,kBACA,iBACH;AAED,MAAM,YAAY,KAAa,UAA2B;CACtD,IAAI,CAAC,OAAO;EACR,KAAK,MAAM,OAAO,eACd,IAAIA,QAAG,WAAWC,UAAK,QAAQ,KAAK,IAAI,CAAC,EAAE;GACvC,QAAQ;GACR;;EAIR,IAAI,CAAC,OACD,MAAM,IAAI,MAAM,sBAAsB;;CAI9C,OAAOA,UAAK,QAAQ,KAAK,MAAM;;;ACTnC,MAAM,wBAAqD;CACvD,QAAQ;CACR,MAAM;CACN,MAAM;CACN,QAAQ;CACR,WAAW;CACX,YAAY;CACZ,QAAQ;CACR,WAAW;CACX,eAAe;CAClB;AAED,MAAM,uBAAmD;CACrD,QAAQ;CACR,QAAQ;CACR,WAAW;CACX,YAAY;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MAAM,UAAU,YAAsC;CAClD,MAAM,OAA8B,cAAc,QAAQ;CAE1D,MAAM,QAA8B,KAAK;CAEzC,MAAM,UAAoB,CACtB,UAAU,EACN,GAAG,MACN,CAAC,EACF,YAAY,EACR,GAAG,MACN,CAAC,CACL;CAED,IAAI,MAAM,WAAW,aAAa,MAAM,eAAe;EACnD,MAAM,cAA2B,EAC7B,SAAS,CACL;GACI,KAAKC,UAAK,MAAM,KAAK,MAAM,WAAW,MAAM,IAAI;GAChD,MAAMA,UAAK,MAAM,KAAK,MAAM,WAAW,MAAM,UAAU;GAC1D,CACJ,EACJ;EAED,IAAI,KAAK,SAAS;GACd,YAAY,gBAAsB;IAC9B,QAAQ,IAAI,GAAG;IACf,QAAQ,IAAI,GAAG;;GAGnB,YAAY,UAAU,UAA2B;IAK7C,IAAI,UAAkB,GAJFA,UAAK,SAAS,KAAK,KAAK,MAAM,OAAO,IAI7B,CAAC,KAFRA,UAAK,SAAS,KAAK,KAAK,MAAM,OAAO,KAEpB;IAEtC,MAAM,QAAkB,EAAE;IAE1B,IAAI,MAAM,OAAO,SACb,MAAM,KAAK,IAAI;IAGnB,IAAI,MAAM,OAAO,aACb,MAAM,KAAK,IAAI;IAGnB,IAAI,MAAM,SAAS,GACf,WAAW,KAAK,MAAM,KAAK,IAAI,CAAC;IAGpC,IAAI,QAAQ,QAAQ;;GAGxB,YAAY,cAAoB;IAC5B,QAAQ,IAAI,GAAG;;;EAIvB,QAAQ,oCAAU,YAAY,CAAW;;CAG7C,OAAO"}
|
package/dist/vite.mjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { builtinModules } from "node:module";
|
|
2
2
|
import * as Path from "node:path";
|
|
3
3
|
import { copy } from "rolldown-plugin-copy";
|
|
4
|
+
import { createConsola } from "consola";
|
|
4
5
|
import { toMerged } from "es-toolkit";
|
|
5
6
|
import * as Fs from "node:fs";
|
|
6
7
|
import { serve } from "srvx";
|
|
7
8
|
|
|
9
|
+
const log = createConsola({ formatOptions: { date: false } });
|
|
10
|
+
|
|
8
11
|
const ENTRY_DEFAULT = ["./src/index.ts", "./src/index.js"];
|
|
9
12
|
const getEntry = (cwd, entry) => {
|
|
10
13
|
if (!entry) {
|
|
@@ -17,28 +20,32 @@ const getEntry = (cwd, entry) => {
|
|
|
17
20
|
return Path.resolve(cwd, entry);
|
|
18
21
|
};
|
|
19
22
|
|
|
20
|
-
const OPTIONS_BUILD_VERCEL = {
|
|
21
|
-
target: "vercel",
|
|
22
|
-
outputDir: "./dist",
|
|
23
|
-
outputFile: "index.js",
|
|
24
|
-
minify: false
|
|
25
|
-
};
|
|
26
23
|
const OPTIONS_BUILD_DEFAULT = {
|
|
27
24
|
target: "default",
|
|
28
25
|
host: "localhost",
|
|
29
26
|
port: 3e3,
|
|
27
|
+
bundle: "external",
|
|
30
28
|
outputDir: "./dist",
|
|
31
29
|
outputFile: "index.js",
|
|
32
30
|
minify: false,
|
|
33
31
|
publicDir: "./public",
|
|
34
32
|
copyPublicDir: false
|
|
35
33
|
};
|
|
34
|
+
const OPTIONS_BUILD_VERCEL = {
|
|
35
|
+
target: "vercel",
|
|
36
|
+
bundle: "external",
|
|
37
|
+
outputDir: "./dist",
|
|
38
|
+
outputFile: "index.js",
|
|
39
|
+
minify: false
|
|
40
|
+
};
|
|
36
41
|
const OPTIONS_DEFAULT = {
|
|
37
42
|
cwd: process.cwd(),
|
|
43
|
+
runtime: "node",
|
|
38
44
|
dev: {
|
|
39
45
|
host: "localhost",
|
|
40
46
|
port: 3001
|
|
41
|
-
}
|
|
47
|
+
},
|
|
48
|
+
verbose: false
|
|
42
49
|
};
|
|
43
50
|
const getDefaultOptions = (isVercel) => {
|
|
44
51
|
return {
|
|
@@ -61,6 +68,17 @@ const getPackageJson = (cwd) => {
|
|
|
61
68
|
return JSON.parse(rawPackageJson);
|
|
62
69
|
};
|
|
63
70
|
|
|
71
|
+
const toPosix = (path) => {
|
|
72
|
+
return path.split(Path.sep).join(Path.posix.sep);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const getSsrTarget = (runtime) => {
|
|
76
|
+
switch (runtime) {
|
|
77
|
+
case "workerd": return "webworker";
|
|
78
|
+
default: return "node";
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
64
82
|
const VIRTUAL_ENTRY = "virtual:vitend-entry";
|
|
65
83
|
const VIRTUAL_ENTRY_RESOLVED = `\0${VIRTUAL_ENTRY}`;
|
|
66
84
|
const buildPlugin = (opts) => {
|
|
@@ -71,14 +89,20 @@ const buildPlugin = (opts) => {
|
|
|
71
89
|
apply: "build",
|
|
72
90
|
config: (config) => {
|
|
73
91
|
let result = {};
|
|
74
|
-
|
|
92
|
+
let baseConfig = {
|
|
93
|
+
resolve: { conditions: [opts.runtime] },
|
|
75
94
|
ssr: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
target: "webworker"
|
|
95
|
+
target: getSsrTarget(opts.runtime),
|
|
96
|
+
resolve: { conditions: [opts.runtime] }
|
|
79
97
|
},
|
|
80
98
|
build: { copyPublicDir: false }
|
|
81
|
-
}
|
|
99
|
+
};
|
|
100
|
+
if (build.bundle === "external") baseConfig = toMerged(baseConfig, { ssr: {
|
|
101
|
+
external: true,
|
|
102
|
+
noExternal: void 0
|
|
103
|
+
} });
|
|
104
|
+
if (build.bundle === "standalone") baseConfig = toMerged(baseConfig, { ssr: { noExternal: true } });
|
|
105
|
+
result = toMerged(baseConfig, config);
|
|
82
106
|
const overrideConfig = { build: {
|
|
83
107
|
ssr: true,
|
|
84
108
|
outDir: build.outputDir,
|
|
@@ -102,7 +126,7 @@ const buildPlugin = (opts) => {
|
|
|
102
126
|
load: async (id) => {
|
|
103
127
|
if (id !== VIRTUAL_ENTRY_RESOLVED) return void 0;
|
|
104
128
|
let code = "";
|
|
105
|
-
code += `import options from "${opts.entry}";`;
|
|
129
|
+
code += `import options from "${toPosix(opts.entry)}";`;
|
|
106
130
|
code += `import { serve } from "vitend/runtime";`;
|
|
107
131
|
if (build.target === "vercel") {
|
|
108
132
|
code += `const server = serve({ ...options, manual: true });`;
|
|
@@ -115,9 +139,9 @@ const buildPlugin = (opts) => {
|
|
|
115
139
|
if (build.port !== 3e3) code += `port: ${build.port},`;
|
|
116
140
|
if (build.https) {
|
|
117
141
|
code += `tls: {`;
|
|
118
|
-
if (build.https.cert) code += `cert: "${build.https.cert}",`;
|
|
119
|
-
if (build.https.key) code += `key: "${build.https.key}",`;
|
|
120
|
-
if (build.https.passphrase) code += `passphrase: "${build.https.passphrase}",`;
|
|
142
|
+
if (build.https.cert) code += `cert: "${toPosix(build.https.cert)}",`;
|
|
143
|
+
if (build.https.key) code += `key: "${toPosix(build.https.key)}",`;
|
|
144
|
+
if (build.https.passphrase) code += `passphrase: "${toPosix(build.https.passphrase)}",`;
|
|
121
145
|
code += `},`;
|
|
122
146
|
}
|
|
123
147
|
code += `});`;
|
|
@@ -191,6 +215,11 @@ const devPlugin = (opts) => {
|
|
|
191
215
|
apply: "serve",
|
|
192
216
|
config(config) {
|
|
193
217
|
return toMerged(config, {
|
|
218
|
+
resolve: { conditions: [opts.runtime] },
|
|
219
|
+
ssr: {
|
|
220
|
+
target: getSsrTarget(opts.runtime),
|
|
221
|
+
resolve: { conditions: [opts.runtime] }
|
|
222
|
+
},
|
|
194
223
|
build: {
|
|
195
224
|
ssr: true,
|
|
196
225
|
rollupOptions: { input: opts.entry }
|
|
@@ -249,14 +278,32 @@ const devPlugin = (opts) => {
|
|
|
249
278
|
const vitend = (options) => {
|
|
250
279
|
const opts = createOptions(options);
|
|
251
280
|
const build = opts.build;
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
281
|
+
const plugins = [devPlugin({ ...opts }), buildPlugin({ ...opts })];
|
|
282
|
+
if (build.target === "default" && build.copyPublicDir) {
|
|
283
|
+
const copyOptions = { targets: [{
|
|
284
|
+
src: Path.posix.join(build.publicDir, "**", "*"),
|
|
285
|
+
dest: Path.posix.join(build.outputDir, build.publicDir)
|
|
286
|
+
}] };
|
|
287
|
+
if (opts.verbose) {
|
|
288
|
+
copyOptions.onStart = () => {
|
|
289
|
+
console.log("");
|
|
290
|
+
console.log("");
|
|
291
|
+
};
|
|
292
|
+
copyOptions.onCopy = (event) => {
|
|
293
|
+
let message = `${Path.relative(opts.cwd, event.target.src)} → ${Path.relative(opts.cwd, event.target.dest)}`;
|
|
294
|
+
const flags = [];
|
|
295
|
+
if (event.target.renamed) flags.push("R");
|
|
296
|
+
if (event.target.transformed) flags.push("T");
|
|
297
|
+
if (flags.length > 0) message += ` [${flags.join(",")}]`;
|
|
298
|
+
log.success(message);
|
|
299
|
+
};
|
|
300
|
+
copyOptions.onEnd = () => {
|
|
301
|
+
console.log("");
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
plugins.push(copy(copyOptions));
|
|
305
|
+
}
|
|
306
|
+
return plugins;
|
|
260
307
|
};
|
|
261
308
|
|
|
262
309
|
export { vitend };
|
package/dist/vite.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.mjs","names":[],"sources":["../src/functions/entry.ts","../src/functions/options.ts","../src/functions/package-json.ts","../src/vite/build.ts","../src/vite/dev.ts","../src/vite/vitend.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","import type { Omit } from \"ts-vista\";\n\nimport type { VitendOptions } from \"#/@types/options/default\";\nimport type {\n ResolvedDefaultBuildOptions,\n ResolvedVercelBuildOptions,\n ResolvedVitendOptions,\n} from \"#/@types/options/resolved\";\n\nimport { toMerged } from \"es-toolkit\";\n\nimport { getEntry } from \"#/functions/entry\";\n\nconst OPTIONS_BUILD_VERCEL: ResolvedVercelBuildOptions = {\n target: \"vercel\",\n outputDir: \"./dist\",\n outputFile: \"index.js\",\n minify: false,\n};\n\nconst OPTIONS_BUILD_DEFAULT: ResolvedDefaultBuildOptions = {\n target: \"default\",\n host: \"localhost\",\n port: 3000,\n outputDir: \"./dist\",\n outputFile: \"index.js\",\n minify: false,\n publicDir: \"./public\",\n copyPublicDir: false,\n};\n\nconst OPTIONS_DEFAULT: Omit<ResolvedVitendOptions, \"entry\" | \"build\"> = {\n cwd: process.cwd(),\n dev: {\n host: \"localhost\",\n port: 3001,\n },\n};\n\nconst getDefaultOptions = (\n isVercel: boolean,\n): Omit<ResolvedVitendOptions, \"entry\"> => {\n return {\n ...OPTIONS_DEFAULT,\n build: isVercel ? OPTIONS_BUILD_VERCEL : OPTIONS_BUILD_DEFAULT,\n };\n};\n\nconst createOptions = (options?: VitendOptions): ResolvedVitendOptions => {\n const isVercel: boolean = options?.build?.target === \"vercel\";\n\n const merged = toMerged(getDefaultOptions(isVercel), options ?? {});\n\n return {\n ...merged,\n entry: getEntry(merged.cwd, options?.entry),\n };\n};\n\nexport { createOptions };\n","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","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 options from \"${opts.entry}\";`;\n code += `import { serve } from \"vitend/runtime\";`;\n\n // vercel export\n\n if (build.target === \"vercel\") {\n code += `const server = serve({ ...options, manual: true });`;\n code += `export default server;`;\n\n return code;\n }\n\n // default export\n\n code += `serve({`;\n code += `...options,`;\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","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 createRequestHeaders = (headers: HTTP.IncomingHttpHeaders): Headers => {\n const result: Headers = new Headers();\n\n const entries: [\n string,\n string | string[] | undefined,\n ][] = Object.entries(headers);\n\n for (let i: number = 0; i < entries.length; i++) {\n const entry:\n | [\n string,\n string | string[] | undefined,\n ]\n | undefined = entries[i];\n\n if (entry === void 0) continue;\n\n const [key, value] = entry;\n\n // ignore HTTP/2 pseudo-headers\n if (key.startsWith(\":\")) continue;\n\n if (value === void 0) continue;\n\n if (Array.isArray(value)) {\n for (let j: number = 0; j < value.length; j++) {\n const vl: string | undefined = value[j];\n\n if (vl === void 0) continue;\n\n result.append(key, vl);\n }\n } else {\n result.set(key, value);\n }\n }\n\n return result;\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 =\n vite.config.server.https?.cert !== void 0 &&\n vite.config.server.https?.key !== void 0;\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: createRequestHeaders(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.cert !== void 0 && https.key !== void 0\n ? {\n https: {\n cert: https.cert,\n key: https.key,\n passphrase: https.passphrase,\n },\n }\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","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 \"rolldown-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.target === \"default\" && build.copyPublicDir\n ? ([\n copy({\n targets: [\n {\n src: Path.resolve(build.publicDir, \"**\", \"*\"),\n dest: Path.resolve(\n build.outputDir,\n build.publicDir,\n ),\n },\n ],\n }),\n ] as Plugin[])\n : []),\n ];\n};\n\nexport { vitend };\n"],"mappings":";;;;;;;AAGA,MAAM,gBAA0B,CAC5B,kBACA,iBACH;AAED,MAAM,YAAY,KAAa,UAA2B;CACtD,IAAI,CAAC,OAAO;EACR,KAAK,MAAM,OAAO,eACd,IAAI,GAAG,WAAW,KAAK,QAAQ,KAAK,IAAI,CAAC,EAAE;GACvC,QAAQ;GACR;;EAIR,IAAI,CAAC,OACD,MAAM,IAAI,MAAM,sBAAsB;;CAI9C,OAAO,KAAK,QAAQ,KAAK,MAAM;;;ACTnC,MAAM,uBAAmD;CACrD,QAAQ;CACR,WAAW;CACX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,QAAgC;GAuBnC,OAAO,SAAS,QAAQ;IArBpB,OAAO;KACH,KAAK;KACL,eAAe,EACX,OAAO,KAAK,OACf;KACJ;IACD,QAAQ;KACJ,MAAM,IAAI;KACV,MAAM,IAAI;KACV,GAAI,MAAM,SAAS,KAAK,KAAK,MAAM,QAAQ,KAAK,IAC1C,EACI,OAAO;MACH,MAAM,MAAM;MACZ,KAAK,MAAM;MACX,YAAY,MAAM;MACrB,EACJ,GACD,EAAE;KACX;IAG4B,CAAC;;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,CAIS;IACT,CAAC;GAEF,KAAK,YAAY,IAAI,WAAW;;EAEvC;;;;;;;;;;;;;;;;;;;;;AC1JL,MAAM,UAAU,YAAsC;CAClD,MAAM,OAA8B,cAAc,QAAQ;CAE1D,MAAM,QAA8B,KAAK;CAEzC,OAAO;EACH,UAAU,EACN,GAAG,MACN,CAAC;EACF,YAAY,EACR,GAAG,MACN,CAAC;EACF,GAAI,MAAM,WAAW,aAAa,MAAM,gBACjC,CACG,KAAK,EACD,SAAS,CACL;GACI,KAAK,KAAK,QAAQ,MAAM,WAAW,MAAM,IAAI;GAC7C,MAAM,KAAK,QACP,MAAM,WACN,MAAM,UACT;GACJ,CACJ,EACJ,CAAC,CACL,GACD,EAAE;EACX"}
|
|
1
|
+
{"version":3,"file":"vite.mjs","names":[],"sources":["../src/configs/log.ts","../src/functions/entry.ts","../src/functions/options.ts","../src/functions/package-json.ts","../src/functions/posix.ts","../src/functions/ssr.ts","../src/vite/build.ts","../src/vite/dev.ts","../src/vite/vitend.ts"],"sourcesContent":["import type { ConsolaInstance } from \"consola\";\n\nimport { createConsola } from \"consola\";\n\nconst log: ConsolaInstance = createConsola({\n formatOptions: {\n date: false,\n },\n});\n\nexport { log };\n","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","import type { Omit } from \"ts-vista\";\n\nimport type { VitendOptions } from \"#/@types/options/default\";\nimport type {\n ResolvedDefaultBuildOptions,\n ResolvedVercelBuildOptions,\n ResolvedVitendOptions,\n} from \"#/@types/options/resolved\";\n\nimport { toMerged } from \"es-toolkit\";\n\nimport { getEntry } from \"#/functions/entry\";\n\nconst OPTIONS_BUILD_DEFAULT: ResolvedDefaultBuildOptions = {\n target: \"default\",\n host: \"localhost\",\n port: 3000,\n bundle: \"external\",\n outputDir: \"./dist\",\n outputFile: \"index.js\",\n minify: false,\n publicDir: \"./public\",\n copyPublicDir: false,\n};\n\nconst OPTIONS_BUILD_VERCEL: ResolvedVercelBuildOptions = {\n target: \"vercel\",\n bundle: \"external\",\n outputDir: \"./dist\",\n outputFile: \"index.js\",\n minify: false,\n};\n\nconst OPTIONS_DEFAULT: Omit<ResolvedVitendOptions, \"entry\" | \"build\"> = {\n cwd: process.cwd(),\n runtime: \"node\",\n dev: {\n host: \"localhost\",\n port: 3001,\n },\n verbose: false,\n};\n\nconst getDefaultOptions = (\n isVercel: boolean,\n): Omit<ResolvedVitendOptions, \"entry\"> => {\n return {\n ...OPTIONS_DEFAULT,\n build: isVercel ? OPTIONS_BUILD_VERCEL : OPTIONS_BUILD_DEFAULT,\n };\n};\n\nconst createOptions = (options?: VitendOptions): ResolvedVitendOptions => {\n const isVercel: boolean = options?.build?.target === \"vercel\";\n\n const merged = toMerged(getDefaultOptions(isVercel), options ?? {});\n\n return {\n ...merged,\n entry: getEntry(merged.cwd, options?.entry),\n };\n};\n\nexport { createOptions };\n","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","import * as Path from \"node:path\";\n\nconst toPosix = (path: string): string => {\n return path.split(Path.sep).join(Path.posix.sep);\n};\n\nexport { toPosix };\n","import type { SSRTarget } from \"vite\";\n\nimport type { Runtime } from \"#/@types/options/complete\";\n\nconst getSsrTarget = (runtime: Runtime): SSRTarget => {\n switch (runtime) {\n case \"workerd\":\n return \"webworker\";\n default:\n return \"node\";\n }\n};\n\nexport { getSsrTarget };\n","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\";\nimport { toPosix } from \"#/functions/posix\";\nimport { getSsrTarget } from \"#/functions/ssr\";\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 let baseConfig: UserConfig = {\n resolve: {\n conditions: [\n opts.runtime,\n ],\n },\n ssr: {\n target: getSsrTarget(opts.runtime),\n resolve: {\n conditions: [\n opts.runtime,\n ],\n },\n },\n build: {\n copyPublicDir: false,\n },\n };\n\n if (build.bundle === \"external\") {\n baseConfig = toMerged(baseConfig, {\n ssr: {\n external: true,\n noExternal: void 0,\n },\n });\n }\n\n if (build.bundle === \"standalone\") {\n baseConfig = toMerged(baseConfig, {\n ssr: {\n noExternal: true,\n },\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 options from \"${toPosix(opts.entry)}\";`;\n code += `import { serve } from \"vitend/runtime\";`;\n\n // vercel export\n\n if (build.target === \"vercel\") {\n code += `const server = serve({ ...options, manual: true });`;\n code += `export default server;`;\n\n return code;\n }\n\n // default export\n\n code += `serve({`;\n code += `...options,`;\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)\n code += `cert: \"${toPosix(build.https.cert)}\",`;\n if (build.https.key)\n code += `key: \"${toPosix(build.https.key)}\",`;\n if (build.https.passphrase)\n code += `passphrase: \"${toPosix(build.https.passphrase)}\",`;\n code += `},`;\n }\n\n code += `});`;\n\n return code;\n },\n };\n};\n\nexport { buildPlugin };\n","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\nimport { getSsrTarget } from \"#/functions/ssr\";\n\ntype CreateMiddlewareOptions = {\n vite: ViteDevServer;\n server: Server;\n};\n\nconst createRequestHeaders = (headers: HTTP.IncomingHttpHeaders): Headers => {\n const result: Headers = new Headers();\n\n const entries: [\n string,\n string | string[] | undefined,\n ][] = Object.entries(headers);\n\n for (let i: number = 0; i < entries.length; i++) {\n const entry:\n | [\n string,\n string | string[] | undefined,\n ]\n | undefined = entries[i];\n\n if (entry === void 0) continue;\n\n const [key, value] = entry;\n\n // ignore HTTP/2 pseudo-headers\n if (key.startsWith(\":\")) continue;\n\n if (value === void 0) continue;\n\n if (Array.isArray(value)) {\n for (let j: number = 0; j < value.length; j++) {\n const vl: string | undefined = value[j];\n\n if (vl === void 0) continue;\n\n result.append(key, vl);\n }\n } else {\n result.set(key, value);\n }\n }\n\n return result;\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 =\n vite.config.server.https?.cert !== void 0 &&\n vite.config.server.https?.key !== void 0;\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: createRequestHeaders(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 resolve: {\n conditions: [\n opts.runtime,\n ],\n },\n ssr: {\n target: getSsrTarget(opts.runtime),\n resolve: {\n conditions: [\n opts.runtime,\n ],\n },\n },\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.cert !== void 0 && https.key !== void 0\n ? {\n https: {\n cert: https.cert,\n key: https.key,\n passphrase: https.passphrase,\n },\n }\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","import type { CopyEvent, Options as CopyOptions } from \"rolldown-plugin-copy\";\nimport 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 \"rolldown-plugin-copy\";\n\nimport { log } from \"#/configs/log\";\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 const plugins: Plugin[] = [\n devPlugin({\n ...opts,\n }),\n buildPlugin({\n ...opts,\n }),\n ];\n\n if (build.target === \"default\" && build.copyPublicDir) {\n const copyOptions: CopyOptions = {\n targets: [\n {\n src: Path.posix.join(build.publicDir, \"**\", \"*\"),\n dest: Path.posix.join(build.outputDir, build.publicDir),\n },\n ],\n };\n\n if (opts.verbose) {\n copyOptions.onStart = (): void => {\n console.log(\"\");\n console.log(\"\");\n };\n\n copyOptions.onCopy = (event: CopyEvent): void => {\n const src: string = Path.relative(opts.cwd, event.target.src);\n\n const dest: string = Path.relative(opts.cwd, event.target.dest);\n\n let message: string = `${src} → ${dest}`;\n\n const flags: string[] = [];\n\n if (event.target.renamed) {\n flags.push(\"R\");\n }\n\n if (event.target.transformed) {\n flags.push(\"T\");\n }\n\n if (flags.length > 0) {\n message += ` [${flags.join(\",\")}]`;\n }\n\n log.success(message);\n };\n\n copyOptions.onEnd = (): void => {\n console.log(\"\");\n };\n }\n\n plugins.push(copy(copyOptions) as Plugin);\n }\n\n return plugins;\n};\n\nexport { vitend };\n"],"mappings":";;;;;;;;AAIA,MAAM,MAAuB,cAAc,EACvC,eAAe,EACX,MAAM,OACT,EACJ,CAAC;;ACLF,MAAM,gBAA0B,CAC5B,kBACA,iBACH;AAED,MAAM,YAAY,KAAa,UAA2B;CACtD,IAAI,CAAC,OAAO;EACR,KAAK,MAAM,OAAO,eACd,IAAI,GAAG,WAAW,KAAK,QAAQ,KAAK,IAAI,CAAC,EAAE;GACvC,QAAQ;GACR;;EAIR,IAAI,CAAC,OACD,MAAM,IAAI,MAAM,sBAAsB;;CAI9C,OAAO,KAAK,QAAQ,KAAK,MAAM;;;ACTnC,MAAM,wBAAqD;CACvD,QAAQ;CACR,MAAM;CACN,MAAM;CACN,QAAQ;CACR,WAAW;CACX,YAAY;CACZ,QAAQ;CACR,WAAW;CACX,eAAe;CAClB;AAED,MAAM,uBAAmD;CACrD,QAAQ;CACR,QAAQ;CACR,WAAW;CACX,YAAY;CACZ,QAAQ;CACX;AAED,MAAM,kBAAkE;CACpE,KAAK,QAAQ,KAAK;CAClB,SAAS;CACT,KAAK;EACD,MAAM;EACN,MAAM;EACT;CACD,SAAS;CACZ;AAED,MAAM,qBACF,aACuC;CACvC,OAAO;EACH,GAAG;EACH,OAAO,WAAW,uBAAuB;EAC5C;;AAGL,MAAM,iBAAiB,YAAmD;CAGtE,MAAM,SAAS,SAAS,kBAFE,SAAS,OAAO,WAAW,SAEF,EAAE,WAAW,EAAE,CAAC;CAEnE,OAAO;EACH,GAAG;EACH,OAAO,SAAS,OAAO,KAAK,SAAS,MAAM;EAC9C;;;AC9CL,MAAM,kBAAkB,QAA6B;CACjD,MAAM,OAAe,KAAK,QAAQ,KAAK,eAA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G;IACf,QAAQ,IAAI,GAAG;;GAGnB,YAAY,UAAU,UAA2B;IAK7C,IAAI,UAAkB,GAJF,KAAK,SAAS,KAAK,KAAK,MAAM,OAAO,IAI7B,CAAC,KAFR,KAAK,SAAS,KAAK,KAAK,MAAM,OAAO,KAEpB;IAEtC,MAAM,QAAkB,EAAE;IAE1B,IAAI,MAAM,OAAO,SACb,MAAM,KAAK,IAAI;IAGnB,IAAI,MAAM,OAAO,aACb,MAAM,KAAK,IAAI;IAGnB,IAAI,MAAM,SAAS,GACf,WAAW,KAAK,MAAM,KAAK,IAAI,CAAC;IAGpC,IAAI,QAAQ,QAAQ;;GAGxB,YAAY,cAAoB;IAC5B,QAAQ,IAAI,GAAG;;;EAIvB,QAAQ,KAAK,KAAK,YAAY,CAAW;;CAG7C,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/vitejs/vite-plugin-registry/refs/heads/main/data/schema/extended-package-json.schema.json",
|
|
3
3
|
"name": "vitend",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"description": "A library for backend development with Vite",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"vitend",
|
|
@@ -57,8 +57,9 @@
|
|
|
57
57
|
"dist"
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
|
+
"consola": "^3.4.0",
|
|
60
61
|
"es-toolkit": "^1.40.0",
|
|
61
|
-
"rolldown-plugin-copy": "~0.
|
|
62
|
+
"rolldown-plugin-copy": "~0.2.0",
|
|
62
63
|
"srvx": "~0.11.0",
|
|
63
64
|
"ts-vista": "~0.2.3"
|
|
64
65
|
},
|