Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define a JS format for Sass plugins #2511

Open
nex3 opened this issue Apr 27, 2018 · 10 comments
Open

Define a JS format for Sass plugins #2511

nex3 opened this issue Apr 27, 2018 · 10 comments
Labels
enhancement New feature or request JS API About the shared JS API

Comments

@nex3
Copy link
Contributor

nex3 commented Apr 27, 2018

Users want to load plugins when using Dart Sass and Node Sass via the command line (see sass/dart-sass#264). This means we need a way for such plugins to be defined in a way that makes sense for both Dart Sass and Node Sass. Plugins may include Sass stylesheets as well as functions or importers defined in JS.

Note that Eyeglass has a format that works here, so it may make sense to integrate with that somehow. However, this would mean that some aspects of the raw executables would only work in an Eyeglass context, which might be a problem.

@nex3 nex3 added the JS API About the shared JS API label Apr 27, 2018
@nex3 nex3 added this to To do in JS API Overhaul via automation Apr 27, 2018
@chriseppstein
Copy link

chriseppstein commented Apr 27, 2018

Eyeglass has a very simple integration point that I think can be a general contract for any such plugin system.

Given an single option -r PLUGIN to any js-capable executable.

The executable can integrate to any generic plugin, or plugin system like so:

// pseudo code inside the sass implementation
const parseOptions = require("someOptionParser");
let execOptions = parseOptions();
const plugin = execOptions['-r'] ? require(execOptions['-r']) : ((opts) => opts);
let sassOptions = {}; // calculates options from other arguments to executable
sassOptions = plugin(sassOptions);
// goes on to render the file(s) with these options.
// npm module: PLUGIN/index.js
module.exports = function(options) {
  // calculate new options or changes to them.
  return options;
}

If desired, this contract can be extended to support multiple invocations of the -r option where options are chained in order to them.

Eyeglass would trivially integrate with this system, and it would allow for other such frameworks.

@xzyfer
Copy link

xzyfer commented Apr 27, 2018 via email

@nex3
Copy link
Contributor Author

nex3 commented Apr 27, 2018

@xzyfer Can you do a survey of what those libraries do?

@ArmorDarks
Copy link

Worth to mention JSPM and SystemJS (that's what JSPM uses under the hood) to the list.

SystemJS implements ES module specs — what some modern browsers already supporting — so it should be regarded as a more accurete source of truth.

@chriseppstein
Copy link

There are a couple of config loader systems that are used in the js world to read from standard location(s):

I'm sure there are others. This is more for app's than plugins. I would expect the config to be able to specify plugins that would then receive the resolved configuration from all possible sources (including the CLI options, if any)

@xzyfer
Copy link

xzyfer commented May 22, 2018 via email

@ArmorDarks
Copy link

Also worth to check how it's done in Babel, ESLint, Stylelint and Jest

@nex3
Copy link
Contributor Author

nex3 commented May 22, 2018

I'm less interested here in how we define what code will be loaded, whether that's through a configuration file or command-line options or whatever, than I am in what that code will look like.

The Eyeglass method for defining plugins is to take some sort of configuration object as a parameter and return it modified however. This is a possibility, but I'm not sure there's a clear use-case for plugins manipulating configuration other than by defining functions and importers, and as a matter of policy I'd like to keep the surface area as small as possible to give us more flexibility both for future changes and in how individual implementations represent their configuration.

@chriseppstein
Copy link

Most of these examples have a way of extending a configuration from a known location. I’ve not seen one that has a notion of composing configuration from several locations that are independent of the others.

@lunelson
Copy link

This discussion has probably moved on already; but FWIW I would suggest that plugins may want to receive the sass instance (whether it be node-sass or dartsass) as well as a config object, I've found this to be helpful 🤷‍♂

@nex3 nex3 moved this from To do to In design in JS API Overhaul Aug 6, 2021
@nex3 nex3 moved this from In design to To do in JS API Overhaul Aug 6, 2021
@nex3 nex3 removed this from To do in JS API Overhaul Aug 6, 2021
@nex3 nex3 added the enhancement New feature or request label Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request JS API About the shared JS API
5 participants