@gnosticdev/hono-actions 2.0.8 → 2.0.10

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/actions.js CHANGED
@@ -2,7 +2,7 @@ import { zValidator } from '@hono/zod-validator';
2
2
  import { z } from 'astro/zod';
3
3
  import { Hono } from 'hono';
4
4
 
5
- // src/actions.ts
5
+ // src/define-action.ts
6
6
 
7
7
  // src/error.ts
8
8
  var HonoActionError = class extends Error {
@@ -20,7 +20,7 @@ var HonoActionError = class extends Error {
20
20
  }
21
21
  };
22
22
 
23
- // src/actions.ts
23
+ // src/define-action.ts
24
24
  function defineHonoAction({ schema, handler }) {
25
25
  const app = new Hono();
26
26
  const route = app.post(
package/dist/index.d.ts CHANGED
@@ -14,6 +14,9 @@ declare const optionsSchema: z.ZodOptional<z.ZodObject<{
14
14
  * - `src/hono/actions.ts`
15
15
  * - `src/hono/index.ts`
16
16
  * - `src/hono.ts`
17
+ * - `src/hono-actions.ts`
18
+ *
19
+ * **NOTE** `src/actions.ts` is reserved for Astro Actions and will be ignored.
17
20
  *
18
21
  * @default 'src/server/actions.ts'
19
22
  */
package/dist/index.js CHANGED
@@ -213,6 +213,9 @@ var optionsSchema = z.object({
213
213
  * - `src/hono/actions.ts`
214
214
  * - `src/hono/index.ts`
215
215
  * - `src/hono.ts`
216
+ * - `src/hono-actions.ts`
217
+ *
218
+ * **NOTE** `src/actions.ts` is reserved for Astro Actions and will be ignored.
216
219
  *
217
220
  * @default 'src/server/actions.ts'
218
221
  */
@@ -224,7 +227,8 @@ var ACTION_PATTERNS = [
224
227
  "src/server/actions.ts",
225
228
  "src/hono/actions.ts",
226
229
  "src/hono/index.ts",
227
- "src/hono.ts"
230
+ "src/hono.ts",
231
+ "src/hono-actions.ts"
228
232
  ];
229
233
  var integration_default = defineIntegration({
230
234
  name: "@gnosticdev/hono-actions",
@@ -236,36 +240,37 @@ var integration_default = defineIntegration({
236
240
  `Base path ${basePath} is reserved by Astro; pick another (e.g. /api2).`
237
241
  );
238
242
  }
239
- const baseResolver = createResolver(import.meta.url);
243
+ const { resolve } = createResolver(import.meta.url);
244
+ const IS_DEBUG = process.env.__DEBUG__ === "true";
240
245
  return {
241
246
  name,
242
247
  hooks: {
243
248
  "astro:config:setup": async (params) => {
244
249
  const { logger, injectRoute, createCodegenDir, config } = params;
245
250
  const root = config.root.pathname;
246
- const files = await glob(ACTION_PATTERNS, {
247
- cwd: root,
251
+ const absPatterns = ACTION_PATTERNS.map((p) => path.join(root, p));
252
+ const files = await glob(absPatterns, {
248
253
  expandDirectories: false,
249
254
  absolute: true
250
255
  });
256
+ if (IS_DEBUG) {
257
+ logger.info(`DEBUG: Found actions: ${files.join("\n")}`);
258
+ }
251
259
  const actionsPath = options.actionsPath ?? files[0];
252
- if (!actionsPath) {
260
+ if (!actionsPath || actionsPath.includes("node_modules")) {
253
261
  logger.warn(
254
262
  `No actions found. Create one of:
255
263
  ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
256
264
  );
257
265
  return;
258
266
  }
259
- const resolvedActionsPath = baseResolver.resolve(actionsPath);
267
+ const resolvedActionsPath = resolve(actionsPath);
260
268
  params.addWatchFile(resolvedActionsPath);
261
269
  logger.info(
262
270
  `Found actions: ${path.relative(root, resolvedActionsPath)}`
263
271
  );
264
272
  const codeGenDir = createCodegenDir();
265
- const routerPathAbs = path.join(
266
- codeGenDir.pathname,
267
- "router.ts"
268
- );
273
+ const routerPathAbs = path.join(codeGenDir.pathname, "router.ts");
269
274
  const relFromGenToActions = path.relative(codeGenDir.pathname, resolvedActionsPath).split(path.sep).join("/");
270
275
  const adapter = params.config.adapter?.name;
271
276
  if (!adapter) {
@@ -287,22 +292,14 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
287
292
  adapter
288
293
  });
289
294
  await fs.writeFile(routerPathAbs, routerContent, "utf-8");
290
- const astroHandlerPathAbs = path.join(
291
- codeGenDir.pathname,
292
- "api.ts"
293
- );
295
+ const astroHandlerPathAbs = path.join(codeGenDir.pathname, "api.ts");
294
296
  const astroHandlerContent = generateAstroHandler(adapter);
295
- await fs.writeFile(
296
- astroHandlerPathAbs,
297
- astroHandlerContent,
298
- "utf-8"
299
- );
300
- const clientPathAbs = path.join(
301
- codeGenDir.pathname,
302
- "client.ts"
303
- );
297
+ await fs.writeFile(astroHandlerPathAbs, astroHandlerContent, "utf-8");
298
+ const clientPathAbs = path.join(codeGenDir.pathname, "client.ts");
304
299
  if (!config.site) {
305
- logger.warn("No site url found in astro config, add one if you want to use the hono client with SSR");
300
+ logger.warn(
301
+ "No site url found in astro config, add one if you want to use the hono client with SSR"
302
+ );
306
303
  }
307
304
  const clientContent = generateHonoClient(config.server.port);
308
305
  await fs.writeFile(clientPathAbs, clientContent, "utf-8");
@@ -319,15 +316,9 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
319
316
  entrypoint: astroHandlerPathAbs,
320
317
  prerender: false
321
318
  });
322
- logger.info(
323
- `\u2705 Hono Actions route mounted at ${basePath}/[...slug]`
324
- );
319
+ logger.info(`\u2705 Hono Actions route mounted at ${basePath}/[...slug]`);
325
320
  },
326
- "astro:config:done": async ({
327
- injectTypes,
328
- config,
329
- logger
330
- }) => {
321
+ "astro:config:done": async ({ injectTypes, config, logger }) => {
331
322
  const adapter = config.adapter?.name;
332
323
  if (!adapter) {
333
324
  logger.warn("No adapter found...");
package/package.json CHANGED
@@ -61,5 +61,5 @@
61
61
  },
62
62
  "type": "module",
63
63
  "types": "./dist/index.d.ts",
64
- "version": "2.0.8"
64
+ "version": "2.0.10"
65
65
  }