-
Notifications
You must be signed in to change notification settings - Fork 118
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
based on various discussions I've switched to require.main.filename #3
Conversation
… using require.main.filename
This looks good on first blush, but is |
Given the couple edge cases like Unitech/pm2#66 & iisnode on Microsoft Azure, should we do one or more of the following Does NPM have testing infrastructure for trying out modules such as this w/ iisnode on Azure? |
@jameswomack it seems like there's a fairly easy workaround on iisnode: {id: '.',
exports: {},
parent: null,
filename: 'D:\\Program Files (x86)\\iisnode\\interceptor.js',
loaded: false,
children:
[ { id: 'D:\\home\\site\\wwwroot\\server.js',
exports: [Object],
parent: [Circular],
filename: 'D:\\home\\site\\wwwroot\\server.js',
loaded: false,
children: [Object],
paths: [Object] } ],
paths:
[ 'D:\\Program Files (x86)\\iisnode\\node_modules',
'D:\\Program Files (x86)\\node_modules',
'D:\\node_modules' ] } We could use the |
@jameswomack @nexdrew testing with pm2 output: yargs-testing-module-0 (out): Module {
yargs-testing-module-0 (out): id: '.',
yargs-testing-module-0 (out): exports: {},
yargs-testing-module-0 (out): parent: null,
yargs-testing-module-0 (out): filename: '/Users/benjamincoe/bcoe/yargs-testing-module/bin/yargs-testing-module.js',
yargs-testing-module-0 (out): loaded: false,
yargs-testing-module-0 (out): children:
yargs-testing-module-0 (out): [ Module {
yargs-testing-module-0 (out): id: '/Users/benjamincoe/bcoe/yargs-testing-module/node_modules/yargs/index.js',
yargs-testing-module-0 (out): exports: [Object],
yargs-testing-module-0 (out): parent: [Circular],
yargs-testing-module-0 (out): filename: '/Users/benjamincoe/bcoe/yargs-testing-module/node_modules/yargs/index.js',
yargs-testing-module-0 (out): loaded: true,
yargs-testing-module-0 (out): children: [Object],
yargs-testing-module-0 (out): paths: [Object] } ],
yargs-testing-module-0 (out): paths:
yargs-testing-module-0 (out): [ '/Users/benjamincoe/bcoe/yargs-testing-module/bin/node_modules',
yargs-testing-module-0 (out): '/Users/benjamincoe/bcoe/yargs-testing-module/node_modules',
yargs-testing-module-0 (out): '/Users/benjamincoe/bcoe/node_modules',
yargs-testing-module-0 (out): '/Users/benjamincoe/node_modules',
yargs-testing-module-0 (out): '/Users/node_modules',
yargs-testing-module-0 (out): '/node_modules' ] } I think writing a shim for My gut is that this would cover the majority of our use-cases, and we could address others in issues as they come up (updating the tiny shim module). how do you feel about this @nexdrew? |
@bcoe Works for me 👍 |
👍 |
Can't speak to pm2, iisnode, etc. But if they're using the stock |
Boom, I've written: https://github.com/yargs/require-main-filename And stood up a Node Azure instance that I've tested on using: https://github.com/bcoe/test-node-path (which we can use for debugging future edge-cases). I'm pretty confident with this approach at this point. We might occasionally run into a process runner that steps on our toes but we can simply update |
I guess this works fine for the use-case of |
@sindresorhus 👍 I will expand on this:
Further before merging, explaining that it looks for a |
And be clear that it should be turned off if you plan on using this in a reusable module and not in a CLI or app. |
I still think we should consider doing the That may resolve some of the concerns brought up here and would reduce the coupling b/w the 2 modules, making |
@nexdrew there are two reasons I'm not too excited about this:
I honestly don't fully understand the use-case of wanting to be able to use |
I'm kind of with @nexdrew and @sindresorhus on this. The use case isn't using yargs-parser without configuring it. It's about using yargs-parser and configuring it in a different way. yargs-parser should be just a parser. If you want to remove the "get the yargs config stuff out of package.json" to also be abstracted out, that's great. Yargs can do But if I wanted to use the yargs-parser in, say, nopt or dashdash, it's pretty weird to have to override it or else have it pull a |
I can't argue with three people's instinct. As much as I'd like to stop bike-shedding this thread, I will continue bike-shedding this API. |
I agree with the esteemed collaborators above, with a slightly different take on it. I could see a module with both CLI parsing and pkg configuration, but that becomes a highly specialized configuration module rather than a CLI parser that follows the UNIX philosophy of doing one thing and one thing well. |
based on various discussions I've switched to require.main.filename
Based on discussions with @sindresorhus, @isaacs, and @iarna, I've switched to using:
require.main.filename
I've thoroughly tested this approach with the following testing module:
https://www.npmjs.com/package/yargs-testing-module
And the following branch of yargs, which has integration tests for symlinks:
yargs/yargs#356
Using the two approaches outlined above, I've tested the following on
npm 2.x
andnpm 3.x
:Sorry for keeping this conversation going so long, I really want to be careful to get this right (
yargs@4.x
needs to be an improvement not a step backwards).Reviewers: @sindresorhus, @jameswomack, @nexdrew