refactor: enforce type import specifiers (#6230)

* refactor: enforce type import specifiers

* fix

* Upgrade esbuild

* Fix (haha)
This commit is contained in:
Joshua Chen 2021-12-31 21:17:09 +08:00 committed by GitHub
parent 24d65d9bdd
commit cb1aa30286
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
192 changed files with 484 additions and 337 deletions

View file

@ -7,7 +7,7 @@
import path from 'path';
import {cliDocsVersionCommand} from '../cli';
import {PathOptions, SidebarOptions} from '../types';
import type {PathOptions, SidebarOptions} from '../types';
import fs from 'fs-extra';
import {
getVersionedDocsDirPath,

View file

@ -6,7 +6,7 @@
*/
import {validateDocFrontMatter} from '../docFrontMatter';
import {DocFrontMatter} from '../types';
import type {DocFrontMatter} from '../types';
import escapeStringRegexp from 'escape-string-regexp';
function testField(params: {

View file

@ -27,7 +27,7 @@ import type {
} from '../types';
import type {LoadContext} from '@docusaurus/types';
import {DEFAULT_OPTIONS} from '../options';
import {Optional} from 'utility-types';
import type {Optional} from 'utility-types';
import {createSlugger, posixPath, DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
import {createSidebarsUtils} from '../sidebars/utils';

View file

@ -13,7 +13,7 @@ import {
DisabledNumberPrefixParser,
} from '../numberPrefix';
import {GlobExcludeDefault} from '@docusaurus/utils';
import {PluginOptions} from '../types';
import type {PluginOptions} from '../types';
// the type of remark/rehype plugins is function
const markdownPluginsFunctionStub = () => {};

View file

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import {LoadedContent, DocMetadata, LoadedVersion} from '../types';
import type {LoadedContent, DocMetadata, LoadedVersion} from '../types';
import {CURRENT_VERSION_NAME} from '../constants';
import {
getLoadedContentTranslationFiles,

View file

@ -14,7 +14,7 @@ import {
} from '../versions';
import {DEFAULT_OPTIONS} from '../options';
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
import {PluginOptions, VersionMetadata} from '../types';
import type {PluginOptions, VersionMetadata} from '../types';
import type {I18n} from '@docusaurus/types';
const DefaultI18N: I18n = {

View file

@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/
import {CategoryGeneratedIndexMetadata, DocMetadataBase} from './types';
import {SidebarItemCategoryWithGeneratedIndex} from './sidebars/types';
import {SidebarsUtils, toNavigationLink} from './sidebars/utils';
import type {CategoryGeneratedIndexMetadata, DocMetadataBase} from './types';
import type {SidebarItemCategoryWithGeneratedIndex} from './sidebars/types';
import {type SidebarsUtils, toNavigationLink} from './sidebars/utils';
import {createDocsByIdIndex} from './docs';
function getCategoryGeneratedIndexMetadata({

View file

@ -6,14 +6,14 @@
*/
import {
ActivePlugin,
type ActivePlugin,
getActivePlugin,
getLatestVersion,
getActiveDocContext,
getActiveVersion,
getDocVersionSuggestions,
} from '../docsClientUtils';
import {GlobalPluginData, GlobalVersion} from '../../types';
import type {GlobalPluginData, GlobalVersion} from '../../types';
import {shuffle} from 'lodash';
describe('docsClientUtils', () => {

View file

@ -7,7 +7,7 @@
import {matchPath} from '@docusaurus/router';
import {GlobalPluginData, GlobalVersion, GlobalDoc} from '../types';
import type {GlobalPluginData, GlobalVersion, GlobalDoc} from '../types';
// This code is not part of the api surface, not in ./theme on purpose

View file

@ -22,7 +22,7 @@ import {
import type {LoadContext} from '@docusaurus/types';
import {getFileLastUpdate} from './lastUpdate';
import {
import type {
DocFile,
DocMetadataBase,
DocMetadata,
@ -38,11 +38,8 @@ import {CURRENT_VERSION_NAME} from './constants';
import {getDocsDirPaths} from './versions';
import {stripPathNumberPrefixes} from './numberPrefix';
import {validateDocFrontMatter} from './docFrontMatter';
import {
SidebarsUtils,
toDocNavigationLink,
toNavigationLink,
} from './sidebars/utils';
import type {SidebarsUtils} from './sidebars/utils';
import {toDocNavigationLink, toNavigationLink} from './sidebars/utils';
type LastUpdateOptions = Pick<
PluginOptions,

View file

@ -29,7 +29,7 @@ import {
} from './docs';
import {getDocsDirPaths, readVersionsMetadata} from './versions';
import {
import type {
PluginOptions,
LoadedContent,
SourceToPermalink,

View file

@ -8,7 +8,7 @@
import fs from 'fs-extra';
import path from 'path';
import {linkify} from '../linkify';
import {
import type {
DocsMarkdownOption,
SourceToPermalink,
VersionMetadata,

View file

@ -6,7 +6,7 @@
*/
import {linkify} from './linkify';
import {DocsMarkdownOption} from '../types';
import type {DocsMarkdownOption} from '../types';
import type {LoaderContext} from 'webpack';
export default function markdownLoader(

View file

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import {DocsMarkdownOption} from '../types';
import type {DocsMarkdownOption} from '../types';
import {getDocsDirPaths} from '../versions';
import {replaceMarkdownLinks} from '@docusaurus/utils';

View file

@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/
import {PluginContentLoadedActions, RouteConfig} from '@docusaurus/types';
import type {PluginContentLoadedActions, RouteConfig} from '@docusaurus/types';
import {docuHash, createSlugger} from '@docusaurus/utils';
import {
import type {
CategoryGeneratedIndexMetadata,
DocMetadata,
LoadedVersion,

View file

@ -5,8 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/
import {CategoryMetadataFile, DefaultSidebarItemsGenerator} from '../generator';
import {Sidebar, SidebarItemsGenerator} from '../types';
import {
DefaultSidebarItemsGenerator,
type CategoryMetadataFile,
} from '../generator';
import type {Sidebar, SidebarItemsGenerator} from '../types';
import fs from 'fs-extra';
import {DefaultNumberPrefixParser} from '../../numberPrefix';

View file

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import {processSidebars, SidebarProcessorParams} from '../processor';
import {processSidebars, type SidebarProcessorParams} from '../processor';
import type {
SidebarItem,
SidebarItemsGenerator,
@ -14,7 +14,7 @@ import type {
} from '../types';
import {DefaultSidebarItemsGenerator} from '../generator';
import {createSlugger} from '@docusaurus/utils';
import {VersionMetadata} from '../../types';
import type {VersionMetadata} from '../../types';
import {DefaultNumberPrefixParser} from '../../numberPrefix';
describe('processSidebars', () => {

View file

@ -12,12 +12,12 @@ import {
collectSidebarLinks,
transformSidebarItems,
collectSidebarsDocIds,
SidebarNavigation,
type SidebarNavigation,
toDocNavigationLink,
toNavigationLink,
} from '../utils';
import type {Sidebar, Sidebars} from '../types';
import {DocMetadataBase, DocNavLink} from '../../types';
import type {DocMetadataBase, DocNavLink} from '../../types';
describe('createSidebarsUtils', () => {
const sidebar1: Sidebar = [

View file

@ -6,8 +6,8 @@
*/
import {validateSidebars, validateCategoryMetadataFile} from '../validation';
import {CategoryMetadataFile} from '../generator';
import {SidebarsConfig} from '../types';
import type {CategoryMetadataFile} from '../generator';
import type {SidebarsConfig} from '../types';
describe('validateSidebars', () => {
// TODO add more tests

View file

@ -11,7 +11,7 @@ import type {SidebarsConfig, Sidebars, NormalizedSidebars} from './types';
import type {NormalizeSidebarsParams, PluginOptions} from '../types';
import {validateSidebars} from './validation';
import {normalizeSidebars} from './normalization';
import {processSidebars, SidebarProcessorParams} from './processor';
import {processSidebars, type SidebarProcessorParams} from './processor';
import path from 'path';
import {createSlugger} from '@docusaurus/utils';

View file

@ -30,7 +30,7 @@ import {DefaultSidebarItemsGenerator} from './generator';
import {mapValues, memoize, pick} from 'lodash';
import combinePromises from 'combine-promises';
import {normalizeItem} from './normalization';
import {Slugger} from '@docusaurus/utils';
import type {Slugger} from '@docusaurus/utils';
export type SidebarProcessorParams = {
sidebarItemsGenerator: SidebarItemsGeneratorOption;

View file

@ -5,14 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/
import type {Optional} from 'utility-types';
import type {Optional, Required} from 'utility-types';
import type {
DocMetadataBase,
VersionMetadata,
NumberPrefixParser,
SidebarOptions,
} from '../types';
import {Required} from 'utility-types';
// Makes all properties visible when hovering over the type
type Expand<T extends Record<string, unknown>> = {[P in keyof T]: T[P]};

View file

@ -15,17 +15,15 @@ import type {
SidebarItemType,
SidebarCategoriesShorthand,
SidebarItemConfig,
} from './types';
import {mapValues, difference, uniq} from 'lodash';
import {getElementsAround, toMessageRelativeFilePath} from '@docusaurus/utils';
import {DocMetadataBase, DocNavLink} from '../types';
import {
SidebarItemCategoryWithGeneratedIndex,
SidebarItemCategoryWithLink,
SidebarNavigationItem,
} from './types';
import {mapValues, difference, uniq} from 'lodash';
import {getElementsAround, toMessageRelativeFilePath} from '@docusaurus/utils';
import type {DocMetadataBase, DocNavLink} from '../types';
export function isCategoriesShorthand(
item: SidebarItemConfig,
): item is SidebarCategoriesShorthand {

View file

@ -20,7 +20,7 @@ import type {
SidebarItemCategoryLinkGeneratedIndex,
} from './types';
import {isCategoriesShorthand} from './utils';
import {CategoryMetadataFile} from './generator';
import type {CategoryMetadataFile} from './generator';
const sidebarItemBaseSchema = Joi.object<SidebarItemBase>({
className: Joi.string(),

View file

@ -11,17 +11,17 @@ import useGlobalData, {
usePluginData,
} from '@docusaurus/useGlobalData';
import {GlobalPluginData, GlobalVersion} from '../../types';
import type {GlobalPluginData, GlobalVersion} from '../../types';
import {
getActivePlugin,
getLatestVersion,
getActiveVersion,
getActiveDocContext,
getDocVersionSuggestions,
ActivePlugin,
ActiveDocContext,
DocVersionSuggestions,
GetActivePluginOptions,
type ActivePlugin,
type ActiveDocContext,
type DocVersionSuggestions,
type GetActivePluginOptions,
} from '../../client/docsClientUtils';
// Important to use a constant object to avoid React useEffect executions etc...,

View file

@ -23,10 +23,10 @@ import type {
TranslationFileContent,
TranslationFile,
TranslationFiles,
TranslationMessage,
} from '@docusaurus/types';
import {mergeTranslations} from '@docusaurus/utils';
import {CURRENT_VERSION_NAME} from './constants';
import {TranslationMessage} from '@docusaurus/types';
function getVersionFileName(versionName: string): string {
if (versionName === CURRENT_VERSION_NAME) {