Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bcrypt for Node.js with Node addon api #551

Merged
merged 29 commits into from
Dec 12, 2017
Merged

bcrypt for Node.js with Node addon api #551

merged 29 commits into from
Dec 12, 2017

Conversation

NickNaso
Copy link
Contributor

@NickNaso NickNaso commented Oct 9, 2017

Hi,
I'm opening the PR to start iterate over the porting of bcrypt to N-API

Closes #513

recrsn
recrsn previously requested changes Oct 9, 2017
Copy link
Collaborator

@recrsn recrsn left a comment

Choose a reason for hiding this comment

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

Code looks good to me. Except for a little typo in exception messages and a build issue in linux

if (info.Length() < 2) {
Nan::ThrowTypeError("2 arguments expected");
return;
throw Napi::TypeError::New(info.Env(), "3 arguments expected");
Copy link
Collaborator

Choose a reason for hiding this comment

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

should be 2 args expected ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I think that I’m the code there are some errors. I will change as soon as possible now I’m leaving from Vancouver to Italy and I cannot be very active

@recrsn recrsn requested a review from defunctzombie October 9, 2017 17:44
binding.gyp Outdated
},
"xcode_settings": {
"CLANG_CXX_LIBRARY": "libc++",
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need same settings in linux too.

@recrsn recrsn dismissed their stale review October 9, 2017 17:49

There is additional cases for windows that needs to be handled

@recrsn
Copy link
Collaborator

recrsn commented Oct 9, 2017

@NickNaso The windows targets fail with nasty errors. Can you have a look ?

@recrsn recrsn changed the title bcrypt for Nofe.js with Node addon api bcrypt for Node.js with Node addon api Oct 9, 2017
@NickNaso
Copy link
Contributor Author

@agathver I have to do others little modifications. Can I add me to the contributors?

package.json Outdated
@@ -29,7 +29,7 @@
"install": "node-pre-gyp install --fallback-to-build"
},
"dependencies": {
"nan": "2.6.2",
"node-addon-api": "git+https://github.com/nodejs/node-addon-api.git",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not merge this. This is a dependency on a floating master branch and will lead to breaking changes. Please pick a specific version to depend on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you're right I want only understand where was the real problem if on the code or on ```node-addon-api`` version

@defunctzombie
Copy link
Collaborator

Is nan discontinued? Looking at the node-addon-api project, it seems to serve the exact same purpose as nan. What is the benefit of switching?

@recrsn
Copy link
Collaborator

recrsn commented Oct 21, 2017

@defunctzombie See this:

In short, this will bring "compile once, run in any node" versions of native addons, which will save dozens of "bcrypt does not work" issues on the release of a new node version.

@NickNaso
Copy link
Contributor Author

NickNaso commented Oct 21, 2017

Hi @agathver @defunctzombie
node-addon-api and nan are very different. NAN could be considered a thin layer build over the V8 API, so it's strong bounded with it. The main purpose of NAN is to guarantee the API compatibility across different version of Node.js.
node-addon-api is a C++ wapper of the new N-API https://nodejs.org/api/n-api.html it's completely JavaScript engine agnostic and it guarentees the API and ABI compatibility between different version of Node.js. So if you switch to a different version of Node.js you must not reinstall and maybe recompile the addon.
You could consider the idea to have two packages one with N-API and other with NAN as reported here:
https://nodejs.org/en/docs/guides/publishing-napi-modules/

@defunctzombie
Copy link
Collaborator

It is intended to insulate Addons from changes in the underlying JavaScript engine and allow modules compiled for one version to run on later versions of Node.js without recompilation.

This is a cute goal that I doubt will be achieved; maybe if they never introduce backwards breaking abi changes but with c++ that can be quite hard. In any case, it seems like this is the forward direction nodejs itself is promoting instead of nan. Thanks for doing the porting.

@NickNaso
Copy link
Contributor Author

Hi @agathver @defunctzombie ,
today we have been released the new version of node-addon-api. I substituted it on package.json now all seems work fine.
What do you think if with this starting point we work together to publish a release of bcrypt that use N-API?
I mean to follow this guide https://nodejs.org/en/docs/guides/publishing-napi-modules/ obviously before that we need to do all work that you feel necessary to publish the addon.

@ncb000gt
Copy link
Member

@NickNaso please feel free to add yourself to the list of contributors.

Nan::ThrowTypeError("3 arguments expected");
return;
throw Napi::TypeError::New(info.Env(), "3 arguments expected");
return info.Env().Undefined();
Copy link
Member

Choose a reason for hiding this comment

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

Why are these returns needed if you're throwing? I see them throughout, but thought they were unnecessary, no?

Copy link
Contributor Author

@NickNaso NickNaso Nov 22, 2017

Choose a reason for hiding this comment

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

You're right it's not necessary if exceptions system is enable. I provided to remove all unuseful code.

Copy link
Collaborator

@recrsn recrsn left a comment

Choose a reason for hiding this comment

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

Semver is nice but things break. Please pin the version numbers to prevent any accidental breakage ever.

package.json Outdated
@@ -29,8 +29,9 @@
"install": "node-pre-gyp install --fallback-to-build"
},
"dependencies": {
"nan": "2.6.2",
"node-pre-gyp": "0.6.36"
"bindings": "^1.3.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please pin these dependencies.

Copy link
Contributor Author

@NickNaso NickNaso Nov 27, 2017

Choose a reason for hiding this comment

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

Sorry I didn't understand. Do I need to add nan and node-pre-gyp ???

Copy link
Collaborator

Choose a reason for hiding this comment

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

No. Just remove the caret. "^1.3.0" becomes "1.3.0" and so on.

Copy link
Contributor Author

@NickNaso NickNaso Nov 28, 2017

Choose a reason for hiding this comment

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

Ok just done. Can you check?

@NickNaso
Copy link
Contributor Author

NickNaso commented Dec 7, 2017

Hi guys,
can you continue to review the code so we can publish the N-API version of bcrypt?

@recrsn
Copy link
Collaborator

recrsn commented Dec 8, 2017

@defunctzombie @ncb000gt Thoughts?

Copy link
Collaborator

@defunctzombie defunctzombie left a comment

Choose a reason for hiding this comment

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

LGTM we can iterate further as needed.

@NickNaso
Copy link
Contributor Author

Hi guys,
what do you think if we tag the version as 1.0.3-napi and publish it throw this command:

npm publish --tag n-api

More explanation here:
To publish N-API version of a package alongside a non-N-API version

@recrsn recrsn merged commit 3edea5f into kelektiv:napi Dec 12, 2017
fast-facts pushed a commit to fast-facts/node.bcrypt.js that referenced this pull request Jun 17, 2022
bcrypt for Node.js with Node addon api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants