Skip to content

Commit dd9c7e1

Browse files
authored
Make @parcel/watcher optional (dotansimha#9506)
1 parent a509268 commit dd9c7e1

File tree

8 files changed

+136
-3
lines changed

8 files changed

+136
-3
lines changed

.changeset/five-spies-impress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/cli': major
3+
---
4+
5+
Make @parcel/watcher optional

packages/graphql-codegen-cli/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"@graphql-tools/prisma-loader": "^8.0.0",
5656
"@graphql-tools/url-loader": "^8.0.0",
5757
"@graphql-tools/utils": "^10.0.0",
58-
"@parcel/watcher": "^2.1.0",
5958
"@whatwg-node/fetch": "^0.8.0",
6059
"chalk": "^4.1.0",
6160
"cosmiconfig": "^8.1.3",
@@ -78,6 +77,7 @@
7877
},
7978
"devDependencies": {
8079
"@graphql-tools/merge": "9.0.0",
80+
"@parcel/watcher": "^2.1.0",
8181
"@types/debounce": "1.2.1",
8282
"@types/inquirer": "8.2.6",
8383
"@types/is-glob": "4.0.2",
@@ -92,8 +92,14 @@
9292
"prettier": "2.8.8"
9393
},
9494
"peerDependencies": {
95+
"@parcel/watcher": "^2.1.0",
9596
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
9697
},
98+
"peerDependenciesMeta": {
99+
"@parcel/watcher": {
100+
"optional": true
101+
}
102+
},
97103
"main": "dist/cjs/index.js",
98104
"module": "dist/esm/index.js",
99105
"exports": {

packages/graphql-codegen-cli/src/utils/watcher.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ export const createWatcher = (
6060
const runWatcher = async (abortSignal: AbortSignal) => {
6161
const watchDirectory = await findHighestCommonDirectory(allAffirmativePatterns);
6262

63-
const parcelWatcher = await import('@parcel/watcher');
63+
// Try to load the parcel watcher, but don't fail if it's not available.
64+
let parcelWatcher: typeof import('@parcel/watcher');
65+
try {
66+
parcelWatcher = await import('@parcel/watcher');
67+
} catch (err) {
68+
log(
69+
`Parcel watcher not found. To use this feature, please make sure to provide @parcel/watcher as a peer dependency.`
70+
);
71+
return;
72+
}
73+
6474
debugLog(`[Watcher] Parcel watcher loaded...`);
6575

6676
let isShutdown = false;

website/route-lockfile.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
/docs/integrations/vscode
5858
/docs/migration/from-0-13
5959
/docs/migration/from-0-18
60+
/docs/migration/from-4-0
6061
/docs/plugins -> /plugins
6162
/docs/plugins/c-sharp -> /plugins/c-sharp/c-sharp-operations
6263
/docs/plugins/client-note -> /plugins

website/src/pages/docs/getting-started/development-workflow.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
description: How to integrate GraphQL Code Generator into your development workflow. Learn how to run it in watch mode, or as part of your CI flow.
33
---
44

5+
import { Callout } from '@theguild/components'
6+
57
# Development workflow
68

79
GraphQL Code Generator should be integrated as part of your development workflow.
@@ -28,6 +30,13 @@ It's also helpful to run the codegen during your continuous integration flow and
2830

2931
## Watch Mode
3032

33+
<Callout type="info">
34+
Watch mode was made optional to reduce install size in CI and prevent build errors in certain environments.
35+
36+
To use watch mode, make sure to provide `@parcel/watcher` as a peer dependency.
37+
38+
</Callout>
39+
3140
If you wish to run the codegen in watch mode, you can specify `--watch` (or `-w`) when running it.
3241

3342
You can either run it in a separate terminal session or use tools like [`concurrently`](https://npmjs.com/package/concurrently) to run two scripts at the same time:

website/src/pages/docs/getting-started/installation.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ npm i graphql
1414
npm i -D typescript @graphql-codegen/cli
1515
```
1616

17+
If you want [watch mode](/docs/getting-started/development-workflow#watch-mode) support you need to add `@parcel/watcher` as well:
18+
19+
```sh npm2yarn
20+
npm i -D @parcel/watcher
21+
```
22+
1723
## Global Installation
1824

1925
<Callout type="warning">
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"graphql-cli": "GraphQL-CLI Deprecation",
33
"from-0-18": "v0.18 -> v1.0",
4-
"from-0-13": "v0.13 -> v0.17"
4+
"from-0-13": "v0.13 -> v0.17",
5+
"from-4-0": "v4.0 -> v5.0"
56
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
description: Migrating to 5.0.0. What has changed? How to migrate? What are the new features?
3+
---
4+
5+
import { Tabs, Tab } from '@theguild/components'
6+
7+
# Migration to 5.0.0
8+
9+
## What has changed?
10+
11+
There was an outstanding issue with `@parcel/watcher` which prevented it to be installed in certain environments, or needed an extra amount of dependencies to be built.
12+
This release focuses on improving the usage of `@graphql-codegen/cli` in those environments by making it an optional peer dependency.
13+
NPM (or Yarn) will not emit errors when an optional peer dependency is missing.
14+
15+
## How to migrate?
16+
17+
To use `@graphql-codegen/cli`'s watch mode (based on @parcel/watcher) you need to provide it in a package that uses `@graphql-codegen/cli` from now on.
18+
19+
Start by updating your package.json
20+
21+
<Tabs items={['Before', 'After']}>
22+
<Tab>
23+
```json filename="package.json"
24+
{
25+
"devDependencies": {
26+
"@graphql-codegen/cli": "^1.0.0",
27+
"@graphql-codegen/typescript": "^1.0.0",
28+
"@graphql-codegen/typescript-operations": "^1.0.0"
29+
}
30+
}
31+
```
32+
</Tab>
33+
34+
<Tab>
35+
```json filename="package.json"
36+
{
37+
"devDependencies": {
38+
"@graphql-codegen/cli": "^1.0.0",
39+
"@graphql-codegen/typescript": "^1.0.0",
40+
"@graphql-codegen/typescript-operations": "^1.0.0",
41+
"@parcel/watcher": "^2.1.0"
42+
}
43+
}
44+
```
45+
</Tab>
46+
</Tabs>
47+
48+
If you had issues with `@parcel/watcher` previously, you can make NPM and Yarn silently discard any build errors, by using `optionalDependencies` instead:
49+
50+
<Tabs items={['Before', 'After', 'After (Alternative)']}>
51+
<Tab>
52+
```json filename="package.json"
53+
{
54+
"devDependencies": {
55+
"@graphql-codegen/cli": "^1.0.0",
56+
"@graphql-codegen/typescript": "^1.0.0",
57+
"@graphql-codegen/typescript-operations": "^1.0.0"
58+
}
59+
}
60+
```
61+
</Tab>
62+
63+
<Tab>
64+
```json filename="package.json"
65+
{
66+
"devDependencies": {
67+
"@graphql-codegen/cli": "^1.0.0",
68+
"@graphql-codegen/typescript": "^1.0.0",
69+
"@graphql-codegen/typescript-operations": "^1.0.0"
70+
},
71+
"optionalDependencies": {
72+
"@parcel/watcher": "^2.1.0"
73+
}
74+
}
75+
```
76+
</Tab>
77+
78+
<Tab>
79+
```json filename="package.json"
80+
{
81+
"devDependencies": {
82+
"@graphql-codegen/cli": "^1.0.0",
83+
"@graphql-codegen/typescript": "^1.0.0",
84+
"@graphql-codegen/typescript-operations": "^1.0.0",
85+
"@parcel/watcher": "^2.1.0"
86+
},
87+
"dependenciesMeta": {
88+
"@parcel/watcher": {
89+
"optional": true
90+
}
91+
}
92+
}
93+
```
94+
</Tab>
95+
</Tabs>

0 commit comments

Comments
 (0)