Skip to content

Commit

Permalink
Merge pull request #1244 from Quramy/modify_import_types
Browse files Browse the repository at this point in the history
chore: Modify type imports
  • Loading branch information
Quramy committed Mar 18, 2024
2 parents e9977fc + fea7981 commit ef45afc
Show file tree
Hide file tree
Showing 40 changed files with 101 additions and 98 deletions.
2 changes: 1 addition & 1 deletion src/analyzer/analyzer-factory.test.ts
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';
import { AnalyzerFactory } from './analyzer-factory';
import { Analyzer } from './analyzer';

Expand Down
4 changes: 2 additions & 2 deletions src/analyzer/analyzer-factory.ts
@@ -1,7 +1,7 @@
import path from 'path';
import path from 'node:path';
import ts from 'typescript';
import { Analyzer } from './analyzer';
import { TsGraphQLPluginConfigOptions } from '../types';
import type { TsGraphQLPluginConfigOptions } from '../types';
import { ScriptHost } from '../ts-ast-util';
import { SchemaManagerFactory, createSchemaManagerHostFromTSGqlPluginConfig } from '../schema-manager';
import { ErrorWithoutLocation } from '../errors';
Expand Down
6 changes: 3 additions & 3 deletions src/analyzer/analyzer.ts
@@ -1,6 +1,6 @@
import path from 'node:path';
import ts from 'typescript';
import path from 'path';
import { ScriptSourceHelper } from '../ts-ast-util/types';
import type { ScriptSourceHelper } from '../ts-ast-util/types';
import { Extractor } from './extractor';
import {
createScriptSourceHelper,
Expand All @@ -15,7 +15,7 @@ import { SchemaManager, SchemaBuildErrorInfo } from '../schema-manager/schema-ma
import { TsGqlError, ErrorWithLocation, ErrorWithoutLocation } from '../errors';
import { location2pos } from '../string-util';
import { validate } from './validator';
import { ManifestOutput, TsGraphQLPluginConfig } from './types';
import type { ManifestOutput, TsGraphQLPluginConfig } from './types';
import { MarkdownReporter } from './markdown-reporter';
import { TypeGenerator } from './type-generator';
import { createFileNameFilter } from '../ts-ast-util/file-name-filter';
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/extractor.ts
Expand Up @@ -17,7 +17,7 @@ import {
ResolvedTemplateInfo,
StrictTagCondition,
} from '../ts-ast-util';
import { ManifestOutput, ManifestDocumentEntry, OperationType } from './types';
import type { ManifestOutput, ManifestDocumentEntry, OperationType } from './types';
import { ErrorWithLocation, ERROR_CODES } from '../errors';
import {
detectDuplicatedFragments,
Expand Down
4 changes: 2 additions & 2 deletions src/analyzer/markdown-reporter.ts
@@ -1,5 +1,5 @@
import path from 'path';
import { ManifestOutput, ManifestDocumentEntry } from './types';
import path from 'node:path';
import type { ManifestOutput, ManifestDocumentEntry } from './types';

export type ToMarkdownContentOptions = {
baseDir: string;
Expand Down
16 changes: 11 additions & 5 deletions src/analyzer/type-generator.ts
@@ -1,12 +1,18 @@
import path from 'path';
import path from 'node:path';
import ts from 'typescript';
import { GraphQLSchema } from 'graphql';
import type { GraphQLSchema } from 'graphql';

import { TsGqlError, ErrorWithLocation } from '../errors';
import { mergeAddons, TypeGenVisitor, TypeGenError, TypeGenAddonFactory, TypeGenVisitorAddonContext } from '../typegen';
import {
mergeAddons,
TypeGenVisitor,
TypeGenError,
type TypeGenAddonFactory,
type TypeGenVisitorAddonContext,
} from '../typegen';
import { dasherize } from '../string-util';
import { OutputSource, createOutputSource, type StrictTagCondition } from '../ts-ast-util';
import { Extractor, ExtractSucceededResult } from './extractor';
import { createOutputSource, type OutputSource, type StrictTagCondition } from '../ts-ast-util';
import type { Extractor, ExtractSucceededResult } from './extractor';

export type TypeGeneratorOptions = {
prjRootPath: string;
Expand Down
6 changes: 3 additions & 3 deletions src/analyzer/validator.ts
@@ -1,9 +1,9 @@
import { GraphQLSchema } from 'graphql';
import type { GraphQLSchema } from 'graphql';
import { getDiagnostics, getFragmentDependenciesForAST } from 'graphql-language-service';
import { ErrorWithLocation, ERROR_CODES } from '../errors';
import { ComputePosition } from '../ts-ast-util';
import type { ComputePosition } from '../ts-ast-util';
import { getFragmentsInDocument, getFragmentNamesInDocument, cloneFragmentMap } from '../gql-ast-util';
import { ExtractResult } from './extractor';
import type { ExtractResult } from './extractor';
import { OutOfRangeError } from '../string-util';

function calcEndPositionSafely(
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/extract.ts
@@ -1,4 +1,4 @@
import { CommandOptions } from '../parser';
import type { CommandOptions, CommandCliSetting } from '../parser';
import { ConsoleLogger } from '../logger';

export const cliDefinition = {
Expand All @@ -22,7 +22,7 @@ export const cliDefinition = {
type: 'boolean',
},
},
} as const;
} as const satisfies CommandCliSetting;

export async function extractCommand({ options }: CommandOptions<typeof cliDefinition>) {
const ts = require('typescript') as typeof import('typescript');
Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/report.ts
@@ -1,5 +1,5 @@
import path from 'path';
import { CommandOptions } from '../parser';
import path from 'node:path';
import type { CommandOptions, CommandCliSetting } from '../parser';
import { ConsoleLogger } from '../logger';

export const cliDefinition = {
Expand Down Expand Up @@ -32,7 +32,7 @@ export const cliDefinition = {
type: 'boolean',
},
},
} as const;
} as const satisfies CommandCliSetting;

export async function reportCommand({ options }: CommandOptions<typeof cliDefinition>) {
const ts = require('typescript') as typeof import('typescript');
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/typegen.ts
@@ -1,4 +1,4 @@
import { CommandOptions } from '../parser';
import type { CommandOptions, CommandCliSetting } from '../parser';
import { ConsoleLogger } from '../logger';

export const cliDefinition = {
Expand All @@ -16,7 +16,7 @@ export const cliDefinition = {
type: 'boolean',
},
},
} as const;
} as const satisfies CommandCliSetting;

export async function typegenCommand({ options }: CommandOptions<typeof cliDefinition>) {
const ts = require('typescript') as typeof import('typescript');
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/validate.ts
@@ -1,4 +1,4 @@
import { CommandOptions } from '../parser';
import type { CommandOptions, CommandCliSetting } from '../parser';
import { ConsoleLogger } from '../logger';

export const cliDefinition = {
Expand All @@ -20,7 +20,7 @@ export const cliDefinition = {
type: 'boolean',
},
},
} as const;
} as const satisfies CommandCliSetting;

