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

What are Node.js "Linked" modules? #12516

Closed
thefourtheye opened this issue Apr 19, 2017 · 11 comments
Closed

What are Node.js "Linked" modules? #12516

thefourtheye opened this issue Apr 19, 2017 · 11 comments
Labels
doc Issues and PRs related to the documentations. good first issue Issues that are suitable for first-time contributors. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. lib / src Issues and PRs related to general changes in the lib or src directory.

Comments

@thefourtheye
Copy link
Contributor

When I was going through the source code, I found this in node.cc,

// "Linked" modules are included as part of the node project.
// Like builtins they are registered *before* node::Init runs.
mp->nm_flags = NM_F_LINKED;

Does anybody know what "Linked" modules are? @bnoordhuis maybe?


cc @addaleax

@thefourtheye thefourtheye added lib / src Issues and PRs related to general changes in the lib or src directory. question Issues that look for answers. labels Apr 19, 2017
@mscdex
Copy link
Contributor

mscdex commented Apr 19, 2017

It's probably this in the build script:

parser.add_option("--link-module",
    action="append",
    dest="linked_module",
    help="Path to a JS file to be bundled in the binary as a builtin."
         "This module will be referenced by path without extension."
         "e.g. /root/x/y.js will be referenced via require('root/x/y')."
         "Can be used multiple times")

@addaleax
Copy link
Member

@mscdex That’s something different. The linked modules the C++ source is talking about would be native modules that are compiled into (or LD_PRELOLADed into?) the node executable itself, not JS code.

@mscdex
Copy link
Contributor

mscdex commented Apr 19, 2017

Well, that's not confusing ;-)

@bnoordhuis
Copy link
Member

The configure switch is for baking third-party JS source code into the binary, NM_F_LINKED is for bundling add-ons into the binary. Unfortunate name clash, yes.

@addaleax
Copy link
Member

@bnoordhuis Is there anybody who uses that feature? Would documenting it be a good idea?

@bnoordhuis
Copy link
Member

I assume so, at least at the time, otherwise why bother making a pull request? Both features where requested and implemented by non-collaborators.

Documenting it: no reason not to, I suppose.

@Trott Trott added doc Issues and PRs related to the documentations. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. labels Aug 2, 2017
@BridgeAR BridgeAR added good first issue Issues that are suitable for first-time contributors. and removed question Issues that look for answers. labels Sep 23, 2017
@snggeng
Copy link

snggeng commented Oct 29, 2017

Hi I'd like to work on this. This is my first time working on open source and I was wondering which part of the documentation this should go into, and generally the relevant parts of the source I should be looking at.

@gibfahn
Copy link
Member

gibfahn commented Oct 29, 2017

I guess it should go somewhere in https://nodejs.org/api/modules.html (source here)?

As mentioned above, for the Native module you probably want to start here:

node/src/node.cc

Lines 2595 to 2599 in 4359a93

// "Linked" modules are included as part of the node project.
// Like builtins they are registered *before* node::Init runs.
mp->nm_flags = NM_F_LINKED;
mp->nm_link = modlist_linked;
modlist_linked = mp;

For the js module you probably want to start here:

node/configure

Lines 152 to 158 in 201ecef

parser.add_option("--link-module",
action="append",
dest="linked_module",
help="Path to a JS file to be bundled in the binary as a builtin."
"This module will be referenced by path without extension."
"e.g. /root/x/y.js will be referenced via require('root/x/y')."
"Can be used multiple times")

@bnoordhuis are the two features functionally identical, except for the fact that one is for native addons and one is for js addons?

@snggeng
Copy link

snggeng commented Oct 30, 2017

Awesome, thanks for the tips @gibfahn I'll look into it.

Suixinlei added a commit to Suixinlei/node that referenced this issue Jan 9, 2018
evanlucas pushed a commit that referenced this issue Jan 30, 2018
Fixes: #12516
Refs: #2497

PR-URL: #17705
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
evanlucas pushed a commit that referenced this issue Jan 30, 2018
Fixes: #12516
Refs: #2497

PR-URL: #17705
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Feb 27, 2018
Fixes: #12516
Refs: #2497

PR-URL: #17705
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Feb 27, 2018
Fixes: #12516
Refs: #2497

PR-URL: #17705
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@joyeecheung joyeecheung reopened this Mar 4, 2018
@joyeecheung
Copy link
Member

Reopen since the OP is asking about native modules and they are still not documented. Should be fixed by #19112

@apapirovski
Copy link
Member

Sounds like this was addressed by @joyeecheung above. Closing.

MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
Fixes: nodejs#12516
Refs: nodejs#2497

PR-URL: nodejs#17705
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. good first issue Issues that are suitable for first-time contributors. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants