-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Promise support #1066
Comments
Custom importers and functions are still pretty experimental feature. Most importantly they are pretty tightly bound with our C++ implementation. I wonder if this will work at all. Can you sketch a minimal, pure-JS example to test? |
I'm only mentioning Basically index.js L322-L324 (and the same some lines above for arrays) need to be modified for this: if (result) {
if (result.then) { // New
result.then(function(r) { done(null, r) }, function(e) { done(e) });
} else { // Current
done(result === module.exports.NULL ? null : result);
}
} It's a tiny modification: Detects the promise and calls |
Are you OK with this change? I will create the PR with code changes and updates to the |
I'm curious to see what am implementation of this would look like. However I'm against only doing this for importers. If we were to support promised we'd have to support custom importers, custom functions, and async render. |
@xzyfer I agree that it makes most sense to augment all mechanisms that use callbacks in one go. |
There are no plans to do this in the near future. Callbacks can be promisifed in user land easily enough. |
Can this be reopened, even if it's not going to be fixed immediately? @MajorBreakfast's original example is really nice: let { css, map } = await sass.render({
async importer(url, prev) { ... }
})
It's true that you can do |
@callumlocke we're open to pull requests with test coverage that also maintain the existing callback API. However the core team has no plans to progress this feature in the foreseeable future. |
@xzyfer Are you sure you want to retain the old API alongside a new promise-based API? Why not do a major version bump, embrace promises, and simplify the codebase? The existing callback API is outdated and confusing. The fact you can call |
No, but I am sure I do not wish to stop supporting the callback API. The callback is universally supported. A significant number of node-sass users are still using node 0.10 and 0.12. This is true for the node ecosystem as a whole. Forcing those users to require a polyfill or
True, this unfortunately and predates my involvement with the project. This is some thing we will likely fix in the future however the
True which is why this was originally closed. |
There would be no need for polyfills or flags. I think you might be confusing the ES6 Anyone who wants to use this new API would just have to change
What in the ecosystem would break? Wouldn't a semver major version bump solve this? |
Nice that this as come up again. I think it'd be very simple to have both APIs living side-by-side:
Both things can be added via an |
I understand the appeal of promises, but please understand they are a barrier to entry to a lot of new developers. We see promises as an enhancement, not a requirement. We'll happily consider a promise API as long as
|
polygoat looks like it could be a promising solution. |
any update on this? |
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Fix backslash multiline string with win linefeed
Is there any interest in supporting promises? I'll provide a PR if you're interested. This can be added without introducing an npm dependency by detecting the Promise global via
typeof Promise !== 'undefined'
and enabling the behavior only if promises are available.sass.render()
if no callback is providedoptions.importer()
The text was updated successfully, but these errors were encountered: