less / less.js

Less. The dynamic stylesheet language.
http://lesscss.org
Apache License 2.0
17.01k stars 3.41k forks source link

Handle the lack of the optional dependencies #3791

Open mems opened 1 year ago

mems commented 1 year ago

What:

When optional dependencies are not installed or missing (ex: npm ci --omit=optional) less.js throw errors for features that use that dependencies.

This is in contradiction with the purpose of optionaldependencies:

It is still your program's responsibility to handle the lack of the dependency.

Why:

This is a graceful degradation when optional dependencies are not installed or missing. Less.js will still generate CSS but with a less optimal result. (ex: data-uri() always generate application/octet-stream base64 URIs, image-size() resolve to 0px 0px)

How:

Checklist:

matthew-dean commented 1 year ago

EDIT: 🤔 Okay I thought about this for another bit. If someone is explicitly using image-size, and whatever optional dependency is not installed, then Less definitely should throw an error, although the error should be explicit about what they need to do (e.g. install the dependency). Outputting no error or warning is IMO worse DX.

In this case, I would take "It is still your program's responsibility to handle the lack of the dependency" as it is the responsibility of Less to throw an error that is instructive, for each of these errors. It should not silently insert values that are other than the stylesheet author's intent. That is, when they use image-size(), they expect to get the size of the image as an output. A zero-dimension result is not the size of the image.