Skip to content

Commit

Permalink
Make @parcel/watcher optional (#9506)
Browse files Browse the repository at this point in the history
  • Loading branch information
valkum authored Jul 7, 2023
1 parent a509268 commit dd9c7e1
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-spies-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/cli': major
---

Make @parcel/watcher optional
8 changes: 7 additions & 1 deletion packages/graphql-codegen-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"@graphql-tools/prisma-loader": "^8.0.0",
"@graphql-tools/url-loader": "^8.0.0",
"@graphql-tools/utils": "^10.0.0",
"@parcel/watcher": "^2.1.0",
"@whatwg-node/fetch": "^0.8.0",
"chalk": "^4.1.0",
"cosmiconfig": "^8.1.3",
Expand All @@ -78,6 +77,7 @@
},
"devDependencies": {
"@graphql-tools/merge": "9.0.0",
"@parcel/watcher": "^2.1.0",
"@types/debounce": "1.2.1",
"@types/inquirer": "8.2.6",
"@types/is-glob": "4.0.2",
Expand All @@ -92,8 +92,14 @@
"prettier": "2.8.8"
},
"peerDependencies": {
"@parcel/watcher": "^2.1.0",
"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"
},
"peerDependenciesMeta": {
"@parcel/watcher": {
"optional": true
}
},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
Expand Down
12 changes: 11 additions & 1 deletion packages/graphql-codegen-cli/src/utils/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@ export const createWatcher = (
const runWatcher = async (abortSignal: AbortSignal) => {
const watchDirectory = await findHighestCommonDirectory(allAffirmativePatterns);

const parcelWatcher = await import('@parcel/watcher');
// Try to load the parcel watcher, but don't fail if it's not available.
let parcelWatcher: typeof import('@parcel/watcher');
try {
parcelWatcher = await import('@parcel/watcher');
} catch (err) {
log(
`Parcel watcher not found. To use this feature, please make sure to provide @parcel/watcher as a peer dependency.`
);
return;
}

debugLog(`[Watcher] Parcel watcher loaded...`);

let isShutdown = false;
Expand Down
1 change: 1 addition & 0 deletions website/route-lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
/docs/integrations/vscode
/docs/migration/from-0-13
/docs/migration/from-0-18
/docs/migration/from-4-0
/docs/plugins -> /plugins
/docs/plugins/c-sharp -> /plugins/c-sharp/c-sharp-operations
/docs/plugins/client-note -> /plugins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
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.
---

import { Callout } from '@theguild/components'

# Development workflow

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

## Watch Mode

<Callout type="info">
Watch mode was made optional to reduce install size in CI and prevent build errors in certain environments.

To use watch mode, make sure to provide `@parcel/watcher` as a peer dependency.

</Callout>

If you wish to run the codegen in watch mode, you can specify `--watch` (or `-w`) when running it.

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:
Expand Down
6 changes: 6 additions & 0 deletions website/src/pages/docs/getting-started/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ npm i graphql
npm i -D typescript @graphql-codegen/cli
```

If you want [watch mode](/docs/getting-started/development-workflow#watch-mode) support you need to add `@parcel/watcher` as well:

```sh npm2yarn
npm i -D @parcel/watcher
```

## Global Installation

<Callout type="warning">
Expand Down
3 changes: 2 additions & 1 deletion website/src/pages/docs/migration/_meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"graphql-cli": "GraphQL-CLI Deprecation",
"from-0-18": "v0.18 -> v1.0",
"from-0-13": "v0.13 -> v0.17"
"from-0-13": "v0.13 -> v0.17",
"from-4-0": "v4.0 -> v5.0"
}
95 changes: 95 additions & 0 deletions website/src/pages/docs/migration/from-4-0.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
description: Migrating to 5.0.0. What has changed? How to migrate? What are the new features?
---

import { Tabs, Tab } from '@theguild/components'

# Migration to 5.0.0

## What has changed?

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.
This release focuses on improving the usage of `@graphql-codegen/cli` in those environments by making it an optional peer dependency.
NPM (or Yarn) will not emit errors when an optional peer dependency is missing.

## How to migrate?

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.

Start by updating your package.json

<Tabs items={['Before', 'After']}>
<Tab>
```json filename="package.json"
{
"devDependencies": {
"@graphql-codegen/cli": "^1.0.0",
"@graphql-codegen/typescript": "^1.0.0",
"@graphql-codegen/typescript-operations": "^1.0.0"
}
}
```
</Tab>

<Tab>
```json filename="package.json"
{
"devDependencies": {
"@graphql-codegen/cli": "^1.0.0",
"@graphql-codegen/typescript": "^1.0.0",
"@graphql-codegen/typescript-operations": "^1.0.0",
"@parcel/watcher": "^2.1.0"
}
}
```
</Tab>
</Tabs>

If you had issues with `@parcel/watcher` previously, you can make NPM and Yarn silently discard any build errors, by using `optionalDependencies` instead:

<Tabs items={['Before', 'After', 'After (Alternative)']}>
<Tab>
```json filename="package.json"
{
"devDependencies": {
"@graphql-codegen/cli": "^1.0.0",
"@graphql-codegen/typescript": "^1.0.0",
"@graphql-codegen/typescript-operations": "^1.0.0"
}
}
```
</Tab>

<Tab>
```json filename="package.json"
{
"devDependencies": {
"@graphql-codegen/cli": "^1.0.0",
"@graphql-codegen/typescript": "^1.0.0",
"@graphql-codegen/typescript-operations": "^1.0.0"
},
"optionalDependencies": {
"@parcel/watcher": "^2.1.0"
}
}
```
</Tab>

<Tab>
```json filename="package.json"
{
"devDependencies": {
"@graphql-codegen/cli": "^1.0.0",
"@graphql-codegen/typescript": "^1.0.0",
"@graphql-codegen/typescript-operations": "^1.0.0",
"@parcel/watcher": "^2.1.0"
},
"dependenciesMeta": {
"@parcel/watcher": {
"optional": true
}
}
}
```
</Tab>
</Tabs>

0 comments on commit dd9c7e1

Please sign in to comment.