Skip to content

Commit e7870ac

Browse files
authored
feat: remove latest-version dependency (#8035)
* feat: remove latest-version dependency * fix:mock * chore: add changeset
1 parent 28f8346 commit e7870ac

File tree

6 files changed

+24
-233
lines changed

6 files changed

+24
-233
lines changed

.changeset/nine-llamas-bathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/cli': patch
3+
---
4+
5+
Fix security vulnerability by removing `latest-version` dependency.

packages/graphql-codegen-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@
5858
"chokidar": "^3.5.2",
5959
"common-tags": "^1.8.0",
6060
"cosmiconfig": "^7.0.0",
61+
"cross-undici-fetch": "^0.4.11",
6162
"debounce": "^1.2.0",
6263
"detect-indent": "^6.0.0",
6364
"graphql-config": "^4.3.1",
6465
"inquirer": "^8.0.0",
6566
"is-glob": "^4.0.1",
6667
"json-to-pretty-yaml": "^1.2.2",
67-
"latest-version": "5.1.0",
6868
"listr": "^0.14.3",
6969
"listr-update-renderer": "^0.5.0",
7070
"log-symbols": "^4.0.0",

packages/graphql-codegen-cli/src/init/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { writeFileSync, readFileSync } from 'fs';
44
import { Types } from '@graphql-codegen/plugin-helpers';
55
import detectIndent from 'detect-indent';
66
import { Answers } from './types.js';
7-
import getLatestVersion from 'latest-version';
7+
import { getLatestVersion } from '../utils/get-latest-version.js';
88

99
// Parses config and writes it to a file
1010
export async function writeConfig(answers: Answers, config: Types.Config) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { fetch } from 'cross-undici-fetch';
2+
3+
/**
4+
* Fetches the version directly from the registry instead of depending on
5+
* an ESM only module as latest-version does.
6+
* @param packageName
7+
*/
8+
export async function getLatestVersion(packageName: string): Promise<string> {
9+
return fetch(`https://unpkg.com/${packageName}/package.json`)
10+
.then(res => res.json())
11+
.then(pkg => pkg.version);
12+
}

packages/graphql-codegen-cli/tests/init.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
jest.mock('latest-version', () => {
2-
return () => Promise.resolve('1.0.0');
1+
jest.mock('../src/utils/get-latest-version.ts', () => {
2+
return { getLatestVersion: () => Promise.resolve('1.0.0') };
33
});
44

55
import bddStdin from 'bdd-stdin';

0 commit comments

Comments
 (0)