scripts: Replace node-wrapper with a symlink.

Commit 00e057bf44 (#4727) simplified
node-wrapper to a one-line wrapper script for performance.  Copying
the binary was proposed and rejected because node finds some of its
modules relative to its own path.  But a symlink doesn’t have that
issue, as you can verify with

    node -e 'console.log(require.resolve.paths("foo"))'

(To find its own path, node uses `process.execPath`, which resolves
symlinks, and there’s no plausible reason for that behavior to change.
https://github.com/nodejs/node/blob/v8.11.1/lib/module.js#L708-L717
https://github.com/nodejs/node/blob/v10.7.0/lib/internal/modules/cjs/loader.js#L761-L770)

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2018-07-28 19:50:53 -04:00 committed by Tim Abbott
parent 1ce31ecd7d
commit a5407e1c7d
2 changed files with 5 additions and 8 deletions

View File

@ -16,16 +16,16 @@ yarn_version=1.7.0
export HOME=/root
current_node_version="none"
if hash node 2>/dev/null; then
if node_wrapper_path="$(type -p node)"; then
current_node_version="$(node --version)"
fi
if [ "$($YARN_BIN --version 2>/dev/null)" = "$yarn_version" ] && [ "$current_node_version" = "v$node_version" ]; then
if [ "$($YARN_BIN --version 2>/dev/null)" = "$yarn_version" ] && [ "$current_node_version" = "v$node_version" ] && [ -L "$node_wrapper_path" ]; then
echo "Node version $node_version and yarn version $yarn_version are already installed."
exit 0
fi
if [ "$current_node_version" != "v$node_version" ]; then
if [ "$current_node_version" != "v$node_version" ] || ! [ -L "$node_wrapper_path" ]; then
export NVM_DIR=/usr/local/nvm
if ! [ -e "$NVM_DIR/nvm.sh" ]; then
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
@ -41,9 +41,8 @@ if [ "$current_node_version" != "v$node_version" ]; then
chown -R root:root "$n"
chmod -R go-w "$n"
# Install node wrapper to /usr/local/bin
cp "$ZULIP_PATH/scripts/setup/node-wrapper" /usr/local/bin/node
sed -i "s|NODE_PATH|$NODE_BIN|" /usr/local/bin/node
# Install node symlink to /usr/local/bin
ln -nsf "$NODE_BIN" /usr/local/bin/node
fi
# Work around the fact that apparently sudo doesn't clear the HOME

View File

@ -1,2 +0,0 @@
#!/bin/bash
NODE_PATH "$@"