asdf-vm / asdf-vm/asdf-nodejs

Fix symlink interaction with modulinos

Open
#400 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
989
Forks
162
PR merge metrics
No merged PRs in 30d

Description

When managing executable scripts with `npm install [-g]` in an ASDF context, then ASDF's symlinks break how the conventional modulion snippet works.

```js
#!/usr/bin/env node

export default function main() {
// ...
}

if (import.meta.url === `file://${process.argv[1]}`) { main(); }
```

https://rosettacode.org/wiki/Modulinos

In many cases, Node.js loads the absolute path in `import.meta.url` but a symlink in `process.argv[1]`.

Node.js is documented as normally resolving symlinks automatically. However, asdf-nodejs doesn't use plain files to manage executables, but symlinks. Somewhere in the guts of the `node` interpreter entrypoint handler is an assumption that the names of the script file to load are always plain files.

That deserves a patch upstream to Node.js in its own right.

However, meanwhile, we have two strategies to get asdf-nodejs integrating better with modulinos.

* Patch Node.js as part of the asdf-nodejs build process, with a code snippet to explicitly follow (optional!) symlinks when loading script names.
* Come up with a more complicated modulino snippet that works in both asdf-nodejs and plain host contexts of Node.js installations. Presumably that works with older version managers as well, like nodenv, nodeenv, nvm, n, etc.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.