@gnosticdev/hono-actions 2.0.9 → 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/index.js +13 -28
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -241,19 +241,23 @@ var integration_default = defineIntegration({
|
|
|
241
241
|
);
|
|
242
242
|
}
|
|
243
243
|
const { resolve } = createResolver(import.meta.url);
|
|
244
|
+
const IS_DEBUG = process.env.__DEBUG__ === "true";
|
|
244
245
|
return {
|
|
245
246
|
name,
|
|
246
247
|
hooks: {
|
|
247
248
|
"astro:config:setup": async (params) => {
|
|
248
249
|
const { logger, injectRoute, createCodegenDir, config } = params;
|
|
249
250
|
const root = config.root.pathname;
|
|
250
|
-
const
|
|
251
|
-
|
|
251
|
+
const absPatterns = ACTION_PATTERNS.map((p) => path.join(root, p));
|
|
252
|
+
const files = await glob(absPatterns, {
|
|
252
253
|
expandDirectories: false,
|
|
253
254
|
absolute: true
|
|
254
255
|
});
|
|
256
|
+
if (IS_DEBUG) {
|
|
257
|
+
logger.info(`DEBUG: Found actions: ${files.join("\n")}`);
|
|
258
|
+
}
|
|
255
259
|
const actionsPath = options.actionsPath ?? files[0];
|
|
256
|
-
if (!actionsPath) {
|
|
260
|
+
if (!actionsPath || actionsPath.includes("node_modules")) {
|
|
257
261
|
logger.warn(
|
|
258
262
|
`No actions found. Create one of:
|
|
259
263
|
${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
|
|
@@ -266,10 +270,7 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
|
|
|
266
270
|
`Found actions: ${path.relative(root, resolvedActionsPath)}`
|
|
267
271
|
);
|
|
268
272
|
const codeGenDir = createCodegenDir();
|
|
269
|
-
const routerPathAbs = path.join(
|
|
270
|
-
codeGenDir.pathname,
|
|
271
|
-
"router.ts"
|
|
272
|
-
);
|
|
273
|
+
const routerPathAbs = path.join(codeGenDir.pathname, "router.ts");
|
|
273
274
|
const relFromGenToActions = path.relative(codeGenDir.pathname, resolvedActionsPath).split(path.sep).join("/");
|
|
274
275
|
const adapter = params.config.adapter?.name;
|
|
275
276
|
if (!adapter) {
|
|
@@ -291,20 +292,10 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
|
|
|
291
292
|
adapter
|
|
292
293
|
});
|
|
293
294
|
await fs.writeFile(routerPathAbs, routerContent, "utf-8");
|
|
294
|
-
const astroHandlerPathAbs = path.join(
|
|
295
|
-
codeGenDir.pathname,
|
|
296
|
-
"api.ts"
|
|
297
|
-
);
|
|
295
|
+
const astroHandlerPathAbs = path.join(codeGenDir.pathname, "api.ts");
|
|
298
296
|
const astroHandlerContent = generateAstroHandler(adapter);
|
|
299
|
-
await fs.writeFile(
|
|
300
|
-
|
|
301
|
-
astroHandlerContent,
|
|
302
|
-
"utf-8"
|
|
303
|
-
);
|
|
304
|
-
const clientPathAbs = path.join(
|
|
305
|
-
codeGenDir.pathname,
|
|
306
|
-
"client.ts"
|
|
307
|
-
);
|
|
297
|
+
await fs.writeFile(astroHandlerPathAbs, astroHandlerContent, "utf-8");
|
|
298
|
+
const clientPathAbs = path.join(codeGenDir.pathname, "client.ts");
|
|
308
299
|
if (!config.site) {
|
|
309
300
|
logger.warn(
|
|
310
301
|
"No site url found in astro config, add one if you want to use the hono client with SSR"
|
|
@@ -325,15 +316,9 @@ ${ACTION_PATTERNS.map((p) => ` - ${p}`).join("\n")}`
|
|
|
325
316
|
entrypoint: astroHandlerPathAbs,
|
|
326
317
|
prerender: false
|
|
327
318
|
});
|
|
328
|
-
logger.info(
|
|
329
|
-
`\u2705 Hono Actions route mounted at ${basePath}/[...slug]`
|
|
330
|
-
);
|
|
319
|
+
logger.info(`\u2705 Hono Actions route mounted at ${basePath}/[...slug]`);
|
|
331
320
|
},
|
|
332
|
-
"astro:config:done": async ({
|
|
333
|
-
injectTypes,
|
|
334
|
-
config,
|
|
335
|
-
logger
|
|
336
|
-
}) => {
|
|
321
|
+
"astro:config:done": async ({ injectTypes, config, logger }) => {
|
|
337
322
|
const adapter = config.adapter?.name;
|
|
338
323
|
if (!adapter) {
|
|
339
324
|
logger.warn("No adapter found...");
|
package/package.json
CHANGED