Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit ba4da84

Browse files
authored
Prepare for typescript 5. Enable consistent type import formatting (#2608)
* Update `@typescript-eslint/*`, prettier and eslint-plugin-import * enable consistent-type-imports and apply autofixes * Fix usages of dynamic type imports * add changeset * yarn dedupe
1 parent 51f32bd commit ba4da84

File tree

144 files changed

+740
-626
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+740
-626
lines changed

.changeset/short-snails-push.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
'@shopify/address': patch
3+
'@shopify/address-mocks': patch
4+
'@shopify/async': patch
5+
'graphql-fixtures': patch
6+
'graphql-mini-transforms': patch
7+
'@shopify/graphql-persisted': patch
8+
'@shopify/graphql-testing': patch
9+
'graphql-tool-utilities': patch
10+
'graphql-typed': patch
11+
'graphql-typescript-definitions': patch
12+
'graphql-validate-fixtures': patch
13+
'@shopify/jest-dom-mocks': patch
14+
'@shopify/jest-koa-mocks': patch
15+
'@shopify/koa-metrics': patch
16+
'@shopify/koa-performance': patch
17+
'@shopify/koa-shopify-webhooks': patch
18+
'@shopify/logger': patch
19+
'@shopify/performance': patch
20+
'@shopify/react-async': patch
21+
'@shopify/react-bugsnag': patch
22+
'@shopify/react-form': patch
23+
'@shopify/react-form-state': patch
24+
'@shopify/react-google-analytics': patch
25+
'@shopify/react-graphql': patch
26+
'@shopify/react-graphql-universal-provider': patch
27+
'@shopify/react-hooks': patch
28+
'@shopify/react-html': patch
29+
'@shopify/react-i18n': patch
30+
'@shopify/react-i18n-universal-provider': patch
31+
'@shopify/react-idle': patch
32+
'@shopify/react-import-remote': patch
33+
'@shopify/react-intersection-observer': patch
34+
'@shopify/react-network': patch
35+
'@shopify/react-performance': patch
36+
'@shopify/react-server': patch
37+
'@shopify/react-shortcuts': patch
38+
'@shopify/react-testing': patch
39+
'@shopify/react-web-worker': patch
40+
'@shopify/statsd': patch
41+
'@shopify/storybook-a11y-test': patch
42+
'@shopify/useful-types': patch
43+
'@shopify/web-worker': patch
44+
---
45+
46+
Use `import type` everywhere that we deal with importing types

.eslintrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ module.exports = {
2727
'@shopify/jsx-no-hardcoded-content': 'off',
2828
// reports false positives with React's useRef hook
2929
'require-atomic-updates': 'off',
30+
'@typescript-eslint/consistent-type-imports': 'error',
31+
'@typescript-eslint/consistent-type-exports': 'error',
32+
'@typescript-eslint/no-import-type-side-effects': 'error',
3033
'@typescript-eslint/no-unnecessary-type-arguments': 'off',
3134
'@typescript-eslint/no-unnecessary-condition': 'off',
3235
'@typescript-eslint/prefer-readonly': 'off',
@@ -35,6 +38,7 @@ module.exports = {
3538
'@typescript-eslint/no-misused-promises': 'off',
3639
'@typescript-eslint/await-thenable': 'off',
3740
'import/no-extraneous-dependencies': 'error',
41+
'import/consistent-type-specifier-style': 'error',
3842
'no-restricted-imports': [
3943
'error',
4044
{

config/typescript/matchers.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ComponentType, Context as ReactContext} from 'react';
1+
import type {ComponentType, Context as ReactContext} from 'react';
22
import type {} from 'saddle-up/matchers';
33
import type {} from 'saddle-up/koa-matchers';
44

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"jest-watch-typeahead": "^2.2.2",
7070
"npm-run-all": "^4.1.5",
7171
"plop": "^2.6.0",
72-
"prettier": "~2.7.1",
72+
"prettier": "~2.8.6",
7373
"puppeteer": "^13.2.0",
7474
"react": "^18.1.0",
7575
"react-dom": "^18.1.0",

packages/address-mocks/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {
2-
GRAPHQL_ENDPOINT,
1+
import type {
32
LoadCountriesResponse,
43
LoadCountryResponse,
54
ResponseError,
65
} from '@shopify/address-consts';
6+
import {GRAPHQL_ENDPOINT} from '@shopify/address-consts';
77
import {fetch} from '@shopify/jest-dom-mocks';
88

99
import {fixtures} from './fixtures';

packages/address/src/loader.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import {
1+
import type {
22
Country,
33
LoadCountriesResponse,
44
LoadCountryResponse,
55
ResponseError,
6+
} from '@shopify/address-consts';
7+
import {
68
GRAPHQL_ENDPOINT,
79
HEADERS,
810
GraphqlOperationName,

packages/address/src/utilities.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {Address, FieldName, Country, Zone} from '@shopify/address-consts';
1+
import type {Address, Country, Zone} from '@shopify/address-consts';
2+
import {FieldName} from '@shopify/address-consts';
23

34
export const FIELD_REGEXP = /({\w+})/g;
45
/* eslint-disable @typescript-eslint/naming-convention */

packages/async/src/tests/babel-plugin.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {transformAsync} from '@babel/core';
22

3-
import asyncBabelPlugin, {Options} from '../babel-plugin';
3+
import type {Options} from '../babel-plugin';
4+
import asyncBabelPlugin from '../babel-plugin';
45

56
const defaultPackage = 'some-async-package';
67
const defaultImport = 'createAsyncComponent';

packages/graphql-fixtures/src/fill.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
import {faker} from '@faker-js/faker/locale/en';
2-
import {
2+
import type {
33
GraphQLSchema,
44
GraphQLType,
5+
GraphQLObjectType,
6+
GraphQLEnumType,
7+
GraphQLScalarType,
8+
} from 'graphql';
9+
import {
510
isNonNullType,
611
isEnumType,
712
isListType,
813
isAbstractType,
9-
GraphQLObjectType,
10-
GraphQLEnumType,
1114
isScalarType,
12-
GraphQLScalarType,
1315
} from 'graphql';
1416
import type {DocumentNode, GraphQLOperation} from 'graphql-typed';
1517
import type {IfEmptyObject, IfAllNullableKeys} from '@shopify/useful-types';
16-
import {
17-
compile,
18-
Field,
19-
InlineFragment,
20-
Operation,
21-
} from 'graphql-tool-utilities';
18+
import type {Field, InlineFragment, Operation} from 'graphql-tool-utilities';
19+
import {compile} from 'graphql-tool-utilities';
2220

2321
import {randomFromArray, chooseNull} from './utilities';
2422

packages/graphql-fixtures/src/tests/fill.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// eslint-disable-next-line @shopify/typescript/prefer-build-client-schema
22
import {buildSchema} from 'graphql';
3-
import {parse, DocumentNode} from 'graphql-typed';
3+
import type {DocumentNode} from 'graphql-typed';
4+
import {parse} from 'graphql-typed';
45
import {faker as originalFaker} from '@faker-js/faker/locale/en';
56

6-
import {createFiller, list, Options, faker} from '../fill';
7+
import type {Options} from '../fill';
8+
import {createFiller, list, faker} from '../fill';
79

810
jest.mock('../utilities', () => {
911
const utilities = jest.requireActual('../utilities');

packages/graphql-mini-transforms/src/document.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import {createHash} from 'crypto';
22

3-
import {
4-
print,
5-
parse,
3+
import type {
64
DocumentNode as UntypedDocumentNode,
75
DefinitionNode,
86
SelectionSetNode,
@@ -11,6 +9,7 @@ import {
119
SelectionNode,
1210
Location,
1311
} from 'graphql';
12+
import {print, parse} from 'graphql';
1413
import type {DocumentNode, SimpleDocument} from 'graphql-typed';
1514

1615
const IMPORT_REGEX = /^#import\s+['"]([^'"]*)['"];?[\s\n]*/gm;

packages/graphql-mini-transforms/src/webpack-loader.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {dirname} from 'path';
22

33
import type {LoaderContext} from 'webpack';
4-
import {parse, DocumentNode} from 'graphql';
4+
import type {DocumentNode} from 'graphql';
5+
import {parse} from 'graphql';
56

67
import {cleanDocument, extractImports, toSimpleDocument} from './document';
78

packages/graphql-persisted/src/apollo.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import {
2-
ApolloLink,
3-
Operation,
4-
NextLink,
5-
Observable,
6-
FetchResult,
7-
} from '@apollo/client';
1+
import type {Operation, NextLink, FetchResult} from '@apollo/client';
2+
import {ApolloLink, Observable} from '@apollo/client';
83

94
import {CacheMissBehavior} from './shared';
105

packages/graphql-persisted/src/tests/koa-middleware.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {Header} from '@shopify/network';
33
import {createMockContext} from '@shopify/jest-koa-mocks';
44
import {setAssets} from '@shopify/sewing-kit-koa';
55

6+
import type {Cache} from '../koa-middleware';
67
import {
7-
Cache,
88
CacheMissBehavior,
99
createPersistedGraphQLMiddleware,
1010
} from '../koa-middleware';

packages/graphql-persisted/src/tests/utilities.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import {
2-
ApolloLink,
3-
execute,
4-
Operation,
5-
Observable,
6-
FetchResult,
7-
NextLink,
8-
} from '@apollo/client';
9-
import {DocumentNode} from 'graphql-typed';
1+
import type {Operation, FetchResult, NextLink} from '@apollo/client';
2+
import {ApolloLink, execute, Observable} from '@apollo/client';
3+
import type {DocumentNode} from 'graphql-typed';
104

115
interface ExecuteOnceOutcome {
126
operation: Operation;

packages/graphql-testing/src/factory.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {GraphQL, Options} from './graphql-controller';
1+
import type {Options} from './graphql-controller';
2+
import {GraphQL} from './graphql-controller';
23
import type {GraphQLMock} from './types';
34

45
export function createGraphQLFactory(options?: Options) {

packages/graphql-testing/src/graphql-controller.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import {
2-
ApolloClient,
3-
ApolloLink,
4-
InMemoryCacheConfig,
5-
InMemoryCache,
6-
} from '@apollo/client';
1+
import type {InMemoryCacheConfig} from '@apollo/client';
2+
import {ApolloClient, ApolloLink, InMemoryCache} from '@apollo/client';
73

84
import {MockLink, InflightLink} from './links';
95
import {Operations} from './operations';

packages/graphql-testing/src/links/inflight.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import {
2-
ApolloLink,
3-
Observable,
4-
Operation,
5-
NextLink,
6-
FetchResult,
7-
} from '@apollo/client';
1+
import type {Operation, NextLink, FetchResult} from '@apollo/client';
2+
import {ApolloLink, Observable} from '@apollo/client';
83

94
import type {MockRequest} from '../types';
105

packages/graphql-testing/src/links/mocks.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import {ApolloLink, Observable, Operation} from '@apollo/client';
2-
import {ExecutionResult, GraphQLError} from 'graphql';
1+
import type {Operation} from '@apollo/client';
2+
import {ApolloLink, Observable} from '@apollo/client';
3+
import type {ExecutionResult} from 'graphql';
4+
import {GraphQLError} from 'graphql';
35

46
import type {GraphQLMock, MockGraphQLFunction} from '../types';
57

packages/graphql-testing/src/links/tests/mocks.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {gql} from '@apollo/client';
22
import {GraphQLError} from 'graphql';
33

4-
import {MockGraphQLResponse} from '../../types';
4+
import type {MockGraphQLResponse} from '../../types';
55
import {MockLink} from '../mocks';
66

77
import {executeOnce} from './utilities';

packages/graphql-testing/src/links/tests/utilities.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import {
2-
ApolloLink,
3-
execute,
4-
Operation,
5-
Observable,
6-
FetchResult,
7-
NextLink,
8-
} from '@apollo/client';
9-
import {DocumentNode} from 'graphql-typed';
1+
import type {Operation, FetchResult, NextLink} from '@apollo/client';
2+
import {ApolloLink, execute, Observable} from '@apollo/client';
3+
import type {DocumentNode} from 'graphql-typed';
104

115
interface ExecuteOnceOutcome {
126
operation: Operation;

packages/graphql-testing/src/tests/e2e.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {useCallback} from 'react';
22
import {GraphQLError} from 'graphql';
33
import {gql} from '@apollo/client';
4-
import {DocumentNode} from 'graphql-typed';
4+
import type {DocumentNode} from 'graphql-typed';
55
import {mount} from '@shopify/react-testing';
66
import {ApolloProvider, useQuery, ApolloError} from '@shopify/react-graphql';
77

packages/graphql-tool-utilities/src/ast.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type {DocumentNode, GraphQLInputType, GraphQLSchema} from 'graphql';
2-
import {
2+
import type {
33
BooleanCondition,
44
CompilerOptions,
5-
compileToLegacyIR as compileToIR,
65
LegacyCompilerContext,
76
LegacyField,
87
LegacyFragment,
98
LegacyInlineFragment,
109
LegacyOperation,
1110
} from 'apollo-codegen-core/lib/compiler/legacyIR';
11+
import {compileToLegacyIR as compileToIR} from 'apollo-codegen-core/lib/compiler/legacyIR';
1212

1313
export enum OperationType {
1414
Query = 'query',

packages/graphql-typed/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {
2-
parse as graphQLParse,
1+
import type {
32
DocumentNode as BaseDocumentNode,
43
Source,
54
ParseOptions,
65
} from 'graphql';
6+
import {parse as graphQLParse} from 'graphql';
77

88
export interface GraphQLOperation<Data = {}, Variables = {}, DeepPartial = {}> {
99
// We need something to actually use the types, otherwise TypeScript

packages/graphql-typescript-definitions/src/cli.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import yargs from 'yargs';
55

66
import {EnumFormat, ExportFormat} from './types';
77

8-
import {Builder, SchemaBuild, DocumentBuild} from '.';
8+
import type {SchemaBuild, DocumentBuild} from '.';
9+
import {Builder} from '.';
910

1011
const argv = yargs
1112
.usage('Usage: $0 [options]')

packages/graphql-typescript-definitions/src/filesystem/default-graphql-filesystem.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {FSWatcher, watch} from 'chokidar';
1+
import type {FSWatcher} from 'chokidar';
2+
import {watch} from 'chokidar';
23
import type {GraphQLProjectConfig, GraphQLConfig} from 'graphql-config';
34
import {
45
getGraphQLProjectIncludedFilePaths,

0 commit comments

Comments
 (0)