Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions packages/gatsby-plugin-manifest/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"name": "gatsby-plugin-manifest",
"name": "@redocly/gatsby-plugin-manifest",
"description": "Gatsby plugin which adds a manifest.webmanifest to make sites progressive web apps",
"version": "3.3.0-next.1",
"version": "3.3.2",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
},
"dependencies": {
"@babel/runtime": "^7.12.5",
"gatsby-core-utils": "^2.3.0-next.1",
"gatsby-plugin-utils": "^1.3.0-next.1",
"semver": "^7.3.2",
"sharp": "^0.28.0"
"gatsby-core-utils": "^2.3.0",
"gatsby-plugin-utils": "^1.3.0",
"semver": "^7.3.2"
},
"optionalDependencies": {
"sharp": "^0.27.2"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"babel-preset-gatsby-package": "^1.3.0-next.1",
"cross-env": "^7.0.3"
"babel-preset-gatsby-package": "^1.3.0",
"cross-env": "^7.0.3",
"sharp": "^0.27.2"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-manifest#readme",
"keywords": [
Expand All @@ -32,7 +35,7 @@
"license": "MIT",
"main": "index.js",
"peerDependencies": {
"gatsby": "^3.0.0-next.0"
"gatsby": "^3.0.0"
},
"repository": {
"type": "git",
Expand Down
24 changes: 16 additions & 8 deletions packages/gatsby-plugin-manifest/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import * as fs from "fs"
import * as path from "path"
import sharp from "./safe-sharp"
import { createContentDigest, cpuCoreCount, slash } from "gatsby-core-utils"
import { defaultIcons, addDigestToPath, favicons } from "./common"
import { doesIconExist } from "./node-helpers"

import pluginOptionsSchema from "./pluginOptionsSchema"

sharp.simd(true)
let sharp
function getSharp() {
// import sharp lazily
if (!sharp) {
sharp = require(`./safe-sharp`)
sharp.simd(true)
}

// Handle Sharp's concurrency based on the Gatsby CPU count
// See: http://sharp.pixelplumbing.com/en/stable/api-utility/#concurrency
// See: https://www.gatsbyjs.org/docs/multi-core-builds/
sharp.concurrency(cpuCoreCount())

// Handle Sharp's concurrency based on the Gatsby CPU count
// See: http://sharp.pixelplumbing.com/en/stable/api-utility/#concurrency
// See: https://www.gatsbyjs.org/docs/multi-core-builds/
sharp.concurrency(cpuCoreCount())
return sharp
}

async function generateIcon(icon, srcIcon) {
const imgPath = path.join(`public`, icon.src)
Expand All @@ -30,7 +38,7 @@ async function generateIcon(icon, srcIcon) {
// Sharp accept density from 1 to 2400
const density = Math.min(2400, Math.max(1, size))

return sharp(srcIcon, { density })
return getSharp()(srcIcon, { density })
.resize({
width: size,
height: size,
Expand Down Expand Up @@ -195,7 +203,7 @@ const makeManifest = async ({
)
}

const sharpIcon = sharp(icon)
const sharpIcon = getSharp()(icon)

const metadata = await sharpIcon.metadata()

Expand Down
10 changes: 10 additions & 0 deletions packages/gatsby-plugin-manifest/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ exports.onRenderBody = (
)
}
}
} else if (icons.length) {
// otherwise use first icon as favicon.
headComponents.push(
<link
key={`gatsby-plugin-manifest-icon-link-png`}
rel="icon"
href={withPrefix(addDigestToPath(icons[0].src, cacheDigest, `none`))}
type="image/png"
/>
)
}

// Add manifest link tag.
Expand Down