Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Binding: Refurbishes binding to use new API #543

Merged
merged 9 commits into from
Dec 18, 2014
Merged

Binding: Refurbishes binding to use new API #543

merged 9 commits into from
Dec 18, 2014

Conversation

am11
Copy link
Contributor

@am11 am11 commented Nov 16, 2014

(Responding to: sass/libsass#635)

Libsass is getting a new API. It doesn't replaces the current one, but renders it somewhat obsolete.

Thanks to @mgreter; the new API is beauty! 👍

I have managed to implement it as drop-in replacement to the existing one, by revamping the bindings and context-wrapper.

Status:

  • Update binding.gyp to acquire new code files.
  • Update context-wrapper to act like an interface as well as helper to our bindings: now compilation takes place from context-wrapper.
  • Update binding.cpp to abide by the new API docs.
  • Make use of new JSON serialized errors (fixes Serialize errors as JS objects (optional?) #464 and CLI ouput in JSON OR any custom format libsass#235).
  • Make sure the code is cleaned up, no memory leaks, remove unused header inclusions and keep code readable.
  • Add variants of source-maps.
  • Parse source-map as JSON.
  • Make sure all existing tests are passing.
  • Once @mgreter's repo is merged and libsass' tagged release is available rebase and pull libsass and sass-spec submodules.

The new API also fixed: sass/libsass#634 and the corresponding node-sass test is updated and is passing.

@am11
Copy link
Contributor Author

am11 commented Nov 16, 2014

@mgreter, can you please review the code and let me know if you find memory leaks or any other issue which needs to be addressed?

Out of 622, 619 tests are passing and the following three are failing:

  • api .renderFile(options) should save source paths relative to the source map file (link).
  • api .render({stats: {}}) should report correct source map in stats (link).
  • api .renderSync({stats: {}}) should report correct source map in stats (link).

Please let me know if there is something we need to update in order to pass those tests. I couldn't find a pattern. There are other passing tests with similar configuration. My first hunch was that they are failing due to the reason bar.scss file is empty, but even after adding some CSS code lines in it, these tests are failing.

void free_file_context(struct Sass_File_Context* fctx) {
// delete[] fctx->input_path;
// delete[] fctx->options.include_paths;
// delete[] fctx->options.image_path;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgreter, should we remove these?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should be safe to remove, since sass_free_xxx_context should take care of that!

@@ -51,56 +32,63 @@ void ExtractOptions(Local<Value> optionsValue, void* cptr, sass_context_wrapper*
}

if (isFile) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably merge most or all of the following statements, as they now share a common struct (Sass_Options) to setup the options (before you had to split it up, since the options were living on two totally unrelated structs).

@am11
Copy link
Contributor Author

am11 commented Nov 17, 2014

Thanks for the review @mgreter. I have made those changes in 4abc7dd. :)

@mgreter
Copy link
Contributor

mgreter commented Nov 17, 2014

Please see commit mgreter@f375c37 for a fix for the failing unit test.
IMO the bindings could be simplified even more!
Let me see if I can come up with something in an hour or two :)
P.s. it should be documented better that the command to run the test suite is:
./node_modules/.bin/mocha

@am11
Copy link
Contributor Author

am11 commented Nov 17, 2014

Great! I will try it now.

For running tests, you can use npm test in node-sass root directory.

I follow this sequence:

# (1)
cd into/node-sass/dir

# (2) first get latest libsass
cd src/libsass
git pull --rebase mgreter-libsass api/c-interface
cd ../..

# (3) now install npm, only if you haven't already
#     just once (a while; in case we modify dependencies or newer version of dependencies
#     have arrived)
npm install  # optionally you can delete npm_modules before running this command,
             #  so you don't have unused / outdated dependencies laying around

# (4) now rebuild so it doesn't use the old binaries
node scripts/build -f

# (5) finally run the test
npm test
node scripts/build -f

Repeat (4) and (5) if you are making changes in cpp code. :)

This code is ported from @mgreter's fork.
@am11
Copy link
Contributor Author

am11 commented Nov 17, 2014

Now all tests are passing. 😄

Thanks again @mgreter. 👍

@mgreter
Copy link
Contributor

mgreter commented Nov 17, 2014

OK, glanced over the code and refactored some bits and removed some obsolete parts. Test still pass, but I would strongly recommend to do at least some basic memory leak testing. In perl-libsass I just use a lot of the spec tests in an endless loop to see if memory stabilizes at some point.
mgreter@7bc9479

@am11
Copy link
Contributor Author

am11 commented Nov 17, 2014

Thanks can you please rebase your branch so I can pull your changes.

