diff --git a/.changeset/@graphql-codegen_cli-9051-dependencies.md b/.changeset/@graphql-codegen_cli-9051-dependencies.md new file mode 100644 index 00000000000..2813199667f --- /dev/null +++ b/.changeset/@graphql-codegen_cli-9051-dependencies.md @@ -0,0 +1,5 @@ +--- +"@graphql-codegen/cli": patch +--- +dependencies updates: + - Added dependency [`micromatch@^4.0.5` ↗︎](https://www.npmjs.com/package/micromatch/v/4.0.5) (to `dependencies`) diff --git a/.changeset/honest-spiders-rush.md b/.changeset/honest-spiders-rush.md new file mode 100644 index 00000000000..7aa5909fe18 --- /dev/null +++ b/.changeset/honest-spiders-rush.md @@ -0,0 +1,5 @@ +--- +'@graphql-codegen/cli': patch +--- + +only run generate for files that users have listed in config to avoid running this over every change that codegen is not supposed to execute diff --git a/packages/graphql-codegen-cli/package.json b/packages/graphql-codegen-cli/package.json index a181f134920..8ec988d13bc 100644 --- a/packages/graphql-codegen-cli/package.json +++ b/packages/graphql-codegen-cli/package.json @@ -68,6 +68,7 @@ "json-to-pretty-yaml": "^1.2.2", "listr2": "^4.0.5", "log-symbols": "^4.0.0", + "micromatch": "^4.0.5", "shell-quote": "^1.7.3", "string-env-interpolation": "^1.0.1", "ts-log": "^2.2.3", @@ -82,6 +83,7 @@ "@types/inquirer": "8.2.6", "@types/is-glob": "4.0.2", "@types/js-yaml": "4.0.5", + "@types/micromatch": "^4.0.2", "@types/mkdirp": "1.0.2", "@types/shell-quote": "1.7.1", "bdd-stdin": "0.2.0", diff --git a/packages/graphql-codegen-cli/src/utils/watcher.ts b/packages/graphql-codegen-cli/src/utils/watcher.ts index 4e136d790e1..e527fa67b5b 100644 --- a/packages/graphql-codegen-cli/src/utils/watcher.ts +++ b/packages/graphql-codegen-cli/src/utils/watcher.ts @@ -4,6 +4,7 @@ import { isValidPath } from '@graphql-tools/utils'; import type { subscribe } from '@parcel/watcher'; import debounce from 'debounce'; import isGlob from 'is-glob'; +import mm from 'micromatch'; import logSymbols from 'log-symbols'; import { executeCodegen } from '../codegen.js'; import { CodegenContext, loadContext } from '../config.js'; @@ -95,6 +96,12 @@ export const createWatcher = ( // it doesn't matter what has changed, need to run whole process anyway await Promise.all( events.map(async ({ type: eventName, path }) => { + /** + * @parcel/watcher has no way to run watcher on specific files (https://github.com/parcel-bundler/watcher/issues/42) + * But we can use micromatch to filter out events that we don't care about + */ + if (!mm.contains(path, files)) return; + lifecycleHooks(config.hooks).onWatchTriggered(eventName, path); debugLog(`[Watcher] triggered due to a file ${eventName} event: ${path}`); const fullPath = join(process.cwd(), path); diff --git a/yarn.lock b/yarn.lock index 64370256ae8..7055741fefa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4430,6 +4430,11 @@ dependencies: "@types/node" "*" +"@types/braces@*": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@types/braces/-/braces-3.0.1.tgz#5a284d193cfc61abb2e5a50d36ebbc50d942a32b" + integrity sha512-+euflG6ygo4bn0JHtn4pYqcXwRtLvElQ7/nnjDu7iYG56H0+OhCd7d6Ug0IE3WcFpZozBKW2+80FUbv5QGk5AQ== + "@types/connect-history-api-fallback@^1.3.5": version "1.3.5" resolved "https://registry.yarnpkg.com/@types/connect-history-api-fallback/-/connect-history-api-fallback-1.3.5.tgz#d1f7a8a09d0ed5a57aee5ae9c18ab9b803205dae" @@ -4654,6 +4659,13 @@ resolved "https://registry.yarnpkg.com/@types/mdx/-/mdx-2.0.3.tgz#43fd32414f17fcbeced3578109a6edd877a2d96e" integrity sha512-IgHxcT3RC8LzFLhKwP3gbMPeaK7BM9eBH46OdapPA7yvuIUJ8H6zHZV53J8hGZcTSnt95jANt+rTBNUUc22ACQ== +"@types/micromatch@^4.0.2": + version "4.0.2" + resolved "https://registry.yarnpkg.com/@types/micromatch/-/micromatch-4.0.2.tgz#ce29c8b166a73bf980a5727b1e4a4d099965151d" + integrity sha512-oqXqVb0ci19GtH0vOA/U2TmHTcRY9kuZl4mqUxe0QmJAlIW13kzhuK5pi1i9+ngav8FjpSb9FVS/GE00GLX1VA== + dependencies: + "@types/braces" "*" + "@types/mime@*": version "3.0.1" resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.1.tgz#5f8f2bca0a5863cb69bc0b0acd88c96cb1d4ae10" @@ -8135,35 +8147,7 @@ esbuild@^0.16.14: "@esbuild/win32-ia32" "0.16.17" "@esbuild/win32-x64" "0.16.17" -esbuild@^0.17.6: - version "0.17.8" - resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.8.tgz#f7f799abc7cdce3f0f2e3e0c01f120d4d55193b4" - integrity sha512-g24ybC3fWhZddZK6R3uD2iF/RIPnRpwJAqLov6ouX3hMbY4+tKolP0VMF3zuIYCaXun+yHwS5IPQ91N2BT191g== - optionalDependencies: - "@esbuild/android-arm" "0.17.8" - "@esbuild/android-arm64" "0.17.8" - "@esbuild/android-x64" "0.17.8" - "@esbuild/darwin-arm64" "0.17.8" - "@esbuild/darwin-x64" "0.17.8" - "@esbuild/freebsd-arm64" "0.17.8" - "@esbuild/freebsd-x64" "0.17.8" - "@esbuild/linux-arm" "0.17.8" - "@esbuild/linux-arm64" "0.17.8" - "@esbuild/linux-ia32" "0.17.8" - "@esbuild/linux-loong64" "0.17.8" - "@esbuild/linux-mips64el" "0.17.8" - "@esbuild/linux-ppc64" "0.17.8" - "@esbuild/linux-riscv64" "0.17.8" - "@esbuild/linux-s390x" "0.17.8" - "@esbuild/linux-x64" "0.17.8" - "@esbuild/netbsd-x64" "0.17.8" - "@esbuild/openbsd-x64" "0.17.8" - "@esbuild/sunos-x64" "0.17.8" - "@esbuild/win32-arm64" "0.17.8" - "@esbuild/win32-ia32" "0.17.8" - "@esbuild/win32-x64" "0.17.8" - -esbuild@~0.17.6: +esbuild@^0.17.6, esbuild@~0.17.6: version "0.17.10" resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.10.tgz#3be050561b34c5dc05b46978f4e1f326d5cc9437" integrity sha512-n7V3v29IuZy5qgxx25TKJrEm0FHghAlS6QweUcyIgh/U0zYmQcvogWROitrTyZId1mHSkuhhuyEXtI9OXioq7A==