Skip to content

Commit

Permalink
Try loading formatter by relative dir then by name
Browse files Browse the repository at this point in the history
This commit makes it possible to load a custom formatter that is
not relative to the current working directory, such as one installed
globally, or via Yarn PNP.
  • Loading branch information
dawn-minion committed Aug 26, 2020
1 parent fef94dd commit 6d01071
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/formatter/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,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

try {
const fullCustomFormatterPath = path.resolve(cwd, customFormatterPath)
CustomFormatter = require(fullCustomFormatterPath) // eslint-disable-line @typescript-eslint/no-var-requires
} catch {
CustomFormatter = require(customFormatterPath) // eslint-disable-line @typescript-eslint/no-var-requires
}

if (typeof CustomFormatter === 'function') {
return CustomFormatter
} else if (
Expand Down

0 comments on commit 6d01071

Please sign in to comment.