Skip to content

Commit 6f34164

Browse files
committed
feat(prettier) upgrade to prettier v3 (#10179)
Second attempt of #9077 now that Jest tests are holding us back thanks to @Josh-Walker-GM! 🚀 I've also included the changes in #9078. I'm pretty sure this isn't breaking but will be more thorough after CI passes.
1 parent d2eddd3 commit 6f34164

File tree

49 files changed

+463
-278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+463
-278
lines changed

.changesets/10179.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
- feat(prettier) upgrade to prettier v3 (#10179) by @jtoar
2+
3+
This PR upgrades Redwood internally to Prettier v3. We believe this won't have any downstream effect for users.
4+
5+
If you have Tailwind CSS configured, can upgrade `prettier-plugin-tailwindcss` to a version later than `0.4.1` if you make a few changes:
6+
7+
- Change `prettier.config.js` to `prettier.config.mjs` (js -> mjs)
8+
- `export default` instead of `module.exports`
9+
- `await import('...')` any plugins instead of `require('...')`
10+
11+
Here's an example of an updated `prettier.config.mjs` to work with `prettier-plugin-tailwindcss@^0.5.12`:
12+
13+
```js
14+
// prettier.config.mjs
15+
16+
export default {
17+
trailingComma: 'es5',
18+
bracketSpacing: true,
19+
tabWidth: 2,
20+
semi: false,
21+
singleQuote: true,
22+
arrowParens: 'always',
23+
overrides: [
24+
{
25+
files: 'Routes.*',
26+
options: {
27+
printWidth: 999,
28+
},
29+
},
30+
],
31+
tailwindConfig: './web/config/tailwind.config.js',
32+
plugins: [await import('prettier-plugin-tailwindcss')],
33+
}
34+
```

packages/cli-helpers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"listr2": "6.6.1",
3939
"lodash": "4.17.21",
4040
"pascalcase": "1.0.0",
41-
"prettier": "2.8.8",
41+
"prettier": "3.2.5",
4242
"prompts": "2.4.2",
4343
"terminal-link": "2.1.1"
4444
},

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"pascalcase": "1.0.0",
7373
"pluralize": "8.0.0",
7474
"portfinder": "1.0.32",
75-
"prettier": "2.8.8",
75+
"prettier": "3.2.5",
7676
"prisma": "5.10.2",
7777
"prompts": "2.4.2",
7878
"rimraf": "5.0.5",

packages/cli/src/commands/generate/cell/__tests__/__snapshots__/cell.test.js.snap

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -887,16 +887,14 @@ import type {
887887
TypedDocumentNode,
888888
} from '@redwoodjs/web'
889889
890-
export const QUERY: TypedDocumentNode<
891-
MembersQuery,
892-
MembersQueryVariables
893-
> = gql\`
894-
query MembersQuery {
895-
members {
896-
id
890+
export const QUERY: TypedDocumentNode<MembersQuery, MembersQueryVariables> =
891+
gql\`
892+
query MembersQuery {
893+
members {
894+
id
895+
}
897896
}
898-
}
899-
\`
897+
\`
900898
901899
export const Loading = () => <div>Loading...</div>
902900

packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffold.test.js.snap

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,28 +2233,26 @@ import type {
22332233

22342234
import Post from 'src/components/Post/Post'
22352235

2236-
export const QUERY: TypedDocumentNode<
2237-
FindPostById,
2238-
FindPostByIdVariables
2239-
> = gql\`
2240-
query FindPostById($id: Int!) {
2241-
post: post(id: $id) {
2242-
id
2243-
title
2244-
slug
2245-
author
2246-
body
2247-
image
2248-
postedAt
2249-
isPinned
2250-
readTime
2251-
rating
2252-
upvotes
2253-
metadata
2254-
hugeNumber
2236+
export const QUERY: TypedDocumentNode<FindPostById, FindPostByIdVariables> =
2237+
gql\`
2238+
query FindPostById($id: Int!) {
2239+
post: post(id: $id) {
2240+
id
2241+
title
2242+
slug
2243+
author
2244+
body
2245+
image
2246+
postedAt
2247+
isPinned
2248+
readTime
2249+
rating
2250+
upvotes
2251+
metadata
2252+
hugeNumber
2253+
}
22552254
}
2256-
}
2257-
\`
2255+
\`
22582256

22592257
export const Loading = () => <div>Loading...</div>
22602258

packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffoldNoNest.test.js.snap

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,28 +1618,26 @@ import type {
16181618

16191619
import Post from 'src/components/Post'
16201620

1621-
export const QUERY: TypedDocumentNode<
1622-
FindPostById,
1623-
FindPostByIdVariables
1624-
> = gql\`
1625-
query FindPostById($id: Int!) {
1626-
post: post(id: $id) {
1627-
id
1628-
title
1629-
slug
1630-
author
1631-
body
1632-
image
1633-
postedAt
1634-
isPinned
1635-
readTime
1636-
rating
1637-
upvotes
1638-
metadata
1639-
hugeNumber
1621+
export const QUERY: TypedDocumentNode<FindPostById, FindPostByIdVariables> =
1622+
gql\`
1623+
query FindPostById($id: Int!) {
1624+
post: post(id: $id) {
1625+
id
1626+
title
1627+
slug
1628+
author
1629+
body
1630+
image
1631+
postedAt
1632+
isPinned
1633+
readTime
1634+
rating
1635+
upvotes
1636+
metadata
1637+
hugeNumber
1638+
}
16401639
}
1641-
}
1642-
\`
1640+
\`
16431641

16441642
export const Loading = () => <div>Loading...</div>
16451643

packages/cli/src/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function handler({ force }: { force: boolean }) {
6464

6565
const prettierOptions = await getPrettierOptions()
6666

67-
const prettifiedApp = format(source, {
67+
const prettifiedApp = await format(source, {
6868
...prettierOptions,
6969
parser: 'babel-ts',
7070
})

packages/cli/src/commands/setup/ui/libraries/tailwindcss.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const handler = async ({ force, install }) => {
115115
})
116116
const rwPaths = getPaths()
117117

118-
const projectPackages = ['prettier-plugin-tailwindcss@0.4.1']
118+
const projectPackages = ['prettier-plugin-tailwindcss']
119119

120120
const webWorkspacePackages = [
121121
'postcss',

packages/cli/src/lib/__tests__/mergeBasics.test.js

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import { concatUnique } from '../merge/strategy'
55

66
import { unindented } from './fixtures/unindented'
77

8-
const expectMerged = (base, ext, merged, strategy = {}) => {
9-
expect(merge(unindented(base), unindented(ext), strategy)).toBe(
8+
const expectMerged = async (base, ext, merged, strategy = {}) => {
9+
expect(await merge(unindented(base), unindented(ext), strategy)).toBe(
1010
unindented(merged)
1111
)
1212
}
1313

14-
const expectTrivialConcat = (base, ext, strategy = {}) => {
14+
const expectTrivialConcat = async (base, ext, strategy = {}) => {
1515
const ubase = unindented(base)
1616
const uext = unindented(ext)
17-
expect(merge(ubase, uext, strategy)).toBe(`${ubase}\n${uext}\n`)
17+
expect(await merge(ubase, uext, strategy)).toBe(`${ubase}\n${uext}\n`)
1818
}
1919

2020
describe('the basics', () => {
21-
it('Inserts extension declarations in the last possible position', () => {
21+
it('Inserts extension declarations in the last possible position', async () => {
2222
// Notice how 'y' is reordered above 'list' to ensure its reference in 'list' is valid.
23-
expectMerged(
23+
await expectMerged(
2424
`\
2525
const x = 'x'
2626
const list = [x]
@@ -37,20 +37,20 @@ describe('the basics', () => {
3737
{ ArrayExpression: concatUnique }
3838
)
3939
})
40-
it('Merges JSX strings', () => {
40+
it('Merges JSX strings', async () => {
4141
const componentA = 'const ComponentA = (props) => <div>Hello</div>'
4242
const componentB = 'const ComponentB = (props) => <div>Bye</div>'
43-
expectTrivialConcat(componentA, componentB)
43+
await expectTrivialConcat(componentA, componentB)
4444
})
45-
it('Merges TSX strings', () => {
45+
it('Merges TSX strings', async () => {
4646
const componentA =
4747
'const ComponentA: MyComponent = (props) => <div>Hello</div>'
4848
const componentB =
4949
'const ComponentB: MyComponent = (props) => <div>Bye</div>'
50-
expectTrivialConcat(componentA, componentB)
50+
await expectTrivialConcat(componentA, componentB)
5151
})
52-
it('Merges TS strings', () => {
53-
expectMerged(
52+
it('Merges TS strings', async () => {
53+
await expectMerged(
5454
`\
5555
const x: string = 'x'
5656
const list: string[] = [x]
@@ -70,108 +70,117 @@ describe('the basics', () => {
7070
})
7171

7272
describe('Import behavior', () => {
73-
it('keeps both identical namespace imports', () => {
74-
expectTrivialConcat(
73+
it('keeps both identical namespace imports', async () => {
74+
await expectTrivialConcat(
7575
"import * as React from 'react'",
7676
"import * as React from 'react'"
7777
)
7878
})
7979

80-
it('keeps both identical specifier imports', () => {
81-
expectTrivialConcat(
80+
it('keeps both identical specifier imports', async () => {
81+
await expectTrivialConcat(
8282
"import { foo } from 'source'",
8383
"import { foo } from 'source'"
8484
)
8585
})
8686

87-
it('keeps both differing import specifiers in separate imports', () => {
88-
expectTrivialConcat(
87+
it('keeps both differing import specifiers in separate imports', async () => {
88+
await expectTrivialConcat(
8989
"import { bar } from 'source'",
9090
"import { foo } from 'source'"
9191
)
9292
})
9393

94-
it('keeps both differing sets of import specifiers, even with an overlap.', () => {
95-
expectTrivialConcat(
94+
it('keeps both differing sets of import specifiers, even with an overlap.', async () => {
95+
await expectTrivialConcat(
9696
"import { foo, bar } from 'source'",
9797
"import { bar, baz } from 'source'"
9898
)
9999
})
100100

101-
it('keeps both default and specifier imports', () => {
102-
expectTrivialConcat(
101+
it('keeps both default and specifier imports', async () => {
102+
await expectTrivialConcat(
103103
"import def from 'source'",
104104
"import { foo } from 'source'"
105105
)
106106
})
107107

108-
it('keeps both default + specifier and specifier imports', () => {
109-
expectTrivialConcat(
108+
it('keeps both default + specifier and specifier imports', async () => {
109+
await expectTrivialConcat(
110110
"import def, { foo } from 'source'",
111111
"import { bar } from 'source'"
112112
)
113113
})
114114

115-
it('keeps both specifier and default imports', () => {
116-
expectTrivialConcat(
115+
it('keeps both specifier and default imports', async () => {
116+
await expectTrivialConcat(
117117
"import { foo } from 'source'",
118118
"import def from 'source'"
119119
)
120120
})
121121

122-
it('does not merge import namespace identifiers with conflicting local names', () => {
123-
expectTrivialConcat(
122+
it('does not merge import namespace identifiers with conflicting local names', async () => {
123+
await expectTrivialConcat(
124124
"import * as One from 'source'",
125125
"import * as Two from 'source'"
126126
)
127127
})
128128

129-
it('does not merge default specifiers with conflicting local names', () => {
130-
expectTrivialConcat("import One from 'source'", "import Two from 'source'")
129+
it('does not merge default specifiers with conflicting local names', async () => {
130+
await expectTrivialConcat(
131+
"import One from 'source'",
132+
"import Two from 'source'"
133+
)
131134
})
132135

133-
it('does not merge side-effect imports and default imports', () => {
134-
expectTrivialConcat("import 'source'", "import Def from 'source'")
136+
it('does not merge side-effect imports and default imports', async () => {
137+
await expectTrivialConcat("import 'source'", "import Def from 'source'")
135138
})
136139

137-
it('does not merge side-effect imports and namespace imports', () => {
138-
expectTrivialConcat("import 'source'", "import * as Name from 'source'")
140+
it('does not merge side-effect imports and namespace imports', async () => {
141+
await expectTrivialConcat(
142+
"import 'source'",
143+
"import * as Name from 'source'"
144+
)
139145
})
140146

141-
it('does not merge side-effect imports import specifiers', () => {
142-
expectTrivialConcat("import 'source'", "import { foo, bar } from 'source'")
147+
it('does not merge side-effect imports import specifiers', async () => {
148+
await expectTrivialConcat(
149+
"import 'source'",
150+
"import { foo, bar } from 'source'"
151+
)
143152
})
144153

145-
it('Does not merge side-effect imports with other import types', () => {
146-
expectTrivialConcat(
154+
it('Does not merge side-effect imports with other import types', async () => {
155+
await expectTrivialConcat(
147156
"import def, { foo, bar } from 'source'",
148157
"import 'source'"
149158
)
150159
})
151160

152-
it('keeps both import default specifiers and import namespace identifiers', () => {
153-
expectTrivialConcat(
161+
it('keeps both import default specifiers and import namespace identifiers', async () => {
162+
await expectTrivialConcat(
154163
"import src from 'source'",
155164
"import * as Source from 'source'"
156165
)
157166
})
158167

159-
it('keeps all imports with the same source', () => {
160-
expectTrivialConcat(
168+
it('keeps all imports with the same source', async () => {
169+
await expectTrivialConcat(
161170
"import { foo } from 'source'",
162171
"import { bar } from 'source'\nimport { baz } from 'source'"
163172
)
164173
})
165174

166-
it('keeps multiple default imports with the same source', () => {
167-
expectTrivialConcat(
175+
it('keeps multiple default imports with the same source', async () => {
176+
await expectTrivialConcat(
168177
"import default1 from 'source'",
169178
"import default2 from 'source'\nimport { foo } from 'source'"
170179
)
171180
})
172181

173-
it('keeps multiple types of imports with the same source', () => {
174-
expectTrivialConcat(
182+
it('keeps multiple types of imports with the same source', async () => {
183+
await expectTrivialConcat(
175184
"import default1 from 'source'\nimport * as namespace from 'source'",
176185
"import default2 from 'source'\nimport { foo } from 'source'"
177186
)

0 commit comments

Comments
 (0)