-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Accessing @debug and @warn output #646
Comments
Nice idea. 👍 I think you would have to open this with libsass issue tracker. LibSass should not pipe those directly to the stdout or stderr, but provide them as output via (for instance) |
You could add custom functions to handle them yourself! |
@mgreter, this is super fantastic! I missed that part. |
Just checking in to see if there's been any movement on this. Having access to these would allow me to do some cool stuff on SassMeister.com. |
@jedfoster, it is on our TODO list. The show-stopper atm is #644. |
@jedfoster, FYI, 3.0.0-beta is released with Custom Functions support. We can now use: require('node-sass').render({
data: 'b {l: ah}; @warn "foo";',
functions: {
'@warn': function(warning) {
console.log(warning.getValue());
}
}
}, function(err, result) {
if(err) {
console.log(err); throw err;
}
console.log(result, result.css.toString());
}) As far as I have understood from the implementation, these four signature do not return anything (if you return, it would have no effect in the callback's result). |
@am11 I'm trying your example and I get the warning value from the I pasted your example into a new file in my project and ran it:
I still need the |
You are right. I am also new to this. (= var sass = require('node-sass');
sass.render({
data: 'b {l: ah}; @warn "foo";',
functions: {
'@warn': function(warning) {
console.log(warning.getValue());
return sass.NULL; // or sass.types.NULL, both work
// or you can return a regular JS string,
// or a sass string: return new sass.types.String('squiggly');
// or elaborated syntax:
// var str = new sass.types.String;
// str.setValue('meh');
//
// nit: returning an empty JS string "", undefined or null wouldn't work either
}
}
}, function(err, result) {
if(err) {
console.log(err); throw err;
}
console.log(result, result.css.toString());
}) We will polish these behaviours overtime. Since this is kind of meta programming with interop types, there is a learning curve and the ReadMe is quite helpful: https://github.com/sass/node-sass#functions--v300. |
Should we consider it fixed/addressed by #644? |
Is there any way to access the line number? For me, that's the last missing piece. |
I don't think libsass emits that kind of contextual information in functions (yet?). |
We don't yet expose the parser state to C code! But since we now pass |
Thank you @mgreter @jedfoster, IMO, we should close this issue as fixed. Once LibSass provide the contextual information, we will bubble it to the JS method in subsequent release. At least. the 'basic' functionality has been implemented. |
@jedfoster, sass/libsass#1037. We will need to wait for LibSass to expose that information first. |
@mgreter I see that you closed sass/libsass#1037. I'm not sure if that's been rolled into the latest version of node-sass? When that change does propagate to node-sass, how would I use it to achieve the end result I outlined above? I've had partial success with the code below, but the final piece is the line number of nodeSass.render({
data: sass + ' ',
outputStyle: outputStyle,
includePaths: includePaths,
functions: {
'@warn': function(msg) {
warn.push(msg.getValue());
return nodeSass.NULL;
},
'@debug': function(msg) {
debuggers.push(msg.getValue());
return nodeSass.NULL;
},
'@error': function(msg) {
errors.push(msg.getValue());
console.log(msg);
return nodeSass.NULL;
}
}
}, function(error, result) {
if (error) {
return res.status(500).json({
css: error.message + ' on line ' + error.line + ' at column ' + error.column,
error: error
});
}
else {
return res.json({
css: result.css.toString(),
dependencies: { 'libsass': LIBSASS_VERSION },
stats: result.stats.duration / 1000,
time: result.stats.duration / 1000,
warn: warn,
errors: errors,
debuggers: debuggers
});
}
}); Background on this request: I want to display debug/error/warn info on http://sassmeister.com, as described in jedfoster/SassMeister#123. Need line numbers for that to work. |
This might take a while. Node-sass hasn't recently implemented libsass experimental features very quickly (some are still missing since a few years). So i cant make a prediction, beside that all features are available in the perl implementation. |
Any progress on this?! |
Is there any way to access output from
@debug
and@warn
other than looking at the console? Ideally as part of theresult
object passed to thesuccess
anderror
callbacks.Given this Sass input:
I get this output in my console:
I've tried a number of things to capture
stdin
(andstdout
) and just can't seem to get figure it out. It would awesome if theresult
object contained something like:The text was updated successfully, but these errors were encountered: