#New filetype Astro Integration return value

2 messages · Page 1 of 1 (latest)

toxic glacier
#

I'm basing my new filetype plugin/integration off of the vite-plugin-markdown and the mdx integrations in the Astro src repo. The MDX seems to be returning a string of either raw JS or of hscript and the markdown plugin I think is returning a string of hscript as well. I've tried returning a few different things from the plugin and am given various errors based on what is returned. I'm assuming it wants the hAST in some form or another, or maybe the esAST, but I've seen examples of both (I think) being returned and since this is a Vite plugin, which is a rollup plugin, there seems to be just a lot of differing examples and I'm unsure what is needed.

Here is the repo/index.ts for the plugin I'm working on (it's currently a local plugin since that's a whole lot easier to work with for this initial development effort) https://github.com/pard68/astro-blog/blob/master/src/lib/vite-plugin-orgmode/index.ts

The error I am currently getting, when trying to return the hAST as a string is:

 error   Parse failure: Unexpected token (1:8)
  Contents of line 1: [object Object]
Error: Parse failure: Unexpected token (1:8)
Contents of line 1: [object Object]
    at ssrTransformScript (file:///Users/ian/git/hub/pard68/astro-blog/node_modules/vite/dist/node/chunks/dep-6b3a5aff.js:52864:15)
    at ssrTransform (file:///Users/ian/git/hub/pard68/astro-blog/node_modules/vite/dist/node/chunks/dep-6b3a5aff.js:52839:12)
    at Object.ssrTransform (file:///Users/ian/git/hub/pard68/astro-blog/node_modules/vite/dist/node/chunks/dep-6b3a5aff.js:62095:20)
    at loadAndTransform (file:///Users/ian/git/hub/pard68/astro-blog/node_modules/vite/dist/node/chunks/dep-6b3a5aff.js:37388:24)

Any idea what I ought to be doing? This currently is generating a proper hAST of the input Org file, it's not the best or most ideal setup right now, this is verbatim ripped out of my NextJS plugin to do the same thing.

GitHub

Sandbox for testing out Astrojs for use as a replacement framework for Sylvan - astro-blog/index.ts at master · pard68/astro-blog

toxic glacier
#

Got time to poke at the internals and it should be a string. It definitely needs to be a string, not using a string returns a number of issues because the Vite and Astro cores operate on code with string methods. I'm not sure what sort of string though. The parser/thing is currently telling me the string is not valid JS. So I'm wondering if I need to convert from rehype to the ESast, but that doesn't make sense to me since neither markdown or mdx integrations are doing that, though they do have some intermediary jsx transformer that seems to be sitting in the pipeline somehow.