Closed as not planned
Description
Details
Hi there!
In Node v18 the loader was able to easily access all cmd line args viaprocess.argv
.
node --experimental-loader ./loader.mjs /opt/app/server.mjs
loader.mjs
console.log(process.argv)
[
'.../node/v18.16.0/bin/node',
'/opt/app/server.mjs'
]
But with the off-thread change, the process.argv
are no longer complete.
[ '.../node/v20.3.0/bin/node' ]
The second entry is missing. The path to the app is missing.
I found a workaround, but I am not really happy with it. Wondering if there is an easier way.
When using the resolver hook, it is possible to get the parent path.
loader.mjs
let appSpecifier;
export async function resolve(specifier, context, nextResolve) {
if (!appSpecifier) {
appSpecifier = specifier;
process.argv[1] = appSpecifier.replace('file://', '');
...
}
return nextResolve(specifier, context, nextResolve);
}
This is important for APM tools, because we auto-load a tracer tool inside the loader to monitor an app. And we need access to the app path.
Node.js version
v20.3.0
Example code
See above.
Operating system
darwin
Scope
See above.
Module and version
Not applicable.