mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-02 03:37:48 +02:00
chore: upgrade image-size deps to v2 (#11065)
* upgrade image-size to v2 * fix resizeImage script * fix tests
This commit is contained in:
parent
31b279fea6
commit
b7ba0b54fb
7 changed files with 14 additions and 24 deletions
|
@ -9,9 +9,9 @@ import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {fileURLToPath} from 'url';
|
import {fileURLToPath} from 'url';
|
||||||
import {program} from 'commander';
|
import {program} from 'commander';
|
||||||
import logger from '@docusaurus/logger';
|
import {logger} from '@docusaurus/logger';
|
||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
import imageSize from 'image-size';
|
import {imageSizeFromFile} from 'image-size/fromFile';
|
||||||
|
|
||||||
// You can use it as:
|
// You can use it as:
|
||||||
//
|
//
|
||||||
|
@ -64,7 +64,7 @@ program
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
images.map(async (imgPath) => {
|
images.map(async (imgPath) => {
|
||||||
const {width, height} = imageSize(imgPath);
|
const {width, height} = await imageSizeFromFile(imgPath);
|
||||||
const targetWidth =
|
const targetWidth =
|
||||||
options.width ?? (imgPath.includes(showcasePath) ? 640 : 1000);
|
options.width ?? (imgPath.includes(showcasePath) ? 640 : 1000);
|
||||||
const targetHeight =
|
const targetHeight =
|
||||||
|
|
|
@ -104,7 +104,7 @@
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
"eslint-plugin-regexp": "^1.15.0",
|
"eslint-plugin-regexp": "^1.15.0",
|
||||||
"husky": "^8.0.3",
|
"husky": "^8.0.3",
|
||||||
"image-size": "^1.0.2",
|
"image-size": "^2.0.2",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-environment-jsdom": "^29.7.0",
|
"jest-environment-jsdom": "^29.7.0",
|
||||||
"jest-serializer-ansi-escapes": "^3.0.0",
|
"jest-serializer-ansi-escapes": "^3.0.0",
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
"estree-util-value-to-estree": "^3.0.1",
|
"estree-util-value-to-estree": "^3.0.1",
|
||||||
"file-loader": "^6.2.0",
|
"file-loader": "^6.2.0",
|
||||||
"fs-extra": "^11.1.1",
|
"fs-extra": "^11.1.1",
|
||||||
"image-size": "^1.0.2",
|
"image-size": "^2.0.2",
|
||||||
"mdast-util-mdx": "^3.0.0",
|
"mdast-util-mdx": "^3.0.0",
|
||||||
"mdast-util-to-string": "^4.0.0",
|
"mdast-util-to-string": "^4.0.0",
|
||||||
"rehype-raw": "^7.0.0",
|
"rehype-raw": "^7.0.0",
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import {promisify} from 'util';
|
|
||||||
import {
|
import {
|
||||||
toMessageRelativeFilePath,
|
toMessageRelativeFilePath,
|
||||||
posixPath,
|
posixPath,
|
||||||
|
@ -17,7 +16,7 @@ import {
|
||||||
getFileLoaderUtils,
|
getFileLoaderUtils,
|
||||||
} from '@docusaurus/utils';
|
} from '@docusaurus/utils';
|
||||||
import escapeHtml from 'escape-html';
|
import escapeHtml from 'escape-html';
|
||||||
import sizeOf from 'image-size';
|
import {imageSizeFromFile} from 'image-size/fromFile';
|
||||||
import logger from '@docusaurus/logger';
|
import logger from '@docusaurus/logger';
|
||||||
import {assetRequireAttributeValue, transformNode} from '../utils';
|
import {assetRequireAttributeValue, transformNode} from '../utils';
|
||||||
import type {Plugin, Transformer} from 'unified';
|
import type {Plugin, Transformer} from 'unified';
|
||||||
|
@ -80,7 +79,7 @@ async function toImageRequireNode(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const size = (await promisify(sizeOf)(imagePath))!;
|
const size = (await imageSizeFromFile(imagePath))!;
|
||||||
if (size.width) {
|
if (size.width) {
|
||||||
attributes.push({
|
attributes.push({
|
||||||
type: 'mdxJsxAttribute',
|
type: 'mdxJsxAttribute',
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import imageSize from 'image-size';
|
import {imageSizeFromFile} from 'image-size/fromFile';
|
||||||
import {Joi} from '@docusaurus/utils-validation';
|
import {Joi} from '@docusaurus/utils-validation';
|
||||||
import {TagList, sortedUsers, type User} from '../users';
|
import {TagList, sortedUsers, type User} from '../users';
|
||||||
|
|
||||||
|
@ -157,8 +157,8 @@ describe('preview images', () => {
|
||||||
.readdirSync(imageDir)
|
.readdirSync(imageDir)
|
||||||
.filter((file) => ['.png', 'jpg', '.jpeg'].includes(path.extname(file)));
|
.filter((file) => ['.png', 'jpg', '.jpeg'].includes(path.extname(file)));
|
||||||
|
|
||||||
it.each(files)('%s', (file) => {
|
it.each(files)('%s', async (file) => {
|
||||||
const size = imageSize(path.join(imageDir, file));
|
const size = await imageSizeFromFile(path.join(imageDir, file));
|
||||||
|
|
||||||
expect(size).toHaveGoodDimensions();
|
expect(size).toHaveGoodDimensions();
|
||||||
});
|
});
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 365 KiB After Width: | Height: | Size: 35 KiB |
17
yarn.lock
17
yarn.lock
|
@ -9847,12 +9847,10 @@ ignore@^5.0.4, ignore@^5.2.0, ignore@^5.2.1, ignore@^5.2.4:
|
||||||
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.2.tgz#3cd40e729f3643fd87cb04e50bf0eb722bc596f5"
|
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.2.tgz#3cd40e729f3643fd87cb04e50bf0eb722bc596f5"
|
||||||
integrity sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==
|
integrity sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==
|
||||||
|
|
||||||
image-size@^1.0.2:
|
image-size@^2.0.2:
|
||||||
version "1.1.1"
|
version "2.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/image-size/-/image-size-1.1.1.tgz#ddd67d4dc340e52ac29ce5f546a09f4e29e840ac"
|
resolved "https://registry.yarnpkg.com/image-size/-/image-size-2.0.2.tgz#84a7b43704db5736f364bf0d1b029821299b4bdc"
|
||||||
integrity sha512-541xKlUw6jr/6gGuk92F+mYM5zaFAc5ahphvkqvNe2bQ6gVBkd6bfrmVJ2t4KDAfikAYZyIqTnktX3i6/aQDrQ==
|
integrity sha512-IRqXKlaXwgSMAMtpNzZa1ZAe8m+Sa1770Dhk8VkSsP9LS+iHD62Zd8FQKs8fbPiagBE7BzoFX23cxFnwshpV6w==
|
||||||
dependencies:
|
|
||||||
queue "6.0.2"
|
|
||||||
|
|
||||||
import-fresh@^3.2.1, import-fresh@^3.3.0:
|
import-fresh@^3.2.1, import-fresh@^3.3.0:
|
||||||
version "3.3.0"
|
version "3.3.0"
|
||||||
|
@ -14939,13 +14937,6 @@ queue-tick@^1.0.1:
|
||||||
resolved "https://registry.yarnpkg.com/queue-tick/-/queue-tick-1.0.1.tgz#f6f07ac82c1fd60f82e098b417a80e52f1f4c142"
|
resolved "https://registry.yarnpkg.com/queue-tick/-/queue-tick-1.0.1.tgz#f6f07ac82c1fd60f82e098b417a80e52f1f4c142"
|
||||||
integrity sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag==
|
integrity sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag==
|
||||||
|
|
||||||
queue@6.0.2:
|
|
||||||
version "6.0.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/queue/-/queue-6.0.2.tgz#b91525283e2315c7553d2efa18d83e76432fed65"
|
|
||||||
integrity sha512-iHZWu+q3IdFZFX36ro/lKBkSvfkztY5Y7HMiPlOUjhupPcG2JMfst2KKEpu5XndviX/3UhFbRngUPNKtgvtZiA==
|
|
||||||
dependencies:
|
|
||||||
inherits "~2.0.3"
|
|
||||||
|
|
||||||
quick-lru@^4.0.1:
|
quick-lru@^4.0.1:
|
||||||
version "4.0.1"
|
version "4.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-4.0.1.tgz#5b8878f113a58217848c6482026c73e1ba57727f"
|
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-4.0.1.tgz#5b8878f113a58217848c6482026c73e1ba57727f"
|
||||||
|
|
Loading…
Add table
Reference in a new issue