-
Notifications
You must be signed in to change notification settings - Fork 1.3k
v2 proposal: Restructure index.js and remove deprecated code #547
Comments
* Removes deprecated functions. * Introduces breaking change. * Reponds to sass#547.
I have made the breaking changes in
Please let me know if you guys think this approach is flawed. Next, I think we need to make custom importers (and custom functions in future) work with sync function as well. The problem is that, currently in our binding code we are not instantiating |
Sounds good 👍 Concerning my suggestion on moving the stats-object into the result-object (and your comment): Imho it feels kind of hacky to pass in a stats-object to the options that will be filled by node-sass. It was just a workaround because node-sass did return a string back then. It's probably a C-like approach (the object is like a |
This makes sense. At this point its bit tricky to manage it while complying with DRY. So here is what one way to deal with it: sass.render({
..
success: function(css, map, stats) {
// map and stats both would carry source-maps.
// since the source-map's mappings size is directly proportional to that of input,
// its anti-productive to have it twice.
},
error: function(error, status) {
// error is the object literal (parsed JSON)
// status is integer
},
..
}) Therefore, it will probably be a good idea to strip source-maps off of Then the matching sync variant would be: var result = sass.renderSync({ ... });
// result.css returns css as string
// result.map returns map as string
// result.stats is an object literal without map (just meta info: how compilation transpired)
// if error, it prints out to stdOut as JSON without sparing any object return. The point is, instead of making stats -- which is essentially extra info -- as a first-class citizen of result, we can just add it to result object as is (without map). |
Nice! Just one thing: If sass.render({
..
success: function(result) {
// result.css returns css as string
// result.map returns map as string
..
}
..
}) |
Well, since we are going to have number of breaking changes in v2 anyway, wouldn't hurt to incorporate this change. :) |
* Removes deprecated functions. * Introduces breaking change. * Reponds to sass#547.
v2.0.0-beta is just released. |
Since v2 is coming with breaking changes. Here is another batch, which I think will mitigate redundancies:
deprecatedRender and deprecatedRenderSync
.render and renderFile
intorender
.renderSync and renderFileSync
intorenderSync
.writeOutput
.The behavior goes like this:
file
inrender( { file: '/path/to/file' } )
, libsass will read the file, compile the code and returns back the code. We will pass the code (css: as string and map: as JS object literal) on to the caller, instead of writing it to the disk.data
inrender( { data: 'body { color: navy} ' } )
, libsass will read the file, compile the code and returns back the code. Pass on code without writing to disk.file
anddata
inrender( { file: 'c:/temp/example.scss', data: "body { color: white }" } )
, libsass will give precedence todata
and usefile
path in source-maps generation. In this casefile
will just make the parser more "context-aware". Again pass the code as is to the caller with no write to disk involved.writeOutput
(which would befalse
by default) as inrender( { writeOutput: true } )
, we will write both CSS and source-maps to disk only then. (this shall address Emit source map as data (not file) #303)*Sync
variants.writeOutput
would betrue
by default and presence of--stdOut
would be translated intowriteOutput: false
.Our API will end up exposing only two methods:
as opposed to the existing four:
which is confusing, because (1) middleware is obsolete, (2) there is no renderFileSync to complete the pair.
Future extension:
parseOnly: [Function]
:I'm not sure if libsass provide parse-only (lint mode) functionality, to check the code and reports back error without the compilation step involved (it is comparatively faster and will help the IDE's to validate syntax). However, if libssass' parser step is too tied up with compiler and there no such performance gain with or without compilation step involved; then the consumer of node-sass will just compile the code and grab the errors (pretend parse-only).
@andrew, @kevva, @mgreter thoughts?
The text was updated successfully, but these errors were encountered: