-
-
Notifications
You must be signed in to change notification settings - Fork 19
feat(cli): Support prettier.config.mjs when calling prettify #999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for cedarjs canceled.
|
Greptile SummaryThis PR adds support for Confidence Score: 1/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller as Generate Command
participant Generate as generateTemplate()
participant Prettify as prettify()
participant Prettier as getPrettierOptions()
participant FS as fs/import
Caller->>Generate: call generateTemplate(file, params)
Note over Generate: Now returns Promise<br/>(was async)
Generate->>Prettify: return prettify() [Promise]
Caller->>Caller: ERROR: Expected string,<br/>got Promise!
alt Original Async Flow
Caller->>Generate: await generateTemplate()
Generate->>Prettify: await prettify()
Prettify->>Prettier: await getPrettierOptions()
Prettier->>FS: fs.existsSync(cjsPath)
Prettier->>FS: fs.existsSync(mjsPath)
FS-->>Prettier: return path
Prettier->>FS: import(prettierConfigPath)
FS-->>Prettier: return config
Prettier-->>Prettify: return options
Prettify->>FS: format(content, options)
FS-->>Prettify: return formatted
Prettify-->>Generate: return formatted
Generate-->>Caller: return formatted string
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 1 comment
| export const generateTemplate = (templateFilename, { name, ...rest }) => { | ||
| try { | ||
| const templateFn = template(readFile(templateFilename).toString()) | ||
|
|
||
| const renderedTemplate = templateFn({ | ||
| name, | ||
| ...nameVariants(name), | ||
| ...rest, | ||
| }) | ||
|
|
||
| return prettify(templateFilename, renderedTemplate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The function signature was changed from async to non-async, but prettify returns a Promise. This breaks the function's return value - callers expecting a formatted string will now receive a Promise instead. This is a breaking change that will cause runtime errors in any code calling generateTemplate and expecting a string result.
All callers of generateTemplate need to handle it as an async function.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cli/src/lib/index.js
Line: 61:70
Comment:
**logic:** The function signature was changed from `async` to non-async, but `prettify` returns a Promise. This breaks the function's return value - callers expecting a formatted string will now receive a Promise instead. This is a breaking change that will cause runtime errors in any code calling `generateTemplate` and expecting a string result.
All callers of `generateTemplate` need to handle it as an async function.
How can I resolve this? If you propose a fix, please make it concise.
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx run-many -t test --minWorkers=1 --maxWorkers=4 |
✅ Succeeded | 1m 54s | View ↗ |
nx run-many -t build:pack --exclude create-ceda... |
✅ Succeeded | 22s | View ↗ |
nx run-many -t build |
✅ Succeeded | 57s | View ↗ |
nx run-many -t test:types |
✅ Succeeded | 9s | View ↗ |
☁️ Nx Cloud last updated this comment at 2026-01-14 03:42:04 UTC
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx run-many -t build:pack --exclude create-ceda... |
✅ Succeeded | 14s | View ↗ |
nx run-many -t build |
✅ Succeeded | 40s | View ↗ |
☁️ Nx Cloud last updated this comment at 2026-01-14 03:27:52 UTC
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx run-many -t build |
✅ Succeeded | 52s | View ↗ |
nx run-many -t build:pack --exclude create-ceda... |
✅ Succeeded | 18s | View ↗ |
nx run-many -t test --minWorkers=1 --maxWorkers=4 |
✅ Succeeded | 1m 35s | View ↗ |
nx run-many -t test:types |
✅ Succeeded | 6s | View ↗ |
☁️ Nx Cloud last updated this comment at 2026-01-14 03:30:51 UTC
|
@greptileai you said:
If all callers already do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right! I made an error in my analysis. If all callers are already using await generateTemplate(...), then removing the async keyword is actually safe.
Here's why:
generateTemplatestill returns a Promise (from theprettify()call)awaitworks on any Promise, whether the function is declaredasyncor not- The callers will still get the resolved value (string) instead of a Promise object
The async keyword was unnecessary since the function doesn't use await internally - it just returns the Promise directly from prettify(). Removing it is actually a minor improvement, not a breaking change.
My apologies for the confusion in my original review. The PR is safe to merge as-is. The prettier config fallback feature works correctly and the generateTemplate change doesn't introduce any breaking functionality.

Code formatting was silently skipped when using the generators if a project had a .mjs prettier config file. This would lead to code full of red squiggles because of formatting "errors". This PR updates the formatting code to look for both .cjs and .mjs config files.