diff --git a/.eslintignore b/.eslintignore index e9d5176..b561b46 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,4 +3,5 @@ coverage lib node_modules pnpm-lock.yaml -src/tests/vendor \ No newline at end of file +src/tests/vendor +src/formatDTS.ts \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ab2200..4faeb85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### 1.0.2 + +- Better prettier detection (and fallback) for the generated files, re #14 + ### 1.0 - No changes diff --git a/package.json b/package.json index a91ad53..f82259d 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "format": "prettier \"**/*\" --ignore-unknown", "format:write": "pnpm format --write", "jest": "vitest", - "lint": "eslint . --max-warnings 0 --report-unused-disable-directives", + "lint": "eslint . --report-unused-disable-directives", "lint:knip": "knip", "lint:md": "markdownlint \"**/*.md\" \".github/**/*.md\" --rules sentences-per-line", "lint:package": "npmPkgJsonLint .", @@ -35,7 +35,7 @@ }, "lint-staged": { "*": "prettier --ignore-unknown --write", - "*.ts": "eslint --fix --max-warnings 0" + "*.ts": "eslint --fix" }, "dependencies": { "@mrleebo/prisma-ast": "^0.12.0", diff --git a/src/formatDTS.ts b/src/formatDTS.ts index 0fc5854..1270767 100644 --- a/src/formatDTS.ts +++ b/src/formatDTS.ts @@ -1,9 +1,7 @@ // https://prettier.io/docs/en/api.html -// eslint-disable-next-line @typescript-eslint/no-explicit-any let prettier: any | null = null try { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment prettier = await import("prettier") } catch (er) { console.error(er) @@ -11,16 +9,18 @@ try { } export const getPrettierConfig = (path: string): unknown => { - if (!prettier) return {} + if (!prettier?.default?.resolveConfig) return {} + if (typeof prettier.default.resolveConfig !== "function") return {} - // I confirmed that this lookup hits caches in Redwood - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + // I confirmed that this lookup hits caches in RedwoodJS const opts = prettier.default.resolveConfig.sync(path) ?? {} return opts } export const formatDTS = (path: string, content: string, config: unknown): string => { - if (!prettier) return content + if (!prettier?.default?.format) return content + if (typeof prettier.default.format !== "function") return content + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call return prettier.default.format(content, { ...(config as object), filepath: path }) as string } diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index be9d37b..a28e8b5 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -1,5 +1,5 @@ { - "extends": "./tsconfig.json", "exclude": ["src/tests/vendor"], + "extends": "./tsconfig.json", "include": [".", "src/tests/**/*"] }