Hi,
I was trying out dum
and noticed that there is one mistake (?) it does in how it interprets the PATH
environment variable. Pasting some logs below to give a clearer picture.
$ cat file.js
Object.entries(process.env).forEach(([key, value]) => {
if (key.startsWith("npm_")) {
// Skip the npm related envs as those are not supported yet by `dum`.
return;
}
console.log(`${key}: ${value}`);
});
The following are the results from npm
and dum
respectively. I'm only pasting the differences in output here.
$ npm run env
NODE: /usr/local/lib/node_modules/node/bin/node
INIT_CWD: /Users/faizaan.m/Developer/webpro-frontend
PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/faizaan.m/Developer/webpro-frontend/node_modules/.bin:/Users/faizaan.m/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/faizaan.m/.cargo/bin
_: /usr/local/bin/node
$ dum env
PATH: /Users/faizaan.m/.cargo/bin:/Users/faizaan.m/.cargo/bin:/Users/faizaan.m/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/faizaan.m/.cargo/bin:/Users/faizaan.m/Developer/webpro-frontend/node_modules/.bin
_: /usr/local/bin/node
As you can see there are a couple of differences,
INIT_CWD
is missing from dum
but this is easily fixable by adding current_dir
to the envs
Map.
NODE
is missing from dum
, but I think using the result of which node
might fix this (or we can evaluate if this is needed)
PATH
is different in both versions - npm
injects it own internal binary into the PATH. While one could argue that this is not necessary for dum
to support, there's one more bigger issue.
Let's say we start with the following PATH
value
$ echo $PATH
/Users/faizaan.m/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin
And then I change the PATH
$ export PATH=$PATH:/opt/new-tool
Then, if I rerun the above commands, this is the output I see. Again, pasting only the differences.
$ npm run env
PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/faizaan.m/Developer/webpro-frontend/node_modules/.bin:/Users/faizaan.m/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/faizaan.m/.cargo/bin:/opt/new-tool
$ dum env
PATH: /Users/faizaan.m/.cargo/bin:/Users/faizaan.m/.cargo/bin:/Users/faizaan.m/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/faizaan.m/.cargo/bin:/Users/faizaan.m/Developer/webpro-frontend/node_modules/.bin
You can see that /opt/new-tool
is missing when running via dum
. I believe this is because env!
is injecting the value when compiling dum
thereby hardcoding the value into the binary.
bug