Skip to content

[Plugins] PluginRoutes seem not to be registered correctly in fresh.gen.ts #1514

Description

@bjesuiter

I want to update my fresh_openprops integration to use a real Fresh Plugin for the integration:

https://github.com/codemonument/deno_fresh_openprops/blob/main/src/fresh_openprops_plugin.ts

It has a factory function, which returns the plugin object like so:

export async function FreshOpenProps(rawOptions?: PluginOptions) {
  // Throws when option parsing fails
  const { cssInputPath, postcssModuleDirs, isProd, doPrefillCssCache } =
    PluginOptions.parse(
      rawOptions,
    );

  // Should only happen once, since this plugin is only initialized once
  await initPostcssInstance(postcssModuleDirs);

  if (doPrefillCssCache) {
    await prefillCssCache({ cssInputPath });
  }

  const postcssRoute = {
    path: "postcss/[...path]",
    handler: async (
      req: Request,
      ctx: HandlerContext,
    ): Promise<Response> => {
       // The handler code 
    } 
  } satisfies PluginRoute; 
  
  return {
    name: "openprops",
    routes: [postcssRoute],
  } satisfies Plugin;

It integrates like this:

See my example in the repo for full code: https://github.com/codemonument/deno_fresh_openprops/blob/main/example/main.ts

// inside main.ts file 

const openpropsPlugin = await FreshOpenProps({
  isProd: false,
  doPrefillCssCache: true,
  cssInputPath: "example/css",
  postcssModuleDirs: ["example/css_deps"],
});

await start(manifest, {
  plugins: [
    openpropsPlugin,
  ],
});

First, I had the openpropsPlugin object inlined but extracted it afterwards bc. I suspected the await of the factory function to mess up the plugin initialization.

Error Observations

  • The route /postcss/global.css cannot be found (404)
  • After Inspection: The route from the plugin is not even registered in fresh.gen.ts
// Content of fresh.gen.ts
import * as $0 from "./routes/index.tsx";

const manifest = {
  routes: {
    "./routes/index.tsx": $0,
  },
  islands: {},
  baseUrl: import.meta.url,
};

export default manifest;

Source: https://github.com/codemonument/deno_fresh_openprops/blob/main/example/fresh.gen.ts

What may be wrong here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions