@hono/vite-build 1.10.1 → 1.11.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/CHANGELOG.md +6 -0
- package/README.md +37 -0
- package/dist/adapter/bun/{index.d.ts → index.d.mts} +6 -6
- package/dist/adapter/bun/index.mjs +47 -0
- package/dist/adapter/cloudflare-pages/{index.d.ts → index.d.mts} +5 -5
- package/dist/adapter/cloudflare-pages/index.mjs +41 -0
- package/dist/adapter/cloudflare-workers/{index.d.ts → index.d.mts} +6 -5
- package/dist/adapter/cloudflare-workers/index.mjs +33 -0
- package/dist/adapter/deno/index.d.mts +10 -0
- package/dist/adapter/deno/index.mjs +21 -0
- package/dist/adapter/netlify-functions/{index.d.ts → index.d.mts} +5 -5
- package/dist/adapter/netlify-functions/index.mjs +16 -0
- package/dist/adapter/node/index.d.mts +19 -0
- package/dist/adapter/node/index.mjs +37 -0
- package/dist/adapter/vercel/index.d.mts +22 -0
- package/dist/adapter/vercel/index.mjs +170 -0
- package/dist/adapter/vercel/types.d.mts +276 -0
- package/dist/adapter/vercel/types.mjs +1 -0
- package/dist/base.d.mts +30 -0
- package/dist/base.mjs +99 -0
- package/dist/entry/index.d.mts +27 -0
- package/dist/entry/index.mjs +63 -0
- package/dist/entry/{serve-static.d.ts → serve-static.d.mts} +5 -4
- package/dist/entry/serve-static.mjs +8 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +5 -0
- package/package.json +21 -53
- package/dist/adapter/bun/index.js +0 -55
- package/dist/adapter/cloudflare-pages/index.js +0 -53
- package/dist/adapter/cloudflare-workers/index.js +0 -37
- package/dist/adapter/deno/index.d.ts +0 -10
- package/dist/adapter/deno/index.js +0 -28
- package/dist/adapter/netlify-functions/index.js +0 -18
- package/dist/adapter/node/index.d.ts +0 -19
- package/dist/adapter/node/index.js +0 -50
- package/dist/adapter/vercel/index.d.ts +0 -14
- package/dist/adapter/vercel/index.js +0 -85
- package/dist/adapter/vercel/types.d.ts +0 -368
- package/dist/adapter/vercel/types.js +0 -0
- package/dist/base.d.ts +0 -29
- package/dist/base.js +0 -112
- package/dist/entry/index.d.ts +0 -26
- package/dist/entry/index.js +0 -69
- package/dist/entry/serve-static.js +0 -11
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -6
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import buildPlugin, { defaultOptions as baseDefaultOptions } from "../../base.js";
|
|
2
|
-
import { serveStaticHook } from "../../entry/serve-static.js";
|
|
3
|
-
const defaultOptions = {
|
|
4
|
-
...baseDefaultOptions,
|
|
5
|
-
entryContentAfterHooks: [
|
|
6
|
-
() => `
|
|
7
|
-
let websocket
|
|
8
|
-
for (const [, app] of Object.entries(modules)) {
|
|
9
|
-
if (
|
|
10
|
-
app &&
|
|
11
|
-
typeof app === 'object' &&
|
|
12
|
-
'websocket' in app &&
|
|
13
|
-
app.websocket !== undefined
|
|
14
|
-
) {
|
|
15
|
-
if (websocket !== undefined) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
\`Handler "websocket" is defined in multiple entry files. Please ensure each handler is defined only once.\`
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
websocket = app.websocket
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
`
|
|
24
|
-
],
|
|
25
|
-
entryContentDefaultExportHook: (appName) => `export default websocket !== undefined ? { fetch: ${appName}.fetch.bind(${appName}), websocket } : ${appName}`
|
|
26
|
-
};
|
|
27
|
-
const bunBuildPlugin = (pluginOptions) => {
|
|
28
|
-
return {
|
|
29
|
-
...buildPlugin({
|
|
30
|
-
ssrTarget: "node",
|
|
31
|
-
...{
|
|
32
|
-
entryContentBeforeHooks: [
|
|
33
|
-
async (appName, options) => {
|
|
34
|
-
let code = "import { serveStatic } from 'hono/bun'\n";
|
|
35
|
-
code += serveStaticHook(appName, {
|
|
36
|
-
filePaths: options?.staticPaths,
|
|
37
|
-
root: pluginOptions?.staticRoot
|
|
38
|
-
});
|
|
39
|
-
return code;
|
|
40
|
-
}
|
|
41
|
-
]
|
|
42
|
-
},
|
|
43
|
-
...pluginOptions,
|
|
44
|
-
external: ["bun", ...pluginOptions?.external ?? []],
|
|
45
|
-
entryContentAfterHooks: pluginOptions?.entryContentAfterHooks ?? defaultOptions.entryContentAfterHooks,
|
|
46
|
-
entryContentDefaultExportHook: pluginOptions?.entryContentDefaultExportHook ?? defaultOptions.entryContentDefaultExportHook
|
|
47
|
-
}),
|
|
48
|
-
name: "@hono/vite-build/bun"
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
var bun_default = bunBuildPlugin;
|
|
52
|
-
export {
|
|
53
|
-
bun_default as default,
|
|
54
|
-
defaultOptions
|
|
55
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { readdir, writeFile } from "node:fs/promises";
|
|
2
|
-
import { resolve } from "node:path";
|
|
3
|
-
import buildPlugin, { defaultOptions } from "../../base.js";
|
|
4
|
-
const WORKER_JS_NAME = "_worker.js";
|
|
5
|
-
const ROUTES_JSON_NAME = "_routes.json";
|
|
6
|
-
const cloudflarePagesBuildPlugin = (pluginOptions) => {
|
|
7
|
-
let config;
|
|
8
|
-
const staticPaths = [];
|
|
9
|
-
return {
|
|
10
|
-
...buildPlugin({
|
|
11
|
-
...pluginOptions,
|
|
12
|
-
output: WORKER_JS_NAME
|
|
13
|
-
}),
|
|
14
|
-
configResolved: async (resolvedConfig) => {
|
|
15
|
-
config = resolvedConfig;
|
|
16
|
-
},
|
|
17
|
-
writeBundle: async () => {
|
|
18
|
-
const paths = await readdir(resolve(config.root, config.build.outDir), {
|
|
19
|
-
withFileTypes: true
|
|
20
|
-
});
|
|
21
|
-
if (paths.some((p) => p.name === ROUTES_JSON_NAME)) {
|
|
22
|
-
return;
|
|
23
|
-
} else {
|
|
24
|
-
paths.forEach((p) => {
|
|
25
|
-
if (p.isDirectory()) {
|
|
26
|
-
staticPaths.push(`/${p.name}/*`);
|
|
27
|
-
} else {
|
|
28
|
-
if (p.name === WORKER_JS_NAME) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
staticPaths.push(`/${p.name}`);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
const staticRoutes = {
|
|
35
|
-
version: 1,
|
|
36
|
-
include: ["/*"],
|
|
37
|
-
exclude: staticPaths
|
|
38
|
-
};
|
|
39
|
-
const path = resolve(
|
|
40
|
-
config.root,
|
|
41
|
-
pluginOptions?.outputDir ?? defaultOptions.outputDir,
|
|
42
|
-
"_routes.json"
|
|
43
|
-
);
|
|
44
|
-
await writeFile(path, JSON.stringify(staticRoutes));
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
name: "@hono/vite-build/cloudflare-pages"
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
var cloudflare_pages_default = cloudflarePagesBuildPlugin;
|
|
51
|
-
export {
|
|
52
|
-
cloudflare_pages_default as default
|
|
53
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import buildPlugin, { defaultOptions as baseDefaultOptions } from "../../base.js";
|
|
2
|
-
const defaultOptions = {
|
|
3
|
-
...baseDefaultOptions,
|
|
4
|
-
entryContentAfterHooks: [
|
|
5
|
-
() => `
|
|
6
|
-
const merged = {}
|
|
7
|
-
const definedHandlers = new Set()
|
|
8
|
-
for (const [file, app] of Object.entries(modules)) {
|
|
9
|
-
for (const [key, handler] of Object.entries(app)) {
|
|
10
|
-
if (key !== 'fetch') {
|
|
11
|
-
if (definedHandlers.has(key)) {
|
|
12
|
-
throw new Error(\`Handler "\${key}" is defined in multiple entry files. Please ensure each handler (except fetch) is defined only once.\`);
|
|
13
|
-
}
|
|
14
|
-
definedHandlers.add(key)
|
|
15
|
-
merged[key] = handler
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
`
|
|
20
|
-
],
|
|
21
|
-
entryContentDefaultExportHook: (appName) => `export default { ...merged, fetch: ${appName}.fetch }`
|
|
22
|
-
};
|
|
23
|
-
const cloudflareWorkersBuildPlugin = (pluginOptions) => {
|
|
24
|
-
return {
|
|
25
|
-
...buildPlugin({
|
|
26
|
-
...pluginOptions,
|
|
27
|
-
entryContentAfterHooks: pluginOptions?.entryContentAfterHooks ?? defaultOptions.entryContentAfterHooks,
|
|
28
|
-
entryContentDefaultExportHook: pluginOptions?.entryContentDefaultExportHook ?? defaultOptions.entryContentDefaultExportHook
|
|
29
|
-
}),
|
|
30
|
-
name: "@hono/vite-build/cloudflare-workers"
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
var cloudflare_workers_default = cloudflareWorkersBuildPlugin;
|
|
34
|
-
export {
|
|
35
|
-
cloudflare_workers_default as default,
|
|
36
|
-
defaultOptions
|
|
37
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
import { BuildOptions } from '../../base.js';
|
|
3
|
-
import '../../entry/index.js';
|
|
4
|
-
|
|
5
|
-
type DenoBuildOptions = {
|
|
6
|
-
staticRoot?: string | undefined;
|
|
7
|
-
} & BuildOptions;
|
|
8
|
-
declare const denoBuildPlugin: (pluginOptions?: DenoBuildOptions) => Plugin;
|
|
9
|
-
|
|
10
|
-
export { DenoBuildOptions, denoBuildPlugin as default };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import buildPlugin from "../../base.js";
|
|
2
|
-
import { serveStaticHook } from "../../entry/serve-static.js";
|
|
3
|
-
const denoBuildPlugin = (pluginOptions) => {
|
|
4
|
-
return {
|
|
5
|
-
...buildPlugin({
|
|
6
|
-
...{
|
|
7
|
-
entryContentBeforeHooks: [
|
|
8
|
-
async (appName, options) => {
|
|
9
|
-
const preset = pluginOptions?.preset ?? "hono";
|
|
10
|
-
let code = `import { serveStatic } from '${preset}/deno'
|
|
11
|
-
`;
|
|
12
|
-
code += serveStaticHook(appName, {
|
|
13
|
-
filePaths: options?.staticPaths,
|
|
14
|
-
root: pluginOptions?.staticRoot
|
|
15
|
-
});
|
|
16
|
-
return code;
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
},
|
|
20
|
-
...pluginOptions
|
|
21
|
-
}),
|
|
22
|
-
name: "@hono/vite-build/deno"
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
var deno_default = denoBuildPlugin;
|
|
26
|
-
export {
|
|
27
|
-
deno_default as default
|
|
28
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import buildPlugin from "../../base.js";
|
|
2
|
-
function netlifyFunctionsBuildPlugin(pluginOptions) {
|
|
3
|
-
return {
|
|
4
|
-
...buildPlugin({
|
|
5
|
-
ssrTarget: "node",
|
|
6
|
-
...{
|
|
7
|
-
entryContentBeforeHooks: [() => 'import { handle } from "hono/netlify"'],
|
|
8
|
-
entryContentAfterHooks: [() => 'export const config = { path: "/*", preferStatic: true }'],
|
|
9
|
-
entryContentDefaultExportHook: (appName) => `export default handle(${appName})`
|
|
10
|
-
},
|
|
11
|
-
...pluginOptions
|
|
12
|
-
}),
|
|
13
|
-
name: "@hono/vite-build/netlify-functions"
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export {
|
|
17
|
-
netlifyFunctionsBuildPlugin as default
|
|
18
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
import { BuildOptions } from '../../base.js';
|
|
3
|
-
import '../../entry/index.js';
|
|
4
|
-
|
|
5
|
-
type NodeBuildOptions = {
|
|
6
|
-
staticRoot?: string | undefined;
|
|
7
|
-
port?: number | undefined;
|
|
8
|
-
/**
|
|
9
|
-
* Enable graceful shutdown on SIGINT and SIGTERM signals.
|
|
10
|
-
* Set to a number to specify the timeout in milliseconds before forcing shutdown.
|
|
11
|
-
* Set to 0 to wait indefinitely for connections to close.
|
|
12
|
-
* Leave undefined to disable graceful shutdown.
|
|
13
|
-
* @default undefined
|
|
14
|
-
*/
|
|
15
|
-
shutdownTimeoutMs?: number | undefined;
|
|
16
|
-
} & BuildOptions;
|
|
17
|
-
declare const nodeBuildPlugin: (pluginOptions?: NodeBuildOptions) => Plugin;
|
|
18
|
-
|
|
19
|
-
export { NodeBuildOptions, nodeBuildPlugin as default };
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import buildPlugin from "../../base.js";
|
|
2
|
-
import { serveStaticHook } from "../../entry/serve-static.js";
|
|
3
|
-
const nodeBuildPlugin = (pluginOptions) => {
|
|
4
|
-
const port = pluginOptions?.port ?? 3e3;
|
|
5
|
-
const shutdownTimeoutMs = pluginOptions?.shutdownTimeoutMs;
|
|
6
|
-
return {
|
|
7
|
-
...buildPlugin({
|
|
8
|
-
ssrTarget: "node",
|
|
9
|
-
...{
|
|
10
|
-
entryContentBeforeHooks: [
|
|
11
|
-
async (appName, options) => {
|
|
12
|
-
let code = "import { serveStatic } from '@hono/node-server/serve-static'\n";
|
|
13
|
-
code += serveStaticHook(appName, {
|
|
14
|
-
filePaths: options?.staticPaths,
|
|
15
|
-
root: pluginOptions?.staticRoot
|
|
16
|
-
});
|
|
17
|
-
return code;
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
entryContentAfterHooks: [
|
|
21
|
-
async (appName) => {
|
|
22
|
-
let code = "import { serve } from '@hono/node-server'\n";
|
|
23
|
-
if (shutdownTimeoutMs !== void 0) {
|
|
24
|
-
code += `const server = serve({ fetch: ${appName}.fetch, port: ${port.toString()} })
|
|
25
|
-
`;
|
|
26
|
-
code += "const gracefulShutdown = () => {\n";
|
|
27
|
-
code += " server.close(() => process.exit(0))\n";
|
|
28
|
-
if (shutdownTimeoutMs > 0) {
|
|
29
|
-
code += ` setTimeout(() => process.exit(1), ${shutdownTimeoutMs}).unref()
|
|
30
|
-
`;
|
|
31
|
-
}
|
|
32
|
-
code += "}\n";
|
|
33
|
-
code += "process.on('SIGINT', gracefulShutdown)\n";
|
|
34
|
-
code += "process.on('SIGTERM', gracefulShutdown)";
|
|
35
|
-
} else {
|
|
36
|
-
code += `serve({ fetch: ${appName}.fetch, port: ${port.toString()} })`;
|
|
37
|
-
}
|
|
38
|
-
return code;
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
},
|
|
42
|
-
...pluginOptions
|
|
43
|
-
}),
|
|
44
|
-
name: "@hono/vite-build/node"
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
var node_default = nodeBuildPlugin;
|
|
48
|
-
export {
|
|
49
|
-
node_default as default
|
|
50
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
import { BuildOptions } from '../../base.js';
|
|
3
|
-
import { VercelBuildConfigV3, VercelNodejsServerlessFunctionConfig } from './types.js';
|
|
4
|
-
import '../../entry/index.js';
|
|
5
|
-
|
|
6
|
-
type VercelBuildOptions = {
|
|
7
|
-
vercel?: {
|
|
8
|
-
config?: VercelBuildConfigV3;
|
|
9
|
-
function?: Partial<VercelNodejsServerlessFunctionConfig>;
|
|
10
|
-
};
|
|
11
|
-
} & Omit<BuildOptions, 'output' | 'outputDir'>;
|
|
12
|
-
declare const vercelBuildPlugin: (pluginOptions?: VercelBuildOptions) => Plugin;
|
|
13
|
-
|
|
14
|
-
export { VercelBuildOptions, vercelBuildPlugin as default };
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
2
|
-
import { cp, writeFile } from "node:fs/promises";
|
|
3
|
-
import { resolve } from "node:path";
|
|
4
|
-
import buildPlugin from "../../base.js";
|
|
5
|
-
const BUNDLE_NAME = "index.js";
|
|
6
|
-
const FUNCTION_NAME = "__hono";
|
|
7
|
-
const writeJSON = (path, data) => {
|
|
8
|
-
const dir = resolve(path, "..");
|
|
9
|
-
if (!existsSync(dir)) {
|
|
10
|
-
mkdirSync(dir, { recursive: true });
|
|
11
|
-
}
|
|
12
|
-
return writeFile(path, JSON.stringify(data));
|
|
13
|
-
};
|
|
14
|
-
const getRuntimeVersion = () => {
|
|
15
|
-
try {
|
|
16
|
-
const systemNodeVersion = process.versions.node.split(".")[0];
|
|
17
|
-
return `nodejs${Number(systemNodeVersion)}.x`;
|
|
18
|
-
} catch {
|
|
19
|
-
return "nodejs22.x";
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const vercelBuildPlugin = (pluginOptions) => {
|
|
23
|
-
let config;
|
|
24
|
-
return {
|
|
25
|
-
...buildPlugin({
|
|
26
|
-
ssrTarget: "node",
|
|
27
|
-
output: `functions/${FUNCTION_NAME}.func/${BUNDLE_NAME}`,
|
|
28
|
-
outputDir: ".vercel/output",
|
|
29
|
-
...{
|
|
30
|
-
entryContentAfterHooks: [
|
|
31
|
-
// eslint-disable-next-line quotes
|
|
32
|
-
() => "import { handle } from '@hono/node-server/vercel'"
|
|
33
|
-
],
|
|
34
|
-
entryContentDefaultExportHook: (appName) => `export default handle(${appName})`
|
|
35
|
-
},
|
|
36
|
-
...pluginOptions
|
|
37
|
-
}),
|
|
38
|
-
configResolved: (resolvedConfig) => {
|
|
39
|
-
config = resolvedConfig;
|
|
40
|
-
},
|
|
41
|
-
writeBundle: async () => {
|
|
42
|
-
const outputDir = resolve(config.root, config.build.outDir);
|
|
43
|
-
const functionDir = resolve(outputDir, "functions", `${FUNCTION_NAME}.func`);
|
|
44
|
-
const buildConfig = {
|
|
45
|
-
...pluginOptions?.vercel?.config,
|
|
46
|
-
version: 3,
|
|
47
|
-
routes: [
|
|
48
|
-
...pluginOptions?.vercel?.config?.routes ?? [],
|
|
49
|
-
{
|
|
50
|
-
handle: "filesystem"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
src: "/(.*)",
|
|
54
|
-
dest: `/${FUNCTION_NAME}`
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
};
|
|
58
|
-
const functionConfig = {
|
|
59
|
-
...pluginOptions?.vercel?.function,
|
|
60
|
-
runtime: getRuntimeVersion(),
|
|
61
|
-
launcherType: "Nodejs",
|
|
62
|
-
handler: BUNDLE_NAME,
|
|
63
|
-
shouldAddHelpers: Boolean(pluginOptions?.vercel?.function?.shouldAddHelpers),
|
|
64
|
-
shouldAddSourcemapSupport: Boolean(config.build.sourcemap),
|
|
65
|
-
supportsResponseStreaming: true
|
|
66
|
-
};
|
|
67
|
-
const publicDirPath = resolve(config.root, config.publicDir);
|
|
68
|
-
await Promise.all([
|
|
69
|
-
// Copy static files to the .vercel/output/static directory
|
|
70
|
-
...existsSync(publicDirPath) ? [cp(publicDirPath, resolve(outputDir, "static"), { recursive: true })] : [],
|
|
71
|
-
// Write the all necessary config files
|
|
72
|
-
writeJSON(resolve(outputDir, "config.json"), buildConfig),
|
|
73
|
-
writeJSON(resolve(functionDir, ".vc-config.json"), functionConfig),
|
|
74
|
-
writeJSON(resolve(functionDir, "package.json"), {
|
|
75
|
-
type: "module"
|
|
76
|
-
})
|
|
77
|
-
]);
|
|
78
|
-
},
|
|
79
|
-
name: "@hono/vite-build/vercel"
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
var vercel_default = vercelBuildPlugin;
|
|
83
|
-
export {
|
|
84
|
-
vercel_default as default
|
|
85
|
-
};
|