Skip to content

Commit bc9bed4

Browse files
authored
fix: Fix gen --pr command (#71)
* fix: Improve bundling to fix --pr option Apollo need to be part of the bundle to rely on the same version of react. * Add a warning if no operation Closed #70 * Optimize the bundle
1 parent 69651df commit bc9bed4

File tree

10 files changed

+72
-58
lines changed

10 files changed

+72
-58
lines changed

cli/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
],
2525
"license": "MIT",
2626
"scripts": {
27-
"build": "npm run build:tsc && npm run build:rollup",
28-
"build:tsc": "tsc -p tsconfig.package.json",
29-
"build:rollup": "rollup -c",
27+
"build": "rollup -c",
3028
"prepublishOnly": "npm run build",
3129
"gen": "graphql-codegen --config codegen.yml -r dotenv/config"
3230
},
@@ -49,7 +47,6 @@
4947
"js-yaml": "^4.1.0",
5048
"openapi3-ts": "^2.0.1",
5149
"prettier": "^2.6.2",
52-
"react": "^17.0.2",
5350
"rxjs": "^7.5.4",
5451
"slash": "^4.0.0",
5552
"swagger2openapi": "^7.0.8",
@@ -74,6 +71,7 @@
7471
"@types/react": "^17.0.39",
7572
"@types/slash": "^3.0.0",
7673
"nock": "^13.2.1",
74+
"react": "^17.0.2",
7775
"rollup-plugin-auto-external": "^2.0.0",
7876
"rollup-plugin-internal": "^1.0.4",
7977
"rollup-plugin-preserve-shebang": "^1.0.1"

cli/rollup.config.js

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,41 @@ import autoExternal from "rollup-plugin-auto-external";
66
import internal from "rollup-plugin-internal";
77
import typescript from "@rollup/plugin-typescript";
88

