Skip to content

Fix symlink interaction with modulinos #400

Open
@mcandre

Description

@mcandre

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions