Skip to content

Commit

Permalink
Load formatter by rel path only if starts with .
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. If the path begins with a . it will be
loaded relative to the current directory.
  • Loading branch information
dawn-minion committed Oct 28, 2020
1 parent fef94dd commit ac93d12
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

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
}

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

0 comments on commit ac93d12

Please sign in to comment.