Skip to content

Commit 10ce0fb

Browse files
authored
fix: formatting with prettier not working in non skeleton repos (#3512)
### WHY are these changes introduced? Since we moved to `pnpm` prettier has been silently failing in code changes that are not the skeleton: because `npm` used to hoist the `@shopify/prettier-config` package from skeleton to the root of the monorepo, we were able to run it in other places. Oh and we were not checking or formatting the skeleton template! ### WHAT is this pull request doing? - adding `@shopify/prettier-config` at the root package.json - standardised version with `catalog:` - added `./templates` to formating and checks ### HOW to test your changes? - change the formatting a file outside skeleton (like a test) - format it - check output of prettier if you are on vscode and use the extension to ensure it loaded it all good #### Checklist - [x] I've read the [Contributing Guidelines](https://github.com/Shopify/hydrogen/blob/main/CONTRIBUTING.md) - [x] I've considered possible cross-platform impacts (Mac, Linux, Windows) - I've added a [changeset](https://github.com/Shopify/hydrogen/blob/main/CONTRIBUTING.md#changesets) if this PR contains user-facing or noteworthy changes - I've added [tests](https://github.com/Shopify/hydrogen/blob/main/CONTRIBUTING.md#testing) to cover my changes - I've added or updated the documentation <!-- THANK YOU for your pull request! Members from the Hydrogen team will review these changes and provide feedback as soon as they are available. -->
1 parent 676d40c commit 10ce0fb

17 files changed

+52
-74
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"encrypt": "ejson encrypt secrets.ejson",
2020
"lint": "eslint --no-error-on-unmatched-pattern ./packages",
2121
"lint-staged": "eslint --no-error-on-unmatched-pattern",
22-
"format": "prettier --write --ignore-unknown ./packages",
23-
"format:check": "prettier --check --ignore-unknown ./packages",
22+
"format": "prettier --write --ignore-unknown ./packages ./templates",
23+
"format:check": "prettier --check --ignore-unknown ./packages ./templates",
2424
"typecheck": "turbo typecheck --parallel",
2525
"test": "turbo run test --parallel",
2626
"test:watch": "turbo run test:watch",
@@ -106,7 +106,8 @@
106106
"tiny-invariant": "^1.3.3",
107107
"tsup": "^8.4.0",
108108
"turbo": "2.8.9",
109-
"typescript": "5.9.2"
109+
"typescript": "5.9.2",
110+
"@shopify/prettier-config": "catalog:"
110111
},
111112
"engines": {
112113
"node": "^22 || ^24",

pnpm-lock.yaml

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ catalog:
2424
'@types/react-dom': '^18.3.7'
2525
react: '^18.3.1'
2626
react-dom: '^18.3.1'
27+
'@shopify/prettier-config': '^1.1.2'

templates/skeleton/app/entry.client.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import {NonceProvider} from '@shopify/hydrogen';
66
if (!window.location.origin.includes('webcache.googleusercontent.com')) {
77
startTransition(() => {
88
// Extract nonce from existing script tags
9-
const existingNonce = document
10-
.querySelector<HTMLScriptElement>('script[nonce]')
11-
?.nonce;
9+
const existingNonce =
10+
document.querySelector<HTMLScriptElement>('script[nonce]')?.nonce;
1211

1312
hydrateRoot(
1413
document,

templates/skeleton/app/routes/account.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ export function shouldRevalidate() {
1414

1515
export async function loader({context}: Route.LoaderArgs) {
1616
const {customerAccount} = context;
17-
const {data, errors} = await customerAccount.query(
18-
CUSTOMER_DETAILS_QUERY,
19-
{
20-
variables: {
21-
language: customerAccount.i18n.language,
22-
},
17+
const {data, errors} = await customerAccount.query(CUSTOMER_DETAILS_QUERY, {
18+
variables: {
19+
language: customerAccount.i18n.language,
2320
},
24-
);
21+
});
2522

2623
if (errors?.length || !data?.customer) {
2724
throw new Error('Customer not found');

templates/skeleton/app/routes/blogs.$blogHandle._index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
Link,
3-
useLoaderData,
4-
} from 'react-router';
1+
import {Link, useLoaderData} from 'react-router';
52
import type {Route} from './+types/blogs.$blogHandle._index';
63
import {Image, getPaginationVariables} from '@shopify/hydrogen';
74
import type {ArticleItemFragment} from 'storefrontapi.generated';
@@ -26,11 +23,7 @@ export async function loader(args: Route.LoaderArgs) {
2623
* Load data necessary for rendering content above the fold. This is the critical data
2724
* needed to render the page. If it's unavailable, the whole page should 400 or 500 error.
2825
*/
29-
async function loadCriticalData({
30-
context,
31-
request,
32-
params,
33-
}: Route.LoaderArgs) {
26+
async function loadCriticalData({context, request, params}: Route.LoaderArgs) {
3427
const paginationVariables = getPaginationVariables(request, {
3528
pageBy: 4,
3629
});

templates/skeleton/app/routes/blogs._index.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
Link,
3-
useLoaderData,
4-
} from 'react-router';
1+
import {Link, useLoaderData} from 'react-router';
52
import type {Route} from './+types/blogs._index';
63
import {getPaginationVariables} from '@shopify/hydrogen';
74
import {PaginatedResourceSection} from '~/components/PaginatedResourceSection';

templates/skeleton/app/routes/cart.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
useLoaderData,
3-
data,
4-
type HeadersFunction,
5-
} from 'react-router';
1+
import {useLoaderData, data, type HeadersFunction} from 'react-router';
62
import type {Route} from './+types/cart';
73
import type {CartQueryDataReturn} from '@shopify/hydrogen';
84
import {CartForm} from '@shopify/hydrogen';

templates/skeleton/app/routes/collections.all.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type {Route} from './+types/collections.all';
2-
import {
3-
useLoaderData,
4-
} from 'react-router';
2+
import {useLoaderData} from 'react-router';
53
import {getPaginationVariables, Image, Money} from '@shopify/hydrogen';
64
import {PaginatedResourceSection} from '~/components/PaginatedResourceSection';
75
import {ProductItem} from '~/components/ProductItem';

templates/skeleton/app/routes/pages.$handle.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import {
2-
useLoaderData,
3-
} from 'react-router';
1+
import {useLoaderData} from 'react-router';
42
import type {Route} from './+types/pages.$handle';
53
import {redirectIfHandleIsLocalized} from '~/lib/redirect';
64

@@ -22,11 +20,7 @@ export async function loader(args: Route.LoaderArgs) {
2220
* Load data necessary for rendering content above the fold. This is the critical data
2321
* needed to render the page. If it's unavailable, the whole page should 400 or 500 error.
2422
*/
25-
async function loadCriticalData({
26-
context,
27-
request,
28-
params,
29-
}: Route.LoaderArgs) {
23+
async function loadCriticalData({context, request, params}: Route.LoaderArgs) {
3024
if (!params.handle) {
3125
throw new Error('Missing page handle');
3226
}

0 commit comments

Comments
 (0)