From ac93d123070b11ab9017b035424d792663f3c440 Mon Sep 17 00:00:00 2001 From: Dawn Minion Date: Wed, 26 Aug 2020 09:57:49 +0200 Subject: [PATCH] Load formatter by rel path only if starts with . 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. --- src/formatter/builder.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/formatter/builder.ts b/src/formatter/builder.ts index 0800424920..fea1be62e9 100644 --- a/src/formatter/builder.ts +++ b/src/formatter/builder.ts @@ -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 (