From 5d449bd2c59a03aa1f405fe4feed00acf373d860 Mon Sep 17 00:00:00 2001 From: Bartosz Kaszubowski Date: Mon, 30 Nov 2020 11:33:28 +0100 Subject: [PATCH] fix several lint warnings, add missing types, cleanup --- .../index.js | 6 +- .../src/remark/transformImage/index.js | 17 +++--- packages/docusaurus-migrate/package.json | 3 +- packages/docusaurus-migrate/src/index.ts | 40 +++++++------- packages/docusaurus-migrate/src/sanitizeMD.ts | 10 +--- packages/docusaurus-migrate/src/transform.ts | 55 ++++++++++--------- .../src/collectRedirects.ts | 10 ++-- .../src/createRedirectPageContent.ts | 4 +- .../src/blogUtils.ts | 2 +- .../src/types.ts | 14 +++-- .../docusaurus-plugin-content-blog/types.d.ts | 2 +- .../src/docs.ts | 12 ++-- .../src/sidebars.ts | 4 +- .../src/slug.ts | 2 +- .../src/types.ts | 14 +++-- .../docusaurus-plugin-content-docs/types.d.ts | 2 +- .../src/index.ts | 2 +- .../src/types.ts | 14 +++-- .../types.d.ts | 2 +- .../src/createSitemap.ts | 22 ++++---- .../docusaurus-plugin-sitemap/src/types.ts | 3 +- .../docusaurus-theme-classic/src/index.ts | 2 +- .../src/theme/BlogSidebar/index.tsx | 2 +- .../src/theme/CodeBlock/index.tsx | 9 ++- .../src/theme/DocItem/index.tsx | 18 +++--- .../src/theme/LayoutProviders/index.tsx | 3 +- .../src/theme/SearchMetadatas/index.tsx | 2 +- .../docusaurus-theme-classic/src/types.d.ts | 9 +++ .../src/utils/pathUtils.ts | 2 +- .../src/utils/searchUtils.ts | 5 +- packages/docusaurus-types/src/index.d.ts | 5 +- .../src/__tests__/validationSchemas.test.ts | 4 +- .../src/validationUtils.ts | 2 +- packages/docusaurus-utils/src/index.ts | 6 +- packages/docusaurus/package.json | 1 + packages/docusaurus/src/choosePort.ts | 12 ++-- .../docusaurus/src/client/LinksCollector.tsx | 4 +- .../src/client/PendingNavigation.tsx | 5 +- .../baseUrlIssueBanner/BaseUrlIssueBanner.tsx | 2 +- .../src/client/exports/isInternalUrl.ts | 2 +- packages/docusaurus/src/server/brokenLinks.ts | 2 +- .../docusaurus/src/server/duplicateRoutes.ts | 7 +-- .../docusaurus/src/server/plugins/init.ts | 7 +-- .../src/server/plugins/pluginIds.ts | 4 +- packages/docusaurus/src/webpack/base.ts | 4 +- packages/docusaurus/src/webpack/utils.ts | 12 +++- yarn.lock | 21 ++++++- 47 files changed, 224 insertions(+), 168 deletions(-) diff --git a/packages/docusaurus-cssnano-preset/src/remove-overridden-custom-properties/index.js b/packages/docusaurus-cssnano-preset/src/remove-overridden-custom-properties/index.js index 2ee67fec8948..40058dfbc42f 100644 --- a/packages/docusaurus-cssnano-preset/src/remove-overridden-custom-properties/index.js +++ b/packages/docusaurus-cssnano-preset/src/remove-overridden-custom-properties/index.js @@ -28,11 +28,13 @@ module.exports = postcss.plugin( const sameProperties = decl.parent.nodes.filter((n) => n.prop === decl.prop) || []; const hasImportantProperties = sameProperties.some((p) => - p.hasOwnProperty('important'), + Object.prototype.hasOwnProperty.call(p, 'important'), ); const overriddenProperties = hasImportantProperties - ? sameProperties.filter((p) => !p.hasOwnProperty('important')) + ? sameProperties.filter( + (p) => !Object.prototype.hasOwnProperty.call(p, 'important'), + ) : sameProperties.slice(0, -1); overriddenProperties.map((p) => p.remove()); diff --git a/packages/docusaurus-mdx-loader/src/remark/transformImage/index.js b/packages/docusaurus-mdx-loader/src/remark/transformImage/index.js index 4d67ef9cd758..e7e178e59d17 100644 --- a/packages/docusaurus-mdx-loader/src/remark/transformImage/index.js +++ b/packages/docusaurus-mdx-loader/src/remark/transformImage/index.js @@ -18,21 +18,22 @@ const { } = getFileLoaderUtils(); const createJSX = (node, pathUrl) => { - node.type = 'jsx'; - node.value = ``; - if (node.url) { - delete node.url; + if (jsxNode.url) { + delete jsxNode.url; } - if (node.alt) { - delete node.alt; + if (jsxNode.alt) { + delete jsxNode.alt; } - if (node.title) { - delete node.title; + if (jsxNode.title) { + delete jsxNode.title; } }; diff --git a/packages/docusaurus-migrate/package.json b/packages/docusaurus-migrate/package.json index 02334da15c0c..0edf29ecdec3 100644 --- a/packages/docusaurus-migrate/package.json +++ b/packages/docusaurus-migrate/package.json @@ -1,7 +1,7 @@ { "name": "@docusaurus/migrate", "version": "2.0.0-alpha.69", - "description": "A cli tool to migrate between different version of docusuarus", + "description": "A cli tool to migrate between different version of Docusuarus", "main": "lib/index.js", "license": "MIT", "engines": { @@ -43,6 +43,7 @@ "unist-util-visit": "^2.0.2" }, "devDependencies": { + "@types/color": "^3.0.1", "@types/jscodeshift": "^0.7.1" } } diff --git a/packages/docusaurus-migrate/src/index.ts b/packages/docusaurus-migrate/src/index.ts index 58050295070b..c39b668d9852 100644 --- a/packages/docusaurus-migrate/src/index.ts +++ b/packages/docusaurus-migrate/src/index.ts @@ -12,10 +12,10 @@ import glob from 'glob'; import Color from 'color'; import { - VersionOneConfig, - VersionTwoConfig, ClassicPresetEntries, SidebarEntries, + VersionOneConfig, + VersionTwoConfig, } from './types'; import extractMetadata, {shouldQuotifyFrontMatter} from './frontMatter'; import migratePage from './transform'; @@ -229,9 +229,9 @@ export function createConfigFile({ const homePageId = siteConfig.headerLinks?.filter((value) => value.doc)[0] .doc; - const customConfigFields: Record = {}; + const customConfigFields: Record = {}; // add fields that are unknown to v2 to customConfigFields - Object.keys(siteConfig).forEach((key: any) => { + Object.keys(siteConfig).forEach((key) => { const knownFields = [ 'title', 'tagline', @@ -289,7 +289,7 @@ export function createConfigFile({ v2DocsPath = path.relative(newDir, absoluteDocsPath); } - const result: VersionTwoConfig = { + return { title: siteConfig.title ?? '', tagline: siteConfig.tagline, url: siteConfig.url ?? '', @@ -330,22 +330,24 @@ export function createConfigFile({ : undefined, items: (siteConfig.headerLinks ?? []) .map((link) => { - if (link.doc) { + const {doc, href, label, page} = link; + const position = 'left'; + if (doc) { return { - to: `docs/${link.doc === homePageId ? '' : link.doc}`, - label: link.label, - position: 'left', + to: `docs/${doc === homePageId ? '' : doc}`, + label, + position, }; } - if (link.page) { + if (page) { return { - to: `/${link.page}`, - label: link.label, - position: 'left', + to: `/${page}`, + label, + position, }; } - if (link.href) { - return {href: link.href, label: link.label, position: 'left'}; + if (href) { + return {href, label, position}; } return null; }) @@ -379,7 +381,6 @@ export function createConfigFile({ : undefined, }, }; - return result; } function createClientRedirects( @@ -476,7 +477,7 @@ function handleVersioning( const loadedVersions: Array = JSON.parse( String(fs.readFileSync(path.join(siteDir, 'versions.json'))), ); - fs.copyFile( + fs.copyFileSync( path.join(siteDir, 'versions.json'), path.join(newDir, 'versions.json'), ); @@ -732,11 +733,10 @@ function migrateLatestDocs( classicPreset: ClassicPresetEntries, ): void { if (fs.existsSync(path.join(siteDir, '..', 'docs'))) { - const docsPath = path.join( + classicPreset.docs.path = path.join( path.relative(newDir, path.join(siteDir, '..')), 'docs', ); - classicPreset.docs.path = docsPath; const files = walk(path.join(siteDir, '..', 'docs')); files.forEach((file) => { const content = String(fs.readFileSync(file)); @@ -797,5 +797,5 @@ export async function migrateMDToMDX( sanitizedFileContent(String(fs.readFileSync(file)), true), ); }); - console.log(`Succesfully migrated ${siteDir} to ${newDir}`); + console.log(`Successfully migrated ${siteDir} to ${newDir}`); } diff --git a/packages/docusaurus-migrate/src/sanitizeMD.ts b/packages/docusaurus-migrate/src/sanitizeMD.ts index c06843756763..c182073ffbb5 100644 --- a/packages/docusaurus-migrate/src/sanitizeMD.ts +++ b/packages/docusaurus-migrate/src/sanitizeMD.ts @@ -20,9 +20,7 @@ const tags = htmlTags.reduce((acc: {[key: string]: boolean}, tag) => { }, {}); export default function sanitizeMD(code: string): string { - const markdownTree = unified() - .use(markdown as any) - .parse(code); + const markdownTree = unified().use(markdown).parse(code); visit(markdownTree, 'code', (node) => { node.value = `\n\n`; }); @@ -31,12 +29,10 @@ export default function sanitizeMD(code: string): string { }); const markdownString = unified() - .use(remarkStringify as any, {fence: '`', fences: true}) + .use(remarkStringify, {fence: '`', fences: true}) .stringify(markdownTree); - const htmlTree = unified() - .use(parse as any) - .parse(markdownString); + const htmlTree = unified().use(parse).parse(markdownString); visit(htmlTree, 'element', (node) => { if (!tags[node.tagName as string]) { node.type = 'text'; diff --git a/packages/docusaurus-migrate/src/transform.ts b/packages/docusaurus-migrate/src/transform.ts index e8e7577dd5a6..6c034dadc78b 100644 --- a/packages/docusaurus-migrate/src/transform.ts +++ b/packages/docusaurus-migrate/src/transform.ts @@ -5,7 +5,14 @@ * LICENSE file in the root directory of this source tree. */ -import jscodeshift from 'jscodeshift'; +import jscodeshift, { + ArrowFunctionExpression, + AssignmentExpression, + ASTPath, + Collection, + TemplateElement, + VariableDeclarator, +} from 'jscodeshift'; const empty = () => jscodeshift.arrowFunctionExpression( @@ -18,16 +25,14 @@ const empty = () => ), ); -const property = (key: string, value: jscodeshift.ArrowFunctionExpression) => +const property = (key: string, value: ArrowFunctionExpression) => jscodeshift.objectProperty(jscodeshift.identifier(key), value); -const processCallExpression = ( - node: jscodeshift.ASTPath, -) => { +const processCallExpression = (node: ASTPath) => { const args = (node?.value?.init as any)?.arguments[0]; if (args.type === 'Literal') { if (args.value.includes('../../core/CompLibrary')) { - const newDeclartor = jscodeshift.variableDeclarator( + const newDeclarator = jscodeshift.variableDeclarator( node.value.id, jscodeshift.objectExpression([ property('Container', empty()), @@ -35,32 +40,30 @@ const processCallExpression = ( property('MarkdownBlock', empty()), ]), ); - jscodeshift(node).replaceWith(newDeclartor); + jscodeshift(node).replaceWith(newDeclarator); } } if (args.type === 'TemplateLiteral') { if ( args.quasis - .map((element: jscodeshift.TemplateElement) => element.value.raw) + .map((element: TemplateElement) => element.value.raw) .join('') .match(/\/core\//) ) { - const newDeclartor = jscodeshift.variableDeclarator( + const newDeclarator = jscodeshift.variableDeclarator( node.value.id, empty(), ); - jscodeshift(node).replaceWith(newDeclartor); + jscodeshift(node).replaceWith(newDeclarator); } } }; -const processMemberExpression = ( - node: jscodeshift.ASTPath, -) => { +const processMemberExpression = (node: ASTPath) => { const args = (node?.value?.init as any)?.object?.arguments[0]; if (args.type === 'Literal') { if (args.value === '../../core/CompLibrary.js') { - const newDeclartor = jscodeshift.variableDeclarator( + const newDeclarator = jscodeshift.variableDeclarator( node.value.id, jscodeshift.objectExpression([ property('Container', empty()), @@ -68,27 +71,27 @@ const processMemberExpression = ( property('MarkdownBlock', empty()), ]), ); - jscodeshift(node).replaceWith(newDeclartor); + jscodeshift(node).replaceWith(newDeclarator); } else if (args.value.match(/server/)) { - const newDeclartor = jscodeshift.variableDeclarator( + const newDeclarator = jscodeshift.variableDeclarator( node.value.id, empty(), ); - jscodeshift(node).replaceWith(newDeclartor); + jscodeshift(node).replaceWith(newDeclarator); } } if (args.type === 'TemplateLiteral') { if ( args.quasis - .map((ele: jscodeshift.TemplateElement) => ele.value.raw) + .map((ele: TemplateElement) => ele.value.raw) .join('') .match(/\/core\//) ) { - const newDeclartor = jscodeshift.variableDeclarator( + const newDeclarator = jscodeshift.variableDeclarator( node.value.id, empty(), ); - jscodeshift(node).replaceWith(newDeclartor); + jscodeshift(node).replaceWith(newDeclarator); } } }; @@ -113,7 +116,7 @@ export default function transformer(file: string): string { } root - .find(jscodeshift.AssignmentExpression, { + .find(AssignmentExpression, { operator: '=', left: { type: 'MemberExpression', @@ -164,10 +167,10 @@ export default function transformer(file: string): string { return root.toSource(); } -function getDefaultImportDeclarators(rootAst: jscodeshift.Collection) { +function getDefaultImportDeclarators(rootAst: Collection) { // var ... = require('y') return rootAst - .find(jscodeshift.VariableDeclarator, { + .find(VariableDeclarator, { init: { callee: { name: 'require', @@ -179,9 +182,9 @@ function getDefaultImportDeclarators(rootAst: jscodeshift.Collection) { }); } -function getNamedImportDeclarators(rootAst: jscodeshift.Collection) { +function getNamedImportDeclarators(rootAst: Collection) { // var ... = require('y').x - return rootAst.find(jscodeshift.VariableDeclarator, { + return rootAst.find(VariableDeclarator, { init: { object: { callee: { @@ -192,7 +195,7 @@ function getNamedImportDeclarators(rootAst: jscodeshift.Collection) { }); } -function getImportDeclaratorPaths(variableDeclaration: jscodeshift.Collection) { +function getImportDeclaratorPaths(variableDeclaration: Collection) { const defaultImports = getDefaultImportDeclarators(variableDeclaration); const namedImports = getNamedImportDeclarators(variableDeclaration); diff --git a/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts b/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts index 1a2541897d90..599990b2a436 100644 --- a/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts +++ b/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts @@ -85,11 +85,11 @@ It is not possible to redirect the same pathname to multiple destinations: } }, ); - redirects = uniqBy(redirects, (redirect) => redirect.from); + const collectedRedirects = uniqBy(redirects, (redirect) => redirect.from); // We don't want to override an already existing route with a redirect file! - const redirectsOverridingExistingPath = redirects.filter((redirect) => - pluginContext.relativeRoutesPaths.includes(redirect.from), + const redirectsOverridingExistingPath = collectedRedirects.filter( + (redirect) => pluginContext.relativeRoutesPaths.includes(redirect.from), ); if (redirectsOverridingExistingPath.length > 0) { console.error( @@ -100,11 +100,9 @@ It is not possible to redirect the same pathname to multiple destinations: ), ); } - redirects = redirects.filter( + return collectedRedirects.filter( (redirect) => !pluginContext.relativeRoutesPaths.includes(redirect.from), ); - - return redirects; } // For each plugin config option, create the appropriate redirects diff --git a/packages/docusaurus-plugin-client-redirects/src/createRedirectPageContent.ts b/packages/docusaurus-plugin-client-redirects/src/createRedirectPageContent.ts index 34cba18517fa..86f4060712d6 100644 --- a/packages/docusaurus-plugin-client-redirects/src/createRedirectPageContent.ts +++ b/packages/docusaurus-plugin-client-redirects/src/createRedirectPageContent.ts @@ -17,14 +17,14 @@ const getCompiledRedirectPageTemplate = memoize(() => { return eta.compile(redirectPageTemplate.trim()); }); -function renderRedirectPageTemplate(data: object) { +function renderRedirectPageTemplate(data: Record) { const compiled = getCompiledRedirectPageTemplate(); return compiled(data, eta.defaultConfig); } export default function createRedirectPageContent({ toUrl, -}: CreateRedirectPageOptions) { +}: CreateRedirectPageOptions): string { return renderRedirectPageTemplate({ toUrl: encodeURI(toUrl), }); diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index 6c1963cd8f8a..e9486fe65daf 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -272,6 +272,6 @@ export function linkify({ } // Order matters: we look in priority in localized folder -export function getContentPathList(contentPaths: BlogContentPaths) { +export function getContentPathList(contentPaths: BlogContentPaths): string[] { return [contentPaths.contentPathLocalized, contentPaths.contentPath]; } diff --git a/packages/docusaurus-plugin-content-blog/src/types.ts b/packages/docusaurus-plugin-content-blog/src/types.ts index 93554fda5a04..159ecd64afc1 100644 --- a/packages/docusaurus-plugin-content-blog/src/types.ts +++ b/packages/docusaurus-plugin-content-blog/src/types.ts @@ -38,9 +38,15 @@ export interface PluginOptions { blogDescription: string; blogSidebarCount: number | 'ALL'; blogSidebarTitle: string; - remarkPlugins: ([Function, object] | Function)[]; - beforeDefaultRehypePlugins: ([Function, object] | Function)[]; - beforeDefaultRemarkPlugins: ([Function, object] | Function)[]; + remarkPlugins: ([Function, Record] | Function)[]; + beforeDefaultRehypePlugins: ( + | [Function, Record] + | Function + )[]; + beforeDefaultRemarkPlugins: ( + | [Function, Record] + | Function + )[]; rehypePlugins: string[]; truncateMarker: RegExp; showReadingTime: boolean; @@ -52,7 +58,7 @@ export interface PluginOptions { language?: string; }; editUrl?: string; - admonitions: any; + admonitions: Record; } export interface BlogTags { diff --git a/packages/docusaurus-plugin-content-blog/types.d.ts b/packages/docusaurus-plugin-content-blog/types.d.ts index c0c9f3a8ec03..c9976d8a584b 100644 --- a/packages/docusaurus-plugin-content-blog/types.d.ts +++ b/packages/docusaurus-plugin-content-blog/types.d.ts @@ -6,7 +6,7 @@ */ declare module 'remark-admonitions' { - type Options = any; + type Options = Record; const plugin: (options?: Options) => void; export = plugin; diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index 0439b8e6dc52..a635f91737cb 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -9,21 +9,21 @@ import path from 'path'; import fs from 'fs-extra'; import { aliasedSitePath, - normalizeUrl, getEditUrl, - parseMarkdownString, getFolderContainingFile, + normalizeUrl, + parseMarkdownString, } from '@docusaurus/utils'; import {LoadContext} from '@docusaurus/types'; import {getFileLastUpdate} from './lastUpdate'; import { + DocFile, DocMetadataBase, LastUpdateData, MetadataOptions, - VersionMetadata, - DocFile, PluginOptions, + VersionMetadata, } from './types'; import getSlug from './slug'; import {CURRENT_VERSION_NAME} from './constants'; @@ -173,7 +173,7 @@ export function processDocMetadata({ // NodeJS optimization. // Adding properties to object after instantiation will cause hidden // class transitions. - const metadata: DocMetadataBase = { + return { unversionedId, id, isDocsHomePage, @@ -188,6 +188,4 @@ export function processDocMetadata({ lastUpdatedAt: lastUpdate.lastUpdatedAt, sidebar_label, }; - - return metadata; } diff --git a/packages/docusaurus-plugin-content-docs/src/sidebars.ts b/packages/docusaurus-plugin-content-docs/src/sidebars.ts index fba543f0558d..8d2926aeebd5 100644 --- a/packages/docusaurus-plugin-content-docs/src/sidebars.ts +++ b/packages/docusaurus-plugin-content-docs/src/sidebars.ts @@ -268,7 +268,9 @@ export function collectSidebarsDocIds( }); } -export function createSidebarsUtils(sidebars: Sidebars) { +export function createSidebarsUtils( + sidebars: Sidebars, +): Record { const sidebarNameToDocIds = collectSidebarsDocIds(sidebars); function getFirstDocIdOfFirstSidebar(): string | undefined { diff --git a/packages/docusaurus-plugin-content-docs/src/slug.ts b/packages/docusaurus-plugin-content-docs/src/slug.ts index 4c25aae6358d..84d0397336a3 100644 --- a/packages/docusaurus-plugin-content-docs/src/slug.ts +++ b/packages/docusaurus-plugin-content-docs/src/slug.ts @@ -21,7 +21,7 @@ export default function getSlug({ frontmatterSlug?: string; dirName: string; }): string { - const baseSlug: string = frontmatterSlug || baseID; + const baseSlug = frontmatterSlug || baseID; let slug: string; if (baseSlug.startsWith('/')) { slug = baseSlug; diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index 0022ab30294d..0152a211f3ba 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -59,11 +59,17 @@ export type PluginOptions = MetadataOptions & include: string[]; docLayoutComponent: string; docItemComponent: string; - remarkPlugins: ([Function, object] | Function)[]; + remarkPlugins: ([Function, Record] | Function)[]; rehypePlugins: string[]; - beforeDefaultRemarkPlugins: ([Function, object] | Function)[]; - beforeDefaultRehypePlugins: ([Function, object] | Function)[]; - admonitions: any; + beforeDefaultRemarkPlugins: ( + | [Function, Record] + | Function + )[]; + beforeDefaultRehypePlugins: ( + | [Function, Record] + | Function + )[]; + admonitions: Record; disableVersioning: boolean; excludeNextVersionDocs?: boolean; includeCurrentVersion: boolean; diff --git a/packages/docusaurus-plugin-content-docs/types.d.ts b/packages/docusaurus-plugin-content-docs/types.d.ts index c0c9f3a8ec03..c9976d8a584b 100644 --- a/packages/docusaurus-plugin-content-docs/types.d.ts +++ b/packages/docusaurus-plugin-content-docs/types.d.ts @@ -6,7 +6,7 @@ */ declare module 'remark-admonitions' { - type Options = any; + type Options = Record; const plugin: (options?: Options) => void; export = plugin; diff --git a/packages/docusaurus-plugin-content-pages/src/index.ts b/packages/docusaurus-plugin-content-pages/src/index.ts index 3e7e3db32f87..68c2ea9c08e8 100644 --- a/packages/docusaurus-plugin-content-pages/src/index.ts +++ b/packages/docusaurus-plugin-content-pages/src/index.ts @@ -42,7 +42,7 @@ import { } from './types'; import {flatten} from 'lodash'; -export function getContentPathList(contentPaths: PagesContentPaths) { +export function getContentPathList(contentPaths: PagesContentPaths): string[] { return [contentPaths.contentPathLocalized, contentPaths.contentPath]; } diff --git a/packages/docusaurus-plugin-content-pages/src/types.ts b/packages/docusaurus-plugin-content-pages/src/types.ts index f53e1f115d23..b1b6cab22780 100644 --- a/packages/docusaurus-plugin-content-pages/src/types.ts +++ b/packages/docusaurus-plugin-content-pages/src/types.ts @@ -12,11 +12,17 @@ export interface PluginOptions { include: string[]; exclude: string[]; mdxPageComponent: string; - remarkPlugins: ([Function, object] | Function)[]; + remarkPlugins: ([Function, Record] | Function)[]; rehypePlugins: string[]; - beforeDefaultRemarkPlugins: ([Function, object] | Function)[]; - beforeDefaultRehypePlugins: ([Function, object] | Function)[]; - admonitions: any; + beforeDefaultRemarkPlugins: ( + | [Function, Record] + | Function + )[]; + beforeDefaultRehypePlugins: ( + | [Function, Record] + | Function + )[]; + admonitions: Record; } export type JSXPageMetadata = { diff --git a/packages/docusaurus-plugin-content-pages/types.d.ts b/packages/docusaurus-plugin-content-pages/types.d.ts index c0c9f3a8ec03..c9976d8a584b 100644 --- a/packages/docusaurus-plugin-content-pages/types.d.ts +++ b/packages/docusaurus-plugin-content-pages/types.d.ts @@ -6,7 +6,7 @@ */ declare module 'remark-admonitions' { - type Options = any; + type Options = Record; const plugin: (options?: Options) => void; export = plugin; diff --git a/packages/docusaurus-plugin-sitemap/src/createSitemap.ts b/packages/docusaurus-plugin-sitemap/src/createSitemap.ts index de3b1cb80b0d..bb2a639863ee 100644 --- a/packages/docusaurus-plugin-sitemap/src/createSitemap.ts +++ b/packages/docusaurus-plugin-sitemap/src/createSitemap.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import sitemap, {SitemapItemOptions} from 'sitemap'; +import sitemap, {Sitemap, SitemapItemOptions} from 'sitemap'; import {PluginOptions} from './types'; import {DocusaurusConfig} from '@docusaurus/types'; @@ -13,28 +13,26 @@ export default function createSitemap( siteConfig: DocusaurusConfig, routesPaths: string[], options: PluginOptions, -): sitemap.Sitemap { +): Sitemap { const {url: hostname} = siteConfig; if (!hostname) { throw new Error('url in docusaurus.config.js cannot be empty/undefined'); } + const {cacheTime, changefreq, priority, trailingSlash} = options; const urls = routesPaths - .filter((route: string) => !route.endsWith('404.html')) + .filter((route) => !route.endsWith('404.html')) .map( - (routesPath) => - ({ - url: `${routesPath}${ - options.trailingSlash && routesPath !== '/' ? '/' : '' - }`, - changefreq: options.changefreq, - priority: options.priority, - } as SitemapItemOptions), + (routesPath): SitemapItemOptions => ({ + url: `${routesPath}${trailingSlash && routesPath !== '/' ? '/' : ''}`, + changefreq, + priority, + }), ); return sitemap.createSitemap({ hostname, - cacheTime: options.cacheTime, + cacheTime, urls, }); } diff --git a/packages/docusaurus-plugin-sitemap/src/types.ts b/packages/docusaurus-plugin-sitemap/src/types.ts index ad818c8ae318..fc24fb038991 100644 --- a/packages/docusaurus-plugin-sitemap/src/types.ts +++ b/packages/docusaurus-plugin-sitemap/src/types.ts @@ -4,10 +4,11 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ +import {EnumChangefreq} from 'sitemap'; export interface PluginOptions { cacheTime?: number; - changefreq?: string; + changefreq?: EnumChangefreq; priority?: number; trailingSlash?: boolean; } diff --git a/packages/docusaurus-theme-classic/src/index.ts b/packages/docusaurus-theme-classic/src/index.ts index 1b2b949a1fab..ad7510a65559 100644 --- a/packages/docusaurus-theme-classic/src/index.ts +++ b/packages/docusaurus-theme-classic/src/index.ts @@ -151,7 +151,7 @@ const swizzleAllowedComponents = [ 'prism-include-languages', ]; -export function getSwizzleComponentList() { +export function getSwizzleComponentList(): string[] { return swizzleAllowedComponents; } diff --git a/packages/docusaurus-theme-classic/src/theme/BlogSidebar/index.tsx b/packages/docusaurus-theme-classic/src/theme/BlogSidebar/index.tsx index 1d755bc295c3..2adf2dbaaff8 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogSidebar/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/BlogSidebar/index.tsx @@ -11,7 +11,7 @@ import Link from '@docusaurus/Link'; import type {Props} from '@theme/BlogSidebar'; import styles from './styles.module.css'; -export default function BlogSidebar({sidebar}: Props) { +export default function BlogSidebar({sidebar}: Props): JSX.Element | null { if (sidebar.items.length === 0) { return null; } diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx index 3c86b916b86d..6bc91278e4a1 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx @@ -113,9 +113,7 @@ export default ({ const prismTheme = usePrismTheme(); // In case interleaved Markdown (e.g. when using CodeBlock as standalone component). - if (Array.isArray(children)) { - children = children.join(''); - } + const content = Array.isArray(children) ? children.join('') : children; if (metastring && highlightLinesRangeRegex.test(metastring)) { // Tested above @@ -133,6 +131,7 @@ export default ({ let language = languageClassName && // Force Prism's language union type to `any` because it does not contain all available languages + // eslint-disable-next-line @typescript-eslint/no-explicit-any ((languageClassName.replace(/language-/, '') as Language) as any); if (!language && prism.defaultLanguage) { @@ -140,12 +139,12 @@ export default ({ } // only declaration OR directive highlight can be used for a block - let code = children.replace(/\n$/, ''); + let code = content.replace(/\n$/, ''); if (highlightLines.length === 0 && language !== undefined) { let range = ''; const directiveRegex = highlightDirectiveRegex(language); // go through line by line - const lines = children.replace(/\n$/, '').split('\n'); + const lines = content.replace(/\n$/, '').split('\n'); let blockStart; // loop through lines for (let index = 0; index < lines.length; ) { diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx index 9e4025237ade..6f0e6627d77b 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx @@ -27,16 +27,8 @@ function DocItem(props: Props): JSX.Element { const {siteConfig} = useDocusaurusContext(); const {url: siteUrl, title: siteTitle, titleDelimiter} = siteConfig; const {content: DocContent} = props; - const {metadata} = DocContent; - const { - description, - title, - permalink, - editUrl, - lastUpdatedAt, - lastUpdatedBy, - } = metadata; const { + metadata, frontMatter: { image: metaImage, keywords, @@ -44,6 +36,14 @@ function DocItem(props: Props): JSX.Element { hide_table_of_contents: hideTableOfContents, }, } = DocContent; + const { + description, + title, + permalink, + editUrl, + lastUpdatedAt, + lastUpdatedBy, + } = metadata; const {pluginId} = useActivePlugin({failfast: true}); const versions = useVersions(pluginId); diff --git a/packages/docusaurus-theme-classic/src/theme/LayoutProviders/index.tsx b/packages/docusaurus-theme-classic/src/theme/LayoutProviders/index.tsx index 710cfb0218a2..3bb0fa48dab6 100644 --- a/packages/docusaurus-theme-classic/src/theme/LayoutProviders/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/LayoutProviders/index.tsx @@ -9,8 +9,9 @@ import React from 'react'; import ThemeProvider from '@theme/ThemeProvider'; import UserPreferencesProvider from '@theme/UserPreferencesProvider'; import {DocsPreferredVersionContextProvider} from '@docusaurus/theme-common'; +import {Props} from '@theme/LayoutProviders'; -export default function LayoutProviders({children}) { +export default function LayoutProviders({children}: Props): JSX.Element { return ( diff --git a/packages/docusaurus-theme-classic/src/theme/SearchMetadatas/index.tsx b/packages/docusaurus-theme-classic/src/theme/SearchMetadatas/index.tsx index 6c8886801e5b..bb66c40f5102 100644 --- a/packages/docusaurus-theme-classic/src/theme/SearchMetadatas/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/SearchMetadatas/index.tsx @@ -22,7 +22,7 @@ export default function SearchMetadatas({ locale, version, tag, -}: SearchTagMetaProps) { +}: SearchTagMetaProps): JSX.Element { return ( {locale && } diff --git a/packages/docusaurus-theme-classic/src/types.d.ts b/packages/docusaurus-theme-classic/src/types.d.ts index 79f7631c4ced..b2668f711b58 100644 --- a/packages/docusaurus-theme-classic/src/types.d.ts +++ b/packages/docusaurus-theme-classic/src/types.d.ts @@ -440,6 +440,15 @@ declare module '@theme/UserPreferencesProvider' { export default UserPreferencesProvider; } +declare module '@theme/LayoutProviders' { + import type {ReactNode} from 'react'; + + export type Props = {readonly children: ReactNode}; + + const LayoutProviders: (props: Props) => JSX.Element; + export default LayoutProviders; +} + declare module '@theme/ThemeContext' { import type {Context} from 'react'; import type {ThemeContextProps} from '@theme/hooks/useThemeContext'; diff --git a/packages/docusaurus-theme-common/src/utils/pathUtils.ts b/packages/docusaurus-theme-common/src/utils/pathUtils.ts index d2b769cab124..c88e1b6588a1 100644 --- a/packages/docusaurus-theme-common/src/utils/pathUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/pathUtils.ts @@ -9,7 +9,7 @@ export const isSamePath = ( path1: string | undefined, path2: string | undefined, -) => { +): boolean => { const normalize = (pathname: string | undefined) => { return !pathname || pathname?.endsWith('/') ? pathname : `${pathname}/`; }; diff --git a/packages/docusaurus-theme-common/src/utils/searchUtils.ts b/packages/docusaurus-theme-common/src/utils/searchUtils.ts index ae1dba0261ca..daa93c9c4db1 100644 --- a/packages/docusaurus-theme-common/src/utils/searchUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/searchUtils.ts @@ -7,6 +7,9 @@ export const DEFAULT_SEARCH_TAG = 'default'; -export function docVersionSearchTag(pluginId: string, versionName: string) { +export function docVersionSearchTag( + pluginId: string, + versionName: string, +): string { return `docs-${pluginId}-${versionName}`; } diff --git a/packages/docusaurus-types/src/index.d.ts b/packages/docusaurus-types/src/index.d.ts index 107541525d6b..8b24666380c5 100644 --- a/packages/docusaurus-types/src/index.d.ts +++ b/packages/docusaurus-types/src/index.d.ts @@ -336,7 +336,10 @@ export interface ThemeConfigValidationContext { // TODO we should use a Joi type here export interface ValidationSchema { - validate(options: Partial, opt: object): ValidationResult; + validate( + options: Partial, + opt: Record, + ): ValidationResult; unknown(): ValidationSchema; append(data: any): ValidationSchema; } diff --git a/packages/docusaurus-utils-validation/src/__tests__/validationSchemas.test.ts b/packages/docusaurus-utils-validation/src/__tests__/validationSchemas.test.ts index 19b38f77b8fc..39a4ee55be67 100644 --- a/packages/docusaurus-utils-validation/src/__tests__/validationSchemas.test.ts +++ b/packages/docusaurus-utils-validation/src/__tests__/validationSchemas.test.ts @@ -19,7 +19,7 @@ function createTestHelpers({ schema, defaultValue, }: { - schema: Joi.SchemaLike; + schema: Joi.Schema; defaultValue?: unknown; }) { function testOK(value: unknown) { @@ -36,7 +36,7 @@ function createTestHelpers({ return {testOK, testFail}; } -function testMarkdownPluginSchemas(schema: Joi.SchemaLike) { +function testMarkdownPluginSchemas(schema: Joi.Schema) { const {testOK, testFail} = createTestHelpers({ schema, defaultValue: [], diff --git a/packages/docusaurus-utils-validation/src/validationUtils.ts b/packages/docusaurus-utils-validation/src/validationUtils.ts index acfc0822142a..5a270dc4f243 100644 --- a/packages/docusaurus-utils-validation/src/validationUtils.ts +++ b/packages/docusaurus-utils-validation/src/validationUtils.ts @@ -25,7 +25,7 @@ if (isValidationDisabledEscapeHatch) { ); } -export const logValidationBugReportHint = () => { +export const logValidationBugReportHint = (): void => { console.log( `\n${chalk.red('A validation error occured.')}${chalk.cyanBright( '\nThe validation system was added recently to Docusaurus as an attempt to avoid user configuration errors.' + diff --git a/packages/docusaurus-utils/src/index.ts b/packages/docusaurus-utils/src/index.ts index 88644f48c5c0..22fd61f7b6c3 100644 --- a/packages/docusaurus-utils/src/index.ts +++ b/packages/docusaurus-utils/src/index.ts @@ -266,7 +266,7 @@ export function parseMarkdownString(markdownString: string): ParsedMarkdown { return {frontMatter, content, excerpt}; } catch (e) { throw new Error(`Error while parsing markdown front matter. -This can happen if you use special characteres like : in frontmatter values (try using "" around that value) +This can happen if you use special characters like : in frontmatter values (try using "" around that value) ${e.message}`); } } @@ -394,7 +394,7 @@ export function isValidPathname(str: string): boolean { } // resolve pathname and fail fast if resolution fails -export function resolvePathname(to: string, from?: string) { +export function resolvePathname(to: string, from?: string): string { return resolvePathnameUnsafe(to, from); } export function addLeadingSlash(str: string): string { @@ -456,7 +456,7 @@ export function getPluginI18nPath({ pluginName: string; pluginId?: string | undefined; subPaths?: string[]; -}) { +}): string { return path.join( siteDir, 'i18n', diff --git a/packages/docusaurus/package.json b/packages/docusaurus/package.json index 0f51f97c63c7..0021b54af5d2 100644 --- a/packages/docusaurus/package.json +++ b/packages/docusaurus/package.json @@ -33,6 +33,7 @@ "devDependencies": { "@docusaurus/module-type-aliases": "2.0.0-alpha.69", "@types/detect-port": "^1.3.0", + "@types/nprogress": "^0.2.0", "tmp-promise": "^3.0.2" }, "dependencies": { diff --git a/packages/docusaurus/src/choosePort.ts b/packages/docusaurus/src/choosePort.ts index 8a07bfe2e77a..62f973ec98bb 100644 --- a/packages/docusaurus/src/choosePort.ts +++ b/packages/docusaurus/src/choosePort.ts @@ -18,7 +18,7 @@ import inquirer from 'inquirer'; const isInteractive = process.stdout.isTTY; -const execOptions: object = { +const execOptions: Record = { encoding: 'utf8', stdio: [ 'pipe', // stdin (default) @@ -43,15 +43,13 @@ function getProcessIdOnPort(port: number): string { } // Gets process command -function getProcessCommand(processId: string): Promise | string { - let command: Buffer | string = execSync( +function getProcessCommand(processId: string): string { + const command: Buffer = execSync( `ps -o command -p ${processId} | sed -n 2p`, execOptions, ); - command = command.toString().replace(/\n$/, ''); - - return command; + return command.toString().replace(/\n$/, ''); } // Gets directory of a process from its process id @@ -103,7 +101,7 @@ export default async function choosePort( if (isInteractive) { clearConsole(); const existingProcess = getProcessForPort(defaultPort); - const question: any = { + const question: Record = { type: 'confirm', name: 'shouldChangePort', message: `${chalk.yellow( diff --git a/packages/docusaurus/src/client/LinksCollector.tsx b/packages/docusaurus/src/client/LinksCollector.tsx index f38de070203b..bf15a67d71af 100644 --- a/packages/docusaurus/src/client/LinksCollector.tsx +++ b/packages/docusaurus/src/client/LinksCollector.tsx @@ -35,7 +35,7 @@ const Context = createContext({ }, }); -export const useLinksCollector = () => { +export const useLinksCollector = (): LinksCollector => { return useContext(Context); }; @@ -45,6 +45,6 @@ export const ProvideLinksCollector = ({ }: { children: ReactNode; linksCollector: LinksCollector; -}) => { +}): JSX.Element => { return {children}; }; diff --git a/packages/docusaurus/src/client/PendingNavigation.tsx b/packages/docusaurus/src/client/PendingNavigation.tsx index 1b2ae12ec1e6..0af38d3543ff 100644 --- a/packages/docusaurus/src/client/PendingNavigation.tsx +++ b/packages/docusaurus/src/client/PendingNavigation.tsx @@ -7,6 +7,7 @@ import React from 'react'; import {Route, withRouter} from 'react-router-dom'; +import {RouteConfig} from 'react-router-config'; import nprogress from 'nprogress'; import clientLifecyclesDispatcher from './client-lifecycles-dispatcher'; @@ -18,7 +19,7 @@ import './nprogress.css'; nprogress.configure({showSpinner: false}); interface Props { - routes: any[]; + routes: RouteConfig[]; delay: number; location: any; } @@ -104,7 +105,7 @@ class PendingNavigation extends React.Component { } } - startProgressBar(delay) { + startProgressBar(delay: number) { this.clearProgressBarTimeout(); this.progressBarTimeout = setTimeout(() => { clientLifecyclesDispatcher.onRouteUpdateDelayed({ diff --git a/packages/docusaurus/src/client/baseUrlIssueBanner/BaseUrlIssueBanner.tsx b/packages/docusaurus/src/client/baseUrlIssueBanner/BaseUrlIssueBanner.tsx index 25a59b644836..4eb41e5f5761 100644 --- a/packages/docusaurus/src/client/baseUrlIssueBanner/BaseUrlIssueBanner.tsx +++ b/packages/docusaurus/src/client/baseUrlIssueBanner/BaseUrlIssueBanner.tsx @@ -18,7 +18,7 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; // Note: it might create false positives (ie network failures): not a big deal // Note: we only inline this for the homepage to avoid polluting all the site's pages // See https://github.com/facebook/docusaurus/pull/3621 -export default function BaseUrlIssueBanner() { +export default function BaseUrlIssueBanner(): JSX.Element | null { const { siteConfig: {baseUrl, baseUrlIssueBanner}, } = useDocusaurusContext(); diff --git a/packages/docusaurus/src/client/exports/isInternalUrl.ts b/packages/docusaurus/src/client/exports/isInternalUrl.ts index d4755e658ab9..eb503cb54c5e 100644 --- a/packages/docusaurus/src/client/exports/isInternalUrl.ts +++ b/packages/docusaurus/src/client/exports/isInternalUrl.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -export function hasProtocol(url: string) { +export function hasProtocol(url: string): boolean { return /^(\w*:|\/\/)/.test(url) === true; } diff --git a/packages/docusaurus/src/server/brokenLinks.ts b/packages/docusaurus/src/server/brokenLinks.ts index 81bc58fac1c9..a4e0d5c4c48a 100644 --- a/packages/docusaurus/src/server/brokenLinks.ts +++ b/packages/docusaurus/src/server/brokenLinks.ts @@ -202,7 +202,7 @@ export async function handleBrokenLinks({ routes: RouteConfig[]; baseUrl: string; outDir: string; -}) { +}): Promise { if (onBrokenLinks === 'ignore') { return; } diff --git a/packages/docusaurus/src/server/duplicateRoutes.ts b/packages/docusaurus/src/server/duplicateRoutes.ts index 54af2aa70ad8..147cca896e75 100644 --- a/packages/docusaurus/src/server/duplicateRoutes.ts +++ b/packages/docusaurus/src/server/duplicateRoutes.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -import {RouteConfig, ReportingSeverity} from '@docusaurus/types'; +import {ReportingSeverity, RouteConfig} from '@docusaurus/types'; import {reportMessage} from '@docusaurus/utils'; import {getAllFinalRoutes} from './utils'; @@ -15,15 +15,14 @@ export function getAllDuplicateRoutes( (routeConfig) => routeConfig.path, ); const seenRoutes: Record = {}; - const duplicateRoutes: string[] = allRoutes.filter(function (route) { - if (seenRoutes.hasOwnProperty(route)) { + return allRoutes.filter((route) => { + if (Object.prototype.hasOwnProperty.call(seenRoutes, route)) { return true; } else { seenRoutes[route] = true; return false; } }); - return duplicateRoutes; } export function getDuplicateRoutesMessage( diff --git a/packages/docusaurus/src/server/plugins/init.ts b/packages/docusaurus/src/server/plugins/init.ts index d7e9de0e4205..4b5979f7cc09 100644 --- a/packages/docusaurus/src/server/plugins/init.ts +++ b/packages/docusaurus/src/server/plugins/init.ts @@ -9,11 +9,11 @@ import Module from 'module'; import {join} from 'path'; import importFresh from 'import-fresh'; import { + DocusaurusPluginVersionInformation, LoadContext, Plugin, - PluginOptions, PluginConfig, - DocusaurusPluginVersionInformation, + PluginOptions, } from '@docusaurus/types'; import {CONFIG_FILE_NAME, DEFAULT_PLUGIN_ID} from '../../constants'; import {getPluginVersion} from '../versions'; @@ -74,11 +74,10 @@ export default function initPlugins({ pluginModule.default?.validateOptions ?? pluginModule.validateOptions; if (validateOptions) { - const normalizedOptions = validateOptions({ + pluginOptions = validateOptions({ validate: normalizePluginOptions, options: pluginOptions, }); - pluginOptions = normalizedOptions; } else { // Important to ensure all plugins have an id // as we don't go through the Joi schema that adds it diff --git a/packages/docusaurus/src/server/plugins/pluginIds.ts b/packages/docusaurus/src/server/plugins/pluginIds.ts index e3fff3b9dd38..7c4c0288337e 100644 --- a/packages/docusaurus/src/server/plugins/pluginIds.ts +++ b/packages/docusaurus/src/server/plugins/pluginIds.ts @@ -9,9 +9,9 @@ import {groupBy} from 'lodash'; import {InitPlugin} from './init'; import {DEFAULT_PLUGIN_ID} from '../../constants'; -// It is forbidden to have 2 plugins of the same name sharind the same id +// It is forbidden to have 2 plugins of the same name sharing the same id // this is required to support multi-instance plugins without conflict -export function ensureUniquePluginInstanceIds(plugins: InitPlugin[]) { +export function ensureUniquePluginInstanceIds(plugins: InitPlugin[]): void { const pluginsByName = groupBy(plugins, (p) => p.name); Object.entries(pluginsByName).forEach(([pluginName, pluginInstances]) => { const pluginInstancesById = groupBy( diff --git a/packages/docusaurus/src/webpack/base.ts b/packages/docusaurus/src/webpack/base.ts index fff5da0a1748..fb5264ec0192 100644 --- a/packages/docusaurus/src/webpack/base.ts +++ b/packages/docusaurus/src/webpack/base.ts @@ -36,11 +36,11 @@ export function excludeJS(modulePath: string): boolean { ); } -export function getDocusaurusAliases() { +export function getDocusaurusAliases(): Record { const dirPath = path.resolve(__dirname, '../client/exports'); const extensions = ['.js', '.ts', '.tsx']; - const aliases: Record = {}; + const aliases = {}; fs.readdirSync(dirPath) .filter((fileName) => extensions.includes(path.extname(fileName))) diff --git a/packages/docusaurus/src/webpack/utils.ts b/packages/docusaurus/src/webpack/utils.ts index e079671e914e..a30faeca92d6 100644 --- a/packages/docusaurus/src/webpack/utils.ts +++ b/packages/docusaurus/src/webpack/utils.ts @@ -8,7 +8,13 @@ import MiniCssExtractPlugin from 'mini-css-extract-plugin'; import env from 'std-env'; import merge from 'webpack-merge'; -import webpack, {Configuration, Loader, RuleSetRule, Stats} from 'webpack'; +import webpack, { + Configuration, + Loader, + Plugin, + RuleSetRule, + Stats, +} from 'webpack'; import fs from 'fs-extra'; import TerserPlugin from 'terser-webpack-plugin'; import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin'; @@ -228,7 +234,7 @@ export function compile(config: Configuration[]): Promise { type AssetFolder = 'images' | 'files' | 'medias'; // Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447 -export function getFileLoaderUtils() { +export function getFileLoaderUtils(): Record { // files/images < 10kb will be inlined as base64 strings directly in the html const urlLoaderLimit = 10000; @@ -375,7 +381,7 @@ function getTerserParallel() { return terserParallel; } -export function getMinimizer(useSimpleCssMinifier = false) { +export function getMinimizer(useSimpleCssMinifier = false): Plugin[] { const minimizer = [ new TerserPlugin({ cache: true, diff --git a/yarn.lock b/yarn.lock index 4c1246cc271c..2be74fe5cfaa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3197,11 +3197,25 @@ dependencies: "@types/node" "*" -"@types/color-name@^1.1.1": +"@types/color-convert@*": + version "1.9.0" + resolved "https://registry.yarnpkg.com/@types/color-convert/-/color-convert-1.9.0.tgz#bfa8203e41e7c65471e9841d7e306a7cd8b5172d" + integrity sha512-OKGEfULrvSL2VRbkl/gnjjgbbF7ycIlpSsX7Nkab4MOWi5XxmgBYvuiQ7lcCFY5cPDz7MUNaKgxte2VRmtr4Fg== + dependencies: + "@types/color-name" "*" + +"@types/color-name@*", "@types/color-name@^1.1.1": version "1.1.1" resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ== +"@types/color@^3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@types/color/-/color-3.0.1.tgz#2900490ed04da8116c5058cd5dba3572d5a25071" + integrity sha512-oeUWVaAwI+xINDUx+3F2vJkl/vVB03VChFF/Gl3iQCdbcakjuoJyMOba+3BXRtnBhxZ7uBYqQBi9EpLnvSoztA== + dependencies: + "@types/color-convert" "*" + "@types/connect-history-api-fallback@*": version "1.3.3" resolved "https://registry.yarnpkg.com/@types/connect-history-api-fallback/-/connect-history-api-fallback-1.3.3.tgz#4772b79b8b53185f0f4c9deab09236baf76ee3b4" @@ -3537,6 +3551,11 @@ resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA== +"@types/nprogress@^0.2.0": + version "0.2.0" + resolved "https://registry.yarnpkg.com/@types/nprogress/-/nprogress-0.2.0.tgz#86c593682d4199212a0509cc3c4d562bbbd6e45f" + integrity sha512-1cYJrqq9GezNFPsWTZpFut/d4CjpZqA0vhqDUPFWYKF1oIyBz5qnoYMzR+0C/T96t3ebLAC1SSnwrVOm5/j74A== + "@types/parse-json@^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"