From 8a948102c3e31abcdfd6ee32a8e1d8e4b057c4c4 Mon Sep 17 00:00:00 2001 From: Endi Date: Sun, 1 Dec 2019 21:59:02 +0700 Subject: [PATCH] fix(v2): fix plugin-ideal-image breaking website (exports not defined) (#2074) * fix(v2): fix plugin-ideal-image breaking website (exports not defined) * nits * add npm ignore * lint --- .eslintignore | 1 + .../docusaurus-plugin-ideal-image/.npmignore | 2 ++ .../@types/react-ideal-image.d.ts | 28 ------------------- .../copyUntypedFiles.js | 19 +++++++++++++ .../package.json | 5 ++-- .../src/index.ts | 4 +-- .../theme/{IdealImage.tsx => IdealImage.js} | 8 ++---- .../src/types.ts | 4 --- .../tsconfig.json | 2 -- 9 files changed, 30 insertions(+), 43 deletions(-) create mode 100644 packages/docusaurus-plugin-ideal-image/.npmignore delete mode 100644 packages/docusaurus-plugin-ideal-image/@types/react-ideal-image.d.ts create mode 100644 packages/docusaurus-plugin-ideal-image/copyUntypedFiles.js rename packages/docusaurus-plugin-ideal-image/src/theme/{IdealImage.tsx => IdealImage.js} (81%) diff --git a/.eslintignore b/.eslintignore index 9097f5d54515..1dc5c5691851 100644 --- a/.eslintignore +++ b/.eslintignore @@ -18,3 +18,4 @@ packages/docusaurus-plugin-content-docs/lib/ packages/docusaurus-plugin-content-pages/lib/ packages/docusaurus-plugin-sitemap/lib/ packages/docusaurus-plugin-ideal-image/lib/ +packages/docusaurus-plugin-ideal-image/copyUntypedFiles.js diff --git a/packages/docusaurus-plugin-ideal-image/.npmignore b/packages/docusaurus-plugin-ideal-image/.npmignore new file mode 100644 index 000000000000..4978437c5d30 --- /dev/null +++ b/packages/docusaurus-plugin-ideal-image/.npmignore @@ -0,0 +1,2 @@ +src +copyUntypedFiles.js \ No newline at end of file diff --git a/packages/docusaurus-plugin-ideal-image/@types/react-ideal-image.d.ts b/packages/docusaurus-plugin-ideal-image/@types/react-ideal-image.d.ts deleted file mode 100644 index 057611f3e4bc..000000000000 --- a/packages/docusaurus-plugin-ideal-image/@types/react-ideal-image.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2017-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -declare module '@endiliey/react-ideal-image' { - interface SrcType { - width: number; - src?: string; - size?: number; - format?: 'webp' | 'jpeg'; - } - - export interface IdealImageProps { - alt?: string; - className?: string; - height: number; - width: number; - placeholder: {color: string} | {lqip: string}; - src: string; - srcSet: SrcType[]; - } - - const IdealImage: React.ComponentType; - export default IdealImage; -} diff --git a/packages/docusaurus-plugin-ideal-image/copyUntypedFiles.js b/packages/docusaurus-plugin-ideal-image/copyUntypedFiles.js new file mode 100644 index 000000000000..6bf16e395611 --- /dev/null +++ b/packages/docusaurus-plugin-ideal-image/copyUntypedFiles.js @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +const path = require('path'); +const fs = require('fs-extra'); + +/** + * Copy all untyped and static assets files to lib. + */ +const srcDir = path.resolve(__dirname, 'src'); +const libDir = path.resolve(__dirname, 'lib'); +fs.copySync(srcDir, libDir, { + filter(filepath) { + return !/__tests__/.test(filepath) && !/\.ts$/.test(filepath); + }, +}); diff --git a/packages/docusaurus-plugin-ideal-image/package.json b/packages/docusaurus-plugin-ideal-image/package.json index 633864abbf22..622cd5caf265 100644 --- a/packages/docusaurus-plugin-ideal-image/package.json +++ b/packages/docusaurus-plugin-ideal-image/package.json @@ -4,14 +4,15 @@ "description": "Docusaurus Plugin to generate an almost ideal image (responsive, lazy-loading, and low quality placeholder)", "main": "lib/index.js", "scripts": { - "tsc": "tsc" + "tsc": "tsc && node copyUntypedFiles.js" }, "publishConfig": { "access": "public" }, "license": "MIT", "devDependencies": { - "@docusaurus/types": "^2.0.0-alpha.37" + "@docusaurus/types": "^2.0.0-alpha.37", + "fs-extra": "^8.1.0" }, "dependencies": { "@endiliey/lqip-loader": "^3.0.2", diff --git a/packages/docusaurus-plugin-ideal-image/src/index.ts b/packages/docusaurus-plugin-ideal-image/src/index.ts index f35d291aecc2..4a5ae9eec55b 100644 --- a/packages/docusaurus-plugin-ideal-image/src/index.ts +++ b/packages/docusaurus-plugin-ideal-image/src/index.ts @@ -10,7 +10,7 @@ import {Configuration} from 'webpack'; import path from 'path'; -export = function(_context: LoadContext, options: PluginOptions) { +export default function(_context: LoadContext, options: PluginOptions) { const isProd = process.env.NODE_ENV === 'production'; return { name: 'docusaurus-plugin-ideal-image', @@ -47,4 +47,4 @@ export = function(_context: LoadContext, options: PluginOptions) { }; }, }; -}; +} diff --git a/packages/docusaurus-plugin-ideal-image/src/theme/IdealImage.tsx b/packages/docusaurus-plugin-ideal-image/src/theme/IdealImage.js similarity index 81% rename from packages/docusaurus-plugin-ideal-image/src/theme/IdealImage.tsx rename to packages/docusaurus-plugin-ideal-image/src/theme/IdealImage.js index ecb0508d3811..99ed4d9b239a 100644 --- a/packages/docusaurus-plugin-ideal-image/src/theme/IdealImage.tsx +++ b/packages/docusaurus-plugin-ideal-image/src/theme/IdealImage.js @@ -4,12 +4,10 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ - import React from 'react'; -import {ImageProps} from '../types'; import IdealImage from '@endiliey/react-ideal-image'; -const Image: React.FC = props => { +function Image(props) { const {alt, className, img} = props; return ( = props => { width={img.src.width || 100} placeholder={{lqip: img.preSrc}} src={img.src.src} - srcSet={img.src.images.map((image: any) => ({ + srcSet={img.src.images.map(image => ({ ...image, src: image.path, }))} /> ); -}; +} export default Image; diff --git a/packages/docusaurus-plugin-ideal-image/src/types.ts b/packages/docusaurus-plugin-ideal-image/src/types.ts index b0019955a3cb..4415b255ab55 100644 --- a/packages/docusaurus-plugin-ideal-image/src/types.ts +++ b/packages/docusaurus-plugin-ideal-image/src/types.ts @@ -35,7 +35,3 @@ export interface PluginOptions { */ quality?: number; } - -export interface ImageProps extends React.ImgHTMLAttributes<{}> { - img: any; -} diff --git a/packages/docusaurus-plugin-ideal-image/tsconfig.json b/packages/docusaurus-plugin-ideal-image/tsconfig.json index 6fead23031a1..f50aa9ee6d86 100644 --- a/packages/docusaurus-plugin-ideal-image/tsconfig.json +++ b/packages/docusaurus-plugin-ideal-image/tsconfig.json @@ -5,7 +5,5 @@ "tsBuildInfoFile": "./lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib", - "jsx": "react", - "typeRoots": ["@types"], } }