-
Notifications
You must be signed in to change notification settings - Fork 3
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
add script path #2
base: master
Are you sure you want to change the base?
Conversation
cdd1824
to
0201eb3
Compare
@gajus thoughts on this? I was also thinking maybe having only this (the short script path) without the function name. What would you say about making the function name optional, like |
I'm using this in Node |
|
||
if (opts.scriptPath) { | ||
if (basename === 'index.js') { | ||
return '[' + Path.basename(basedir) + '/' + basename + ':' + line + ']'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the reason for needing to wrap the path in square brackets?
if (basename === 'index.js') { | ||
return '[' + Path.basename(basedir) + '/' + basename + ':' + line + ']'; | ||
} else { | ||
return '[' + basename + ':' + line + ']'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the reason for not including the column?
const relativeFilename = Path.relative(Path.dirname(pkgDir), fullPath); | ||
|
||
return { | ||
scriptColumn: t.numericLiteral(column), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the reason for representing this as an object, as opposed to a single string scriptPath:line:column
?
I know thats what I do at https://github.com/gajus/babel-plugin-log-deprecated
though I am not necessarily a good developer to follow by example. :-(
Representing it as a single string will enable you to click–open in IDE the file at a specified line, column (e.g. https://coderwall.com/p/0kapug/iterm2-open-text-file-paths-in-sublime-text-with-jump-to-line-number)
// => | ||
console.log('[file.js:3]', 'foo()', 'apple') | ||
``` | ||
Use `"fullScriptPath": true` to add more detailed script path info |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that fullScriptPath
behaves different from scriptPath
, i.e. one adds path as the first parameter of console.log
, the second one adds it as an object to the end. I'd rather that scriptPath
would always add a string path as the first parameter. Use it in combination with scriptPathStyle
(ENUM 'relative' | 'fileName'
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea. To clarify, 'fileName'
would be just foo.js
, and 'relative'
would be relative to the project root, right? Should there also be an option 'fullpath'
for actual full path? You mentioned above "iterm2-open-text-file-paths", I'm not familiar with it but would it require full path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made it a single setting scriptPath: 'relative' | 'filename' | 'fullpath'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mentioned above "iterm2-open-text-file-paths", I'm not familiar with it but would it require full path?
Not necessarily. Depends on the PWD.
badfcf8
to
b4808c3
Compare
@@ -61,9 +63,34 @@ export default ({ | |||
throw new Error('Unexpected state.'); | |||
}; | |||
|
|||
const getScriptPath = (path: Object, state: Object) => { | |||
const opts = state.opts; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add type definition for:
type OptionsType = {
scriptPath: 'filename' | 'fullpath' | 'relative'
};
const opts: OptionsType = state.opts;
If you specify option
"scriptPath": true
:it'll add a short script path (and line number)
If the filename was
index.js
it'll ad the parent foldernameUse
"fullScriptPath": true
to add more detailed script path infofixes #1