layouts icon indicating copy to clipboard operation
layouts copied to clipboard

Loosen dependency on jstransformers

Open webketje opened this issue 2 years ago • 2 comments

Some of the JS transformers are severely outdated and due to the update mechanism (jstransformer-boilerplate -> test-jstransformer -> jstransformer-*) this is probably going to keep being an issue in the future.

For example:

  • jstransformer-marked uses [email protected] while the latest version is 4.0.7 (4 years ahead)
  • jstransformer-handlebars uses [email protected] while the latest version is 4.7.7 (6 years ahead)

Furthermore the renderAsync method used in layouts is not guaranteed to be present on all jstransformers.

There are a few options:

  1. Fork & republish a selection of the most commonly used jstransformers.
  2. Narrow the selection of supported templating languages (eg markdown, handlebars, nunjucks, twig) by bundling adapters in metalsmith-layouts, and specifying peerDependencies and peerDependenciesMeta: optional
  3. Keep using jstransformers, but provide an option transformers: ['path/to/transformer.js', 'path/to/other/transformer.js]` that will be added to the cache with the node_modules transformers, update the docs explaining how to create your own jstransformer.

In favor of option 3

webketje avatar Dec 11 '21 16:12 webketje

I've become member of the jstransformer's org and have updated the 2 jstransformers mentioned. I still think providing a transformers option has several advantages:

  1. It has to be explicitly passed with require('jstransformer-nunjucks') -> explicit is better than implicit
  2. It makes inputformat-to-jstransformer obsolete, which does a dictionary - key lookup of rendering engines matching an ext. 3. Instead, the transformer's inputFormat properties can be used, this allows custom matching & custom transformers
  3. No need for caching the rendering engine

Disadvantages:

  • Major semver breaking change
  • Might need to do changes to in-place too to keep it consistent, and sync release between both

webketje avatar May 02 '22 20:05 webketje

To be aligned with @metalsmith/in-place 5.x transform option

webketje avatar Feb 07 '24 21:02 webketje