@hono/vite-build 1.9.3 → 1.10.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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @hono/vite-build
2
2
 
3
+ ## 1.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#349](https://github.com/honojs/vite-plugins/pull/349) [`7680ba2f76618082b3be6f94da7ef61429f08567`](https://github.com/honojs/vite-plugins/commit/7680ba2f76618082b3be6f94da7ef61429f08567) Thanks [@Moshyfawn](https://github.com/Moshyfawn)! - Propagate user externals to rollupOptions.external and auto-externalize bare "bun" specifier in Bun adapter
8
+
9
+ ## 1.10.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#339](https://github.com/honojs/vite-plugins/pull/339) [`6896d6d17809c8148c1b2ad067a7deeb4ecb6744`](https://github.com/honojs/vite-plugins/commit/6896d6d17809c8148c1b2ad067a7deeb4ecb6744) Thanks [@josiahwiebe](https://github.com/josiahwiebe)! - feat: allows configuring vercel helpers
14
+
15
+ ### Patch Changes
16
+
17
+ - [#342](https://github.com/honojs/vite-plugins/pull/342) [`ce81be036106779d04fe690d7eb8baa85b47b03f`](https://github.com/honojs/vite-plugins/commit/ce81be036106779d04fe690d7eb8baa85b47b03f) Thanks [@meck93](https://github.com/meck93)! - Fix static path discovery when `publicDir` does not exist.
18
+ Split shared `try/catch` so a missing `publicDir` no longer prevents `outDir` from being read, which caused `serveStatic` middleware to not be injected.
19
+
3
20
  ## 1.9.3
4
21
 
5
22
  ### Patch Changes
@@ -41,6 +41,7 @@ const bunBuildPlugin = (pluginOptions) => {
41
41
  ]
42
42
  },
43
43
  ...pluginOptions,
44
+ external: ["bun", ...pluginOptions?.external ?? []],
44
45
  entryContentAfterHooks: pluginOptions?.entryContentAfterHooks ?? defaultOptions.entryContentAfterHooks,
45
46
  entryContentDefaultExportHook: pluginOptions?.entryContentDefaultExportHook ?? defaultOptions.entryContentDefaultExportHook
46
47
  }),
@@ -1,12 +1,12 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { BuildOptions } from '../../base.js';
3
- import { VercelBuildConfigV3, VercelServerlessFunctionConfig } from './types.js';
3
+ import { VercelBuildConfigV3, VercelNodejsServerlessFunctionConfig } from './types.js';
4
4
  import '../../entry/index.js';
5
5
 
6
6
  type VercelBuildOptions = {
7
7
  vercel?: {
8
8
  config?: VercelBuildConfigV3;
9
- function?: VercelServerlessFunctionConfig;
9
+ function?: Partial<VercelNodejsServerlessFunctionConfig>;
10
10
  };
11
11
  } & Omit<BuildOptions, 'output' | 'outputDir'>;
12
12
  declare const vercelBuildPlugin: (pluginOptions?: VercelBuildOptions) => Plugin;
@@ -60,15 +60,14 @@ const vercelBuildPlugin = (pluginOptions) => {
60
60
  runtime: getRuntimeVersion(),
61
61
  launcherType: "Nodejs",
62
62
  handler: BUNDLE_NAME,
63
- shouldAddHelpers: true,
63
+ shouldAddHelpers: Boolean(pluginOptions?.vercel?.function?.shouldAddHelpers),
64
64
  shouldAddSourcemapSupport: Boolean(config.build.sourcemap),
65
65
  supportsResponseStreaming: true
66
66
  };
