marksmccann / node-sass-extra

A drop-in replacement for node-sass' Node API that adds support for globs, promises and more.
MIT License
2 stars 1 forks source link

Drop-in replacement for async render #35

Closed marksmccann closed 5 years ago

marksmccann commented 5 years ago

Our async render is not truly a drop-in replacement because the syntax is different; we are returning a promise instead of using a callback. can we support both so that it truly is a drop-in replacement?

render({...}, function(err, result) {});
-- or --
render({...}).then(function(result){}).catch(function(err){});
marksmccann commented 5 years ago

Would something like this work?

async function render(options, callback) {
    try {
        ...
        const results = marshalArray(compiled);
        if (callback) {
            callback(null, results);
        }
        return results;
    } catch(err) {
        if (callback) {
            callback(err);
        }
    }
}
phillipluther commented 5 years ago

That's a great point. So if your setup looks like -

import sass from 'node-sass';
...
sass.render('path/to/file.scss', someCallback);

... and you swap out node-sass-extra for node-sass, your callback will never get invoked.

I think your proposal above is solid. It won't break anything if you do nothing but swap the module, but also opens up syntax for async/await or the Promise API.