Skip to content
This repository was archived by the owner on Oct 26, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ coverage
lib
node_modules
pnpm-lock.yaml
src/tests/vendor
src/tests/vendor
src/formatDTS.ts
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 1.0.2

- Better prettier detection (and fallback) for the generated files, re #14

### 1.0

- No changes
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand All @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions src/formatDTS.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
// 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)
prettier = null
}

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
}
2 changes: 1 addition & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.json",
"exclude": ["src/tests/vendor"],
"extends": "./tsconfig.json",
"include": [".", "src/tests/**/*"]
}