@hono/cli 0.1.8 → 0.1.9

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.
Files changed (3) hide show
  1. package/README.md +8 -0
  2. package/dist/cli.js +65 -52
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -157,6 +157,7 @@ hono request [file] [options]
157
157
  - `-d, --data <data>` - Request body data
158
158
  - `-H, --header <header>` - Custom headers (can be used multiple times)
159
159
  - `-w, --watch` - Watch for changes and resend request
160
+ - `-e, --external <package>` - Mark package as external (can be used multiple times)
160
161
 
161
162
  **Examples:**
162
163
 
@@ -178,6 +179,9 @@ hono request -P /api/protected \
178
179
  -H 'Authorization: Bearer token' \
179
180
  -H 'User-Agent: MyApp' \
180
181
  src/your-app.ts
182
+
183
+ # Request with external packages (useful for Node.js native modules)
184
+ hono request -e pg -e dotenv src/your-app.ts
181
185
  ```
182
186
 
183
187
  **Response Format:**
@@ -212,6 +216,7 @@ hono serve [entry] [options]
212
216
  - `-p, --port <port>` - Port number (default: 7070)
213
217
  - `--show-routes` - Show registered routes
214
218
  - `--use <middleware>` - Use middleware (can be used multiple times)
219
+ - `-e, --external <package>` - Mark package as external (can be used multiple times)
215
220
 
216
221
  **Examples:**
217
222
 
@@ -238,6 +243,9 @@ hono serve --use 'cors()' --use 'logger()' src/app.ts
238
243
  hono serve \
239
244
  --use 'basicAuth({ username: "foo", password: "bar" })' \
240
245
  --use "serveStatic({ root: './' })"
246
+
247
+ # Start server with external packages (useful for Node.js native modules)
248
+ hono serve -e pg -e prisma src/app.ts
241
249
  ```
242
250
 
243
251
  ### `optimize`
package/dist/cli.js CHANGED
@@ -16217,17 +16217,25 @@ function requestCommand(program2) {
16217
16217
  return previous ? [...previous, value] : [value];
16218
16218
  },
16219
16219
  []
16220
+ ).option(
16221
+ "-e, --external <package>",
16222
+ "Mark package as external (can be used multiple times)",
16223
+ (value, previous) => {
16224
+ return previous ? [...previous, value] : [value];
16225
+ },
16226
+ []
16220
16227
  ).action(async (file, options) => {
16221
16228
  const path = options.path || "/";
16222
16229
  const watch = options.watch;
16223
- const buildIterator = getBuildIterator(file, watch);
16230
+ const external = options.external || [];
16231
+ const buildIterator = getBuildIterator(file, watch, external);
16224
16232
  for await (const app of buildIterator) {
16225
16233
  const result = await executeRequest(app, path, options);
16226
16234
  console.log(JSON.stringify(result, null, 2));
16227
16235
  }
16228
16236
  });
16229
16237
  }
16230
- function getBuildIterator(appPath, watch) {
16238
+ function getBuildIterator(appPath, watch, external = []) {
16231
16239
  let entry;
16232
16240
  let resolvedAppPath;
16233
16241
  if (appPath) {
@@ -16242,7 +16250,7 @@ function getBuildIterator(appPath, watch) {
16242
16250
  }
16243
16251
  const appFilePath = realpathSync2(resolvedAppPath);
16244
16252
  return buildAndImportApp(appFilePath, {
16245
- external: ["@hono/node-server"],
16253
+ external: ["@hono/node-server", ...external],
16246
16254
  watch,
16247
16255
  sourcemap: true
16248
16256
  });
@@ -16496,62 +16504,67 @@ function serveCommand(program2) {
16496
16504
  return previous ? [...previous, value] : [value];
16497
16505
  },
16498
16506
  []
16499
- ).action(
16500
- async (entry, options) => {
16501
- let app;
16502
- if (!entry) {
16507
+ ).option(
16508
+ "-e, --external <package>",
16509
+ "Mark package as external (can be used multiple times)",
16510
+ (value, previous) => {
16511
+ return previous ? [...previous, value] : [value];
16512
+ },
16513
+ []
16514
+ ).action(async (entry, options) => {
16515
+ let app;
16516
+ if (!entry) {
16517
+ app = new Hono();
16518
+ } else {
16519
+ const appPath = resolve3(process.cwd(), entry);
16520
+ if (!existsSync3(appPath)) {
16503
16521
  app = new Hono();
16504
16522
  } else {
16505
- const appPath = resolve3(process.cwd(), entry);
16506
- if (!existsSync3(appPath)) {
16507
- app = new Hono();
16508
- } else {
16509
- const appFilePath = realpathSync3(appPath);
16510
- const buildIterator = buildAndImportApp(appFilePath, {
16511
- external: ["@hono/node-server"],
16512
- sourcemap: true
16513
- });
16514
- app = (await buildIterator.next()).value;
16515
- }
16523
+ const appFilePath = realpathSync3(appPath);
16524
+ const buildIterator = buildAndImportApp(appFilePath, {
16525
+ external: ["@hono/node-server", ...options.external || []],
16526
+ sourcemap: true
16527
+ });
16528
+ app = (await buildIterator.next()).value;
16516
16529
  }
16517
- const allFunctions = {};
16518
- const uniqueModules = [...new Set(Object.values(builtinMap))];
16519
- for (const modulePath of uniqueModules) {
16520
- try {
16521
- const module = await import(modulePath);
16522
- for (const [funcName, modulePathInMap] of Object.entries(builtinMap)) {
16523
- if (modulePathInMap === modulePath && module[funcName]) {
16524
- allFunctions[funcName] = module[funcName];
16525
- }
16530
+ }
16531
+ const allFunctions = {};
16532
+ const uniqueModules = [...new Set(Object.values(builtinMap))];
16533
+ for (const modulePath of uniqueModules) {
16534
+ try {
16535
+ const module = await import(modulePath);
16536
+ for (const [funcName, modulePathInMap] of Object.entries(builtinMap)) {
16537
+ if (modulePathInMap === modulePath && module[funcName]) {
16538
+ allFunctions[funcName] = module[funcName];
16526
16539
  }
16527
- } catch (error) {
16528
16540
  }
16541
+ } catch (error) {
16529
16542
  }
16530
- const baseApp = new Hono();
16531
- for (const use of options.use || []) {
16532
- const functionNames = Object.keys(allFunctions);
16533
- const functionValues = Object.values(allFunctions);
16534
- const func = new Function("c", "next", ...functionNames, `return (${use})`);
16535
- baseApp.use(async (c, next) => {
16536
- const middleware = func(c, next, ...functionValues);
16537
- return typeof middleware === "function" ? middleware(c, next) : middleware;
16538
- });
16539
- }
16540
- baseApp.route("/", app);
16541
- if (options.showRoutes) {
16542
- showRoutes(baseApp);
16543
- }
16544
- serve(
16545
- {
16546
- fetch: baseApp.fetch,
16547
- port: options.port ?? 7070
16548
- },
16549
- (info) => {
16550
- console.log(`Listening on http://localhost:${info.port}`);
16551
- }
16552
- );
16553
16543
  }
16554
- );
16544
+ const baseApp = new Hono();
16545
+ for (const use of options.use || []) {
16546
+ const functionNames = Object.keys(allFunctions);
16547
+ const functionValues = Object.values(allFunctions);
16548
+ const func = new Function("c", "next", ...functionNames, `return (${use})`);
16549
+ baseApp.use(async (c, next) => {
16550
+ const middleware = func(c, next, ...functionValues);
16551
+ return typeof middleware === "function" ? middleware(c, next) : middleware;
16552
+ });
16553
+ }
16554
+ baseApp.route("/", app);
16555
+ if (options.showRoutes) {
16556
+ showRoutes(baseApp);
16557
+ }
16558
+ serve(
16559
+ {
16560
+ fetch: baseApp.fetch,
16561
+ port: options.port ?? 7070
16562
+ },
16563
+ (info) => {
16564
+ console.log(`Listening on http://localhost:${info.port}`);
16565
+ }
16566
+ );
16567
+ });
16555
16568
  }
16556
16569
 
16557
16570
  // src/cli.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/cli",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "hono": "dist/cli.js"