From 317fd547094685d7dcd97f525b738b9bc6d63613 Mon Sep 17 00:00:00 2001 From: zanminkian Date: Sun, 24 Sep 2023 04:59:57 +0000 Subject: [PATCH] fix(prettier-config): fix crash when running `npx git-validator` --- .changeset/weak-plants-sell.md | 5 +++++ packages/prettier-config/index.js | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changeset/weak-plants-sell.md diff --git a/.changeset/weak-plants-sell.md b/.changeset/weak-plants-sell.md new file mode 100644 index 00000000..584a4dc6 --- /dev/null +++ b/.changeset/weak-plants-sell.md @@ -0,0 +1,5 @@ +--- +"@git-validator/prettier-config": patch +--- + +fix(prettier-config): fix crash when running `npx git-validator` diff --git a/packages/prettier-config/index.js b/packages/prettier-config/index.js index c0fcdeda..3c453bc5 100644 --- a/packages/prettier-config/index.js +++ b/packages/prettier-config/index.js @@ -1,8 +1,11 @@ // @ts-check import fs from "node:fs/promises"; +import { createRequire } from "node:module"; import path from "node:path"; import process from "node:process"; +const requireResolve = createRequire(import.meta.url).resolve; + const configFilePaths = ["js", "ts", "json"].map((i) => path.resolve(process.cwd(), `tailwind.config.${i}`), ); @@ -20,9 +23,9 @@ const tailwindConfig = configFilePaths[index]; export default { plugins: [ - "prettier-plugin-curly", - "prettier-plugin-packagejson", - ...(tailwindConfig ? ["prettier-plugin-tailwindcss"] : []), + requireResolve("prettier-plugin-curly"), + requireResolve("prettier-plugin-packagejson"), + ...(tailwindConfig ? [requireResolve("prettier-plugin-tailwindcss")] : []), ], ...(tailwindConfig ? { tailwindConfig } : {}), printWidth: 100, // 120 may be too long