Or, instead of having a "compiled resource", a resource can have
multiple "representations", each with a specified MIME type. Then
things could work approximately like this:
1) When the .coffee file is read from disk, the resource is created
with the .coffee path and the CoffeeScript content with a CoffeeScript
MIME type (text/x-coffeescript, or text/coffeescript if one ignores
that that MIME type isn't registed with IANA).
2) When buster-coffee (or the future buster-resource-compiler) is run,
it loops over all the resources, and for each resource with a
CoffeeScript MIME type, adds a new representation with a JavaScript
MIME type and a content function that will compile the CoffeeScript
content.
3) When e.g. buster-html-docs is run, it loops over all resources, and
extracts docs for each resource with JavaScript contents available,
which includes the .coffee resources, which have been previously
"enriched" with a JavaScript version by buster-coffee.
At the moment I can't come up with an example where more than two
representations will be needed, but if we allow multiple MIME type
identified representations, we have a bit more flexibility. Who knows
what representations future extensions will find useful to piggy-back
on resources.
I can't think of any reason for why you would want to have more than two "content types" for each resource. For now, the only use case is to store "something" that isn't JS, a source map, and the resulting JS from compiling the "something".
Perhaps we should just explicitly support this, instead of having a generic content type system?
Specific support for non-JS + source map + JS (alternatively, only JS) would probably make it easier to serve the JS with X-Sourcemap, etc.
I'm hard-pressed to come up with examples of more than two MIME
types that are not input/output/sourcemap, but I don't see what
we gain from making this restriction (it's likely to make the
implementation more specific/complicated), while the "n MIME
types" approach solves all the problems we've identified so far.
Please correct me if I'm mistaken.
Christian
I've not read the entire sourcemap specification, but as far as I gather at this point we don't need to do anything special with them.
We need to set X-Sourcemap on the .js files if their source is compiled code, i.e. they have a source map. Setting this header causes the browsers to automatically fetch the source map etc.I've not read the entire sourcemap specification, but as far as I gather at this point we don't need to do anything special with them.
I'm not sure I understand your critisism, perhaps you misunderstood me. In essence, what I'm saying is that since we today support different types of resources - proxies and raw content - it makes sense to add support for a 3rd type of resource - a compiled script that has a source map. I don't see how we can add support for source maps with a generic content-type based setup alone.
The path in X-Sourcemap is a bitch.. Perhaps we should have a special "path" type:
{headers: {"X-Sourcemap": new ramp.resources.Path(sourcemapPath)}}
Compilation and source map generation is generally the same process so it would be nice if the two could somehow go together. With two separate callbacks you would essentially need to compile twice.