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

Fix symlink interaction with modulinos #400

Open
mcandre opened this issue Sep 26, 2024 · 0 comments
Open

Fix symlink interaction with modulinos #400

mcandre opened this issue Sep 26, 2024 · 0 comments

Comments

@mcandre
Copy link

mcandre commented Sep 26, 2024

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

#!/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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant