Skip to content

Commit 6879e0b

Browse files
authored
Merge pull request #33724 from github/repo-sync
Repo sync
2 parents 3b9d172 + 53b5f97 commit 6879e0b

File tree

6 files changed

+29
-38
lines changed

6 files changed

+29
-38
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@
355355
"eslint-plugin-jsx-a11y": "^6.9.0",
356356
"eslint-plugin-primer-react": "^5.3.0",
357357
"event-to-promise": "^0.8.0",
358-
"graphql": "^16.8.1",
358+
"graphql": "^16.9.0",
359359
"http-status-code": "^2.1.0",
360360
"husky": "^9.0.8",
361361
"json-schema-merge-allof": "^0.8.1",
@@ -376,7 +376,7 @@
376376
"robots-parser": "^3.0.0",
377377
"sass": "^1.77.1",
378378
"start-server-and-test": "^2.0.3",
379-
"typescript": "^5.4.4",
379+
"typescript": "^5.5.2",
380380
"unist-util-remove": "^4.0.0",
381381
"unist-util-visit-parents": "6.0.1",
382382
"vitest": "1.6.0",

src/assets/middleware/dynamic-assets.js renamed to src/assets/middleware/dynamic-assets.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import fs from 'fs/promises'
22

3+
import type { Response, NextFunction } from 'express'
34
import sharp from 'sharp'
45

5-
import { assetCacheControl, defaultCacheControl } from '#src/frame/middleware/cache-control.js'
6+
import type { ExtendedRequest } from '@/types'
7+
import { assetCacheControl, defaultCacheControl } from '@/frame/middleware/cache-control.js'
68
import {
79
setFastlySurrogateKey,
810
SURROGATE_ENUMS,
9-
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
11+
} from '@/frame/middleware/set-fastly-surrogate-key.js'
1012

1113
/**
1214
* This is the indicator that is a virtual part of the URL.
@@ -37,7 +39,11 @@ const maxWidthPathPartRegex = /\/mw-(\d+)\//
3739
*/
3840
const VALID_MAX_WIDTHS = [1440, 1000]
3941

40-
export default async function dynamicAssets(req, res, next) {
42+
export default async function dynamicAssets(
43+
req: ExtendedRequest,
44+
res: Response,
45+
next: NextFunction,
46+
) {
4147
if (!req.url.startsWith('/assets/')) return next()
4248

4349
if (!(req.method === 'GET' || req.method === 'HEAD')) {
@@ -88,6 +94,7 @@ export default async function dynamicAssets(req, res, next) {
8894

8995
if (maxWidth) {
9096
const { width } = await image.metadata()
97+
if (width === undefined) throw new Error('image metadata does not have a width')
9198
if (width > maxWidth) {
9299
image.resize({ width: maxWidth })
93100
}
@@ -140,7 +147,7 @@ export default async function dynamicAssets(req, res, next) {
140147
assetCacheControl(res)
141148
return res.type('image/webp').send(buffer)
142149
} catch (error) {
143-
if (error.code !== 'ENOENT') {
150+
if (error instanceof Error && (error as any).code !== 'ENOENT') {
144151
throw error
145152
}
146153
}
@@ -166,7 +173,7 @@ export default async function dynamicAssets(req, res, next) {
166173
res.status(404).type('text/plain').send('Asset not found')
167174
}
168175

169-
function deconstructImageURL(url) {
176+
function deconstructImageURL(url: string) {
170177
let error
171178
let maxWidth
172179
const match = url.match(maxWidthPathPartRegex)

src/assets/tests/dynamic-assets.js renamed to src/assets/tests/dynamic-assets.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { describe, expect, test, vi } from 'vitest'
33
import sharp from 'sharp'
44
import { fileTypeFromBuffer } from 'file-type'
55

6-
import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
7-
import { get, head } from '#src/tests/helpers/e2etest.js'
6+
import { SURROGATE_ENUMS } from '@/frame/middleware/set-fastly-surrogate-key.js'
7+
import { get, head } from '@/tests/helpers/e2etest.js'
88

99
describe('dynamic assets', () => {
1010
vi.setConfig({ testTimeout: 3 * 60 * 1000 })
@@ -15,7 +15,10 @@ describe('dynamic assets', () => {
1515
})
1616
expect(res.statusCode).toBe(200)
1717
expect(res.headers['content-type']).toBe('image/webp')
18-
const { mime } = await fileTypeFromBuffer(res.body)
18+
19+
const fileTypeResult = await fileTypeFromBuffer(res.body)
20+
if (!fileTypeResult) throw new Error('fileTypeFromBuffer failed')
21+
const { mime } = fileTypeResult
1922
expect(mime).toBe('image/webp')
2023
})
2124

src/frame/middleware/fastly-behavior.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/frame/middleware/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ import setStaticAssetCaching from '@/assets/middleware/static-asset-caching'
5959
import fastHead from './fast-head'
6060
import fastlyCacheTest from './fastly-cache-test'
6161
import trailingSlashes from './trailing-slashes'
62-
import fastlyBehavior from './fastly-behavior.js'
6362
import mockVaPortal from './mock-va-portal.js'
64-
import dynamicAssets from '@/assets/middleware/dynamic-assets.js'
63+
import dynamicAssets from '@/assets/middleware/dynamic-assets'
6564
import contextualizeSearch from '@/search/middleware/contextualize.js'
6665
import shielding from '@/shielding/middleware'
6766
import tracking from '@/tracking/middleware'
@@ -205,10 +204,6 @@ export default function (app: Express) {
205204
app.use(cookieParser)
206205
app.use(express.json())
207206

208-
if (ENABLE_FASTLY_TESTING) {
209-
app.use(fastlyBehavior) // FOR TESTING.
210-
}
211-
212207
if (process.env.NODE_ENV === 'development') {
213208
app.use(mockVaPortal) // FOR TESTING.
214209
}

0 commit comments

Comments
 (0)