Also, for memory leaks, wouldn't it make sense to use preexisting tools like http://valgrind.org/downloads/current.html#current to detect the memory leaks? I haven't tried it yet. :)

@mgreter
Copy link
Contributor

mgreter commented Nov 17, 2014

Sure, Valgrind would be much better if you know how to use them properly with node.js ;)
But a poor mans memory leak test should still show the most obvious memory leaks!

@am11
Copy link
Contributor Author

am11 commented Nov 17, 2014

LOL, first I would have to compile it on Windows, and if that works then there is a learning curve for its usage. :)
So poor man's memory leak test that is. 😄
Or may be something like this: http://stackoverflow.com/a/2981185/863980.
Now I am realizing that for memory leaks, I am like that one-trick pony who just learnt how to detect it by monitoring task-manager or dry running the code. 👎

@mgreter
Copy link
Contributor

mgreter commented Nov 17, 2014

Sorry, rebase has to many conflicts. Maybe you can scavenge some bits from the diffs in my branch.

@am11
Copy link
Contributor Author

am11 commented Nov 17, 2014

Yup I will give it a try now. BTW, with latest sass-spec master, we are passing all 626 tests with your api/c-interface !

@am11
Copy link
Contributor Author

am11 commented Nov 17, 2014

@andrew, with this API, we can get error messages in both formats; JSON and (the old) plain text. I changed it to get JSON. Do we need to make it optional as well? I don't think with code usage anyone would not prefer JS-object. TBH, on CLI it also looks nicer. For instance, in CLI:

C:\users\Adeel\Source\Repos\node-sass [master]> node bin/node-sass --stdout c:/temp/foo3.scss
{
  "status": 1,
  "file": "c:/temp/foo3.scss",
  "line": 3,
  "column": 9,
  "message": "invalid syntax"
}

Secondly; do we need to parse the errors as object? So in onerror: callback, the consumer will just do error.message, error.column , error.line and error.status. For other errors generated within our JS code (like fs I/O ops), we can wrap them in object {message: err}.

Thoughts?

@andrew
Copy link
Contributor

andrew commented Nov 17, 2014

I don't see why not, when we release this I expect we'll bump it to 2.0.0 so breaking changes are to be expected.

@am11
Copy link
Contributor Author

am11 commented Nov 17, 2014

Awesome! 👍
Hopefully, we will get source-maps inlining and other varieties from libsass as well. We would need to exposes options for those (and someday, sooner or later, we would be consuming other charming features like; custom functions and sass-importer).

For CLI format as JSON with indent = 2.
@am11
Copy link
Contributor Author

am11 commented Nov 18, 2014

@andrew, see 9f7a78d; on CLI it will also print JSON errors. :)

Also fixes the issue with destination path
being resolved w.r.t input, without accounting
for it being already absolute.
@am11
Copy link
Contributor Author

am11 commented Nov 18, 2014

With d58c303, I have added two new source-map options:

  • sourceMapEmbed: embed sourceMappingUrl as data URI.
  • sourceMapContents: embed include contents in maps.

Addresses #372.


^ This needs test cases. 😊

This was referenced Nov 18, 2014
am11 referenced this pull request in sass/libsass-net Nov 18, 2014
latest libsass, fixing x64 problem
@am11 am11 added the v2 label Nov 19, 2014
@iamvdo
Copy link

iamvdo commented Dec 11, 2014

When will this PR be integrated? Any though?

@am11
Copy link
Contributor Author

am11 commented Dec 11, 2014

Will it depends on libsass' next tagged release. This is related: sass/libsass#697.

@am11 am11 changed the title Binding: Refurbishes binding to use new API [DO NOT MERGE] Binding: Refurbishes binding to use new API Dec 18, 2014
am11 added a commit that referenced this pull request Dec 18, 2014
Binding: Refurbishes binding to use new API
@am11 am11 merged commit 7c354bf into sass:master Dec 18, 2014
@andrew
Copy link
Contributor

andrew commented Dec 18, 2014

7drhiqr

@am11
Copy link
Contributor Author

am11 commented Dec 18, 2014

Yay! 🎉

@mgreter
Copy link
Contributor

mgreter commented Dec 18, 2014

👍

@leehambley
Copy link

Forgive me posting here not being a Node.js'er, but looks like this didn't make it into the real release yet? I noticed that node-sass doesn't make use of milestones (neither do I), and that the last release was about ~2.5 months ago, can we rely on a note here when the new version including the commit goes live? I can barely wait to abandon Ruby sass for my front end build!

jiongle1 pushed a commit to scantist-ossops-m2/node-sass that referenced this pull request Apr 7, 2024
Exports quote and unquote functions for C bindings
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ctx->includedFiles misleading stdin
5 participants