Closed edemaine closed 2 years ago
Array maybe means to run the rules in sequence (or in parallel?)
Potentially we could allow arrays of functions in the above exports to make it easy to combine multiple steps.
We already have an easy way of calling functions in sequence :stuck_out_tongue_closed_eyes:. You can always add that shorthand later if there's demand for it, but you can never remove it because of backwards compatibility.
Other than your insistence on always having more than one obvious way to do everything, the proposal looks great! :tada:
Currently
export
s are used in two ways:export default
is how mappings get exported (sometimes implicitly). This is OK but is ambiguous with Maketiles which feels a little ugly.export rule
is how Maketiles export rules, with the default rule viaexport default
(which is ambiguous with mappings). A bigger uglyness is when we want to rules to be computed names, as ESMexport
doesn't support exporting computed names. Current workaround is to use CommonJSexports[name] = ...
but this means we could never go to true ESM which seems like a bad design decision.I'd like to propose instead that
export
has a finite set of intended names.export default
will remain ambiguous between Maketiles and mappings, for convenience, but you can choose to be unambiguous viaexport map
orexport make
.Maketiles (Maketile.{js,coffee})
export make
orexport default
can be specified recursively, similar to maps:Map
) mapping rule names to rules. Should default rule name be''
or'default'
orundefined
ornull
? I think''
probably makes the most sense.export make
is present,export default
is ignored (in case used as mapping file)The result is that a
Maketile.coffee
could be written much closer to an actual Makefile, via implicitexport default
:And programmatically generated rules could be written reasonably nicely and in ESM:
Or totally generic rule names, something we couldn't do at all with the
export
approach:One limitation here is there's no way to tell, given an argument, whether it's a Maketile rule or a filename. That's fine with the current design: currently, filenames take priority over Maketile rules, so if you do
svgtiler foo
andfoo
is a filename, then it gets treated as a filename; indeed, the Maketile only gets loaded if the argument doesn't match as a filename. I think this is fine, as filenames should have.
s in them, while rules should not, so there's no real conflict..
,*
,?
in rule names, to avoid conflicts with filenames/globs.foo
as a filename if it doesn't have a.
in it, or any glob operators, as it can't possibly be treated as an input; instead directly try to apply as a rule.*foo
gets treated as a rule if there aren't any files ending infoo
.Mappings
This is the second half of #95. In the end, I think the
svgtiler.{onInit,preprocess,postprocess}
side effects are dangerous and hard to use:require('mapping.js')
breaks later use assvgtiler.require('mapping.js')
orsvgtiler('mapping.js')
; the side effects are lost forever.InlineMapping
class that simulates the behavior, but{init, preprocess, postprocess, map}
(passed intonew Mapping
probably) is simpler.So instead the proposal is:
export init = -> ...
replacessvgtiler.init -> ...
export preprocess = (render) -> ...
replacessvgtiler.preprocess (render) -> ...
export postprocess = (render) -> ...
replacessvgtiler.postprocess (render) -> ...
export map
orexport default
specifies a mapping as we currently do.export map
is present,export default
is ignored.Cool features of this approach:
svgtiler.require('map.js')
andrequire('map.js')
are equivalent; there's no special processing for JS/CS mapping files.svgtiler('map.js')
is equivalent tosvgtiler(require('./map.js'))
.export {preprocess, postprocess} from '...js'
postprocess
is called in mapping file order, but perhaps it should be in reverse order.{init, preprocess, postprocess, map}
mapping object can be created viaimport * as mapping from './mapping.js'
We will have to change the situations in which
svgtiler.background
is allowed; it can no longer be at the top level of a mapping file.svgtiler.background
to only be callable withinpostprocess
callbacks, with the meaning "add background rect now"; orpreprocess
orpostprocess
).