export async function validateCommand({ options }: CommandOptions<typeof cliDefinition>) {
const { AnalyzerFactory } = require('../../analyzer') as typeof import('../../analyzer');
Expand Down
4 changes: 2 additions & 2 deletions src/errors/error-reporter.ts
@@ -1,6 +1,6 @@
import path from 'path';
import { TsGqlError, ErrorWithLocation, ErrorWithoutLocation } from '.';
import path from 'node:path';
import { pos2location, pad, color } from '../string-util';
import { type TsGqlError, ErrorWithLocation, ErrorWithoutLocation } from '.';

const lineMark = (line: number, width: number) => {
const strLine = line + 1 + '';
Expand Down
2 changes: 1 addition & 1 deletion src/gql-ast-util/fragment-registry.ts
@@ -1,4 +1,4 @@
import { parse, type DocumentNode, FragmentDefinitionNode, visit } from 'graphql';
import { parse, visit, type DocumentNode, type FragmentDefinitionNode } from 'graphql';
import { getFragmentDependenciesForAST } from 'graphql-language-service';
import { LRUCache } from '../cache';
import { getFragmentsInDocument, getFragmentNamesInDocument } from './utility-functions';
Expand Down
2 changes: 1 addition & 1 deletion src/gql-ast-util/utility-functions.ts
@@ -1,4 +1,4 @@
import { DocumentNode, FragmentDefinitionNode } from 'graphql';
import type { DocumentNode, FragmentDefinitionNode } from 'graphql';

export function getFragmentsInDocument(...documentNodes: (DocumentNode | undefined)[]) {
const fragmentDefs = new Map<string, FragmentDefinitionNode>();
Expand Down
@@ -1,6 +1,6 @@
import ts from 'typescript';
import type ts from 'typescript';
import { getAutocompleteSuggestions, type CompletionItem } from 'graphql-language-service';
import { AnalysisContext, GetCompletionAtPosition } from './types';
import type { AnalysisContext, GetCompletionAtPosition } from './types';
import { SimplePosition } from './simple-position';

function translateCompletionItems(items: CompletionItem[]): ts.CompletionInfo {
Expand Down
@@ -1,6 +1,6 @@
import ts from 'typescript';
import { getHoverInformation } from 'graphql-language-service';
import { AnalysisContext, GetQuickInfoAtPosition } from './types';
import type { AnalysisContext, GetQuickInfoAtPosition } from './types';
import { SimplePosition } from './simple-position';

export function getQuickInfoAtPosition(
Expand Down
Expand Up @@ -3,7 +3,7 @@ import type { FragmentDefinitionNode } from 'graphql';
import { getDiagnostics, type Diagnostic } from 'graphql-language-service';
import { SchemaBuildErrorInfo } from '../schema-manager/schema-manager';
import { ERROR_CODES } from '../errors';
import { AnalysisContext, GetSemanticDiagnostics } from './types';
import type { AnalysisContext, GetSemanticDiagnostics } from './types';
import { getSanitizedTemplateText } from '../ts-ast-util';
import { getFragmentsInDocument } from '../gql-ast-util';
import { OutOfRangeError } from '../string-util';
Expand Down
@@ -1,15 +1,15 @@
import ts from 'typescript';
import { GraphQLSchema, parse, type DocumentNode } from 'graphql';
import { parse, type GraphQLSchema, type DocumentNode } from 'graphql';
import {
getTemplateNodeUnder,
isTaggedTemplateNode,
ScriptSourceHelper,
StrictTagCondition,
isTemplateLiteralTypeNode,
type ScriptSourceHelper,
type StrictTagCondition,
} from '../ts-ast-util';
import { SchemaBuildErrorInfo } from '../schema-manager/schema-manager';
import type { SchemaBuildErrorInfo } from '../schema-manager/schema-manager';
import { getFragmentNamesInDocument, detectDuplicatedFragments, type FragmentRegistry } from '../gql-ast-util';
import { AnalysisContext, GetCompletionAtPosition, GetSemanticDiagnostics, GetQuickInfoAtPosition } from './types';
import type { AnalysisContext, GetCompletionAtPosition, GetSemanticDiagnostics, GetQuickInfoAtPosition } from './types';
import { getCompletionAtPosition } from './get-completion-at-position';
import { getSemanticDiagnostics } from './get-semantic-diagnostics';
import { getQuickInfoAtPosition } from './get-quick-info-at-position';
Expand All @@ -24,8 +24,6 @@ export interface GraphQLLanguageServiceAdapterCreateOptions {
fragmentRegistry: FragmentRegistry;
}

type Args<T> = T extends (...args: infer A) => any ? A : never;

export class GraphQLLanguageServiceAdapter {
private _schemaErrors?: SchemaBuildErrorInfo[] | null;
private _schema?: GraphQLSchema | null;
Expand All @@ -48,15 +46,15 @@ export class GraphQLLanguageServiceAdapter {
this._fragmentRegisry = opt.fragmentRegistry;
}

getCompletionAtPosition(delegate: GetCompletionAtPosition, ...args: Args<GetCompletionAtPosition>) {
getCompletionAtPosition(delegate: GetCompletionAtPosition, ...args: Parameters<GetCompletionAtPosition>) {
return getCompletionAtPosition(this._analysisContext, delegate, ...args);
}

getSemanticDiagnostics(delegate: GetSemanticDiagnostics, ...args: Args<GetSemanticDiagnostics>) {
getSemanticDiagnostics(delegate: GetSemanticDiagnostics, ...args: Parameters<GetSemanticDiagnostics>) {
return getSemanticDiagnostics(this._analysisContext, delegate, ...args);
}

getQuickInfoAtPosition(delegate: GetQuickInfoAtPosition, ...args: Args<GetQuickInfoAtPosition>) {
getQuickInfoAtPosition(delegate: GetQuickInfoAtPosition, ...args: Parameters<GetQuickInfoAtPosition>) {
return getQuickInfoAtPosition(this._analysisContext, delegate, ...args);
}

Expand Down
8 changes: 4 additions & 4 deletions src/graphql-language-service-adapter/types.ts
@@ -1,7 +1,7 @@
import ts from 'typescript';
import { GraphQLSchema, type DocumentNode, type FragmentDefinitionNode } from 'graphql';
import { ScriptSourceHelper, ResolveResult } from '../ts-ast-util';
import { SchemaBuildErrorInfo } from '../schema-manager/schema-manager';
import type ts from 'typescript';
import type { GraphQLSchema, DocumentNode, FragmentDefinitionNode } from 'graphql';
import type { ScriptSourceHelper, ResolveResult } from '../ts-ast-util';
import type { SchemaBuildErrorInfo } from '../schema-manager/schema-manager';

export type GetCompletionAtPosition = ts.LanguageService['getCompletionsAtPosition'];
export type GetSemanticDiagnostics = ts.LanguageService['getSemanticDiagnostics'];
Expand Down
@@ -1,4 +1,4 @@
import ts from 'typescript/lib/tsserverlibrary';
import type ts from 'typescript/lib/tsserverlibrary';

export type LanguageServiceMethodWrapper<K extends keyof ts.LanguageService> = (
delegate: ts.LanguageService[K],
Expand Down
2 changes: 1 addition & 1 deletion src/language-service-plugin/plugin-module-factory.ts
@@ -1,5 +1,5 @@
import ts from 'typescript/lib/tsserverlibrary';
import { TsGraphQLPluginConfigOptions } from '../types';
import type { TsGraphQLPluginConfigOptions } from '../types';
import { GraphQLLanguageServiceAdapter } from '../graphql-language-service-adapter';
import { SchemaManagerFactory, createSchemaManagerHostFromLSPluginInfo } from '../schema-manager';
import { FragmentRegistry } from '../gql-ast-util';
Expand Down
2 changes: 1 addition & 1 deletion src/register-hooks/register-typescript.ts
@@ -1,5 +1,5 @@
import fs from 'node:fs';
import type { CompilerOptions } from 'typescript';
import fs from 'fs';

export function registerTypeScript() {
let defaultCompileOptions: CompilerOptions;
Expand Down
8 changes: 4 additions & 4 deletions src/schema-manager/extension-manager.ts
@@ -1,7 +1,7 @@
import path from 'path';
import { GraphQLSchema, parse, extendSchema, DocumentNode, GraphQLError } from 'graphql';
import { SchemaBuildErrorInfo } from './schema-manager';
import { SchemaManagerHost } from './types';
import path from 'node:path';
import { parse, extendSchema, GraphQLError, type GraphQLSchema, type DocumentNode } from 'graphql';
import type { SchemaBuildErrorInfo } from './schema-manager';
import type { SchemaManagerHost } from './types';

export class ExtensionManager {
private _targetSdlFileNames: string[];
Expand Down
6 changes: 3 additions & 3 deletions src/schema-manager/file-schema-manager.ts
@@ -1,9 +1,9 @@
import path from 'path';
import ts from 'typescript/lib/tsserverlibrary';
import path from 'node:path';
import type ts from 'typescript';
import { buildSchema, buildClientSchema } from 'graphql';

import { SchemaManager } from './schema-manager';
import { SchemaManagerHost } from './types';
import type { SchemaManagerHost } from './types';

function extractIntrospectionContentFromJson(jsonObject: any) {
if (jsonObject.data) {
Expand Down
2 changes: 1 addition & 1 deletion src/schema-manager/http-schema-manager.ts
@@ -1,5 +1,5 @@
import { SchemaManager } from './schema-manager';
import { SchemaManagerHost } from './types';
import type { SchemaManagerHost } from './types';
import { requestIntrospectionQuery, type RequestSetup } from './request-introspection-query';

export class HttpSchemaManager extends SchemaManager {
Expand Down
8 changes: 4 additions & 4 deletions src/schema-manager/request-introspection-query.ts
@@ -1,7 +1,7 @@
import { GraphQLSchema, buildClientSchema, getIntrospectionQuery } from 'graphql';
import { parse } from 'url';
import Http from 'http';
import Https from 'https';
import { parse } from 'node:url';
import Http from 'node:http';
import Https from 'node:https';
import { buildClientSchema, getIntrospectionQuery, type GraphQLSchema } from 'graphql';

const INTROSPECTION_QUERY_BODY = JSON.stringify({
query: getIntrospectionQuery(),
Expand Down
2 changes: 1 addition & 1 deletion src/schema-manager/schema-manager-factory.ts
@@ -1,4 +1,4 @@
import { SchemaManagerHost } from './types';
import type { SchemaManagerHost } from './types';
import { SchemaManager, NoopSchemaManager } from './schema-manager';
import { FileSchemaManagerOptions, FileSchemaManager } from './file-schema-manager';
import { HttpSchemaManager } from './http-schema-manager';
Expand Down
8 changes: 4 additions & 4 deletions src/schema-manager/schema-manager-host.ts
@@ -1,7 +1,7 @@
import ts from 'typescript/lib/tsserverlibrary';
import path from 'path';
import { SchemaManagerHost, SchemaConfig } from './types';
import { TsGraphQLPluginConfigOptions } from '../types';
import path from 'node:path';
import ts from 'typescript';
import type { SchemaManagerHost, SchemaConfig } from './types';
import type { TsGraphQLPluginConfigOptions } from '../types';

class SystemSchemaManagerHost implements SchemaManagerHost {
constructor(
Expand Down
4 changes: 2 additions & 2 deletions src/schema-manager/schema-manager.ts
@@ -1,6 +1,6 @@
import { GraphQLSchema } from 'graphql';
import type { GraphQLSchema } from 'graphql';
import { ExtensionManager } from './extension-manager';
import { SchemaManagerHost } from './types';
import type { SchemaManagerHost } from './types';

export type SchemaBuildErrorInfo = {
message: string;
Expand Down
4 changes: 2 additions & 2 deletions src/schema-manager/scripted-http-schema-manager.ts
@@ -1,6 +1,6 @@
import { SchemaManagerHost } from './types';
import { join, isAbsolute } from 'node:path';
import type { SchemaManagerHost } from './types';
import { RequestSetup, isRequestSetup } from './request-introspection-query';
import { join, isAbsolute } from 'path';
import { HttpSchemaManager } from './http-schema-manager';

interface ScriptedHttpSchemaManagerOptions {
Expand Down
8 changes: 4 additions & 4 deletions src/transformer/transformer-host.ts
@@ -1,10 +1,10 @@
import ts from 'typescript';
import { Kind, type DocumentNode, FragmentDefinitionNode } from 'graphql';
import type ts from 'typescript';
import { Kind, type DocumentNode, type FragmentDefinitionNode } from 'graphql';
import { getFragmentDependenciesForAST } from 'graphql-language-service';
import { Analyzer, AnalyzerFactory, ExtractFileResult } from '../analyzer';
import { getTransformer, DocumentTransformer } from './transformer';
import { AnalyzerFactory, type Analyzer, type ExtractFileResult } from '../analyzer';
import { parseTagConfig } from '../ts-ast-util';
import { cloneFragmentMap, getFragmentNamesInDocument } from '../gql-ast-util';
import { getTransformer, type DocumentTransformer } from './transformer';

class DocumentNodeRegistory {
protected readonly _map = new Map<string, Map<number, DocumentNode>>();
Expand Down
2 changes: 1 addition & 1 deletion src/transformer/transformer.ts
@@ -1,5 +1,5 @@
import ts from 'typescript';
import { DocumentNode, print } from 'graphql';
import { print, type DocumentNode } from 'graphql';
import { astf, getTemplateNodeUnder, removeAliasFromImportDeclaration, type StrictTagCondition } from '../ts-ast-util';

export type DocumentTransformer = (documentNode: DocumentNode) => DocumentNode;
Expand Down
7 changes: 3 additions & 4 deletions src/ts-ast-util/output-source.ts
@@ -1,10 +1,9 @@
import path from 'path';
import path from 'node:path';
import ts from 'typescript';

import { OutputSource } from './types';
import { isImportDeclarationWithCondition, mergeImportDeclarationsWithSameModules } from './utilily-functions';

import type { OutputSource } from './types';
import { astf } from './ast-factory-alias';
import { isImportDeclarationWithCondition, mergeImportDeclarationsWithSameModules } from './utilily-functions';

const printer = ts.createPrinter();

Expand Down

0 comments on commit ef45afc

Please sign in to comment.