Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add script path #2

wants to merge 1 commit into from

Conversation

laggingreflex
Copy link

@laggingreflex laggingreflex commented Nov 29, 2016

If you specify option "scriptPath": true:

"plugins": [
  ["annotate-console-log", {
    "scriptPath": true
  }]
]

it'll add a short script path (and line number)

console.log('hi')
// =>
console.log('[file.js:3]', 'foo()', 'hi')

If the filename was index.js it'll ad the parent foldername

console.log('[foo/index.js:5]', 'foo()', 'hi')

Use "fullScriptPath": true to add more detailed script path info

console.log('foo()', 'hi', {
  scriptColumn: 4,
  scriptLine: 9,
  scriptPath: 'relative/to/nearest/package.json/full-script-path/index.js'
})

fixes #1

@laggingreflex
Copy link
Author

@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 {functionName: false, scriptPath: true}

@gajus
Copy link
Owner

gajus commented Jan 2, 2017

Whats the reason for wanting to include the file name, line, column if this information is already present in the console?

screen shot 2017-01-02 at 13 18 05

As is "VM214:1" in this screenshot.

@laggingreflex
Copy link
Author

laggingreflex commented Jan 2, 2017

I'm using this in Node


if (opts.scriptPath) {
if (basename === 'index.js') {
return '[' + Path.basename(basedir) + '/' + basename + ':' + line + ']';
Copy link
Owner

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 + ']';
Copy link
Owner

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),
Copy link
Owner

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
Copy link
Owner

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').

Copy link
Author

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?

Copy link
Author

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'

Copy link
Owner

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.

@@ -61,9 +63,34 @@ export default ({
throw new Error('Unexpected state.');
};

const getScriptPath = (path: Object, state: Object) => {
const opts = state.opts;
Copy link
Owner

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add information about the script path
2 participants