remove the need for 'image-size' dependency (#36202)

This commit is contained in:
Peter Bengtsson 2023-04-05 13:37:18 -04:00 коммит произвёл GitHub
Родитель e47fe283c1
Коммит 8e4ba76223
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 13 добавлений и 70 удалений

43
package-lock.json сгенерированный
Просмотреть файл

@ -173,7 +173,6 @@
},
"optionalDependencies": {
"esm": "^3.2.25",
"image-size": "^1.0.1",
"jest-puppeteer": "^5.0.4",
"puppeteer": "^9.1.1",
"website-scraper": "^5.0.0"
@ -10595,21 +10594,6 @@
"dev": true,
"license": "ISC"
},
"node_modules/image-size": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/image-size/-/image-size-1.0.2.tgz",
"integrity": "sha512-xfOoWjceHntRb3qFCrh5ZFORYH8XCdYpASltMhZ/Q0KZiOwjdE/Yl2QCiWdwD+lygV5bMCvauzgu5PxBX/Yerg==",
"optional": true,
"dependencies": {
"queue": "6.0.2"
},
"bin": {
"image-size": "bin/image-size.js"
},
"engines": {
"node": ">=14.0.0"
}
},
"node_modules/immutable": {
"version": "4.0.0",
"devOptional": true,
@ -16759,15 +16743,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/queue": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/queue/-/queue-6.0.2.tgz",
"integrity": "sha512-iHZWu+q3IdFZFX36ro/lKBkSvfkztY5Y7HMiPlOUjhupPcG2JMfst2KKEpu5XndviX/3UhFbRngUPNKtgvtZiA==",
"optional": true,
"dependencies": {
"inherits": "~2.0.3"
}
},
"node_modules/queue-microtask": {
"version": "1.2.3",
"dev": true,
@ -27620,15 +27595,6 @@
"version": "1.0.1",
"dev": true
},
"image-size": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/image-size/-/image-size-1.0.2.tgz",
"integrity": "sha512-xfOoWjceHntRb3qFCrh5ZFORYH8XCdYpASltMhZ/Q0KZiOwjdE/Yl2QCiWdwD+lygV5bMCvauzgu5PxBX/Yerg==",
"optional": true,
"requires": {
"queue": "6.0.2"
}
},
"immutable": {
"version": "4.0.0",
"devOptional": true
@ -31739,15 +31705,6 @@
"side-channel": "^1.0.4"
}
},
"queue": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/queue/-/queue-6.0.2.tgz",
"integrity": "sha512-iHZWu+q3IdFZFX36ro/lKBkSvfkztY5Y7HMiPlOUjhupPcG2JMfst2KKEpu5XndviX/3UhFbRngUPNKtgvtZiA==",
"optional": true,
"requires": {
"inherits": "~2.0.3"
}
},
"queue-microtask": {
"version": "1.2.3",
"dev": true

Просмотреть файл

@ -178,7 +178,6 @@
"name": "docs.github.com",
"optionalDependencies": {
"esm": "^3.2.25",
"image-size": "^1.0.1",
"jest-puppeteer": "^5.0.4",
"puppeteer": "^9.1.1",
"website-scraper": "^5.0.0"

Просмотреть файл

@ -469,14 +469,6 @@ A helper that returns an array of files for a given path and file extension.
This script lists all local image files, sorted by their dimensions.
NOTE: If you get this error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'image-size' ...
it's because you haven't installed all the *optional* dependencies. To do that, run:
npm install --include=optional
---
@ -762,5 +754,3 @@ Exceptions: * Links with fragments (e.g., [Bar](/foo#bar)) will get their root l
This script crawls the script directory, hooks on special comment markers in each script, and adds the comment to `script/README.md`.
---

Просмотреть файл

@ -4,37 +4,34 @@
//
// This script lists all local image files, sorted by their dimensions.
//
// NOTE: If you get this error:
//
// Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'image-size' ...
//
// it's because you haven't installed all the *optional* dependencies.
// To do that, run:
//
// npm install --include=optional
//
// [end-readme]
import { fileURLToPath } from 'url'
import path from 'path'
import walk from 'walk-sync'
import imageSize from 'image-size'
import sharp from 'sharp'
import { chain } from 'lodash-es'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const imagesPath = path.join(__dirname, '../assets/images')
const imagesExtensions = ['.jpg', '.jpeg', '.png', '.gif']
const images = chain(walk(imagesPath, { directories: false }))
.filter((relativePath) => {
return imagesExtensions.includes(path.extname(relativePath.toLowerCase()))
})
.map((relativePath) => {
const files = chain(walk(imagesPath, { directories: false })).filter((relativePath) => {
return imagesExtensions.includes(path.extname(relativePath.toLowerCase()))
})
const infos = await Promise.all(
files.map(async (relativePath) => {
const fullPath = path.join(imagesPath, relativePath)
const { width, height } = imageSize(fullPath)
const image = sharp(fullPath)
const { width, height } = await image.metadata()
const size = width * height
return { relativePath, width, height, size }
})
)
const images = files
.map((relativePath, i) => {
return { relativePath, ...infos[i] }
})
.orderBy('size', 'desc')
.value()