diff --git a/.changeset/config.json b/.changeset/config.json index b2f1f7d26bd..03b6ad792ed 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -8,10 +8,9 @@ "ignore": [ "website", "example-*", + "rust-example-*", "dev-test*", - "@graphql-codegen/client-preset-swc-plugin", - "example-apollo-client-swc-plugin", - "example-react-nextjs-swr" + "@graphql-codegen/client-preset-swc-plugin" ], "changelog": [ "@changesets/changelog-github", diff --git a/eslint.config.mjs b/eslint.config.mjs index 20f5064c914..8d3550c6d88 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -174,9 +174,10 @@ export default [ // Scripts and config files { - files: ['scripts/*.{ts,js}', 'prettier.config.cjs'], + files: ['scripts/*.{mjs,ts,js}', 'prettier.config.cjs'], rules: { '@typescript-eslint/no-require-imports': 'off', + 'no-console': 'off', }, }, ]; diff --git a/package.json b/package.json index a36c4948121..e0adb7cdddb 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "prebuild": "rimraf dist/ .bob/ tsconfig.tsbuildinfo", "build": "bob build", - "postbuild": "pnpm fix-bins", + "postbuild": "pnpm fix-bins && pnpm inject-cli-version", "clean": "rimraf node_modules/", "dev-test:generate": "pnpm --filter=\"dev-test*\" generate", "dev-test:generate:cjs": "pnpm --filter=\"dev-test*\" generate:cjs", @@ -21,6 +21,7 @@ "examples:codegen": "pnpm --filter=\"example-*\" codegen", "examples:test:end2end": "pnpm --filter=\"example-*\" --workspace-concurrency=1 test:end2end", "fix-bins": "node scripts/fix-bin.js", + "inject-cli-version": "node scripts/inject-cli-version.mjs", "postinstall": "husky install", "lint": "eslint --cache .", "lint:ci": "eslint --cache --output-file eslint_report.json --format json .", diff --git a/packages/graphql-codegen-cli/CHANGELOG.md b/packages/graphql-codegen-cli/CHANGELOG.md index 73bf7b0588f..0012f3dc1a4 100644 --- a/packages/graphql-codegen-cli/CHANGELOG.md +++ b/packages/graphql-codegen-cli/CHANGELOG.md @@ -1,5 +1,13 @@ # @graphql-codegen/cli +## 7.1.1 + +### Patch Changes + +- [#10858](https://github.com/dotansimha/graphql-code-generator/pull/10858) + [`3fa901b`](https://github.com/dotansimha/graphql-code-generator/commit/3fa901b23ad6d3ef0522d2d8121d654bcacbd65d) + Thanks [@eddeee888](https://github.com/eddeee888)! - Fix --version flag + ## 7.1.0 ### Minor Changes diff --git a/packages/graphql-codegen-cli/package.json b/packages/graphql-codegen-cli/package.json index f1f2fe5b98a..d724779e11e 100644 --- a/packages/graphql-codegen-cli/package.json +++ b/packages/graphql-codegen-cli/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/cli", - "version": "7.1.0", + "version": "7.1.1", "type": "module", "repository": { "type": "git", diff --git a/packages/graphql-codegen-cli/src/config.ts b/packages/graphql-codegen-cli/src/config.ts index 845c5274cc4..49d1f7e7ade 100644 --- a/packages/graphql-codegen-cli/src/config.ts +++ b/packages/graphql-codegen-cli/src/config.ts @@ -24,6 +24,7 @@ import { loadDocuments, loadSchema, } from './load.js'; +import { version } from './version.js'; const { lstat } = promises; @@ -283,7 +284,7 @@ export function buildOptions() { } export function parseArgv(argv = process.argv): YamlCliFlags { - return yargs(argv).options(buildOptions()).parse(argv) as any; + return yargs(argv).version(version).options(buildOptions()).parse(argv) as any; } export async function createContext( diff --git a/packages/graphql-codegen-cli/src/version.ts b/packages/graphql-codegen-cli/src/version.ts new file mode 100644 index 00000000000..f8af9d7a657 --- /dev/null +++ b/packages/graphql-codegen-cli/src/version.ts @@ -0,0 +1 @@ +export const version = '__VERSION__'; diff --git a/scripts/fix-bin.js b/scripts/fix-bin.js index d6b28a22a00..b35284a38d7 100644 --- a/scripts/fix-bin.js +++ b/scripts/fix-bin.js @@ -1,5 +1,3 @@ -/* eslint-disable import/no-extraneous-dependencies */ -// @ts-check const fs = require('fs-extra'); const path = require('path'); const fg = require('fast-glob'); diff --git a/scripts/inject-cli-version.mjs b/scripts/inject-cli-version.mjs new file mode 100644 index 00000000000..0bf1b1b99ee --- /dev/null +++ b/scripts/inject-cli-version.mjs @@ -0,0 +1,33 @@ +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import * as url from 'node:url'; + +/** + * This script injects the `@graphql-codegen/cli` version after building, + * so at runtime, we don't have to import `package.json` file for the package version. + */ + +const __dirname = url.fileURLToPath(new url.URL('.', import.meta.url)); + +const packageJsonFile = path.resolve(__dirname, '../packages/graphql-codegen-cli/package.json'); +const versionFiles = [ + path.resolve(__dirname, '../packages/graphql-codegen-cli/dist/cjs/version.js'), + path.resolve(__dirname, '../packages/graphql-codegen-cli/dist/esm/version.js'), +]; + +const packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'utf8')); + +for (const versionFile of versionFiles) { + const versionFileContent = fs.readFileSync(versionFile, 'utf8'); + fs.writeFileSync( + versionFile, + versionFileContent.replace('__VERSION__', packageJson.version || 'unknown'), + 'utf8', + ); + + const updatedVersionContent = fs.readFileSync(versionFile, 'utf8'); + + console.log('***'); + console.log(`Updated ${versionFile} content:\n"${updatedVersionContent}"`); + console.log('***'); +} diff --git a/scripts/match-graphql.js b/scripts/match-graphql.js index 73d7557c910..5216208cdf6 100644 --- a/scripts/match-graphql.js +++ b/scripts/match-graphql.js @@ -10,7 +10,6 @@ const pkg = require(pkgPath); const version = argv[2]; if (pkg.devDependencies.graphql?.startsWith(version)) { - // eslint-disable-next-line no-console console.info(`GraphQL v${version} is match! Skipping.`); return; }