Coder Social home page Coder Social logo

Implement 'copy' command about node-gyp HOT 5 CLOSED

nodejs avatar nodejs commented on September 22, 2024
Implement 'copy' command

from node-gyp.

Comments (5)

cmundi avatar cmundi commented on September 22, 2024

I'm not sure if this related, but... here is a general question about node-gyp (and maybe bindings) made specific in the context of node-sqlite3.

Now that I have node-sqlite3 building with node-gyp, I would like to be able to relocate it (directly into production and not via uploading an npm package) so that require('sqlite3') just works. I gather this is what 'node-gyp copy' will do when implemented?

I'm not sure why the node requires logic confuses me so much. I've only read the nice docs at nodejs.org a dozen times. I seem to get one thing working and then have trouble with the next. :)

I've been trying to coerce node-bindings into working for any node_modules directory, but I have not been able to get 'bindings' to discover the root, perhaps because I do not have a package.json that it likes and perhaps because I only get about ten minutes to think about this between meetings. The error is something like

Error: Could not find module root given file: C:\Documents and Settings\cm\node_modules\sqlite3\sqlite3.js

where I have put the node_sqlite3.node file right there in the node_modules\sqlite3 folder alongside sqlite3.js.

In the short term, I just need to know how to hack the relocation the the module /lib and *.node artifacts created by node-gyp. I hope this makes sense in a sleep-deprived way.

from node-gyp.

TooTallNate avatar TooTallNate commented on September 22, 2024

@cmundi The error you are seeing is from node-bindings it indeed is because you do not have a package.json file, so you will need to add one of those to make it find the module root properly. Once you have the package.json in place, then you can see where node-bindings is looking for the native addon module, but for a quick reference:

> require('bindings')('node_sqlite3.node')
Error: Could not load the bindings file. Tried:
 ↳  /Users/nrajlich/node-sqlite3/out/Debug/node_sqlite3.node
 ↳  /Users/nrajlich/node-sqlite3/Debug/node_sqlite3.node
 ↳  /Users/nrajlich/node-sqlite3/out/Release/node_sqlite3.node
 ↳  /Users/nrajlich/node-sqlite3/Release/node_sqlite3.node
 ↳  /Users/nrajlich/node-sqlite3/compiled/0.6/darwin/x64/node_sqlite3.node
 ↳  /Users/nrajlich/node-sqlite3/build/Release/node_sqlite3.node
 ↳  /Users/nrajlich/node-sqlite3/build/default/node_sqlite3.node
    at bindings (/Users/nrajlich/node-sqlite3/node_modules/bindings/bindings.js:78:13)
    at repl:1:20
    at REPLServer.eval (repl.js:80:21)
    at Interface.<anonymous> (repl.js:182:12)

Does that make sense? node-bindings exists because of the historical differences in the location that node's addon files get built by default, so it's designed so that you build the addon and then require 'bindings' and it "just works" (i.e. no copying the resulting binary is necessary).

The copy command would be for the /Users/nrajlich/node-sqlite3/compiled/0.6/darwin/x64/node_sqlite3.node case, where the path is determined at runtime based on the current node version, platform and architecture. You could then commit the resulting copied binary or something, but that's "a sin" and we're still working on a better solution (likely involving npm).

from node-gyp.

cmundi avatar cmundi commented on September 22, 2024

Ah! I was just about to go looking for how to turn on verbose logging for
bindings. Sure enough, a package.json file will get the ball rolling.

Yes, I am very impressed with how node-bindings found the node_sqlite3.node
file in the Release folder. I realized some of what was going on when I
saw that a successful require results in the path to the .node file being
returned as part of the object. So much to learn...

I am very grateful that you and a few other capable devs recognize the
importance of cross-platform support for node. For example, I am working
on an application now which must exist in a heterogeneous networking
environment of Linux and Windows boxes. Node has the potential to make a
lot of things really simple. SO far, I've been doing hackish things just
to get going, but I am looking forward to using your work to create a much
better situation. Thanks!

On Mon, Feb 13, 2012 at 8:42 PM, Nathan Rajlich <
[email protected]

wrote:

@cmundi The error you are seeing is from node-bindings it indeed is
because you do not have a package.json file, so you will need to add one
of those to make it find the module root properly. Once you have the
package.json in place, then you can see where node-bindings is looking
for the native addon module, but for a quick reference:

> require('bindings')('node_sqlite3.node')
Error: Could not load the bindings file. Tried:
 ↳  /Users/nrajlich/node-sqlite3/out/Debug/node_sqlite3.node
 ↳  /Users/nrajlich/node-sqlite3/Debug/node_sqlite3.node
 ↳  /Users/nrajlich/node-sqlite3/out/Release/node_sqlite3.node
 ↳  /Users/nrajlich/node-sqlite3/Release/node_sqlite3.node
 ↳  /Users/nrajlich/node-sqlite3/compiled/0.6/darwin/x64/node_sqlite3.node
 ↳  /Users/nrajlich/node-sqlite3/build/Release/node_sqlite3.node
 ↳  /Users/nrajlich/node-sqlite3/build/default/node_sqlite3.node
   at bindings
(/Users/nrajlich/node-sqlite3/node_modules/bindings/bindings.js:78:13)
   at repl:1:20
   at REPLServer.eval (repl.js:80:21)
   at Interface.<anonymous> (repl.js:182:12)

Does that make sense? node-bindings exists because of the historical
differences in the location that node's addon files get built by default,
so it's designed so that you build the addon and then require 'bindings'
and it "just works" (i.e. no copying the resulting binary is necessary).

The copy command would be for the
/Users/nrajlich/node-sqlite3/compiled/0.6/darwin/x64/node_sqlite3.node
case, where the path is determined at runtime based on the current node
version, platform and architecture. You could then commit the resulting
copied binary or something, but that's "a sin" and we're still working on a
better solution (likely involving npm).


Reply to this email directly or view it on GitHub:
#4 (comment)

from node-gyp.

cmundi avatar cmundi commented on September 22, 2024

Got it! I hacked a semi-legit package.json file, found the path which looked nicest (the platform-specific 'compiled' path of course), dropped in node_sqlite3.node and... just like you promised... it just worked. I did all of this in a "deployment" node_modules directory completely separate from where I built node-sqlite3.

Thank You!

from node-gyp.

TooTallNate avatar TooTallNate commented on September 22, 2024

Closing. I don't think we want/need a copy command after all...

from node-gyp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.