@hono/cli 0.1.7 → 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 +70 -55
  3. package/package.json +3 -2
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
@@ -15865,11 +15865,12 @@ async function* buildAndImportApp(filePath, options = {}) {
15865
15865
  ]
15866
15866
  });
15867
15867
  await context2.watch();
15868
- if (!options.watch) {
15869
- await context2.dispose();
15870
- }
15871
15868
  do {
15872
- yield await appPromise;
15869
+ const app = await appPromise;
15870
+ if (!options.watch) {
15871
+ await context2.dispose();
15872
+ }
15873
+ yield app;
15873
15874
  preparePromise();
15874
15875
  } while (options.watch);
15875
15876
  }
@@ -16216,17 +16217,25 @@ function requestCommand(program2) {
16216
16217
  return previous ? [...previous, value] : [value];
16217
16218
  },
16218
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
+ []
16219
16227
  ).action(async (file, options) => {
16220
16228
  const path = options.path || "/";
16221
16229
  const watch = options.watch;
16222
- const buildIterator = getBuildIterator(file, watch);
16230
+ const external = options.external || [];
16231
+ const buildIterator = getBuildIterator(file, watch, external);
16223
16232
  for await (const app of buildIterator) {
16224
16233
  const result = await executeRequest(app, path, options);
16225
16234
  console.log(JSON.stringify(result, null, 2));
16226
16235
  }
16227
16236
  });
16228
16237
  }
16229
- function getBuildIterator(appPath, watch) {
16238
+ function getBuildIterator(appPath, watch, external = []) {
16230
16239
  let entry;
16231
16240
  let resolvedAppPath;
16232
16241
  if (appPath) {
@@ -16241,7 +16250,7 @@ function getBuildIterator(appPath, watch) {
16241
16250
  }
16242
16251
  const appFilePath = realpathSync2(resolvedAppPath);
16243
16252
  return buildAndImportApp(appFilePath, {
16244
- external: ["@hono/node-server"],
16253
+ external: ["@hono/node-server", ...external],
16245
16254
  watch,
16246
16255
  sourcemap: true
16247
16256
  });
@@ -16495,61 +16504,67 @@ function serveCommand(program2) {
16495
16504
  return previous ? [...previous, value] : [value];
16496
16505
  },
16497
16506
  []
16498
- ).action(
16499
- async (entry, options) => {
16500
- let app;
16501
- 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)) {
16502
16521
  app = new Hono();
16503
16522
  } else {
16504
- const appPath = resolve3(process.cwd(), entry);
16505
- if (!existsSync3(appPath)) {
16506
- app = new Hono();
16507
- } else {
16508
- const appFilePath = realpathSync3(appPath);
16509
- const buildIterator = buildAndImportApp(appFilePath, {
16510
- external: ["@hono/node-server"]
16511
- });
16512
- app = (await buildIterator.next()).value;
16513
- }
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;
16514
16529
  }
16515
- const allFunctions = {};
16516
- const uniqueModules = [...new Set(Object.values(builtinMap))];
16517
- for (const modulePath of uniqueModules) {
16518
- try {
16519
- const module = await import(modulePath);
16520
- for (const [funcName, modulePathInMap] of Object.entries(builtinMap)) {
16521
- if (modulePathInMap === modulePath && module[funcName]) {
16522
- allFunctions[funcName] = module[funcName];
16523
- }
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];
16524
16539
  }
16525
- } catch (error) {
16526
16540
  }
16541
+ } catch (error) {
16527
16542
  }
16528
- const baseApp = new Hono();
16529
- for (const use of options.use || []) {
16530
- const functionNames = Object.keys(allFunctions);
16531
- const functionValues = Object.values(allFunctions);
16532
- const func = new Function("c", "next", ...functionNames, `return (${use})`);
16533
- baseApp.use(async (c, next) => {
16534
- const middleware = func(c, next, ...functionValues);
16535
- return typeof middleware === "function" ? middleware(c, next) : middleware;
16536
- });
16537
- }
16538
- baseApp.route("/", app);
16539
- if (options.showRoutes) {
16540
- showRoutes(baseApp);
16541
- }
16542
- serve(
16543
- {
16544
- fetch: baseApp.fetch,
16545
- port: options.port ?? 7070
16546
- },
16547
- (info) => {
16548
- console.log(`Listening on http://localhost:${info.port}`);
16549
- }
16550
- );
16551
16543
  }
16552
- );
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
+ });
16553
16568
  }
16554
16569
 
16555
16570
  // src/cli.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/cli",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "hono": "dist/cli.js"
@@ -9,13 +9,14 @@
9
9
  "build": "tsup",
10
10
  "watch": "tsup --watch",
11
11
  "test": "vitest",
12
- "test:run": "vitest run",
12
+ "test:run": "vitest --run",
13
13
  "test:watch": "vitest watch",
14
14
  "lint": "eslint --ext js,ts src",
15
15
  "lint:fix": "eslint --ext js,ts src --fix",
16
16
  "format": "prettier src --check",
17
17
  "format:fix": "prettier src --write",
18
18
  "postbuild": "publint",
19
+ "prerelease": "bun run build",
19
20
  "release": "np"
20
21
  },
21
22
  "files": [