Permalink
Browse files

Document require.main doesn't work as usual in bin file.

  • Loading branch information...
1 parent 8d0cfdb commit 19206eea4a10e09e6adfe855e2c35ff7034ed36f @5long 5long committed with isaacs Oct 26, 2010
Showing with 13 additions and 0 deletions.
  1. +6 −0 doc/json.md
  2. +7 −0 man1/json.1
View
@@ -109,6 +109,12 @@ So, when you install npm, it'll create a symlink from the `cli.js` script to
`/usr/local/bin/npm-version`. Then, when you activate that version, it'll
create a symlink from `/usr/local/bin/npm-version` to `/usr/local/bin/npm`.
+Notice that if the executable file is interpreted by node (i.e., specifying
+node in the shebang line), npm actually installs a shim instead of symlinking
+it, which causes expressions `require.main === module` and `module.id === "."`
+evaluate to `false` within the file. This seems unable to be resolved until
+node provides a "flexible `require()`".
+
Shortcut: If you have a single executable, and its name is already what you
want it to be, then you can just supply it as a string. For example:
View
@@ -152,6 +152,13 @@ So, when you install npm, it\'ll create a symlink from the \fBcli\.js\fR script
create a symlink from \fB/usr/local/bin/npm\-version\fR to \fB/usr/local/bin/npm\fR\|\.
.
.P
+Notice that if the executable file is interpreted by node (i\.e\., specifying
+node in the shebang line), npm actually installs a shim instead of symlinking
+it, which causes expressions \fBrequire\.main === module\fR and \fBmodule\.id === "\."\fR
+evaluate to \fBfalse\fR within the file\. This seems unable to be resolved until
+node provides a "flexible \fBrequire()\fR"\.
+.
+.P
Shortcut: If you have a single executable, and its name is already what you
want it to be, then you can just supply it as a string\. For example:
.

0 comments on commit 19206ee

Please sign in to comment.