Munter/fusile

Rewrite file extensions to target file extension?

Munter opened this issue · 4 comments

Just compiling the contents of a file without changing anything else usually works perfectly fine in a web browser context. But other systems tend to make assumptions about file extensions. For example the CommonJS require function.

Case in point: Trying to find a bug in accord and having the .coffee files be compiled using fusile makes node throw errors because the files don't exist with a .js extension.

Should the file extensions be rewritten to the target extension?

Pro:

  • Making CommonJS work

Contra:

  • Losing the direct link to a traceable file on disk with the same file name. (might be mitigated by source maps)

Pinging some possible interested parties on this: @papandreou @gustavnikolaj @Jenius @mafintosh

The module module can relatively easily be extended to load files with whatever file extensions. But it introduces a dependency in your code, so that should be a last resort.

Livestyle and Fusile are taking two wildly different approaches to solving the same problem. Livestyle is trying to move the build step of different compiled languages into a proxy, where Fusile is more of a traditional compiler (or transpiler). So you cannot apply the same ideas and semantics to both cases without trouble.

Fusile is not in the same way as Livestyle able to abstract away the build step to the user - not without introducing something proxy-like at least, be it a module-monkey-patch or an express proxy to rewrite content-types on certain files.

There is no downsides to rewriting file extensions with fusile, that is not already something that people using transpiled languages is used to.

I hope that you can use these thoughts for something. I haven't looked a lot at your code, but only heard you explain the idea a few times... So take my input with a big grain of salt, as I might have missed something... :-)

Hey there,

Sorry I don't exactly know what this library is or how it works, I'll look into it a bit more when I have a few minutes later. But at least for accord, it does not force the usage of any file extensions, each adapter simply comes with a list of commonly used extensions which you can use as you please wherever accord is implemented, as well as the intended output extension.

In roots, which implements accord, in order to use a compiled language, you need to install the language's node module then use any of its supported extensions, and it will compile and output the file with the "output extension", for example .coffee files will compile to .js files. This has worked reasonably well for roots users. Not sure if this is totally off-base, let me know if there's something more specific that I could pitch in on!

It probably makes most sense to replace the file extension to match the output format. That should make things compatible to cover most use cases