-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Load custom formatter by relative path only if it begins with a dot #1413
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
Changes from 2 commits
1b8839e
4bb5a34
91dbe2d
54f2c6a
47d0a8c
36b2823
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -107,8 +107,15 @@ const FormatterBuilder = { | |||||||||||||||
}, | ||||||||||||||||
|
||||||||||||||||
loadCustomFormatter(customFormatterPath: string, cwd: string) { | ||||||||||||||||
const fullCustomFormatterPath = path.resolve(cwd, customFormatterPath) | ||||||||||||||||
const CustomFormatter = require(fullCustomFormatterPath) // eslint-disable-line @typescript-eslint/no-var-requires | ||||||||||||||||
let CustomFormatter = null | ||||||||||||||||
|
||||||||||||||||
if (customFormatterPath.startsWith('.')) { | ||||||||||||||||
const fullCustomFormatterPath = path.resolve(cwd, customFormatterPath) | ||||||||||||||||
CustomFormatter = require(fullCustomFormatterPath) // eslint-disable-line @typescript-eslint/no-var-requires | ||||||||||||||||
} else { | ||||||||||||||||
CustomFormatter = require(customFormatterPath) // eslint-disable-line @typescript-eslint/no-var-requires | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that seems a fair point, although per the docs:
Given we're still supporting Node 10 for the time being (its EOL is April 2021), could use https://github.com/sindresorhus/import-cwd instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest using https://yarnpkg.com/package/create-require as it will use the node builtins when it can, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should actually use it for both branches here, which simplifies the logic and has the same end result There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the above, works great for both cases, thanks for pointing it out |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switched to this |
||||||||||||||||
if (typeof CustomFormatter === 'function') { | ||||||||||||||||
return CustomFormatter | ||||||||||||||||
} else if ( | ||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.