67
+ const publicDirPath = resolve(config.root, config.publicDir);
67
68
  await Promise.all([
68
69
  // Copy static files to the .vercel/output/static directory
69
- cp(resolve(config.root, config.publicDir), resolve(outputDir, "static"), {
70
- recursive: true
71
- }),
70
+ ...existsSync(publicDirPath) ? [cp(publicDirPath, resolve(outputDir, "static"), { recursive: true })] : [],
72
71
  // Write the all necessary config files
73
72
  writeJSON(resolve(outputDir, "config.json"), buildConfig),
74
73
  writeJSON(resolve(functionDir, ".vc-config.json"), functionConfig),
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Main configuration type for Vercel Build Output API v3.
3
3
  * This type represents the root configuration object that should be output in the `.vercel/output/config.json` file.
4
- * @see https://vercel.com/docs/build-output-api/configuration
4
+ * @see https://vercel.com/docs/build-output-api/v3/configuration
5
5
  */
6
6
  type VercelBuildConfigV3 = {
7
7
  /** Version identifier for the Build Output API. Must be 3. */
@@ -14,33 +14,38 @@ type VercelBuildConfigV3 = {
14
14
  /**
15
15
  * Configuration for Vercel's Image Optimization feature.
16
16
  * Defines how images should be optimized, cached, and served.
17
- * @see https://vercel.com/docs/build-output-api/configuration#images
17
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#images
18
18
  */
19
19
  images?: ImagesConfig;
20
20
  /**
21
21
  * Custom domain wildcard configurations for internationalization.
22
22
  * Maps domain names to values that can be referenced by the routes configuration.
23
- * @see https://vercel.com/docs/build-output-api/configuration#wildcard
23
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#wildcard
24
24
  */
25
25
  wildcard?: WildCard[];
26
26
  /**
27
27
  * File-specific overrides for static files in the `.vercel/output/static` directory.
28
28
  * Allows overriding Content-Type headers and URL paths for static files.
29
- * @see https://vercel.com/docs/build-output-api/configuration#overrides
29
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#overrides
30
30
  */
31
31
  overrides?: Record<string, Override>;
32
32
  /**
33
33
  * Array of file paths or glob patterns to be cached between builds.
34
34
  * Only relevant when Vercel is building from source code.
35
- * @see https://vercel.com/docs/build-output-api/configuration#cache
35
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#cache
36
36
  */
37
37
  cache?: string[];
38
38
  /**
39
39
  * Scheduled tasks configuration for production deployments.
40
40
  * Defines API routes that should be invoked on a schedule.
41
- * @see https://vercel.com/docs/build-output-api/configuration#crons
41
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#crons
42
42
  */
43
43
  crons?: Cron[];
44
+ /**
45
+ * Framework metadata for display purposes only.
46
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#framework
47
+ */
48
+ framework?: Framework;
44
49
  };
45
50
  /**
46
51
  * Route configuration that can either be a Source route or a Handler route.
@@ -69,15 +74,19 @@ type Source = {
69
74
  /** HTTP status code to return (e.g., 308 for redirects) */
70
75
  status?: number;
71
76
  /** Conditions that must be present in the request for the route to match */
72
- has?: Array<HostHasField | HeaderHasField | CookieHasField | QueryHasField>;
77
+ has?: HasField;
73
78
  /** Conditions that must be absent from the request for the route to match */
74
- missing?: Array<HostHasField | HeaderHasField | CookieHasField | QueryHasField>;
79
+ missing?: HasField;
75
80
  /** Configuration for locale-based routing and redirects */
76
81
  locale?: Locale;
77
82
  /** Raw source patterns used by middleware */
78
83
  middlewareRawSrc?: string[];
79
84
  /** Path to the middleware implementation file */
80
85
  middlewarePath?: string;
86
+ /** Mitigation action to apply to the route */
87
+ mitigate?: Mitigate;
88
+ /** List of transforms to apply to the route */
89
+ transforms?: Transform[];
81
90
  };
82
91
  /**
83
92
  * Locale configuration for internationalization routing.
@@ -90,51 +99,52 @@ type Locale = {
90
99
  cookie?: string;
91
100
  };
92
101
  /**
93
- * Host-based condition for route matching.
94
- * Used to match requests based on the Host header.
95
- */
96
- type HostHasField = {
97
- /** Identifies this as a host matching condition */
98
- type: 'host';
99
- /** Pattern to match against the Host header */
100
- value: string;
101
- };
102
- /**
103
- * Header-based condition for route matching.
104
- * Used to match requests based on HTTP headers.
102
+ * Matchable value for complex route condition matching.
103
+ * Allows matching against values using various comparison operators.
104
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#source-route-matchablevalue
105
105
  */
106
- type HeaderHasField = {
107
- /** Identifies this as a header matching condition */
108
- type: 'header';
109
- /** Name of the header to match */
110
- key: string;
111
- /** Optional value the header should match */
112
- value?: string;
106
+ type MatchableValue = {
107
+ /** Value must equal this value */
108
+ eq?: string | number;
109
+ /** Value must not equal this value */
110
+ neq?: string;
111
+ /** Value must be included in this array */
112
+ inc?: string[];
113
+ /** Value must not be included in this array */
114
+ ninc?: string[];
115
+ /** Value must start with this prefix */
116
+ pre?: string;
117
+ /** Value must end with this suffix */
118
+ suf?: string;
119
+ /** Value must match this regular expression */
120
+ re?: string;
121
+ /** Value must be greater than this number */
122
+ gt?: number;
123
+ /** Value must be greater than or equal to this number */
124
+ gte?: number;
125
+ /** Value must be less than this number */
126
+ lt?: number;
127
+ /** Value must be less than or equal to this number */
128
+ lte?: number;
113
129
  };
114
130
  /**
115
- * Cookie-based condition for route matching.
116
- * Used to match requests based on cookie values.
131
+ * Condition fields for route matching based on request properties.
132
+ * Used in `has` and `missing` arrays on Source routes.
133
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#source-route-hasfield
117
134
  */
118
- type CookieHasField = {
119
- /** Identifies this as a cookie matching condition */
120
- type: 'cookie';
121
- /** Name of the cookie to match */
122
- key: string;
123
- /** Optional value the cookie should match */
124
- value?: string;
125
- };
126
- /**
127
- * Query parameter condition for route matching.
128
- * Used to match requests based on query string parameters.
129
- */
130
- type QueryHasField = {
131
- /** Identifies this as a query parameter matching condition */
132
- type: 'query';
133
- /** Name of the query parameter to match */
135
+ type HasField = Array<{
136
+ /** Identifies this as a host matching condition */
137
+ type: 'host';
138
+ /** Pattern to match against the Host header */
139
+ value: string | MatchableValue;
140
+ } | {
141
+ /** Identifies the condition type: header, cookie, or query parameter */
142
+ type: 'header' | 'cookie' | 'query';
143
+ /** Name of the header, cookie, or query parameter to match */
134
144
  key: string;
135
- /** Optional value the query parameter should match */
136
- value?: string;
137
- };
145
+ /** Optional value the field should match */
146
+ value?: string | MatchableValue;
147
+ }>;
138
148
  /**
139
149
  * Special handler phases for request processing.
140
150
  * Defines when and how requests should be processed in the routing pipeline.
@@ -154,9 +164,33 @@ type Handler = {
154
164
  /** HTTP status code to return in the response */
155
165
  status?: number;
156
166
  };
167
+ /**
168
+ * Mitigation action to apply to a route.
169
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#source-route-mitigate
170
+ */
171
+ type Mitigate = {
172
+ /** The mitigation action to apply */
173
+ action: 'challenge' | 'deny';
174
+ };
175
+ /**
176
+ * Transform to apply to request or response properties on a route.
177
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#source-route-transform
178
+ */
179
+ type Transform = {
180
+ /** The target of the transform: request headers, request query, or response headers */
181
+ type: 'request.headers' | 'request.query' | 'response.headers';
182
+ /** The operation to perform */
183
+ op: 'append' | 'set' | 'delete';
184
+ /** The target key for the transform (regex matching not supported) */
185
+ target: {
186
+ key: string | Omit<MatchableValue, 're'>;
187
+ };
188
+ /** Arguments for the transform operation */
189
+ args?: string | string[];
190
+ };
157
191
  /**
158
192
  * Supported image formats for the Image Optimization API.
159
- * @see https://vercel.com/docs/build-output-api/configuration#images
193
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#images
160
194
  */
161
195
  type ImageFormat = 'image/avif' | 'image/webp';
162
196
  /**
@@ -187,7 +221,7 @@ type LocalPattern = {
187
221
  };
188
222
  /**
189
223
  * Configuration for Vercel's Image Optimization feature.
190
- * @see https://vercel.com/docs/build-output-api/configuration#images
224
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#images
191
225
  */
192
226
  type ImagesConfig = {
193
227
  /** Array of allowed image widths for resizing */
@@ -214,7 +248,7 @@ type ImagesConfig = {
214
248
  /**
215
249
  * Configuration for custom domain wildcards.
216
250
  * Used for internationalization and dynamic routing based on domains.
217
- * @see https://vercel.com/docs/build-output-api/configuration#wildcard
251
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#wildcard
218
252
  */
219
253
  type WildCard = {
220
254
  /** Domain name to match for this wildcard configuration */
@@ -224,7 +258,7 @@ type WildCard = {
224
258
  };
225
259
  /**
226
260
  * Configuration for path or content-type overrides of static files.
227
- * @see https://vercel.com/docs/build-output-api/configuration#overrides
261
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#overrides
228
262
  */
229
263
  type Override = {
230
264
  /** URL path where the static file will be accessible */
@@ -234,7 +268,7 @@ type Override = {
234
268
  };
235
269
  /**
236
270
  * Configuration for scheduled tasks (Cron Jobs).
237
- * @see https://vercel.com/docs/build-output-api/configuration#crons
271
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#crons
238
272
  */
239
273
  type Cron = {
240
274
  /** Path to the API route that handles the cron job */
@@ -243,29 +277,92 @@ type Cron = {
243
277
  schedule: string;
244
278
  };
245
279
  /**
246
- * Configuration for a serverless function in Vercel.
247
- * This type **partially** represents the configuration object that should be output in the `.vercel/output/functions/<functionName>/config.json` file.
248
- * @see https://vercel.com/docs/build-output-api/primitives#serverless-function-configuration
280
+ * Framework metadata for display purposes.
281
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#framework
282
+ */
283
+ type Framework = {
284
+ /** Framework version string */
285
+ version: string;
286
+ };
287
+ /**
288
+ * Base configuration for a serverless function in Vercel.
289
+ * This type represents the `.vc-config.json` configuration within a `.func` directory.
290
+ * @see https://vercel.com/docs/build-output-api/v3/primitives#serverless-function-configuration
249
291
  */
250
292
  type VercelServerlessFunctionConfig = {
251
- /** Indicates the initial file where code will be executed for the Serverless Function. */
252
- handler?: string;
253
- /** Specifies which "launcher" will be used to execute the Serverless Function */
254
- launcherType?: 'Nodejs';
255
- /** Specifies which "runtime" will be used to execute the Serverless Function, only Node.js is supported currently */
256
- runtime?: `nodejs${number}.x`;
257
- /** The amount of memory allocated to the function in MB */
293
+ /** Indicates the initial file where code will be executed for the Serverless Function */
294
+ handler: string;
295
+ /** Specifies which "runtime" will be used to execute the Serverless Function */
296
+ runtime: string;
297
+ /** The amount of memory (RAM in MB) allocated to the function */
258
298
  memory?: number;
259
299
  /** The maximum duration of the function in seconds */
260
300
  maxDuration?: number;
301
+ /** Map of additional environment variables available to the function */
302
+ environment?: Record<string, string>;
261
303
  /** The regions the function is available in */
262
304
  regions?: string[];
305
+ /** Instruction set architecture the function supports */
306
+ architecture?: 'x86_64' | 'arm64';
307
+ /** Whether the custom runtime supports Lambda runtime wrappers */
308
+ supportsWrapper?: boolean;
263
309
  /** Whether the function supports response streaming */
264
310
  supportsResponseStreaming?: boolean;
311
+ };
312
+ /**
313
+ * Node.js-specific serverless function configuration.
314
+ * Extends the base serverless function config with Node.js launcher options.
315
+ * @see https://vercel.com/docs/build-output-api/v3/primitives#nodejs-config
316
+ */
317
+ type VercelNodejsServerlessFunctionConfig = VercelServerlessFunctionConfig & {
318
+ /** Specifies which "launcher" will be used to execute the Serverless Function */
319
+ launcherType: 'Nodejs';
265
320
  /** Enables request and response helpers methods */
266
321
  shouldAddHelpers?: boolean;
267
322
  /** Enables source map generation */
268
323
  shouldAddSourcemapSupport?: boolean;
324
+ /** AWS Handler Value for when the serverless function uses AWS Lambda syntax */
325
+ awsLambdaHandler?: string;
326
+ };
327
+ /**
328
+ * Configuration for an Edge Function in Vercel.
329
+ * This type represents the `.vc-config.json` configuration for Edge Functions.
330
+ * @see https://vercel.com/docs/build-output-api/v3/primitives#edge-function-configuration
331
+ */
332
+ type VercelEdgeFunctionConfig = {
333
+ /** Must be 'edge' to indicate this is an Edge Function */
334
+ runtime: 'edge';
335
+ /** Initial file where code will be executed for the Edge Function */
336
+ entrypoint: string;
337
+ /** List of environment variable names available to the Edge Function */
338
+ envVarsInUse?: string[];
339
+ /** Regions the edge function will be available in (defaults to 'all') */
340
+ regions?: 'all' | string | string[];
341
+ };
342
+ /**
343
+ * Configuration for a Prerender Function in Vercel (ISR).
344
+ * This type represents the `.prerender-config.json` configuration file.
345
+ * @see https://vercel.com/docs/build-output-api/v3/primitives#prerender-configuration-file
346
+ */
347
+ type VercelPrerenderFunctionConfig = {
348
+ /** Cache expiration time in seconds, or false to never expire */
349
+ expiration: number | false;
350
+ /** Group number for co-revalidating prerender assets together */
351
+ group?: number;
352
+ /** Random token for Draft Mode bypass cookie (`__prerender_bypass`) */
353
+ bypassToken?: string;
354
+ /** Name of the optional fallback file relative to the configuration file */
355
+ fallback?: string;
356
+ /** Query string parameter names that will be cached independently */
357
+ allowQuery?: string[];
358
+ /** When true, the query string will be present on the request argument */
359
+ passQuery?: boolean;
360
+ /** Initial headers to include with the build-time prerendered response */
361
+ initialHeaders?: Record<string, string>;
362
+ /** Initial HTTP status code for the build-time prerendered response (default 200) */
363
+ initialStatus?: number;
364
+ /** When true, expose the response body regardless of status code including errors */
365
+ exposeErrBody?: boolean;
269
366
  };
270
367
 
271
- export { VercelBuildConfigV3, VercelServerlessFunctionConfig };
368
+ export { VercelBuildConfigV3, VercelEdgeFunctionConfig, VercelNodejsServerlessFunctionConfig, VercelPrerenderFunctionConfig, VercelServerlessFunctionConfig };
package/dist/base.js CHANGED
@@ -44,6 +44,9 @@ const buildPlugin = (options) => {
44
44
  withFileTypes: true
45
45
  });
46
46
  direntPaths.push(...publicDirPaths);
47
+ } catch {
48
+ }
49
+ try {
47
50
  const buildOutDirPaths = readdirSync(resolve(config.root, config.build.outDir), {
48
51
  withFileTypes: true
49
52
  });
@@ -87,7 +90,11 @@ const buildPlugin = (options) => {
87
90
  minify: options?.minify ?? defaultOptions.minify,
88
91
  ssr: true,
89
92
  rollupOptions: {
90
- external: [...builtinModules, /^node:/],
93
+ external: [
94
+ ...builtinModules,
95
+ /^node:/,
96
+ ...options?.external ?? defaultOptions.external
97
+ ],
91
98
  input: virtualEntryId,
92
99
  output: {
93
100
  entryFileNames: output
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hono/vite-build",
3
3
  "description": "Vite plugin to build your Hono app",
4
- "version": "1.9.3",
4
+ "version": "1.10.1",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.js",
7
7
  "type": "module",
@@ -93,7 +93,7 @@
93
93
  "vite-plugin"
94
94
  ],
95
95
  "devDependencies": {
96
- "@hono/node-server": "^1.19.6",
96
+ "@hono/node-server": "^1.19.11",
97
97
  "@types/node": "^24.10.0",
98
98
  "glob": "^10.3.10",
99
99
  "hono": "^4.6.12",