9-
export default {
10-
input: "src/cli.ts",
11-
output: {
12-
file: "lib/cli.js",
13-
format: "es",
14-
banner: "#!/usr/bin/env node",
9+
const typescriptPlugin = typescript({
10+
tsconfig: "./tsconfig.package.json",
11+
compilerOptions: {
12+
outDir: ".",
13+
sourceMap: false,
1514
},
16-
cache: false,
17-
plugins: [
18-
shebang(),
19-
resolve(),
20-
typescript({
21-
tsconfig: "./tsconfig.package.json",
22-
compilerOptions: {
23-
outDir: ".",
24-
sourceMap: false,
25-
},
26-
}),
27-
commonjs(),
28-
json(),
29-
autoExternal(),
30-
internal(["react", "ink"]),
31-
],
32-
external: ["yoga-layout-prebuilt"],
33-
};
15+
});
16+
17+
export default [
18+
{
19+
input: "src/index.ts",
20+
output: {
21+
file: "lib/index.js",
22+
format: "es",
23+
},
24+
cache: false,
25+
plugins: [typescriptPlugin],
26+
},
27+
{
28+
input: "src/cli.ts",
29+
output: {
30+
file: "lib/cli.js",
31+
format: "es",
32+
banner: "#!/usr/bin/env node",
33+
},
34+
cache: false,
35+
plugins: [
36+
shebang(),
37+
resolve(),
38+
typescriptPlugin,
39+
commonjs(),
40+
json(),
41+
autoExternal(),
42+
internal(["react", "ink", "@apollo/client"]),
43+
],
44+
external: ["yoga-layout-prebuilt"],
45+
},
46+
];

cli/src/commands/GenerateCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import slash from "slash";
1010
import { Config, FromOptions, Namespace } from "../types";
1111
import { getOpenAPISourceFile } from "../core/getOpenAPISourceFile.js";
1212
import { parseOpenAPISourceFile } from "../core/parseOpenAPISourceFile.js";
13+
import { Prompt } from "../prompts/Prompt.js";
1314

1415
const __filename = fileURLToPath(import.meta.url);
1516

@@ -210,7 +211,6 @@ export class GenerateCommand extends Command {
210211
const config = configs[this.namespace];
211212
const options = this.getFromOptions(config);
212213
if (options.source === "github" && this.pullRequest) {
213-
const { Prompt } = await import("../prompts/Prompt.js");
214214
const prompt = new Prompt();
215215
const token = await prompt.githubToken();
216216
const pullRequest = await prompt.githubPullRequest({

cli/src/prompts/Github.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Apollo from "@apollo/client";
1+
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
22

33
import { Box, Text } from "ink";
44
import fetch from "got-fetch";
@@ -14,8 +14,6 @@ import {
1414
import { Select } from "./Select.js";
1515
import { TextInput } from "./TextInput.js";
1616

17-
const { ApolloClient, HttpLink, InMemoryCache } = Apollo;
18-
1917
type Step1 = Pick<Partial<GithubOptions>, "owner">;
2018
type Step2 = Required<Step1> & Pick<Partial<GithubOptions>, "repository">;
2119
type Step3 = Required<Step2> & Pick<Partial<GithubOptions>, "source">;

cli/src/prompts/GithubPullRequest.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Apollo from "@apollo/client";
1+
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
22

33
import React, { useEffect, useState } from "react";
44
import { Box, Text } from "ink";
@@ -11,8 +11,6 @@ import { TextInput } from "./TextInput.js";
1111
import { Confirm } from "./Confirm.js";
1212
import { Spinner } from "./Spinner.js";
1313

14-
const { ApolloClient, HttpLink, InMemoryCache } = Apollo;
15-
1614
export type PullRequest = {
1715
ref: string;
1816
owner: string;

cli/src/prompts/queries/github.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Apollo from "@apollo/client";
2-
const { gql } = Apollo;
1+
import type Apollo from "@apollo/client";
2+
import { gql, useQuery, useLazyQuery } from "@apollo/client";
33
export type Maybe<T> = T | null;
44
export type InputMaybe<T> = Maybe<T>;
55
export type Exact<T extends { [key: string]: unknown }> = {
@@ -23669,7 +23669,7 @@ export function useSearchFileQuery(
2366923669
>
2367023670
) {
2367123671
const options = { ...defaultOptions, ...baseOptions };
23672-
return Apollo.useQuery<SearchFileQuery, SearchFileQueryVariables>(
23672+
return useQuery<SearchFileQuery, SearchFileQueryVariables>(
2367323673
SearchFileDocument,
2367423674
options
2367523675
);
@@ -23681,7 +23681,7 @@ export function useSearchFileLazyQuery(
2368123681
>
2368223682
) {
2368323683
const options = { ...defaultOptions, ...baseOptions };
23684-
return Apollo.useLazyQuery<SearchFileQuery, SearchFileQueryVariables>(
23684+
return useLazyQuery<SearchFileQuery, SearchFileQueryVariables>(
2368523685
SearchFileDocument,
2368623686
options
2368723687
);
@@ -23741,10 +23741,10 @@ export function useSearchPullRequestQuery(
2374123741
>
2374223742
) {
2374323743
const options = { ...defaultOptions, ...baseOptions };
23744-
return Apollo.useQuery<
23745-
SearchPullRequestQuery,
23746-
SearchPullRequestQueryVariables
23747-
>(SearchPullRequestDocument, options);
23744+
return useQuery<SearchPullRequestQuery, SearchPullRequestQueryVariables>(
23745+
SearchPullRequestDocument,
23746+
options
23747+
);
2374823748
}
2374923749
export function useSearchPullRequestLazyQuery(
2375023750
baseOptions?: Apollo.LazyQueryHookOptions<
@@ -23753,10 +23753,10 @@ export function useSearchPullRequestLazyQuery(
2375323753
>
2375423754
) {
2375523755
const options = { ...defaultOptions, ...baseOptions };
23756-
return Apollo.useLazyQuery<
23757-
SearchPullRequestQuery,
23758-
SearchPullRequestQueryVariables
23759-
>(SearchPullRequestDocument, options);
23756+
return useLazyQuery<SearchPullRequestQuery, SearchPullRequestQueryVariables>(
23757+
SearchPullRequestDocument,
23758+
options
23759+
);
2376023760
}
2376123761
export type SearchPullRequestQueryHookResult = ReturnType<
2376223762
typeof useSearchPullRequestQuery
@@ -23803,7 +23803,7 @@ export function useSearchRepositoryQuery(
2380323803
>
2380423804
) {
2380523805
const options = { ...defaultOptions, ...baseOptions };
23806-
return Apollo.useQuery<SearchRepositoryQuery, SearchRepositoryQueryVariables>(
23806+
return useQuery<SearchRepositoryQuery, SearchRepositoryQueryVariables>(
2380723807
SearchRepositoryDocument,
2380823808
options
2380923809
);
@@ -23815,10 +23815,10 @@ export function useSearchRepositoryLazyQuery(
2381523815
>
2381623816
) {
2381723817
const options = { ...defaultOptions, ...baseOptions };
23818-
return Apollo.useLazyQuery<
23819-
SearchRepositoryQuery,
23820-
SearchRepositoryQueryVariables
23821-
>(SearchRepositoryDocument, options);
23818+
return useLazyQuery<SearchRepositoryQuery, SearchRepositoryQueryVariables>(
23819+
SearchRepositoryDocument,
23820+
options
23821+
);
2382223822
}
2382323823
export type SearchRepositoryQueryHookResult = ReturnType<
2382423824
typeof useSearchRepositoryQuery
@@ -23865,7 +23865,7 @@ export function useSearchUserQuery(
2386523865
>
2386623866
) {
2386723867
const options = { ...defaultOptions, ...baseOptions };
23868-
return Apollo.useQuery<SearchUserQuery, SearchUserQueryVariables>(
23868+
return useQuery<SearchUserQuery, SearchUserQueryVariables>(
2386923869
SearchUserDocument,
2387023870
options
2387123871
);
@@ -23877,7 +23877,7 @@ export function useSearchUserLazyQuery(
2387723877
>
2387823878
) {
2387923879
const options = { ...defaultOptions, ...baseOptions };
23880-
return Apollo.useLazyQuery<SearchUserQuery, SearchUserQueryVariables>(
23880+
return useLazyQuery<SearchUserQuery, SearchUserQueryVariables>(
2388123881
SearchUserDocument,
2388223882
options
2388323883
);

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/typescript/src/generators/generateFetchers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ export const generateFetchers = async (context: Context, config: Config) => {
178178
}
179179
);
180180

181+
if (operationIds.length === 0) {
182+
console.log(`⚠️ You don't have any operation with "operationId" defined!`);
183+
}
184+
181185
if (Object.keys(operationByTags).length > 0) {
182186
nodes.push(
183187
f.createVariableStatement(

plugins/typescript/src/generators/generateReactQueryComponents.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ export const generateReactQueryComponents = async (
219219
}
220220
);
221221

222+
if (operationIds.length === 0) {
223+
console.log(`⚠️ You don't have any operation with "operationId" defined!`);
224+
}
222225
const queryKeyManager = f.createTypeAliasDeclaration(
223226
undefined,
224227
[f.createModifier(ts.SyntaxKind.ExportKeyword)],

0 commit comments

Comments
 (0)