@secretlint/formatter
Advanced tools
Comparing version 8.3.2 to 8.3.3
@@ -1,10 +0,7 @@ | ||
import { loadFormatter as textlintCreateFormatter, getFormatterList as textlintGetFormatterList, } from "@textlint/linter-formatter"; | ||
import { getFormatterList as textlintGetFormatterList, loadFormatter as textlintCreateFormatter, } from "@textlint/linter-formatter"; | ||
import terminalLink from "terminal-link"; | ||
import { moduleInterop } from "@textlint/module-interop"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
// @ts-expect-error: no @types | ||
import tryResolve from "try-resolve"; | ||
import debug0 from "debug"; | ||
import url from "node:url"; | ||
import { dynamicImport, tryResolve } from "@secretlint/resolver"; | ||
import jsonFormatter from "./formatters/json.js"; | ||
@@ -15,2 +12,8 @@ import maskResultFormatter from "./formatters/mask-result.js"; | ||
const debug = debug0("@secretlint/formatter"); | ||
const tryResolveModule = (moduleName) => { | ||
return tryResolve(moduleName, { | ||
parentImportMeta: import.meta, | ||
parentModule: "formatter", | ||
}); | ||
}; | ||
/** | ||
@@ -129,3 +132,3 @@ * Convert secretlint result to textlint result for formatter | ||
else { | ||
const pkgPath = tryResolve(formatterName) || tryResolve(`secretlint-formatter-${formatterName}`); | ||
const pkgPath = tryResolveModule(formatterName) || tryResolveModule(`secretlint-formatter-${formatterName}`); | ||
if (pkgPath) { | ||
@@ -135,6 +138,11 @@ formatterPath = pkgPath; | ||
} | ||
if (!formatterPath) { | ||
throw new Error(`Could not find formatter ${formatterName}`); | ||
} | ||
try { | ||
// dynamic import require file url | ||
const fileUrl = url.pathToFileURL(formatterPath).href; | ||
formatter = moduleInterop(await import(fileUrl)).default; | ||
formatter = (await dynamicImport(formatterPath, { | ||
parentImportMeta: import.meta, | ||
parentModule: "formatter", | ||
})).exports.default; | ||
} | ||
@@ -141,0 +149,0 @@ catch (ex) { |
{ | ||
"name": "@secretlint/formatter", | ||
"version": "8.3.2", | ||
"version": "8.3.3", | ||
"description": "A formatter collection for Secretlint.", | ||
@@ -57,3 +57,4 @@ "homepage": "https://github.com/secretlint/secretlint/tree/master/packages/@secretlint/formatter/", | ||
"dependencies": { | ||
"@secretlint/types": "^8.3.2", | ||
"@secretlint/resolver": "^8.3.3", | ||
"@secretlint/types": "^8.3.3", | ||
"@textlint/linter-formatter": "^14.2.1", | ||
@@ -88,3 +89,3 @@ "@textlint/module-interop": "^14.2.1", | ||
}, | ||
"gitHead": "97ebb453fa3dc82454dcbb29fb2e4a14194c6f97" | ||
"gitHead": "f5b6e6d2ce95d31d8161fc71d0b692ccbacb7c21" | ||
} |
// LICENSE : MIT | ||
import { TextlintResult } from "@textlint/types"; | ||
import { | ||
getFormatterList as textlintGetFormatterList, | ||
loadFormatter as textlintCreateFormatter, | ||
getFormatterList as textlintGetFormatterList, | ||
} from "@textlint/linter-formatter"; | ||
@@ -10,10 +10,6 @@ import { SecretLintCoreResult } from "@secretlint/types"; | ||
import { FormatterConfig } from "./types.js"; | ||
import { moduleInterop } from "@textlint/module-interop"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
// @ts-expect-error: no @types | ||
import tryResolve from "try-resolve"; | ||
import debug0 from "debug"; | ||
import url from "node:url"; | ||
import { dynamicImport, tryResolve } from "@secretlint/resolver"; | ||
import jsonFormatter from "./formatters/json.js"; | ||
@@ -25,2 +21,9 @@ import maskResultFormatter from "./formatters/mask-result.js"; | ||
const debug = debug0("@secretlint/formatter"); | ||
const tryResolveModule = (moduleName: string) => { | ||
return tryResolve(moduleName, { | ||
parentImportMeta: import.meta, | ||
parentModule: "formatter", | ||
}); | ||
}; | ||
type Formatter = (results: SecretLintCoreResult[], formatterConfig: FormatterConfig) => string; | ||
@@ -161,3 +164,3 @@ export interface SecretLintFormatterConfig { | ||
} | ||
let formatter: (results: SecretLintCoreResult[], formatterConfig: FormatterConfig) => string; | ||
let formatter: Formatter; | ||
let formatterPath; | ||
@@ -169,3 +172,3 @@ if (fs.existsSync(formatterName)) { | ||
} else { | ||
const pkgPath = tryResolve(formatterName) || tryResolve(`secretlint-formatter-${formatterName}`); | ||
const pkgPath = tryResolveModule(formatterName) || tryResolveModule(`secretlint-formatter-${formatterName}`); | ||
if (pkgPath) { | ||
@@ -175,6 +178,17 @@ formatterPath = pkgPath; | ||
} | ||
if (!formatterPath) { | ||
throw new Error(`Could not find formatter ${formatterName}`); | ||
} | ||
try { | ||
// dynamic import require file url | ||
const fileUrl = url.pathToFileURL(formatterPath).href; | ||
formatter = moduleInterop(await import(fileUrl)).default; | ||
formatter = ( | ||
( | ||
await dynamicImport(formatterPath, { | ||
parentImportMeta: import.meta, | ||
parentModule: "formatter", | ||
}) | ||
).exports as { | ||
default: Formatter; | ||
} | ||
).default; | ||
} catch (ex) { | ||
@@ -181,0 +195,0 @@ throw new Error(`Could not find formatter ${formatterName} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
41901
755
12
+ Added@secretlint/resolver@^8.3.3
+ Added@secretlint/resolver@8.5.0(transitive)
Updated@secretlint/types@^8.3.3