danez/pirates

Async compilation

GianlucaGuarini opened this issue · 4 comments

Hi thanks for this great script, I am using it for the new riotjs ssr module. I have a question: is it possible to compile the required files asynchronously?

import {addHook} from 'pirates'

addHook(
  async function(source, filename) {
     return await compile(source)
  },
  { exts: ['.riot'] }
)

I would be very interested in this as well. I'd like to use this to build tooling for Svelte, which has an asynchronous preprocessing method.

The new riot compiler was enough flexible to handle also the sync compilation. I guess async compilation is not a good idea anyways.

The actual compilation in Svelte is also synchronous. What's async is the preprocessing part, where you can hook preprocessors in, such as LESS, SASS, etc. – which may in turn rely on async compilation. In order to generically handle compilation and preprocessing in a hook, you'd need some way to do it async.

I am closing this issue since the node commonjs API is completely synchronous. There is no simple solution to hook async loading without blocking the node process main thread. Many thanks for this great script!