Skip to content

Commit 1371440

Browse files
authored
fix: ensure rendering engine has vendored libvips (#39317)
* fix: ensure rendering engine has vendored libvips * chore: bump caniuse * test: visit and intercept direct html routes and avoid hitting redirects which mess up html header assertions
1 parent 8d44379 commit 1371440

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

e2e-tests/adapters/cypress/e2e/headers.cy.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { applyTrailingSlashOption } from "../../utils"
12
import { WorkaroundCachedResponse } from "../utils/dont-cache-responses-in-browser"
23

4+
const TRAILING_SLASH = Cypress.env(`TRAILING_SLASH`) || `never`
35
const PATH_PREFIX = Cypress.env(`PATH_PREFIX`) || ``
46

57
describe("Headers", () => {
@@ -75,7 +77,10 @@ describe("Headers", () => {
7577
}
7678

7779
beforeEach(() => {
78-
cy.intercept(PATH_PREFIX + "/", WorkaroundCachedResponse).as("index")
80+
cy.intercept(
81+
applyTrailingSlashOption(PATH_PREFIX, TRAILING_SLASH),
82+
WorkaroundCachedResponse
83+
).as("index")
7984
cy.intercept(
8085
PATH_PREFIX + "/routes/ssg/static",
8186
WorkaroundCachedResponse
@@ -114,7 +119,9 @@ describe("Headers", () => {
114119
})
115120

116121
it("should contain correct headers for index page", () => {
117-
cy.visit("/").waitForRouteChange()
122+
cy.visit(
123+
applyTrailingSlashOption(Cypress.config().baseUrl, TRAILING_SLASH)
124+
).waitForRouteChange()
118125

119126
checkHeaders("@index", {
120127
...defaultHeaders,
@@ -133,7 +140,12 @@ describe("Headers", () => {
133140
})
134141

135142
it("should contain correct headers for ssg page", () => {
136-
cy.visit("routes/ssg/static").waitForRouteChange()
143+
cy.visit(
144+
applyTrailingSlashOption(
145+
Cypress.config().baseUrl + "/routes/ssg/static",
146+
TRAILING_SLASH
147+
)
148+
).waitForRouteChange()
137149

138150
checkHeaders("@ssg", {
139151
...defaultHeaders,

packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,24 @@ function checkIfNeedToInstallMissingSharp(
233233
currentTarget: IPlatformAndArch
234234
): IBinaryPackageStatus | undefined {
235235
try {
236-
// check if shapr is resolvable
237-
const { version: sharpVersion } = require(`sharp/package.json`)
236+
// check if sharp is resolvable
237+
const sharp: typeof import("sharp") = require(`sharp`)
238238

239239
if (isEqual(functionsTarget, currentTarget)) {
240-
return undefined
240+
// if current platform and target is the same as functions target, we need to check if vendored libvips
241+
// exists in the current sharp installation as it will be needed in lambda
242+
if (sharp.vendor.installed.includes(sharp.vendor.current)) {
243+
// vendored libvips is installed, so we can use it
244+
return undefined
245+
}
241246
}
242247

243248
return checkIfInstalledInInternalPackagesCache(
244249
{
245250
needToInstall: true,
246251
packageName: `sharp`,
247-
packageVersion: sharpVersion,
252+
packageVersion:
253+
sharp.versions.sharp ?? require(`sharp/package.json`).version,
248254
},
249255
functionsTarget
250256
)
@@ -279,6 +285,10 @@ async function installMissing(
279285
env: {
280286
npm_config_arch: functionsTarget.arch,
281287
npm_config_platform: functionsTarget.platform,
288+
// force sharp to download vendored libvips and not skip it if globally installed libvips matches sharp requirements
289+
// so that produced function is self-sufficient and doesn't rely on function execution environment having (same)
290+
// globally available libvips
291+
SHARP_IGNORE_GLOBAL_LIBVIPS: `1`,
282292
},
283293
}
284294

yarn.lock

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7608,15 +7608,10 @@ caniuse-api@^3.0.0:
76087608
lodash.memoize "^4.1.2"
76097609
lodash.uniq "^4.5.0"
76107610

7611-
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001538, caniuse-lite@^1.0.30001565:
7612-
version "1.0.30001692"
7613-
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001692.tgz"
7614-
integrity sha512-A95VKan0kdtrsnMubMKxEKUKImOPSuCpYgxSQBo036P5YYgVIcOYJEgt/txJWqObiRQeISNCfef9nvlQ0vbV7A==
7615-
7616-
caniuse-lite@^1.0.30001688:
7617-
version "1.0.30001712"
7618-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001712.tgz#41ee150f12de11b5f57c5889d4f30deb451deedf"
7619-
integrity sha512-MBqPpGYYdQ7/hfKiet9SCI+nmN5/hp4ZzveOJubl5DTAMa5oggjAuoi0Z4onBpKPFI2ePGnQuQIzF3VxDjDJig==
7611+
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001538, caniuse-lite@^1.0.30001565, caniuse-lite@^1.0.30001688:
7612+
version "1.0.30001723"
7613+
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001723.tgz"
7614+
integrity sha512-1R/elMjtehrFejxwmexeXAtae5UO9iSyFn6G/I806CYC/BLyyBk1EPhrKBkWhy6wM6Xnm47dSJQec+tLJ39WHw==
76207615

76217616
capital-case@^1.0.4:
76227617
version "1.0.4"

0 commit comments

Comments
 (0)